Skip to content

Commit

Permalink
overrides: add override for Function.call to match Function.apply
Browse files Browse the repository at this point in the history
rewrite: also rewrite TrustedScripts, by first converting toString
  • Loading branch information
ikreymer committed May 30, 2024
1 parent 20596ca commit dc12c0b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,9 @@ Wombat.prototype.rewriteHTMLAssign = function(thisObj, oSetter, newValue) {
* @return {*}
*/
Wombat.prototype.rewriteEvalArg = function(rawEvalOrWrapper, evalArg, extraArg) {
if (this.$wbwindow.TrustedScript && (evalArg instanceof this.$wbwindow.TrustedScript)) {
evalArg = evalArg.toString();
}
var toBeEvald =
this.isString(evalArg) && !this.skipWrapScriptTextBasedOnText(evalArg)
? this.wrapScriptTextJsProxy(evalArg)
Expand Down Expand Up @@ -3525,6 +3528,30 @@ Wombat.prototype.overrideFunctionApply = function($wbwindow) {
};


/**
* Overrides Function.prototype.call in order to ensure that none of the
* arguments of `native` functions are one of the JS Proxy objects used by wombat.
* @param {Window} $wbwindow
*/
Wombat.prototype.overrideFunctionCall = function($wbwindow) {
if ($wbwindow.Function.prototype.__WB_orig_call) {
return;
}
var orig_call = $wbwindow.Function.prototype.call;
$wbwindow.Function.prototype.__WB_orig_call = orig_call;
var wombat = this;
$wbwindow.Function.prototype.call = function call(obj, ...args) {
// if native function, de-proxy
if (wombat.isNativeFunction(this)) {
obj = wombat.proxyToObj(obj);
args = wombat.deproxyArrayHandlingArgumentsObj(args);
}

return this.__WB_orig_call(obj, ...args);
};

this.wb_funToString.call = orig_call;
};
/**
* Override Function.prototype.bind to deproxy the param target
* in case of native functions
Expand Down Expand Up @@ -6629,6 +6656,7 @@ Wombat.prototype.wombatInit = function() {
this.initHistoryOverrides();

this.overrideFunctionApply(this.$wbwindow);
this.overrideFunctionCall(this.$wbwindow);
this.overrideFunctionBind(this.$wbwindow);

// Doc Title
Expand Down

0 comments on commit dc12c0b

Please sign in to comment.