mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 16:01:30 +00:00
Slight restructure
This commit is contained in:
33
std/portable.js
Normal file
33
std/portable.js
Normal file
@ -0,0 +1,33 @@
|
||||
var globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
|
||||
|
||||
globalScope["clz"] = Math.clz32;
|
||||
globalScope["abs"] = Math.abs;
|
||||
globalScope["max"] = Math.max;
|
||||
globalScope["min"] = Math.min;
|
||||
globalScope["ceil"] = Math.ceil;
|
||||
globalScope["floor"] = Math.floor;
|
||||
globalScope["select"] = function select(ifTrue, ifFalse, condition) { return condition ? ifTrue : ifFalse; };
|
||||
globalScope["sqrt"] = Math.sqrt;
|
||||
globalScope["trunc"] = Math.trunc;
|
||||
|
||||
function UnreachableError() {
|
||||
this.stack = new Error().stack;
|
||||
}
|
||||
UnreachableError.prototype = new Error;
|
||||
UnreachableError.prototype.name = "UnreachableError";
|
||||
UnreachableError.prototype.message = "unreachable";
|
||||
|
||||
globalScope["unreachable"] = function unreachable() { throw new UnreachableError(); };
|
||||
|
||||
function AssertionError() {
|
||||
this.stack = new Error().stack;
|
||||
}
|
||||
AssertionError.prototype = new Error;
|
||||
AssertionError.prototype.name = "AssertionError";
|
||||
AssertionError.prototype.message = "assertion failed";
|
||||
|
||||
globalScope["assert"] = function assert(isTrue) { if (!isTrue) throw new AssertionError(); };
|
||||
globalScope["changetype"] = function changetype(value) { return value; }
|
||||
|
||||
String["fromCharCodes"] = function fromCharCodes(arr) { return String.fromCharCode.apply(String, arr); }
|
||||
String["fromCodePoints"] = function fromCodePoints(arr) { return String.fromCodePoint.apply(String, arr); }
|
Reference in New Issue
Block a user