proto-from-ctor-realm-one.js (2457B)
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-len 6 description: Default [[Prototype]] value derived from realm of the NewTarget. 7 info: | 8 Array ( len ) 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(0, proto). 14 ... 15 9. 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, [1], newTarget); 34 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [1], newTarget)) returns other.Array.prototype'); 35 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'); 39 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'); 43 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'); 47 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'); 51 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'); 55 56 reportCompare(0, 0);