|
| 1 | +#include <js_native_api.h> |
| 2 | + |
| 3 | +#include "../common.h" |
| 4 | +#include "test_null.h" |
| 5 | + |
| 6 | +static int some_data = 0; |
| 7 | + |
| 8 | +static napi_value TestConstructor(napi_env env, napi_callback_info info) { |
| 9 | + return NULL; |
| 10 | +} |
| 11 | + |
| 12 | +static napi_value TestDefineClass(napi_env env, napi_callback_info info) { |
| 13 | + napi_value return_value, cons; |
| 14 | + |
| 15 | + const napi_property_descriptor prop = |
| 16 | + DECLARE_NODE_API_PROPERTY("testConstructor", TestConstructor); |
| 17 | + |
| 18 | + NODE_API_CALL(env, napi_create_object(env, &return_value)); |
| 19 | + add_returned_status(env, |
| 20 | + "envIsNull", |
| 21 | + return_value, |
| 22 | + "Invalid argument", |
| 23 | + napi_invalid_arg, |
| 24 | + napi_define_class(NULL, |
| 25 | + "TestClass", |
| 26 | + NAPI_AUTO_LENGTH, |
| 27 | + TestConstructor, |
| 28 | + &some_data, |
| 29 | + 1, |
| 30 | + &prop, |
| 31 | + &cons)); |
| 32 | + |
| 33 | + napi_define_class(env, |
| 34 | + NULL, |
| 35 | + NAPI_AUTO_LENGTH, |
| 36 | + TestConstructor, |
| 37 | + &some_data, |
| 38 | + 1, |
| 39 | + &prop, |
| 40 | + &cons); |
| 41 | + add_last_status(env, "nameIsNull", return_value); |
| 42 | + |
| 43 | + napi_define_class( |
| 44 | + env, "TestClass", 0, TestConstructor, &some_data, 1, &prop, &cons); |
| 45 | + add_last_status(env, "lengthIsZero", return_value); |
| 46 | + |
| 47 | + napi_define_class( |
| 48 | + env, "TestClass", NAPI_AUTO_LENGTH, NULL, &some_data, 1, &prop, &cons); |
| 49 | + add_last_status(env, "nativeSideIsNull", return_value); |
| 50 | + |
| 51 | + napi_define_class(env, |
| 52 | + "TestClass", |
| 53 | + NAPI_AUTO_LENGTH, |
| 54 | + TestConstructor, |
| 55 | + NULL, |
| 56 | + 1, |
| 57 | + &prop, |
| 58 | + &cons); |
| 59 | + add_last_status(env, "dataIsNull", return_value); |
| 60 | + |
| 61 | + napi_define_class(env, |
| 62 | + "TestClass", |
| 63 | + NAPI_AUTO_LENGTH, |
| 64 | + TestConstructor, |
| 65 | + &some_data, |
| 66 | + 0, |
| 67 | + &prop, |
| 68 | + &cons); |
| 69 | + add_last_status(env, "propsLengthIsZero", return_value); |
| 70 | + |
| 71 | + napi_define_class(env, |
| 72 | + "TestClass", |
| 73 | + NAPI_AUTO_LENGTH, |
| 74 | + TestConstructor, |
| 75 | + &some_data, |
| 76 | + 1, |
| 77 | + NULL, |
| 78 | + &cons); |
| 79 | + add_last_status(env, "propsIsNull", return_value); |
| 80 | + |
| 81 | + napi_define_class(env, |
| 82 | + "TestClass", |
| 83 | + NAPI_AUTO_LENGTH, |
| 84 | + TestConstructor, |
| 85 | + &some_data, |
| 86 | + 1, |
| 87 | + &prop, |
| 88 | + NULL); |
| 89 | + add_last_status(env, "resultIsNull", return_value); |
| 90 | + |
| 91 | + return return_value; |
| 92 | +} |
| 93 | + |
| 94 | +void init_test_null(napi_env env, napi_value exports) { |
| 95 | + napi_value test_null; |
| 96 | + |
| 97 | + const napi_property_descriptor test_null_props[] = { |
| 98 | + DECLARE_NODE_API_PROPERTY("testDefineClass", TestDefineClass), |
| 99 | + }; |
| 100 | + |
| 101 | + NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null)); |
| 102 | + NODE_API_CALL_RETURN_VOID( |
| 103 | + env, |
| 104 | + napi_define_properties(env, |
| 105 | + test_null, |
| 106 | + sizeof(test_null_props) / sizeof(*test_null_props), |
| 107 | + test_null_props)); |
| 108 | + |
| 109 | + NODE_API_CALL_RETURN_VOID( |
| 110 | + env, napi_set_named_property(env, exports, "testNull", test_null)); |
| 111 | +} |
0 commit comments