mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: cleanup assert() & AssertionError definitions (#13859)
This commit is contained in:
parent
ad8e238348
commit
e55dee7fd8
8 changed files with 30 additions and 60 deletions
|
@ -11,6 +11,7 @@
|
|||
((window) => {
|
||||
const core = Deno.core;
|
||||
const {
|
||||
Error,
|
||||
RegExp,
|
||||
ArrayPrototypeMap,
|
||||
StringPrototypeCharCodeAt,
|
||||
|
@ -275,6 +276,24 @@
|
|||
return StringPrototypeMatch(s, HTTP_BETWEEN_WHITESPACE)?.[1] ?? "";
|
||||
}
|
||||
|
||||
class AssertionError extends Error {
|
||||
constructor(msg) {
|
||||
super(msg);
|
||||
this.name = "AssertionError";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} cond
|
||||
* @param {string=} msg
|
||||
* @returns {asserts cond}
|
||||
*/
|
||||
function assert(cond, msg = "Assertion failed.") {
|
||||
if (!cond) {
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
window.__bootstrap.infra = {
|
||||
collectSequenceOfCodepoints,
|
||||
ASCII_DIGIT,
|
||||
|
@ -299,5 +318,7 @@
|
|||
collectHttpQuotedString,
|
||||
forgivingBase64Encode,
|
||||
forgivingBase64Decode,
|
||||
AssertionError,
|
||||
assert,
|
||||
};
|
||||
})(globalThis);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue