mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
Fix crash when napi_register_module_v1 returns nullptr (#16816)
This commit is contained in:
@@ -438,6 +438,13 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb
|
||||
|
||||
EncodedJSValue exportsValue = JSC::JSValue::encode(exports);
|
||||
JSC::JSValue resultValue = JSValue::decode(napi_register_module_v1(globalObject, exportsValue));
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
// If a module returns `nullptr` (cast to a napi_value) from its register function, we should
|
||||
// use the `exports` value (which may have had properties added to it) as the return value of
|
||||
// `require()`.
|
||||
if (resultValue.isEmpty()) {
|
||||
resultValue = exports;
|
||||
}
|
||||
|
||||
if (auto resultObject = resultValue.getObject()) {
|
||||
#if OS(DARWIN) || OS(LINUX)
|
||||
@@ -454,11 +461,10 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalOb
|
||||
Bun::NapiExternal* napi_external = Bun::NapiExternal::create(vm, globalObject->NapiExternalStructure(), meta, nullptr, nullptr);
|
||||
bool success = resultObject->putDirect(vm, WebCore::builtinNames(vm).napiDlopenHandlePrivateName(), napi_external, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
|
||||
ASSERT(success);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
globalObject->m_pendingNapiModuleAndExports[0].clear();
|
||||
globalObject->m_pendingNapiModuleAndExports[1].clear();
|
||||
globalObject->m_pendingNapiModuleDlopenHandle = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user