Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We should not crash there is a finally inside a for-in loop
https://bugs.webkit.org/show_bug.cgi?id=159243 <rdar://problem/27018910> Reviewed by Benjamin Poulain. Previously we would swap the m_forInContext with an empty vector then attempt to shrink the size of m_forInContext by the amount we expected. This meant that if there was more than one ForInContext on the stack and we wanted to pop exactly one off we would crash. This patch makes ForInContexts RefCounted so they can be duplicated into other vectors. It also has ForInContexts copy the entire stack rather than do the swap that we did before. This makes ForInContexts work the same as the other contexts. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitComplexPopScopes): (JSC::BytecodeGenerator::pushIndexedForInScope): (JSC::BytecodeGenerator::pushStructureForInScope): * bytecompiler/BytecodeGenerator.h: * tests/stress/finally-for-in.js: Added. (repeat): (createSimple): Canonical link: https://commits.webkit.org/177355@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202608 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
4 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function repeat(count, thunk) { | ||
let result = ""; | ||
for (let i = 0; i < count; i++) | ||
result += thunk(i); | ||
return result; | ||
} | ||
|
||
function createSimple(outerDepth, innerDepth, returnDepth) { | ||
return Function( | ||
` | ||
return (function(arg) { | ||
${repeat(outerDepth, (i) => `for (let a${i} in arg) ` + "{\n" )} | ||
try { | ||
${repeat(innerDepth, (i) => `for (let b${i} in arg) ` + "{\n" )} | ||
return {}; | ||
${repeat(innerDepth, () => "}")} | ||
} | ||
finally { return a${returnDepth}} | ||
${repeat(outerDepth, () => "}")} | ||
}) | ||
` | ||
)(); | ||
} | ||
|
||
function test(result, argument, ...args) { | ||
let f = createSimple(...args); | ||
|
||
let r = f(argument); | ||
if (r !== result) { | ||
throw new Error(r); | ||
} | ||
} | ||
|
||
|
||
test("0", [1,2], 1, 1, 0); | ||
test("0", [1,2], 2, 1, 0); | ||
test("0", [1,2], 2, 4, 1); | ||
test("0", [1,2], 1, 0, 0); |