mirror of
https://github.com/tc39/test262.git
synced 2025-10-18 14:23:54 +02:00
parent
432bc2b863
commit
ac316607ba
@ -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 () {
|
||||||
|
@ -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 () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user