Skip to content

Commit dcc72b7

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

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
@@ -961,7 +961,7 @@ REPLServer.prototype.createContext = function() {
961961
}
962962

963963
const module = new CJSModule('<repl>');
964-
module.paths = CJSModule._resolveLookupPaths('<repl>', parentModule) || [];
964+
module.paths = CJSModule._resolveLookupPaths('<repl>', parentModule);
965965

966966
ObjectDefineProperty(context, 'module', {
967967
configurable: true,
@@ -1317,21 +1317,17 @@ function complete(line, callback) {
13171317
}
13181318
// Works for non-objects
13191319
try {
1320-
let sentinel = 5;
13211320
let p;
13221321
if (typeof obj === 'object' || typeof obj === 'function') {
13231322
p = ObjectGetPrototypeOf(obj);
13241323
} else {
13251324
p = obj.constructor ? obj.constructor.prototype : null;
13261325
}
1327-
while (p !== null) {
1326+
// Circular refs possible? Let's guard against that.
1327+
let sentinel = 5;
1328+
while (p !== null && sentinel-- !== 0) {
13281329
memberGroups.push(filteredOwnPropertyNames(p));
13291330
p = ObjectGetPrototypeOf(p);
1330-
// Circular refs possible? Let's guard against that.
1331-
sentinel--;
1332-
if (sentinel <= 0) {
1333-
break;
1334-
}
13351331
}
13361332
} catch {}
13371333
}

0 commit comments

Comments
 (0)