Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/private-method-comparison-multiple-evaluations-of-class.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 getter)
6 esid: sec-privatefieldget
7 info: |
8 PrivateFieldGet (P, O)
9 1. Assert: P is a Private Name.
10 2. If O is not an object, throw a TypeError exception.
11 3. If P.[[Kind]] is "field",
12 a. Let entry be PrivateFieldFind(P, O).
13 b. If entry is empty, throw a TypeError exception.
14 c. Return entry.[[PrivateFieldValue]].
15 4. Perform ? PrivateBrandCheck(O, P).
16 5. If P.[[Kind]] is "method",
17 a. Return P.[[Value]].
18 6. Else,
19 a. Assert: P.[[Kind]] is "accessor".
20 b. If P does not have a [[Get]] field, throw a TypeError exception.
21 c. Let getter be P.[[Get]].
22 d. Return ? Call(getter, O).
23
24 PrivateBrandCheck(O, P)
25 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true,
26 a. Throw a TypeError exception.
27 features: [class, class-methods-private]
28 ---*/
29
30 let createAndInstantiateClass = function () {
31 class C {
32 #m() { return 'test262'; }
33
34 getPrivateMethod() {
35 return this.#m;
36 }
37 }
38
39 return new C();
40 };
41
42 let c1 = createAndInstantiateClass();
43 let c2 = createAndInstantiateClass();
44
45 assert.notSameValue(c1.getPrivateMethod(), c2.getPrivateMethod());
46
47 reportCompare(0, 0);