Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/set-access-of-missing-private-static-setter.js

raw
1 // Copyright (C) 2021 André Bargull. 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 member without setter 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-static-methods-private, class]
25 ---*/
26
27 class C {
28 static get #f() {
29 throw new Test262Error();
30 }
31
32 static setAccess() {
33 this.#f = 'Test262';
34 }
35 }
36
37 assert.throws(TypeError, function() {
38 C.setAccess();
39 }, 'set operation on private accessor without setter should throw TypeError');
40
41 reportCompare(0, 0);