Skip to content
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

48198 node api external strings #48339

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bd8045b
node-api: unify string creation
gabrielschulhof Jun 2, 2023
50a2109
node-api: add string creation benchmark
gabrielschulhof Jun 3, 2023
1364872
node-api: implement external strings
gabrielschulhof Jun 3, 2023
a9e24b9
add test
gabrielschulhof Jun 3, 2023
e1127d1
rename to node_api_*
gabrielschulhof Jun 4, 2023
953304c
put back build type
gabrielschulhof Jun 5, 2023
09f7cdf
make linter work
gabrielschulhof Jun 5, 2023
902cb33
rename as requested
gabrielschulhof Jun 6, 2023
754864e
use std::basic_string_view to calc length in case of NAPI_AUTO_LENGTH
gabrielschulhof Jun 6, 2023
95a9971
test for auto-length
gabrielschulhof Jun 7, 2023
b4f383b
format
gabrielschulhof Jun 7, 2023
05317ac
correct length
gabrielschulhof Jun 7, 2023
20ab0fb
doc
gabrielschulhof Jun 7, 2023
ca4c08c
use right length indicator
gabrielschulhof Jun 8, 2023
5de34d4
final adjustment
gabrielschulhof Jun 8, 2023
64f2498
Apply suggestions from code review
gabrielschulhof Jun 8, 2023
cb9d95a
Apply suggestions from code review
gabrielschulhof Jun 8, 2023
ed83494
remove utf8
gabrielschulhof Jun 9, 2023
e063901
handle the case where we copy the string
gabrielschulhof Jun 10, 2023
4ff5e53
implement the non-copying case
gabrielschulhof Jun 10, 2023
402c93e
Unify the two external cases
gabrielschulhof Jun 11, 2023
32a5600
factor out tracking
gabrielschulhof Jun 11, 2023
0b72009
document
gabrielschulhof Jun 11, 2023
50dfa5d
debug ctor dtor
gabrielschulhof Jun 11, 2023
3a96b04
typo
gabrielschulhof Jun 11, 2023
caccb8e
Apply suggestions from code review
gabrielschulhof Jun 11, 2023
5c11c81
Apply suggestions from code review
gabrielschulhof Jun 11, 2023
b651fca
use common distructor
gabrielschulhof Jun 12, 2023
668fd4d
format
gabrielschulhof Jun 12, 2023
c721439
Apply suggestions from code review
gabrielschulhof Jun 12, 2023
7f67a2f
md lint
gabrielschulhof Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename to node_api_*
  • Loading branch information
gabrielschulhof committed Jun 7, 2023
commit e1127d16ab7c6eb9384cf6d23e9a79490d5330da
6 changes: 3 additions & 3 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
size_t length,
napi_value* result);
#ifdef NAPI_EXPERIMENTAL
NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_string_latin1(
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1(
napi_env env, const char* str, size_t length, napi_value* result);
NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_string_utf8(
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_utf8(
napi_env env, const char* str, size_t length, napi_value* result);
NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_string_utf16(
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_utf16(
napi_env env, const char16_t* str, size_t length, napi_value* result);
#endif // NAPI_EXPERIMENTAL
NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
Expand Down
18 changes: 6 additions & 12 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1463,10 +1463,8 @@ napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
});
}

napi_status NAPI_CDECL napi_create_external_string_latin1(napi_env env,
const char* str,
size_t length,
napi_value* result) {
napi_status NAPI_CDECL node_api_create_external_string_latin1(
napi_env env, const char* str, size_t length, napi_value* result) {
#if defined(V8_ENABLE_SANDBOX)
return napi_create_string_latin1(env, str, length, result);
#else
Expand All @@ -1477,17 +1475,13 @@ napi_status NAPI_CDECL napi_create_external_string_latin1(napi_env env,
#endif // V8_ENABLE_SANDBOX
}

napi_status NAPI_CDECL napi_create_external_string_utf8(napi_env env,
const char* str,
size_t length,
napi_value* result) {
napi_status NAPI_CDECL node_api_create_external_string_utf8(
napi_env env, const char* str, size_t length, napi_value* result) {
return napi_create_string_utf8(env, str, length, result);
}

napi_status NAPI_CDECL napi_create_external_string_utf16(napi_env env,
const char16_t* str,
size_t length,
napi_value* result) {
napi_status NAPI_CDECL node_api_create_external_string_utf16(
napi_env env, const char16_t* str, size_t length, napi_value* result) {
#if defined(V8_ENABLE_SANDBOX)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with Electron if this is needed for strings.

return napi_create_string_utf16(env, str, length, result);
#else
Expand Down
7 changes: 4 additions & 3 deletions test/js-native-api/test_string/test_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ static napi_status create_external_latin1(napi_env env,
size_t length,
napi_value* result) {
return create_external_one_byte(
env, string, length, result, napi_create_external_string_latin1);
env, string, length, result, node_api_create_external_string_latin1);
}

static napi_status create_external_utf8(napi_env env,
const char* string,
size_t length,
napi_value* result) {
return create_external_one_byte(
env, string, length, result, napi_create_external_string_utf8);
env, string, length, result, node_api_create_external_string_utf8);
}

static napi_status create_external_utf16(napi_env env,
Expand All @@ -160,7 +160,8 @@ static napi_status create_external_utf16(napi_env env,
memcpy(string_copy, string, length_bytes);
string_copy[length] = 0;

status = napi_create_external_string_utf16(env, string_copy, length, result);
status =
node_api_create_external_string_utf16(env, string_copy, length, result);
if (status != napi_ok) {
free(string_copy);
return status;
Expand Down