mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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 d920b7c94b) it
throws a DataCloneError. Update the example and surrounding text to
reflect the current behavior.
Fixes: https://github.com/nodejs/node/issues/60504
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Kit Dallege <xaum.io@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62203
Fixes: https://github.com/nodejs/node/issues/60504
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
a6af903e0a
commit
4895c2babc
1 file changed
+3
-6
@@ -1369,17 +1369,14 @@ port2.postMessage(new Foo());
|
||||
// Prints: { c: 3 }
|
||||
```
|
||||
|
||||
This limitation extends to many built-in objects, such as the global `URL`
|
||||
object:
|
||||
Some built-in objects cannot be cloned at all. For example, posting a
|
||||
`URL` object throws a `DataCloneError`:
|
||||
|
||||
```js
|
||||
const { port1, port2 } = new MessageChannel();
|
||||
|
||||
port1.onmessage = ({ data }) => console.log(data);
|
||||
|
||||
port2.postMessage(new URL('https://example.org'));
|
||||
|
||||
// Prints: { }
|
||||
// Throws DataCloneError: Cannot clone object of unsupported type.
|
||||
```
|
||||
|
||||
### `port.hasRef()`
|
||||
|
||||
Reference in new issue
Block a user