Skip to content

src: improve embedder API

Rodrigo Muino Tomonari requested to merge github/fork/addaleax/embedme into master

Various improvements towards making the embedder API more usable.

src: make FreeEnvironment() perform all necessary cleanup

Make the calls stop_sub_worker_contexts(), RunCleanup() part of the public API for easier embedding.

(Note that calling RunAtExit() is idempotent because the at-exit callback queue is cleared after each call.)

src: fix memory leak in CreateEnvironment when bootstrap fails
src: move worker_context from Environment to IsolateData

Workers are fully in control of their Isolates, and this helps avoid a problem with later changes to CreateEnvironment() because now we can run the boostrapping code inside the latter.

src: associate is_main_thread() with worker_context()

In our codebase, the assumption generally is that !is_main_thread() means that the current Environment belongs to a Node.js Worker thread.

src: align worker and main thread code with embedder API

This addresses some long-standing TODOs by Joyee and me about making the embedder API more powerful and us less reliant on internal APIs for creating the main thread and Workers.

src: provide a variant of LoadEnvironment taking a callback

This allows embedders to flexibly control how they start JS code rather than using third_party_main.

src: add LoadEnvironment() variant taking a string

Allow passing a string as the main module rather than using the callback variant.

test: re-enable cctest that was commented out

Refs: https://github.com/nodejs/node/pull/31910

src: add unique_ptr equivalent of CreatePlatform

This makes this bit of the embedder situation a bit easier to use.

src: make InitializeNodeWithArgs() official public API

This is a decent replacement for the to-be-deprecated Init() API.

src: add ability to look up platform based on Environment*

This should eventually remove any necessity to use the global-state GetMainThreadMultiIsolatePlatform().

src: allow non-Node.js TracingControllers

We do not need a Node.js-provided v8::TracingController, generally. Loosen that restriction in order to make it easier for embedders to provide their own subclass of v8::TracingController, or none at all.

Refs: https://github.com/electron/electron/commit/9c36576dddfaecde1298ff3e089d21a6e54fe67f

src: fix what a dispose without checking

If created platform with CreatePlatform, the crash occurs because it does not check if it was initialized to v8_platform when DisposePlatform was called.

Refs: https://github.com/nodejs/node/pull/31260

fixup! src: fix what a dispose without checking
src: shutdown platform from FreePlatform()

There is currently no way to properly do this.

src,test: add full-featured embedder API test
doc: add basic embedding example documentation
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading