mirror of https://github.com/tc39/test262.git
add Promise.try tests
This commit is contained in:
parent
a7e796a4ce
commit
8b6b0f516d
|
@ -105,6 +105,10 @@ iterator-helpers
|
|||
# https://github.com/tc39/proposal-promise-with-resolvers
|
||||
promise-with-resolvers
|
||||
|
||||
# Promise.try
|
||||
# https://github.com/tc39/proposal-promise-try
|
||||
promise-try
|
||||
|
||||
# Set methods
|
||||
# https://github.com/tc39/proposal-set-methods
|
||||
set-methods
|
||||
|
|
|
@ -21,7 +21,7 @@ info: |
|
|||
Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
|
||||
|
||||
flags: [async]
|
||||
includes: [compareArray.js,promiseHelper.js]
|
||||
includes: [compareArray.js, promiseHelper.js]
|
||||
---*/
|
||||
|
||||
let a = new Promise((_, reject) => reject('a'));
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// 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]
|
||||
flags: [async]
|
||||
includes: [asyncHelpers.js, compareArray.js]
|
||||
---*/
|
||||
|
||||
var sentinel = { sentinel: true };
|
||||
|
||||
asyncTest(
|
||||
Promise.try(function () {
|
||||
assert.compareArray(
|
||||
Array.prototype.slice.call(arguments),
|
||||
[1, 2, Test262Error, sentinel]
|
||||
);
|
||||
}, 1, 2, Test262Error, sentinel)
|
||||
);
|
||||
|
|
@ -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 () {});
|
||||
});
|
|
@ -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');
|
|
@ -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);
|
||||
});
|
|
@ -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());
|
||||
});
|
|
@ -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
|
||||
});
|
|
@ -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
|
||||
});
|
|
@ -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 () {});
|
||||
});
|
||||
|
|
@ -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.constructor, Promise);
|
||||
assert.sameValue(instance instanceof Promise, true);
|
|
@ -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
|
||||
})
|
|
@ -0,0 +1,21 @@
|
|||
// 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 resolved to the callback's return value
|
||||
esid: sec-promise.try
|
||||
features: [promise-try]
|
||||
flags: [async]
|
||||
includes: [asyncHelpers.js]
|
||||
---*/
|
||||
|
||||
var sentinel = { sentinel: true };
|
||||
|
||||
asyncTest(
|
||||
Promise.try(function () {
|
||||
return sentinel;
|
||||
}).then(function (v) {
|
||||
assert.sameValue(v, sentinel);
|
||||
})
|
||||
);
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// 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]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
assert.throwsAsync(
|
||||
Test262Error,
|
||||
function () {
|
||||
Promise.try(function () { throw new Test262Error(); })
|
||||
},
|
||||
"error thrown from callback must become a rejection"
|
||||
);
|
|
@ -4,7 +4,7 @@
|
|||
/*---
|
||||
description: Promise.withResolvers produces instances of the receiver
|
||||
esid: sec-promise.withresolvers
|
||||
features: [promise-with-resolvers]
|
||||
features: [promise-with-resolvers, class]
|
||||
---*/
|
||||
|
||||
class SubPromise extends Promise {}
|
||||
|
|
Loading…
Reference in New Issue