From 77feb25c4d4d8a815da991b252ef2b1bbdbfd78c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 17 Jul 2024 09:36:55 -0400 Subject: [PATCH] Improve `set-constant` scriptlet Related feedback: https://github.com/uBlockOrigin/uBlock-discussions/discussions/881#discussioncomment-10072370 --- assets/resources/scriptlets.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index ab98966a1..9678724cc 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -485,9 +485,8 @@ builtinScriptlets.push({ 'safe-self.fn', ], }); -function validateConstantFn(trusted, raw) { +function validateConstantFn(trusted, raw, extraArgs = {}) { const safe = safeSelf(); - const extraArgs = safe.getExtraArgs(Array.from(arguments), 2); let value; if ( raw === 'undefined' ) { value = undefined; @@ -587,7 +586,7 @@ function setConstantFn( }; if ( trappedProp === '' ) { return; } const thisScript = document.currentScript; - let normalValue = validateConstantFn(trusted, rawValue); + let normalValue = validateConstantFn(trusted, rawValue, extraArgs); if ( rawValue === 'noopFunc' || rawValue === 'trueFunc' || rawValue === 'falseFunc' ) { normalValue = cloakFunc(normalValue); } @@ -4772,7 +4771,7 @@ function trustedReplaceArgument( const logPrefix = safe.makeLogPrefix('trusted-replace-argument', propChain, argposRaw, argraw); const argpos = parseInt(argposRaw, 10) || 0; const extraArgs = safe.getExtraArgs(Array.from(arguments), 3); - const normalValue = validateConstantFn(true, argraw); + const normalValue = validateConstantFn(true, argraw, extraArgs); const reCondition = extraArgs.condition ? safe.patternToRegex(extraArgs.condition) : /^/;