55 */
66//! V8-rs is a crate containing bindings to the V8 C++ API.
77
8- #![ warn ( missing_docs) ]
8+ #![ deny ( missing_docs) ]
99
1010/// The module contains the rust-idiomatic data structures and functions.
1111pub mod v8;
@@ -57,17 +57,13 @@ impl From<UserIndex> for RawIndex {
5757mod json_path_tests {
5858 use crate as v8_rs;
5959 use crate :: v8:: types:: any:: LocalValueAny ;
60- use crate :: v8:: types:: native_function:: LocalNativeFunction ;
6160 use crate :: v8:: types:: native_function_template:: LocalNativeFunctionTemplate ;
6261 use crate :: v8:: types:: object_template:: LocalObjectTemplate ;
6362 use crate :: v8:: types:: promise:: LocalPromise ;
6463 use crate :: v8:: types:: try_catch:: TryCatch ;
6564 use crate :: v8:: types:: utf8:: LocalUtf8 ;
6665 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} ;
7167
7268 use v8_derive:: new_native_function;
7369
@@ -199,7 +195,7 @@ mod json_path_tests {
199195 . create_native_function_template ( |args, isolate_scope, ctx_scope| {
200196 let foo: LocalValueAny = isolate_scope. create_string ( "foo" ) . try_into ( ) . unwrap ( ) ;
201197 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] ) ) ;
203199 None
204200 } )
205201 . try_into ( )
@@ -256,7 +252,7 @@ mod json_path_tests {
256252 let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
257253 assert ! ( script. run( & ctx_scope) . is_none( ) ) ;
258254 let exception = trycatch. get_exception ( ) ;
259- let exception_msg = exception . into_utf8 ( ) . unwrap ( ) ;
255+ let exception_msg = LocalUtf8 :: try_from ( exception ) . unwrap ( ) ;
260256 assert_eq ! ( exception_msg. as_str( ) , "this is an error" ) ;
261257 }
262258
@@ -275,10 +271,10 @@ mod json_path_tests {
275271 let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
276272 assert ! ( script. run( & ctx_scope) . is_none( ) ) ;
277273 let exception = trycatch. get_exception ( ) ;
278- let exception_msg = exception . into_utf8 ( ) . unwrap ( ) ;
274+ let exception_msg = LocalUtf8 :: try_from ( exception ) . unwrap ( ) ;
279275 assert_eq ! ( exception_msg. as_str( ) , "Error: this is an error!" ) ;
280276 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 ( ) ;
282278 assert ! ( trace_str. as_str( ) . contains( "at foo" ) ) ;
283279 }
284280
@@ -368,7 +364,7 @@ mod json_path_tests {
368364 crate :: v8:: types:: promise:: PromiseState :: Fulfilled
369365 ) ;
370366 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 ( ) ;
372368 assert_eq ! ( res_utf8. as_str( ) , "1" ) ;
373369 }
374370
@@ -382,7 +378,7 @@ mod json_path_tests {
382378 globals. add_native_function ( "foo" , |_args, isolate_scope, ctx_scope| {
383379 let resolver = ctx_scope. create_resolver ( ) ;
384380 resolver. resolve (
385- & ctx_scope,
381+ ctx_scope,
386382 & isolate_scope. create_string ( "foo" ) . try_into ( ) . unwrap ( ) ,
387383 ) ;
388384 let promise = resolver. get_promise ( ) ;
@@ -404,7 +400,7 @@ mod json_path_tests {
404400 crate :: v8:: types:: promise:: PromiseState :: Fulfilled
405401 ) ;
406402 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 ( ) ;
408404 assert_eq ! ( res_utf8. as_str( ) , "foo" ) ;
409405 }
410406
@@ -420,7 +416,9 @@ mod json_path_tests {
420416 let script = ctx_scope. compile ( & code_str) ;
421417 assert ! ( script. is_none( ) ) ;
422418 assert_eq ! (
423- trycatch. get_exception( ) . into_utf8( ) . unwrap( ) . as_str( ) ,
419+ LocalUtf8 :: try_from( trycatch. get_exception( ) )
420+ . unwrap( )
421+ . as_str( ) ,
424422 "SyntaxError: Unexpected end of input"
425423 ) ;
426424 }
@@ -438,7 +436,9 @@ mod json_path_tests {
438436 let res = script. run ( & ctx_scope) ;
439437 assert ! ( res. is_none( ) ) ;
440438 assert_eq ! (
441- trycatch. get_exception( ) . into_utf8( ) . unwrap( ) . as_str( ) ,
439+ LocalUtf8 :: try_from( trycatch. get_exception( ) )
440+ . unwrap( )
441+ . as_str( ) ,
442442 "ReferenceError: foo is not defined"
443443 ) ;
444444 }
@@ -472,9 +472,7 @@ mod json_path_tests {
472472 let trycatch: TryCatch = isolate_scope. create_try_catch ( ) . try_into ( ) . unwrap ( ) ;
473473 let res = match script. run ( & ctx_scope) {
474474 Some ( _res) => Ok ( ( ) ) ,
475- None => Err ( trycatch
476- . get_exception ( )
477- . into_utf8 ( )
475+ None => Err ( LocalUtf8 :: try_from ( trycatch. get_exception ( ) )
478476 . unwrap ( )
479477 . as_str ( )
480478 . to_string ( ) ) ,
@@ -485,11 +483,7 @@ mod json_path_tests {
485483 #[ test]
486484 fn test_value_is_object ( ) {
487485 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( ) ) ;
493487 None
494488 } )
495489 . expect ( "Got error on function run" ) ;
@@ -501,7 +495,7 @@ mod json_path_tests {
501495 if let Value :: Other ( any) = args. get ( 0 ) {
502496 assert ! ( any. is_function( ) ) ;
503497 } else {
504- assert ! ( false , "The value should have been an object !" ) ;
498+ unreachable ! ( "The value should have been a function !" ) ;
505499 }
506500 None
507501 } )
@@ -517,7 +511,7 @@ mod json_path_tests {
517511 if let Value :: Other ( any) = args. get ( 0 ) {
518512 assert ! ( any. is_async_function( ) ) ;
519513 } else {
520- assert ! ( false , "The value should have been an object !" ) ;
514+ unreachable ! ( "The value should have been an async function !" ) ;
521515 }
522516 None
523517 } ,
@@ -528,11 +522,7 @@ mod json_path_tests {
528522 #[ test]
529523 fn test_value_is_string ( ) {
530524 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( ) ) ;
536526 None
537527 } )
538528 . expect ( "Got error on function run" ) ;
@@ -541,11 +531,7 @@ mod json_path_tests {
541531 #[ test]
542532 fn test_value_is_number ( ) {
543533 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( ) ) ;
549535 None
550536 } )
551537 . expect ( "Got error on function run" ) ;
@@ -557,11 +543,7 @@ mod json_path_tests {
557543 "foo(async function(){}())" ,
558544 "foo" ,
559545 |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( ) ) ;
565547 None
566548 } ,
567549 )
@@ -619,7 +601,7 @@ mod json_path_tests {
619601 new_native_function ! ( |_isolate, _ctx_scope, arg1: i64 , arg2: f64 , arg3: bool | {
620602 assert_eq!( arg1, 1 ) ;
621603 assert_eq!( arg2, 2.2 ) ;
622- assert_eq !( arg3, true ) ;
604+ assert !( arg3) ;
623605 Result :: <Option <LocalValueAny >, String >:: Ok ( None )
624606 } ) ,
625607 )
@@ -839,9 +821,8 @@ mod json_path_tests {
839821 assert_eq!( arg2, 2 ) ;
840822 if let Some ( array) = arg3 {
841823 assert_eq!( array. len( ) , 2 ) ;
842- assert!( true ) ;
843824 } else {
844- assert! ( false , "Should have been an array." ) ;
825+ unreachable! ( "Should have been an array." ) ;
845826 }
846827 Result :: <Option <LocalValueAny >, String >:: Ok ( None )
847828 }
@@ -864,11 +845,7 @@ mod json_path_tests {
864845 |_isolate, _ctx_scope, arg1: i64 , arg2: i64 , arg3: Option <types:: Value >| {
865846 assert_eq!( arg1, 1 ) ;
866847 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( ) ) ;
872849 Result :: <Option <LocalValueAny >, String >:: Ok ( None )
873850 }
874851 ) ,
0 commit comments