summaryrefslogtreecommitdiff
path: root/lib/internal/worker
AgeCommit message (Collapse)Author
2019-12-08lib: replace Symbol global by the primordials SymbolSebastien Ahkrin
PR-URL: https://github.com/nodejs/node/pull/30737 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-11-25lib: flatten access to primordialsMichaël Zasso
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-06-20worker: only unref port for stdin if we ref’ed it beforeAnna Henningsen
We set the `kStartedReading` flag from `_read()` for Worker stdio, and then `ref()` the port. However, the `.on('end')` handler is also attached when `._read()` is not called, e.g. when `process.stdin` inside a Worker is prematurely ended because stdin was not enabled by the parent thread. In that case, we should not call `.unref()` for stdin if we did not also call `.ref()` for it before. Fixes: https://github.com/nodejs/node/issues/28144 PR-URL: https://github.com/nodejs/node/pull/28153 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-05-19worker: add ability to unshift message from MessagePortAnna Henningsen
In combination with Atomics, this makes it possible to implement generic synchronous functionality, e.g. `importScript()`, in Workers purely by communicating with other threads. This is a continuation of https://github.com/nodejs/node/pull/26686, where a preference for a solution was voiced that allowed reading individual messages, rather than emitting all messages through events. PR-URL: https://github.com/nodejs/node/pull/27294 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-04-20util: access process states lazily in debuglogJoyee Cheung
`debuglog()` depends on `process.pid` and `process.env.NODE_DEBUG`, so it needs to be called lazily in top scopes of internal modules that may be loaded before these run time states are allowed to be accessed. This patch makes its implementation lazy by default, the process states are only accessed when the returned debug function is called for the first time. PR-URL: https://github.com/nodejs/node/pull/27281 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2019-04-12lib: enforce the use of Object from primordialsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
2019-03-23worker: remove usage of require('util')toshi1127
PR-URL: https://github.com/nodejs/node/pull/26810 Refs: https://github.com/nodejs/node/issues/26546 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-03-19worker: create per-Environment message port after bootstrapJoyee Cheung
PR-URL: https://github.com/nodejs/node/pull/26593 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-15worker: implement worker.moveMessagePortToContext()Anna Henningsen
This enables using `MessagePort`s in different `vm.Context`s, aiding with the isolation that the `vm` module seeks to provide. Refs: https://github.com/ayojs/ayo/pull/111 PR-URL: https://github.com/nodejs/node/pull/26497 Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-08lib: explicitly initialize debuglog during bootstrapJoyee Cheung
This patch splits the implementation of util.debuglog into a separate file and explicitly initialize it during pre-execution since the initialization depends on environment variables. Also delays the call to `debuglog` in modules that are loaded during bootstrap to make sure we only access the environment variable during pre-execution. PR-URL: https://github.com/nodejs/node/pull/26468 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-02-17worker: do not add removed methods to MessagePortAnna Henningsen
Do not put the `.stop()` and `.drain()` methods on the `MessagePort` prototype if we are going to remove them later on anyway. PR-URL: https://github.com/nodejs/node/pull/26109 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-15worker: use fake MessageEvent for port.onmessageAnna Henningsen
Instead of passing the payload for Workers directly to `.onmessage`, perform something more similar to what the browser API provides, namely create an event object with a `.data` property. This does not make `MessagePort` implement the `EventTarget` API, nor does it implement the full `MessageEvent` API, but it would make such extensions non-breaking changes if we desire them at some point in the future. (This would be a breaking change if Workers were not experimental. Currently, this method is also undocumented and only exists with the idea of enabling some degree of Web compatibility.) PR-URL: https://github.com/nodejs/node/pull/26082 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
2019-02-06worker: remove undocumented .onclose propertyRich Trott
Remove setting of a 'close' event handler on MessagePort through the use of an `.onclose` property. We don't use this convention anywhere else in our codebase for 'close' events, this feature is undocumented, and we don't test it. PR-URL: https://github.com/nodejs/node/pull/25904 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
2019-01-04worker: improve JS-side debuggingAnna Henningsen
Do not print debug messages that indicate that a stdio stream has drained; because `util.debuglog()` uses `console.log`, which in turn uses stdio streams, this would otherwise have lead to an endless loop. PR-URL: https://github.com/nodejs/node/pull/25312 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-12-31process: split worker IO into internal/worker/io.jsJoyee Cheung
- Move `setupProcessStdio` which contains write access to the process object into `bootstrap/node.js` - Move `MessagePort`, `MessageChannel`, `ReadableWorkerStdio`, and `WritableWorkerStdio` into `internal/worker/io.js` - Move more worker-specific bootstrap code into `internal/process/worker_thread_only` from `setupChild` in `internal/worker.js`, and move the `process._fatalException` overwrite into `bootstrap/node.js` for clarity. PR-URL: https://github.com/nodejs/node/pull/25199 Reviewed-By: James M Snell <jasnell@gmail.com>