diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/examples/hello_runtime.rs | 1 | ||||
-rw-r--r-- | runtime/inspector_server.rs | 12 | ||||
-rw-r--r-- | runtime/worker.rs | 17 |
3 files changed, 22 insertions, 8 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index d71cc467a..371ecf63f 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -54,6 +54,7 @@ async fn main() -> Result<(), AnyError> { create_web_worker_cb, maybe_inspector_server: None, should_break_on_first_statement: false, + should_wait_for_inspector_session: false, module_loader, npm_resolver: None, get_error_class_fn: Some(&get_error_class_name), diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index f29eec2e2..0423bbdce 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -67,7 +67,7 @@ impl InspectorServer { &self, module_url: String, js_runtime: &mut JsRuntime, - should_break_on_first_statement: bool, + wait_for_session: bool, ) { let inspector_rc = js_runtime.inspector(); let mut inspector = inspector_rc.borrow_mut(); @@ -78,7 +78,7 @@ impl InspectorServer { session_sender, deregister_rx, module_url, - should_break_on_first_statement, + wait_for_session, ); self.register_inspector_tx.unbounded_send(info).unwrap(); } @@ -233,7 +233,7 @@ async fn server( info.get_websocket_debugger_url() ); eprintln!("Visit chrome://inspect to connect to the debugger."); - if info.should_break_on_first_statement { + if info.wait_for_session { eprintln!("Deno is waiting for debugger to connect."); } if inspector_map.borrow_mut().insert(info.uuid, info).is_some() { @@ -370,7 +370,7 @@ pub struct InspectorInfo { pub new_session_tx: UnboundedSender<InspectorSessionProxy>, pub deregister_rx: oneshot::Receiver<()>, pub url: String, - pub should_break_on_first_statement: bool, + pub wait_for_session: bool, } impl InspectorInfo { @@ -379,7 +379,7 @@ impl InspectorInfo { new_session_tx: mpsc::UnboundedSender<InspectorSessionProxy>, deregister_rx: oneshot::Receiver<()>, url: String, - should_break_on_first_statement: bool, + wait_for_session: bool, ) -> Self { Self { host, @@ -388,7 +388,7 @@ impl InspectorInfo { new_session_tx, deregister_rx, url, - should_break_on_first_statement, + wait_for_session, } } diff --git a/runtime/worker.rs b/runtime/worker.rs index 01498e1f6..b184ac3fa 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -62,6 +62,7 @@ impl ExitCode { pub struct MainWorker { pub js_runtime: JsRuntime, should_break_on_first_statement: bool, + should_wait_for_inspector_session: bool, exit_code: ExitCode, } @@ -81,7 +82,13 @@ pub struct WorkerOptions { pub format_js_error_fn: Option<Arc<FormatJsErrorFn>>, pub source_map_getter: Option<Box<dyn SourceMapGetter>>, pub maybe_inspector_server: Option<Arc<InspectorServer>>, + // If true, the worker will wait for inspector session and break on first + // statement of user code. Takes higher precedence than + // `should_wait_for_inspector_session`. pub should_break_on_first_statement: bool, + // If true, the worker will wait for inspector session before executing + // user code. + pub should_wait_for_inspector_session: bool, pub get_error_class_fn: Option<GetErrorClassFn>, pub cache_storage_dir: Option<std::path::PathBuf>, pub origin_storage_dir: Option<std::path::PathBuf>, @@ -108,6 +115,7 @@ impl Default for WorkerOptions { seed: None, unsafely_ignore_certificate_errors: Default::default(), should_break_on_first_statement: Default::default(), + should_wait_for_inspector_session: Default::default(), compiled_wasm_module_store: Default::default(), shared_array_buffer_store: Default::default(), maybe_inspector_server: Default::default(), @@ -248,7 +256,8 @@ impl MainWorker { server.register_inspector( main_module.to_string(), &mut js_runtime, - options.should_break_on_first_statement, + options.should_break_on_first_statement + || options.should_wait_for_inspector_session, ); // Put inspector handle into the op state so we can put a breakpoint when @@ -261,6 +270,8 @@ impl MainWorker { Self { js_runtime, should_break_on_first_statement: options.should_break_on_first_statement, + should_wait_for_inspector_session: options + .should_wait_for_inspector_session, exit_code, } } @@ -355,7 +366,9 @@ impl MainWorker { .js_runtime .inspector() .borrow_mut() - .wait_for_session_and_break_on_next_statement() + .wait_for_session_and_break_on_next_statement(); + } else if self.should_wait_for_inspector_session { + self.js_runtime.inspector().borrow_mut().wait_for_session(); } } |