Browse Source

vm: fix displayErrors in runIn.. functions

This option has been broken for almost a year when used with any of the
vm.runIn.. family of functions, except for syntax errors.

Backport-PR-URL: https://github.com/nodejs/node/pull/14373
PR-URL: https://github.com/nodejs/node/pull/13074
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v6.x
Marcel Laverdet 8 years ago
committed by Myles Borins
parent
commit
6e60c838c9
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 2
      lib/repl.js
  2. 18
      src/node_contextify.cc
  3. 8
      test/message/vm_display_runtime_error.js
  4. 15
      test/message/vm_display_runtime_error.out

2
lib/repl.js

@ -332,7 +332,7 @@ function REPLServer(prompt,
try { try {
try { try {
const scriptOptions = { const scriptOptions = {
displayErrors: true, displayErrors: false,
breakOnSigint: self.breakEvalOnSigint breakOnSigint: self.breakEvalOnSigint
}; };

18
src/node_contextify.cc

@ -684,8 +684,10 @@ class ContextifyScript : public BaseObject {
return; return;
} }
Local<String> decorated_stack = String::Concat(arrow.As<String>(), Local<String> decorated_stack = String::Concat(
stack.As<String>()); String::Concat(arrow.As<String>(),
FIXED_ONE_BYTE_STRING(env->isolate(), "\n")),
stack.As<String>());
err_obj->Set(env->stack_string(), decorated_stack); err_obj->Set(env->stack_string(), decorated_stack);
err_obj->SetPrivate( err_obj->SetPrivate(
env->context(), env->context(),
@ -932,6 +934,9 @@ class ContextifyScript : public BaseObject {
env->ThrowError("Script execution timed out."); env->ThrowError("Script execution timed out.");
} else if (received_signal) { } else if (received_signal) {
env->ThrowError("Script execution interrupted."); env->ThrowError("Script execution interrupted.");
} else if (display_errors) {
// We should decorate non-termination exceptions
DecorateErrorStack(env, *try_catch);
} }
// If there was an exception thrown during script execution, re-throw it. // If there was an exception thrown during script execution, re-throw it.
@ -944,15 +949,6 @@ class ContextifyScript : public BaseObject {
return false; return false;
} }
if (result.IsEmpty()) {
// Error occurred during execution of the script.
if (display_errors) {
DecorateErrorStack(env, *try_catch);
}
try_catch->ReThrow();
return false;
}
args.GetReturnValue().Set(result); args.GetReturnValue().Set(result);
return true; return true;
} }

8
test/message/vm_display_runtime_error.js

@ -4,6 +4,12 @@ const vm = require('vm');
console.error('beginning'); console.error('beginning');
vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm' }); try {
vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm'});
} catch (err) {
console.error(err.stack);
}
vm.runInThisContext('throw new Error("spooky!")', { filename: 'test.vm' });
console.error('end'); console.error('end');

15
test/message/vm_display_runtime_error.out

@ -14,3 +14,18 @@ Error: boo!
at tryModuleLoad (module.js:*:*) at tryModuleLoad (module.js:*:*)
at Function.Module._load (module.js:*) at Function.Module._load (module.js:*)
at Module.runMain (module.js:*) at Module.runMain (module.js:*)
test.vm:1
throw new Error("spooky!")
^
Error: spooky!
at test.vm:1:7
at ContextifyScript.Script.runInThisContext (vm.js:*)
at Object.runInThisContext (vm.js:*)
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
at Module._compile (module.js:*)
at Object.Module._extensions..js (module.js:*)
at Module.load (module.js:*)
at tryModuleLoad (module.js:*:*)
at Function.Module._load (module.js:*)
at Module.runMain (module.js:*)

Loading…
Cancel
Save