@@ -1438,15 +1438,130 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
14381438 throw V8Exception (V8Exception::Type_Interrupt, m_Name.c_str (), L" Script execution interrupted by host" , *String::Value (tryCatch.StackTrace ()), V8Value (V8Value::Undefined));
14391439 }
14401440
1441- V8Value innerException (V8Value::Undefined);
1442-
14431441 auto hException = tryCatch.Exception ();
1442+ wstring message = *String::Value (hException);
1443+ wstring stackTrace;
1444+
1445+ auto hStackTrace = tryCatch.StackTrace ();
1446+ if (!hStackTrace.IsEmpty ())
1447+ {
1448+ stackTrace = *String::Value (hStackTrace);
1449+ }
1450+
1451+ auto hMessage = tryCatch.Message ();
1452+ if (!hMessage.IsEmpty ())
1453+ {
1454+ if (message.length () < 1 )
1455+ {
1456+ message = *String::Value (hMessage->Get ());
1457+ }
1458+
1459+ stackTrace = message;
1460+
1461+ auto hStackTrace = hMessage->GetStackTrace ();
1462+ int frameCount = !hStackTrace.IsEmpty () ? hStackTrace->GetFrameCount () : 0 ;
1463+
1464+ if (frameCount < 1 )
1465+ {
1466+ auto hScriptResourceName = hMessage->GetScriptResourceName ();
1467+ if (!hScriptResourceName.IsEmpty () && !hScriptResourceName->IsNull () && !hScriptResourceName->IsUndefined ())
1468+ {
1469+ auto hScriptName = hScriptResourceName->ToString ();
1470+ if (!hScriptName.IsEmpty () && (hScriptName->Length () > 0 ))
1471+ {
1472+ stackTrace += L" \n at " ;
1473+ stackTrace += *String::Value (hScriptName);
1474+ }
1475+ else
1476+ {
1477+ stackTrace += L" \n at <anonymous>" ;
1478+ }
1479+ }
1480+ else
1481+ {
1482+ stackTrace += L" \n at <anonymous>" ;
1483+ }
1484+
1485+ stackTrace += L' :' ;
1486+ stackTrace += to_wstring (hMessage->GetLineNumber ());
1487+ stackTrace += L' :' ;
1488+ stackTrace += to_wstring (hMessage->GetStartColumn () + 1 );
1489+
1490+ auto hSourceLine = hMessage->GetSourceLine ();
1491+ if (!hSourceLine.IsEmpty () && (hSourceLine->Length () > 0 ))
1492+ {
1493+ stackTrace += L" -> " ;
1494+ stackTrace += *String::Value (hSourceLine);
1495+ }
1496+ }
1497+ else
1498+ {
1499+ for (int index = 0 ; index < frameCount; index++)
1500+ {
1501+ auto hFrame = hStackTrace->GetFrame (index);
1502+ stackTrace += L" \n at " ;
1503+
1504+ auto hFunctionName = hFrame->GetFunctionName ();
1505+ if (!hFunctionName.IsEmpty () && (hFunctionName->Length () > 0 ))
1506+ {
1507+ if (hFrame->IsConstructor ())
1508+ {
1509+ stackTrace += L" new " ;
1510+ }
1511+
1512+ stackTrace += *String::Value (hFunctionName);
1513+ stackTrace += L" (" ;
1514+ }
1515+
1516+ auto hScriptName = hFrame->GetScriptName ();
1517+ if (!hScriptName.IsEmpty () && (hScriptName->Length () > 0 ))
1518+ {
1519+ stackTrace += *String::Value (hScriptName);
1520+ }
1521+ else
1522+ {
1523+ stackTrace += L" <anonymous>" ;
1524+ }
1525+
1526+ stackTrace += L' :' ;
1527+ auto lineNumber = hFrame->GetLineNumber ();
1528+ if (lineNumber != Message::kNoLineNumberInfo )
1529+ {
1530+ stackTrace += to_wstring (lineNumber);
1531+ }
1532+
1533+ stackTrace += L' :' ;
1534+ auto column = hFrame->GetColumn ();
1535+ if (column != Message::kNoColumnInfo )
1536+ {
1537+ stackTrace += to_wstring (column);
1538+ }
1539+
1540+ if (!hFunctionName.IsEmpty () && (hFunctionName->Length () > 0 ))
1541+ {
1542+ stackTrace += L' )' ;
1543+ }
1544+
1545+ if (index == 0 )
1546+ {
1547+ auto hSourceLine = hMessage->GetSourceLine ();
1548+ if (!hSourceLine.IsEmpty () && (hSourceLine->Length () > 0 ))
1549+ {
1550+ stackTrace += L" -> " ;
1551+ stackTrace += *String::Value (hSourceLine);
1552+ }
1553+ }
1554+ }
1555+ }
1556+ }
1557+
1558+ V8Value innerException (V8Value::Undefined);
14441559 if (hException->IsObject ())
14451560 {
14461561 innerException = ExportValue (hException->ToObject ()->Get (m_hInnerExceptionName));
14471562 }
14481563
1449- throw V8Exception (V8Exception::Type_General, m_Name.c_str (), * String::Value (tryCatch. Exception ()), * String::Value (tryCatch. StackTrace () ), innerException);
1564+ throw V8Exception (V8Exception::Type_General, m_Name.c_str (), message. c_str (), stackTrace. c_str ( ), innerException);
14501565 }
14511566}
14521567
0 commit comments