blob: b6a582f9e45caab08f8164b602fba289308df8e7 (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
((window) => {
const core = Deno.core;
let logDebug = false;
let logSource = "JS";
function setLogDebug(debug, source) {
logDebug = debug;
if (source) {
logSource = source;
}
}
function log(...args) {
if (logDebug) {
const stringifiedArgs = args.map(JSON.stringify).join(" ");
core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`);
}
}
class AssertionError extends Error {
constructor(msg) {
super(msg);
this.name = "AssertionError";
}
}
function assert(cond, msg = "Assertion failed.") {
if (!cond) {
throw new AssertionError(msg);
}
}
function createResolvable() {
let resolve;
let reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
promise.resolve = resolve;
promise.reject = reject;
return promise;
}
function notImplemented() {
throw new Error("not implemented");
}
window.__bootstrap.util = {
log,
setLogDebug,
notImplemented,
createResolvable,
assert,
AssertionError,
};
})(this);
|