1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00
denoland-deno/js/main.ts
2018-07-04 16:43:08 -04:00

42 lines
1.1 KiB
TypeScript

// tslint:disable-next-line:no-reference
/// <reference path="deno.d.ts" />
import * as ts from "typescript";
import { flatbuffers } from "flatbuffers";
import { deno as fbs } from "./msg_generated";
const globalEval = eval;
const window = globalEval("this");
window["denoMain"] = () => {
deno.print(`ts.version: ${ts.version}`);
const res = deno.send("startDeno2", emptyArrayBuffer());
// deno.print(`after`);
const resUi8 = new Uint8Array(res);
const bb = new flatbuffers.ByteBuffer(resUi8);
const msg = fbs.Msg.getRootAsMsg(bb);
// startDebugFlag: debugFlag,
// startMainJs: mainJs,
// startMainMap: mainMap
const cwd = msg.startCwd();
deno.print(`cwd: ${cwd}`);
const argv: string[] = [];
for (let i = 0; i < msg.startArgvLength(); i++) {
const arg = msg.startArgv(i);
deno.print(`argv[${i}] ${arg}`);
}
};
function typedArrayToArrayBuffer(ta: Uint8Array): ArrayBuffer {
return ta.buffer.slice(
ta.byteOffset,
ta.byteOffset + ta.byteLength
) as ArrayBuffer;
}
function emptyArrayBuffer(): ArrayBuffer {
return typedArrayToArrayBuffer(new Uint8Array([]));
}