]> git.kaiwu.me - quickjs.git/commitdiff
Implement nonextensible-applies-to-private proposal (saghul)
authorFabrice Bellard <fabrice@bellard.org>
Mon, 26 Oct 2026 15:20:38 +0000 (16:20 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 26 Oct 2026 15:20:38 +0000 (16:20 +0100)
quickjs.c
test262.conf

index 98bb3ed289e1cc92bc7254de1e4766433a5f0295..ca126b977ab21511dac9ae6e4101158bf5c3137a 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -8487,8 +8487,10 @@ static JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom atom)
                                  atom);
 }
 
-/* Private fields can be added even on non extensible objects or
-   Proxies */
+/* Per the nonextensible-applies-to-private proposal, private fields cannot
+   be added to non-extensible objects. Note that a Proxy's JSObject stays
+   extensible (its trap reflects the target), so private fields can still be
+   stamped onto Proxies. */
 static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
                                  JSValueConst name, JSValue val)
 {
@@ -8508,6 +8510,10 @@ static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
     }
     prop = js_symbol_to_atom(ctx, (JSValue)name);
     p = JS_VALUE_GET_OBJ(obj);
+    if (unlikely(!p->extensible)) {
+        JS_ThrowTypeError(ctx, "object is not extensible");
+        goto fail;
+    }
     prs = find_own_property(&pr, p, prop);
     if (prs) {
         JS_ThrowTypeErrorAtom(ctx, "private class field '%s' already exists",
@@ -8611,6 +8617,11 @@ static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj)
 
     if (JS_IsObject(obj)) {
         p1 = JS_VALUE_GET_OBJ(obj);
+        if (unlikely(!p1->extensible)) {
+            JS_FreeAtom(ctx, brand_atom);
+            JS_ThrowTypeError(ctx, "object is not extensible");
+            return -1;
+        }
         prs = find_own_property(&pr, p1, brand_atom);
         if (unlikely(prs)) {
             JS_FreeAtom(ctx, brand_atom);
index 34a33d4a0194d00a1e1070d897c03c2d72ae5fcd..7706841a2e580ee21adbf62659f9a4e892ec06a5 100644 (file)
@@ -162,7 +162,7 @@ logical-assignment-operators
 Map
 Math.sumPrecise
 new.target
-nonextensible-applies-to-private=skip
+nonextensible-applies-to-private
 numeric-separator-literal
 object-rest
 object-spread