-
-
Notifications
You must be signed in to change notification settings - Fork 475
src: Avoid calling into C++ with a null this #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Just a few minor comments.
when exceptions are off
Thanks for the review! Think I got everything except for the one I commented on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Avoid calling into C++ with a null this when exceptions are off PR-URL: #1313 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]
Landed in 858942c |
Avoid calling into C++ with a null this when exceptions are off PR-URL: nodejs/node-addon-api#1313 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]
I'm posting here to keep the context of the PR and get some early feedback on my thoughts. I believe the To me, it seems that the tests are relying on the Line 4576 in 7c3226f
it simply defers to Lines 6795 to 6798 in 7c3226f
which does report a fatal error (not throwing) if the status indicates a failure Lines 742 to 744 in 7c3226f
but the call to This results in some rather strange behavior where if an addon is instantiated via simple object construction instead of calling it's This is an example of the Napi::Env env{_env};
Napi::HandleScope {env};
Napi::Object exports = Napi::Object::New(env);
HelloAddon addon{env, exports};
// Log the properties of the exports object
for (auto prop: exports.GetPropertyNames()) {
printf("exports.%s = %s\n",
prop.second.operator Napi::Value().As<Napi::String>().Utf8Value().c_str(),
exports.Get(prop.second).ToString().Utf8Value().c_str()
);
}
// Test
auto result = exports.Get("hello").As<Napi::Function>().Call(exports, {});
printf("Result of hello function: %s\n", result.ToString().Utf8Value().c_str());
XCTAssertFalse(result.IsEmpty());
XCTAssertTrue(result.IsString()); This last assertion fails since result is
|
These tests all crash the process because
instance
is null when exceptions are off. If ObjectWrap methods try to access anything onthis
, it's bad news. I don't think the method should get called at all in this case since there's a pending JS exception anyways.Context: I recently ported node-canvas to
node-addon-api
and we have tests for this. It was a pain in v8/NAN, and we could remove a lot of code with these changes. I had a positive experience working withnode-addon-api
, great work everyone!