Adding test cases to verify that private methods and accessors are not visible to [[GetOwnProperty]] and [[HasProperty]].

This commit is contained in:
Caio Lima 2019-05-30 18:41:18 +02:00
parent df1a1c75b7
commit f1ac274f9d
9 changed files with 462 additions and 0 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();