diff options
Diffstat (limited to 'deps/v8/test/mjsunit/optimized-filter.js')
-rw-r--r-- | deps/v8/test/mjsunit/optimized-filter.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/optimized-filter.js b/deps/v8/test/mjsunit/optimized-filter.js index b13edc3b36..3c7d827e0f 100644 --- a/deps/v8/test/mjsunit/optimized-filter.js +++ b/deps/v8/test/mjsunit/optimized-filter.js @@ -417,6 +417,59 @@ } })(); +// Verify holes are skipped. +(() => { + const a = [1, 2, , 3, 4]; + let callback_values = []; + function withHoles() { + callback_values = []; + return a.filter(v => { + callback_values.push(v); + return true; + }); + } + withHoles(); + withHoles(); + %OptimizeFunctionOnNextCall(withHoles); + assertArrayEquals([1, 2, 3, 4], withHoles()); + assertArrayEquals([1, 2, 3, 4], callback_values); +})(); + +(() => { + const a = [1.5, 2.5, , 3.5, 4.5]; + let callback_values = []; + function withHoles() { + callback_values = []; + return a.filter(v => { + callback_values.push(v); + return true; + }); + } + withHoles(); + withHoles(); + %OptimizeFunctionOnNextCall(withHoles); + assertArrayEquals([1.5, 2.5, 3.5, 4.5], withHoles()); + assertArrayEquals([1.5, 2.5, 3.5, 4.5], callback_values); +})(); + +// Ensure that we handle side-effects between load and call. +(() => { + function side_effect(a, b) { if (b) a.foo = 3; return a; } + %NeverOptimizeFunction(side_effect); + + function unreliable(a, b) { + return a.filter(x => x % 2 === 0, side_effect(a, b)); + } + + let a = [1, 2, 3]; + unreliable(a, false); + unreliable(a, false); + %OptimizeFunctionOnNextCall(unreliable); + unreliable(a, false); + // Now actually do change the map. + unreliable(a, true); +})(); + // Messing with the Array species constructor causes deoptimization. (function() { var result = 0; |