Debian Codegraph @

js/src/tests/test262/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval.js

raw
1 // Copyright (C) 2019 Jaideep Bhoosreddy (Bloomberg LP). 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 brand (private setter)
6 esid: sec-privatefieldget
7 info: |
8 ClassTail : ClassHeritage { ClassBody }
9 ...
10 11. Let proto be ObjectCreate(protoParent).
11 ...
12 31. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that the P's [[Kind]] field is either "method" or "accessor",
13 a. Set F.[[PrivateBrand]] to proto.
14 ...
15
16 PrivateBrandCheck(O, P)
17 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true,
18 a. Throw a TypeError exception.
19 features: [class, class-methods-private]
20 flags: [noStrict]
21 ---*/
22
23 let classStringExpression = `(
24 class {
25 set #m(v) { this._v = v; }
26
27 access(o, v) {
28 o.#m = v;
29 }
30 }
31 )`;
32
33 let createAndInstantiateClass = function () {
34 return new (eval(classStringExpression));
35 };
36
37 let c1 = createAndInstantiateClass();
38 let c2 = createAndInstantiateClass();
39
40 c1.access(c1, 'test262');
41 assert.sameValue(c1._v, 'test262');
42 c2.access(c2, 'test262');
43 assert.sameValue(c2._v, 'test262');
44
45 assert.throws(TypeError, function() {
46 c1.access(c2, 'foo');
47 }, 'invalid access of c1 private method');
48
49 assert.throws(TypeError, function() {
50 c2.access(c1, 'foo');
51 }, 'invalid access of c2 private method');
52
53 reportCompare(0, 0);