@@ -85,7 +85,7 @@ pub struct JsRuntimeInspector {
85
85
v8_inspector_client : v8:: inspector:: V8InspectorClientBase ,
86
86
v8_inspector : Rc < RefCell < v8:: UniquePtr < v8:: inspector:: V8Inspector > > > ,
87
87
new_session_tx : UnboundedSender < InspectorSessionProxy > ,
88
- sessions : RefCell < SessionContainer > ,
88
+ sessions : Rc < RefCell < SessionContainer > > ,
89
89
flags : RefCell < InspectorFlags > ,
90
90
waker : Arc < InspectorWaker > ,
91
91
deregister_tx : Option < oneshot:: Sender < ( ) > > ,
@@ -194,7 +194,9 @@ impl JsRuntimeInspector {
194
194
let self__ = Rc :: new ( RefCell :: new ( Self {
195
195
v8_inspector_client,
196
196
v8_inspector : Default :: default ( ) ,
197
- sessions : RefCell :: new ( SessionContainer :: temporary_placeholder ( ) ) ,
197
+ sessions : Rc :: new (
198
+ RefCell :: new ( SessionContainer :: temporary_placeholder ( ) ) ,
199
+ ) ,
198
200
new_session_tx,
199
201
flags : Default :: default ( ) ,
200
202
waker,
@@ -207,10 +209,10 @@ impl JsRuntimeInspector {
207
209
self_. v8_inspector = Rc :: new ( RefCell :: new (
208
210
v8:: inspector:: V8Inspector :: create ( scope, & mut * self_) . into ( ) ,
209
211
) ) ;
210
- self_. sessions = RefCell :: new ( SessionContainer :: new (
212
+ self_. sessions = Rc :: new ( RefCell :: new ( SessionContainer :: new (
211
213
self_. v8_inspector . clone ( ) ,
212
214
new_session_rx,
213
- ) ) ;
215
+ ) ) ) ;
214
216
215
217
// Tell the inspector about the main realm.
216
218
let context_name = v8:: inspector:: StringView :: from ( & b"main realm" [ ..] ) ;
@@ -247,16 +249,6 @@ impl JsRuntimeInspector {
247
249
* self . is_dispatching_message . borrow ( )
248
250
}
249
251
250
- pub fn dispatch_message_from_frontend (
251
- & self ,
252
- session_id : i32 ,
253
- message : String ,
254
- ) {
255
- let mut sessions = self . sessions . borrow_mut ( ) ;
256
- let session = sessions. local . get_mut ( & session_id) . unwrap ( ) ;
257
- session. dispatch_message ( message) ;
258
- }
259
-
260
252
pub fn context_destroyed (
261
253
& mut self ,
262
254
scope : & mut HandleScope ,
@@ -424,16 +416,15 @@ impl JsRuntimeInspector {
424
416
/// established a websocket connection.
425
417
pub fn wait_for_session ( & mut self ) {
426
418
loop {
427
- match self . sessions . get_mut ( ) . established . iter_mut ( ) . next ( ) {
428
- Some ( _session) => {
429
- self . flags . get_mut ( ) . waiting_for_session = false ;
430
- break ;
431
- }
432
- None => {
433
- self . flags . get_mut ( ) . waiting_for_session = true ;
434
- let _ = self . poll_sessions ( None ) . unwrap ( ) ;
435
- }
436
- } ;
419
+ if let Some ( _session) =
420
+ self . sessions . borrow_mut ( ) . established . iter_mut ( ) . next ( )
421
+ {
422
+ self . flags . get_mut ( ) . waiting_for_session = false ;
423
+ break ;
424
+ } else {
425
+ self . flags . get_mut ( ) . waiting_for_session = true ;
426
+ let _ = self . poll_sessions ( None ) . unwrap ( ) ;
427
+ }
437
428
}
438
429
}
439
430
@@ -445,13 +436,14 @@ impl JsRuntimeInspector {
445
436
/// execution.
446
437
pub fn wait_for_session_and_break_on_next_statement ( & mut self ) {
447
438
loop {
448
- match self . sessions . get_mut ( ) . established . iter_mut ( ) . next ( ) {
449
- Some ( session) => break session. break_on_next_statement ( ) ,
450
- None => {
451
- self . flags . get_mut ( ) . waiting_for_session = true ;
452
- let _ = self . poll_sessions ( None ) . unwrap ( ) ;
453
- }
454
- } ;
439
+ if let Some ( session) =
440
+ self . sessions . borrow_mut ( ) . established . iter_mut ( ) . next ( )
441
+ {
442
+ break session. break_on_next_statement ( ) ;
443
+ } else {
444
+ self . flags . get_mut ( ) . waiting_for_session = true ;
445
+ let _ = self . poll_sessions ( None ) . unwrap ( ) ;
446
+ }
455
447
}
456
448
}
457
449
@@ -478,7 +470,7 @@ impl JsRuntimeInspector {
478
470
callback : InspectorSessionSend ,
479
471
options : InspectorSessionOptions ,
480
472
) -> LocalInspectorSession {
481
- let session_id = {
473
+ let ( session_id, sessions ) = {
482
474
let self_ = inspector. borrow_mut ( ) ;
483
475
484
476
let inspector_session = InspectorSession :: new (
@@ -498,10 +490,10 @@ impl JsRuntimeInspector {
498
490
} ;
499
491
500
492
take ( & mut self_. flags . borrow_mut ( ) . waiting_for_session ) ;
501
- session_id
493
+ ( session_id, self_ . sessions . clone ( ) )
502
494
} ;
503
495
504
- LocalInspectorSession :: new ( session_id, inspector )
496
+ LocalInspectorSession :: new ( session_id, sessions )
505
497
}
506
498
}
507
499
@@ -606,6 +598,15 @@ impl SessionContainer {
606
598
local : HashMap :: new ( ) ,
607
599
}
608
600
}
601
+
602
+ pub fn dispatch_message_from_frontend (
603
+ & mut self ,
604
+ session_id : i32 ,
605
+ message : String ,
606
+ ) {
607
+ let session = self . local . get_mut ( & session_id) . unwrap ( ) ;
608
+ session. dispatch_message ( message) ;
609
+ }
609
610
}
610
611
611
612
struct InspectorWakerInner {
@@ -857,24 +858,21 @@ impl InspectorPostMessageError {
857
858
///
858
859
/// Does not provide any abstraction over CDP messages.
859
860
pub struct LocalInspectorSession {
860
- inspector : Rc < RefCell < JsRuntimeInspector > > ,
861
+ sessions : Rc < RefCell < SessionContainer > > ,
861
862
session_id : i32 ,
862
863
}
863
864
864
865
impl LocalInspectorSession {
865
- pub fn new (
866
- session_id : i32 ,
867
- inspector : Rc < RefCell < JsRuntimeInspector > > ,
868
- ) -> Self {
866
+ pub fn new ( session_id : i32 , sessions : Rc < RefCell < SessionContainer > > ) -> Self {
869
867
Self {
870
- inspector ,
868
+ sessions ,
871
869
session_id,
872
870
}
873
871
}
874
872
875
873
pub fn dispatch ( & mut self , msg : String ) {
876
874
self
877
- . inspector
875
+ . sessions
878
876
. borrow_mut ( )
879
877
. dispatch_message_from_frontend ( self . session_id , msg) ;
880
878
}
0 commit comments