Skip to content

Commit df891d4

Browse files
committed
lint
1 parent 642c2b0 commit df891d4

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

core/inspector.rs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ use parking_lot::Mutex;
2222
use std::cell::RefCell;
2323
use std::collections::HashMap;
2424
use std::ffi::c_void;
25-
use std::mem::MaybeUninit;
2625
use std::mem::take;
2726
use std::pin::Pin;
28-
use std::ptr;
2927
use std::ptr::NonNull;
3028
use std::rc::Rc;
3129
use std::sync::Arc;
@@ -190,10 +188,14 @@ impl JsRuntimeInspectorState {
190188
loop {
191189
loop {
192190
// Do one "handshake" with a newly connected session at a time.
193-
if let Some(mut session) = sessions.handshake.take() {
194-
let mut fut = pump_inspector_session_messages(session).boxed_local();
191+
if let Some(session) = sessions.handshake.take() {
192+
let mut fut =
193+
pump_inspector_session_messages(session.clone()).boxed_local();
195194
let _ = fut.poll_unpin(cx);
196195
sessions.established.push(fut);
196+
let id = sessions.next_local_id;
197+
sessions.next_local_id += 1;
198+
sessions.local.insert(id, session);
197199
continue;
198200
}
199201

@@ -533,18 +535,16 @@ impl SessionContainer {
533535
has_active: !self.established.is_empty()
534536
|| self.handshake.is_some()
535537
|| !self.local.is_empty(),
536-
has_blocking: self.local.values().any(|s| {
537-
matches!(s.state.borrow().kind, InspectorSessionKind::Blocking)
538-
}),
538+
has_blocking: self
539+
.local
540+
.values()
541+
.any(|s| matches!(s.state.kind, InspectorSessionKind::Blocking)),
539542
has_nonblocking: self.local.values().any(|s| {
540-
matches!(
541-
s.state.borrow().kind,
542-
InspectorSessionKind::NonBlocking { .. }
543-
)
543+
matches!(s.state.kind, InspectorSessionKind::NonBlocking { .. })
544544
}),
545545
has_nonblocking_wait_for_disconnect: self.local.values().any(|s| {
546546
matches!(
547-
s.state.borrow().kind,
547+
s.state.kind,
548548
InspectorSessionKind::NonBlocking {
549549
wait_for_disconnect: true
550550
}
@@ -655,31 +655,27 @@ impl task::ArcWake for InspectorWaker {
655655
}
656656
}
657657

658-
#[derive(Debug)]
658+
#[derive(Clone, Copy, Debug)]
659659
pub enum InspectorSessionKind {
660660
Blocking,
661661
NonBlocking { wait_for_disconnect: bool },
662662
}
663663

664+
#[derive(Clone)]
664665
struct InspectorSessionState {
665666
is_dispatching_message: Rc<RefCell<bool>>,
666-
send: InspectorSessionSend,
667-
rx: Option<SessionProxyReceiver>,
667+
send: Rc<InspectorSessionSend>,
668+
rx: Rc<RefCell<Option<SessionProxyReceiver>>>,
668669
// Describes if session should keep event loop alive, eg. a local REPL
669670
// session should keep event loop alive, but a Websocket session shouldn't.
670671
kind: InspectorSessionKind,
671672
}
672673

673-
#[derive(Clone)]
674-
struct InspectorSessionInner {
675-
state: Rc<RefCell<InspectorSessionState>>,
676-
}
677-
678674
/// An inspector session that proxies messages to concrete "transport layer",
679675
/// eg. Websocket or another set of channels.
680676
struct InspectorSession {
681677
v8_session: v8::inspector::V8InspectorSession,
682-
state: Rc<RefCell<InspectorSessionState>>,
678+
state: InspectorSessionState,
683679
}
684680

685681
impl InspectorSession {
@@ -694,33 +690,27 @@ impl InspectorSession {
694690
) -> Rc<Self> {
695691
let state = InspectorSessionState {
696692
is_dispatching_message,
697-
send,
698-
rx,
693+
send: Rc::new(send),
694+
rx: Rc::new(RefCell::new(rx)),
699695
kind: options.kind,
700696
};
701-
let inner = InspectorSessionInner {
702-
state: Rc::new(RefCell::new(state)),
703-
};
704697

705698
let v8_session = v8_inspector.connect(
706699
Self::CONTEXT_GROUP_ID,
707-
v8::inspector::Channel::new(Box::new(inner.clone())),
700+
v8::inspector::Channel::new(Box::new(state.clone())),
708701
v8::inspector::StringView::empty(),
709702
v8::inspector::V8InspectorClientTrustLevel::FullyTrusted,
710703
);
711704

712-
Rc::new(Self {
713-
v8_session,
714-
state: inner.state.clone(),
715-
})
705+
Rc::new(Self { v8_session, state })
716706
}
717707

718708
// Dispatch message to V8 session
719709
fn dispatch_message(&self, msg: String) {
720-
*self.state.borrow().is_dispatching_message.borrow_mut() = true;
710+
*self.state.is_dispatching_message.borrow_mut() = true;
721711
let msg = v8::inspector::StringView::from(msg.as_bytes());
722712
self.v8_session.dispatch_protocol_message(msg);
723-
*self.state.borrow().is_dispatching_message.borrow_mut() = false;
713+
*self.state.is_dispatching_message.borrow_mut() = false;
724714
}
725715

726716
pub fn break_on_next_statement(&self) {
@@ -732,21 +722,21 @@ impl InspectorSession {
732722
}
733723
}
734724

735-
impl InspectorSessionInner {
725+
impl InspectorSessionState {
736726
fn send_message(
737727
&self,
738728
msg_kind: InspectorMsgKind,
739729
msg: v8::UniquePtr<v8::inspector::StringBuffer>,
740730
) {
741731
let msg = msg.unwrap().string().to_string();
742-
(self.state.borrow().send)(InspectorMsg {
732+
(self.send)(InspectorMsg {
743733
kind: msg_kind,
744734
content: msg,
745735
});
746736
}
747737
}
748738

749-
impl v8::inspector::ChannelImpl for InspectorSessionInner {
739+
impl v8::inspector::ChannelImpl for InspectorSessionState {
750740
fn send_response(
751741
&self,
752742
call_id: i32,
@@ -768,7 +758,7 @@ impl v8::inspector::ChannelImpl for InspectorSessionInner {
768758
type InspectorSessionPumpMessages = Pin<Box<dyn Future<Output = ()>>>;
769759

770760
async fn pump_inspector_session_messages(session: Rc<InspectorSession>) {
771-
let mut rx = session.state.borrow_mut().rx.take().unwrap();
761+
let mut rx = session.state.rx.borrow_mut().take().unwrap();
772762
while let Some(msg) = rx.next().await {
773763
session.dispatch_message(msg);
774764
}

0 commit comments

Comments
 (0)