Skip to content

Commit e93117c

Browse files
committed
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.
1 parent 5fe0416 commit e93117c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

assets/resources/scriptlets.js

+28
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,34 @@
19811981
})();
19821982

19831983

1984+
/// call-nothrow.js
1985+
(function() {
1986+
const chain = '{{1}}';
1987+
if ( chain === '' || chain === '{{1}}' ) { return; }
1988+
const parts = chain.split('.');
1989+
let owner = window, prop;
1990+
for (;;) {
1991+
prop = parts.shift();
1992+
if ( parts.length === 0 ) { break; }
1993+
owner = owner[prop];
1994+
if ( owner instanceof Object === false ) { return; }
1995+
}
1996+
if ( prop === '' ) { return; }
1997+
const fn = owner[prop];
1998+
if ( typeof fn !== 'function' ) { return; }
1999+
owner[prop] = new Proxy(fn, {
2000+
apply: function(...args) {
2001+
let r;
2002+
try {
2003+
r = Reflect.apply(...args);
2004+
} catch(ex) {
2005+
}
2006+
return r;
2007+
},
2008+
});
2009+
})();
2010+
2011+
19842012
// These lines below are skipped by the resource parser.
19852013
// <<<< end of private namespace
19862014
})();

0 commit comments

Comments
 (0)