The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / mjsunit / keyed-ic.js @ 40c0f755

History | View | Annotate | Download (5.55 KB)

1 40c0f755 Ryan
// Copyright 2008 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
// This test attempts to test the inline caching for keyed access.
29
30
// ----------------------------------------------------------------------
31
// Prototype accessor.
32
// ----------------------------------------------------------------------
33
var runTest = function() {
34
  var initial_P = 'prototype';
35
  var P = initial_P;
36
  var H = 'hasOwnProperty';
37
38
  var f = function() {};
39
40
  function prototypeTest(change_index) {
41
    for (var i = 0; i < 10; i++) {
42
      var property = f[P];
43
      if (i <= change_index) {
44
        assertEquals(f.prototype, property);
45
      } else {
46
        assertEquals(f.hasOwnProperty, property);
47
      }
48
      if (i == change_index) P = H;
49
    }
50
    P = initial_P;
51
  }
52
53
  for (var i = 0; i < 10; i++) prototypeTest(i);
54
55
  f.prototype = 43;
56
57
  for (var i = 0; i < 10; i++) prototypeTest(i);
58
}
59
60
runTest();
61
62
// ----------------------------------------------------------------------
63
// Array length accessor.
64
// ----------------------------------------------------------------------
65
runTest = function() {
66
  var initial_L = 'length';
67
  var L = initial_L;
68
  var zero = '0';
69
70
  var a = new Array(10);
71
72
  function arrayLengthTest(change_index) {
73
    for (var i = 0; i < 10; i++) {
74
      var l = a[L];
75
      if (i <= change_index) {
76
        assertEquals(10, l);
77
      } else {
78
        assertEquals(undefined, l);
79
      }
80
      if (i == change_index) L = zero;
81
    }
82
    L = initial_L;
83
  }
84
85
  for (var i = 0; i < 10; i++) arrayLengthTest(i);
86
}
87
88
runTest();
89
90
// ----------------------------------------------------------------------
91
// String length accessor.
92
// ----------------------------------------------------------------------
93
runTest = function() {
94
  var initial_L = 'length';
95
  var L = initial_L;
96
  var zero = '0';
97
98
  var s = "asdf"
99
100
  function stringLengthTest(change_index) {
101
    for (var i = 0; i < 10; i++) {
102
      var l = s[L];
103
      if (i <= change_index) {
104
        assertEquals(4, l);
105
      } else {
106
        assertEquals('a', l);
107
      }
108
      if (i == change_index) L = zero;
109
    }
110
    L = initial_L;
111
  }
112
113
  for (var i = 0; i < 10; i++) stringLengthTest(i);
114
}
115
116
runTest();
117
118
// ----------------------------------------------------------------------
119
// Field access.
120
// ----------------------------------------------------------------------
121
runTest = function() {
122
  var o = { x: 42, y: 43 }
123
124
  var initial_X = 'x';
125
  var X = initial_X;
126
  var Y = 'y';
127
128
  function fieldTest(change_index) {
129
    for (var i = 0; i < 10; i++) {
130
      var property = o[X];
131
      if (i <= change_index) {
132
        assertEquals(42, property);
133
      } else {
134
        assertEquals(43, property);
135
      }
136
      if (i == change_index) X = Y;
137
    }
138
    X = initial_X;
139
  };
140
141
  for (var i = 0; i < 10; i++) fieldTest(i);
142
}
143
144
runTest();
145
146
147
// ----------------------------------------------------------------------
148
// Constant function access.
149
// ----------------------------------------------------------------------
150
runTest = function() {
151
  function fun() { };
152
153
  var o = new Object();
154
  o.f = fun;
155
  o.x = 42;
156
157
  var initial_F = 'f';
158
  var F = initial_F;
159
  var X = 'x'
160
161
  function constantFunctionTest(change_index) {
162
    for (var i = 0; i < 10; i++) {
163
      var property = o[F];
164
      if (i <= change_index) {
165
        assertEquals(fun, property);
166
      } else {
167
        assertEquals(42, property);
168
      }
169
      if (i == change_index) F = X;
170
    }
171
    F = initial_F;
172
  };
173
174
  for (var i = 0; i < 10; i++) constantFunctionTest(i);
175
}
176
177
runTest();
178
179
// ----------------------------------------------------------------------
180
// Keyed store field.
181
// ----------------------------------------------------------------------
182
183
runTest = function() {
184
  var o = { x: 42, y: 43 }
185
186
  var initial_X = 'x';
187
  var X = initial_X;
188
  var Y = 'y';
189
190
  function fieldTest(change_index) {
191
    for (var i = 0; i < 10; i++) {
192
      o[X] = X;
193
      var property = o[X];
194
      if (i <= change_index) {
195
        assertEquals('x', property);
196
      } else {
197
        assertEquals('y', property);
198
      }
199
      if (i == change_index) X = Y;
200
    }
201
    X = initial_X;
202
  };
203
204
  for (var i = 0; i < 10; i++) fieldTest(i);
205
}
206
207
runTest();