remove **Free type functions

This commit is contained in:
2026-02-02 08:32:11 -06:00
parent f2a76cbb55
commit be71ae3bba

View File

@@ -1645,8 +1645,7 @@ enum OPCodeEnum {
static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv);
static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv);
static JSValue JS_CallInternal (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags); static JSValue JS_CallInternal (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags);
static JSValue JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static __exception int JS_ToArrayLength (JSContext *ctx, uint32_t *plen, JSValue val, BOOL is_array_ctor);
static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSValue val, BOOL is_array_ctor);
static JSValue JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, int flags, int scope_idx); static JSValue JS_EvalObject (JSContext *ctx, JSValue this_obj, JSValue val, int flags, int scope_idx);
int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop); int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop);
JSValue __attribute__ ((format (printf, 2, 3))) JSValue __attribute__ ((format (printf, 2, 3)))
@@ -1693,10 +1692,6 @@ int JS_SetPropertyInternal (JSContext *ctx, JSValue this_obj, JSValue prop, JSVa
} }
static blob *js_get_blob (JSContext *ctx, JSValue val); static blob *js_get_blob (JSContext *ctx, JSValue val);
static JSValue JS_ToStringFree (JSContext *ctx, JSValue val);
static int JS_ToBoolFree (JSContext *ctx, JSValue val);
static int JS_ToInt32Free (JSContext *ctx, int32_t *pres, JSValue val);
static int JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val);
static JSValue js_new_string8_len (JSContext *ctx, const char *buf, int len); static JSValue js_new_string8_len (JSContext *ctx, const char *buf, int len);
static JSValue js_compile_regexp (JSContext *ctx, JSValue pattern, JSValue flags); static JSValue js_compile_regexp (JSContext *ctx, JSValue pattern, JSValue flags);
static JSValue js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, JSValue bc); static JSValue js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, JSValue bc);
@@ -1705,7 +1700,6 @@ static int JS_NewClass1 (JSRuntime *rt, JSClassID class_id, const JSClassDef *cl
static BOOL js_strict_eq (JSContext *ctx, JSValue op1, JSValue op2); static BOOL js_strict_eq (JSContext *ctx, JSValue op1, JSValue op2);
static JSValue JS_ToObject (JSContext *ctx, JSValue val); static JSValue JS_ToObject (JSContext *ctx, JSValue val);
static JSValue JS_ToObjectFree (JSContext *ctx, JSValue val);
static JSValue js_cell_text (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_text (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
static JSValue js_cell_push (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_push (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
static JSValue js_cell_pop (JSContext *ctx, JSValue this_val, int argc, JSValue *argv); static JSValue js_cell_pop (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
@@ -1718,7 +1712,6 @@ static void free_var_ref (JSRuntime *rt, JSVarRef *var_ref);
static int js_string_compare (JSContext *ctx, const JSText *p1, const JSText *p2); static int js_string_compare (JSContext *ctx, const JSText *p1, const JSText *p2);
static JSValue JS_ToNumber (JSContext *ctx, JSValue val); static JSValue JS_ToNumber (JSContext *ctx, JSValue val);
static int JS_SetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop, JSValue val); static int JS_SetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop, JSValue val);
static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val);
static int JS_GetOwnPropertyInternal (JSContext *ctx, static int JS_GetOwnPropertyInternal (JSContext *ctx,
JSValue *desc, JSValue *desc,
JSRecord *p, JSRecord *p,
@@ -3072,7 +3065,7 @@ static JSText *pretext_concat_value_free (JSContext *ctx, JSText *s, JSValue v)
JSText *p; JSText *p;
if (unlikely (JS_VALUE_GET_TAG (v) != JS_TAG_STRING)) { if (unlikely (JS_VALUE_GET_TAG (v) != JS_TAG_STRING)) {
v = JS_ToStringFree (ctx, v); v = JS_ToString (ctx, v);
if (JS_IsException (v)) return NULL; if (JS_IsException (v)) return NULL;
} }
p = JS_VALUE_GET_STRING (v); p = JS_VALUE_GET_STRING (v);
@@ -3170,7 +3163,7 @@ static JSValue JS_ConcatString3 (JSContext *ctx, const char *str1, JSValue str2,
JSText *p; JSText *p;
if (unlikely (JS_VALUE_GET_TAG (str2) != JS_TAG_STRING)) { if (unlikely (JS_VALUE_GET_TAG (str2) != JS_TAG_STRING)) {
str2 = JS_ToStringFree (ctx, str2); str2 = JS_ToString (ctx, str2);
if (JS_IsException (str2)) goto fail; if (JS_IsException (str2)) goto fail;
} }
p = JS_VALUE_GET_STRING (str2); p = JS_VALUE_GET_STRING (str2);
@@ -3354,13 +3347,13 @@ static int js_string_compare_value (JSContext *ctx, JSValue op1, JSValue op2, BO
static JSValue JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) { static JSValue JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) {
if (unlikely (!JS_IsText (op1))) { if (unlikely (!JS_IsText (op1))) {
op1 = JS_ToStringFree (ctx, op1); op1 = JS_ToString (ctx, op1);
if (JS_IsException (op1)) { if (JS_IsException (op1)) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
} }
if (unlikely (!JS_IsText (op2))) { if (unlikely (!JS_IsText (op2))) {
op2 = JS_ToStringFree (ctx, op2); op2 = JS_ToString (ctx, op2);
if (JS_IsException (op2)) { if (JS_IsException (op2)) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
@@ -4446,12 +4439,6 @@ JSValue JS_GetPrototype (JSContext *ctx, JSValue obj) {
return val; return val;
} }
static JSValue JS_GetPrototypeFree (JSContext *ctx, JSValue obj) {
JSValue obj1;
obj1 = JS_GetPrototype (ctx, obj);
return obj1;
}
/* Get property from object using JSRecord-based lookup */ /* Get property from object using JSRecord-based lookup */
JSValue JS_GetProperty (JSContext *ctx, JSValue obj, JSValue prop) { JSValue JS_GetProperty (JSContext *ctx, JSValue obj, JSValue prop) {
if (JS_IsNull (obj)) return JS_NULL; if (JS_IsNull (obj)) return JS_NULL;
@@ -5173,7 +5160,7 @@ void *JS_GetAnyOpaque (JSValue obj, JSClassID *class_id) {
return REC_GET_OPAQUE(p); return REC_GET_OPAQUE(p);
} }
static int JS_ToBoolFree (JSContext *ctx, JSValue val) { int JS_ToBool (JSContext *ctx, JSValue val) {
uint32_t tag = JS_VALUE_GET_TAG (val); uint32_t tag = JS_VALUE_GET_TAG (val);
/* Check for pointer types first (new tagging system) */ /* Check for pointer types first (new tagging system) */
@@ -5212,10 +5199,6 @@ static int JS_ToBoolFree (JSContext *ctx, JSValue val) {
} }
} }
int JS_ToBool (JSContext *ctx, JSValue val) {
return JS_ToBoolFree (ctx, val);
}
static int skip_spaces (const char *pc) { static int skip_spaces (const char *pc) {
const uint8_t *p, *p_next, *p_start; const uint8_t *p, *p_next, *p_start;
uint32_t c; uint32_t c;
@@ -5419,7 +5402,7 @@ mem_error:
goto done; goto done;
} }
static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val) { static JSValue JS_ToNumber (JSContext *ctx, JSValue val) {
uint32_t tag; uint32_t tag;
JSValue ret; JSValue ret;
@@ -5456,15 +5439,11 @@ static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val) {
return ret; return ret;
} }
static JSValue JS_ToNumber (JSContext *ctx, JSValue val) { static __exception int __JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) {
return JS_ToNumberFree (ctx, val);
}
static __exception int __JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) {
double d; double d;
uint32_t tag; uint32_t tag;
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) goto fail; if (JS_IsException (val)) goto fail;
tag = JS_VALUE_GET_NORM_TAG (val); tag = JS_VALUE_GET_NORM_TAG (val);
switch (tag) { switch (tag) {
@@ -5484,7 +5463,7 @@ fail:
return -1; return -1;
} }
static inline int JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) { int JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) {
uint32_t tag; uint32_t tag;
tag = JS_VALUE_GET_TAG (val); tag = JS_VALUE_GET_TAG (val);
@@ -5495,16 +5474,12 @@ static inline int JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) {
*pres = JS_VALUE_GET_FLOAT64 (val); *pres = JS_VALUE_GET_FLOAT64 (val);
return 0; return 0;
} else { } else {
return __JS_ToFloat64Free (ctx, pres, val); return __JS_ToFloat64 (ctx, pres, val);
} }
} }
int JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) {
return JS_ToFloat64Free (ctx, pres, val);
}
/* Note: the integer value is satured to 32 bits */ /* Note: the integer value is satured to 32 bits */
static int JS_ToInt32SatFree (JSContext *ctx, int *pres, JSValue val) { int JS_ToInt32Sat (JSContext *ctx, int *pres, JSValue val) {
uint32_t tag; uint32_t tag;
int ret; int ret;
@@ -5530,7 +5505,7 @@ redo:
ret = (int)d; ret = (int)d;
} break; } break;
default: default:
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) { if (JS_IsException (val)) {
*pres = 0; *pres = 0;
return -1; return -1;
@@ -5541,12 +5516,8 @@ redo:
return 0; return 0;
} }
int JS_ToInt32Sat (JSContext *ctx, int *pres, JSValue val) {
return JS_ToInt32SatFree (ctx, pres, val);
}
int JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, int min_offset) { int JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, int min_offset) {
int res = JS_ToInt32SatFree (ctx, pres, val); int res = JS_ToInt32Sat (ctx, pres, val);
if (res == 0) { if (res == 0) {
if (*pres < min) { if (*pres < min) {
*pres += min_offset; *pres += min_offset;
@@ -5558,7 +5529,7 @@ int JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, i
return res; return res;
} }
static int JS_ToInt64SatFree (JSContext *ctx, int64_t *pres, JSValue val) { int JS_ToInt64Sat (JSContext *ctx, int64_t *pres, JSValue val) {
uint32_t tag; uint32_t tag;
redo: redo:
@@ -5585,7 +5556,7 @@ redo:
} }
return 0; return 0;
default: default:
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) { if (JS_IsException (val)) {
*pres = 0; *pres = 0;
return -1; return -1;
@@ -5594,12 +5565,8 @@ redo:
} }
} }
int JS_ToInt64Sat (JSContext *ctx, int64_t *pres, JSValue val) {
return JS_ToInt64SatFree (ctx, pres, val);
}
int JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, int64_t max, int64_t neg_offset) { int JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, int64_t max, int64_t neg_offset) {
int res = JS_ToInt64SatFree (ctx, pres, val); int res = JS_ToInt64Sat (ctx, pres, val);
if (res == 0) { if (res == 0) {
if (*pres < 0) *pres += neg_offset; if (*pres < 0) *pres += neg_offset;
if (*pres < min) if (*pres < min)
@@ -5610,9 +5577,9 @@ int JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, in
return res; return res;
} }
/* Same as JS_ToInt32Free() but with a 64 bit result. Return (<0, 0) /* Same as JS_ToInt32() but with a 64 bit result. Return (<0, 0)
in case of exception */ in case of exception */
static int JS_ToInt64Free (JSContext *ctx, int64_t *pres, JSValue val) { int JS_ToInt64 (JSContext *ctx, int64_t *pres, JSValue val) {
uint32_t tag; uint32_t tag;
int64_t ret; int64_t ret;
@@ -5647,7 +5614,7 @@ redo:
} }
} break; } break;
default: default:
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) { if (JS_IsException (val)) {
*pres = 0; *pres = 0;
return -1; return -1;
@@ -5658,12 +5625,8 @@ redo:
return 0; return 0;
} }
int JS_ToInt64 (JSContext *ctx, int64_t *pres, JSValue val) {
return JS_ToInt64Free (ctx, pres, val);
}
/* return (<0, 0) in case of exception */ /* return (<0, 0) in case of exception */
static int JS_ToInt32Free (JSContext *ctx, int32_t *pres, JSValue val) { int JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) {
uint32_t tag; uint32_t tag;
int32_t ret; int32_t ret;
@@ -5701,7 +5664,7 @@ redo:
default: default:
*pres = 0; *pres = 0;
return -1; return -1;
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) { if (JS_IsException (val)) {
*pres = 0; *pres = 0;
return -1; return -1;
@@ -5712,15 +5675,7 @@ redo:
return 0; return 0;
} }
int JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) { static __exception int JS_ToArrayLength (JSContext *ctx, uint32_t *plen, JSValue val, BOOL is_array_ctor) {
return JS_ToInt32Free (ctx, pres, val);
}
static inline int JS_ToUint32Free (JSContext *ctx, uint32_t *pres, JSValue val) {
return JS_ToInt32Free (ctx, (int32_t *)pres, val);
}
static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSValue val, BOOL is_array_ctor) {
uint32_t tag, len; uint32_t tag, len;
tag = JS_VALUE_GET_TAG (val); tag = JS_VALUE_GET_TAG (val);
@@ -5744,19 +5699,19 @@ static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSV
uint32_t len1; uint32_t len1;
if (is_array_ctor) { if (is_array_ctor) {
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) return -1; if (JS_IsException (val)) return -1;
/* cannot recurse because val is a number */ /* cannot recurse because val is a number */
if (JS_ToArrayLengthFree (ctx, &len, val, TRUE)) return -1; if (JS_ToArrayLength (ctx, &len, val, TRUE)) return -1;
} else { } else {
/* legacy behavior: must do the conversion twice and compare */ /* legacy behavior: must do the conversion twice and compare */
if (JS_ToUint32 (ctx, &len, val)) { if (JS_ToUint32 (ctx, &len, val)) {
return -1; return -1;
} }
val = JS_ToNumberFree (ctx, val); val = JS_ToNumber (ctx, val);
if (JS_IsException (val)) return -1; if (JS_IsException (val)) return -1;
/* cannot recurse because val is a number */ /* cannot recurse because val is a number */
if (JS_ToArrayLengthFree (ctx, &len1, val, FALSE)) return -1; if (JS_ToArrayLength (ctx, &len1, val, FALSE)) return -1;
if (len1 != len) { if (len1 != len) {
fail: fail:
JS_ThrowRangeError (ctx, "invalid array length"); JS_ThrowRangeError (ctx, "invalid array length");
@@ -5774,7 +5729,7 @@ static __exception int JS_ToArrayLengthFree (JSContext *ctx, uint32_t *plen, JSV
/* convert a value to a length between 0 and MAX_SAFE_INTEGER. /* convert a value to a length between 0 and MAX_SAFE_INTEGER.
return -1 for exception */ return -1 for exception */
static __exception int JS_ToLengthFree (JSContext *ctx, int64_t *plen, JSValue val) { static __exception int JS_ToLength (JSContext *ctx, int64_t *plen, JSValue val) {
int res = JS_ToInt64Clamp (ctx, plen, val, 0, MAX_SAFE_INTEGER, 0); int res = JS_ToInt64Clamp (ctx, plen, val, 0, MAX_SAFE_INTEGER, 0);
return res; return res;
} }
@@ -5850,12 +5805,6 @@ JSValue JS_ToString (JSContext *ctx, JSValue val) {
return JS_ToStringInternal (ctx, val, FALSE); return JS_ToStringInternal (ctx, val, FALSE);
} }
static JSValue JS_ToStringFree (JSContext *ctx, JSValue val) {
JSValue ret;
ret = JS_ToString (ctx, val);
return ret;
}
JSValue JS_ToPropertyKey (JSContext *ctx, JSValue val) { JSValue JS_ToPropertyKey (JSContext *ctx, JSValue val) {
/* Objects are handled directly via objkey map, not through atoms */ /* Objects are handled directly via objkey map, not through atoms */
if (JS_IsRecord (val)) { return val; } if (JS_IsRecord (val)) { return val; }
@@ -6444,10 +6393,10 @@ static no_inline int js_not_slow (JSContext *ctx, JSValue *sp) {
JSValue op1; JSValue op1;
op1 = sp[-1]; op1 = sp[-1];
op1 = JS_ToNumberFree (ctx, op1); op1 = JS_ToNumber (ctx, op1);
if (JS_IsException (op1)) goto exception; if (JS_IsException (op1)) goto exception;
int32_t v1; int32_t v1;
if (unlikely (JS_ToInt32Free (ctx, &v1, op1))) goto exception; if (unlikely (JS_ToInt32 (ctx, &v1, op1))) goto exception;
sp[-1] = JS_NewInt32 (ctx, ~v1); sp[-1] = JS_NewInt32 (ctx, ~v1);
return 0; return 0;
exception: exception:
@@ -6485,11 +6434,11 @@ js_binary_arith_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) {
goto handle_float64; goto handle_float64;
} }
op1 = JS_ToNumberFree (ctx, op1); op1 = JS_ToNumber (ctx, op1);
if (JS_IsException (op1)) { if (JS_IsException (op1)) {
goto exception; goto exception;
} }
op2 = JS_ToNumberFree (ctx, op2); op2 = JS_ToNumber (ctx, op2);
if (JS_IsException (op2)) { if (JS_IsException (op2)) {
goto exception; goto exception;
} }
@@ -6530,10 +6479,10 @@ js_binary_arith_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) {
} else { } else {
double dr; double dr;
/* float64 result */ /* float64 result */
if (JS_ToFloat64Free (ctx, &d1, op1)) { if (JS_ToFloat64 (ctx, &d1, op1)) {
goto exception; goto exception;
} }
if (JS_ToFloat64Free (ctx, &d2, op2)) goto exception; if (JS_ToFloat64 (ctx, &d2, op2)) goto exception;
handle_float64: handle_float64:
switch (op) { switch (op) {
case OP_sub: case OP_sub:
@@ -7943,7 +7892,7 @@ restart:
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) { if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
res = JS_VALUE_GET_INT (op1); res = JS_VALUE_GET_INT (op1);
} else { } else {
res = JS_ToBoolFree (ctx, op1); res = JS_ToBool (ctx, op1);
} }
sp--; sp--;
if (res) { pc += (int32_t)get_u32 (pc - 4) - 4; } if (res) { pc += (int32_t)get_u32 (pc - 4) - 4; }
@@ -7961,7 +7910,7 @@ restart:
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) { if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
res = JS_VALUE_GET_INT (op1); res = JS_VALUE_GET_INT (op1);
} else { } else {
res = JS_ToBoolFree (ctx, op1); res = JS_ToBool (ctx, op1);
} }
sp--; sp--;
if (!res) { pc += (int32_t)get_u32 (pc - 4) - 4; } if (!res) { pc += (int32_t)get_u32 (pc - 4) - 4; }
@@ -7978,7 +7927,7 @@ restart:
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) { if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
res = JS_VALUE_GET_INT (op1); res = JS_VALUE_GET_INT (op1);
} else { } else {
res = JS_ToBoolFree (ctx, op1); res = JS_ToBool (ctx, op1);
} }
sp--; sp--;
if (res) { pc += (int8_t)pc[-1] - 1; } if (res) { pc += (int8_t)pc[-1] - 1; }
@@ -7994,7 +7943,7 @@ restart:
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) { if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
res = JS_VALUE_GET_INT (op1); res = JS_VALUE_GET_INT (op1);
} else { } else {
res = JS_ToBoolFree (ctx, op1); res = JS_ToBool (ctx, op1);
} }
sp--; sp--;
if (!res) { pc += (int8_t)pc[-1] - 1; } if (!res) { pc += (int8_t)pc[-1] - 1; }
@@ -8058,7 +8007,7 @@ restart:
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) { if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
res = JS_VALUE_GET_INT (op1) != 0; res = JS_VALUE_GET_INT (op1) != 0;
} else { } else {
res = JS_ToBoolFree (ctx, op1); res = JS_ToBool (ctx, op1);
} }
sp[-1] = JS_NewBool (ctx, !res); sp[-1] = JS_NewBool (ctx, !res);
} }
@@ -9058,11 +9007,6 @@ JSValue JS_Call (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, J
return JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); return JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV);
} }
static JSValue JS_CallFree (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv) {
JSValue res = JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV);
return res;
}
/* warning: the refcount of the context is not incremented. Return /* warning: the refcount of the context is not incremented. Return
NULL in case of exception (case of revoked proxy only) */ NULL in case of exception (case of revoked proxy only) */
static JSContext *JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) { static JSContext *JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) {
@@ -17950,7 +17894,7 @@ static JSValue JS_EvalFunctionInternal (JSContext *ctx, JSValue fun_obj, JSValue
/* JSFunctionBytecode uses OBJ_CODE type with JS_TAG_PTR */ /* JSFunctionBytecode uses OBJ_CODE type with JS_TAG_PTR */
if (tag == JS_TAG_PTR && objhdr_type (*(objhdr_t *)JS_VALUE_GET_PTR (fun_obj)) == OBJ_CODE) { if (tag == JS_TAG_PTR && objhdr_type (*(objhdr_t *)JS_VALUE_GET_PTR (fun_obj)) == OBJ_CODE) {
fun_obj = js_closure (ctx, fun_obj, var_refs, sf); fun_obj = js_closure (ctx, fun_obj, var_refs, sf);
ret_val = JS_CallFree (ctx, fun_obj, this_obj, 0, NULL); ret_val = JS_Call (ctx, fun_obj, this_obj, 0, NULL);
} else { } else {
ret_val = JS_ThrowTypeError (ctx, "bytecode function expected"); ret_val = JS_ThrowTypeError (ctx, "bytecode function expected");
} }
@@ -19404,11 +19348,6 @@ static JSValue JS_ToObject (JSContext *ctx, JSValue val) {
} }
} }
static JSValue JS_ToObjectFree (JSContext *ctx, JSValue val) {
JSValue obj = JS_ToObject (ctx, val);
return obj;
}
/* Function class */ /* Function class */
static JSValue js_function_proto (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { static JSValue js_function_proto (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
@@ -19449,7 +19388,7 @@ static __exception int js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue
*pres = 0; *pres = 0;
return -1; return -1;
} }
return JS_ToUint32Free (ctx, pres, len_val); return JS_ToUint32 (ctx, pres, len_val);
} }
static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, JSValue obj) { static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, JSValue obj) {
@@ -19465,7 +19404,7 @@ static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, JSValue o
*pres = 0; *pres = 0;
return -1; return -1;
} }
return JS_ToLengthFree (ctx, pres, len_val); return JS_ToLength (ctx, pres, len_val);
} }
int JS_GetLength (JSContext *ctx, JSValue obj, int64_t *pres) { int JS_GetLength (JSContext *ctx, JSValue obj, int64_t *pres) {
@@ -19609,14 +19548,14 @@ static JSValue js_error_toString (JSContext *ctx, JSValue this_val, int argc, JS
if (JS_IsNull (name)) if (JS_IsNull (name))
name = JS_KEY_Error; name = JS_KEY_Error;
else else
name = JS_ToStringFree (ctx, name); name = JS_ToString (ctx, name);
if (JS_IsException (name)) return JS_EXCEPTION; if (JS_IsException (name)) return JS_EXCEPTION;
msg = JS_GetProperty (ctx, this_val, JS_KEY_message); msg = JS_GetProperty (ctx, this_val, JS_KEY_message);
if (JS_IsNull (msg)) if (JS_IsNull (msg))
msg = JS_KEY_empty; msg = JS_KEY_empty;
else else
msg = JS_ToStringFree (ctx, msg); msg = JS_ToString (ctx, msg);
if (JS_IsException (msg)) { if (JS_IsException (msg)) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
@@ -19776,7 +19715,7 @@ static int js_is_regexp (JSContext *ctx, JSValue obj) {
if (!JS_IsObject (obj)) return FALSE; if (!JS_IsObject (obj)) return FALSE;
m = JS_GetPropertyStr (ctx, obj, "Symbol.match"); m = JS_GetPropertyStr (ctx, obj, "Symbol.match");
if (JS_IsException (m)) return -1; if (JS_IsException (m)) return -1;
if (!JS_IsNull (m)) return JS_ToBoolFree (ctx, m); if (!JS_IsNull (m)) return JS_ToBool (ctx, m);
return js_get_regexp (ctx, obj, FALSE) != NULL; return js_get_regexp (ctx, obj, FALSE) != NULL;
} }
@@ -19963,7 +19902,7 @@ static JSValue js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, JSVal
capture = NULL; capture = NULL;
val = JS_GetPropertyStr (ctx, this_val, "lastIndex"); val = JS_GetPropertyStr (ctx, this_val, "lastIndex");
if (JS_IsException (val) || JS_ToLengthFree (ctx, &last_index, val)) if (JS_IsException (val) || JS_ToLength (ctx, &last_index, val))
goto fail; goto fail;
re_bytecode = (uint8_t *)re->bytecode->packed; re_bytecode = (uint8_t *)re->bytecode->packed;
@@ -20139,7 +20078,7 @@ static JSValue JS_RegExpDelete (JSContext *ctx, JSValue this_val, JSValue arg) {
last_index = 0; last_index = 0;
} else { } else {
val = JS_GetPropertyStr (ctx, this_val, "lastIndex"); val = JS_GetPropertyStr (ctx, this_val, "lastIndex");
if (JS_IsException (val) || JS_ToLengthFree (ctx, &last_index, val)) if (JS_IsException (val) || JS_ToLength (ctx, &last_index, val))
goto fail; goto fail;
} }
capture_count = lre_get_capture_count (re_bytecode); capture_count = lre_get_capture_count (re_bytecode);
@@ -20221,7 +20160,7 @@ static JSValue JS_RegExpExec (JSContext *ctx, JSValue r, JSValue s) {
method = JS_GetProperty (ctx, r, JS_KEY_exec); method = JS_GetProperty (ctx, r, JS_KEY_exec);
if (JS_IsException (method)) return method; if (JS_IsException (method)) return method;
if (JS_IsFunction (method)) { if (JS_IsFunction (method)) {
ret = JS_CallFree (ctx, method, r, 1, &s); ret = JS_Call (ctx, method, r, 1, &s);
if (JS_IsException (ret)) return ret; if (JS_IsException (ret)) return ret;
if (!JS_IsObject (ret) && !JS_IsNull (ret)) { if (!JS_IsObject (ret) && !JS_IsNull (ret)) {
return JS_ThrowTypeError ( return JS_ThrowTypeError (
@@ -20485,11 +20424,6 @@ typedef struct JSONStringifyContext {
JSText *b; JSText *b;
} JSONStringifyContext; } JSONStringifyContext;
static JSValue JS_ToQuotedStringFree (JSContext *ctx, JSValue val) {
JSValue r = JS_ToQuotedString (ctx, val);
return r;
}
static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue holder, JSValue val, JSValue key) { static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue holder, JSValue val, JSValue key) {
JSValue v; JSValue v;
JSValue args[2]; JSValue args[2];
@@ -20500,7 +20434,7 @@ static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue
JSValue f = JS_GetProperty (ctx, val, JS_KEY_toJSON); JSValue f = JS_GetProperty (ctx, val, JS_KEY_toJSON);
if (JS_IsException (f)) goto exception; if (JS_IsException (f)) goto exception;
if (JS_IsFunction (f)) { if (JS_IsFunction (f)) {
v = JS_CallFree (ctx, f, val, 1, &key); v = JS_Call (ctx, f, val, 1, &key);
val = v; val = v;
if (JS_IsException (val)) goto exception; if (JS_IsException (val)) goto exception;
} else { } else {
@@ -20557,7 +20491,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
val)) { /* includes arrays (OBJ_ARRAY) since they have JS_TAG_PTR */ val)) { /* includes arrays (OBJ_ARRAY) since they have JS_TAG_PTR */
v = js_array_includes (ctx, jsc->stack, 1, (JSValue *)&val); v = js_array_includes (ctx, jsc->stack, 1, (JSValue *)&val);
if (JS_IsException (v)) goto exception; if (JS_IsException (v)) goto exception;
if (JS_ToBoolFree (ctx, v)) { if (JS_ToBool (ctx, v)) {
JS_ThrowTypeError (ctx, "circular reference"); JS_ThrowTypeError (ctx, "circular reference");
goto exception; goto exception;
} }
@@ -20590,7 +20524,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
v = JS_GetPropertyInt64 (ctx, val, i); v = JS_GetPropertyInt64 (ctx, val, i);
if (JS_IsException (v)) goto exception; if (JS_IsException (v)) goto exception;
/* XXX: could do this string conversion only when needed */ /* XXX: could do this string conversion only when needed */
prop = JS_ToStringFree (ctx, JS_NewInt64 (ctx, i)); prop = JS_ToString (ctx, JS_NewInt64 (ctx, i));
if (JS_IsException (prop)) goto exception; if (JS_IsException (prop)) goto exception;
v = js_json_check (ctx, jsc, val, v, prop); v = js_json_check (ctx, jsc, val, v, prop);
prop = JS_NULL; prop = JS_NULL;
@@ -20628,7 +20562,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
jsc->b = pretext_putc (ctx, jsc->b, ','); jsc->b = pretext_putc (ctx, jsc->b, ',');
if (!jsc->b) goto exception; if (!jsc->b) goto exception;
} }
prop = JS_ToQuotedStringFree (ctx, prop); prop = JS_ToQuotedString (ctx, prop);
if (JS_IsException (prop)) { if (JS_IsException (prop)) {
goto exception; goto exception;
} }
@@ -20660,7 +20594,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
concat_primitive: concat_primitive:
switch (JS_VALUE_GET_NORM_TAG (val)) { switch (JS_VALUE_GET_NORM_TAG (val)) {
case JS_TAG_STRING_IMM: case JS_TAG_STRING_IMM:
val = JS_ToQuotedStringFree (ctx, val); val = JS_ToQuotedString (ctx, val);
if (JS_IsException (val)) goto exception; if (JS_IsException (val)) goto exception;
goto concat_value; goto concat_value;
case JS_TAG_FLOAT64: case JS_TAG_FLOAT64:
@@ -20718,7 +20652,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
/* Objects are not valid property list items */ /* Objects are not valid property list items */
continue; continue;
} else if (JS_IsNumber (v)) { } else if (JS_IsNumber (v)) {
v = JS_ToStringFree (ctx, v); v = JS_ToString (ctx, v);
if (JS_IsException (v)) goto exception; if (JS_IsException (v)) goto exception;
} else if (!JS_IsText (v)) { } else if (!JS_IsText (v)) {
continue; continue;
@@ -20728,7 +20662,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
if (JS_IsException (present)) { if (JS_IsException (present)) {
goto exception; goto exception;
} }
if (!JS_ToBoolFree (ctx, present)) { if (!JS_ToBool (ctx, present)) {
JS_SetPropertyInt64 (ctx, jsc->property_list, j++, v); JS_SetPropertyInt64 (ctx, jsc->property_list, j++, v);
} else { } else {
} }