[TurboFan] Improved unit test for optimized Array.prototype.map.

Test mjsunit/optimized-map walked an array through different
ElementsKind transitions, but it failed to verify that the
expected ElementsKind was in place. Although we have a regression
test for the bug, it's a good idea to make sure the basic
test covers all paths.

Bug: chromium:747075
Change-Id: I1424880801857f3356bfd63839d351d6fd1521e0
Reviewed-on: https://chromium-review.googlesource.com/584837
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46933}
This commit is contained in:
Mike Stanton 2017-07-25 14:35:24 +02:00 committed by Commit Bot
parent b1e10f4b49
commit 950e4f4631

View File

@ -362,6 +362,33 @@ var c = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
(function() {
var result = 0;
var to_double = function() {
var callback = function(v,i,o) {
result += v;
if (i < 5) {
// First transition the output array to PACKED_DOUBLE_ELEMENTS.
return v + 0.5;
} else {
// Then return smi values and make sure they can live in the double
// array.
return v;
}
}
return c.map(callback);
}
to_double();
to_double();
%OptimizeFunctionOnNextCall(to_double);
var output = to_double();
assertTrue(%HasDoubleElements(output));
assertEquals(1.5, output[0]);
assertEquals(6, output[5]);
assertEquals(975, result);
assertOptimized(to_double);
})();
(function() {
var result = 0;
var to_fast = function() {
var callback = function(v,i,o) {
result += v;
if (i < 5) {
@ -378,13 +405,14 @@ var c = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
}
return c.map(callback);
}
to_double();
to_double();
%OptimizeFunctionOnNextCall(to_double);
var output = to_double();
to_fast();
to_fast();
%OptimizeFunctionOnNextCall(to_fast);
var output = to_fast();
%HasObjectElements(output);
assertEquals(975, result);
assertEquals("11hello", output[10]);
assertOptimized(to_double);
assertOptimized(to_fast);
})();
// Messing with the Array species constructor causes deoptimization.