-
Notifications
You must be signed in to change notification settings - Fork 456
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
224 additions
and
2 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
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) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try forwards arguments | ||
esid: sec-promise.try | ||
features: [promise-try, async] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var sentinel = { sentinel: true }; | ||
|
||
Promise.try(function () { | ||
assert.compareArray( | ||
Array.prototype.slice.call(arguments), | ||
[1, 2, Test262Error, sentinel] | ||
); | ||
|
||
return sentinel; | ||
}, 1, 2, Test262Error, sentinel) | ||
.then(function(v) { | ||
assert.sameValue(v, sentinel); | ||
}) | ||
.then( | ||
function(v) { | ||
$DONE(); | ||
}, | ||
function() { | ||
$DONE('The promise should not be rejected.'); | ||
} | ||
) | ||
|
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,16 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: > | ||
`Promise.try` invoked on a constructor value that throws an error | ||
features: [promise-try] | ||
---*/ | ||
|
||
var CustomPromise = function() { | ||
throw new Test262Error(); | ||
}; | ||
|
||
assert.throws(Test262Error, function() { | ||
Promise.try.call(CustomPromise, function () {}); | ||
}); |
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,27 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try produces instances of the receiver | ||
esid: sec-promise.try | ||
features: [promise-try, class] | ||
---*/ | ||
|
||
var executor = null; | ||
var callCount = 0; | ||
|
||
class SubPromise extends Promise { | ||
constructor(a) { | ||
super(a); | ||
executor = a; | ||
callCount += 1; | ||
} | ||
} | ||
|
||
var instance = Promise.try.call(SubPromise, function () {}); | ||
|
||
assert.sameValue(instance.promise.constructor, SubPromise); | ||
assert.sameValue(instance.promise instanceof SubPromise, true); | ||
|
||
assert.sameValue(callCount, 1); | ||
assert.sameValue(typeof executor, 'function'); |
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,12 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try errors when the receiver is not a constructor | ||
esid: sec-promise.try | ||
features: [promise-try] | ||
---*/ | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(eval); | ||
}); |
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) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try errors when the receiver is not an object | ||
esid: sec-promise.try | ||
features: [promise-try] | ||
---*/ | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(undefined); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(null); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(86); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call('string'); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(true); | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
Promise.try.call(Symbol()); | ||
}); |
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,14 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
description: Promise.try `length` property | ||
includes: [propertyHelper.js] | ||
features: [promise-try] | ||
---*/ | ||
|
||
verifyProperty(Promise.try, "length", { | ||
value: 1, | ||
writable: false, | ||
enumerable: false, | ||
configurable: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
description: Promise.try `name` property | ||
includes: [propertyHelper.js] | ||
features: [promise-try] | ||
---*/ | ||
|
||
verifyProperty(Promise.try, "name", { | ||
value: "try", | ||
writable: false, | ||
enumerable: false, | ||
configurable: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: > | ||
Promise.try does not implement [[Construct]], is not new-able | ||
includes: [isConstructor.js] | ||
features: [Reflect.construct, promise-try] | ||
---*/ | ||
|
||
assert.sameValue(isConstructor(Promise.try), false, 'isConstructor(Promise.all) must return false'); | ||
|
||
assert.throws(TypeError, function () { | ||
new Promise.try(function () {}); | ||
}); | ||
|
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,12 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try return value is a Promise | ||
features: [promise-try] | ||
---*/ | ||
|
||
var instance = Promise.try(function () {}); | ||
|
||
assert.sameValue(instance.promise.constructor, Promise); | ||
assert.sameValue(instance.promise instanceof Promise, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// See LICENSE for details. | ||
|
||
/*--- | ||
author: Jordan Harband | ||
description: Promise.try property descriptor | ||
features: [promise-try] | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyProperty(Promise, 'try', { | ||
value: Promise.try, | ||
writable: true, | ||
enumerable: false, | ||
configurable: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2024 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Promise.try returns a Promise that rejects when the function throws | ||
esid: sec-promise.try | ||
features: [promise-try, async] | ||
---*/ | ||
|
||
|
||
Promise.try(function () { throw new Test262Error(); }) | ||
.then( | ||
function() { | ||
$DONE('The promise should not be fulfilled.'); | ||
}, | ||
function(err) { | ||
assert.throws(Test262Error, function () { throw err; }); | ||
} | ||
) | ||
.then( | ||
function() { | ||
$DONE(); | ||
}, | ||
function() { | ||
$DONE('The promise should not be rejected.'); | ||
} | ||
) |
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