Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/set-access-of-private-method.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: Trying to set a private method throws TypeError
6 esid: sec-privatefieldset
7 info: |
8 PrivateFieldSet ( P, O, value )
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. Set entry.[[PrivateFieldValue]] to value.
15 d. Return.
16 4. If P.[[Kind]] is "method", throw a TypeError exception.
17 5. Else,
18 a. Assert: P.[[Kind]] is "accessor".
19 b. If O.[[PrivateFieldBrands]] does not contain P.[[Brand]], throw a TypeError exception.
20 c. If P does not have a [[Set]] field, throw a TypeError exception.
21 d. Let setter be P.[[Set]].
22 e. Perform ? Call(setter, O, value).
23 f. Return.
24 features: [class-methods-private, class]
25 ---*/
26
27 class C {
28 #f() {
29 throw new Test262Error();
30 }
31
32 setAccess() {
33 this.#f = 'Test262';
34 }
35 }
36
37 let c = new C();
38 assert.throws(TypeError, function() {
39 c.setAccess();
40 }, 'set operation on private method should throw TypeError');
41
42
43 reportCompare(0, 0);