1 // Copyright 2009 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
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.
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.
28 // Test that we can make large object literals that work.
29 // Also test that we can attempt to make even larger object literals without
31 function testLiteral(size, array_in_middle) {
36 // Build object-literal string.
37 var literal = "function f() { return ";
39 for (var i = 0; i < size; i++) {
43 literal += array_in_middle ? " [42.2]" : "{a:42.2}";
45 for (var i = 0; i < size; i++) {
48 literal += ", b:42, c:/asd/, x:'foo', y:[], z:new Object()";
54 // Create the object literal.
59 // Check that the properties have the expected values.
60 for (var i = 0; i < size; i++) {
64 if (array_in_middle) {
65 assertEquals(42.2, x[0]), "x array in middle";
68 assertEquals(42.2, x.a, "x object in middle");
73 for (var i = 0; i < size; i++) {
77 if (array_in_middle) {
78 assertEquals(42.2, y[0], "y array in middle");
81 assertEquals(42.2, y.a, "y object in middle");
87 var sizes = [1, 2, 100, 200];
90 for (var i = 0; i < sizes.length; i++) {
91 testLiteral(sizes[i], false);
92 testLiteral(sizes[i], true);
96 function checkExpectedException(e) {
97 assertInstanceof(e, RangeError);
98 assertTrue(e.message.indexOf("Maximum call stack size exceeded") >= 0);
102 function testLiteralAndCatch(size) {
103 var big_enough = false;
105 testLiteral(size, false);
107 checkExpectedException(e);
111 testLiteral(size, true);
113 checkExpectedException(e);
119 // Catch stack overflows.
121 testLiteralAndCatch(1000) ||
122 testLiteralAndCatch(20000) ||
123 testLiteralAndCatch(200000);