-
Notifications
You must be signed in to change notification settings - Fork 459
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
Add error checking in String::New function #1015
Conversation
test/name.js
Outdated
try{ | ||
binding.name.nullStringShouldThrow(); | ||
}catch(e) | ||
{ | ||
assert.strictEqual(e.message, 'String::New recieved a nullpointer as a value'); | ||
} |
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.
You can use assert.throws()
napi-inl.h
Outdated
@@ -900,6 +900,11 @@ inline String String::New(napi_env env, const std::u16string& val) { | |||
} | |||
|
|||
inline String String::New(napi_env env, const char* val) { | |||
if (val == nullptr) { | |||
NAPI_THROW( | |||
TypeError::New(env, "String::New recieved a nullpointer as a value"), |
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.
typo 😉
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
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
PR-URL: #1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
Landed in da50b51 |
PR-URL: nodejs#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
PR-URL: nodejs#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
PR-URL: nodejs/node-addon-api#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
PR-URL: nodejs/node-addon-api#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
PR-URL: nodejs/node-addon-api#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
PR-URL: nodejs/node-addon-api#1015 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com>
Added an if statement to String::New(env, const char * str) to make sure that str pointer is not null