summaryrefslogtreecommitdiff
path: root/src/node_contextify.cc
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-01-25 22:44:17 -0500
committercjihrig <cjihrig@gmail.com>2016-01-26 11:03:13 -0500
commit57003520f83a9431dbef0dfce2edacf430923f20 (patch)
tree41b8a702f6fb5b30883375261756d237223e6e5b /src/node_contextify.cc
parentd66f18e6cde8cadf20e3c4ddc85ec495546d1fb4 (diff)
downloadnode-new-57003520f83a9431dbef0dfce2edacf430923f20.tar.gz
src: attach error to stack on displayErrors
The vm module's displayErrors option attaches error arrow messages as a hidden property. Later, core JavaScript code can optionally decorate the error stack with the arrow message. However, when user code catches an error, it has no way to access the arrow message. This commit changes the behavior of displayErrors to mean "decorate the error stack if an error occurs." Fixes: https://github.com/nodejs/node/issues/4835 PR-URL: https://github.com/nodejs/node/pull/4874 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_contextify.cc')
-rw-r--r--src/node_contextify.cc28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 31d98853d3..7ca622de43 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -541,7 +541,7 @@ class ContextifyScript : public BaseObject {
if (v8_script.IsEmpty()) {
if (display_errors) {
- AppendExceptionLine(env, try_catch.Exception(), try_catch.Message());
+ DecorateErrorStack(env, try_catch);
}
try_catch.ReThrow();
return;
@@ -640,6 +640,30 @@ class ContextifyScript : public BaseObject {
}
}
+ static void DecorateErrorStack(Environment* env, const TryCatch& try_catch) {
+ Local<Value> exception = try_catch.Exception();
+
+ if (!exception->IsObject())
+ return;
+
+ Local<Object> err_obj = exception.As<Object>();
+
+ if (IsExceptionDecorated(env, err_obj))
+ return;
+
+ AppendExceptionLine(env, exception, try_catch.Message());
+ Local<Value> stack = err_obj->Get(env->stack_string());
+ Local<Value> arrow = err_obj->GetHiddenValue(env->arrow_message_string());
+
+ if (!(stack->IsString() && arrow->IsString()))
+ return;
+
+ Local<String> decorated_stack = String::Concat(arrow.As<String>(),
+ stack.As<String>());
+ err_obj->Set(env->stack_string(), decorated_stack);
+ err_obj->SetHiddenValue(env->decorated_string(), True(env->isolate()));
+ }
+
static int64_t GetTimeoutArg(const FunctionCallbackInfo<Value>& args,
const int i) {
if (args[i]->IsUndefined() || args[i]->IsString()) {
@@ -816,7 +840,7 @@ class ContextifyScript : public BaseObject {
if (result.IsEmpty()) {
// Error occurred during execution of the script.
if (display_errors) {
- AppendExceptionLine(env, try_catch.Exception(), try_catch.Message());
+ DecorateErrorStack(env, try_catch);
}
try_catch.ReThrow();
return false;