-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
n-api: refactoring a previous commit #28848
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| #include <js_native_api.h> | ||||||
| #include "common.h" | ||||||
|
|
||||||
| #include <stdio.h> | ||||||
|
|
||||||
| void add_returned_status(napi_env env, | ||||||
| const char* key, | ||||||
| napi_value object, | ||||||
| napi_status expected_status, | ||||||
| napi_status actual_status) { | ||||||
|
|
||||||
| char p_napi_message[100] = ""; | ||||||
| napi_value prop_value; | ||||||
|
|
||||||
| if (actual_status == expected_status) { | ||||||
| snprintf(p_napi_message, 99, "Invalid argument"); | ||||||
|
Member
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.
Suggested change
(Side note: why the
Author
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. Hi @addaleax Thank you for your message. Usually I use p_ for a name that indicates a pointer. Could you please suggest a better name? Thank you in advance,
Member
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.
Okay, that makes sense, but we generally don’t to this elsewhere 🙂. How about just |
||||||
| } else { | ||||||
| snprintf(p_napi_message, 99, "Invalid status [%d]", actual_status); | ||||||
|
Member
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.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| NAPI_CALL_RETURN_VOID(env, | ||||||
| napi_create_string_utf8(env, | ||||||
| p_napi_message, | ||||||
| NAPI_AUTO_LENGTH, | ||||||
| &prop_value)); | ||||||
| NAPI_CALL_RETURN_VOID(env, | ||||||
| napi_set_named_property(env, | ||||||
| object, | ||||||
| key, | ||||||
| prop_value)); | ||||||
| } | ||||||
|
|
||||||
| void add_last_status(napi_env env, const char* key, napi_value return_value) { | ||||||
| napi_value prop_value; | ||||||
| const napi_extended_error_info* p_last_error; | ||||||
| NAPI_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error)); | ||||||
|
|
||||||
| NAPI_CALL_RETURN_VOID(env, | ||||||
| napi_create_string_utf8(env, | ||||||
| (p_last_error->error_message == NULL ? | ||||||
| "napi_ok" : | ||||||
| p_last_error->error_message), | ||||||
| NAPI_AUTO_LENGTH, | ||||||
| &prop_value)); | ||||||
| NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, | ||||||
| return_value, | ||||||
| key, | ||||||
| prop_value)); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| { | ||
| "target_name": "test_object", | ||
| "sources": [ | ||
| "../common.c", | ||
| "../entry_point.c", | ||
| "test_object.c" | ||
| ] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.