Skip to content

Handle the case where one cannot execute JavaScript#37446

@gabrielschulhof

Description

@gabrielschulhof

Re #30327#37236

One (somewhat elaborate?) API for semver-minorly handling the inability to execute JS would be the following (somewhat introspective) API:

typedefenum{node_api_reason_call_function, node_api_reason_throw_exception, node_api_reason_open_handle_scope, node_api_reason_open_escapable_handle_scope, node_api_reason_open_callback_scope, ... // etc. } node_api_js_exec_failure_reason; typedefnapi_status (*node_api_js_exec_failure_callback)( napi_env env, node_api_js_exec_failure_reason reason, void* reason_data, void* user_data); NAPI_EXTERN napi_status node_api_handle_js_execution_failure( napi_env env, node_api_js_exec_failure_callback exec_fail_cb, void* user_data);

The add-on maintainer would attach a callback similarly to the napi_set_instance_data finalizer, which would get called whenever we would otherwise return napi_cannot_call_into_js. The callback would analyze the reason and the associated reason_data (which would be a pointer to a stack-allocated structure the type of which depends on reason – a little bit like ioctl(2)) and would return a napi_status that would then be passed as the return value to the original Node-API call.

This could be used to correct a return value of napi_pending_exception from a call to, say, napi_call_function into a return value of napi_ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    node-apiIssues and PRs related to the Node-API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions