summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/escape-analysis-array.js
blob: 2c44fa8c9b8ae2d593041e387e11eac12eb2bef8 (plain)
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
26
27
28
29
30
31
32
// 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];
  }

  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];
  }

  assertEquals("first", f(0));
  assertEquals("second", f(1));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("first", f(0));
  assertEquals("second", f(1));
})();