aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
m---------src/bun.js/WebKit0
-rw-r--r--src/bun.js/bindings/BunDebugger.cpp41
-rw-r--r--src/bun.js/javascript.zig6
-rw-r--r--src/bun.js/module_loader.zig2
4 files changed, 39 insertions, 10 deletions
diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit
-Subproject fc705595a2e10361a64f1dab56527d7b112e75c
+Subproject fd79ce3120a692f4aed314c3da3dd452b4aa865
diff --git a/src/bun.js/bindings/BunDebugger.cpp b/src/bun.js/bindings/BunDebugger.cpp
index 41001a8f2..440a5125b 100644
--- a/src/bun.js/bindings/BunDebugger.cpp
+++ b/src/bun.js/bindings/BunDebugger.cpp
@@ -23,14 +23,40 @@ static WebCore::ScriptExecutionContext* debuggerScriptExecutionContext = nullptr
static WTF::Lock inspectorConnectionsLock = WTF::Lock();
static WTF::HashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>* inspectorConnections = nullptr;
+static bool waitingForConnection = false;
+extern "C" void Debugger__didConnect();
+
+class BunJSGlobalObjectDebuggable final : public JSC::JSGlobalObjectDebuggable {
+public:
+ using Base = JSC::JSGlobalObjectDebuggable;
+
+ BunJSGlobalObjectDebuggable(JSC::JSGlobalObject& globalObject)
+ : Base(globalObject)
+ {
+ }
+
+ ~BunJSGlobalObjectDebuggable() final
+ {
+ }
+
+ void pauseWaitingForAutomaticInspection() override
+ {
+ }
+ void unpauseForInitializedInspector() override
+ {
+ if (waitingForConnection) {
+ waitingForConnection = false;
+ Debugger__didConnect();
+ }
+ }
+};
+
enum class ConnectionStatus : int32_t {
Pending = 0,
Connected = 1,
Disconnecting = 2,
Disconnected = 3,
};
-static bool waitingForConnection = false;
-extern "C" void Debugger__didConnect();
class BunInspectorConnection : public Inspector::FrontendChannel {
@@ -81,15 +107,9 @@ public:
Bun__eventLoop__incrementRefConcurrently(reinterpret_cast<Zig::GlobalObject*>(globalObject)->bunVM(), 1);
}
globalObject->setInspectable(true);
-
auto& inspector = globalObject->inspectorDebuggable();
inspector.setInspectable(true);
-
- inspector.connect(*connection);
- if (waitingForConnection) {
- waitingForConnection = false;
- Debugger__didConnect();
- }
+ globalObject->inspectorController().connectFrontend(*connection, true, waitingForConnection);
Inspector::JSGlobalObjectDebugger* debugger = reinterpret_cast<Inspector::JSGlobalObjectDebugger*>(globalObject->debugger());
if (debugger) {
@@ -99,7 +119,6 @@ public:
}
connection->receiveMessagesOnInspectorThread(context, reinterpret_cast<Zig::GlobalObject*>(globalObject));
-
break;
}
default: {
@@ -415,6 +434,8 @@ extern "C" void Bun__ensureDebugger(ScriptExecutionContextIdentifier scriptId, b
auto* globalObject = ScriptExecutionContext::getScriptExecutionContext(scriptId)->jsGlobalObject();
globalObject->m_inspectorController = makeUnique<Inspector::JSGlobalObjectInspectorController>(*globalObject, Bun::BunInjectedScriptHost::create());
+ globalObject->m_inspectorDebuggable = makeUnique<BunJSGlobalObjectDebuggable>(*globalObject);
+
globalObject->setInspectable(true);
auto& inspector = globalObject->inspectorDebuggable();
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 98e61f3b0..07d3f64cf 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -748,6 +748,8 @@ pub const VirtualMachine = struct {
next_debugger_id: u64 = 1,
poll_ref: JSC.PollRef = .{},
wait_for_connection: bool = false,
+ set_breakpoint_on_first_line: bool = false,
+
const debug = Output.scoped(.DEBUGGER, false);
extern "C" fn Bun__createJSDebugger(*JSC.JSGlobalObject) u32;
@@ -784,6 +786,8 @@ pub const VirtualMachine = struct {
Bun__ensureDebugger(debugger.script_execution_context_id, debugger.wait_for_connection);
while (debugger.wait_for_connection) {
this.eventLoop().tick();
+ if (debugger.wait_for_connection)
+ this.eventLoop().autoTickActive();
}
}
@@ -1136,6 +1140,7 @@ pub const VirtualMachine = struct {
this.debugger = Debugger{
.path_or_port = debugger.enable.path_or_port,
.wait_for_connection = debugger.enable.wait_for_connection,
+ .set_breakpoint_on_first_line = debugger.enable.set_breakpoint_on_first_line,
};
},
}
@@ -1870,6 +1875,7 @@ pub const VirtualMachine = struct {
pub fn reloadEntryPoint(this: *VirtualMachine, entry_path: []const u8) !*JSInternalPromise {
this.has_loaded = false;
this.main = entry_path;
+ this.main_hash = bun.JSC.Watcher.getHash(entry_path);
try this.entry_point.generate(
this.allocator,
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index be10b9722..dfb9077e2 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -403,6 +403,7 @@ pub const RuntimeTranspilerStore = struct {
vm.main.len == path.text.len and
vm.main_hash == hash and
strings.eqlLong(vm.main, path.text, false),
+ .set_breakpoint_on_first_line = vm.debugger != null and vm.debugger.?.set_breakpoint_on_first_line and strings.eqlLong(vm.main, path.text, false),
};
defer {
@@ -1439,6 +1440,7 @@ pub const ModuleLoader = struct {
.dont_bundle_twice = true,
.allow_commonjs = true,
.inject_jest_globals = jsc_vm.bundler.options.rewrite_jest_for_tests and is_main,
+ .set_breakpoint_on_first_line = is_main and jsc_vm.debugger != null and jsc_vm.debugger.?.set_breakpoint_on_first_line,
};
defer {
if (should_close_input_file_fd and input_file_fd != 0) {