tor-browser

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

binding.js (1443B)


      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 subclass binding
      7 ---*/
      8 class Base {
      9  constructor(x, y) {
     10    this.x = x;
     11    this.y = y;
     12  }
     13 }
     14 
     15 var obj = {};
     16 class Subclass extends Base {
     17  constructor(x, y) {
     18    super(x,y);
     19    assert.sameValue(this !== obj, true, "The result of `this !== obj` is `true`");
     20  }
     21 }
     22 
     23 var f = Subclass.bind(obj);
     24 assert.throws(TypeError, function () { f(1, 2); });
     25 var s = new f(1, 2);
     26 assert.sameValue(s.x, 1, "The value of `s.x` is `1`");
     27 assert.sameValue(s.y, 2, "The value of `s.y` is `2`");
     28 assert.sameValue(
     29  Object.getPrototypeOf(s),
     30  Subclass.prototype,
     31  "`Object.getPrototypeOf(s)` returns `Subclass.prototype`"
     32 );
     33 
     34 var s1 = new f(1);
     35 assert.sameValue(s1.x, 1, "The value of `s1.x` is `1`");
     36 assert.sameValue(s1.y, undefined, "The value of `s1.y` is `undefined`");
     37 assert.sameValue(
     38  Object.getPrototypeOf(s1),
     39  Subclass.prototype,
     40  "`Object.getPrototypeOf(s1)` returns `Subclass.prototype`"
     41 );
     42 
     43 var g = Subclass.bind(obj, 1);
     44 assert.throws(TypeError, function () { g(8); });
     45 var s2 = new g(8);
     46 assert.sameValue(s2.x, 1, "The value of `s2.x` is `1`");
     47 assert.sameValue(s2.y, 8, "The value of `s2.y` is `8`");
     48 assert.sameValue(
     49  Object.getPrototypeOf(s),
     50  Subclass.prototype,
     51  "`Object.getPrototypeOf(s)` returns `Subclass.prototype`"
     52 );
     53 
     54 reportCompare(0, 0);