src: Avoid calling into C++ with a null this#1313
src: Avoid calling into C++ with a null this#1313chearon wants to merge 1 commit intonodejs:mainfrom
Conversation
gabrielschulhof
left a comment
There was a problem hiding this comment.
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. |
Avoid calling into C++ with a null this when exceptions are off PR-URL: #1313 Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com
|
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 <gabrielschulhof@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com
|
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
instanceis 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-apiand 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!