Skip to content

Commit

Permalink
hasOwn & catchError utils (for extensions)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-kiss authored Nov 12, 2024
1 parent 29f1ff7 commit f82d562
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/extension-support/usb-unsandboxed-object.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
const ContextMenuContext = require('./context-menu-context');
const Util = require('../util/usb-util');
const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop):
const catchError = async (promise, errors) => {
if (!(promise instanceof Promise)) {
throw new TypeError('Expected "promise" to be PromiseLike.');
}
if (errors !== undefined) {
if (!Array.isArray(errors)) {
throw new TypeError('Expected "errors" to be undefined or an array.');
}
if (!errors[0]) {
throw new RangeError('Expected "errors" array to be bigger than 0.');
}
}
return promise.then(v => [undefined, v]).catch(e => {
if (
errors !== undefined ||
!errors.some(p => (e instanceof p))
) return;
return [e, undefined];
});
};

module.exports = function() {
return {
ContextMenuContext,
Util
};
return {
ContextMenuContext,
Util,
hasOwn,
catchError
};
};

0 comments on commit f82d562

Please sign in to comment.