Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down