Skip to content

Commit 638b186

Browse files
author
meg-gupta
committed
[1.8>1.9] [MERGE #4449 @meg-gupta] Clear inlinee callinfo from the catch of OP_TryFinally as well
Merge pull request #4449 from meg-gupta:swandclearinlineinfo When we hit an exception and we have a try finally within a try catch. We will execute finally code by calling BailOnException. Since we inline into functions with try now, we will end up in inconsistent inlinee callinfo when we call the bailout code from finally. So add the walker and clear inlinee callinfo. Also move tryCatchAddr ctor inside a scope, so that it executes before user catch code. Fixes OS#14336922
2 parents 5983ef6 + f127fd9 commit 638b186

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

lib/Runtime/Language/JavascriptExceptionOperators.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ namespace Js
174174

175175
if (exception)
176176
{
177+
#if ENABLE_NATIVE_CODEGEN
178+
if (scriptContext->GetThreadContext()->GetTryCatchFrameAddr() != nullptr)
179+
{
180+
if (exception->GetExceptionContext() && exception->GetExceptionContext()->ThrowingFunction())
181+
{
182+
WalkStackForCleaningUpInlineeInfo(scriptContext, nullptr /* start stackwalk from the current frame */, scriptContext->GetThreadContext()->GetTryCatchFrameAddr());
183+
}
184+
}
185+
#endif
177186
bool hasBailedOut = *(bool*)((char*)frame + hasBailedOutOffset); // stack offsets are negative
178187
if (hasBailedOut)
179188
{
@@ -182,6 +191,7 @@ namespace Js
182191
// Re-throw!
183192
JavascriptExceptionOperators::DoThrow(exception, scriptContext);
184193
}
194+
185195
scriptContext->GetThreadContext()->SetPendingFinallyException(exception);
186196
void *continuation = amd64_CallWithFakeFrame(finallyAddr, frame, spillSize, argsSize, exception);
187197
return continuation;
@@ -328,6 +338,15 @@ namespace Js
328338

329339
if (exception)
330340
{
341+
#if ENABLE_NATIVE_CODEGEN
342+
if (scriptContext->GetThreadContext()->GetTryCatchFrameAddr() != nullptr)
343+
{
344+
if (exception->GetExceptionContext() && exception->GetExceptionContext()->ThrowingFunction())
345+
{
346+
WalkStackForCleaningUpInlineeInfo(scriptContext, nullptr /* start stackwalk from the current frame */, scriptContext->GetThreadContext()->GetTryCatchFrameAddr());
347+
}
348+
}
349+
#endif
331350
// Clone static exception object early in case finally block overwrites it
332351
exception = exception->CloneIfStaticExceptionObject(scriptContext);
333352
bool hasBailedOut = *(bool*)((char*)localsPtr + hasBailedOutOffset); // stack offsets are sp relative
@@ -640,6 +659,15 @@ namespace Js
640659

641660
if (pExceptionObject)
642661
{
662+
#if ENABLE_NATIVE_CODEGEN
663+
if (scriptContext->GetThreadContext()->GetTryCatchFrameAddr() != nullptr)
664+
{
665+
if (pExceptionObject->GetExceptionContext() && pExceptionObject->GetExceptionContext()->ThrowingFunction())
666+
{
667+
WalkStackForCleaningUpInlineeInfo(scriptContext, nullptr /* start stackwalk from the current frame */, scriptContext->GetThreadContext()->GetTryCatchFrameAddr());
668+
}
669+
}
670+
#endif
643671
// Clone static exception object early in case finally block overwrites it
644672
pExceptionObject = pExceptionObject->CloneIfStaticExceptionObject(scriptContext);
645673
bool hasBailedOut = *(bool*)((char*)framePtr + hasBailedOutOffset); // stack offsets are negative

test/EH/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,10 @@
170170
<files>helperlabelbug2.js</files>
171171
</default>
172172
</test>
173+
<test>
174+
<default>
175+
<files>tryfinallyinlineswbug.js</files>
176+
<compile-flags> -force:inline </compile-flags>
177+
</default>
178+
</test>
173179
</regress-exe>

test/EH/tryfinallyinlineswbug.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function test2() {
7+
with ({})
8+
try {
9+
for (let nlvjnq in new Array(-3 / 0, -3 / 0, rzkvjs = {}, -3 / 0, rzkvjs = {}, -3 / 0, -3 / 0, rzkvjs = {}, rzkvjs = {}, -3 / 0, -3 / 0, rzkvjs = {}, rzkvjs = {}, rzkvjs = {}, -3 / 0, rzkvjs = {}, rzkvjs = {}, -3 / 0, rzkvjs = {}))
10+
try {
11+
try {
12+
(function () {
13+
return fxwkkq = this.zzz.zzz;
14+
}());
15+
} finally {
16+
}
17+
} catch (e) {
18+
}
19+
} catch (e) {
20+
}
21+
}
22+
test2();
23+
test2();
24+
test2();
25+
26+
WScript.Echo("Passed");

test/Error/rlexe.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<default>
3333
<files>stack.js</files>
3434
<compile-flags>-JsBuiltIn- -off:inline </compile-flags>
35+
<tags>Slow</tags>
36+
<timeout>600</timeout>
3537
</default>
3638
</test>
3739
<test>

0 commit comments

Comments
 (0)