Skip to content

Commit 13b5ace

Browse files
tniessenMylesBorins
authored andcommitted
doc: explain napi_run_script
PR-URL: #30918 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b6ddbc1 commit 13b5ace

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/api/n-api.md

+16
Original file line numberDiff line numberDiff line change
@@ -4929,6 +4929,19 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env,
49294929
* `[in] script`: A JavaScript string containing the script to execute.
49304930
* `[out] result`: The value resulting from having executed the script.
49314931

4932+
This function executes a string of JavaScript code and returns its result with
4933+
the following caveats:
4934+
4935+
* Unlike `eval`, this function does not allow the script to access the current
4936+
lexical scope, and therefore also does not allow to access the
4937+
[module scope][], meaning that pseudo-globals such as `require` will not be
4938+
available.
4939+
* The script can access the [global scope][]. Function and `var` declarations
4940+
in the script will be added to the [`global`][] object. Variable declarations
4941+
made using `let` and `const` will be visible globally, but will not be added
4942+
to the [`global`][] object.
4943+
* The value of `this` is [`global`][] within the script.
4944+
49324945
## libuv event loop
49334946

49344947
N-API provides a function for getting the current event loop associated with
@@ -5291,6 +5304,7 @@ This API may only be called from the main thread.
52915304
[Xcode]: https://developer.apple.com/xcode/
52925305
[`Number.MAX_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.max_safe_integer
52935306
[`Number.MIN_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.min_safe_integer
5307+
[`global`]: globals.html#globals_global
52945308
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
52955309
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
52965310
[`napi_async_init`]: #n_api_napi_async_init
@@ -5341,6 +5355,8 @@ This API may only be called from the main thread.
53415355
[async_hooks `type`]: async_hooks.html#async_hooks_type
53425356
[context-aware addons]: addons.html#addons_context_aware_addons
53435357
[docs]: https://github.com/nodejs/node-addon-api#api-documentation
5358+
[global scope]: globals.html
5359+
[module scope]: modules.html#modules_the_module_scope
53445360
[node-addon-api]: https://github.com/nodejs/node-addon-api
53455361
[node-gyp]: https://github.com/nodejs/node-gyp
53465362
[node-pre-gyp]: https://github.com/mapbox/node-pre-gyp

0 commit comments

Comments
 (0)