From 616343bc61d389cae571191c52abe97708878570 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 26 Nov 2014 10:46:59 -0500 Subject: [PATCH] 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: https://github.com/joyent/node/issues/8359 PR-URL: https://github.com/iojs/io.js/pull/49 Reviewed-By: Ben Noordhuis --- lib/_debugger.js | 6 ++++-- test/simple/test-repl-tab-complete.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index cd8d68898..2e708db76 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -25,7 +25,8 @@ var util = require('util'), path = require('path'), net = require('net'), vm = require('vm'), - repl = require('repl'), + module = require('module'), + repl = module.requireRepl(), inherits = util.inherits, assert = require('assert'), spawn = require('child_process').spawn; @@ -776,6 +777,7 @@ function Interface(stdin, stdout, args) { if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) { opts.useColors = false; } + this.repl = repl.start(opts); // Do not print useless warning @@ -1129,7 +1131,7 @@ Interface.prototype.list = function(delta) { if (lineno == 1) { // The first line needs to have the module wrapper filtered out of // it. - var wrapper = require('module').wrapper[0]; + var wrapper = module.wrapper[0]; lines[i] = lines[i].slice(wrapper.length); client.currentSourceColumn -= wrapper.length; diff --git a/test/simple/test-repl-tab-complete.js b/test/simple/test-repl-tab-complete.js index 684063831..48df4033d 100644 --- a/test/simple/test-repl-tab-complete.js +++ b/test/simple/test-repl-tab-complete.js @@ -211,3 +211,18 @@ testMe.complete(' ', function(error, data) { testMe.complete('toSt', function(error, data) { assert.deepEqual(data, [['toString'], 'toSt']); }); + +// Tab complete provides built in libs for require() +putIn.run(['.clear']); + +testMe.complete('require(\'', function(error, data) { + assert.strictEqual(error, null); + repl._builtinLibs.forEach(function(lib) { + assert.notStrictEqual(data[0].indexOf(lib), -1, lib + ' not found'); + }); +}); + +testMe.complete('require(\'n', function(error, data) { + assert.strictEqual(error, null); + assert.deepEqual(data, [['net'], 'n']); +}); -- 2.34.1