| 1 |
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Every new evaluation of a class creates a different Private Name (private static setter) |
| 6 |
esid: sec-runtime-semantics-evaluate-name |
| 7 |
info: | |
| 8 |
ClassTail : ClassHeritage { ClassBody } |
| 9 |
... |
| 10 |
19. Let F be constructorInfo.[[Closure]]. |
| 11 |
20. If ClassHeritage_opt is present and protoParent is not null, then set F.[[ConstructorKind]] to "derived". |
| 12 |
21. Perform MakeConstructor(F, false, proto). |
| 13 |
22. Perform MakeClassConstructor(F). |
| 14 |
... |
| 15 |
33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, |
| 16 |
a. PrivateBrandAdd(F, F). |
| 17 |
... |
| 18 |
|
| 19 |
PrivateBrandCheck(O, P) |
| 20 |
1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, |
| 21 |
a. Throw a TypeError exception. |
| 22 |
features: [class, class-static-methods-private] |
| 23 |
---*/ |
| 24 |
|
| 25 |
let classStringExpression = ` |
| 26 |
return class { |
| 27 |
static set #m(v) { |
| 28 |
this._v = v; |
| 29 |
} |
| 30 |
|
| 31 |
static access() { |
| 32 |
this.#m = 'test262'; |
| 33 |
} |
| 34 |
} |
| 35 |
`; |
| 36 |
|
| 37 |
let createClass = function () { |
| 38 |
let classFactoryFunction = new Function(classStringExpression); |
| 39 |
return classFactoryFunction(); |
| 40 |
}; |
| 41 |
|
| 42 |
let C1 = createClass(); |
| 43 |
let C2 = createClass(); |
| 44 |
|
| 45 |
C1.access(); |
| 46 |
assert.sameValue(C1._v, 'test262'); |
| 47 |
C2.access(); |
| 48 |
assert.sameValue(C2._v, 'test262'); |
| 49 |
|
| 50 |
assert.throws(TypeError, function() { |
| 51 |
C1.access.call(C2); |
| 52 |
}, 'invalid access of C1 private static setter'); |
| 53 |
|
| 54 |
assert.throws(TypeError, function() { |
| 55 |
C2.access.call(C1); |
| 56 |
}, 'invalid access of C2 private static setter'); |
| 57 |
|
| 58 |
reportCompare(0, 0); |