Debian Codegraph @

js/src/tests/test262/language/expressions/class/private-method-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 method)
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 #m() { return 'test262'; }
31
32 access(o) {
33 return o.#m();
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 assert.sameValue(c1.access(c1), 'test262');
46 assert.sameValue(c2.access(c2), 'test262');
47
48 assert.throws(realm1.global.TypeError, function() {
49 c1.access(c2);
50 }, 'invalid access of c1 private method');
51
52 assert.throws(realm2.global.TypeError, function() {
53 c2.access(c1);
54 }, 'invalid access of c2 private method');
55
56 reportCompare(0, 0);