Skip to content

Commit caa2c86

Browse files
Version 5.3.3: Improved V8 error handling (Issue ClearFoundry#12), lowered .NET framework target to v4.0, added several tests, tested with V8 3.19.18.
1 parent f55568c commit caa2c86

File tree

22 files changed

+221
-37
lines changed

22 files changed

+221
-37
lines changed

ClearScript/ClearScript.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>Microsoft.ClearScript</RootNamespace>
1212
<AssemblyName>ClearScript</AssemblyName>
13-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<SccProjectName>
1616
</SccProjectName>

ClearScript/Exports/VersionSymbols.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363

6464
#pragma once
6565

66-
#define CLEARSCRIPT_VERSION_STRING "5.3.2.0"
67-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,3,2,0
66+
#define CLEARSCRIPT_VERSION_STRING "5.3.3.0"
67+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 5,3,3,0

ClearScript/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@
7373
[assembly: InternalsVisibleTo("ClearScriptTest")]
7474

7575
[assembly: ComVisible(false)]
76-
[assembly: AssemblyVersion("5.3.2.0")]
77-
[assembly: AssemblyFileVersion("5.3.2.0")]
76+
[assembly: AssemblyVersion("5.3.3.0")]
77+
[assembly: AssemblyFileVersion("5.3.3.0")]

ClearScript/V8/ClearScriptV8/32/ClearScriptV8-32.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313
<PropertyGroup Label="Globals">
1414
<ProjectGuid>{2D63EA35-BA9C-4E77-B5A4-4938DBBFEFA6}</ProjectGuid>
15-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
15+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1616
<Keyword>ManagedCProj</Keyword>
1717
<RootNamespace>ClearScriptV832</RootNamespace>
1818
</PropertyGroup>
-8 Bytes
Binary file not shown.

ClearScript/V8/ClearScriptV8/64/ClearScriptV8-64.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313
<PropertyGroup Label="Globals">
1414
<ProjectGuid>{CDCF4EEA-1CA4-412E-8C77-78893A67A577}</ProjectGuid>
15-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
15+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1616
<Keyword>ManagedCProj</Keyword>
1717
<RootNamespace>ClearScriptV864</RootNamespace>
1818
</PropertyGroup>
-8 Bytes
Binary file not shown.

ClearScript/V8/ClearScriptV8/V8ContextImpl.cpp

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

ClearScript/V8/ClearScriptV8/V8IsolateImpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ V8IsolateImpl::V8IsolateImpl(const wchar_t* pName, const V8IsolateConstraints* p
118118

119119
BEGIN_ISOLATE_ENTRY_SCOPE
120120

121+
V8::SetCaptureStackTraceForUncaughtExceptions(true, 64, StackTrace::kDetailed);
121122
V8::IgnoreOutOfMemoryException();
122123
if (pConstraints != nullptr)
123124
{

ClearScript/V8/ClearScriptV8/V8Platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
#pragma warning(push, 3)
6969

70+
#define V8_USE_UNSAFE_HANDLES
7071
#include "v8.h"
7172
#include "v8-debug.h"
7273
using namespace v8;

0 commit comments

Comments
 (0)