[webkit-changes] [WebKit/WebKit] 0e3ae7: [JSC] add support for `Promise.withResolvers`

Devin Rousso noreply at github.com
Wed Jul 12 17:02:26 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0e3ae70dd28cc89fc67a92312808f26ec35c60ff
      https://github.com/WebKit/WebKit/commit/0e3ae70dd28cc89fc67a92312808f26ec35c60ff
  Author: Devin Rousso <hi at devinrousso.com>
  Date:   2023-07-12 (Wed, 12 Jul 2023)

  Changed paths:
    A JSTests/stress/promise-withResolvers.js
    M Source/JavaScriptCore/builtins/PromiseConstructor.js
    M Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
    M Source/JavaScriptCore/runtime/OptionsList.h

  Log Message:
  -----------
  [JSC] add support for `Promise.withResolvers`
https://bugs.webkit.org/show_bug.cgi?id=259153

Reviewed by Yusuke Suzuki.

This allows for developers to `resolve`/`reject` a `Promise` after it's been created instead of having to provide a function to `new Promise`.

For example, the following
```
function foo(target) {
    return new Promise((resolve, reject) => {
        target.addEventListener("good", resolve);
        target.addEventListener("bad", reject);
    });
}
```
can now be rewritten as
```
function foo(target, event) {
    let {promise, resolve, reject} = Promise.withResolvers();

    target.addEventListener("good", resolve);
    target.addEventListener("bad", reject);

    return promise;
}
```

Spec: https://tc39.es/proposal-promise-with-resolvers/
Proposal: https://github.com/tc39/proposal-promise-with-resolvers

* Source/JavaScriptCore/builtins/PromiseConstructor.js:
(withResolvers): Added.
* Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp:
(JSC::JSPromiseConstructor::finishCreation):

* Source/JavaScriptCore/runtime/OptionsList.h:
Add an off-by-default feature flag for this.

* JSTests/stress/promise-withResolvers.js: Added.

Canonical link: https://commits.webkit.org/266015@main




More information about the webkit-changes mailing list