microsoft / v8-jsi

React Native V8 JSI adapter
Other
157 stars 36 forks source link

[0.65] Implement PreparedScriptStore for V8 Node-API #130

Closed vmoroz closed 2 years ago

vmoroz commented 2 years ago

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:

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.

Microsoft Reviewers: Open in CodeFlow