-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a refactoring of #27628 following #28505. This change factors out functions `add_last_status()` and `add_returned_status()` so they may be reused in the tests for passing information about the last error status and/or a returned `napi_status` to JavaScript. PR-URL: #28848 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
- Loading branch information
Showing
7 changed files
with
154 additions
and
201 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <js_native_api.h> | ||
#include "common.h" | ||
|
||
#include <stdio.h> | ||
|
||
void add_returned_status(napi_env env, | ||
const char* key, | ||
napi_value object, | ||
char* expected_message, | ||
napi_status expected_status, | ||
napi_status actual_status) { | ||
|
||
char napi_message_string[100] = ""; | ||
napi_value prop_value; | ||
|
||
if (actual_status != expected_status) { | ||
snprintf(napi_message_string, sizeof(napi_message_string), "Invalid status [%d]", actual_status); | ||
} | ||
|
||
NAPI_CALL_RETURN_VOID(env, | ||
napi_create_string_utf8( | ||
env, | ||
(actual_status == expected_status ? | ||
expected_message : | ||
napi_message_string), | ||
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)); | ||
} |
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
{ | ||
"target_name": "test_object", | ||
"sources": [ | ||
"../common.c", | ||
"../entry_point.c", | ||
"test_object.c" | ||
] | ||
|
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
Oops, something went wrong.