NAPI_EXTERN napi_status napi_run_script(napi_env env,napi_value script,napi_value* result);
[in] env: The environment that the API is invoked under.[in] script: A JavaScript string containing the script to execute.[out] result: The value resulting from having executed the script.
This function executes a string of JavaScript code and returns its result with the following caveats:
- Unlike
eval, this function does not allow the script to access the current lexical scope, and therefore also does not allow to access the [module scope][], meaning that pseudo-globals such asrequirewill not be available. - The script can access the [global scope][]. Function and
vardeclarations in the script will be added to the [global][] object. Variable declarations made usingletandconstwill be visible globally, but will not be added to the [global][] object. - The value of
thisis [global][] within the script.
