Skip to content

Commit

Permalink
fix json dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Apr 15, 2020
1 parent fdc303a commit a2c146b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {

// Main snapshot
let bundle_path = PathBuf::from("super_runtime.js");
println!("cargo:rerun-if-changed={}", bundle_path.display());
let snapshot_path = o.join("CLI_SNAPSHOT.bin");

let main_module_name = deno_typescript::compile_bundle(
Expand Down
18 changes: 9 additions & 9 deletions cli/super_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@
};

// Using an object without a prototype because `Map` was causing GC problems.
const promiseTableMin = Object.create(null);
const promiseTable = Object.create(null);

// Note it's important that promiseId starts at 1 instead of 0, because sync
// messages are indicated with promiseId 0. If we ever add wrap around logic for
Expand Down Expand Up @@ -1130,8 +1130,8 @@
function asyncMsgFromRustMinimal(ui8) {
const record = recordFromBufMinimal(ui8);
const { promiseId } = record;
const promise = promiseTableMin[promiseId];
delete promiseTableMin[promiseId];
const promise = promiseTable[promiseId];
delete promiseTable[promiseId];
assert(promise);
promise.resolve(record);
}
Expand All @@ -1149,7 +1149,7 @@
promise.resolve(record);
} else {
// Async result.
promiseTableMin[promiseId] = promise;
promiseTable[promiseId] = promise;
}

const res = await promise;
Expand Down Expand Up @@ -1183,7 +1183,7 @@
}

function asyncMsgFromRustJson(resUi8) {
const res = decode(resUi8);
const res = jsonDecode(resUi8);
assert(res.promiseId != null);

const promise = promiseTable[res.promiseId];
Expand All @@ -1195,10 +1195,10 @@
function sendSyncJson(opName, args = {}, zeroCopy) {
const opId = OPS_CACHE[opName];
log("sendSync", opName, opId);
const argsUi8 = encode(args);
const argsUi8 = jsonEncode(args);
const resUi8 = core.dispatch(opId, argsUi8, zeroCopy);
assert(resUi8 != null);
const res = decode(resUi8);
const res = jsonDecode(resUi8);
assert(res.promiseId == null);
return unwrapResponseJson(res);
}
Expand All @@ -1210,11 +1210,11 @@
args = Object.assign(args, { promiseId });
const promise = createResolvable();

const argsUi8 = encode(args);
const argsUi8 = jsonEncode(args);
const buf = core.dispatch(opId, argsUi8, zeroCopy);
if (buf) {
// Sync result.
const res = decode(buf);
const res = jsonDecode(buf);
promise.resolve(res);
} else {
// Async result.
Expand Down

0 comments on commit a2c146b

Please sign in to comment.