Skip to content

Commit 919fd07

Browse files
committed
fixup! doc: improve worker_threads documentation
1 parent 2bd5cd7 commit 919fd07

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

doc/api/worker_threads.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ added: v10.5.0
120120
An arbitrary JavaScript value that contains a clone of the data passed
121121
to this thread’s `Worker` constructor.
122122

123+
The data is cloned as if using [`postMessage()`][`port.postMessage()`],
124+
using the [HTML structured clone algorithm][].
125+
123126
```js
124127
const { Worker, isMainThread, workerData } = require('worker_threads');
125128

@@ -222,10 +225,16 @@ added: v10.5.0
222225

223226
Sends a JavaScript value to the receiving side of this channel.
224227
`value` will be transferred in a way which is compatible with
225-
the [HTML structured clone algorithm][]. In particular, it may contain circular
226-
references and objects like typed arrays that the `JSON` API is not able
227-
to stringify.
228+
the [HTML structured clone algorithm][].
228229

230+
In particular, the significant differences to `JSON` are:
231+
- `value` may contain circular references.
232+
- `value` may contain instances of builtin JS types such as `RegExp`s,
233+
`BigInt`s, `Map`s, `Set`s, etc.
234+
- `value` may contained typed arrays, both using `ArrayBuffer`s
235+
and `SharedArrayBuffer`s. and
236+
- `value` may contain [`WebAssembly.Module`][] instances.
237+
- `value` may not contain native (C++-backed) objects other than `MessagePort`s.
229238

230239
```js
231240
const { MessageChannel } = require('worker_threads');
@@ -567,6 +576,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
567576
[`MessagePort`]: #worker_threads_class_messageport
568577
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
569578
[`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
579+
[`WebAssembly.Module`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module
570580
[`Worker`]: #worker_threads_class_worker
571581
[`'close'` event]: #worker_threads_event_close
572582
[`cluster` module]: cluster.html

0 commit comments

Comments
 (0)