Skip to content

Commit 6188650

Browse files
BridgeARtargos
authored andcommitted
repl: simplify code
This simplifies some repl code and removes a code branch that is unreachable. PR-URL: #30907 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 9b893e1 commit 6188650

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/repl.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ REPLServer.prototype.createContext = function() {
965965
}
966966

967967
const module = new CJSModule('<repl>');
968-
module.paths = CJSModule._resolveLookupPaths('<repl>', parentModule) || [];
968+
module.paths = CJSModule._resolveLookupPaths('<repl>', parentModule);
969969

970970
ObjectDefineProperty(context, 'module', {
971971
configurable: true,
@@ -1321,21 +1321,17 @@ function complete(line, callback) {
13211321
}
13221322
// Works for non-objects
13231323
try {
1324-
let sentinel = 5;
13251324
let p;
13261325
if (typeof obj === 'object' || typeof obj === 'function') {
13271326
p = ObjectGetPrototypeOf(obj);
13281327
} else {
13291328
p = obj.constructor ? obj.constructor.prototype : null;
13301329
}
1331-
while (p !== null) {
1330+
// Circular refs possible? Let's guard against that.
1331+
let sentinel = 5;
1332+
while (p !== null && sentinel-- !== 0) {
13321333
memberGroups.push(filteredOwnPropertyNames(p));
13331334
p = ObjectGetPrototypeOf(p);
1334-
// Circular refs possible? Let's guard against that.
1335-
sentinel--;
1336-
if (sentinel <= 0) {
1337-
break;
1338-
}
13391335
}
13401336
} catch {}
13411337
}

0 commit comments

Comments
 (0)