In this PR we add new Node-API extension capability to run JavaScript functions that can use the prepared script store.
The solution consists of the following parts:
new function napi_ext_run_script_buffer that can run JavaScript from the provided buffer.
the napi_ext_env_settings struct is extended with a new field script_cache of type napi_ext_script_cache.
new napi_ext_script_cache struct that represents the prepared script store.
new napi_ext_cached_script_metadata struct with JavaScript metadata that used for validating byte code cache.
new napi_ext_buffer struct to represent script text or binary buffer.
new napi_ext_native_data struct as a base type to control lifetime of an external object.
The implementation wraps up the napi_ext_script_cache into NodeApiPreparedScriptStore class that implements facebook::jsi::PreparedScriptStore interface, which then passed to the internal V8Runtime instance.
Then, the napi_ext_run_script_buffer calls the V8Runtime::loadJavaScript and V8Runtime::ExecuteString methods to evaluate the script that internally relies on the NodeApiPreparedScriptStore.
The V8Runtime::ExecuteString is modified to return v8::Local<v8::Value> instead of facebook::jsi::Value to use the result for the Node-API napi_value.
In this PR we add new Node-API extension capability to run JavaScript functions that can use the prepared script store. The solution consists of the following parts:
napi_ext_run_script_buffer
that can run JavaScript from the provided buffer.napi_ext_env_settings
struct is extended with a new fieldscript_cache
of typenapi_ext_script_cache
.napi_ext_script_cache
struct that represents the prepared script store.napi_ext_cached_script_metadata
struct with JavaScript metadata that used for validating byte code cache.napi_ext_buffer
struct to represent script text or binary buffer.napi_ext_native_data
struct as a base type to control lifetime of an external object.The implementation wraps up the
napi_ext_script_cache
intoNodeApiPreparedScriptStore
class that implementsfacebook::jsi::PreparedScriptStore
interface, which then passed to the internalV8Runtime
instance. Then, thenapi_ext_run_script_buffer
calls theV8Runtime::loadJavaScript
andV8Runtime::ExecuteString
methods to evaluate the script that internally relies on theNodeApiPreparedScriptStore
.The
V8Runtime::ExecuteString
is modified to returnv8::Local<v8::Value>
instead offacebook::jsi::Value
to use the result for the Node-APInapi_value
.Microsoft Reviewers: Open in CodeFlow