Skip to content

Commit

Permalink
Add test for proposal-class-fields#92
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored and chicoxyzzy committed May 14, 2019
1 parent e4b6ecb commit 1413fc5
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,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: >
`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);

0 comments on commit 1413fc5

Please sign in to comment.