Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Array.prototype.indexOf constant-folding should account for non-numer…
…ic index https://bugs.webkit.org/show_bug.cgi?id=246275 <rdar://problem/101242631> Reviewed by Yusuke Suzuki. With this change, a Check DFG node is emitted when Array.prototype.indexOf is constant-folded to ensure an OSR exit for non-numeric index, whose coercion might be observable. * JSTests/stress/array-indexof-constant-folding-index-coercion.js: Added. * Source/JavaScriptCore/dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupArrayIndexOf): Canonical link: https://commits.webkit.org/256590@main
- Loading branch information
Alexey Shvayka
committed
Nov 11, 2022
1 parent
90805ce
commit 77b468c
Showing
2 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
JSTests/stress/array-indexof-constant-folding-index-coercion.js
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,50 @@ | ||
function shouldBe(actual, expected) | ||
{ | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
(function() { | ||
const int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
const doubleArray = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]; | ||
|
||
const indexOfInt32Cell = index => int32Array.indexOf("test", index); | ||
const indexOfInt32Other = index => int32Array.indexOf(null, index); | ||
const indexOfInt32Boolean = index => int32Array.indexOf(true, index); | ||
const indexOfDoubleCell = index => doubleArray.indexOf(Symbol(), index); | ||
const indexOfDoubleOther = index => doubleArray.indexOf(undefined, index); | ||
const indexOfDoubleBoolean = index => doubleArray.indexOf(false, index); | ||
|
||
noInline(indexOfInt32Cell); | ||
noInline(indexOfInt32Other); | ||
noInline(indexOfInt32Boolean); | ||
noInline(indexOfDoubleCell); | ||
noInline(indexOfDoubleOther); | ||
noInline(indexOfDoubleBoolean); | ||
|
||
for (var i = 0; i < 1e6; ++i) { | ||
shouldBe(indexOfInt32Cell(0), -1); | ||
shouldBe(indexOfInt32Other(0), -1); | ||
shouldBe(indexOfInt32Boolean(0), -1); | ||
shouldBe(indexOfDoubleCell(0), -1); | ||
shouldBe(indexOfDoubleOther(0), -1); | ||
shouldBe(indexOfDoubleBoolean(0), -1); | ||
} | ||
|
||
let coercibleIndexCalls = 0; | ||
const coercibleIndex = { | ||
valueOf: () => { | ||
coercibleIndexCalls++; | ||
return 0; | ||
}, | ||
}; | ||
|
||
shouldBe(indexOfInt32Cell(coercibleIndex), -1); | ||
shouldBe(indexOfInt32Other(coercibleIndex), -1); | ||
shouldBe(indexOfInt32Boolean(coercibleIndex), -1); | ||
shouldBe(indexOfDoubleCell(coercibleIndex), -1); | ||
shouldBe(indexOfDoubleOther(coercibleIndex), -1); | ||
shouldBe(indexOfDoubleBoolean(coercibleIndex), -1); | ||
|
||
shouldBe(coercibleIndexCalls, 6); | ||
})(); |
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