summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go3
-rw-r--r--main.ts48
2 files changed, 31 insertions, 20 deletions
diff --git a/main.go b/main.go
index 349926396..9e5b6349c 100644
--- a/main.go
+++ b/main.go
@@ -64,6 +64,9 @@ func main() {
cwd, err := os.Getwd()
check(err)
+ err = worker.Load("deno_main.js", "denoMain()")
+ exitOnError(err)
+
var command = Msg_START // TODO use proto3
PubMsg("start", &Msg{
Command: command,
diff --git a/main.ts b/main.ts
index 75f5780ce..ddcbebb13 100644
--- a/main.ts
+++ b/main.ts
@@ -17,27 +17,35 @@ import { initFetch } from "./fetch";
export let debug = false;
let startCalled = false;
-dispatch.sub("start", (payload: Uint8Array) => {
- if (startCalled) {
- throw Error("start message received more than once!");
- }
- startCalled = true;
-
- const msg = pb.Msg.decode(payload);
- const cwd = msg.startCwd;
- const argv = msg.startArgv;
- const debugFlag = msg.startDebugFlag;
- const mainJs = msg.startMainJs;
- const mainMap = msg.startMainMap;
-
- debug = debugFlag;
- util.log("start", { cwd, argv, debugFlag });
+// denoMain is needed to allow hooks into the system.
+// Also eventual snapshot support needs it.
+(window as any)["denoMain"] = () => {
+ delete (window as any)["denoMain"];
initTimers();
initFetch();
- runtime.setup(mainJs, mainMap);
- const inputFn = argv[0];
- const mod = runtime.resolveModule(inputFn, `${cwd}/`);
- mod.compileAndRun();
-});
+ dispatch.sub("start", (payload: Uint8Array) => {
+ if (startCalled) {
+ throw Error("start message received more than once!");
+ }
+ startCalled = true;
+
+ const msg = pb.Msg.decode(payload);
+ const cwd = msg.startCwd;
+ const argv = msg.startArgv;
+ const debugFlag = msg.startDebugFlag;
+ const mainJs = msg.startMainJs;
+ const mainMap = msg.startMainMap;
+
+ debug = debugFlag;
+ util.log("start", { cwd, argv, debugFlag });
+
+ runtime.setup(mainJs, mainMap);
+
+ const inputFn = argv[0];
+ const mod = runtime.resolveModule(inputFn, `${cwd}/`);
+ mod.compileAndRun();
+ });
+}
+