summaryrefslogtreecommitdiff
path: root/deno2/js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-06-13 19:38:22 +0200
committerRyan Dahl <ry@tinyclouds.org>2018-06-14 14:19:17 +0200
commit4ac67cf3435b3e15f95fadc20c98e37abf706ea4 (patch)
tree651b18c568e6ca8130d3d37de60a6a44e12e855b /deno2/js
parentf97216609d1705a21ddbe6ca3efb04817f026fc3 (diff)
Demo protobufs in deno2.
Adds deno_set_response() to allow stack allocated responses.
Diffstat (limited to 'deno2/js')
-rw-r--r--deno2/js/main.ts31
1 files changed, 26 insertions, 5 deletions
diff --git a/deno2/js/main.ts b/deno2/js/main.ts
index c5d490b0b..750813293 100644
--- a/deno2/js/main.ts
+++ b/deno2/js/main.ts
@@ -4,11 +4,32 @@ import * as ts from "typescript";
const globalEval = eval;
const window = globalEval("this");
+
window["denoMain"] = () => {
- denoPrint("Hello world");
- const msg = pb.Msg.fromObject({});
- denoPrint(`msg.command: ${msg.command}`);
denoPrint(`ts.version: ${ts.version}`);
- denoPrint("Hello world from foo");
- return "foo";
+ const res = denoPub("startDeno2", emptyArrayBuffer());
+ //denoPrint(`after`);
+ const resUi8 = new Uint8Array(res);
+ denoPrint(`before`);
+ const msg = pb.Msg.decode(resUi8);
+ denoPrint(`after`);
+ const {
+ startCwd: cwd,
+ startArgv: argv,
+ startDebugFlag: debugFlag,
+ startMainJs: mainJs,
+ startMainMap: mainMap
+ } = msg;
+ denoPrint(`cwd: ${cwd}`);
};
+
+function typedArrayToArrayBuffer(ta: Uint8Array): ArrayBuffer {
+ return ta.buffer.slice(
+ ta.byteOffset,
+ ta.byteOffset + ta.byteLength
+ ) as ArrayBuffer;
+}
+
+function emptyArrayBuffer(): ArrayBuffer {
+ return typedArrayToArrayBuffer(new Uint8Array([]));
+}