summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/expressions/class/elements/fields-run-once-on-double-super.js
blob: 51210282162746980871f57574b4ff088bca2d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2018 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-super-keyword-runtime-semantics-evaluation
description: >
    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
info: |
    [...]
    6. Let result be ? Construct(func, argList, newTarget).
    [...]
    10. Perform ? thisER.BindThisValue(result).
    11. Perform ? InitializeInstanceFields(result, F).
    [...]
features: [class-fields-public]
---*/


var baseCtorCalled = 0;
var fieldInitCalled = 0;
class Base {
  constructor() {
    ++baseCtorCalled;
  }
}

var C = class extends Base {
  field = ++fieldInitCalled;
  constructor() {
    assert.sameValue(baseCtorCalled, 0);
    assert.sameValue(fieldInitCalled, 0);
    super();
    assert.sameValue(baseCtorCalled, 1);
    assert.sameValue(fieldInitCalled, 1);
    assert.throws(ReferenceError, () => super());
  }
};

new C();

assert.sameValue(baseCtorCalled, 2);
assert.sameValue(fieldInitCalled, 1);

reportCompare(0, 0);