Skip to content

Commit 191bb5a

Browse files
laverdetjasnell
authored andcommitted
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. PR-URL: #13074 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 4cbdac3 commit 191bb5a

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function REPLServer(prompt,
231231
try {
232232
try {
233233
const scriptOptions = {
234-
displayErrors: true,
234+
displayErrors: false,
235235
breakOnSigint: self.breakEvalOnSigint
236236
};
237237

src/node_contextify.cc

+7-11
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,10 @@ class ContextifyScript : public BaseObject {
736736
return;
737737
}
738738

739-
Local<String> decorated_stack = String::Concat(arrow.As<String>(),
740-
stack.As<String>());
739+
Local<String> decorated_stack = String::Concat(
740+
String::Concat(arrow.As<String>(),
741+
FIXED_ONE_BYTE_STRING(env->isolate(), "\n")),
742+
stack.As<String>());
741743
err_obj->Set(env->stack_string(), decorated_stack);
742744
err_obj->SetPrivate(
743745
env->context(),
@@ -984,6 +986,9 @@ class ContextifyScript : public BaseObject {
984986
env->ThrowError("Script execution timed out.");
985987
} else if (received_signal) {
986988
env->ThrowError("Script execution interrupted.");
989+
} else if (display_errors) {
990+
// We should decorate non-termination exceptions
991+
DecorateErrorStack(env, *try_catch);
987992
}
988993

989994
// If there was an exception thrown during script execution, re-throw it.
@@ -996,15 +1001,6 @@ class ContextifyScript : public BaseObject {
9961001
return false;
9971002
}
9981003

999-
if (result.IsEmpty()) {
1000-
// Error occurred during execution of the script.
1001-
if (display_errors) {
1002-
DecorateErrorStack(env, *try_catch);
1003-
}
1004-
try_catch->ReThrow();
1005-
return false;
1006-
}
1007-
10081004
args.GetReturnValue().Set(result);
10091005
return true;
10101006
}

test/message/vm_display_runtime_error.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const vm = require('vm');
2525

2626
console.error('beginning');
2727

28-
vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm' });
28+
try {
29+
vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm'});
30+
} catch (err) {
31+
console.error(err.stack);
32+
}
33+
34+
vm.runInThisContext('throw new Error("spooky!")', { filename: 'test.vm' });
2935

3036
console.error('end');

test/message/vm_display_runtime_error.out

+15
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@ Error: boo!
1414
at tryModuleLoad (module.js:*:*)
1515
at Function.Module._load (module.js:*)
1616
at Function.Module.runMain (module.js:*)
17+
test.vm:1
18+
throw new Error("spooky!")
19+
^
20+
21+
Error: spooky!
22+
at test.vm:1:7
23+
at ContextifyScript.Script.runInThisContext (vm.js:*)
24+
at Object.runInThisContext (vm.js:*)
25+
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
26+
at Module._compile (module.js:*)
27+
at Object.Module._extensions..js (module.js:*)
28+
at Module.load (module.js:*)
29+
at tryModuleLoad (module.js:*:*)
30+
at Function.Module._load (module.js:*)
31+
at Function.Module.runMain (module.js:*)

0 commit comments

Comments
 (0)