blob: 39156a4a2ef3f8af8a0899410cd6c65251b8646a [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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 Murdoch4a90d5f2016-03-22 12:00:34 +00005// Test the ES2015 @@species feature
6
7'use strict';
8
9let TypedArray = Uint8Array.__proto__;
10
11// The @@species property exists on the right objects and has the right values
12
13let classesWithSpecies = [RegExp, Array, TypedArray, ArrayBuffer, Map, Set, Promise];
14let classesWithoutSpecies = [Object, Function, String, Number, Symbol, WeakMap, WeakSet];
15
16for (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
28assertEquals(classesWithSpecies.length,
29 new Set(classesWithSpecies.map(constructor =>
30 Object.getOwnPropertyDescriptor(
31 constructor, Symbol.species).get)
32 ).size);
33
34for (let constructor of classesWithoutSpecies)
35 assertEquals(undefined, constructor[Symbol.species]);