@@ -11,10 +11,13 @@ use cooked_waker::WakeRef;
11
11
use deno_error:: JsErrorBox ;
12
12
use parking_lot:: Mutex ;
13
13
use rstest:: rstest;
14
+ use serde_json:: Value ;
15
+ use serde_json:: json;
14
16
use std:: borrow:: Cow ;
15
17
use std:: collections:: HashMap ;
16
18
use std:: collections:: HashSet ;
17
19
use std:: future:: poll_fn;
20
+ use std:: pin:: pin;
18
21
use std:: rc:: Rc ;
19
22
use std:: sync:: Arc ;
20
23
use std:: sync:: atomic:: AtomicBool ;
@@ -437,6 +440,66 @@ fn inspector() {
437
440
runtime. execute_script ( "check.js" , "null" ) . unwrap ( ) ;
438
441
}
439
442
443
+ #[ rstest]
444
+ // https://github.com/denoland/deno/issues/29059
445
+ #[ case( 0.9999999999999999 ) ]
446
+ #[ case( 31.245270191439438 ) ]
447
+ #[ case( 117.63331139400017 ) ]
448
+ #[ tokio:: test]
449
+ async fn test_preserve_float_precision_from_local_inspector_evaluate (
450
+ #[ case] input : f64 ,
451
+ ) {
452
+ let mut runtime = JsRuntime :: new ( RuntimeOptions {
453
+ inspector : true ,
454
+ ..Default :: default ( )
455
+ } ) ;
456
+
457
+ let result = local_inspector_evaluate ( & mut runtime, & format ! ( "{}" , input) )
458
+ . await
459
+ . unwrap ( ) ;
460
+
461
+ assert_eq ! (
462
+ result[ "result" ] [ "value" ] ,
463
+ Value :: Number ( serde_json:: Number :: from_f64( input) . unwrap( ) ) ,
464
+ ) ;
465
+ }
466
+
467
+ async fn local_inspector_evaluate (
468
+ runtime : & mut JsRuntime ,
469
+ expression : & str ,
470
+ ) -> Result < Value , CoreError > {
471
+ let session_options = inspector:: InspectorSessionOptions {
472
+ kind : inspector:: InspectorSessionKind :: NonBlocking {
473
+ wait_for_disconnect : true ,
474
+ } ,
475
+ } ;
476
+
477
+ let mut local_inspector_session = runtime
478
+ . inspector ( )
479
+ . borrow ( )
480
+ . create_local_session ( session_options) ;
481
+
482
+ let post_message_future = pin ! ( local_inspector_session. post_message(
483
+ "Runtime.evaluate" ,
484
+ Some ( json!( {
485
+ "expression" : expression,
486
+ } ) ) ,
487
+ ) ) ;
488
+
489
+ // https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
490
+ let remote_object_result = runtime
491
+ . with_event_loop_future (
492
+ post_message_future,
493
+ PollEventLoopOptions {
494
+ pump_v8_message_loop : false ,
495
+ ..Default :: default ( )
496
+ } ,
497
+ )
498
+ . await ?;
499
+
500
+ Ok ( remote_object_result)
501
+ }
502
+
440
503
#[ test]
441
504
fn test_get_module_namespace ( ) {
442
505
let mut runtime = JsRuntime :: new ( RuntimeOptions {
0 commit comments