summaryrefslogtreecommitdiff
path: root/util.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-14 01:30:56 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-14 01:30:56 -0400
commit1a80bcb250c81a8959b8af816f499c22bca0db51 (patch)
tree449d9c35437d995e02c473e8b328dbcd3f43367f /util.ts
parentbfb3cd7a5c55dbf59eacb7d93e88f38632e47260 (diff)
Add console.log
Diffstat (limited to 'util.ts')
-rw-r--r--util.ts23
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(" "));
+ }
+};