@@ -822,83 +822,96 @@ Utils.unwrapParameters = function(wrappedParameters, doc) {
822
822
823
823
824
824
Utils . wrapResult = function ( result , doc ) {
825
- result = fxdriver . moz . unwrap ( result ) ;
825
+ var _wrap = function ( result , doc , seen ) {
826
+ result = fxdriver . moz . unwrap ( result ) ;
826
827
827
- // Sophisticated.
828
- switch ( typeof result ) {
829
- case 'string' :
830
- case 'number' :
831
- case 'boolean' :
832
- return result ;
833
-
834
- case 'function' :
835
- return result . toString ( ) ;
828
+ // Sophisticated.
829
+ switch ( typeof result ) {
830
+ case 'string' :
831
+ case 'number' :
832
+ case 'boolean' :
833
+ return result ;
836
834
837
- case 'undefined ' :
838
- return null ;
835
+ case 'function ' :
836
+ return result . toString ( ) ;
839
837
840
- case 'object' :
841
- if ( result == null ) {
838
+ case 'undefined' :
842
839
return null ;
843
- }
844
840
845
- // There's got to be a more intelligent way of detecting this.
846
- if ( result . nodeType == 1 && result [ 'tagName' ] ) {
847
- return { 'ELEMENT' : Utils . addToKnownElements ( result ) } ;
848
- }
841
+ case 'object' :
842
+ if ( result == null ) {
843
+ return null ;
844
+ }
849
845
850
- if ( typeof result . getMonth === 'function' ) {
851
- return result . toJSON ( ) ;
852
- }
846
+ if ( seen . indexOf ( result ) >= 0 ) {
847
+ throw new bot . Error ( bot . ErrorCode . JAVASCRIPT_ERROR ,
848
+ 'Recursive object cannot be transferred' ) ;
849
+ }
853
850
854
- if ( typeof result . length === 'number' &&
855
- ! ( result . propertyIsEnumerable ( 'length' ) ) ) {
856
- var array = [ ] ;
857
- for ( var i = 0 ; i < result . length ; i ++ ) {
858
- array . push ( Utils . wrapResult ( result [ i ] , doc ) ) ;
851
+ // There's got to be a more intelligent way of detecting this.
852
+ if ( result . nodeType == 1 && result [ 'tagName' ] ) {
853
+ return { 'ELEMENT' : Utils . addToKnownElements ( result ) } ;
859
854
}
860
- return array ;
861
- }
862
855
863
- // Document. Grab the document element.
864
- if ( result . nodeType == 9 ) {
865
- return Utils . wrapResult ( result . documentElement ) ;
866
- }
856
+ if ( typeof result . getMonth === 'function' ) {
857
+ return result . toJSON ( ) ;
858
+ }
867
859
868
- try {
869
- var nodeList = result . QueryInterface ( CI . nsIDOMNodeList ) ;
870
- var array = [ ] ;
871
- for ( var i = 0 ; i < nodeList . length ; i ++ ) {
872
- array . push ( Utils . wrapResult ( result . item ( i ) , doc ) ) ;
860
+ seen . push ( result ) ;
861
+
862
+ if ( typeof result . length === 'number' &&
863
+ ! ( result . propertyIsEnumerable ( 'length' ) ) ) {
864
+ var array = [ ] ;
865
+ for ( var i = 0 ; i < result . length ; i ++ ) {
866
+ array . push ( _wrap ( result [ i ] , doc , seen ) ) ;
867
+ }
868
+ return array ;
869
+ }
870
+
871
+ // Document. Grab the document element.
872
+ if ( result . nodeType == 9 ) {
873
+ return _wrap ( result . documentElement , doc , seen ) ;
873
874
}
874
- return array ;
875
- } catch ( ignored ) {
876
- goog . log . warning ( Utils . LOG_ , 'Error wrapping NodeList' , ignored ) ;
877
- }
878
875
879
- try {
880
- // There's got to be a better way, but 'result instanceof Error' returns false
881
- if ( Object . getPrototypeOf ( result ) != null && goog . string . endsWith ( Object . getPrototypeOf ( result ) . toString ( ) , 'Error' ) ) {
882
- try {
883
- return fxdriver . error . toJSON ( result ) ;
884
- } catch ( ignored2 ) {
885
- goog . log . info ( Utils . LOG_ , 'Error' , ignored2 ) ;
886
- return result . toString ( ) ;
876
+ var nodeList ;
877
+ try {
878
+ nodeList = result . QueryInterface ( CI . nsIDOMNodeList ) ;
879
+ } catch ( ignored ) {
880
+ }
881
+ if ( nodeList ) {
882
+ var array = [ ] ;
883
+ for ( var i = 0 ; i < nodeList . length ; i ++ ) {
884
+ array . push ( _wrap ( result . item ( i ) , doc , seen ) ) ;
887
885
}
886
+ return array ;
888
887
}
889
- } catch ( ignored ) {
890
- goog . log . info ( Utils . LOG_ , 'Error' , ignored ) ;
891
- }
892
888
893
- var convertedObj = { } ;
894
- for ( var prop in result ) {
895
- convertedObj [ prop ] = Utils . wrapResult ( result [ prop ] , doc ) ;
896
- }
897
- return convertedObj ;
889
+ try {
890
+ // There's got to be a better way, but 'result instanceof Error' returns false
891
+ if ( Object . getPrototypeOf ( result ) != null && goog . string . endsWith (
892
+ Object . getPrototypeOf ( result ) . toString ( ) , 'Error' ) ) {
893
+ try {
894
+ return fxdriver . error . toJSON ( result ) ;
895
+ } catch ( ignored2 ) {
896
+ goog . log . info ( Utils . LOG_ , 'Error' , ignored2 ) ;
897
+ return result . toString ( ) ;
898
+ }
899
+ }
900
+ } catch ( ignored ) {
901
+ goog . log . info ( Utils . LOG_ , 'Error' , ignored ) ;
902
+ }
898
903
899
- default :
900
- return result ;
901
- }
904
+ var convertedObj = { } ;
905
+ for ( var prop in result ) {
906
+ convertedObj [ prop ] = _wrap ( result [ prop ] , doc , seen ) ;
907
+ }
908
+ return convertedObj ;
909
+
910
+ default :
911
+ return result ;
912
+ }
913
+ } ;
914
+ return _wrap ( result , doc , [ ] ) ;
902
915
} ;
903
916
904
917
0 commit comments