| OLD | NEW |
| (Empty) |
| 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: --harmony-species | |
| 6 | |
| 7 // Test the ES2015 @@species feature | |
| 8 | |
| 9 'use strict'; | |
| 10 | |
| 11 let TypedArray = Uint8Array.__proto__; | |
| 12 | |
| 13 // The @@species property exists on the right objects and has the right values | |
| 14 | |
| 15 let classesWithSpecies = [RegExp, Array, TypedArray, ArrayBuffer, Map, Set, Prom
ise]; | |
| 16 let classesWithoutSpecies = [Object, Function, String, Number, Symbol, WeakMap,
WeakSet]; | |
| 17 | |
| 18 for (let constructor of classesWithSpecies) { | |
| 19 assertEquals(constructor, constructor[Symbol.species]); | |
| 20 assertThrows(function() { constructor[Symbol.species] = undefined }, TypeError
); | |
| 21 let descriptor = Object.getOwnPropertyDescriptor(constructor, Symbol.species); | |
| 22 assertTrue(descriptor.configurable); | |
| 23 assertFalse(descriptor.enumerable); | |
| 24 assertEquals(undefined, descriptor.writable); | |
| 25 assertEquals(undefined, descriptor.set); | |
| 26 assertEquals('function', typeof descriptor.get); | |
| 27 } | |
| 28 | |
| 29 // @@species is defined with distinct getters | |
| 30 assertEquals(classesWithSpecies.length, | |
| 31 new Set(classesWithSpecies.map(constructor => | |
| 32 Object.getOwnPropertyDescriptor( | |
| 33 constructor, Symbol.species).get) | |
| 34 ).size); | |
| 35 | |
| 36 for (let constructor of classesWithoutSpecies) | |
| 37 assertEquals(undefined, constructor[Symbol.species]); | |
| OLD | NEW |