forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function branding boilerplate tests from PR tc39#3866
- Loading branch information
Showing
31 changed files
with
1,517 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
test/built-ins/AsyncDisposableStack/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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack | ||
description: > | ||
[[Prototype]] defaults to %AsyncDisposableStack.prototype% if NewTarget.prototype is not an object. | ||
info: | | ||
AsyncDisposableStack( target ) | ||
... | ||
2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »). | ||
3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending. | ||
4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability(). | ||
5. Return asyncDisposableStack. | ||
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: [explicit-resource-management, Reflect.construct, Symbol] | ||
---*/ | ||
|
||
var stack; | ||
function newTarget() {} | ||
|
||
newTarget.prototype = undefined; | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is undefined'); | ||
|
||
newTarget.prototype = null; | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is null'); | ||
|
||
newTarget.prototype = true; | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is a Boolean'); | ||
|
||
newTarget.prototype = ''; | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is a String'); | ||
|
||
newTarget.prototype = Symbol(); | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is a Symbol'); | ||
|
||
newTarget.prototype = 1; | ||
stack = Reflect.construct(AsyncDisposableStack, [], newTarget); | ||
assert.sameValue(Object.getPrototypeOf(stack), AsyncDisposableStack.prototype, 'newTarget.prototype is a Number'); |
42 changes: 42 additions & 0 deletions
42
...isposableStack/prototype/adopt/this-does-not-have-internal-asyncdisposablestate-throws.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,42 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.adopt | ||
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot | ||
info: | | ||
AsyncDisposableStack.prototype.adopt ( value, onDisposeAsync ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
3. ... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
2. If O does not have an internalSlot internal slot, throw a TypeError exception. | ||
... | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.sameValue(typeof AsyncDisposableStack.prototype.adopt, 'function'); | ||
|
||
var adopt = AsyncDisposableStack.prototype.adopt; | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call({ ['[[AsyncDisposableState]]']: {} }); | ||
}, 'Ordinary object without [[AsyncDisposableState]]'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(AsyncDisposableStack.prototype); | ||
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(AsyncDisposableStack); | ||
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
var stack = new DisposableStack(); | ||
assert.throws(TypeError, function() { | ||
adopt.call(stack); | ||
}, 'DisposableStack instance'); |
53 changes: 53 additions & 0 deletions
53
test/built-ins/AsyncDisposableStack/prototype/adopt/this-not-object-throws.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,53 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.adopt | ||
description: Throws a TypeError if this is not an Object | ||
info: | | ||
AsyncDisposableStack.prototype.adopt ( value, onDisposeAsync ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
... | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.sameValue(typeof AsyncDisposableStack.prototype.adopt, 'function'); | ||
|
||
var adopt = AsyncDisposableStack.prototype.adopt; | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(undefined); | ||
}, 'undefined'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(null); | ||
}, 'null'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(true); | ||
}, 'true'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(false); | ||
}, 'false'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call(1); | ||
}, 'number'); | ||
|
||
assert.throws(TypeError, function() { | ||
adopt.call('object'); | ||
}, 'string'); | ||
|
||
var s = Symbol(); | ||
assert.throws(TypeError, function() { | ||
adopt.call(s); | ||
}, 'symbol'); |
42 changes: 42 additions & 0 deletions
42
...isposableStack/prototype/defer/this-does-not-have-internal-asyncdisposablestate-throws.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,42 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.defer | ||
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot | ||
info: | | ||
AsyncDisposableStack.prototype.defer ( ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
3. ... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
2. If O does not have an internalSlot internal slot, throw a TypeError exception. | ||
... | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.sameValue(typeof AsyncDisposableStack.prototype.defer, 'function'); | ||
|
||
var defer = AsyncDisposableStack.prototype.defer; | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call({ ['[[AsyncDisposableState]]']: {} }); | ||
}, 'Ordinary object without [[AsyncDisposableState]]'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(AsyncDisposableStack.prototype); | ||
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(AsyncDisposableStack); | ||
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
var stack = new DisposableStack(); | ||
assert.throws(TypeError, function() { | ||
defer.call(stack); | ||
}, 'DisposableStack instance'); |
53 changes: 53 additions & 0 deletions
53
test/built-ins/AsyncDisposableStack/prototype/defer/this-not-object-throws.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,53 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.defer | ||
description: Throws a TypeError if this is not an Object | ||
info: | | ||
AsyncDisposableStack.prototype.defer ( ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
... | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.sameValue(typeof AsyncDisposableStack.prototype.defer, 'function'); | ||
|
||
var defer = AsyncDisposableStack.prototype.defer; | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(undefined); | ||
}, 'undefined'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(null); | ||
}, 'null'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(true); | ||
}, 'true'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(false); | ||
}, 'false'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call(1); | ||
}, 'number'); | ||
|
||
assert.throws(TypeError, function() { | ||
defer.call('object'); | ||
}, 'string'); | ||
|
||
var s = Symbol(); | ||
assert.throws(TypeError, function() { | ||
defer.call(s); | ||
}, 'symbol'); |
46 changes: 46 additions & 0 deletions
46
...eStack/prototype/disposeAsync/this-does-not-have-internal-asyncdisposablestate-rejects.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,46 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.disposeAsync | ||
description: Throws a TypeError if this does not have a [[AsyncDisposableState]] internal slot | ||
info: | | ||
AsyncDisposableStack.prototype.disposeAsync ( ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
3. ... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
2. If O does not have an internalSlot internal slot, throw a TypeError exception. | ||
... | ||
flags: [async] | ||
includes: [asyncHelpers.js] | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
asyncTest(async function() { | ||
assert.sameValue(typeof AsyncDisposableStack.prototype.disposeAsync, 'function'); | ||
|
||
var disposeAsync = AsyncDisposableStack.prototype.disposeAsync; | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call({ ['[[AsyncDisposableState]]']: {} }); | ||
}, 'Ordinary object without [[AsyncDisposableState]]'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(AsyncDisposableStack.prototype); | ||
}, 'AsyncDisposableStack.prototype does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(AsyncDisposableStack); | ||
}, 'AsyncDisposableStack does not have a [[AsyncDisposableState]] internal slot'); | ||
|
||
var stack = new DisposableStack(); | ||
await assert.throwsAsync(TypeError, function () { | ||
return disposeAsync.call(stack); | ||
}, 'DisposableStack instance'); | ||
}); |
57 changes: 57 additions & 0 deletions
57
test/built-ins/AsyncDisposableStack/prototype/disposeAsync/this-not-object-rejects.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,57 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-asyncdisposablestack.prototype.disposeAsync | ||
description: Throws a TypeError if this is not an Object | ||
info: | | ||
AsyncDisposableStack.prototype.disposeAsync ( ) | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
... | ||
flags: [async] | ||
includes: [asyncHelpers.js] | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.sameValue(typeof AsyncDisposableStack.prototype.disposeAsync, 'function'); | ||
|
||
var disposeAsync = AsyncDisposableStack.prototype.disposeAsync; | ||
|
||
asyncTest(async function () { | ||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(undefined); | ||
}, 'undefined'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(null); | ||
}, 'null'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(true); | ||
}, 'true'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(false); | ||
}, 'false'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(1); | ||
}, 'number'); | ||
|
||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call('object'); | ||
}, 'string'); | ||
|
||
var s = Symbol(); | ||
await assert.throwsAsync(TypeError, function() { | ||
return disposeAsync.call(s); | ||
}, 'symbol'); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...yncDisposableStack/prototype/disposed/does-not-have-asyncdisposablestate-internal-slot.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,32 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-get-asyncdisposablestack.prototype.disposed | ||
description: > | ||
Throws a TypeError if `this` object does not have a [[AsyncDisposableState]] internal slot. | ||
info: | | ||
get AsyncDisposableStack.prototype.disposed | ||
1. Let asyncDisposableStack be the this value. | ||
2. Perform ? RequireInternalSlot(asyncDisposableStack, [[AsyncDisposableState]]). | ||
... | ||
RequireInternalSlot ( O, internalSlot ) | ||
1. If O is not an Object, throw a TypeError exception. | ||
2. If O does not have an internalSlot internal slot, throw a TypeError exception. | ||
... | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
var descriptor = Object.getOwnPropertyDescriptor(AsyncDisposableStack.prototype, 'disposed'); | ||
|
||
var stack = new AsyncDisposableStack(); | ||
|
||
// Does not throw | ||
descriptor.get.call(stack); | ||
|
||
assert.throws(TypeError, function() { | ||
descriptor.get.call([]); | ||
}); |
Oops, something went wrong.