-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
A Napi::Error may become invalid if it is thrown out of a handle scope #31
Comments
Merged
jasongin
added a commit
to jasongin/node-addon-api
that referenced
this issue
May 1, 2017
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs#31
jasongin
added a commit
to jasongin/node-addon-api
that referenced
this issue
May 1, 2017
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs#31
jasongin
added a commit
that referenced
this issue
May 4, 2017
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: #31
kevindavies8
added a commit
to kevindavies8/node-addon-api-Develop
that referenced
this issue
Aug 24, 2022
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs/node-addon-api#31
Marlyfleitas
added a commit
to Marlyfleitas/node-api-addon-Development
that referenced
this issue
Aug 26, 2022
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs/node-addon-api#31
wroy7860
added a commit
to wroy7860/addon-api-benchmark-node
that referenced
this issue
Sep 19, 2022
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs/node-addon-api#31
johnfrench3
pushed a commit
to johnfrench3/node-addon-api-git
that referenced
this issue
Aug 11, 2023
A Napi::Error instance must hold a persistent reference to the JS error object so that it can escape from handle scopes when thrown as a C++ exception. Fixes: nodejs/node-addon-api#31
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
When a
Napi::Error
is constructed, it acquires a handle to a JS error object vianapi_get_and_clear_last_exception()
. Then theNapi::Error
instance is intended to be thrown and caught as a C++ exception. But if any stack frame between where it is thrown and where it is caught has set up a handle scope, then the error object handle gets released as the exception propagates up the stack.One way to resolve this is whenever using handle scopes be sure to catch any
Napi::Error
and escape it from the scope before re-throwing it. But this makes it difficult to use handle scopes correctly and therefore would result in bugs that only occur in exception conditions. So, not a good solution.Instead, the
Error
class can be changed to acquire a persistent reference to the error object, instead of just a handle. I'm working on this.The text was updated successfully, but these errors were encountered: