diff options
Diffstat (limited to 'src/node_errors.cc')
-rw-r--r-- | src/node_errors.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_errors.cc b/src/node_errors.cc index 4e13c24e15..22bc4d994b 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -57,6 +57,16 @@ static std::string GetErrorSource(Isolate* isolate, node::Utf8Value encoded_source(isolate, source_line_maybe.ToLocalChecked()); std::string sourceline(*encoded_source, encoded_source.length()); + // If source maps have been enabled, the exception line will instead be + // added in the JavaScript context: + Environment* env = Environment::GetCurrent(isolate); + const bool has_source_map_url = + !message->GetScriptOrigin().SourceMapUrl().IsEmpty(); + if (has_source_map_url && env->source_maps_enabled()) { + *added_exception_line = false; + return sourceline; + } + if (sourceline.find("node-do-not-add-exception-line") != std::string::npos) { *added_exception_line = false; return sourceline; @@ -802,6 +812,11 @@ void SetPrepareStackTraceCallback(const FunctionCallbackInfo<Value>& args) { env->set_prepare_stack_trace_callback(args[0].As<Function>()); } +static void EnableSourceMaps(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + env->set_source_maps_enabled(true); +} + static void SetEnhanceStackForFatalException( const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -840,6 +855,7 @@ void Initialize(Local<Object> target, Environment* env = Environment::GetCurrent(context); env->SetMethod( target, "setPrepareStackTraceCallback", SetPrepareStackTraceCallback); + env->SetMethod(target, "enableSourceMaps", EnableSourceMaps); env->SetMethod(target, "setEnhanceStackForFatalException", SetEnhanceStackForFatalException); |