From eef552774e1c78b113e1b543cb9463cd64ecd5ed Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 21 Aug 2013 17:19:41 -0700 Subject: [PATCH] vm: Put back display_errors flag This is an important part of the repl use-case. TODO: The arg parsing in vm.runIn*Context() is rather wonky. It would be good to move more of that into the Script class, and/or an options object. --- lib/repl.js | 4 +- lib/vm.js | 26 +++++----- src/node_contextify.cc | 29 +++++++++-- test/simple/test-repl-syntax-error-handling.js | 69 ++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 test/simple/test-repl-syntax-error-handling.js diff --git a/lib/repl.js b/lib/repl.js index cf33228..782e79e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -113,9 +113,9 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { var err, result; try { if (self.useGlobal) { - result = vm.runInThisContext(code, file); + result = vm.runInThisContext(code, file, 0, false); } else { - result = vm.runInContext(code, context, file); + result = vm.runInContext(code, context, file, 0, false); } } catch (e) { err = e; diff --git a/lib/vm.js b/lib/vm.js index 5dd1dde..c71bb81 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -30,15 +30,15 @@ var util = require('util'); // - makeContext(sandbox) // From this we build the entire documented API. -Script.prototype.runInNewContext = function(initSandbox, timeout) { +Script.prototype.runInNewContext = function(initSandbox, timeout, disp) { var context = exports.createContext(initSandbox); - return this.runInContext(context, timeout); + return this.runInContext(context, timeout, disp); }; exports.Script = Script; -exports.createScript = function(code, filename) { - return new Script(code, filename); +exports.createScript = function(code, filename, disp) { + return new Script(code, filename, disp); }; exports.createContext = function(initSandbox) { @@ -51,17 +51,17 @@ exports.createContext = function(initSandbox) { return initSandbox; }; -exports.runInContext = function(code, sandbox, filename, timeout) { - var script = exports.createScript(code, filename); - return script.runInContext(sandbox, timeout); +exports.runInContext = function(code, sandbox, filename, timeout, disp) { + var script = exports.createScript(code, filename, disp); + return script.runInContext(sandbox, timeout, disp); }; -exports.runInNewContext = function(code, sandbox, filename, timeout) { - var script = exports.createScript(code, filename); - return script.runInNewContext(sandbox, timeout); +exports.runInNewContext = function(code, sandbox, filename, timeout, disp) { + var script = exports.createScript(code, filename, disp); + return script.runInNewContext(sandbox, timeout, disp); }; -exports.runInThisContext = function(code, filename, timeout) { - var script = exports.createScript(code, filename); - return script.runInThisContext(timeout); +exports.runInThisContext = function(code, filename, timeout, disp) { + var script = exports.createScript(code, filename, disp); + return script.runInThisContext(timeout, disp); }; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 002cffe..b2b7324 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -329,6 +329,7 @@ class ContextifyScript : ObjectWrap { contextify_script->Wrap(args.Holder()); Local code = args[0]->ToString(); Local filename = GetFilenameArg(args, 1); + bool display_exception = GetDisplayArg(args, 2); Local context = Context::GetCurrent(); Context::Scope context_scope(context); @@ -338,7 +339,8 @@ class ContextifyScript : ObjectWrap { Local