@@ -1149,13 +1149,8 @@ static JSProperty *add_property(JSContext *ctx,
1149
1149
static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val);
1150
1150
JSValue JS_ThrowOutOfMemory(JSContext *ctx);
1151
1151
static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx);
1152
- static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj);
1153
- static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
1154
- JSValueConst proto_val, BOOL throw_flag);
1155
1152
1156
1153
static int js_resolve_proxy(JSContext *ctx, JSValueConst *pval, int throw_exception);
1157
- static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj);
1158
- static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj);
1159
1154
static int JS_CreateProperty(JSContext *ctx, JSObject *p,
1160
1155
JSAtom prop, JSValueConst val,
1161
1156
JSValueConst getter, JSValueConst setter,
@@ -7194,7 +7189,8 @@ static inline __exception int js_poll_interrupts(JSContext *ctx)
7194
7189
}
7195
7190
}
7196
7191
7197
- /* return -1 (exception) or TRUE/FALSE */
7192
+ /* Return -1 (exception) or TRUE/FALSE. 'throw_flag' = FALSE indicates
7193
+ that it is called from Reflect.setPrototypeOf(). */
7198
7194
static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,
7199
7195
JSValueConst proto_val,
7200
7196
BOOL throw_flag)
@@ -7225,8 +7221,20 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,
7225
7221
if (throw_flag && JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)
7226
7222
return TRUE;
7227
7223
7228
- if (unlikely(p->class_id == JS_CLASS_PROXY))
7229
- return js_proxy_setPrototypeOf(ctx, obj, proto_val, throw_flag);
7224
+ if (unlikely(p->is_exotic)) {
7225
+ const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;
7226
+ int ret;
7227
+ if (em && em->set_prototype) {
7228
+ ret = em->set_prototype(ctx, obj, proto_val);
7229
+ if (ret == 0 && throw_flag) {
7230
+ JS_ThrowTypeError(ctx, "proxy: bad prototype");
7231
+ return -1;
7232
+ } else {
7233
+ return ret;
7234
+ }
7235
+ }
7236
+ }
7237
+
7230
7238
sh = p->shape;
7231
7239
if (sh->proto == proto)
7232
7240
return TRUE;
@@ -7303,22 +7311,24 @@ static JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueConst val)
7303
7311
return val;
7304
7312
}
7305
7313
7306
- /* Return an Object, JS_NULL or JS_EXCEPTION in case of Proxy object. */
7314
+ /* Return an Object, JS_NULL or JS_EXCEPTION in case of exotic object. */
7307
7315
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj)
7308
7316
{
7309
7317
JSValue val;
7310
7318
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
7311
7319
JSObject *p;
7312
7320
p = JS_VALUE_GET_OBJ(obj);
7313
- if (unlikely(p->class_id == JS_CLASS_PROXY)) {
7314
- val = js_proxy_getPrototypeOf(ctx, obj);
7315
- } else {
7316
- p = p->shape->proto;
7317
- if (!p)
7318
- val = JS_NULL;
7319
- else
7320
- val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));
7321
+ if (unlikely(p->is_exotic)) {
7322
+ const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;
7323
+ if (em && em->get_prototype) {
7324
+ return em->get_prototype(ctx, obj);
7325
+ }
7321
7326
}
7327
+ p = p->shape->proto;
7328
+ if (!p)
7329
+ val = JS_NULL;
7330
+ else
7331
+ val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));
7322
7332
} else {
7323
7333
val = JS_DupValue(ctx, JS_GetPrototypePrimitive(ctx, obj));
7324
7334
}
@@ -7365,8 +7375,8 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val,
7365
7375
for(;;) {
7366
7376
proto1 = p->shape->proto;
7367
7377
if (!proto1) {
7368
- /* slow case if proxy in the prototype chain */
7369
- if (unlikely(p->class_id == JS_CLASS_PROXY )) {
7378
+ /* slow case if exotic object in the prototype chain */
7379
+ if (unlikely(p->is_exotic && !p->fast_array )) {
7370
7380
JSValue obj1;
7371
7381
obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, (JSObject *)p));
7372
7382
for(;;) {
@@ -8170,30 +8180,37 @@ int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
8170
8180
return JS_GetOwnPropertyInternal(ctx, desc, JS_VALUE_GET_OBJ(obj), prop);
8171
8181
}
8172
8182
8173
- /* return -1 if exception (Proxy object only) or TRUE/FALSE */
8183
+ /* return -1 if exception (exotic object only) or TRUE/FALSE */
8174
8184
int JS_IsExtensible(JSContext *ctx, JSValueConst obj)
8175
8185
{
8176
8186
JSObject *p;
8177
8187
8178
8188
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
8179
8189
return FALSE;
8180
8190
p = JS_VALUE_GET_OBJ(obj);
8181
- if (unlikely(p->class_id == JS_CLASS_PROXY))
8182
- return js_proxy_isExtensible(ctx, obj);
8183
- else
8184
- return p->extensible;
8191
+ if (unlikely(p->is_exotic)) {
8192
+ const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;
8193
+ if (em && em->is_extensible) {
8194
+ return em->is_extensible(ctx, obj);
8195
+ }
8196
+ }
8197
+ return p->extensible;
8185
8198
}
8186
8199
8187
- /* return -1 if exception (Proxy object only) or TRUE/FALSE */
8200
+ /* return -1 if exception (exotic object only) or TRUE/FALSE */
8188
8201
int JS_PreventExtensions(JSContext *ctx, JSValueConst obj)
8189
8202
{
8190
8203
JSObject *p;
8191
8204
8192
8205
if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))
8193
8206
return FALSE;
8194
8207
p = JS_VALUE_GET_OBJ(obj);
8195
- if (unlikely(p->class_id == JS_CLASS_PROXY))
8196
- return js_proxy_preventExtensions(ctx, obj);
8208
+ if (unlikely(p->is_exotic)) {
8209
+ const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;
8210
+ if (em && em->prevent_extensions) {
8211
+ return em->prevent_extensions(ctx, obj);
8212
+ }
8213
+ }
8197
8214
p->extensible = FALSE;
8198
8215
return TRUE;
8199
8216
}
@@ -46040,7 +46057,7 @@ static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod,
46040
46057
return s;
46041
46058
}
46042
46059
46043
- static JSValue js_proxy_getPrototypeOf (JSContext *ctx, JSValueConst obj)
46060
+ static JSValue js_proxy_get_prototype (JSContext *ctx, JSValueConst obj)
46044
46061
{
46045
46062
JSProxyData *s;
46046
46063
JSValue method, ret, proto1;
@@ -46081,8 +46098,8 @@ static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj)
46081
46098
return ret;
46082
46099
}
46083
46100
46084
- static int js_proxy_setPrototypeOf (JSContext *ctx, JSValueConst obj,
46085
- JSValueConst proto_val, BOOL throw_flag )
46101
+ static int js_proxy_set_prototype (JSContext *ctx, JSValueConst obj,
46102
+ JSValueConst proto_val)
46086
46103
{
46087
46104
JSProxyData *s;
46088
46105
JSValue method, ret, proto1;
@@ -46094,21 +46111,15 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
46094
46111
if (!s)
46095
46112
return -1;
46096
46113
if (JS_IsUndefined(method))
46097
- return JS_SetPrototypeInternal(ctx, s->target, proto_val, throw_flag );
46114
+ return JS_SetPrototypeInternal(ctx, s->target, proto_val, FALSE );
46098
46115
args[0] = s->target;
46099
46116
args[1] = proto_val;
46100
46117
ret = JS_CallFree(ctx, method, s->handler, 2, args);
46101
46118
if (JS_IsException(ret))
46102
46119
return -1;
46103
46120
res = JS_ToBoolFree(ctx, ret);
46104
- if (!res) {
46105
- if (throw_flag) {
46106
- JS_ThrowTypeError(ctx, "proxy: bad prototype");
46107
- return -1;
46108
- } else {
46109
- return FALSE;
46110
- }
46111
- }
46121
+ if (!res)
46122
+ return FALSE;
46112
46123
res2 = JS_IsExtensible(ctx, s->target);
46113
46124
if (res2 < 0)
46114
46125
return -1;
@@ -46126,7 +46137,7 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
46126
46137
return TRUE;
46127
46138
}
46128
46139
46129
- static int js_proxy_isExtensible (JSContext *ctx, JSValueConst obj)
46140
+ static int js_proxy_is_extensible (JSContext *ctx, JSValueConst obj)
46130
46141
{
46131
46142
JSProxyData *s;
46132
46143
JSValue method, ret;
@@ -46152,7 +46163,7 @@ static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj)
46152
46163
return res;
46153
46164
}
46154
46165
46155
- static int js_proxy_preventExtensions (JSContext *ctx, JSValueConst obj)
46166
+ static int js_proxy_prevent_extensions (JSContext *ctx, JSValueConst obj)
46156
46167
{
46157
46168
JSProxyData *s;
46158
46169
JSValue method, ret;
@@ -46860,6 +46871,10 @@ static const JSClassExoticMethods js_proxy_exotic_methods = {
46860
46871
.has_property = js_proxy_has,
46861
46872
.get_property = js_proxy_get,
46862
46873
.set_property = js_proxy_set,
46874
+ .get_prototype = js_proxy_get_prototype,
46875
+ .set_prototype = js_proxy_set_prototype,
46876
+ .is_extensible = js_proxy_is_extensible,
46877
+ .prevent_extensions = js_proxy_prevent_extensions,
46863
46878
};
46864
46879
46865
46880
static JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val,
0 commit comments