proto-from-ctor-realm.js (2792B)
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-finalization-registry-target 6 description: Default [[Prototype]] value derived from realm of the newTarget 7 info: | 8 FinalizationRegistry ( cleanupCallback ) 9 10 ... 11 3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »). 12 ... 13 9. Return finalizationRegistry. 14 15 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 16 17 ... 18 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 19 3. Return ObjectCreate(proto, internalSlotsList). 20 21 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 22 23 3. Let proto be ? Get(constructor, 'prototype'). 24 4. If Type(proto) is not Object, then 25 a. Let realm be ? GetFunctionRealm(constructor). 26 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 27 5. Return proto. 28 features: [FinalizationRegistry, cross-realm, Reflect, Symbol] 29 ---*/ 30 31 var other = $262.createRealm().global; 32 var newTarget = new other.Function(); 33 function fn() {} 34 var finalizationRegistry; 35 36 newTarget.prototype = undefined; 37 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 38 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is undefined'); 39 40 newTarget.prototype = null; 41 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 42 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is null'); 43 44 newTarget.prototype = true; 45 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 46 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Boolean'); 47 48 newTarget.prototype = ''; 49 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 50 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a String'); 51 52 newTarget.prototype = Symbol(); 53 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 54 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Symbol'); 55 56 newTarget.prototype = 1; 57 finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); 58 assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Number'); 59 60 61 reportCompare(0, 0);