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

promise cloneinto clarification #19125

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
corrections
  • Loading branch information
rebloor committed Aug 4, 2022
commit 9b975b343ba1ec95532c0c034344e1888a4d0362
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ window.wrappedJSObject.messenger = cloneInto(
{cloneFunctions: true});
```

Now page scripts sees a new property on the window, `messenger`, which has a function `notify()`:
Now page scripts see a new property on the window, `messenger`, which has a function `notify()`:

```js
window.messenger.notify("Message from the page script!");
```

In the special case of a Promise, which is not supported by [structured clone algorithm](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), the desired result can be achieved by using `window.Promise` instead of `Promise`, and then cloning the resolution value with `cloneInto` like this:
In the special case of a Promise, which is not supported by [structured clone algorithm](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), the desired result can be achieved using `window.Promise` instead of `Promise`, and then cloning the resolution value with `cloneInto` like this:

```js
let promise = new window.Promise(resolve => {
Expand Down