Skip to content

Normative: make Promise.try use PromiseResolve in non-error case#3883

Open
bakkot wants to merge 1 commit into
tc39:mainfrom
bakkot:faster-promise-try
Open

Normative: make Promise.try use PromiseResolve in non-error case#3883
bakkot wants to merge 1 commit into
tc39:mainfrom
bakkot:faster-promise-try

Conversation

@bakkot
Copy link
Copy Markdown
Member

@bakkot bakkot commented Jun 2, 2026

Using PromiseResolve differs from the current behavior in that when the argument returns a Promise whose .constructor is whatever the this value of the Promise.try call is1, we just return that Promise directly instead of wrapping it in a new one. Otherwise it's exactly the same.

This has the advantage of better matching the intuition that this is for cases where you want to write Promise.resolve(foo()) but you also want to wrap sync errors in rejected Promises. Now it actually works exactly like

try {
  result = Promise.resolve(foo());
} catch (e) {
  result = Promise.reject(e);
}

As a bonus, it also means this costs zero microtask ticks in the case where the argument is actually an async function, instead of (as currently) two.

See matrix chat 1 2.

Footnotes

  1. Precise check might change.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/3883 and as multiple pages at https://tc39.es/ecma262/pr/3883/multipage .

@michaelficarra michaelficarra added needs consensus This needs committee consensus before it can be eligible to be merged. normative change Affects behavior required to correctly evaluate some ECMAScript source text needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 needs implementations labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs consensus This needs committee consensus before it can be eligible to be merged. needs implementations needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 normative change Affects behavior required to correctly evaluate some ECMAScript source text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants