Browse Source

repl: fix _debugger by properly proxying repl

The _debugger module uses the internal REPL module, but expects
to receive the userland REPL module. This fixes the breakage that
occurs by proxying the userland REPL module through the internal
module.

It also fixes an unintended in-REPL bug, where require(node-module)
was not resolving correctly.

PR-URL: https://github.com/iojs/io.js/pull/1605
Reviewed-By: Roman Reiss <me@silverwind.io>
v2.0.2
Chris Dickinson 10 years ago
parent
commit
051d482b15
  1. 21
      lib/internal/repl.js
  2. 14
      lib/repl.js
  3. 2
      src/node.js

21
lib/internal/repl.js

@ -1,29 +1,22 @@
'use strict'; 'use strict';
module.exports = {createRepl: createRepl};
const Interface = require('readline').Interface; const Interface = require('readline').Interface;
const REPL = require('repl'); const REPL = require('repl');
const path = require('path'); const path = require('path');
module.exports = Object.create(REPL);
module.exports.createInternalRepl = createRepl;
// XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary. // XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary.
// The debounce is to guard against code pasted into the REPL. // The debounce is to guard against code pasted into the REPL.
const kDebounceHistoryMS = 15; const kDebounceHistoryMS = 15;
try { // XXX(chrisdickinson): hack to make sure that the internal debugger
// hack for require.resolve("./relative") to work properly. // uses the original repl.
module.filename = path.resolve('repl'); function replStart() {
} catch (e) { return REPL.start.apply(REPL, arguments);
// path.resolve('repl') fails when the current working directory has been
// deleted. Fall back to the directory name of the (absolute) executable
// path. It's not really correct but what are the alternatives?
const dirname = path.dirname(process.execPath);
module.filename = path.resolve(dirname, 'repl');
} }
// hack for repl require to work properly with node_modules folders
module.paths = require('module')._nodeModulePaths(module.filename);
function createRepl(env, cb) { function createRepl(env, cb) {
const opts = { const opts = {
ignoreUndefined: false, ignoreUndefined: false,

14
lib/repl.js

@ -32,6 +32,20 @@ const Console = require('console').Console;
const domain = require('domain'); const domain = require('domain');
const debug = util.debuglog('repl'); const debug = util.debuglog('repl');
try {
// hack for require.resolve("./relative") to work properly.
module.filename = path.resolve('repl');
} catch (e) {
// path.resolve('repl') fails when the current working directory has been
// deleted. Fall back to the directory name of the (absolute) executable
// path. It's not really correct but what are the alternatives?
const dirname = path.dirname(process.execPath);
module.filename = path.resolve(dirname, 'repl');
}
// hack for repl require to work properly with node_modules folders
module.paths = require('module')._nodeModulePaths(module.filename);
// If obj.hasOwnProperty has been overridden, then calling // If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break. // obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707 // See: https://github.com/joyent/node/issues/1707

2
src/node.js

@ -130,7 +130,7 @@
// If -i or --interactive were passed, or stdin is a TTY. // If -i or --interactive were passed, or stdin is a TTY.
if (process._forceRepl || NativeModule.require('tty').isatty(0)) { if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
// REPL // REPL
Module.requireRepl().createRepl(process.env, function(err, repl) { Module.requireRepl().createInternalRepl(process.env, function(err, repl) {
if (err) { if (err) {
throw err; throw err;
} }

Loading…
Cancel
Save