mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-02 08:52:45 +01:00
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 fn = thisArg[fnName];
|
||||
return function() {
|
||||
return function(...args) {
|
||||
return new Promise(resolve => {
|
||||
fn.call(thisArg, ...arguments, function() {
|
||||
if ( chrome.runtime.lastError instanceof Object ) {
|
||||
void chrome.runtime.lastError.message;
|
||||
}
|
||||
resolve(outFn(...arguments));
|
||||
});
|
||||
try {
|
||||
fn.call(thisArg, ...args, function(...args) {
|
||||
void chrome.runtime.lastError;
|
||||
resolve(outFn(...args));
|
||||
});
|
||||
} catch(ex) {
|
||||
console.error(ex);
|
||||
resolve(outFn());
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const promisify = function(thisArg, fnName) {
|
||||
const fn = thisArg[fnName];
|
||||
return function() {
|
||||
return function(...args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn.call(thisArg, ...arguments, function() {
|
||||
const lastError = chrome.runtime.lastError;
|
||||
if ( lastError instanceof Object ) {
|
||||
return reject(lastError.message);
|
||||
}
|
||||
resolve(...arguments);
|
||||
});
|
||||
try {
|
||||
fn.call(thisArg, ...args, function(...args) {
|
||||
const lastError = chrome.runtime.lastError;
|
||||
if ( lastError instanceof Object ) {
|
||||
return reject(lastError.message);
|
||||
}
|
||||
resolve(...args);
|
||||
});
|
||||
} catch(ex) {
|
||||
console.error(ex);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user