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