mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
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
|
# https://github.com/tc39/proposal-promise-with-resolvers
|
||||||
promise-with-resolvers
|
promise-with-resolvers
|
||||||
|
|
||||||
|
# Promise.try
|
||||||
|
# https://github.com/tc39/proposal-promise-try
|
||||||
|
promise-try
|
||||||
|
|
||||||
# Set methods
|
# Set methods
|
||||||
# https://github.com/tc39/proposal-set-methods
|
# https://github.com/tc39/proposal-set-methods
|
||||||
set-methods
|
set-methods
|
||||||
|
@ -21,7 +21,7 @@ info: |
|
|||||||
Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
|
Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
|
||||||
|
|
||||||
flags: [async]
|
flags: [async]
|
||||||
includes: [compareArray.js,promiseHelper.js]
|
includes: [compareArray.js, promiseHelper.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
let a = new Promise((_, reject) => reject('a'));
|
let a = new Promise((_, reject) => reject('a'));
|
||||||
|
22
test/built-ins/Promise/try/args.js
Normal file
22
test/built-ins/Promise/try/args.js
Normal file
@ -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)
|
||||||
|
);
|
||||||
|
|
16
test/built-ins/Promise/try/ctx-ctor-throws.js
Normal file
16
test/built-ins/Promise/try/ctx-ctor-throws.js
Normal file
@ -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 () {});
|
||||||
|
});
|
27
test/built-ins/Promise/try/ctx-ctor.js
Normal file
27
test/built-ins/Promise/try/ctx-ctor.js
Normal file
@ -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');
|
12
test/built-ins/Promise/try/ctx-non-ctor.js
Normal file
12
test/built-ins/Promise/try/ctx-non-ctor.js
Normal file
@ -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);
|
||||||
|
});
|
32
test/built-ins/Promise/try/ctx-non-object.js
Normal file
32
test/built-ins/Promise/try/ctx-non-object.js
Normal file
@ -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());
|
||||||
|
});
|
14
test/built-ins/Promise/try/length.js
Normal file
14
test/built-ins/Promise/try/length.js
Normal file
@ -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
|
||||||
|
});
|
14
test/built-ins/Promise/try/name.js
Normal file
14
test/built-ins/Promise/try/name.js
Normal file
@ -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
|
||||||
|
});
|
16
test/built-ins/Promise/try/not-a-constructor.js
Normal file
16
test/built-ins/Promise/try/not-a-constructor.js
Normal file
@ -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 () {});
|
||||||
|
});
|
||||||
|
|
12
test/built-ins/Promise/try/promise.js
Normal file
12
test/built-ins/Promise/try/promise.js
Normal file
@ -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);
|
16
test/built-ins/Promise/try/prop-desc.js
Normal file
16
test/built-ins/Promise/try/prop-desc.js
Normal file
@ -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
|
||||||
|
})
|
21
test/built-ins/Promise/try/return-value.js
Normal file
21
test/built-ins/Promise/try/return-value.js
Normal file
@ -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);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
17
test/built-ins/Promise/try/throws.js
Normal file
17
test/built-ins/Promise/try/throws.js
Normal file
@ -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
|
description: Promise.withResolvers produces instances of the receiver
|
||||||
esid: sec-promise.withresolvers
|
esid: sec-promise.withresolvers
|
||||||
features: [promise-with-resolvers]
|
features: [promise-with-resolvers, class]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
class SubPromise extends Promise {}
|
class SubPromise extends Promise {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user