Skip to content

vm: add experimental NodeRealm implementation

Rodrigo Muino Tomonari requested to merge github/fork/mcollina/localworker2 into main

A NodeRealm is a complete Node.js environment that runs within the same thread. This feature is added behind a --experimental-noderealm flag.

This work is based on https://github.com/nodejs/node/pull/45018, which adds the synchronous-worker module initially written by @addaleax. and is incorporated here with Anna's permission as stated in https://github.com/nodejs/node/pull/45018 by @jasnell (listed as a co-author of this change). The main difference from the synchronous-worker module is that I removed all the "synchronous" parts: it's now impossible to spin the event loop manually.

The reason for including this inside Node.js instead of keeping it as a separate module is access to internal API that would make stop() possible without crashing the process.

This implementation still suffers from a few bugs that I would aim to solve before removing the experimental flags:

  • leaks memory like ShadowRealm (https://github.com/nodejs/node/issues/47353);
  • avoid polling during stop();
  • ESM support using internals (instead of the current hack);
  • complete inspector support (currently, it crashes with --inspect-brk due to an async_hooks issue).

Merge request reports

Loading