@@ -545,6 +545,24 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
545
545
}
546
546
}
547
547
548
+ impl < T : FromJSValConvertible > FromJSValConvertible for Option < T > {
549
+ type Config = T :: Config ;
550
+ unsafe fn from_jsval (
551
+ cx : * mut JSContext ,
552
+ value : HandleValue ,
553
+ option : T :: Config ,
554
+ ) -> Result < ConversionResult < Option < T > > , ( ) > {
555
+ if value. get ( ) . is_null_or_undefined ( ) {
556
+ Ok ( ConversionResult :: Success ( None ) )
557
+ } else {
558
+ Ok ( match FromJSValConvertible :: from_jsval ( cx, value, option) ? {
559
+ ConversionResult :: Success ( v) => ConversionResult :: Success ( Some ( v) ) ,
560
+ ConversionResult :: Failure ( v) => ConversionResult :: Failure ( v) ,
561
+ } )
562
+ }
563
+ }
564
+ }
565
+
548
566
impl < T : ToJSValConvertible > ToJSValConvertible for & ' _ T {
549
567
#[ inline]
550
568
unsafe fn to_jsval ( & self , cx : * mut JSContext , rval : MutableHandleValue ) {
@@ -566,24 +584,6 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Rc<T> {
566
584
}
567
585
}
568
586
569
- impl < T : FromJSValConvertible > FromJSValConvertible for Option < T > {
570
- type Config = T :: Config ;
571
- unsafe fn from_jsval (
572
- cx : * mut JSContext ,
573
- value : HandleValue ,
574
- option : T :: Config ,
575
- ) -> Result < ConversionResult < Option < T > > , ( ) > {
576
- if value. get ( ) . is_null_or_undefined ( ) {
577
- Ok ( ConversionResult :: Success ( None ) )
578
- } else {
579
- Ok ( match FromJSValConvertible :: from_jsval ( cx, value, option) ? {
580
- ConversionResult :: Success ( v) => ConversionResult :: Success ( Some ( v) ) ,
581
- ConversionResult :: Failure ( v) => ConversionResult :: Failure ( v) ,
582
- } )
583
- }
584
- }
585
- }
586
-
587
587
// https://heycam.github.io/webidl/#es-sequence
588
588
impl < T : ToJSValConvertible > ToJSValConvertible for [ T ] {
589
589
#[ inline]
0 commit comments