Skip to content

Commit 5fccd08

Browse files
committed
Improve std Error compatibility
1 parent 84ffa91 commit 5fccd08

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

std/assembly/error.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
export class Error {
22

3+
name: string = "Error";
34
message: string;
45
stack: string = ""; // TODO
56

67
constructor(message: string = "") {
78
this.message = message;
89
}
10+
11+
toString(): string {
12+
var message = this.message;
13+
return message.length
14+
? this.name + ": " + message
15+
: this.name;
16+
}
917
}
1018

11-
export class RangeError extends Error {}
12-
export class TypeError extends Error {}
19+
export class RangeError extends Error {
20+
constructor(message: string = "") {
21+
super(message);
22+
this.name = "RangeError";
23+
}
24+
}
25+
26+
export class TypeError extends Error {
27+
constructor(message: string = "") {
28+
super(message);
29+
this.name = "TypeError";
30+
}
31+
}

0 commit comments

Comments
 (0)