[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);
// extensible objects can be extended
assert.sameValue(m.publicAccessor, 42);
assert.sameValue(a.publicAccessor, 42);
// where superclass prevented extensions & subclass extended
assert.throws(TypeError, function () {

View File

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