mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-22 18:32:45 +01:00
Add call-nothrow
scriptlet
The purpose is to prevent a call to an existing function from throwing an exception. The exception will be caught by the scriptlet and neutralized. The first argument must be a reference to a function call. At the moment, the function call must exist at the time the scriptlet is called.
This commit is contained in:
parent
5fe0416001
commit
e93117cbb6
@ -1981,6 +1981,34 @@
|
||||
})();
|
||||
|
||||
|
||||
/// call-nothrow.js
|
||||
(function() {
|
||||
const chain = '{{1}}';
|
||||
if ( chain === '' || chain === '{{1}}' ) { return; }
|
||||
const parts = chain.split('.');
|
||||
let owner = window, prop;
|
||||
for (;;) {
|
||||
prop = parts.shift();
|
||||
if ( parts.length === 0 ) { break; }
|
||||
owner = owner[prop];
|
||||
if ( owner instanceof Object === false ) { return; }
|
||||
}
|
||||
if ( prop === '' ) { return; }
|
||||
const fn = owner[prop];
|
||||
if ( typeof fn !== 'function' ) { return; }
|
||||
owner[prop] = new Proxy(fn, {
|
||||
apply: function(...args) {
|
||||
let r;
|
||||
try {
|
||||
r = Reflect.apply(...args);
|
||||
} catch(ex) {
|
||||
}
|
||||
return r;
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
// These lines below are skipped by the resource parser.
|
||||
// <<<< end of private namespace
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user