-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
358 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: Instances of WeakRef are extensible | ||
info: | | ||
WeakRef( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
ObjectCreate ( proto [ , internalSlotsList ] ) | ||
4. Set obj.[[Prototype]] to proto. | ||
5. Set obj.[[Extensible]] to true. | ||
6. Return obj. | ||
features: [WeakRef, Reflect] | ||
---*/ | ||
|
||
var wr = new WeakRef({}); | ||
assert.sameValue(Object.isExtensible(wr), true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/built-ins/WeakRef/newtarget-prototype-is-not-object.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: > | ||
[[Prototype]] defaults to %WeakRefPrototype% if NewTarget.prototype is not an object. | ||
info: | | ||
WeakRef( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) | ||
3. Let proto be ? Get(constructor, 'prototype'). | ||
4. If Type(proto) is not Object, then | ||
a. Let realm be ? GetFunctionRealm(constructor). | ||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto. | ||
5. Return proto. | ||
features: [WeakRef, Reflect.construct, Symbol] | ||
---*/ | ||
|
||
var WeakRef; | ||
function newTarget() {} | ||
|
||
newTarget.prototype = undefined; | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is undefined'); | ||
|
||
newTarget.prototype = null; | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is null'); | ||
|
||
newTarget.prototype = true; | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is a Boolean'); | ||
|
||
newTarget.prototype = ''; | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is a String'); | ||
|
||
newTarget.prototype = Symbol(); | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is a Symbol'); | ||
|
||
newTarget.prototype = 1; | ||
WeakRef = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(WeakRef), WeakRef.prototype, 'newTarget.prototype is a Number'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: Default [[Prototype]] value derived from realm of the newTarget | ||
info: | | ||
WeakRef( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, '%WeakRefPrototype%', « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) | ||
3. Let proto be ? Get(constructor, 'prototype'). | ||
4. If Type(proto) is not Object, then | ||
a. Let realm be ? GetFunctionRealm(constructor). | ||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto. | ||
5. Return proto. | ||
features: [WeakRef, cross-realm, Reflect] | ||
---*/ | ||
|
||
var other = $262.createRealm().global; | ||
var newTarget = new other.Function(); | ||
var wr; | ||
|
||
newTarget.prototype = undefined; | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is undefined'); | ||
|
||
newTarget.prototype = null; | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is null'); | ||
|
||
newTarget.prototype = true; | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Boolean'); | ||
|
||
newTarget.prototype = ''; | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a String'); | ||
|
||
newTarget.prototype = Symbol(); | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Symbol'); | ||
|
||
newTarget.prototype = 1; | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), other.WeakRef.prototype, 'newTarget.prototype is a Number'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: > | ||
Return abrupt from getting the NewTarget prototype | ||
info: | | ||
WeakRef ( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) | ||
3. Let proto be ? Get(constructor, 'prototype'). | ||
features: [WeakRef, Reflect.construct] | ||
---*/ | ||
|
||
var calls = 0; | ||
var newTarget = function() {}.bind(null); | ||
Object.defineProperty(newTarget, 'prototype', { | ||
get: function() { | ||
calls += 1; | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
assert.throws(Test262Error, function() { | ||
Reflect.construct(WeakRef, [{}], newTarget); | ||
}); | ||
|
||
assert.sameValue(calls, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: > | ||
The [[Prototype]] internal slot is computed from NewTarget. | ||
info: | | ||
WeakRef ( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) | ||
3. Let proto be ? Get(constructor, 'prototype'). | ||
4. If Type(proto) is not Object, then | ||
a. Let realm be ? GetFunctionRealm(constructor). | ||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto. | ||
5. Return proto. | ||
features: [WeakRef, Reflect.construct] | ||
---*/ | ||
|
||
var wr; | ||
|
||
wr = Reflect.construct(WeakRef, [{}], Object); | ||
assert.sameValue(Object.getPrototypeOf(wr), Object.prototype, 'NewTarget is built-in Object constructor'); | ||
|
||
var newTarget = function() {}.bind(null); | ||
Object.defineProperty(newTarget, 'prototype', { | ||
get: function() { | ||
return Array.prototype; | ||
} | ||
}); | ||
wr = Reflect.construct(WeakRef, [{}], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(wr), Array.prototype, 'NewTarget is BoundFunction with accessor'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: > | ||
The [[Prototype]] internal slot is computed from NewTarget. | ||
info: | | ||
WeakRef ( target ) | ||
... | ||
3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). | ||
4. Perfom ! KeepDuringJob(target). | ||
5. Set weakRef.[[Target]] to target. | ||
6. Return weakRef. | ||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) | ||
... | ||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). | ||
3. Return ObjectCreate(proto, internalSlotsList). | ||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) | ||
3. Let proto be ? Get(constructor, 'prototype'). | ||
4. If Type(proto) is not Object, then | ||
a. Let realm be ? GetFunctionRealm(constructor). | ||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto. | ||
5. Return proto. | ||
features: [WeakRef] | ||
---*/ | ||
|
||
var wr = new WeakRef({}); | ||
assert.sameValue(Object.getPrototypeOf(wr), WeakRef.prototype); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2019 Leo Balter. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-weak-ref-target | ||
description: > | ||
Throws a TypeError if target is not Object | ||
info: | | ||
WeakRef ( target ) | ||
1. If NewTarget is undefined, throw a TypeError exception. | ||
2. If Type(target) is not Object, throw a TypeError exception. | ||
... | ||
features: [WeakRef] | ||
---*/ | ||
|
||
assert.sameValue( | ||
typeof WeakRef, 'function', | ||
'typeof WeakRef is 'function'' | ||
); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(); | ||
}, 'implicit undefined'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(undefined); | ||
}, 'explicit undefined'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(null); | ||
}, 'null'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(1); | ||
}, 'number'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef('Object'); | ||
}, 'string'); | ||
|
||
var s = Symbol(); | ||
assert.throws(TypeError, function() { | ||
new WeakRef(s); | ||
}, 'symbol'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(true); | ||
}, 'Boolean, true'); | ||
|
||
assert.throws(TypeError, function() { | ||
new WeakRef(false); | ||
}, 'Boolean, false'); |
Oops, something went wrong.