branch: externals/drepl commit 982672ceabb799ae4a922f03e07ae9a181fc86f2 Author: Augusto Stoffel <arstof...@gmail.com> Commit: Augusto Stoffel <arstof...@gmail.com>
Improve operation handler lookup code in Node.js --- drepl-node.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drepl-node.js b/drepl-node.js index 222e0ef1e1..9831dafc58 100644 --- a/drepl-node.js +++ b/drepl-node.js @@ -27,7 +27,7 @@ class dREPL extends repl.REPLServer { this.sendMsg({ op: "log", text }) } - ops = { + ops = Object.assign(Object.create(null), { complete: (msg) => { const { id, code, pos } = msg const cb = (err, data) => { @@ -71,7 +71,7 @@ class dREPL extends repl.REPLServer { if (id) { this.sendMsg({ id }) } this.sendMsg({ op: "status", status: "ready" }) } - } + }) onLine(buffer, line) { if (line.startsWith("\x1b+")) { @@ -82,9 +82,8 @@ class dREPL extends repl.REPLServer { buffer.push(line.slice(2)) const msg = JSON.parse(buffer.join("")) buffer.length = 0 - const { op } = msg - const f = this.ops.hasOwnProperty(op) ? this.ops[op] : this.ops.default - f.bind(this)(msg) + const f = this.ops[msg.op] || this.ops.default + f(msg) return } this.sendLog("Invalid message: " + JSON.stringify(line))