Skip to content
Permalink
Browse files

lint

  • Loading branch information...
ry committed Mar 15, 2019
1 parent 66a491b commit c7842b55460d12781c8d6fbb4b6d01e90baab79f
Showing with 35 additions and 36 deletions.
  1. +3 −5 core/http_bench.js
  2. +30 −30 core/shared_queue.js
  3. +0 −1 core/shared_queue.rs
  4. +2 −0 core/shared_queue_test.js
@@ -6,10 +6,6 @@ const OP_ACCEPT = 2;
const OP_READ = 3;
const OP_WRITE = 4;
const OP_CLOSE = 5;
const INDEX_START = 0;
const INDEX_END = 1;
const NUM_RECORDS = 128;
const RECORD_SIZE = 4;

function assert(cond) {
if (!cond) {
@@ -82,7 +78,9 @@ function recv() {
/** Returns u32 number */
function sendSync(opId, arg) {
send(0, opId, arg);
return recv().result;
const record = recv();
assert(recv() == null);
return record.result;
}

function handleAsyncMsgFromRust() {
@@ -36,38 +36,14 @@
shared32[INDEX_HEAD] = HEAD_INIT;
}

function push(buf) {
let off = head();
let end = off + buf.byteLength;
let index = numRecords();
if (end > shared32.byteLength) {
console.log("shared_queue.ts push fail");
return false;
}
setEnd(index, end);
assert(end - off == buf.byteLength);
sharedBytes.set(buf, off);
shared32[INDEX_NUM_RECORDS] += 1;
shared32[INDEX_HEAD] = end;
return true;
}

/// Returns null if empty.
function shift() {
let i = shared32[INDEX_NUM_SHIFTED_OFF];
if (i >= numRecords()) {
return null;
}
let off = getOffset(i);
let end = getEnd(i);
shared32[INDEX_NUM_SHIFTED_OFF] += 1;
return sharedBytes.subarray(off, end);
}

function head() {
return shared32[INDEX_HEAD];
}

function numRecords() {
return shared32[INDEX_NUM_RECORDS];
}

function setEnd(index, end) {
shared32[INDEX_OFFSETS + index] = end;
}
@@ -92,8 +68,32 @@
}
}

function numRecords() {
return shared32[INDEX_NUM_RECORDS];
function push(buf) {
let off = head();
let end = off + buf.byteLength;
let index = numRecords();
if (end > shared32.byteLength) {
console.log("shared_queue.ts push fail");
return false;
}
setEnd(index, end);
assert(end - off == buf.byteLength);
sharedBytes.set(buf, off);
shared32[INDEX_NUM_RECORDS] += 1;
shared32[INDEX_HEAD] = end;
return true;
}

/// Returns null if empty.
function shift() {
let i = shared32[INDEX_NUM_SHIFTED_OFF];
if (i >= numRecords()) {
return null;
}
let off = getOffset(i);
let end = getEnd(i);
shared32[INDEX_NUM_SHIFTED_OFF] += 1;
return sharedBytes.subarray(off, end);
}

function activeRecords() {
@@ -231,7 +231,6 @@ mod tests {
isolate
.execute("shared_queue_test.js", include_str!("shared_queue_test.js")),
);
js_check(isolate.execute("<main>", "main()"));
assert_eq!(Ok(Async::Ready(())), isolate.poll());
}
}
@@ -61,3 +61,5 @@ function main() {
assert(q.activeRecords() == 0);
libdeno.print("shared_queue_test.js ok\n");
}

main();

0 comments on commit c7842b5

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.