Skip to content

Commit 6775a10

Browse files
author
Atul Katti
committed
[MERGE #5496 @atulkatti] MSFT:18321215 Typed array functions need to release the guest arena if errors happen.
Merge pull request #5496 from atulkatti:Bug18321215.TypedArray.ReleaseGuestArena.1
2 parents d80f172 + 4f71f1a commit 6775a10

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

lib/Runtime/Base/ScriptContext.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,10 +2034,16 @@ namespace Js
20342034
ArenaAllocator * allocator = nullptr;
20352035

20362036
#define ACQUIRE_TEMP_GUEST_ALLOCATOR(allocator, scriptContext, name) \
2037-
tempGuest##allocator = scriptContext->GetTemporaryGuestAllocator(name); \
2038-
allocator = tempGuest##allocator->GetAllocator();
2037+
TryFinally([&]() \
2038+
{ \
2039+
tempGuest##allocator = scriptContext->GetTemporaryGuestAllocator(name); \
2040+
allocator = tempGuest##allocator->GetAllocator();
20392041

20402042
#define RELEASE_TEMP_GUEST_ALLOCATOR(allocator, scriptContext) \
2041-
if (tempGuest##allocator) \
2042-
scriptContext->ReleaseTemporaryGuestAllocator(tempGuest##allocator);
2043+
}, \
2044+
[&](bool /*hasException*/) \
2045+
{ \
2046+
if (tempGuest##allocator) \
2047+
scriptContext->ReleaseTemporaryGuestAllocator(tempGuest##allocator); \
2048+
});
20432049

test/typedarray/bug18321215.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
// OS18321215: Typed array functions need to release the guest arena if errors happen.
7+
// This is added as a seperate file and doesn't use the unittestframework as the test depends
8+
// on certain GC behavior that doesn't trigger otherwise.
9+
try
10+
{
11+
// Type error in filter function
12+
WScript.LoadModule(`;`);
13+
(async () => {
14+
testArray1 = new Float32Array(1);
15+
testArray1.filter(function () {
16+
// type error here
17+
ArrayBuffer();
18+
});
19+
})().then();
20+
/x/, /x/, /x/, /x/;
21+
}
22+
catch(e){}
23+
24+
try
25+
{
26+
// Type error in filter function
27+
WScript.LoadModule(``);
28+
for (var foo = 0; /x/g && 0; ) {
29+
}
30+
/x/g;
31+
/x/g;
32+
try {
33+
testArray2 = new Float64Array(1);
34+
testArray2.filter(function () {
35+
// type error here
36+
ArrayBuffer();
37+
});
38+
} catch (e) {
39+
}
40+
function bar(baz = /x/g) {
41+
}
42+
}
43+
catch(e){}
44+
45+
console.log("PASS");

test/typedarray/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,9 @@ Below test fails with difference in space. Investigate the cause and re-enable t
412412
<files>typeofDetached.js</files>
413413
</default>
414414
</test>
415+
<test>
416+
<default>
417+
<files>bug18321215.js</files>
418+
</default>
419+
</test>
415420
</regress-exe>

0 commit comments

Comments
 (0)