Stdlib preparations

This commit is contained in:
dcodeIO
2017-12-16 02:27:39 +01:00
parent 4b3cc981a6
commit 85a9fb1eb5
50 changed files with 834 additions and 137 deletions

View File

@ -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); };