forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for double super for proposal-class-fields#92
- Loading branch information
1 parent
1413fc5
commit 2fe5658
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
test/language/expressions/class/fields-run-once-on-double-super.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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); |