feat: op registration in core (#3002)

This commit is contained in:
Bartek Iwańczuk 2019-09-30 20:59:44 +02:00 committed by Ryan Dahl
parent ae26a9c7a2
commit ffbf0c20cc
8 changed files with 207 additions and 91 deletions

View file

@ -58,6 +58,13 @@ SharedQueue Binary Layout
Deno.core.recv(handleAsyncMsgFromRust);
}
function ops() {
// op id 0 is a special value to retreive the map of registered ops.
const opsMapBytes = Deno.core.send(0, new Uint8Array([]), null);
const opsMapJson = String.fromCharCode.apply(null, opsMapBytes);
return JSON.parse(opsMapJson);
}
function assert(cond) {
if (!cond) {
throw Error("assert");
@ -84,7 +91,6 @@ SharedQueue Binary Layout
return shared32[INDEX_NUM_RECORDS] - shared32[INDEX_NUM_SHIFTED_OFF];
}
// TODO(ry) rename to setMeta
function setMeta(index, end, opId) {
shared32[INDEX_OFFSETS + 2 * index] = end;
shared32[INDEX_OFFSETS + 2 * index + 1] = opId;
@ -189,7 +195,8 @@ SharedQueue Binary Layout
push,
reset,
shift
}
},
ops
};
assert(window[GLOBAL_NAMESPACE] != null);