Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deopt-array-prototype-indexof.js « compiler « mjsunit « test « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78cf60507c7222bc40f4528705ff4a06171160c3 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 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 --opt

/* Test deopt behaviors when the prototype has elements */

// indexOf

(function() {
  const iarr = [0,1,2];
  const darr = [0.0, 2.0, 3.3];

  function indexOf(arr, val) {
    return arr.indexOf(val);
  }

  assertEquals(0, indexOf(iarr, 0));
  assertEquals(0, indexOf(darr, 0));
  assertEquals(2, indexOf(iarr, 2));
  assertEquals(1, indexOf(darr, 2));

  // JSCallReducer for indexOf will not reduce
  // because it only works with single map
  %OptimizeFunctionOnNextCall(indexOf);

  assertEquals(0, indexOf(iarr, 0));
  assertEquals(0, indexOf(darr, 0));
})();

(function() {
  const iarr = [0,1,2];

  function indexOf(arr, val) {
    return arr.indexOf(val);
  }

  assertEquals(0, indexOf(iarr, 0));
  assertEquals(2, indexOf(iarr, 2));

  %OptimizeFunctionOnNextCall(indexOf);

  assertEquals(0, indexOf(iarr, 0));

  const darr = [0.0, 2.0, 3.3];
  // deopt because of map change
  assertEquals(0, indexOf(darr, 0));
})();

(function() {
  const iarr = [,3];

  function indexOf(arr, val) {
    return arr.indexOf(val);
  }

  iarr.__proto__ = [2];
  assertEquals(-1, indexOf(iarr, 0));
  assertEquals(0, indexOf(iarr, 2));

  %OptimizeFunctionOnNextCall(indexOf);

  assertEquals(-1, indexOf(iarr, 0));

  assertEquals(0, indexOf(iarr, 2));
})();

(function() {
  const iarr = [,3];

  function indexOf(arr, val) {
    return arr.indexOf(val);
  }

  assertEquals(-1, indexOf(iarr, 2));
  assertEquals(1, indexOf(iarr, 3));

  %OptimizeFunctionOnNextCall(indexOf);
  assertEquals(-1, indexOf(iarr, 2));

  // deopt because of map change
  iarr.__proto__ = [2];
  assertEquals(0, indexOf(iarr, 2));
})();

// This pollutes the Array prototype, so we should not run more tests
// in the same environment after this.
(function () {
  var array = [,];

  function indexOf(val) {
    return array.indexOf(val);
  }

  indexOf(6); indexOf(6);

  %OptimizeFunctionOnNextCall(indexOf);
  assertEquals(indexOf(6), -1);

  array.__proto__.push(6);
  // deopt because of no_elements_protector
  assertEquals(indexOf(6), 0);
})();