forked from TurboWarp/scratch-vm
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hasOwn & catchError utils (for extensions)
- Loading branch information
Showing
1 changed file
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
}; |