| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <fstream> | 5 #include <fstream> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/interpreter/bytecode-array-iterator.h" | 10 #include "src/interpreter/bytecode-array-iterator.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 for (const char* snippet : snippet_list) { | 106 for (const char* snippet : snippet_list) { |
| 107 std::string source_code; | 107 std::string source_code; |
| 108 if (prologue) source_code += prologue; | 108 if (prologue) source_code += prologue; |
| 109 source_code += snippet; | 109 source_code += snippet; |
| 110 if (epilogue) source_code += epilogue; | 110 if (epilogue) source_code += epilogue; |
| 111 printer.PrintExpectation(actual_stream, source_code); | 111 printer.PrintExpectation(actual_stream, source_code); |
| 112 } | 112 } |
| 113 return actual_stream.str(); | 113 return actual_stream.str(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool CompareTexts(const std::string& generated, const std::string& expected) { |
| 117 std::istringstream generated_stream(generated); |
| 118 std::istringstream expected_stream(expected); |
| 119 std::string generated_line; |
| 120 std::string expected_line; |
| 121 // Line number does not include golden file header. |
| 122 int line_number = 0; |
| 123 |
| 124 do { |
| 125 std::getline(generated_stream, generated_line); |
| 126 std::getline(expected_stream, expected_line); |
| 127 |
| 128 if (!generated_stream.good() && !expected_stream.good()) { |
| 129 return true; |
| 130 } |
| 131 |
| 132 if (!generated_stream.good()) { |
| 133 std::cerr << "Expected has extra lines after line " << line_number |
| 134 << "\n"; |
| 135 std::cerr << " Expected: '" << expected_line << "'\n"; |
| 136 return false; |
| 137 } else if (!expected_stream.good()) { |
| 138 std::cerr << "Generated has extra lines after line " << line_number |
| 139 << "\n"; |
| 140 std::cerr << " Generated: '" << generated_line << "'\n"; |
| 141 return false; |
| 142 } |
| 143 |
| 144 if (generated_line != expected_line) { |
| 145 std::cerr << "Inputs differ at line " << line_number << "\n"; |
| 146 std::cerr << " Generated: '" << generated_line << "'\n"; |
| 147 std::cerr << " Expected: '" << expected_line << "'\n"; |
| 148 return false; |
| 149 } |
| 150 line_number++; |
| 151 } while (true); |
| 152 } |
| 153 |
| 116 using ConstantPoolType = BytecodeExpectationsPrinter::ConstantPoolType; | 154 using ConstantPoolType = BytecodeExpectationsPrinter::ConstantPoolType; |
| 117 | 155 |
| 118 TEST(PrimitiveReturnStatements) { | 156 TEST(PrimitiveReturnStatements) { |
| 119 InitializedIgnitionHandleScope scope; | 157 InitializedIgnitionHandleScope scope; |
| 120 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 158 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 121 ConstantPoolType::kNumber); | 159 ConstantPoolType::kNumber); |
| 122 const char* snippets[] = { | 160 const char* snippets[] = { |
| 123 "", | 161 "", |
| 124 | 162 |
| 125 "return;", | 163 "return;\n", |
| 126 | 164 |
| 127 "return null;", | 165 "return null;\n", |
| 128 | 166 |
| 129 "return true;", | 167 "return true;\n", |
| 130 | 168 |
| 131 "return false;", | 169 "return false;\n", |
| 132 | 170 |
| 133 "return 0;", | 171 "return 0;\n", |
| 134 | 172 |
| 135 "return +1;", | 173 "return +1;\n", |
| 136 | 174 |
| 137 "return -1;", | 175 "return -1;\n", |
| 138 | 176 |
| 139 "return +127;", | 177 "return +127;\n", |
| 140 | 178 |
| 141 "return -128;", | 179 "return -128;\n", |
| 142 }; | 180 }; |
| 143 | 181 |
| 144 CHECK_EQ(BuildActual(printer, snippets), | 182 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 145 LoadGolden("PrimitiveReturnStatements.golden")); | 183 LoadGolden("PrimitiveReturnStatements.golden"))); |
| 146 } | 184 } |
| 147 | 185 |
| 148 TEST(PrimitiveExpressions) { | 186 TEST(PrimitiveExpressions) { |
| 149 InitializedIgnitionHandleScope scope; | 187 InitializedIgnitionHandleScope scope; |
| 150 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 188 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 151 ConstantPoolType::kNumber); | 189 ConstantPoolType::kNumber); |
| 152 const char* snippets[] = { | 190 const char* snippets[] = { |
| 153 "var x = 0; return x;", | 191 "var x = 0; return x;\n", |
| 154 | 192 |
| 155 "var x = 0; return x + 3;", | 193 "var x = 0; return x + 3;\n", |
| 156 | 194 |
| 157 "var x = 0; return x - 3;", | 195 "var x = 0; return x - 3;\n", |
| 158 | 196 |
| 159 "var x = 4; return x * 3;", | 197 "var x = 4; return x * 3;\n", |
| 160 | 198 |
| 161 "var x = 4; return x / 3;", | 199 "var x = 4; return x / 3;\n", |
| 162 | 200 |
| 163 "var x = 4; return x % 3;", | 201 "var x = 4; return x % 3;\n", |
| 164 | 202 |
| 165 "var x = 1; return x | 2;", | 203 "var x = 1; return x | 2;\n", |
| 166 | 204 |
| 167 "var x = 1; return x ^ 2;", | 205 "var x = 1; return x ^ 2;\n", |
| 168 | 206 |
| 169 "var x = 1; return x & 2;", | 207 "var x = 1; return x & 2;\n", |
| 170 | 208 |
| 171 "var x = 10; return x << 3;", | 209 "var x = 10; return x << 3;\n", |
| 172 | 210 |
| 173 "var x = 10; return x >> 3;", | 211 "var x = 10; return x >> 3;\n", |
| 174 | 212 |
| 175 "var x = 10; return x >>> 3;", | 213 "var x = 10; return x >>> 3;\n", |
| 176 | 214 |
| 177 "var x = 0; return (x, 3);", | 215 "var x = 0; return (x, 3);\n", |
| 178 }; | 216 }; |
| 179 | 217 |
| 180 CHECK_EQ(BuildActual(printer, snippets), | 218 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 181 LoadGolden("PrimitiveExpressions.golden")); | 219 LoadGolden("PrimitiveExpressions.golden"))); |
| 182 } | 220 } |
| 183 | 221 |
| 184 TEST(LogicalExpressions) { | 222 TEST(LogicalExpressions) { |
| 185 InitializedIgnitionHandleScope scope; | 223 InitializedIgnitionHandleScope scope; |
| 186 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 224 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 187 ConstantPoolType::kNumber); | 225 ConstantPoolType::kNumber); |
| 188 const char* snippets[] = { | 226 const char* snippets[] = { |
| 189 "var x = 0; return x || 3;", | 227 "var x = 0; return x || 3;\n", |
| 190 | 228 |
| 191 "var x = 0; return (x == 1) || 3;", | 229 "var x = 0; return (x == 1) || 3;\n", |
| 192 | 230 |
| 193 "var x = 0; return x && 3;", | 231 "var x = 0; return x && 3;\n", |
| 194 | 232 |
| 195 "var x = 0; return (x == 0) && 3;", | 233 "var x = 0; return (x == 0) && 3;\n", |
| 196 | 234 |
| 197 "var x = 0; return x || (1, 2, 3);", | 235 "var x = 0; return x || (1, 2, 3);\n", |
| 198 | 236 |
| 199 "var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);", | 237 "var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);\n", |
| 200 | 238 |
| 201 "var x = 1; var a = 2, b = 3; return x || (" // | 239 "var x = 1; var a = 2, b = 3; return x || (" // |
| 202 REPEAT_32("\n a = 1, b = 2, ") // | 240 REPEAT_32("\n a = 1, b = 2, ") // |
| 203 "3);", | 241 "3);\n", |
| 204 | 242 |
| 205 "var x = 0; var a = 2, b = 3; return x && (" // | 243 "var x = 0; var a = 2, b = 3; return x && (" // |
| 206 REPEAT_32("\n a = 1, b = 2, ") // | 244 REPEAT_32("\n a = 1, b = 2, ") // |
| 207 "3);", | 245 "3);\n", |
| 208 | 246 |
| 209 "var x = 1; var a = 2, b = 3; return (x > 3) || (" // | 247 "var x = 1; var a = 2, b = 3; return (x > 3) || (" // |
| 210 REPEAT_32("\n a = 1, b = 2, ") // | 248 REPEAT_32("\n a = 1, b = 2, ") // |
| 211 "3);", | 249 "3);\n", |
| 212 | 250 |
| 213 "var x = 0; var a = 2, b = 3; return (x < 5) && (" // | 251 "var x = 0; var a = 2, b = 3; return (x < 5) && (" // |
| 214 REPEAT_32("\n a = 1, b = 2, ") // | 252 REPEAT_32("\n a = 1, b = 2, ") // |
| 215 "3);", | 253 "3);\n", |
| 216 | 254 |
| 217 "return 0 && 3;", | 255 "return 0 && 3;\n", |
| 218 | 256 |
| 219 "return 1 || 3;", | 257 "return 1 || 3;\n", |
| 220 | 258 |
| 221 "var x = 1; return x && 3 || 0, 1;", | 259 "var x = 1; return x && 3 || 0, 1;\n", |
| 222 }; | 260 }; |
| 223 | 261 |
| 224 CHECK_EQ(BuildActual(printer, snippets), | 262 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 225 LoadGolden("LogicalExpressions.golden")); | 263 LoadGolden("LogicalExpressions.golden"))); |
| 226 } | 264 } |
| 227 | 265 |
| 228 TEST(Parameters) { | 266 TEST(Parameters) { |
| 229 InitializedIgnitionHandleScope scope; | 267 InitializedIgnitionHandleScope scope; |
| 230 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 268 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 231 ConstantPoolType::kNumber); | 269 ConstantPoolType::kNumber); |
| 232 printer.set_wrap(false); | 270 printer.set_wrap(false); |
| 233 printer.set_test_function_name("f"); | 271 printer.set_test_function_name("f"); |
| 234 | 272 |
| 235 const char* snippets[] = { | 273 const char* snippets[] = { |
| 236 "function f() { return this; }", | 274 "function f() { return this; }", |
| 237 | 275 |
| 238 "function f(arg1) { return arg1; }", | 276 "function f(arg1) { return arg1; }", |
| 239 | 277 |
| 240 "function f(arg1) { return this; }", | 278 "function f(arg1) { return this; }", |
| 241 | 279 |
| 242 "function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", | 280 "function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", |
| 243 | 281 |
| 244 "function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", | 282 "function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", |
| 245 | 283 |
| 246 "function f(arg1) { arg1 = 1; }", | 284 "function f(arg1) { arg1 = 1; }", |
| 247 | 285 |
| 248 "function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", | 286 "function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", |
| 249 }; | 287 }; |
| 250 | 288 |
| 251 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 289 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 252 LoadGolden("Parameters.golden")); | 290 LoadGolden("Parameters.golden"))); |
| 253 } | 291 } |
| 254 | 292 |
| 255 TEST(IntegerConstants) { | 293 TEST(IntegerConstants) { |
| 256 InitializedIgnitionHandleScope scope; | 294 InitializedIgnitionHandleScope scope; |
| 257 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 295 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 258 ConstantPoolType::kNumber); | 296 ConstantPoolType::kNumber); |
| 259 const char* snippets[] = { | 297 const char* snippets[] = { |
| 260 "return 12345678;", | 298 "return 12345678;\n", |
| 261 | 299 |
| 262 "var a = 1234; return 5678;", | 300 "var a = 1234; return 5678;\n", |
| 263 | 301 |
| 264 "var a = 1234; return 1234;", | 302 "var a = 1234; return 1234;\n", |
| 265 }; | 303 }; |
| 266 | 304 |
| 267 CHECK_EQ(BuildActual(printer, snippets), | 305 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 268 LoadGolden("IntegerConstants.golden")); | 306 LoadGolden("IntegerConstants.golden"))); |
| 269 } | 307 } |
| 270 | 308 |
| 271 TEST(HeapNumberConstants) { | 309 TEST(HeapNumberConstants) { |
| 272 InitializedIgnitionHandleScope scope; | 310 InitializedIgnitionHandleScope scope; |
| 273 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 311 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 274 ConstantPoolType::kNumber); | 312 ConstantPoolType::kNumber); |
| 275 const char* snippets[] = { | 313 const char* snippets[] = { |
| 276 "return 1.2;", | 314 "return 1.2;\n", |
| 277 | 315 |
| 278 "var a = 1.2; return 2.6;", | 316 "var a = 1.2; return 2.6;\n", |
| 279 | 317 |
| 280 "var a = 3.14; return 3.14;", | 318 "var a = 3.14; return 3.14;\n", |
| 281 | 319 |
| 282 "var a;" // | 320 "var a;" // |
| 283 REPEAT_256("\na = 1.414;") // | 321 REPEAT_256("\na = 1.414;") // |
| 284 " a = 3.14;", | 322 " a = 3.14;\n", |
| 285 }; | 323 }; |
| 286 | 324 |
| 287 CHECK_EQ(BuildActual(printer, snippets), | 325 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 288 LoadGolden("HeapNumberConstants.golden")); | 326 LoadGolden("HeapNumberConstants.golden"))); |
| 289 } | 327 } |
| 290 | 328 |
| 291 TEST(StringConstants) { | 329 TEST(StringConstants) { |
| 292 InitializedIgnitionHandleScope scope; | 330 InitializedIgnitionHandleScope scope; |
| 293 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 331 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 294 ConstantPoolType::kString); | 332 ConstantPoolType::kString); |
| 295 const char* snippets[] = { | 333 const char* snippets[] = { |
| 296 "return \"This is a string\";", | 334 "return \"This is a string\";\n", |
| 297 | 335 |
| 298 "var a = \"First string\"; return \"Second string\";", | 336 "var a = \"First string\"; return \"Second string\";\n", |
| 299 | 337 |
| 300 "var a = \"Same string\"; return \"Same string\";", | 338 "var a = \"Same string\"; return \"Same string\";\n", |
| 301 }; | 339 }; |
| 302 | 340 |
| 303 CHECK_EQ(BuildActual(printer, snippets), | 341 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 304 LoadGolden("StringConstants.golden")); | 342 LoadGolden("StringConstants.golden"))); |
| 305 } | 343 } |
| 306 | 344 |
| 307 TEST(PropertyLoads) { | 345 TEST(PropertyLoads) { |
| 308 InitializedIgnitionHandleScope scope; | 346 InitializedIgnitionHandleScope scope; |
| 309 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 347 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 310 ConstantPoolType::kString); | 348 ConstantPoolType::kString); |
| 311 printer.set_wrap(false); | 349 printer.set_wrap(false); |
| 312 printer.set_test_function_name("f"); | 350 printer.set_test_function_name("f"); |
| 313 | 351 |
| 314 const char* snippets[] = { | 352 const char* snippets[] = { |
| 315 "function f(a) { return a.name; }\n" | 353 "function f(a) { return a.name; }\n" |
| 316 "f({name : \"test\"});", | 354 "f({name : \"test\"});\n", |
| 317 | 355 |
| 318 "function f(a) { return a[\"key\"]; }\n" | 356 "function f(a) { return a[\"key\"]; }\n" |
| 319 "f({key : \"test\"});", | 357 "f({key : \"test\"});\n", |
| 320 | 358 |
| 321 "function f(a) { return a[100]; }\n" | 359 "function f(a) { return a[100]; }\n" |
| 322 "f({100 : \"test\"});", | 360 "f({100 : \"test\"});\n", |
| 323 | 361 |
| 324 "function f(a, b) { return a[b]; }\n" | 362 "function f(a, b) { return a[b]; }\n" |
| 325 "f({arg : \"test\"}, \"arg\");", | 363 "f({arg : \"test\"}, \"arg\");\n", |
| 326 | 364 |
| 327 "function f(a) { var b = a.name; return a[-124]; }\n" | 365 "function f(a) { var b = a.name; return a[-124]; }\n" |
| 328 "f({\"-124\" : \"test\", name : 123 })", | 366 "f({\"-124\" : \"test\", name : 123 })", |
| 329 | 367 |
| 330 "function f(a) {\n" | 368 "function f(a) {\n" |
| 331 " var b;\n" | 369 " var b;\n" |
| 332 " b = a.name;\n" | 370 " b = a.name;\n" |
| 333 REPEAT_127(" b = a.name;\n") | 371 REPEAT_127(" b = a.name;\n") |
| 334 " return a.name;\n" | 372 " return a.name;\n" |
| 335 "}\n" | 373 "}\n" |
| 336 "f({name : \"test\"})\n", | 374 "f({name : \"test\"})\n", |
| 337 | 375 |
| 338 "function f(a, b) {\n" | 376 "function f(a, b) {\n" |
| 339 " var c;\n" | 377 " var c;\n" |
| 340 " c = a[b];\n" | 378 " c = a[b];\n" |
| 341 REPEAT_127(" c = a[b];\n") | 379 REPEAT_127(" c = a[b];\n") |
| 342 " return a[b];\n" | 380 " return a[b];\n" |
| 343 "}\n" | 381 "}\n" |
| 344 "f({name : \"test\"}, \"name\")\n", | 382 "f({name : \"test\"}, \"name\")\n", |
| 345 }; | 383 }; |
| 346 | 384 |
| 347 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("PropertyLoads.golden")); | 385 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 386 LoadGolden("PropertyLoads.golden"))); |
| 348 } | 387 } |
| 349 | 388 |
| 350 TEST(PropertyStores) { | 389 TEST(PropertyStores) { |
| 351 InitializedIgnitionHandleScope scope; | 390 InitializedIgnitionHandleScope scope; |
| 352 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 391 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 353 ConstantPoolType::kString); | 392 ConstantPoolType::kString); |
| 354 printer.set_wrap(false); | 393 printer.set_wrap(false); |
| 355 printer.set_test_function_name("f"); | 394 printer.set_test_function_name("f"); |
| 356 | 395 |
| 357 const char* snippets[] = { | 396 const char* snippets[] = { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 439 |
| 401 "function f(a, b) {\n" | 440 "function f(a, b) {\n" |
| 402 " 'use strict';\n" | 441 " 'use strict';\n" |
| 403 " a[b] = 1;\n" | 442 " a[b] = 1;\n" |
| 404 REPEAT_127(" a[b] = 1;\n") | 443 REPEAT_127(" a[b] = 1;\n") |
| 405 " a[b] = 2;\n" | 444 " a[b] = 2;\n" |
| 406 "}\n" | 445 "}\n" |
| 407 "f({name : \"test\"})\n", | 446 "f({name : \"test\"})\n", |
| 408 }; | 447 }; |
| 409 | 448 |
| 410 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("PropertyStores.golden")); | 449 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 450 LoadGolden("PropertyStores.golden"))); |
| 411 } | 451 } |
| 412 | 452 |
| 413 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" | 453 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" |
| 414 | 454 |
| 415 TEST(PropertyCall) { | 455 TEST(PropertyCall) { |
| 416 InitializedIgnitionHandleScope scope; | 456 InitializedIgnitionHandleScope scope; |
| 417 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 457 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 418 ConstantPoolType::kString); | 458 ConstantPoolType::kString); |
| 419 printer.set_wrap(false); | 459 printer.set_wrap(false); |
| 420 printer.set_test_function_name("f"); | 460 printer.set_test_function_name("f"); |
| 421 | 461 |
| 422 const char* snippets[] = { | 462 const char* snippets[] = { |
| 423 "function f(a) { return a.func(); }\n" | 463 "function f(a) { return a.func(); }\n" |
| 424 "f(" FUNC_ARG ")", | 464 "f(" FUNC_ARG ")", |
| 425 | 465 |
| 426 "function f(a, b, c) { return a.func(b, c); }\n" | 466 "function f(a, b, c) { return a.func(b, c); }\n" |
| 427 "f(" FUNC_ARG ", 1, 2)", | 467 "f(" FUNC_ARG ", 1, 2)", |
| 428 | 468 |
| 429 "function f(a, b) { return a.func(b + b, b); }\n" | 469 "function f(a, b) { return a.func(b + b, b); }\n" |
| 430 "f(" FUNC_ARG ", 1)", | 470 "f(" FUNC_ARG ", 1)", |
| 431 | 471 |
| 432 "function f(a) {\n" | 472 "function f(a) {\n" |
| 433 " a.func;\n" // | 473 " a.func;\n" // |
| 434 REPEAT_127(" a.func;\n") // | 474 REPEAT_127(" a.func;\n") // |
| 435 " return a.func(); }\n" | 475 " return a.func(); }\n" |
| 436 "f(" FUNC_ARG ")", | 476 "f(" FUNC_ARG ")", |
| 437 }; | 477 }; |
| 438 | 478 |
| 439 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("PropertyCall.golden")); | 479 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 480 LoadGolden("PropertyCall.golden"))); |
| 440 } | 481 } |
| 441 | 482 |
| 442 TEST(LoadGlobal) { | 483 TEST(LoadGlobal) { |
| 443 InitializedIgnitionHandleScope scope; | 484 InitializedIgnitionHandleScope scope; |
| 444 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 485 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 445 ConstantPoolType::kString); | 486 ConstantPoolType::kString); |
| 446 printer.set_wrap(false); | 487 printer.set_wrap(false); |
| 447 printer.set_test_function_name("f"); | 488 printer.set_test_function_name("f"); |
| 448 | 489 |
| 449 const char* snippets[] = { | 490 const char* snippets[] = { |
| 450 "var a = 1;\n" | 491 "var a = 1;\n" |
| 451 "function f() { return a; }\n" | 492 "function f() { return a; }\n" |
| 452 "f()", | 493 "f()", |
| 453 | 494 |
| 454 "function t() { }\n" | 495 "function t() { }\n" |
| 455 "function f() { return t; }\n" | 496 "function f() { return t; }\n" |
| 456 "f()", | 497 "f()", |
| 457 | 498 |
| 458 "a = 1;\n" | 499 "a = 1;\n" |
| 459 "function f() { return a; }\n" | 500 "function f() { return a; }\n" |
| 460 "f()", | 501 "f()", |
| 461 | 502 |
| 462 "a = 1;\n" | 503 "a = 1;\n" |
| 463 "function f(b) {\n" | 504 "function f(b) {\n" |
| 464 " b.name;\n" | 505 " b.name;\n" |
| 465 REPEAT_127(" b.name;\n") | 506 REPEAT_127(" b.name;\n") |
| 466 " return a;\n" | 507 " return a;\n" |
| 467 "}\n" | 508 "}\n" |
| 468 "f({name: 1});", | 509 "f({name: 1});\n", |
| 469 }; | 510 }; |
| 470 | 511 |
| 471 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("LoadGlobal.golden")); | 512 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 513 LoadGolden("LoadGlobal.golden"))); |
| 472 } | 514 } |
| 473 | 515 |
| 474 TEST(StoreGlobal) { | 516 TEST(StoreGlobal) { |
| 475 InitializedIgnitionHandleScope scope; | 517 InitializedIgnitionHandleScope scope; |
| 476 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 518 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 477 ConstantPoolType::kString); | 519 ConstantPoolType::kString); |
| 478 printer.set_wrap(false); | 520 printer.set_wrap(false); |
| 479 printer.set_test_function_name("f"); | 521 printer.set_test_function_name("f"); |
| 480 | 522 |
| 481 const char* snippets[] = { | 523 const char* snippets[] = { |
| 482 "var a = 1;\n" | 524 "var a = 1;\n" |
| 483 "function f() { a = 2; }\n" | 525 "function f() { a = 2; }\n" |
| 484 "f();", | 526 "f();\n", |
| 485 | 527 |
| 486 "var a = \"test\"; function f(b) { a = b; }\n" | 528 "var a = \"test\"; function f(b) { a = b; }\n" |
| 487 "f(\"global\");", | 529 "f(\"global\");\n", |
| 488 | 530 |
| 489 "'use strict'; var a = 1;\n" | 531 "'use strict'; var a = 1;\n" |
| 490 "function f() { a = 2; }\n" | 532 "function f() { a = 2; }\n" |
| 491 "f();", | 533 "f();\n", |
| 492 | 534 |
| 493 "a = 1;\n" | 535 "a = 1;\n" |
| 494 "function f() { a = 2; }\n" | 536 "function f() { a = 2; }\n" |
| 495 "f();", | 537 "f();\n", |
| 496 | 538 |
| 497 "a = 1;\n" | 539 "a = 1;\n" |
| 498 "function f(b) {\n" | 540 "function f(b) {\n" |
| 499 " b.name;\n" | 541 " b.name;\n" |
| 500 REPEAT_127(" b.name;\n") | 542 REPEAT_127(" b.name;\n") |
| 501 " a = 2;\n" | 543 " a = 2;\n" |
| 502 "}\n" | 544 "}\n" |
| 503 "f({name: 1});", | 545 "f({name: 1});\n", |
| 504 | 546 |
| 505 "a = 1;\n" | 547 "a = 1;\n" |
| 506 "function f(b) {\n" | 548 "function f(b) {\n" |
| 507 " 'use strict';\n" | 549 " 'use strict';\n" |
| 508 " b.name;\n" | 550 " b.name;\n" |
| 509 REPEAT_127(" b.name;\n") | 551 REPEAT_127(" b.name;\n") |
| 510 " a = 2;\n" | 552 " a = 2;\n" |
| 511 "}\n" | 553 "}\n" |
| 512 "f({name: 1});", | 554 "f({name: 1});\n", |
| 513 }; | 555 }; |
| 514 | 556 |
| 515 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("StoreGlobal.golden")); | 557 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 558 LoadGolden("StoreGlobal.golden"))); |
| 516 } | 559 } |
| 517 | 560 |
| 518 TEST(CallGlobal) { | 561 TEST(CallGlobal) { |
| 519 InitializedIgnitionHandleScope scope; | 562 InitializedIgnitionHandleScope scope; |
| 520 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 563 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 521 ConstantPoolType::kString); | 564 ConstantPoolType::kString); |
| 522 printer.set_wrap(false); | 565 printer.set_wrap(false); |
| 523 printer.set_test_function_name("f"); | 566 printer.set_test_function_name("f"); |
| 524 | 567 |
| 525 const char* snippets[] = { | 568 const char* snippets[] = { |
| 526 "function t() { }\n" | 569 "function t() { }\n" |
| 527 "function f() { return t(); }\n" | 570 "function f() { return t(); }\n" |
| 528 "f();", | 571 "f();\n", |
| 529 | 572 |
| 530 "function t(a, b, c) { }\n" | 573 "function t(a, b, c) { }\n" |
| 531 "function f() { return t(1, 2, 3); }\n" | 574 "function f() { return t(1, 2, 3); }\n" |
| 532 "f();", | 575 "f();\n", |
| 533 }; | 576 }; |
| 534 | 577 |
| 535 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("CallGlobal.golden")); | 578 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 579 LoadGolden("CallGlobal.golden"))); |
| 536 } | 580 } |
| 537 | 581 |
| 538 TEST(CallRuntime) { | 582 TEST(CallRuntime) { |
| 539 InitializedIgnitionHandleScope scope; | 583 InitializedIgnitionHandleScope scope; |
| 540 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 584 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 541 ConstantPoolType::kMixed); | 585 ConstantPoolType::kMixed); |
| 542 printer.set_wrap(false); | 586 printer.set_wrap(false); |
| 543 printer.set_test_function_name("f"); | 587 printer.set_test_function_name("f"); |
| 544 | 588 |
| 545 const char* snippets[] = { | 589 const char* snippets[] = { |
| 546 "function f() { %TheHole() }\n" | 590 "function f() { %TheHole() }\n" |
| 547 "f();", | 591 "f();\n", |
| 548 | 592 |
| 549 "function f(a) { return %IsArray(a) }\n" | 593 "function f(a) { return %IsArray(a) }\n" |
| 550 "f(undefined);", | 594 "f(undefined);\n", |
| 551 | 595 |
| 552 "function f() { return %Add(1, 2) }\n" | 596 "function f() { return %Add(1, 2) }\n" |
| 553 "f();", | 597 "f();\n", |
| 554 | 598 |
| 555 "function f() { return %spread_iterable([1]) }\n" | 599 "function f() { return %spread_iterable([1]) }\n" |
| 556 "f();", | 600 "f();\n", |
| 557 }; | 601 }; |
| 558 | 602 |
| 559 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("CallRuntime.golden")); | 603 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 604 LoadGolden("CallRuntime.golden"))); |
| 560 } | 605 } |
| 561 | 606 |
| 562 TEST(IfConditions) { | 607 TEST(IfConditions) { |
| 563 InitializedIgnitionHandleScope scope; | 608 InitializedIgnitionHandleScope scope; |
| 564 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 609 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 565 ConstantPoolType::kMixed); | 610 ConstantPoolType::kMixed); |
| 566 printer.set_wrap(false); | 611 printer.set_wrap(false); |
| 567 printer.set_test_function_name("f"); | 612 printer.set_test_function_name("f"); |
| 568 | 613 |
| 569 const char* snippets[] = { | 614 const char* snippets[] = { |
| 570 "function f() {\n" | 615 "function f() {\n" |
| 571 " if (0) {\n" | 616 " if (0) {\n" |
| 572 " return 1;\n" | 617 " return 1;\n" |
| 573 " } else {\n" | 618 " } else {\n" |
| 574 " return -1;\n" | 619 " return -1;\n" |
| 575 " }\n" | 620 " }\n" |
| 576 "};\n" | 621 "};\n" |
| 577 "f();", | 622 "f();\n", |
| 578 | 623 |
| 579 "function f() {\n" | 624 "function f() {\n" |
| 580 " if ('lucky') {\n" | 625 " if ('lucky') {\n" |
| 581 " return 1;\n" | 626 " return 1;\n" |
| 582 " } else {\n" | 627 " } else {\n" |
| 583 " return -1;\n" | 628 " return -1;\n" |
| 584 " }\n" | 629 " }\n" |
| 585 "};\n" | 630 "};\n" |
| 586 "f();", | 631 "f();\n", |
| 587 | 632 |
| 588 "function f() {\n" | 633 "function f() {\n" |
| 589 " if (false) {\n" | 634 " if (false) {\n" |
| 590 " return 1;\n" | 635 " return 1;\n" |
| 591 " } else {\n" | 636 " } else {\n" |
| 592 " return -1;\n" | 637 " return -1;\n" |
| 593 " }\n" | 638 " }\n" |
| 594 "};\n" | 639 "};\n" |
| 595 "f();", | 640 "f();\n", |
| 596 | 641 |
| 597 "function f() {\n" | 642 "function f() {\n" |
| 598 " if (false) {\n" | 643 " if (false) {\n" |
| 599 " return 1;\n" | 644 " return 1;\n" |
| 600 " }\n" | 645 " }\n" |
| 601 "};\n" | 646 "};\n" |
| 602 "f();", | 647 "f();\n", |
| 603 | 648 |
| 604 "function f() {\n" | 649 "function f() {\n" |
| 605 " var a = 1;\n" | 650 " var a = 1;\n" |
| 606 " if (a) {\n" | 651 " if (a) {\n" |
| 607 " a += 1;\n" | 652 " a += 1;\n" |
| 608 " } else {\n" | 653 " } else {\n" |
| 609 " return 2;\n" | 654 " return 2;\n" |
| 610 " }\n" | 655 " }\n" |
| 611 "};\n" | 656 "};\n" |
| 612 "f();", | 657 "f();\n", |
| 613 | 658 |
| 614 "function f(a) {\n" | 659 "function f(a) {\n" |
| 615 " if (a <= 0) {\n" | 660 " if (a <= 0) {\n" |
| 616 " return 200;\n" | 661 " return 200;\n" |
| 617 " } else {\n" | 662 " } else {\n" |
| 618 " return -200;\n" | 663 " return -200;\n" |
| 619 " }\n" | 664 " }\n" |
| 620 "};\n" | 665 "};\n" |
| 621 "f(99);", | 666 "f(99);\n", |
| 622 | 667 |
| 623 "function f(a, b) { if (a in b) { return 200; } }" | 668 "function f(a, b) { if (a in b) { return 200; } }" |
| 624 "f('prop', { prop: 'yes'});", | 669 "f('prop', { prop: 'yes'});\n", |
| 625 | 670 |
| 626 "function f(z) { var a = 0; var b = 0; if (a === 0.01) {\n" | 671 "function f(z) { var a = 0; var b = 0; if (a === 0.01) {\n" |
| 627 REPEAT_64(" b = a; a = b;\n") | 672 REPEAT_64(" b = a; a = b;\n") |
| 628 " return 200; } else { return -200; } } f(0.001);", | 673 " return 200; } else { return -200; } } f(0.001);\n", |
| 629 | 674 |
| 630 "function f() {\n" | 675 "function f() {\n" |
| 631 " var a = 0; var b = 0;\n" | 676 " var a = 0; var b = 0;\n" |
| 632 " if (a) {\n" | 677 " if (a) {\n" |
| 633 REPEAT_64(" b = a; a = b;\n") | 678 REPEAT_64(" b = a; a = b;\n") |
| 634 " return 200; } else { return -200; }\n" | 679 " return 200; } else { return -200; }\n" |
| 635 "};\n" | 680 "};\n" |
| 636 "f();", | 681 "f();\n", |
| 637 | 682 |
| 638 "function f(a, b) {\n" | 683 "function f(a, b) {\n" |
| 639 " if (a == b) { return 1; }\n" | 684 " if (a == b) { return 1; }\n" |
| 640 " if (a === b) { return 1; }\n" | 685 " if (a === b) { return 1; }\n" |
| 641 " if (a < b) { return 1; }\n" | 686 " if (a < b) { return 1; }\n" |
| 642 " if (a > b) { return 1; }\n" | 687 " if (a > b) { return 1; }\n" |
| 643 " if (a <= b) { return 1; }\n" | 688 " if (a <= b) { return 1; }\n" |
| 644 " if (a >= b) { return 1; }\n" | 689 " if (a >= b) { return 1; }\n" |
| 645 " if (a in b) { return 1; }\n" | 690 " if (a in b) { return 1; }\n" |
| 646 " if (a instanceof b) { return 1; }\n" | 691 " if (a instanceof b) { return 1; }\n" |
| 647 " return 0;\n" | 692 " return 0;\n" |
| 648 "}\n" | 693 "}\n" |
| 649 "f(1, 1);", | 694 "f(1, 1);\n", |
| 650 | 695 |
| 651 "function f() {\n" | 696 "function f() {\n" |
| 652 " var a = 0;\n" | 697 " var a = 0;\n" |
| 653 " if (a) {\n" | 698 " if (a) {\n" |
| 654 " return 20;\n" | 699 " return 20;\n" |
| 655 " } else {\n" | 700 " } else {\n" |
| 656 " return -20;\n" | 701 " return -20;\n" |
| 657 " }\n" | 702 " }\n" |
| 658 "};\n" | 703 "};\n" |
| 659 "f();", | 704 "f();\n", |
| 660 }; | 705 }; |
| 661 | 706 |
| 662 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("IfConditions.golden")); | 707 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 708 LoadGolden("IfConditions.golden"))); |
| 663 } | 709 } |
| 664 | 710 |
| 665 TEST(DeclareGlobals) { | 711 TEST(DeclareGlobals) { |
| 666 InitializedIgnitionHandleScope scope; | 712 InitializedIgnitionHandleScope scope; |
| 667 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 713 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 668 ConstantPoolType::kMixed); | 714 ConstantPoolType::kMixed); |
| 669 printer.set_wrap(false); | 715 printer.set_wrap(false); |
| 670 printer.set_test_function_name("f"); | 716 printer.set_test_function_name("f"); |
| 671 printer.set_execute(false); | 717 printer.set_execute(false); |
| 672 printer.set_top_level(true); | 718 printer.set_top_level(true); |
| 673 | 719 |
| 674 const char* snippets[] = { | 720 const char* snippets[] = { |
| 675 "var a = 1;", | 721 "var a = 1;\n", |
| 676 | 722 |
| 677 "function f() {}", | 723 "function f() {}\n", |
| 678 | 724 |
| 679 "var a = 1;\n" | 725 "var a = 1;\n" |
| 680 "a=2;", | 726 "a=2;\n", |
| 681 | 727 |
| 682 "function f() {}\n" | 728 "function f() {}\n" |
| 683 "f();", | 729 "f();\n", |
| 684 }; | 730 }; |
| 685 | 731 |
| 686 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("DeclareGlobals.golden")); | 732 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 733 LoadGolden("DeclareGlobals.golden"))); |
| 687 } | 734 } |
| 688 | 735 |
| 689 TEST(BreakableBlocks) { | 736 TEST(BreakableBlocks) { |
| 690 InitializedIgnitionHandleScope scope; | 737 InitializedIgnitionHandleScope scope; |
| 691 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 738 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 692 ConstantPoolType::kMixed); | 739 ConstantPoolType::kMixed); |
| 693 | 740 |
| 694 const char* snippets[] = { | 741 const char* snippets[] = { |
| 695 "var x = 0;\n" | 742 "var x = 0;\n" |
| 696 "label: {\n" | 743 "label: {\n" |
| 697 " x = x + 1;\n" | 744 " x = x + 1;\n" |
| 698 " break label;\n" | 745 " break label;\n" |
| 699 " x = x + 1;\n" | 746 " x = x + 1;\n" |
| 700 "}\n" | 747 "}\n" |
| 701 "return x;", | 748 "return x;\n", |
| 702 | 749 |
| 703 "var sum = 0;\n" | 750 "var sum = 0;\n" |
| 704 "outer: {\n" | 751 "outer: {\n" |
| 705 " for (var x = 0; x < 10; ++x) {\n" | 752 " for (var x = 0; x < 10; ++x) {\n" |
| 706 " for (var y = 0; y < 3; ++y) {\n" | 753 " for (var y = 0; y < 3; ++y) {\n" |
| 707 " ++sum;\n" | 754 " ++sum;\n" |
| 708 " if (x + y == 12) { break outer; }\n" | 755 " if (x + y == 12) { break outer; }\n" |
| 709 " }\n" | 756 " }\n" |
| 710 " }\n" | 757 " }\n" |
| 711 "}\n" | 758 "}\n" |
| 712 "return sum;", | 759 "return sum;\n", |
| 713 | 760 |
| 714 "outer: {\n" | 761 "outer: {\n" |
| 715 " let y = 10;\n" | 762 " let y = 10;\n" |
| 716 " function f() { return y; }\n" | 763 " function f() { return y; }\n" |
| 717 " break outer;\n" | 764 " break outer;\n" |
| 718 "}\n", | 765 "}\n", |
| 719 | 766 |
| 720 "let x = 1;\n" | 767 "let x = 1;\n" |
| 721 "outer: {\n" | 768 "outer: {\n" |
| 722 " inner: {\n" | 769 " inner: {\n" |
| 723 " let y = 2;\n" | 770 " let y = 2;\n" |
| 724 " function f() { return x + y; }\n" | 771 " function f() { return x + y; }\n" |
| 725 " if (y) break outer;\n" | 772 " if (y) break outer;\n" |
| 726 " y = 3;\n" | 773 " y = 3;\n" |
| 727 " }\n" | 774 " }\n" |
| 728 "}\n" | 775 "}\n" |
| 729 "x = 4;", | 776 "x = 4;\n", |
| 730 }; | 777 }; |
| 731 | 778 |
| 732 CHECK_EQ(BuildActual(printer, snippets), | 779 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 733 LoadGolden("BreakableBlocks.golden")); | 780 LoadGolden("BreakableBlocks.golden"))); |
| 734 } | 781 } |
| 735 | 782 |
| 736 TEST(BasicLoops) { | 783 TEST(BasicLoops) { |
| 737 InitializedIgnitionHandleScope scope; | 784 InitializedIgnitionHandleScope scope; |
| 738 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 785 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 739 ConstantPoolType::kMixed); | 786 ConstantPoolType::kMixed); |
| 740 const char* snippets[] = { | 787 const char* snippets[] = { |
| 741 "var x = 0;\n" | 788 "var x = 0;\n" |
| 742 "while (false) { x = 99; break; continue; }\n" | 789 "while (false) { x = 99; break; continue; }\n" |
| 743 "return x;", | 790 "return x;\n", |
| 744 | 791 |
| 745 "var x = 0;\n" | 792 "var x = 0;\n" |
| 746 "while (false) {\n" | 793 "while (false) {\n" |
| 747 " x = x + 1;\n" | 794 " x = x + 1;\n" |
| 748 "};\n" | 795 "};\n" |
| 749 "return x;", | 796 "return x;\n", |
| 750 | 797 |
| 751 "var x = 0;\n" | 798 "var x = 0;\n" |
| 752 "var y = 1;\n" | 799 "var y = 1;\n" |
| 753 "while (x < 10) {\n" | 800 "while (x < 10) {\n" |
| 754 " y = y * 12;\n" | 801 " y = y * 12;\n" |
| 755 " x = x + 1;\n" | 802 " x = x + 1;\n" |
| 756 " if (x == 3) continue;\n" | 803 " if (x == 3) continue;\n" |
| 757 " if (x == 4) break;\n" | 804 " if (x == 4) break;\n" |
| 758 "}\n" | 805 "}\n" |
| 759 "return y;", | 806 "return y;\n", |
| 760 | 807 |
| 761 "var i = 0;\n" | 808 "var i = 0;\n" |
| 762 "while (true) {\n" | 809 "while (true) {\n" |
| 763 " if (i < 0) continue;\n" | 810 " if (i < 0) continue;\n" |
| 764 " if (i == 3) break;\n" | 811 " if (i == 3) break;\n" |
| 765 " if (i == 4) break;\n" | 812 " if (i == 4) break;\n" |
| 766 " if (i == 10) continue;\n" | 813 " if (i == 10) continue;\n" |
| 767 " if (i == 5) break;\n" | 814 " if (i == 5) break;\n" |
| 768 " i = i + 1;\n" | 815 " i = i + 1;\n" |
| 769 "}\n" | 816 "}\n" |
| 770 "return i;", | 817 "return i;\n", |
| 771 | 818 |
| 772 "var i = 0;\n" | 819 "var i = 0;\n" |
| 773 "while (true) {\n" | 820 "while (true) {\n" |
| 774 " while (i < 3) {\n" | 821 " while (i < 3) {\n" |
| 775 " if (i == 2) break;\n" | 822 " if (i == 2) break;\n" |
| 776 " i = i + 1;\n" | 823 " i = i + 1;\n" |
| 777 " }\n" | 824 " }\n" |
| 778 " i = i + 1;\n" | 825 " i = i + 1;\n" |
| 779 " break;\n" | 826 " break;\n" |
| 780 "}\n" | 827 "}\n" |
| 781 "return i;", | 828 "return i;\n", |
| 782 | 829 |
| 783 "var x = 10;\n" | 830 "var x = 10;\n" |
| 784 "var y = 1;\n" | 831 "var y = 1;\n" |
| 785 "while (x) {\n" | 832 "while (x) {\n" |
| 786 " y = y * 12;\n" | 833 " y = y * 12;\n" |
| 787 " x = x - 1;\n" | 834 " x = x - 1;\n" |
| 788 "}\n" | 835 "}\n" |
| 789 "return y;", | 836 "return y;\n", |
| 790 | 837 |
| 791 "var x = 0; var y = 1;\n" | 838 "var x = 0; var y = 1;\n" |
| 792 "do {\n" | 839 "do {\n" |
| 793 " y = y * 10;\n" | 840 " y = y * 10;\n" |
| 794 " if (x == 5) break;\n" | 841 " if (x == 5) break;\n" |
| 795 " if (x == 6) continue;\n" | 842 " if (x == 6) continue;\n" |
| 796 " x = x + 1;\n" | 843 " x = x + 1;\n" |
| 797 "} while (x < 10);\n" | 844 "} while (x < 10);\n" |
| 798 "return y;", | 845 "return y;\n", |
| 799 | 846 |
| 800 "var x = 10;\n" | 847 "var x = 10;\n" |
| 801 "var y = 1;\n" | 848 "var y = 1;\n" |
| 802 "do {\n" | 849 "do {\n" |
| 803 " y = y * 12;\n" | 850 " y = y * 12;\n" |
| 804 " x = x - 1;\n" | 851 " x = x - 1;\n" |
| 805 "} while (x);\n" | 852 "} while (x);\n" |
| 806 "return y;", | 853 "return y;\n", |
| 807 | 854 |
| 808 "var x = 0; var y = 1;\n" | 855 "var x = 0; var y = 1;\n" |
| 809 "do {\n" | 856 "do {\n" |
| 810 " y = y * 10;\n" | 857 " y = y * 10;\n" |
| 811 " if (x == 5) break;\n" | 858 " if (x == 5) break;\n" |
| 812 " x = x + 1;\n" | 859 " x = x + 1;\n" |
| 813 " if (x == 6) continue;\n" | 860 " if (x == 6) continue;\n" |
| 814 "} while (false);\n" | 861 "} while (false);\n" |
| 815 "return y;", | 862 "return y;\n", |
| 816 | 863 |
| 817 "var x = 0; var y = 1;\n" | 864 "var x = 0; var y = 1;\n" |
| 818 "do {\n" | 865 "do {\n" |
| 819 " y = y * 10;\n" | 866 " y = y * 10;\n" |
| 820 " if (x == 5) break;\n" | 867 " if (x == 5) break;\n" |
| 821 " x = x + 1;\n" | 868 " x = x + 1;\n" |
| 822 " if (x == 6) continue;\n" | 869 " if (x == 6) continue;\n" |
| 823 "} while (true);\n" | 870 "} while (true);\n" |
| 824 "return y;", | 871 "return y;\n", |
| 825 | 872 |
| 826 "var x = 0;\n" | 873 "var x = 0;\n" |
| 827 "for (;;) {\n" | 874 "for (;;) {\n" |
| 828 " if (x == 1) break;\n" | 875 " if (x == 1) break;\n" |
| 829 " if (x == 2) continue;\n" | 876 " if (x == 2) continue;\n" |
| 830 " x = x + 1;\n" | 877 " x = x + 1;\n" |
| 831 "}", | 878 "}\n", |
| 832 | 879 |
| 833 "for (var x = 0;;) {\n" | 880 "for (var x = 0;;) {\n" |
| 834 " if (x == 1) break;\n" | 881 " if (x == 1) break;\n" |
| 835 " if (x == 2) continue;\n" | 882 " if (x == 2) continue;\n" |
| 836 " x = x + 1;\n" | 883 " x = x + 1;\n" |
| 837 "}", | 884 "}\n", |
| 838 | 885 |
| 839 "var x = 0;\n" | 886 "var x = 0;\n" |
| 840 "for (;; x = x + 1) {\n" | 887 "for (;; x = x + 1) {\n" |
| 841 " if (x == 1) break;\n" | 888 " if (x == 1) break;\n" |
| 842 " if (x == 2) continue;\n" | 889 " if (x == 2) continue;\n" |
| 843 "}", | 890 "}\n", |
| 844 | 891 |
| 845 "for (var x = 0;; x = x + 1) {\n" | 892 "for (var x = 0;; x = x + 1) {\n" |
| 846 " if (x == 1) break;\n" | 893 " if (x == 1) break;\n" |
| 847 " if (x == 2) continue;\n" | 894 " if (x == 2) continue;\n" |
| 848 "}", | 895 "}\n", |
| 849 | 896 |
| 850 "var u = 0;\n" | 897 "var u = 0;\n" |
| 851 "for (var i = 0; i < 100; i = i + 1) {\n" | 898 "for (var i = 0; i < 100; i = i + 1) {\n" |
| 852 " u = u + 1;\n" | 899 " u = u + 1;\n" |
| 853 " continue;\n" | 900 " continue;\n" |
| 854 "}", | 901 "}\n", |
| 855 | 902 |
| 856 "var y = 1;\n" | 903 "var y = 1;\n" |
| 857 "for (var x = 10; x; --x) {\n" | 904 "for (var x = 10; x; --x) {\n" |
| 858 " y = y * 12;\n" | 905 " y = y * 12;\n" |
| 859 "}\n" | 906 "}\n" |
| 860 "return y;", | 907 "return y;\n", |
| 861 | 908 |
| 862 "var x = 0;\n" | 909 "var x = 0;\n" |
| 863 "for (var i = 0; false; i++) {\n" | 910 "for (var i = 0; false; i++) {\n" |
| 864 " x = x + 1;\n" | 911 " x = x + 1;\n" |
| 865 "};\n" | 912 "};\n" |
| 866 "return x;", | 913 "return x;\n", |
| 867 | 914 |
| 868 "var x = 0;\n" | 915 "var x = 0;\n" |
| 869 "for (var i = 0; true; ++i) {\n" | 916 "for (var i = 0; true; ++i) {\n" |
| 870 " x = x + 1;\n" | 917 " x = x + 1;\n" |
| 871 " if (x == 20) break;\n" | 918 " if (x == 20) break;\n" |
| 872 "};\n" | 919 "};\n" |
| 873 "return x;", | 920 "return x;\n", |
| 874 | 921 |
| 875 "var a = 0;\n" | 922 "var a = 0;\n" |
| 876 "while (a) {\n" | 923 "while (a) {\n" |
| 877 " { \n" | 924 " { \n" |
| 878 " let z = 1;\n" | 925 " let z = 1;\n" |
| 879 " function f() { z = 2; }\n" | 926 " function f() { z = 2; }\n" |
| 880 " if (z) continue;\n" | 927 " if (z) continue;\n" |
| 881 " z++;\n" | 928 " z++;\n" |
| 882 " }\n" | 929 " }\n" |
| 883 "}", | 930 "}\n", |
| 884 }; | 931 }; |
| 885 | 932 |
| 886 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("BasicLoops.golden")); | 933 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 934 LoadGolden("BasicLoops.golden"))); |
| 887 } | 935 } |
| 888 | 936 |
| 889 TEST(JumpsRequiringConstantWideOperands) { | 937 TEST(JumpsRequiringConstantWideOperands) { |
| 890 InitializedIgnitionHandleScope scope; | 938 InitializedIgnitionHandleScope scope; |
| 891 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 939 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 892 ConstantPoolType::kNumber); | 940 ConstantPoolType::kNumber); |
| 893 const char* snippets[] = { | 941 const char* snippets[] = { |
| 894 REPEAT_256("var x = 0.1;\n") | 942 REPEAT_256("var x = 0.1;\n") |
| 895 REPEAT_32("var x = 0.2;\n") | 943 REPEAT_32("var x = 0.2;\n") |
| 896 REPEAT_16("var x = 0.3;\n") | 944 REPEAT_16("var x = 0.3;\n") |
| 897 REPEAT_8("var x = 0.4;\n") | 945 REPEAT_8("var x = 0.4;\n") |
| 898 "for (var i = 0; i < 3; i++) {\n" | 946 "for (var i = 0; i < 3; i++) {\n" |
| 899 " if (i == 1) continue;\n" | 947 " if (i == 1) continue;\n" |
| 900 " if (i == 2) break;\n" | 948 " if (i == 2) break;\n" |
| 901 "}\n" | 949 "}\n" |
| 902 "return 3;", | 950 "return 3;\n", |
| 903 }; | 951 }; |
| 904 | 952 |
| 905 CHECK_EQ(BuildActual(printer, snippets), | 953 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 906 LoadGolden("JumpsRequiringConstantWideOperands.golden")); | 954 LoadGolden("JumpsRequiringConstantWideOperands.golden"))); |
| 907 } | 955 } |
| 908 | 956 |
| 909 TEST(UnaryOperators) { | 957 TEST(UnaryOperators) { |
| 910 InitializedIgnitionHandleScope scope; | 958 InitializedIgnitionHandleScope scope; |
| 911 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 959 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 912 ConstantPoolType::kNumber); | 960 ConstantPoolType::kNumber); |
| 913 const char* snippets[] = { | 961 const char* snippets[] = { |
| 914 "var x = 0;\n" | 962 "var x = 0;\n" |
| 915 "while (x != 10) {\n" | 963 "while (x != 10) {\n" |
| 916 " x = x + 10;\n" | 964 " x = x + 10;\n" |
| 917 "}\n" | 965 "}\n" |
| 918 "return x;", | 966 "return x;\n", |
| 919 | 967 |
| 920 "var x = false;\n" | 968 "var x = false;\n" |
| 921 "do {\n" | 969 "do {\n" |
| 922 " x = !x;\n" | 970 " x = !x;\n" |
| 923 "} while(x == false);\n" | 971 "} while(x == false);\n" |
| 924 "return x;", | 972 "return x;\n", |
| 925 | 973 |
| 926 "var x = 101;\n" | 974 "var x = 101;\n" |
| 927 "return void(x * 3);", | 975 "return void(x * 3);\n", |
| 928 | 976 |
| 929 "var x = 1234;\n" | 977 "var x = 1234;\n" |
| 930 "var y = void (x * x - 1);\n" | 978 "var y = void (x * x - 1);\n" |
| 931 "return y;", | 979 "return y;\n", |
| 932 | 980 |
| 933 "var x = 13;\n" | 981 "var x = 13;\n" |
| 934 "return ~x;", | 982 "return ~x;\n", |
| 935 | 983 |
| 936 "var x = 13;\n" | 984 "var x = 13;\n" |
| 937 "return +x;", | 985 "return +x;\n", |
| 938 | 986 |
| 939 "var x = 13;\n" | 987 "var x = 13;\n" |
| 940 "return -x;", | 988 "return -x;\n", |
| 941 }; | 989 }; |
| 942 | 990 |
| 943 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("UnaryOperators.golden")); | 991 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 992 LoadGolden("UnaryOperators.golden"))); |
| 944 } | 993 } |
| 945 | 994 |
| 946 TEST(Typeof) { | 995 TEST(Typeof) { |
| 947 InitializedIgnitionHandleScope scope; | 996 InitializedIgnitionHandleScope scope; |
| 948 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 997 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 949 ConstantPoolType::kString); | 998 ConstantPoolType::kString); |
| 950 printer.set_wrap(false); | 999 printer.set_wrap(false); |
| 951 printer.set_test_function_name("f"); | 1000 printer.set_test_function_name("f"); |
| 952 | 1001 |
| 953 const char* snippets[] = { | 1002 const char* snippets[] = { |
| 954 "function f() {\n" | 1003 "function f() {\n" |
| 955 " var x = 13;\n" | 1004 " var x = 13;\n" |
| 956 " return typeof(x);\n" | 1005 " return typeof(x);\n" |
| 957 "};", | 1006 "};", |
| 958 | 1007 |
| 959 "var x = 13;\n" | 1008 "var x = 13;\n" |
| 960 "function f() {\n" | 1009 "function f() {\n" |
| 961 " return typeof(x);\n" | 1010 " return typeof(x);\n" |
| 962 "};", | 1011 "};", |
| 963 }; | 1012 }; |
| 964 | 1013 |
| 965 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1014 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 966 LoadGolden("Typeof.golden")); | 1015 LoadGolden("Typeof.golden"))); |
| 967 } | 1016 } |
| 968 | 1017 |
| 969 TEST(Delete) { | 1018 TEST(Delete) { |
| 970 InitializedIgnitionHandleScope scope; | 1019 InitializedIgnitionHandleScope scope; |
| 971 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1020 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 972 ConstantPoolType::kMixed); | 1021 ConstantPoolType::kMixed); |
| 973 | 1022 |
| 974 const char* snippets[] = { | 1023 const char* snippets[] = { |
| 975 "var a = {x:13, y:14}; return delete a.x;", | 1024 "var a = {x:13, y:14}; return delete a.x;\n", |
| 976 | 1025 |
| 977 "'use strict'; var a = {x:13, y:14}; return delete a.x;", | 1026 "'use strict'; var a = {x:13, y:14}; return delete a.x;\n", |
| 978 | 1027 |
| 979 "var a = {1:13, 2:14}; return delete a[2];", | 1028 "var a = {1:13, 2:14}; return delete a[2];\n", |
| 980 | 1029 |
| 981 "var a = 10; return delete a;", | 1030 "var a = 10; return delete a;\n", |
| 982 | 1031 |
| 983 "'use strict';\n" | 1032 "'use strict';\n" |
| 984 "var a = {1:10};\n" | 1033 "var a = {1:10};\n" |
| 985 "(function f1() {return a;});\n" | 1034 "(function f1() {return a;});\n" |
| 986 "return delete a[1];", | 1035 "return delete a[1];\n", |
| 987 | 1036 |
| 988 "return delete 'test';", | 1037 "return delete 'test';\n", |
| 989 }; | 1038 }; |
| 990 | 1039 |
| 991 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Delete.golden")); | 1040 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1041 LoadGolden("Delete.golden"))); |
| 992 } | 1042 } |
| 993 | 1043 |
| 994 TEST(GlobalDelete) { | 1044 TEST(GlobalDelete) { |
| 995 InitializedIgnitionHandleScope scope; | 1045 InitializedIgnitionHandleScope scope; |
| 996 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1046 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 997 ConstantPoolType::kMixed); | 1047 ConstantPoolType::kMixed); |
| 998 printer.set_wrap(false); | 1048 printer.set_wrap(false); |
| 999 printer.set_test_function_name("f"); | 1049 printer.set_test_function_name("f"); |
| 1000 | 1050 |
| 1001 const char* snippets[] = { | 1051 const char* snippets[] = { |
| 1002 "var a = {x:13, y:14};\n" | 1052 "var a = {x:13, y:14};\n" |
| 1003 "function f() {\n" | 1053 "function f() {\n" |
| 1004 " return delete a.x;\n" | 1054 " return delete a.x;\n" |
| 1005 "};\n" | 1055 "};\n" |
| 1006 "f();", | 1056 "f();\n", |
| 1007 | 1057 |
| 1008 "a = {1:13, 2:14};\n" | 1058 "a = {1:13, 2:14};\n" |
| 1009 "function f() {\n" | 1059 "function f() {\n" |
| 1010 " 'use strict';\n" | 1060 " 'use strict';\n" |
| 1011 " return delete a[1];\n" | 1061 " return delete a[1];\n" |
| 1012 "};\n" | 1062 "};\n" |
| 1013 "f();", | 1063 "f();\n", |
| 1014 | 1064 |
| 1015 "var a = {x:13, y:14};\n" | 1065 "var a = {x:13, y:14};\n" |
| 1016 "function f() {\n" | 1066 "function f() {\n" |
| 1017 " return delete a;\n" | 1067 " return delete a;\n" |
| 1018 "};\n" | 1068 "};\n" |
| 1019 "f();", | 1069 "f();\n", |
| 1020 | 1070 |
| 1021 "b = 30;\n" | 1071 "b = 30;\n" |
| 1022 "function f() {\n" | 1072 "function f() {\n" |
| 1023 " return delete b;\n" | 1073 " return delete b;\n" |
| 1024 "};\n" | 1074 "};\n" |
| 1025 "f();", | 1075 "f();\n", |
| 1026 }; | 1076 }; |
| 1027 | 1077 |
| 1028 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("GlobalDelete.golden")); | 1078 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1079 LoadGolden("GlobalDelete.golden"))); |
| 1029 } | 1080 } |
| 1030 | 1081 |
| 1031 TEST(FunctionLiterals) { | 1082 TEST(FunctionLiterals) { |
| 1032 InitializedIgnitionHandleScope scope; | 1083 InitializedIgnitionHandleScope scope; |
| 1033 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1084 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1034 ConstantPoolType::kMixed); | 1085 ConstantPoolType::kMixed); |
| 1035 | 1086 |
| 1036 const char* snippets[] = { | 1087 const char* snippets[] = { |
| 1037 "return function(){ }", | 1088 "return function(){ }\n", |
| 1038 | 1089 |
| 1039 "return (function(){ })()", | 1090 "return (function(){ })()\n", |
| 1040 | 1091 |
| 1041 "return (function(x){ return x; })(1)", | 1092 "return (function(x){ return x; })(1)\n", |
| 1042 }; | 1093 }; |
| 1043 | 1094 |
| 1044 CHECK_EQ(BuildActual(printer, snippets), | 1095 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1045 LoadGolden("FunctionLiterals.golden")); | 1096 LoadGolden("FunctionLiterals.golden"))); |
| 1046 } | 1097 } |
| 1047 | 1098 |
| 1048 TEST(RegExpLiterals) { | 1099 TEST(RegExpLiterals) { |
| 1049 InitializedIgnitionHandleScope scope; | 1100 InitializedIgnitionHandleScope scope; |
| 1050 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1101 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1051 ConstantPoolType::kString); | 1102 ConstantPoolType::kString); |
| 1052 | 1103 |
| 1053 const char* snippets[] = { | 1104 const char* snippets[] = { |
| 1054 "return /ab+d/;", | 1105 "return /ab+d/;\n", |
| 1055 | 1106 |
| 1056 "return /(\\w+)\\s(\\w+)/i;", | 1107 "return /(\\w+)\\s(\\w+)/i;\n", |
| 1057 | 1108 |
| 1058 "return /ab+d/.exec('abdd');", | 1109 "return /ab+d/.exec('abdd');\n", |
| 1059 }; | 1110 }; |
| 1060 | 1111 |
| 1061 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("RegExpLiterals.golden")); | 1112 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1113 LoadGolden("RegExpLiterals.golden"))); |
| 1062 } | 1114 } |
| 1063 | 1115 |
| 1064 TEST(RegExpLiteralsWide) { | 1116 TEST(RegExpLiteralsWide) { |
| 1065 InitializedIgnitionHandleScope scope; | 1117 InitializedIgnitionHandleScope scope; |
| 1066 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1118 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1067 ConstantPoolType::kMixed); | 1119 ConstantPoolType::kMixed); |
| 1068 | 1120 |
| 1069 const char* snippets[] = { | 1121 const char* snippets[] = { |
| 1070 "var a;" // | 1122 "var a;" // |
| 1071 REPEAT_256("\na = 1.23;") // | 1123 REPEAT_256("\na = 1.23;") // |
| 1072 "\nreturn /ab+d/;", | 1124 "\nreturn /ab+d/;\n", |
| 1073 }; | 1125 }; |
| 1074 | 1126 |
| 1075 CHECK_EQ(BuildActual(printer, snippets), | 1127 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1076 LoadGolden("RegExpLiteralsWide.golden")); | 1128 LoadGolden("RegExpLiteralsWide.golden"))); |
| 1077 } | 1129 } |
| 1078 | 1130 |
| 1079 TEST(ArrayLiterals) { | 1131 TEST(ArrayLiterals) { |
| 1080 InitializedIgnitionHandleScope scope; | 1132 InitializedIgnitionHandleScope scope; |
| 1081 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1133 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1082 ConstantPoolType::kMixed); | 1134 ConstantPoolType::kMixed); |
| 1083 | 1135 |
| 1084 const char* snippets[] = { | 1136 const char* snippets[] = { |
| 1085 "return [ 1, 2 ];", | 1137 "return [ 1, 2 ];\n", |
| 1086 | 1138 |
| 1087 "var a = 1; return [ a, a + 1 ];", | 1139 "var a = 1; return [ a, a + 1 ];\n", |
| 1088 | 1140 |
| 1089 "return [ [ 1, 2 ], [ 3 ] ];", | 1141 "return [ [ 1, 2 ], [ 3 ] ];\n", |
| 1090 | 1142 |
| 1091 "var a = 1; return [ [ a, 2 ], [ a + 2 ] ];", | 1143 "var a = 1; return [ [ a, 2 ], [ a + 2 ] ];\n", |
| 1092 }; | 1144 }; |
| 1093 | 1145 |
| 1094 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("ArrayLiterals.golden")); | 1146 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1147 LoadGolden("ArrayLiterals.golden"))); |
| 1095 } | 1148 } |
| 1096 | 1149 |
| 1097 TEST(ArrayLiteralsWide) { | 1150 TEST(ArrayLiteralsWide) { |
| 1098 InitializedIgnitionHandleScope scope; | 1151 InitializedIgnitionHandleScope scope; |
| 1099 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1152 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1100 ConstantPoolType::kMixed); | 1153 ConstantPoolType::kMixed); |
| 1101 | 1154 |
| 1102 const char* snippets[] = { | 1155 const char* snippets[] = { |
| 1103 "var a;" // | 1156 "var a;" // |
| 1104 REPEAT_256("\na = 1.23;") // | 1157 REPEAT_256("\na = 1.23;") // |
| 1105 "\nreturn [ 1 , 2 ];", | 1158 "\nreturn [ 1 , 2 ];\n", |
| 1106 }; | 1159 }; |
| 1107 | 1160 |
| 1108 CHECK_EQ(BuildActual(printer, snippets), | 1161 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1109 LoadGolden("ArrayLiteralsWide.golden")); | 1162 LoadGolden("ArrayLiteralsWide.golden"))); |
| 1110 } | 1163 } |
| 1111 | 1164 |
| 1112 TEST(ObjectLiterals) { | 1165 TEST(ObjectLiterals) { |
| 1113 InitializedIgnitionHandleScope scope; | 1166 InitializedIgnitionHandleScope scope; |
| 1114 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1167 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1115 ConstantPoolType::kMixed); | 1168 ConstantPoolType::kMixed); |
| 1116 | 1169 |
| 1117 const char* snippets[] = { | 1170 const char* snippets[] = { |
| 1118 "return { };", | 1171 "return { };\n", |
| 1119 | 1172 |
| 1120 "return { name: 'string', val: 9.2 };", | 1173 "return { name: 'string', val: 9.2 };\n", |
| 1121 | 1174 |
| 1122 "var a = 1; return { name: 'string', val: a };", | 1175 "var a = 1; return { name: 'string', val: a };\n", |
| 1123 | 1176 |
| 1124 "var a = 1; return { val: a, val: a + 1 };", | 1177 "var a = 1; return { val: a, val: a + 1 };\n", |
| 1125 | 1178 |
| 1126 "return { func: function() { } };", | 1179 "return { func: function() { } };\n", |
| 1127 | 1180 |
| 1128 "return { func(a) { return a; } };", | 1181 "return { func(a) { return a; } };\n", |
| 1129 | 1182 |
| 1130 "return { get a() { return 2; } };", | 1183 "return { get a() { return 2; } };\n", |
| 1131 | 1184 |
| 1132 "return { get a() { return this.x; }, set a(val) { this.x = val } };", | 1185 "return { get a() { return this.x; }, set a(val) { this.x = val } };\n", |
| 1133 | 1186 |
| 1134 "return { set b(val) { this.y = val } };", | 1187 "return { set b(val) { this.y = val } };\n", |
| 1135 | 1188 |
| 1136 "var a = 1; return { 1: a };", | 1189 "var a = 1; return { 1: a };\n", |
| 1137 | 1190 |
| 1138 "return { __proto__: null };", | 1191 "return { __proto__: null };\n", |
| 1139 | 1192 |
| 1140 "var a = 'test'; return { [a]: 1 };", | 1193 "var a = 'test'; return { [a]: 1 };\n", |
| 1141 | 1194 |
| 1142 "var a = 'test'; return { val: a, [a]: 1 };", | 1195 "var a = 'test'; return { val: a, [a]: 1 };\n", |
| 1143 | 1196 |
| 1144 "var a = 'test'; return { [a]: 1, __proto__: {} };", | 1197 "var a = 'test'; return { [a]: 1, __proto__: {} };\n", |
| 1145 | 1198 |
| 1146 "var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };", | 1199 "var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };\n", |
| 1147 }; | 1200 }; |
| 1148 | 1201 |
| 1149 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("ObjectLiterals.golden")); | 1202 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1203 LoadGolden("ObjectLiterals.golden"))); |
| 1150 } | 1204 } |
| 1151 | 1205 |
| 1152 TEST(ObjectLiteralsWide) { | 1206 TEST(ObjectLiteralsWide) { |
| 1153 InitializedIgnitionHandleScope scope; | 1207 InitializedIgnitionHandleScope scope; |
| 1154 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1208 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1155 ConstantPoolType::kMixed); | 1209 ConstantPoolType::kMixed); |
| 1156 const char* snippets[] = { | 1210 const char* snippets[] = { |
| 1157 "var a;" // | 1211 "var a;" // |
| 1158 REPEAT_256("\na = 1.23;") // | 1212 REPEAT_256("\na = 1.23;") // |
| 1159 "\nreturn { name: 'string', val: 9.2 };", | 1213 "\nreturn { name: 'string', val: 9.2 };\n", |
| 1160 }; | 1214 }; |
| 1161 | 1215 |
| 1162 CHECK_EQ(BuildActual(printer, snippets), | 1216 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1163 LoadGolden("ObjectLiteralsWide.golden")); | 1217 LoadGolden("ObjectLiteralsWide.golden"))); |
| 1164 } | 1218 } |
| 1165 | 1219 |
| 1166 TEST(TopLevelObjectLiterals) { | 1220 TEST(TopLevelObjectLiterals) { |
| 1167 InitializedIgnitionHandleScope scope; | 1221 InitializedIgnitionHandleScope scope; |
| 1168 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1222 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1169 ConstantPoolType::kMixed); | 1223 ConstantPoolType::kMixed); |
| 1170 printer.set_wrap(false); | 1224 printer.set_wrap(false); |
| 1171 printer.set_test_function_name("f"); | 1225 printer.set_test_function_name("f"); |
| 1172 printer.set_execute(false); | 1226 printer.set_execute(false); |
| 1173 printer.set_top_level(true); | 1227 printer.set_top_level(true); |
| 1174 | 1228 |
| 1175 const char* snippets[] = { | 1229 const char* snippets[] = { |
| 1176 "var a = { func: function() { } };", | 1230 "var a = { func: function() { } };\n", |
| 1177 }; | 1231 }; |
| 1178 | 1232 |
| 1179 CHECK_EQ(BuildActual(printer, snippets), | 1233 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1180 LoadGolden("TopLevelObjectLiterals.golden")); | 1234 LoadGolden("TopLevelObjectLiterals.golden"))); |
| 1181 } | 1235 } |
| 1182 | 1236 |
| 1183 TEST(TryCatch) { | 1237 TEST(TryCatch) { |
| 1184 InitializedIgnitionHandleScope scope; | 1238 InitializedIgnitionHandleScope scope; |
| 1185 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1239 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1186 ConstantPoolType::kString); | 1240 ConstantPoolType::kString); |
| 1187 | 1241 |
| 1188 const char* snippets[] = { | 1242 const char* snippets[] = { |
| 1189 "try { return 1; } catch(e) { return 2; }", | 1243 "try { return 1; } catch(e) { return 2; }\n", |
| 1190 | 1244 |
| 1191 "var a;\n" | 1245 "var a;\n" |
| 1192 "try { a = 1 } catch(e1) {};\n" | 1246 "try { a = 1 } catch(e1) {};\n" |
| 1193 "try { a = 2 } catch(e2) { a = 3 }", | 1247 "try { a = 2 } catch(e2) { a = 3 }\n", |
| 1194 }; | 1248 }; |
| 1195 | 1249 |
| 1196 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("TryCatch.golden")); | 1250 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1251 LoadGolden("TryCatch.golden"))); |
| 1197 } | 1252 } |
| 1198 | 1253 |
| 1199 TEST(TryFinally) { | 1254 TEST(TryFinally) { |
| 1200 InitializedIgnitionHandleScope scope; | 1255 InitializedIgnitionHandleScope scope; |
| 1201 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1256 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1202 ConstantPoolType::kString); | 1257 ConstantPoolType::kString); |
| 1203 const char* snippets[] = { | 1258 const char* snippets[] = { |
| 1204 "var a = 1;\n" | 1259 "var a = 1;\n" |
| 1205 "try { a = 2; } finally { a = 3; }", | 1260 "try { a = 2; } finally { a = 3; }\n", |
| 1206 | 1261 |
| 1207 "var a = 1;\n" | 1262 "var a = 1;\n" |
| 1208 "try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 1263 "try { a = 2; } catch(e) { a = 20 } finally { a = 3; }\n", |
| 1209 | 1264 |
| 1210 "var a; try {\n" | 1265 "var a; try {\n" |
| 1211 " try { a = 1 } catch(e) { a = 2 }\n" | 1266 " try { a = 1 } catch(e) { a = 2 }\n" |
| 1212 "} catch(e) { a = 20 } finally { a = 3; }", | 1267 "} catch(e) { a = 20 } finally { a = 3; }\n", |
| 1213 }; | 1268 }; |
| 1214 | 1269 |
| 1215 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("TryFinally.golden")); | 1270 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1271 LoadGolden("TryFinally.golden"))); |
| 1216 } | 1272 } |
| 1217 | 1273 |
| 1218 TEST(Throw) { | 1274 TEST(Throw) { |
| 1219 InitializedIgnitionHandleScope scope; | 1275 InitializedIgnitionHandleScope scope; |
| 1220 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1276 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1221 ConstantPoolType::kString); | 1277 ConstantPoolType::kString); |
| 1222 const char* snippets[] = { | 1278 const char* snippets[] = { |
| 1223 "throw 1;", | 1279 "throw 1;\n", |
| 1224 | 1280 |
| 1225 "throw 'Error';", | 1281 "throw 'Error';\n", |
| 1226 | 1282 |
| 1227 "var a = 1; if (a) { throw 'Error'; };", | 1283 "var a = 1; if (a) { throw 'Error'; };\n", |
| 1228 }; | 1284 }; |
| 1229 | 1285 |
| 1230 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Throw.golden")); | 1286 CHECK( |
| 1287 CompareTexts(BuildActual(printer, snippets), LoadGolden("Throw.golden"))); |
| 1231 } | 1288 } |
| 1232 | 1289 |
| 1233 TEST(CallNew) { | 1290 TEST(CallNew) { |
| 1234 InitializedIgnitionHandleScope scope; | 1291 InitializedIgnitionHandleScope scope; |
| 1235 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1292 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1236 ConstantPoolType::kMixed); | 1293 ConstantPoolType::kMixed); |
| 1237 printer.set_wrap(false); | 1294 printer.set_wrap(false); |
| 1238 printer.set_test_function_name("f"); | 1295 printer.set_test_function_name("f"); |
| 1239 | 1296 |
| 1240 const char* snippets[] = { | 1297 const char* snippets[] = { |
| 1241 "function bar() { this.value = 0; }\n" | 1298 "function bar() { this.value = 0; }\n" |
| 1242 "function f() { return new bar(); }\n" | 1299 "function f() { return new bar(); }\n" |
| 1243 "f();", | 1300 "f();\n", |
| 1244 | 1301 |
| 1245 "function bar(x) { this.value = 18; this.x = x;}\n" | 1302 "function bar(x) { this.value = 18; this.x = x;}\n" |
| 1246 "function f() { return new bar(3); }\n" | 1303 "function f() { return new bar(3); }\n" |
| 1247 "f();", | 1304 "f();\n", |
| 1248 | 1305 |
| 1249 "function bar(w, x, y, z) {\n" | 1306 "function bar(w, x, y, z) {\n" |
| 1250 " this.value = 18;\n" | 1307 " this.value = 18;\n" |
| 1251 " this.x = x;\n" | 1308 " this.x = x;\n" |
| 1252 " this.y = y;\n" | 1309 " this.y = y;\n" |
| 1253 " this.z = z;\n" | 1310 " this.z = z;\n" |
| 1254 "}\n" | 1311 "}\n" |
| 1255 "function f() { return new bar(3, 4, 5); }\n" | 1312 "function f() { return new bar(3, 4, 5); }\n" |
| 1256 "f();", | 1313 "f();\n", |
| 1257 }; | 1314 }; |
| 1258 | 1315 |
| 1259 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("CallNew.golden")); | 1316 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1317 LoadGolden("CallNew.golden"))); |
| 1260 } | 1318 } |
| 1261 | 1319 |
| 1262 TEST(ContextVariables) { | 1320 TEST(ContextVariables) { |
| 1263 // The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this | 1321 // The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this |
| 1264 // ever changes, the REPEAT_XXX should be changed to output the correct number | 1322 // ever changes, the REPEAT_XXX should be changed to output the correct number |
| 1265 // of unique variables to trigger the wide slot load / store. | 1323 // of unique variables to trigger the wide slot load / store. |
| 1266 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256); | 1324 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256); |
| 1267 | 1325 |
| 1268 InitializedIgnitionHandleScope scope; | 1326 InitializedIgnitionHandleScope scope; |
| 1269 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1327 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1270 ConstantPoolType::kMixed); | 1328 ConstantPoolType::kMixed); |
| 1271 const char* snippets[] = { | 1329 const char* snippets[] = { |
| 1272 "var a; return function() { a = 1; };", | 1330 "var a; return function() { a = 1; };\n", |
| 1273 | 1331 |
| 1274 "var a = 1; return function() { a = 2; };", | 1332 "var a = 1; return function() { a = 2; };\n", |
| 1275 | 1333 |
| 1276 "var a = 1; var b = 2; return function() { a = 2; b = 3 };", | 1334 "var a = 1; var b = 2; return function() { a = 2; b = 3 };\n", |
| 1277 | 1335 |
| 1278 "var a; (function() { a = 2; })(); return a;", | 1336 "var a; (function() { a = 2; })(); return a;\n", |
| 1279 | 1337 |
| 1280 "'use strict';\n" | 1338 "'use strict';\n" |
| 1281 "let a = 1;\n" | 1339 "let a = 1;\n" |
| 1282 "{ let b = 2; return function() { a + b; }; }", | 1340 "{ let b = 2; return function() { a + b; }; }\n", |
| 1283 | 1341 |
| 1284 "'use strict';\n" | 1342 "'use strict';\n" |
| 1285 REPEAT_249_UNIQUE_VARS() | 1343 REPEAT_249_UNIQUE_VARS() |
| 1286 "eval();\n" | 1344 "eval();\n" |
| 1287 "var b = 100;\n" | 1345 "var b = 100;\n" |
| 1288 "return b", | 1346 "return b\n", |
| 1289 }; | 1347 }; |
| 1290 | 1348 |
| 1291 CHECK_EQ(BuildActual(printer, snippets), | 1349 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1292 LoadGolden("ContextVariables.golden")); | 1350 LoadGolden("ContextVariables.golden"))); |
| 1293 } | 1351 } |
| 1294 | 1352 |
| 1295 TEST(ContextParameters) { | 1353 TEST(ContextParameters) { |
| 1296 InitializedIgnitionHandleScope scope; | 1354 InitializedIgnitionHandleScope scope; |
| 1297 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1355 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1298 ConstantPoolType::kMixed); | 1356 ConstantPoolType::kMixed); |
| 1299 printer.set_wrap(false); | 1357 printer.set_wrap(false); |
| 1300 printer.set_test_function_name("f"); | 1358 printer.set_test_function_name("f"); |
| 1301 | 1359 |
| 1302 const char* snippets[] = { | 1360 const char* snippets[] = { |
| 1303 "function f(arg1) { return function() { arg1 = 2; }; }", | 1361 "function f(arg1) { return function() { arg1 = 2; }; }", |
| 1304 | 1362 |
| 1305 "function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }", | 1363 "function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }", |
| 1306 | 1364 |
| 1307 "function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }", | 1365 "function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }", |
| 1308 | 1366 |
| 1309 "function f() { var self = this; return function() { self = 2; }; }", | 1367 "function f() { var self = this; return function() { self = 2; }; }", |
| 1310 }; | 1368 }; |
| 1311 | 1369 |
| 1312 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1370 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 1313 LoadGolden("ContextParameters.golden")); | 1371 LoadGolden("ContextParameters.golden"))); |
| 1314 } | 1372 } |
| 1315 | 1373 |
| 1316 TEST(OuterContextVariables) { | 1374 TEST(OuterContextVariables) { |
| 1317 InitializedIgnitionHandleScope scope; | 1375 InitializedIgnitionHandleScope scope; |
| 1318 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1376 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1319 ConstantPoolType::kMixed); | 1377 ConstantPoolType::kMixed); |
| 1320 printer.set_wrap(false); | 1378 printer.set_wrap(false); |
| 1321 printer.set_test_function_name("f"); | 1379 printer.set_test_function_name("f"); |
| 1322 | 1380 |
| 1323 const char* snippets[] = { | 1381 const char* snippets[] = { |
| 1324 "function Outer() {\n" | 1382 "function Outer() {\n" |
| 1325 " var outerVar = 1;\n" | 1383 " var outerVar = 1;\n" |
| 1326 " function Inner(innerArg) {\n" | 1384 " function Inner(innerArg) {\n" |
| 1327 " this.innerFunc = function() { return outerVar * innerArg; }\n" | 1385 " this.innerFunc = function() { return outerVar * innerArg; }\n" |
| 1328 " }\n" | 1386 " }\n" |
| 1329 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n" | 1387 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n" |
| 1330 "}\n" | 1388 "}\n" |
| 1331 "var f = new Outer().getInnerFunc();", | 1389 "var f = new Outer().getInnerFunc();", |
| 1332 | 1390 |
| 1333 "function Outer() {\n" | 1391 "function Outer() {\n" |
| 1334 " var outerVar = 1;\n" | 1392 " var outerVar = 1;\n" |
| 1335 " function Inner(innerArg) {\n" | 1393 " function Inner(innerArg) {\n" |
| 1336 " this.innerFunc = function() { outerVar = innerArg; }\n" | 1394 " this.innerFunc = function() { outerVar = innerArg; }\n" |
| 1337 " }\n" | 1395 " }\n" |
| 1338 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n" | 1396 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }\n" |
| 1339 "}\n" | 1397 "}\n" |
| 1340 "var f = new Outer().getInnerFunc();", | 1398 "var f = new Outer().getInnerFunc();", |
| 1341 }; | 1399 }; |
| 1342 | 1400 |
| 1343 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1401 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 1344 LoadGolden("OuterContextVariables.golden")); | 1402 LoadGolden("OuterContextVariables.golden"))); |
| 1345 } | 1403 } |
| 1346 | 1404 |
| 1347 TEST(CountOperators) { | 1405 TEST(CountOperators) { |
| 1348 InitializedIgnitionHandleScope scope; | 1406 InitializedIgnitionHandleScope scope; |
| 1349 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1407 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1350 ConstantPoolType::kMixed); | 1408 ConstantPoolType::kMixed); |
| 1351 const char* snippets[] = { | 1409 const char* snippets[] = { |
| 1352 "var a = 1; return ++a;", | 1410 "var a = 1; return ++a;\n", |
| 1353 | 1411 |
| 1354 "var a = 1; return a++;", | 1412 "var a = 1; return a++;\n", |
| 1355 | 1413 |
| 1356 "var a = 1; return --a;", | 1414 "var a = 1; return --a;\n", |
| 1357 | 1415 |
| 1358 "var a = 1; return a--;", | 1416 "var a = 1; return a--;\n", |
| 1359 | 1417 |
| 1360 "var a = { val: 1 }; return a.val++;", | 1418 "var a = { val: 1 }; return a.val++;\n", |
| 1361 | 1419 |
| 1362 "var a = { val: 1 }; return --a.val;", | 1420 "var a = { val: 1 }; return --a.val;\n", |
| 1363 | 1421 |
| 1364 "var name = 'var'; var a = { val: 1 }; return a[name]--;", | 1422 "var name = 'var'; var a = { val: 1 }; return a[name]--;\n", |
| 1365 | 1423 |
| 1366 "var name = 'var'; var a = { val: 1 }; return ++a[name];", | 1424 "var name = 'var'; var a = { val: 1 }; return ++a[name];\n", |
| 1367 | 1425 |
| 1368 "var a = 1; var b = function() { return a }; return ++a;", | 1426 "var a = 1; var b = function() { return a }; return ++a;\n", |
| 1369 | 1427 |
| 1370 "var a = 1; var b = function() { return a }; return a--;", | 1428 "var a = 1; var b = function() { return a }; return a--;\n", |
| 1371 | 1429 |
| 1372 "var idx = 1; var a = [1, 2]; return a[idx++] = 2;", | 1430 "var idx = 1; var a = [1, 2]; return a[idx++] = 2;\n", |
| 1373 }; | 1431 }; |
| 1374 | 1432 |
| 1375 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("CountOperators.golden")); | 1433 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1434 LoadGolden("CountOperators.golden"))); |
| 1376 } | 1435 } |
| 1377 | 1436 |
| 1378 TEST(GlobalCountOperators) { | 1437 TEST(GlobalCountOperators) { |
| 1379 InitializedIgnitionHandleScope scope; | 1438 InitializedIgnitionHandleScope scope; |
| 1380 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1439 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1381 ConstantPoolType::kString); | 1440 ConstantPoolType::kString); |
| 1382 printer.set_wrap(false); | 1441 printer.set_wrap(false); |
| 1383 printer.set_test_function_name("f"); | 1442 printer.set_test_function_name("f"); |
| 1384 | 1443 |
| 1385 const char* snippets[] = { | 1444 const char* snippets[] = { |
| 1386 "var global = 1;\n" | 1445 "var global = 1;\n" |
| 1387 "function f() { return ++global; }\n" | 1446 "function f() { return ++global; }\n" |
| 1388 "f();", | 1447 "f();\n", |
| 1389 | 1448 |
| 1390 "var global = 1;\n" | 1449 "var global = 1;\n" |
| 1391 "function f() { return global--; }\n" | 1450 "function f() { return global--; }\n" |
| 1392 "f();", | 1451 "f();\n", |
| 1393 | 1452 |
| 1394 "unallocated = 1;\n" | 1453 "unallocated = 1;\n" |
| 1395 "function f() { 'use strict'; return --unallocated; }\n" | 1454 "function f() { 'use strict'; return --unallocated; }\n" |
| 1396 "f();", | 1455 "f();\n", |
| 1397 | 1456 |
| 1398 "unallocated = 1;\n" | 1457 "unallocated = 1;\n" |
| 1399 "function f() { return unallocated++; }\n" | 1458 "function f() { return unallocated++; }\n" |
| 1400 "f();", | 1459 "f();\n", |
| 1401 }; | 1460 }; |
| 1402 | 1461 |
| 1403 CHECK_EQ(BuildActual(printer, snippets), | 1462 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1404 LoadGolden("GlobalCountOperators.golden")); | 1463 LoadGolden("GlobalCountOperators.golden"))); |
| 1405 } | 1464 } |
| 1406 | 1465 |
| 1407 TEST(CompoundExpressions) { | 1466 TEST(CompoundExpressions) { |
| 1408 InitializedIgnitionHandleScope scope; | 1467 InitializedIgnitionHandleScope scope; |
| 1409 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1468 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1410 ConstantPoolType::kMixed); | 1469 ConstantPoolType::kMixed); |
| 1411 const char* snippets[] = { | 1470 const char* snippets[] = { |
| 1412 "var a = 1; a += 2;", | 1471 "var a = 1; a += 2;\n", |
| 1413 | 1472 |
| 1414 "var a = 1; a /= 2;", | 1473 "var a = 1; a /= 2;\n", |
| 1415 | 1474 |
| 1416 "var a = { val: 2 }; a.name *= 2;", | 1475 "var a = { val: 2 }; a.name *= 2;\n", |
| 1417 | 1476 |
| 1418 "var a = { 1: 2 }; a[1] ^= 2;", | 1477 "var a = { 1: 2 }; a[1] ^= 2;\n", |
| 1419 | 1478 |
| 1420 "var a = 1; (function f() { return a; }); a |= 24;", | 1479 "var a = 1; (function f() { return a; }); a |= 24;\n", |
| 1421 }; | 1480 }; |
| 1422 | 1481 |
| 1423 CHECK_EQ(BuildActual(printer, snippets), | 1482 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1424 LoadGolden("CompoundExpressions.golden")); | 1483 LoadGolden("CompoundExpressions.golden"))); |
| 1425 } | 1484 } |
| 1426 | 1485 |
| 1427 TEST(GlobalCompoundExpressions) { | 1486 TEST(GlobalCompoundExpressions) { |
| 1428 InitializedIgnitionHandleScope scope; | 1487 InitializedIgnitionHandleScope scope; |
| 1429 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1488 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1430 ConstantPoolType::kString); | 1489 ConstantPoolType::kString); |
| 1431 printer.set_wrap(false); | 1490 printer.set_wrap(false); |
| 1432 printer.set_test_function_name("f"); | 1491 printer.set_test_function_name("f"); |
| 1433 | 1492 |
| 1434 const char* snippets[] = { | 1493 const char* snippets[] = { |
| 1435 "var global = 1;\n" | 1494 "var global = 1;\n" |
| 1436 "function f() { return global &= 1; }\n" | 1495 "function f() { return global &= 1; }\n" |
| 1437 "f();", | 1496 "f();\n", |
| 1438 | 1497 |
| 1439 "unallocated = 1;\n" | 1498 "unallocated = 1;\n" |
| 1440 "function f() { return unallocated += 1; }\n" | 1499 "function f() { return unallocated += 1; }\n" |
| 1441 "f();", | 1500 "f();\n", |
| 1442 }; | 1501 }; |
| 1443 | 1502 |
| 1444 CHECK_EQ(BuildActual(printer, snippets), | 1503 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1445 LoadGolden("GlobalCompoundExpressions.golden")); | 1504 LoadGolden("GlobalCompoundExpressions.golden"))); |
| 1446 } | 1505 } |
| 1447 | 1506 |
| 1448 TEST(CreateArguments) { | 1507 TEST(CreateArguments) { |
| 1449 InitializedIgnitionHandleScope scope; | 1508 InitializedIgnitionHandleScope scope; |
| 1450 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1509 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1451 ConstantPoolType::kString); | 1510 ConstantPoolType::kString); |
| 1452 printer.set_wrap(false); | 1511 printer.set_wrap(false); |
| 1453 printer.set_test_function_name("f"); | 1512 printer.set_test_function_name("f"); |
| 1454 | 1513 |
| 1455 const char* snippets[] = { | 1514 const char* snippets[] = { |
| 1456 "function f() { return arguments; }", | 1515 "function f() { return arguments; }", |
| 1457 | 1516 |
| 1458 "function f() { return arguments[0]; }", | 1517 "function f() { return arguments[0]; }", |
| 1459 | 1518 |
| 1460 "function f() { 'use strict'; return arguments; }", | 1519 "function f() { 'use strict'; return arguments; }", |
| 1461 | 1520 |
| 1462 "function f(a) { return arguments[0]; }", | 1521 "function f(a) { return arguments[0]; }", |
| 1463 | 1522 |
| 1464 "function f(a, b, c) { return arguments; }", | 1523 "function f(a, b, c) { return arguments; }", |
| 1465 | 1524 |
| 1466 "function f(a, b, c) { 'use strict'; return arguments; }", | 1525 "function f(a, b, c) { 'use strict'; return arguments; }", |
| 1467 }; | 1526 }; |
| 1468 | 1527 |
| 1469 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1528 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 1470 LoadGolden("CreateArguments.golden")); | 1529 LoadGolden("CreateArguments.golden"))); |
| 1471 } | 1530 } |
| 1472 | 1531 |
| 1473 TEST(CreateRestParameter) { | 1532 TEST(CreateRestParameter) { |
| 1474 InitializedIgnitionHandleScope scope; | 1533 InitializedIgnitionHandleScope scope; |
| 1475 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1534 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1476 ConstantPoolType::kNumber); | 1535 ConstantPoolType::kNumber); |
| 1477 printer.set_wrap(false); | 1536 printer.set_wrap(false); |
| 1478 printer.set_test_function_name("f"); | 1537 printer.set_test_function_name("f"); |
| 1479 | 1538 |
| 1480 const char* snippets[] = { | 1539 const char* snippets[] = { |
| 1481 "function f(...restArgs) { return restArgs; }", | 1540 "function f(...restArgs) { return restArgs; }", |
| 1482 | 1541 |
| 1483 "function f(a, ...restArgs) { return restArgs; }", | 1542 "function f(a, ...restArgs) { return restArgs; }", |
| 1484 | 1543 |
| 1485 "function f(a, ...restArgs) { return restArgs[0]; }", | 1544 "function f(a, ...restArgs) { return restArgs[0]; }", |
| 1486 | 1545 |
| 1487 "function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }", | 1546 "function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }", |
| 1488 }; | 1547 }; |
| 1489 | 1548 |
| 1490 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1549 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 1491 LoadGolden("CreateRestParameter.golden")); | 1550 LoadGolden("CreateRestParameter.golden"))); |
| 1492 } | 1551 } |
| 1493 | 1552 |
| 1494 TEST(ForIn) { | 1553 TEST(ForIn) { |
| 1495 InitializedIgnitionHandleScope scope; | 1554 InitializedIgnitionHandleScope scope; |
| 1496 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1555 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1497 ConstantPoolType::kMixed); | 1556 ConstantPoolType::kMixed); |
| 1498 const char* snippets[] = { | 1557 const char* snippets[] = { |
| 1499 "for (var p in null) {}", | 1558 "for (var p in null) {}\n", |
| 1500 | 1559 |
| 1501 "for (var p in undefined) {}", | 1560 "for (var p in undefined) {}\n", |
| 1502 | 1561 |
| 1503 "for (var p in undefined) {}", | 1562 "for (var p in undefined) {}\n", |
| 1504 | 1563 |
| 1505 "var x = 'potatoes';\n" | 1564 "var x = 'potatoes';\n" |
| 1506 "for (var p in x) { return p; }", | 1565 "for (var p in x) { return p; }\n", |
| 1507 | 1566 |
| 1508 "var x = 0;\n" | 1567 "var x = 0;\n" |
| 1509 "for (var p in [1,2,3]) { x += p; }", | 1568 "for (var p in [1,2,3]) { x += p; }\n", |
| 1510 | 1569 |
| 1511 "var x = { 'a': 1, 'b': 2 };\n" | 1570 "var x = { 'a': 1, 'b': 2 };\n" |
| 1512 "for (x['a'] in [10, 20, 30]) {\n" | 1571 "for (x['a'] in [10, 20, 30]) {\n" |
| 1513 " if (x['a'] == 10) continue;\n" | 1572 " if (x['a'] == 10) continue;\n" |
| 1514 " if (x['a'] == 20) break;\n" | 1573 " if (x['a'] == 20) break;\n" |
| 1515 "}", | 1574 "}\n", |
| 1516 | 1575 |
| 1517 "var x = [ 10, 11, 12 ] ;\n" | 1576 "var x = [ 10, 11, 12 ] ;\n" |
| 1518 "for (x[0] in [1,2,3]) { return x[3]; }", | 1577 "for (x[0] in [1,2,3]) { return x[3]; }\n", |
| 1519 }; | 1578 }; |
| 1520 | 1579 |
| 1521 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("ForIn.golden")); | 1580 CHECK( |
| 1581 CompareTexts(BuildActual(printer, snippets), LoadGolden("ForIn.golden"))); |
| 1522 } | 1582 } |
| 1523 | 1583 |
| 1524 TEST(ForOf) { | 1584 TEST(ForOf) { |
| 1525 InitializedIgnitionHandleScope scope; | 1585 InitializedIgnitionHandleScope scope; |
| 1526 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1586 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1527 ConstantPoolType::kMixed); | 1587 ConstantPoolType::kMixed); |
| 1528 const char* snippets[] = { | 1588 const char* snippets[] = { |
| 1529 "for (var p of [0, 1, 2]) {}", | 1589 "for (var p of [0, 1, 2]) {}\n", |
| 1530 | 1590 |
| 1531 "var x = 'potatoes';\n" | 1591 "var x = 'potatoes';\n" |
| 1532 "for (var p of x) { return p; }", | 1592 "for (var p of x) { return p; }\n", |
| 1533 | 1593 |
| 1534 "for (var x of [10, 20, 30]) {\n" | 1594 "for (var x of [10, 20, 30]) {\n" |
| 1535 " if (x == 10) continue;\n" | 1595 " if (x == 10) continue;\n" |
| 1536 " if (x == 20) break;\n" | 1596 " if (x == 20) break;\n" |
| 1537 "}", | 1597 "}\n", |
| 1538 | 1598 |
| 1539 "var x = { 'a': 1, 'b': 2 };\n" | 1599 "var x = { 'a': 1, 'b': 2 };\n" |
| 1540 "for (x['a'] of [1,2,3]) { return x['a']; }", | 1600 "for (x['a'] of [1,2,3]) { return x['a']; }\n", |
| 1541 }; | 1601 }; |
| 1542 | 1602 |
| 1543 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("ForOf.golden")); | 1603 CHECK( |
| 1604 CompareTexts(BuildActual(printer, snippets), LoadGolden("ForOf.golden"))); |
| 1544 } | 1605 } |
| 1545 | 1606 |
| 1546 TEST(Conditional) { | 1607 TEST(Conditional) { |
| 1547 InitializedIgnitionHandleScope scope; | 1608 InitializedIgnitionHandleScope scope; |
| 1548 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1609 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1549 ConstantPoolType::kNumber); | 1610 ConstantPoolType::kNumber); |
| 1550 const char* snippets[] = { | 1611 const char* snippets[] = { |
| 1551 "return 1 ? 2 : 3;", | 1612 "return 1 ? 2 : 3;\n", |
| 1552 | 1613 |
| 1553 "return 1 ? 2 ? 3 : 4 : 5;", | 1614 "return 1 ? 2 ? 3 : 4 : 5;\n", |
| 1554 }; | 1615 }; |
| 1555 | 1616 |
| 1556 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Conditional.golden")); | 1617 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1618 LoadGolden("Conditional.golden"))); |
| 1557 } | 1619 } |
| 1558 | 1620 |
| 1559 TEST(Switch) { | 1621 TEST(Switch) { |
| 1560 InitializedIgnitionHandleScope scope; | 1622 InitializedIgnitionHandleScope scope; |
| 1561 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1623 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1562 ConstantPoolType::kNumber); | 1624 ConstantPoolType::kNumber); |
| 1563 const char* snippets[] = { | 1625 const char* snippets[] = { |
| 1564 "var a = 1;\n" | 1626 "var a = 1;\n" |
| 1565 "switch(a) {\n" | 1627 "switch(a) {\n" |
| 1566 " case 1: return 2;\n" | 1628 " case 1: return 2;\n" |
| 1567 " case 2: return 3;\n" | 1629 " case 2: return 3;\n" |
| 1568 "}", | 1630 "}\n", |
| 1569 | 1631 |
| 1570 "var a = 1;\n" | 1632 "var a = 1;\n" |
| 1571 "switch(a) {\n" | 1633 "switch(a) {\n" |
| 1572 " case 1: a = 2; break;\n" | 1634 " case 1: a = 2; break;\n" |
| 1573 " case 2: a = 3; break;\n" | 1635 " case 2: a = 3; break;\n" |
| 1574 "}", | 1636 "}\n", |
| 1575 | 1637 |
| 1576 "var a = 1;\n" | 1638 "var a = 1;\n" |
| 1577 "switch(a) {\n" | 1639 "switch(a) {\n" |
| 1578 " case 1: a = 2; // fall-through\n" | 1640 " case 1: a = 2; // fall-through\n" |
| 1579 " case 2: a = 3; break;\n" | 1641 " case 2: a = 3; break;\n" |
| 1580 "}", | 1642 "}\n", |
| 1581 | 1643 |
| 1582 "var a = 1;\n" | 1644 "var a = 1;\n" |
| 1583 "switch(a) {\n" | 1645 "switch(a) {\n" |
| 1584 " case 2: break;\n" | 1646 " case 2: break;\n" |
| 1585 " case 3: break;\n" | 1647 " case 3: break;\n" |
| 1586 " default: a = 1; break;\n" | 1648 " default: a = 1; break;\n" |
| 1587 "}", | 1649 "}\n", |
| 1588 | 1650 |
| 1589 "var a = 1;\n" | 1651 "var a = 1;\n" |
| 1590 "switch(typeof(a)) {\n" | 1652 "switch(typeof(a)) {\n" |
| 1591 " case 2: a = 1; break;\n" | 1653 " case 2: a = 1; break;\n" |
| 1592 " case 3: a = 2; break;\n" | 1654 " case 3: a = 2; break;\n" |
| 1593 " default: a = 3; break;\n" | 1655 " default: a = 3; break;\n" |
| 1594 "}", | 1656 "}\n", |
| 1595 | 1657 |
| 1596 "var a = 1;\n" | 1658 "var a = 1;\n" |
| 1597 "switch(a) {\n" | 1659 "switch(a) {\n" |
| 1598 " case typeof(a): a = 1; break;\n" | 1660 " case typeof(a): a = 1; break;\n" |
| 1599 " default: a = 2; break;\n" | 1661 " default: a = 2; break;\n" |
| 1600 "}", | 1662 "}\n", |
| 1601 | 1663 |
| 1602 "var a = 1;\n" | 1664 "var a = 1;\n" |
| 1603 "switch(a) {\n" | 1665 "switch(a) {\n" |
| 1604 " case 1:\n" | 1666 " case 1:\n" |
| 1605 REPEAT_64(" a = 2;\n") | 1667 REPEAT_64(" a = 2;\n") |
| 1606 " break;\n" | 1668 " break;\n" |
| 1607 " case 2:\n" | 1669 " case 2:\n" |
| 1608 " a = 3;\n" | 1670 " a = 3;\n" |
| 1609 " break;\n" | 1671 " break;\n" |
| 1610 "}", | 1672 "}\n", |
| 1611 | 1673 |
| 1612 "var a = 1;\n" | 1674 "var a = 1;\n" |
| 1613 "switch(a) {\n" | 1675 "switch(a) {\n" |
| 1614 " case 1: \n" | 1676 " case 1: \n" |
| 1615 " switch(a + 1) {\n" | 1677 " switch(a + 1) {\n" |
| 1616 " case 2 : a = 1; break;\n" | 1678 " case 2 : a = 1; break;\n" |
| 1617 " default : a = 2; break;\n" | 1679 " default : a = 2; break;\n" |
| 1618 " } // fall-through\n" | 1680 " } // fall-through\n" |
| 1619 " case 2: a = 3;\n" | 1681 " case 2: a = 3;\n" |
| 1620 "}", | 1682 "}\n", |
| 1621 }; | 1683 }; |
| 1622 | 1684 |
| 1623 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Switch.golden")); | 1685 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1686 LoadGolden("Switch.golden"))); |
| 1624 } | 1687 } |
| 1625 | 1688 |
| 1626 TEST(BasicBlockToBoolean) { | 1689 TEST(BasicBlockToBoolean) { |
| 1627 InitializedIgnitionHandleScope scope; | 1690 InitializedIgnitionHandleScope scope; |
| 1628 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1691 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1629 ConstantPoolType::kNumber); | 1692 ConstantPoolType::kNumber); |
| 1630 const char* snippets[] = { | 1693 const char* snippets[] = { |
| 1631 "var a = 1; if (a || a < 0) { return 1; }", | 1694 "var a = 1; if (a || a < 0) { return 1; }\n", |
| 1632 | 1695 |
| 1633 "var a = 1; if (a && a < 0) { return 1; }", | 1696 "var a = 1; if (a && a < 0) { return 1; }\n", |
| 1634 | 1697 |
| 1635 "var a = 1; a = (a || a < 0) ? 2 : 3;", | 1698 "var a = 1; a = (a || a < 0) ? 2 : 3;\n", |
| 1636 }; | 1699 }; |
| 1637 | 1700 |
| 1638 CHECK_EQ(BuildActual(printer, snippets), | 1701 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1639 LoadGolden("BasicBlockToBoolean.golden")); | 1702 LoadGolden("BasicBlockToBoolean.golden"))); |
| 1640 } | 1703 } |
| 1641 | 1704 |
| 1642 TEST(DeadCodeRemoval) { | 1705 TEST(DeadCodeRemoval) { |
| 1643 InitializedIgnitionHandleScope scope; | 1706 InitializedIgnitionHandleScope scope; |
| 1644 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1707 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1645 ConstantPoolType::kNumber); | 1708 ConstantPoolType::kNumber); |
| 1646 const char* snippets[] = { | 1709 const char* snippets[] = { |
| 1647 "return; var a = 1; a();", | 1710 "return; var a = 1; a();\n", |
| 1648 | 1711 |
| 1649 "if (false) { return; }; var a = 1;", | 1712 "if (false) { return; }; var a = 1;\n", |
| 1650 | 1713 |
| 1651 "if (true) { return 1; } else { return 2; };", | 1714 "if (true) { return 1; } else { return 2; };\n", |
| 1652 | 1715 |
| 1653 "var a = 1; if (a) { return 1; }; return 2;", | 1716 "var a = 1; if (a) { return 1; }; return 2;\n", |
| 1654 }; | 1717 }; |
| 1655 | 1718 |
| 1656 CHECK_EQ(BuildActual(printer, snippets), | 1719 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1657 LoadGolden("DeadCodeRemoval.golden")); | 1720 LoadGolden("DeadCodeRemoval.golden"))); |
| 1658 } | 1721 } |
| 1659 | 1722 |
| 1660 TEST(ThisFunction) { | 1723 TEST(ThisFunction) { |
| 1661 InitializedIgnitionHandleScope scope; | 1724 InitializedIgnitionHandleScope scope; |
| 1662 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1725 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1663 ConstantPoolType::kNumber); | 1726 ConstantPoolType::kNumber); |
| 1664 printer.set_wrap(false); | 1727 printer.set_wrap(false); |
| 1665 printer.set_test_function_name("f"); | 1728 printer.set_test_function_name("f"); |
| 1666 | 1729 |
| 1667 const char* snippets[] = { | 1730 const char* snippets[] = { |
| 1668 "var f;\n" | 1731 "var f;\n" |
| 1669 "f = function f() {};", | 1732 "f = function f() {};", |
| 1670 | 1733 |
| 1671 "var f;\n" | 1734 "var f;\n" |
| 1672 "f = function f() { return f; };", | 1735 "f = function f() { return f; };", |
| 1673 }; | 1736 }; |
| 1674 | 1737 |
| 1675 CHECK_EQ(BuildActual(printer, snippets, "", "\nf();"), | 1738 CHECK(CompareTexts(BuildActual(printer, snippets, "", "\nf();"), |
| 1676 LoadGolden("ThisFunction.golden")); | 1739 LoadGolden("ThisFunction.golden"))); |
| 1677 } | 1740 } |
| 1678 | 1741 |
| 1679 TEST(NewTarget) { | 1742 TEST(NewTarget) { |
| 1680 InitializedIgnitionHandleScope scope; | 1743 InitializedIgnitionHandleScope scope; |
| 1681 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1744 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1682 ConstantPoolType::kMixed); | 1745 ConstantPoolType::kMixed); |
| 1683 | 1746 |
| 1684 const char* snippets[] = { | 1747 const char* snippets[] = { |
| 1685 "return new.target;", | 1748 "return new.target;\n", |
| 1686 | 1749 |
| 1687 "new.target;", | 1750 "new.target;\n", |
| 1688 }; | 1751 }; |
| 1689 | 1752 |
| 1690 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("NewTarget.golden")); | 1753 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1754 LoadGolden("NewTarget.golden"))); |
| 1691 } | 1755 } |
| 1692 | 1756 |
| 1693 TEST(RemoveRedundantLdar) { | 1757 TEST(RemoveRedundantLdar) { |
| 1694 InitializedIgnitionHandleScope scope; | 1758 InitializedIgnitionHandleScope scope; |
| 1695 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1759 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1696 ConstantPoolType::kNumber); | 1760 ConstantPoolType::kNumber); |
| 1697 const char* snippets[] = { | 1761 const char* snippets[] = { |
| 1698 "var ld_a = 1;\n" // This test is to check Ldar does not | 1762 "var ld_a = 1;\n" // This test is to check Ldar does not |
| 1699 "while(true) {\n" // get removed if the preceding Star is | 1763 "while(true) {\n" // get removed if the preceding Star is |
| 1700 " ld_a = ld_a + ld_a;\n" // in a different basicblock. | 1764 " ld_a = ld_a + ld_a;\n" // in a different basicblock. |
| 1701 " if (ld_a > 10) break;\n" | 1765 " if (ld_a > 10) break;\n" |
| 1702 "}\n" | 1766 "}\n" |
| 1703 "return ld_a;", | 1767 "return ld_a;\n", |
| 1704 | 1768 |
| 1705 "var ld_a = 1;\n" | 1769 "var ld_a = 1;\n" |
| 1706 "do {\n" | 1770 "do {\n" |
| 1707 " ld_a = ld_a + ld_a;\n" | 1771 " ld_a = ld_a + ld_a;\n" |
| 1708 " if (ld_a > 10) continue;\n" | 1772 " if (ld_a > 10) continue;\n" |
| 1709 "} while(false);\n" | 1773 "} while(false);\n" |
| 1710 "return ld_a;", | 1774 "return ld_a;\n", |
| 1711 | 1775 |
| 1712 "var ld_a = 1;\n" | 1776 "var ld_a = 1;\n" |
| 1713 " ld_a = ld_a + ld_a;\n" | 1777 " ld_a = ld_a + ld_a;\n" |
| 1714 " return ld_a;", | 1778 " return ld_a;\n", |
| 1715 }; | 1779 }; |
| 1716 | 1780 |
| 1717 CHECK_EQ(BuildActual(printer, snippets), | 1781 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1718 LoadGolden("RemoveRedundantLdar.golden")); | 1782 LoadGolden("RemoveRedundantLdar.golden"))); |
| 1719 } | 1783 } |
| 1720 | 1784 |
| 1721 TEST(AssignmentsInBinaryExpression) { | 1785 TEST(AssignmentsInBinaryExpression) { |
| 1722 InitializedIgnitionHandleScope scope; | 1786 InitializedIgnitionHandleScope scope; |
| 1723 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1787 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1724 ConstantPoolType::kString); | 1788 ConstantPoolType::kString); |
| 1725 const char* snippets[] = { | 1789 const char* snippets[] = { |
| 1726 "var x = 0, y = 1;\n" | 1790 "var x = 0, y = 1;\n" |
| 1727 "return (x = 2, y = 3, x = 4, y = 5);", | 1791 "return (x = 2, y = 3, x = 4, y = 5);\n", |
| 1728 | 1792 |
| 1729 "var x = 55;\n" | 1793 "var x = 55;\n" |
| 1730 "var y = (x = 100);\n" | 1794 "var y = (x = 100);\n" |
| 1731 "return y;", | 1795 "return y;\n", |
| 1732 | 1796 |
| 1733 "var x = 55;\n" | 1797 "var x = 55;\n" |
| 1734 "x = x + (x = 100) + (x = 101);\n" | 1798 "x = x + (x = 100) + (x = 101);\n" |
| 1735 "return x;", | 1799 "return x;\n", |
| 1736 | 1800 |
| 1737 "var x = 55;\n" | 1801 "var x = 55;\n" |
| 1738 "x = (x = 56) - x + (x = 57);\n" | 1802 "x = (x = 56) - x + (x = 57);\n" |
| 1739 "x++;\n" | 1803 "x++;\n" |
| 1740 "return x;", | 1804 "return x;\n", |
| 1741 | 1805 |
| 1742 "var x = 55;\n" | 1806 "var x = 55;\n" |
| 1743 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" | 1807 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" |
| 1744 "return y;", | 1808 "return y;\n", |
| 1745 | 1809 |
| 1746 "var x = 55;\n" | 1810 "var x = 55;\n" |
| 1747 "var x = x + (x = 1) + (x = 2) + (x = 3);\n" | 1811 "var x = x + (x = 1) + (x = 2) + (x = 3);\n" |
| 1748 "return x;", | 1812 "return x;\n", |
| 1749 | 1813 |
| 1750 "var x = 10, y = 20;\n" | 1814 "var x = 10, y = 20;\n" |
| 1751 "return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + " | 1815 "return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + " |
| 1752 "y;\n", | 1816 "y;\n", |
| 1753 | 1817 |
| 1754 "var x = 17;\n" | 1818 "var x = 17;\n" |
| 1755 "return 1 + x + (x++) + (++x);\n", | 1819 "return 1 + x + (x++) + (++x);\n", |
| 1756 }; | 1820 }; |
| 1757 | 1821 |
| 1758 CHECK_EQ(BuildActual(printer, snippets), | 1822 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1759 LoadGolden("AssignmentsInBinaryExpression.golden")); | 1823 LoadGolden("AssignmentsInBinaryExpression.golden"))); |
| 1760 } | 1824 } |
| 1761 | 1825 |
| 1762 TEST(Eval) { | 1826 TEST(Eval) { |
| 1763 InitializedIgnitionHandleScope scope; | 1827 InitializedIgnitionHandleScope scope; |
| 1764 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1828 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1765 ConstantPoolType::kString); | 1829 ConstantPoolType::kString); |
| 1766 const char* snippets[] = { | 1830 const char* snippets[] = { |
| 1767 "return eval('1;');", | 1831 "return eval('1;');\n", |
| 1768 }; | 1832 }; |
| 1769 | 1833 |
| 1770 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Eval.golden")); | 1834 CHECK( |
| 1835 CompareTexts(BuildActual(printer, snippets), LoadGolden("Eval.golden"))); |
| 1771 } | 1836 } |
| 1772 | 1837 |
| 1773 TEST(LookupSlot) { | 1838 TEST(LookupSlot) { |
| 1774 InitializedIgnitionHandleScope scope; | 1839 InitializedIgnitionHandleScope scope; |
| 1775 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1840 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1776 ConstantPoolType::kString); | 1841 ConstantPoolType::kString); |
| 1777 | 1842 |
| 1778 const char* snippets[] = { | 1843 const char* snippets[] = { |
| 1779 "eval('var x = 10;'); return x;", | 1844 "eval('var x = 10;'); return x;\n", |
| 1780 | 1845 |
| 1781 "eval('var x = 10;'); return typeof x;", | 1846 "eval('var x = 10;'); return typeof x;\n", |
| 1782 | 1847 |
| 1783 "x = 20; return eval('');", | 1848 "x = 20; return eval('');\n", |
| 1784 }; | 1849 }; |
| 1785 | 1850 |
| 1786 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("LookupSlot.golden")); | 1851 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1852 LoadGolden("LookupSlot.golden"))); |
| 1787 } | 1853 } |
| 1788 | 1854 |
| 1789 TEST(CallLookupSlot) { | 1855 TEST(CallLookupSlot) { |
| 1790 InitializedIgnitionHandleScope scope; | 1856 InitializedIgnitionHandleScope scope; |
| 1791 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1857 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1792 ConstantPoolType::kMixed); | 1858 ConstantPoolType::kMixed); |
| 1793 const char* snippets[] = { | 1859 const char* snippets[] = { |
| 1794 "g = function(){}; eval(''); return g();", | 1860 "g = function(){}; eval(''); return g();\n", |
| 1795 }; | 1861 }; |
| 1796 | 1862 |
| 1797 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("CallLookupSlot.golden")); | 1863 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1864 LoadGolden("CallLookupSlot.golden"))); |
| 1798 } | 1865 } |
| 1799 | 1866 |
| 1800 // TODO(mythria): tests for variable/function declaration in lookup slots. | 1867 // TODO(mythria): tests for variable/function declaration in lookup slots. |
| 1801 | 1868 |
| 1802 TEST(LookupSlotInEval) { | 1869 TEST(LookupSlotInEval) { |
| 1803 InitializedIgnitionHandleScope scope; | 1870 InitializedIgnitionHandleScope scope; |
| 1804 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1871 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1805 ConstantPoolType::kString); | 1872 ConstantPoolType::kString); |
| 1806 printer.set_wrap(false); | 1873 printer.set_wrap(false); |
| 1807 printer.set_test_function_name("f"); | 1874 printer.set_test_function_name("f"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1819 std::string actual = BuildActual(printer, snippets, | 1886 std::string actual = BuildActual(printer, snippets, |
| 1820 "var f;\n" | 1887 "var f;\n" |
| 1821 "var x = 1;\n" | 1888 "var x = 1;\n" |
| 1822 "function f1() {\n" | 1889 "function f1() {\n" |
| 1823 " eval(\"function t() { ", | 1890 " eval(\"function t() { ", |
| 1824 | 1891 |
| 1825 " }; f = t; f();\");\n" | 1892 " }; f = t; f();\");\n" |
| 1826 "}\n" | 1893 "}\n" |
| 1827 "f1();"); | 1894 "f1();"); |
| 1828 | 1895 |
| 1829 CHECK_EQ(actual, LoadGolden("LookupSlotInEval.golden")); | 1896 CHECK(CompareTexts(actual, LoadGolden("LookupSlotInEval.golden"))); |
| 1830 } | 1897 } |
| 1831 | 1898 |
| 1832 TEST(LookupSlotWideInEval) { | 1899 TEST(LookupSlotWideInEval) { |
| 1833 InitializedIgnitionHandleScope scope; | 1900 InitializedIgnitionHandleScope scope; |
| 1834 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1901 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1835 ConstantPoolType::kMixed); | 1902 ConstantPoolType::kMixed); |
| 1836 printer.set_wrap(false); | 1903 printer.set_wrap(false); |
| 1837 printer.set_test_function_name("f"); | 1904 printer.set_test_function_name("f"); |
| 1838 | 1905 |
| 1839 const char* snippets[] = { | 1906 const char* snippets[] = { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1855 "var f;\n" | 1922 "var f;\n" |
| 1856 "var x = 1;\n" | 1923 "var x = 1;\n" |
| 1857 "function f1() {\n" | 1924 "function f1() {\n" |
| 1858 " eval(\"function t() {\" +\n", | 1925 " eval(\"function t() {\" +\n", |
| 1859 | 1926 |
| 1860 " \"};\" +\n" | 1927 " \"};\" +\n" |
| 1861 " \"f = t; f();\"\n);\n" | 1928 " \"f = t; f();\"\n);\n" |
| 1862 "}\n" | 1929 "}\n" |
| 1863 "f1();"); | 1930 "f1();"); |
| 1864 | 1931 |
| 1865 CHECK_EQ(actual, LoadGolden("LookupSlotWideInEval.golden")); | 1932 CHECK(CompareTexts(actual, LoadGolden("LookupSlotWideInEval.golden"))); |
| 1866 } | 1933 } |
| 1867 | 1934 |
| 1868 TEST(DeleteLookupSlotInEval) { | 1935 TEST(DeleteLookupSlotInEval) { |
| 1869 InitializedIgnitionHandleScope scope; | 1936 InitializedIgnitionHandleScope scope; |
| 1870 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1937 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1871 ConstantPoolType::kString); | 1938 ConstantPoolType::kString); |
| 1872 printer.set_wrap(false); | 1939 printer.set_wrap(false); |
| 1873 printer.set_test_function_name("f"); | 1940 printer.set_test_function_name("f"); |
| 1874 | 1941 |
| 1875 const char* snippets[] = { | 1942 const char* snippets[] = { |
| 1876 "delete x;", | 1943 "delete x;", |
| 1877 | 1944 |
| 1878 "return delete y;", | 1945 "return delete y;", |
| 1879 | 1946 |
| 1880 "return delete z;", | 1947 "return delete z;", |
| 1881 }; | 1948 }; |
| 1882 | 1949 |
| 1883 std::string actual = BuildActual(printer, snippets, | 1950 std::string actual = BuildActual(printer, snippets, |
| 1884 "var f;\n" | 1951 "var f;\n" |
| 1885 "var x = 1;\n" | 1952 "var x = 1;\n" |
| 1886 "z = 10;\n" | 1953 "z = 10;\n" |
| 1887 "function f1() {\n" | 1954 "function f1() {\n" |
| 1888 " var y;\n" | 1955 " var y;\n" |
| 1889 " eval(\"function t() { ", | 1956 " eval(\"function t() { ", |
| 1890 | 1957 |
| 1891 " }; f = t; f();\");\n" | 1958 " }; f = t; f();\");\n" |
| 1892 "}\n" | 1959 "}\n" |
| 1893 "f1();"); | 1960 "f1();"); |
| 1894 | 1961 |
| 1895 CHECK_EQ(actual, LoadGolden("DeleteLookupSlotInEval.golden")); | 1962 CHECK(CompareTexts(actual, LoadGolden("DeleteLookupSlotInEval.golden"))); |
| 1896 } | 1963 } |
| 1897 | 1964 |
| 1898 TEST(WideRegisters) { | 1965 TEST(WideRegisters) { |
| 1899 // Prepare prologue that creates frame for lots of registers. | 1966 // Prepare prologue that creates frame for lots of registers. |
| 1900 std::ostringstream os; | 1967 std::ostringstream os; |
| 1901 for (size_t i = 0; i < 157; ++i) { | 1968 for (size_t i = 0; i < 157; ++i) { |
| 1902 os << "var x" << i << ";\n"; | 1969 os << "var x" << i << ";\n"; |
| 1903 } | 1970 } |
| 1904 std::string prologue(os.str()); | 1971 std::string prologue(os.str()); |
| 1905 | 1972 |
| 1906 InitializedIgnitionHandleScope scope; | 1973 InitializedIgnitionHandleScope scope; |
| 1907 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 1974 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1908 ConstantPoolType::kNumber); | 1975 ConstantPoolType::kNumber); |
| 1909 const char* snippets[] = { | 1976 const char* snippets[] = { |
| 1910 "x0 = x127;\n" | 1977 "x0 = x127;\n" |
| 1911 "return x0;", | 1978 "return x0;\n", |
| 1912 | 1979 |
| 1913 "x127 = x126;\n" | 1980 "x127 = x126;\n" |
| 1914 "return x127;", | 1981 "return x127;\n", |
| 1915 | 1982 |
| 1916 "if (x2 > 3) { return x129; }\n" | 1983 "if (x2 > 3) { return x129; }\n" |
| 1917 "return x128;", | 1984 "return x128;\n", |
| 1918 | 1985 |
| 1919 "var x0 = 0;\n" | 1986 "var x0 = 0;\n" |
| 1920 "if (x129 == 3) { var x129 = x0; }\n" | 1987 "if (x129 == 3) { var x129 = x0; }\n" |
| 1921 "if (x2 > 3) { return x0; }\n" | 1988 "if (x2 > 3) { return x0; }\n" |
| 1922 "return x129;", | 1989 "return x129;\n", |
| 1923 | 1990 |
| 1924 "var x0 = 0;\n" | 1991 "var x0 = 0;\n" |
| 1925 "var x1 = 0;\n" | 1992 "var x1 = 0;\n" |
| 1926 "for (x128 = 0; x128 < 64; x128++) {" | 1993 "for (x128 = 0; x128 < 64; x128++) {" |
| 1927 " x1 += x128;" | 1994 " x1 += x128;" |
| 1928 "}" | 1995 "}" |
| 1929 "return x128;", | 1996 "return x128;\n", |
| 1930 | 1997 |
| 1931 "var x0 = 1234;\n" | 1998 "var x0 = 1234;\n" |
| 1932 "var x1 = 0;\n" | 1999 "var x1 = 0;\n" |
| 1933 "for (x128 in x0) {" | 2000 "for (x128 in x0) {" |
| 1934 " x1 += x128;" | 2001 " x1 += x128;" |
| 1935 "}" | 2002 "}" |
| 1936 "return x1;", | 2003 "return x1;\n", |
| 1937 | 2004 |
| 1938 "x0 = %Add(x64, x63);\n" | 2005 "x0 = %Add(x64, x63);\n" |
| 1939 "x1 = %Add(x27, x143);\n" | 2006 "x1 = %Add(x27, x143);\n" |
| 1940 "%TheHole();\n" | 2007 "%TheHole();\n" |
| 1941 "return x1;", | 2008 "return x1;\n", |
| 1942 }; | 2009 }; |
| 1943 | 2010 |
| 1944 CHECK_EQ(BuildActual(printer, snippets, prologue.c_str()), | 2011 CHECK(CompareTexts(BuildActual(printer, snippets, prologue.c_str()), |
| 1945 LoadGolden("WideRegisters.golden")); | 2012 LoadGolden("WideRegisters.golden"))); |
| 1946 } | 2013 } |
| 1947 | 2014 |
| 1948 TEST(ConstVariable) { | 2015 TEST(ConstVariable) { |
| 1949 InitializedIgnitionHandleScope scope; | 2016 InitializedIgnitionHandleScope scope; |
| 1950 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2017 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1951 ConstantPoolType::kString); | 2018 ConstantPoolType::kString); |
| 1952 const char* snippets[] = { | 2019 const char* snippets[] = { |
| 1953 "const x = 10;", | 2020 "const x = 10;\n", |
| 1954 | 2021 |
| 1955 "const x = 10; return x;", | 2022 "const x = 10; return x;\n", |
| 1956 | 2023 |
| 1957 "const x = ( x = 20);", | 2024 "const x = ( x = 20);\n", |
| 1958 | 2025 |
| 1959 "const x = 10; x = 20;", | 2026 "const x = 10; x = 20;\n", |
| 1960 }; | 2027 }; |
| 1961 | 2028 |
| 1962 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("ConstVariable.golden")); | 2029 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2030 LoadGolden("ConstVariable.golden"))); |
| 1963 } | 2031 } |
| 1964 | 2032 |
| 1965 TEST(LetVariable) { | 2033 TEST(LetVariable) { |
| 1966 InitializedIgnitionHandleScope scope; | 2034 InitializedIgnitionHandleScope scope; |
| 1967 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2035 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1968 ConstantPoolType::kString); | 2036 ConstantPoolType::kString); |
| 1969 const char* snippets[] = { | 2037 const char* snippets[] = { |
| 1970 "let x = 10;", | 2038 "let x = 10;\n", |
| 1971 | 2039 |
| 1972 "let x = 10; return x;", | 2040 "let x = 10; return x;\n", |
| 1973 | 2041 |
| 1974 "let x = (x = 20);", | 2042 "let x = (x = 20);\n", |
| 1975 | 2043 |
| 1976 "let x = 10; x = 20;", | 2044 "let x = 10; x = 20;\n", |
| 1977 }; | 2045 }; |
| 1978 | 2046 |
| 1979 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("LetVariable.golden")); | 2047 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2048 LoadGolden("LetVariable.golden"))); |
| 1980 } | 2049 } |
| 1981 | 2050 |
| 1982 TEST(ConstVariableContextSlot) { | 2051 TEST(ConstVariableContextSlot) { |
| 1983 // TODO(mythria): Add tests for initialization of this via super calls. | 2052 // TODO(mythria): Add tests for initialization of this via super calls. |
| 1984 // TODO(mythria): Add tests that walk the context chain. | 2053 // TODO(mythria): Add tests that walk the context chain. |
| 1985 InitializedIgnitionHandleScope scope; | 2054 InitializedIgnitionHandleScope scope; |
| 1986 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2055 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 1987 ConstantPoolType::kMixed); | 2056 ConstantPoolType::kMixed); |
| 1988 const char* snippets[] = { | 2057 const char* snippets[] = { |
| 1989 "const x = 10; function f1() {return x;}", | 2058 "const x = 10; function f1() {return x;}\n", |
| 1990 | 2059 |
| 1991 "const x = 10; function f1() {return x;} return x;", | 2060 "const x = 10; function f1() {return x;} return x;\n", |
| 1992 | 2061 |
| 1993 "const x = (x = 20); function f1() {return x;}", | 2062 "const x = (x = 20); function f1() {return x;}\n", |
| 1994 | 2063 |
| 1995 "const x = 10; x = 20; function f1() {return x;}", | 2064 "const x = 10; x = 20; function f1() {return x;}\n", |
| 1996 }; | 2065 }; |
| 1997 | 2066 |
| 1998 CHECK_EQ(BuildActual(printer, snippets), | 2067 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 1999 LoadGolden("ConstVariableContextSlot.golden")); | 2068 LoadGolden("ConstVariableContextSlot.golden"))); |
| 2000 } | 2069 } |
| 2001 | 2070 |
| 2002 TEST(LetVariableContextSlot) { | 2071 TEST(LetVariableContextSlot) { |
| 2003 InitializedIgnitionHandleScope scope; | 2072 InitializedIgnitionHandleScope scope; |
| 2004 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2073 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2005 ConstantPoolType::kMixed); | 2074 ConstantPoolType::kMixed); |
| 2006 const char* snippets[] = { | 2075 const char* snippets[] = { |
| 2007 "let x = 10; function f1() {return x;}", | 2076 "let x = 10; function f1() {return x;}\n", |
| 2008 | 2077 |
| 2009 "let x = 10; function f1() {return x;} return x;", | 2078 "let x = 10; function f1() {return x;} return x;\n", |
| 2010 | 2079 |
| 2011 "let x = (x = 20); function f1() {return x;}", | 2080 "let x = (x = 20); function f1() {return x;}\n", |
| 2012 | 2081 |
| 2013 "let x = 10; x = 20; function f1() {return x;}", | 2082 "let x = 10; x = 20; function f1() {return x;}\n", |
| 2014 }; | 2083 }; |
| 2015 | 2084 |
| 2016 CHECK_EQ(BuildActual(printer, snippets), | 2085 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2017 LoadGolden("LetVariableContextSlot.golden")); | 2086 LoadGolden("LetVariableContextSlot.golden"))); |
| 2018 } | 2087 } |
| 2019 | 2088 |
| 2020 TEST(DoExpression) { | 2089 TEST(DoExpression) { |
| 2021 bool old_flag = FLAG_harmony_do_expressions; | 2090 bool old_flag = FLAG_harmony_do_expressions; |
| 2022 FLAG_harmony_do_expressions = true; | 2091 FLAG_harmony_do_expressions = true; |
| 2023 | 2092 |
| 2024 InitializedIgnitionHandleScope scope; | 2093 InitializedIgnitionHandleScope scope; |
| 2025 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2094 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2026 ConstantPoolType::kString); | 2095 ConstantPoolType::kString); |
| 2027 const char* snippets[] = { | 2096 const char* snippets[] = { |
| 2028 "var a = do { }; return a;", | 2097 "var a = do { }; return a;\n", |
| 2029 | 2098 |
| 2030 "var a = do { var x = 100; }; return a;", | 2099 "var a = do { var x = 100; }; return a;\n", |
| 2031 | 2100 |
| 2032 "while(true) { var a = 10; a = do { ++a; break; }; a = 20; }", | 2101 "while(true) { var a = 10; a = do { ++a; break; }; a = 20; }\n", |
| 2033 }; | 2102 }; |
| 2034 | 2103 |
| 2035 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("DoExpression.golden")); | 2104 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2105 LoadGolden("DoExpression.golden"))); |
| 2036 | 2106 |
| 2037 FLAG_harmony_do_expressions = old_flag; | 2107 FLAG_harmony_do_expressions = old_flag; |
| 2038 } | 2108 } |
| 2039 | 2109 |
| 2040 TEST(WithStatement) { | 2110 TEST(WithStatement) { |
| 2041 InitializedIgnitionHandleScope scope; | 2111 InitializedIgnitionHandleScope scope; |
| 2042 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2112 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2043 ConstantPoolType::kMixed); | 2113 ConstantPoolType::kMixed); |
| 2044 const char* snippets[] = { | 2114 const char* snippets[] = { |
| 2045 "with ({x:42}) { return x; }", | 2115 "with ({x:42}) { return x; }\n", |
| 2046 }; | 2116 }; |
| 2047 | 2117 |
| 2048 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("WithStatement.golden")); | 2118 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2119 LoadGolden("WithStatement.golden"))); |
| 2049 } | 2120 } |
| 2050 | 2121 |
| 2051 TEST(DoDebugger) { | 2122 TEST(DoDebugger) { |
| 2052 InitializedIgnitionHandleScope scope; | 2123 InitializedIgnitionHandleScope scope; |
| 2053 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2124 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2054 ConstantPoolType::kString); | 2125 ConstantPoolType::kString); |
| 2055 const char* snippets[] = { | 2126 const char* snippets[] = { |
| 2056 "debugger;", | 2127 "debugger;\n", |
| 2057 }; | 2128 }; |
| 2058 | 2129 |
| 2059 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("DoDebugger.golden")); | 2130 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2131 LoadGolden("DoDebugger.golden"))); |
| 2060 } | 2132 } |
| 2061 | 2133 |
| 2062 TEST(ClassDeclarations) { | 2134 TEST(ClassDeclarations) { |
| 2063 InitializedIgnitionHandleScope scope; | 2135 InitializedIgnitionHandleScope scope; |
| 2064 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2136 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2065 ConstantPoolType::kMixed); | 2137 ConstantPoolType::kMixed); |
| 2066 const char* snippets[] = { | 2138 const char* snippets[] = { |
| 2067 "class Person {\n" | 2139 "class Person {\n" |
| 2068 " constructor(name) { this.name = name; }\n" | 2140 " constructor(name) { this.name = name; }\n" |
| 2069 " speak() { console.log(this.name + ' is speaking.'); }\n" | 2141 " speak() { console.log(this.name + ' is speaking.'); }\n" |
| 2070 "}", | 2142 "}\n", |
| 2071 | 2143 |
| 2072 "class person {\n" | 2144 "class person {\n" |
| 2073 " constructor(name) { this.name = name; }\n" | 2145 " constructor(name) { this.name = name; }\n" |
| 2074 " speak() { console.log(this.name + ' is speaking.'); }\n" | 2146 " speak() { console.log(this.name + ' is speaking.'); }\n" |
| 2075 "}", | 2147 "}\n", |
| 2076 | 2148 |
| 2077 "var n0 = 'a';\n" | 2149 "var n0 = 'a';\n" |
| 2078 "var n1 = 'b';\n" | 2150 "var n1 = 'b';\n" |
| 2079 "class N {\n" | 2151 "class N {\n" |
| 2080 " [n0]() { return n0; }\n" | 2152 " [n0]() { return n0; }\n" |
| 2081 " static [n1]() { return n1; }\n" | 2153 " static [n1]() { return n1; }\n" |
| 2082 "}", | 2154 "}\n", |
| 2083 | 2155 |
| 2084 "var count = 0;\n" | 2156 "var count = 0;\n" |
| 2085 "class C { constructor() { count++; }}\n" | 2157 "class C { constructor() { count++; }}\n" |
| 2086 "return new C();\n", | 2158 "return new C();\n", |
| 2087 }; | 2159 }; |
| 2088 | 2160 |
| 2089 CHECK_EQ(BuildActual(printer, snippets), | 2161 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2090 LoadGolden("ClassDeclarations.golden")); | 2162 LoadGolden("ClassDeclarations.golden"))); |
| 2091 } | 2163 } |
| 2092 | 2164 |
| 2093 TEST(ClassAndSuperClass) { | 2165 TEST(ClassAndSuperClass) { |
| 2094 InitializedIgnitionHandleScope scope; | 2166 InitializedIgnitionHandleScope scope; |
| 2095 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2167 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2096 ConstantPoolType::kMixed); | 2168 ConstantPoolType::kMixed); |
| 2097 printer.set_wrap(false); | 2169 printer.set_wrap(false); |
| 2098 printer.set_test_function_name("test"); | 2170 printer.set_test_function_name("test"); |
| 2099 const char* snippets[] = { | 2171 const char* snippets[] = { |
| 2100 "var test;\n" | 2172 "var test;\n" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2138 " class A {\n" | 2210 " class A {\n" |
| 2139 " constructor() { this.x_ = 1; }\n" | 2211 " constructor() { this.x_ = 1; }\n" |
| 2140 " }\n" | 2212 " }\n" |
| 2141 " class B extends A {\n" | 2213 " class B extends A {\n" |
| 2142 " constructor() { super(); this.y_ = 2; }\n" | 2214 " constructor() { super(); this.y_ = 2; }\n" |
| 2143 " }\n" | 2215 " }\n" |
| 2144 " test = new B().constructor;\n" | 2216 " test = new B().constructor;\n" |
| 2145 "})();\n", | 2217 "})();\n", |
| 2146 }; | 2218 }; |
| 2147 | 2219 |
| 2148 CHECK_EQ(BuildActual(printer, snippets), | 2220 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2149 LoadGolden("ClassAndSuperClass.golden")); | 2221 LoadGolden("ClassAndSuperClass.golden"))); |
| 2150 } | 2222 } |
| 2151 | 2223 |
| 2152 TEST(Generators) { | 2224 TEST(Generators) { |
| 2153 bool old_flag = FLAG_ignition_generators; | 2225 bool old_flag = FLAG_ignition_generators; |
| 2154 FLAG_ignition_generators = true; | 2226 FLAG_ignition_generators = true; |
| 2155 | 2227 |
| 2156 InitializedIgnitionHandleScope scope; | 2228 InitializedIgnitionHandleScope scope; |
| 2157 BytecodeExpectationsPrinter printer(CcTest::isolate(), | 2229 BytecodeExpectationsPrinter printer(CcTest::isolate(), |
| 2158 ConstantPoolType::kMixed); | 2230 ConstantPoolType::kMixed); |
| 2159 printer.set_wrap(false); | 2231 printer.set_wrap(false); |
| 2160 printer.set_test_function_name("f"); | 2232 printer.set_test_function_name("f"); |
| 2161 | 2233 |
| 2162 const char* snippets[] = { | 2234 const char* snippets[] = { |
| 2163 "function* f() { }", | 2235 "function* f() { }\n", |
| 2164 | 2236 |
| 2165 "function* f() { yield 42 }", | 2237 "function* f() { yield 42 }\n", |
| 2166 | 2238 |
| 2167 "function* f() { for (let x of [42]) yield x }", | 2239 "function* f() { for (let x of [42]) yield x }\n", |
| 2168 }; | 2240 }; |
| 2169 | 2241 |
| 2170 CHECK_EQ(BuildActual(printer, snippets), LoadGolden("Generators.golden")); | 2242 CHECK(CompareTexts(BuildActual(printer, snippets), |
| 2243 LoadGolden("Generators.golden"))); |
| 2171 | 2244 |
| 2172 FLAG_ignition_generators = old_flag; | 2245 FLAG_ignition_generators = old_flag; |
| 2173 } | 2246 } |
| 2174 | 2247 |
| 2175 } // namespace interpreter | 2248 } // namespace interpreter |
| 2176 } // namespace internal | 2249 } // namespace internal |
| 2177 } // namespace v8 | 2250 } // namespace v8 |
| OLD | NEW |