Debian Codegraph @

js/src/tests/test262/language/expressions/class/private-method-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 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]
20 flags: [noStrict]
21 ---*/
22
23 let classStringExpression = `(
24 class C {
25 #m() { return 'test262'; }
26
27 access(o) {
28 return o.#m();
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 assert.sameValue(c1.access(c1), 'test262');
41 assert.sameValue(c2.access(c2), 'test262');
42
43 assert.throws(TypeError, function() {
44 c1.access(c2);
45 }, 'invalid access of c1 private method');
46
47 assert.throws(TypeError, function() {
48 c2.access(c1);
49 }, 'invalid access of c2 private method');
50
51 reportCompare(0, 0);