From 9728b73616aec9802d0195810526575afc50a54f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Nov 2023 12:36:40 +0100 Subject: [PATCH 1/5] Replace JS_NewInt32() calls with js_int32() --- quickjs.c | 277 ++++++++++++++++++++++++++---------------------------- 1 file changed, 135 insertions(+), 142 deletions(-) diff --git a/quickjs.c b/quickjs.c index 1650f495e..27a00b06e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -3061,7 +3061,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) JSValue num, str; if (__JS_AtomIsTaggedInt(atom)) - return JS_NewInt32(ctx, __JS_AtomToUInt32(atom)); + return js_int32(__JS_AtomToUInt32(atom)); assert(atom < rt->atom_size); p1 = rt->atom_array[atom]; if (p1->atom_type != JS_ATOM_TYPE_STRING) @@ -4661,7 +4661,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas pr = add_property(ctx, p, JS_ATOM_length, JS_PROP_WRITABLE | JS_PROP_LENGTH); } - pr->u.value = JS_NewInt32(ctx, 0); + pr->u.value = js_int32(0); } break; case JS_CLASS_C_FUNCTION: @@ -4789,7 +4789,7 @@ static void js_function_set_properties(JSContext *ctx, JSValueConst func_obj, JSAtom name, int len) { /* ES6 feature non compatible with ES5.1: length is configurable */ - JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length, JS_NewInt32(ctx, len), + JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length, js_int32(len), JS_PROP_CONFIGURABLE); JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_name, JS_AtomToString(ctx, name), JS_PROP_CONFIGURABLE); @@ -6353,7 +6353,7 @@ static void build_backtrace(JSContext *ctx, JSValueConst error_obj, str = JS_NewString(ctx, filename); JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_fileName, str, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); - JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_lineNumber, JS_NewInt32(ctx, line_num), + JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_lineNumber, js_int32(line_num), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); if (backtrace_flags & JS_BACKTRACE_FLAG_SINGLE_LEVEL) goto done; @@ -6959,7 +6959,7 @@ JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValueConst obj, return js_new_string_char(ctx, ch); } } else if (prop == JS_ATOM_length) { - return JS_NewInt32(ctx, p1->len); + return js_int32(p1->len); } } break; @@ -7750,20 +7750,20 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, return JS_DupValue(ctx, p->u.array.u.values[idx]); case JS_CLASS_INT8_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewInt32(ctx, p->u.array.u.int8_ptr[idx]); + return js_int32(p->u.array.u.int8_ptr[idx]); case JS_CLASS_UINT8C_ARRAY: case JS_CLASS_UINT8_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewInt32(ctx, p->u.array.u.uint8_ptr[idx]); + return js_int32(p->u.array.u.uint8_ptr[idx]); case JS_CLASS_INT16_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewInt32(ctx, p->u.array.u.int16_ptr[idx]); + return js_int32(p->u.array.u.int16_ptr[idx]); case JS_CLASS_UINT16_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewInt32(ctx, p->u.array.u.uint16_ptr[idx]); + return js_int32(p->u.array.u.uint16_ptr[idx]); case JS_CLASS_INT32_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewInt32(ctx, p->u.array.u.int32_ptr[idx]); + return js_int32(p->u.array.u.int32_ptr[idx]); case JS_CLASS_UINT32_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]); @@ -7815,7 +7815,7 @@ static int JS_TryGetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, /* fast path */ present = JS_HasProperty(ctx, obj, __JS_AtomFromUInt32(idx)); if (present > 0) { - val = JS_GetPropertyValue(ctx, obj, JS_NewInt32(ctx, idx)); + val = JS_GetPropertyValue(ctx, obj, js_int32(idx)); if (unlikely(JS_IsException(val))) present = -1; } @@ -7843,7 +7843,7 @@ static JSValue JS_GetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx if ((uint64_t)idx <= INT32_MAX) { /* fast path for fast arrays */ - return JS_GetPropertyValue(ctx, obj, JS_NewInt32(ctx, idx)); + return JS_GetPropertyValue(ctx, obj, js_int32(idx)); } prop = JS_NewAtomInt64(ctx, idx); if (prop == JS_ATOM_NULL) @@ -8181,7 +8181,7 @@ static int add_fast_array_element(JSContext *ctx, JSObject *p, JS_FreeValue(ctx, val); return JS_ThrowTypeErrorReadOnly(ctx, flags, JS_ATOM_length); } - p->prop[0].u.value = JS_NewInt32(ctx, new_len); + p->prop[0].u.value = js_int32(new_len); } } if (unlikely(new_len > p->u.array.u1.size)) { @@ -8389,7 +8389,7 @@ int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst this_obj, uint32_t idx = __JS_AtomToUInt32(prop); if (idx < p1->u.array.count) { if (unlikely(p == p1)) - return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), val, flags); + return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), val, flags); else break; } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY && @@ -8706,7 +8706,7 @@ int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj, if ((uint64_t)idx <= INT32_MAX) { /* fast path for fast arrays */ - return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), val, + return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), val, JS_PROP_THROW); } prop = JS_NewAtomInt64(ctx, idx); @@ -9192,7 +9192,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, return JS_ThrowTypeErrorOrFalse(ctx, flags, "invalid descriptor flags"); } if (flags & JS_PROP_HAS_VALUE) { - return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), JS_DupValue(ctx, val), flags); + return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), JS_DupValue(ctx, val), flags); } return TRUE; typed_array_done: ; @@ -10228,7 +10228,7 @@ static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val, break; case JS_TAG_BOOL: case JS_TAG_NULL: - ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val)); + ret = js_int32(JS_VALUE_GET_INT(val)); break; case JS_TAG_UNDEFINED: ret = JS_NAN; @@ -10251,7 +10251,7 @@ static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val, p = str; p += skip_spaces(p); if ((p - str) == len) { - ret = JS_NewInt32(ctx, 0); + ret = js_int32(0); } else { int flags = ATOD_ACCEPT_BIN_OCT; ret = js_atof(ctx, p, &p, 0, flags); @@ -10367,13 +10367,13 @@ static __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val) case JS_TAG_BOOL: case JS_TAG_NULL: case JS_TAG_UNDEFINED: - ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val)); + ret = js_int32(JS_VALUE_GET_INT(val)); break; case JS_TAG_FLOAT64: { double d = JS_VALUE_GET_FLOAT64(val); if (isnan(d)) { - ret = JS_NewInt32(ctx, 0); + ret = js_int32(0); } else { /* convert -0 to +0 */ d = trunc(d) + 0.0; @@ -12035,7 +12035,7 @@ static no_inline int js_not_slow(JSContext *ctx, JSValue *sp) int32_t v1; if (unlikely(JS_ToInt32Free(ctx, &v1, op1))) goto exception; - sp[-1] = JS_NewInt32(ctx, ~v1); + sp[-1] = js_int32(~v1); } return 0; exception: @@ -12396,7 +12396,7 @@ static no_inline __exception int js_binary_logic_slow(JSContext *ctx, default: abort(); } - sp[-2] = JS_NewInt32(ctx, r); + sp[-2] = js_int32(r); } return 0; exception: @@ -12661,10 +12661,10 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp, } res = js_strict_eq(ctx, op1, op2); } else if (tag1 == JS_TAG_BOOL) { - op1 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op1)); + op1 = js_int32(JS_VALUE_GET_INT(op1)); goto redo; } else if (tag2 == JS_TAG_BOOL) { - op2 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op2)); + op2 = js_int32(JS_VALUE_GET_INT(op2)); goto redo; } else if ((tag1 == JS_TAG_OBJECT && (tag_is_number(tag2) || tag2 == JS_TAG_STRING || tag2 == JS_TAG_SYMBOL)) || @@ -13050,7 +13050,7 @@ static JSValue js_function_proto_lineNumber(JSContext *ctx, { JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val); if (b && b->has_debug) { - return JS_NewInt32(ctx, b->debug.line_num); + return js_int32(b->debug.line_num); } return JS_UNDEFINED; } @@ -13094,7 +13094,7 @@ static JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst *argv) /* add the length field (cannot fail) */ pr = add_property(ctx, p, JS_ATOM_length, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); - pr->u.value = JS_NewInt32(ctx, argc); + pr->u.value = js_int32(argc); /* initialize the fast array part */ tab = NULL; @@ -13145,7 +13145,7 @@ static JSValue js_build_mapped_arguments(JSContext *ctx, int argc, /* add the length field (cannot fail) */ pr = add_property(ctx, p, JS_ATOM_length, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); - pr->u.value = JS_NewInt32(ctx, argc); + pr->u.value = js_int32(argc); for(i = 0; i < arg_count; i++) { JSVarRef *var_ref; @@ -13762,7 +13762,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp) } } /* Note: could raise an error if too many elements */ - sp[-2] = JS_NewInt32(ctx, pos); + sp[-2] = js_int32(pos); JS_FreeValue(ctx, enumobj); JS_FreeValue(ctx, method); return 0; @@ -14062,7 +14062,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, JS_SetConstructorBit(ctx, ctor, TRUE); JS_DefinePropertyValue(ctx, ctor, JS_ATOM_length, - JS_NewInt32(ctx, b->defined_arg_count), + js_int32(b->defined_arg_count), JS_PROP_CONFIGURABLE); if (is_computed_name) { @@ -14452,7 +14452,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, SWITCH(pc) { CASE(OP_push_i32): - *sp++ = JS_NewInt32(ctx, get_u32(pc)); + *sp++ = js_int32(get_u32(pc)); pc += 4; BREAK; CASE(OP_push_const): @@ -14468,14 +14468,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_push_5): CASE(OP_push_6): CASE(OP_push_7): - *sp++ = JS_NewInt32(ctx, opcode - OP_push_0); + *sp++ = js_int32(opcode - OP_push_0); BREAK; CASE(OP_push_i8): - *sp++ = JS_NewInt32(ctx, get_i8(pc)); + *sp++ = js_int32(get_i8(pc)); pc += 1; BREAK; CASE(OP_push_i16): - *sp++ = JS_NewInt32(ctx, get_i16(pc)); + *sp++ = js_int32(get_i16(pc)); pc += 2; BREAK; CASE(OP_push_const8): @@ -15500,7 +15500,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int32_t diff; diff = get_u32(pc); /* XXX: should have a different tag to avoid security flaw */ - sp[0] = JS_NewInt32(ctx, pc + 4 - b->byte_code_buf); + sp[0] = js_int32(pc + 4 - b->byte_code_buf); sp++; pc += diff; } @@ -16116,7 +16116,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, r = (int64_t)JS_VALUE_GET_INT(op1) + JS_VALUE_GET_INT(op2); if (unlikely((int)r != r)) goto add_slow; - sp[-2] = JS_NewInt32(ctx, r); + sp[-2] = js_int32(r); sp--; } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) + @@ -16144,7 +16144,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_VALUE_GET_INT(sp[-1]); if (unlikely((int)r != r)) goto add_loc_slow; - *pv = JS_NewInt32(ctx, r); + *pv = js_int32(r); sp--; } else if (JS_VALUE_GET_TAG(*pv) == JS_TAG_STRING) { JSValue op1; @@ -16181,7 +16181,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, r = (int64_t)JS_VALUE_GET_INT(op1) - JS_VALUE_GET_INT(op2); if (unlikely((int)r != r)) goto binary_arith_slow; - sp[-2] = JS_NewInt32(ctx, r); + sp[-2] = js_int32(r); sp--; } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) - @@ -16213,7 +16213,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, d = -0.0; goto mul_fp_res; } - sp[-2] = JS_NewInt32(ctx, r); + sp[-2] = js_int32(r); sp--; } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { d = JS_VALUE_GET_FLOAT64(op1) * JS_VALUE_GET_FLOAT64(op2); @@ -16255,7 +16255,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (unlikely(v1 < 0 || v2 <= 0)) goto binary_arith_slow; r = v1 % v2; - sp[-2] = JS_NewInt32(ctx, r); + sp[-2] = js_int32(r); sp--; } else { goto binary_arith_slow; @@ -16301,7 +16301,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, d = -(double)val; goto neg_fp_res; } - sp[-1] = JS_NewInt32(ctx, -val); + sp[-1] = js_int32(-val); } else if (JS_TAG_IS_FLOAT64(tag)) { d = -JS_VALUE_GET_FLOAT64(op1); neg_fp_res: @@ -16321,7 +16321,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, val = JS_VALUE_GET_INT(op1); if (unlikely(val == INT32_MAX)) goto inc_slow; - sp[-1] = JS_NewInt32(ctx, val + 1); + sp[-1] = js_int32(val + 1); } else { inc_slow: if (js_unary_arith_slow(ctx, sp, opcode)) @@ -16338,7 +16338,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, val = JS_VALUE_GET_INT(op1); if (unlikely(val == INT32_MIN)) goto dec_slow; - sp[-1] = JS_NewInt32(ctx, val - 1); + sp[-1] = js_int32(val - 1); } else { dec_slow: if (js_unary_arith_slow(ctx, sp, opcode)) @@ -16365,7 +16365,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, val = JS_VALUE_GET_INT(op1); if (unlikely(val == INT32_MAX)) goto inc_loc_slow; - var_buf[idx] = JS_NewInt32(ctx, val + 1); + var_buf[idx] = js_int32(val + 1); } else { inc_loc_slow: /* must duplicate otherwise the variable value may @@ -16390,7 +16390,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, val = JS_VALUE_GET_INT(op1); if (unlikely(val == INT32_MIN)) goto dec_loc_slow; - var_buf[idx] = JS_NewInt32(ctx, val - 1); + var_buf[idx] = js_int32(val - 1); } else { dec_loc_slow: /* must duplicate otherwise the variable value may @@ -16407,7 +16407,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValue op1; op1 = sp[-1]; if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) { - sp[-1] = JS_NewInt32(ctx, ~JS_VALUE_GET_INT(op1)); + sp[-1] = js_int32(~JS_VALUE_GET_INT(op1)); } else { if (js_not_slow(ctx, sp)) goto exception; @@ -16424,7 +16424,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, uint32_t v1, v2; v1 = JS_VALUE_GET_INT(op1); v2 = JS_VALUE_GET_INT(op2) & 0x1f; - sp[-2] = JS_NewInt32(ctx, v1 << v2); + sp[-2] = js_int32(v1 << v2); sp--; } else { if (js_binary_logic_slow(ctx, sp, opcode)) @@ -16464,8 +16464,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (unlikely(v2 > 0x1f)) { v2 &= 0x1f; } - sp[-2] = JS_NewInt32(ctx, - (int)JS_VALUE_GET_INT(op1) >> v2); + sp[-2] = js_int32((int)JS_VALUE_GET_INT(op1) >> v2); sp--; } else { if (js_binary_logic_slow(ctx, sp, opcode)) @@ -16480,9 +16479,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-2]; op2 = sp[-1]; if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) { - sp[-2] = JS_NewInt32(ctx, - 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--; } else { if (js_binary_logic_slow(ctx, sp, opcode)) @@ -16497,9 +16494,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-2]; op2 = sp[-1]; if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) { - sp[-2] = JS_NewInt32(ctx, - 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--; } else { if (js_binary_logic_slow(ctx, sp, opcode)) @@ -16514,9 +16509,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-2]; op2 = sp[-1]; if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) { - sp[-2] = JS_NewInt32(ctx, - 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--; } else { if (js_binary_logic_slow(ctx, sp, opcode)) @@ -16723,14 +16716,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, BREAK; CASE(OP_await): - ret_val = JS_NewInt32(ctx, FUNC_RET_AWAIT); + ret_val = js_int32(FUNC_RET_AWAIT); goto done_generator; CASE(OP_yield): - ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD); + ret_val = js_int32(FUNC_RET_YIELD); goto done_generator; CASE(OP_yield_star): CASE(OP_async_yield_star): - ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD_STAR); + ret_val = js_int32(FUNC_RET_YIELD_STAR); goto done_generator; CASE(OP_return_async): CASE(OP_initial_yield): @@ -17190,7 +17183,7 @@ static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val, s->func_state.throw_flag = TRUE; } else { sf->cur_sp[-1] = ret; - sf->cur_sp[0] = JS_NewInt32(ctx, magic); + sf->cur_sp[0] = js_int32(magic); sf->cur_sp++; exec_no_arg: s->func_state.throw_flag = FALSE; @@ -17737,7 +17730,7 @@ static void js_async_generator_resume_next(JSContext *ctx, in case the 'throw' method is called */ s->func_state.frame.cur_sp[-1] = value; s->func_state.frame.cur_sp[0] = - JS_NewInt32(ctx, next->completion_type); + js_int32(next->completion_type); s->func_state.frame.cur_sp++; exec_no_arg: s->func_state.throw_flag = FALSE; @@ -33696,7 +33689,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) if (bc_get_sleb128(s, &val)) return JS_EXCEPTION; bc_read_trace(s, "%d\n", val); - obj = JS_NewInt32(ctx, val); + obj = js_int32(val); } break; case BC_TAG_FLOAT64: @@ -34005,7 +33998,7 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj, } break; case JS_DEF_PROP_INT32: - val = JS_NewInt32(ctx, e->u.i32); + val = js_int32(e->u.i32); break; case JS_DEF_PROP_INT64: val = JS_NewInt64(ctx, e->u.i64); @@ -34069,7 +34062,7 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, val = JS_NewString(ctx, e->u.str); break; case JS_DEF_PROP_INT32: - val = JS_NewInt32(ctx, e->u.i32); + val = js_int32(e->u.i32); break; case JS_DEF_PROP_INT64: val = JS_NewInt64(ctx, e->u.i64); @@ -34214,7 +34207,7 @@ static JSValue JS_ToObject(JSContext *ctx, JSValueConst val) { JSString *p1 = JS_VALUE_GET_STRING(val); obj = JS_NewObjectClass(ctx, JS_CLASS_STRING); - JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, JS_NewInt32(ctx, p1->len), 0); + JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, js_int32(p1->len), 0); } goto set_value; case JS_TAG_BOOL: @@ -35659,7 +35652,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, if (ret < 0) goto exception; if (!ret) { - len_val = JS_NewInt32(ctx, 0); + len_val = js_int32(0); } else { len_val = JS_GetProperty(ctx, this_val, JS_ATOM_length); if (JS_IsException(len_val)) @@ -35671,7 +35664,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, len1 = 0; else len1 -= arg_count; - len_val = JS_NewInt32(ctx, len1); + len_val = js_int32(len1); } else if (JS_VALUE_GET_NORM_TAG(len_val) == JS_TAG_FLOAT64) { double d = JS_VALUE_GET_FLOAT64(len_val); if (isnan(d)) { @@ -35686,7 +35679,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, len_val = JS_NewFloat64(ctx, d); } else { JS_FreeValue(ctx, len_val); - len_val = JS_NewInt32(ctx, 0); + len_val = js_int32(0); } } JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length, @@ -36095,7 +36088,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, break; if (mapping) { args[0] = v; - args[1] = JS_NewInt32(ctx, k); + args[1] = js_int32(k); v2 = JS_Call(ctx, mapfn, this_arg, 2, args); JS_FreeValue(ctx, v); v = v2; @@ -36128,7 +36121,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, goto exception; if (mapping) { args[0] = v; - args[1] = JS_NewInt32(ctx, k); + args[1] = js_int32(k); v2 = JS_Call(ctx, mapfn, this_arg, 2, args); JS_FreeValue(ctx, v); v = v2; @@ -36164,7 +36157,7 @@ static JSValue js_array_of(JSContext *ctx, JSValueConst this_val, int i; if (JS_IsConstructor(ctx, this_val)) { - args[0] = JS_NewInt32(ctx, argc); + args[0] = js_int32(argc); obj = JS_CallConstructor(ctx, this_val, 1, (JSValueConst *)args); } else { obj = JS_NewArray(ctx); @@ -36388,7 +36381,7 @@ static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val, if (JS_IsException(obj)) goto exception; - arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0)); + arr = JS_ArraySpeciesCreate(ctx, obj, js_int32(0)); if (JS_IsException(arr)) goto exception; n = 0; @@ -36499,13 +36492,13 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, goto exception; break; case special_filter: - ret = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0)); + ret = JS_ArraySpeciesCreate(ctx, obj, js_int32(0)); if (JS_IsException(ret)) goto exception; break; case special_map | special_TA: args[0] = obj; - args[1] = JS_NewInt32(ctx, len); + args[1] = js_int32(len); ret = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args); if (JS_IsException(ret)) goto exception; @@ -36561,7 +36554,7 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, goto exception; break; case special_map | special_TA: - if (JS_SetPropertyValue(ctx, ret, JS_NewInt32(ctx, k), res, JS_PROP_THROW) < 0) + if (JS_SetPropertyValue(ctx, ret, js_int32(k), res, JS_PROP_THROW) < 0) goto exception; break; case special_filter: @@ -36584,7 +36577,7 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, if (special == (special_filter | special_TA)) { JSValue arr; args[0] = obj; - args[1] = JS_NewInt32(ctx, n); + args[1] = js_int32(n); arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args); if (JS_IsException(arr)) goto exception; @@ -36942,7 +36935,7 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val, } JS_FreeValue(ctx, obj); if (mode == ArrayFindIndex || mode == ArrayFindLastIndex) - return JS_NewInt32(ctx, -1); + return js_int32(-1); else return JS_UNDEFINED; @@ -37582,7 +37575,7 @@ static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val, goto exception; } } - arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0)); + arr = JS_ArraySpeciesCreate(ctx, obj, js_int32(0)); if (JS_IsException(arr)) goto exception; if (JS_FlattenIntoArray(ctx, arr, obj, sourceLen, 0, depthNum, @@ -38035,7 +38028,7 @@ static JSValue js_number_constructor(JSContext *ctx, JSValueConst new_target, { JSValue val, obj; if (argc == 0) { - val = JS_NewInt32(ctx, 0); + val = js_int32(0); } else { val = JS_ToNumeric(ctx, argv[0]); if (JS_IsException(val)) @@ -38474,7 +38467,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target, obj = js_create_from_ctor(ctx, new_target, JS_CLASS_STRING); if (!JS_IsException(obj)) { JS_SetObjectData(ctx, obj, val); - JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, JS_NewInt32(ctx, p1->len), 0); + JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, js_int32(p1->len), 0); } return obj; } else { @@ -38668,7 +38661,7 @@ static JSValue js_string_charCodeAt(JSContext *ctx, JSValueConst this_val, c = p->u.str16[idx]; else c = p->u.str8[idx]; - ret = JS_NewInt32(ctx, c); + ret = js_int32(c); } JS_FreeValue(ctx, val); return ret; @@ -38721,7 +38714,7 @@ static JSValue js_string_codePointAt(JSContext *ctx, JSValueConst this_val, ret = JS_UNDEFINED; } else { c = string_getc(p, &idx); - ret = JS_NewInt32(ctx, c); + ret = js_int32(c); } JS_FreeValue(ctx, val); return ret; @@ -38935,7 +38928,7 @@ static JSValue js_string_indexOf(JSContext *ctx, JSValueConst this_val, } JS_FreeValue(ctx, str); JS_FreeValue(ctx, v); - return JS_NewInt32(ctx, ret); + return js_int32(ret); fail: JS_FreeValue(ctx, str); @@ -39274,13 +39267,13 @@ static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val, } if (functionalReplace) { args[0] = search_str; - args[1] = JS_NewInt32(ctx, pos); + args[1] = js_int32(pos); args[2] = str; repl_str = JS_ToStringFree(ctx, JS_Call(ctx, replaceValue, JS_UNDEFINED, 3, args)); } else { args[0] = search_str; args[1] = str; - args[2] = JS_NewInt32(ctx, pos); + args[2] = js_int32(pos); args[3] = JS_UNDEFINED; args[4] = JS_UNDEFINED; args[5] = replaceValue_str; @@ -40135,7 +40128,7 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val, r1 = min_int(r1, a1); } - return JS_NewInt32(ctx, r1); + return js_int32(r1); } else { if (JS_ToFloat64(ctx, &r, argv[0])) return JS_EXCEPTION; @@ -40239,7 +40232,7 @@ static JSValue js_math_imul(JSContext *ctx, JSValueConst this_val, /* TODO(bnoordhuis) Signed integral narrowing has implementation-defined * behavior but that's a step up from the undefined behavior it replaced. */ - return JS_NewInt32(ctx, (int64_t)a * (int64_t)b); + return js_int32((int64_t)a * (int64_t)b); } static JSValue js_math_clz32(JSContext *ctx, JSValueConst this_val, @@ -40253,7 +40246,7 @@ static JSValue js_math_clz32(JSContext *ctx, JSValueConst this_val, r = 32; else r = clz32(a); - return JS_NewInt32(ctx, r); + return js_int32(r); } /* xorshift* random number generator by Marsaglia */ @@ -40488,7 +40481,7 @@ static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueConst ctor, re = &p->u.regexp; re->pattern = JS_VALUE_GET_STRING(pattern); re->bytecode = JS_VALUE_GET_STRING(bc); - JS_DefinePropertyValue(ctx, obj, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0), + JS_DefinePropertyValue(ctx, obj, JS_ATOM_lastIndex, js_int32(0), JS_PROP_WRITABLE); return obj; } @@ -40634,7 +40627,7 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val, re->pattern = JS_VALUE_GET_STRING(pattern); re->bytecode = JS_VALUE_GET_STRING(bc); if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, - JS_NewInt32(ctx, 0)) < 0) + js_int32(0)) < 0) return JS_EXCEPTION; return JS_DupValue(ctx, this_val); fail: @@ -40872,7 +40865,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, if (rc >= 0) { if (rc == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) { if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, - JS_NewInt32(ctx, 0)) < 0) + js_int32(0)) < 0) goto fail; } } else { @@ -40883,7 +40876,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, int prop_flags; if (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) { if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, - JS_NewInt32(ctx, (capture[1] - str_buf) >> shift)) < 0) + js_int32((capture[1] - str_buf) >> shift)) < 0) goto fail; } obj = JS_NewArray(ctx); @@ -41067,7 +41060,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValueConst this_val, JSValueCon if (ret >= 0) { if (ret == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) { if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, - JS_NewInt32(ctx, 0)) < 0) + js_int32(0)) < 0) goto fail; } } else { @@ -41086,7 +41079,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValueConst this_val, JSValueCon next_src_pos = end; if (!(re_flags & LRE_FLAG_GLOBAL)) { if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, - JS_NewInt32(ctx, end)) < 0) + js_int32(end)) < 0) goto fail; break; } @@ -41183,7 +41176,7 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val, if (fullUnicode < 0) goto exception; - if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0) + if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, js_int32(0)) < 0) goto exception; A = JS_NewArray(ctx); if (JS_IsException(A)) @@ -41519,7 +41512,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, fullUnicode = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_unicode)); if (fullUnicode < 0) goto exception; - if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0) + if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, js_int32(0)) < 0) goto exception; } @@ -41597,7 +41590,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, if (JS_IsException(namedCaptures)) goto exception; if (functionalReplace) { - if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_NewInt32(ctx, position), JS_PROP_C_W_E | JS_PROP_THROW) < 0) + if (JS_DefinePropertyValueInt64(ctx, tab, n++, js_int32(position), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_DupValue(ctx, str), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; @@ -41620,7 +41613,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, } args[0] = matched; args[1] = str; - args[2] = JS_NewInt32(ctx, position); + args[2] = js_int32(position); args[3] = tab; args[4] = namedCaptures1; args[5] = rep_val; @@ -41676,8 +41669,8 @@ static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val, if (JS_IsException(previousLastIndex)) goto exception; - if (!js_same_value(ctx, previousLastIndex, JS_NewInt32(ctx, 0))) { - if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0) { + if (!js_same_value(ctx, previousLastIndex, js_int32(0))) { + if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, js_int32(0)) < 0) { goto exception; } } @@ -41699,7 +41692,7 @@ static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, currentLastIndex); if (JS_IsNull(result)) { - return JS_NewInt32(ctx, -1); + return js_int32(-1); } else { index = JS_GetProperty(ctx, result, JS_ATOM_index); JS_FreeValue(ctx, result); @@ -41779,7 +41772,7 @@ static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_val, goto done; } while (q < size) { - if (JS_SetProperty(ctx, splitter, JS_ATOM_lastIndex, JS_NewInt32(ctx, q)) < 0) + if (JS_SetProperty(ctx, splitter, JS_ATOM_lastIndex, js_int32(q)) < 0) goto exception; JS_FreeValue(ctx, z); z = JS_RegExpExec(ctx, splitter, str); @@ -43937,7 +43930,7 @@ static JSValueConst map_normalize_key(JSContext *ctx, JSValueConst key) uint32_t tag = JS_VALUE_GET_TAG(key); /* convert -0.0 to +0.0 */ if (JS_TAG_IS_FLOAT64(tag) && JS_VALUE_GET_FLOAT64(key) == 0.0) { - key = JS_NewInt32(ctx, 0); + key = js_int32(0); } return key; } @@ -45262,7 +45255,7 @@ static __exception int remainingElementsCount_add(JSContext *ctx, return -1; remainingElementsCount += addend; if (JS_SetPropertyUint32(ctx, resolve_element_env, 0, - JS_NewInt32(ctx, remainingElementsCount)) < 0) + js_int32(remainingElementsCount)) < 0) return -1; return (remainingElementsCount == 0); } @@ -45385,7 +45378,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val, goto fail_reject; /* remainingElementsCount field */ if (JS_DefinePropertyValueUint32(ctx, resolve_element_env, 0, - JS_NewInt32(ctx, 1), + js_int32(1), JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE | JS_PROP_WRITABLE) < 0) goto fail_reject; @@ -45407,7 +45400,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val, goto fail_reject; } resolve_element_data[0] = JS_NewBool(ctx, FALSE); - resolve_element_data[1] = (JSValueConst)JS_NewInt32(ctx, index); + resolve_element_data[1] = (JSValueConst)js_int32(index); resolve_element_data[2] = values; resolve_element_data[3] = resolving_funcs[is_promise_any]; resolve_element_data[4] = resolve_element_env; @@ -47657,7 +47650,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) /* Number */ ctx->class_proto[JS_CLASS_NUMBER] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT], JS_CLASS_NUMBER); - JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_NUMBER], JS_NewInt32(ctx, 0)); + JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_NUMBER], js_int32(0)); JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_NUMBER], js_number_proto_funcs, countof(js_number_proto_funcs)); @@ -48202,7 +48195,7 @@ static JSValue js_typed_array_get_length(JSContext *ctx, p = get_typed_array(ctx, this_val, 0); if (!p) return JS_EXCEPTION; - return JS_NewInt32(ctx, p->u.array.count); + return js_int32(p->u.array.count); } static JSValue js_typed_array_get_buffer(JSContext *ctx, @@ -48230,11 +48223,11 @@ static JSValue js_typed_array_get_byteLength(JSContext *ctx, if (is_dataview) { return JS_ThrowTypeErrorDetachedArrayBuffer(ctx); } else { - return JS_NewInt32(ctx, 0); + return js_int32(0); } } ta = p->u.typed_array; - return JS_NewInt32(ctx, ta->length); + return js_int32(ta->length); } static JSValue js_typed_array_get_byteOffset(JSContext *ctx, @@ -48250,11 +48243,11 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx, if (is_dataview) { return JS_ThrowTypeErrorDetachedArrayBuffer(ctx); } else { - return JS_NewInt32(ctx, 0); + return js_int32(0); } } ta = p->u.typed_array; - return JS_NewInt32(ctx, ta->offset); + return js_int32(ta->offset); } /* Return the buffer associated to the typed array or an exception if @@ -48429,16 +48422,16 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val, switch (p->class_id) { case JS_CLASS_INT8_ARRAY: - return JS_NewInt32(ctx, p->u.array.u.int8_ptr[idx]); + return js_int32(p->u.array.u.int8_ptr[idx]); case JS_CLASS_UINT8C_ARRAY: case JS_CLASS_UINT8_ARRAY: - return JS_NewInt32(ctx, p->u.array.u.uint8_ptr[idx]); + return js_int32(p->u.array.u.uint8_ptr[idx]); case JS_CLASS_INT16_ARRAY: - return JS_NewInt32(ctx, p->u.array.u.int16_ptr[idx]); + return js_int32(p->u.array.u.int16_ptr[idx]); case JS_CLASS_UINT16_ARRAY: - return JS_NewInt32(ctx, p->u.array.u.uint16_ptr[idx]); + return js_int32(p->u.array.u.uint16_ptr[idx]); case JS_CLASS_INT32_ARRAY: - return JS_NewInt32(ctx, p->u.array.u.int32_ptr[idx]); + return js_int32(p->u.array.u.int32_ptr[idx]); case JS_CLASS_UINT32_ARRAY: return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]); case JS_CLASS_FLOAT32_ARRAY: @@ -48612,7 +48605,7 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValueConst this_val, goto exception; if (mapping) { args[0] = v; - args[1] = JS_NewInt32(ctx, k); + args[1] = js_int32(k); v2 = JS_Call(ctx, mapfn, this_arg, 2, args); JS_FreeValue(ctx, v); v = v2; @@ -48644,7 +48637,7 @@ static JSValue js_typed_array_of(JSContext *ctx, JSValueConst this_val, JSValueConst args[1]; int i; - args[0] = JS_NewInt32(ctx, argc); + args[0] = js_int32(argc); obj = js_typed_array_create(ctx, this_val, 1, args); if (JS_IsException(obj)) return obj; @@ -48812,7 +48805,7 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val, } for(; k != end; k += dir) { - index_val = JS_NewInt32(ctx, k); + index_val = js_int32(k); val = JS_GetPropertyValue(ctx, this_val, index_val); if (JS_IsException(val)) goto exception; @@ -48833,7 +48826,7 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, val); } if (mode == ArrayFindIndex || mode == ArrayFindLastIndex) - return JS_NewInt32(ctx, -1); + return js_int32(-1); else return JS_UNDEFINED; @@ -49074,7 +49067,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val, if (special == special_includes) return JS_NewBool(ctx, res >= 0); else - return JS_NewInt32(ctx, res); + return js_int32(res); exception: return JS_EXCEPTION; @@ -49230,7 +49223,7 @@ static JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val, shift = typed_array_size_log2(p->class_id); args[0] = this_val; - args[1] = JS_NewInt32(ctx, count); + args[1] = js_int32(count); arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args); if (JS_IsException(arr)) goto exception; @@ -49249,10 +49242,10 @@ static JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val, count << shift); } else { for (n = 0; n < count; n++) { - val = JS_GetPropertyValue(ctx, this_val, JS_NewInt32(ctx, start + n)); + val = JS_GetPropertyValue(ctx, this_val, js_int32(start + n)); if (JS_IsException(val)) goto exception; - if (JS_SetPropertyValue(ctx, arr, JS_NewInt32(ctx, n), val, + if (JS_SetPropertyValue(ctx, arr, js_int32(n), val, JS_PROP_THROW) < 0) goto exception; } @@ -49297,8 +49290,8 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val, goto exception; args[0] = this_val; args[1] = ta_buffer; - args[2] = JS_NewInt32(ctx, offset); - args[3] = JS_NewInt32(ctx, count); + args[2] = js_int32(offset); + args[3] = js_int32(count); arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 4, args); JS_FreeValue(ctx, ta_buffer); return arr; @@ -49369,23 +49362,23 @@ static int js_TA_cmp_float64(const void *a, const void *b, void *opaque) { } static JSValue js_TA_get_int8(JSContext *ctx, const void *a) { - return JS_NewInt32(ctx, *(const int8_t *)a); + return js_int32(*(const int8_t *)a); } static JSValue js_TA_get_uint8(JSContext *ctx, const void *a) { - return JS_NewInt32(ctx, *(const uint8_t *)a); + return js_int32(*(const uint8_t *)a); } static JSValue js_TA_get_int16(JSContext *ctx, const void *a) { - return JS_NewInt32(ctx, *(const int16_t *)a); + return js_int32(*(const int16_t *)a); } static JSValue js_TA_get_uint16(JSContext *ctx, const void *a) { - return JS_NewInt32(ctx, *(const uint16_t *)a); + return js_int32(*(const uint16_t *)a); } static JSValue js_TA_get_int32(JSContext *ctx, const void *a) { - return JS_NewInt32(ctx, *(const int32_t *)a); + return js_int32(*(const int32_t *)a); } static JSValue js_TA_get_uint32(JSContext *ctx, const void *a) { @@ -50023,24 +50016,24 @@ static JSValue js_dataview_getValue(JSContext *ctx, switch(class_id) { case JS_CLASS_INT8_ARRAY: - return JS_NewInt32(ctx, *(int8_t *)ptr); + return js_int32(*(int8_t *)ptr); case JS_CLASS_UINT8_ARRAY: - return JS_NewInt32(ctx, *(uint8_t *)ptr); + return js_int32(*(uint8_t *)ptr); case JS_CLASS_INT16_ARRAY: v = get_u16(ptr); if (is_swap) v = bswap16(v); - return JS_NewInt32(ctx, (int16_t)v); + return js_int32((int16_t)v); case JS_CLASS_UINT16_ARRAY: v = get_u16(ptr); if (is_swap) v = bswap16(v); - return JS_NewInt32(ctx, v); + return js_int32(v); case JS_CLASS_INT32_ARRAY: v = get_u32(ptr); if (is_swap) v = bswap32(v); - return JS_NewInt32(ctx, v); + return js_int32(v); case JS_CLASS_UINT32_ARRAY: v = get_u32(ptr); if (is_swap) @@ -50448,7 +50441,7 @@ static JSValue js_atomics_op(JSContext *ctx, goto done; case JS_CLASS_INT32_ARRAY: done: - ret = JS_NewInt32(ctx, a); + ret = js_int32(a); break; case JS_CLASS_UINT32_ARRAY: ret = JS_NewUint32(ctx, a); @@ -50667,7 +50660,7 @@ static JSValue js_atomics_notify(JSContext *ctx, } pthread_mutex_unlock(&js_atomics_mutex); } - return JS_NewInt32(ctx, n); + return js_int32(n); } static const JSCFunctionListEntry js_atomics_funcs[] = { @@ -50756,7 +50749,7 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx) ctx->class_proto[i] = JS_NewObjectProto(ctx, typed_array_base_proto); JS_DefinePropertyValueStr(ctx, ctx->class_proto[i], "BYTES_PER_ELEMENT", - JS_NewInt32(ctx, 1 << typed_array_size_log2(i)), + js_int32(1 << typed_array_size_log2(i)), 0); name = JS_AtomGetStr(ctx, buf, sizeof(buf), JS_ATOM_Uint8ClampedArray + i - JS_CLASS_UINT8C_ARRAY); @@ -50766,7 +50759,7 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx) JS_NewGlobalCConstructor2(ctx, func_obj, name, ctx->class_proto[i]); JS_DefinePropertyValueStr(ctx, func_obj, "BYTES_PER_ELEMENT", - JS_NewInt32(ctx, 1 << typed_array_size_log2(i)), + js_int32(1 << typed_array_size_log2(i)), 0); } JS_FreeValue(ctx, typed_array_base_proto); From b51e117a6267365ad42e766976d75214fd0b3352 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Nov 2023 12:36:40 +0100 Subject: [PATCH 2/5] Replace JS_NewFloat64() calls with js_float64() --- quickjs.c | 173 +++++++++++++++++++++++++++--------------------------- quickjs.h | 10 ++-- 2 files changed, 93 insertions(+), 90 deletions(-) diff --git a/quickjs.c b/quickjs.c index 27a00b06e..8ced5c20b 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1239,6 +1239,43 @@ static const JSClassExoticMethods js_string_exotic_methods; static const JSClassExoticMethods js_proxy_exotic_methods; static const JSClassExoticMethods js_module_ns_exotic_methods; +// Special care is taken to not invoke UB when checking if the result fits +// in an int32_t. Leans on the fact that the input is integral if the lower +// 52 bits of the equation 2**e * (f + 2**52) are zero. +static BOOL float_is_int32(double d) +{ + uint64_t u, m, e, f; + JSFloat64Union t; + + t.d = d; + u = t.u64; + + // special case -0 + m = 1ull << 63; + if (u == m) + return FALSE; + + e = (u >> 52) & 0x7FF; + if (e > 0) + e -= 1023; + + // too large, nan or inf? + if (e > 30) + return FALSE; + + // fractional or subnormal if low bits are non-zero + f = 0xFFFFFFFFFFFFFull & u; + m = 0xFFFFFFFFFFFFFull >> e; + return 0 == (f & m); +} + +static JSValue js_float64(double d) +{ + if (float_is_int32(d)) + return JS_MKVAL(JS_TAG_INT, (int32_t)d); + return __JS_NewFloat64(d); +} + static int compare_u32(uint32_t a, uint32_t b) { return -(a < b) + (b < a); // -1, 0 or 1 @@ -3103,7 +3140,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) /* -0 case is specific */ if (c == '0' && len == 2) { minus_zero: - return __JS_NewFloat64(ctx, -0.0); + return __JS_NewFloat64(-0.0); } } if (!is_num(c)) { @@ -7775,10 +7812,10 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, return JS_NewBigUint64(ctx, p->u.array.u.uint64_ptr[idx]); case JS_CLASS_FLOAT32_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return __JS_NewFloat64(ctx, p->u.array.u.float_ptr[idx]); + return __JS_NewFloat64(p->u.array.u.float_ptr[idx]); case JS_CLASS_FLOAT64_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return __JS_NewFloat64(ctx, p->u.array.u.double_ptr[idx]); + return __JS_NewFloat64(p->u.array.u.double_ptr[idx]); default: goto slow_path; } @@ -10088,7 +10125,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp, double d = 1.0 / 0.0; if (is_neg) d = -d; - val = JS_NewFloat64(ctx, d); + val = js_float64(d); goto done; } } @@ -10168,7 +10205,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp, double d; d = js_strtod(buf, radix, is_float); /* return int or float64 */ - val = JS_NewFloat64(ctx, d); + val = js_float64(d); } break; case ATOD_TYPE_BIG_INT: @@ -10377,7 +10414,7 @@ static __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val) } else { /* convert -0 to +0 */ d = trunc(d) + 0.0; - ret = JS_NewFloat64(ctx, d); + ret = js_float64(d); } } break; @@ -11554,43 +11591,9 @@ static double js_pow(double a, double b) } } -// Special care is taken to not invoke UB when checking if the result fits -// in an int32_t. Leans on the fact that the input is integral if the lower -// 52 bits of the equation 2**e * (f + 2**52) are zero. -static BOOL float_is_int32(double d) -{ - uint64_t u, m, e, f; - JSFloat64Union t; - - t.d = d; - u = t.u64; - - // special case -0 - m = 1ull << 63; - if (u == m) - return FALSE; - - e = (u >> 52) & 0x7FF; - if (e > 0) - e -= 1023; - - // too large, nan or inf? - if (e > 30) - return FALSE; - - // fractional or subnormal if low bits are non-zero - f = 0xFFFFFFFFFFFFFull & u; - m = 0xFFFFFFFFFFFFFull >> e; - return 0 == (f & m); -} - JSValue JS_NewFloat64(JSContext *ctx, double d) { - if (float_is_int32(d)) { - return JS_MKVAL(JS_TAG_INT, (int32_t)d); - } else { - return __JS_NewFloat64(ctx, d); - } + return js_float64(d); } JSValue JS_NewBigInt64_1(JSContext *ctx, int64_t v) @@ -11960,7 +11963,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx, break; case OP_neg: if (v64 == 0) { - sp[-1] = __JS_NewFloat64(ctx, -0.0); + sp[-1] = __JS_NewFloat64(-0.0); return 0; } else { v64 = -v64; @@ -11994,7 +11997,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx, default: abort(); } - sp[-1] = __JS_NewFloat64(ctx, d); + sp[-1] = __JS_NewFloat64(d); } break; } @@ -12189,23 +12192,23 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s case OP_mul: v = (int64_t)v1 * (int64_t)v2; if (v == 0 && (v1 | v2) < 0) { - sp[-2] = __JS_NewFloat64(ctx, -0.0); + sp[-2] = __JS_NewFloat64(-0.0); return 0; } break; case OP_div: - sp[-2] = __JS_NewFloat64(ctx, (double)v1 / (double)v2); + sp[-2] = __JS_NewFloat64((double)v1 / (double)v2); return 0; case OP_mod: if (v1 < 0 || v2 <= 0) { - sp[-2] = JS_NewFloat64(ctx, fmod(v1, v2)); + sp[-2] = js_float64(fmod(v1, v2)); return 0; } else { v = (int64_t)v1 % (int64_t)v2; } break; case OP_pow: - sp[-2] = JS_NewFloat64(ctx, js_pow(v1, v2)); + sp[-2] = js_float64(js_pow(v1, v2)); return 0; default: abort(); @@ -12243,7 +12246,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s default: abort(); } - sp[-2] = __JS_NewFloat64(ctx, dr); + sp[-2] = __JS_NewFloat64(dr); } return 0; exception: @@ -12267,7 +12270,7 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp) double d1, d2; d1 = JS_VALUE_GET_FLOAT64(op1); d2 = JS_VALUE_GET_FLOAT64(op2); - sp[-2] = __JS_NewFloat64(ctx, d1 + d2); + sp[-2] = __JS_NewFloat64(d1 + d2); return 0; } @@ -12326,7 +12329,7 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp) } if (JS_ToFloat64Free(ctx, &d2, op2)) goto exception; - sp[-2] = __JS_NewFloat64(ctx, d1 + d2); + sp[-2] = __JS_NewFloat64(d1 + d2); } return 0; exception: @@ -14241,7 +14244,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, ret_val = JS_EXCEPTION; break; } - ret_val = JS_NewFloat64(ctx, func.f_f(d1)); + ret_val = js_float64(func.f_f(d1)); } break; case JS_CFUNC_f_f_f: @@ -14256,7 +14259,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, ret_val = JS_EXCEPTION; break; } - ret_val = JS_NewFloat64(ctx, func.f_f_f(d1, d2)); + ret_val = js_float64(func.f_f_f(d1, d2)); } break; case JS_CFUNC_iterator_next: @@ -16119,7 +16122,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-2] = js_int32(r); sp--; } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { - sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) + + sp[-2] = __JS_NewFloat64(JS_VALUE_GET_FLOAT64(op1) + JS_VALUE_GET_FLOAT64(op2)); sp--; } else { @@ -16184,7 +16187,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-2] = js_int32(r); sp--; } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { - sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) - + sp[-2] = __JS_NewFloat64(JS_VALUE_GET_FLOAT64(op1) - JS_VALUE_GET_FLOAT64(op2)); sp--; } else { @@ -16218,7 +16221,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) { d = JS_VALUE_GET_FLOAT64(op1) * JS_VALUE_GET_FLOAT64(op2); mul_fp_res: - sp[-2] = __JS_NewFloat64(ctx, d); + sp[-2] = __JS_NewFloat64(d); sp--; } else { goto binary_arith_slow; @@ -16234,7 +16237,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int v1, v2; v1 = JS_VALUE_GET_INT(op1); v2 = JS_VALUE_GET_INT(op2); - sp[-2] = JS_NewFloat64(ctx, (double)v1 / (double)v2); + sp[-2] = js_float64((double)v1 / (double)v2); sp--; } else { goto binary_arith_slow; @@ -16305,7 +16308,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } else if (JS_TAG_IS_FLOAT64(tag)) { d = -JS_VALUE_GET_FLOAT64(op1); neg_fp_res: - sp[-1] = __JS_NewFloat64(ctx, d); + sp[-1] = __JS_NewFloat64(d); } else { if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; @@ -33698,7 +33701,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) if (bc_get_u64(s, &u.u64)) return JS_EXCEPTION; bc_read_trace(s, "%g\n", u.d); - obj = __JS_NewFloat64(ctx, u.d); + obj = __JS_NewFloat64(u.d); } break; case BC_TAG_STRING: @@ -34004,7 +34007,7 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj, val = JS_NewInt64(ctx, e->u.i64); break; case JS_DEF_PROP_DOUBLE: - val = __JS_NewFloat64(ctx, e->u.f64); + val = __JS_NewFloat64(e->u.f64); break; case JS_DEF_PROP_UNDEFINED: val = JS_UNDEFINED; @@ -34068,7 +34071,7 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, val = JS_NewInt64(ctx, e->u.i64); break; case JS_DEF_PROP_DOUBLE: - val = __JS_NewFloat64(ctx, e->u.f64); + val = __JS_NewFloat64(e->u.f64); break; case JS_DEF_OBJECT: val = JS_NewObject(ctx); @@ -35676,7 +35679,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, else d -= (double)arg_count; /* also converts -0 to +0 */ } - len_val = JS_NewFloat64(ctx, d); + len_val = js_float64(d); } else { JS_FreeValue(ctx, len_val); len_val = js_int32(0); @@ -38040,7 +38043,7 @@ static JSValue js_number_constructor(JSContext *ctx, JSValueConst new_target, double d; bf_get_float64(&p->num, &d, BF_RNDN); JS_FreeValue(ctx, val); - val = __JS_NewFloat64(ctx, d); + val = __JS_NewFloat64(d); } break; default: @@ -38188,7 +38191,7 @@ static JSValue js_number_toFixed(JSContext *ctx, JSValueConst this_val, if (f < 0 || f > 100) return JS_ThrowRangeError(ctx, "invalid number of digits"); if (fabs(d) >= 1e21) { - return JS_ToStringFree(ctx, __JS_NewFloat64(ctx, d)); + return JS_ToStringFree(ctx, __JS_NewFloat64(d)); } else { return js_dtoa(ctx, d, 10, f, JS_DTOA_FRAC_FORMAT); } @@ -38209,7 +38212,7 @@ static JSValue js_number_toExponential(JSContext *ctx, JSValueConst this_val, if (JS_ToInt32Sat(ctx, &f, argv[0])) return JS_EXCEPTION; if (!isfinite(d)) { - return JS_ToStringFree(ctx, __JS_NewFloat64(ctx, d)); + return JS_ToStringFree(ctx, __JS_NewFloat64(d)); } if (JS_IsUndefined(argv[0])) { flags = 0; @@ -38241,7 +38244,7 @@ static JSValue js_number_toPrecision(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; if (!isfinite(d)) { to_string: - return JS_ToStringFree(ctx, __JS_NewFloat64(ctx, d)); + return JS_ToStringFree(ctx, __JS_NewFloat64(d)); } if (p < 1 || p > 100) return JS_ThrowRangeError(ctx, "invalid number of digits"); @@ -40109,7 +40112,7 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val, uint32_t tag; if (unlikely(argc == 0)) { - return __JS_NewFloat64(ctx, is_max ? -1.0 / 0.0 : 1.0 / 0.0); + return __JS_NewFloat64(is_max ? -1.0 / 0.0 : 1.0 / 0.0); } tag = JS_VALUE_GET_TAG(argv[0]); @@ -40149,7 +40152,7 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val, } i++; } - return JS_NewFloat64(ctx, r); + return js_float64(r); } } @@ -40212,7 +40215,7 @@ static JSValue js_math_hypot(JSContext *ctx, JSValueConst this_val, } } } - return JS_NewFloat64(ctx, r); + return js_float64(r); } static double js_math_fround(double a) @@ -40280,7 +40283,7 @@ static JSValue js_math_random(JSContext *ctx, JSValueConst this_val, v = xorshift64star(&ctx->random_state); /* 1.0 <= u.d < 2 */ u.u64 = ((uint64_t)0x3ff << 52) | (v >> 12); - return __JS_NewFloat64(ctx, u.d - 1.0); + return __JS_NewFloat64(u.d - 1.0); } static const JSCFunctionListEntry js_math_funcs[] = { @@ -46382,7 +46385,7 @@ static JSValue JS_SetThisTimeValue(JSContext *ctx, JSValueConst this_val, double JSObject *p = JS_VALUE_GET_OBJ(this_val); if (p->class_id == JS_CLASS_DATE) { JS_FreeValue(ctx, p->u.object_data); - p->u.object_data = JS_NewFloat64(ctx, v); + p->u.object_data = js_float64(v); return JS_DupValue(ctx, p->u.object_data); } } @@ -46532,7 +46535,7 @@ static JSValue get_date_field(JSContext *ctx, JSValueConst this_val, if (magic & 0x100) { // getYear fields[0] -= 1900; } - return JS_NewFloat64(ctx, fields[n]); + return js_float64(fields[n]); } static JSValue set_date_field(JSContext *ctx, JSValueConst this_val, @@ -46746,7 +46749,7 @@ static JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target, has_val: rv = js_create_from_ctor(ctx, new_target, JS_CLASS_DATE); if (!JS_IsException(rv)) - JS_SetObjectData(ctx, rv, JS_NewFloat64(ctx, val)); + JS_SetObjectData(ctx, rv, js_float64(val)); if (!JS_IsException(rv) && JS_IsUndefined(new_target)) { /* invoked as a function, return (new Date()).toString(); */ JSValue s; @@ -46779,7 +46782,7 @@ static JSValue js_Date_UTC(JSContext *ctx, JSValueConst this_val, if (i == 0 && fields[0] >= 0 && fields[0] < 100) fields[0] += 1900; } - return JS_NewFloat64(ctx, set_date_fields(fields, 0)); + return js_float64(set_date_fields(fields, 0)); } static void string_skip_spaces(JSString *sp, int *pp) { @@ -47066,7 +47069,7 @@ static JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val, for(i = 0; i < 7; i++) fields1[i] = fields[i]; d = set_date_fields(fields1, is_local) - tz * 60000; - rv = JS_NewFloat64(ctx, d); + rv = js_float64(d); done: JS_FreeValue(ctx, s); @@ -47134,7 +47137,7 @@ static JSValue js_date_getTime(JSContext *ctx, JSValueConst this_val, if (JS_ThisTimeValue(ctx, &v, this_val)) return JS_EXCEPTION; - return JS_NewFloat64(ctx, v); + return js_float64(v); } static JSValue js_date_setTime(JSContext *ctx, JSValueConst this_val, @@ -47163,7 +47166,7 @@ static JSValue js_date_setYear(JSContext *ctx, JSValueConst this_val, if (y >= 0 && y < 100) y += 1900; } - args[0] = JS_NewFloat64(ctx, y); + args[0] = js_float64(y); return set_date_field(ctx, this_val, 1, args, 0x011); } @@ -47266,7 +47269,7 @@ JSValue JS_NewDate(JSContext *ctx, double epoch_ms) JSValue obj = js_create_from_ctor(ctx, JS_UNDEFINED, JS_CLASS_DATE); if (JS_IsException(obj)) return JS_EXCEPTION; - JS_SetObjectData(ctx, obj, JS_NewFloat64(ctx, time_clip(epoch_ms))); + JS_SetObjectData(ctx, obj, js_float64(time_clip(epoch_ms))); return obj; } @@ -48435,9 +48438,9 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val, case JS_CLASS_UINT32_ARRAY: return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]); case JS_CLASS_FLOAT32_ARRAY: - return __JS_NewFloat64(ctx, p->u.array.u.float_ptr[idx]); + return __JS_NewFloat64(p->u.array.u.float_ptr[idx]); case JS_CLASS_FLOAT64_ARRAY: - return __JS_NewFloat64(ctx, p->u.array.u.double_ptr[idx]); + return __JS_NewFloat64(p->u.array.u.double_ptr[idx]); case JS_CLASS_BIG_INT64_ARRAY: return JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]); case JS_CLASS_BIG_UINT64_ARRAY: @@ -49394,11 +49397,11 @@ static JSValue js_TA_get_uint64(JSContext *ctx, const void *a) { } static JSValue js_TA_get_float32(JSContext *ctx, const void *a) { - return __JS_NewFloat64(ctx, *(const float *)a); + return __JS_NewFloat64(*(const float *)a); } static JSValue js_TA_get_float64(JSContext *ctx, const void *a) { - return __JS_NewFloat64(ctx, *(const double *)a); + return __JS_NewFloat64(*(const double *)a); } struct TA_sort_context { @@ -50067,7 +50070,7 @@ static JSValue js_dataview_getValue(JSContext *ctx, if (is_swap) v = bswap32(v); u.i = v; - return __JS_NewFloat64(ctx, u.f); + return __JS_NewFloat64(u.f); } case JS_CLASS_FLOAT64_ARRAY: { @@ -50078,7 +50081,7 @@ static JSValue js_dataview_getValue(JSContext *ctx, u.i = get_u64(ptr); if (is_swap) u.i = bswap64(u.i); - return __JS_NewFloat64(ctx, u.f); + return __JS_NewFloat64(u.f); } default: abort(); @@ -50791,7 +50794,7 @@ static uint64_t js__now_ms(void) static JSValue js_perf_now(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - return JS_NewFloat64(ctx, js__now_ms() - ctx->time_origin); + return js_float64(js__now_ms() - ctx->time_origin); } static const JSCFunctionListEntry js_perf_proto_funcs[] = { @@ -50805,7 +50808,7 @@ void JS_AddPerformance(JSContext *ctx) JSValue performance = JS_NewObject(ctx); JS_SetPropertyFunctionList(ctx, performance, js_perf_proto_funcs, countof(js_perf_proto_funcs)); JS_DefinePropertyValueStr(ctx, performance, "timeOrigin", - JS_NewFloat64(ctx, ctx->time_origin), + js_float64(ctx->time_origin), JS_PROP_ENUMERABLE); JS_DefinePropertyValueStr(ctx, ctx->global_obj, "performance", JS_DupValue(ctx, performance), diff --git a/quickjs.h b/quickjs.h index 8b8b38466..f11acec2b 100644 --- a/quickjs.h +++ b/quickjs.h @@ -111,7 +111,7 @@ typedef const struct __JSValue *JSValueConst; #define JS_NAN JS_MKVAL(JS_TAG_FLOAT64, 1) -static inline JSValue __JS_NewFloat64(JSContext *ctx, double d) +static inline JSValue __JS_NewFloat64(double d) { return JS_MKVAL(JS_TAG_FLOAT64, (int)d); } @@ -150,7 +150,7 @@ static inline double JS_VALUE_GET_FLOAT64(JSValue v) #define JS_NAN (0x7ff8000000000000 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32)) -static inline JSValue __JS_NewFloat64(JSContext *ctx, double d) +static inline JSValue __JS_NewFloat64(double d) { union { double d; @@ -216,7 +216,7 @@ typedef struct JSValue { #define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 } -static inline JSValue __JS_NewFloat64(JSContext *ctx, double d) +static inline JSValue __JS_NewFloat64(double d) { JSValue v; v.tag = JS_TAG_FLOAT64; @@ -513,7 +513,7 @@ static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val) if (val == (int32_t)val) { v = JS_NewInt32(ctx, val); } else { - v = __JS_NewFloat64(ctx, val); + v = __JS_NewFloat64(val); } return v; } @@ -524,7 +524,7 @@ static js_force_inline JSValue JS_NewUint32(JSContext *ctx, uint32_t val) if (val <= 0x7fffffff) { v = JS_NewInt32(ctx, val); } else { - v = __JS_NewFloat64(ctx, val); + v = __JS_NewFloat64(val); } return v; } From 3cb112d6577f1d5308656f6c64f1b7d5f0becb15 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Nov 2023 12:36:40 +0100 Subject: [PATCH 3/5] Replace JS_NewUint32() calls with js_uint32() --- quickjs.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/quickjs.c b/quickjs.c index 8ced5c20b..40f7938f6 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1286,6 +1286,13 @@ static JSValue js_int32(int32_t v) return JS_MKVAL(JS_TAG_INT, v); } +static JSValue js_uint32(uint32_t v) +{ + if (v <= INT32_MAX) + return js_int32(v); + return js_float64(v); +} + static void js_trigger_gc(JSRuntime *rt, size_t size) { BOOL force_gc; @@ -7803,7 +7810,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, return js_int32(p->u.array.u.int32_ptr[idx]); case JS_CLASS_UINT32_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]); + return js_uint32(p->u.array.u.uint32_ptr[idx]); case JS_CLASS_BIG_INT64_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; return JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]); @@ -7834,7 +7841,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx) { - return JS_GetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx)); + return JS_GetPropertyValue(ctx, this_obj, js_uint32(idx)); } /* Check if an object has a generalized numeric property. Return value: @@ -8115,7 +8122,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val, } p->u.array.count = len; } - p->prop[0].u.value = JS_NewUint32(ctx, len); + p->prop[0].u.value = js_uint32(len); } else { /* Note: length is always a uint32 because the object is an array */ @@ -8175,7 +8182,7 @@ static int set_array_length(JSContext *ctx, JSObject *p, JSValue val, } else { cur_len = len; } - set_value(ctx, &p->prop[0].u.value, JS_NewUint32(ctx, cur_len)); + set_value(ctx, &p->prop[0].u.value, js_uint32(cur_len)); if (unlikely(cur_len > len)) { return JS_ThrowTypeErrorOrFalse(ctx, flags, "not configurable"); } @@ -8731,7 +8738,7 @@ static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj, int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx, JSValue val) { - return JS_SetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx), val, + return JS_SetPropertyValue(ctx, this_obj, js_uint32(idx), val, JS_PROP_THROW); } @@ -8828,7 +8835,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p, /* XXX: should update the length after defining the property */ len = idx + 1; - set_value(ctx, &plen->u.value, JS_NewUint32(ctx, len)); + set_value(ctx, &plen->u.value, js_uint32(len)); } } } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY && @@ -8997,7 +9004,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, return -1; } /* this code relies on the fact that Uint32 are never allocated */ - val = (JSValueConst)JS_NewUint32(ctx, array_length); + val = (JSValueConst)js_uint32(array_length); /* prs may have been modified */ prs = find_own_property(&pr, p, prop); assert(prs != NULL); @@ -9299,7 +9306,7 @@ int JS_DefinePropertyValueValue(JSContext *ctx, JSValueConst this_obj, int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj, uint32_t idx, JSValue val, int flags) { - return JS_DefinePropertyValueValue(ctx, this_obj, JS_NewUint32(ctx, idx), + return JS_DefinePropertyValueValue(ctx, this_obj, js_uint32(idx), val, flags); } @@ -12735,7 +12742,7 @@ static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp) JS_ToUint32Free(ctx, &v1, op1); JS_ToUint32Free(ctx, &v2, op2); r = v1 >> (v2 & 0x1f); - sp[-2] = JS_NewUint32(ctx, r); + sp[-2] = js_uint32(r); return 0; exception: sp[-2] = JS_UNDEFINED; @@ -16445,9 +16452,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, uint32_t v2; v2 = JS_VALUE_GET_INT(op2); v2 &= 0x1f; - sp[-2] = JS_NewUint32(ctx, - (uint32_t)JS_VALUE_GET_INT(op1) >> - v2); + sp[-2] = js_uint32((uint32_t)JS_VALUE_GET_INT(op1) >> v2); sp--; } else { if (js_shr_slow(ctx, sp)) @@ -36026,7 +36031,7 @@ static JSValue js_array_constructor(JSContext *ctx, JSValueConst new_target, uint32_t len; if (JS_ToArrayLengthFree(ctx, &len, JS_DupValue(ctx, argv[0]), TRUE)) goto fail; - if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, len)) < 0) + if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32(len)) < 0) goto fail; } else { for(i = 0; i < argc; i++) { @@ -36136,7 +36141,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, goto exception; } } - if (JS_SetProperty(ctx, r, JS_ATOM_length, JS_NewUint32(ctx, k)) < 0) + if (JS_SetProperty(ctx, r, JS_ATOM_length, js_uint32(k)) < 0) goto exception; goto done; @@ -36173,7 +36178,7 @@ static JSValue js_array_of(JSContext *ctx, JSValueConst this_val, goto fail; } } - if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, argc)) < 0) { + if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32(argc)) < 0) { fail: JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -37946,7 +37951,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, it->idx = idx + 1; *pdone = FALSE; if (it->kind == JS_ITERATOR_KIND_KEY) { - return JS_NewUint32(ctx, idx); + return js_uint32(idx); } else { val = JS_GetPropertyUint32(ctx, it->obj, idx); if (JS_IsException(val)) @@ -37956,7 +37961,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, } else { JSValueConst args[2]; JSValue num; - num = JS_NewUint32(ctx, idx); + num = js_uint32(idx); args[0] = num; args[1] = val; obj = js_create_array(ctx, 2, args); @@ -44307,7 +44312,7 @@ static JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, int magic) JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); if (!s) return JS_EXCEPTION; - return JS_NewUint32(ctx, s->record_count); + return js_uint32(s->record_count); } static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val, @@ -47940,7 +47945,7 @@ static JSValue js_array_buffer_get_byteLength(JSContext *ctx, if (!abuf) return JS_EXCEPTION; /* return 0 if detached */ - return JS_NewUint32(ctx, abuf->byte_length); + return js_uint32(abuf->byte_length); } void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj) @@ -48436,7 +48441,7 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val, case JS_CLASS_INT32_ARRAY: return js_int32(p->u.array.u.int32_ptr[idx]); case JS_CLASS_UINT32_ARRAY: - return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]); + return js_uint32(p->u.array.u.uint32_ptr[idx]); case JS_CLASS_FLOAT32_ARRAY: return __JS_NewFloat64(p->u.array.u.float_ptr[idx]); case JS_CLASS_FLOAT64_ARRAY: @@ -49385,7 +49390,7 @@ static JSValue js_TA_get_int32(JSContext *ctx, const void *a) { } static JSValue js_TA_get_uint32(JSContext *ctx, const void *a) { - return JS_NewUint32(ctx, *(const uint32_t *)a); + return js_uint32(*(const uint32_t *)a); } static JSValue js_TA_get_int64(JSContext *ctx, const void *a) { @@ -50041,7 +50046,7 @@ static JSValue js_dataview_getValue(JSContext *ctx, v = get_u32(ptr); if (is_swap) v = bswap32(v); - return JS_NewUint32(ctx, v); + return js_uint32(v); case JS_CLASS_BIG_INT64_ARRAY: { uint64_t v; @@ -50447,7 +50452,7 @@ static JSValue js_atomics_op(JSContext *ctx, ret = js_int32(a); break; case JS_CLASS_UINT32_ARRAY: - ret = JS_NewUint32(ctx, a); + ret = js_uint32(a); break; case JS_CLASS_BIG_INT64_ARRAY: ret = JS_NewBigInt64(ctx, a); From e1cffb10b4f47e8e22db32d1c13f218d0df9577f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Nov 2023 12:36:40 +0100 Subject: [PATCH 4/5] Replace JS_NewBool() calls with js_bool() --- quickjs.c | 124 +++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/quickjs.c b/quickjs.c index 40f7938f6..7c110fefc 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1293,6 +1293,11 @@ static JSValue js_uint32(uint32_t v) return js_float64(v); } +static JSValue js_bool(JS_BOOL v) +{ + return JS_MKVAL(JS_TAG_BOOL, (v != 0)); +} + static void js_trigger_gc(JSRuntime *rt, size_t size) { BOOL force_gc; @@ -12583,7 +12588,7 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp, } } done: - sp[-2] = JS_NewBool(ctx, res); + sp[-2] = js_bool(res); return 0; exception: sp[-2] = JS_UNDEFINED; @@ -12705,7 +12710,7 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp, JS_FreeValue(ctx, op2); } done: - sp[-2] = JS_NewBool(ctx, res ^ is_neq); + sp[-2] = js_bool(res ^ is_neq); return 0; exception: sp[-2] = JS_UNDEFINED; @@ -12892,7 +12897,7 @@ static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp, { BOOL res; res = js_strict_eq(ctx, sp[-2], sp[-1]); - sp[-2] = JS_NewBool(ctx, res ^ is_neq); + sp[-2] = js_bool(res ^ is_neq); return 0; } @@ -12918,7 +12923,7 @@ static __exception int js_operator_in(JSContext *ctx, JSValue *sp) return -1; JS_FreeValue(ctx, op1); JS_FreeValue(ctx, op2); - sp[-2] = JS_NewBool(ctx, ret); + sp[-2] = js_bool(ret); return 0; } @@ -12952,7 +12957,7 @@ static __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp) return ret; JS_FreeValue(ctx, op1); JS_FreeValue(ctx, op2); - sp[-2] = JS_NewBool(ctx, ret); + sp[-2] = js_bool(ret); return 0; } @@ -13022,7 +13027,7 @@ static __exception int js_operator_delete(JSContext *ctx, JSValue *sp) return -1; JS_FreeValue(ctx, op1); JS_FreeValue(ctx, op2); - sp[-2] = JS_NewBool(ctx, ret); + sp[-2] = js_bool(ret); return 0; } @@ -13601,7 +13606,7 @@ static __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int offset) } } sp[0] = value; - sp[1] = JS_NewBool(ctx, done); + sp[1] = js_bool(done); return 0; } @@ -13638,7 +13643,7 @@ static __exception int js_iterator_get_value_done(JSContext *ctx, JSValue *sp) return -1; JS_FreeValue(ctx, obj); sp[-1] = value; - sp[0] = JS_NewBool(ctx, done); + sp[0] = js_bool(done); return 0; } @@ -13657,7 +13662,7 @@ static JSValue js_create_iterator_result(JSContext *ctx, goto fail; } if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_done, - JS_NewBool(ctx, done), JS_PROP_C_W_E) < 0) { + js_bool(done), JS_PROP_C_W_E) < 0) { fail: JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -15038,7 +15043,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, ret = JS_CheckGlobalVar(ctx, atom); if (ret < 0) goto exception; - *sp++ = JS_NewBool(ctx, ret); + *sp++ = js_bool(ret); } BREAK; @@ -15651,7 +15656,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-1] = ret; ret_flag = FALSE; } - sp[0] = JS_NewBool(ctx, ret_flag); + sp[0] = js_bool(ret_flag); sp += 1; } BREAK; @@ -15667,7 +15672,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } else { res = JS_ToBoolFree(ctx, op1); } - sp[-1] = JS_NewBool(ctx, !res); + sp[-1] = js_bool(!res); } BREAK; @@ -16535,7 +16540,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-2]; \ op2 = sp[-1]; \ if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) { \ - sp[-2] = JS_NewBool(ctx, 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--; \ } else { \ if (slow_call) \ @@ -16591,7 +16596,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0); if (unlikely(ret < 0)) goto exception; - *sp++ = JS_NewBool(ctx, ret); + *sp++ = js_bool(ret); } BREAK; @@ -16690,7 +16695,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (unlikely(ret < 0)) goto exception; JS_FreeValue(ctx, sp[-1]); - sp[-1] = JS_NewBool(ctx, ret); + sp[-1] = js_bool(ret); break; case OP_with_make_ref: /* produce a pair object/propname on the stack */ @@ -33689,7 +33694,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) break; case BC_TAG_BOOL_FALSE: case BC_TAG_BOOL_TRUE: - obj = JS_NewBool(ctx, tag - BC_TAG_BOOL_FALSE); + obj = js_bool(tag - BC_TAG_BOOL_FALSE); break; case BC_TAG_INT32: { @@ -34158,7 +34163,7 @@ static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val, if (unlikely(JS_ToFloat64(ctx, &d, argv[0]))) return JS_EXCEPTION; - return JS_NewBool(ctx, isnan(d)); + return js_bool(isnan(d)); } static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val, @@ -34169,7 +34174,7 @@ static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val, if (unlikely(JS_ToFloat64(ctx, &d, argv[0]))) return JS_EXCEPTION; res = isfinite(d); - return JS_NewBool(ctx, res); + return js_bool(res); } static JSValue js_microtask_job(JSContext *ctx, @@ -34466,7 +34471,7 @@ static JSValue js_object_defineProperty(JSContext *ctx, JSValueConst this_val, if (ret < 0) { return JS_EXCEPTION; } else if (magic) { - return JS_NewBool(ctx, ret); + return js_bool(ret); } else { return JS_DupValue(ctx, obj); } @@ -34571,13 +34576,16 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t } else { if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0 || JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable, - JS_NewBool(ctx, (desc.flags & JS_PROP_WRITABLE) != 0), flags) < 0) + js_bool(desc.flags & JS_PROP_WRITABLE), + flags) < 0) goto exception1; } if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable, - JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0), flags) < 0 + js_bool(desc.flags & JS_PROP_ENUMERABLE), + flags) < 0 || JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable, - JS_NewBool(ctx, (desc.flags & JS_PROP_CONFIGURABLE) != 0), flags) < 0) + js_bool(desc.flags & JS_PROP_CONFIGURABLE), + flags) < 0) goto exception1; js_free_desc(ctx, &desc); } @@ -34853,7 +34861,7 @@ static JSValue js_object_isExtensible(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val, @@ -34873,7 +34881,7 @@ static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val if (ret < 0) return JS_EXCEPTION; if (reflect) { - return JS_NewBool(ctx, ret); + return js_bool(ret); } else { if (!ret) return JS_ThrowTypeError(ctx, "proxy preventExtensions handler returned false"); @@ -34904,7 +34912,7 @@ static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_object_hasOwn(JSContext *ctx, JSValueConst this_val, @@ -34930,7 +34938,7 @@ static JSValue js_object_hasOwn(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_object_valueOf(JSContext *ctx, JSValueConst this_val, @@ -35118,7 +35126,7 @@ static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val, res ^= 1; done: js_free_prop_enum(ctx, props, len); - return JS_NewBool(ctx, res); + return js_bool(res); exception: js_free_prop_enum(ctx, props, len); @@ -35218,7 +35226,7 @@ static JSValue js_object___getClass(JSContext *ctx, JSValueConst this_val, static JSValue js_object_is(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - return JS_NewBool(ctx, js_same_value(ctx, argv[0], argv[1])); + return js_bool(js_same_value(ctx, argv[0], argv[1])); } static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj, @@ -35307,7 +35315,7 @@ static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this_val, } JS_FreeValue(ctx, v1); JS_FreeValue(ctx, obj); - return JS_NewBool(ctx, res); + return js_bool(res); exception: JS_FreeValue(ctx, v1); @@ -35334,7 +35342,7 @@ static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_ if (has_prop < 0) goto exception; if (has_prop) { - res = JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0); + res = js_bool(desc.flags & JS_PROP_ENUMERABLE); js_free_desc(ctx, &desc); } else { res = JS_FALSE; @@ -35763,7 +35771,7 @@ static JSValue js_function_hasInstance(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static const JSCFunctionListEntry js_function_proto_funcs[] = { @@ -36194,7 +36202,7 @@ static JSValue js_array_isArray(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_get_this(JSContext *ctx, @@ -36779,7 +36787,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val, } done: JS_FreeValue(ctx, obj); - return JS_NewBool(ctx, res); + return js_bool(res); exception: JS_FreeValue(ctx, obj); @@ -38089,7 +38097,7 @@ static JSValue js_number_isInteger(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_number_isSafeInteger(JSContext *ctx, JSValueConst this_val, @@ -38100,7 +38108,7 @@ static JSValue js_number_isSafeInteger(JSContext *ctx, JSValueConst this_val, return JS_FALSE; if (unlikely(JS_ToFloat64(ctx, &d, argv[0]))) return JS_EXCEPTION; - return JS_NewBool(ctx, is_safe_integer(d)); + return js_bool(is_safe_integer(d)); } static const JSCFunctionListEntry js_number_funcs[] = { @@ -38312,7 +38320,7 @@ static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv) { JSValue val, obj; - val = JS_NewBool(ctx, JS_ToBool(ctx, argv[0])); + val = js_bool(JS_ToBool(ctx, argv[0])); if (!JS_IsUndefined(new_target)) { obj = js_create_from_ctor(ctx, new_target, JS_CLASS_BOOLEAN); if (!JS_IsException(obj)) @@ -39003,7 +39011,7 @@ static JSValue js_string_includes(JSContext *ctx, JSValueConst this_val, done: JS_FreeValue(ctx, str); JS_FreeValue(ctx, v); - return JS_NewBool(ctx, ret); + return js_bool(ret); fail: JS_FreeValue(ctx, str); @@ -40727,7 +40735,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mas } flags = lre_get_flags(re->bytecode->u.str8); - return JS_NewBool(ctx, (flags & mask) != 0); + return js_bool(flags & mask); } static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val) @@ -41144,7 +41152,7 @@ static JSValue js_regexp_test(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; ret = !JS_IsNull(val); JS_FreeValue(ctx, val); - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val, @@ -42004,7 +42012,7 @@ static JSValue json_parse_value(JSParseState *s) case TOK_IDENT: if (s->token.u.ident.atom == JS_ATOM_false || s->token.u.ident.atom == JS_ATOM_true) { - val = JS_NewBool(ctx, (s->token.u.ident.atom == JS_ATOM_true)); + val = js_bool(s->token.u.ident.atom == JS_ATOM_true); } else if (s->token.u.ident.atom == JS_ATOM_null) { val = JS_NULL; } else { @@ -42615,7 +42623,7 @@ static JSValue js_reflect_deleteProperty(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_reflect_get(JSContext *ctx, JSValueConst this_val, @@ -42660,7 +42668,7 @@ static JSValue js_reflect_has(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val, @@ -42688,7 +42696,7 @@ static JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst this_val, @@ -42699,7 +42707,7 @@ static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst this_val, if (ret < 0) return JS_EXCEPTION; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_reflect_ownKeys(JSContext *ctx, JSValueConst this_val, @@ -43098,17 +43106,17 @@ static JSValue js_create_desc(JSContext *ctx, JSValueConst val, } if (flags & JS_PROP_HAS_WRITABLE) { JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable, - JS_NewBool(ctx, (flags & JS_PROP_WRITABLE) != 0), + js_bool(flags & JS_PROP_WRITABLE), JS_PROP_C_W_E); } if (flags & JS_PROP_HAS_ENUMERABLE) { JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable, - JS_NewBool(ctx, (flags & JS_PROP_ENUMERABLE) != 0), + js_bool(flags & JS_PROP_ENUMERABLE), JS_PROP_C_W_E); } if (flags & JS_PROP_HAS_CONFIGURABLE) { JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable, - JS_NewBool(ctx, (flags & JS_PROP_CONFIGURABLE) != 0), + js_bool(flags & JS_PROP_CONFIGURABLE), JS_PROP_C_W_E); } return ret; @@ -44271,7 +44279,7 @@ static JSValue js_map_has(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; key = map_normalize_key(ctx, argv[0]); mr = map_find_record(ctx, s, key); - return JS_NewBool(ctx, (mr != NULL)); + return js_bool(mr != NULL); } static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val, @@ -44872,7 +44880,7 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise, args[0] = rd->resolving_funcs[0]; args[1] = rd->resolving_funcs[1]; args[2] = rd->handler; - args[3] = JS_NewBool(ctx, is_reject); + args[3] = js_bool(is_reject); args[4] = value; JS_EnqueueJob(ctx, promise_reaction_job, 5, args); list_del(&rd->link); @@ -45291,7 +45299,7 @@ static JSValue js_promise_all_resolve_element(JSContext *ctx, return JS_EXCEPTION; if (alreadyCalled) return JS_UNDEFINED; - func_data[0] = JS_NewBool(ctx, TRUE); + func_data[0] = js_bool(TRUE); if (resolve_type == PROMISE_MAGIC_allSettled) { JSValue str; @@ -45407,7 +45415,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val, JS_IteratorClose(ctx, iter, TRUE); goto fail_reject; } - resolve_element_data[0] = JS_NewBool(ctx, FALSE); + resolve_element_data[0] = js_bool(FALSE); resolve_element_data[1] = (JSValueConst)js_int32(index); resolve_element_data[2] = values; resolve_element_data[3] = resolving_funcs[is_promise_any]; @@ -45602,7 +45610,7 @@ static __exception int perform_promise_then(JSContext *ctx, args[0] = rd->resolving_funcs[0]; args[1] = rd->resolving_funcs[1]; args[2] = rd->handler; - args[3] = JS_NewBool(ctx, i); + args[3] = js_bool(i); args[4] = s->promise_result; JS_EnqueueJob(ctx, promise_reaction_job, 5, args); for(i = 0; i < 2; i++) @@ -45767,7 +45775,7 @@ static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx, { JSValueConst func_data[1]; - func_data[0] = (JSValueConst)JS_NewBool(ctx, done); + func_data[0] = (JSValueConst)js_bool(done); return JS_NewCFunctionData(ctx, js_async_from_sync_iterator_unwrap, 1, 0, 1, func_data); } @@ -47669,7 +47677,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) /* Boolean */ ctx->class_proto[JS_CLASS_BOOLEAN] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT], JS_CLASS_BOOLEAN); - JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], JS_NewBool(ctx, FALSE)); + JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], js_bool(FALSE)); JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], js_boolean_proto_funcs, countof(js_boolean_proto_funcs)); JS_NewGlobalCConstructor(ctx, "Boolean", js_boolean_constructor, 1, @@ -47912,7 +47920,7 @@ static JSValue js_array_buffer_isView(JSContext *ctx, res = TRUE; } } - return JS_NewBool(ctx, res); + return js_bool(res); } static const JSCFunctionListEntry js_array_buffer_funcs[] = { @@ -47934,7 +47942,7 @@ static JSValue js_array_buffer_get_detached(JSContext *ctx, return JS_EXCEPTION; if (abuf->shared) return JS_ThrowTypeError(ctx, "detached called on SharedArrayBuffer"); - return JS_NewBool(ctx, abuf->detached); + return js_bool(abuf->detached); } static JSValue js_array_buffer_get_byteLength(JSContext *ctx, @@ -49073,7 +49081,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val, done: if (special == special_includes) - return JS_NewBool(ctx, res >= 0); + return js_bool(res >= 0); else return js_int32(res); @@ -50528,7 +50536,7 @@ static JSValue js_atomics_isLockFree(JSContext *ctx, if (JS_ToInt32Sat(ctx, &v, argv[0])) return JS_EXCEPTION; ret = (v == 1 || v == 2 || v == 4 || v == 8); - return JS_NewBool(ctx, ret); + return js_bool(ret); } typedef struct JSAtomicsWaiter { From 87021c015f61fe5e80f81bbc6bc2fe7460eb9cfa Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 29 Nov 2023 12:36:40 +0100 Subject: [PATCH 5/5] Replace JS_DupValue() calls with js_dup() --- quickjs.c | 709 +++++++++++++++++++++++++++--------------------------- 1 file changed, 355 insertions(+), 354 deletions(-) diff --git a/quickjs.c b/quickjs.c index 7c110fefc..119cc38d6 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1298,6 +1298,15 @@ static JSValue js_bool(JS_BOOL v) return JS_MKVAL(JS_TAG_BOOL, (v != 0)); } +static JSValue js_dup(JSValueConst v) +{ + if (JS_VALUE_HAS_REF_COUNT(v)) { + JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); + p->ref_count++; + } + return (JSValue)v; +} + static void js_trigger_gc(JSRuntime *rt, size_t size) { BOOL force_gc; @@ -1786,7 +1795,7 @@ int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, e->job_func = job_func; e->argc = argc; for(i = 0; i < argc; i++) { - e->argv[i] = JS_DupValue(ctx, argv[i]); + e->argv[i] = js_dup(argv[i]); } list_add_tail(&e->link, &rt->job_list); return 0; @@ -2167,7 +2176,7 @@ JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id) { JSRuntime *rt = ctx->rt; assert(class_id < rt->class_count); - return JS_DupValue(ctx, ctx->class_proto[class_id]); + return js_dup(ctx->class_proto[class_id]); } typedef enum JSFreeModuleEnum { @@ -2975,7 +2984,7 @@ static JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr, assert(!__JS_AtomIsTaggedInt(descr)); assert(descr < rt->atom_size); p = rt->atom_array[descr]; - JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); + js_dup(JS_MKPTR(JS_TAG_STRING, p)); return JS_NewSymbol(ctx, p, atom_type); } @@ -3056,9 +3065,9 @@ static JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, BOOL force_string) p = rt->atom_array[JS_ATOM_empty_string]; } ret_string: - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); + return js_dup(JS_MKPTR(JS_TAG_STRING, p)); } else { - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_SYMBOL, p)); + return js_dup(JS_MKPTR(JS_TAG_SYMBOL, p)); } } } @@ -3445,7 +3454,7 @@ static JSValue js_sub_string(JSContext *ctx, JSString *p, int start, int end) { int len = end - start; if (start == 0 && end == p->len) { - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); + return js_dup(JS_MKPTR(JS_TAG_STRING, p)); } if (p->is_wide_char && len > 0) { JSString *str; @@ -3932,7 +3941,7 @@ const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, BO if (JS_IsException(val)) goto fail; } else { - val = JS_DupValue(ctx, val1); + val = js_dup(val1); } str = JS_VALUE_GET_STRING(val); @@ -4294,7 +4303,7 @@ static no_inline JSShape *js_new_shape2(JSContext *ctx, JSObject *proto, sh->header.ref_count = 1; add_gc_object(rt, &sh->header, JS_GC_OBJ_TYPE_SHAPE); if (proto) - JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, proto)); + js_dup(JS_MKPTR(JS_TAG_OBJECT, proto)); sh->proto = proto; memset(prop_hash_end(sh) - hash_size, 0, sizeof(prop_hash_end(sh)[0]) * hash_size); @@ -4339,7 +4348,7 @@ static JSShape *js_clone_shape(JSContext *ctx, JSShape *sh1) add_gc_object(ctx->rt, &sh->header, JS_GC_OBJ_TYPE_SHAPE); sh->is_hashed = FALSE; if (sh->proto) { - JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, sh->proto)); + js_dup(JS_MKPTR(JS_TAG_OBJECT, sh->proto)); } for(i = 0, pr = get_shape_prop(sh); i < sh->prop_count; i++, pr++) { JS_DupAtom(ctx, pr->atom); @@ -4882,7 +4891,7 @@ static void js_method_set_home_object(JSContext *ctx, JSValueConst func_obj, JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); } if (JS_VALUE_GET_TAG(home_obj) == JS_TAG_OBJECT) - p1 = JS_VALUE_GET_OBJ(JS_DupValue(ctx, home_obj)); + p1 = JS_VALUE_GET_OBJ(js_dup(home_obj)); else p1 = NULL; p->u.func.home_object = p1; @@ -5042,7 +5051,7 @@ JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func, s->data_len = data_len; s->magic = magic; for(i = 0; i < data_len; i++) - s->data[i] = JS_DupValue(ctx, data[i]); + s->data[i] = js_dup(data[i]); JS_SetOpaque(func_obj, s); js_function_set_properties(ctx, func_obj, JS_ATOM_empty_string, length); @@ -6231,7 +6240,7 @@ void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) JSValue JS_GetGlobalObject(JSContext *ctx) { - return JS_DupValue(ctx, ctx->global_obj); + return js_dup(ctx->global_obj); } /* WARNING: obj is freed */ @@ -6765,7 +6774,7 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj, /* Note: for Proxy objects, proto is NULL */ p1 = p1->shape->proto; } while (p1 != NULL); - JS_DupValue(ctx, proto_val); + js_dup(proto_val); } if (js_shape_prepare_update(ctx, p, NULL)) @@ -6827,10 +6836,10 @@ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj) if (!p) val = JS_NULL; else - val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + val = js_dup(JS_MKPTR(JS_TAG_OBJECT, p)); } } else { - val = JS_DupValue(ctx, JS_GetPrototypePrimitive(ctx, obj)); + val = js_dup(JS_GetPrototypePrimitive(ctx, obj)); } return val; } @@ -6878,7 +6887,7 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val, /* slow case if proxy in the prototype chain */ if (unlikely(p->class_id == JS_CLASS_PROXY)) { JSValue obj1; - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, (JSObject *)p)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, (JSObject *)p)); for(;;) { obj1 = JS_GetPrototypeFree(ctx, obj1); if (JS_IsException(obj1)) { @@ -7034,14 +7043,14 @@ JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValueConst obj, } else { JSValue func = JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter); /* Note: the field could be removed in the getter */ - func = JS_DupValue(ctx, func); + func = js_dup(func); return JS_CallFree(ctx, func, this_obj, 0, NULL); } } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) { JSValue val = *pr->u.var_ref->pvalue; if (unlikely(JS_IsUninitialized(val))) return JS_ThrowReferenceErrorUninitialized(ctx, prs->atom); - return JS_DupValue(ctx, val); + return js_dup(val); } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) { /* Instantiate property and retry */ if (JS_AutoInitProperty(ctx, p, prop, pr, prs)) @@ -7053,7 +7062,7 @@ JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValueConst obj, ic->updated = TRUE; ic->updated_offset = add_ic_slot(ctx, ic, prop, p, offset); } - return JS_DupValue(ctx, pr->u.value); + return js_dup(pr->u.value); } } if (unlikely(p->is_exotic)) { @@ -7086,7 +7095,7 @@ JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValueConst obj, /* XXX: should pass throw_ref_error */ /* Note: if 'p' is a prototype, it can be freed in the called function */ - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, p)); retval = em->get_property(ctx, obj1, prop, this_obj); JS_FreeValue(ctx, obj1); return retval; @@ -7098,7 +7107,7 @@ JSValue JS_GetPropertyInternal2(JSContext *ctx, JSValueConst obj, /* Note: if 'p' is a prototype, it can be freed in the called function */ - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, p)); ret = em->get_own_property(ctx, &desc, obj1, prop); JS_FreeValue(ctx, obj1); if (ret < 0) @@ -7148,7 +7157,7 @@ static JSValue JS_GetPropertyInternalWithIC(JSContext *ctx, JSValueConst obj, p = JS_VALUE_GET_OBJ(obj); offset = get_ic_prop_offset(ic, offset, p->shape); if (likely(offset >= 0)) - return JS_DupValue(ctx, p->prop[offset].u.value); + return js_dup(p->prop[offset].u.value); slow_path: return JS_GetPropertyInternal2(ctx, obj, prop, this_obj, ic, throw_ref_error); } @@ -7216,7 +7225,7 @@ static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj, JS_ThrowTypeErrorPrivateNotFound(ctx, prop); return JS_EXCEPTION; } - return JS_DupValue(ctx, pr->u.value); + return js_dup(pr->u.value); } static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj, @@ -7273,9 +7282,9 @@ static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj) JS_FreeValue(ctx, brand); return -1; } - pr->u.value = JS_DupValue(ctx, brand); + pr->u.value = js_dup(brand); } else { - brand = JS_DupValue(ctx, pr->u.value); + brand = js_dup(pr->u.value); } brand_atom = js_symbol_to_atom(ctx, brand); @@ -7604,16 +7613,16 @@ static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc, if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) { desc->flags |= JS_PROP_GETSET; if (pr->u.getset.getter) - desc->getter = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter)); + desc->getter = js_dup(JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter)); if (pr->u.getset.setter) - desc->setter = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter)); + desc->setter = js_dup(JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter)); } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) { JSValue val = *pr->u.var_ref->pvalue; if (unlikely(JS_IsUninitialized(val))) { JS_ThrowReferenceErrorUninitialized(ctx, prs->atom); return -1; } - desc->value = JS_DupValue(ctx, val); + desc->value = js_dup(val); } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) { /* Instantiate property and retry */ if (JS_AutoInitProperty(ctx, p, prop, pr, prs)) @@ -7621,7 +7630,7 @@ static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc, goto retry; } } else { - desc->value = JS_DupValue(ctx, pr->u.value); + desc->value = js_dup(pr->u.value); } } else { /* for consistency, send the exception even if desc is NULL */ @@ -7717,14 +7726,14 @@ int JS_HasProperty(JSContext *ctx, JSValueConst obj, JSAtom prop) const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic; if (em && em->has_property) { /* has_property can free the prototype */ - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, p)); ret = em->has_property(ctx, obj1, prop); JS_FreeValue(ctx, obj1); return ret; } } /* JS_GetOwnPropertyInternal can free the prototype */ - JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + js_dup(JS_MKPTR(JS_TAG_OBJECT, p)); ret = JS_GetOwnPropertyInternal(ctx, NULL, p, prop); JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); if (ret != 0) @@ -7796,7 +7805,7 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, case JS_CLASS_ARRAY: case JS_CLASS_ARGUMENTS: if (unlikely(idx >= p->u.array.count)) goto slow_path; - return JS_DupValue(ctx, p->u.array.u.values[idx]); + return js_dup(p->u.array.u.values[idx]); case JS_CLASS_INT8_ARRAY: if (unlikely(idx >= p->u.array.count)) goto slow_path; return js_int32(p->u.array.u.int8_ptr[idx]); @@ -8086,7 +8095,7 @@ static int call_setter(JSContext *ctx, JSObject *setter, if (likely(setter)) { func = JS_MKPTR(JS_TAG_OBJECT, setter); /* Note: the field could be removed in the setter */ - func = JS_DupValue(ctx, func); + func = js_dup(func); ret = JS_CallFree(ctx, func, this_obj, 1, (JSValueConst *)&val); JS_FreeValue(ctx, val); if (JS_IsException(ret)) @@ -8263,7 +8272,7 @@ static int JS_SetPropertyGeneric(JSContext *ctx, JSValue obj1; JSObject *p; - obj1 = JS_DupValue(ctx, obj); + obj1 = js_dup(obj); for(;;) { p = JS_VALUE_GET_OBJ(obj1); if (p->is_exotic) { @@ -8467,7 +8476,7 @@ int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst this_obj, JSValue obj1; if (em->set_property) { /* set_property can free the prototype */ - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, p1)); ret = em->set_property(ctx, obj1, prop, val, this_obj, flags); JS_FreeValue(ctx, obj1); @@ -8476,7 +8485,7 @@ int JS_SetPropertyInternal2(JSContext *ctx, JSValueConst this_obj, } if (em->get_own_property) { /* get_own_property can free the prototype */ - obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); + obj1 = js_dup(JS_MKPTR(JS_TAG_OBJECT, p1)); ret = em->get_own_property(ctx, &desc, obj1, prop); JS_FreeValue(ctx, obj1); @@ -8815,7 +8824,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p, if (prop_flags != JS_PROP_C_W_E) goto convert_to_array; return add_fast_array_element(ctx, p, - JS_DupValue(ctx, val), flags); + js_dup(val), flags); } else { goto convert_to_array; } @@ -8885,16 +8894,16 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p, pr->u.getset.getter = NULL; if ((flags & JS_PROP_HAS_GET) && JS_IsFunction(ctx, getter)) { pr->u.getset.getter = - JS_VALUE_GET_OBJ(JS_DupValue(ctx, getter)); + JS_VALUE_GET_OBJ(js_dup(getter)); } pr->u.getset.setter = NULL; if ((flags & JS_PROP_HAS_SET) && JS_IsFunction(ctx, setter)) { pr->u.getset.setter = - JS_VALUE_GET_OBJ(JS_DupValue(ctx, setter)); + JS_VALUE_GET_OBJ(js_dup(setter)); } } else { if (flags & JS_PROP_HAS_VALUE) { - pr->u.value = JS_DupValue(ctx, val); + pr->u.value = js_dup(val); } else { pr->u.value = JS_UNDEFINED; } @@ -9005,7 +9014,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, if ((prs->flags & JS_PROP_LENGTH) && (flags & JS_PROP_HAS_VALUE)) { uint32_t array_length; if (JS_ToArrayLengthFree(ctx, &array_length, - JS_DupValue(ctx, val), FALSE)) { + js_dup(val), FALSE)) { return -1; } /* this code relies on the fact that Uint32 are never allocated */ @@ -9073,14 +9082,14 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, if (pr->u.getset.getter) JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter)); if (new_getter) - JS_DupValue(ctx, getter); + js_dup(getter); pr->u.getset.getter = new_getter; } if (flags & JS_PROP_HAS_SET) { if (pr->u.getset.setter) JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter)); if (new_setter) - JS_DupValue(ctx, setter); + js_dup(setter); pr->u.getset.setter = new_setter; } } else { @@ -9117,7 +9126,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, } /* update the reference */ set_value(ctx, pr->u.var_ref->pvalue, - JS_DupValue(ctx, val)); + js_dup(val)); } /* if writable is set to false, no longer a reference (for mapped arguments) */ @@ -9125,7 +9134,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, JSValue val1; if (js_shape_prepare_update(ctx, p, &prs)) return -1; - val1 = JS_DupValue(ctx, *pr->u.var_ref->pvalue); + val1 = js_dup(*pr->u.var_ref->pvalue); free_var_ref(ctx->rt, pr->u.var_ref); pr->u.value = val1; prs->flags &= ~(JS_PROP_TMASK | JS_PROP_WRITABLE); @@ -9134,7 +9143,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, if (flags & JS_PROP_HAS_VALUE) { /* Note: no JS code is executable because 'val' is guaranted to be a Uint32 */ - res = set_array_length(ctx, p, JS_DupValue(ctx, val), + res = set_array_length(ctx, p, js_dup(val), flags); } else { res = TRUE; @@ -9154,7 +9163,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, } else { if (flags & JS_PROP_HAS_VALUE) { JS_FreeValue(ctx, pr->u.value); - pr->u.value = JS_DupValue(ctx, val); + pr->u.value = js_dup(val); } if (flags & JS_PROP_HAS_WRITABLE) { if (js_update_property_flags(ctx, p, &prs, @@ -9195,7 +9204,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, goto redo_prop_update; } if (flags & JS_PROP_HAS_VALUE) { - set_value(ctx, &p->u.array.u.values[idx], JS_DupValue(ctx, val)); + set_value(ctx, &p->u.array.u.values[idx], js_dup(val)); } return TRUE; } @@ -9241,7 +9250,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, return JS_ThrowTypeErrorOrFalse(ctx, flags, "invalid descriptor flags"); } if (flags & JS_PROP_HAS_VALUE) { - return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), JS_DupValue(ctx, val), flags); + return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), js_dup(val), flags); } return TRUE; typed_array_done: ; @@ -9528,7 +9537,7 @@ static JSValue JS_GetGlobalVar(JSContext *ctx, JSAtom prop, /* XXX: should handle JS_PROP_TMASK properties */ if (unlikely(JS_IsUninitialized(pr->u.value))) return JS_ThrowReferenceErrorUninitialized(ctx, prs->atom); - return JS_DupValue(ctx, pr->u.value); + return js_dup(pr->u.value); } return JS_GetPropertyInternal(ctx, ctx->global_obj, prop, ctx->global_obj, throw_ref_error); @@ -9555,14 +9564,14 @@ static int JS_GetGlobalVarRef(JSContext *ctx, JSAtom prop, JSValue *sp) if (unlikely(!(prs->flags & JS_PROP_WRITABLE))) { return JS_ThrowTypeErrorReadOnly(ctx, JS_PROP_THROW, prop); } - sp[0] = JS_DupValue(ctx, ctx->global_var_obj); + sp[0] = js_dup(ctx->global_var_obj); } else { int ret; ret = JS_HasProperty(ctx, ctx->global_obj, prop); if (ret < 0) return -1; if (ret) { - sp[0] = JS_DupValue(ctx, ctx->global_obj); + sp[0] = js_dup(ctx->global_obj); } else { sp[0] = JS_UNDEFINED; } @@ -9875,7 +9884,7 @@ static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint) static JSValue JS_ToPrimitive(JSContext *ctx, JSValueConst val, int hint) { - return JS_ToPrimitiveFree(ctx, JS_DupValue(ctx, val), hint); + return JS_ToPrimitiveFree(ctx, js_dup(val), hint); } void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj) @@ -9944,7 +9953,7 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val) int JS_ToBool(JSContext *ctx, JSValueConst val) { - return JS_ToBoolFree(ctx, JS_DupValue(ctx, val)); + return JS_ToBoolFree(ctx, js_dup(val)); } static int skip_spaces(const char *pc) @@ -10338,7 +10347,7 @@ static JSValue JS_ToNumericFree(JSContext *ctx, JSValue val) static JSValue JS_ToNumeric(JSContext *ctx, JSValueConst val) { - return JS_ToNumericFree(ctx, JS_DupValue(ctx, val)); + return JS_ToNumericFree(ctx, js_dup(val)); } static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres, @@ -10395,12 +10404,12 @@ static inline int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val) int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val) { - return JS_ToFloat64Free(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToFloat64Free(ctx, pres, js_dup(val)); } static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val) { - return JS_ToNumberFree(ctx, JS_DupValue(ctx, val)); + return JS_ToNumberFree(ctx, js_dup(val)); } /* same as JS_ToNumber() but return 0 in case of NaN/Undefined */ @@ -10486,13 +10495,13 @@ static int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val) int JS_ToInt32Sat(JSContext *ctx, int *pres, JSValueConst val) { - return JS_ToInt32SatFree(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToInt32SatFree(ctx, pres, js_dup(val)); } int JS_ToInt32Clamp(JSContext *ctx, int *pres, JSValueConst val, int min, int max, int min_offset) { - int res = JS_ToInt32SatFree(ctx, pres, JS_DupValue(ctx, val)); + int res = JS_ToInt32SatFree(ctx, pres, js_dup(val)); if (res == 0) { if (*pres < min) { *pres += min_offset; @@ -10549,13 +10558,13 @@ static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val) int JS_ToInt64Sat(JSContext *ctx, int64_t *pres, JSValueConst val) { - return JS_ToInt64SatFree(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToInt64SatFree(ctx, pres, js_dup(val)); } int JS_ToInt64Clamp(JSContext *ctx, int64_t *pres, JSValueConst val, int64_t min, int64_t max, int64_t neg_offset) { - int res = JS_ToInt64SatFree(ctx, pres, JS_DupValue(ctx, val)); + int res = JS_ToInt64SatFree(ctx, pres, js_dup(val)); if (res == 0) { if (*pres < 0) *pres += neg_offset; @@ -10623,7 +10632,7 @@ static int JS_ToInt64Free(JSContext *ctx, int64_t *pres, JSValue val) int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val) { - return JS_ToInt64Free(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToInt64Free(ctx, pres, js_dup(val)); } int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val) @@ -10690,7 +10699,7 @@ static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val) int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val) { - return JS_ToInt32Free(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToInt32Free(ctx, pres, js_dup(val)); } static inline int JS_ToUint32Free(JSContext *ctx, uint32_t *pres, JSValue val) @@ -11191,7 +11200,7 @@ JSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val, BOOL is_ToProperty tag = JS_VALUE_GET_NORM_TAG(val); switch(tag) { case JS_TAG_STRING: - return JS_DupValue(ctx, val); + return js_dup(val); case JS_TAG_INT: snprintf(buf, sizeof(buf), "%d", JS_VALUE_GET_INT(val)); str = buf; @@ -11221,7 +11230,7 @@ JSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val, BOOL is_ToProperty goto new_string; case JS_TAG_SYMBOL: if (is_ToPropertyKey) { - return JS_DupValue(ctx, val); + return js_dup(val); } else { return JS_ThrowTypeError(ctx, "cannot convert symbol to string"); } @@ -11771,7 +11780,7 @@ static bf_t *JS_ToBigIntFree(JSContext *ctx, bf_t *buf, JSValue val) static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val) { - return JS_ToBigIntFree(ctx, buf, JS_DupValue(ctx, val)); + return JS_ToBigIntFree(ctx, buf, js_dup(val)); } static __maybe_unused JSValue JS_ToBigIntValueFree(JSContext *ctx, JSValue val) @@ -11830,7 +11839,7 @@ static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val) int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val) { - return JS_ToBigInt64Free(ctx, pres, JS_DupValue(ctx, val)); + return JS_ToBigInt64Free(ctx, pres, js_dup(val)); } static JSBigInt *js_new_bf(JSContext *ctx) @@ -12032,7 +12041,7 @@ static __exception int js_post_inc_slow(JSContext *ctx, return -1; } sp[-1] = op1; - sp[0] = JS_DupValue(ctx, op1); + sp[0] = js_dup(op1); return js_unary_arith_slow(ctx, sp + 1, op - OP_post_dec + OP_dec); } @@ -12880,16 +12889,12 @@ static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2) static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2) { - return js_strict_eq2(ctx, - JS_DupValue(ctx, op1), JS_DupValue(ctx, op2), - JS_EQ_SAME_VALUE); + return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_SAME_VALUE); } static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2) { - return js_strict_eq2(ctx, - JS_DupValue(ctx, op1), JS_DupValue(ctx, op2), - JS_EQ_SAME_VALUE_ZERO); + return js_strict_eq2(ctx, js_dup(op1), js_dup(op2), JS_EQ_SAME_VALUE_ZERO); } static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp, @@ -13120,14 +13125,14 @@ static JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst *argv) return JS_EXCEPTION; } for(i = 0; i < argc; i++) { - tab[i] = JS_DupValue(ctx, argv[i]); + tab[i] = js_dup(argv[i]); } } p->u.array.u.values = tab; p->u.array.count = argc; JS_DefinePropertyValue(ctx, val, JS_ATOM_Symbol_iterator, - JS_DupValue(ctx, ctx->array_proto_values), + js_dup(ctx->array_proto_values), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); /* add callee property to throw a TypeError in strict mode */ JS_DefineProperty(ctx, val, JS_ATOM_callee, JS_UNDEFINED, @@ -13179,17 +13184,17 @@ static JSValue js_build_mapped_arguments(JSContext *ctx, int argc, be normal properties */ for(i = arg_count; i < argc; i++) { if (JS_DefinePropertyValueUint32(ctx, val, i, - JS_DupValue(ctx, argv[i]), + js_dup(argv[i]), JS_PROP_C_W_E) < 0) goto fail; } JS_DefinePropertyValue(ctx, val, JS_ATOM_Symbol_iterator, - JS_DupValue(ctx, ctx->array_proto_values), + js_dup(ctx->array_proto_values), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); /* callee returns this function in non strict mode */ JS_DefinePropertyValue(ctx, val, JS_ATOM_callee, - JS_DupValue(ctx, ctx->rt->current_stack_frame->cur_func), + js_dup(ctx->rt->current_stack_frame->cur_func), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); return val; fail: @@ -13207,7 +13212,7 @@ static JSValue js_build_rest(JSContext *ctx, int first, int argc, JSValueConst * return val; for (i = first; i < argc; i++) { ret = JS_DefinePropertyValueUint32(ctx, val, i - first, - JS_DupValue(ctx, argv[i]), + js_dup(argv[i]), JS_PROP_C_W_E); if (ret < 0) { JS_FreeValue(ctx, val); @@ -13252,7 +13257,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj) return enum_obj; /* fast path: assume no enumerable properties in the prototype chain */ - obj1 = JS_DupValue(ctx, obj); + obj1 = js_dup(obj); for(;;) { obj1 = JS_GetPrototypeFree(ctx, obj1); if (JS_IsNull(obj1)) @@ -13306,7 +13311,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj) slow_path: /* non enumerable properties hide the enumerables ones in the prototype chain */ - obj1 = JS_DupValue(ctx, obj); + obj1 = js_dup(obj); for(;;) { if (JS_GetOwnPropertyNamesInternal(ctx, &tab_atom, &tab_atom_count, JS_VALUE_GET_OBJ(obj1), @@ -13758,7 +13763,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp) /* Handle fast arrays explicitly */ for (i = 0; i < count32; i++) { if (JS_DefinePropertyValueUint32(ctx, sp[-3], pos++, - JS_DupValue(ctx, arrp[i]), JS_PROP_C_W_E) < 0) + js_dup(arrp[i]), JS_PROP_C_W_E) < 0) goto exception; } } else { @@ -13952,7 +13957,7 @@ static JSValue js_instantiate_prototype(JSContext *ctx, JSObject *p, JSAtom atom set_cycle_flag(ctx, obj); set_cycle_flag(ctx, this_val); ret = JS_DefinePropertyValue(ctx, obj, JS_ATOM_constructor, - JS_DupValue(ctx, this_val), + js_dup(this_val), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); if (ret < 0) { JS_FreeValue(ctx, obj); @@ -14040,7 +14045,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, if (class_flags & JS_DEFINE_CLASS_HAS_HERITAGE) { if (JS_IsNull(parent_class)) { parent_proto = JS_NULL; - parent_class = JS_DupValue(ctx, ctx->function_proto); + parent_class = js_dup(ctx->function_proto); } else { if (!JS_IsConstructor(ctx, parent_class)) { JS_ThrowTypeError(ctx, "parent class must be constructor"); @@ -14056,8 +14061,8 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, } } else { /* parent_class is JS_UNDEFINED in this case */ - parent_proto = JS_DupValue(ctx, ctx->class_proto[JS_CLASS_OBJECT]); - parent_class = JS_DupValue(ctx, ctx->function_proto); + parent_proto = js_dup(ctx->class_proto[JS_CLASS_OBJECT]); + parent_class = js_dup(ctx->function_proto); } proto = JS_NewObjectProto(ctx, parent_proto); if (JS_IsException(proto)) @@ -14092,13 +14097,13 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, /* the constructor property must be first. It can be overriden by computed property names */ if (JS_DefinePropertyValue(ctx, proto, JS_ATOM_constructor, - JS_DupValue(ctx, ctor), + js_dup(ctor), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE | JS_PROP_THROW) < 0) goto fail; /* set the prototype property */ if (JS_DefinePropertyValue(ctx, ctor, JS_ATOM_prototype, - JS_DupValue(ctx, proto), JS_PROP_THROW) < 0) + js_dup(proto), JS_PROP_THROW) < 0) goto fail; set_cycle_flag(ctx, ctor); set_cycle_flag(ctx, proto); @@ -14130,9 +14135,9 @@ static void close_var_refs(JSRuntime *rt, JSStackFrame *sf) var_ref = list_entry(el, JSVarRef, header.link); var_idx = var_ref->var_idx; if (var_ref->is_arg) - var_ref->value = JS_DupValueRT(rt, sf->arg_buf[var_idx]); + var_ref->value = js_dup(sf->arg_buf[var_idx]); else - var_ref->value = JS_DupValueRT(rt, sf->var_buf[var_idx]); + var_ref->value = js_dup(sf->var_buf[var_idx]); var_ref->pvalue = &var_ref->value; /* the reference is no longer to a local variable */ var_ref->is_detached = TRUE; @@ -14149,7 +14154,7 @@ static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx, int is_ list_for_each_safe(el, el1, &sf->var_ref_list) { var_ref = list_entry(el, JSVarRef, header.link); if (var_idx == var_ref->var_idx && var_ref->is_arg == is_arg) { - var_ref->value = JS_DupValue(ctx, sf->var_buf[var_idx]); + var_ref->value = js_dup(sf->var_buf[var_idx]); var_ref->pvalue = &var_ref->value; list_del(&var_ref->header.link); /* the reference is no longer to a local variable */ @@ -14471,7 +14476,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, pc += 4; BREAK; CASE(OP_push_const): - *sp++ = JS_DupValue(ctx, b->cpool[get_u32(pc)]); + *sp++ = js_dup(b->cpool[get_u32(pc)]); pc += 4; BREAK; CASE(OP_push_minus1): @@ -14494,10 +14499,10 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, pc += 2; BREAK; CASE(OP_push_const8): - *sp++ = JS_DupValue(ctx, b->cpool[*pc++]); + *sp++ = js_dup(b->cpool[*pc++]); BREAK; CASE(OP_fclosure8): - *sp++ = js_closure(ctx, JS_DupValue(ctx, b->cpool[*pc++]), var_refs, sf); + *sp++ = js_closure(ctx, js_dup(b->cpool[*pc++]), var_refs, sf); if (unlikely(JS_IsException(sp[-1]))) goto exception; BREAK; @@ -14534,7 +14539,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (likely(tag == JS_TAG_OBJECT)) goto normal_this; if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED) { - val = JS_DupValue(ctx, ctx->global_obj); + val = js_dup(ctx->global_obj); } else { val = JS_ToObject(ctx, this_obj); if (JS_IsException(val)) @@ -14542,7 +14547,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } } else { normal_this: - val = JS_DupValue(ctx, this_obj); + val = js_dup(this_obj); } *sp++ = val; } @@ -14574,10 +14579,10 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, goto exception; break; case OP_SPECIAL_OBJECT_THIS_FUNC: - *sp++ = JS_DupValue(ctx, sf->cur_func); + *sp++ = js_dup(sf->cur_func); break; case OP_SPECIAL_OBJECT_NEW_TARGET: - *sp++ = JS_DupValue(ctx, new_target); + *sp++ = js_dup(new_target); break; case OP_SPECIAL_OBJECT_HOME_OBJECT: { @@ -14586,7 +14591,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (unlikely(!p1)) *sp++ = JS_UNDEFINED; else - *sp++ = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1)); + *sp++ = js_dup(JS_MKPTR(JS_TAG_OBJECT, p1)); } break; case OP_SPECIAL_OBJECT_VAR_OBJECT: @@ -14630,36 +14635,36 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp--; BREAK; CASE(OP_dup): - sp[0] = JS_DupValue(ctx, sp[-1]); + sp[0] = js_dup(sp[-1]); sp++; BREAK; CASE(OP_dup2): /* a b -> a b a b */ - sp[0] = JS_DupValue(ctx, sp[-2]); - sp[1] = JS_DupValue(ctx, sp[-1]); + sp[0] = js_dup(sp[-2]); + sp[1] = js_dup(sp[-1]); sp += 2; BREAK; CASE(OP_dup3): /* a b c -> a b c a b c */ - sp[0] = JS_DupValue(ctx, sp[-3]); - sp[1] = JS_DupValue(ctx, sp[-2]); - sp[2] = JS_DupValue(ctx, sp[-1]); + sp[0] = js_dup(sp[-3]); + sp[1] = js_dup(sp[-2]); + sp[2] = js_dup(sp[-1]); sp += 3; BREAK; CASE(OP_dup1): /* a b -> a a b */ sp[0] = sp[-1]; - sp[-1] = JS_DupValue(ctx, sp[-2]); + sp[-1] = js_dup(sp[-2]); sp++; BREAK; CASE(OP_insert2): /* obj a -> a obj a (dup_x1) */ sp[0] = sp[-1]; sp[-1] = sp[-2]; - sp[-2] = JS_DupValue(ctx, sp[0]); + sp[-2] = js_dup(sp[0]); sp++; BREAK; CASE(OP_insert3): /* obj prop a -> a obj prop a (dup_x2) */ sp[0] = sp[-1]; sp[-1] = sp[-2]; sp[-2] = sp[-3]; - sp[-3] = JS_DupValue(ctx, sp[0]); + sp[-3] = js_dup(sp[0]); sp++; BREAK; CASE(OP_insert4): /* this obj prop a -> a this obj prop a */ @@ -14667,7 +14672,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-1] = sp[-2]; sp[-2] = sp[-3]; sp[-3] = sp[-4]; - sp[-4] = JS_DupValue(ctx, sp[0]); + sp[-4] = js_dup(sp[0]); sp++; BREAK; CASE(OP_perm3): /* obj a b -> a obj b (213) */ @@ -14758,7 +14763,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_fclosure): { - JSValue bfunc = JS_DupValue(ctx, b->cpool[get_u32(pc)]); + JSValue bfunc = js_dup(b->cpool[get_u32(pc)]); pc += 4; *sp++ = js_closure(ctx, bfunc, var_refs, sf); if (unlikely(JS_IsException(sp[-1]))) @@ -15137,7 +15142,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int idx; idx = get_u16(pc); pc += 2; - sp[0] = JS_DupValue(ctx, var_buf[idx]); + sp[0] = js_dup(var_buf[idx]); sp++; } BREAK; @@ -15155,7 +15160,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int idx; idx = get_u16(pc); pc += 2; - set_value(ctx, &var_buf[idx], JS_DupValue(ctx, sp[-1])); + set_value(ctx, &var_buf[idx], js_dup(sp[-1])); } BREAK; CASE(OP_get_arg): @@ -15163,7 +15168,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int idx; idx = get_u16(pc); pc += 2; - sp[0] = JS_DupValue(ctx, arg_buf[idx]); + sp[0] = js_dup(arg_buf[idx]); sp++; } BREAK; @@ -15181,58 +15186,58 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int idx; idx = get_u16(pc); pc += 2; - set_value(ctx, &arg_buf[idx], JS_DupValue(ctx, sp[-1])); + set_value(ctx, &arg_buf[idx], js_dup(sp[-1])); } BREAK; - CASE(OP_get_loc8): *sp++ = JS_DupValue(ctx, var_buf[*pc++]); BREAK; + CASE(OP_get_loc8): *sp++ = js_dup(var_buf[*pc++]); BREAK; CASE(OP_put_loc8): set_value(ctx, &var_buf[*pc++], *--sp); BREAK; - CASE(OP_set_loc8): set_value(ctx, &var_buf[*pc++], JS_DupValue(ctx, sp[-1])); BREAK; + CASE(OP_set_loc8): set_value(ctx, &var_buf[*pc++], js_dup(sp[-1])); BREAK; // Observation: get_loc0 and get_loc1 are individually very // frequent opcodes _and_ they are very often paired together, // making them ideal candidates for opcode fusion. CASE(OP_get_loc0_loc1): - *sp++ = JS_DupValue(ctx, var_buf[0]); - *sp++ = JS_DupValue(ctx, var_buf[1]); + *sp++ = js_dup(var_buf[0]); + *sp++ = js_dup(var_buf[1]); BREAK; - CASE(OP_get_loc0): *sp++ = JS_DupValue(ctx, var_buf[0]); BREAK; - CASE(OP_get_loc1): *sp++ = JS_DupValue(ctx, var_buf[1]); BREAK; - CASE(OP_get_loc2): *sp++ = JS_DupValue(ctx, var_buf[2]); BREAK; - CASE(OP_get_loc3): *sp++ = JS_DupValue(ctx, var_buf[3]); BREAK; + CASE(OP_get_loc0): *sp++ = js_dup(var_buf[0]); BREAK; + CASE(OP_get_loc1): *sp++ = js_dup(var_buf[1]); BREAK; + CASE(OP_get_loc2): *sp++ = js_dup(var_buf[2]); BREAK; + CASE(OP_get_loc3): *sp++ = js_dup(var_buf[3]); BREAK; CASE(OP_put_loc0): set_value(ctx, &var_buf[0], *--sp); BREAK; CASE(OP_put_loc1): set_value(ctx, &var_buf[1], *--sp); BREAK; CASE(OP_put_loc2): set_value(ctx, &var_buf[2], *--sp); BREAK; CASE(OP_put_loc3): set_value(ctx, &var_buf[3], *--sp); BREAK; - CASE(OP_set_loc0): set_value(ctx, &var_buf[0], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_loc1): set_value(ctx, &var_buf[1], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_loc2): set_value(ctx, &var_buf[2], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_loc3): set_value(ctx, &var_buf[3], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_get_arg0): *sp++ = JS_DupValue(ctx, arg_buf[0]); BREAK; - CASE(OP_get_arg1): *sp++ = JS_DupValue(ctx, arg_buf[1]); BREAK; - CASE(OP_get_arg2): *sp++ = JS_DupValue(ctx, arg_buf[2]); BREAK; - CASE(OP_get_arg3): *sp++ = JS_DupValue(ctx, arg_buf[3]); BREAK; + CASE(OP_set_loc0): set_value(ctx, &var_buf[0], js_dup(sp[-1])); BREAK; + CASE(OP_set_loc1): set_value(ctx, &var_buf[1], js_dup(sp[-1])); BREAK; + CASE(OP_set_loc2): set_value(ctx, &var_buf[2], js_dup(sp[-1])); BREAK; + CASE(OP_set_loc3): set_value(ctx, &var_buf[3], js_dup(sp[-1])); BREAK; + CASE(OP_get_arg0): *sp++ = js_dup(arg_buf[0]); BREAK; + CASE(OP_get_arg1): *sp++ = js_dup(arg_buf[1]); BREAK; + CASE(OP_get_arg2): *sp++ = js_dup(arg_buf[2]); BREAK; + CASE(OP_get_arg3): *sp++ = js_dup(arg_buf[3]); BREAK; CASE(OP_put_arg0): set_value(ctx, &arg_buf[0], *--sp); BREAK; CASE(OP_put_arg1): set_value(ctx, &arg_buf[1], *--sp); BREAK; CASE(OP_put_arg2): set_value(ctx, &arg_buf[2], *--sp); BREAK; CASE(OP_put_arg3): set_value(ctx, &arg_buf[3], *--sp); BREAK; - CASE(OP_set_arg0): set_value(ctx, &arg_buf[0], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_arg1): set_value(ctx, &arg_buf[1], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_arg2): set_value(ctx, &arg_buf[2], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_arg3): set_value(ctx, &arg_buf[3], JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_get_var_ref0): *sp++ = JS_DupValue(ctx, *var_refs[0]->pvalue); BREAK; - CASE(OP_get_var_ref1): *sp++ = JS_DupValue(ctx, *var_refs[1]->pvalue); BREAK; - CASE(OP_get_var_ref2): *sp++ = JS_DupValue(ctx, *var_refs[2]->pvalue); BREAK; - CASE(OP_get_var_ref3): *sp++ = JS_DupValue(ctx, *var_refs[3]->pvalue); BREAK; + CASE(OP_set_arg0): set_value(ctx, &arg_buf[0], js_dup(sp[-1])); BREAK; + CASE(OP_set_arg1): set_value(ctx, &arg_buf[1], js_dup(sp[-1])); BREAK; + CASE(OP_set_arg2): set_value(ctx, &arg_buf[2], js_dup(sp[-1])); BREAK; + CASE(OP_set_arg3): set_value(ctx, &arg_buf[3], js_dup(sp[-1])); BREAK; + CASE(OP_get_var_ref0): *sp++ = js_dup(*var_refs[0]->pvalue); BREAK; + CASE(OP_get_var_ref1): *sp++ = js_dup(*var_refs[1]->pvalue); BREAK; + CASE(OP_get_var_ref2): *sp++ = js_dup(*var_refs[2]->pvalue); BREAK; + CASE(OP_get_var_ref3): *sp++ = js_dup(*var_refs[3]->pvalue); BREAK; CASE(OP_put_var_ref0): set_value(ctx, var_refs[0]->pvalue, *--sp); BREAK; CASE(OP_put_var_ref1): set_value(ctx, var_refs[1]->pvalue, *--sp); BREAK; CASE(OP_put_var_ref2): set_value(ctx, var_refs[2]->pvalue, *--sp); BREAK; CASE(OP_put_var_ref3): set_value(ctx, var_refs[3]->pvalue, *--sp); BREAK; - CASE(OP_set_var_ref0): set_value(ctx, var_refs[0]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_var_ref1): set_value(ctx, var_refs[1]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_var_ref2): set_value(ctx, var_refs[2]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK; - CASE(OP_set_var_ref3): set_value(ctx, var_refs[3]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK; + CASE(OP_set_var_ref0): set_value(ctx, var_refs[0]->pvalue, js_dup(sp[-1])); BREAK; + CASE(OP_set_var_ref1): set_value(ctx, var_refs[1]->pvalue, js_dup(sp[-1])); BREAK; + CASE(OP_set_var_ref2): set_value(ctx, var_refs[2]->pvalue, js_dup(sp[-1])); BREAK; + CASE(OP_set_var_ref3): set_value(ctx, var_refs[3]->pvalue, js_dup(sp[-1])); BREAK; CASE(OP_get_var_ref): { @@ -15241,7 +15246,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, idx = get_u16(pc); pc += 2; val = *var_refs[idx]->pvalue; - sp[0] = JS_DupValue(ctx, val); + sp[0] = js_dup(val); sp++; } BREAK; @@ -15259,7 +15264,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int idx; idx = get_u16(pc); pc += 2; - set_value(ctx, var_refs[idx]->pvalue, JS_DupValue(ctx, sp[-1])); + set_value(ctx, var_refs[idx]->pvalue, js_dup(sp[-1])); } BREAK; CASE(OP_get_var_ref_check): @@ -15273,7 +15278,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_ThrowReferenceErrorUninitialized2(ctx, b, idx, TRUE); goto exception; } - sp[0] = JS_DupValue(ctx, val); + sp[0] = js_dup(val); sp++; } BREAK; @@ -15321,7 +15326,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, FALSE); goto exception; } - sp[0] = JS_DupValue(ctx, var_buf[idx]); + sp[0] = js_dup(var_buf[idx]); sp++; } BREAK; @@ -15997,7 +16002,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, goto exception; } val = JS_GetPropertyValue(ctx, sp[-2], - JS_DupValue(ctx, sp[-1])); + js_dup(sp[-1])); if (unlikely(JS_IsException(val))) goto exception; sp[0] = val; @@ -16049,7 +16054,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } goto exception; } else { - sp[-3] = JS_DupValue(ctx, ctx->global_obj); + sp[-3] = js_dup(ctx->global_obj); } } else { if (is_strict_mode(ctx)) @@ -16089,7 +16094,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_define_array_el): { int ret; - ret = JS_DefinePropertyValueValue(ctx, sp[-3], JS_DupValue(ctx, sp[-2]), sp[-1], + ret = JS_DefinePropertyValueValue(ctx, sp[-3], js_dup(sp[-2]), sp[-1], JS_PROP_C_W_E | JS_PROP_THROW); sp -= 1; if (unlikely(ret < 0)) @@ -16168,7 +16173,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE); if (JS_IsException(op1)) goto exception; - op1 = JS_ConcatString(ctx, JS_DupValue(ctx, *pv), op1); + op1 = JS_ConcatString(ctx, js_dup(*pv), op1); if (JS_IsException(op1)) goto exception; set_value(ctx, pv, op1); @@ -16177,7 +16182,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, add_loc_slow: /* In case of exception, js_add_slow frees ops[0] and ops[1], so we must duplicate *pv */ - ops[0] = JS_DupValue(ctx, *pv); + ops[0] = js_dup(*pv); ops[1] = sp[-1]; sp--; if (js_add_slow(ctx, ops + 2)) @@ -16385,7 +16390,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, inc_loc_slow: /* must duplicate otherwise the variable value may be destroyed before JS code accesses it */ - op1 = JS_DupValue(ctx, op1); + op1 = js_dup(op1); if (js_unary_arith_slow(ctx, &op1 + 1, OP_inc)) goto exception; set_value(ctx, &var_buf[idx], op1); @@ -16410,7 +16415,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, dec_loc_slow: /* must duplicate otherwise the variable value may be destroyed before JS code accesses it */ - op1 = JS_DupValue(ctx, op1); + op1 = js_dup(op1); if (js_unary_arith_slow(ctx, &op1 + 1, OP_dec)) goto exception; set_value(ctx, &var_buf[idx], op1); @@ -16918,7 +16923,7 @@ static JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor, JSContext *realm; if (JS_IsUndefined(ctor)) { - proto = JS_DupValue(ctx, ctx->class_proto[class_id]); + proto = js_dup(ctx->class_proto[class_id]); } else { proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype); if (JS_IsException(proto)) @@ -16928,7 +16933,7 @@ static JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor, realm = JS_GetFunctionRealm(ctx, ctor); if (!realm) return JS_EXCEPTION; - proto = JS_DupValue(ctx, realm->class_proto[class_id]); + proto = js_dup(realm->class_proto[class_id]); } } obj = JS_NewObjectProtoClass(ctx, proto, class_id); @@ -17041,14 +17046,14 @@ static __exception int async_func_init(JSContext *ctx, JSAsyncFunctionState *s, sf->arg_buf = js_malloc(ctx, sizeof(JSValue) * max_int(local_count, 1)); if (!sf->arg_buf) return -1; - sf->cur_func = JS_DupValue(ctx, func_obj); - s->this_val = JS_DupValue(ctx, this_obj); + sf->cur_func = js_dup(func_obj); + s->this_val = js_dup(this_obj); s->argc = argc; sf->arg_count = arg_buf_len; sf->var_buf = sf->arg_buf + arg_buf_len; sf->cur_sp = sf->var_buf + b->var_count; for(i = 0; i < argc; i++) - sf->arg_buf[i] = JS_DupValue(ctx, argv[i]); + sf->arg_buf[i] = js_dup(argv[i]); n = arg_buf_len + b->var_count; for(i = argc; i < n; i++) sf->arg_buf[i] = JS_UNDEFINED; @@ -17189,7 +17194,7 @@ static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val, case JS_GENERATOR_STATE_SUSPENDED_YIELD_STAR: case JS_GENERATOR_STATE_SUSPENDED_YIELD: /* cur_sp[-1] was set to JS_UNDEFINED in the previous call */ - ret = JS_DupValue(ctx, argv[0]); + ret = js_dup(argv[0]); if (magic == GEN_MAGIC_THROW && s->state == JS_GENERATOR_STATE_SUSPENDED_YIELD) { JS_Throw(ctx, ret); @@ -17237,10 +17242,10 @@ static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val, ret = JS_UNDEFINED; break; case GEN_MAGIC_RETURN: - ret = JS_DupValue(ctx, argv[0]); + ret = js_dup(argv[0]); break; case GEN_MAGIC_THROW: - ret = JS_Throw(ctx, JS_DupValue(ctx, argv[0])); + ret = JS_Throw(ctx, js_dup(argv[0])); break; } break; @@ -17427,10 +17432,10 @@ static JSValue js_async_function_resolve_call(JSContext *ctx, arg = JS_UNDEFINED; s->func_state.throw_flag = is_reject; if (is_reject) { - JS_Throw(ctx, JS_DupValue(ctx, arg)); + JS_Throw(ctx, js_dup(arg)); } else { /* return value of await */ - s->func_state.frame.cur_sp[-1] = JS_DupValue(ctx, arg); + s->func_state.frame.cur_sp[-1] = js_dup(arg); } js_async_function_resume(ctx, s); return JS_UNDEFINED; @@ -17637,7 +17642,7 @@ static void js_async_generator_resolve(JSContext *ctx, BOOL done) { JSValue result; - result = js_create_iterator_result(ctx, JS_DupValue(ctx, value), done); + result = js_create_iterator_result(ctx, js_dup(value), done); /* XXX: better exception handling ? */ js_async_generator_resolve_or_reject(ctx, s, result, 0); JS_FreeValue(ctx, result); @@ -17733,7 +17738,7 @@ static void js_async_generator_resume_next(JSContext *ctx, goto done; case JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD: case JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD_STAR: - value = JS_DupValue(ctx, next->result); + value = js_dup(next->result); if (next->completion_type == GEN_MAGIC_THROW && s->state == JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD) { JS_Throw(ctx, value); @@ -17821,10 +17826,10 @@ static JSValue js_async_generator_resolve_function(JSContext *ctx, assert(s->state == JS_ASYNC_GENERATOR_STATE_EXECUTING); s->func_state.throw_flag = is_reject; if (is_reject) { - JS_Throw(ctx, JS_DupValue(ctx, arg)); + JS_Throw(ctx, js_dup(arg)); } else { /* return value of await */ - s->func_state.frame.cur_sp[-1] = JS_DupValue(ctx, arg); + s->func_state.frame.cur_sp[-1] = js_dup(arg); } js_async_generator_resume_next(ctx, s); } @@ -17859,8 +17864,8 @@ static JSValue js_async_generator_next(JSContext *ctx, JSValueConst this_val, if (!req) goto fail; req->completion_type = magic; - req->result = JS_DupValue(ctx, argv[0]); - req->promise = JS_DupValue(ctx, promise); + req->result = js_dup(argv[0]); + req->promise = js_dup(promise); req->resolving_funcs[0] = resolving_funcs[0]; req->resolving_funcs[1] = resolving_funcs[1]; list_add_tail(&req->link, &s->queue); @@ -20225,7 +20230,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc) cooked = s->token; if (call) { if (JS_DefinePropertyValueUint32(ctx, raw_array, depth, - JS_DupValue(ctx, s->token.u.str.str), + js_dup(s->token.u.str.str), JS_PROP_ENUMERABLE | JS_PROP_THROW) < 0) { return -1; } @@ -25819,7 +25824,7 @@ static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m) return JS_EXCEPTION; m->module_ns = val; } - return JS_DupValue(ctx, m->module_ns); + return js_dup(m->module_ns); } /* Load all the required modules for module 'm' */ @@ -26168,7 +26173,7 @@ JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m) return JS_EXCEPTION; m->meta_obj = obj; } - return JS_DupValue(ctx, obj); + return js_dup(obj); } static JSValue js_import_meta(JSContext *ctx) @@ -26209,7 +26214,7 @@ JSModuleDef *JS_RunModule(JSContext *ctx, const char *basename, } /* Evaluate the module code */ - func_obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m)); + func_obj = js_dup(JS_MKPTR(JS_TAG_MODULE, m)); ret = JS_EvalFunction(ctx, func_obj); if (JS_IsException(ret)) return NULL; @@ -26348,9 +26353,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m) /* if the module was already evaluated, rethrow the exception it raised */ if (m->eval_has_exception) { - return JS_Throw(ctx, JS_DupValue(ctx, m->eval_exception)); + return JS_Throw(ctx, js_dup(m->eval_exception)); } else { - return JS_DupValue(ctx, m->promise); + return js_dup(m->promise); } } @@ -26400,9 +26405,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m) if (s->promise_state != JS_PROMISE_PENDING) { JSValue ret_val2 = ret_val; if (s->promise_state == JS_PROMISE_REJECTED) - ret_val = JS_Throw(ctx, JS_DupValue(ctx, s->promise_result)); + ret_val = JS_Throw(ctx, js_dup(s->promise_result)); else - ret_val = JS_DupValue(ctx, s->promise_result); + ret_val = js_dup(s->promise_result); JS_FreeValue(ctx, ret_val2); } } else { @@ -26417,9 +26422,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m) if (JS_IsException(ret_val)) { /* save the thrown exception value */ m->eval_has_exception = TRUE; - m->eval_exception = JS_DupValue(ctx, ctx->rt->current_exception); + m->eval_exception = js_dup(ctx->rt->current_exception); } else if (!JS_IsUndefined(ret_val)) { - m->promise = JS_DupValue(ctx, ret_val); + m->promise = js_dup(ret_val); } m->eval_mark = FALSE; m->evaluated = TRUE; @@ -31643,7 +31648,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj, m->func_obj = fun_obj; if (js_resolve_module(ctx, m) < 0) goto fail1; - fun_obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m)); + fun_obj = js_dup(JS_MKPTR(JS_TAG_MODULE, m)); } if (flags & JS_EVAL_FLAG_COMPILE_ONLY) { ret_val = fun_obj; @@ -31678,7 +31683,7 @@ static JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj, size_t len; if (!JS_IsString(val)) - return JS_DupValue(ctx, val); + return js_dup(val); str = JS_ToCStringLen(ctx, &len, val); if (!str) return JS_EXCEPTION; @@ -33335,7 +33340,7 @@ static JSValue JS_ReadModule(BCReaderState *s) m = js_new_module_def(ctx, module_name); if (!m) goto fail; - obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m)); + obj = js_dup(JS_MKPTR(JS_TAG_MODULE, m)); if (bc_get_leb128_int(s, &m->req_module_entries_count)) goto fail; if (m->req_module_entries_count != 0) { @@ -33775,7 +33780,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) return JS_ThrowSyntaxError(ctx, "invalid object reference (%u >= %u)", val, s->objects_count); } - obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, s->objects[val])); + obj = js_dup(JS_MKPTR(JS_TAG_OBJECT, s->objects[val])); } break; default: @@ -34103,10 +34108,9 @@ static void JS_SetConstructor2(JSContext *ctx, int proto_flags, int ctor_flags) { JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_prototype, - JS_DupValue(ctx, proto), proto_flags); + js_dup(proto), proto_flags); JS_DefinePropertyValue(ctx, proto, JS_ATOM_constructor, - JS_DupValue(ctx, func_obj), - ctor_flags); + js_dup(func_obj), ctor_flags); set_cycle_flag(ctx, func_obj); set_cycle_flag(ctx, proto); } @@ -34124,7 +34128,7 @@ static void JS_NewGlobalCConstructor2(JSContext *ctx, JSValueConst proto) { JS_DefinePropertyValueStr(ctx, ctx->global_obj, name, - JS_DupValue(ctx, func_obj), + js_dup(func_obj), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); JS_SetConstructor(ctx, func_obj, proto); JS_FreeValue(ctx, func_obj); @@ -34207,7 +34211,7 @@ static JSValue JS_ToObject(JSContext *ctx, JSValueConst val) return JS_ThrowTypeError(ctx, "cannot convert to object"); case JS_TAG_OBJECT: case JS_TAG_EXCEPTION: - return JS_DupValue(ctx, val); + return js_dup(val); case JS_TAG_BIG_INT: obj = JS_NewObjectClass(ctx, JS_CLASS_BIG_INT); goto set_value; @@ -34230,7 +34234,7 @@ static JSValue JS_ToObject(JSContext *ctx, JSValueConst val) obj = JS_NewObjectClass(ctx, JS_CLASS_SYMBOL); set_value: if (!JS_IsException(obj)) - JS_SetObjectData(ctx, obj, JS_DupValue(ctx, val)); + JS_SetObjectData(ctx, obj, js_dup(val)); return obj; } } @@ -34443,7 +34447,7 @@ static JSValue js_object_setPrototypeOf(JSContext *ctx, JSValueConst this_val, obj = argv[0]; if (JS_SetPrototypeInternal(ctx, obj, argv[1], TRUE) < 0) return JS_EXCEPTION; - return JS_DupValue(ctx, obj); + return js_dup(obj); } /* magic = 1 if called as Reflect.defineProperty */ @@ -34473,7 +34477,7 @@ static JSValue js_object_defineProperty(JSContext *ctx, JSValueConst this_val, } else if (magic) { return js_bool(ret); } else { - return JS_DupValue(ctx, obj); + return js_dup(obj); } } @@ -34486,7 +34490,7 @@ static JSValue js_object_defineProperties(JSContext *ctx, JSValueConst this_val, if (JS_ObjectDefineProperties(ctx, obj, argv[1])) return JS_EXCEPTION; else - return JS_DupValue(ctx, obj); + return js_dup(obj); } /* magic = 1 if called as __defineSetter__ */ @@ -34549,7 +34553,7 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t /* Reflect.getOwnPropertyDescriptor case */ if (JS_VALUE_GET_TAG(argv[0]) != JS_TAG_OBJECT) return JS_ThrowTypeErrorNotAnObject(ctx); - obj = JS_DupValue(ctx, argv[0]); + obj = js_dup(argv[0]); } else { obj = JS_ToObject(ctx, argv[0]); if (JS_IsException(obj)) @@ -34570,11 +34574,11 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t goto exception1; flags = JS_PROP_C_W_E | JS_PROP_THROW; if (desc.flags & JS_PROP_GETSET) { - if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, JS_DupValue(ctx, desc.getter), flags) < 0 - || JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, JS_DupValue(ctx, desc.setter), flags) < 0) + if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, js_dup(desc.getter), flags) < 0 + || JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, js_dup(desc.setter), flags) < 0) goto exception1; } else { - if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0 + if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, js_dup(desc.value), flags) < 0 || JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable, js_bool(desc.flags & JS_PROP_WRITABLE), flags) < 0) @@ -34793,7 +34797,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, if (JS_IsException(k)) goto exception; - k = JS_DupValue(ctx, k); + k = js_dup(k); prop = JS_GetPropertyValue(ctx, groups, k); if (JS_IsException(prop)) goto exception; @@ -34802,8 +34806,8 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, prop = JS_NewArray(ctx); if (JS_IsException(prop)) goto exception; - k = JS_DupValue(ctx, k); - prop = JS_DupValue(ctx, prop); + k = js_dup(k); + prop = js_dup(prop); if (JS_SetPropertyValue(ctx, groups, k, prop, JS_PROP_C_W_E|JS_PROP_THROW) < 0) { goto exception; @@ -34875,7 +34879,7 @@ static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val if (reflect) return JS_ThrowTypeErrorNotAnObject(ctx); else - return JS_DupValue(ctx, obj); + return js_dup(obj); } ret = JS_PreventExtensions(ctx, obj); if (ret < 0) @@ -34885,7 +34889,7 @@ static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val } else { if (!ret) return JS_ThrowTypeError(ctx, "proxy preventExtensions handler returned false"); - return JS_DupValue(ctx, obj); + return js_dup(obj); } } @@ -35046,7 +35050,7 @@ static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val, int flags, desc_flags, res; if (!JS_IsObject(obj)) - return JS_DupValue(ctx, obj); + return js_dup(obj); res = JS_PreventExtensions(ctx, obj); if (res < 0) @@ -35080,7 +35084,7 @@ static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val, goto exception; } js_free_prop_enum(ctx, props, len); - return JS_DupValue(ctx, obj); + return js_dup(obj); exception: js_free_prop_enum(ctx, props, len); @@ -35240,7 +35244,7 @@ static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj, if (JS_IsException(ctor)) return ctor; if (JS_IsUndefined(ctor)) - return JS_DupValue(ctx, defaultConstructor); + return js_dup(defaultConstructor); if (!JS_IsObject(ctor)) { JS_FreeValue(ctx, ctor); return JS_ThrowTypeErrorNotAnObject(ctx); @@ -35250,7 +35254,7 @@ static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj, if (JS_IsException(species)) return species; if (JS_IsUndefined(species) || JS_IsNull(species)) - return JS_DupValue(ctx, defaultConstructor); + return js_dup(defaultConstructor); if (!JS_IsConstructor(ctx, species)) { JS_FreeValue(ctx, species); return JS_ThrowTypeError(ctx, "not a constructor"); @@ -35296,7 +35300,7 @@ static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this_val, obj = JS_ToObject(ctx, this_val); if (JS_IsException(obj)) return JS_EXCEPTION; - v1 = JS_DupValue(ctx, v); + v1 = js_dup(v); for(;;) { v1 = JS_GetPrototypeFree(ctx, v1); if (JS_IsException(v1)) @@ -35375,7 +35379,7 @@ static JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst this_val, goto exception; if (has_prop) { if (desc.flags & JS_PROP_GETSET) - res = JS_DupValue(ctx, setter ? desc.setter : desc.getter); + res = js_dup(setter ? desc.setter : desc.getter); else res = JS_UNDEFINED; js_free_desc(ctx, &desc); @@ -35503,7 +35507,7 @@ static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target, realm = JS_GetFunctionRealm(ctx, new_target); if (!realm) goto fail1; - proto = JS_DupValue(ctx, realm->class_proto[func_kind_to_class_id[func_kind]]); + proto = js_dup(realm->class_proto[func_kind_to_class_id[func_kind]]); } ret = JS_SetPrototypeInternal(ctx, obj, proto, TRUE); JS_FreeValue(ctx, proto); @@ -35579,7 +35583,7 @@ static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen, p->fast_array && len == p->u.array.count) { for(i = 0; i < len; i++) { - tab[i] = JS_DupValue(ctx, p->u.array.u.values[i]); + tab[i] = js_dup(p->u.array.u.values[i]); } } else { for(i = 0; i < len; i++) { @@ -35655,11 +35659,11 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, bf = js_malloc(ctx, sizeof(*bf) + arg_count * sizeof(JSValue)); if (!bf) goto exception; - bf->func_obj = JS_DupValue(ctx, this_val); - bf->this_val = JS_DupValue(ctx, argv[0]); + bf->func_obj = js_dup(this_val); + bf->this_val = js_dup(argv[0]); bf->argc = arg_count; for(i = 0; i < arg_count; i++) { - bf->argv[i] = JS_DupValue(ctx, argv[i + 1]); + bf->argv[i] = js_dup(argv[i + 1]); } p->u.bound_function = bf; @@ -35850,7 +35854,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, } else { proto1 = realm->native_error_proto[magic]; } - proto = JS_DupValue(ctx, proto1); + proto = js_dup(proto1); } obj = JS_NewObjectProtoClass(ctx, proto, JS_CLASS_ERROR); JS_FreeValue(ctx, proto); @@ -35949,7 +35953,7 @@ static JSValue js_aggregate_error_constructor(JSContext *ctx, JS_CLASS_ERROR); if (JS_IsException(obj)) return obj; - JS_DefinePropertyValue(ctx, obj, JS_ATOM_errors, JS_DupValue(ctx, errors), + JS_DefinePropertyValue(ctx, obj, JS_ATOM_errors, js_dup(errors), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); return obj; } @@ -35994,14 +35998,14 @@ static int JS_CopySubArray(JSContext *ctx, l = min_int64(l, to + 1); for(j = 0; j < l; j++) { set_value(ctx, &p->u.array.u.values[to - j], - JS_DupValue(ctx, p->u.array.u.values[from - j])); + js_dup(p->u.array.u.values[from - j])); } } else { l = min_int64(l, len - from); l = min_int64(l, len - to); for(j = 0; j < l; j++) { set_value(ctx, &p->u.array.u.values[to + j], - JS_DupValue(ctx, p->u.array.u.values[from + j])); + js_dup(p->u.array.u.values[from + j])); } } i += l; @@ -36037,13 +36041,13 @@ static JSValue js_array_constructor(JSContext *ctx, JSValueConst new_target, return obj; if (argc == 1 && JS_IsNumber(argv[0])) { uint32_t len; - if (JS_ToArrayLengthFree(ctx, &len, JS_DupValue(ctx, argv[0]), TRUE)) + if (JS_ToArrayLengthFree(ctx, &len, js_dup(argv[0]), TRUE)) goto fail; if (JS_SetProperty(ctx, obj, JS_ATOM_length, js_uint32(len)) < 0) goto fail; } else { for(i = 0; i < argc; i++) { - if (JS_SetPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i])) < 0) + if (JS_SetPropertyUint32(ctx, obj, i, js_dup(argv[i])) < 0) goto fail; } } @@ -36093,7 +36097,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, r = JS_NewArray(ctx); if (JS_IsException(r)) goto exception; - stack[0] = JS_DupValue(ctx, items); + stack[0] = js_dup(items); if (js_for_of_start(ctx, &stack[1], FALSE)) goto exception; for (k = 0;; k++) { @@ -36181,7 +36185,7 @@ static JSValue js_array_of(JSContext *ctx, JSValueConst this_val, if (JS_IsException(obj)) return JS_EXCEPTION; for(i = 0; i < argc; i++) { - if (JS_CreateDataPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i]), + if (JS_CreateDataPropertyUint32(ctx, obj, i, js_dup(argv[i]), JS_PROP_THROW) < 0) { goto fail; } @@ -36208,7 +36212,7 @@ static JSValue js_array_isArray(JSContext *ctx, JSValueConst this_val, static JSValue js_get_this(JSContext *ctx, JSValueConst this_val) { - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj, @@ -36300,7 +36304,7 @@ static JSValue js_array_at(JSContext *ctx, JSValueConst this_val, if (idx < 0 || idx >= len) { ret = JS_UNDEFINED; } else if (js_get_fast_array(ctx, obj, &arrp, &count) && count == len) { - ret = JS_DupValue(ctx, arrp[idx]); + ret = js_dup(arrp[idx]); } else if (!JS_TryGetPropertyInt64(ctx, obj, idx, &ret)) { ret = JS_UNDEFINED; } @@ -36353,15 +36357,15 @@ static JSValue js_array_with(JSContext *ctx, JSValueConst this_val, pval = p->u.array.u.values; if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) { for (; i < idx; i++, pval++) - *pval = JS_DupValue(ctx, arrp[i]); - *pval = JS_DupValue(ctx, argv[1]); + *pval = js_dup(arrp[i]); + *pval = js_dup(argv[1]); for (i++, pval++; i < len; i++, pval++) - *pval = JS_DupValue(ctx, arrp[i]); + *pval = js_dup(arrp[i]); } else { for (; i < idx; i++, pval++) if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) goto fill_and_fail; - *pval = JS_DupValue(ctx, argv[1]); + *pval = js_dup(argv[1]); for (i++, pval++; i < len; i++, pval++) { if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) { fill_and_fail: @@ -36432,7 +36436,7 @@ static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val, JS_ThrowTypeError(ctx, "Array loo long"); goto exception; } - if (JS_DefinePropertyValueInt64(ctx, arr, n, JS_DupValue(ctx, e), + if (JS_DefinePropertyValueInt64(ctx, arr, n, js_dup(e), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; n++; @@ -36475,7 +36479,7 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, ret = JS_UNDEFINED; val = JS_UNDEFINED; if (special & special_TA) { - obj = JS_DupValue(ctx, this_val); + obj = js_dup(this_val); len = js_typed_array_get_length_internal(ctx, obj); if (len < 0) goto exception; @@ -36576,7 +36580,7 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, case special_filter: case special_filter | special_TA: if (JS_ToBoolFree(ctx, res)) { - if (JS_DefinePropertyValueInt64(ctx, ret, n++, JS_DupValue(ctx, val), + if (JS_DefinePropertyValueInt64(ctx, ret, n++, js_dup(val), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; } @@ -36630,7 +36634,7 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, acc = JS_UNDEFINED; val = JS_UNDEFINED; if (special & special_TA) { - obj = JS_DupValue(ctx, this_val); + obj = js_dup(this_val); len = js_typed_array_get_length_internal(ctx, obj); if (len < 0) goto exception; @@ -36646,7 +36650,7 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, k = 0; if (argc > 1) { - acc = JS_DupValue(ctx, argv[1]); + acc = js_dup(argv[1]); } else { for(;;) { if (k >= len) { @@ -36733,8 +36737,7 @@ static JSValue js_array_fill(JSContext *ctx, JSValueConst this_val, /* XXX: should special case fast arrays */ while (start < end) { - if (JS_SetPropertyInt64(ctx, obj, start, - JS_DupValue(ctx, argv[0])) < 0) + if (JS_SetPropertyInt64(ctx, obj, start, js_dup(argv[0])) < 0) goto exception; start++; } @@ -36766,8 +36769,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val, } if (js_get_fast_array(ctx, obj, &arrp, &count)) { for (; n < count; n++) { - if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), - JS_DupValue(ctx, arrp[n]), + if (js_strict_eq2(ctx, js_dup(argv[0]), js_dup(arrp[n]), JS_EQ_SAME_VALUE_ZERO)) { res = TRUE; goto done; @@ -36778,7 +36780,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyInt64(ctx, obj, n); if (JS_IsException(val)) goto exception; - if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val, + if (js_strict_eq2(ctx, js_dup(argv[0]), val, JS_EQ_SAME_VALUE_ZERO)) { res = TRUE; break; @@ -36815,8 +36817,8 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val, } if (js_get_fast_array(ctx, obj, &arrp, &count)) { for (; n < count; n++) { - if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), - JS_DupValue(ctx, arrp[n]), JS_EQ_STRICT)) { + if (js_strict_eq2(ctx, js_dup(argv[0]), js_dup(arrp[n]), + JS_EQ_STRICT)) { res = n; goto done; } @@ -36827,7 +36829,7 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val, if (present < 0) goto exception; if (present) { - if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val, JS_EQ_STRICT)) { + if (js_strict_eq2(ctx, js_dup(argv[0]), val, JS_EQ_STRICT)) { res = n; break; } @@ -36867,7 +36869,7 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val, if (present < 0) goto exception; if (present) { - if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val, JS_EQ_STRICT)) { + if (js_strict_eq2(ctx, js_dup(argv[0]), val, JS_EQ_STRICT)) { res = n; break; } @@ -37117,8 +37119,7 @@ static JSValue js_array_push(JSContext *ctx, JSValueConst this_val, from = 0; } for(i = 0; i < argc; i++) { - if (JS_SetPropertyInt64(ctx, obj, from + i, - JS_DupValue(ctx, argv[i])) < 0) + if (JS_SetPropertyInt64(ctx, obj, from + i, js_dup(argv[i])) < 0) goto exception; } if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewInt64(ctx, newLen)) < 0) @@ -37238,7 +37239,7 @@ static JSValue js_array_toReversed(JSContext *ctx, JSValueConst this_val, pval = p->u.array.u.values; if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) { for (; i >= 0; i--, pval++) - *pval = JS_DupValue(ctx, arrp[i]); + *pval = js_dup(arrp[i]); } else { // Query order is observable; test262 expects descending order. for (; i >= 0; i--, pval++) { @@ -37324,7 +37325,7 @@ static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val, js_is_fast_array(ctx, arr)) { /* XXX: should share code with fast array constructor */ for (; k < final && k < count32; k++, n++) { - if (JS_CreateDataPropertyUint32(ctx, arr, n, JS_DupValue(ctx, arrp[k]), JS_PROP_THROW) < 0) + if (JS_CreateDataPropertyUint32(ctx, arr, n, js_dup(arrp[k]), JS_PROP_THROW) < 0) goto exception; } } @@ -37355,7 +37356,7 @@ static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val, } } for (i = 0; i < item_count; i++) { - if (JS_SetPropertyInt64(ctx, obj, start + i, JS_DupValue(ctx, argv[i + 2])) < 0) + if (JS_SetPropertyInt64(ctx, obj, start + i, js_dup(argv[i + 2])) < 0) goto exception; } if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewInt64(ctx, new_len)) < 0) @@ -37431,17 +37432,17 @@ static JSValue js_array_toSpliced(JSContext *ctx, JSValueConst this_val, if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) { for (i = 0; i < start; i++, pval++) - *pval = JS_DupValue(ctx, arrp[i]); + *pval = js_dup(arrp[i]); for (j = 0; j < add; j++, pval++) - *pval = JS_DupValue(ctx, argv[2 + j]); + *pval = js_dup(argv[2 + j]); for (i += del; i < len; i++, pval++) - *pval = JS_DupValue(ctx, arrp[i]); + *pval = js_dup(arrp[i]); } else { for (i = 0; i < start; i++, pval++) if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) goto exception; for (j = 0; j < add; j++, pval++) - *pval = JS_DupValue(ctx, argv[2 + j]); + *pval = js_dup(argv[2 + j]); for (i += del; i < len; i++, pval++) if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) goto exception; @@ -37810,7 +37811,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValueConst this_val, pval = p->u.array.u.values; if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) { for (; i < len; i++, pval++) - *pval = JS_DupValue(ctx, arrp[i]); + *pval = js_dup(arrp[i]); } else { for (; i < len; i++, pval++) { if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) { @@ -37874,7 +37875,7 @@ static JSValue js_create_array(JSContext *ctx, int len, JSValueConst *tab) if (JS_IsException(obj)) return JS_EXCEPTION; for(i = 0; i < len; i++) { - if (JS_CreateDataPropertyUint32(ctx, obj, i, JS_DupValue(ctx, tab[i]), 0) < 0) { + if (JS_CreateDataPropertyUint32(ctx, obj, i, js_dup(tab[i]), 0) < 0) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; } @@ -37983,7 +37984,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, static JSValue js_iterator_proto_iterator(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static const JSCFunctionListEntry js_iterator_proto_funcs[] = { @@ -38132,13 +38133,13 @@ static const JSCFunctionListEntry js_number_funcs[] = { static JSValue js_thisNumberValue(JSContext *ctx, JSValueConst this_val) { if (JS_IsNumber(this_val)) - return JS_DupValue(ctx, this_val); + return js_dup(this_val); if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(this_val); if (p->class_id == JS_CLASS_NUMBER) { if (JS_IsNumber(p->u.object_data)) - return JS_DupValue(ctx, p->u.object_data); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a number"); @@ -38334,7 +38335,7 @@ static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_target, static JSValue js_thisBooleanValue(JSContext *ctx, JSValueConst this_val) { if (JS_VALUE_GET_TAG(this_val) == JS_TAG_BOOL) - return JS_DupValue(ctx, this_val); + return js_dup(this_val); if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(this_val); @@ -38494,13 +38495,13 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target, static JSValue js_thisStringValue(JSContext *ctx, JSValueConst this_val) { if (JS_VALUE_GET_TAG(this_val) == JS_TAG_STRING) - return JS_DupValue(ctx, this_val); + return js_dup(this_val); if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(this_val); if (p->class_id == JS_CLASS_STRING) { if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_STRING) - return JS_DupValue(ctx, p->u.object_data); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a string"); @@ -38749,7 +38750,7 @@ static JSValue js_string_concat(JSContext *ctx, JSValueConst this_val, for (i = 0; i < argc; i++) { if (JS_IsException(r)) break; - r = JS_ConcatString(ctx, r, JS_DupValue(ctx, argv[i])); + r = JS_ConcatString(ctx, r, js_dup(argv[i])); } return r; } @@ -40555,14 +40556,14 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, res = js_same_value(ctx, ctor, new_target); JS_FreeValue(ctx, ctor); if (res) - return JS_DupValue(ctx, pat); + return js_dup(pat); } } re = js_get_regexp(ctx, pat, FALSE); if (re) { - pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->pattern)); + pattern = js_dup(JS_MKPTR(JS_TAG_STRING, re->pattern)); if (JS_IsUndefined(flags1)) { - bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->bytecode)); + bc = js_dup(JS_MKPTR(JS_TAG_STRING, re->bytecode)); goto no_compilation; } else { flags = JS_ToString(ctx, flags1); @@ -40580,11 +40581,11 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, if (JS_IsException(flags)) goto fail; } else { - flags = JS_DupValue(ctx, flags1); + flags = js_dup(flags1); } } else { - pattern = JS_DupValue(ctx, pat); - flags = JS_DupValue(ctx, flags1); + pattern = js_dup(pat); + flags = js_dup(flags1); } if (JS_IsUndefined(pattern)) { pattern = JS_AtomToString(ctx, JS_ATOM_empty_string); @@ -40624,8 +40625,8 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val, if (re1) { if (!JS_IsUndefined(flags1)) return JS_ThrowTypeError(ctx, "flags must be undefined"); - pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->pattern)); - bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->bytecode)); + pattern = js_dup(JS_MKPTR(JS_TAG_STRING, re1->pattern)); + bc = js_dup(JS_MKPTR(JS_TAG_STRING, re1->bytecode)); } else { bc = JS_UNDEFINED; if (JS_IsUndefined(pattern1)) @@ -40645,7 +40646,7 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val, if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex, js_int32(0)) < 0) return JS_EXCEPTION; - return JS_DupValue(ctx, this_val); + return js_dup(this_val); fail: JS_FreeValue(ctx, pattern); JS_FreeValue(ctx, bc); @@ -40952,7 +40953,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, } } if (name && !JS_IsUndefined(indices_groups)) { - val = JS_DupValue(ctx, val); + val = js_dup(val); if (JS_DefinePropertyValueStr(ctx, indices_groups, name, val, prop_flags) < 0) { JS_FreeValue(ctx, val); @@ -40974,7 +40975,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, if (name) { if (JS_DefinePropertyValueStr(ctx, groups, name, - JS_DupValue(ctx, val), + js_dup(val), prop_flags) < 0) { JS_FreeValue(ctx, val); goto fail; @@ -41584,7 +41585,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, tab = JS_NewArray(ctx); if (JS_IsException(tab)) goto exception; - if (JS_DefinePropertyValueInt64(ctx, tab, 0, JS_DupValue(ctx, matched), + if (JS_DefinePropertyValueInt64(ctx, tab, 0, js_dup(matched), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; for(n = 1; n < nCaptures; n++) { @@ -41608,10 +41609,10 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, if (functionalReplace) { if (JS_DefinePropertyValueInt64(ctx, tab, n++, js_int32(position), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; - if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_DupValue(ctx, str), JS_PROP_C_W_E | JS_PROP_THROW) < 0) + if (JS_DefinePropertyValueInt64(ctx, tab, n++, js_dup(str), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; if (!JS_IsUndefined(namedCaptures)) { - if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_DupValue(ctx, namedCaptures), JS_PROP_C_W_E | JS_PROP_THROW) < 0) + if (JS_DefinePropertyValueInt64(ctx, tab, n++, js_dup(namedCaptures), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; } args[0] = JS_UNDEFINED; @@ -41895,7 +41896,7 @@ void JS_AddIntrinsicRegExp(JSContext *ctx) countof(js_regexp_proto_funcs)); obj = JS_NewGlobalCConstructor(ctx, "RegExp", js_regexp_constructor, 2, ctx->class_proto[JS_CLASS_REGEXP]); - ctx->regexp_ctor = JS_DupValue(ctx, obj); + ctx->regexp_ctor = js_dup(obj); JS_SetPropertyFunctionList(ctx, obj, js_regexp_funcs, countof(js_regexp_funcs)); ctx->class_proto[JS_CLASS_REGEXP_STRING_ITERATOR] = @@ -42000,7 +42001,7 @@ static JSValue json_parse_value(JSParseState *s) } break; case TOK_STRING: - val = JS_DupValue(ctx, s->token.u.str.str); + val = js_dup(s->token.u.str.str); if (json_next_token(s)) goto fail; break; @@ -42279,19 +42280,19 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, JS_ThrowTypeError(ctx, "circular reference"); goto exception; } - indent1 = JS_ConcatString(ctx, JS_DupValue(ctx, indent), JS_DupValue(ctx, jsc->gap)); + indent1 = JS_ConcatString(ctx, js_dup(indent), js_dup(jsc->gap)); if (JS_IsException(indent1)) goto exception; if (!JS_IsEmptyString(jsc->gap)) { - sep = JS_ConcatString3(ctx, "\n", JS_DupValue(ctx, indent1), ""); + sep = JS_ConcatString3(ctx, "\n", js_dup(indent1), ""); if (JS_IsException(sep)) goto exception; sep1 = JS_NewString(ctx, " "); if (JS_IsException(sep1)) goto exception; } else { - sep = JS_DupValue(ctx, jsc->empty); - sep1 = JS_DupValue(ctx, jsc->empty); + sep = js_dup(jsc->empty); + sep1 = js_dup(jsc->empty); } v = js_array_push(ctx, jsc->stack, 1, (JSValueConst *)&val, 0); if (check_exception_free(ctx, v)) @@ -42331,7 +42332,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, string_buffer_putc8(jsc->b, ']'); } else { if (!JS_IsUndefined(jsc->property_list)) - tab = JS_DupValue(ctx, jsc->property_list); + tab = js_dup(jsc->property_list); else tab = js_object_keys(ctx, JS_UNDEFINED, 1, (JSValueConst *)&val, JS_ITERATOR_KIND_KEY); if (JS_IsException(tab)) @@ -42345,7 +42346,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, prop = JS_GetPropertyInt64(ctx, tab, i); if (JS_IsException(prop)) goto exception; - v = JS_GetPropertyValue(ctx, val, JS_DupValue(ctx, prop)); + v = JS_GetPropertyValue(ctx, val, js_dup(prop)); if (JS_IsException(v)) goto exception; v = js_json_check(ctx, jsc, val, v, prop); @@ -42489,7 +42490,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj, } } } - space = JS_DupValue(ctx, space0); + space = js_dup(space0); if (JS_IsObject(space)) { JSObject *p = JS_VALUE_GET_OBJ(space); if (p->class_id == JS_CLASS_NUMBER) { @@ -42511,7 +42512,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj, JSString *p = JS_VALUE_GET_STRING(space); jsc->gap = js_sub_string(ctx, p, 0, min_int(p->len, 10)); } else { - jsc->gap = JS_DupValue(ctx, jsc->empty); + jsc->gap = js_dup(jsc->empty); } JS_FreeValue(ctx, space); if (JS_IsException(jsc->gap)) @@ -42520,9 +42521,9 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj, if (JS_IsException(wrapper)) goto exception; if (JS_DefinePropertyValue(ctx, wrapper, JS_ATOM_empty_string, - JS_DupValue(ctx, obj), JS_PROP_C_W_E) < 0) + js_dup(obj), JS_PROP_C_W_E) < 0) goto exception; - val = JS_DupValue(ctx, obj); + val = js_dup(obj); val = js_json_check(ctx, jsc, wrapper, val, jsc->empty); if (JS_IsException(val)) @@ -42691,7 +42692,7 @@ static JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val, if (unlikely(atom == JS_ATOM_NULL)) return JS_EXCEPTION; ret = JS_SetPropertyGeneric(ctx, obj, atom, - JS_DupValue(ctx, val), receiver, 0); + js_dup(val), receiver, 0); JS_FreeAtom(ctx, atom); if (ret < 0) return JS_EXCEPTION; @@ -43039,7 +43040,7 @@ static int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom, return -1; if (JS_IsUndefined(method)) { return JS_SetPropertyGeneric(ctx, s->target, atom, - JS_DupValue(ctx, value), receiver, + js_dup(value), receiver, flags); } atom_val = JS_AtomToValue(ctx, atom); @@ -43093,15 +43094,15 @@ static JSValue js_create_desc(JSContext *ctx, JSValueConst val, if (JS_IsException(ret)) return ret; if (flags & JS_PROP_HAS_GET) { - JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, JS_DupValue(ctx, getter), + JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, js_dup(getter), JS_PROP_C_W_E); } if (flags & JS_PROP_HAS_SET) { - JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, JS_DupValue(ctx, setter), + JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, js_dup(setter), JS_PROP_C_W_E); } if (flags & JS_PROP_HAS_VALUE) { - JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, val), + JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, js_dup(val), JS_PROP_C_W_E); } if (flags & JS_PROP_HAS_WRITABLE) { @@ -43611,8 +43612,8 @@ static JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, obj); return JS_EXCEPTION; } - s->target = JS_DupValue(ctx, target); - s->handler = JS_DupValue(ctx, handler); + s->target = js_dup(target); + s->handler = js_dup(handler); s->is_func = JS_IsFunction(ctx, target); s->is_revoked = FALSE; JS_SetOpaque(obj, s); @@ -43718,13 +43719,13 @@ static JSValue js_symbol_constructor(JSContext *ctx, JSValueConst new_target, static JSValue js_thisSymbolValue(JSContext *ctx, JSValueConst this_val) { if (JS_VALUE_GET_TAG(this_val) == JS_TAG_SYMBOL) - return JS_DupValue(ctx, this_val); + return js_dup(this_val); if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(this_val); if (p->class_id == JS_CLASS_SYMBOL) { if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_SYMBOL) - return JS_DupValue(ctx, p->u.object_data); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a symbol"); @@ -43797,7 +43798,7 @@ static JSValue js_symbol_keyFor(JSContext *ctx, JSValueConst this_val, p = JS_VALUE_GET_PTR(argv[0]); if (p->atom_type != JS_ATOM_TYPE_GLOBAL_SYMBOL) return JS_UNDEFINED; - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); + return js_dup(JS_MKPTR(JS_TAG_STRING, p)); } static const JSCFunctionListEntry js_symbol_funcs[] = { @@ -44089,7 +44090,7 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s, wr->next_weak_ref = *pwr; *pwr = wr; } else { - JS_DupValue(ctx, key); + js_dup(key); } mr->key = (JSValue)key; h = map_hash_key(ctx, key) & (s->hash_size - 1); @@ -44247,8 +44248,8 @@ static JSValue js_map_set(JSContext *ctx, JSValueConst this_val, if (!mr) return JS_EXCEPTION; } - mr->value = JS_DupValue(ctx, value); - return JS_DupValue(ctx, this_val); + mr->value = js_dup(value); + return js_dup(this_val); } static JSValue js_map_get(JSContext *ctx, JSValueConst this_val, @@ -44265,7 +44266,7 @@ static JSValue js_map_get(JSContext *ctx, JSValueConst this_val, if (!mr) return JS_UNDEFINED; else - return JS_DupValue(ctx, mr->value); + return js_dup(mr->value); } static JSValue js_map_has(JSContext *ctx, JSValueConst this_val, @@ -44349,11 +44350,11 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val, if (!mr->empty) { mr->ref_count++; /* must duplicate in case the record is deleted */ - args[1] = JS_DupValue(ctx, mr->key); + args[1] = js_dup(mr->key); if (magic) args[0] = args[1]; else - args[0] = JS_DupValue(ctx, mr->value); + args[0] = js_dup(mr->value); args[2] = (JSValue)this_val; ret = JS_Call(ctx, func, this_arg, 3, (JSValueConst *)args); JS_FreeValue(ctx, args[0]); @@ -44562,7 +44563,7 @@ static JSValue js_create_map_iterator(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, enum_obj); goto fail; } - it->obj = JS_DupValue(ctx, this_val); + it->obj = js_dup(this_val); it->kind = kind; it->cur_record = NULL; JS_SetOpaque(enum_obj, it); @@ -44620,7 +44621,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val, *pdone = FALSE; if (it->kind == JS_ITERATOR_KIND_KEY) { - return JS_DupValue(ctx, mr->key); + return js_dup(mr->key); } else { JSValueConst args[2]; args[0] = mr->key; @@ -44629,7 +44630,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val, else args[1] = mr->value; if (it->kind == JS_ITERATOR_KIND_VALUE) { - return JS_DupValue(ctx, args[1]); + return js_dup(args[1]); } else { return js_create_array(ctx, 2, args); } @@ -44787,7 +44788,7 @@ JSValue JS_PromiseResult(JSContext *ctx, JSValue promise) JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); if (!s) return JS_UNDEFINED; - return JS_DupValue(ctx, s->promise_result); + return js_dup(s->promise_result); } static int js_create_resolving_functions(JSContext *ctx, JSValue *args, @@ -44819,9 +44820,9 @@ static JSValue promise_reaction_job(JSContext *ctx, int argc, if (JS_IsUndefined(handler)) { if (is_reject) { - res = JS_Throw(ctx, JS_DupValue(ctx, arg)); + res = JS_Throw(ctx, js_dup(arg)); } else { - res = JS_DupValue(ctx, arg); + res = js_dup(arg); } } else { res = JS_Call(ctx, handler, JS_UNDEFINED, 1, &arg); @@ -44862,7 +44863,7 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise, if (!s || s->promise_state != JS_PROMISE_PENDING) return; /* should never happen */ - set_value(ctx, &s->promise_result, JS_DupValue(ctx, value)); + set_value(ctx, &s->promise_result, js_dup(value)); s->promise_state = JS_PROMISE_FULFILLED + is_reject; #ifdef DUMP_PROMISE printf("fulfill_or_reject_promise: is_reject=%d\n", is_reject); @@ -44967,7 +44968,7 @@ static int js_create_resolving_functions(JSContext *ctx, } sr->ref_count++; s->presolved = sr; - s->promise = JS_DupValue(ctx, promise); + s->promise = js_dup(promise); JS_SetOpaque(obj, s); js_function_set_properties(ctx, obj, JS_ATOM_empty_string, 1); resolving_funcs[i] = obj; @@ -45146,7 +45147,7 @@ static JSValue js_promise_executor(JSContext *ctx, for(i = 0; i < 2; i++) { if (!JS_IsUndefined(func_data[i])) return JS_ThrowTypeError(ctx, "resolving function already set"); - func_data[i] = JS_DupValue(ctx, argv[i]); + func_data[i] = js_dup(argv[i]); } return JS_UNDEFINED; } @@ -45188,7 +45189,7 @@ static JSValue js_new_promise_capability(JSContext *ctx, goto fail; } for(i = 0; i < 2; i++) - resolving_funcs[i] = JS_DupValue(ctx, s->data[i]); + resolving_funcs[i] = js_dup(s->data[i]); JS_FreeValue(ctx, executor); return result_promise; fail: @@ -45219,7 +45220,7 @@ static JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val, is_same = js_same_value(ctx, ctor, this_val); JS_FreeValue(ctx, ctor); if (is_same) - return JS_DupValue(ctx, argv[0]); + return js_dup(argv[0]); } result_promise = js_new_promise_capability(ctx, resolving_funcs, this_val); if (JS_IsException(result_promise)) @@ -45316,14 +45317,14 @@ static JSValue js_promise_all_resolve_element(JSContext *ctx, goto fail1; if (JS_DefinePropertyValue(ctx, obj, is_reject ? JS_ATOM_reason : JS_ATOM_value, - JS_DupValue(ctx, argv[0]), + js_dup(argv[0]), JS_PROP_C_W_E) < 0) { fail1: JS_FreeValue(ctx, obj); return JS_EXCEPTION; } } else { - obj = JS_DupValue(ctx, argv[0]); + obj = js_dup(argv[0]); } if (JS_DefinePropertyValueUint32(ctx, values, index, obj, JS_PROP_C_W_E) < 0) @@ -45441,9 +45442,9 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val, JS_UNDEFINED, JS_PROP_C_W_E) < 0) goto fail_reject1; reject_element = resolve_element; - resolve_element = JS_DupValue(ctx, resolving_funcs[0]); + resolve_element = js_dup(resolving_funcs[0]); } else { - reject_element = JS_DupValue(ctx, resolving_funcs[1]); + reject_element = js_dup(resolving_funcs[1]); } if (remainingElementsCount_add(ctx, resolve_element_env, 1) < 0) { @@ -45585,11 +45586,11 @@ static __exception int perform_promise_then(JSContext *ctx, return -1; } for(j = 0; j < 2; j++) - rd->resolving_funcs[j] = JS_DupValue(ctx, cap_resolving_funcs[j]); + rd->resolving_funcs[j] = js_dup(cap_resolving_funcs[j]); handler = resolve_reject[i]; if (!JS_IsFunction(ctx, handler)) handler = JS_UNDEFINED; - rd->handler = JS_DupValue(ctx, handler); + rd->handler = js_dup(handler); rd_array[i] = rd; } @@ -45662,14 +45663,14 @@ static JSValue js_promise_finally_value_thunk(JSContext *ctx, JSValueConst this_ int argc, JSValueConst *argv, int magic, JSValue *func_data) { - return JS_DupValue(ctx, func_data[0]); + return js_dup(func_data[0]); } static JSValue js_promise_finally_thrower(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { - return JS_Throw(ctx, JS_DupValue(ctx, func_data[0])); + return JS_Throw(ctx, js_dup(func_data[0])); } static JSValue js_promise_then_finally_func(JSContext *ctx, JSValueConst this_val, @@ -45716,8 +45717,8 @@ static JSValue js_promise_finally(JSContext *ctx, JSValueConst this_val, if (JS_IsException(ctor)) return ctor; if (!JS_IsFunction(ctx, onFinally)) { - then_funcs[0] = JS_DupValue(ctx, onFinally); - then_funcs[1] = JS_DupValue(ctx, onFinally); + then_funcs[0] = js_dup(onFinally); + then_funcs[1] = js_dup(onFinally); } else { func_data[0] = ctor; func_data[1] = onFinally; @@ -45766,7 +45767,7 @@ static JSValue js_async_from_sync_iterator_unwrap(JSContext *ctx, int argc, JSValueConst *argv, int magic, JSValue *func_data) { - return js_create_iterator_result(ctx, JS_DupValue(ctx, argv[0]), + return js_create_iterator_result(ctx, js_dup(argv[0]), JS_ToBool(ctx, func_data[0])); } @@ -45835,7 +45836,7 @@ static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx, JS_FreeValue(ctx, next_method); return JS_EXCEPTION; } - s->sync_iter = JS_DupValue(ctx, sync_iter); + s->sync_iter = js_dup(sync_iter); s->next_method = next_method; JS_SetOpaque(async_iter, s); return async_iter; @@ -45860,7 +45861,7 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValueConst thi } if (magic == GEN_MAGIC_NEXT) { - method = JS_DupValue(ctx, s->next_method); + method = js_dup(s->next_method); } else { method = JS_GetProperty(ctx, s->sync_iter, magic == GEN_MAGIC_RETURN ? JS_ATOM_return : @@ -45869,10 +45870,10 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValueConst thi goto reject; if (JS_IsUndefined(method) || JS_IsNull(method)) { if (magic == GEN_MAGIC_RETURN) { - err = js_create_iterator_result(ctx, JS_DupValue(ctx, argv[0]), TRUE); + err = js_create_iterator_result(ctx, js_dup(argv[0]), TRUE); is_reject = 0; } else { - err = JS_DupValue(ctx, argv[0]); + err = js_dup(argv[0]); is_reject = 1; } goto done_resolve; @@ -46002,7 +46003,7 @@ void JS_AddIntrinsicPromise(JSContext *ctx) countof(js_promise_proto_funcs)); obj1 = JS_NewCFunction2(ctx, js_promise_constructor, "Promise", 1, JS_CFUNC_constructor, 0); - ctx->promise_ctor = JS_DupValue(ctx, obj1); + ctx->promise_ctor = js_dup(obj1); JS_SetPropertyFunctionList(ctx, obj1, js_promise_funcs, countof(js_promise_funcs)); @@ -46399,7 +46400,7 @@ static JSValue JS_SetThisTimeValue(JSContext *ctx, JSValueConst this_val, double if (p->class_id == JS_CLASS_DATE) { JS_FreeValue(ctx, p->u.object_data); p->u.object_data = js_float64(v); - return JS_DupValue(ctx, p->u.object_data); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a Date object"); @@ -47378,19 +47379,19 @@ static JSValue js_bigint_constructor(JSContext *ctx, { if (!JS_IsUndefined(new_target)) return JS_ThrowTypeError(ctx, "not a constructor"); - return JS_ToBigIntCtorFree(ctx, JS_DupValue(ctx, argv[0])); + return JS_ToBigIntCtorFree(ctx, js_dup(argv[0])); } static JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val) { if (JS_IsBigInt(ctx, this_val)) - return JS_DupValue(ctx, this_val); + return js_dup(this_val); if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) { JSObject *p = JS_VALUE_GET_OBJ(this_val); if (p->class_id == JS_CLASS_BIG_INT) { if (JS_IsBigInt(ctx, p->u.object_data)) - return JS_DupValue(ctx, p->u.object_data); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a bigint"); @@ -47509,7 +47510,7 @@ static void JS_AddIntrinsicBasicObjects(JSContext *ctx) ctx->function_proto = JS_NewCFunction3(ctx, js_function_proto, "", 0, JS_CFUNC_generic, 0, ctx->class_proto[JS_CLASS_OBJECT]); - ctx->class_proto[JS_CLASS_BYTECODE_FUNCTION] = JS_DupValue(ctx, ctx->function_proto); + ctx->class_proto[JS_CLASS_BYTECODE_FUNCTION] = js_dup(ctx->function_proto); ctx->class_proto[JS_CLASS_ERROR] = JS_NewObject(ctx); JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ERROR], js_error_proto_funcs, @@ -47580,7 +47581,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) ctx->function_ctor = JS_NewCFunctionMagic(ctx, js_function_constructor, "Function", 1, JS_CFUNC_constructor_or_func_magic, JS_FUNC_NORMAL); - JS_NewGlobalCConstructor2(ctx, JS_DupValue(ctx, ctx->function_ctor), "Function", + JS_NewGlobalCConstructor2(ctx, js_dup(ctx->function_ctor), "Function", ctx->function_proto); /* Error */ @@ -47615,7 +47616,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) obj = JS_NewGlobalCConstructor(ctx, "Array", js_array_constructor, 1, ctx->class_proto[JS_CLASS_ARRAY]); - ctx->array_ctor = JS_DupValue(ctx, obj); + ctx->array_ctor = js_dup(obj); JS_SetPropertyFunctionList(ctx, obj, js_array_funcs, countof(js_array_funcs)); @@ -47749,11 +47750,11 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) /* global properties */ ctx->eval_obj = JS_NewCFunction(ctx, js_global_eval, "eval", 1); JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_eval, - JS_DupValue(ctx, ctx->eval_obj), + js_dup(ctx->eval_obj), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE); JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_globalThis, - JS_DupValue(ctx, ctx->global_obj), + js_dup(ctx->global_obj), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); } @@ -48223,7 +48224,7 @@ static JSValue js_typed_array_get_buffer(JSContext *ctx, if (!p) return JS_EXCEPTION; ta = p->u.typed_array; - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, ta->buffer)); + return js_dup(JS_MKPTR(JS_TAG_OBJECT, ta->buffer)); } static JSValue js_typed_array_get_byteLength(JSContext *ctx, @@ -48289,7 +48290,7 @@ JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj, if (pbytes_per_element) { *pbytes_per_element = 1 << typed_array_size_log2(p->class_id); } - return JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, ta->buffer)); + return js_dup(JS_MKPTR(JS_TAG_OBJECT, ta->buffer)); } /* return NULL if exception. WARNING: any JS call can detach the @@ -48514,7 +48515,7 @@ static JSValue js_typed_array_create(JSContext *ctx, JSValueConst ctor, goto fail; if (argc == 1) { /* ensure that it is large enough */ - if (JS_ToLengthFree(ctx, &len, JS_DupValue(ctx, argv[0]))) + if (JS_ToLengthFree(ctx, &len, js_dup(argv[0]))) goto fail; if (new_len < len) { JS_ThrowTypeError(ctx, "TypedArray length is too small"); @@ -48590,7 +48591,7 @@ static JSValue js_typed_array_from(JSContext *ctx, JSValueConst this_val, arr = JS_NewArray(ctx); if (JS_IsException(arr)) goto exception; - stack[0] = JS_DupValue(ctx, items); + stack[0] = js_dup(items); if (js_for_of_start(ctx, &stack[1], FALSE)) goto exception; for (k = 0;; k++) { @@ -48659,7 +48660,7 @@ static JSValue js_typed_array_of(JSContext *ctx, JSValueConst this_val, return obj; for(i = 0; i < argc; i++) { - if (JS_SetPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i])) < 0) { + if (JS_SetPropertyUint32(ctx, obj, i, js_dup(argv[i])) < 0) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; } @@ -48699,7 +48700,7 @@ static JSValue js_typed_array_copyWithin(JSContext *ctx, JSValueConst this_val, p->u.array.u.uint8_ptr + (from << shift), count << shift); } - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val, @@ -48716,7 +48717,7 @@ static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val, if (p->class_id == JS_CLASS_UINT8C_ARRAY) { int32_t v; - if (JS_ToUint8ClampFree(ctx, &v, JS_DupValue(ctx, argv[0]))) + if (JS_ToUint8ClampFree(ctx, &v, js_dup(argv[0]))) return JS_EXCEPTION; v64 = v; } else if (p->class_id <= JS_CLASS_UINT32_ARRAY) { @@ -48786,7 +48787,7 @@ static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val, default: abort(); } - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val, @@ -49208,7 +49209,7 @@ static JSValue js_typed_array_reverse(JSContext *ctx, JSValueConst this_val, abort(); } } - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val, @@ -49604,7 +49605,7 @@ static JSValue js_typed_array_sort(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } } - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static const JSCFunctionListEntry js_typed_array_base_funcs[] = { @@ -49756,7 +49757,7 @@ static JSValue js_typed_array_constructor_obj(JSContext *ctx, } else { if (js_get_length64(ctx, &len, obj)) goto fail; - arr = JS_DupValue(ctx, obj); + arr = js_dup(obj); } buffer = js_array_buffer_constructor1(ctx, JS_UNDEFINED, @@ -49893,7 +49894,7 @@ static JSValue js_typed_array_constructor(JSContext *ctx, return JS_ThrowRangeError(ctx, "invalid length"); } } - buffer = JS_DupValue(ctx, argv[0]); + buffer = js_dup(argv[0]); } else { if (p->class_id >= JS_CLASS_UINT8C_ARRAY && p->class_id <= JS_CLASS_FLOAT64_ARRAY) { @@ -49992,7 +49993,7 @@ static JSValue js_dataview_constructor(JSContext *ctx, } p = JS_VALUE_GET_OBJ(obj); ta->obj = p; - ta->buffer = JS_VALUE_GET_OBJ(JS_DupValue(ctx, buffer)); + ta->buffer = JS_VALUE_GET_OBJ(js_dup(buffer)); ta->offset = offset; ta->length = len; list_add_tail(&ta->link, &abuf->array_list); @@ -50489,7 +50490,7 @@ static JSValue js_atomics_store(JSContext *ctx, return JS_EXCEPTION; if (size_log2 == 3) { int64_t v64; - ret = JS_ToBigIntValueFree(ctx, JS_DupValue(ctx, argv[2])); + ret = JS_ToBigIntValueFree(ctx, js_dup(argv[2])); if (JS_IsException(ret)) return ret; if (JS_ToBigInt64(ctx, &v64, ret)) { @@ -50502,7 +50503,7 @@ static JSValue js_atomics_store(JSContext *ctx, } else { uint32_t v; /* XXX: spec, would be simpler to return the written value */ - ret = JS_ToIntegerFree(ctx, JS_DupValue(ctx, argv[2])); + ret = JS_ToIntegerFree(ctx, js_dup(argv[2])); if (JS_IsException(ret)) return ret; if (JS_ToUint32(ctx, &v, ret)) { @@ -50824,7 +50825,7 @@ void JS_AddPerformance(JSContext *ctx) js_float64(ctx->time_origin), JS_PROP_ENUMERABLE); JS_DefinePropertyValueStr(ctx, ctx->global_obj, "performance", - JS_DupValue(ctx, performance), + js_dup(performance), JS_PROP_ENUMERABLE); JS_FreeValue(ctx, performance); } @@ -50904,7 +50905,7 @@ static JSValue js_weakref_deref(JSContext *ctx, JSValueConst this_val, int argc, JSWeakRefData *wrd = JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAK_REF); if (!wrd) return JS_EXCEPTION; - return JS_DupValue(ctx, wrd->target); + return js_dup(wrd->target); } static const JSCFunctionListEntry js_weakref_proto_funcs[] = {