-
Notifications
You must be signed in to change notification settings - Fork 7
Implementation of V1 buffer runtime functions #168
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d6fca0c
Added node_api_impl files
paradowstack d2b6e49
Added test addon for buffers
paradowstack b74771b
Injecting runtime functions
paradowstack a4d578e
Adjusting scripts
paradowstack f6b3f13
Buffer test updated
paradowstack f868935
Cleanup
paradowstack 82dd33b
Added eslint-disable for test addon
paradowstack 4db670c
Removed debug lines
paradowstack 4130877
Moved .gitignore up
paradowstack 35f0b24
Renamed files to RuntimeNodeApi
paradowstack d6d57a1
Removed gc related tests
paradowstack aa770f6
Cleaned up file
paradowstack 7c4e9ae
Renamed to IMPLEMENTED_RUNTIME_FUNCTIONS
paradowstack 2441fc8
Added reference to the issue
paradowstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,108 @@ | ||
| #include "node_api_impl.hpp" | ||
| #include <string> | ||
|
|
||
| auto ArrayType = napi_uint8_array; | ||
|
|
||
| napi_status NAPI_CDECL callstack::nodeapihost::napi_create_buffer( | ||
| napi_env env, size_t length, void** data, napi_value* result) { | ||
| napi_value buffer; | ||
| const auto status = napi_create_arraybuffer(env, length, data, &buffer); | ||
| if (status != napi_ok) { | ||
| return status; | ||
| } | ||
|
|
||
| return napi_create_typedarray(env, ArrayType, length, buffer, 0, result); | ||
paradowstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| napi_status NAPI_CDECL callstack::nodeapihost::napi_create_buffer_copy( | ||
| napi_env env, | ||
| size_t length, | ||
| const void* data, | ||
| void** result_data, | ||
| napi_value* result) { | ||
| if (!length || !data || !result) { | ||
| return napi_invalid_arg; | ||
| } | ||
|
|
||
| void* buffer = nullptr; | ||
| if (const auto status = ::napi_create_buffer(env, length, &buffer, result); | ||
| status != napi_ok) { | ||
| return status; | ||
| } | ||
|
|
||
| std::memcpy(buffer, data, length); | ||
| return napi_ok; | ||
| } | ||
|
|
||
| napi_status callstack::nodeapihost::napi_is_buffer( | ||
| napi_env env, napi_value value, bool* result) { | ||
| if (!result) { | ||
| return napi_invalid_arg; | ||
| } | ||
|
|
||
| if (!value) { | ||
| *result = false; | ||
| return napi_ok; | ||
| } | ||
|
|
||
| napi_valuetype type{}; | ||
| if (const auto status = napi_typeof(env, value, &type); status != napi_ok) { | ||
| return status; | ||
| } | ||
|
|
||
| if (type != napi_object && type != napi_external) { | ||
| *result = false; | ||
| return napi_ok; | ||
| } | ||
|
|
||
| auto isArrayBuffer{false}; | ||
| if (const auto status = napi_is_arraybuffer(env, value, &isArrayBuffer); | ||
| status != napi_ok) { | ||
| return status; | ||
| } | ||
| auto isTypedArray{false}; | ||
| if (const auto status = napi_is_typedarray(env, value, &isTypedArray); | ||
| status != napi_ok) { | ||
| return status; | ||
| } | ||
|
|
||
| *result = isArrayBuffer || isTypedArray; | ||
| return napi_ok; | ||
| } | ||
|
|
||
| napi_status callstack::nodeapihost::napi_get_buffer_info( | ||
| napi_env env, napi_value value, void** data, size_t* length) { | ||
| if (!data || !length) { | ||
| return napi_invalid_arg; | ||
| } | ||
| *data = nullptr; | ||
| *length = 0; | ||
| if (!value) { | ||
| return napi_ok; | ||
| } | ||
|
|
||
| auto isArrayBuffer{false}; | ||
| if (const auto status = napi_is_arraybuffer(env, value, &isArrayBuffer); | ||
| status == napi_ok && isArrayBuffer) { | ||
| return napi_get_arraybuffer_info(env, value, data, length); | ||
| } | ||
|
|
||
| auto isTypedArray{false}; | ||
| if (const auto status = napi_is_typedarray(env, value, &isTypedArray); | ||
| status == napi_ok && isTypedArray) { | ||
| return napi_get_typedarray_info( | ||
| env, value, &ArrayType, length, data, nullptr, nullptr); | ||
| } | ||
|
|
||
| return napi_ok; | ||
| } | ||
|
|
||
| napi_status callstack::nodeapihost::napi_create_external_buffer(napi_env env, | ||
| size_t length, | ||
| void* data, | ||
| node_api_basic_finalize basic_finalize_cb, | ||
| void* finalize_hint, | ||
| napi_value* result) { | ||
| return napi_create_external_arraybuffer( | ||
| env, data, length, basic_finalize_cb, finalize_hint, result); | ||
| } | ||
This file contains hidden or 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,25 @@ | ||
| #include "node_api.h" | ||
|
|
||
| namespace callstack::nodeapihost { | ||
| napi_status napi_create_buffer( | ||
| napi_env env, size_t length, void** data, napi_value* result); | ||
|
|
||
| napi_status napi_create_buffer_copy(napi_env env, | ||
| size_t length, | ||
| const void* data, | ||
| void** result_data, | ||
| napi_value* result); | ||
|
|
||
| napi_status napi_is_buffer(napi_env env, napi_value value, bool* result); | ||
|
|
||
| napi_status napi_get_buffer_info( | ||
| napi_env env, napi_value value, void** data, size_t* length); | ||
|
|
||
| napi_status napi_create_external_buffer(napi_env env, | ||
| size_t length, | ||
| void* data, | ||
| node_api_basic_finalize basic_finalize_cb, | ||
| void* finalize_hint, | ||
| napi_value* result); | ||
|
|
||
| } // namespace callstack::nodeapihost |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| build | ||
paradowstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,15 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(tests-buffers) | ||
|
|
||
| add_compile_definitions(NAPI_VERSION=8) | ||
|
|
||
| add_library(addon SHARED addon.c ${CMAKE_JS_SRC}) | ||
| set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") | ||
| target_include_directories(addon PRIVATE ${CMAKE_JS_INC}) | ||
| target_link_libraries(addon PRIVATE ${CMAKE_JS_LIB}) | ||
| target_compile_features(addon PRIVATE cxx_std_17) | ||
|
|
||
| if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) | ||
| # Generate node.lib | ||
| execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) | ||
| endif() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.