tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lexical-super-call-from-within-constructor.js (948B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 es6id: 12.3.5.1
      5 description: >
      6    Runtime Semantics: Evaluation
      7 
      8    SuperCall : super Arguments
      9 
     10    ...
     11    7. Let result be Construct(func, argList, newTarget).
     12    ...
     13    10. Return thisER.BindThisValue(result)
     14 
     15 
     16    8.1.1.3.1 BindThisValue(V)
     17 
     18    ...
     19    3. If envRec.[[thisBindingStatus]] is "initialized", throw a ReferenceError exception.
     20    ...
     21 ---*/
     22 
     23 var count = 0;
     24 
     25 class A {
     26  constructor() {
     27    count++;
     28  }
     29 }
     30 
     31 class B extends A {
     32  constructor() {
     33    super();
     34    // envRec.[[thisBindingStatus]] is "initialized"
     35    this.af = _ => super();
     36  }
     37 }
     38 
     39 var b = new B();
     40 
     41 assert.throws(ReferenceError, function() {
     42  b.af();
     43 });
     44 
     45 
     46 assert.sameValue(count, 2, "The value of `count` is `2`, because S7 of `SuperCall : super Arguments` will call the super constructor.");
     47 
     48 reportCompare(0, 0);