From 8b92223ed1cf670c77ee2a627e40c01f24a63af5 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 10 Dec 2019 18:17:01 +0100 Subject: [PATCH] repl: simplify code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simplifies some repl code and removes a code branch that is unreachable. PR-URL: https://github.com/nodejs/node/pull/30907 Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott --- lib/repl.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index eeee83fee3c70f..1e7ab29bac03ab 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -953,7 +953,7 @@ REPLServer.prototype.createContext = function() { } const module = new CJSModule(''); - module.paths = CJSModule._resolveLookupPaths('', parentModule) || []; + module.paths = CJSModule._resolveLookupPaths('', parentModule); ObjectDefineProperty(context, 'module', { configurable: true, @@ -1307,21 +1307,17 @@ function complete(line, callback) { } // Works for non-objects try { - let sentinel = 5; let p; if (typeof obj === 'object' || typeof obj === 'function') { p = ObjectGetPrototypeOf(obj); } else { p = obj.constructor ? obj.constructor.prototype : null; } - while (p !== null) { + // Circular refs possible? Let's guard against that. + let sentinel = 5; + while (p !== null && sentinel-- !== 0) { memberGroups.push(filteredOwnPropertyNames(p)); p = ObjectGetPrototypeOf(p); - // Circular refs possible? Let's guard against that. - sentinel--; - if (sentinel <= 0) { - break; - } } } catch {} }