diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-14 01:30:56 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-14 01:30:56 -0400 |
commit | 1a80bcb250c81a8959b8af816f499c22bca0db51 (patch) | |
tree | 449d9c35437d995e02c473e8b328dbcd3f43367f /util.ts | |
parent | bfb3cd7a5c55dbf59eacb7d93e88f38632e47260 (diff) |
Add console.log
Diffstat (limited to 'util.ts')
-rw-r--r-- | util.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/util.ts b/util.ts new file mode 100644 index 000000000..467515225 --- /dev/null +++ b/util.ts @@ -0,0 +1,23 @@ +// 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. +const globalEval = eval; + +// A reference to the global object. +const _global = globalEval("this"); + +_global["console"] = { + log(...args: any[]): void { + const out: string[] = []; + for (let a of args) { + if (typeof(a) === "string") { + out.push(a); + } else { + out.push(JSON.stringify(a)); + } + } + V8Worker2.print(out.join(" ")); + } +}; |