tor-browser

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

default-constructor-2.js (1587B)


      1 // Copyright (C) 2014 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 es6id: 14.5
      5 description: >
      6    class default constructor 2
      7 ---*/
      8 class Base1 { }
      9 assert.throws(TypeError, function() { Base1(); });
     10 
     11 class Subclass1 extends Base1 { }
     12 
     13 assert.throws(TypeError, function() { Subclass1(); });
     14 
     15 var s1 = new Subclass1();
     16 assert.sameValue(
     17  Subclass1.prototype,
     18  Object.getPrototypeOf(s1),
     19  "The value of `Subclass1.prototype` is `Object.getPrototypeOf(s1)`, after executing `var s1 = new Subclass1();`"
     20 );
     21 
     22 class Base2 {
     23  constructor(x, y) {
     24    this.x = x;
     25    this.y = y;
     26  }
     27 }
     28 
     29 class Subclass2 extends Base2 {};
     30 
     31 var s2 = new Subclass2(1, 2);
     32 
     33 assert.sameValue(
     34  Subclass2.prototype,
     35  Object.getPrototypeOf(s2),
     36  "The value of `Subclass2.prototype` is `Object.getPrototypeOf(s2)`, after executing `var s2 = new Subclass2(1, 2);`"
     37 );
     38 assert.sameValue(s2.x, 1, "The value of `s2.x` is `1`");
     39 assert.sameValue(s2.y, 2, "The value of `s2.y` is `2`");
     40 
     41 var f = Subclass2.bind({}, 3, 4);
     42 var s2prime = new f();
     43 assert.sameValue(
     44  Subclass2.prototype,
     45  Object.getPrototypeOf(s2prime),
     46  "The value of `Subclass2.prototype` is `Object.getPrototypeOf(s2prime)`"
     47 );
     48 assert.sameValue(s2prime.x, 3, "The value of `s2prime.x` is `3`");
     49 assert.sameValue(s2prime.y, 4, "The value of `s2prime.y` is `4`");
     50 
     51 
     52 var obj = {};
     53 class Base3 {
     54  constructor() {
     55    return obj;
     56  }
     57 }
     58 
     59 class Subclass3 extends Base3 {};
     60 
     61 var s3 = new Subclass3();
     62 assert.sameValue(s3, obj, "The value of `s3` is `obj`");
     63 
     64 
     65 reportCompare(0, 0);