Debian Codegraph @

js/src/tests/test262/language/expressions/class/elements/fields-run-once-on-double-super.js

raw
1 // Copyright (C) 2018 Kevin Gibbons. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-super-keyword-runtime-semantics-evaluation
5 description: >
6 when calling `super()` for a second time in a derived class, the super constructor is run twice but the field initializers are only run once
7 info: |
8 [...]
9 6. Let result be ? Construct(func, argList, newTarget).
10 [...]
11 10. Perform ? thisER.BindThisValue(result).
12 11. Perform ? InitializeInstanceFields(result, F).
13 [...]
14 features: [class-fields-public]
15 ---*/
16
17
18 var baseCtorCalled = 0;
19 var fieldInitCalled = 0;
20 class Base {
21 constructor() {
22 ++baseCtorCalled;
23 }
24 }
25
26 var C = class extends Base {
27 field = ++fieldInitCalled;
28 constructor() {
29 assert.sameValue(baseCtorCalled, 0);
30 assert.sameValue(fieldInitCalled, 0);
31 super();
32 assert.sameValue(baseCtorCalled, 1);
33 assert.sameValue(fieldInitCalled, 1);
34 assert.throws(ReferenceError, () => super());
35 }
36 };
37
38 new C();
39
40 assert.sameValue(baseCtorCalled, 2);
41 assert.sameValue(fieldInitCalled, 1);
42
43 reportCompare(0, 0);