From c4b3b321c2e0550a7bce92fdeee6082f61d5ccc8 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 13 Apr 2023 04:54:05 -0700 Subject: [PATCH] slightly more progress --- src/bun.js/bindings/BunInspector.cpp | 11 ++++++++++- src/bun.js/bindings/BunInspector.h | 1 + src/bun.js/event_loop.zig | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bun.js/bindings/BunInspector.cpp b/src/bun.js/bindings/BunInspector.cpp index a88823edd6..4790c5a60f 100644 --- a/src/bun.js/bindings/BunInspector.cpp +++ b/src/bun.js/bindings/BunInspector.cpp @@ -2,6 +2,7 @@ #include #include #include "JSGlobalObjectInspectorController.h" +#include namespace Zig { @@ -111,6 +112,8 @@ void BunInspector::drainOutgoingMessages() } } +extern "C" void Bun__tickWhileWaitingForDebugger(JSC::JSGlobalObject* globalObject); + RefPtr BunInspector::startWebSocketServer( WebCore::ScriptExecutionContext& context, WTF::String hostname, @@ -184,7 +187,13 @@ RefPtr BunInspector::startWebSocketServer( *connectionPtr = new BunInspectorConnection(inspector); ws->subscribe("BunInspectorConnection"); BunInspectorConnection* connection = *connectionPtr; - inspector->connect(Inspector::FrontendChannel::ConnectionType::Local); }, + inspector->connect(Inspector::FrontendChannel::ConnectionType::Local); + auto* debugger = reinterpret_cast(inspector->globalObject()->inspectorController().debugger()); + debugger->runWhilePausedCallback = [](JSC::JSGlobalObject& globalObject, bool& isPaused) { + while (isPaused) { + Bun__tickWhileWaitingForDebugger(&globalObject); + } + }; }, .message = [inspector](auto* ws, std::string_view message, uWS::OpCode opCode) { if (opCode == uWS::OpCode::TEXT) { diff --git a/src/bun.js/bindings/BunInspector.h b/src/bun.js/bindings/BunInspector.h index 219cfdcf38..c02e810cb7 100644 --- a/src/bun.js/bindings/BunInspector.h +++ b/src/bun.js/bindings/BunInspector.h @@ -11,6 +11,7 @@ namespace Zig { using namespace JSC; +using namespace WebCore; class BunInspector final : public RefCounted, ::Inspector::InspectorTarget, ::Inspector::FrontendChannel, public WebCore::ContextDestructionObserver { public: diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index c2125e64f7..04935c79be 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -879,3 +879,12 @@ pub const AnyEventLoop = union(enum) { } } }; + +pub export fn Bun__tickWhileWaitingForDebugger(globalObject: *JSC.JSGlobalObject) callconv(.C) void { + globalObject.bunVM().eventLoop().tickPossiblyForever(); +} + +comptime { + if (!JSC.is_bindgen) + _ = Bun__tickWhileWaitingForDebugger; +}