Debian Codegraph @

js/src/tests/test262/language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-realm.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, cross-realm]
20 flags: [noStrict]
21 ---*/
22
23 let realm1 = $262.createRealm();
24 let realm2 = $262.createRealm();
25 let eval1 = realm1.global.eval;
26 let eval2 = realm2.global.eval;
27
28 let classStringExpression = `(
29 class {
30 set #m(v) { this._v = v; }
31
32 access(o, v) {
33 o.#m = v;
34 }
35 }
36 )`;
37
38 let createAndInstantiateClass = function (_eval) {
39 return new (_eval(classStringExpression));
40 };
41
42 let c1 = createAndInstantiateClass(eval1);
43 let c2 = createAndInstantiateClass(eval2);
44
45 c1.access(c1, 'test262');
46 assert.sameValue(c1._v, 'test262');
47 c2.access(c2, 'test262');
48 assert.sameValue(c2._v, 'test262');
49
50 assert.throws(realm1.global.TypeError, function() {
51 c1.access(c2, 'foo');
52 }, 'invalid access of c1 private method');
53
54 assert.throws(realm2.global.TypeError, function() {
55 c2.access(c1, 'foo');
56 }, 'invalid access of c2 private method');
57
58 reportCompare(0, 0);