Skip to content

Commit b0de620

Browse files
authored
feat: remove unneeded inspector types (#1206)
This commit removes following types: - InspectorPortMessageError - InspectorPortMessageErrorKind - InspectorSessionOptions These are not really used anymore and can be removed to simplify the implementation. Pulls out some code from #1198
1 parent a53c8bd commit b0de620

File tree

4 files changed

+12
-61
lines changed

4 files changed

+12
-61
lines changed

core/inspector.rs

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//! <https://chromedevtools.github.io/devtools-protocol/>
55
//! <https://hyperandroid.com/2020/02/12/v8-inspector-from-an-embedder-standpoint/>
66
7-
use crate::error::CoreError;
8-
use crate::error::CoreErrorKind;
97
use crate::futures::channel::mpsc;
108
use crate::futures::channel::mpsc::UnboundedReceiver;
119
use crate::futures::channel::mpsc::UnboundedSender;
@@ -16,8 +14,6 @@ use crate::futures::stream::StreamExt;
1614
use crate::futures::task;
1715
use crate::serde_json::json;
1816

19-
use boxed_error::Boxed;
20-
use deno_error::JsErrorBox;
2117
use parking_lot::Mutex;
2218
use std::cell::RefCell;
2319
use std::collections::HashMap;
@@ -30,7 +26,6 @@ use std::sync::Arc;
3026
use std::task::Context;
3127
use std::task::Poll;
3228
use std::thread;
33-
use thiserror::Error;
3429

3530
#[derive(Debug)]
3631
pub enum InspectorMsgKind {
@@ -54,7 +49,7 @@ pub type SessionProxyReceiver = UnboundedReceiver<String>;
5449
pub struct InspectorSessionProxy {
5550
pub tx: SessionProxySender,
5651
pub rx: SessionProxyReceiver,
57-
pub options: InspectorSessionOptions,
52+
pub kind: InspectorSessionKind,
5853
}
5954

6055
pub type InspectorSessionSend = Box<dyn Fn(InspectorMsg)>;
@@ -213,7 +208,7 @@ impl JsRuntimeInspectorState {
213208
let _ = session_proxy.tx.unbounded_send(msg);
214209
}),
215210
Some(session_proxy.rx),
216-
session_proxy.options,
211+
session_proxy.kind,
217212
);
218213
let prev = sessions.handshake.replace(session);
219214
assert!(prev.is_none());
@@ -453,7 +448,7 @@ impl JsRuntimeInspector {
453448
pub fn create_local_session(
454449
inspector: Rc<JsRuntimeInspector>,
455450
callback: InspectorSessionSend,
456-
options: InspectorSessionOptions,
451+
kind: InspectorSessionKind,
457452
) -> LocalInspectorSession {
458453
let (session_id, sessions) = {
459454
let sessions = inspector.state.sessions.clone();
@@ -463,7 +458,7 @@ impl JsRuntimeInspector {
463458
inspector.state.is_dispatching_message.clone(),
464459
callback,
465460
None,
466-
options,
461+
kind,
467462
);
468463

469464
let session_id = {
@@ -482,11 +477,6 @@ impl JsRuntimeInspector {
482477
}
483478
}
484479

485-
#[derive(Debug)]
486-
pub struct InspectorSessionOptions {
487-
pub kind: InspectorSessionKind,
488-
}
489-
490480
#[derive(Default)]
491481
struct InspectorFlags {
492482
waiting_for_session: bool,
@@ -694,13 +684,13 @@ impl InspectorSession {
694684
is_dispatching_message: Rc<RefCell<bool>>,
695685
send: InspectorSessionSend,
696686
rx: Option<SessionProxyReceiver>,
697-
options: InspectorSessionOptions,
687+
kind: InspectorSessionKind,
698688
) -> Rc<Self> {
699689
let state = InspectorSessionState {
700690
is_dispatching_message,
701691
send: Rc::new(send),
702692
rx: Rc::new(RefCell::new(rx)),
703-
kind: options.kind,
693+
kind,
704694
};
705695

706696
let v8_session = v8_inspector.connect(
@@ -772,34 +762,6 @@ async fn pump_inspector_session_messages(session: Rc<InspectorSession>) {
772762
}
773763
}
774764

775-
#[derive(Debug, Boxed)]
776-
pub struct InspectorPostMessageError(pub Box<InspectorPostMessageErrorKind>);
777-
778-
#[derive(Debug, Error)]
779-
pub enum InspectorPostMessageErrorKind {
780-
#[error(transparent)]
781-
JsBox(#[from] JsErrorBox),
782-
#[error(transparent)]
783-
FutureCanceled(futures::channel::oneshot::Canceled),
784-
}
785-
786-
impl From<InspectorPostMessageError> for CoreError {
787-
fn from(value: InspectorPostMessageError) -> Self {
788-
CoreErrorKind::JsBox(value.into_js_error_box()).into_box()
789-
}
790-
}
791-
792-
impl InspectorPostMessageError {
793-
pub fn into_js_error_box(self) -> JsErrorBox {
794-
match self.into_kind() {
795-
InspectorPostMessageErrorKind::JsBox(e) => e,
796-
InspectorPostMessageErrorKind::FutureCanceled(e) => {
797-
JsErrorBox::generic(e.to_string())
798-
}
799-
}
800-
}
801-
}
802-
803765
/// A local inspector session that can be used to send and receive protocol messages directly on
804766
/// the same thread as an isolate.
805767
///

core/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ pub use crate::fast_string::FastStringV8AllocationError;
8686
pub use crate::flags::v8_set_flags;
8787
pub use crate::inspector::InspectorMsg;
8888
pub use crate::inspector::InspectorMsgKind;
89-
pub use crate::inspector::InspectorPostMessageError;
90-
pub use crate::inspector::InspectorPostMessageErrorKind;
9189
pub use crate::inspector::InspectorSessionKind;
92-
pub use crate::inspector::InspectorSessionOptions;
9390
pub use crate::inspector::InspectorSessionProxy;
9491
pub use crate::inspector::InspectorSessionSend;
9592
pub use crate::inspector::JsRuntimeInspector;

core/runtime/tests/misc.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,8 @@ fn local_inspector_evaluate(
466466
runtime: &mut JsRuntime,
467467
expression: &str,
468468
) -> Value {
469-
let session_options = inspector::InspectorSessionOptions {
470-
kind: inspector::InspectorSessionKind::NonBlocking {
471-
wait_for_disconnect: false,
472-
},
469+
let kind = inspector::InspectorSessionKind::NonBlocking {
470+
wait_for_disconnect: false,
473471
};
474472

475473
let inspector = runtime.inspector();
@@ -481,11 +479,8 @@ fn local_inspector_evaluate(
481479
let _ = tx.send(value["result"].clone());
482480
}
483481
});
484-
let mut local_inspector_session = JsRuntimeInspector::create_local_session(
485-
inspector,
486-
callback,
487-
session_options,
488-
);
482+
let mut local_inspector_session =
483+
JsRuntimeInspector::create_local_session(inspector, callback, kind);
489484

490485
local_inspector_session.post_message(
491486
1,

dcore/src/inspector_server.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use core::convert::Infallible as Never;
55
use deno_core::InspectorMsg;
66
use deno_core::InspectorSessionKind;
7-
use deno_core::InspectorSessionOptions;
87
use deno_core::InspectorSessionProxy;
98
use deno_core::JsRuntime;
109
use deno_core::anyhow::Context;
@@ -197,10 +196,8 @@ fn handle_ws_request(
197196
let inspector_session_proxy = InspectorSessionProxy {
198197
tx: outbound_tx,
199198
rx: inbound_rx,
200-
options: InspectorSessionOptions {
201-
kind: InspectorSessionKind::NonBlocking {
202-
wait_for_disconnect: true,
203-
},
199+
kind: InspectorSessionKind::NonBlocking {
200+
wait_for_disconnect: true,
204201
},
205202
};
206203

0 commit comments

Comments
 (0)