Home | History | Annotate | Download | only in es6
      1 // Copyright 2015 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Flags: --noharmony-species
      6 
      7 // Before Symbol.species was added, ArrayBuffer subclasses constructed
      8 // ArrayBuffers, and Array subclasses constructed Arrays, but TypedArray and
      9 // Promise subclasses constructed an instance of the subclass.
     10 
     11 'use strict';
     12 
     13 assertEquals(undefined, Symbol.species);
     14 
     15 class MyArray extends Array { }
     16 let myArray = new MyArray();
     17 assertEquals(MyArray, myArray.constructor);
     18 assertEquals(Array, myArray.map(x => x + 1).constructor);
     19 assertEquals(Array, myArray.concat().constructor);
     20 
     21 class MyUint8Array extends Uint8Array { }
     22 Object.defineProperty(MyUint8Array.prototype, "BYTES_PER_ELEMENT", {value: 1});
     23 let myTypedArray = new MyUint8Array(3);
     24 assertEquals(MyUint8Array, myTypedArray.constructor);
     25 assertEquals(MyUint8Array, myTypedArray.map(x => x + 1).constructor);
     26 
     27 class MyArrayBuffer extends ArrayBuffer { }
     28 let myBuffer = new MyArrayBuffer(0);
     29 assertEquals(MyArrayBuffer, myBuffer.constructor);
     30 assertEquals(ArrayBuffer, myBuffer.slice().constructor);
     31 
     32 class MyPromise extends Promise { }
     33 let myPromise = new MyPromise(() => {});
     34 assertEquals(MyPromise, myPromise.constructor);
     35 assertEquals(MyPromise, myPromise.then().constructor);
     36 
     37 // However, subarray instantiates members of the parent class
     38 assertEquals(Uint8Array, myTypedArray.subarray(1).constructor);
     39