regress-1229.js 4.3 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
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
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Flags: --allow-natives-syntax

// Check that %NewObjectFromBound works correctly when called from optimized
// frame.
32
function foo1(x, y, z) {
33 34 35 36 37
  assertEquals(1, x);
  assertEquals(2, y);
  assertEquals(3, z);
}

38 39 40 41 42
function foo2(x, y, z) {
  assertEquals(1, x);
  assertEquals(2, y);
  assertEquals(undefined, z);
}
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
function foo3(x, y, z) {
  assertEquals(1, x);
  assertEquals(2, y);
  assertEquals(3, z);
}


var foob1 = foo1.bind({}, 1);
var foob2 = foo2.bind({}, 1);
var foob3 = foo3.bind({}, 1);


function f1(y, z) {
  return %NewObjectFromBound(foob1);
}

function f2(y, z) {
  return %NewObjectFromBound(foob2);
}

function f3(y, z) {
  return %NewObjectFromBound(foob3);
66 67 68
}

// Check that %NewObjectFromBound looks at correct frame for inlined function.
69 70 71 72 73 74 75 76 77 78
function g1(z, y) {
  return f1(y, z); /* f should be inlined into g, note rotated arguments */
}

function g2(z, y, x) {
  return f2(y); /* f should be inlined into g, note argument count mismatch */
}

function g3(z, y, x) {
  return f3(x, y, z); /* f should be inlined into g, note argument count mismatch */
79 80 81 82
}

// Check that %NewObjectFromBound looks at correct frame for inlined function.
function ff(x) { }
83
function h1(z2, y2) {
84 85 86 87
  var local_z = z2 >> 1;
  ff(local_z);
  var local_y = y2 >> 1;
  ff(local_y);
88
  return f1(local_y, local_z); /* f should be inlined into h */
89 90
}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
function h2(z2, y2, x2) {
  var local_z = z2 >> 1;
  ff(local_z);
  var local_y = y2 >> 1;
  ff(local_y);
  return f2(local_y); /* f should be inlined into h */
}

function h3(z2, y2, x2) {
  var local_z = z2 >> 1;
  ff(local_z);
  var local_y = y2 >> 1;
  ff(local_y);
  var local_x = x2 >> 1;
  ff(local_x);
  return f3(local_x, local_y, local_z); /* f should be inlined into h */
}
108 109


110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
function invoke(f, args) {
  for (var i = 0; i < 5; i++) f.apply(this, args);
  %OptimizeFunctionOnNextCall(f);
  f.apply(this, args);
}

invoke(f1, [2, 3]);
invoke(f2, [2]);
invoke(f3, [2, 3, 4]);
invoke(g1, [3, 2]);
invoke(g2, [3, 2, 4]);
invoke(g3, [4, 3, 2]);
invoke(h1, [6, 4]);
invoke(h2, [6, 4, 8]);
invoke(h3, [8, 6, 4]);
125

126
// Check that new.target returns correct value when inlined
127 128
var NON_CONSTRUCT_MARKER = {};
var CONSTRUCT_MARKER = {};
129
function baz(x) {
130
  return (new.target === undefined) ? NON_CONSTRUCT_MARKER : CONSTRUCT_MARKER;
131 132
}

133 134
function bar(x, y, z) {
  var non_construct = baz(0); /* baz should be inlined */
135
  assertSame(non_construct, NON_CONSTRUCT_MARKER);
136
  var non_construct = baz(); /* baz should be inlined */
137
  assertSame(non_construct, NON_CONSTRUCT_MARKER);
138
  var non_construct = baz(0, 0); /* baz should be inlined */
139
  assertSame(non_construct, NON_CONSTRUCT_MARKER);
140
  var construct = new baz(0);
141
  assertSame(construct, CONSTRUCT_MARKER);
142
  var construct = new baz(0, 0);
143 144 145
  assertSame(construct, CONSTRUCT_MARKER);
}

146
invoke(bar, [1, 2, 3]);