xref: /third_party/node/test/js-native-api/common-inl.h (revision 1cb0ef41)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/js-native-api/
1#ifndef JS_NATIVE_API_COMMON_INL_H_
2#define JS_NATIVE_API_COMMON_INL_H_
3
4#include <js_native_api.h>
5#include "common.h"
6
7#include <stdio.h>
8
9inline void add_returned_status(napi_env env,
10                                const char* key,
11                                napi_value object,
12                                char* expected_message,
13                                napi_status expected_status,
14                                napi_status actual_status) {
15  char napi_message_string[100] = "";
16  napi_value prop_value;
17
18  if (actual_status != expected_status) {
19    snprintf(napi_message_string,
20             sizeof(napi_message_string),
21             "Invalid status [%d]",
22             actual_status);
23  }
24
25  NODE_API_CALL_RETURN_VOID(
26      env,
27      napi_create_string_utf8(
28          env,
29          (actual_status == expected_status ? expected_message
30                                            : napi_message_string),
31          NAPI_AUTO_LENGTH,
32          &prop_value));
33  NODE_API_CALL_RETURN_VOID(
34      env, napi_set_named_property(env, object, key, prop_value));
35}
36
37inline void add_last_status(napi_env env,
38                            const char* key,
39                            napi_value return_value) {
40  napi_value prop_value;
41  const napi_extended_error_info* p_last_error;
42  NODE_API_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error));
43
44  NODE_API_CALL_RETURN_VOID(
45      env,
46      napi_create_string_utf8(
47          env,
48          (p_last_error->error_message == NULL ? "napi_ok"
49                                               : p_last_error->error_message),
50          NAPI_AUTO_LENGTH,
51          &prop_value));
52  NODE_API_CALL_RETURN_VOID(
53      env, napi_set_named_property(env, return_value, key, prop_value));
54}
55
56#endif  // JS_NATIVE_API_COMMON_INL_H_
57

Indexes created Thu Nov 07 10:32:03 CST 2024