array-length.js revision 8b112d2025046f85ef7f6be087c6129c872ebad2
1b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Copyright 2010 the V8 project authors. All rights reserved. 281362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// Redistribution and use in source and binary forms, with or without 381362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// modification, are permitted provided that the following conditions are 481362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// met: 581362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// 681362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// * Redistributions of source code must retain the above copyright 781362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// notice, this list of conditions and the following disclaimer. 881362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// * Redistributions in binary form must reproduce the above 981362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// copyright notice, this list of conditions and the following 1081362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// disclaimer in the documentation and/or other materials provided 1181362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// with the distribution. 1281362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// * Neither the name of Google Inc. nor the names of its 1381362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// contributors may be used to endorse or promote products derived 1481362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// from this software without specific prior written permission. 1581362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// 1681362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1781362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1881362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1981362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2081362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2181362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2281362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2381362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2481362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2581362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2681362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2781362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen 288b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch// Flags: --allow-natives-syntax 298b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch 30b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochfunction ArrayLength(a) { return a.length; } 3181362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen 32b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochfunction Test(a0, a2, a5) { 33b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch assertEquals(0, ArrayLength(a0)); 34b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch assertEquals(2, ArrayLength(a2)); 35b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch assertEquals(5, ArrayLength(a5)); 3681362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen} 3781362e16c30e9e970af6b17592f627ad8cdee4d8Kristian Monsen 38b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochvar a0 = []; 39b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochvar a2 = [1,2]; 40b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochvar a5 = [1,2,3,4,5]; 418b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdochfor (var i = 0; i < 5; i++) Test(a0, a2, a5); 428b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch%OptimizeFunctionOnNextCall(ArrayLength); 438b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch%OptimizeFunctionOnNextCall(Test); 448b112d2025046f85ef7f6be087c6129c872ebad2Ben MurdochTest(a0, a2, a5); 45b0fe1620dcb4135ac3ab2d66ff93072373911299Ben MurdochassertEquals("undefined", typeof(ArrayLength(0))); 468b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdochfor (var i = 0; i < 5; i++) Test(a0, a2, a5); 478b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch%OptimizeFunctionOnNextCall(Test); 488b112d2025046f85ef7f6be087c6129c872ebad2Ben MurdochTest(a0, a2, a5); 49b0fe1620dcb4135ac3ab2d66ff93072373911299Ben MurdochassertEquals(4, ArrayLength("hest")); 50