Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: test/mjsunit/big-object-literal.js

Issue 48133: // Test that we can make large object literals that work.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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 // Test that we can make large object literals that work.
29 // Also test that we can attempt to make even larger object literals without
30 // crashing.
31 function testLiteral(size, arrays, array_in_middle) {
32 print(size);
33
34 var f;
35
36 // Build object-literal string.
37 var literal = "function f() { return ";
38
39 for (var i = 0; i < size; i++) {
40 literal += arrays ? "[" : "{a:";
41 }
42
43 literal += array_in_middle ? " [42.2]" : "{a:42.2}";
44
45 for (var i = 0; i < size; i++) {
46 if (arrays) {
47 literal += "]";
48 } else {
49 literal += "}";
50 if (i < size - 1) {
51 literal += ", b:42, c:/asd/, x:'foo', y:[], z:new Object()";
52 }
53 }
54 }
55
56 literal += "; }";
57
58 // Create the object literal.
59 eval(literal);
60
61 var x = f();
62
63 // Check that the properties have the expected values.
64 for (var i = 0; i < size; i++) {
65 x = arrays ? x[0] : x.a;
66 }
67
68 if (array_in_middle) {
69 assertEquals(42.2, x[0]), "x array in middle";
70 x[0] = 41.2;
71 } else {
72 assertEquals(42.2, x.a, "x object in middle");
73 x.a = 41.2;
74 }
75
76 var y = f();
77 for (var i = 0; i < size; i++) {
78 y = arrays ? y[0] : y.a;
79 }
80
81 if (array_in_middle) {
82 assertEquals(42.2, y[0], "y array in middle");
83 y[0] = 41.2;
84 } else {
85 assertEquals(42.2, y.a, "y object in middle");
86 y.a = 41.2;
87 }
88 }
89
90 // The sizes to test.
91 var sizes = [1, 2, 100, 200, 400];
92
93 // Run the test.
94 for (var i = 0; i < sizes.length; i++) {
95 testLiteral(sizes[i], false, false);
96 testLiteral(sizes[i], false, true);
97 testLiteral(sizes[i], true, false);
98 testLiteral(sizes[i], true, true);
99 }
100
101 function testLiteralAndCatch(size) {
102 var big_enough = false;
103 try {
104 testLiteral(size, false, false);
105 } catch (e) {
106 big_enough = true;
107 }
108 try {
109 testLiteral(size, false, true);
110 } catch (e) {
111 big_enough = true;
112 }
113 try {
114 testLiteral(size, true, false);
115 } catch (e) {
116 big_enough = true;
117 }
118 try {
119 testLiteral(size, true, true);
120 } catch (e) {
121 big_enough = true;
122 }
123 return big_enough;
124 }
125
126 // Catch stack overflows.
127
128 testLiteralAndCatch(1000) ||
129 testLiteralAndCatch(20000) ||
130 testLiteralAndCatch(200000);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698