escape-analysis-array.js 941 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2018 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

// Test variable index access to array with 1 element.
(function testOneElementArrayVariableIndex() {
  function f(i) {
    const a = new Array("first");
    return a[i];
  }

14
  %PrepareFunctionForOptimization(f);
15 16 17 18 19 20 21 22 23 24 25 26 27
  assertEquals("first", f(0));
  assertEquals("first", f(0));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("first", f(0));
})();

// Test variable index access to array with 2 elements.
(function testTwoElementArrayVariableIndex() {
  function f(i) {
    const a = new Array("first", "second");
    return a[i];
  }

28
  %PrepareFunctionForOptimization(f);
29 30 31 32 33 34
  assertEquals("first", f(0));
  assertEquals("second", f(1));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("first", f(0));
  assertEquals("second", f(1));
})();