aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/Process.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-17 21:56:30 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-17 21:56:30 -0700
commita08b323e617c6e2db6c6bc2e1731f447b43ccb50 (patch)
tree58068b571282a1d194a716a59c819ac04cfca714 /src/bun.js/bindings/Process.cpp
parent745cc5c65502f1c1bcd69392e526d63f04653e11 (diff)
downloadbun-a08b323e617c6e2db6c6bc2e1731f447b43ccb50.tar.gz
bun-a08b323e617c6e2db6c6bc2e1731f447b43ccb50.tar.zst
bun-a08b323e617c6e2db6c6bc2e1731f447b43ccb50.zip
Fix napi module registration
Fixes https://github.com/oven-sh/bun/issues/1240
Diffstat (limited to 'src/bun.js/bindings/Process.cpp')
-rw-r--r--src/bun.js/bindings/Process.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp
index c3a98d876..b4297edab 100644
--- a/src/bun.js/bindings/Process.cpp
+++ b/src/bun.js/bindings/Process.cpp
@@ -114,6 +114,7 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
(JSC::JSGlobalObject * globalObject_, JSC::CallFrame* callFrame))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject_);
+ auto callCountAtStart = globalObject->napiModuleRegisterCallCount;
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::VM& vm = globalObject->vm();
@@ -144,15 +145,19 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
return JSC::JSValue::encode(JSC::JSValue {});
}
- if (JSValue pendingModule = globalObject->pendingNapiModule) {
+ if (callCountAtStart != globalObject->napiModuleRegisterCallCount) {
+ JSValue pendingModule = globalObject->pendingNapiModule;
globalObject->pendingNapiModule = JSValue {};
- if (pendingModule.isCell() && pendingModule.getObject()->isErrorInstance()) {
- JSC::throwException(globalObject, scope, pendingModule);
- return JSC::JSValue::encode(JSC::JSValue {});
+ globalObject->napiModuleRegisterCallCount = 0;
+
+ if (pendingModule) {
+ if (pendingModule.isCell() && pendingModule.getObject()->isErrorInstance()) {
+ JSC::throwException(globalObject, scope, pendingModule);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
+ return JSC::JSValue::encode(pendingModule);
}
- return JSC::JSValue::encode(pendingModule);
}
- globalObject->pendingNapiModule = JSValue {};
JSC::EncodedJSValue (*napi_register_module_v1)(JSC::JSGlobalObject * globalObject,
JSC::EncodedJSValue exports);