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