1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-19 11:18:42 +02:00

Fix potential exception when casting to string

Related discussion:
- https://github.com/uBlockOrigin/uAssets/issues/9123#issuecomment-848255120
This commit is contained in:
Raymond Hill 2021-05-26 07:22:17 -04:00
parent 7508700892
commit 07d3c96261
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -307,6 +307,7 @@
/// addEventListener-defuser.js /// addEventListener-defuser.js
/// alias aeld.js /// alias aeld.js
// https://github.com/uBlockOrigin/uAssets/issues/9123#issuecomment-848255120
(function() { (function() {
let needle1 = '{{1}}'; let needle1 = '{{1}}';
if ( needle1 === '' || needle1 === '{{1}}' ) { if ( needle1 === '' || needle1 === '{{1}}' ) {
@ -330,8 +331,12 @@
self.EventTarget.prototype.addEventListener, self.EventTarget.prototype.addEventListener,
{ {
apply: function(target, thisArg, args) { apply: function(target, thisArg, args) {
const type = String(args[0]); let type, handler;
const handler = String(args[1]); try {
type = String(args[0]);
handler = String(args[1]);
} catch(ex) {
}
if ( if (
needle1.test(type) === false || needle1.test(type) === false ||
needle2.test(handler) === false needle2.test(handler) === false
@ -346,14 +351,19 @@
/// addEventListener-logger.js /// addEventListener-logger.js
/// alias aell.js /// alias aell.js
// https://github.com/uBlockOrigin/uAssets/issues/9123#issuecomment-848255120
(function() { (function() {
const log = console.log.bind(console); const log = console.log.bind(console);
self.EventTarget.prototype.addEventListener = new Proxy( self.EventTarget.prototype.addEventListener = new Proxy(
self.EventTarget.prototype.addEventListener, self.EventTarget.prototype.addEventListener,
{ {
apply: function(target, thisArg, args) { apply: function(target, thisArg, args) {
const type = String(args[0]); let type, handler;
const handler = String(args[1]); try {
type = String(args[0]);
handler = String(args[1]);
} catch(ex) {
}
log('uBO: addEventListener("%s", %s)', type, handler); log('uBO: addEventListener("%s", %s)', type, handler);
return target.apply(thisArg, args); return target.apply(thisArg, args);
} }