Compare commits
2 Commits
f2a76cbb55
...
9a9775690f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a9775690f | ||
|
|
be71ae3bba |
237
source/quickjs.c
237
source/quickjs.c
@@ -773,8 +773,6 @@ struct JSContext {
|
||||
JSGCRef *last_gc_ref; /* used to reference temporary GC roots (list) */
|
||||
|
||||
JSValue *class_proto;
|
||||
JSValue function_proto;
|
||||
JSValue array_ctor;
|
||||
JSValue regexp_ctor;
|
||||
JSValue native_error_proto[JS_NATIVE_ERROR_COUNT];
|
||||
JSValue array_proto_values;
|
||||
@@ -1645,8 +1643,6 @@ enum OPCodeEnum {
|
||||
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_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_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);
|
||||
int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop);
|
||||
JSValue __attribute__ ((format (printf, 2, 3)))
|
||||
@@ -1693,10 +1689,6 @@ int JS_SetPropertyInternal (JSContext *ctx, JSValue this_obj, JSValue prop, JSVa
|
||||
}
|
||||
|
||||
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_compile_regexp (JSContext *ctx, JSValue pattern, JSValue flags);
|
||||
static JSValue js_regexp_constructor_internal (JSContext *ctx, JSValue pattern, JSValue bc);
|
||||
@@ -1705,7 +1697,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 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_push (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 +1709,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 JSValue JS_ToNumber (JSContext *ctx, 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,
|
||||
JSValue *desc,
|
||||
JSRecord *p,
|
||||
@@ -2268,8 +2258,6 @@ static int ctx_gc (JSContext *ctx) {
|
||||
/* Copy roots: global object, class prototypes, exception, etc. */
|
||||
ctx->global_obj = gc_copy_value (ctx, ctx->global_obj, &to_free, to_end);
|
||||
ctx->global_var_obj = gc_copy_value (ctx, ctx->global_var_obj, &to_free, to_end);
|
||||
ctx->function_proto = gc_copy_value (ctx, ctx->function_proto, &to_free, to_end);
|
||||
ctx->array_ctor = gc_copy_value (ctx, ctx->array_ctor, &to_free, to_end);
|
||||
ctx->regexp_ctor = gc_copy_value (ctx, ctx->regexp_ctor, &to_free, to_end);
|
||||
ctx->throw_type_error = gc_copy_value (ctx, ctx->throw_type_error, &to_free, to_end);
|
||||
ctx->eval_obj = gc_copy_value (ctx, ctx->eval_obj, &to_free, to_end);
|
||||
@@ -2552,7 +2540,7 @@ JSContext *JS_NewContextRaw (JSRuntime *rt) {
|
||||
list_add_tail (&ctx->link, &rt->context_list);
|
||||
for (i = 0; i < rt->class_count; i++)
|
||||
ctx->class_proto[i] = JS_NULL;
|
||||
ctx->array_ctor = JS_NULL;
|
||||
|
||||
ctx->regexp_ctor = JS_NULL;
|
||||
|
||||
/* Initialize VM stacks for trampoline */
|
||||
@@ -2674,7 +2662,6 @@ static void JS_MarkContext (JSRuntime *rt, JSContext *ctx, JS_MarkFunc *mark_fun
|
||||
for (i = 0; i < rt->class_count; i++) {
|
||||
JS_MarkValue (rt, ctx->class_proto[i], mark_func);
|
||||
}
|
||||
JS_MarkValue (rt, ctx->array_ctor, mark_func);
|
||||
JS_MarkValue (rt, ctx->regexp_ctor, mark_func);
|
||||
}
|
||||
|
||||
@@ -3072,7 +3059,7 @@ static JSText *pretext_concat_value_free (JSContext *ctx, JSText *s, JSValue v)
|
||||
JSText *p;
|
||||
|
||||
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;
|
||||
}
|
||||
p = JS_VALUE_GET_STRING (v);
|
||||
@@ -3170,7 +3157,7 @@ static JSValue JS_ConcatString3 (JSContext *ctx, const char *str1, JSValue str2,
|
||||
JSText *p;
|
||||
|
||||
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;
|
||||
}
|
||||
p = JS_VALUE_GET_STRING (str2);
|
||||
@@ -3354,13 +3341,13 @@ static int js_string_compare_value (JSContext *ctx, JSValue op1, JSValue op2, BO
|
||||
|
||||
static JSValue JS_ConcatString (JSContext *ctx, JSValue op1, JSValue op2) {
|
||||
if (unlikely (!JS_IsText (op1))) {
|
||||
op1 = JS_ToStringFree (ctx, op1);
|
||||
op1 = JS_ToString (ctx, op1);
|
||||
if (JS_IsException (op1)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
}
|
||||
if (unlikely (!JS_IsText (op2))) {
|
||||
op2 = JS_ToStringFree (ctx, op2);
|
||||
op2 = JS_ToString (ctx, op2);
|
||||
if (JS_IsException (op2)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
@@ -3507,10 +3494,9 @@ static int js_method_set_properties (JSContext *ctx, JSValue func_obj, JSValue n
|
||||
}
|
||||
|
||||
/* Note: at least 'length' arguments will be readable in 'argv' */
|
||||
static JSValue JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *name, int length, JSCFunctionEnum cproto, int magic, JSValue proto_val) {
|
||||
static JSValue JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *name, int length, JSCFunctionEnum cproto, int magic) {
|
||||
JSValue func_obj;
|
||||
JSFunction *f;
|
||||
(void)proto_val;
|
||||
|
||||
func_obj = js_new_function (ctx, JS_FUNC_KIND_C);
|
||||
if (JS_IsException (func_obj)) return func_obj;
|
||||
@@ -3526,7 +3512,7 @@ static JSValue JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *
|
||||
|
||||
/* Note: at least 'length' arguments will be readable in 'argv' */
|
||||
JSValue JS_NewCFunction2 (JSContext *ctx, JSCFunction *func, const char *name, int length, JSCFunctionEnum cproto, int magic) {
|
||||
return JS_NewCFunction3 (ctx, func, name, length, cproto, magic, ctx->function_proto);
|
||||
return JS_NewCFunction3 (ctx, func, name, length, cproto, magic);
|
||||
}
|
||||
|
||||
typedef struct JSCFunctionDataRecord {
|
||||
@@ -4446,12 +4432,6 @@ JSValue JS_GetPrototype (JSContext *ctx, JSValue obj) {
|
||||
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 */
|
||||
JSValue JS_GetProperty (JSContext *ctx, JSValue obj, JSValue prop) {
|
||||
if (JS_IsNull (obj)) return JS_NULL;
|
||||
@@ -5173,7 +5153,7 @@ void *JS_GetAnyOpaque (JSValue obj, JSClassID *class_id) {
|
||||
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);
|
||||
|
||||
/* Check for pointer types first (new tagging system) */
|
||||
@@ -5212,10 +5192,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) {
|
||||
const uint8_t *p, *p_next, *p_start;
|
||||
uint32_t c;
|
||||
@@ -5419,7 +5395,7 @@ mem_error:
|
||||
goto done;
|
||||
}
|
||||
|
||||
static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val) {
|
||||
static JSValue JS_ToNumber (JSContext *ctx, JSValue val) {
|
||||
uint32_t tag;
|
||||
JSValue ret;
|
||||
|
||||
@@ -5456,15 +5432,11 @@ static JSValue JS_ToNumberFree (JSContext *ctx, JSValue val) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static JSValue JS_ToNumber (JSContext *ctx, JSValue val) {
|
||||
return JS_ToNumberFree (ctx, val);
|
||||
}
|
||||
|
||||
static __exception int __JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) {
|
||||
static __exception int __JS_ToFloat64 (JSContext *ctx, double *pres, JSValue val) {
|
||||
double d;
|
||||
uint32_t tag;
|
||||
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
val = JS_ToNumber (ctx, val);
|
||||
if (JS_IsException (val)) goto fail;
|
||||
tag = JS_VALUE_GET_NORM_TAG (val);
|
||||
switch (tag) {
|
||||
@@ -5484,7 +5456,7 @@ fail:
|
||||
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;
|
||||
|
||||
tag = JS_VALUE_GET_TAG (val);
|
||||
@@ -5495,16 +5467,12 @@ static inline int JS_ToFloat64Free (JSContext *ctx, double *pres, JSValue val) {
|
||||
*pres = JS_VALUE_GET_FLOAT64 (val);
|
||||
return 0;
|
||||
} 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 */
|
||||
static int JS_ToInt32SatFree (JSContext *ctx, int *pres, JSValue val) {
|
||||
int JS_ToInt32Sat (JSContext *ctx, int *pres, JSValue val) {
|
||||
uint32_t tag;
|
||||
int ret;
|
||||
|
||||
@@ -5530,7 +5498,7 @@ redo:
|
||||
ret = (int)d;
|
||||
} break;
|
||||
default:
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
val = JS_ToNumber (ctx, val);
|
||||
if (JS_IsException (val)) {
|
||||
*pres = 0;
|
||||
return -1;
|
||||
@@ -5541,12 +5509,8 @@ redo:
|
||||
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 res = JS_ToInt32SatFree (ctx, pres, val);
|
||||
int res = JS_ToInt32Sat (ctx, pres, val);
|
||||
if (res == 0) {
|
||||
if (*pres < min) {
|
||||
*pres += min_offset;
|
||||
@@ -5558,7 +5522,7 @@ int JS_ToInt32Clamp (JSContext *ctx, int *pres, JSValue val, int min, int max, i
|
||||
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;
|
||||
|
||||
redo:
|
||||
@@ -5585,7 +5549,7 @@ redo:
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
val = JS_ToNumber (ctx, val);
|
||||
if (JS_IsException (val)) {
|
||||
*pres = 0;
|
||||
return -1;
|
||||
@@ -5594,12 +5558,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 res = JS_ToInt64SatFree (ctx, pres, val);
|
||||
int res = JS_ToInt64Sat (ctx, pres, val);
|
||||
if (res == 0) {
|
||||
if (*pres < 0) *pres += neg_offset;
|
||||
if (*pres < min)
|
||||
@@ -5610,9 +5570,9 @@ int JS_ToInt64Clamp (JSContext *ctx, int64_t *pres, JSValue val, int64_t min, in
|
||||
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 */
|
||||
static int JS_ToInt64Free (JSContext *ctx, int64_t *pres, JSValue val) {
|
||||
int JS_ToInt64 (JSContext *ctx, int64_t *pres, JSValue val) {
|
||||
uint32_t tag;
|
||||
int64_t ret;
|
||||
|
||||
@@ -5647,7 +5607,7 @@ redo:
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
val = JS_ToNumber (ctx, val);
|
||||
if (JS_IsException (val)) {
|
||||
*pres = 0;
|
||||
return -1;
|
||||
@@ -5658,12 +5618,8 @@ redo:
|
||||
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 */
|
||||
static int JS_ToInt32Free (JSContext *ctx, int32_t *pres, JSValue val) {
|
||||
int JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) {
|
||||
uint32_t tag;
|
||||
int32_t ret;
|
||||
|
||||
@@ -5701,7 +5657,7 @@ redo:
|
||||
default:
|
||||
*pres = 0;
|
||||
return -1;
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
val = JS_ToNumber (ctx, val);
|
||||
if (JS_IsException (val)) {
|
||||
*pres = 0;
|
||||
return -1;
|
||||
@@ -5712,69 +5668,11 @@ redo:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JS_ToInt32 (JSContext *ctx, int32_t *pres, JSValue val) {
|
||||
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;
|
||||
|
||||
tag = JS_VALUE_GET_TAG (val);
|
||||
switch (tag) {
|
||||
case JS_TAG_INT:
|
||||
case JS_TAG_BOOL:
|
||||
case JS_TAG_NULL: {
|
||||
int v;
|
||||
v = JS_VALUE_GET_INT (val);
|
||||
if (v < 0) goto fail;
|
||||
len = v;
|
||||
} break;
|
||||
default:
|
||||
if (JS_TAG_IS_FLOAT64 (tag)) {
|
||||
double d;
|
||||
d = JS_VALUE_GET_FLOAT64 (val);
|
||||
if (!(d >= 0 && d <= UINT32_MAX)) goto fail;
|
||||
len = (uint32_t)d;
|
||||
if (len != d) goto fail;
|
||||
} else {
|
||||
uint32_t len1;
|
||||
|
||||
if (is_array_ctor) {
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
if (JS_IsException (val)) return -1;
|
||||
/* cannot recurse because val is a number */
|
||||
if (JS_ToArrayLengthFree (ctx, &len, val, TRUE)) return -1;
|
||||
} else {
|
||||
/* legacy behavior: must do the conversion twice and compare */
|
||||
if (JS_ToUint32 (ctx, &len, val)) {
|
||||
return -1;
|
||||
}
|
||||
val = JS_ToNumberFree (ctx, val);
|
||||
if (JS_IsException (val)) return -1;
|
||||
/* cannot recurse because val is a number */
|
||||
if (JS_ToArrayLengthFree (ctx, &len1, val, FALSE)) return -1;
|
||||
if (len1 != len) {
|
||||
fail:
|
||||
JS_ThrowRangeError (ctx, "invalid array length");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
*plen = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MAX_SAFE_INTEGER (((int64_t)1 << 53) - 1)
|
||||
|
||||
/* convert a value to a length between 0 and MAX_SAFE_INTEGER.
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
@@ -5850,12 +5748,6 @@ JSValue JS_ToString (JSContext *ctx, JSValue val) {
|
||||
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) {
|
||||
/* Objects are handled directly via objkey map, not through atoms */
|
||||
if (JS_IsRecord (val)) { return val; }
|
||||
@@ -6444,10 +6336,10 @@ static no_inline int js_not_slow (JSContext *ctx, JSValue *sp) {
|
||||
JSValue op1;
|
||||
|
||||
op1 = sp[-1];
|
||||
op1 = JS_ToNumberFree (ctx, op1);
|
||||
op1 = JS_ToNumber (ctx, op1);
|
||||
if (JS_IsException (op1)) goto exception;
|
||||
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);
|
||||
return 0;
|
||||
exception:
|
||||
@@ -6485,11 +6377,11 @@ js_binary_arith_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) {
|
||||
goto handle_float64;
|
||||
}
|
||||
|
||||
op1 = JS_ToNumberFree (ctx, op1);
|
||||
op1 = JS_ToNumber (ctx, op1);
|
||||
if (JS_IsException (op1)) {
|
||||
goto exception;
|
||||
}
|
||||
op2 = JS_ToNumberFree (ctx, op2);
|
||||
op2 = JS_ToNumber (ctx, op2);
|
||||
if (JS_IsException (op2)) {
|
||||
goto exception;
|
||||
}
|
||||
@@ -6530,10 +6422,10 @@ js_binary_arith_slow (JSContext *ctx, JSValue *sp, OPCodeEnum op) {
|
||||
} else {
|
||||
double dr;
|
||||
/* float64 result */
|
||||
if (JS_ToFloat64Free (ctx, &d1, op1)) {
|
||||
if (JS_ToFloat64 (ctx, &d1, op1)) {
|
||||
goto exception;
|
||||
}
|
||||
if (JS_ToFloat64Free (ctx, &d2, op2)) goto exception;
|
||||
if (JS_ToFloat64 (ctx, &d2, op2)) goto exception;
|
||||
handle_float64:
|
||||
switch (op) {
|
||||
case OP_sub:
|
||||
@@ -7943,7 +7835,7 @@ restart:
|
||||
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
|
||||
res = JS_VALUE_GET_INT (op1);
|
||||
} else {
|
||||
res = JS_ToBoolFree (ctx, op1);
|
||||
res = JS_ToBool (ctx, op1);
|
||||
}
|
||||
sp--;
|
||||
if (res) { pc += (int32_t)get_u32 (pc - 4) - 4; }
|
||||
@@ -7961,7 +7853,7 @@ restart:
|
||||
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
|
||||
res = JS_VALUE_GET_INT (op1);
|
||||
} else {
|
||||
res = JS_ToBoolFree (ctx, op1);
|
||||
res = JS_ToBool (ctx, op1);
|
||||
}
|
||||
sp--;
|
||||
if (!res) { pc += (int32_t)get_u32 (pc - 4) - 4; }
|
||||
@@ -7978,7 +7870,7 @@ restart:
|
||||
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
|
||||
res = JS_VALUE_GET_INT (op1);
|
||||
} else {
|
||||
res = JS_ToBoolFree (ctx, op1);
|
||||
res = JS_ToBool (ctx, op1);
|
||||
}
|
||||
sp--;
|
||||
if (res) { pc += (int8_t)pc[-1] - 1; }
|
||||
@@ -7994,7 +7886,7 @@ restart:
|
||||
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
|
||||
res = JS_VALUE_GET_INT (op1);
|
||||
} else {
|
||||
res = JS_ToBoolFree (ctx, op1);
|
||||
res = JS_ToBool (ctx, op1);
|
||||
}
|
||||
sp--;
|
||||
if (!res) { pc += (int8_t)pc[-1] - 1; }
|
||||
@@ -8058,7 +7950,7 @@ restart:
|
||||
if ((uint32_t)JS_VALUE_GET_TAG (op1) <= JS_TAG_NULL) {
|
||||
res = JS_VALUE_GET_INT (op1) != 0;
|
||||
} else {
|
||||
res = JS_ToBoolFree (ctx, op1);
|
||||
res = JS_ToBool (ctx, op1);
|
||||
}
|
||||
sp[-1] = JS_NewBool (ctx, !res);
|
||||
}
|
||||
@@ -9058,11 +8950,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);
|
||||
}
|
||||
|
||||
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
|
||||
NULL in case of exception (case of revoked proxy only) */
|
||||
static JSContext *JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) {
|
||||
@@ -17950,7 +17837,7 @@ static JSValue JS_EvalFunctionInternal (JSContext *ctx, JSValue fun_obj, JSValue
|
||||
/* 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) {
|
||||
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 {
|
||||
ret_val = JS_ThrowTypeError (ctx, "bytecode function expected");
|
||||
}
|
||||
@@ -19404,17 +19291,8 @@ 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 */
|
||||
|
||||
static JSValue js_function_proto (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
static __exception int js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue obj) {
|
||||
int tag = JS_VALUE_GET_TAG (obj);
|
||||
|
||||
@@ -19449,7 +19327,7 @@ static __exception int js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue
|
||||
*pres = 0;
|
||||
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) {
|
||||
@@ -19465,7 +19343,7 @@ static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, JSValue o
|
||||
*pres = 0;
|
||||
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) {
|
||||
@@ -19609,14 +19487,14 @@ static JSValue js_error_toString (JSContext *ctx, JSValue this_val, int argc, JS
|
||||
if (JS_IsNull (name))
|
||||
name = JS_KEY_Error;
|
||||
else
|
||||
name = JS_ToStringFree (ctx, name);
|
||||
name = JS_ToString (ctx, name);
|
||||
if (JS_IsException (name)) return JS_EXCEPTION;
|
||||
|
||||
msg = JS_GetProperty (ctx, this_val, JS_KEY_message);
|
||||
if (JS_IsNull (msg))
|
||||
msg = JS_KEY_empty;
|
||||
else
|
||||
msg = JS_ToStringFree (ctx, msg);
|
||||
msg = JS_ToString (ctx, msg);
|
||||
if (JS_IsException (msg)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
@@ -19776,7 +19654,7 @@ static int js_is_regexp (JSContext *ctx, JSValue obj) {
|
||||
if (!JS_IsObject (obj)) return FALSE;
|
||||
m = JS_GetPropertyStr (ctx, obj, "Symbol.match");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -19963,7 +19841,7 @@ static JSValue js_regexp_exec (JSContext *ctx, JSValue this_val, int argc, JSVal
|
||||
capture = NULL;
|
||||
|
||||
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;
|
||||
|
||||
re_bytecode = (uint8_t *)re->bytecode->packed;
|
||||
@@ -20139,7 +20017,7 @@ static JSValue JS_RegExpDelete (JSContext *ctx, JSValue this_val, JSValue arg) {
|
||||
last_index = 0;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
capture_count = lre_get_capture_count (re_bytecode);
|
||||
@@ -20221,7 +20099,7 @@ static JSValue JS_RegExpExec (JSContext *ctx, JSValue r, JSValue s) {
|
||||
method = JS_GetProperty (ctx, r, JS_KEY_exec);
|
||||
if (JS_IsException (method)) return 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_IsObject (ret) && !JS_IsNull (ret)) {
|
||||
return JS_ThrowTypeError (
|
||||
@@ -20485,11 +20363,6 @@ typedef struct JSONStringifyContext {
|
||||
JSText *b;
|
||||
} 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) {
|
||||
JSValue v;
|
||||
JSValue args[2];
|
||||
@@ -20500,7 +20373,7 @@ static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue
|
||||
JSValue f = JS_GetProperty (ctx, val, JS_KEY_toJSON);
|
||||
if (JS_IsException (f)) goto exception;
|
||||
if (JS_IsFunction (f)) {
|
||||
v = JS_CallFree (ctx, f, val, 1, &key);
|
||||
v = JS_Call (ctx, f, val, 1, &key);
|
||||
val = v;
|
||||
if (JS_IsException (val)) goto exception;
|
||||
} else {
|
||||
@@ -20557,7 +20430,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
|
||||
val)) { /* includes arrays (OBJ_ARRAY) since they have JS_TAG_PTR */
|
||||
v = js_array_includes (ctx, jsc->stack, 1, (JSValue *)&val);
|
||||
if (JS_IsException (v)) goto exception;
|
||||
if (JS_ToBoolFree (ctx, v)) {
|
||||
if (JS_ToBool (ctx, v)) {
|
||||
JS_ThrowTypeError (ctx, "circular reference");
|
||||
goto exception;
|
||||
}
|
||||
@@ -20590,7 +20463,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
|
||||
v = JS_GetPropertyInt64 (ctx, val, i);
|
||||
if (JS_IsException (v)) goto exception;
|
||||
/* 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;
|
||||
v = js_json_check (ctx, jsc, val, v, prop);
|
||||
prop = JS_NULL;
|
||||
@@ -20628,7 +20501,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
|
||||
jsc->b = pretext_putc (ctx, jsc->b, ',');
|
||||
if (!jsc->b) goto exception;
|
||||
}
|
||||
prop = JS_ToQuotedStringFree (ctx, prop);
|
||||
prop = JS_ToQuotedString (ctx, prop);
|
||||
if (JS_IsException (prop)) {
|
||||
goto exception;
|
||||
}
|
||||
@@ -20660,7 +20533,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
|
||||
concat_primitive:
|
||||
switch (JS_VALUE_GET_NORM_TAG (val)) {
|
||||
case JS_TAG_STRING_IMM:
|
||||
val = JS_ToQuotedStringFree (ctx, val);
|
||||
val = JS_ToQuotedString (ctx, val);
|
||||
if (JS_IsException (val)) goto exception;
|
||||
goto concat_value;
|
||||
case JS_TAG_FLOAT64:
|
||||
@@ -20718,7 +20591,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
|
||||
/* Objects are not valid property list items */
|
||||
continue;
|
||||
} else if (JS_IsNumber (v)) {
|
||||
v = JS_ToStringFree (ctx, v);
|
||||
v = JS_ToString (ctx, v);
|
||||
if (JS_IsException (v)) goto exception;
|
||||
} else if (!JS_IsText (v)) {
|
||||
continue;
|
||||
@@ -20728,7 +20601,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
|
||||
if (JS_IsException (present)) {
|
||||
goto exception;
|
||||
}
|
||||
if (!JS_ToBoolFree (ctx, present)) {
|
||||
if (!JS_ToBool (ctx, present)) {
|
||||
JS_SetPropertyInt64 (ctx, jsc->property_list, j++, v);
|
||||
} else {
|
||||
}
|
||||
@@ -24626,11 +24499,7 @@ void JS_AddIntrinsicBasicObjects (JSContext *ctx) {
|
||||
int i;
|
||||
|
||||
ctx->class_proto[JS_CLASS_OBJECT] = JS_NewObjectProto (ctx, JS_NULL);
|
||||
|
||||
/* function_proto is kept for API compatibility but functions are now
|
||||
* intrinsic types */
|
||||
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_ERROR] = JS_NewObject (ctx);
|
||||
|
||||
for (i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {
|
||||
|
||||
Reference in New Issue
Block a user