| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 assertThrows("f0.apply(this, 1, 2);"); | 87 assertThrows("f0.apply(this, 1, 2);"); |
| 88 assertThrows("f0.apply(this, 1, new Array(2));"); | 88 assertThrows("f0.apply(this, 1, new Array(2));"); |
| 89 | 89 |
| 90 function f() { | 90 function f() { |
| 91 var doo = ""; | 91 var doo = ""; |
| 92 for (var i = 0; i < arguments.length; i++) { | 92 for (var i = 0; i < arguments.length; i++) { |
| 93 doo += arguments[i]; | 93 doo += arguments[i]; |
| 94 } | 94 } |
| 95 return doo; | 95 return doo; |
| 96 } | 96 } |
| 97 | 97 |
| 98 assertEquals("42foofishhorse", f.apply(this, arr), "apply to this"); | 98 assertEquals("42foofishhorse", f.apply(this, arr), "apply to this"); |
| 99 | 99 |
| 100 function s() { | 100 function s() { |
| 101 var doo = this; | 101 var doo = this; |
| 102 for (var i = 0; i < arguments.length; i++) { | 102 for (var i = 0; i < arguments.length; i++) { |
| 103 doo += arguments[i]; | 103 doo += arguments[i]; |
| 104 } | 104 } |
| 105 return doo; | 105 return doo; |
| 106 } | 106 } |
| 107 | 107 |
| 108 assertEquals("bar42foofishhorse", s.apply("bar", arr), "apply to string"); | 108 assertEquals("bar42foofishhorse", s.apply("bar", arr), "apply to string"); |
| 109 | 109 |
| 110 function al() { | 110 function al() { |
| 111 assertEquals(345, this); | 111 assertEquals(345, this); |
| 112 return arguments.length + arguments[arguments.length - 1]; | 112 return arguments.length + arguments[arguments.length - 1]; |
| 113 } | 113 } |
| 114 | 114 |
| 115 var stack_corner_case_failure = false; | |
| 116 | |
| 117 for (var j = 1; j < 0x40000000; j <<= 1) { | 115 for (var j = 1; j < 0x40000000; j <<= 1) { |
| 118 try { | 116 try { |
| 119 var a = new Array(j); | 117 var a = new Array(j); |
| 120 a[j - 1] = 42; | 118 a[j - 1] = 42; |
| 121 assertEquals(42 + j, al.apply(345, a)); | 119 assertEquals(42 + j, al.apply(345, a)); |
| 122 } catch (e) { | 120 } catch (e) { |
| 123 if (e.toString().indexOf("Maximum call stack size exceeded") != -1) { | 121 assertTrue(e.toString().indexOf("Maximum call stack size exceeded") != -1); |
| 124 // For some combinations of build settings, it may be the case that the | |
| 125 // stack here is just tall enough to contain the array whose size is | |
| 126 // specified by j but is not tall enough to contain the activation | |
| 127 // record for the apply call. Allow one such corner case through, | |
| 128 // checking that the length check will do the right thing for an array | |
| 129 // the next size up. | |
| 130 assertEquals(false, stack_corner_case_failure); | |
| 131 stack_corner_case_failure = true; | |
| 132 continue; | |
| 133 } | |
| 134 assertTrue(e.toString().indexOf("Function.prototype.apply") != -1, | |
| 135 "exception does not contain Function.prototype.apply: " + | |
| 136 e.toString()); | |
| 137 for (; j < 0x40000000; j <<= 1) { | 122 for (; j < 0x40000000; j <<= 1) { |
| 138 var caught = false; | 123 var caught = false; |
| 139 try { | 124 try { |
| 140 a = new Array(j); | 125 a = new Array(j); |
| 141 a[j - 1] = 42; | 126 a[j - 1] = 42; |
| 142 al.apply(345, a); | 127 al.apply(345, a); |
| 143 assertUnreachable("Apply of array with length " + a.length + | 128 assertUnreachable("Apply of array with length " + a.length + |
| 144 " should have thrown"); | 129 " should have thrown"); |
| 145 } catch (e) { | 130 } catch (e) { |
| 146 assertTrue(e.toString().indexOf("Function.prototype.apply") != -1, | 131 assertTrue(e.toString().indexOf("Maximum call stack size exceeded") != -
1); |
| 147 "exception does not contain Function.prototype.apply [" + | |
| 148 "length = " + j + "]: " + e.toString()); | |
| 149 caught = true; | 132 caught = true; |
| 150 } | 133 } |
| 151 assertTrue(caught, "exception not caught"); | 134 assertTrue(caught, "exception not caught"); |
| 152 } | 135 } |
| 153 break; | 136 break; |
| 154 } | 137 } |
| 155 } | 138 } |
| 156 | 139 |
| 157 var primes = new Array(0); | 140 var primes = new Array(0); |
| 158 | 141 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 "morseper4"); | 183 "morseper4"); |
| 201 | 184 |
| 202 primes[0] = ""; | 185 primes[0] = ""; |
| 203 primes[1] = holey; | 186 primes[1] = holey; |
| 204 assertThrows("String.prototype.concat.apply.apply('foo', primes)"); | 187 assertThrows("String.prototype.concat.apply.apply('foo', primes)"); |
| 205 assertEquals("morseper", | 188 assertEquals("morseper", |
| 206 String.prototype.concat.apply.apply(String.prototype.concat, primes), | 189 String.prototype.concat.apply.apply(String.prototype.concat, primes), |
| 207 "moreseper-prime"); | 190 "moreseper-prime"); |
| 208 | 191 |
| 209 delete(Array.prototype["1"]); | 192 delete(Array.prototype["1"]); |
| OLD | NEW |