diff options
author | Chengzhong Wu <chengzhong.wcz@alibaba-inc.com> | 2022-08-26 06:09:05 +0000 |
---|---|---|
committer | legendecas <legendecas@gmail.com> | 2022-09-02 14:02:00 +0800 |
commit | f7896d4671cbce6deaa7bb9a520b37c87e46aebe (patch) | |
tree | 303a572c88065f0f7c7129b1be6c57d0650933b5 /src | |
parent | 7f496fefb67c6a9ad22db87eb69104e9a9abb6d2 (diff) | |
download | node-new-f7896d4671cbce6deaa7bb9a520b37c87e46aebe.tar.gz |
report: get stack trace with cross origin contexts
When a new context with a different security token is entered, or
when no context is entered, `StackTrace::CurrentStackTrace` need to
be explicitly set with flag `kExposeFramesAcrossSecurityOrigins` to
avoid crashing.
PR-URL: https://github.com/nodejs/node/pull/44398
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_errors.cc | 5 | ||||
-rw-r--r-- | src/node_report.cc | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/node_errors.cc b/src/node_errors.cc index aa54bc2fe7..323fc7d4ff 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -513,6 +513,11 @@ void OOMErrorHandler(const char* location, bool is_heap_oom) { } if (report_on_fatalerror) { + // Trigger report with the isolate. Environment::GetCurrent may return + // nullptr here: + // - If the OOM is reported by a young generation space allocation, + // Isolate::GetCurrentContext returns an empty handle. + // - Otherwise, Isolate::GetCurrentContext returns a non-empty handle. TriggerNodeReport(isolate, message, "OOMError", "", Local<Object>()); } diff --git a/src/node_report.cc b/src/node_report.cc index 38391300cd..bf37e24d09 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -470,8 +470,12 @@ static void PrintJavaScriptStack(JSONWriter* writer, void* samples[MAX_FRAME_COUNT]; isolate->GetStackSample(state, samples, MAX_FRAME_COUNT, &info); + constexpr StackTrace::StackTraceOptions stack_trace_options = + static_cast<StackTrace::StackTraceOptions>( + StackTrace::kDetailed | + StackTrace::kExposeFramesAcrossSecurityOrigins); Local<StackTrace> stack = StackTrace::CurrentStackTrace( - isolate, MAX_FRAME_COUNT, StackTrace::kDetailed); + isolate, MAX_FRAME_COUNT, stack_trace_options); if (stack->GetFrameCount() == 0) { PrintEmptyJavaScriptStack(writer); |