@@ -4932,6 +4932,19 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env,
4932
4932
* `[in] script`: A JavaScript string containing the script to execute.
4933
4933
* `[out] result`: The value resulting from having executed the script.
4934
4934
4935
+ This function executes a string of JavaScript code and returns its result with
4936
+ the following caveats:
4937
+
4938
+ * Unlike `eval`, this function does not allow the script to access the current
4939
+ lexical scope, and therefore also does not allow to access the
4940
+ [module scope][], meaning that pseudo-globals such as `require` will not be
4941
+ available.
4942
+ * The script can access the [global scope][]. Function and `var` declarations
4943
+ in the script will be added to the [`global`][] object. Variable declarations
4944
+ made using `let` and `const` will be visible globally, but will not be added
4945
+ to the [`global`][] object.
4946
+ * The value of `this` is [`global`][] within the script.
4947
+
4935
4948
## libuv event loop
4936
4949
4937
4950
N-API provides a function for getting the current event loop associated with
@@ -5293,6 +5306,7 @@ This API may only be called from the main thread.
5293
5306
[Xcode]: https://developer.apple.com/xcode/
5294
5307
[`Number.MAX_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.max_safe_integer
5295
5308
[`Number.MIN_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.min_safe_integer
5309
+ [`global`]: globals.html#globals_global
5296
5310
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
5297
5311
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
5298
5312
[`napi_async_init`]: #n_api_napi_async_init
@@ -5343,6 +5357,8 @@ This API may only be called from the main thread.
5343
5357
[async_hooks `type`]: async_hooks.html#async_hooks_type
5344
5358
[context-aware addons]: addons.html#addons_context_aware_addons
5345
5359
[docs]: https://github.com/nodejs/node-addon-api#api-documentation
5360
+ [global scope]: globals.html
5361
+ [module scope]: modules.html#modules_the_module_scope
5346
5362
[node-addon-api]: https://github.com/nodejs/node-addon-api
5347
5363
[node-gyp]: https://github.com/nodejs/node-gyp
5348
5364
[node-pre-gyp]: https://github.com/mapbox/node-pre-gyp
0 commit comments