@@ -64,6 +64,17 @@ function Wombat($wbwindow, wbinfo) {
64
64
65
65
this . SKIP_OWN_FUNC_PROPS = [ 'name' , 'length' , '__WB_is_native_func__' , 'arguments' , 'caller' , 'callee' , 'prototype' ] ;
66
66
67
+ this . OVERRIDE_PROPS = [
68
+ 'window' ,
69
+ 'self' ,
70
+ 'document' ,
71
+ 'location' ,
72
+ 'top' ,
73
+ 'parent' ,
74
+ 'frames' ,
75
+ 'opener'
76
+ ] ;
77
+
67
78
/** @type {function(qualifiedName: string, value: string): void } */
68
79
this . wb_setAttribute = $wbwindow . Element . prototype . setAttribute ;
69
80
@@ -696,32 +707,28 @@ Wombat.prototype.skipWrapScriptBasedOnType = function(scriptType) {
696
707
* @param {?string } text
697
708
* @return {boolean }
698
709
*/
699
- Wombat . prototype . skipWrapScriptTextBasedOnText = function ( text ) {
710
+ Wombat . prototype . skipWrapScriptTextBasedOnText = function ( text , excludes ) {
700
711
if (
701
712
! text ||
702
713
text . indexOf ( this . WB_ASSIGN_FUNC ) >= 0 ||
703
714
text . indexOf ( '<' ) === 0
704
715
) {
705
716
return true ;
706
717
}
707
- var override_props = [
708
- 'window' ,
709
- 'self' ,
710
- 'document' ,
711
- 'location' ,
712
- 'top' ,
713
- 'parent' ,
714
- 'frames' ,
715
- 'opener'
716
- ] ;
717
718
718
- for ( var i = 0 ; i < override_props . length ; i ++ ) {
719
- if ( text . indexOf ( override_props [ i ] ) >= 0 ) {
720
- return false ;
719
+ let found = false ;
720
+
721
+ for ( const prop of this . OVERRIDE_PROPS ) {
722
+ const inx = text . indexOf ( prop ) ;
723
+ if ( inx >= 0 ) {
724
+ if ( text . indexOf ( 'var ' + prop ) >= 0 ) {
725
+ excludes . push ( prop ) ;
726
+ }
727
+ found = true ;
721
728
}
722
729
}
723
730
724
- return true ;
731
+ return ! found ;
725
732
} ;
726
733
727
734
/**
@@ -829,24 +836,23 @@ Wombat.prototype.retrieveWBOSRC = function(elem) {
829
836
* @param {?string } scriptText
830
837
* @return {string }
831
838
*/
832
- Wombat . prototype . wrapScriptTextJsProxy = function ( scriptText ) {
833
- return (
839
+ Wombat . prototype . wrapScriptTextJsProxy = function ( scriptText , excludes = [ ] ) {
840
+ let prefix =
834
841
'var _____WB$wombat$assign$function_____ = function(name) {return ' +
835
842
'(self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };\n' +
836
843
'if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { ' +
837
- 'this.__WB_source = obj; return this; } }\n{\n' +
838
- 'let window = _____WB$wombat$assign$function_____("window");\n' +
839
- 'let globalThis = _____WB$wombat$assign$function_____("globalThis");\n' +
840
- 'let self = _____WB$wombat$assign$function_____("self");\n' +
841
- 'let document = _____WB$wombat$assign$function_____("document");\n' +
842
- 'let location = _____WB$wombat$assign$function_____("location");\n' +
843
- 'let top = _____WB$wombat$assign$function_____("top");\n' +
844
- 'let parent = _____WB$wombat$assign$function_____("parent");\n' +
845
- 'let frames = _____WB$wombat$assign$function_____("frames");\n' +
846
- 'let opener = _____WB$wombat$assign$function_____("opener");\n{\n' +
847
- scriptText . replace ( this . DotPostMessageRe , '.__WB_pmw(self.window)$1' ) +
848
- '\n\n}}'
849
- ) ;
844
+ 'this.__WB_source = obj; return this; } }\n{\n' ;
845
+
846
+ for ( const prop of this . OVERRIDE_PROPS ) {
847
+ if ( ! excludes . includes ( prop ) ) {
848
+ prefix += `let ${ prop } = _____WB$wombat$assign$function_____("${ prop } ");\n` ;
849
+ }
850
+ }
851
+
852
+ prefix += '{\n' ;
853
+
854
+ return prefix + scriptText . replace ( this . DotPostMessageRe , '.__WB_pmw(self.window)$1' ) +
855
+ '\n\n}}' ;
850
856
} ;
851
857
852
858
/**
@@ -2185,8 +2191,9 @@ Wombat.prototype.rewriteScript = function(elem) {
2185
2191
}
2186
2192
if ( this . skipWrapScriptBasedOnType ( elem . type ) ) return false ;
2187
2193
var text = elem . textContent . trim ( ) ;
2188
- if ( this . skipWrapScriptTextBasedOnText ( text ) ) return false ;
2189
- elem . textContent = this . wrapScriptTextJsProxy ( text ) ;
2194
+ var excludes = [ ] ;
2195
+ if ( this . skipWrapScriptTextBasedOnText ( text , excludes ) ) return false ;
2196
+ elem . textContent = this . wrapScriptTextJsProxy ( text , excludes ) ;
2190
2197
if ( this . wb_info . injectDocClose && elem . textContent . trim ( ) . length ) {
2191
2198
elem . textContent += ';document.close();' ;
2192
2199
}
@@ -2849,13 +2856,15 @@ Wombat.prototype.rewriteHTMLAssign = function(thisObj, oSetter, newValue) {
2849
2856
res = this . rewriteHtml ( newValue ) ;
2850
2857
}
2851
2858
2859
+ var excludes = [ ] ;
2860
+
2852
2861
// likely actual JS, not tags
2853
2862
if ( res === newValue ) {
2854
2863
if (
2855
2864
! this . skipWrapScriptBasedOnType ( thisObj . type ) &&
2856
- ! this . skipWrapScriptTextBasedOnText ( newValue )
2865
+ ! this . skipWrapScriptTextBasedOnText ( newValue , excludes )
2857
2866
) {
2858
- res = this . wrapScriptTextJsProxy ( res ) ;
2867
+ res = this . wrapScriptTextJsProxy ( res , excludes ) ;
2859
2868
}
2860
2869
}
2861
2870
} else {
@@ -2884,9 +2893,10 @@ Wombat.prototype.rewriteEvalArg = function(rawEvalOrWrapper, evalArg, extraArg)
2884
2893
if ( this . $wbwindow . TrustedScript && ( evalArg instanceof this . $wbwindow . TrustedScript ) ) {
2885
2894
evalArg = evalArg . toString ( ) ;
2886
2895
}
2896
+ var excludes = [ ] ;
2887
2897
var toBeEvald =
2888
- this . isString ( evalArg ) && ! this . skipWrapScriptTextBasedOnText ( evalArg )
2889
- ? this . wrapScriptTextJsProxy ( evalArg )
2898
+ this . isString ( evalArg ) && ! this . skipWrapScriptTextBasedOnText ( evalArg , excludes )
2899
+ ? this . wrapScriptTextJsProxy ( evalArg , excludes )
2890
2900
: this . otherEvalRewrite ( evalArg ) ;
2891
2901
return rawEvalOrWrapper ( toBeEvald , extraArg ) ;
2892
2902
} ;
0 commit comments