@@ -6267,6 +6267,136 @@ idempotent.
62676267
62686268This API may only be called from the main thread.
62696269
6270+ ## Using embedded Node.js
6271+
6272+ ### `napi_create_platform`
6273+
6274+ <!-- YAML
6275+ added: REPLACEME
6276+ -->
6277+
6278+ > Stability: 1 - Experimental
6279+
6280+ ```c
6281+ napi_status napi_create_platform(int argc,
6282+ char** argv,
6283+ int exec_argc,
6284+ char** exec_argv,
6285+ char*** errors,
6286+ int thread_pool_size,
6287+ napi_platform* result);
6288+ ```
6289+
6290+ * `[in] argc`: CLI argument count, pass 0 for autofilling.
6291+ * `[in] argv`: CLI arguments, pass NULL for autofilling.
6292+ * `[in] exec_argc`: Node.js CLI options count.
6293+ * `[in] exec_argv`: Node.js CLI options.
6294+ * `[in] errors`: If different than NULL, will receive an array of
6295+ strings that must be freed.
6296+ * `[in] thread_pool_size`: Thread pool size, 0 for automatic.
6297+ * `[out] result`: A `napi_platform` result.
6298+
6299+ This function must be called once to initialize V8 and Node.js when using as a
6300+ shared library.
6301+
6302+ ### `napi_destroy_platform`
6303+
6304+ <!-- YAML
6305+ added: REPLACEME
6306+ -->
6307+
6308+ > Stability: 1 - Experimental
6309+
6310+ ```c
6311+ napi_status napi_destroy_platform(napi_platform platform, int *exit_code);
6312+ ```
6313+
6314+ * `[in] platform`: platform handle.
6315+ * `[out] exit_code`: if not NULL will receive the process exit code.
6316+
6317+ Destroy the Node.js / V8 processes.
6318+
6319+ ### `napi_create_environment`
6320+
6321+ <!-- YAML
6322+ added: REPLACEME
6323+ -->
6324+
6325+ > Stability: 1 - Experimental
6326+
6327+ ```c
6328+ napi_status napi_create_environment(napi_platform platform,
6329+ char*** errors,
6330+ const char* main_script,
6331+ napi_env* result);
6332+ ```
6333+
6334+ * `[in] platform`: platform handle.
6335+ * `[in] errors`: If different than NULL, will receive an array of strings
6336+ that must be freed.
6337+ * `[in] main_script`: If different than NULL, custom JavaScript to run in
6338+ addition to the default bootstrap that creates an empty
6339+ ready-to-use CJS/ES6 environment with `global.require()` and
6340+ `global.import()` functions that resolve modules from the directory of
6341+ the compiled binary.
6342+ It can be used to redirect `process.stdin`/ `process.stdout` streams
6343+ since Node.js might switch these file descriptors to non-blocking mode.
6344+ * `[out] result`: A `napi_env` result.
6345+
6346+ Initialize a new environment. A single platform can hold multiple Node.js
6347+ environments that will run in a separate V8 isolate each. If the returned
6348+ value is `napi_ok` or `napi_pending_exception`, the environment must be
6349+ destroyed with `napi_destroy_environment` to free all allocated memory.
6350+
6351+ ### `napi_run_environment`
6352+
6353+ <!-- YAML
6354+ added: REPLACEME
6355+ -->
6356+
6357+ > Stability: 1 - Experimental
6358+
6359+ ```c
6360+ napi_status napi_run_environment(napi_env env);
6361+ ```
6362+
6363+ ### `napi_await_promise`
6364+
6365+ <!-- YAML
6366+ added: REPLACEME
6367+ -->
6368+
6369+ > Stability: 1 - Experimental
6370+
6371+ ```c
6372+ napi_status napi_await_promise(napi_env env,
6373+ napi_value promise,
6374+ napi_value *result);
6375+ ```
6376+
6377+ * `[in] env`: environment handle.
6378+ * `[in] promise`: JS Promise.
6379+ * `[out] result`: Will receive the value that the Promise resolved with.
6380+
6381+ Iterate the event loop of the environment until the `promise` has been
6382+ resolved. Returns `napi_pending_exception` on rejection.
6383+
6384+ ### `napi_destroy_environment`
6385+
6386+ <!-- YAML
6387+ added: REPLACEME
6388+ -->
6389+
6390+ > Stability: 1 - Experimental
6391+
6392+ ```c
6393+ napi_status napi_destroy_environment(napi_env env);
6394+ ```
6395+
6396+ * `[in] env`: environment handle.
6397+
6398+ Destroy the Node.js environment / V8 isolate.
6399+
62706400## Miscellaneous utilities
62716401
62726402### `node_api_get_module_file_name`
0 commit comments