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:
Raymond Hill 2023-03-14 18:50:01 -04:00
parent 5fe0416001
commit e93117cbb6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 28 additions and 0 deletions

View File

@ -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. // These lines below are skipped by the resource parser.
// <<<< end of private namespace // <<<< end of private namespace
})(); })();