~ubuntu-branches/ubuntu/trusty/libv8/trusty

« back to all changes in this revision

Viewing changes to test/mjsunit/elements-transition.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2012-02-20 14:08:17 UTC
  • mfrom: (15.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20120220140817-bsvmeoa4sxsj5hbz
Tags: 3.7.12.22-3
Fix mipsel build, allow test debug-step-3 to fail (non-crucial)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2011 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 --smi-only-arrays
 
29
 
 
30
support_smi_only_arrays = %HasFastSmiOnlyElements([]);
 
31
 
 
32
if (support_smi_only_arrays) {
 
33
  function test(test_double, test_object, set, length) {
 
34
    // We apply the same operations to two identical arrays.  The first array
 
35
    // triggers an IC miss, upon which the conversion stub is generated, but the
 
36
    // actual conversion is done in runtime.  The second array, arriving at
 
37
    // the previously patched IC, is then converted using the conversion stub.
 
38
    var array_1 = new Array(length);
 
39
    var array_2 = new Array(length);
 
40
 
 
41
    assertTrue(%HasFastSmiOnlyElements(array_1));
 
42
    assertTrue(%HasFastSmiOnlyElements(array_2));
 
43
    for (var i = 0; i < length; i++) {
 
44
      if (i == length - 5 && test_double) {
 
45
        // Trigger conversion to fast double elements at length-5.
 
46
        set(array_1, i, 0.5);
 
47
        set(array_2, i, 0.5);
 
48
        assertTrue(%HasFastDoubleElements(array_1));
 
49
        assertTrue(%HasFastDoubleElements(array_2));
 
50
      } else if (i == length - 3 && test_object) {
 
51
        // Trigger conversion to fast object elements at length-3.
 
52
        set(array_1, i, 'object');
 
53
        set(array_2, i, 'object');
 
54
        assertTrue(%HasFastElements(array_1));
 
55
        assertTrue(%HasFastElements(array_2));
 
56
      } else if (i != length - 7) {
 
57
        // Set the element to an integer but leave a hole at length-7.
 
58
        set(array_1, i, 2*i+1);
 
59
        set(array_2, i, 2*i+1);
 
60
      }
 
61
    }
 
62
 
 
63
    for (var i = 0; i < length; i++) {
 
64
      if (i == length - 5 && test_double) {
 
65
        assertEquals(0.5, array_1[i]);
 
66
        assertEquals(0.5, array_2[i]);
 
67
      } else if (i == length - 3 && test_object) {
 
68
        assertEquals('object', array_1[i]);
 
69
        assertEquals('object', array_2[i]);
 
70
      } else if (i != length - 7) {
 
71
        assertEquals(2*i+1, array_1[i]);
 
72
        assertEquals(2*i+1, array_2[i]);
 
73
      } else {
 
74
        assertEquals(undefined, array_1[i]);
 
75
        assertEquals(undefined, array_2[i]);
 
76
      }
 
77
    }
 
78
 
 
79
    assertEquals(length, array_1.length);
 
80
    assertEquals(length, array_2.length);
 
81
  }
 
82
 
 
83
  test(false, false, function(a,i,v){ a[i] = v; }, 20);
 
84
  test(true,  false, function(a,i,v){ a[i] = v; }, 20);
 
85
  test(false, true,  function(a,i,v){ a[i] = v; }, 20);
 
86
  test(true,  true,  function(a,i,v){ a[i] = v; }, 20);
 
87
 
 
88
  test(false, false, function(a,i,v){ a[i] = v; }, 10000);
 
89
  test(true,  false, function(a,i,v){ a[i] = v; }, 10000);
 
90
  test(false, true,  function(a,i,v){ a[i] = v; }, 10000);
 
91
  test(true,  true,  function(a,i,v){ a[i] = v; }, 10000);
 
92
 
 
93
  // Check COW arrays
 
94
  function get_cow() { return [1, 2, 3]; }
 
95
 
 
96
  function transition(x) { x[0] = 1.5; }
 
97
 
 
98
  var ignore = get_cow();
 
99
  transition(ignore);  // Handled by runtime.
 
100
  var a = get_cow();
 
101
  var b = get_cow();
 
102
  transition(a);  // Handled by IC.
 
103
  assertEquals(1.5, a[0]);
 
104
  assertEquals(1, b[0]);
 
105
} else {
 
106
  print("Test skipped because smi only arrays are not supported.");
 
107
}
 
 
b'\\ No newline at end of file'