Skip to content

Commit 1d90563

Browse files
committed
fix console.log(error) should include stack trace
1 parent 2c3f915 commit 1d90563

File tree

1 file changed

+11
-0
lines changed
  • test-app/runtime/src/main/cpp/runtime/console

1 file changed

+11
-0
lines changed

test-app/runtime/src/main/cpp/runtime/console/Console.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,23 @@ std::string transformJSObject(napi_env env, napi_value object) {
7575

7676
// Check if the object has a toString method
7777
napi_has_named_property(env, object, "toString", &hasToString);
78+
7879
if (hasToString) {
7980
napi_get_named_property(env, object, "toString", &toStringFunc);
8081
if (napi_util::is_of_type(env, toStringFunc, napi_function)) {
8182
napi_value result;
8283
napi_call_function(env, object, toStringFunc, 0, nullptr, &result);
8384
auto value = ArgConverter::ConvertToString(env, result);
85+
86+
bool is_error = false;
87+
napi_is_error(env, object, &is_error);
88+
if (is_error) {
89+
napi_value stack;
90+
napi_get_named_property(env, object, "stack", &stack);
91+
auto stack_value = ArgConverter::ConvertToString(env, stack);
92+
value += "\n" + stack_value;
93+
}
94+
8495
auto hasCustomToStringImplementation = value.find("[object Object]") == std::string::npos;
8596
if (hasCustomToStringImplementation) return value;
8697
}

0 commit comments

Comments
 (0)