0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00
denoland-deno/main.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-05-14 01:19:23 -04:00
//import * as ts from "typescript";
2018-05-14 03:06:09 -04:00
import { main as pb } from "./msg.pb";
2018-05-14 01:30:56 -04:00
import "./util";
2018-05-14 02:50:55 -04:00
import { TextDecoder } from "text-encoding";
2018-05-14 01:30:56 -04:00
2018-05-14 02:50:55 -04:00
function readFileSync(filename: string): string {
const msg = pb.Msg.fromObject({
kind: pb.Msg.MsgKind.READ_FILE_SYNC,
path: filename
});
const ui8 = pb.Msg.encode(msg).finish();
const ab = ui8.buffer.slice(ui8.byteOffset, ui8.byteOffset + ui8.byteLength);
const resBuf = V8Worker2.send(ab as ArrayBuffer);
const res = pb.Msg.decode(new Uint8Array(resBuf));
if (res.error != null && res.error.length > 0) {
throw Error(res.error);
}
const decoder = new TextDecoder("utf8");
2018-05-14 03:06:09 -04:00
return decoder.decode(res.data);
2018-05-14 02:50:55 -04:00
}
2018-05-14 01:30:56 -04:00
function load(argv: string[]): void {
console.log("Load argv", argv);
2018-05-14 02:50:55 -04:00
const inputFn = argv[1];
const source = readFileSync(inputFn);
2018-05-14 03:06:09 -04:00
console.log("source", source);
2018-05-14 01:30:56 -04:00
}
2018-05-13 23:32:01 -04:00
2018-05-14 01:19:23 -04:00
V8Worker2.recv((ab: ArrayBuffer) => {
2018-05-14 01:30:56 -04:00
const msg = pb.Msg.decode(new Uint8Array(ab));
switch (msg.kind) {
case pb.Msg.MsgKind.LOAD:
load(msg.argv);
break;
default:
console.log("Unknown message", msg);
break;
}
2018-05-14 00:31:48 -04:00
});
2018-05-13 23:32:01 -04:00
2018-05-14 00:31:48 -04:00
V8Worker2.print("Hello");