[nonextensible-applies-to-private] Fix bugs (#4590)

Fixes #4587
This commit is contained in:
Mark S. Miller 2025-10-08 08:30:40 -07:00 committed by GitHub
parent 432bc2b863
commit ac316607ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View File

@ -92,7 +92,7 @@ class ClassWithPrivateAccessor extends NonExtensibleBase {
const a = new ClassWithPrivateAccessor(false); const a = new ClassWithPrivateAccessor(false);
// extensible objects can be extended // extensible objects can be extended
assert.sameValue(m.publicAccessor, 42); assert.sameValue(a.publicAccessor, 42);
// where superclass prevented extensions & subclass extended // where superclass prevented extensions & subclass extended
assert.throws(TypeError, function () { assert.throws(TypeError, function () {

View File

@ -35,14 +35,14 @@ class ClassWithPrivateField extends TrojanBase {
super(obj); super(obj);
this.#val = 42; this.#val = 42;
} }
val() { static val(obj) {
return this.#val; return obj.#val;
} }
} }
const t = new ClassWithPrivateField({}); const t = new ClassWithPrivateField({});
// extensible objects can be extended // extensible objects can be extended
assert.sameValue(t.val(), 42); assert.sameValue(ClassWithPrivateField.val(t), 42);
// where superclass prevented extensions & subclass extended // where superclass prevented extensions & subclass extended
assert.throws(TypeError, function () { assert.throws(TypeError, function () {
@ -59,15 +59,14 @@ class ClassWithPrivateMethod extends TrojanBase {
#privateMethod() { #privateMethod() {
return 42; return 42;
}; };
// public methods are on the prototype, so are ok. static val(obj) {
publicMethod() { return obj.#privateMethod();
return this.#privateMethod();
} }
} }
const m = new ClassWithPrivateMethod({}); const m = new ClassWithPrivateMethod({});
// extensible objects can be extended // extensible objects can be extended
assert.sameValue(m.publicMethod(), 42); assert.sameValue(ClassWithPrivateMethod.val(m), 42);
// where superclass prevented extensions & subclass extended // where superclass prevented extensions & subclass extended
assert.throws(TypeError, function () { assert.throws(TypeError, function () {
@ -84,15 +83,14 @@ class ClassWithPrivateAccessor extends TrojanBase {
get #privateAccessor() { get #privateAccessor() {
return 42; return 42;
}; };
// public accessors are on the prototype, so are ok. static val(obj) {
get publicAccessor() { return obj.#privateAccessor;
return this.#privateAccessor;
} }
} }
const a = new ClassWithPrivateAccessor({}); const a = new ClassWithPrivateAccessor({});
// extensible objects can be extended // extensible objects can be extended
assert.sameValue(m.publicAccessor, 42); assert.sameValue(ClassWithPrivateAccessor.val(a), 42);
// where superclass prevented extensions & subclass extended // where superclass prevented extensions & subclass extended
assert.throws(TypeError, function () { assert.throws(TypeError, function () {