diff --git a/quickjs.c b/quickjs.c index 1650f495e..119cc38d6 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 @@ -1249,6 +1286,27 @@ 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 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; @@ -1737,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; @@ -2118,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 { @@ -2926,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); } @@ -3007,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)); } } } @@ -3061,7 +3119,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) @@ -3103,7 +3161,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)) { @@ -3396,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; @@ -3883,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); @@ -4245,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); @@ -4290,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); @@ -4661,7 +4719,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 +4847,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); @@ -4833,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; @@ -4993,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); @@ -6182,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 */ @@ -6353,7 +6411,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; @@ -6716,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)) @@ -6778,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; } @@ -6829,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)) { @@ -6959,7 +7017,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; @@ -6985,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)) @@ -7004,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)) { @@ -7037,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; @@ -7049,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) @@ -7099,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); } @@ -7167,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, @@ -7224,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); @@ -7555,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)) @@ -7572,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 */ @@ -7668,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) @@ -7747,26 +7805,26 @@ 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_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]); + 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]); @@ -7775,10 +7833,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; } @@ -7797,7 +7855,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: @@ -7815,7 +7873,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 +7901,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) @@ -8037,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)) @@ -8078,7 +8136,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 */ @@ -8138,7 +8196,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"); } @@ -8181,7 +8239,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)) { @@ -8214,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) { @@ -8389,7 +8447,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 && @@ -8418,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); @@ -8427,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); @@ -8694,7 +8752,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); } @@ -8706,7 +8764,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); @@ -8766,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; } @@ -8791,7 +8849,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 && @@ -8836,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; } @@ -8956,11 +9014,11 @@ 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 */ - 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); @@ -9024,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 { @@ -9068,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) */ @@ -9076,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); @@ -9085,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; @@ -9105,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, @@ -9146,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; } @@ -9192,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_NewInt32(ctx, idx), JS_DupValue(ctx, val), flags); + return JS_SetPropertyValue(ctx, this_obj, js_int32(idx), js_dup(val), flags); } return TRUE; typed_array_done: ; @@ -9262,7 +9320,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); } @@ -9479,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); @@ -9506,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; } @@ -9826,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) @@ -9895,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) @@ -10088,7 +10146,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 +10226,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: @@ -10228,7 +10286,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 +10309,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); @@ -10289,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, @@ -10346,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 */ @@ -10367,17 +10425,17 @@ 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; - ret = JS_NewFloat64(ctx, d); + ret = js_float64(d); } } break; @@ -10437,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; @@ -10500,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; @@ -10574,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) @@ -10641,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) @@ -11142,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; @@ -11172,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"); } @@ -11554,43 +11612,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) @@ -11756,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) @@ -11815,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) @@ -11960,7 +11984,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 +12018,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; } @@ -12017,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); } @@ -12035,7 +12059,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: @@ -12189,23 +12213,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 +12267,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 +12291,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 +12350,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: @@ -12396,7 +12420,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: @@ -12573,7 +12597,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; @@ -12661,10 +12685,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)) || @@ -12695,7 +12719,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; @@ -12732,7 +12756,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; @@ -12865,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, @@ -12882,7 +12902,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; } @@ -12908,7 +12928,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; } @@ -12942,7 +12962,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; } @@ -13012,7 +13032,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; } @@ -13050,7 +13070,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 +13114,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; @@ -13105,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, @@ -13145,7 +13165,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; @@ -13164,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: @@ -13192,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); @@ -13237,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)) @@ -13291,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), @@ -13591,7 +13611,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; } @@ -13628,7 +13648,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; } @@ -13647,7 +13667,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; @@ -13743,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 { @@ -13762,7 +13782,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; @@ -13937,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); @@ -14025,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"); @@ -14041,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)) @@ -14062,7 +14082,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) { @@ -14077,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); @@ -14115,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; @@ -14134,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 */ @@ -14241,7 +14261,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 +14276,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: @@ -14452,11 +14472,11 @@ 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): - *sp++ = JS_DupValue(ctx, b->cpool[get_u32(pc)]); + *sp++ = js_dup(b->cpool[get_u32(pc)]); pc += 4; BREAK; CASE(OP_push_minus1): @@ -14468,21 +14488,21 @@ 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): - *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; @@ -14519,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)) @@ -14527,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; } @@ -14559,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: { @@ -14571,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: @@ -14615,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 */ @@ -14652,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) */ @@ -14743,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]))) @@ -15028,7 +15048,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; @@ -15122,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; @@ -15140,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): @@ -15148,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; @@ -15166,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): { @@ -15226,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; @@ -15244,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): @@ -15258,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; @@ -15306,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; @@ -15500,7 +15520,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; } @@ -15641,7 +15661,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; @@ -15657,7 +15677,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; @@ -15982,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; @@ -16034,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)) @@ -16074,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)) @@ -16116,10 +16136,10 @@ 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) + + sp[-2] = __JS_NewFloat64(JS_VALUE_GET_FLOAT64(op1) + JS_VALUE_GET_FLOAT64(op2)); sp--; } else { @@ -16144,7 +16164,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; @@ -16153,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); @@ -16162,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)) @@ -16181,10 +16201,10 @@ 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) - + sp[-2] = __JS_NewFloat64(JS_VALUE_GET_FLOAT64(op1) - JS_VALUE_GET_FLOAT64(op2)); sp--; } else { @@ -16213,12 +16233,12 @@ 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); mul_fp_res: - sp[-2] = __JS_NewFloat64(ctx, d); + sp[-2] = __JS_NewFloat64(d); sp--; } else { goto binary_arith_slow; @@ -16234,7 +16254,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; @@ -16255,7 +16275,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,11 +16321,11 @@ 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: - sp[-1] = __JS_NewFloat64(ctx, d); + sp[-1] = __JS_NewFloat64(d); } else { if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; @@ -16321,7 +16341,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 +16358,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,12 +16385,12 @@ 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 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); @@ -16390,12 +16410,12 @@ 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 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); @@ -16407,7 +16427,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 +16444,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)) @@ -16442,9 +16462,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)) @@ -16464,8 +16482,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 +16497,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 +16512,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 +16527,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)) @@ -16534,7 +16545,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) \ @@ -16590,7 +16601,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; @@ -16689,7 +16700,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 */ @@ -16723,14 +16734,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): @@ -16912,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)) @@ -16922,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); @@ -17035,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; @@ -17183,14 +17194,14 @@ 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); 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; @@ -17231,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; @@ -17421,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; @@ -17631,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); @@ -17727,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); @@ -17737,7 +17748,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; @@ -17815,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); } @@ -17853,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); @@ -20219,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; } @@ -25813,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' */ @@ -26162,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) @@ -26203,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; @@ -26342,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); } } @@ -26394,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 { @@ -26411,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; @@ -31637,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; @@ -31672,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; @@ -33329,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) { @@ -33688,7 +33699,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: { @@ -33696,7 +33707,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: @@ -33705,7 +33716,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: @@ -33769,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: @@ -34005,13 +34016,13 @@ 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); 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; @@ -34069,13 +34080,13 @@ 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); 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); @@ -34097,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); } @@ -34118,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); @@ -34157,7 +34167,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, @@ -34168,7 +34178,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, @@ -34201,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; @@ -34214,7 +34224,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: @@ -34224,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; } } @@ -34437,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 */ @@ -34465,9 +34475,9 @@ 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); + return js_dup(obj); } } @@ -34480,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__ */ @@ -34543,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)) @@ -34564,19 +34574,22 @@ 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_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); } @@ -34784,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; @@ -34793,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; @@ -34852,7 +34865,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, @@ -34866,17 +34879,17 @@ 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) 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"); - return JS_DupValue(ctx, obj); + return js_dup(obj); } } @@ -34903,7 +34916,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, @@ -34929,7 +34942,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, @@ -35037,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) @@ -35071,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); @@ -35117,7 +35130,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); @@ -35217,7 +35230,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, @@ -35231,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); @@ -35241,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"); @@ -35287,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)) @@ -35306,7 +35319,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); @@ -35333,7 +35346,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; @@ -35366,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); @@ -35494,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); @@ -35570,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++) { @@ -35646,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; @@ -35659,7 +35672,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 +35684,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)) { @@ -35683,10 +35696,10 @@ 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_NewInt32(ctx, 0); + len_val = js_int32(0); } } JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length, @@ -35762,7 +35775,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[] = { @@ -35841,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); @@ -35940,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; } @@ -35985,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; @@ -36028,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_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++) { - 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; } } @@ -36084,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++) { @@ -36095,7 +36108,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 +36141,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; @@ -36140,7 +36153,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; @@ -36164,7 +36177,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); @@ -36172,12 +36185,12 @@ 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; } } - 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; @@ -36193,13 +36206,13 @@ 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, JSValueConst this_val) { - return JS_DupValue(ctx, this_val); + return js_dup(this_val); } static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj, @@ -36291,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; } @@ -36344,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: @@ -36388,7 +36401,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; @@ -36423,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++; @@ -36466,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; @@ -36499,13 +36512,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,13 +36574,13 @@ 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: 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; } @@ -36584,7 +36597,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; @@ -36621,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; @@ -36637,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) { @@ -36724,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++; } @@ -36757,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; @@ -36769,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; @@ -36778,7 +36789,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); @@ -36806,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; } @@ -36818,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; } @@ -36858,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; } @@ -36942,7 +36953,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; @@ -37108,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) @@ -37229,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++) { @@ -37315,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; } } @@ -37346,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) @@ -37422,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; @@ -37582,7 +37592,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, @@ -37801,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)) { @@ -37865,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; } @@ -37950,7 +37960,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)) @@ -37960,7 +37970,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); @@ -37974,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[] = { @@ -38035,7 +38045,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)) @@ -38047,7 +38057,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: @@ -38088,7 +38098,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, @@ -38099,7 +38109,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[] = { @@ -38123,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"); @@ -38195,7 +38205,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); } @@ -38216,7 +38226,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; @@ -38248,7 +38258,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"); @@ -38311,7 +38321,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)) @@ -38325,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); @@ -38474,7 +38484,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 { @@ -38485,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"); @@ -38668,7 +38678,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 +38731,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; @@ -38740,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; } @@ -38935,7 +38945,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); @@ -39002,7 +39012,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); @@ -39274,13 +39284,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; @@ -40116,7 +40126,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]); @@ -40135,7 +40145,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; @@ -40156,7 +40166,7 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val, } i++; } - return JS_NewFloat64(ctx, r); + return js_float64(r); } } @@ -40219,7 +40229,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) @@ -40239,7 +40249,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 +40263,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 */ @@ -40287,7 +40297,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[] = { @@ -40488,7 +40498,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; } @@ -40546,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); @@ -40571,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); @@ -40615,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)) @@ -40634,9 +40644,9 @@ 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); + return js_dup(this_val); fail: JS_FreeValue(ctx, pattern); JS_FreeValue(ctx, bc); @@ -40726,7 +40736,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) @@ -40872,7 +40882,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 +40893,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); @@ -40943,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); @@ -40965,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; @@ -41067,7 +41077,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 +41096,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; } @@ -41143,7 +41153,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, @@ -41183,7 +41193,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 +41529,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; } @@ -41575,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++) { @@ -41597,12 +41607,12 @@ 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) + 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; @@ -41620,7 +41630,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 +41686,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 +41709,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 +41789,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); @@ -41886,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] = @@ -41991,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; @@ -42003,7 +42013,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 { @@ -42270,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)) @@ -42322,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)) @@ -42336,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); @@ -42480,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) { @@ -42502,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)) @@ -42511,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)) @@ -42614,7 +42624,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, @@ -42659,7 +42669,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, @@ -42682,12 +42692,12 @@ 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; else - return JS_NewBool(ctx, ret); + return js_bool(ret); } static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst this_val, @@ -42698,7 +42708,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, @@ -43030,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); @@ -43084,30 +43094,30 @@ 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) { 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; @@ -43602,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); @@ -43709,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"); @@ -43788,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[] = { @@ -43937,7 +43947,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; } @@ -44080,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); @@ -44238,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, @@ -44256,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, @@ -44270,7 +44280,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, @@ -44311,7 +44321,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, @@ -44340,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]); @@ -44553,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); @@ -44611,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; @@ -44620,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); } @@ -44778,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, @@ -44810,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); @@ -44853,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); @@ -44871,7 +44881,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); @@ -44958,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; @@ -45137,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; } @@ -45179,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: @@ -45210,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)) @@ -45262,7 +45272,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); } @@ -45290,7 +45300,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; @@ -45307,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) @@ -45385,7 +45395,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; @@ -45406,8 +45416,8 @@ 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[1] = (JSValueConst)JS_NewInt32(ctx, index); + 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]; resolve_element_data[4] = resolve_element_env; @@ -45432,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) { @@ -45576,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; } @@ -45601,7 +45611,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++) @@ -45653,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, @@ -45707,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; @@ -45757,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])); } @@ -45766,7 +45776,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); } @@ -45826,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; @@ -45851,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 : @@ -45860,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; @@ -45993,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)); @@ -46389,8 +46399,8 @@ 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); - return JS_DupValue(ctx, p->u.object_data); + p->u.object_data = js_float64(v); + return js_dup(p->u.object_data); } } return JS_ThrowTypeError(ctx, "not a Date object"); @@ -46539,7 +46549,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, @@ -46753,7 +46763,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; @@ -46786,7 +46796,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) { @@ -47073,7 +47083,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); @@ -47141,7 +47151,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, @@ -47170,7 +47180,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); } @@ -47273,7 +47283,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; } @@ -47369,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"); @@ -47500,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, @@ -47571,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 */ @@ -47606,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)); @@ -47657,7 +47667,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)); @@ -47668,7 +47678,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, @@ -47740,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); } @@ -47911,7 +47921,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[] = { @@ -47933,7 +47943,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, @@ -47944,7 +47954,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) @@ -48202,7 +48212,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, @@ -48214,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, @@ -48230,11 +48240,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 +48260,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 @@ -48280,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 @@ -48429,22 +48439,22 @@ 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]); + return js_uint32(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: @@ -48505,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"); @@ -48581,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++) { @@ -48612,7 +48622,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,13 +48654,13 @@ 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; 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; } @@ -48690,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, @@ -48707,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) { @@ -48777,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, @@ -48812,7 +48822,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 +48843,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; @@ -49072,9 +49082,9 @@ 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_NewInt32(ctx, res); + return js_int32(res); exception: return JS_EXCEPTION; @@ -49199,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, @@ -49230,7 +49240,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 +49259,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 +49307,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,27 +49379,27 @@ 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) { - 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) { @@ -49401,11 +49411,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 { @@ -49595,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[] = { @@ -49747,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, @@ -49884,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) { @@ -49983,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); @@ -50023,29 +50033,29 @@ 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) v = bswap32(v); - return JS_NewUint32(ctx, v); + return js_uint32(v); case JS_CLASS_BIG_INT64_ARRAY: { uint64_t v; @@ -50074,7 +50084,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: { @@ -50085,7 +50095,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(); @@ -50448,10 +50458,10 @@ 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); + ret = js_uint32(a); break; case JS_CLASS_BIG_INT64_ARRAY: ret = JS_NewBigInt64(ctx, a); @@ -50480,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)) { @@ -50493,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)) { @@ -50527,7 +50537,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 { @@ -50667,7 +50677,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 +50766,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 +50776,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); @@ -50798,7 +50808,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[] = { @@ -50812,10 +50822,10 @@ 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), + js_dup(performance), JS_PROP_ENUMERABLE); JS_FreeValue(ctx, performance); } @@ -50895,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[] = { 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; }