From 1ff8155c2831b95b72fb9749b7e837df48893df6 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Fri, 1 Sep 2023 00:33:33 -0700 Subject: Add Bun.canReload event to inspector --- src/bun.js/bindings/BunDebugger.cpp | 15 +++++++++++++++ src/bun.js/javascript.zig | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/bun.js') diff --git a/src/bun.js/bindings/BunDebugger.cpp b/src/bun.js/bindings/BunDebugger.cpp index f4a5f535a..046739923 100644 --- a/src/bun.js/bindings/BunDebugger.cpp +++ b/src/bun.js/bindings/BunDebugger.cpp @@ -452,6 +452,21 @@ extern "C" void Bun__ensureDebugger(ScriptExecutionContextIdentifier scriptId, b } } +extern "C" void BunDebugger__willHotReload() { + if (debuggerScriptExecutionContext == nullptr) { + return; + } + + debuggerScriptExecutionContext->postTaskConcurrently([](ScriptExecutionContext &context){ + WTF::LockHolder locker(inspectorConnectionsLock); + for (auto& connections : *inspectorConnections) { + for (auto* connection : connections.value) { + connection->sendMessageToFrontend("{\"method\":\"Bun.canReload\"}"_s); + } + } + }); +} + JSC_DEFINE_HOST_FUNCTION(jsFunctionCreateConnection, (JSGlobalObject * globalObject, CallFrame* callFrame)) { auto* debuggerGlobalObject = jsDynamicCast(globalObject); diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 32cf04346..212e6be71 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -2720,6 +2720,7 @@ pub const VirtualMachine = struct { pub const HotReloader = NewHotReloader(VirtualMachine, JSC.EventLoop, false); pub const Watcher = HotReloader.Watcher; +extern fn BunDebugger__willHotReload() void; pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime reload_immediately: bool) type { return struct { @@ -2777,6 +2778,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime unreachable; } + BunDebugger__willHotReload(); var that = bun.default_allocator.create(HotReloadTask) catch unreachable; that.* = this.*; -- cgit v1.2.3