Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/built-ins/Promise/try/avoids-wrap-for-subclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2026 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: When the callback passed to PromiseSubclass.try returns a PromiseSubclass, it is not wrapped
esid: sec-promise.try
Comment thread
bakkot marked this conversation as resolved.
Resolved
features: [promise-try, class]
---*/

class SubPromise extends Promise {
constructor(executor) {
super(executor);
}
}

var sentinel = SubPromise.resolve();
assert(sentinel instanceof SubPromise);

var returnValue = SubPromise.try(function () {
return sentinel;
});
assert.sameValue(returnValue, sentinel);
15 changes: 15 additions & 0 deletions test/built-ins/Promise/try/avoids-wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2026 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: When the callback passed to Promise.try returns a Promise, it is not wrapped
esid: sec-promise.try
Comment thread
bakkot marked this conversation as resolved.
Resolved
features: [promise-try]
---*/

var sentinel = Promise.resolve();

var returnValue = Promise.try(function () {
return sentinel;
});
assert.sameValue(returnValue, sentinel);
30 changes: 30 additions & 0 deletions test/built-ins/Promise/try/ctx-ctor-for-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2026 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Promise.try produces instances of the receiver for errors
esid: sec-promise.try
Comment thread
bakkot marked this conversation as resolved.
Resolved
features: [promise-try, class]
flags: [async]
includes: [asyncHelpers.js]
---*/

class SubPromise extends Promise {
constructor(executor) {
super(executor);
}
}

var error = {};
var instance = SubPromise.try(function () {
throw error;
});
assert(instance instanceof SubPromise);

asyncTest(function() {
return instance.then(function () {
throw new Test262Error('Promise.try given a throwing function should throw');
}, function (observedError) {
assert.sameValue(observedError, error);
});
});
Loading