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 assertEquals("ab", "a" + "b", "ll");
30 assertEquals("12", "1" + "2", "dd");
31 assertEquals("123", "1" + "2" + "3", "ddd");
32 assertEquals("123", 1 + "2" + "3", "ndd");
33 assertEquals("123", "1" + 2 + "3", "dnd");
34 assertEquals("123", "1" + "2" + 3, "ddn");
36 assertEquals("123", "1" + 2 + 3, "dnn");
37 assertEquals("123", 1 + "2" + 3, "ndn");
38 assertEquals("33", 1 + 2 + "3", "nnd");
41 assertEquals("12", x + 2, "vn");
42 assertEquals("12", x + "2", "vd");
43 assertEquals("21", 2 + x, "nv");
44 assertEquals("21", "2" + x, "dv");
47 assertEquals("12", x + y, "vdvd");
50 assertEquals("12", x + y, "vnvd");
53 assertEquals(3, x + y, "vnvn");
56 assertEquals("12", x + y, "vdvn");
59 assertEquals("12", x + y, "vdvd2");
65 assertEquals("11", x + x, "xx");
66 assertEquals("12", x + y, "xy");
67 assertEquals("13", x + z, "xz");
68 assertEquals("14", x + w, "xw");
70 assertEquals("21", y + x, "yx");
71 assertEquals("22", y + y, "yy");
72 assertEquals("23", y + z, "yz");
73 assertEquals("24", y + w, "yw");
75 assertEquals("31", z + x, "zx");
76 assertEquals("32", z + y, "zy");
77 assertEquals("33", z + z, "zz");
78 assertEquals("34", z + w, "zw");
80 assertEquals("41", w + x, "wx");
81 assertEquals("42", w + y, "wy");
82 assertEquals("43", w + z, "wz");
83 assertEquals("44", w + w, "ww");
85 (function(){x = 1; z = 3;})();
87 assertEquals(2, x + x, "x'x");
88 assertEquals("12", x + y, "x'y");
89 assertEquals(4, x + z, "x'z'");
90 assertEquals("14", x + w, "x'w");
92 assertEquals("21", y + x, "yx'");
93 assertEquals("22", y + y, "yy");
94 assertEquals("23", y + z, "yz'");
95 assertEquals("24", y + w, "yw");
97 assertEquals(4, z + x, "z'x'");
98 assertEquals("32", z + y, "z'y");
99 assertEquals(6, z + z, "z'z'");
100 assertEquals("34", z + w, "z'w");
102 assertEquals("41", w + x, "wx'");
103 assertEquals("42", w + y, "wy");
104 assertEquals("43", w + z, "wz'");
105 assertEquals("44", w + w, "ww");
108 assertEquals("142", "1" + new Number(42), "sN");
109 assertEquals("421", new Number(42) + "1", "Ns");
110 assertEquals(84, new Number(42) + new Number(42), "NN");
112 assertEquals("142", "1" + new String("42"), "sS");
113 assertEquals("421", new String("42") + "1", "Ss");
114 assertEquals("142", "1" + new String("42"), "sS");
115 assertEquals("4242", new String("42") + new String("42"), "SS");
117 assertEquals("1true", "1" + true, "sb");
118 assertEquals("true1", true + "1", "bs");
119 assertEquals(2, true + true, "bs");
121 assertEquals("1true", "1" + new Boolean(true), "sB");
122 assertEquals("true1", new Boolean(true) + "1", "Bs");
123 assertEquals(2, new Boolean(true) + new Boolean(true), "Bs");
125 assertEquals("1undefined", "1" + void 0, "sv");
126 assertEquals("undefined1", (void 0) + "1", "vs");
127 assertTrue(isNaN(void 0 + void 0), "vv");
129 assertEquals("1null", "1" + null, "su");
130 assertEquals("null1", null + "1", "us");
131 assertEquals(0, null + null, "uu");
134 // Check that incoming frames are merged correctly.
140 case 1: x = 42; y = "stry"; z = "strz"; w = 42; break;
141 default: x = "strx", y = 42; z = "strz"; w = 42; break;
159 assertEquals(84, resxx, "swxx");
160 assertEquals("42stry", resxy, "swxy");
161 assertEquals("42strz", resxz, "swxz");
162 assertEquals(84, resxw, "swxw");
163 assertEquals("stry42", resyx, "swyx");
164 assertEquals("strystry", resyy, "swyy");
165 assertEquals("strystrz", resyz, "swyz");
166 assertEquals("stry42", resyw, "swyw");
167 assertEquals("strz42", reszx, "swzx");
168 assertEquals("strzstry", reszy, "swzy");
169 assertEquals("strzstrz", reszz, "swzz");
170 assertEquals("strz42", reszw, "swzw");
171 assertEquals(84, reswx, "swwx");
172 assertEquals("42stry", reswy, "swwy");
173 assertEquals("42strz", reswz, "swwz");
174 assertEquals(84, resww, "swww");
177 // Generate ascii and non ascii strings from length 0 to 20.
178 var ascii = 'aaaaaaaaaaaaaaaaaaaa';
179 var non_ascii = '\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234';
180 assertEquals(20, ascii.length);
181 assertEquals(20, non_ascii.length);
184 for (var i = 0; i <= 20; i++) {
185 a[i] = ascii.substring(0, i);
186 b[i] = non_ascii.substring(0, i);
189 // Add ascii and non-ascii strings generating strings with length from 0 to 20.
190 for (var i = 0; i <= 20; i++) {
191 for (var j = 0; j < i; j++) {
192 assertEquals(a[i], a[j] + a[i - j])
193 assertEquals(b[i], b[j] + b[i - j])