Fix more error cases (#332)

* Fix more error cases

- fix more cases of missing `sf->cur_pc`.
- use more precise error messages for number conversion methods
- add test cases in test_builtin.js
- updated v8 test results
This commit is contained in:
Charlie Gordon 2024-03-26 13:22:37 +01:00 committed by GitHub
parent c076339899
commit f02ed184a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 120 additions and 14 deletions

View file

@ -14625,7 +14625,8 @@ 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->cur_pc must we set to pc before any recursive calls to JS_CallInternal. */
sf->cur_pc = NULL;
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 */
@ -14681,9 +14682,9 @@ 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;
sf->cur_pc = pc;
val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length); val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);
if (unlikely(JS_IsException(val))) if (unlikely(JS_IsException(val)))
goto exception; goto exception;
@ -15156,6 +15157,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
scope_idx = get_u16(pc) - 1; scope_idx = get_u16(pc) - 1;
pc += 2; pc += 2;
sf->cur_pc = pc;
tab = build_arg_list(ctx, &len, sp[-1]); tab = build_arg_list(ctx, &len, sp[-1]);
if (!tab) if (!tab)
goto exception; goto exception;
@ -15202,6 +15204,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_import): CASE(OP_import):
{ {
JSValue val; JSValue val;
sf->cur_pc = pc;
val = js_dynamic_import(ctx, sp[-1]); val = js_dynamic_import(ctx, sp[-1]);
if (JS_IsException(val)) if (JS_IsException(val))
goto exception; goto exception;
@ -15231,6 +15234,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_GetGlobalVar(ctx, atom, opcode - OP_get_var_undef); val = JS_GetGlobalVar(ctx, atom, opcode - OP_get_var_undef);
if (unlikely(JS_IsException(val))) if (unlikely(JS_IsException(val)))
@ -15246,6 +15250,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_SetGlobalVar(ctx, atom, sp[-1], opcode - OP_put_var); ret = JS_SetGlobalVar(ctx, atom, sp[-1], opcode - OP_put_var);
sp--; sp--;
@ -15260,6 +15265,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;
/* sp[-2] is JS_TRUE or JS_FALSE */ /* sp[-2] is JS_TRUE or JS_FALSE */
if (unlikely(!JS_VALUE_GET_INT(sp[-2]))) { if (unlikely(!JS_VALUE_GET_INT(sp[-2]))) {
@ -15716,15 +15722,18 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK; BREAK;
CASE(OP_for_in_start): CASE(OP_for_in_start):
sf->cur_pc = pc;
if (js_for_in_start(ctx, sp)) if (js_for_in_start(ctx, sp))
goto exception; goto exception;
BREAK; BREAK;
CASE(OP_for_in_next): CASE(OP_for_in_next):
sf->cur_pc = pc;
if (js_for_in_next(ctx, sp)) if (js_for_in_next(ctx, sp))
goto exception; goto exception;
sp += 2; sp += 2;
BREAK; BREAK;
CASE(OP_for_of_start): CASE(OP_for_of_start):
sf->cur_pc = pc;
if (js_for_of_start(ctx, sp, FALSE)) if (js_for_of_start(ctx, sp, FALSE))
goto exception; goto exception;
sp += 1; sp += 1;
@ -15734,18 +15743,21 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{ {
int offset = -3 - pc[0]; int offset = -3 - pc[0];
pc += 1; pc += 1;
sf->cur_pc = pc;
if (js_for_of_next(ctx, sp, offset)) if (js_for_of_next(ctx, sp, offset))
goto exception; goto exception;
sp += 2; sp += 2;
} }
BREAK; BREAK;
CASE(OP_for_await_of_start): CASE(OP_for_await_of_start):
sf->cur_pc = pc;
if (js_for_of_start(ctx, sp, TRUE)) if (js_for_of_start(ctx, sp, TRUE))
goto exception; goto exception;
sp += 1; sp += 1;
*sp++ = JS_NewCatchOffset(ctx, 0); *sp++ = JS_NewCatchOffset(ctx, 0);
BREAK; BREAK;
CASE(OP_iterator_get_value_done): CASE(OP_iterator_get_value_done):
sf->cur_pc = pc;
if (js_iterator_get_value_done(ctx, sp)) if (js_iterator_get_value_done(ctx, sp))
goto exception; goto exception;
sp += 1; sp += 1;
@ -15763,6 +15775,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JS_FreeValue(ctx, sp[-1]); /* drop the next method */ JS_FreeValue(ctx, sp[-1]); /* drop the next method */
sp--; sp--;
if (!JS_IsUndefined(sp[-1])) { if (!JS_IsUndefined(sp[-1])) {
sf->cur_pc = pc;
if (JS_IteratorClose(ctx, sp[-1], FALSE)) if (JS_IteratorClose(ctx, sp[-1], FALSE))
goto exception; goto exception;
JS_FreeValue(ctx, sp[-1]); JS_FreeValue(ctx, sp[-1]);
@ -15791,8 +15804,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
/* stack: iter_obj next catch_offset val */ /* stack: iter_obj next catch_offset val */
{ {
JSValue ret; JSValue ret;
ret = JS_Call(ctx, sp[-3], sp[-4], sf->cur_pc = pc;
1, (sp - 1)); ret = JS_Call(ctx, sp[-3], sp[-4], 1, (sp - 1));
if (JS_IsException(ret)) if (JS_IsException(ret))
goto exception; goto exception;
JS_FreeValue(ctx, sp[-1]); JS_FreeValue(ctx, sp[-1]);
@ -15807,6 +15820,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BOOL ret_flag; BOOL ret_flag;
int flags; int flags;
flags = *pc++; flags = *pc++;
sf->cur_pc = pc;
method = JS_GetProperty(ctx, sp[-4], (flags & 1) ? method = JS_GetProperty(ctx, sp[-4], (flags & 1) ?
JS_ATOM_throw : JS_ATOM_return); JS_ATOM_throw : JS_ATOM_return);
if (JS_IsException(method)) if (JS_IsException(method))
@ -15982,7 +15996,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_get_private_field): CASE(OP_get_private_field):
{ {
JSValue val; JSValue val;
sf->cur_pc = pc;
val = JS_GetPrivateField(ctx, sp[-2], sp[-1]); val = JS_GetPrivateField(ctx, sp[-2], sp[-1]);
JS_FreeValue(ctx, sp[-1]); JS_FreeValue(ctx, sp[-1]);
JS_FreeValue(ctx, sp[-2]); JS_FreeValue(ctx, sp[-2]);
@ -15996,6 +16010,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_put_private_field): CASE(OP_put_private_field):
{ {
int ret; int ret;
sf->cur_pc = pc;
ret = JS_SetPrivateField(ctx, sp[-3], sp[-1], sp[-2]); ret = JS_SetPrivateField(ctx, sp[-3], sp[-1], sp[-2]);
JS_FreeValue(ctx, sp[-3]); JS_FreeValue(ctx, sp[-3]);
JS_FreeValue(ctx, sp[-1]); JS_FreeValue(ctx, sp[-1]);
@ -16146,6 +16161,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{ {
JSValue val; JSValue val;
sf->cur_pc = pc;
val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]); val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]);
JS_FreeValue(ctx, sp[-2]); JS_FreeValue(ctx, sp[-2]);
sp[-2] = val; sp[-2] = val;
@ -16159,6 +16175,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{ {
JSValue val; JSValue val;
sf->cur_pc = pc;
val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]); val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]);
sp[-1] = val; sp[-1] = val;
if (unlikely(JS_IsException(val))) if (unlikely(JS_IsException(val)))
@ -16169,6 +16186,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_get_ref_value): CASE(OP_get_ref_value):
{ {
JSValue val; JSValue val;
sf->cur_pc = pc;
if (unlikely(JS_IsUndefined(sp[-2]))) { if (unlikely(JS_IsUndefined(sp[-2]))) {
JSAtom atom = JS_ValueToAtom(ctx, sp[-1]); JSAtom atom = JS_ValueToAtom(ctx, sp[-1]);
if (atom != JS_ATOM_NULL) { if (atom != JS_ATOM_NULL) {
@ -16190,6 +16208,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{ {
JSValue val; JSValue val;
JSAtom atom; JSAtom atom;
sf->cur_pc = pc;
atom = JS_ValueToAtom(ctx, sp[-1]); atom = JS_ValueToAtom(ctx, sp[-1]);
if (unlikely(atom == JS_ATOM_NULL)) if (unlikely(atom == JS_ATOM_NULL))
goto exception; goto exception;
@ -16208,7 +16227,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_put_array_el): CASE(OP_put_array_el):
{ {
int ret; int ret;
sf->cur_pc = pc;
ret = JS_SetPropertyValue(ctx, sp[-3], sp[-2], sp[-1], JS_PROP_THROW_STRICT); ret = JS_SetPropertyValue(ctx, sp[-3], sp[-2], sp[-1], JS_PROP_THROW_STRICT);
JS_FreeValue(ctx, sp[-3]); JS_FreeValue(ctx, sp[-3]);
sp -= 3; sp -= 3;
@ -16220,6 +16239,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_put_ref_value): CASE(OP_put_ref_value):
{ {
int ret, flags; int ret, flags;
sf->cur_pc = pc;
flags = JS_PROP_THROW_STRICT; flags = JS_PROP_THROW_STRICT;
if (unlikely(JS_IsUndefined(sp[-3]))) { if (unlikely(JS_IsUndefined(sp[-3]))) {
if (is_strict_mode(ctx)) { if (is_strict_mode(ctx)) {
@ -16248,6 +16268,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
{ {
int ret; int ret;
JSAtom atom; JSAtom atom;
sf->cur_pc = pc;
if (JS_VALUE_GET_TAG(sp[-3]) != JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG(sp[-3]) != JS_TAG_OBJECT) {
JS_ThrowTypeErrorNotAnObject(ctx); JS_ThrowTypeErrorNotAnObject(ctx);
goto exception; goto exception;
@ -16282,6 +16303,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_append): /* array pos enumobj -- array pos */ CASE(OP_append): /* array pos enumobj -- array pos */
{ {
sf->cur_pc = pc;
if (js_append_enumerate(ctx, sp)) if (js_append_enumerate(ctx, sp))
goto exception; goto exception;
JS_FreeValue(ctx, *--sp); JS_FreeValue(ctx, *--sp);
@ -16297,6 +16319,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
int mask; int mask;
mask = *pc++; mask = *pc++;
sf->cur_pc = pc;
if (JS_CopyDataProperties(ctx, sp[-1 - (mask & 3)], if (JS_CopyDataProperties(ctx, sp[-1 - (mask & 3)],
sp[-1 - ((mask >> 2) & 7)], sp[-1 - ((mask >> 2) & 7)],
sp[-1 - ((mask >> 5) & 7)], 0)) sp[-1 - ((mask >> 5) & 7)], 0))
@ -16309,7 +16332,6 @@ 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);
@ -16323,6 +16345,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp--; sp--;
} else { } else {
add_slow: add_slow:
sf->cur_pc = pc;
if (js_add_slow(ctx, sp)) if (js_add_slow(ctx, sp))
goto exception; goto exception;
sp--; sp--;
@ -16335,7 +16358,6 @@ 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]))) {
@ -16350,6 +16372,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JSValue op1; JSValue op1;
op1 = sp[-1]; op1 = sp[-1];
sp--; sp--;
sf->cur_pc = pc;
op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE); op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE);
if (JS_IsException(op1)) if (JS_IsException(op1))
goto exception; goto exception;
@ -16362,6 +16385,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
add_loc_slow: add_loc_slow:
/* In case of exception, js_add_slow frees ops[0] /* In case of exception, js_add_slow frees ops[0]
and ops[1], so we must duplicate *pv */ and ops[1], so we must duplicate *pv */
sf->cur_pc = pc;
ops[0] = js_dup(*pv); ops[0] = js_dup(*pv);
ops[1] = sp[-1]; ops[1] = sp[-1];
sp--; sp--;
@ -16464,6 +16488,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK; BREAK;
CASE(OP_pow): CASE(OP_pow):
binary_arith_slow: binary_arith_slow:
sf->cur_pc = pc;
if (js_binary_arith_slow(ctx, sp, opcode)) if (js_binary_arith_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16477,6 +16502,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
tag = JS_VALUE_GET_TAG(op1); tag = JS_VALUE_GET_TAG(op1);
if (tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)) { if (tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)) {
} else { } else {
sf->cur_pc = pc;
if (js_unary_arith_slow(ctx, sp, opcode)) if (js_unary_arith_slow(ctx, sp, opcode))
goto exception; goto exception;
} }
@ -16507,6 +16533,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
neg_fp_res: neg_fp_res:
sp[-1] = js_float64(d); sp[-1] = js_float64(d);
} else { } else {
sf->cur_pc = pc;
if (js_unary_arith_slow(ctx, sp, opcode)) if (js_unary_arith_slow(ctx, sp, opcode))
goto exception; goto exception;
} }
@ -16524,6 +16551,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-1] = js_int32(val + 1); sp[-1] = js_int32(val + 1);
} else { } else {
inc_slow: inc_slow:
sf->cur_pc = pc;
if (js_unary_arith_slow(ctx, sp, opcode)) if (js_unary_arith_slow(ctx, sp, opcode))
goto exception; goto exception;
} }
@ -16541,6 +16569,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-1] = js_int32(val - 1); sp[-1] = js_int32(val - 1);
} else { } else {
dec_slow: dec_slow:
sf->cur_pc = pc;
if (js_unary_arith_slow(ctx, sp, opcode)) if (js_unary_arith_slow(ctx, sp, opcode))
goto exception; goto exception;
} }
@ -16548,6 +16577,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK; BREAK;
CASE(OP_post_inc): CASE(OP_post_inc):
CASE(OP_post_dec): CASE(OP_post_dec):
sf->cur_pc = pc;
if (js_post_inc_slow(ctx, sp, opcode)) if (js_post_inc_slow(ctx, sp, opcode))
goto exception; goto exception;
sp++; sp++;
@ -16568,6 +16598,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
var_buf[idx] = js_int32(val + 1); var_buf[idx] = js_int32(val + 1);
} else { } else {
inc_loc_slow: inc_loc_slow:
sf->cur_pc = pc;
/* must duplicate otherwise the variable value may /* must duplicate otherwise the variable value may
be destroyed before JS code accesses it */ be destroyed before JS code accesses it */
op1 = js_dup(op1); op1 = js_dup(op1);
@ -16593,6 +16624,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
var_buf[idx] = js_int32(val - 1); var_buf[idx] = js_int32(val - 1);
} else { } else {
dec_loc_slow: dec_loc_slow:
sf->cur_pc = pc;
/* must duplicate otherwise the variable value may /* must duplicate otherwise the variable value may
be destroyed before JS code accesses it */ be destroyed before JS code accesses it */
op1 = js_dup(op1); op1 = js_dup(op1);
@ -16609,6 +16641,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) { if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {
sp[-1] = js_int32(~JS_VALUE_GET_INT(op1)); sp[-1] = js_int32(~JS_VALUE_GET_INT(op1));
} else { } else {
sf->cur_pc = pc;
if (js_not_slow(ctx, sp)) if (js_not_slow(ctx, sp))
goto exception; goto exception;
} }
@ -16627,6 +16660,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_int32(v1 << v2); sp[-2] = js_int32(v1 << v2);
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_binary_logic_slow(ctx, sp, opcode)) if (js_binary_logic_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16645,6 +16679,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_uint32((uint32_t)JS_VALUE_GET_INT(op1) >> v2); sp[-2] = js_uint32((uint32_t)JS_VALUE_GET_INT(op1) >> v2);
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_shr_slow(ctx, sp)) if (js_shr_slow(ctx, sp))
goto exception; goto exception;
sp--; sp--;
@ -16665,6 +16700,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_int32((int)JS_VALUE_GET_INT(op1) >> v2); sp[-2] = js_int32((int)JS_VALUE_GET_INT(op1) >> v2);
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_binary_logic_slow(ctx, sp, opcode)) if (js_binary_logic_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16680,6 +16716,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_int32(JS_VALUE_GET_INT(op1) & JS_VALUE_GET_INT(op2)); sp[-2] = js_int32(JS_VALUE_GET_INT(op1) & JS_VALUE_GET_INT(op2));
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_binary_logic_slow(ctx, sp, opcode)) if (js_binary_logic_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16695,6 +16732,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_int32(JS_VALUE_GET_INT(op1) | JS_VALUE_GET_INT(op2)); sp[-2] = js_int32(JS_VALUE_GET_INT(op1) | JS_VALUE_GET_INT(op2));
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_binary_logic_slow(ctx, sp, opcode)) if (js_binary_logic_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16710,6 +16748,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_int32(JS_VALUE_GET_INT(op1) ^ JS_VALUE_GET_INT(op2)); sp[-2] = js_int32(JS_VALUE_GET_INT(op1) ^ JS_VALUE_GET_INT(op2));
sp--; sp--;
} else { } else {
sf->cur_pc = pc;
if (js_binary_logic_slow(ctx, sp, opcode)) if (js_binary_logic_slow(ctx, sp, opcode))
goto exception; goto exception;
sp--; sp--;
@ -16728,6 +16767,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
sp[-2] = js_bool(JS_VALUE_GET_INT(op1) binary_op JS_VALUE_GET_INT(op2)); \ sp[-2] = js_bool(JS_VALUE_GET_INT(op1) binary_op JS_VALUE_GET_INT(op2)); \
sp--; \ sp--; \
} else { \ } else { \
sf->cur_pc = pc; \
if (slow_call) \ if (slow_call) \
goto exception; \ goto exception; \
sp--; \ sp--; \
@ -16780,6 +16820,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
atom = get_u32(pc); atom = get_u32(pc);
pc += 4; pc += 4;
sf->cur_pc = pc;
ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0); ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0);
if (unlikely(ret < 0)) if (unlikely(ret < 0))
goto exception; goto exception;
@ -16789,6 +16830,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
CASE(OP_to_object): CASE(OP_to_object):
if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_OBJECT) { if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_OBJECT) {
sf->cur_pc = pc;
ret_val = JS_ToObject(ctx, sp[-1]); ret_val = JS_ToObject(ctx, sp[-1]);
if (JS_IsException(ret_val)) if (JS_IsException(ret_val))
goto exception; goto exception;
@ -16804,6 +16846,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
case JS_TAG_SYMBOL: case JS_TAG_SYMBOL:
break; break;
default: default:
sf->cur_pc = pc;
ret_val = JS_ToPropertyKey(ctx, sp[-1]); ret_val = JS_ToPropertyKey(ctx, sp[-1]);
if (JS_IsException(ret_val)) if (JS_IsException(ret_val))
goto exception; goto exception;
@ -16825,6 +16868,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
case JS_TAG_SYMBOL: case JS_TAG_SYMBOL:
break; break;
default: default:
sf->cur_pc = pc;
ret_val = JS_ToPropertyKey(ctx, sp[-1]); ret_val = JS_ToPropertyKey(ctx, sp[-1]);
if (JS_IsException(ret_val)) if (JS_IsException(ret_val))
goto exception; goto exception;
@ -16848,6 +16892,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
diff = get_u32(pc + 4); diff = get_u32(pc + 4);
is_with = pc[8]; is_with = pc[8];
pc += 9; pc += 9;
sf->cur_pc = pc;
obj = sp[-1]; obj = sp[-1];
ret = JS_HasProperty(ctx, obj, atom); ret = JS_HasProperty(ctx, obj, atom);
@ -38833,8 +38878,10 @@ static JSValue js_number_toFixed(JSContext *ctx, JSValue this_val,
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToInt32Sat(ctx, &f, argv[0])) if (JS_ToInt32Sat(ctx, &f, argv[0]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (f < 0 || f > 100) if (f < 0 || f > 100) {
return JS_ThrowRangeError(ctx, "invalid number of digits"); return JS_ThrowRangeError(ctx, "%s() argument must be between 1 and 100",
"toFixed");
}
if (fabs(d) >= 1e21) { if (fabs(d) >= 1e21) {
return JS_ToStringFree(ctx, js_float64(d)); return JS_ToStringFree(ctx, js_float64(d));
} else { } else {
@ -38863,8 +38910,10 @@ static JSValue js_number_toExponential(JSContext *ctx, JSValue this_val,
flags = 0; flags = 0;
f = 0; f = 0;
} else { } else {
if (f < 0 || f > 100) if (f < 0 || f > 100) {
return JS_ThrowRangeError(ctx, "invalid number of digits"); return JS_ThrowRangeError(ctx, "%s() argument must be between 1 and 100",
"toExponential");
}
f++; f++;
flags = JS_DTOA_FIXED_FORMAT; flags = JS_DTOA_FIXED_FORMAT;
} }
@ -38891,8 +38940,10 @@ static JSValue js_number_toPrecision(JSContext *ctx, JSValue this_val,
to_string: to_string:
return JS_ToStringFree(ctx, js_float64(d)); return JS_ToStringFree(ctx, js_float64(d));
} }
if (p < 1 || p > 100) if (p < 1 || p > 100) {
return JS_ThrowRangeError(ctx, "invalid number of digits"); return JS_ThrowRangeError(ctx, "%s() argument must be between 1 and 100",
"toPrecision");
}
return js_dtoa(ctx, d, 10, p, JS_DTOA_FIXED_FORMAT); return js_dtoa(ctx, d, 10, p, JS_DTOA_FIXED_FORMAT);
} }

View file

@ -966,6 +966,54 @@ function test_proxy_is_array()
} }
} }
function test_cur_pc()
{
var a = [];
Object.defineProperty(a, '1', {
get: function() { throw Error("a[1]_get"); },
set: function(x) { throw Error("a[1]_set"); }
});
assert_throws(Error, function() { return a[1]; });
assert_throws(Error, function() { a[1] = 1; });
assert_throws(Error, function() { return [...a]; });
assert_throws(Error, function() { return ({...b} = a); });
var o = {};
Object.defineProperty(o, 'x', {
get: function() { throw Error("o.x_get"); },
set: function(x) { throw Error("o.x_set"); }
});
o.valueOf = function() { throw Error("o.valueOf"); };
assert_throws(Error, function() { return +o; });
assert_throws(Error, function() { return -o; });
assert_throws(Error, function() { return o+1; });
assert_throws(Error, function() { return o-1; });
assert_throws(Error, function() { return o*1; });
assert_throws(Error, function() { return o/1; });
assert_throws(Error, function() { return o%1; });
assert_throws(Error, function() { return o**1; });
assert_throws(Error, function() { return o<<1; });
assert_throws(Error, function() { return o>>1; });
assert_throws(Error, function() { return o>>>1; });
assert_throws(Error, function() { return o&1; });
assert_throws(Error, function() { return o|1; });
assert_throws(Error, function() { return o^1; });
assert_throws(Error, function() { return o<1; });
assert_throws(Error, function() { return o==1; });
assert_throws(Error, function() { return o++; });
assert_throws(Error, function() { return o--; });
assert_throws(Error, function() { return ++o; });
assert_throws(Error, function() { return --o; });
assert_throws(Error, function() { return ~o; });
Object.defineProperty(globalThis, 'xxx', {
get: function() { throw Error("xxx_get"); },
set: function(x) { throw Error("xxx_set"); }
});
assert_throws(Error, function() { return xxx; });
assert_throws(Error, function() { xxx = 1; });
}
test(); test();
test_function(); test_function();
test_enum(); test_enum();
@ -989,3 +1037,4 @@ test_exception_source_pos();
test_function_source_pos(); test_function_source_pos();
test_exception_prepare_stack(); test_exception_prepare_stack();
test_exception_stack_size_limit(); test_exception_stack_size_limit();
test_cur_pc();

6
v8.txt
View file

@ -762,6 +762,12 @@ 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