Skip to content

Commit 7f11519

Browse files
kovanclaude
authored andcommitted
doc: fix URL postMessage example in worker_threads
The example claimed that posting a URL object via MessageChannel would print an empty object, but since v21.0.0 (commit d920b7c) it throws a DataCloneError. Update the example and surrounding text to reflect the current behavior. Fixes: #60504 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kit Dallege <xaum.io@gmail.com> PR-URL: #62203 Fixes: #60504 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent b131f74 commit 7f11519

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

doc/api/worker_threads.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,17 +1259,14 @@ port2.postMessage(new Foo());
12591259
// Prints: { c: 3 }
12601260
```
12611261
1262-
This limitation extends to many built-in objects, such as the global `URL`
1263-
object:
1262+
Some built-in objects cannot be cloned at all. For example, posting a
1263+
`URL` object throws a `DataCloneError`:
12641264
12651265
```js
12661266
const { port1, port2 } = new MessageChannel();
12671267

1268-
port1.onmessage = ({ data }) => console.log(data);
1269-
12701268
port2.postMessage(new URL('https://example.org'));
1271-
1272-
// Prints: { }
1269+
// Throws DataCloneError: Cannot clone object of unsupported type.
12731270
```
12741271
12751272
### `port.hasRef()`

0 commit comments

Comments
 (0)