blob: da1df4331fc948e7f9b927dacbda1a9b320f8f31 [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
5// Flags: --harmony-species
6
7// Test the ES2015 @@species feature
8
9'use strict';
10
11let TypedArray = Uint8Array.__proto__;
12
13// The @@species property exists on the right objects and has the right values
14
15let classesWithSpecies = [RegExp, Array, TypedArray, ArrayBuffer, Map, Set, Promise];
16let classesWithoutSpecies = [Object, Function, String, Number, Symbol, WeakMap, WeakSet];
17
18for (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
30assertEquals(classesWithSpecies.length,
31 new Set(classesWithSpecies.map(constructor =>
32 Object.getOwnPropertyDescriptor(
33 constructor, Symbol.species).get)
34 ).size);
35
36for (let constructor of classesWithoutSpecies)
37 assertEquals(undefined, constructor[Symbol.species]);