Repository navigation
Expand file tree
/
Copy pathconsole.ts
More file actions
100 lines (88 loc) · 2.41 KB
/
Copy pathconsole.ts
File metadata and controls
100 lines (88 loc) · 2.41 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {
process
} from "./process";
// @ts-ignore: decorator
@lazy var timers = new Map<string,u64>();
export namespace console {
export function assert<T>(condition: T, message: string): void {
if (!condition) {
let stderr = process.stderr;
stderr.write("Assertion failed: ");
stderr.write(message);
stderr.write("\n");
}
}
export function log(message: string): void {
var stdout = process.stdout;
stdout.write(message);
stdout.write("\n");
}
export function debug(message: string): void {
var stdout = process.stdout;
stdout.write("Debug: ");
stdout.write(message);
stdout.write("\n");
}
export function info(message: string): void {
var stdout = process.stdout;
stdout.write("Info: ");
stdout.write(message);
stdout.write("\n");
}
export function warn(message: string): void {
var stdout = process.stdout;
stdout.write("Warning: ");
stdout.write(message);
stdout.write("\n");
}
export function error(message: string): void {
var stdout = process.stdout;
stdout.write("Error: ");
stdout.write(message);
stdout.write("\n");
}
export function time(label: string): void {
var stdout = process.stdout;
if (timers.has(label)) {
stdout.write("Warning: Label '");
stdout.write(label);
stdout.write("' already exists for console.time()\n");
return;
}
timers.set(label, process.hrtime());
}
export function timeLog(label: string): void {
var stdout = process.stdout;
if (!timers.has(label)) {
stdout.write("Warning: No such label '");
stdout.write(label);
stdout.write("' for console.timeLog()\n");
return;
}
timeLogImpl(label);
}
export function timeEnd(label: string): void {
var stdout = process.stdout;
if (!timers.has(label)) {
stdout.write("Warning: No such label '");
stdout.write(label);
stdout.write("' for console.timeEnd()\n");
return;
}
timeLogImpl(label);
timers.delete(label);
}
}
function timeLogImpl(label: string): void {
var start = changetype<u64>(timers.get(label));
var end = process.hrtime();
var nanos = end - start;
var millis = nanos / 1000000;
var millisStr = millis.toString();
var stdout = process.stdout;
stdout.write(label);
stdout.write(": ");
stdout.write(millisStr);
stdout.write("ms\n");
// __dispose(changetype<usize>(millisStr));
}