Skip to content

Commit

Permalink
Add call-nothrow scriptlet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Mar 14, 2023
1 parent 5fe0416 commit e93117c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})();

0 comments on commit e93117c

Please sign in to comment.