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
This commit is contained in:
Raymond Hill 2025-03-29 09:54:41 -04:00
parent 44c038b9a1
commit b381ceda72
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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]);