proto-from-ctor-realm-two.js (2562B)
1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-array-items 6 description: Default [[Prototype]] value derived from realm of the NewTarget. 7 info: | 8 Array ( ...items ) 9 10 ... 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(numberOfArgs, proto). 14 ... 15 10. Return array. 16 17 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 18 19 ... 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. 24 5. Return proto. 25 features: [cross-realm, Reflect, Symbol] 26 ---*/ 27 28 var other = $262.createRealm().global; 29 var newTarget = new other.Function(); 30 var arr; 31 32 newTarget.prototype = undefined; 33 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 34 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 35 36 newTarget.prototype = null; 37 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 38 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 39 40 newTarget.prototype = false; 41 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 42 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 43 44 newTarget.prototype = ''; 45 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 46 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 47 48 newTarget.prototype = Symbol(); 49 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 50 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 51 52 newTarget.prototype = -1; 53 arr = Reflect.construct(Array, ['a', 'b'], newTarget); 54 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, ["a", "b"], newTarget)) returns other.Array.prototype'); 55 56 reportCompare(0, 0);