check descriptor before private field access (#12910)
* fix: check descriptor before private field access * add test cases
This commit is contained in:
parent
b12a4de457
commit
70c77e550c
@ -1336,6 +1336,9 @@ helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
|
||||
|
||||
helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
|
||||
export default function _classPrivateFieldDestructureSet(receiver, privateMap) {
|
||||
if (privateMap === undefined) {
|
||||
throw new TypeError("attempted to set private static field before its declaration");
|
||||
}
|
||||
if (!privateMap.has(receiver)) {
|
||||
throw new TypeError("attempted to set private field on non-instance");
|
||||
}
|
||||
@ -1367,6 +1370,9 @@ helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
|
||||
if (receiver !== classConstructor) {
|
||||
throw new TypeError("Private static access of wrong provenance");
|
||||
}
|
||||
if (descriptor === undefined) {
|
||||
throw new TypeError("attempted to get private static field before its declaration");
|
||||
}
|
||||
if (descriptor.get) {
|
||||
return descriptor.get.call(receiver);
|
||||
}
|
||||
@ -1379,6 +1385,9 @@ helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
|
||||
if (receiver !== classConstructor) {
|
||||
throw new TypeError("Private static access of wrong provenance");
|
||||
}
|
||||
if (descriptor === undefined) {
|
||||
throw new TypeError("attempted to set private static field before its declaration");
|
||||
}
|
||||
if (descriptor.set) {
|
||||
descriptor.set.call(receiver, value);
|
||||
} else {
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to get private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static #p;
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static get #p() { return C };
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static get #p() { return C };
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to use private field on non-instance/);
|
||||
@ -0,0 +1,29 @@
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static get #p() { return C };
|
||||
constructor() {
|
||||
C.#p;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to get private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
C.#p = 0;
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
|
||||
expect(() => {
|
||||
class C {
|
||||
static #_ = new C;
|
||||
static set #p(v) {};
|
||||
constructor() {
|
||||
for (C.#p of [0]);
|
||||
}
|
||||
}
|
||||
}).toThrow(/attempted to set private static field before its declaration/);
|
||||
Loading…
x
Reference in New Issue
Block a user