-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
32 lines (28 loc) · 895 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
function rethrowAssertionErrorRejection(e) {
// Used throughout the reference implementation, as `.catch(rethrowAssertionErrorRejection)`, to ensure any errors
// get shown. There are places in the spec where we do promise transformations and purposefully ignore or don't
// expect any errors, but assertion errors are always problematic.
if (e && e.constructor === AssertionError) {
setTimeout(() => {
throw e;
}, 0);
}
};
function AssertionError(message) {
this.name = 'AssertionError';
this.message = message || '';
this.stack = (new Error()).stack;
}
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.constructor = AssertionError;
function assert (value, message) {
if (!value) {
throw new AssertionError(message);
}
}
module.exports = {
rethrowAssertionErrorRejection,
AssertionError,
assert
}