From 11aa17a57cc679d34e8e6f6f7aa665f565cb7305 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 5 Sep 2022 23:05:22 -0700 Subject: Support async `onLoad` callbacks in `Bun.plugin` --- src/bun.js/bindings/ZigGlobalObject.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/ZigGlobalObject.h') diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 6c5c23b3a..160aef714 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -35,7 +35,9 @@ class EventLoopTask; #include "BunPlugin.h" extern "C" void Bun__reportError(JSC__JSGlobalObject*, JSC__JSValue); - +// defined in ModuleLoader.cpp +extern "C" JSC::EncodedJSValue jsFunctionOnLoadObjectResultResolve(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame); +extern "C" JSC::EncodedJSValue jsFunctionOnLoadObjectResultReject(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame); // #include "EventTarget.h" // namespace WebCore { @@ -239,7 +241,10 @@ public: Bun__HTTPRequestContextDebugTLS__onResolve, Bun__HTTPRequestContextDebugTLS__onResolveStream, + jsFunctionOnLoadObjectResultResolve, + jsFunctionOnLoadObjectResultReject, }; + static constexpr size_t promiseFunctionsSize = 18; static PromiseFunctions promiseHandlerID(EncodedJSValue (*handler)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1)) { @@ -275,6 +280,14 @@ public: return PromiseFunctions::Bun__HTTPRequestContextDebugTLS__onResolve; } else if (handler == Bun__HTTPRequestContextDebugTLS__onResolveStream) { return PromiseFunctions::Bun__HTTPRequestContextDebugTLS__onResolveStream; + } else if (handler == Bun__HTTPRequestContextDebugTLS__onResolveStream) { + return PromiseFunctions::Bun__HTTPRequestContextDebugTLS__onResolveStream; + } else if (handler == Bun__HTTPRequestContextDebugTLS__onResolveStream) { + return PromiseFunctions::Bun__HTTPRequestContextDebugTLS__onResolveStream; + } else if (handler == jsFunctionOnLoadObjectResultResolve) { + return PromiseFunctions::jsFunctionOnLoadObjectResultResolve; + } else if (handler == jsFunctionOnLoadObjectResultReject) { + return PromiseFunctions::jsFunctionOnLoadObjectResultReject; } else { RELEASE_ASSERT_NOT_REACHED(); } @@ -300,7 +313,7 @@ public: mutable WriteBarrier m_readableStreamToJSON; mutable WriteBarrier m_readableStreamToArrayBuffer; mutable WriteBarrier m_assignToStream; - mutable WriteBarrier m_thenables[16]; + mutable WriteBarrier m_thenables[promiseFunctionsSize + 1]; void trackFFIFunction(JSC::JSFunction* function) { @@ -311,6 +324,8 @@ public: BunPlugin::OnResolve onResolvePlugins[BunPluginTargetMax + 1] {}; BunPluginTarget defaultBunPluginTarget = BunPluginTargetBun; + JSC::Structure* pendingVirtualModuleResultStructure() { return m_pendingVirtualModuleResultStructure.get(this); } + // When a napi module initializes on dlopen, we need to know what the value is JSValue pendingNapiModule = JSValue {}; @@ -344,6 +359,8 @@ private: LazyProperty m_requireMap; LazyProperty m_performanceObject; + LazyProperty m_pendingVirtualModuleResultStructure; + LazyProperty m_encodeIntoObjectPrototype; // LazyProperty m_eventTarget; -- cgit v1.2.3