Skip to content

Commit 616343b

Browse files
committed
debugger: use requireRepl() to load debugger repl
Currently, the debugger uses require('repl') to setup the repl. However, require.extensions is not available yet, causing a crash on tab completion of require('. This commit uses the module.requireRepl() method to bootstrap the repl. Fixes: nodejs/node-v0.x-archive#8359 PR-URL: #49 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 244a8f7 commit 616343b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/_debugger.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ var util = require('util'),
2525
path = require('path'),
2626
net = require('net'),
2727
vm = require('vm'),
28-
repl = require('repl'),
28+
module = require('module'),
29+
repl = module.requireRepl(),
2930
inherits = util.inherits,
3031
assert = require('assert'),
3132
spawn = require('child_process').spawn;
@@ -776,6 +777,7 @@ function Interface(stdin, stdout, args) {
776777
if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
777778
opts.useColors = false;
778779
}
780+
779781
this.repl = repl.start(opts);
780782

781783
// Do not print useless warning
@@ -1129,7 +1131,7 @@ Interface.prototype.list = function(delta) {
11291131
if (lineno == 1) {
11301132
// The first line needs to have the module wrapper filtered out of
11311133
// it.
1132-
var wrapper = require('module').wrapper[0];
1134+
var wrapper = module.wrapper[0];
11331135
lines[i] = lines[i].slice(wrapper.length);
11341136

11351137
client.currentSourceColumn -= wrapper.length;

test/simple/test-repl-tab-complete.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,18 @@ testMe.complete(' ', function(error, data) {
211211
testMe.complete('toSt', function(error, data) {
212212
assert.deepEqual(data, [['toString'], 'toSt']);
213213
});
214+
215+
// Tab complete provides built in libs for require()
216+
putIn.run(['.clear']);
217+
218+
testMe.complete('require(\'', function(error, data) {
219+
assert.strictEqual(error, null);
220+
repl._builtinLibs.forEach(function(lib) {
221+
assert.notStrictEqual(data[0].indexOf(lib), -1, lib + ' not found');
222+
});
223+
});
224+
225+
testMe.complete('require(\'n', function(error, data) {
226+
assert.strictEqual(error, null);
227+
assert.deepEqual(data, [['net'], 'n']);
228+
});

0 commit comments

Comments
 (0)