[0.70] Fix task runner for Node-API (#153) #169
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry pick PR #153 to the main branch.
Original PR description:
Currently the Node-API foreground task runner lifetime is depending on the
napi_env
lifetime.This is wrong because some tasks must be run after the
napi_env
is destroyed.This issue causes a crash in React Native for Windows when we do direct debugging.
In this PR we are fixing this issue by implementing a new task runner:
v8_create_task_runner
function to create a new task runner and then pass it tonapi_ext_env_settings
when creating newnapi_env
. The code that internally usesv8runtime::JSITaskRunner
is responsible for deleting it.v8_create_task_runner
captures external task scheduler and functions to run tasks and to destroy the external task scheduler.An additional change in this PR: removed
NAPI_EXTERN
from all implementations as it may cause issues if the function signature is not the same in the .h and .cpp files. This issue was observed while working on the newv8_create_task_runner
function.Note that the new code has prefix
v8_
instead of previously usednapi_ext_
. The reason is that these functions are V8 JS Engine specific and will be never accepted as a part of the Node-API in Node.JS. Thus, the proposal is to use thev8_
prefix instead. Ideally, we should replacejs_native_ext_api.h
with a newv8_api.h
where all declarations will have thev8_
prefix.Microsoft Reviewers: Open in CodeFlow