diff options
Diffstat (limited to 'cli/worker.rs')
-rw-r--r-- | cli/worker.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index 6593ade0b..994f22f04 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -97,6 +97,7 @@ pub struct Worker { pub waker: AtomicWaker, pub(crate) internal_channels: WorkerChannelsInternal, external_channels: WorkerHandle, + inspector: Option<Box<crate::inspector::DenoInspector>>, } impl Worker { @@ -104,9 +105,15 @@ impl Worker { let loader = Rc::new(state.clone()); let mut isolate = deno_core::EsIsolate::new(loader, startup_data, false); - let global_state_ = state.borrow().global_state.clone(); + let global_state = state.borrow().global_state.clone(); + + let inspector = global_state + .inspector_server + .as_ref() + .map(|s| s.add_inspector(&mut *isolate)); + isolate.set_js_error_create_fn(move |core_js_error| { - JSError::create(core_js_error, &global_state_.ts_compiler) + JSError::create(core_js_error, &global_state.ts_compiler) }); let (internal_channels, external_channels) = create_channels(); @@ -118,6 +125,7 @@ impl Worker { waker: AtomicWaker::new(), internal_channels, external_channels, + inspector, } } @@ -175,11 +183,23 @@ impl Worker { } } +impl Drop for Worker { + fn drop(&mut self) { + // The Isolate object must outlive the Inspector object, but this is + // currently not enforced by the type system. + self.inspector.take(); + } +} + impl Future for Worker { type Output = Result<(), ErrBox>; fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { let inner = self.get_mut(); + if let Some(deno_inspector) = inner.inspector.as_mut() { + // We always poll the inspector if it exists. + let _ = deno_inspector.poll_unpin(cx); + } inner.waker.register(cx.waker()); inner.isolate.poll_unpin(cx) } |