1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
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. Let array be ! ArrayCreate(0, proto).
17 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
20 3. Let proto be ? Get(constructor, "prototype").
21 4. If Type(proto) is not Object, then
22 a. Let realm be ? GetFunctionRealm(constructor).
23 b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
25 features: [cross-realm, Reflect, Symbol]
28 var other = $262.createRealm().global;
29 var newTarget = new other.Function();
32 newTarget.prototype = undefined;
33 arr = Reflect.construct(Array, [1], newTarget);
34 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
36 newTarget.prototype = null;
37 arr = Reflect.construct(Array, [1], newTarget);
38 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
40 newTarget.prototype = true;
41 arr = Reflect.construct(Array, [1], newTarget);
42 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
44 newTarget.prototype = '';
45 arr = Reflect.construct(Array, [1], newTarget);
46 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
48 newTarget.prototype = Symbol();
49 arr = Reflect.construct(Array, [1], newTarget);
50 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');
52 newTarget.prototype = 0;
53 arr = Reflect.construct(Array, [1], newTarget);
54 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype');