Merge pull request #2188 from caiolima/private-methods-own-property

Verify that private methods and accessors aren't visible to [[GetOwnProperty]] and [[HasProperty]].
This commit is contained in:
Leo Balter 2019-06-26 15:07:47 -04:00 committed by GitHub
commit 1fb2b78a8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 563 additions and 0 deletions

View File

@ -0,0 +1,41 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupGetter__("#m"), undefined);
assert.sameValue(this.#m, "Test262");
return 0;
}
//- assertions
let c = new C();
assert.sameValue(c.checkPrivateGetter(), 0);

View File

@ -0,0 +1,39 @@
// 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
features: [class-methods-private]
---*/
//- elements
#m() { return "Test262"; }
checkPrivateMethod() {
assert.sameValue(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.#m(), "Test262");
return 0;
}
//- assertions
let c = new C();
assert.sameValue(c.checkPrivateMethod(), 0);

View File

@ -0,0 +1,42 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupSetter__("#m"), undefined);
this.#m = "Test262";
assert.sameValue(this._v, "Test262");
return 0;
}
//- assertions
let c = new C();
assert.sameValue(c.checkPrivateSetter(), 0);

View File

@ -0,0 +1,45 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupGetter__("#m"), undefined);
assert.sameValue(this.#m, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateGetter(), 0);

View File

@ -0,0 +1,43 @@
// 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]
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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.#m(), "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateMethod(), 0);

View File

@ -0,0 +1,46 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupSetter__("#m"), undefined);
this.#m = "Test262";
assert.sameValue(this._v, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateSetter(), 0);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Private field is not clobbered by computed property
esid: sec-privatefieldget
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).
features: [class-fields-public, class-fields-private, class]
---*/
class C {
#m = 44;
["#m"] = this.#m / 11;
checkPrivateField() {
assert.sameValue(this.hasOwnProperty("#m"), true);
assert.sameValue("#m" in this, true);
assert.sameValue(this["#m"], 4);
assert.sameValue(this.#m, 44);
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateField(), 0);

View File

@ -0,0 +1,45 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupGetter__("#m"), undefined);
assert.sameValue(this.#m, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateGetter(), 0);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Private getter is not clobbered by computed property
esid: sec-privatefieldget
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).
features: [class-methods-private, class-fields-public, class]
---*/
class C {
get #m() { return "Test262"; }
["#m"] = 0;
checkPrivateGetter() {
assert.sameValue(this.hasOwnProperty("#m"), true);
assert.sameValue("#m" in this, true);
assert.sameValue(this["#m"], 0);
assert.sameValue(this.#m, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateGetter(), 0);

View File

@ -0,0 +1,43 @@
// 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]
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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.#m(), "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateMethod(), 0);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Private method is not clobbered by computed property
esid: sec-privatefieldget
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).
features: [class-methods-private, class-fields-public, class]
---*/
class C {
#m() { return "Test262"; }
["#m"] = 0;
checkPrivateMethod() {
assert.sameValue(this.hasOwnProperty("#m"), true);
assert.sameValue("#m" in this, true);
assert.sameValue(this["#m"], 0);
assert.sameValue(this.#m(), "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateMethod(), 0);

View File

@ -0,0 +1,46 @@
// 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(this.hasOwnProperty("#m"), false);
assert.sameValue("#m" in this, false);
assert.sameValue(this.__lookupSetter__("#m"), undefined);
this.#m = "Test262";
assert.sameValue(this._v, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateSetter(), 0);

View File

@ -0,0 +1,44 @@
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Private setter is not clobbered by computed property
esid: sec-privatefieldget
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).
features: [class-methods-private, class-fields-public, class]
---*/
class C {
set #m(v) { this._v = v; }
["#m"] = 0;
checkPrivateSetter() {
assert.sameValue(this.hasOwnProperty("#m"), true);
assert.sameValue("#m" in this, true);
assert.sameValue(this["#m"], 0);
this.#m = "Test262";
assert.sameValue(this._v, "Test262");
return 0;
}
}
let c = new C();
assert.sameValue(c.checkPrivateSetter(), 0);