Debian Codegraph @

js/src/tests/test262/language/expressions/class/private-static-method-brand-check-multiple-evaluations-of-class-realm.js

raw
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 brand (private static methods)
6 esid: sec-privatefieldget
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, cross-realm]
23 flags: [noStrict]
24 ---*/
25
26 let global1 = $262.createRealm().global;
27 let global2 = $262.createRealm().global;
28 let eval1 = global1.eval;
29 let eval2 = global2.eval;
30
31 let classStringExpression = `(
32 class {
33 static #m() { return 'test262'; }
34
35 static access() {
36 return this.#m();
37 }
38 }
39 )`;
40
41 let createClass = function (_eval) {
42 return _eval(classStringExpression);
43 };
44
45 let C1 = createClass(eval1);
46 let C2 = createClass(eval2);
47
48 assert.sameValue(C1.access(), 'test262');
49 assert.sameValue(C2.access(), 'test262');
50
51 assert.throws(global1.TypeError, function() {
52 C1.access.call(C2);
53 }, 'invalid access of c1 private static method');
54
55 assert.throws(global2.TypeError, function() {
56 C2.access.call(C1);
57 }, 'invalid access of c2 private static method');
58
59 reportCompare(0, 0);