1// Copyright 2013 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 --expose-gc 29// Flags: --track-allocation-sites --noalways-opt 30 31// Test element kind of objects. 32// Since --smi-only-arrays affects builtins, its default setting at compile 33// time sticks if built with snapshot. If --smi-only-arrays is deactivated 34// by default, only a no-snapshot build actually has smi-only arrays enabled 35// in this test case. Depending on whether smi-only arrays are actually 36// enabled, this test takes the appropriate code path to check smi-only arrays. 37 38// support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); 39support_smi_only_arrays = true; 40 41if (support_smi_only_arrays) { 42 print("Tests include smi-only arrays."); 43} else { 44 print("Tests do NOT include smi-only arrays."); 45} 46 47function isHoley(obj) { 48 if (%HasFastHoleyElements(obj)) return true; 49 return false; 50} 51 52function assertHoley(obj, name_opt) { 53 assertEquals(true, isHoley(obj), name_opt); 54} 55 56function assertNotHoley(obj, name_opt) { 57 assertEquals(false, isHoley(obj), name_opt); 58} 59 60if (support_smi_only_arrays) { 61 function create_array(arg) { 62 return new Array(arg); 63 } 64 65 obj = create_array(0); 66 assertNotHoley(obj); 67 create_array(0); 68 %OptimizeFunctionOnNextCall(create_array); 69 obj = create_array(10); 70 assertHoley(obj); 71} 72 73// The code below would assert in debug or crash in release 74function f(length) { 75 return new Array(length) 76} 77 78f(0); 79f(0); 80%OptimizeFunctionOnNextCall(f); 81var a = f(10); 82 83function g(a) { 84 return a[0]; 85} 86 87var b = [0]; 88g(b); 89g(b); 90assertEquals(undefined, g(a)); 91