From b381ceda72bec4e718bf92ddba1b24a761957add Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 29 Mar 2025 09:54:41 -0400 Subject: [PATCH] Mind other old constructs for scriptlets Related feedback: https://old.reddit.com/r/uBlockOrigin/comments/1jmcqhn/ Related commit: https://github.com/gorhill/uBlock/commit/44c038b9a1 --- src/js/scriptlet-filtering-core.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/scriptlet-filtering-core.js b/src/js/scriptlet-filtering-core.js index eca58e310..00888da1c 100644 --- a/src/js/scriptlet-filtering-core.js +++ b/src/js/scriptlet-filtering-core.js @@ -67,8 +67,10 @@ const lookupScriptlet = (rawToken, mainMap, isolatedMap, debug = false) => { const details = reng.contentFromName(token, 'text/javascript'); if ( details === undefined ) { return; } const targetWorldMap = details.world !== 'ISOLATED' ? mainMap : isolatedMap; - const content = patchScriptlet(details.js, args.slice(1)); - if ( content.startsWith('(function(') === false ) { + const match = /^function\s+([^(\s]+)\s*\(/.exec(details.js); + const fname = match && match[1]; + const content = patchScriptlet(fname, details.js, args.slice(1)); + if ( fname ) { targetWorldMap.set(token, details.js); } const dependencies = details.dependencies || []; @@ -92,10 +94,9 @@ const lookupScriptlet = (rawToken, mainMap, isolatedMap, debug = false) => { }; // Fill-in scriptlet argument placeholders. -const patchScriptlet = (content, arglist) => { - const match = /^function\s+([^(\s]+)\s*\(/.exec(content); - if ( match ) { - content = `${match[1]}({{args}});`; +const patchScriptlet = (fname, content, arglist) => { + if ( fname ) { + content = `${fname}({{args}});`; } else { for ( let i = 0; i < arglist.length; i++ ) { content = content.replace(`{{${i+1}}}`, arglist[i]);