Skip to content

Commit

Permalink
vm: remove display_error hack, add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
apaprocki authored and bnoordhuis committed Jul 29, 2013
1 parent 1710ceb commit 055e4fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/node_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,6 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
timeout = args[timeout_index]->Uint32Value();
}

const int display_error_index = timeout_index +
(timeout_flag == noTimeout ? 0 : 1);
bool display_error = false;
if (args.Length() > display_error_index &&
args[display_error_index]->IsBoolean() &&
args[display_error_index]->BooleanValue() == true) {
display_error = true;
}

Local<Context> context = Context::GetCurrent();

Local<Array> keys;
Expand Down Expand Up @@ -389,10 +380,6 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
script = output_flag == returnResult ? Script::Compile(code, filename)
: Script::New(code, filename);
if (script.IsEmpty()) {
// FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
if (display_error) DisplayExceptionLine(try_catch.Message());

// Hack because I can't get a proper stacktrace on SyntaxError
try_catch.ReThrow();
return;
}
Expand Down Expand Up @@ -420,7 +407,6 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
return ThrowError("Script execution timed out.");
}
if (result.IsEmpty()) {
if (display_error) DisplayExceptionLine(try_catch.Message());
try_catch.ReThrow();
return;
}
Expand Down
31 changes: 31 additions & 0 deletions test/message/vm_syntax_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var vm = require('vm');

var context = {
run: function() {
vm.runInNewContext('invalid ?= 1', context, 'bar');
}
};
vm.runInNewContext('run()', context, 'foo');
6 changes: 6 additions & 0 deletions test/message/vm_syntax_error.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bar:1
invalid ?= 1
^
SyntaxError: Unexpected token =
at context.run (*test*message*vm_syntax_error.js:*:*)
at foo:1:1

0 comments on commit 055e4fb

Please sign in to comment.