1// Copyright 2008 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 L0() { 31 return %_ArgumentsLength(); 32} 33 34function L1(a) { 35 return %_ArgumentsLength(); 36} 37 38function L5(a,b,c,d,e) { 39 return %_ArgumentsLength(); 40} 41 42 43assertEquals(0, L0()); 44assertEquals(1, L0(1)); 45assertEquals(2, L0(1,2)); 46assertEquals(5, L0(1,2,3,4,5)); 47 48assertEquals(0, L1()); 49assertEquals(1, L1(1)); 50assertEquals(2, L1(1,2)); 51assertEquals(5, L1(1,2,3,4,5)); 52 53assertEquals(0, L5()); 54assertEquals(1, L5(1)); 55assertEquals(2, L5(1,2)); 56assertEquals(5, L5(1,2,3,4,5)); 57 58 59function A(key) { 60 return %_Arguments(key); 61} 62 63// Integer access. 64assertEquals(0, A(0)); 65assertEquals(0, A(0,1)); 66assertEquals(2, A(1,2)); 67assertEquals(2, A(1,2,3,4,5)); 68assertEquals(5, A(4,2,3,4,5)); 69assertTrue(typeof A(1) == 'undefined'); 70assertTrue(typeof A(3,2,1) == 'undefined'); 71 72// Out-of-bounds integer access with and without argument 73// adaptor frames. 74assertTrue(typeof(A(-10000)) == 'undefined'); 75assertTrue(typeof(A(-10000, 0)) == 'undefined'); 76assertTrue(typeof(A(-1)) == 'undefined'); 77assertTrue(typeof(A(-1, 0)) == 'undefined'); 78assertTrue(typeof(A(10000)) == 'undefined'); 79assertTrue(typeof(A(10000, 0)) == 'undefined'); 80 81// String access. 82assertEquals('0', A('0')); 83assertEquals('0', A('0',1)); 84assertEquals(2, A('1',2)); 85assertEquals(2, A('1',2,3,4,5)); 86assertEquals(5, A('4',2,3,4,5)); 87assertEquals('undefined', typeof A('1')); 88assertEquals('undefined', typeof A('3',2,1)); 89assertEquals(A, A('callee')); 90assertEquals(1, A('length')); 91assertEquals(2, A('length',2)); 92assertEquals(5, A('length',2,3,4,5)); 93assertEquals({}.toString, A('toString')); 94assertEquals({}.isPrototypeOf, A('isPrototypeOf')); 95assertEquals('undefined', typeof A('xxx')); 96 97// Object access. 98function O(key) { 99 return { toString: function() { return key; } }; 100} 101 102var O0 = O(0); 103assertSame(O0, A(O0)); 104assertSame(O0, A(O0,1)); 105assertEquals(2, A(O(1),2)); 106assertEquals(2, A(O(1),2,3,4,5)); 107assertEquals(5, A(O(4),2,3,4,5)); 108assertTrue(typeof A(O(1)) == 'undefined'); 109assertTrue(typeof A(O(3),2,1) == 'undefined'); 110 111O0 = O('0'); 112assertSame(O0, A(O0)); 113assertSame(O0, A(O0,1)); 114assertEquals(2, A(O('1'),2)); 115assertEquals(2, A(O('1'),2,3,4,5)); 116assertEquals(5, A(O('4'),2,3,4,5)); 117assertTrue(typeof A(O('1')) == 'undefined'); 118assertTrue(typeof A(O('3'),2,1) == 'undefined'); 119assertEquals(A, A(O('callee'))); 120assertEquals(1, A(O('length'))); 121assertEquals(2, A(O('length'),2)); 122assertEquals(5, A(O('length'),2,3,4,5)); 123assertEquals({}.toString, A(O('toString'))); 124assertEquals({}.isPrototypeOf, A(O('isPrototypeOf'))); 125assertTrue(typeof A(O('xxx')) == 'undefined'); 126 127// Make sure that out-of-bounds access do lookups in the 128// prototype chain. 129Object.prototype[5] = 42; 130assertEquals(42, A(5)); 131Object.prototype[-5] = 87; 132assertEquals(87, A(-5)); 133