• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2012 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// Flags: --allow-natives-syntax
29
30function test1() {
31  var a = Array(8);
32  assertTrue(%HasFastSmiOrObjectElements(a));
33  assertTrue(%HasFastHoleyElements(a));
34}
35
36function test2() {
37  var a = Array();
38  assertTrue(%HasFastSmiOrObjectElements(a));
39  assertFalse(%HasFastHoleyElements(a));
40}
41
42function test3() {
43  var a = Array(1,2,3,4,5,6,7);
44  assertTrue(%HasFastSmiOrObjectElements(a));
45  assertFalse(%HasFastHoleyElements(a));
46}
47
48function test4() {
49  var a = [1, 2, 3, 4];
50  assertTrue(%HasFastSmiElements(a));
51  assertFalse(%HasFastHoleyElements(a));
52  var b = [1, 2,, 4];
53  assertTrue(%HasFastSmiElements(b));
54  assertTrue(%HasFastHoleyElements(b));
55}
56
57function test5() {
58  var a = [1, 2, 3, 4.5];
59  assertTrue(%HasFastDoubleElements(a));
60  assertFalse(%HasFastHoleyElements(a));
61  var b = [1,, 3.5, 4];
62  assertTrue(%HasFastDoubleElements(b));
63  assertTrue(%HasFastHoleyElements(b));
64  var c = [1, 3.5,, 4];
65  assertTrue(%HasFastDoubleElements(c));
66  assertTrue(%HasFastHoleyElements(c));
67}
68
69function test6() {
70  var x = new Object();
71  var a = [1, 2, 3.5, x];
72  assertTrue(%HasFastObjectElements(a));
73  assertFalse(%HasFastHoleyElements(a));
74  assertEquals(1, a[0]);
75  assertEquals(2, a[1]);
76  assertEquals(3.5, a[2]);
77  assertEquals(x, a[3]);
78  var b = [1,, 3.5, x];
79  assertTrue(%HasFastObjectElements(b));
80  assertTrue(%HasFastHoleyElements(b));
81  assertEquals(1, b[0]);
82  assertEquals(undefined, b[1]);
83  assertEquals(3.5, b[2]);
84  assertEquals(x, b[3]);
85  var c = [1, 3.5, x,,];
86  assertTrue(%HasFastObjectElements(c));
87  assertTrue(%HasFastHoleyElements(c));
88  assertEquals(1, c[0]);
89  assertEquals(3.5, c[1]);
90  assertEquals(x, c[2]);
91  assertEquals(undefined, c[3]);
92}
93
94function test_with_optimization(f) {
95  // Run tests in a loop to make sure that inlined Array() constructor runs out
96  // of new space memory and must fall back on runtime impl.
97  for (i = 0; i < 25000; ++i) f();
98  %OptimizeFunctionOnNextCall(f);
99  for (i = 0; i < 25000; ++i) f(); // Make sure GC happens
100}
101
102test_with_optimization(test1);
103test_with_optimization(test2);
104test_with_optimization(test3);
105test_with_optimization(test4);
106test_with_optimization(test5);
107test_with_optimization(test6);
108