diff options
Diffstat (limited to 'src/bun.js/bindings/Process.cpp')
-rw-r--r-- | src/bun.js/bindings/Process.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp index a7798bf9f..6c58c94dd 100644 --- a/src/bun.js/bindings/Process.cpp +++ b/src/bun.js/bindings/Process.cpp @@ -230,23 +230,35 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, auto argCount = callFrame->argumentCount(); if (argCount < 2) { - JSC::throwTypeError(globalObject, scope, "dlopen requires 2 arguments"_s); return JSC::JSValue::encode(JSC::JSValue {}); } JSC::JSValue moduleValue = callFrame->uncheckedArgument(0); - if (!moduleValue.isObject()) { + JSC::JSObject* moduleObject = jsDynamicCast<JSC::JSObject*>(moduleValue); + if (UNLIKELY(!moduleObject)) { JSC::throwTypeError(globalObject, scope, "dlopen requires an object as first argument"_s); return JSC::JSValue::encode(JSC::JSValue {}); } - JSC::Identifier exportsSymbol = JSC::Identifier::fromString(vm, "exports"_s); - JSC::JSObject* exports = moduleValue.getObject()->getIfPropertyExists(globalObject, exportsSymbol).getObject(); + + JSValue exports = moduleObject->getIfPropertyExists(globalObject, builtinNames(vm).exportsPublicName()); + RETURN_IF_EXCEPTION(scope, {}); + + if (UNLIKELY(!exports)) { + JSC::throwTypeError(globalObject, scope, "dlopen requires an object with an exports property"_s); + return JSC::JSValue::encode(JSC::JSValue {}); + } + + globalObject->pendingNapiModule = exports; + if (exports.isCell()) { + vm.writeBarrier(globalObject, exports.asCell()); + } WTF::String filename = callFrame->uncheckedArgument(1).toWTFString(globalObject); + RETURN_IF_EXCEPTION(scope, {}); + CString utf8 = filename.utf8(); - globalObject->pendingNapiModule = exports; void* handle = dlopen(utf8.data(), RTLD_LAZY); if (!handle) { |