-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
test: add coverage for napi_typeof #13990
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ napi_value testGetVersion(napi_env env, napi_callback_info info) { | |
uint32_t version; | ||
napi_value result; | ||
NAPI_CALL(env, napi_get_version(env, &version)); | ||
NAPI_CALL(env ,napi_create_number(env, version, &result)); | ||
NAPI_CALL(env,napi_create_number(env, version, &result)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a space after the first comma. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
return result; | ||
} | ||
|
||
|
@@ -90,6 +90,35 @@ napi_value testNapiErrorCleanup(napi_env env, napi_callback_info info) { | |
return result; | ||
} | ||
|
||
napi_value testNapiTypeof(napi_env env, napi_callback_info info) { | ||
size_t argc = 1; | ||
napi_value args[1]; | ||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
||
napi_valuetype argument_type; | ||
NAPI_CALL(env, napi_typeof(env, args[0], &argument_type)); | ||
|
||
napi_value result; | ||
if (argument_type == napi_number) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "number", -1, &result)); | ||
} else if (argument_type == napi_string) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "string", -1, &result)); | ||
} else if (argument_type == napi_function) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "function", -1, &result)); | ||
} else if (argument_type == napi_object) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "object", -1, &result)); | ||
} else if (argument_type == napi_boolean) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "boolean", -1, &result)); | ||
} else if (argument_type == napi_undefined) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "undefined", -1, &result)); | ||
} else if (argument_type == napi_symbol) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "symbol", -1, &result)); | ||
} else if (argument_type == napi_null) { | ||
NAPI_CALL(env, napi_create_string_utf8(env, "null", -1, &result)); | ||
} | ||
return result; | ||
} | ||
|
||
void Init(napi_env env, napi_value exports, napi_value module, void* priv) { | ||
napi_property_descriptor descriptors[] = { | ||
DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals), | ||
|
@@ -100,6 +129,7 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) { | |
DECLARE_NAPI_PROPERTY("getNull", getNull), | ||
DECLARE_NAPI_PROPERTY("createNapiError", createNapiError), | ||
DECLARE_NAPI_PROPERTY("testNapiErrorCleanup", testNapiErrorCleanup), | ||
DECLARE_NAPI_PROPERTY("testNapiTypeof", testNapiTypeof), | ||
}; | ||
|
||
NAPI_CALL_RETURN_VOID(env, napi_define_properties( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oh. A tiny nit here and on line 52. I think the parameter order should be switched to reflect
actual, expected
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.
Thanks for catching that will update.