Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/privatefieldget-primitive-receiver.js

raw
1 // Copyright (C) 2020 Caio Lima (Igalia S.L). All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: PrivateField calls ToObject when receiver is a primitive
6 esid: sec-getvalue
7 info: |
8 GetValue ( V )
9 ...
10 5. If IsPropertyReference(V), then
11 a. If HasPrimitiveBase(V), then
12 i. Assert: In this case, base will never be null or undefined.
13 ii. Let base be ToObject(base).
14 b. If IsPrivateReference(V), then
15 i. Return ? PrivateFieldGet(field, base).
16 ...
17
18 PrivateFieldGet (P, O )
19 1. Assert: P is a Private Name value.
20 2. If O is not an object, throw a TypeError exception.
21 3. Let entry be PrivateFieldFind(P, O).
22 4. If entry is empty, throw a TypeError exception.
23 5. Return entry.[[PrivateFieldValue]].
24
25 features: [class, class-fields-private, BigInt]
26 ---*/
27
28 let count = 0;
29
30 class C {
31 #p = 1;
32
33 method() {
34 count++;
35 try {
36 count++;
37 this.#p;
38 } catch (e) {
39 count++;
40 if (e instanceof TypeError) {
41 throw new Test262Error();
42 }
43 }
44 }
45 }
46
47 assert.throws(Test262Error, () => {
48 new C().method.call(15);
49 });
50 assert.sameValue(count, 3);
51
52 assert.throws(Test262Error, () => {
53 new C().method.call('Test262');
54 });
55 assert.sameValue(count, 6);
56
57 assert.throws(Test262Error, () => {
58 new C().method.call(Symbol('Test262'));
59 });
60 assert.sameValue(count, 9);
61
62 assert.throws(Test262Error, () => {
63 new C().method.call(15n);
64 });
65 assert.sameValue(count, 12);
66
67 assert.throws(Test262Error, () => {
68 new C().method.call(null);
69 });
70 assert.sameValue(count, 15);
71
72 assert.throws(Test262Error, () => {
73 new C().method.call(undefined);
74 });
75 assert.sameValue(count, 18);
76
77
78 reportCompare(0, 0);