summaryrefslogtreecommitdiff
path: root/core/core.js
diff options
context:
space:
mode:
authorDe Rouck Antoine <pulsead94@gmail.com>2020-11-21 14:19:43 +0100
committerGitHub <noreply@github.com>2020-11-21 14:19:43 +0100
commit671f96025a477ea9c47b6ea8915a90f98084cca9 (patch)
tree1c139b264fd33ae5039d513d900cdf1e83f65f39 /core/core.js
parentb63fe3f35c6dd06059e3d34e566b95ed9ccf2724 (diff)
refactor(core): Improve code readability in core.js (#8345)
Diffstat (limited to 'core/core.js')
-rw-r--r--core/core.js58
1 files changed, 28 insertions, 30 deletions
diff --git a/core/core.js b/core/core.js
index 2e01da0d2..8be7dc4ff 100644
--- a/core/core.js
+++ b/core/core.js
@@ -97,26 +97,23 @@ SharedQueue Binary Layout
}
function getMeta(index) {
- if (index < numRecords()) {
- const buf = shared32[INDEX_OFFSETS + 2 * index];
- const opId = shared32[INDEX_OFFSETS + 2 * index + 1];
- return [opId, buf];
- } else {
+ if (index >= numRecords()) {
return null;
}
+ const buf = shared32[INDEX_OFFSETS + 2 * index];
+ const opId = shared32[INDEX_OFFSETS + 2 * index + 1];
+ return [opId, buf];
}
function getOffset(index) {
- if (index < numRecords()) {
- if (index == 0) {
- return HEAD_INIT;
- } else {
- const prevEnd = shared32[INDEX_OFFSETS + 2 * (index - 1)];
- return (prevEnd + 3) & ~3;
- }
- } else {
+ if (index >= numRecords()) {
return null;
}
+ if (index == 0) {
+ return HEAD_INIT;
+ }
+ const prevEnd = shared32[INDEX_OFFSETS + 2 * (index - 1)];
+ return (prevEnd + 3) & ~3;
}
function push(opId, buf) {
@@ -124,7 +121,9 @@ SharedQueue Binary Layout
const end = off + buf.byteLength;
const alignedEnd = (end + 3) & ~3;
const index = numRecords();
- if (alignedEnd > shared32.byteLength || index >= MAX_RECORDS) {
+ const shouldNotPush = alignedEnd > shared32.byteLength ||
+ index >= MAX_RECORDS;
+ if (shouldNotPush) {
// console.log("shared_queue.js push fail");
return false;
}
@@ -170,15 +169,15 @@ SharedQueue Binary Layout
if (buf) {
// This is the overflow_response case of deno::JsRuntime::poll().
asyncHandlers[opId](buf);
- } else {
- while (true) {
- const opIdBuf = shift();
- if (opIdBuf == null) {
- break;
- }
- assert(asyncHandlers[opIdBuf[0]] != null);
- asyncHandlers[opIdBuf[0]](opIdBuf[1]);
+ return;
+ }
+ while (true) {
+ const opIdBuf = shift();
+ if (opIdBuf == null) {
+ break;
}
+ assert(asyncHandlers[opIdBuf[0]] != null);
+ asyncHandlers[opIdBuf[0]](opIdBuf[1]);
}
}
@@ -214,15 +213,14 @@ SharedQueue Binary Layout
function processResponse(res) {
if ("ok" in res) {
return res.ok;
- } else {
- const ErrorClass = getErrorClass(res.err.className);
- if (!ErrorClass) {
- throw new Error(
- `Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
- );
- }
- throw new ErrorClass(res.err.message);
}
+ const ErrorClass = getErrorClass(res.err.className);
+ if (!ErrorClass) {
+ throw new Error(
+ `Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
+ );
+ }
+ throw new ErrorClass(res.err.message);
}
async function jsonOpAsync(opName, args = {}, ...zeroCopy) {