Skip to content
Permalink
Browse files

pull stuff from core_improvements2

  • Loading branch information...
ry committed Mar 15, 2019
1 parent c7842b5 commit b2ae33375e4eb1f83db3204694f0f0d4fe15ed15
Showing with 1,952 additions and 1,253 deletions.
  1. +34 −22 js/dispatch.ts
  2. +5 −2 js/libdeno.ts
  3. +552 −0 js/msg_ring.ts
  4. +2 −0 js/os.ts
  5. +145 −0 src/cli.rs
  6. +9 −9 src/compiler.rs
  7. +0 −5 src/flags.rs
  8. +112 −684 src/isolate.rs
  9. +1 −1 src/isolate_init.rs
  10. +113 −0 src/isolate_state.rs
  11. +29 −24 src/js_errors.rs
  12. +36 −23 src/main.rs
  13. +39 −43 src/modules.rs
  14. +3 −2 src/msg.rs
  15. +655 −0 src/msg_ring.rs
  16. +148 −318 src/ops.rs
  17. +6 −22 src/permissions.rs
  18. +2 −40 src/resources.rs
  19. +10 −24 src/tokio_util.rs
  20. +51 −34 src/workers.rs
@@ -4,23 +4,30 @@ import * as flatbuffers from "./flatbuffers";
import * as msg from "gen/msg_generated";
import * as errors from "./errors";
import * as util from "./util";
import * as msgRing from "./msg_ring";

let nextCmdId = 0;
const promiseTable = new Map<number, util.Resolvable<msg.Base>>();

export function handleAsyncMsgFromRust(ui8: Uint8Array): void {
util.assert(ui8 != null && ui8.length > 0);
const bb = new flatbuffers.ByteBuffer(ui8);
const base = msg.Base.getRootAsBase(bb);
const cmdId = base.cmdId();
const promise = promiseTable.get(cmdId);
util.assert(promise != null, `Expecting promise in table. ${cmdId}`);
promiseTable.delete(cmdId);
const err = errors.maybeError(base);
if (err != null) {
promise!.reject(err);
} else {
promise!.resolve(base);
export function handleAsyncMsgFromRust(_unused: Uint8Array): void {
util.log("handleAsyncMsgFromRust start");
util.assert(_unused == null);
let i = 0;
let ui8: Uint8Array | null;
while ((ui8 = msgRing.rx.receive(Uint8Array)) !== null) {
util.log(`handleAsyncMsgFromRust ${i++}`);
const bb = new flatbuffers.ByteBuffer(ui8!);
const base = msg.Base.getRootAsBase(bb);
const cmdId = base.cmdId();
const promise = promiseTable.get(cmdId);
util.assert(promise != null, `Expecting promise in table. ${cmdId}`);
promiseTable.delete(cmdId);
const err = errors.maybeError(base);
if (err != null) {
promise!.reject(err);
} else {
promise!.resolve(base);
}
}
}

@@ -30,17 +37,23 @@ function sendInternal(
inner: flatbuffers.Offset,
data: undefined | ArrayBufferView,
sync = true
): [number, null | Uint8Array] {
): number {
const cmdId = nextCmdId++;
msg.Base.startBase(builder);
msg.Base.addInner(builder, inner);
msg.Base.addInnerType(builder, innerType);
msg.Base.addSync(builder, sync);
msg.Base.addCmdId(builder, cmdId);
builder.finish(msg.Base.endBase(builder));
const res = libdeno.send(builder.asUint8Array(), data);

const ui8 = builder.asUint8Array();
msgRing.tx.send(ui8);

// Somehow put this in the shared buffer.

libdeno.send(null, data);
builder.inUse = false;
return [cmdId, res];
return cmdId;
}

// @internal
@@ -50,8 +63,7 @@ export function sendAsync(
inner: flatbuffers.Offset,
data?: ArrayBufferView
): Promise<msg.Base> {
const [cmdId, resBuf] = sendInternal(builder, innerType, inner, data, false);
util.assert(resBuf == null);
const cmdId = sendInternal(builder, innerType, inner, data, false);
const promise = util.createResolvable<msg.Base>();
promiseTable.set(cmdId, promise);
return promise;
@@ -64,13 +76,13 @@ export function sendSync(
inner: flatbuffers.Offset,
data?: ArrayBufferView
): null | msg.Base {
const [cmdId, resBuf] = sendInternal(builder, innerType, inner, data, true);
const cmdId = sendInternal(builder, innerType, inner, data, true);
util.assert(cmdId >= 0);
if (resBuf == null) {
let resBuf: Uint8Array | null = msgRing.rx.receive(Uint8Array);
if (resBuf == null || resBuf.length === 0) {
return null;
} else {
const u8 = new Uint8Array(resBuf!);
const bb = new flatbuffers.ByteBuffer(u8);
const bb = new flatbuffers.ByteBuffer(resBuf);
const baseRes = msg.Base.getRootAsBase(bb);
errors.maybeThrowError(baseRes);
return baseRes;
@@ -19,11 +19,14 @@ interface EvalErrorInfo {
interface Libdeno {
recv(cb: MessageCallback): void;

send(control: ArrayBufferView, data?: ArrayBufferView): null | Uint8Array;
send(
control: null | ArrayBufferView,
data?: ArrayBufferView
): null | Uint8Array;

print(x: string, isErr?: boolean): void;

shared: ArrayBuffer;
shared: SharedArrayBuffer;

/** Evaluate provided code in the current context.
* It differs from eval(...) in that it does not create a new context.
Oops, something went wrong.

0 comments on commit b2ae333

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.