Skip to content

Commit 109c92e

Browse files
addaleaxtargos
authored andcommitted
worker: initial implementation
Implement multi-threading support for most of the API. Thanks to Stephen Belanger for reviewing this change in its original form, to Olivia Hugger for reviewing the documentation and some of the tests coming along with it, and to Alexey Orlenko and Timothy Gu for reviewing other parts of the tests. Refs: ayojs/ayo#110 Refs: ayojs/ayo#114 Refs: ayojs/ayo#117 PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 314b47d commit 109c92e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1630
-74
lines changed

doc/api/errors.md

+23
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,13 @@ but not provided in the `transferList` for that call.
13231323
13241324
An [ES6 module][] could not be resolved.
13251325

1326+
<a id="ERR_MISSING_PLATFORM_FOR_WORKER"></a>
1327+
### ERR_MISSING_PLATFORM_FOR_WORKER
1328+
1329+
The V8 platform used by this instance of Node.js does not support creating
1330+
Workers. This is caused by lack of embedder support for Workers. In particular,
1331+
this error will not occur with standard builds of Node.js.
1332+
13261333
<a id="ERR_MODULE_RESOLUTION_LEGACY"></a>
13271334
### ERR_MODULE_RESOLUTION_LEGACY
13281335

@@ -1723,6 +1730,22 @@ The fulfilled value of a linking promise is not a `vm.Module` object.
17231730
The current module's status does not allow for this operation. The specific
17241731
meaning of the error depends on the specific function.
17251732

1733+
<a id="ERR_WORKER_NEED_ABSOLUTE_PATH"></a>
1734+
### ERR_WORKER_NEED_ABSOLUTE_PATH
1735+
1736+
The path for the main script of a worker is not an absolute path.
1737+
1738+
<a id="ERR_WORKER_UNSERIALIZABLE_ERROR"></a>
1739+
### ERR_WORKER_UNSERIALIZABLE_ERROR
1740+
1741+
All attempts at serializing an uncaught exception from a worker thread failed.
1742+
1743+
<a id="ERR_WORKER_UNSUPPORTED_EXTENSION"></a>
1744+
### ERR_WORKER_UNSUPPORTED_EXTENSION
1745+
1746+
The pathname used for the main script of a worker has an
1747+
unknown file extension.
1748+
17261749
<a id="ERR_ZLIB_INITIALIZATION_FAILED"></a>
17271750
### ERR_ZLIB_INITIALIZATION_FAILED
17281751

doc/api/process.md

+27
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ added: v0.7.0
410410
The `process.abort()` method causes the Node.js process to exit immediately and
411411
generate a core file.
412412

413+
This feature is not available in [`Worker`][] threads.
414+
413415
## process.arch
414416
<!-- YAML
415417
added: v0.5.0
@@ -517,6 +519,8 @@ try {
517519
}
518520
```
519521

522+
This feature is not available in [`Worker`][] threads.
523+
520524
## process.config
521525
<!-- YAML
522526
added: v0.7.7
@@ -918,6 +922,8 @@ console.log(process.env.test);
918922
// => 1
919923
```
920924

925+
`process.env` is read-only in [`Worker`][] threads.
926+
921927
## process.execArgv
922928
<!-- YAML
923929
added: v0.7.7
@@ -1030,6 +1036,9 @@ If it is necessary to terminate the Node.js process due to an error condition,
10301036
throwing an *uncaught* error and allowing the process to terminate accordingly
10311037
is safer than calling `process.exit()`.
10321038

1039+
In [`Worker`][] threads, this function stops the current thread rather
1040+
than the current process.
1041+
10331042
## process.exitCode
10341043
<!-- YAML
10351044
added: v0.11.8
@@ -1203,6 +1212,7 @@ console.log(process.getgroups()); // [ 27, 30, 46, 1000 ]
12031212

12041213
This function is only available on POSIX platforms (i.e. not Windows or
12051214
Android).
1215+
This feature is not available in [`Worker`][] threads.
12061216

12071217
## process.kill(pid[, signal])
12081218
<!-- YAML
@@ -1306,6 +1316,9 @@ The _heap_ is where objects, strings, and closures are stored. Variables are
13061316
stored in the _stack_ and the actual JavaScript code resides in the
13071317
_code segment_.
13081318

1319+
When using [`Worker`][] threads, `rss` will be a value that is valid for the
1320+
entire process, while the other fields will only refer to the current thread.
1321+
13091322
## process.nextTick(callback[, ...args])
13101323
<!-- YAML
13111324
added: v0.1.26
@@ -1569,6 +1582,7 @@ if (process.getegid && process.setegid) {
15691582

15701583
This function is only available on POSIX platforms (i.e. not Windows or
15711584
Android).
1585+
This feature is not available in [`Worker`][] threads.
15721586

15731587
## process.seteuid(id)
15741588
<!-- YAML
@@ -1596,6 +1610,7 @@ if (process.geteuid && process.seteuid) {
15961610

15971611
This function is only available on POSIX platforms (i.e. not Windows or
15981612
Android).
1613+
This feature is not available in [`Worker`][] threads.
15991614

16001615
## process.setgid(id)
16011616
<!-- YAML
@@ -1623,6 +1638,7 @@ if (process.getgid && process.setgid) {
16231638

16241639
This function is only available on POSIX platforms (i.e. not Windows or
16251640
Android).
1641+
This feature is not available in [`Worker`][] threads.
16261642

16271643
## process.setgroups(groups)
16281644
<!-- YAML
@@ -1639,6 +1655,7 @@ The `groups` array can contain numeric group IDs, group names or both.
16391655

16401656
This function is only available on POSIX platforms (i.e. not Windows or
16411657
Android).
1658+
This feature is not available in [`Worker`][] threads.
16421659

16431660
## process.setuid(id)
16441661
<!-- YAML
@@ -1664,6 +1681,7 @@ if (process.getuid && process.setuid) {
16641681

16651682
This function is only available on POSIX platforms (i.e. not Windows or
16661683
Android).
1684+
This feature is not available in [`Worker`][] threads.
16671685

16681686
## process.setUncaughtExceptionCaptureCallback(fn)
16691687
<!-- YAML
@@ -1700,6 +1718,8 @@ a [Writable][] stream.
17001718
`process.stderr` differs from other Node.js streams in important ways, see
17011719
[note on process I/O][] for more information.
17021720

1721+
This feature is not available in [`Worker`][] threads.
1722+
17031723
## process.stdin
17041724

17051725
* {Stream}
@@ -1732,6 +1752,8 @@ In "old" streams mode the `stdin` stream is paused by default, so one
17321752
must call `process.stdin.resume()` to read from it. Note also that calling
17331753
`process.stdin.resume()` itself would switch stream to "old" mode.
17341754

1755+
This feature is not available in [`Worker`][] threads.
1756+
17351757
## process.stdout
17361758

17371759
* {Stream}
@@ -1750,6 +1772,8 @@ process.stdin.pipe(process.stdout);
17501772
`process.stdout` differs from other Node.js streams in important ways, see
17511773
[note on process I/O][] for more information.
17521774

1775+
This feature is not available in [`Worker`][] threads.
1776+
17531777
### A note on process I/O
17541778

17551779
`process.stdout` and `process.stderr` differ from other Node.js streams in
@@ -1865,6 +1889,8 @@ console.log(
18651889
);
18661890
```
18671891

1892+
This feature is not available in [`Worker`][] threads.
1893+
18681894
## process.uptime()
18691895
<!-- YAML
18701896
added: v0.5.0
@@ -1992,6 +2018,7 @@ cases:
19922018
[`ChildProcess`]: child_process.html#child_process_class_childprocess
19932019
[`Error`]: errors.html#errors_class_error
19942020
[`EventEmitter`]: events.html#events_class_eventemitter
2021+
[`Worker`]: worker.html#worker_worker
19952022
[`console.error()`]: console.html#console_console_error_data_args
19962023
[`console.log()`]: console.html#console_console_log_data_args
19972024
[`domain`]: domain.html

doc/api/vm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });
174174

175175
Creates a new ES `Module` object.
176176

177-
*Note*: Properties assigned to the `import.meta` object that are objects may
177+
Properties assigned to the `import.meta` object that are objects may
178178
allow the `Module` to access information outside the specified `context`, if the
179179
object is created in the top level context. Use `vm.runInContext()` to create
180180
objects in a specific context.

0 commit comments

Comments
 (0)