-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Start fixing bugs discovered by Node.js's Node-API tests #14501
Open
190n
wants to merge
255
commits into
main
Choose a base branch
from
ben/fix-node-napi-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 249 commits
Commits
Show all changes
255 commits
Select commit
Hold shift + click to select a range
2583f33
Make NAPI tests allocate in the finalizer
190n afcf7b1
Route all finalizers through NapiFinalizer
190n 23dc0fe
Test that threadsafe function finalizers run on the next tick
190n 85f617f
Fix bugs in napi_create_class and napi_get_value_bigint_*
190n 6169f10
Fix bugs with napi_define_class
190n 6a440aa
Merge branch 'main' into ben/fix-node-napi-tests
190n ef4728c
WIP convert napi.cpp functions to set the last error
190n 49b2de9
Set last error in all C++ napi functions
190n 1649c03
Merge branch 'main' into ben/fix-node-napi-tests
190n a0c2a73
Fix napi_create_bigint_words error handling
190n ed4175b
Arg checking in napi_define_class
190n 216e5b3
Fix napi_coerce_to_*
190n 2fee09f
Change sizeof division to std::size
190n b773e66
Move napi_get_value_string_{latin1,utf16} to C++
190n 2d0e0c9
Set error code in Zig napi functions
190n 7be1bf3
Fix napi_create_dataview
190n 8c571d8
Merge branch 'main' into ben/fix-node-napi-tests
190n 6d1db2c
WIP supporting napi_wrap for more values
190n ea1ddb2
napi_wrap WIP + rip out NAPICallFrame tagging
190n 5bae294
More (self-contained for now) napi tests
190n e5ffd66
Merge branch 'main' into ben/fix-node-napi-tests
190n a240093
Pass data pointer to NAPI constructors
190n 020c32b
clangd config for NAPI tests
190n d612cff
Misc CallFrame fixes
190n e5e643d
Merge branch 'main' into ben/fix-node-napi-tests
190n c44eb73
Do not propagate nullptr out of NAPIFunction::call
190n 710f779
Delete NapiPrototype::napiRef
190n b2080c8
JS exceptions instead of assertions in napi tests
190n a7bc53b
Split NAPI tests out of the huge C++ file
190n b753e4b
Fix providing class's data pointer to method without data pointer
190n b8aba83
napi_wrap fixes
190n bdcca41
Refine NAPI tests
190n e04f461
Work on leak testing for NAPI wrap/ref/external
190n d29e72f
Add missing #include
190n f71b440
Add filename to napi_log
190n 600bc1c
Fix napi_ref finalizers
190n 3ba398f
Stress test napi_wrap and napi_external
190n 43d7cfc
Fix NAPI tests compiling on Windows
190n 3587391
Add napi_type_tag_object and napi_check_type_tag
190n c28d419
Reset last NAPI error before calling into a native module
190n 71101e1
Fix NAPI bugs
190n 249227d
Fix NAPI string creation bugs
heimskr 39b442b
Move napi_create_typedarray from napi.zig to napi.cpp to produce Rang…
heimskr 528d9a6
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 6999978
Make napi_create_external_arraybuffer produce a non-shared ArrayBuffer
heimskr 19b0fed
Include all properties except enums in napi_get_property_names, and e…
heimskr 73579e1
Support filtering by property descriptor in napi_get_all_property_names
190n 84c4f96
Merge branch 'main' into ben/fix-node-napi-tests
190n 8b19e08
Rename wrap-lifetime-test.mjs
190n 774bb89
Fix node_api_symbol_for behavior for null description parameters
heimskr 8a0a88c
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr 838ca00
Replace NAPIFunction with NapiClass
heimskr 059185f
Fix napi_get_new_target
heimskr 197a26f
Fix some confusion over the "length" parameter in NapiClass
heimskr 91a5231
Merge branch 'main' into ben/fix-node-napi-tests
190n a669ff1
Build napi-app in debug mode
190n 5176ab5
Test napi_set_property and napi_set_named_property
190n fb6a48a
Fix property-related NAPI methods
heimskr d2c4a9a
Fix napi_get_all_property_names not including inherited properties wh…
heimskr dc4177f
Keep napi_envs separate, keep track of them, associate module info
heimskr a1c4240
Integrate #12660 into bun/fix-node-napi-tests
heimskr fe18b87
Move napi_wrap lifetime test to existing test suite
190n 936ae5a
Fix and test edge cases calling NAPI constructors
190n b6dfd89
Remove reference to nonexistent test
190n 2d96ec0
Fix napi_set_property
190n f15059f
Handle exceptions in NAPI finalizers as uncaught exceptions
heimskr dffc718
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr 8bb8193
Fix use after free
heimskr 1293039
Clean up some code in node validators (#14897)
Jarred-Sumner b5ed0f0
ci: If only tests change, use artifacts from last successful build (#…
Electroid 664c080
Fixes #14918 (#14921)
Jarred-Sumner a8a2403
Add `bytesWritten` property to Bun.Socket, fix encoding issue in node…
Jarred-Sumner 30fe8d5
fix(install): only globally link requested packages (#12506)
dylan-conway 7fab670
Redact secrets in `bunfig.toml` and `npmrc` logs (#14919)
dylan-conway 08116e4
Fix napi property methods on non-objects (#14935)
190n 03d945e
Run tests from npm packages, `elysia` to start (#14932)
Electroid 7110c07
Inline `process.versions.bun` in `bun build --compile` (#14940)
Jarred-Sumner 1d5da9e
Fixes #11754 (#14948)
Jarred-Sumner afd023a
Fix remaining error in NAPI property functions
190n 7a20f51
Fix NAPI property tests
190n 066b1da
Fix errors from rebase
190n e3b5927
Work on NAPI leak tests
190n d8557ea
Merge branch 'main' into ben/fix-node-napi-tests
190n 3303a5d
Improve finalizer support
heimskr a60ae54
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr c659b3b
Require key to be a string or symbol in napi_has_own_property
heimskr ce46947
Use WebKit branch kai/inherited-property-names
heimskr a6d707a
Don't require node_api_module_get_api_version_v1, default to version 8
heimskr 1c06dbd
Fix multiple dispatch of beforeExit
heimskr f5dc049
Fix some formatting
heimskr ab92fc5
Add a typedef for node_api_basic_env in napi-app
heimskr 3296a6e
Fix napi_instanceof
heimskr d4b7102
Clear NAPI error after native function invocations
heimskr 07a217f
Fix napi_get_version misunderstanding
heimskr 71f3089
Defer external (array)buffer finalizers if necessary
heimskr 0dce736
oops
heimskr 7978505
Fix napi_get_buffer_info return code
heimskr 80b7426
Add node_api_create_buffer_from_arraybuffer
heimskr a152557
Fix napi_env usage in FFI
heimskr 0f29267
Add node_api_get_module_file_name
heimskr 85dcebe
Fix typedef in napi-app
heimskr fceeb22
Don't dlclose if node_api_module_get_api_version_v1 is missing
heimskr 855b710
Use node_api_post_finalizer in napi-app and add some missing includes
heimskr c30ef2c
Fix more missing includes in napi-app
heimskr 07a3913
Escape NAPI file:// URIs
heimskr 9f3b0f7
Adjust some NAPI error messages to match Node equivalents
heimskr 7c13e63
Update WebKit version
heimskr e34673c
Fix test_reference_by_node_api_version
heimskr 86e421a
Merge branch 'main' into ben/fix-node-napi-tests
190n 657f5b9
Set WebKit version to merge commit instead of commit on branch of ove…
190n 8b5fb34
Assert there is an env when calling external finalizer
190n 1de2319
Update TODO in napi-app
190n 3a71be3
Use node_api_post_finalize in napi-app
190n 0bee1c9
Don't create napi_envs for FFI unless actually needed
heimskr 1d8423e
Allow null data in napi_async_work
heimskr 9490c30
Remove stray include
190n 469be87
Merge branch 'main' into ben/fix-node-napi-tests
190n 9ea9925
Rename napiEnv FFI symbol to avoid potential collisions
heimskr c17e05c
Better use of types in FFI.h
heimskr 09a6a11
Don't needlessly tick the event loop if the napi finalizer queue is e…
heimskr 7993f4f
Address some feedback
heimskr bd45a65
Fix napi module file URIs
heimskr 2335e35
Remove `defer` parameter from NapiRef constructor
heimskr 6e7240b
Derefcountify NapiFinalizer
heimskr 563b3c0
Address more feedback
heimskr d11a483
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr 83f536f
Make parameter const
190n 86d4dbe
Treat a call to process.exit() inside napi_call_function as if it thr…
heimskr c20c0de
Undo the previous commit and add a TODO about Web Worker termination
heimskr 7b25ce1
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr a8fa566
Fix beforeOnExit being dispatched multiple times
heimskr ac8c6f0
Run some of Node's Node-API tests in CI
190n 5970006
Merge branch 'main' into ben/fix-node-napi-tests
190n ccd7275
Remove console log
190n 440111f
`bun run prettier:extra`
190n b11d631
Ensure NapiRef finalizers are called by the time the env is cleaned up
heimskr d3b509e
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr adc00e0
Don't defer finalizers if the VM is shutting down
heimskr f54f4e6
Remove stray iostream include
heimskr 9dbe40d
Compile tests in parallel
190n 8358f4d
Merge branch 'main' into ben/fix-node-napi-tests
190n 6dd369e
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr 06d37bf
Actually call instance data finalizers
heimskr bb8b465
Remove workaround for #15111
190n 0e7ed99
Remove stray import
190n 544dd24
Increase timeout
190n f439dac
Merge branch 'main' into ben/fix-node-napi-tests
190n e11a683
Fix compile error
190n 83a2c24
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr 9fa480c
Fix env cleanup hooks
heimskr 2646ea0
Fix async cleanup hooks?
heimskr ed1f25e
Skip node-api/test_async_cleanup_hook/test.js because it uses libuv f…
heimskr f37df90
Add typedef for node_api_basic_env in napi tests
heimskr 134f66c
Undo accidental formatting
heimskr 2afb5e6
Skip compiling Node NAPI tests that we skip running
190n 90852a3
Use correct path separators on Windows
190n f501143
Fix incorrect calling convention usage
heimskr f9718af
Make checkGC fail if running a finalizer during napi env cleanup
heimskr f73ef54
Compile Node tests using Node 23 headers
190n 4103b73
Report NAPI assertion failures more forcefully
heimskr 2aee623
Remove async cleanup hooks from the list after they're called, not be…
heimskr 28830f0
Don't defer finalizers if not in GC
heimskr d9c8f27
Merge branch 'ben/fix-node-napi-tests' into kai/fix-node-napi-tests
heimskr e5c5033
Use clang 16 to compile Node NAPI tests on CI linux
190n 6603871
Add logs for NAPI refs and handle scopes
190n cf960b5
Change how GC is detected
heimskr eef79ce
Skip test_worker_buffer_callback/test-free-called.js
heimskr d090501
Change Windows crash behavior
heimskr 73e9866
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 3e085b5
Cast argument to quick_exit in crash()
heimskr ba5490d
Change abort exit code on Windows
heimskr b02fb24
Add Bun__crashHandler binding
heimskr d93122a
Typedef napi_env in napi_with_version.h and then use it in the node_a…
heimskr c38eca2
Node NAPI tests: get clang(++) from $PATH in CI
heimskr 437d333
Actually never mind on that last one
heimskr 7f9935a
Will this fix the Windows timeout problem?
heimskr 5949777
Or maybe this might
heimskr 1e649b4
Merge branch 'main' into ben/fix-node-napi-tests
heimskr b0a30ca
Fix leak in napi_threadsafe_function
190n 01bbe30
Disable part of js-native-api/test_instance_data/test.js
heimskr dec572e
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr 6ba0563
Add test for napi_threadsafe_function memory leak
190n 7a73f14
Fix napi_threadsafe_function memory leak with fixed queue size
190n 24a3f96
Flush stdout explicitly in test_cleanup_hook
heimskr 2406936
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr b191968
Skip test_callback_scope/test.js on Windows
heimskr e0414d0
Allow ten minutes for compiling node-napi tests
heimskr 30eda1e
Maybe increase the timeout with setDefaultTimeout too
heimskr 8169061
Revert "Maybe increase the timeout with setDefaultTimeout too"
heimskr 9426039
Add Prisma leak test from #15289
190n f78ac63
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr 7a623fe
Print compilation progress in node-napi.test.ts
heimskr 3fc6ad4
Increase napi timeout
heimskr e817928
Reenable Worker test in js-native-api/test_instance_data/test.js
heimskr 7886182
Fix setRawMode return value on Windows
heimskr 33d3732
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 4a10bf2
Oops
heimskr bb33176
Oops, again
heimskr 1789364
Add missing globals in napi tests
heimskr 1baa1b6
Clean up missing globals code a bit
heimskr c1a25d0
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 769c6de
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 7ee91a9
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 7448f05
Initial work on re-mainifying 14501
heimskr ba8cf34
Fix test_conversions
heimskr 793c378
Fix test_object/test_exceptions.js
heimskr 8118aa0
Don't explode if the napi module register function returns nullptr
heimskr d763ef8
Fix most of napi-app
heimskr 923e96a
Use napi-app from main
heimskr 6039af0
Fix napi-app
heimskr a2e1ff9
Fix napi_get_new_target
heimskr 7820f93
Fix native_plugin test
heimskr b4aeb6d
Use LLVM 18 to compile the NAPI tests
heimskr 1d1e4bc
Replace napi finalizer queue with NapiFinalizerTask
heimskr 29c53b2
Remove m_eternalGlobalSymbolRef
heimskr fbbb2f1
Merge branch 'main' into ben/fix-node-napi-tests
Jarred-Sumner e927e75
Skip a prisma test in CI
heimskr 8f63b34
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
heimskr 341c46c
Expect napi failures on musl
heimskr 4be4bf9
Remove traces of Zig::GlobalObject::napiWraps()
190n 376ac49
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
190n 89be2c7
Remove duplicate static assertions
190n 98cf76e
Can't reassign to const
heimskr 7068782
Remove more traces of Zig::GlobalObject::napiWraps
190n 7ebae64
Merge branch 'ben/fix-node-napi-tests' of github.com:oven-sh/bun into…
190n 00fe5f0
Delete dead code in NAPICallFrame
190n 7f43db2
Redo "Fix providing class's data pointer to method without data pointer"
190n 3b5c01a
Redo change that was reverted by merge
190n 0fee96d
Fix some tests
190n fe23f33
Restore more napi tests
190n 5dc7676
Make leak tests more clearly skipped
190n 0097ae2
Restore napi_wrap weak value owner behavior
190n 5e2793e
Remove dead code
190n bf274ec
Unskip one Node.js test
190n 097521a
Remove dead code
190n 89cca66
Fix unnecessary error handling in napi_create_bigint_words
190n d6d6082
Fix segfault caused by Node test
190n 2c8ff71
Merge branch 'main' into ben/fix-node-napi-tests
190n feb2dde
remove dead code
190n 196914d
Fix napi_create_bigint_words error handling
190n 687b3b9
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 329622f
Merge branch 'main' into ben/fix-node-napi-tests
heimskr 4248123
De-flake node-dns.test.js
heimskr 0b88859
Merge branch 'main' into ben/fix-node-napi-tests
190n 1432ada
Remove duplicate macros when NAPI_VERBOSE is 1
190n a74952b
Merge branch 'main' into ben/fix-node-napi-tests
190n 30abd0c
Fix Zig build error
190n aa22fb4
Fix incorrect JSC::getVM find/replace
190n ef5575f
JSC::getVM
190n eb00b43
Merge branch 'main' into ben/fix-node-napi-tests
190n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#include "napi.h" | ||
|
||
#include "BunProcess.h" | ||
#include <JavaScriptCore/InternalFieldTuple.h> | ||
#include <JavaScriptCore/JSMicrotask.h> | ||
|
@@ -37,6 +39,8 @@ | |
#include <JavaScriptCore/LazyPropertyInlines.h> | ||
#include <JavaScriptCore/VMTrapsInlines.h> | ||
#include "wtf-bindings.h" | ||
#include "EventLoopTask.h" | ||
|
||
#include <webcore/SerializedScriptValue.h> | ||
#include "ProcessBindingTTYWrap.h" | ||
#include "wtf/text/ASCIILiteral.h" | ||
|
@@ -101,6 +105,7 @@ typedef int mode_t; | |
#include <unistd.h> // setuid, getuid | ||
#endif | ||
|
||
#include <cstring> | ||
extern "C" bool Bun__Node__ProcessNoDeprecation; | ||
extern "C" bool Bun__Node__ProcessThrowDeprecation; | ||
extern "C" int32_t bun_stdio_tty[3]; | ||
|
@@ -292,6 +297,69 @@ extern "C" bool Bun__resolveEmbeddedNodeFile(void*, BunString*); | |
extern "C" HMODULE Bun__LoadLibraryBunString(BunString*); | ||
#endif | ||
|
||
/// Returns a pointer that needs to be freed with `delete[]`. | ||
static char* toFileURI(std::string_view path) | ||
{ | ||
auto needs_escape = [](char ch) { | ||
return !(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9') | ||
|| ch == '_' || ch == '-' || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')' || ch == '/' || ch == ':'); | ||
}; | ||
|
||
auto to_hex = [](uint8_t nybble) -> char { | ||
if (nybble < 0xa) { | ||
return '0' + nybble; | ||
} | ||
|
||
return 'a' + (nybble - 0xa); | ||
}; | ||
|
||
size_t escape_count = 0; | ||
for (char ch : path) { | ||
#if OS(WINDOWS) | ||
if (needs_escape(ch) && ch != '\\') { | ||
#else | ||
if (needs_escape(ch)) { | ||
#endif | ||
++escape_count; | ||
} | ||
} | ||
|
||
#if OS(WINDOWS) | ||
#define FILE_URI_START "file:///" | ||
#else | ||
#define FILE_URI_START "file://" | ||
#endif | ||
|
||
const size_t string_size = sizeof(FILE_URI_START) + path.size() + 2 * escape_count; // null byte is included in the sizeof expression | ||
char* characters = new char[string_size]; | ||
strncpy(characters, FILE_URI_START, sizeof(FILE_URI_START)); | ||
size_t i = sizeof(FILE_URI_START) - 1; | ||
for (char ch : path) { | ||
#if OS(WINDOWS) | ||
if (ch == '\\') { | ||
characters[i++] = '/'; | ||
continue; | ||
} | ||
#endif | ||
if (needs_escape(ch)) { | ||
characters[i++] = '%'; | ||
characters[i++] = to_hex(static_cast<uint8_t>(ch) >> 4); | ||
characters[i++] = to_hex(ch & 0xf); | ||
} else { | ||
characters[i++] = ch; | ||
} | ||
} | ||
|
||
characters[i] = '\0'; | ||
ASSERT(i + 1 == string_size); | ||
return characters; | ||
} | ||
|
||
static char* toFileURI(std::span<const uint8_t> span) | ||
{ | ||
return toFileURI(std::string_view(reinterpret_cast<const char*>(span.data()), span.size())); | ||
} | ||
|
||
extern "C" size_t Bun__process_dlopen_count; | ||
|
||
JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalObject_, JSC::CallFrame* callFrame)) | ||
|
@@ -408,18 +476,17 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb | |
return JSValue::encode(jsUndefined()); | ||
} | ||
|
||
JSC::EncodedJSValue (*napi_register_module_v1)(JSC::JSGlobalObject* globalObject, | ||
JSC::EncodedJSValue exports); | ||
#if OS(WINDOWS) | ||
#define dlsym GetProcAddress | ||
#endif | ||
|
||
// TODO(@190n) look for node_register_module_vXYZ according to BuildOptions.reported_nodejs_version | ||
// (bun/src/env.zig:36) and the table at https://github.com/nodejs/node/blob/main/doc/abi_version_registry.json | ||
napi_register_module_v1 = reinterpret_cast<JSC::EncodedJSValue (*)(JSC::JSGlobalObject*, | ||
JSC::EncodedJSValue)>( | ||
auto napi_register_module_v1 = reinterpret_cast<napi_value (*)(napi_env, napi_value)>( | ||
dlsym(handle, "napi_register_module_v1")); | ||
|
||
auto node_api_module_get_api_version_v1 = reinterpret_cast<int32_t (*)()>(dlsym(handle, "node_api_module_get_api_version_v1")); | ||
|
||
#if OS(WINDOWS) | ||
#undef dlsym | ||
#endif | ||
|
@@ -430,14 +497,40 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb | |
#else | ||
dlclose(handle); | ||
#endif | ||
|
||
JSC::throwTypeError(globalObject, scope, "symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?"_s); | ||
return {}; | ||
} | ||
|
||
// TODO(@heimskr): get the API version without node_api_module_get_api_version_v1 a different way | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the other way? curious There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in some cases there's a global variable of type |
||
int module_version = 8; | ||
if (node_api_module_get_api_version_v1) { | ||
module_version = node_api_module_get_api_version_v1(); | ||
} | ||
|
||
NapiHandleScope handleScope(globalObject); | ||
|
||
EncodedJSValue exportsValue = JSC::JSValue::encode(exports); | ||
JSC::JSValue resultValue = JSValue::decode(napi_register_module_v1(globalObject, exportsValue)); | ||
|
||
char* filename_cstr = toFileURI(filename.utf8().span()); | ||
|
||
napi_module nmodule { | ||
.nm_version = module_version, | ||
.nm_flags = 0, | ||
.nm_filename = filename_cstr, | ||
.nm_register_func = nullptr, | ||
.nm_modname = "[no modname]", | ||
.nm_priv = nullptr, | ||
.reserved = {}, | ||
}; | ||
|
||
static_assert(sizeof(napi_value) == sizeof(EncodedJSValue), "EncodedJSValue must be reinterpretable as a pointer"); | ||
|
||
auto env = globalObject->makeNapiEnv(nmodule); | ||
env->filename = filename_cstr; | ||
|
||
auto encoded = reinterpret_cast<EncodedJSValue>(napi_register_module_v1(env, reinterpret_cast<napi_value>(exportsValue))); | ||
JSC::JSValue resultValue = encoded == 0 ? jsUndefined() : JSValue::decode(encoded); | ||
|
||
if (auto resultObject = resultValue.getObject()) { | ||
#if OS(DARWIN) || OS(LINUX) | ||
|
@@ -451,7 +544,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb | |
// TODO: think about the finalizer here | ||
// currently we do not dealloc napi modules so we don't have to worry about it right now | ||
auto* meta = new Bun::NapiModuleMeta(globalObject->m_pendingNapiModuleDlopenHandle); | ||
Bun::NapiExternal* napi_external = Bun::NapiExternal::create(vm, globalObject->NapiExternalStructure(), meta, nullptr, nullptr); | ||
Bun::NapiExternal* napi_external = Bun::NapiExternal::create(vm, globalObject->NapiExternalStructure(), meta, nullptr, env, nullptr); | ||
bool success = resultObject->putDirect(vm, WebCore::builtinNames(vm).napiDlopenHandlePrivateName(), napi_external, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); | ||
ASSERT(success); | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this return the right string on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not. It expects ASCII.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTF8, actually, which it's receiving from the WTF::String. And the NAPI docs don't specify anything about a required encoding. The
const char **
type suggests to me that it's not expecting the output to be UTF16/UCS2.