Skip to content

Commit 0a64a1c

Browse files
committed
[1.4>master] [MERGE #2315 @tcare] Remove InternalErrorException and FailFast instead
Merge pull request #2315 from tcare:bait There are a series of bugs we are getting where the dump has happened after we have thrown a InternalErrorException and returned E_FAIL. We don't even really need an InternalErrorException anyway, so we can FailFast in this case and get a more useful dump.
2 parents 20e1e6e + ee8e57e commit 0a64a1c

File tree

10 files changed

+40
-83
lines changed

10 files changed

+40
-83
lines changed

lib/Common/Common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ template<> struct IntMath<int64> { using Type = Int64Math; };
7474

7575
// Exceptions
7676
#include "Exceptions/ExceptionBase.h"
77-
#include "Exceptions/InternalErrorException.h"
7877
#include "Exceptions/JavascriptException.h"
7978
#include "Exceptions/OutOfMemoryException.h"
8079
#include "Exceptions/OperationAbortedException.h"

lib/Common/Exceptions/Chakra.Common.Exceptions.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
<ClInclude Include="EvalDisabledException.h" />
4646
<ClInclude Include="ExceptionBase.h" />
4747
<ClInclude Include="ExceptionCheck.h" />
48-
<ClInclude Include="InternalErrorException.h" />
4948
<ClInclude Include="JavascriptException.h" />
5049
<ClInclude Include="NotImplementedException.h" />
5150
<ClInclude Include="OperationAbortedException.h" />

lib/Common/Exceptions/InternalErrorException.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/Common/Exceptions/Throw.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "StackOverflowException.h"
1717
#include "AsmJsParseException.h"
18-
#include "InternalErrorException.h"
1918
#include "OutOfMemoryException.h"
2019
#include "NotImplementedException.h"
2120

@@ -84,8 +83,7 @@ namespace Js {
8483

8584
void Throw::InternalError()
8685
{
87-
AssertMsg(false, "Internal error!!");
88-
throw InternalErrorException();
86+
AssertOrFailFastMsg(false, "Internal error!!");
8987
}
9088

9189
void Throw::OutOfMemory()

lib/Common/Exceptions/Throw.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ namespace Js {
110110

111111
#define END_TRANSLATE_KNOWN_EXCEPTION_TO_HRESULT(hr) \
112112
} \
113-
catch (Js::InternalErrorException) \
114-
{ \
115-
hr = E_FAIL; \
116-
} \
117113
catch (Js::OutOfMemoryException) \
118114
{ \
119115
hr = E_OUTOFMEMORY; \
@@ -135,14 +131,43 @@ namespace Js {
135131
hr = JSERR_AsmJsCompileError; \
136132
}
137133

134+
// This should be the inverse of END_TRANSLATE_KNOWN_EXCEPTION_TO_HRESULT, and catch all the same cases.
135+
#define THROW_KNOWN_HRESULT_EXCEPTIONS(hr, scriptContext) \
136+
if (hr == E_OUTOFMEMORY) \
137+
{ \
138+
JavascriptError::ThrowOutOfMemoryError(scriptContext); \
139+
} \
140+
else if (hr == VBSERR_OutOfStack) \
141+
{ \
142+
JavascriptError::ThrowStackOverflowError(scriptContext); \
143+
} \
144+
else if (hr == E_NOTIMPL) \
145+
{ \
146+
throw Js::NotImplementedException(); \
147+
} \
148+
else if (hr == E_ABORT) \
149+
{ \
150+
throw Js::ScriptAbortException(); \
151+
} \
152+
else if (hr == JSERR_AsmJsCompileError) \
153+
{ \
154+
throw Js::AsmJsParseException(); \
155+
} \
156+
else if (FAILED(hr)) \
157+
{ \
158+
/* Intended to be the inverse of E_FAIL in CATCH_UNHANDLED_EXCEPTION */ \
159+
AssertOrFailFast(false); \
160+
}
161+
138162
#define CATCH_UNHANDLED_EXCEPTION(hr) \
139163
catch (...) \
140-
{ \
141-
AssertMsg(FALSE, "invalid exception thrown and didn't get handled"); \
142-
hr = E_FAIL; \
164+
{ \
165+
AssertOrFailFastMsg(FALSE, "invalid exception thrown and didn't get handled"); \
166+
hr = E_FAIL; /* Suppress C4701 */ \
143167
} \
144168
}
145169

170+
146171
#define END_TRANSLATE_EXCEPTION_TO_HRESULT(hr) \
147172
END_TRANSLATE_KNOWN_EXCEPTION_TO_HRESULT(hr)\
148173
CATCH_UNHANDLED_EXCEPTION(hr)

lib/Common/Memory/PageAllocator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66
#include "PageAllocatorDefines.h"
77
#include "Exceptions/ExceptionBase.h"
8-
#include "Exceptions/InternalErrorException.h"
98

109
#ifdef PROFILE_MEM
1110
struct PageMemoryData;
@@ -400,7 +399,7 @@ class MemoryOperationLastError
400399
if (MemOpLastError == 0)
401400
{
402401
MemOpLastError = GetLastError();
403-
throw Js::InternalErrorException();
402+
AssertOrFailFast(false);
404403
}
405404
}
406405
static void CheckProcessAndThrowFatalError(HANDLE hProcess)

lib/JITServer/JITServer.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,17 +833,12 @@ HRESULT ServerCallWrapper(ServerThreadContext* threadContextInfo, Fn fn)
833833
{
834834
hr = E_ABORT;
835835
}
836-
catch (Js::InternalErrorException)
837-
{
838-
hr = E_FAIL;
839-
}
840836
catch (...)
841837
{
842-
AssertMsg(false, "Unknown exception caught in JIT server call.");
843-
hr = E_FAIL;
838+
AssertOrFailFastMsg(false, "Unknown exception caught in JIT server call.");
844839
}
845840

846-
if (hr == E_OUTOFMEMORY || hr == E_FAIL)
841+
if (hr == E_OUTOFMEMORY)
847842
{
848843
if (HRESULT_FROM_WIN32(MemoryOperationLastError::GetLastError()) != S_OK)
849844
{

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,22 +2343,7 @@ namespace Js
23432343
}
23442344
END_LEAVE_SCRIPT_INTERNAL(m_scriptContext);
23452345

2346-
if (hr == E_OUTOFMEMORY)
2347-
{
2348-
JavascriptError::ThrowOutOfMemoryError(m_scriptContext);
2349-
}
2350-
else if(hr == VBSERR_OutOfStack)
2351-
{
2352-
JavascriptError::ThrowStackOverflowError(m_scriptContext);
2353-
}
2354-
else if(hr == E_ABORT)
2355-
{
2356-
throw Js::ScriptAbortException();
2357-
}
2358-
else if(FAILED(hr))
2359-
{
2360-
throw Js::InternalErrorException();
2361-
}
2346+
THROW_KNOWN_HRESULT_EXCEPTIONS(hr, m_scriptContext);
23622347

23632348
Assert(hr == NO_ERROR);
23642349

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -925,22 +925,7 @@ namespace Js
925925
#ifdef PROFILE_EXEC
926926
scriptContext->ProfileEnd(Js::EvalCompilePhase);
927927
#endif
928-
if (hr == E_OUTOFMEMORY)
929-
{
930-
JavascriptError::ThrowOutOfMemoryError(scriptContext);
931-
}
932-
else if(hr == VBSERR_OutOfStack)
933-
{
934-
JavascriptError::ThrowStackOverflowError(scriptContext);
935-
}
936-
else if(hr == E_ABORT)
937-
{
938-
throw Js::ScriptAbortException();
939-
}
940-
else if(FAILED(hr))
941-
{
942-
throw Js::InternalErrorException();
943-
}
928+
THROW_KNOWN_HRESULT_EXCEPTIONS(hr, scriptContext);
944929

945930
if (!SUCCEEDED(hrParser))
946931
{
@@ -1087,22 +1072,7 @@ namespace Js
10871072
#ifdef PROFILE_EXEC
10881073
scriptContext->ProfileEnd(Js::EvalCompilePhase);
10891074
#endif
1090-
if (hr == E_OUTOFMEMORY)
1091-
{
1092-
JavascriptError::ThrowOutOfMemoryError(scriptContext);
1093-
}
1094-
else if(hr == VBSERR_OutOfStack)
1095-
{
1096-
JavascriptError::ThrowStackOverflowError(scriptContext);
1097-
}
1098-
else if(hr == E_ABORT)
1099-
{
1100-
throw Js::ScriptAbortException();
1101-
}
1102-
else if(FAILED(hr))
1103-
{
1104-
throw Js::InternalErrorException();
1105-
}
1075+
THROW_KNOWN_HRESULT_EXCEPTIONS(hr);
11061076

11071077
if (!SUCCEEDED(hrParser))
11081078
{

lib/Runtime/Library/JavascriptFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ namespace Js
709709
{
710710
// Just don't execute anything if we are in an assert
711711
// throw the exception directly to avoid additional assert in Js::Throw::InternalError
712-
throw Js::InternalErrorException();
712+
AssertOrFailFast(false);
713713
}
714714
#endif
715715

0 commit comments

Comments
 (0)