From e9edd7e14d9d78f03c5f2e67fcc44e4dbaab8f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 26 May 2021 17:47:33 +0200 Subject: refactor: Rewrite Inspector implementation (#10725) This commit refactors implementation of inspector. The intention is to be able to move inspector implementation to "deno_core". Following things were done to make that possible: * "runtime/inspector.rs" was split into "runtime/inspector/mod.rs" and "runtime/inspector/server.rs", separating inspector implementation from Websocket server implementation. * "DenoInspector" was renamed to "JsRuntimeInspector" and reference to "server" was removed from the structure, making it independent of Websocket server used to connect to Chrome Devtools. * "WebsocketSession" was renamed to "InspectorSession" and rewritten in such a way that it's not tied to Websockets anymore; instead it accepts a pair of "proxy" channel ends that allow to integrate the session with different "transports". * "InspectorSession" was renamed to "LocalInspectorSession" to better indicate that it's an "in-memory" session and doesn't require Websocket server. It was also rewritten in such a way that it uses "InspectorSession" from previous point instead of reimplementing "v8::inspector::ChannelImpl" trait; this is done by using the "proxy" channels to communicate with the V8 session. Consequently "LocalInspectorSession" is now a frontend to "InspectorSession". This introduces a small inconvenience that awaiting responses for "LocalInspectorSession" requires to concurrently poll worker's event loop. This arises from the fact that "InspectorSession" is now owned by "JsRuntimeInspector", which in turn is owned by "Worker" or "WebWorker". To ease this situation "Worker::with_event_loop" helper method was added, that takes a future and concurrently polls it along with the event loop (using "tokio::select!" macro inside a loop). --- cli/tools/coverage.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'cli/tools/coverage.rs') diff --git a/cli/tools/coverage.rs b/cli/tools/coverage.rs index 23b4a4fb6..204141b25 100644 --- a/cli/tools/coverage.rs +++ b/cli/tools/coverage.rs @@ -13,7 +13,7 @@ use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::url::Url; -use deno_runtime::inspector::InspectorSession; +use deno_runtime::inspector::LocalInspectorSession; use deno_runtime::permissions::Permissions; use regex::Regex; use serde::Deserialize; @@ -26,18 +26,17 @@ use uuid::Uuid; pub struct CoverageCollector { pub dir: PathBuf, - session: Box, + session: LocalInspectorSession, } impl CoverageCollector { - pub fn new(dir: PathBuf, session: Box) -> Self { + pub fn new(dir: PathBuf, session: LocalInspectorSession) -> Self { Self { dir, session } } pub async fn start_collecting(&mut self) -> Result<(), AnyError> { self.session.post_message("Debugger.enable", None).await?; self.session.post_message("Profiler.enable", None).await?; - self .session .post_message( @@ -45,7 +44,6 @@ impl CoverageCollector { Some(json!({"callCount": true, "detailed": true})), ) .await?; - Ok(()) } -- cgit v1.2.3