Skip to content

Commit 8357c52

Browse files
author
Mike Kaufman
committed
[MERGE #5320 @mike-kaufman] updating ch's unhandled rejection handler to print the stack if available
Merge pull request #5320 from mike-kaufman:build/mkaufman/update-ch-unhandled-rejection-handler-to-print-stack If no stack property is available, we'll just convert the reason to a string like we did previously & print that.
2 parents e4fa38d + e7a9a00 commit 8357c52

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

bin/ch/WScriptJsrt.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,6 @@ void WScriptJsrt::PromiseRejectionTrackerCallback(JsValueRef promise, JsValueRef
20202020
{
20212021
Assert(promise != JS_INVALID_REFERENCE);
20222022
Assert(reason != JS_INVALID_REFERENCE);
2023-
JsValueRef strValue;
2024-
JsErrorCode error = ChakraRTInterface::JsConvertValueToString(reason, &strValue);
20252023

20262024
if (!handled)
20272025
{
@@ -2032,11 +2030,32 @@ void WScriptJsrt::PromiseRejectionTrackerCallback(JsValueRef promise, JsValueRef
20322030
wprintf(_u("Promise rejection handled\n"));
20332031
}
20342032

2033+
JsPropertyIdRef stackPropertyID;
2034+
JsErrorCode error = ChakraRTInterface::JsCreatePropertyId("stack", strlen("stack"), &stackPropertyID);
20352035
if (error == JsNoError)
20362036
{
2037-
AutoString str(strValue);
2038-
if (str.GetError() == JsNoError)
2037+
JsValueRef stack;
2038+
error = ChakraRTInterface::JsGetProperty(reason, stackPropertyID, &stack);
2039+
if (error == JsNoError)
2040+
{
2041+
JsValueRef stackStrValue;
2042+
error = ChakraRTInterface::JsConvertValueToString(stack, &stackStrValue);
2043+
if (error == JsNoError)
2044+
{
2045+
AutoString str(stackStrValue);
2046+
wprintf(_u("%ls\n"), str.GetWideString());
2047+
}
2048+
}
2049+
}
2050+
2051+
if (error != JsNoError)
2052+
{
2053+
// weren't able to print stack, so just convert reason to a string
2054+
JsValueRef strValue;
2055+
error = ChakraRTInterface::JsConvertValueToString(reason, &strValue);
2056+
if (error == JsNoError)
20392057
{
2058+
AutoString str(strValue);
20402059
wprintf(_u("%ls\n"), str.GetWideString());
20412060
}
20422061
}

0 commit comments

Comments
 (0)