| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8c7b2ba commit f7724ab
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1485,6 +1485,8 @@ napi_status napi_create_string_latin1(napi_env env, | |||
| 1485 | 1485 | size_t length, | |
| 1486 | 1486 | napi_value* result) { | |
| 1487 | 1487 | CHECK_ENV(env); | |
| 1488 | + if (length > 0) | ||
| 1489 | + CHECK_ARG(env, str); | ||
| 1488 | 1490 | CHECK_ARG(env, result); | |
| 1489 | 1491 | RETURN_STATUS_IF_FALSE(env, | |
| 1490 | 1492 | (length == NAPI_AUTO_LENGTH) || length <= INT_MAX, | |
@@ -1507,6 +1509,8 @@ napi_status napi_create_string_utf8(napi_env env, | |||
| 1507 | 1509 | size_t length, | |
| 1508 | 1510 | napi_value* result) { | |
| 1509 | 1511 | CHECK_ENV(env); | |
| 1512 | + if (length > 0) | ||
| 1513 | + CHECK_ARG(env, str); | ||
| 1510 | 1514 | CHECK_ARG(env, result); | |
| 1511 | 1515 | RETURN_STATUS_IF_FALSE(env, | |
| 1512 | 1516 | (length == NAPI_AUTO_LENGTH) || length <= INT_MAX, | |
@@ -1528,6 +1532,8 @@ napi_status napi_create_string_utf16(napi_env env, | |||
| 1528 | 1532 | size_t length, | |
| 1529 | 1533 | napi_value* result) { | |
| 1530 | 1534 | CHECK_ENV(env); | |
| 1535 | + if (length > 0) | ||
| 1536 | + CHECK_ARG(env, str); | ||
| 1531 | 1537 | CHECK_ARG(env, result); | |
| 1532 | 1538 | RETURN_STATUS_IF_FALSE(env, | |
| 1533 | 1539 | (length == NAPI_AUTO_LENGTH) || length <= INT_MAX, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,9 @@ | |||
| 4 | 4 | "target_name": "test_string", | |
| 5 | 5 | "sources": [ | |
| 6 | 6 | "../entry_point.c", | |
| 7 | - "test_string.c" | ||
| 7 | + "test_string.c", | ||
| 8 | + "test_null.c", | ||
| 9 | + "../common.c", | ||
| 8 | 10 | ] | |
| 9 | 11 | } | |
| 10 | 12 | ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,71 @@ | |||
| 1 | + #include <js_native_api.h> | ||
| 2 | + | ||
| 3 | + #include "../common.h" | ||
| 4 | + #include "test_null.h" | ||
| 5 | + | ||
| 6 | + #define DECLARE_TEST(charset, str_arg) \ | ||
| 7 | + static napi_value \ | ||
| 8 | + test_create_##charset(napi_env env, napi_callback_info info) { \ | ||
| 9 | + napi_value return_value, result; \ | ||
| 10 | + NODE_API_CALL(env, napi_create_object(env, &return_value)); \ | ||
| 11 | + \ | ||
| 12 | + add_returned_status(env, \ | ||
| 13 | + "envIsNull", \ | ||
| 14 | + return_value, \ | ||
| 15 | + "Invalid argument", \ | ||
| 16 | + napi_invalid_arg, \ | ||
| 17 | + napi_create_string_##charset(NULL, \ | ||
| 18 | + (str_arg), \ | ||
| 19 | + NAPI_AUTO_LENGTH, \ | ||
| 20 | + &result)); \ | ||
| 21 | + \ | ||
| 22 | + napi_create_string_##charset(env, NULL, NAPI_AUTO_LENGTH, &result); \ | ||
| 23 | + add_last_status(env, "stringIsNullNonZeroLength", return_value); \ | ||
| 24 | + \ | ||
| 25 | + napi_create_string_##charset(env, NULL, 0, &result); \ | ||
| 26 | + add_last_status(env, "stringIsNullZeroLength", return_value); \ | ||
| 27 | + \ | ||
| 28 | + napi_create_string_##charset(env, (str_arg), NAPI_AUTO_LENGTH, NULL); \ | ||
| 29 | + add_last_status(env, "resultIsNull", return_value); \ | ||
| 30 | + \ | ||
| 31 | + return return_value; \ | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + static const char16_t something[] = { | ||
| 35 | + (char16_t)'s', | ||
| 36 | + (char16_t)'o', | ||
| 37 | + (char16_t)'m', | ||
| 38 | + (char16_t)'e', | ||
| 39 | + (char16_t)'t', | ||
| 40 | + (char16_t)'h', | ||
| 41 | + (char16_t)'i', | ||
| 42 | + (char16_t)'n', | ||
| 43 | + (char16_t)'g', | ||
| 44 | + (char16_t)'\0' | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + DECLARE_TEST(utf8, "something") | ||
| 48 | + DECLARE_TEST(latin1, "something") | ||
| 49 | + DECLARE_TEST(utf16, something) | ||
| 50 | + | ||
| 51 | + void init_test_null(napi_env env, napi_value exports) { | ||
| 52 | + napi_value test_null; | ||
| 53 | + | ||
| 54 | + const napi_property_descriptor test_null_props[] = { | ||
| 55 | + DECLARE_NODE_API_PROPERTY("test_create_utf8", test_create_utf8), | ||
| 56 | + DECLARE_NODE_API_PROPERTY("test_create_latin1", test_create_latin1), | ||
| 57 | + DECLARE_NODE_API_PROPERTY("test_create_utf16", test_create_utf16), | ||
| 58 | + }; | ||
| 59 | + | ||
| 60 | + NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null)); | ||
| 61 | + NODE_API_CALL_RETURN_VOID(env, napi_define_properties( | ||
| 62 | + env, test_null, sizeof(test_null_props) / sizeof(*test_null_props), | ||
| 63 | + test_null_props)); | ||
| 64 | + | ||
| 65 | + const napi_property_descriptor test_null_set = { | ||
| 66 | + "testNull", NULL, NULL, NULL, NULL, test_null, napi_enumerable, NULL | ||
| 67 | + }; | ||
| 68 | + | ||
| 69 | + NODE_API_CALL_RETURN_VOID(env, | ||
| 70 | + napi_define_properties(env, exports, 1, &test_null_set)); | ||
| 71 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + #ifndef TEST_JS_NATIVE_API_TEST_STRING_TEST_NULL_H_ | ||
| 2 | + #define TEST_JS_NATIVE_API_TEST_STRING_TEST_NULL_H_ | ||
| 3 | + | ||
| 4 | + #include <js_native_api.h> | ||
| 5 | + | ||
| 6 | + void init_test_null(napi_env env, napi_value exports); | ||
| 7 | + | ||
| 8 | + #endif // TEST_JS_NATIVE_API_TEST_STRING_TEST_NULL_H_ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + // Test passing NULL to object-related N-APIs. | ||
| 6 | + const { testNull } = require(`./build/${common.buildType}/test_string`); | ||
| 7 | + | ||
| 8 | + const expectedResult = { | ||
| 9 | + envIsNull: 'Invalid argument', | ||
| 10 | + stringIsNullNonZeroLength: 'Invalid argument', | ||
| 11 | + stringIsNullZeroLength: 'napi_ok', | ||
| 12 | + resultIsNull: 'Invalid argument', | ||
| 13 | + }; | ||
| 14 | + | ||
| 15 | + assert.deepStrictEqual(expectedResult, testNull.test_create_latin1()); | ||
| 16 | + assert.deepStrictEqual(expectedResult, testNull.test_create_utf8()); | ||
| 17 | + assert.deepStrictEqual(expectedResult, testNull.test_create_utf16()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | #include <string.h> | |
| 3 | 3 | #include <js_native_api.h> | |
| 4 | 4 | #include "../common.h" | |
| 5 | + #include "test_null.h" | ||
| 5 | 6 | ||
| 6 | 7 | static napi_value TestLatin1(napi_env env, napi_callback_info info) { | |
| 7 | 8 | size_t argc = 1; | |
@@ -283,6 +284,8 @@ napi_value Init(napi_env env, napi_value exports) { | |||
| 283 | 284 | DECLARE_NODE_API_PROPERTY("TestMemoryCorruption", TestMemoryCorruption), | |
| 284 | 285 | }; | |
| 285 | 286 | ||
| 287 | + init_test_null(env, exports); | ||
| 288 | + | ||
| 286 | 289 | NODE_API_CALL(env, napi_define_properties( | |
| 287 | 290 | env, exports, sizeof(properties) / sizeof(*properties), properties)); | |
| 288 | 291 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments