Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/private-setter-brand-check-super-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: Subclass can access private methods of a superclass (private setter)
6 esid: sec-privatefieldget
7 info: |
8 SuperCall : super Arguments
9 ...
10 10. Perform ? InitializeInstanceElements(result, F).
11 ...
12
13 InitializeInstanceFieldsElements ( O, constructor )
14 1. Assert: Type ( O ) is Object.
15 2. Assert: Assert constructor is an ECMAScript function object.
16 3. If constructor.[[PrivateBrand]] is not undefined,
17 a. Perform ? PrivateBrandAdd(O, constructor.[[PrivateBrand]]).
18 4. Let fieldRecords be the value of constructor's [[Fields]] internal slot.
19 5. For each item fieldRecord in order from fieldRecords,
20 a. Perform ? DefineField(O, fieldRecord).
21 6. Return.
22 features: [class, class-methods-private]
23 ---*/
24
25 class S {
26 set #m(v) { this._v = v }
27
28 superAccess(v) { this.#m = v; }
29 }
30
31 class C extends S {
32 set #m(v) { this._u = v; }
33
34 access(v) {
35 return this.#m = v;
36 }
37 }
38
39 let c = new C();
40
41 c.access('test262');
42 assert.sameValue(c._u, 'test262');
43
44 c.superAccess('super class');
45 assert.sameValue(c._v, 'super class');
46
47 let s = new S();
48 s.superAccess('super class')
49 assert.sameValue(s._v, 'super class');
50
51 assert.throws(TypeError, function() {
52 c.access.call(s, 'foo');
53 }, 'invalid access of C private method');
54
55 reportCompare(0, 0);