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