diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-21 18:53:53 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-21 18:53:53 -0400 |
commit | 9a6621659937c55c6005a1fa6ce9641a4ceff385 (patch) | |
tree | 723763263c610069635db80252d9e638a28052b0 /util.ts | |
parent | 8e2e17cdbe02847b19d8bc2002ba713d18e291b9 (diff) |
Add globals.ts
Diffstat (limited to 'util.ts')
-rw-r--r-- | util.ts | 46 |
1 files changed, 6 insertions, 40 deletions
@@ -1,19 +1,5 @@ -// If you use the eval function indirectly, by invoking it via a reference -// other than eval, as of ECMAScript 5 it works in the global scope rather than -// the local scope. This means, for instance, that function declarations create -// global functions, and that the code being evaluated doesn't have access to -// local variables within the scope where it's being called. -export const globalEval = eval; - -// A reference to the global object. -// TODO The underscore is because it's conflicting with @types/node. -export const _global = globalEval("this"); - -_global["window"] = _global; // Create a window object. - -const print = V8Worker2.print; - import { debug } from "./main"; +import { TypedArray } from "./types"; // Internal logging for deno. Use the "debug" variable above to control // output. @@ -24,33 +10,13 @@ export function log(...args: any[]): void { } } -_global["console"] = { - // tslint:disable-next-line:no-any - log(...args: any[]): void { - print(stringifyArgs(args)); - }, - - // tslint:disable-next-line:no-any - error(...args: any[]): void { - print("ERROR: " + stringifyArgs(args)); - } -}; - -// tslint:disable-next-line:no-any -function stringifyArgs(args: any[]): string { - const out: string[] = []; - for (const a of args) { - if (typeof a === "string") { - out.push(a); - } else { - out.push(JSON.stringify(a)); - } - } - return out.join(" "); -} - export function assert(cond: boolean, msg = "") { if (!cond) { throw Error("Assert fail. " + msg); } } + +export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer { + const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength); + return ab as ArrayBuffer; +} |