mirror of
https://github.com/denoland/deno.git
synced 2024-10-30 09:08:00 -04:00
24b0e91d80
* send()/recv() now operate on TypedArrays rather than ArrayBuffers. * Remove a copy (through ArrayBuffer.slice()) from the send path. * Remove a copy (through v8::ArrayBuffer::New()) from the return path. * After moving a buffer from JS to native, the ArrayBuffer object and it's views are made inaccessible ('neutered'). * `struct deno_buf` now holds two [ptr, length] tuples, one for the actual memory allocation, and one for the logical data contained therein. This is necessary because flatbuffers fills it's buffer bottom-up, so the serialized blob doesn't start at beginning of the buffer, but somewhere in the middle.
71 lines
2.1 KiB
TypeScript
71 lines
2.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";
|
|
import { assert } from "./util";
|
|
|
|
// import * as runtime from "./runtime";
|
|
|
|
const globalEval = eval;
|
|
const window = globalEval("this");
|
|
|
|
let cmdIdCounter = 0;
|
|
function assignCmdId(): number {
|
|
// TODO(piscisaureus) Safely re-use so they don't overflow.
|
|
const cmdId = ++cmdIdCounter;
|
|
assert(cmdId < 2 ** 32, "cmdId overflow");
|
|
return cmdId;
|
|
}
|
|
|
|
function startMsg(cmdId: number): Uint8Array {
|
|
const builder = new flatbuffers.Builder();
|
|
const msg = fbs.Start.createStart(builder, 0);
|
|
fbs.Base.startBase(builder);
|
|
fbs.Base.addCmdId(builder, cmdId);
|
|
fbs.Base.addMsg(builder, msg);
|
|
fbs.Base.addMsgType(builder, fbs.Any.Start);
|
|
builder.finish(fbs.Base.endBase(builder));
|
|
return builder.asUint8Array();
|
|
}
|
|
|
|
window["denoMain"] = () => {
|
|
deno.print(`ts.version: ${ts.version}`);
|
|
|
|
// First we send an empty "Start" message to let the privlaged side know we
|
|
// are ready. The response should be a "StartRes" message containing the CLI
|
|
// argv and other info.
|
|
const cmdId = assignCmdId();
|
|
const res = deno.send(startMsg(cmdId));
|
|
|
|
// TODO(ry) Remove this conditional once main.rs gets up to speed.
|
|
if (res == null) {
|
|
console.log(`The 'Start' message got a null response. Normally this would
|
|
be an error but main.rs currently does this."); Exiting without error.`);
|
|
return;
|
|
}
|
|
|
|
// Deserialize res into startResMsg.
|
|
const bb = new flatbuffers.ByteBuffer(res);
|
|
const base = fbs.Base.getRootAsBase(bb);
|
|
assert(base.cmdId() === cmdId);
|
|
assert(fbs.Any.StartRes === base.msgType());
|
|
const startResMsg = new fbs.StartRes();
|
|
assert(base.msg(startResMsg) != null);
|
|
|
|
const cwd = startResMsg.cwd();
|
|
deno.print(`cwd: ${cwd}`);
|
|
|
|
const argv: string[] = [];
|
|
for (let i = 0; i < startResMsg.argvLength(); i++) {
|
|
argv.push(startResMsg.argv(i));
|
|
}
|
|
deno.print(`argv ${argv}`);
|
|
|
|
/* TODO(ry) Uncomment to test further message passing.
|
|
const inputFn = argv[0];
|
|
const mod = runtime.resolveModule(inputFn, `${cwd}/`);
|
|
mod.compileAndRun();
|
|
*/
|
|
};
|