Fix fully initializing JSStackFrame (#328)
Fixes: https://github.com/quickjs-ng/quickjs/issues/323
This commit is contained in:
parent
1796b36db7
commit
18f2898f52
2 changed files with 17 additions and 6 deletions
17
quickjs.c
17
quickjs.c
|
@ -6517,6 +6517,10 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj,
|
||||||
const char *atom_str;
|
const char *atom_str;
|
||||||
int line_num1, col_num1;
|
int line_num1, col_num1;
|
||||||
|
|
||||||
|
/* Bytecode functions must have cur_pc set in the stack frame. */
|
||||||
|
if (sf->cur_pc == NULL)
|
||||||
|
abort();
|
||||||
|
|
||||||
line_num1 = find_line_num(ctx, b,
|
line_num1 = find_line_num(ctx, b,
|
||||||
sf->cur_pc - b->byte_code_buf - 1,
|
sf->cur_pc - b->byte_code_buf - 1,
|
||||||
&col_num1);
|
&col_num1);
|
||||||
|
@ -14611,6 +14615,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
stack_buf = var_buf + b->var_count;
|
stack_buf = var_buf + b->var_count;
|
||||||
sp = stack_buf;
|
sp = stack_buf;
|
||||||
pc = b->byte_code_buf;
|
pc = b->byte_code_buf;
|
||||||
|
sf->cur_pc = NULL; /* It's != NULL for bytecode functions. */
|
||||||
sf->prev_frame = rt->current_stack_frame;
|
sf->prev_frame = rt->current_stack_frame;
|
||||||
rt->current_stack_frame = sf;
|
rt->current_stack_frame = sf;
|
||||||
ctx = b->realm; /* set the current realm */
|
ctx = b->realm; /* set the current realm */
|
||||||
|
@ -14666,6 +14671,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
BREAK;
|
BREAK;
|
||||||
CASE(OP_get_length):
|
CASE(OP_get_length):
|
||||||
{
|
{
|
||||||
|
sf->cur_pc = pc;
|
||||||
JSValue val;
|
JSValue val;
|
||||||
|
|
||||||
val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);
|
val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);
|
||||||
|
@ -15017,6 +15023,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
int magic;
|
int magic;
|
||||||
magic = get_u16(pc);
|
magic = get_u16(pc);
|
||||||
pc += 2;
|
pc += 2;
|
||||||
|
sf->cur_pc = pc;
|
||||||
|
|
||||||
ret_val = js_function_apply(ctx, sp[-3], 2, &sp[-2], magic);
|
ret_val = js_function_apply(ctx, sp[-3], 2, &sp[-2], magic);
|
||||||
if (unlikely(JS_IsException(ret_val)))
|
if (unlikely(JS_IsException(ret_val)))
|
||||||
|
@ -15837,6 +15844,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
JSAtom atom;
|
JSAtom atom;
|
||||||
atom = get_u32(pc);
|
atom = get_u32(pc);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], ic, FALSE);
|
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], ic, FALSE);
|
||||||
if (unlikely(JS_IsException(val)))
|
if (unlikely(JS_IsException(val)))
|
||||||
goto exception;
|
goto exception;
|
||||||
|
@ -15859,6 +15867,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
ic_offset = get_u32(pc);
|
ic_offset = get_u32(pc);
|
||||||
atom = get_ic_atom(ic, ic_offset);
|
atom = get_ic_atom(ic, ic_offset);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
|
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
|
||||||
ic->updated = FALSE;
|
ic->updated = FALSE;
|
||||||
if (unlikely(JS_IsException(val)))
|
if (unlikely(JS_IsException(val)))
|
||||||
|
@ -15873,6 +15882,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
JSAtom atom;
|
JSAtom atom;
|
||||||
atom = get_u32(pc);
|
atom = get_u32(pc);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], NULL, FALSE);
|
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], NULL, FALSE);
|
||||||
if (unlikely(JS_IsException(val)))
|
if (unlikely(JS_IsException(val)))
|
||||||
goto exception;
|
goto exception;
|
||||||
|
@ -15894,6 +15904,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
ic_offset = get_u32(pc);
|
ic_offset = get_u32(pc);
|
||||||
atom = get_ic_atom(ic, ic_offset);
|
atom = get_ic_atom(ic, ic_offset);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
|
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
|
||||||
ic->updated = FALSE;
|
ic->updated = FALSE;
|
||||||
if (unlikely(JS_IsException(val)))
|
if (unlikely(JS_IsException(val)))
|
||||||
|
@ -15908,6 +15919,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
JSAtom atom;
|
JSAtom atom;
|
||||||
atom = get_u32(pc);
|
atom = get_u32(pc);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
ret = JS_SetPropertyInternal2(ctx,
|
ret = JS_SetPropertyInternal2(ctx,
|
||||||
sp[-2], atom,
|
sp[-2], atom,
|
||||||
sp[-1], sp[-2],
|
sp[-1], sp[-2],
|
||||||
|
@ -15933,6 +15945,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
ic_offset = get_u32(pc);
|
ic_offset = get_u32(pc);
|
||||||
atom = get_ic_atom(ic, ic_offset);
|
atom = get_ic_atom(ic, ic_offset);
|
||||||
pc += 4;
|
pc += 4;
|
||||||
|
sf->cur_pc = pc;
|
||||||
ret = JS_SetPropertyInternalWithIC(ctx, sp[-2], atom, sp[-1], JS_PROP_THROW_STRICT, ic, ic_offset);
|
ret = JS_SetPropertyInternalWithIC(ctx, sp[-2], atom, sp[-1], JS_PROP_THROW_STRICT, ic, ic_offset);
|
||||||
ic->updated = FALSE;
|
ic->updated = FALSE;
|
||||||
JS_FreeValue(ctx, sp[-2]);
|
JS_FreeValue(ctx, sp[-2]);
|
||||||
|
@ -16286,6 +16299,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
JSValue op1, op2;
|
JSValue op1, op2;
|
||||||
op1 = sp[-2];
|
op1 = sp[-2];
|
||||||
op2 = sp[-1];
|
op2 = sp[-1];
|
||||||
|
sf->cur_pc = pc;
|
||||||
if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {
|
if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {
|
||||||
int64_t r;
|
int64_t r;
|
||||||
r = (int64_t)JS_VALUE_GET_INT(op1) + JS_VALUE_GET_INT(op2);
|
r = (int64_t)JS_VALUE_GET_INT(op1) + JS_VALUE_GET_INT(op2);
|
||||||
|
@ -16311,6 +16325,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
int idx;
|
int idx;
|
||||||
idx = *pc;
|
idx = *pc;
|
||||||
pc += 1;
|
pc += 1;
|
||||||
|
sf->cur_pc = pc;
|
||||||
|
|
||||||
pv = &var_buf[idx];
|
pv = &var_buf[idx];
|
||||||
if (likely(JS_VALUE_IS_BOTH_INT(*pv, sp[-1]))) {
|
if (likely(JS_VALUE_IS_BOTH_INT(*pv, sp[-1]))) {
|
||||||
|
@ -16720,11 +16735,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
|
||||||
OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1));
|
OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1));
|
||||||
|
|
||||||
CASE(OP_in):
|
CASE(OP_in):
|
||||||
|
sf->cur_pc = pc;
|
||||||
if (js_operator_in(ctx, sp))
|
if (js_operator_in(ctx, sp))
|
||||||
goto exception;
|
goto exception;
|
||||||
sp--;
|
sp--;
|
||||||
BREAK;
|
BREAK;
|
||||||
CASE(OP_instanceof):
|
CASE(OP_instanceof):
|
||||||
|
sf->cur_pc = pc;
|
||||||
if (js_operator_instanceof(ctx, sp))
|
if (js_operator_instanceof(ctx, sp))
|
||||||
goto exception;
|
goto exception;
|
||||||
sp--;
|
sp--;
|
||||||
|
|
6
v8.txt
6
v8.txt
|
@ -762,12 +762,6 @@ Failure (testClassNames doesn't contain expected[1] stack = at MyObj (stack-
|
||||||
at <eval> (stack-traces.js:291:49)
|
at <eval> (stack-traces.js:291:49)
|
||||||
): expected <true> found <false>
|
): expected <true> found <false>
|
||||||
Failure (UnintendedCallerCensorship didn't contain new ReferenceError): expected <true> found <false>
|
Failure (UnintendedCallerCensorship didn't contain new ReferenceError): expected <true> found <false>
|
||||||
Failure: expected <"abc"> found <undefined>
|
|
||||||
Failure: expected <"abc"> found <" at <eval> (stack-traces.js:371:13)\n">
|
|
||||||
Failure: expected <undefined> found <" at <eval> (stack-traces.js:375:13)\n">
|
|
||||||
TypeError: not a function
|
|
||||||
at <eval> (stack-traces.js:381:1)
|
|
||||||
|
|
||||||
=== str-to-num.js
|
=== str-to-num.js
|
||||||
Failure: expected <7.922816251426436e+28> found <7.922816251426434e+28>
|
Failure: expected <7.922816251426436e+28> found <7.922816251426434e+28>
|
||||||
=== stress-array-push.js
|
=== stress-array-push.js
|
||||||
|
|
Loading…
Reference in a new issue