| 1 |
// |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')) -- FinalizationRegistry is not enabled unconditionally |
| 2 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-finalization-registry-target |
| 7 |
description: Default [[Prototype]] value derived from realm of the newTarget |
| 8 |
info: | |
| 9 |
FinalizationRegistry ( cleanupCallback ) |
| 10 |
|
| 11 |
... |
| 12 |
3. Let finalizationRegistry be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationRegistryPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationRegistryCleanupJobActive]] »). |
| 13 |
... |
| 14 |
9. Return finalizationRegistry. |
| 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: [FinalizationRegistry, cross-realm, Reflect, Symbol] |
| 30 |
---*/ |
| 31 |
|
| 32 |
var other = $262.createRealm().global; |
| 33 |
var newTarget = new other.Function(); |
| 34 |
function fn() {} |
| 35 |
var finalizationRegistry; |
| 36 |
|
| 37 |
newTarget.prototype = undefined; |
| 38 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 39 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is undefined'); |
| 40 |
|
| 41 |
newTarget.prototype = null; |
| 42 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 43 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is null'); |
| 44 |
|
| 45 |
newTarget.prototype = true; |
| 46 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 47 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Boolean'); |
| 48 |
|
| 49 |
newTarget.prototype = ''; |
| 50 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 51 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a String'); |
| 52 |
|
| 53 |
newTarget.prototype = Symbol(); |
| 54 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 55 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Symbol'); |
| 56 |
|
| 57 |
newTarget.prototype = 1; |
| 58 |
finalizationRegistry = Reflect.construct(FinalizationRegistry, [fn], newTarget); |
| 59 |
assert.sameValue(Object.getPrototypeOf(finalizationRegistry), other.FinalizationRegistry.prototype, 'newTarget.prototype is a Number'); |
| 60 |
|
| 61 |
|
| 62 |
reportCompare(0, 0); |