proto-from-ctor-realm.js (2292B)
1 // Copyright (C) 2019 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-weak-ref-target 6 description: Default [[Prototype]] value derived from realm of the newTarget 7 info: | 8 WeakRef( target ) 9 10 ... 11 3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, '%WeakRefPrototype%', « [[Target]] »). 12 4. Perfom ! KeepDuringJob(target). 13 5. Set weakRef.[[Target]] to target. 14 6. Return weakRef. 15 16 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 17 18 ... 19 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 20 3. Return ObjectCreate(proto, internalSlotsList). 21 22 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 23 24 3. Let proto be ? Get(constructor, 'prototype'). 25 4. If Type(proto) is not Object, then 26 a. Let realm be ? GetFunctionRealm(constructor). 27 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 28 5. Return proto. 29 features: [WeakRef, cross-realm, Reflect, Symbol] 30 ---*/ 31 32 var other = $262.createRealm().global; 33 var newTarget = new other.Function(); 34 var wr; 35 36 newTarget.prototype = undefined; 37 wr = Reflect.construct(WeakRef, [{}], newTarget); 38 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is undefined'); 39 40 newTarget.prototype = null; 41 wr = Reflect.construct(WeakRef, [{}], newTarget); 42 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is null'); 43 44 newTarget.prototype = true; 45 wr = Reflect.construct(WeakRef, [{}], newTarget); 46 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Boolean'); 47 48 newTarget.prototype = ''; 49 wr = Reflect.construct(WeakRef, [{}], newTarget); 50 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a String'); 51 52 newTarget.prototype = Symbol(); 53 wr = Reflect.construct(WeakRef, [{}], newTarget); 54 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Symbol'); 55 56 newTarget.prototype = 1; 57 wr = Reflect.construct(WeakRef, [{}], newTarget); 58 assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Number'); 59 60 61 reportCompare(0, 0);