array-push-2.js 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --opt

// Test elements transition from SMI to DOUBLE.
(function() {
  const a = [];
  const foo = (x, y) => a.push(x, y);
11
  %PrepareFunctionForOptimization(foo);
12 13 14 15 16 17 18 19 20
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo(5, 6.6);
  assertEquals([1, 2, 3, 4, 5, 6.6], a);
})();
(function() {
  const a = [];
  const foo = (x, y) => a.push(x, y);
21
  %PrepareFunctionForOptimization(foo);
22 23 24 25 26 27 28 29 30 31 32
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo(5.5, 6.6);
  assertEquals([1, 2, 3, 4, 5.5, 6.6], a);
})();

// Test elements transition from SMI to OBJECT.
(function() {
  const a = [];
  const foo = (x, y) => a.push(x, y);
33
  %PrepareFunctionForOptimization(foo);
34 35 36 37 38 39 40 41 42
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo(5, '6');
  assertEquals([1, 2, 3, 4, 5, '6'], a);
})();
(function() {
  const a = [];
  const foo = (x, y) => a.push(x, y);
43
  %PrepareFunctionForOptimization(foo);
44 45 46 47 48 49 50 51 52 53 54
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo('5', '6');
  assertEquals([1, 2, 3, 4, '5', '6'], a);
})();

// Test elements transition from DOUBLE to OBJECT.
(function() {
  const a = [0.5];
  const foo = (x, y) => a.push(x, y);
55
  %PrepareFunctionForOptimization(foo);
56 57 58 59 60 61 62 63 64
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo(5, '6');
  assertEquals([0.5, 1, 2, 3, 4, 5, '6'], a);
})();
(function() {
  const a = [0.5];
  const foo = (x, y) => a.push(x, y);
65
  %PrepareFunctionForOptimization(foo);
66 67 68 69 70 71
  foo(1, 2);
  foo(3, 4);
  %OptimizeFunctionOnNextCall(foo);
  foo('5', '6');
  assertEquals([0.5, 1, 2, 3, 4, '5', '6'], a);
})();