From a08b323e617c6e2db6c6bc2e1731f447b43ccb50 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 17 Sep 2022 21:56:30 -0700 Subject: Fix napi module registration Fixes https://github.com/oven-sh/bun/issues/1240 --- src/bun.js/bindings/Process.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/bun.js/bindings/Process.cpp') 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(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); -- cgit v1.2.3