Skip to content
Snippets Groups Projects
Unverified Commit ee3a57ca authored by Rick Waldron's avatar Rick Waldron Committed by GitHub
Browse files

Merge pull request #1507 from bakkot/field-ref-error

Add test for proposal-class-fields#92
parents 3e4f58de 49039979
No related branches found
No related tags found
No related merge requests found
// 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: >
`this` is bound in the constructor of derived classes immediately before running initializers
info: |
[...]
6. Let result be ? Construct(func, argList, newTarget).
[...]
10. Perform ? thisER.BindThisValue(result).
11. Perform ? InitializeInstanceFields(result, F).
[...]
features: [class-fields-public]
---*/
var probeCtorThis;
var thisDuringField;
var thisFromProbe;
var thisDuringCtor;
class Base {
constructor() {
assert.throws(ReferenceError, probeCtorThis);
}
}
var C = class extends Base {
field = (thisDuringField = this, thisFromProbe = probeCtorThis());
constructor() {
probeCtorThis = () => this;
assert.throws(ReferenceError, probeCtorThis);
super();
thisDuringCtor = this;
}
};
var instance = new C();
assert.sameValue(thisDuringField, instance);
assert.sameValue(thisFromProbe, instance);
assert.sameValue(thisDuringCtor, instance);
// 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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment