1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
5 esid: sec-array-constructor-array
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
11 3. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
12 4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%").
13 5. Return ! ArrayCreate(0, proto).
15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
18 3. Let proto be ? Get(constructor, "prototype").
19 4. If Type(proto) is not Object, then
20 a. Let realm be ? GetFunctionRealm(constructor).
21 b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
23 features: [cross-realm, Reflect, Symbol]
26 var other = $262.createRealm().global;
27 var newTarget = new other.Function();
30 newTarget.prototype = undefined;
31 arr = Reflect.construct(Array, [], newTarget);
32 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
34 newTarget.prototype = null;
35 arr = Reflect.construct(Array, [], newTarget);
36 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
38 newTarget.prototype = true;
39 arr = Reflect.construct(Array, [], newTarget);
40 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
42 newTarget.prototype = 'str';
43 arr = Reflect.construct(Array, [], newTarget);
44 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
46 newTarget.prototype = Symbol();
47 arr = Reflect.construct(Array, [], newTarget);
48 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
50 newTarget.prototype = 1;
51 arr = Reflect.construct(Array, [], newTarget);
52 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');