tor-browser

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

regular-subclassing.js (908B)


      1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 es6id: 22.1.1
      5 description: Subclassing Array
      6 info: |
      7  22.1.1 The Array Constructor
      8 
      9  The Array constructor is designed to be subclassable. It may be used as the
     10  value of an extends clause of a class definition. (...)
     11 includes: [compareArray.js]
     12 ---*/
     13 
     14 class Sub extends Array {}
     15 
     16 var a1 = new Sub(42, 'foo');
     17 
     18 assert.sameValue(a1.length, 2);
     19 assert.sameValue(a1[0], 42);
     20 assert.sameValue(a1[1], 'foo');
     21 
     22 a1.push(true);
     23 assert.sameValue(a1.length, 3, 'Array#push updates the length property');
     24 assert.sameValue(a1[0], 42);
     25 assert.sameValue(a1[1], 'foo');
     26 assert.sameValue(a1[2], true, 'Adds new item');
     27 
     28 var a2 = new Sub(7);
     29 assert.sameValue(a2.length, 7);
     30 
     31 var a3 = new Sub();
     32 assert.compareArray(a3, []);
     33 assert.sameValue(a3.length, 0);
     34 
     35 reportCompare(0, 0);