@@ -12059,8 +12059,17 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val)
12059
12059
}
12060
12060
}
12061
12061
12062
+ bool JS_IsArray(JSValue val)
12063
+ {
12064
+ if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
12065
+ JSObject *p = JS_VALUE_GET_OBJ(val);
12066
+ return p->class_id == JS_CLASS_ARRAY;
12067
+ }
12068
+ return false;
12069
+ }
12070
+
12062
12071
/* return -1 if exception (proxy case) or true/false */
12063
- int JS_IsArray (JSContext *ctx, JSValue val)
12072
+ static int js_is_array (JSContext *ctx, JSValue val)
12064
12073
{
12065
12074
JSObject *p;
12066
12075
if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
@@ -36880,7 +36889,7 @@ static JSValue js_object_toString(JSContext *ctx, JSValue this_val,
36880
36889
obj = JS_ToObject(ctx, this_val);
36881
36890
if (JS_IsException(obj))
36882
36891
return obj;
36883
- is_array = JS_IsArray (ctx, obj);
36892
+ is_array = js_is_array (ctx, obj);
36884
36893
if (is_array < 0) {
36885
36894
JS_FreeValue(ctx, obj);
36886
36895
return JS_EXCEPTION;
@@ -38197,7 +38206,7 @@ static JSValue js_array_isArray(JSContext *ctx, JSValue this_val,
38197
38206
int argc, JSValue *argv)
38198
38207
{
38199
38208
int ret;
38200
- ret = JS_IsArray (ctx, argv[0]);
38209
+ ret = js_is_array (ctx, argv[0]);
38201
38210
if (ret < 0)
38202
38211
return JS_EXCEPTION;
38203
38212
else
@@ -38217,7 +38226,7 @@ static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValue obj,
38217
38226
int res;
38218
38227
JSContext *realm;
38219
38228
38220
- res = JS_IsArray (ctx, obj);
38229
+ res = js_is_array (ctx, obj);
38221
38230
if (res < 0)
38222
38231
return JS_EXCEPTION;
38223
38232
if (!res)
@@ -38274,7 +38283,7 @@ static int JS_isConcatSpreadable(JSContext *ctx, JSValue obj)
38274
38283
return -1;
38275
38284
if (!JS_IsUndefined(val))
38276
38285
return JS_ToBoolFree(ctx, val);
38277
- return JS_IsArray (ctx, obj);
38286
+ return js_is_array (ctx, obj);
38278
38287
}
38279
38288
38280
38289
static JSValue js_array_at(JSContext *ctx, JSValue this_val,
@@ -39555,7 +39564,7 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValue target,
39555
39564
return -1;
39556
39565
}
39557
39566
if (depth > 0) {
39558
- is_array = JS_IsArray (ctx, element);
39567
+ is_array = js_is_array (ctx, element);
39559
39568
if (is_array < 0)
39560
39569
goto fail;
39561
39570
if (is_array) {
@@ -45088,7 +45097,7 @@ static JSValue internalize_json_property(JSContext *ctx, JSValue holder,
45088
45097
if (JS_IsException(val))
45089
45098
return val;
45090
45099
if (JS_IsObject(val)) {
45091
- is_array = JS_IsArray (ctx, val);
45100
+ is_array = js_is_array (ctx, val);
45092
45101
if (is_array < 0)
45093
45102
goto fail;
45094
45103
if (is_array) {
@@ -45299,7 +45308,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
45299
45308
v = js_array_push(ctx, jsc->stack, 1, &val, 0);
45300
45309
if (check_exception_free(ctx, v))
45301
45310
goto exception;
45302
- ret = JS_IsArray (ctx, val);
45311
+ ret = js_is_array (ctx, val);
45303
45312
if (ret < 0)
45304
45313
goto exception;
45305
45314
if (ret) {
@@ -45447,7 +45456,7 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValue obj,
45447
45456
if (JS_IsFunction(ctx, replacer)) {
45448
45457
jsc->replacer_func = replacer;
45449
45458
} else {
45450
- res = JS_IsArray (ctx, replacer);
45459
+ res = js_is_array (ctx, replacer);
45451
45460
if (res < 0)
45452
45461
goto exception;
45453
45462
if (res) {
@@ -46591,7 +46600,7 @@ static int js_proxy_isArray(JSContext *ctx, JSValue obj)
46591
46600
JS_ThrowTypeErrorRevokedProxy(ctx);
46592
46601
return -1;
46593
46602
}
46594
- return JS_IsArray (ctx, s->target);
46603
+ return js_is_array (ctx, s->target);
46595
46604
}
46596
46605
46597
46606
static const JSClassExoticMethods js_proxy_exotic_methods = {
@@ -46708,6 +46717,39 @@ void JS_AddIntrinsicProxy(JSContext *ctx)
46708
46717
obj1, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
46709
46718
}
46710
46719
46720
+ bool JS_IsProxy(JSValue val)
46721
+ {
46722
+ if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
46723
+ JSObject *p = JS_VALUE_GET_OBJ(val);
46724
+ return p->class_id == JS_CLASS_PROXY;
46725
+ }
46726
+ return false;
46727
+ }
46728
+
46729
+ static JSValue js_get_proxy_field(JSContext *ctx, JSValue proxy, int offset)
46730
+ {
46731
+ if (JS_VALUE_GET_TAG(proxy) == JS_TAG_OBJECT) {
46732
+ JSObject *p = JS_VALUE_GET_OBJ(proxy);
46733
+ if (p->class_id == JS_CLASS_PROXY) {
46734
+ JSProxyData *s = JS_GetOpaque(proxy, JS_CLASS_PROXY);
46735
+ if (s->is_revoked)
46736
+ return JS_ThrowTypeErrorRevokedProxy(ctx);
46737
+ return js_dup(*(JSValue *)((char *)s + offset));
46738
+ }
46739
+ }
46740
+ return JS_ThrowTypeError(ctx, "not a proxy");
46741
+ }
46742
+
46743
+ JSValue JS_GetProxyTarget(JSContext *ctx, JSValue proxy)
46744
+ {
46745
+ return js_get_proxy_field(ctx, proxy, offsetof(JSProxyData, target));
46746
+ }
46747
+
46748
+ JSValue JS_GetProxyHandler(JSContext *ctx, JSValue proxy)
46749
+ {
46750
+ return js_get_proxy_field(ctx, proxy, offsetof(JSProxyData, handler));
46751
+ }
46752
+
46711
46753
/* Symbol */
46712
46754
46713
46755
static JSValue js_symbol_constructor(JSContext *ctx, JSValue new_target,
0 commit comments