5
5
*/
6
6
//! V8-rs is a crate containing bindings to the V8 C++ API.
7
7
8
- #![ warn ( missing_docs) ]
8
+ #![ deny ( missing_docs) ]
9
9
10
10
/// The module contains the rust-idiomatic data structures and functions.
11
11
pub mod v8;
@@ -57,17 +57,13 @@ impl From<UserIndex> for RawIndex {
57
57
mod json_path_tests {
58
58
use crate as v8_rs;
59
59
use crate :: v8:: types:: any:: LocalValueAny ;
60
- use crate :: v8:: types:: native_function:: LocalNativeFunction ;
61
60
use crate :: v8:: types:: native_function_template:: LocalNativeFunctionTemplate ;
62
61
use crate :: v8:: types:: object_template:: LocalObjectTemplate ;
63
62
use crate :: v8:: types:: promise:: LocalPromise ;
64
63
use crate :: v8:: types:: try_catch:: TryCatch ;
65
64
use crate :: v8:: types:: utf8:: LocalUtf8 ;
66
65
use crate :: v8:: types:: Value ;
67
- use crate :: v8:: {
68
- context_scope, isolate, isolate_scope, types, types:: array, types:: array_buffer,
69
- types:: native_function_template, types:: object, types:: set, types:: utf8, v8_init,
70
- } ;
66
+ use crate :: v8:: { context_scope, isolate, isolate_scope, types, v8_init} ;
71
67
72
68
use v8_derive:: new_native_function;
73
69
@@ -199,7 +195,7 @@ mod json_path_tests {
199
195
. create_native_function_template ( |args, isolate_scope, ctx_scope| {
200
196
let foo: LocalValueAny = isolate_scope. create_string ( "foo" ) . try_into ( ) . unwrap ( ) ;
201
197
let v: LocalValueAny = args. get ( 0 ) . try_into ( ) . unwrap ( ) ;
202
- let _res = v. call ( ctx_scope, Some ( & [ & foo. into ( ) ] ) ) ;
198
+ let _res = v. call ( ctx_scope, Some ( & [ & foo] ) ) ;
203
199
None
204
200
} )
205
201
. try_into ( )
@@ -256,7 +252,7 @@ mod json_path_tests {
256
252
let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
257
253
assert ! ( script. run( & ctx_scope) . is_none( ) ) ;
258
254
let exception = trycatch. get_exception ( ) ;
259
- let exception_msg = exception . into_utf8 ( ) . unwrap ( ) ;
255
+ let exception_msg = LocalUtf8 :: try_from ( exception ) . unwrap ( ) ;
260
256
assert_eq ! ( exception_msg. as_str( ) , "this is an error" ) ;
261
257
}
262
258
@@ -275,10 +271,10 @@ mod json_path_tests {
275
271
let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
276
272
assert ! ( script. run( & ctx_scope) . is_none( ) ) ;
277
273
let exception = trycatch. get_exception ( ) ;
278
- let exception_msg = exception . into_utf8 ( ) . unwrap ( ) ;
274
+ let exception_msg = LocalUtf8 :: try_from ( exception ) . unwrap ( ) ;
279
275
assert_eq ! ( exception_msg. as_str( ) , "Error: this is an error!" ) ;
280
276
let trace = trycatch. get_trace ( & ctx_scope) ;
281
- let trace_str = trace. unwrap ( ) . into_utf8 ( ) . unwrap ( ) ;
277
+ let trace_str = LocalUtf8 :: try_from ( trace. unwrap ( ) ) . unwrap ( ) ;
282
278
assert ! ( trace_str. as_str( ) . contains( "at foo" ) ) ;
283
279
}
284
280
@@ -368,7 +364,7 @@ mod json_path_tests {
368
364
crate :: v8:: types:: promise:: PromiseState :: Fulfilled
369
365
) ;
370
366
let promise_res = promise. get_result ( ) ;
371
- let res_utf8 = promise_res . into_utf8 ( ) . unwrap ( ) ;
367
+ let res_utf8 = LocalUtf8 :: try_from ( promise_res ) . unwrap ( ) ;
372
368
assert_eq ! ( res_utf8. as_str( ) , "1" ) ;
373
369
}
374
370
@@ -382,7 +378,7 @@ mod json_path_tests {
382
378
globals. add_native_function ( "foo" , |_args, isolate_scope, ctx_scope| {
383
379
let resolver = ctx_scope. create_resolver ( ) ;
384
380
resolver. resolve (
385
- & ctx_scope,
381
+ ctx_scope,
386
382
& isolate_scope. create_string ( "foo" ) . try_into ( ) . unwrap ( ) ,
387
383
) ;
388
384
let promise = resolver. get_promise ( ) ;
@@ -404,7 +400,7 @@ mod json_path_tests {
404
400
crate :: v8:: types:: promise:: PromiseState :: Fulfilled
405
401
) ;
406
402
let promise_res = promise. get_result ( ) ;
407
- let res_utf8 = promise_res . into_utf8 ( ) . unwrap ( ) ;
403
+ let res_utf8 = LocalUtf8 :: try_from ( promise_res ) . unwrap ( ) ;
408
404
assert_eq ! ( res_utf8. as_str( ) , "foo" ) ;
409
405
}
410
406
@@ -420,7 +416,9 @@ mod json_path_tests {
420
416
let script = ctx_scope. compile ( & code_str) ;
421
417
assert ! ( script. is_none( ) ) ;
422
418
assert_eq ! (
423
- trycatch. get_exception( ) . into_utf8( ) . unwrap( ) . as_str( ) ,
419
+ LocalUtf8 :: try_from( trycatch. get_exception( ) )
420
+ . unwrap( )
421
+ . as_str( ) ,
424
422
"SyntaxError: Unexpected end of input"
425
423
) ;
426
424
}
@@ -438,7 +436,9 @@ mod json_path_tests {
438
436
let res = script. run ( & ctx_scope) ;
439
437
assert ! ( res. is_none( ) ) ;
440
438
assert_eq ! (
441
- trycatch. get_exception( ) . into_utf8( ) . unwrap( ) . as_str( ) ,
439
+ LocalUtf8 :: try_from( trycatch. get_exception( ) )
440
+ . unwrap( )
441
+ . as_str( ) ,
442
442
"ReferenceError: foo is not defined"
443
443
) ;
444
444
}
@@ -472,9 +472,7 @@ mod json_path_tests {
472
472
let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
473
473
let res = match script. run ( & ctx_scope) {
474
474
Some ( _res) => Ok ( ( ) ) ,
475
- None => Err ( trycatch
476
- . get_exception ( )
477
- . into_utf8 ( )
475
+ None => Err ( LocalUtf8 :: try_from ( trycatch. get_exception ( ) )
478
476
. unwrap ( )
479
477
. as_str ( )
480
478
. to_string ( ) ) ,
@@ -485,11 +483,7 @@ mod json_path_tests {
485
483
#[ test]
486
484
fn test_value_is_object ( ) {
487
485
define_function_and_call ( "foo({})" , "foo" , |args, _isolate, _ctx_scope| {
488
- if let Value :: Object ( _) = args. get ( 0 ) {
489
- assert ! ( true ) ;
490
- } else {
491
- assert ! ( false , "The value should have been an object!" ) ;
492
- }
486
+ assert ! ( args. get( 0 ) . is_object( ) ) ;
493
487
None
494
488
} )
495
489
. expect ( "Got error on function run" ) ;
@@ -501,7 +495,7 @@ mod json_path_tests {
501
495
if let Value :: Other ( any) = args. get ( 0 ) {
502
496
assert ! ( any. is_function( ) ) ;
503
497
} else {
504
- assert ! ( false , "The value should have been an object !" ) ;
498
+ unreachable ! ( "The value should have been a function !" ) ;
505
499
}
506
500
None
507
501
} )
@@ -517,7 +511,7 @@ mod json_path_tests {
517
511
if let Value :: Other ( any) = args. get ( 0 ) {
518
512
assert ! ( any. is_async_function( ) ) ;
519
513
} else {
520
- assert ! ( false , "The value should have been an object !" ) ;
514
+ unreachable ! ( "The value should have been an async function !" ) ;
521
515
}
522
516
None
523
517
} ,
@@ -528,11 +522,7 @@ mod json_path_tests {
528
522
#[ test]
529
523
fn test_value_is_string ( ) {
530
524
define_function_and_call ( "foo(\" foo\" )" , "foo" , |args, _isolate, _ctx_scope| {
531
- if let Value :: String ( _) = args. get ( 0 ) {
532
- assert ! ( true ) ;
533
- } else {
534
- assert ! ( false , "The value should have been a string!" ) ;
535
- }
525
+ assert ! ( args. get( 0 ) . is_string( ) ) ;
536
526
None
537
527
} )
538
528
. expect ( "Got error on function run" ) ;
@@ -541,11 +531,7 @@ mod json_path_tests {
541
531
#[ test]
542
532
fn test_value_is_number ( ) {
543
533
define_function_and_call ( "foo(1)" , "foo" , |args, _isolate, _ctx_scope| {
544
- if let Value :: Double ( _) = args. get ( 0 ) {
545
- assert ! ( true ) ;
546
- } else {
547
- assert ! ( false , "The value should have been a number!" ) ;
548
- }
534
+ assert ! ( args. get( 0 ) . is_number( ) ) ;
549
535
None
550
536
} )
551
537
. expect ( "Got error on function run" ) ;
@@ -557,11 +543,7 @@ mod json_path_tests {
557
543
"foo(async function(){}())" ,
558
544
"foo" ,
559
545
|args, _isolate, _ctx_scope| {
560
- if let Value :: Other ( any) = args. get ( 0 ) {
561
- assert ! ( any. is_promise( ) ) ;
562
- } else {
563
- assert ! ( false , "The value should have been a number!" ) ;
564
- }
546
+ assert ! ( args. get( 0 ) . is_promise( ) ) ;
565
547
None
566
548
} ,
567
549
)
@@ -619,7 +601,7 @@ mod json_path_tests {
619
601
new_native_function ! ( |_isolate, _ctx_scope, arg1: i64 , arg2: f64 , arg3: bool | {
620
602
assert_eq!( arg1, 1 ) ;
621
603
assert_eq!( arg2, 2.2 ) ;
622
- assert_eq !( arg3, true ) ;
604
+ assert !( arg3) ;
623
605
Result :: <Option <LocalValueAny >, String >:: Ok ( None )
624
606
} ) ,
625
607
)
@@ -839,9 +821,8 @@ mod json_path_tests {
839
821
assert_eq!( arg2, 2 ) ;
840
822
if let Some ( array) = arg3 {
841
823
assert_eq!( array. len( ) , 2 ) ;
842
- assert!( true ) ;
843
824
} else {
844
- assert! ( false , "Should have been an array." ) ;
825
+ unreachable! ( "Should have been an array." ) ;
845
826
}
846
827
Result :: <Option <LocalValueAny >, String >:: Ok ( None )
847
828
}
@@ -864,11 +845,7 @@ mod json_path_tests {
864
845
|_isolate, _ctx_scope, arg1: i64 , arg2: i64 , arg3: Option <types:: Value >| {
865
846
assert_eq!( arg1, 1 ) ;
866
847
assert_eq!( arg2, 2 ) ;
867
- if let Some ( Value :: Array ( _) ) = arg3 {
868
- assert!( true ) ;
869
- } else {
870
- assert!( false , "Should have been an array." ) ;
871
- }
848
+ assert!( arg3. unwrap( ) . is_array( ) ) ;
872
849
Result :: <Option <LocalValueAny >, String >:: Ok ( None )
873
850
}
874
851
) ,
0 commit comments