From 0808cbc509b493c74ed898e7d6259c9428b946b4 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Mon, 26 Oct 2026 16:20:38 +0100 Subject: [PATCH] Implement nonextensible-applies-to-private proposal (saghul) --- quickjs.c | 15 +++++++++++++-- test262.conf | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/quickjs.c b/quickjs.c index 98bb3ed..ca126b9 100644 --- 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); diff --git a/test262.conf b/test262.conf index 34a33d4..7706841 100644 --- a/test262.conf +++ b/test262.conf @@ -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 -- 2.47.3