-
Notifications
You must be signed in to change notification settings - Fork 465
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
feat: add IsNullOrUndefined #909
Conversation
napi.h
Outdated
bool IsNull() const; ///< Tests if a value is a null JavaScript value. | ||
bool IsUndefined() const; ///< Tests if a value is an undefined JavaScript value. | ||
bool IsNullOrUndefined() const; ///< Tests if a value is a null or undefined JavaScript 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.
Maybe IsNullish
would be more concise. With the definition of ??
from MDN as (emphasis mine)
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
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.
New changes have been submitted
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.
Hi @januwA ,
Thanks for your patience. So take a look at the comments. Also, you will need to add documentation to doc/value.md
and a tests to test/basic_types/value.js
. For the test, I think checking for true
on null
and undefined
, and false
on something else is a good enough test coverage.
@@ -539,6 +539,10 @@ inline bool Value::IsNull() const { | |||
return Type() == napi_null; | |||
} | |||
|
|||
inline bool Value::IsNullish() const { | |||
return Type() == napi_undefined || Type() == napi_null; |
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.
The compiler may optimize this since it is const
, but let's store the Type()
call in a variable or use a switch statement to ensure it isn't called twice.
@januwA are you still planning to move this forward? |
Added IsNullOrUndefined detection js type function 😃