forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.ts
More file actions
32 lines (27 loc) · 1.01 KB
/
debug.ts
File metadata and controls
32 lines (27 loc) · 1.01 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
///<reference path='references.ts' />
module TypeScript {
export enum AssertionLevel {
None = 0,
Normal = 1,
Aggressive = 2,
VeryAggressive = 3,
}
export class Debug {
private static currentAssertionLevel = AssertionLevel.None;
public static shouldAssert(level: AssertionLevel): boolean {
return this.currentAssertionLevel >= level;
}
public static assert(expression: any, message: string = "", verboseDebugInfo: () => string = null): void {
if (!expression) {
var verboseDebugString = "";
if (verboseDebugInfo) {
verboseDebugString = "\r\nVerbose Debug Information:" + verboseDebugInfo();
}
throw new Error("Debug Failure. False expression: " + message + verboseDebugString);
}
}
public static fail(message?: string): void {
Debug.assert(false, message);
}
}
}