From f92f10b848d1be439094a84d5115e0100d685f6f Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 14 Jun 2018 01:40:35 +0200 Subject: [PATCH] deno2: pass argv to js --- deno2/deno.cc | 2 +- deno2/js/main.ts | 6 ++++++ deno2/main.cc | 23 ++++++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/deno2/deno.cc b/deno2/deno.cc index c344629b9f..bfd76f806f 100644 --- a/deno2/deno.cc +++ b/deno2/deno.cc @@ -24,9 +24,9 @@ IN THE SOFTWARE. #include #include -#include "v8/src/base/logging.h" #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" +#include "v8/src/base/logging.h" #include "./deno_internal.h" #include "include/deno.h" diff --git a/deno2/js/main.ts b/deno2/js/main.ts index 7508132937..baa19638fa 100644 --- a/deno2/js/main.ts +++ b/deno2/js/main.ts @@ -20,7 +20,13 @@ window["denoMain"] = () => { startMainJs: mainJs, startMainMap: mainMap } = msg; + denoPrint(`cwd: ${cwd}`); + denoPrint(`debugFlag: ${debugFlag}`); + + for (let i = 0; i < argv.length; i++) { + denoPrint(`argv[${i}] ${argv[i]}`); + } }; function typedArrayToArrayBuffer(ta: Uint8Array): ArrayBuffer { diff --git a/deno2/main.cc b/deno2/main.cc index 37e2719519..342b957b9f 100644 --- a/deno2/main.cc +++ b/deno2/main.cc @@ -5,30 +5,43 @@ #include #include -#include "v8/src/base/logging.h" #include "./msg.pb.h" #include "include/deno.h" +#include "v8/src/base/logging.h" + +static char** global_argv; +static int global_argc; void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) { printf("MessagesFromJS %s\n", channel); - char cwdbuf[1024]; - std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf))); - deno::Msg response; response.set_command(deno::Msg_Command_START); + + char cwdbuf[1024]; + std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf))); response.set_start_cwd(cwd); + for (int i = 0; i < global_argc; ++i) { + printf("arg %d %s\n", i, global_argv[i]); + response.add_start_argv(global_argv[i]); + } + printf("response.start_argv_size %d \n", response.start_argv_size()); + std::string output; CHECK(response.SerializeToString(&output)); - auto bufout = deno_buf{output.c_str(), output.length()}; + deno_buf bufout{output.c_str(), output.length()}; deno_set_response(d, bufout); } int main(int argc, char** argv) { deno_init(); + deno_set_flags(&argc, argv); + global_argv = argv; + global_argc = argc; + Deno* d = deno_new(NULL, MessagesFromJS); bool r = deno_execute(d, "deno_main.js", "denoMain();"); if (!r) {