Skip to content

Commit a239477

Browse files
committed
src: print more information in C++ assertions
This patch: - Indent the assertion message so that is separated from the native stack trace for redability - Print the JS stack trace when it's available Previoiusly the abort message looks like this: ``` out/Release/node[24458]: ../../src/node_file.cc:2008:void node::fs::Ope n(const FunctionCallbackInfo<v8::Value> &): Assertion `(argc) >= (3)' f ailed. 1: 0x1043fb9a4 node::Abort() [node] 2: 0x1043fb6e4 node::PrintCaughtException(v8::Isolate*, v8::Local<v8:: Context>, v8::TryCatch const&) [node] 3: 0x104407708 node::fs::Open(v8::FunctionCallbackInfo<v8::Value> cons t&) [node] 4: 0x104611e74 v8::internal::MaybeHandle<v8::internal::Object> v8::int ernal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal:: Isolate*, v8::internal::Handle<v8::internal::HeapObject >, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::intern al::Handle<v8::internal::Object>, unsigned long*, int) [node ] 5: 0x1046116c8 v8::internal::Builtin_HandleApiCall(int, unsigned long* , v8::internal::Isolate*) [node] 6: 0x104e9cb24 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit [node] 7: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 8: 0x104e1250c Builtins_JSEntryTrampoline [node] 9: 0x104e121f4 Builtins_JSEntry [node] 10: 0x1046ed54c v8::internal::(anonymous namespace)::Invoke(v8::interna l::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [node] 11: 0x1046edb60 v8::internal::Execution::CallScript(v8::internal::Isola te*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Hand le<v8::internal::Object>, v8::internal::Handle<v8::in ternal::Object>) [node] 12: 0x1045a9fa0 v8::Script::Run(v8::Local<v8::Context>, v8::Local<v8::D ata>) [node] 13: 0x1043efb68 node::contextify::ContextifyScript::EvalMachine(v8::Loc al<v8::Context>, node::Environment*, long long, bool, bool, bool, v8::M icrotaskQueue*, v8::FunctionCallbackInfo<v8::Value> const&) [node ] 14: 0x1043ef3e0 node::contextify::ContextifyScript::RunInContext(v8::Fu nctionCallbackInfo<v8::Value> const&) [node] 15: 0x104611e74 v8::internal::MaybeHandle<v8::internal::Object> v8::int ernal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal:: Isolate*, v8::internal::Handle<v8::internal::HeapObject> , v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::interna l::Handle<v8::internal::Object>, unsigned long*, int) [node ] 16: 0x1046116c8 v8::internal::Builtin_HandleApiCall(int, unsigned long* , v8::internal::Isolate*) [node] 17: 0x104e9cb24 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit [node] 18: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 19: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 20: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 21: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 22: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 23: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 24: 0x104e143e4 Builtins_InterpreterEntryTrampoline [node] 25: 0x104e1250c Builtins_JSEntryTrampoline [node] 26: 0x104e121f4 Builtins_JSEntry [node] 27: 0x1046ed54c v8::internal::(anonymous namespace)::Invoke(v8::interna l::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [node] 28: 0x1046ecdc8 v8::internal::Execution::Call(v8::internal::Isolate*, v 8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::int ernal::Object>, int, v8::internal::Handle<v 8::internal::Object>*) [node] 29: 0x1045be23c v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8 ::Value>, int, v8::Local<v8::Value>*) [node] 30: 0x1043df704 node::builtins::BuiltinLoader::CompileAndCall(v8::Local <v8::Context>, char const*, node::Realm*) [node] 31: 0x10446f2d4 node::Realm::ExecuteBootstrapper(char const*) [node] 32: 0x1043c3378 node::StartExecution(node::Environment*, std::__1::func tion<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const& )>) [node] 33: 0x10432dc28 node::LoadEnvironment(node::Environment*, std::__1::fun ction<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const &)>) [node] 34: 0x10443d1f4 node::NodeMainInstance::Run(node::ExitCode*, node::Envi ronment*) [node] 35: 0x10443cfd0 node::NodeMainInstance::Run() [node] 36: 0x1043c5d18 node::Start(int, char**) [node] 37: 0x19a027f28 start [/usr/lib/dyld] [1] 24458 abort out/Release/node -p "process.binding('fs').open ()" ``` Now it looks like this: ``` # out/Release/node[24856]: void node::fs::Open(const FunctionCallbac kInfo<v8::Value> &) at ../../src/node_file.cc:2008 # Assertion failed: (argc) >= (3) ----- Native stack trace ----- 1: 0x1001efe64 node::Abort() [node] 2: 0x1001efba4 node::PrintCaughtException(v8::Isolate*, v8::Local<v8:: Context>, v8::TryCatch const&) [node] 3: 0x1001fb868 node::fs::Open(v8::FunctionCallbackInfo<v8::Value> cons t&) [node] 4: 0x100405fd4 v8::internal::MaybeHandle<v8::internal::Object> v8::int ernal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal:: Isolate*, v8::internal::Handle<v8::internal::HeapObject >, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::intern al::Handle<v8::internal::Object>, unsigned long*, int) [node ] 5: 0x100405828 v8::internal::Builtin_HandleApiCall(int, unsigned long* , v8::internal::Isolate*) [node] 6: 0x100c90b24 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit [node] 7: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 8: 0x100c0650c Builtins_JSEntryTrampoline [node] 9: 0x100c061f4 Builtins_JSEntry [node] 10: 0x1004e16ac v8::internal::(anonymous namespace)::Invoke(v8::interna l::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [node] 11: 0x1004e1cc0 v8::internal::Execution::CallScript(v8::internal::Isola te*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Hand le<v8::internal::Object>, v8::internal::Handle<v8::in ternal::Object>) [node] 12: 0x10039e100 v8::Script::Run(v8::Local<v8::Context>, v8::Local<v8::D ata>) [node] 13: 0x1001e4028 node::contextify::ContextifyScript::EvalMachine(v8::Loc al<v8::Context>, node::Environment*, long long, bool, bool, bool, v8::M icrotaskQueue*, v8::FunctionCallbackInfo<v8::Value> const&) [node ] 14: 0x1001e38a0 node::contextify::ContextifyScript::RunInContext(v8::Fu nctionCallbackInfo<v8::Value> const&) [node] 15: 0x100405fd4 v8::internal::MaybeHandle<v8::internal::Object> v8::int ernal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal:: Isolate*, v8::internal::Handle<v8::internal::HeapObject> , v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::interna l::Handle<v8::internal::Object>, unsigned long*, int) [node ] 16: 0x100405828 v8::internal::Builtin_HandleApiCall(int, unsigned long* , v8::internal::Isolate*) [node] 17: 0x100c90b24 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit [node] 18: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 19: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 20: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 21: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 22: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 23: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 24: 0x100c083e4 Builtins_InterpreterEntryTrampoline [node] 25: 0x100c0650c Builtins_JSEntryTrampoline [node] 26: 0x100c061f4 Builtins_JSEntry [node] 27: 0x1004e16ac v8::internal::(anonymous namespace)::Invoke(v8::interna l::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [node] 28: 0x1004e0f28 v8::internal::Execution::Call(v8::internal::Isolate*, v 8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::int ernal::Object>, int, v8::internal::Handle<v 8::internal::Object>*) [node] 29: 0x1003b239c v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8 ::Value>, int, v8::Local<v8::Value>*) [node] 30: 0x1001d3bc4 node::builtins::BuiltinLoader::CompileAndCall(v8::Local <v8::Context>, char const*, node::Realm*) [node] 31: 0x100263434 node::Realm::ExecuteBootstrapper(char const*) [node] 32: 0x1001b7838 node::StartExecution(node::Environment*, std::__1::func tion<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const& )>) [node] 33: 0x100121c28 node::LoadEnvironment(node::Environment*, std::__1::fun ction<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const &)>) [node] 34: 0x100231354 node::NodeMainInstance::Run(node::ExitCode*, node::Envi ronment*) [node] 35: 0x100231130 node::NodeMainInstance::Run() [node] 36: 0x1001ba1d8 node::Start(int, char**) [node] 37: 0x19a027f28 start [/usr/lib/dyld] ----- JavaScript stack trace ----- 1: [eval]:1:23 2: runScriptInThisContext (node:internal/vm:144:10) 3: node:internal/process/execution:109:14 4: [eval]-wrapper:6:24 5: runScript (node:internal/process/execution:92:62) 6: evalScript (node:internal/process/execution:123:10) 7: node:internal/main/eval_string:51:3 [1] 24856 abort out/Release/node -p "process.binding('fs').open ()" ```
1 parent c60c11a commit a239477

12 files changed

+139
-41
lines changed

src/debug_utils.cc

+34-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ namespace per_process {
5959
EnabledDebugList enabled_debug_list;
6060
}
6161

62+
using v8::Local;
63+
using v8::StackTrace;
64+
6265
void EnabledDebugList::Parse(std::shared_ptr<KVStore> env_vars,
6366
v8::Isolate* isolate) {
6467
std::string cats;
@@ -303,7 +306,8 @@ std::string NativeSymbolDebuggingContext::SymbolInfo::Display() const {
303306
return oss.str();
304307
}
305308

306-
void DumpBacktrace(FILE* fp) {
309+
void DumpNativeBacktrace(FILE* fp) {
310+
fprintf(fp, "----- Native stack trace -----\n\n");
307311
auto sym_ctx = NativeSymbolDebuggingContext::New();
308312
void* frames[256];
309313
const int size = sym_ctx->GetStackTrace(frames, arraysize(frames));
@@ -314,6 +318,33 @@ void DumpBacktrace(FILE* fp) {
314318
}
315319
}
316320

321+
static std::atomic<bool> is_dumping_js_stacktrace{false};
322+
void DumpJavaScriptBacktrace(FILE* fp) {
323+
// Printing JavaScript stack trace can result in V8 fatal error,
324+
// which can re-enter this function.
325+
if (is_dumping_js_stacktrace.load()) {
326+
return;
327+
}
328+
329+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
330+
if (isolate == nullptr) {
331+
return;
332+
}
333+
334+
std::string js_stack;
335+
std::stringstream ss;
336+
is_dumping_js_stacktrace.store(true);
337+
Local<StackTrace> stack =
338+
StackTrace::CurrentStackTrace(isolate, 10, StackTrace::kDetailed);
339+
340+
fprintf(fp, "\n----- JavaScript stack trace -----\n\n");
341+
342+
PrintStackTrace(isolate, stack, StackTracePrefix::kNumber);
343+
fprintf(fp, "\n");
344+
345+
is_dumping_js_stacktrace.store(false);
346+
}
347+
317348
void CheckedUvLoopClose(uv_loop_t* loop) {
318349
if (uv_loop_close(loop) == 0) return;
319350

@@ -514,5 +545,6 @@ void FWrite(FILE* file, const std::string& str) {
514545
} // namespace node
515546

516547
extern "C" void __DumpBacktrace(FILE* fp) {
517-
node::DumpBacktrace(fp);
548+
node::DumpNativeBacktrace(fp);
549+
node::DumpJavaScriptBacktrace(fp);
518550
}

src/env.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,8 @@ void AsyncHooks::FailWithCorruptedAsyncStack(double expected_async_id) {
16621662
"actual: %.f, expected: %.f)\n",
16631663
async_id_fields_.GetValue(kExecutionAsyncId),
16641664
expected_async_id);
1665-
DumpBacktrace(stderr);
1665+
DumpNativeBacktrace(stderr);
1666+
DumpJavaScriptBacktrace(stderr);
16661667
fflush(stderr);
16671668
// TODO(joyeecheung): should this exit code be more specific?
16681669
if (!env()->abort_on_uncaught_exception()) Exit(ExitCode::kGenericUserError);

src/node_errors.cc

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cerrno>
22
#include <cstdarg>
3+
#include <sstream>
34

45
#include "debug_utils-inl.h"
56
#include "node_errors.h"
@@ -185,23 +186,29 @@ static std::string GetErrorSource(Isolate* isolate,
185186
return buf + std::string(underline_buf, off);
186187
}
187188

188-
static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
189+
static std::string FormatStackTrace(
190+
Isolate* isolate,
191+
Local<StackTrace> stack,
192+
StackTracePrefix prefix = StackTracePrefix::kAt) {
189193
std::string result;
190194
for (int i = 0; i < stack->GetFrameCount(); i++) {
191195
Local<StackFrame> stack_frame = stack->GetFrame(isolate, i);
192196
node::Utf8Value fn_name_s(isolate, stack_frame->GetFunctionName());
193197
node::Utf8Value script_name(isolate, stack_frame->GetScriptName());
194198
const int line_number = stack_frame->GetLineNumber();
195199
const int column = stack_frame->GetColumn();
196-
200+
std::string prefix_str = prefix == StackTracePrefix::kAt
201+
? " at "
202+
: std::to_string(i + 1) + ": ";
197203
if (stack_frame->IsEval()) {
198204
if (stack_frame->GetScriptId() == Message::kNoScriptIdInfo) {
199-
result += SPrintF(" at [eval]:%i:%i\n", line_number, column);
205+
result += SPrintF("%s[eval]:%i:%i\n", prefix_str, line_number, column);
200206
} else {
201207
std::vector<char> buf(script_name.length() + 64);
202208
snprintf(buf.data(),
203209
buf.size(),
204-
" at [eval] (%s:%i:%i)\n",
210+
"%s[eval] (%s:%i:%i)\n",
211+
prefix_str.c_str(),
205212
*script_name,
206213
line_number,
207214
column);
@@ -214,7 +221,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
214221
std::vector<char> buf(script_name.length() + 64);
215222
snprintf(buf.data(),
216223
buf.size(),
217-
" at %s:%i:%i\n",
224+
"%s%s:%i:%i\n",
225+
prefix_str.c_str(),
218226
*script_name,
219227
line_number,
220228
column);
@@ -223,7 +231,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
223231
std::vector<char> buf(fn_name_s.length() + script_name.length() + 64);
224232
snprintf(buf.data(),
225233
buf.size(),
226-
" at %s (%s:%i:%i)\n",
234+
"%s%s (%s:%i:%i)\n",
235+
prefix_str.c_str(),
227236
*fn_name_s,
228237
*script_name,
229238
line_number,
@@ -239,8 +248,10 @@ static void PrintToStderrAndFlush(const std::string& str) {
239248
fflush(stderr);
240249
}
241250

242-
void PrintStackTrace(Isolate* isolate, Local<StackTrace> stack) {
243-
PrintToStderrAndFlush(FormatStackTrace(isolate, stack));
251+
void PrintStackTrace(Isolate* isolate,
252+
Local<StackTrace> stack,
253+
StackTracePrefix prefix) {
254+
PrintToStderrAndFlush(FormatStackTrace(isolate, stack, prefix));
244255
}
245256

246257
std::string FormatCaughtException(Isolate* isolate,
@@ -329,7 +340,8 @@ void AppendExceptionLine(Environment* env,
329340
}
330341

331342
[[noreturn]] void Abort() {
332-
DumpBacktrace(stderr);
343+
DumpNativeBacktrace(stderr);
344+
DumpJavaScriptBacktrace(stderr);
333345
fflush(stderr);
334346
ABORT_NO_BACKTRACE();
335347
}
@@ -338,14 +350,15 @@ void AppendExceptionLine(Environment* env,
338350
std::string name = GetHumanReadableProcessName();
339351

340352
fprintf(stderr,
341-
"%s: %s:%s%s Assertion `%s' failed.\n",
353+
"\n"
354+
" # %s: %s at %s\n"
355+
" # Assertion failed: %s\n\n",
342356
name.c_str(),
343-
info.file_line,
344-
info.function,
345-
*info.function ? ":" : "",
357+
info.function ? info.function : "(unknown function)",
358+
info.file_line ? info.file_line : "(unknown source location)",
346359
info.message);
347-
fflush(stderr);
348360

361+
fflush(stderr);
349362
Abort();
350363
}
351364

src/node_internals.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>& args) {
7979
args.GetReturnValue().Set(err);
8080
}
8181

82-
void PrintStackTrace(v8::Isolate* isolate, v8::Local<v8::StackTrace> stack);
82+
enum class StackTracePrefix {
83+
kAt, // " at "
84+
kNumber
85+
};
86+
void PrintStackTrace(v8::Isolate* isolate,
87+
v8::Local<v8::StackTrace> stack,
88+
StackTracePrefix prefix = StackTracePrefix::kAt);
8389
void PrintCaughtException(v8::Isolate* isolate,
8490
v8::Local<v8::Context> context,
8591
const v8::TryCatch& try_catch);

src/node_platform.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ v8::TracingController* NodePlatform::GetTracingController() {
560560
Platform::StackTracePrinter NodePlatform::GetStackTracePrinter() {
561561
return []() {
562562
fprintf(stderr, "\n");
563-
DumpBacktrace(stderr);
563+
DumpNativeBacktrace(stderr);
564564
fflush(stderr);
565565
};
566566
}

src/util.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ struct AssertionInfo {
115115
};
116116
[[noreturn]] void NODE_EXTERN_PRIVATE Assert(const AssertionInfo& info);
117117
[[noreturn]] void NODE_EXTERN_PRIVATE Abort();
118-
void DumpBacktrace(FILE* fp);
118+
void DumpNativeBacktrace(FILE* fp);
119+
void DumpJavaScriptBacktrace(FILE* fp);
119120

120121
// Windows 8+ does not like abort() in Release mode
121122
#ifdef _WIN32

test/abort/test-abort-backtrace.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ if (process.argv[2] === 'child') {
1010
const stderr = child.stderr.toString();
1111

1212
assert.strictEqual(child.stdout.toString(), '');
13-
// Stderr will be empty for systems that don't support backtraces.
14-
if (stderr !== '') {
15-
const frames = stderr.trimRight().split('\n').map((s) => s.trim());
13+
const { nativeStack, jsStack } = common.getPrintedStackTrace(stderr);
1614

17-
if (!frames.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
18-
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
19-
}
15+
if (!nativeStack.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
16+
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
17+
}
2018

21-
if (!common.isWindows) {
22-
const { getBinaryPath } = require('../common/shared-lib-util');
23-
if (!frames.some((frame) => frame.includes(`[${getBinaryPath()}]`))) {
24-
assert.fail(`Some frames should include the binary name:\n${stderr}`);
25-
}
19+
// For systems that don't support backtraces, the native stack is
20+
// going to be empty.
21+
if (!common.isWindows && nativeStack.length > 0) {
22+
const { getBinaryPath } = require('../common/shared-lib-util');
23+
if (!nativeStack.some((frame) => frame.includes(`[${getBinaryPath()}]`))) {
24+
assert.fail(`Some native stack frame include the binary name:\n${stderr}`);
2625
}
2726
}
27+
28+
if (jsStack.length > 0) {
29+
assert(jsStack.some((frame) => frame.includes(__filename)));
30+
}
2831
}

test/abort/test-abort-fatal-error.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,5 @@ exec(cmdline, function(err, stdout, stderr) {
3838
assert(false, 'this test should fail');
3939
}
4040

41-
if (err.code !== 134 && err.signal !== 'SIGABRT') {
42-
console.log(stdout);
43-
console.log(stderr);
44-
console.log(err);
45-
assert(false, err);
46-
}
41+
assert(common.nodeProcessAborted(err.code, err.signal));
4742
});

test/abort/test-addon-uv-handle-leak.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ if (process.argv[2] === 'child') {
8888

8989
while (lines.length > 0) {
9090
const line = lines.shift().trim();
91+
if (line.length === 0) {
92+
continue; // Skip empty lines.
93+
}
9194

9295
switch (state) {
9396
case 'initial':
@@ -96,7 +99,7 @@ if (process.argv[2] === 'child') {
9699
break;
97100
case 'handle-start':
98101
if (/^uv loop at \[.+\] has \d+ open handles in total$/.test(line)) {
99-
state = 'assertion-failure';
102+
state = 'source-line';
100103
break;
101104
}
102105
assert.match(line, /^\[.+\] timer( \(active\))?$/);
@@ -116,8 +119,12 @@ if (process.argv[2] === 'child') {
116119
}
117120
state = 'handle-start';
118121
break;
122+
case 'source-line':
123+
assert.match(line, /CheckedUvLoopClose/);
124+
state = 'assertion-failure';
125+
break;
119126
case 'assertion-failure':
120-
assert.match(line, /Assertion .+ failed/);
127+
assert.match(line, /Assertion failed:/);
121128
state = 'done';
122129
break;
123130
case 'done':

test/common/index.js

+40
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,45 @@ function spawnPromisified(...args) {
906906
});
907907
}
908908

909+
function getPrintedStackTrace(stderr) {
910+
const lines = stderr.split('\n');
911+
912+
let state = 'initial';
913+
const result = {
914+
message: [],
915+
nativeStack: [],
916+
jsStack: [],
917+
};
918+
for (let i = 0; i < lines.length; ++i) {
919+
const line = lines[i].trim();
920+
if (line.length === 0) {
921+
continue; // Skip empty lines.
922+
}
923+
924+
switch (state) {
925+
case 'initial':
926+
result.message.push(line);
927+
if (line.includes('Native stack trace')) {
928+
state = 'native-stack';
929+
} else {
930+
result.message.push(line);
931+
}
932+
break;
933+
case 'native-stack':
934+
if (line.includes('JavaScript stack trace')) {
935+
state = 'js-stack';
936+
} else {
937+
result.nativeStack.push(line);
938+
}
939+
break;
940+
case 'js-stack':
941+
result.jsStack.push(line);
942+
break;
943+
}
944+
}
945+
return result;
946+
}
947+
909948
const common = {
910949
allowGlobals,
911950
buildType,
@@ -919,6 +958,7 @@ const common = {
919958
getArrayBufferViews,
920959
getBufferSources,
921960
getCallSite,
961+
getPrintedStackTrace,
922962
getTTYfd,
923963
hasIntl,
924964
hasCrypto,

test/js-native-api/test_finalizer/test_fatal_finalize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ const { spawnSync } = require('child_process');
2727
const child = spawnSync(process.execPath, [
2828
'--expose-gc', __filename, 'child',
2929
]);
30-
assert.strictEqual(child.signal, common.isWindows ? null : 'SIGABRT');
30+
assert(common.nodeProcessAborted(child.status, child.signal));
3131
assert.match(child.stderr.toString(), /Finalizer is calling a function that may affect GC state/);

test/node-api/test_fatal/test_threads.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ const p = child_process.spawnSync(
1818
assert.ifError(p.error);
1919
assert.ok(p.stderr.toString().includes(
2020
'FATAL ERROR: work_thread foobar'));
21-
assert.ok(p.status === 134 || p.signal === 'SIGABRT');
21+
assert(common.nodeProcessAborted(p.status, p.signal));

0 commit comments

Comments
 (0)