summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.ts17
-rw-r--r--tsconfig.json5
-rw-r--r--util.ts23
3 files changed, 41 insertions, 4 deletions
diff --git a/main.ts b/main.ts
index 44519489a..153414a19 100644
--- a/main.ts
+++ b/main.ts
@@ -1,9 +1,22 @@
//import * as ts from "typescript";
import { main as pb } from "./msg.pb"
+import "./util";
+
+
+function load(argv: string[]): void {
+ console.log("Load argv", argv);
+}
V8Worker2.recv((ab: ArrayBuffer) => {
- let msg = pb.Msg.decode(new Uint8Array(ab));
- V8Worker2.print("msg.argv", msg.argv);
+ const msg = pb.Msg.decode(new Uint8Array(ab));
+ switch (msg.kind) {
+ case pb.Msg.MsgKind.LOAD:
+ load(msg.argv);
+ break;
+ default:
+ console.log("Unknown message", msg);
+ break;
+ }
});
V8Worker2.print("Hello");
diff --git a/tsconfig.json b/tsconfig.json
index aa81406c3..d0810f830 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,5 +1,6 @@
{
"compilerOptions": {
+ "allowJs": true,
"module": "commonjs",
"noImplicitAny": true,
"sourceMap": true,
@@ -7,7 +8,7 @@
"preserveConstEnums": true,
"declaration": true,
"target": "es5",
- "lib": ["es2015", "dom"],
+ "lib": ["es2015"],
"noEmit": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
@@ -19,5 +20,5 @@
"allowUnreachableCode": false,
"experimentalDecorators": true
},
- "include": ["*.ts"]
+ "include": ["*.ts", "*.js"]
}
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(" "));
+ }
+};