Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ to as `node::Environment`. Each `node::Environment` is associated with:
that `node::IsolateData` is shared only among `node::Environment`s that
use the same `v8::Isolate`, Node.js does not perform this check.

`node::Environment`s that share a `node::IsolateData` also share its
`uv_loop_t`. `node::FreeEnvironment()` runs that loop until the handles of the
`node::Environment` being freed have closed, and JavaScript execution is
disallowed on the whole `v8::Isolate` while it does, so pending timers, I/O
callbacks and thread pool completions that belong to other `node::Environment`s
on the same loop can run inside that call without being able to call into
JavaScript. `node::Environment`s that are freed independently of one another
should each use their own `uv_loop_t` and `node::IsolateData`, or the embedder
should make sure the others have no pending work when one of them is freed.

In order to set up a `v8::Isolate`, an `v8::ArrayBuffer::Allocator` needs
to be provided. One possible choice is the default Node.js allocator, which
can be created through `node::ArrayBufferAllocator::Create()`. Using the Node.js
Expand Down
3 changes: 3 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ NODE_EXTERN v8::MaybeLocal<v8::Value> LoadEnvironment(
const ModuleData* entry_point,
EmbedderPreloadCallback preload = nullptr);

// Runs `env`'s event loop until its handles have closed, with JavaScript
// execution disallowed on the isolate; see doc/api/embedding.md if that loop
// is shared with other Environments.
NODE_EXTERN void FreeEnvironment(Environment* env);

// Set a callback that is called when process.exit() is called from JS,
Expand Down
Loading