From b6c0ad15fae9f747dbf91525caf6189beb358f76 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 29 May 2018 03:43:54 -0400 Subject: [PATCH] Add denoMain --- main.go | 3 +++ main.ts | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 349926396e..9e5b6349ca 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 75f5780ce5..ddcbebb13c 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(); + }); +} +