Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec] accept optional arguments to pass to the callback #16

Merged
merged 1 commit into from Apr 8, 2024
Merged

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Feb 7, 2024

Fixes #9

This was referenced Feb 7, 2024
webkit-commit-queue pushed a commit to rkirsling/WebKit that referenced this pull request Feb 21, 2024
https://bugs.webkit.org/show_bug.cgi?id=269775

Reviewed by Justin Michaud.

This patch implements https://github.com/tc39/proposal-promise-try behind a runtime option;
the proposal is currently at Stage 2 but the spec is very simple and not expected to change.

Effectively, Promise.try(f) is a more convenient way to write `new Promise((resolve) => { resolve(f()); })` --
we don't care whether f is sync or async, but if is synchronous, we want it to be executed immediately.

This implementation includes tc39/proposal-promise-try#16, which the champion expects to merge;
it simply extends the API to Promise.try(f, ...args) such that arguments can be forwarded to the callback.

* JSTests/stress/promise-try.js: Added.
* Source/JavaScriptCore/builtins/PromiseConstructor.js:
(try): Added.
* Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp:
(JSC::JSPromiseConstructor::finishCreation):
* Source/JavaScriptCore/runtime/OptionsList.h:

Canonical link: https://commits.webkit.org/275081@main
Copy link

@syg syg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ljharb ljharb merged commit e36699a into main Apr 8, 2024
@ljharb ljharb deleted the args branch April 8, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing arguments to the function
3 participants