From f1ac274f9d3252a6a4276ef1dc2c71b86beb573e Mon Sep 17 00:00:00 2001 From: Caio Lima Date: Thu, 30 May 2019 18:41:18 +0200 Subject: [PATCH] Adding test cases to verify that private methods and accessors are not visible to [[GetOwnProperty]] and [[HasProperty]]. --- .../private-getter-is-not-a-own-property.case | 48 +++++++++++++++++ .../private-method-is-not-a-own-property.case | 49 +++++++++++++++++ .../private-setter-is-not-a-own-property.case | 49 +++++++++++++++++ .../private-getter-is-not-a-own-property.js | 52 ++++++++++++++++++ .../private-method-is-not-a-own-property.js | 53 +++++++++++++++++++ .../private-setter-is-not-a-own-property.js | 53 +++++++++++++++++++ .../private-getter-is-not-a-own-property.js | 52 ++++++++++++++++++ .../private-method-is-not-a-own-property.js | 53 +++++++++++++++++++ .../private-setter-is-not-a-own-property.js | 53 +++++++++++++++++++ 9 files changed, 462 insertions(+) create mode 100644 src/class-elements/private-getter-is-not-a-own-property.case create mode 100644 src/class-elements/private-method-is-not-a-own-property.case create mode 100644 src/class-elements/private-setter-is-not-a-own-property.case create mode 100644 test/language/expressions/class/elements/private-getter-is-not-a-own-property.js create mode 100644 test/language/expressions/class/elements/private-method-is-not-a-own-property.js create mode 100644 test/language/expressions/class/elements/private-setter-is-not-a-own-property.js create mode 100644 test/language/statements/class/elements/private-getter-is-not-a-own-property.js create mode 100644 test/language/statements/class/elements/private-method-is-not-a-own-property.js create mode 100644 test/language/statements/class/elements/private-setter-is-not-a-own-property.js diff --git a/src/class-elements/private-getter-is-not-a-own-property.case b/src/class-elements/private-getter-is-not-a-own-property.case new file mode 100644 index 0000000000..293c343ea6 --- /dev/null +++ b/src/class-elements/private-getter-is-not-a-own-property.case @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Private getter is not stored as an own property of objects +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). +template: default +features: [class-methods-private] +---*/ + +//- elements +get #m() { return "Test262"; } + +checkPrivateGetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m, "Test262"); +} +//- assertions +let c = new C(); +c.checkPrivateGetter(); diff --git a/src/class-elements/private-method-is-not-a-own-property.case b/src/class-elements/private-method-is-not-a-own-property.case new file mode 100644 index 0000000000..5f4b54177a --- /dev/null +++ b/src/class-elements/private-method-is-not-a-own-property.case @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Private method is not stored as an own property of objects +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). +template: default +includes: [compareArray.js] +features: [class-methods-private] +---*/ + +//- elements +#m() { return "Test262"; } + +checkPrivateMethod() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m(), "Test262"); +} +//- assertions +let c = new C(); +c.checkPrivateMethod(); diff --git a/src/class-elements/private-setter-is-not-a-own-property.case b/src/class-elements/private-setter-is-not-a-own-property.case new file mode 100644 index 0000000000..15d493fc54 --- /dev/null +++ b/src/class-elements/private-setter-is-not-a-own-property.case @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Private setter is not stored as an own property of objects +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). +template: default +features: [class-methods-private] +---*/ + +//- elements +set #m(v) { this._v = v; } + +checkPrivateSetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + this.#m = "Test262"; + assert.sameValue(this._v, "Test262"); +} +//- assertions +let c = new C(); +c.checkPrivateSetter(); diff --git a/test/language/expressions/class/elements/private-getter-is-not-a-own-property.js b/test/language/expressions/class/elements/private-getter-is-not-a-own-property.js new file mode 100644 index 0000000000..3b31ded942 --- /dev/null +++ b/test/language/expressions/class/elements/private-getter-is-not-a-own-property.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-getter-is-not-a-own-property.case +// - src/class-elements/default/cls-expr.template +/*--- +description: Private getter is not stored as an own property of objects (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +var C = class { + get #m() { return "Test262"; } + + checkPrivateGetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m, "Test262"); + } +} + +let c = new C(); +c.checkPrivateGetter(); diff --git a/test/language/expressions/class/elements/private-method-is-not-a-own-property.js b/test/language/expressions/class/elements/private-method-is-not-a-own-property.js new file mode 100644 index 0000000000..f494e992b7 --- /dev/null +++ b/test/language/expressions/class/elements/private-method-is-not-a-own-property.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-method-is-not-a-own-property.case +// - src/class-elements/default/cls-expr.template +/*--- +description: Private method is not stored as an own property of objects (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +includes: [compareArray.js] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +var C = class { + #m() { return "Test262"; } + + checkPrivateMethod() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m(), "Test262"); + } +} + +let c = new C(); +c.checkPrivateMethod(); diff --git a/test/language/expressions/class/elements/private-setter-is-not-a-own-property.js b/test/language/expressions/class/elements/private-setter-is-not-a-own-property.js new file mode 100644 index 0000000000..a90dc6dd5a --- /dev/null +++ b/test/language/expressions/class/elements/private-setter-is-not-a-own-property.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-setter-is-not-a-own-property.case +// - src/class-elements/default/cls-expr.template +/*--- +description: Private setter is not stored as an own property of objects (field definitions in a class expression) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +var C = class { + set #m(v) { this._v = v; } + + checkPrivateSetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + this.#m = "Test262"; + assert.sameValue(this._v, "Test262"); + } +} + +let c = new C(); +c.checkPrivateSetter(); diff --git a/test/language/statements/class/elements/private-getter-is-not-a-own-property.js b/test/language/statements/class/elements/private-getter-is-not-a-own-property.js new file mode 100644 index 0000000000..5e38c60e5f --- /dev/null +++ b/test/language/statements/class/elements/private-getter-is-not-a-own-property.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-getter-is-not-a-own-property.case +// - src/class-elements/default/cls-decl.template +/*--- +description: Private getter is not stored as an own property of objects (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +class C { + get #m() { return "Test262"; } + + checkPrivateGetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m, "Test262"); + } +} + +let c = new C(); +c.checkPrivateGetter(); diff --git a/test/language/statements/class/elements/private-method-is-not-a-own-property.js b/test/language/statements/class/elements/private-method-is-not-a-own-property.js new file mode 100644 index 0000000000..584f291912 --- /dev/null +++ b/test/language/statements/class/elements/private-method-is-not-a-own-property.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-method-is-not-a-own-property.case +// - src/class-elements/default/cls-decl.template +/*--- +description: Private method is not stored as an own property of objects (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +includes: [compareArray.js] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +class C { + #m() { return "Test262"; } + + checkPrivateMethod() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + assert.sameValue(this.#m(), "Test262"); + } +} + +let c = new C(); +c.checkPrivateMethod(); diff --git a/test/language/statements/class/elements/private-setter-is-not-a-own-property.js b/test/language/statements/class/elements/private-setter-is-not-a-own-property.js new file mode 100644 index 0000000000..6e7422d6ab --- /dev/null +++ b/test/language/statements/class/elements/private-setter-is-not-a-own-property.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/class-elements/private-setter-is-not-a-own-property.case +// - src/class-elements/default/cls-decl.template +/*--- +description: Private setter is not stored as an own property of objects (field definitions in a class declaration) +esid: prod-FieldDefinition +features: [class-methods-private, class] +flags: [generated] +info: | + PrivateFieldGet (P, O) + 1. Assert: P is a Private Name. + 2. If O is not an object, throw a TypeError exception. + 3. If P.[[Kind]] is "field", + a. Let entry be PrivateFieldFind(P, O). + b. If entry is empty, throw a TypeError exception. + c. Return entry.[[PrivateFieldValue]]. + 4. Perform ? PrivateBrandCheck(O, P). + 5. If P.[[Kind]] is "method", + a. Return P.[[Value]]. + 6. Else, + a. Assert: P.[[Kind]] is "accessor". + b. If P does not have a [[Get]] field, throw a TypeError exception. + c. Let getter be P.[[Get]]. + d. Return ? Call(getter, O). + +---*/ + + +class C { + set #m(v) { this._v = v; } + + checkPrivateSetter() { + assert.sameValue(Object.getOwnPropertyDescriptor(this, "#m"), undefined); + assert.sameValue(Reflect.getOwnPropertyDescriptor(this, "#m"), undefined); + + assert.sameValue(this.hasOwnProperty("#m"), false); + assert.sameValue(Reflect.has(this, "#m"), false); + + assert.compareArray(Object.getOwnPropertyNames(this), []); + assert.compareArray(Reflect.ownKeys(this), []); + + assert.sameValue("#m" in this, false); + + const descriptors = Object.getOwnPropertyDescriptors(this); + assert.sameValue("#m" in descriptors, false); + + this.#m = "Test262"; + assert.sameValue(this._v, "Test262"); + } +} + +let c = new C(); +c.checkPrivateSetter();