Merge branch 'fix_gc' into mcode_streamline
This commit is contained in:
100
source/runtime.c
100
source/runtime.c
@@ -36,36 +36,28 @@ static inline JS_BOOL JS_IsInteger (JSValue v) {
|
||||
return d == (double)(int64_t)d;
|
||||
}
|
||||
|
||||
static inline JS_BOOL JS_IsGCObject (JSValue v) {
|
||||
return JS_IsPtr (v);
|
||||
}
|
||||
|
||||
JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT;
|
||||
|
||||
/* === Function definitions from header region (non-inline) === */
|
||||
/* === Public API wrappers (non-inline, for quickjs.h declarations) ===
|
||||
These delegate to the static inline versions in quickjs-internal.h. */
|
||||
|
||||
JS_BOOL JS_IsStone(JSValue v) {
|
||||
return !JS_IsGCObject(v) || objhdr_s(*chase(v));
|
||||
JS_BOOL JS_IsStone(JSValue v) { return mist_is_stone(v); }
|
||||
JS_BOOL JS_IsArray(JSValue v) { return mist_is_array(v); }
|
||||
JS_BOOL JS_IsRecord(JSValue v) { return mist_is_record(v); }
|
||||
JS_BOOL JS_IsFunction(JSValue v) { return mist_is_function(v); }
|
||||
JS_BOOL JS_IsBlob(JSValue v) { return mist_is_blob(v); }
|
||||
JS_BOOL JS_IsText(JSValue v) { return mist_is_text(v); }
|
||||
|
||||
JS_BOOL JS_IsCode(JSValue v) {
|
||||
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_CODE;
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsArray(JSValue v) {
|
||||
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_ARRAY;
|
||||
JS_BOOL JS_IsForwarded(JSValue v) {
|
||||
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_FORWARD;
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsRecord (JSValue v) {
|
||||
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_RECORD;
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsFunction (JSValue v) {
|
||||
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_FUNCTION;
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsBlob (JSValue v) {
|
||||
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_BLOB;
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsText(JSValue v) {
|
||||
return MIST_IsImmediateASCII(v) || (JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_TEXT);
|
||||
JS_BOOL JS_IsFrame(JSValue v) {
|
||||
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_FRAME;
|
||||
}
|
||||
|
||||
uint64_t get_text_hash (JSText *text) {
|
||||
@@ -4521,7 +4513,7 @@ static JSRegExp *js_get_regexp (JSContext *ctx, JSValue obj, BOOL throw_error) {
|
||||
static int js_is_regexp (JSContext *ctx, JSValue obj) {
|
||||
JSValue m;
|
||||
|
||||
if (!JS_IsGCObject (obj)) return FALSE;
|
||||
if (!mist_is_gc_object (obj)) return FALSE;
|
||||
m = JS_GetPropertyStr (ctx, obj, "Symbol.match");
|
||||
if (JS_IsException (m)) return -1;
|
||||
if (!JS_IsNull (m)) return JS_ToBool (ctx, m);
|
||||
@@ -4664,7 +4656,7 @@ fail:
|
||||
JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
JSValue pattern, flags;
|
||||
|
||||
if (!JS_IsGCObject (this_val)) return JS_ThrowTypeErrorNotAnObject (ctx);
|
||||
if (!mist_is_gc_object (this_val)) return JS_ThrowTypeErrorNotAnObject (ctx);
|
||||
|
||||
JSText *b = pretext_init (ctx, 0);
|
||||
if (!b) return JS_EXCEPTION;
|
||||
@@ -5062,7 +5054,7 @@ static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue
|
||||
|
||||
/* check for object.toJSON method */
|
||||
/* ECMA specifies this is done only for Object and BigInt */
|
||||
if (JS_IsGCObject (val)) {
|
||||
if (mist_is_gc_object (val)) {
|
||||
JSValue f = JS_GetProperty (ctx, val, JS_KEY_toJSON);
|
||||
if (JS_IsException (f)) goto exception;
|
||||
if (JS_IsFunction (f)) {
|
||||
@@ -5134,7 +5126,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
|
||||
goto concat_value;
|
||||
}
|
||||
|
||||
if (JS_IsGCObject (
|
||||
if (mist_is_gc_object (
|
||||
val_ref.val)) { /* includes arrays (OBJ_ARRAY) since they have JS_TAG_PTR */
|
||||
v = js_array_includes (ctx, jsc->stack, 1, &val_ref.val);
|
||||
if (JS_IsException (v)) goto exception;
|
||||
@@ -5322,7 +5314,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
|
||||
JSValue present;
|
||||
v = JS_GetPropertyNumber (ctx, replacer, i);
|
||||
if (JS_IsException (v)) goto exception;
|
||||
if (JS_IsGCObject (v)) {
|
||||
if (mist_is_gc_object (v)) {
|
||||
/* Objects are not valid property list items */
|
||||
continue;
|
||||
} else if (JS_IsNumber (v)) {
|
||||
@@ -6561,7 +6553,7 @@ static JSValue make_replacement (JSContext *ctx, int argc, JSValue *argv, int fo
|
||||
}
|
||||
|
||||
static int JS_IsRegExp (JSContext *ctx, JSValue v) {
|
||||
if (!JS_IsGCObject (v)) return 0;
|
||||
if (!mist_is_gc_object (v)) return 0;
|
||||
|
||||
JSValue exec = JS_GetPropertyStr (ctx, v, "exec");
|
||||
if (JS_IsException (exec)) return -1;
|
||||
@@ -6595,7 +6587,7 @@ static JSValue js_cell_text_replace (JSContext *ctx, JSValue this_val, int argc,
|
||||
{
|
||||
if (JS_IsText (argv[1])) {
|
||||
target_is_regex = 0;
|
||||
} else if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
} else if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
target_is_regex = 1;
|
||||
} else {
|
||||
return JS_NULL;
|
||||
@@ -6877,7 +6869,7 @@ static JSValue js_cell_text_search (JSContext *ctx, JSValue this_val, int argc,
|
||||
int target_is_regex = 0;
|
||||
if (JS_IsText (argv[1])) {
|
||||
target_is_regex = 0;
|
||||
} else if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
} else if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
target_is_regex = 1;
|
||||
} else {
|
||||
return JS_NULL;
|
||||
@@ -7015,7 +7007,7 @@ static JSValue js_cell_text_extract (JSContext *ctx, JSValue this_val, int argc,
|
||||
if (from > to) return JS_NULL;
|
||||
|
||||
/* RegExp path: convert new exec result record -> classic array */
|
||||
if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
/* Root rx, str, out across allocating calls */
|
||||
JSGCRef rx_ref, str_ref, out_ref;
|
||||
JS_PushGCRef (ctx, &rx_ref);
|
||||
@@ -7736,7 +7728,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
return result;
|
||||
}
|
||||
|
||||
if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
|
||||
/* Split by regex (manual "global" iteration; ignore g flag semantics) */
|
||||
/* Root rx, result, arg across allocating calls */
|
||||
JSGCRef rx_ref, res_ref, arg_ref;
|
||||
@@ -8396,7 +8388,7 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
|
||||
JSValue arg = argv[0];
|
||||
|
||||
/* object(object) - shallow mutable copy */
|
||||
if (JS_IsGCObject (arg) && !JS_IsArray (arg) && !JS_IsFunction (arg)) {
|
||||
if (mist_is_gc_object (arg) && !JS_IsArray (arg) && !JS_IsFunction (arg)) {
|
||||
if (argc < 2 || JS_IsNull (argv[1])) {
|
||||
/* Shallow copy - root arg, result, keys across allocating calls */
|
||||
JSGCRef arg_ref, res_ref, keys_ref;
|
||||
@@ -8438,7 +8430,7 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
|
||||
#undef OBJ_COPY_CLEANUP
|
||||
|
||||
/* object(object, another_object) - combine */
|
||||
if (JS_IsGCObject (argv[1]) && !JS_IsArray (argv[1])) {
|
||||
if (mist_is_gc_object (argv[1]) && !JS_IsArray (argv[1])) {
|
||||
JSGCRef arg_ref, arg2_ref, res_ref, keys_ref;
|
||||
JS_PushGCRef (ctx, &arg_ref);
|
||||
arg_ref.val = arg;
|
||||
@@ -8760,7 +8752,7 @@ static JSValue js_blob_constructor (JSContext *ctx, JSValue this_val, int argc,
|
||||
}
|
||||
}
|
||||
/* blob(blob, from, to) - copy from another blob */
|
||||
else if (argc >= 1 && JS_IsGCObject (argv[0]) && !JS_IsText (argv[0])) {
|
||||
else if (argc >= 1 && mist_is_gc_object (argv[0]) && !JS_IsText (argv[0])) {
|
||||
blob *src = js_get_blob (ctx, argv[0]);
|
||||
if (!src)
|
||||
return JS_ThrowTypeError (ctx,
|
||||
@@ -9239,7 +9231,7 @@ static JSValue js_mach_load (JSContext *ctx, JSValue this_val, int argc, JSValue
|
||||
if (!mc)
|
||||
return JS_ThrowSyntaxError (ctx, "mach_load: failed to deserialize bytecode");
|
||||
|
||||
JSValue env = (argc >= 2 && JS_IsGCObject (argv[1])) ? argv[1] : JS_NULL;
|
||||
JSValue env = (argc >= 2 && mist_is_gc_object (argv[1])) ? argv[1] : JS_NULL;
|
||||
|
||||
JSGCRef env_ref;
|
||||
JS_PushGCRef (ctx, &env_ref);
|
||||
@@ -9287,7 +9279,7 @@ static JSValue js_mach_eval_mcode (JSContext *ctx, JSValue this_val, int argc, J
|
||||
return JS_ThrowInternalError (ctx, "mach_eval_mcode: compilation failed");
|
||||
}
|
||||
|
||||
JSValue env = (argc >= 3 && JS_IsGCObject (argv[2])) ? argv[2] : JS_NULL;
|
||||
JSValue env = (argc >= 3 && mist_is_gc_object (argv[2])) ? argv[2] : JS_NULL;
|
||||
|
||||
JSGCRef env_ref;
|
||||
JS_PushGCRef (ctx, &env_ref);
|
||||
@@ -9334,7 +9326,7 @@ static JSValue js_mach_dump_mcode (JSContext *ctx, JSValue this_val, int argc, J
|
||||
return JS_ThrowInternalError (ctx, "mach_dump_mcode: compilation failed");
|
||||
}
|
||||
|
||||
JSValue env = (argc >= 3 && JS_IsGCObject (argv[2])) ? argv[2] : JS_NULL;
|
||||
JSValue env = (argc >= 3 && mist_is_gc_object (argv[2])) ? argv[2] : JS_NULL;
|
||||
|
||||
JSGCRef env_ref;
|
||||
JS_PushGCRef (ctx, &env_ref);
|
||||
@@ -9414,7 +9406,7 @@ static JSValue js_cell_stone (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (JS_IsGCObject (obj)) {
|
||||
if (mist_is_gc_object (obj)) {
|
||||
JSRecord *rec = JS_VALUE_GET_RECORD (obj);
|
||||
obj_set_stone (rec);
|
||||
return obj;
|
||||
@@ -9922,15 +9914,15 @@ static JSValue js_cell_proto (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
return JS_ThrowTypeError (ctx, "arrays do not have prototypes");
|
||||
}
|
||||
|
||||
if (!JS_IsGCObject (obj)) return JS_NULL;
|
||||
if (!mist_is_gc_object (obj)) return JS_NULL;
|
||||
|
||||
JSValue proto = JS_GetPrototype (ctx, obj);
|
||||
if (JS_IsException (proto)) return JS_NULL;
|
||||
|
||||
/* If prototype is Object.prototype, return null */
|
||||
if (JS_IsGCObject (proto)) {
|
||||
if (mist_is_gc_object (proto)) {
|
||||
JSValue obj_proto = ctx->class_proto[JS_CLASS_OBJECT];
|
||||
if (JS_IsGCObject (obj_proto)
|
||||
if (mist_is_gc_object (obj_proto)
|
||||
&& JS_VALUE_GET_OBJ (proto) == JS_VALUE_GET_OBJ (obj_proto)) {
|
||||
return JS_NULL;
|
||||
}
|
||||
@@ -9956,7 +9948,7 @@ static JSValue js_cell_meme (JSContext *ctx, JSValue this_val, int argc, JSValue
|
||||
/* Helper function to apply a single mixin */
|
||||
#define APPLY_MIXIN(mix_val) \
|
||||
do { \
|
||||
if (!JS_IsGCObject (mix_val) || JS_IsNull (mix_val) || JS_IsArray (mix_val)) \
|
||||
if (!mist_is_gc_object (mix_val) || JS_IsNull (mix_val) || JS_IsArray (mix_val)) \
|
||||
break; \
|
||||
JSGCRef _mix_ref; \
|
||||
JS_PushGCRef (ctx, &_mix_ref); \
|
||||
@@ -10012,7 +10004,7 @@ static JSValue js_cell_meme (JSContext *ctx, JSValue this_val, int argc, JSValue
|
||||
APPLY_MIXIN (mix);
|
||||
}
|
||||
JS_PopGCRef (ctx, &mixins_ref);
|
||||
} else if (JS_IsGCObject (mixins) && !JS_IsNull (mixins)) {
|
||||
} else if (mist_is_gc_object (mixins) && !JS_IsNull (mixins)) {
|
||||
/* Single mixin object */
|
||||
APPLY_MIXIN (mixins);
|
||||
}
|
||||
@@ -10034,7 +10026,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
if (argc < 1) return JS_NULL;
|
||||
|
||||
JSValue obj = argv[0];
|
||||
if (!JS_IsGCObject (obj) || JS_IsNull (obj)) return JS_NULL;
|
||||
if (!mist_is_gc_object (obj) || JS_IsNull (obj)) return JS_NULL;
|
||||
|
||||
/* Root obj, result, current, keys across allocating calls */
|
||||
JSGCRef obj_ref, res_ref, cur_ref, keys_ref;
|
||||
@@ -10078,7 +10070,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
int tag = JS_VALUE_GET_TAG (val);
|
||||
if (JS_IsGCObject (val) || JS_IsNumber (val) || tag == JS_TAG_STRING
|
||||
if (mist_is_gc_object (val) || JS_IsNumber (val) || tag == JS_TAG_STRING
|
||||
|| tag == JS_TAG_STRING_IMM || tag == JS_TAG_BOOL) {
|
||||
JS_SetProperty (ctx, res_ref.val, key, val);
|
||||
}
|
||||
@@ -10093,7 +10085,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
|
||||
if (JS_IsFunction (to_data)) {
|
||||
JSValue args[1] = { res_ref.val };
|
||||
JSValue extra = JS_Call (ctx, to_data, obj_ref.val, 1, args);
|
||||
if (!JS_IsException (extra) && JS_IsGCObject (extra)) {
|
||||
if (!JS_IsException (extra) && mist_is_gc_object (extra)) {
|
||||
keys_ref.val = JS_GetOwnPropertyNames (ctx, extra);
|
||||
if (!JS_IsException (keys_ref.val)) {
|
||||
uint32_t len;
|
||||
@@ -10153,7 +10145,7 @@ static JSValue js_cell_length (JSContext *ctx, JSValue this_val, int argc, JSVal
|
||||
}
|
||||
|
||||
/* Objects with length property */
|
||||
if (JS_IsGCObject (val)) {
|
||||
if (mist_is_gc_object (val)) {
|
||||
JSValue len = JS_GetPropertyStr (ctx, val, "length");
|
||||
if (!JS_IsException (len) && !JS_IsNull (len)) {
|
||||
if (JS_IsFunction (len)) {
|
||||
@@ -10247,7 +10239,7 @@ static JSValue js_cell_is_blob (JSContext *ctx, JSValue this_val, int argc, JSVa
|
||||
static JSValue js_cell_is_data (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
if (argc < 1) return JS_FALSE;
|
||||
JSValue val = argv[0];
|
||||
if (!JS_IsGCObject (val)) return JS_FALSE;
|
||||
if (!mist_is_gc_object (val)) return JS_FALSE;
|
||||
if (JS_IsArray (val)) return JS_FALSE;
|
||||
if (JS_IsFunction (val)) return JS_FALSE;
|
||||
if (js_get_blob (ctx, val)) return JS_FALSE;
|
||||
@@ -10296,7 +10288,7 @@ static JSValue js_cell_is_number (JSContext *ctx, JSValue this_val, int argc, JS
|
||||
static JSValue js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
|
||||
if (argc < 1) return JS_FALSE;
|
||||
JSValue val = argv[0];
|
||||
if (!JS_IsGCObject (val)) return JS_FALSE;
|
||||
if (!mist_is_gc_object (val)) return JS_FALSE;
|
||||
if (JS_IsArray (val)) return JS_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -10330,7 +10322,7 @@ static JSValue js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, JSV
|
||||
JSValue val = argv[0];
|
||||
JSValue master = argv[1];
|
||||
|
||||
if (!JS_IsGCObject (val) || JS_IsNull (master)) return JS_FALSE;
|
||||
if (!mist_is_gc_object (val) || JS_IsNull (master)) return JS_FALSE;
|
||||
|
||||
/* Walk prototype chain */
|
||||
JSValue proto = JS_GetPrototype (ctx, val);
|
||||
@@ -10348,7 +10340,7 @@ static JSValue js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, JSV
|
||||
}
|
||||
}
|
||||
/* Also check if proto == master directly */
|
||||
if (JS_IsGCObject (master)) {
|
||||
if (mist_is_gc_object (master)) {
|
||||
JSRecord *p1 = JS_VALUE_GET_OBJ (proto);
|
||||
JSRecord *p2 = JS_VALUE_GET_OBJ (master);
|
||||
if (p1 == p2) {
|
||||
@@ -10719,7 +10711,7 @@ static int nota_stack_has (NotaEncodeContext *enc, JSValueConst val) {
|
||||
int len = nota_get_arr_len (ctx, enc->visitedStack_ref->val);
|
||||
for (int i = 0; i < len; i++) {
|
||||
JSValue elem = JS_GetPropertyNumber (ctx, enc->visitedStack_ref->val, i);
|
||||
if (JS_IsGCObject (elem) && JS_IsGCObject (val)) {
|
||||
if (mist_is_gc_object (elem) && mist_is_gc_object (val)) {
|
||||
if (JS_StrictEq (ctx, elem, val)) {
|
||||
JS_FreeValue (ctx, elem);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user