mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 18:26:40 +00:00
Stdlib preparations
This commit is contained in:
@ -66,9 +66,12 @@ globalScope["sqrt"] = Math.sqrt;
|
||||
globalScope["trunc"] = Math.trunc;
|
||||
|
||||
function UnreachableError() {
|
||||
this.stack = new Error().stack;
|
||||
if (Error.captureStackTrace)
|
||||
Error.captureStackTrace(this, UnreachableError);
|
||||
else
|
||||
this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
|
||||
}
|
||||
UnreachableError.prototype = new Error;
|
||||
UnreachableError.prototype = Object.create(Error.prototype);
|
||||
UnreachableError.prototype.name = "UnreachableError";
|
||||
UnreachableError.prototype.message = "unreachable";
|
||||
|
||||
@ -76,9 +79,12 @@ globalScope["unreachable"] = function unreachable() { throw new UnreachableError
|
||||
|
||||
function AssertionError(message) {
|
||||
this.message = message || "assertion failed";
|
||||
this.stack = new Error().stack;
|
||||
if (Error.captureStackTrace)
|
||||
Error.captureStackTrace(this, AssertionError);
|
||||
else
|
||||
this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
|
||||
}
|
||||
AssertionError.prototype = new Error;
|
||||
AssertionError.prototype = Object.create(Error.prototype);
|
||||
AssertionError.prototype.name = "AssertionError";
|
||||
|
||||
globalScope["assert"] = function assert(isTrue, message) { if (!isTrue) throw new AssertionError(message); };
|
||||
|
Reference in New Issue
Block a user