mirror of https://github.com/gorhill/uBlock.git
Catch exceptions in API calls for the sake of old Chromium versions
Related feedback: https://github.com/uBlockOrigin/uBlock-issues/issues/3217#issuecomment-2103628821
This commit is contained in:
parent
363ad6795c
commit
bb479b0a66
|
@ -24,29 +24,37 @@
|
||||||
|
|
||||||
const promisifyNoFail = function(thisArg, fnName, outFn = r => r) {
|
const promisifyNoFail = function(thisArg, fnName, outFn = r => r) {
|
||||||
const fn = thisArg[fnName];
|
const fn = thisArg[fnName];
|
||||||
return function() {
|
return function(...args) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
fn.call(thisArg, ...arguments, function() {
|
try {
|
||||||
if ( chrome.runtime.lastError instanceof Object ) {
|
fn.call(thisArg, ...args, function(...args) {
|
||||||
void chrome.runtime.lastError.message;
|
void chrome.runtime.lastError;
|
||||||
}
|
resolve(outFn(...args));
|
||||||
resolve(outFn(...arguments));
|
|
||||||
});
|
});
|
||||||
|
} catch(ex) {
|
||||||
|
console.error(ex);
|
||||||
|
resolve(outFn());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const promisify = function(thisArg, fnName) {
|
const promisify = function(thisArg, fnName) {
|
||||||
const fn = thisArg[fnName];
|
const fn = thisArg[fnName];
|
||||||
return function() {
|
return function(...args) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fn.call(thisArg, ...arguments, function() {
|
try {
|
||||||
|
fn.call(thisArg, ...args, function(...args) {
|
||||||
const lastError = chrome.runtime.lastError;
|
const lastError = chrome.runtime.lastError;
|
||||||
if ( lastError instanceof Object ) {
|
if ( lastError instanceof Object ) {
|
||||||
return reject(lastError.message);
|
return reject(lastError.message);
|
||||||
}
|
}
|
||||||
resolve(...arguments);
|
resolve(...args);
|
||||||
});
|
});
|
||||||
|
} catch(ex) {
|
||||||
|
console.error(ex);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue