Skip to content

Fix fully initializing JSStackFrame #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6507,6 +6507,10 @@ static void build_backtrace(JSContext *ctx, JSValue error_obj,
const char *atom_str;
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,
sf->cur_pc - b->byte_code_buf - 1,
&col_num1);
Expand Down Expand Up @@ -14601,6 +14605,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
stack_buf = var_buf + b->var_count;
sp = stack_buf;
pc = b->byte_code_buf;
sf->cur_pc = NULL; /* It's != NULL for bytecode functions. */
sf->prev_frame = rt->current_stack_frame;
rt->current_stack_frame = sf;
ctx = b->realm; /* set the current realm */
Expand Down Expand Up @@ -14656,6 +14661,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_get_length):
{
sf->cur_pc = pc;
JSValue val;

val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);
Expand Down Expand Up @@ -15007,6 +15013,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
int magic;
magic = get_u16(pc);
pc += 2;
sf->cur_pc = pc;

ret_val = js_function_apply(ctx, sp[-3], 2, &sp[-2], magic);
if (unlikely(JS_IsException(ret_val)))
Expand Down Expand Up @@ -15827,6 +15834,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSAtom atom;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], ic, FALSE);
if (unlikely(JS_IsException(val)))
goto exception;
Expand All @@ -15849,6 +15857,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
ic_offset = get_u32(pc);
atom = get_ic_atom(ic, ic_offset);
pc += 4;
sf->cur_pc = pc;
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
ic->updated = FALSE;
if (unlikely(JS_IsException(val)))
Expand All @@ -15863,6 +15872,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSAtom atom;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
val = JS_GetPropertyInternal2(ctx, sp[-1], atom, sp[-1], NULL, FALSE);
if (unlikely(JS_IsException(val)))
goto exception;
Expand All @@ -15884,6 +15894,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
ic_offset = get_u32(pc);
atom = get_ic_atom(ic, ic_offset);
pc += 4;
sf->cur_pc = pc;
val = JS_GetPropertyInternalWithIC(ctx, sp[-1], atom, sp[-1], ic, ic_offset, FALSE);
ic->updated = FALSE;
if (unlikely(JS_IsException(val)))
Expand All @@ -15898,6 +15909,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSAtom atom;
atom = get_u32(pc);
pc += 4;
sf->cur_pc = pc;
ret = JS_SetPropertyInternal2(ctx,
sp[-2], atom,
sp[-1], sp[-2],
Expand All @@ -15923,6 +15935,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
ic_offset = get_u32(pc);
atom = get_ic_atom(ic, ic_offset);
pc += 4;
sf->cur_pc = pc;
ret = JS_SetPropertyInternalWithIC(ctx, sp[-2], atom, sp[-1], JS_PROP_THROW_STRICT, ic, ic_offset);
ic->updated = FALSE;
JS_FreeValue(ctx, sp[-2]);
Expand Down Expand Up @@ -16276,6 +16289,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSValue op1, op2;
op1 = sp[-2];
op2 = sp[-1];
sf->cur_pc = pc;
if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {
int64_t r;
r = (int64_t)JS_VALUE_GET_INT(op1) + JS_VALUE_GET_INT(op2);
Expand All @@ -16301,6 +16315,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
int idx;
idx = *pc;
pc += 1;
sf->cur_pc = pc;

pv = &var_buf[idx];
if (likely(JS_VALUE_IS_BOTH_INT(*pv, sp[-1]))) {
Expand Down Expand Up @@ -16710,11 +16725,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1));

CASE(OP_in):
sf->cur_pc = pc;
if (js_operator_in(ctx, sp))
goto exception;
sp--;
BREAK;
CASE(OP_instanceof):
sf->cur_pc = pc;
if (js_operator_instanceof(ctx, sp))
goto exception;
sp--;
Expand Down
6 changes: 0 additions & 6 deletions v8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,6 @@ Failure (testClassNames doesn't contain expected[1] stack = at MyObj (stack-
at <eval> (stack-traces.js:291:49)
): 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
Failure: expected <7.922816251426436e+28> found <7.922816251426434e+28>
=== stress-array-push.js
Expand Down