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