constructor-this-tdz-during-initializers.js (1135B)
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 `this` is bound in the constructor of derived classes immediately before running initializers 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 probeCtorThis; 19 var thisDuringField; 20 var thisFromProbe; 21 var thisDuringCtor; 22 23 class Base { 24 constructor() { 25 assert.throws(ReferenceError, probeCtorThis); 26 } 27 } 28 29 var C = class extends Base { 30 field = (thisDuringField = this, thisFromProbe = probeCtorThis()); 31 constructor() { 32 probeCtorThis = () => this; 33 assert.throws(ReferenceError, probeCtorThis); 34 super(); 35 thisDuringCtor = this; 36 } 37 }; 38 39 var instance = new C(); 40 41 assert.sameValue(thisDuringField, instance); 42 assert.sameValue(thisFromProbe, instance); 43 assert.sameValue(thisDuringCtor, instance); 44 45 reportCompare(0, 0);