Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/static-field-initializer-error.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: Class evaluation is incomplete when initializer resutls in an abrupt completition
6 esid: sec-define-field
7 info: |
8 ClassDefinitionEvaluation:
9 ...
10
11 27. Let staticFields be a new empty List.
12 28. For each ClassElement e in order from elements,
13 a. If IsStatic of e is false, then
14 ...
15 b. Else,
16 i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
17 c. If field is an abrupt completion, then
18 ...
19 d. If field is not empty,
20 i. If IsStatic of e is false, append field to instanceFields.
21 ii. Otherwise, append field to staticFields.
22
23 34. For each item fieldRecord in order from staticFields,
24 a. Perform ? DefineField(F, field).
25 ...
26
27 DefineField(receiver, fieldRecord)
28 1. Assert: Type(receiver) is Object.
29 2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
30 3. Let name be fieldRecord.[[Name]].
31 4. Let initializer be fieldRecord.[[Initializer]].
32 5. If initializer is not empty, then
33 a. Let initValue be ? Call(initializer, receiver).
34 6. Else, let initValue be undefined.
35 7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
36 a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
37 b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
38 8. If fieldName is a Private Name,
39 a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
40 9. Else,
41 a. Assert: IsPropertyKey(fieldName) is true.
42 b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
43 10. Return.
44 features: [class-static-fields-public, class]
45 ---*/
46
47 function initThrows() {
48 throw new Test262Error();
49 }
50
51 assert.throws(Test262Error, function() {
52 class C {
53 static f = initThrows();
54 static g;
55 };
56
57 assert(false, 'this should never execute');
58 }, 'static field initializer should throw exception');
59
60 reportCompare(0, 0);