| 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 "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 267 } |
| 268 iterator.Advance(); | 268 iterator.Advance(); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 TEST(PrimitiveReturnStatements) { | 273 TEST(PrimitiveReturnStatements) { |
| 274 InitializedHandleScope handle_scope; | 274 InitializedHandleScope handle_scope; |
| 275 BytecodeGeneratorHelper helper; | 275 BytecodeGeneratorHelper helper; |
| 276 | 276 |
| 277 // clang-format off |
| 277 ExpectedSnippet<int> snippets[] = { | 278 ExpectedSnippet<int> snippets[] = { |
| 278 {"", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0}, | 279 {"", |
| 279 {"return;", 0, 1, 2, {B(LdaUndefined), B(Return)}, 0}, | 280 0, |
| 280 {"return null;", 0, 1, 2, {B(LdaNull), B(Return)}, 0}, | 281 1, |
| 281 {"return true;", 0, 1, 2, {B(LdaTrue), B(Return)}, 0}, | 282 3, |
| 282 {"return false;", 0, 1, 2, {B(LdaFalse), B(Return)}, 0}, | 283 { |
| 283 {"return 0;", 0, 1, 2, {B(LdaZero), B(Return)}, 0}, | 284 B(StackCheck), // |
| 284 {"return +1;", 0, 1, 3, {B(LdaSmi8), U8(1), B(Return)}, 0}, | 285 B(LdaUndefined), // |
| 285 {"return -1;", 0, 1, 3, {B(LdaSmi8), U8(-1), B(Return)}, 0}, | 286 B(Return) // |
| 286 {"return +127;", 0, 1, 3, {B(LdaSmi8), U8(127), B(Return)}, 0}, | 287 }, |
| 287 {"return -128;", 0, 1, 3, {B(LdaSmi8), U8(-128), B(Return)}, 0}, | 288 0}, |
| 289 {"return;", |
| 290 0, |
| 291 1, |
| 292 3, |
| 293 { |
| 294 B(StackCheck), // |
| 295 B(LdaUndefined), // |
| 296 B(Return) // |
| 297 }, |
| 298 0}, |
| 299 {"return null;", |
| 300 0, |
| 301 1, |
| 302 3, |
| 303 { |
| 304 B(StackCheck), // |
| 305 B(LdaNull), // |
| 306 B(Return) // |
| 307 }, |
| 308 0}, |
| 309 {"return true;", |
| 310 0, |
| 311 1, |
| 312 3, |
| 313 { |
| 314 B(StackCheck), // |
| 315 B(LdaTrue), // |
| 316 B(Return) // |
| 317 }, |
| 318 0}, |
| 319 {"return false;", |
| 320 0, |
| 321 1, |
| 322 3, |
| 323 { |
| 324 B(StackCheck), // |
| 325 B(LdaFalse), // |
| 326 B(Return) // |
| 327 }, |
| 328 0}, |
| 329 {"return 0;", |
| 330 0, |
| 331 1, |
| 332 3, |
| 333 { |
| 334 B(StackCheck), // |
| 335 B(LdaZero), // |
| 336 B(Return) // |
| 337 }, |
| 338 0}, |
| 339 {"return +1;", |
| 340 0, |
| 341 1, |
| 342 4, |
| 343 { |
| 344 B(StackCheck), // |
| 345 B(LdaSmi8), U8(1), // |
| 346 B(Return) // |
| 347 }, |
| 348 0}, |
| 349 {"return -1;", |
| 350 0, |
| 351 1, |
| 352 4, |
| 353 { |
| 354 B(StackCheck), // |
| 355 B(LdaSmi8), U8(-1), // |
| 356 B(Return) // |
| 357 }, |
| 358 0}, |
| 359 {"return +127;", |
| 360 0, |
| 361 1, |
| 362 4, |
| 363 { |
| 364 B(StackCheck), // |
| 365 B(LdaSmi8), U8(127), // |
| 366 B(Return) // |
| 367 }, |
| 368 0}, |
| 369 {"return -128;", |
| 370 0, |
| 371 1, |
| 372 4, |
| 373 { |
| 374 B(StackCheck), // |
| 375 B(LdaSmi8), U8(-128), // |
| 376 B(Return) // |
| 377 }, |
| 378 0}, |
| 288 }; | 379 }; |
| 380 // clang-format on |
| 289 | 381 |
| 290 for (size_t i = 0; i < arraysize(snippets); i++) { | 382 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 291 Handle<BytecodeArray> bytecode_array = | 383 Handle<BytecodeArray> bytecode_array = |
| 292 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 384 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 293 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 385 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 294 } | 386 } |
| 295 } | 387 } |
| 296 | 388 |
| 297 | 389 |
| 298 TEST(PrimitiveExpressions) { | 390 TEST(PrimitiveExpressions) { |
| 299 InitializedHandleScope handle_scope; | 391 InitializedHandleScope handle_scope; |
| 300 BytecodeGeneratorHelper helper; | 392 BytecodeGeneratorHelper helper; |
| 301 | 393 |
| 394 // clang-format off |
| 302 ExpectedSnippet<int> snippets[] = { | 395 ExpectedSnippet<int> snippets[] = { |
| 303 {"var x = 0; return x;", | 396 {"var x = 0; return x;", |
| 304 kPointerSize, | 397 kPointerSize, |
| 305 1, | 398 1, |
| 306 4, | 399 5, |
| 307 {B(LdaZero), // | 400 {B(StackCheck), // |
| 401 B(LdaZero), // |
| 308 B(Star), R(0), // | 402 B(Star), R(0), // |
| 309 B(Return)}, | 403 B(Return)}, |
| 310 0}, | 404 0}, |
| 311 {"var x = 0; return x + 3;", | 405 {"var x = 0; return x + 3;", |
| 312 2 * kPointerSize, | 406 2 * kPointerSize, |
| 313 1, | 407 1, |
| 314 10, | 408 11, |
| 315 {B(LdaZero), // | 409 {B(StackCheck), // |
| 410 B(LdaZero), // |
| 316 B(Star), R(0), // | 411 B(Star), R(0), // |
| 317 B(Star), R(1), // | 412 B(Star), R(1), // |
| 318 B(LdaSmi8), U8(3), // | 413 B(LdaSmi8), U8(3), // |
| 319 B(Add), R(1), // | 414 B(Add), R(1), // |
| 320 B(Return)}, | 415 B(Return)}, |
| 321 0}, | 416 0}, |
| 322 {"var x = 0; return x - 3;", | 417 {"var x = 0; return x - 3;", |
| 323 2 * kPointerSize, | 418 2 * kPointerSize, |
| 324 1, | 419 1, |
| 325 10, | 420 11, |
| 326 {B(LdaZero), // | 421 {B(StackCheck), // |
| 422 B(LdaZero), // |
| 327 B(Star), R(0), // | 423 B(Star), R(0), // |
| 328 B(Star), R(1), // | 424 B(Star), R(1), // |
| 329 B(LdaSmi8), U8(3), // | 425 B(LdaSmi8), U8(3), // |
| 330 B(Sub), R(1), // | 426 B(Sub), R(1), // |
| 331 B(Return)}, | 427 B(Return)}, |
| 332 0}, | 428 0}, |
| 333 {"var x = 4; return x * 3;", | 429 {"var x = 4; return x * 3;", |
| 334 2 * kPointerSize, | 430 2 * kPointerSize, |
| 335 1, | 431 1, |
| 336 11, | 432 12, |
| 337 {B(LdaSmi8), U8(4), // | 433 {B(StackCheck), // |
| 434 B(LdaSmi8), U8(4), // |
| 338 B(Star), R(0), // | 435 B(Star), R(0), // |
| 339 B(Star), R(1), // | 436 B(Star), R(1), // |
| 340 B(LdaSmi8), U8(3), // | 437 B(LdaSmi8), U8(3), // |
| 341 B(Mul), R(1), // | 438 B(Mul), R(1), // |
| 342 B(Return)}, | 439 B(Return)}, |
| 343 0}, | 440 0}, |
| 344 {"var x = 4; return x / 3;", | 441 {"var x = 4; return x / 3;", |
| 345 2 * kPointerSize, | 442 2 * kPointerSize, |
| 346 1, | 443 1, |
| 347 11, | 444 12, |
| 348 {B(LdaSmi8), U8(4), // | 445 {B(StackCheck), // |
| 446 B(LdaSmi8), U8(4), // |
| 349 B(Star), R(0), // | 447 B(Star), R(0), // |
| 350 B(Star), R(1), // | 448 B(Star), R(1), // |
| 351 B(LdaSmi8), U8(3), // | 449 B(LdaSmi8), U8(3), // |
| 352 B(Div), R(1), // | 450 B(Div), R(1), // |
| 353 B(Return)}, | 451 B(Return)}, |
| 354 0}, | 452 0}, |
| 355 {"var x = 4; return x % 3;", | 453 {"var x = 4; return x % 3;", |
| 356 2 * kPointerSize, | 454 2 * kPointerSize, |
| 357 1, | 455 1, |
| 358 11, | 456 12, |
| 359 {B(LdaSmi8), U8(4), // | 457 {B(StackCheck), // |
| 458 B(LdaSmi8), U8(4), // |
| 360 B(Star), R(0), // | 459 B(Star), R(0), // |
| 361 B(Star), R(1), // | 460 B(Star), R(1), // |
| 362 B(LdaSmi8), U8(3), // | 461 B(LdaSmi8), U8(3), // |
| 363 B(Mod), R(1), // | 462 B(Mod), R(1), // |
| 364 B(Return)}, | 463 B(Return)}, |
| 365 0}, | 464 0}, |
| 366 {"var x = 1; return x | 2;", | 465 {"var x = 1; return x | 2;", |
| 367 2 * kPointerSize, | 466 2 * kPointerSize, |
| 368 1, | 467 1, |
| 369 11, | 468 12, |
| 370 {B(LdaSmi8), U8(1), // | 469 {B(StackCheck), // |
| 470 B(LdaSmi8), U8(1), // |
| 371 B(Star), R(0), // | 471 B(Star), R(0), // |
| 372 B(Star), R(1), // | 472 B(Star), R(1), // |
| 373 B(LdaSmi8), U8(2), // | 473 B(LdaSmi8), U8(2), // |
| 374 B(BitwiseOr), R(1), // | 474 B(BitwiseOr), R(1), // |
| 375 B(Return)}, | 475 B(Return)}, |
| 376 0}, | 476 0}, |
| 377 {"var x = 1; return x ^ 2;", | 477 {"var x = 1; return x ^ 2;", |
| 378 2 * kPointerSize, | 478 2 * kPointerSize, |
| 379 1, | 479 1, |
| 380 11, | 480 12, |
| 381 {B(LdaSmi8), U8(1), // | 481 {B(StackCheck), // |
| 482 B(LdaSmi8), U8(1), // |
| 382 B(Star), R(0), // | 483 B(Star), R(0), // |
| 383 B(Star), R(1), // | 484 B(Star), R(1), // |
| 384 B(LdaSmi8), U8(2), // | 485 B(LdaSmi8), U8(2), // |
| 385 B(BitwiseXor), R(1), // | 486 B(BitwiseXor), R(1), // |
| 386 B(Return)}, | 487 B(Return)}, |
| 387 0}, | 488 0}, |
| 388 {"var x = 1; return x & 2;", | 489 {"var x = 1; return x & 2;", |
| 389 2 * kPointerSize, | 490 2 * kPointerSize, |
| 390 1, | 491 1, |
| 391 11, | 492 12, |
| 392 {B(LdaSmi8), U8(1), // | 493 {B(StackCheck), // |
| 494 B(LdaSmi8), U8(1), // |
| 393 B(Star), R(0), // | 495 B(Star), R(0), // |
| 394 B(Star), R(1), // | 496 B(Star), R(1), // |
| 395 B(LdaSmi8), U8(2), // | 497 B(LdaSmi8), U8(2), // |
| 396 B(BitwiseAnd), R(1), // | 498 B(BitwiseAnd), R(1), // |
| 397 B(Return)}, | 499 B(Return)}, |
| 398 0}, | 500 0}, |
| 399 {"var x = 10; return x << 3;", | 501 {"var x = 10; return x << 3;", |
| 400 2 * kPointerSize, | 502 2 * kPointerSize, |
| 401 1, | 503 1, |
| 402 11, | 504 12, |
| 403 {B(LdaSmi8), U8(10), // | 505 {B(StackCheck), // |
| 506 B(LdaSmi8), U8(10), // |
| 404 B(Star), R(0), // | 507 B(Star), R(0), // |
| 405 B(Star), R(1), // | 508 B(Star), R(1), // |
| 406 B(LdaSmi8), U8(3), // | 509 B(LdaSmi8), U8(3), // |
| 407 B(ShiftLeft), R(1), // | 510 B(ShiftLeft), R(1), // |
| 408 B(Return)}, | 511 B(Return)}, |
| 409 0}, | 512 0}, |
| 410 {"var x = 10; return x >> 3;", | 513 {"var x = 10; return x >> 3;", |
| 411 2 * kPointerSize, | 514 2 * kPointerSize, |
| 412 1, | 515 1, |
| 413 11, | 516 12, |
| 414 {B(LdaSmi8), U8(10), // | 517 {B(StackCheck), // |
| 518 B(LdaSmi8), U8(10), // |
| 415 B(Star), R(0), // | 519 B(Star), R(0), // |
| 416 B(Star), R(1), // | 520 B(Star), R(1), // |
| 417 B(LdaSmi8), U8(3), // | 521 B(LdaSmi8), U8(3), // |
| 418 B(ShiftRight), R(1), // | 522 B(ShiftRight), R(1), // |
| 419 B(Return)}, | 523 B(Return)}, |
| 420 0}, | 524 0}, |
| 421 {"var x = 10; return x >>> 3;", | 525 {"var x = 10; return x >>> 3;", |
| 422 2 * kPointerSize, | 526 2 * kPointerSize, |
| 423 1, | 527 1, |
| 424 11, | 528 12, |
| 425 {B(LdaSmi8), U8(10), // | 529 {B(StackCheck), // |
| 530 B(LdaSmi8), U8(10), // |
| 426 B(Star), R(0), // | 531 B(Star), R(0), // |
| 427 B(Star), R(1), // | 532 B(Star), R(1), // |
| 428 B(LdaSmi8), U8(3), // | 533 B(LdaSmi8), U8(3), // |
| 429 B(ShiftRightLogical), R(1), // | 534 B(ShiftRightLogical), R(1), // |
| 430 B(Return)}, | 535 B(Return)}, |
| 431 0}, | 536 0}, |
| 432 {"var x = 0; return (x, 3);", | 537 {"var x = 0; return (x, 3);", |
| 433 1 * kPointerSize, | 538 1 * kPointerSize, |
| 434 1, | 539 1, |
| 435 6, | 540 7, |
| 436 {B(LdaZero), // | 541 {B(StackCheck), // |
| 542 B(LdaZero), // |
| 437 B(Star), R(0), // | 543 B(Star), R(0), // |
| 438 B(LdaSmi8), U8(3), // | 544 B(LdaSmi8), U8(3), // |
| 439 B(Return)}, | 545 B(Return)}, |
| 440 0}}; | 546 0}, |
| 547 }; |
| 548 // clang-format on |
| 441 | 549 |
| 442 for (size_t i = 0; i < arraysize(snippets); i++) { | 550 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 443 Handle<BytecodeArray> bytecode_array = | 551 Handle<BytecodeArray> bytecode_array = |
| 444 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 552 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 445 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 553 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 446 } | 554 } |
| 447 } | 555 } |
| 448 | 556 |
| 449 | 557 |
| 450 TEST(LogicalExpressions) { | 558 TEST(LogicalExpressions) { |
| 451 InitializedHandleScope handle_scope; | 559 InitializedHandleScope handle_scope; |
| 452 BytecodeGeneratorHelper helper; | 560 BytecodeGeneratorHelper helper; |
| 453 | 561 |
| 562 // clang-format off |
| 454 ExpectedSnippet<int> snippets[] = { | 563 ExpectedSnippet<int> snippets[] = { |
| 455 {"var x = 0; return x || 3;", | 564 {"var x = 0; return x || 3;", |
| 456 1 * kPointerSize, | 565 1 * kPointerSize, |
| 457 1, | 566 1, |
| 458 8, | 567 9, |
| 459 {B(LdaZero), // | 568 {B(StackCheck), // |
| 569 B(LdaZero), // |
| 460 B(Star), R(0), // | 570 B(Star), R(0), // |
| 461 B(JumpIfToBooleanTrue), U8(4), // | 571 B(JumpIfToBooleanTrue), U8(4), // |
| 462 B(LdaSmi8), U8(3), // | 572 B(LdaSmi8), U8(3), // |
| 463 B(Return)}, | 573 B(Return)}, |
| 464 0}, | 574 0}, |
| 465 {"var x = 0; return (x == 1) || 3;", | 575 {"var x = 0; return (x == 1) || 3;", |
| 466 2 * kPointerSize, | 576 2 * kPointerSize, |
| 467 1, | 577 1, |
| 468 14, | 578 15, |
| 469 {B(LdaZero), // | 579 {B(StackCheck), // |
| 580 B(LdaZero), // |
| 470 B(Star), R(0), // | 581 B(Star), R(0), // |
| 471 B(Star), R(1), // | 582 B(Star), R(1), // |
| 472 B(LdaSmi8), U8(1), // | 583 B(LdaSmi8), U8(1), // |
| 473 B(TestEqual), R(1), // | 584 B(TestEqual), R(1), // |
| 474 B(JumpIfTrue), U8(4), // | 585 B(JumpIfTrue), U8(4), // |
| 475 B(LdaSmi8), U8(3), // | 586 B(LdaSmi8), U8(3), // |
| 476 B(Return)}, | 587 B(Return)}, |
| 477 0}, | 588 0}, |
| 478 {"var x = 0; return x && 3;", | 589 {"var x = 0; return x && 3;", |
| 479 1 * kPointerSize, | 590 1 * kPointerSize, |
| 480 1, | 591 1, |
| 481 8, | 592 9, |
| 482 {B(LdaZero), // | 593 {B(StackCheck), // |
| 594 B(LdaZero), // |
| 483 B(Star), R(0), // | 595 B(Star), R(0), // |
| 484 B(JumpIfToBooleanFalse), U8(4), // | 596 B(JumpIfToBooleanFalse), U8(4), // |
| 485 B(LdaSmi8), U8(3), // | 597 B(LdaSmi8), U8(3), // |
| 486 B(Return)}, | 598 B(Return)}, |
| 487 0}, | 599 0}, |
| 488 {"var x = 0; return (x == 0) && 3;", | 600 {"var x = 0; return (x == 0) && 3;", |
| 489 2 * kPointerSize, | 601 2 * kPointerSize, |
| 490 1, | 602 1, |
| 491 13, | 603 14, |
| 492 {B(LdaZero), // | 604 {B(StackCheck), // |
| 605 B(LdaZero), // |
| 493 B(Star), R(0), // | 606 B(Star), R(0), // |
| 494 B(Star), R(1), // | 607 B(Star), R(1), // |
| 495 B(LdaZero), // | 608 B(LdaZero), // |
| 496 B(TestEqual), R(1), // | 609 B(TestEqual), R(1), // |
| 497 B(JumpIfFalse), U8(4), // | 610 B(JumpIfFalse), U8(4), // |
| 498 B(LdaSmi8), U8(3), // | 611 B(LdaSmi8), U8(3), // |
| 499 B(Return)}, | 612 B(Return)}, |
| 500 0}, | 613 0}, |
| 501 {"var x = 0; return x || (1, 2, 3);", | 614 {"var x = 0; return x || (1, 2, 3);", |
| 502 1 * kPointerSize, | 615 1 * kPointerSize, |
| 503 1, | 616 1, |
| 504 8, | 617 9, |
| 505 {B(LdaZero), // | 618 {B(StackCheck), // |
| 619 B(LdaZero), // |
| 506 B(Star), R(0), // | 620 B(Star), R(0), // |
| 507 B(JumpIfToBooleanTrue), U8(4), // | 621 B(JumpIfToBooleanTrue), U8(4), // |
| 508 B(LdaSmi8), U8(3), // | 622 B(LdaSmi8), U8(3), // |
| 509 B(Return)}, | 623 B(Return)}, |
| 510 0}, | 624 0}, |
| 511 {"var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);", | 625 {"var a = 2, b = 3, c = 4; return a || (a, b, a, b, c = 5, 3);", |
| 512 3 * kPointerSize, | 626 3 * kPointerSize, |
| 513 1, | 627 1, |
| 514 31, | 628 32, |
| 515 {B(LdaSmi8), U8(2), // | 629 {B(StackCheck), // |
| 630 B(LdaSmi8), U8(2), // |
| 516 B(Star), R(0), // | 631 B(Star), R(0), // |
| 517 B(LdaSmi8), U8(3), // | 632 B(LdaSmi8), U8(3), // |
| 518 B(Star), R(1), // | 633 B(Star), R(1), // |
| 519 B(LdaSmi8), U8(4), // | 634 B(LdaSmi8), U8(4), // |
| 520 B(Star), R(2), // | 635 B(Star), R(2), // |
| 521 B(Ldar), R(0), // | 636 B(Ldar), R(0), // |
| 522 B(JumpIfToBooleanTrue), U8(16), // | 637 B(JumpIfToBooleanTrue), U8(16), // |
| 523 B(Ldar), R(0), // | 638 B(Ldar), R(0), // |
| 524 B(Ldar), R(1), // | 639 B(Ldar), R(1), // |
| 525 B(Ldar), R(0), // | 640 B(Ldar), R(0), // |
| 526 B(Ldar), R(1), // | 641 B(Ldar), R(1), // |
| 527 B(LdaSmi8), U8(5), // | 642 B(LdaSmi8), U8(5), // |
| 528 B(Star), R(2), // | 643 B(Star), R(2), // |
| 529 B(LdaSmi8), U8(3), // | 644 B(LdaSmi8), U8(3), // |
| 530 B(Return)}, | 645 B(Return)}, |
| 531 0}, | 646 0}, |
| 532 {"var x = 1; var a = 2, b = 3; return x || (" | 647 {"var x = 1; var a = 2, b = 3; return x || (" |
| 533 REPEAT_32(SPACE, "a = 1, b = 2, ") | 648 REPEAT_32(SPACE, "a = 1, b = 2, ") |
| 534 "3);", | 649 "3);", |
| 535 3 * kPointerSize, | 650 3 * kPointerSize, |
| 536 1, | 651 1, |
| 537 275, | 652 276, |
| 538 {B(LdaSmi8), U8(1), // | 653 {B(StackCheck), // |
| 654 B(LdaSmi8), U8(1), // |
| 539 B(Star), R(0), // | 655 B(Star), R(0), // |
| 540 B(LdaSmi8), U8(2), // | 656 B(LdaSmi8), U8(2), // |
| 541 B(Star), R(1), // | 657 B(Star), R(1), // |
| 542 B(LdaSmi8), U8(3), // | 658 B(LdaSmi8), U8(3), // |
| 543 B(Star), R(2), // | 659 B(Star), R(2), // |
| 544 B(Ldar), R(0), // | 660 B(Ldar), R(0), // |
| 545 B(JumpIfToBooleanTrueConstant), U8(0), // | 661 B(JumpIfToBooleanTrueConstant), U8(0), // |
| 546 REPEAT_32(COMMA, // | 662 REPEAT_32(COMMA, // |
| 547 B(LdaSmi8), U8(1), // | 663 B(LdaSmi8), U8(1), // |
| 548 B(Star), R(1), // | 664 B(Star), R(1), // |
| 549 B(LdaSmi8), U8(2), // | 665 B(LdaSmi8), U8(2), // |
| 550 B(Star), R(2)), // | 666 B(Star), R(2)), // |
| 551 B(LdaSmi8), U8(3), // | 667 B(LdaSmi8), U8(3), // |
| 552 B(Return)}, | 668 B(Return)}, |
| 553 1, | 669 1, |
| 554 {260, 0, 0, 0}}, | 670 {260, 0, 0, 0}}, |
| 555 {"var x = 0; var a = 2, b = 3; return x && (" | 671 {"var x = 0; var a = 2, b = 3; return x && (" |
| 556 REPEAT_32(SPACE, "a = 1, b = 2, ") | 672 REPEAT_32(SPACE, "a = 1, b = 2, ") |
| 557 "3);", | 673 "3);", |
| 558 3 * kPointerSize, | 674 3 * kPointerSize, |
| 559 1, | 675 1, |
| 560 274, | 676 275, |
| 561 {B(LdaZero), // | 677 {B(StackCheck), // |
| 678 B(LdaZero), // |
| 562 B(Star), R(0), // | 679 B(Star), R(0), // |
| 563 B(LdaSmi8), U8(2), // | 680 B(LdaSmi8), U8(2), // |
| 564 B(Star), R(1), // | 681 B(Star), R(1), // |
| 565 B(LdaSmi8), U8(3), // | 682 B(LdaSmi8), U8(3), // |
| 566 B(Star), R(2), // | 683 B(Star), R(2), // |
| 567 B(Ldar), R(0), // | 684 B(Ldar), R(0), // |
| 568 B(JumpIfToBooleanFalseConstant), U8(0), // | 685 B(JumpIfToBooleanFalseConstant), U8(0), // |
| 569 REPEAT_32(COMMA, // | 686 REPEAT_32(COMMA, // |
| 570 B(LdaSmi8), U8(1), // | 687 B(LdaSmi8), U8(1), // |
| 571 B(Star), R(1), // | 688 B(Star), R(1), // |
| 572 B(LdaSmi8), U8(2), // | 689 B(LdaSmi8), U8(2), // |
| 573 B(Star), R(2)), // | 690 B(Star), R(2)), // |
| 574 B(LdaSmi8), U8(3), // | 691 B(LdaSmi8), U8(3), // |
| 575 B(Return)}, // | 692 B(Return)}, // |
| 576 1, | 693 1, |
| 577 {260, 0, 0, 0}}, | 694 {260, 0, 0, 0}}, |
| 578 {"var x = 1; var a = 2, b = 3; return (x > 3) || (" | 695 {"var x = 1; var a = 2, b = 3; return (x > 3) || (" |
| 579 REPEAT_32(SPACE, "a = 1, b = 2, ") | 696 REPEAT_32(SPACE, "a = 1, b = 2, ") |
| 580 "3);", | 697 "3);", |
| 581 4 * kPointerSize, | 698 4 * kPointerSize, |
| 582 1, | 699 1, |
| 583 281, | 700 282, |
| 584 {B(LdaSmi8), U8(1), // | 701 {B(StackCheck), // |
| 702 B(LdaSmi8), U8(1), // |
| 585 B(Star), R(0), // | 703 B(Star), R(0), // |
| 586 B(LdaSmi8), U8(2), // | 704 B(LdaSmi8), U8(2), // |
| 587 B(Star), R(1), // | 705 B(Star), R(1), // |
| 588 B(LdaSmi8), U8(3), // | 706 B(LdaSmi8), U8(3), // |
| 589 B(Star), R(2), // | 707 B(Star), R(2), // |
| 590 B(Ldar), R(0), // | 708 B(Ldar), R(0), // |
| 591 B(Star), R(3), // | 709 B(Star), R(3), // |
| 592 B(LdaSmi8), U8(3), // | 710 B(LdaSmi8), U8(3), // |
| 593 B(TestGreaterThan), R(3), // | 711 B(TestGreaterThan), R(3), // |
| 594 B(JumpIfTrueConstant), U8(0), // | 712 B(JumpIfTrueConstant), U8(0), // |
| 595 REPEAT_32(COMMA, // | 713 REPEAT_32(COMMA, // |
| 596 B(LdaSmi8), U8(1), // | 714 B(LdaSmi8), U8(1), // |
| 597 B(Star), R(1), // | 715 B(Star), R(1), // |
| 598 B(LdaSmi8), U8(2), // | 716 B(LdaSmi8), U8(2), // |
| 599 B(Star), R(2)), // | 717 B(Star), R(2)), // |
| 600 B(LdaSmi8), U8(3), // | 718 B(LdaSmi8), U8(3), // |
| 601 B(Return)}, | 719 B(Return)}, |
| 602 1, | 720 1, |
| 603 {260, 0, 0, 0}}, | 721 {260, 0, 0, 0}}, |
| 604 {"var x = 0; var a = 2, b = 3; return (x < 5) && (" | 722 {"var x = 0; var a = 2, b = 3; return (x < 5) && (" |
| 605 REPEAT_32(SPACE, "a = 1, b = 2, ") | 723 REPEAT_32(SPACE, "a = 1, b = 2, ") |
| 606 "3);", | 724 "3);", |
| 607 4 * kPointerSize, | 725 4 * kPointerSize, |
| 608 1, | 726 1, |
| 609 280, | 727 281, |
| 610 {B(LdaZero), // | 728 {B(StackCheck), // |
| 729 B(LdaZero), // |
| 611 B(Star), R(0), // | 730 B(Star), R(0), // |
| 612 B(LdaSmi8), U8(2), // | 731 B(LdaSmi8), U8(2), // |
| 613 B(Star), R(1), // | 732 B(Star), R(1), // |
| 614 B(LdaSmi8), U8(3), // | 733 B(LdaSmi8), U8(3), // |
| 615 B(Star), R(2), // | 734 B(Star), R(2), // |
| 616 B(Ldar), R(0), // | 735 B(Ldar), R(0), // |
| 617 B(Star), R(3), // | 736 B(Star), R(3), // |
| 618 B(LdaSmi8), U8(5), // | 737 B(LdaSmi8), U8(5), // |
| 619 B(TestLessThan), R(3), // | 738 B(TestLessThan), R(3), // |
| 620 B(JumpIfFalseConstant), U8(0), // | 739 B(JumpIfFalseConstant), U8(0), // |
| 621 REPEAT_32(COMMA, // | 740 REPEAT_32(COMMA, // |
| 622 B(LdaSmi8), U8(1), // | 741 B(LdaSmi8), U8(1), // |
| 623 B(Star), R(1), // | 742 B(Star), R(1), // |
| 624 B(LdaSmi8), U8(2), // | 743 B(LdaSmi8), U8(2), // |
| 625 B(Star), R(2)), // | 744 B(Star), R(2)), // |
| 626 B(LdaSmi8), U8(3), // | 745 B(LdaSmi8), U8(3), // |
| 627 B(Return)}, | 746 B(Return)}, |
| 628 1, | 747 1, |
| 629 {260, 0, 0, 0}}, | 748 {260, 0, 0, 0}}, |
| 630 {"return 0 && 3;", | 749 {"return 0 && 3;", |
| 631 0 * kPointerSize, | 750 0 * kPointerSize, |
| 632 1, | 751 1, |
| 633 2, | 752 3, |
| 634 {B(LdaZero), // | 753 {B(StackCheck), // |
| 754 B(LdaZero), // |
| 635 B(Return)}, | 755 B(Return)}, |
| 636 0}, | 756 0}, |
| 637 {"return 1 || 3;", | 757 {"return 1 || 3;", |
| 638 0 * kPointerSize, | 758 0 * kPointerSize, |
| 639 1, | 759 1, |
| 640 3, | 760 4, |
| 641 {B(LdaSmi8), U8(1), // | 761 {B(StackCheck), // |
| 762 B(LdaSmi8), U8(1), // |
| 642 B(Return)}, | 763 B(Return)}, |
| 643 0}, | 764 0}, |
| 644 {"var x = 1; return x && 3 || 0, 1;", | 765 {"var x = 1; return x && 3 || 0, 1;", |
| 645 1 * kPointerSize, | 766 1 * kPointerSize, |
| 646 1, | 767 1, |
| 647 14, | 768 15, |
| 648 {B(LdaSmi8), U8(1), // | 769 {B(StackCheck), // |
| 770 B(LdaSmi8), U8(1), // |
| 649 B(Star), R(0), // | 771 B(Star), R(0), // |
| 650 B(JumpIfToBooleanFalse), U8(4), // | 772 B(JumpIfToBooleanFalse), U8(4), // |
| 651 B(LdaSmi8), U8(3), // | 773 B(LdaSmi8), U8(3), // |
| 652 B(JumpIfToBooleanTrue), U8(3), // | 774 B(JumpIfToBooleanTrue), U8(3), // |
| 653 B(LdaZero), // | 775 B(LdaZero), // |
| 654 B(LdaSmi8), U8(1), // | 776 B(LdaSmi8), U8(1), // |
| 655 B(Return)}, | 777 B(Return)}, |
| 656 0}}; | 778 0} |
| 779 }; |
| 780 // clang-format on |
| 657 | 781 |
| 658 for (size_t i = 0; i < arraysize(snippets); i++) { | 782 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 659 Handle<BytecodeArray> bytecode_array = | 783 Handle<BytecodeArray> bytecode_array = |
| 660 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 784 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 661 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 785 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 662 } | 786 } |
| 663 } | 787 } |
| 664 | 788 |
| 665 | 789 |
| 666 TEST(Parameters) { | 790 TEST(Parameters) { |
| 667 InitializedHandleScope handle_scope; | 791 InitializedHandleScope handle_scope; |
| 668 BytecodeGeneratorHelper helper; | 792 BytecodeGeneratorHelper helper; |
| 669 | 793 |
| 794 // clang-format off |
| 670 ExpectedSnippet<int> snippets[] = { | 795 ExpectedSnippet<int> snippets[] = { |
| 671 {"function f() { return this; }", | 796 {"function f() { return this; }", |
| 672 0, | 797 0, |
| 673 1, | 798 1, |
| 674 3, | 799 4, |
| 675 {B(Ldar), THIS(1), B(Return)}, | 800 {B(StackCheck), // |
| 801 B(Ldar), THIS(1), // |
| 802 B(Return)}, |
| 676 0}, | 803 0}, |
| 677 {"function f(arg1) { return arg1; }", | 804 {"function f(arg1) { return arg1; }", |
| 678 0, | 805 0, |
| 679 2, | 806 2, |
| 680 3, | 807 4, |
| 681 {B(Ldar), A(1, 2), B(Return)}, | 808 {B(StackCheck), // |
| 809 B(Ldar), A(1, 2), // |
| 810 B(Return)}, |
| 682 0}, | 811 0}, |
| 683 {"function f(arg1) { return this; }", | 812 {"function f(arg1) { return this; }", |
| 684 0, | 813 0, |
| 685 2, | 814 2, |
| 686 3, | 815 4, |
| 687 {B(Ldar), THIS(2), B(Return)}, | 816 {B(StackCheck), // |
| 817 B(Ldar), THIS(2), // |
| 818 B(Return)}, |
| 688 0}, | 819 0}, |
| 689 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", | 820 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }", |
| 690 0, | 821 0, |
| 691 8, | 822 8, |
| 692 3, | 823 4, |
| 693 {B(Ldar), A(4, 8), B(Return)}, | 824 {B(StackCheck), // |
| 825 B(Ldar), A(4, 8), // |
| 826 B(Return)}, |
| 694 0}, | 827 0}, |
| 695 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", | 828 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return this; }", |
| 696 0, | 829 0, |
| 697 8, | 830 8, |
| 698 3, | 831 4, |
| 699 {B(Ldar), THIS(8), B(Return)}, | 832 {B(StackCheck), // |
| 833 B(Ldar), THIS(8), // |
| 834 B(Return)}, |
| 700 0}, | 835 0}, |
| 701 {"function f(arg1) { arg1 = 1; }", | 836 {"function f(arg1) { arg1 = 1; }", |
| 702 0, | 837 0, |
| 703 2, | 838 2, |
| 704 6, | 839 7, |
| 705 {B(LdaSmi8), U8(1), // | 840 {B(StackCheck), // |
| 841 B(LdaSmi8), U8(1), // |
| 706 B(Star), A(1, 2), // | 842 B(Star), A(1, 2), // |
| 707 B(LdaUndefined), // | 843 B(LdaUndefined), // |
| 708 B(Return)}, | 844 B(Return)}, |
| 709 0}, | 845 0}, |
| 710 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", | 846 {"function f(arg1, arg2, arg3, arg4) { arg2 = 1; }", |
| 711 0, | 847 0, |
| 712 5, | 848 5, |
| 713 6, | 849 7, |
| 714 {B(LdaSmi8), U8(1), // | 850 {B(StackCheck), // |
| 851 B(LdaSmi8), U8(1), // |
| 715 B(Star), A(2, 5), // | 852 B(Star), A(2, 5), // |
| 716 B(LdaUndefined), // | 853 B(LdaUndefined), // |
| 717 B(Return)}, | 854 B(Return)}, |
| 718 0}, | 855 0}, |
| 719 }; | 856 }; |
| 857 // clang-format on |
| 720 | 858 |
| 721 for (size_t i = 0; i < arraysize(snippets); i++) { | 859 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 722 Handle<BytecodeArray> bytecode_array = | 860 Handle<BytecodeArray> bytecode_array = |
| 723 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 861 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 724 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 862 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 725 } | 863 } |
| 726 } | 864 } |
| 727 | 865 |
| 728 | 866 |
| 729 TEST(IntegerConstants) { | 867 TEST(IntegerConstants) { |
| 730 InitializedHandleScope handle_scope; | 868 InitializedHandleScope handle_scope; |
| 731 BytecodeGeneratorHelper helper; | 869 BytecodeGeneratorHelper helper; |
| 732 | 870 |
| 871 // clang-format off |
| 733 ExpectedSnippet<int> snippets[] = { | 872 ExpectedSnippet<int> snippets[] = { |
| 734 {"return 12345678;", | 873 {"return 12345678;", |
| 735 0, | 874 0, |
| 736 1, | 875 1, |
| 737 3, | 876 4, |
| 738 { | 877 { |
| 878 B(StackCheck), // |
| 739 B(LdaConstant), U8(0), // | 879 B(LdaConstant), U8(0), // |
| 740 B(Return) // | 880 B(Return) // |
| 741 }, | 881 }, |
| 742 1, | 882 1, |
| 743 {12345678}}, | 883 {12345678}}, |
| 744 {"var a = 1234; return 5678;", | 884 {"var a = 1234; return 5678;", |
| 745 1 * kPointerSize, | 885 1 * kPointerSize, |
| 746 1, | 886 1, |
| 747 7, | 887 8, |
| 748 { | 888 { |
| 889 B(StackCheck), // |
| 749 B(LdaConstant), U8(0), // | 890 B(LdaConstant), U8(0), // |
| 750 B(Star), R(0), // | 891 B(Star), R(0), // |
| 751 B(LdaConstant), U8(1), // | 892 B(LdaConstant), U8(1), // |
| 752 B(Return) // | 893 B(Return) // |
| 753 }, | 894 }, |
| 754 2, | 895 2, |
| 755 {1234, 5678}}, | 896 {1234, 5678}}, |
| 756 {"var a = 1234; return 1234;", | 897 {"var a = 1234; return 1234;", |
| 757 1 * kPointerSize, | 898 1 * kPointerSize, |
| 758 1, | 899 1, |
| 759 7, | 900 8, |
| 760 { | 901 { |
| 902 B(StackCheck), // |
| 761 B(LdaConstant), U8(0), // | 903 B(LdaConstant), U8(0), // |
| 762 B(Star), R(0), // | 904 B(Star), R(0), // |
| 763 B(LdaConstant), U8(0), // | 905 B(LdaConstant), U8(0), // |
| 764 B(Return) // | 906 B(Return) // |
| 765 }, | 907 }, |
| 766 1, | 908 1, |
| 767 {1234}}}; | 909 {1234}} |
| 910 }; |
| 911 // clang-format on |
| 768 | 912 |
| 769 for (size_t i = 0; i < arraysize(snippets); i++) { | 913 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 770 Handle<BytecodeArray> bytecode_array = | 914 Handle<BytecodeArray> bytecode_array = |
| 771 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 915 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 772 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 916 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 773 } | 917 } |
| 774 } | 918 } |
| 775 | 919 |
| 776 | 920 |
| 777 TEST(HeapNumberConstants) { | 921 TEST(HeapNumberConstants) { |
| 778 InitializedHandleScope handle_scope; | 922 InitializedHandleScope handle_scope; |
| 779 BytecodeGeneratorHelper helper; | 923 BytecodeGeneratorHelper helper; |
| 780 | 924 |
| 781 int wide_idx = 0; | 925 int wide_idx = 0; |
| 782 | 926 |
| 927 // clang-format off |
| 783 ExpectedSnippet<double, 257> snippets[] = { | 928 ExpectedSnippet<double, 257> snippets[] = { |
| 784 {"return 1.2;", | 929 {"return 1.2;", |
| 785 0, | 930 0, |
| 786 1, | 931 1, |
| 787 3, | 932 4, |
| 788 { | 933 { |
| 934 B(StackCheck), // |
| 789 B(LdaConstant), U8(0), // | 935 B(LdaConstant), U8(0), // |
| 790 B(Return) // | 936 B(Return) // |
| 791 }, | 937 }, |
| 792 1, | 938 1, |
| 793 {1.2}}, | 939 {1.2}}, |
| 794 {"var a = 1.2; return 2.6;", | 940 {"var a = 1.2; return 2.6;", |
| 795 1 * kPointerSize, | 941 1 * kPointerSize, |
| 796 1, | 942 1, |
| 797 7, | 943 8, |
| 798 { | 944 { |
| 945 B(StackCheck), // |
| 799 B(LdaConstant), U8(0), // | 946 B(LdaConstant), U8(0), // |
| 800 B(Star), R(0), // | 947 B(Star), R(0), // |
| 801 B(LdaConstant), U8(1), // | 948 B(LdaConstant), U8(1), // |
| 802 B(Return) // | 949 B(Return) // |
| 803 }, | 950 }, |
| 804 2, | 951 2, |
| 805 {1.2, 2.6}}, | 952 {1.2, 2.6}}, |
| 806 {"var a = 3.14; return 3.14;", | 953 {"var a = 3.14; return 3.14;", |
| 807 1 * kPointerSize, | 954 1 * kPointerSize, |
| 808 1, | 955 1, |
| 809 7, | 956 8, |
| 810 { | 957 { |
| 958 B(StackCheck), // |
| 811 B(LdaConstant), U8(0), // | 959 B(LdaConstant), U8(0), // |
| 812 B(Star), R(0), // | 960 B(Star), R(0), // |
| 813 B(LdaConstant), U8(1), // | 961 B(LdaConstant), U8(1), // |
| 814 B(Return) // | 962 B(Return) // |
| 815 }, | 963 }, |
| 816 2, | 964 2, |
| 817 {3.14, 3.14}}, | 965 {3.14, 3.14}}, |
| 818 {"var a;" | 966 {"var a;" |
| 819 REPEAT_256(SPACE, " a = 1.414;") | 967 REPEAT_256(SPACE, " a = 1.414;") |
| 820 " a = 3.14;", | 968 " a = 3.14;", |
| 821 1 * kPointerSize, | 969 1 * kPointerSize, |
| 822 1, | 970 1, |
| 823 1031, | 971 1032, |
| 824 { | 972 { |
| 973 B(StackCheck), // |
| 825 REPEAT_256(COMMA, // | 974 REPEAT_256(COMMA, // |
| 826 B(LdaConstant), U8(wide_idx++), // | 975 B(LdaConstant), U8(wide_idx++), // |
| 827 B(Star), R(0)), // | 976 B(Star), R(0)), // |
| 828 B(LdaConstantWide), U16(wide_idx), // | 977 B(LdaConstantWide), U16(wide_idx), // |
| 829 B(Star), R(0), // | 978 B(Star), R(0), // |
| 830 B(LdaUndefined), // | 979 B(LdaUndefined), // |
| 831 B(Return), // | 980 B(Return), // |
| 832 }, | 981 }, |
| 833 257, | 982 257, |
| 834 {REPEAT_256(COMMA, 1.414), | 983 {REPEAT_256(COMMA, 1.414), |
| 835 3.14}} | 984 3.14}} |
| 836 }; | 985 }; |
| 986 // clang-format on |
| 987 |
| 837 for (size_t i = 0; i < arraysize(snippets); i++) { | 988 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 838 Handle<BytecodeArray> bytecode_array = | 989 Handle<BytecodeArray> bytecode_array = |
| 839 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 990 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 840 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 991 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 841 } | 992 } |
| 842 } | 993 } |
| 843 | 994 |
| 844 | 995 |
| 845 TEST(StringConstants) { | 996 TEST(StringConstants) { |
| 846 InitializedHandleScope handle_scope; | 997 InitializedHandleScope handle_scope; |
| 847 BytecodeGeneratorHelper helper; | 998 BytecodeGeneratorHelper helper; |
| 848 | 999 |
| 1000 // clang-format off |
| 849 ExpectedSnippet<const char*> snippets[] = { | 1001 ExpectedSnippet<const char*> snippets[] = { |
| 850 {"return \"This is a string\";", | 1002 {"return \"This is a string\";", |
| 851 0, | 1003 0, |
| 852 1, | 1004 1, |
| 853 3, | 1005 4, |
| 854 { | 1006 { |
| 1007 B(StackCheck), // |
| 855 B(LdaConstant), U8(0), // | 1008 B(LdaConstant), U8(0), // |
| 856 B(Return) // | 1009 B(Return) // |
| 857 }, | 1010 }, |
| 858 1, | 1011 1, |
| 859 {"This is a string"}}, | 1012 {"This is a string"}}, |
| 860 {"var a = \"First string\"; return \"Second string\";", | 1013 {"var a = \"First string\"; return \"Second string\";", |
| 861 1 * kPointerSize, | 1014 1 * kPointerSize, |
| 862 1, | 1015 1, |
| 863 7, | 1016 8, |
| 864 { | 1017 { |
| 1018 B(StackCheck), // |
| 865 B(LdaConstant), U8(0), // | 1019 B(LdaConstant), U8(0), // |
| 866 B(Star), R(0), // | 1020 B(Star), R(0), // |
| 867 B(LdaConstant), U8(1), // | 1021 B(LdaConstant), U8(1), // |
| 868 B(Return) // | 1022 B(Return) // |
| 869 }, | 1023 }, |
| 870 2, | 1024 2, |
| 871 {"First string", "Second string"}}, | 1025 {"First string", "Second string"}}, |
| 872 {"var a = \"Same string\"; return \"Same string\";", | 1026 {"var a = \"Same string\"; return \"Same string\";", |
| 873 1 * kPointerSize, | 1027 1 * kPointerSize, |
| 874 1, | 1028 1, |
| 875 7, | 1029 8, |
| 876 { | 1030 { |
| 1031 B(StackCheck), // |
| 877 B(LdaConstant), U8(0), // | 1032 B(LdaConstant), U8(0), // |
| 878 B(Star), R(0), // | 1033 B(Star), R(0), // |
| 879 B(LdaConstant), U8(0), // | 1034 B(LdaConstant), U8(0), // |
| 880 B(Return) // | 1035 B(Return) // |
| 881 }, | 1036 }, |
| 882 1, | 1037 1, |
| 883 {"Same string"}}}; | 1038 {"Same string"}} |
| 1039 }; |
| 1040 // clang-format on |
| 884 | 1041 |
| 885 for (size_t i = 0; i < arraysize(snippets); i++) { | 1042 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 886 Handle<BytecodeArray> bytecode_array = | 1043 Handle<BytecodeArray> bytecode_array = |
| 887 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1044 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 888 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1045 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 889 } | 1046 } |
| 890 } | 1047 } |
| 891 | 1048 |
| 892 | 1049 |
| 893 TEST(PropertyLoads) { | 1050 TEST(PropertyLoads) { |
| 894 InitializedHandleScope handle_scope; | 1051 InitializedHandleScope handle_scope; |
| 895 BytecodeGeneratorHelper helper; | 1052 BytecodeGeneratorHelper helper; |
| 896 Zone zone; | 1053 Zone zone; |
| 897 | 1054 |
| 898 FeedbackVectorSpec feedback_spec(&zone); | 1055 FeedbackVectorSpec feedback_spec(&zone); |
| 899 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 1056 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 900 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 1057 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 901 | 1058 |
| 902 Handle<i::TypeFeedbackVector> vector = | 1059 Handle<i::TypeFeedbackVector> vector = |
| 903 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1060 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 904 | 1061 |
| 905 // These are a hack used by the LoadICXXXWide tests below. | 1062 // These are a hack used by the LoadICXXXWide tests below. |
| 906 int wide_idx_1 = vector->GetIndex(slot1) - 2; | 1063 int wide_idx_1 = vector->GetIndex(slot1) - 2; |
| 907 int wide_idx_2 = vector->GetIndex(slot1) - 2; | 1064 int wide_idx_2 = vector->GetIndex(slot1) - 2; |
| 908 int wide_idx_3 = vector->GetIndex(slot1) - 2; | 1065 int wide_idx_3 = vector->GetIndex(slot1) - 2; |
| 909 int wide_idx_4 = vector->GetIndex(slot1) - 2; | 1066 int wide_idx_4 = vector->GetIndex(slot1) - 2; |
| 910 | 1067 |
| 1068 // clang-format off |
| 911 ExpectedSnippet<const char*> snippets[] = { | 1069 ExpectedSnippet<const char*> snippets[] = { |
| 912 {"function f(a) { return a.name; }\nf({name : \"test\"})", | 1070 {"function f(a) { return a.name; }\nf({name : \"test\"})", |
| 913 1 * kPointerSize, | 1071 1 * kPointerSize, |
| 914 2, | 1072 2, |
| 915 9, | 1073 10, |
| 916 { | 1074 { |
| 1075 B(StackCheck), // |
| 917 B(Ldar), A(1, 2), // | 1076 B(Ldar), A(1, 2), // |
| 918 B(Star), R(0), // | 1077 B(Star), R(0), // |
| 919 B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), // | 1078 B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), // |
| 920 B(Return), // | 1079 B(Return), // |
| 921 }, | 1080 }, |
| 922 1, | 1081 1, |
| 923 {"name"}}, | 1082 {"name"}}, |
| 924 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})", | 1083 {"function f(a) { return a[\"key\"]; }\nf({key : \"test\"})", |
| 925 1 * kPointerSize, | 1084 1 * kPointerSize, |
| 926 2, | 1085 2, |
| 927 9, | 1086 10, |
| 928 { | 1087 { |
| 1088 B(StackCheck), // |
| 929 B(Ldar), A(1, 2), // | 1089 B(Ldar), A(1, 2), // |
| 930 B(Star), R(0), // | 1090 B(Star), R(0), // |
| 931 B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), // | 1091 B(LoadICSloppy), R(0), U8(0), U8(vector->GetIndex(slot1)), // |
| 932 B(Return) // | 1092 B(Return) // |
| 933 }, | 1093 }, |
| 934 1, | 1094 1, |
| 935 {"key"}}, | 1095 {"key"}}, |
| 936 {"function f(a) { return a[100]; }\nf({100 : \"test\"})", | 1096 {"function f(a) { return a[100]; }\nf({100 : \"test\"})", |
| 937 1 * kPointerSize, | 1097 1 * kPointerSize, |
| 938 2, | 1098 2, |
| 939 10, | 1099 11, |
| 940 { | 1100 { |
| 1101 B(StackCheck), // |
| 941 B(Ldar), A(1, 2), // | 1102 B(Ldar), A(1, 2), // |
| 942 B(Star), R(0), // | 1103 B(Star), R(0), // |
| 943 B(LdaSmi8), U8(100), // | 1104 B(LdaSmi8), U8(100), // |
| 944 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // | 1105 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
| 945 B(Return) // | 1106 B(Return) // |
| 946 }, | 1107 }, |
| 947 0}, | 1108 0}, |
| 948 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")", | 1109 {"function f(a, b) { return a[b]; }\nf({arg : \"test\"}, \"arg\")", |
| 949 1 * kPointerSize, | 1110 1 * kPointerSize, |
| 950 3, | 1111 3, |
| 951 10, | 1112 11, |
| 952 { | 1113 { |
| 1114 B(StackCheck), // |
| 953 B(Ldar), A(1, 3), // | 1115 B(Ldar), A(1, 3), // |
| 954 B(Star), R(0), // | 1116 B(Star), R(0), // |
| 955 B(Ldar), A(1, 2), // | 1117 B(Ldar), A(1, 2), // |
| 956 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // | 1118 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
| 957 B(Return) // | 1119 B(Return) // |
| 958 }, | 1120 }, |
| 959 0}, | 1121 0}, |
| 960 {"function f(a) { var b = a.name; return a[-124]; }\n" | 1122 {"function f(a) { var b = a.name; return a[-124]; }\n" |
| 961 "f({\"-124\" : \"test\", name : 123 })", | 1123 "f({\"-124\" : \"test\", name : 123 })", |
| 962 2 * kPointerSize, | 1124 2 * kPointerSize, |
| 963 2, | 1125 2, |
| 964 20, | 1126 21, |
| 965 { | 1127 { |
| 1128 B(StackCheck), // |
| 966 B(Ldar), A(1, 2), // | 1129 B(Ldar), A(1, 2), // |
| 967 B(Star), R(1), // | 1130 B(Star), R(1), // |
| 968 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot1)), // | 1131 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot1)), // |
| 969 B(Star), R(0), // | 1132 B(Star), R(0), // |
| 970 B(Ldar), A(1, 2), // | 1133 B(Ldar), A(1, 2), // |
| 971 B(Star), R(1), // | 1134 B(Star), R(1), // |
| 972 B(LdaSmi8), U8(-124), // | 1135 B(LdaSmi8), U8(-124), // |
| 973 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // | 1136 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot2)), // |
| 974 B(Return), // | 1137 B(Return), // |
| 975 }, | 1138 }, |
| 976 1, | 1139 1, |
| 977 {"name"}}, | 1140 {"name"}}, |
| 978 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})", | 1141 {"function f(a) { \"use strict\"; return a.name; }\nf({name : \"test\"})", |
| 979 1 * kPointerSize, | 1142 1 * kPointerSize, |
| 980 2, | 1143 2, |
| 981 9, | 1144 10, |
| 982 { | 1145 { |
| 1146 B(StackCheck), // |
| 983 B(Ldar), A(1, 2), // | 1147 B(Ldar), A(1, 2), // |
| 984 B(Star), R(0), // | 1148 B(Star), R(0), // |
| 985 B(LoadICStrict), R(0), U8(0), U8(vector->GetIndex(slot1)), // | 1149 B(LoadICStrict), R(0), U8(0), U8(vector->GetIndex(slot1)), // |
| 986 B(Return), // | 1150 B(Return), // |
| 987 }, | 1151 }, |
| 988 1, | 1152 1, |
| 989 {"name"}}, | 1153 {"name"}}, |
| 990 {"function f(a, b) { \"use strict\"; return a[b]; }\n" | 1154 {"function f(a, b) { \"use strict\"; return a[b]; }\n" |
| 991 "f({arg : \"test\"}, \"arg\")", | 1155 "f({arg : \"test\"}, \"arg\")", |
| 992 1 * kPointerSize, | 1156 1 * kPointerSize, |
| 993 3, | 1157 3, |
| 994 10, | 1158 11, |
| 995 { | 1159 { |
| 1160 B(StackCheck), // |
| 996 B(Ldar), A(1, 3), // | 1161 B(Ldar), A(1, 3), // |
| 997 B(Star), R(0), // | 1162 B(Star), R(0), // |
| 998 B(Ldar), A(2, 3), // | 1163 B(Ldar), A(2, 3), // |
| 999 B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), // | 1164 B(KeyedLoadICStrict), R(0), U8(vector->GetIndex(slot1)), // |
| 1000 B(Return), // | 1165 B(Return), // |
| 1001 }, | 1166 }, |
| 1002 0}, | 1167 0}, |
| 1003 {"function f(a) {\n" | 1168 {"function f(a) {\n" |
| 1004 " var b;\n" | 1169 " var b;\n" |
| 1005 "b = a.name;" | 1170 "b = a.name;" |
| 1006 REPEAT_127(SPACE, " b = a.name; ") | 1171 REPEAT_127(SPACE, " b = a.name; ") |
| 1007 " return a.name; }\n" | 1172 " return a.name; }\n" |
| 1008 "f({name : \"test\"})\n", | 1173 "f({name : \"test\"})\n", |
| 1009 2 * kPointerSize, | 1174 2 * kPointerSize, |
| 1010 2, | 1175 2, |
| 1011 1291, | 1176 1292, |
| 1012 { | 1177 { |
| 1178 B(StackCheck), // |
| 1013 B(Ldar), A(1, 2), // | 1179 B(Ldar), A(1, 2), // |
| 1014 B(Star), R(1), // | 1180 B(Star), R(1), // |
| 1015 B(LoadICSloppy), R(1), U8(0), U8(wide_idx_1 += 2), // | 1181 B(LoadICSloppy), R(1), U8(0), U8(wide_idx_1 += 2), // |
| 1016 B(Star), R(0), // | 1182 B(Star), R(0), // |
| 1017 REPEAT_127(COMMA, // | 1183 REPEAT_127(COMMA, // |
| 1018 B(Ldar), A(1, 2), // | 1184 B(Ldar), A(1, 2), // |
| 1019 B(Star), R(1), // | 1185 B(Star), R(1), // |
| 1020 B(LoadICSloppy), R(1), U8(0), // | 1186 B(LoadICSloppy), R(1), U8(0), // |
| 1021 U8((wide_idx_1 += 2)), // | 1187 U8((wide_idx_1 += 2)), // |
| 1022 B(Star), R(0)), // | 1188 B(Star), R(0)), // |
| 1023 B(Ldar), A(1, 2), // | 1189 B(Ldar), A(1, 2), // |
| 1024 B(Star), R(1), // | 1190 B(Star), R(1), // |
| 1025 B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx_1 + 2), // | 1191 B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx_1 + 2), // |
| 1026 B(Return), // | 1192 B(Return), // |
| 1027 }, | 1193 }, |
| 1028 1, | 1194 1, |
| 1029 {"name"}}, | 1195 {"name"}}, |
| 1030 {"function f(a) {\n" | 1196 {"function f(a) {\n" |
| 1031 " 'use strict'; var b;\n" | 1197 " 'use strict'; var b;\n" |
| 1032 " b = a.name;\n" | 1198 " b = a.name;\n" |
| 1033 REPEAT_127(SPACE, " b = a.name; ") | 1199 REPEAT_127(SPACE, " b = a.name; ") |
| 1034 " return a.name; }\n" | 1200 " return a.name; }\n" |
| 1035 "f({name : \"test\"})\n", | 1201 "f({name : \"test\"})\n", |
| 1036 2 * kPointerSize, | 1202 2 * kPointerSize, |
| 1037 2, | 1203 2, |
| 1038 1291, | 1204 1292, |
| 1039 { | 1205 { |
| 1206 B(StackCheck), // |
| 1040 B(Ldar), A(1, 2), // | 1207 B(Ldar), A(1, 2), // |
| 1041 B(Star), R(1), // | 1208 B(Star), R(1), // |
| 1042 B(LoadICStrict), R(1), U8(0), U8((wide_idx_2 += 2)), // | 1209 B(LoadICStrict), R(1), U8(0), U8((wide_idx_2 += 2)), // |
| 1043 B(Star), R(0), // | 1210 B(Star), R(0), // |
| 1044 REPEAT_127(COMMA, // | 1211 REPEAT_127(COMMA, // |
| 1045 B(Ldar), A(1, 2), // | 1212 B(Ldar), A(1, 2), // |
| 1046 B(Star), R(1), // | 1213 B(Star), R(1), // |
| 1047 B(LoadICStrict), R(1), U8(0), // | 1214 B(LoadICStrict), R(1), U8(0), // |
| 1048 U8((wide_idx_2 += 2)), // | 1215 U8((wide_idx_2 += 2)), // |
| 1049 B(Star), R(0)), // | 1216 B(Star), R(0)), // |
| 1050 B(Ldar), A(1, 2), // | 1217 B(Ldar), A(1, 2), // |
| 1051 B(Star), R(1), // | 1218 B(Star), R(1), // |
| 1052 B(LoadICStrictWide), R(1), U16(0), U16(wide_idx_2 + 2), // | 1219 B(LoadICStrictWide), R(1), U16(0), U16(wide_idx_2 + 2), // |
| 1053 B(Return), // | 1220 B(Return), // |
| 1054 }, | 1221 }, |
| 1055 1, | 1222 1, |
| 1056 {"name"}}, | 1223 {"name"}}, |
| 1057 {"function f(a, b) {\n" | 1224 {"function f(a, b) {\n" |
| 1058 " var c;\n" | 1225 " var c;\n" |
| 1059 " c = a[b];" | 1226 " c = a[b];" |
| 1060 REPEAT_127(SPACE, " c = a[b]; ") | 1227 REPEAT_127(SPACE, " c = a[b]; ") |
| 1061 " return a[b]; }\n" | 1228 " return a[b]; }\n" |
| 1062 "f({name : \"test\"}, \"name\")\n", | 1229 "f({name : \"test\"}, \"name\")\n", |
| 1063 2 * kPointerSize, | 1230 2 * kPointerSize, |
| 1064 3, | 1231 3, |
| 1065 1419, | 1232 1420, |
| 1066 { | 1233 { |
| 1234 B(StackCheck), // |
| 1067 B(Ldar), A(1, 3), // | 1235 B(Ldar), A(1, 3), // |
| 1068 B(Star), R(1), // | 1236 B(Star), R(1), // |
| 1069 B(Ldar), A(2, 3), // | 1237 B(Ldar), A(2, 3), // |
| 1070 B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), // | 1238 B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), // |
| 1071 B(Star), R(0), // | 1239 B(Star), R(0), // |
| 1072 REPEAT_127(COMMA, // | 1240 REPEAT_127(COMMA, // |
| 1073 B(Ldar), A(1, 3), // | 1241 B(Ldar), A(1, 3), // |
| 1074 B(Star), R(1), // | 1242 B(Star), R(1), // |
| 1075 B(Ldar), A(2, 3), // | 1243 B(Ldar), A(2, 3), // |
| 1076 B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), // | 1244 B(KeyedLoadICSloppy), R(1), U8((wide_idx_3 += 2)), // |
| 1077 B(Star), R(0)), // | 1245 B(Star), R(0)), // |
| 1078 B(Ldar), A(1, 3), // | 1246 B(Ldar), A(1, 3), // |
| 1079 B(Star), R(1), // | 1247 B(Star), R(1), // |
| 1080 B(Ldar), A(2, 3), // | 1248 B(Ldar), A(2, 3), // |
| 1081 B(KeyedLoadICSloppyWide), R(1), U16(wide_idx_3 + 2), // | 1249 B(KeyedLoadICSloppyWide), R(1), U16(wide_idx_3 + 2), // |
| 1082 B(Return), // | 1250 B(Return), // |
| 1083 }}, | 1251 }}, |
| 1084 {"function f(a, b) {\n" | 1252 {"function f(a, b) {\n" |
| 1085 " 'use strict'; var c;\n" | 1253 " 'use strict'; var c;\n" |
| 1086 " c = a[b];" | 1254 " c = a[b];" |
| 1087 REPEAT_127(SPACE, " c = a[b]; ") | 1255 REPEAT_127(SPACE, " c = a[b]; ") |
| 1088 " return a[b]; }\n" | 1256 " return a[b]; }\n" |
| 1089 "f({name : \"test\"}, \"name\")\n", | 1257 "f({name : \"test\"}, \"name\")\n", |
| 1090 2 * kPointerSize, | 1258 2 * kPointerSize, |
| 1091 3, | 1259 3, |
| 1092 1419, | 1260 1420, |
| 1093 { | 1261 { |
| 1262 B(StackCheck), // |
| 1094 B(Ldar), A(1, 3), // | 1263 B(Ldar), A(1, 3), // |
| 1095 B(Star), R(1), // | 1264 B(Star), R(1), // |
| 1096 B(Ldar), A(2, 3), // | 1265 B(Ldar), A(2, 3), // |
| 1097 B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), // | 1266 B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), // |
| 1098 B(Star), R(0), // | 1267 B(Star), R(0), // |
| 1099 REPEAT_127(COMMA, // | 1268 REPEAT_127(COMMA, // |
| 1100 B(Ldar), A(1, 3), // | 1269 B(Ldar), A(1, 3), // |
| 1101 B(Star), R(1), // | 1270 B(Star), R(1), // |
| 1102 B(Ldar), A(2, 3), // | 1271 B(Ldar), A(2, 3), // |
| 1103 B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), // | 1272 B(KeyedLoadICStrict), R(1), U8((wide_idx_4 += 2)), // |
| 1104 B(Star), R(0)), // | 1273 B(Star), R(0)), // |
| 1105 B(Ldar), A(1, 3), // | 1274 B(Ldar), A(1, 3), // |
| 1106 B(Star), R(1), // | 1275 B(Star), R(1), // |
| 1107 B(Ldar), A(2, 3), // | 1276 B(Ldar), A(2, 3), // |
| 1108 B(KeyedLoadICStrictWide), R(1), U16(wide_idx_4 + 2), // | 1277 B(KeyedLoadICStrictWide), R(1), U16(wide_idx_4 + 2), // |
| 1109 B(Return), // | 1278 B(Return), // |
| 1110 }}, | 1279 }}, |
| 1111 }; | 1280 }; |
| 1281 // clang-format on |
| 1282 |
| 1112 for (size_t i = 0; i < arraysize(snippets); i++) { | 1283 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1113 Handle<BytecodeArray> bytecode_array = | 1284 Handle<BytecodeArray> bytecode_array = |
| 1114 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1285 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
| 1115 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1286 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1116 } | 1287 } |
| 1117 } | 1288 } |
| 1118 | 1289 |
| 1119 | 1290 |
| 1120 TEST(PropertyStores) { | 1291 TEST(PropertyStores) { |
| 1121 InitializedHandleScope handle_scope; | 1292 InitializedHandleScope handle_scope; |
| 1122 BytecodeGeneratorHelper helper; | 1293 BytecodeGeneratorHelper helper; |
| 1123 Zone zone; | 1294 Zone zone; |
| 1124 | 1295 |
| 1125 FeedbackVectorSpec feedback_spec(&zone); | 1296 FeedbackVectorSpec feedback_spec(&zone); |
| 1126 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); | 1297 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); |
| 1127 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); | 1298 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
| 1128 | 1299 |
| 1129 Handle<i::TypeFeedbackVector> vector = | 1300 Handle<i::TypeFeedbackVector> vector = |
| 1130 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1301 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1131 | 1302 |
| 1132 // These are a hack used by the StoreICXXXWide tests below. | 1303 // These are a hack used by the StoreICXXXWide tests below. |
| 1133 int wide_idx_1 = vector->GetIndex(slot1) - 2; | 1304 int wide_idx_1 = vector->GetIndex(slot1) - 2; |
| 1134 int wide_idx_2 = vector->GetIndex(slot1) - 2; | 1305 int wide_idx_2 = vector->GetIndex(slot1) - 2; |
| 1135 int wide_idx_3 = vector->GetIndex(slot1) - 2; | 1306 int wide_idx_3 = vector->GetIndex(slot1) - 2; |
| 1136 int wide_idx_4 = vector->GetIndex(slot1) - 2; | 1307 int wide_idx_4 = vector->GetIndex(slot1) - 2; |
| 1137 | 1308 |
| 1309 // clang-format off |
| 1138 ExpectedSnippet<const char*> snippets[] = { | 1310 ExpectedSnippet<const char*> snippets[] = { |
| 1139 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", | 1311 {"function f(a) { a.name = \"val\"; }\nf({name : \"test\"})", |
| 1140 kPointerSize, | 1312 kPointerSize, |
| 1141 2, | 1313 2, |
| 1142 12, | 1314 13, |
| 1143 { | 1315 { |
| 1316 B(StackCheck), // |
| 1144 B(Ldar), A(1, 2), // | 1317 B(Ldar), A(1, 2), // |
| 1145 B(Star), R(0), // | 1318 B(Star), R(0), // |
| 1146 B(LdaConstant), U8(0), // | 1319 B(LdaConstant), U8(0), // |
| 1147 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), // | 1320 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), // |
| 1148 B(LdaUndefined), // | 1321 B(LdaUndefined), // |
| 1149 B(Return), // | 1322 B(Return), // |
| 1150 }, | 1323 }, |
| 1151 2, | 1324 2, |
| 1152 {"val", "name"}}, | 1325 {"val", "name"}}, |
| 1153 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})", | 1326 {"function f(a) { a[\"key\"] = \"val\"; }\nf({key : \"test\"})", |
| 1154 kPointerSize, | 1327 kPointerSize, |
| 1155 2, | 1328 2, |
| 1156 12, | 1329 13, |
| 1157 { | 1330 { |
| 1331 B(StackCheck), // |
| 1158 B(Ldar), A(1, 2), // | 1332 B(Ldar), A(1, 2), // |
| 1159 B(Star), R(0), // | 1333 B(Star), R(0), // |
| 1160 B(LdaConstant), U8(0), // | 1334 B(LdaConstant), U8(0), // |
| 1161 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), // | 1335 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), // |
| 1162 B(LdaUndefined), // | 1336 B(LdaUndefined), // |
| 1163 B(Return), // | 1337 B(Return), // |
| 1164 }, | 1338 }, |
| 1165 2, | 1339 2, |
| 1166 {"val", "key"}}, | 1340 {"val", "key"}}, |
| 1167 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})", | 1341 {"function f(a) { a[100] = \"val\"; }\nf({100 : \"test\"})", |
| 1168 2 * kPointerSize, | 1342 2 * kPointerSize, |
| 1169 2, | 1343 2, |
| 1170 16, | 1344 17, |
| 1171 { | 1345 { |
| 1346 B(StackCheck), // |
| 1172 B(Ldar), A(1, 2), // | 1347 B(Ldar), A(1, 2), // |
| 1173 B(Star), R(0), // | 1348 B(Star), R(0), // |
| 1174 B(LdaSmi8), U8(100), // | 1349 B(LdaSmi8), U8(100), // |
| 1175 B(Star), R(1), // | 1350 B(Star), R(1), // |
| 1176 B(LdaConstant), U8(0), // | 1351 B(LdaConstant), U8(0), // |
| 1177 B(KeyedStoreICSloppy), R(0), R(1), // | 1352 B(KeyedStoreICSloppy), R(0), R(1), // |
| 1178 U8(vector->GetIndex(slot1)), // | 1353 U8(vector->GetIndex(slot1)), // |
| 1179 B(LdaUndefined), // | 1354 B(LdaUndefined), // |
| 1180 B(Return), // | 1355 B(Return), // |
| 1181 }, | 1356 }, |
| 1182 1, | 1357 1, |
| 1183 {"val"}}, | 1358 {"val"}}, |
| 1184 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")", | 1359 {"function f(a, b) { a[b] = \"val\"; }\nf({arg : \"test\"}, \"arg\")", |
| 1185 2 * kPointerSize, | 1360 2 * kPointerSize, |
| 1186 3, | 1361 3, |
| 1187 16, | 1362 17, |
| 1188 { | 1363 { |
| 1364 B(StackCheck), // |
| 1189 B(Ldar), A(1, 3), // | 1365 B(Ldar), A(1, 3), // |
| 1190 B(Star), R(0), // | 1366 B(Star), R(0), // |
| 1191 B(Ldar), A(2, 3), // | 1367 B(Ldar), A(2, 3), // |
| 1192 B(Star), R(1), // | 1368 B(Star), R(1), // |
| 1193 B(LdaConstant), U8(0), // | 1369 B(LdaConstant), U8(0), // |
| 1194 B(KeyedStoreICSloppy), R(0), R(1), // | 1370 B(KeyedStoreICSloppy), R(0), R(1), // |
| 1195 U8(vector->GetIndex(slot1)), // | 1371 U8(vector->GetIndex(slot1)), // |
| 1196 B(LdaUndefined), // | 1372 B(LdaUndefined), // |
| 1197 B(Return), // | 1373 B(Return), // |
| 1198 }, | 1374 }, |
| 1199 1, | 1375 1, |
| 1200 {"val"}}, | 1376 {"val"}}, |
| 1201 {"function f(a) { a.name = a[-124]; }\n" | 1377 {"function f(a) { a.name = a[-124]; }\n" |
| 1202 "f({\"-124\" : \"test\", name : 123 })", | 1378 "f({\"-124\" : \"test\", name : 123 })", |
| 1203 2 * kPointerSize, | 1379 2 * kPointerSize, |
| 1204 2, | 1380 2, |
| 1205 19, | 1381 20, |
| 1206 { | 1382 { |
| 1383 B(StackCheck), // |
| 1207 B(Ldar), A(1, 2), // | 1384 B(Ldar), A(1, 2), // |
| 1208 B(Star), R(0), // | 1385 B(Star), R(0), // |
| 1209 B(Ldar), A(1, 2), // | 1386 B(Ldar), A(1, 2), // |
| 1210 B(Star), R(1), // | 1387 B(Star), R(1), // |
| 1211 B(LdaSmi8), U8(-124), // | 1388 B(LdaSmi8), U8(-124), // |
| 1212 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // | 1389 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // |
| 1213 B(StoreICSloppy), R(0), U8(0), U8(vector->GetIndex(slot2)), // | 1390 B(StoreICSloppy), R(0), U8(0), U8(vector->GetIndex(slot2)), // |
| 1214 B(LdaUndefined), // | 1391 B(LdaUndefined), // |
| 1215 B(Return), // | 1392 B(Return), // |
| 1216 }, | 1393 }, |
| 1217 1, | 1394 1, |
| 1218 {"name"}}, | 1395 {"name"}}, |
| 1219 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n" | 1396 {"function f(a) { \"use strict\"; a.name = \"val\"; }\n" |
| 1220 "f({name : \"test\"})", | 1397 "f({name : \"test\"})", |
| 1221 kPointerSize, | 1398 kPointerSize, |
| 1222 2, | 1399 2, |
| 1223 12, | 1400 13, |
| 1224 { | 1401 { |
| 1402 B(StackCheck), // |
| 1225 B(Ldar), A(1, 2), // | 1403 B(Ldar), A(1, 2), // |
| 1226 B(Star), R(0), // | 1404 B(Star), R(0), // |
| 1227 B(LdaConstant), U8(0), // | 1405 B(LdaConstant), U8(0), // |
| 1228 B(StoreICStrict), R(0), U8(1), U8(vector->GetIndex(slot1)), // | 1406 B(StoreICStrict), R(0), U8(1), U8(vector->GetIndex(slot1)), // |
| 1229 B(LdaUndefined), // | 1407 B(LdaUndefined), // |
| 1230 B(Return), // | 1408 B(Return), // |
| 1231 }, | 1409 }, |
| 1232 2, | 1410 2, |
| 1233 {"val", "name"}}, | 1411 {"val", "name"}}, |
| 1234 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n" | 1412 {"function f(a, b) { \"use strict\"; a[b] = \"val\"; }\n" |
| 1235 "f({arg : \"test\"}, \"arg\")", | 1413 "f({arg : \"test\"}, \"arg\")", |
| 1236 2 * kPointerSize, | 1414 2 * kPointerSize, |
| 1237 3, | 1415 3, |
| 1238 16, | 1416 17, |
| 1239 { | 1417 { |
| 1418 B(StackCheck), // |
| 1240 B(Ldar), A(1, 3), // | 1419 B(Ldar), A(1, 3), // |
| 1241 B(Star), R(0), // | 1420 B(Star), R(0), // |
| 1242 B(Ldar), A(2, 3), // | 1421 B(Ldar), A(2, 3), // |
| 1243 B(Star), R(1), // | 1422 B(Star), R(1), // |
| 1244 B(LdaConstant), U8(0), // | 1423 B(LdaConstant), U8(0), // |
| 1245 B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // | 1424 B(KeyedStoreICStrict), R(0), R(1), U8(vector->GetIndex(slot1)), // |
| 1246 B(LdaUndefined), // | 1425 B(LdaUndefined), // |
| 1247 B(Return), // | 1426 B(Return), // |
| 1248 }, | 1427 }, |
| 1249 1, | 1428 1, |
| 1250 {"val"}}, | 1429 {"val"}}, |
| 1251 {"function f(a) {\n" | 1430 {"function f(a) {\n" |
| 1252 "a.name = 1;" | 1431 "a.name = 1;" |
| 1253 REPEAT_127(SPACE, " a.name = 1; ") | 1432 REPEAT_127(SPACE, " a.name = 1; ") |
| 1254 " a.name = 2; }\n" | 1433 " a.name = 2; }\n" |
| 1255 "f({name : \"test\"})\n", | 1434 "f({name : \"test\"})\n", |
| 1256 kPointerSize, | 1435 kPointerSize, |
| 1257 2, | 1436 2, |
| 1258 1294, | 1437 1295, |
| 1259 { | 1438 { |
| 1439 B(StackCheck), // |
| 1260 B(Ldar), A(1, 2), // | 1440 B(Ldar), A(1, 2), // |
| 1261 B(Star), R(0), // | 1441 B(Star), R(0), // |
| 1262 B(LdaSmi8), U8(1), // | 1442 B(LdaSmi8), U8(1), // |
| 1263 B(StoreICSloppy), R(0), U8(0), U8((wide_idx_1 += 2)), // | 1443 B(StoreICSloppy), R(0), U8(0), U8((wide_idx_1 += 2)), // |
| 1264 REPEAT_127(COMMA, // | 1444 REPEAT_127(COMMA, // |
| 1265 B(Ldar), A(1, 2), // | 1445 B(Ldar), A(1, 2), // |
| 1266 B(Star), R(0), // | 1446 B(Star), R(0), // |
| 1267 B(LdaSmi8), U8(1), // | 1447 B(LdaSmi8), U8(1), // |
| 1268 B(StoreICSloppy), R(0), U8(0), // | 1448 B(StoreICSloppy), R(0), U8(0), // |
| 1269 U8((wide_idx_1 += 2))), // | 1449 U8((wide_idx_1 += 2))), // |
| 1270 B(Ldar), A(1, 2), // | 1450 B(Ldar), A(1, 2), // |
| 1271 B(Star), R(0), // | 1451 B(Star), R(0), // |
| 1272 B(LdaSmi8), U8(2), // | 1452 B(LdaSmi8), U8(2), // |
| 1273 B(StoreICSloppyWide), R(0), U16(0), U16(wide_idx_1 + 2), // | 1453 B(StoreICSloppyWide), R(0), U16(0), U16(wide_idx_1 + 2), // |
| 1274 B(LdaUndefined), // | 1454 B(LdaUndefined), // |
| 1275 B(Return), // | 1455 B(Return), // |
| 1276 }, | 1456 }, |
| 1277 1, | 1457 1, |
| 1278 {"name"}}, | 1458 {"name"}}, |
| 1279 {"function f(a) {\n" | 1459 {"function f(a) {\n" |
| 1280 " 'use strict';\n" | 1460 " 'use strict';\n" |
| 1281 " a.name = 1;" | 1461 " a.name = 1;" |
| 1282 REPEAT_127(SPACE, " a.name = 1; ") | 1462 REPEAT_127(SPACE, " a.name = 1; ") |
| 1283 " a.name = 2; }\n" | 1463 " a.name = 2; }\n" |
| 1284 "f({name : \"test\"})\n", | 1464 "f({name : \"test\"})\n", |
| 1285 kPointerSize, | 1465 kPointerSize, |
| 1286 2, | 1466 2, |
| 1287 1294, | 1467 1295, |
| 1288 { | 1468 { |
| 1469 B(StackCheck), // |
| 1289 B(Ldar), A(1, 2), // | 1470 B(Ldar), A(1, 2), // |
| 1290 B(Star), R(0), // | 1471 B(Star), R(0), // |
| 1291 B(LdaSmi8), U8(1), // | 1472 B(LdaSmi8), U8(1), // |
| 1292 B(StoreICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // | 1473 B(StoreICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // |
| 1293 REPEAT_127(COMMA, // | 1474 REPEAT_127(COMMA, // |
| 1294 B(Ldar), A(1, 2), // | 1475 B(Ldar), A(1, 2), // |
| 1295 B(Star), R(0), // | 1476 B(Star), R(0), // |
| 1296 B(LdaSmi8), U8(1), // | 1477 B(LdaSmi8), U8(1), // |
| 1297 B(StoreICStrict), R(0), U8(0), // | 1478 B(StoreICStrict), R(0), U8(0), // |
| 1298 U8((wide_idx_2 += 2))), // | 1479 U8((wide_idx_2 += 2))), // |
| 1299 B(Ldar), A(1, 2), // | 1480 B(Ldar), A(1, 2), // |
| 1300 B(Star), R(0), // | 1481 B(Star), R(0), // |
| 1301 B(LdaSmi8), U8(2), // | 1482 B(LdaSmi8), U8(2), // |
| 1302 B(StoreICStrictWide), R(0), U16(0), U16(wide_idx_2 + 2), // | 1483 B(StoreICStrictWide), R(0), U16(0), U16(wide_idx_2 + 2), // |
| 1303 B(LdaUndefined), // | 1484 B(LdaUndefined), // |
| 1304 B(Return), // | 1485 B(Return), // |
| 1305 }, | 1486 }, |
| 1306 1, | 1487 1, |
| 1307 {"name"}}, | 1488 {"name"}}, |
| 1308 {"function f(a, b) {\n" | 1489 {"function f(a, b) {\n" |
| 1309 " a[b] = 1;" | 1490 " a[b] = 1;" |
| 1310 REPEAT_127(SPACE, " a[b] = 1; ") | 1491 REPEAT_127(SPACE, " a[b] = 1; ") |
| 1311 " a[b] = 2; }\n" | 1492 " a[b] = 2; }\n" |
| 1312 "f({name : \"test\"})\n", | 1493 "f({name : \"test\"})\n", |
| 1313 2 * kPointerSize, | 1494 2 * kPointerSize, |
| 1314 3, | 1495 3, |
| 1315 1809, | 1496 1810, |
| 1316 { | 1497 { |
| 1498 B(StackCheck), // |
| 1317 B(Ldar), A(1, 3), // | 1499 B(Ldar), A(1, 3), // |
| 1318 B(Star), R(0), // | 1500 B(Star), R(0), // |
| 1319 B(Ldar), A(2, 3), // | 1501 B(Ldar), A(2, 3), // |
| 1320 B(Star), R(1), // | 1502 B(Star), R(1), // |
| 1321 B(LdaSmi8), U8(1), // | 1503 B(LdaSmi8), U8(1), // |
| 1322 B(KeyedStoreICSloppy), R(0), R(1), U8(wide_idx_3 += 2), // | 1504 B(KeyedStoreICSloppy), R(0), R(1), U8(wide_idx_3 += 2), // |
| 1323 REPEAT_127(COMMA, // | 1505 REPEAT_127(COMMA, // |
| 1324 B(Ldar), A(1, 3), // | 1506 B(Ldar), A(1, 3), // |
| 1325 B(Star), R(0), // | 1507 B(Star), R(0), // |
| 1326 B(Ldar), A(2, 3), // | 1508 B(Ldar), A(2, 3), // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1338 B(Return), // | 1520 B(Return), // |
| 1339 }}, | 1521 }}, |
| 1340 {"function f(a, b) {\n" | 1522 {"function f(a, b) {\n" |
| 1341 " 'use strict';\n" | 1523 " 'use strict';\n" |
| 1342 " a[b] = 1;" | 1524 " a[b] = 1;" |
| 1343 REPEAT_127(SPACE, " a[b] = 1; ") | 1525 REPEAT_127(SPACE, " a[b] = 1; ") |
| 1344 " a[b] = 2; }\n" | 1526 " a[b] = 2; }\n" |
| 1345 "f({name : \"test\"})\n", | 1527 "f({name : \"test\"})\n", |
| 1346 2 * kPointerSize, | 1528 2 * kPointerSize, |
| 1347 3, | 1529 3, |
| 1348 1809, | 1530 1810, |
| 1349 { | 1531 { |
| 1532 B(StackCheck), // |
| 1350 B(Ldar), A(1, 3), // | 1533 B(Ldar), A(1, 3), // |
| 1351 B(Star), R(0), // | 1534 B(Star), R(0), // |
| 1352 B(Ldar), A(2, 3), // | 1535 B(Ldar), A(2, 3), // |
| 1353 B(Star), R(1), // | 1536 B(Star), R(1), // |
| 1354 B(LdaSmi8), U8(1), // | 1537 B(LdaSmi8), U8(1), // |
| 1355 B(KeyedStoreICStrict), R(0), R(1), U8(wide_idx_4 += 2), // | 1538 B(KeyedStoreICStrict), R(0), R(1), U8(wide_idx_4 += 2), // |
| 1356 REPEAT_127(COMMA, // | 1539 REPEAT_127(COMMA, // |
| 1357 B(Ldar), A(1, 3), // | 1540 B(Ldar), A(1, 3), // |
| 1358 B(Star), R(0), // | 1541 B(Star), R(0), // |
| 1359 B(Ldar), A(2, 3), // | 1542 B(Ldar), A(2, 3), // |
| 1360 B(Star), R(1), // | 1543 B(Star), R(1), // |
| 1361 B(LdaSmi8), U8(1), // | 1544 B(LdaSmi8), U8(1), // |
| 1362 B(KeyedStoreICStrict), R(0), R(1), // | 1545 B(KeyedStoreICStrict), R(0), R(1), // |
| 1363 U8((wide_idx_4 += 2))), // | 1546 U8((wide_idx_4 += 2))), // |
| 1364 B(Ldar), A(1, 3), // | 1547 B(Ldar), A(1, 3), // |
| 1365 B(Star), R(0), // | 1548 B(Star), R(0), // |
| 1366 B(Ldar), A(2, 3), // | 1549 B(Ldar), A(2, 3), // |
| 1367 B(Star), R(1), // | 1550 B(Star), R(1), // |
| 1368 B(LdaSmi8), U8(2), // | 1551 B(LdaSmi8), U8(2), // |
| 1369 B(KeyedStoreICStrictWide), R(0), R(1), U16(wide_idx_4 + 2), // | 1552 B(KeyedStoreICStrictWide), R(0), R(1), U16(wide_idx_4 + 2), // |
| 1370 B(LdaUndefined), // | 1553 B(LdaUndefined), // |
| 1371 B(Return), // | 1554 B(Return), // |
| 1372 }}}; | 1555 }} |
| 1556 }; |
| 1557 // clang-format on |
| 1558 |
| 1373 for (size_t i = 0; i < arraysize(snippets); i++) { | 1559 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1374 Handle<BytecodeArray> bytecode_array = | 1560 Handle<BytecodeArray> bytecode_array = |
| 1375 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1561 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
| 1376 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1562 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1377 } | 1563 } |
| 1378 } | 1564 } |
| 1379 | 1565 |
| 1380 | 1566 |
| 1381 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" | 1567 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" |
| 1382 | 1568 |
| 1383 | 1569 |
| 1384 TEST(PropertyCall) { | 1570 TEST(PropertyCall) { |
| 1385 InitializedHandleScope handle_scope; | 1571 InitializedHandleScope handle_scope; |
| 1386 BytecodeGeneratorHelper helper; | 1572 BytecodeGeneratorHelper helper; |
| 1387 Zone zone; | 1573 Zone zone; |
| 1388 | 1574 |
| 1389 FeedbackVectorSpec feedback_spec(&zone); | 1575 FeedbackVectorSpec feedback_spec(&zone); |
| 1390 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); | 1576 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
| 1391 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 1577 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 1392 | 1578 |
| 1393 Handle<i::TypeFeedbackVector> vector = | 1579 Handle<i::TypeFeedbackVector> vector = |
| 1394 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1580 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1395 | 1581 |
| 1396 // These are a hack used by the CallWide test below. | 1582 // These are a hack used by the CallWide test below. |
| 1397 int wide_idx = vector->GetIndex(slot1) - 2; | 1583 int wide_idx = vector->GetIndex(slot1) - 2; |
| 1398 | 1584 |
| 1585 // clang-format off |
| 1399 ExpectedSnippet<const char*> snippets[] = { | 1586 ExpectedSnippet<const char*> snippets[] = { |
| 1400 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", | 1587 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", |
| 1401 2 * kPointerSize, | 1588 2 * kPointerSize, |
| 1402 2, | 1589 2, |
| 1403 16, | 1590 17, |
| 1404 { | 1591 { |
| 1592 B(StackCheck), // |
| 1405 B(Ldar), A(1, 2), // | 1593 B(Ldar), A(1, 2), // |
| 1406 B(Star), R(1), // | 1594 B(Star), R(1), // |
| 1407 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1595 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
| 1408 B(Star), R(0), // | 1596 B(Star), R(0), // |
| 1409 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 1597 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 1410 B(Return), // | 1598 B(Return), // |
| 1411 }, | 1599 }, |
| 1412 1, | 1600 1, |
| 1413 {"func"}}, | 1601 {"func"}}, |
| 1414 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", | 1602 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", |
| 1415 4 * kPointerSize, | 1603 4 * kPointerSize, |
| 1416 4, | 1604 4, |
| 1417 24, | 1605 25, |
| 1418 { | 1606 { |
| 1607 B(StackCheck), // |
| 1419 B(Ldar), A(1, 4), // | 1608 B(Ldar), A(1, 4), // |
| 1420 B(Star), R(1), // | 1609 B(Star), R(1), // |
| 1421 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1610 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
| 1422 B(Star), R(0), // | 1611 B(Star), R(0), // |
| 1423 B(Ldar), A(2, 4), // | 1612 B(Ldar), A(2, 4), // |
| 1424 B(Star), R(2), // | 1613 B(Star), R(2), // |
| 1425 B(Ldar), A(3, 4), // | 1614 B(Ldar), A(3, 4), // |
| 1426 B(Star), R(3), // | 1615 B(Star), R(3), // |
| 1427 B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), // | 1616 B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), // |
| 1428 B(Return) // | 1617 B(Return) // |
| 1429 }, | 1618 }, |
| 1430 1, | 1619 1, |
| 1431 {"func"}}, | 1620 {"func"}}, |
| 1432 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", | 1621 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", |
| 1433 4 * kPointerSize, | 1622 4 * kPointerSize, |
| 1434 3, | 1623 3, |
| 1435 30, | 1624 31, |
| 1436 { | 1625 { |
| 1626 B(StackCheck), // |
| 1437 B(Ldar), A(1, 3), // | 1627 B(Ldar), A(1, 3), // |
| 1438 B(Star), R(1), // | 1628 B(Star), R(1), // |
| 1439 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1629 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
| 1440 B(Star), R(0), // | 1630 B(Star), R(0), // |
| 1441 B(Ldar), A(2, 3), // | 1631 B(Ldar), A(2, 3), // |
| 1442 B(Star), R(3), // | 1632 B(Star), R(3), // |
| 1443 B(Ldar), A(2, 3), // | 1633 B(Ldar), A(2, 3), // |
| 1444 B(Add), R(3), // | 1634 B(Add), R(3), // |
| 1445 B(Star), R(2), // | 1635 B(Star), R(2), // |
| 1446 B(Ldar), A(2, 3), // | 1636 B(Ldar), A(2, 3), // |
| 1447 B(Star), R(3), // | 1637 B(Star), R(3), // |
| 1448 B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), // | 1638 B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), // |
| 1449 B(Return), // | 1639 B(Return), // |
| 1450 }, | 1640 }, |
| 1451 1, | 1641 1, |
| 1452 {"func"}}, | 1642 {"func"}}, |
| 1453 {"function f(a) {\n" | 1643 {"function f(a) {\n" |
| 1454 " a.func;\n" REPEAT_127( | 1644 " a.func;\n" REPEAT_127( |
| 1455 SPACE, " a.func;\n") " return a.func(); }\nf(" FUNC_ARG ")", | 1645 SPACE, " a.func;\n") " return a.func(); }\nf(" FUNC_ARG ")", |
| 1456 2 * kPointerSize, | 1646 2 * kPointerSize, |
| 1457 2, | 1647 2, |
| 1458 1046, | 1648 1047, |
| 1459 { | 1649 { |
| 1650 B(StackCheck), // |
| 1460 B(Ldar), A(1, 2), // | 1651 B(Ldar), A(1, 2), // |
| 1461 B(Star), R(0), // | 1652 B(Star), R(0), // |
| 1462 B(LoadICSloppy), R(0), U8(0), U8(wide_idx += 2), // | 1653 B(LoadICSloppy), R(0), U8(0), U8(wide_idx += 2), // |
| 1463 REPEAT_127(COMMA, // | 1654 REPEAT_127(COMMA, // |
| 1464 B(Ldar), A(1, 2), // | 1655 B(Ldar), A(1, 2), // |
| 1465 B(Star), R(0), // | 1656 B(Star), R(0), // |
| 1466 B(LoadICSloppy), R(0), U8(0), U8((wide_idx += 2))), // | 1657 B(LoadICSloppy), R(0), U8(0), U8((wide_idx += 2))), // |
| 1467 B(Ldar), A(1, 2), // | 1658 B(Ldar), A(1, 2), // |
| 1468 B(Star), R(1), // | 1659 B(Star), R(1), // |
| 1469 B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), // | 1660 B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), // |
| 1470 B(Star), R(0), // | 1661 B(Star), R(0), // |
| 1471 B(CallWide), R16(0), R16(1), U16(1), U16(wide_idx + 2), // | 1662 B(CallWide), R16(0), R16(1), U16(1), U16(wide_idx + 2), // |
| 1472 B(Return), // | 1663 B(Return), // |
| 1473 }, | 1664 }, |
| 1474 1, | 1665 1, |
| 1475 {"func"}}, | 1666 {"func"}}, |
| 1476 }; | 1667 }; |
| 1668 // clang-format on |
| 1669 |
| 1477 for (size_t i = 0; i < arraysize(snippets); i++) { | 1670 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1478 Handle<BytecodeArray> bytecode_array = | 1671 Handle<BytecodeArray> bytecode_array = |
| 1479 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1672 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
| 1480 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1673 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1481 } | 1674 } |
| 1482 } | 1675 } |
| 1483 | 1676 |
| 1484 | 1677 |
| 1485 TEST(LoadGlobal) { | 1678 TEST(LoadGlobal) { |
| 1486 InitializedHandleScope handle_scope; | 1679 InitializedHandleScope handle_scope; |
| 1487 BytecodeGeneratorHelper helper; | 1680 BytecodeGeneratorHelper helper; |
| 1488 Zone zone; | 1681 Zone zone; |
| 1489 | 1682 |
| 1490 FeedbackVectorSpec feedback_spec(&zone); | 1683 FeedbackVectorSpec feedback_spec(&zone); |
| 1491 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 1684 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 1492 | 1685 |
| 1493 Handle<i::TypeFeedbackVector> vector = | 1686 Handle<i::TypeFeedbackVector> vector = |
| 1494 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1687 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1495 | 1688 |
| 1496 // These are a hack used by the LdaGlobalXXXWide tests below. | 1689 // These are a hack used by the LdaGlobalXXXWide tests below. |
| 1497 int wide_idx_1 = vector->GetIndex(slot) - 2; | 1690 int wide_idx_1 = vector->GetIndex(slot) - 2; |
| 1498 int wide_idx_2 = vector->GetIndex(slot) - 2; | 1691 int wide_idx_2 = vector->GetIndex(slot) - 2; |
| 1499 | 1692 |
| 1693 // clang-format off |
| 1500 ExpectedSnippet<const char*> snippets[] = { | 1694 ExpectedSnippet<const char*> snippets[] = { |
| 1501 {"var a = 1;\nfunction f() { return a; }\nf()", | 1695 {"var a = 1;\nfunction f() { return a; }\nf()", |
| 1502 0, | 1696 0, |
| 1503 1, | 1697 1, |
| 1504 4, | 1698 5, |
| 1505 { | 1699 { |
| 1700 B(StackCheck), // |
| 1506 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1701 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1507 B(Return) // | 1702 B(Return) // |
| 1508 }, | 1703 }, |
| 1509 1, | 1704 1, |
| 1510 {"a"}}, | 1705 {"a"}}, |
| 1511 {"function t() { }\nfunction f() { return t; }\nf()", | 1706 {"function t() { }\nfunction f() { return t; }\nf()", |
| 1512 0, | 1707 0, |
| 1513 1, | 1708 1, |
| 1514 4, | 1709 5, |
| 1515 { | 1710 { |
| 1711 B(StackCheck), // |
| 1516 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1712 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1517 B(Return) // | 1713 B(Return) // |
| 1518 }, | 1714 }, |
| 1519 1, | 1715 1, |
| 1520 {"t"}}, | 1716 {"t"}}, |
| 1521 {"'use strict'; var a = 1;\nfunction f() { return a; }\nf()", | 1717 {"'use strict'; var a = 1;\nfunction f() { return a; }\nf()", |
| 1522 0, | 1718 0, |
| 1523 1, | 1719 1, |
| 1524 4, | 1720 5, |
| 1525 { | 1721 { |
| 1722 B(StackCheck), // |
| 1526 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // | 1723 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // |
| 1527 B(Return) // | 1724 B(Return) // |
| 1528 }, | 1725 }, |
| 1529 1, | 1726 1, |
| 1530 {"a"}}, | 1727 {"a"}}, |
| 1531 {"a = 1;\nfunction f() { return a; }\nf()", | 1728 {"a = 1;\nfunction f() { return a; }\nf()", |
| 1532 0, | 1729 0, |
| 1533 1, | 1730 1, |
| 1534 4, | 1731 5, |
| 1535 { | 1732 { |
| 1733 B(StackCheck), // |
| 1536 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1734 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1537 B(Return) // | 1735 B(Return) // |
| 1538 }, | 1736 }, |
| 1539 1, | 1737 1, |
| 1540 {"a"}}, | 1738 {"a"}}, |
| 1541 {"a = 1;" | 1739 {"a = 1;" |
| 1542 "function f(b) {\n" | 1740 "function f(b) {\n" |
| 1543 " b.name;\n" | 1741 " b.name;\n" |
| 1544 REPEAT_127(SPACE, "b.name; ") | 1742 REPEAT_127(SPACE, "b.name; ") |
| 1545 " return a;" | 1743 " return a;" |
| 1546 "}\nf({name: 1});", | 1744 "}\nf({name: 1});", |
| 1547 kPointerSize, | 1745 kPointerSize, |
| 1548 2, | 1746 2, |
| 1549 1030, | 1747 1031, |
| 1550 { | 1748 { |
| 1749 B(StackCheck), // |
| 1551 B(Ldar), A(1, 2), // | 1750 B(Ldar), A(1, 2), // |
| 1552 B(Star), R(0), // | 1751 B(Star), R(0), // |
| 1553 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), // | 1752 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), // |
| 1554 REPEAT_127(COMMA, // | 1753 REPEAT_127(COMMA, // |
| 1555 B(Ldar), A(1, 2), // | 1754 B(Ldar), A(1, 2), // |
| 1556 B(Star), R(0), // | 1755 B(Star), R(0), // |
| 1557 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), // | 1756 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), // |
| 1558 B(LdaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), // | 1757 B(LdaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), // |
| 1559 B(Return), // | 1758 B(Return), // |
| 1560 }, | 1759 }, |
| 1561 2, | 1760 2, |
| 1562 {"name", "a"}}, | 1761 {"name", "a"}}, |
| 1563 {"a = 1;" | 1762 {"a = 1;" |
| 1564 "function f(b) {\n" | 1763 "function f(b) {\n" |
| 1565 " 'use strict';\n" | 1764 " 'use strict';\n" |
| 1566 " b.name\n" | 1765 " b.name\n" |
| 1567 REPEAT_127(SPACE, "b.name; ") | 1766 REPEAT_127(SPACE, "b.name; ") |
| 1568 " return a;" | 1767 " return a;" |
| 1569 "}\nf({name: 1});", | 1768 "}\nf({name: 1});", |
| 1570 kPointerSize, | 1769 kPointerSize, |
| 1571 2, | 1770 2, |
| 1572 1030, | 1771 1031, |
| 1573 { | 1772 { |
| 1773 B(StackCheck), // |
| 1574 B(Ldar), A(1, 2), // | 1774 B(Ldar), A(1, 2), // |
| 1575 B(Star), R(0), // | 1775 B(Star), R(0), // |
| 1576 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // | 1776 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // |
| 1577 REPEAT_127(COMMA, // | 1777 REPEAT_127(COMMA, // |
| 1578 B(Ldar), A(1, 2), // | 1778 B(Ldar), A(1, 2), // |
| 1579 B(Star), R(0), // | 1779 B(Star), R(0), // |
| 1580 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), // | 1780 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), // |
| 1581 B(LdaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), // | 1781 B(LdaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), // |
| 1582 B(Return), // | 1782 B(Return), // |
| 1583 }, | 1783 }, |
| 1584 2, | 1784 2, |
| 1585 {"name", "a"}}, | 1785 {"name", "a"}}, |
| 1586 }; | 1786 }; |
| 1787 // clang-format on |
| 1587 | 1788 |
| 1588 for (size_t i = 0; i < arraysize(snippets); i++) { | 1789 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1589 Handle<BytecodeArray> bytecode_array = | 1790 Handle<BytecodeArray> bytecode_array = |
| 1590 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1791 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 1591 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1792 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1592 } | 1793 } |
| 1593 } | 1794 } |
| 1594 | 1795 |
| 1595 | 1796 |
| 1596 TEST(StoreGlobal) { | 1797 TEST(StoreGlobal) { |
| 1597 InitializedHandleScope handle_scope; | 1798 InitializedHandleScope handle_scope; |
| 1598 BytecodeGeneratorHelper helper; | 1799 BytecodeGeneratorHelper helper; |
| 1599 Zone zone; | 1800 Zone zone; |
| 1600 | 1801 |
| 1601 FeedbackVectorSpec feedback_spec(&zone); | 1802 FeedbackVectorSpec feedback_spec(&zone); |
| 1602 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); | 1803 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); |
| 1603 | 1804 |
| 1604 Handle<i::TypeFeedbackVector> vector = | 1805 Handle<i::TypeFeedbackVector> vector = |
| 1605 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1806 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1606 | 1807 |
| 1607 // These are a hack used by the StaGlobalXXXWide tests below. | 1808 // These are a hack used by the StaGlobalXXXWide tests below. |
| 1608 int wide_idx_1 = vector->GetIndex(slot) - 2; | 1809 int wide_idx_1 = vector->GetIndex(slot) - 2; |
| 1609 int wide_idx_2 = vector->GetIndex(slot) - 2; | 1810 int wide_idx_2 = vector->GetIndex(slot) - 2; |
| 1610 | 1811 |
| 1812 // clang-format off |
| 1611 ExpectedSnippet<const char*> snippets[] = { | 1813 ExpectedSnippet<const char*> snippets[] = { |
| 1612 {"var a = 1;\nfunction f() { a = 2; }\nf()", | 1814 {"var a = 1;\nfunction f() { a = 2; }\nf()", |
| 1613 0, | 1815 0, |
| 1614 1, | 1816 1, |
| 1615 7, | 1817 8, |
| 1616 { | 1818 { |
| 1819 B(StackCheck), // |
| 1617 B(LdaSmi8), U8(2), // | 1820 B(LdaSmi8), U8(2), // |
| 1618 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1821 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1619 B(LdaUndefined), // | 1822 B(LdaUndefined), // |
| 1620 B(Return) // | 1823 B(Return) // |
| 1621 }, | 1824 }, |
| 1622 1, | 1825 1, |
| 1623 {"a"}}, | 1826 {"a"}}, |
| 1624 {"var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", | 1827 {"var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", |
| 1625 0, | 1828 0, |
| 1626 2, | 1829 2, |
| 1627 7, | 1830 8, |
| 1628 { | 1831 { |
| 1832 B(StackCheck), // |
| 1629 B(Ldar), R(helper.kLastParamIndex), // | 1833 B(Ldar), R(helper.kLastParamIndex), // |
| 1630 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1834 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1631 B(LdaUndefined), // | 1835 B(LdaUndefined), // |
| 1632 B(Return) // | 1836 B(Return) // |
| 1633 }, | 1837 }, |
| 1634 1, | 1838 1, |
| 1635 {"a"}}, | 1839 {"a"}}, |
| 1636 {"'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", | 1840 {"'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", |
| 1637 0, | 1841 0, |
| 1638 1, | 1842 1, |
| 1639 7, | 1843 8, |
| 1640 { | 1844 { |
| 1845 B(StackCheck), // |
| 1641 B(LdaSmi8), U8(2), // | 1846 B(LdaSmi8), U8(2), // |
| 1642 B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // | 1847 B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // |
| 1643 B(LdaUndefined), // | 1848 B(LdaUndefined), // |
| 1644 B(Return) // | 1849 B(Return) // |
| 1645 }, | 1850 }, |
| 1646 1, | 1851 1, |
| 1647 {"a"}}, | 1852 {"a"}}, |
| 1648 {"a = 1;\nfunction f() { a = 2; }\nf()", | 1853 {"a = 1;\nfunction f() { a = 2; }\nf()", |
| 1649 0, | 1854 0, |
| 1650 1, | 1855 1, |
| 1651 7, | 1856 8, |
| 1652 { | 1857 { |
| 1858 B(StackCheck), // |
| 1653 B(LdaSmi8), U8(2), // | 1859 B(LdaSmi8), U8(2), // |
| 1654 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 1860 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 1655 B(LdaUndefined), // | 1861 B(LdaUndefined), // |
| 1656 B(Return) // | 1862 B(Return) // |
| 1657 }, | 1863 }, |
| 1658 1, | 1864 1, |
| 1659 {"a"}}, | 1865 {"a"}}, |
| 1660 {"a = 1;" | 1866 {"a = 1;" |
| 1661 "function f(b) {" | 1867 "function f(b) {" |
| 1662 " b.name;\n" | 1868 " b.name;\n" |
| 1663 REPEAT_127(SPACE, "b.name; ") | 1869 REPEAT_127(SPACE, "b.name; ") |
| 1664 " a = 2; }\n" | 1870 " a = 2; }\n" |
| 1665 "f({name: 1});", | 1871 "f({name: 1});", |
| 1666 kPointerSize, | 1872 kPointerSize, |
| 1667 2, | 1873 2, |
| 1668 1033, | 1874 1034, |
| 1669 { | 1875 { |
| 1876 B(StackCheck), // |
| 1670 B(Ldar), A(1, 2), // | 1877 B(Ldar), A(1, 2), // |
| 1671 B(Star), R(0), // | 1878 B(Star), R(0), // |
| 1672 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), // | 1879 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2), // |
| 1673 REPEAT_127(COMMA, // | 1880 REPEAT_127(COMMA, // |
| 1674 B(Ldar), A(1, 2), // | 1881 B(Ldar), A(1, 2), // |
| 1675 B(Star), R(0), // | 1882 B(Star), R(0), // |
| 1676 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), // | 1883 B(LoadICSloppy), R(0), U8(0), U8(wide_idx_1 += 2)), // |
| 1677 B(LdaSmi8), U8(2), // | 1884 B(LdaSmi8), U8(2), // |
| 1678 B(StaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), // | 1885 B(StaGlobalSloppyWide), U16(1), U16(wide_idx_1 + 2), // |
| 1679 B(LdaUndefined), // | 1886 B(LdaUndefined), // |
| 1680 B(Return), // | 1887 B(Return), // |
| 1681 }, | 1888 }, |
| 1682 2, | 1889 2, |
| 1683 {"name", "a"}}, | 1890 {"name", "a"}}, |
| 1684 {"a = 1;" | 1891 {"a = 1;" |
| 1685 "function f(b) {\n" | 1892 "function f(b) {\n" |
| 1686 " 'use strict';\n" | 1893 " 'use strict';\n" |
| 1687 " b.name;\n" | 1894 " b.name;\n" |
| 1688 REPEAT_127(SPACE, "b.name; ") | 1895 REPEAT_127(SPACE, "b.name; ") |
| 1689 " a = 2; }\n" | 1896 " a = 2; }\n" |
| 1690 "f({name: 1});", | 1897 "f({name: 1});", |
| 1691 kPointerSize, | 1898 kPointerSize, |
| 1692 2, | 1899 2, |
| 1693 1033, | 1900 1034, |
| 1694 { | 1901 { |
| 1902 B(StackCheck), // |
| 1695 B(Ldar), A(1, 2), // | 1903 B(Ldar), A(1, 2), // |
| 1696 B(Star), R(0), // | 1904 B(Star), R(0), // |
| 1697 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // | 1905 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2), // |
| 1698 REPEAT_127(COMMA, // | 1906 REPEAT_127(COMMA, // |
| 1699 B(Ldar), A(1, 2), // | 1907 B(Ldar), A(1, 2), // |
| 1700 B(Star), R(0), // | 1908 B(Star), R(0), // |
| 1701 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), // | 1909 B(LoadICStrict), R(0), U8(0), U8(wide_idx_2 += 2)), // |
| 1702 B(LdaSmi8), U8(2), // | 1910 B(LdaSmi8), U8(2), // |
| 1703 B(StaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), // | 1911 B(StaGlobalStrictWide), U16(1), U16(wide_idx_2 + 2), // |
| 1704 B(LdaUndefined), // | 1912 B(LdaUndefined), // |
| 1705 B(Return), // | 1913 B(Return), // |
| 1706 }, | 1914 }, |
| 1707 2, | 1915 2, |
| 1708 {"name", "a"}}, | 1916 {"name", "a"}}, |
| 1709 }; | 1917 }; |
| 1918 // clang-format on |
| 1710 | 1919 |
| 1711 for (size_t i = 0; i < arraysize(snippets); i++) { | 1920 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1712 Handle<BytecodeArray> bytecode_array = | 1921 Handle<BytecodeArray> bytecode_array = |
| 1713 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1922 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 1714 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1923 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1715 } | 1924 } |
| 1716 } | 1925 } |
| 1717 | 1926 |
| 1718 | 1927 |
| 1719 TEST(CallGlobal) { | 1928 TEST(CallGlobal) { |
| 1720 InitializedHandleScope handle_scope; | 1929 InitializedHandleScope handle_scope; |
| 1721 BytecodeGeneratorHelper helper; | 1930 BytecodeGeneratorHelper helper; |
| 1722 Zone zone; | 1931 Zone zone; |
| 1723 | 1932 |
| 1724 FeedbackVectorSpec feedback_spec(&zone); | 1933 FeedbackVectorSpec feedback_spec(&zone); |
| 1725 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); | 1934 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
| 1726 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 1935 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 1727 | 1936 |
| 1728 Handle<i::TypeFeedbackVector> vector = | 1937 Handle<i::TypeFeedbackVector> vector = |
| 1729 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1938 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1730 | 1939 |
| 1940 // clang-format off |
| 1731 ExpectedSnippet<const char*> snippets[] = { | 1941 ExpectedSnippet<const char*> snippets[] = { |
| 1732 {"function t() { }\nfunction f() { return t(); }\nf()", | 1942 {"function t() { }\nfunction f() { return t(); }\nf()", |
| 1733 2 * kPointerSize, | 1943 2 * kPointerSize, |
| 1734 1, | 1944 1, |
| 1735 14, | 1945 15, |
| 1736 { | 1946 { |
| 1947 B(StackCheck), // |
| 1737 B(LdaUndefined), // | 1948 B(LdaUndefined), // |
| 1738 B(Star), R(1), // | 1949 B(Star), R(1), // |
| 1739 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 1950 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 1740 B(Star), R(0), // | 1951 B(Star), R(0), // |
| 1741 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 1952 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 1742 B(Return) // | 1953 B(Return) // |
| 1743 }, | 1954 }, |
| 1744 1, | 1955 1, |
| 1745 {"t"}}, | 1956 {"t"}}, |
| 1746 {"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", | 1957 {"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", |
| 1747 5 * kPointerSize, | 1958 5 * kPointerSize, |
| 1748 1, | 1959 1, |
| 1749 26, | 1960 27, |
| 1750 { | 1961 { |
| 1962 B(StackCheck), // |
| 1751 B(LdaUndefined), // | 1963 B(LdaUndefined), // |
| 1752 B(Star), R(1), // | 1964 B(Star), R(1), // |
| 1753 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 1965 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 1754 B(Star), R(0), // | 1966 B(Star), R(0), // |
| 1755 B(LdaSmi8), U8(1), // | 1967 B(LdaSmi8), U8(1), // |
| 1756 B(Star), R(2), // | 1968 B(Star), R(2), // |
| 1757 B(LdaSmi8), U8(2), // | 1969 B(LdaSmi8), U8(2), // |
| 1758 B(Star), R(3), // | 1970 B(Star), R(3), // |
| 1759 B(LdaSmi8), U8(3), // | 1971 B(LdaSmi8), U8(3), // |
| 1760 B(Star), R(4), // | 1972 B(Star), R(4), // |
| 1761 B(Call), R(0), R(1), U8(4), U8(vector->GetIndex(slot1)), // | 1973 B(Call), R(0), R(1), U8(4), U8(vector->GetIndex(slot1)), // |
| 1762 B(Return) // | 1974 B(Return) // |
| 1763 }, | 1975 }, |
| 1764 1, | 1976 1, |
| 1765 {"t"}}, | 1977 {"t"}}, |
| 1766 }; | 1978 }; |
| 1979 // clang-format on |
| 1767 | 1980 |
| 1768 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | 1981 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 1769 for (size_t i = 0; i < num_snippets; i++) { | 1982 for (size_t i = 0; i < num_snippets; i++) { |
| 1770 Handle<BytecodeArray> bytecode_array = | 1983 Handle<BytecodeArray> bytecode_array = |
| 1771 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1984 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 1772 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1985 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1773 } | 1986 } |
| 1774 } | 1987 } |
| 1775 | 1988 |
| 1776 | 1989 |
| 1777 TEST(CallRuntime) { | 1990 TEST(CallRuntime) { |
| 1778 InitializedHandleScope handle_scope; | 1991 InitializedHandleScope handle_scope; |
| 1779 BytecodeGeneratorHelper helper; | 1992 BytecodeGeneratorHelper helper; |
| 1780 | 1993 |
| 1994 // clang-format off |
| 1781 ExpectedSnippet<InstanceType> snippets[] = { | 1995 ExpectedSnippet<InstanceType> snippets[] = { |
| 1782 { | 1996 { |
| 1783 "function f() { %TheHole() }\nf()", | 1997 "function f() { %TheHole() }\nf()", |
| 1784 0, | 1998 0, |
| 1785 1, | 1999 1, |
| 1786 7, | 2000 8, |
| 1787 { | 2001 { |
| 2002 B(StackCheck), // |
| 1788 B(CallRuntime), U16(Runtime::kTheHole), R(0), U8(0), // | 2003 B(CallRuntime), U16(Runtime::kTheHole), R(0), U8(0), // |
| 1789 B(LdaUndefined), // | 2004 B(LdaUndefined), // |
| 1790 B(Return) // | 2005 B(Return) // |
| 1791 }, | 2006 }, |
| 1792 }, | 2007 }, |
| 1793 { | 2008 { |
| 1794 "function f(a) { return %IsArray(a) }\nf(undefined)", | 2009 "function f(a) { return %IsArray(a) }\nf(undefined)", |
| 1795 1 * kPointerSize, | 2010 1 * kPointerSize, |
| 1796 2, | 2011 2, |
| 1797 10, | 2012 11, |
| 1798 { | 2013 { |
| 2014 B(StackCheck), // |
| 1799 B(Ldar), A(1, 2), // | 2015 B(Ldar), A(1, 2), // |
| 1800 B(Star), R(0), // | 2016 B(Star), R(0), // |
| 1801 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), // | 2017 B(CallRuntime), U16(Runtime::kIsArray), R(0), U8(1), // |
| 1802 B(Return) // | 2018 B(Return) // |
| 1803 }, | 2019 }, |
| 1804 }, | 2020 }, |
| 1805 { | 2021 { |
| 1806 "function f() { return %Add(1, 2) }\nf()", | 2022 "function f() { return %Add(1, 2) }\nf()", |
| 1807 2 * kPointerSize, | 2023 2 * kPointerSize, |
| 1808 1, | 2024 1, |
| 1809 14, | 2025 15, |
| 1810 { | 2026 { |
| 2027 B(StackCheck), // |
| 1811 B(LdaSmi8), U8(1), // | 2028 B(LdaSmi8), U8(1), // |
| 1812 B(Star), R(0), // | 2029 B(Star), R(0), // |
| 1813 B(LdaSmi8), U8(2), // | 2030 B(LdaSmi8), U8(2), // |
| 1814 B(Star), R(1), // | 2031 B(Star), R(1), // |
| 1815 B(CallRuntime), U16(Runtime::kAdd), R(0), U8(2), // | 2032 B(CallRuntime), U16(Runtime::kAdd), R(0), U8(2), // |
| 1816 B(Return) // | 2033 B(Return) // |
| 1817 }, | 2034 }, |
| 1818 }, | 2035 }, |
| 1819 { | 2036 { |
| 1820 "function f() { return %spread_iterable([1]) }\nf()", | 2037 "function f() { return %spread_iterable([1]) }\nf()", |
| 1821 2 * kPointerSize, | 2038 2 * kPointerSize, |
| 1822 1, | 2039 1, |
| 1823 15, | 2040 16, |
| 1824 { | 2041 { |
| 2042 B(StackCheck), // |
| 1825 B(LdaUndefined), // | 2043 B(LdaUndefined), // |
| 1826 B(Star), R(0), // | 2044 B(Star), R(0), // |
| 1827 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // | 2045 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // |
| 1828 B(Star), R(1), // | 2046 B(Star), R(1), // |
| 1829 B(CallJSRuntime), U16(Context::SPREAD_ITERABLE_INDEX), R(0), // | 2047 B(CallJSRuntime), U16(Context::SPREAD_ITERABLE_INDEX), R(0), // |
| 1830 U8(2), // | 2048 /* */ U8(2), // |
| 1831 B(Return), // | 2049 B(Return), // |
| 1832 }, | 2050 }, |
| 1833 1, | 2051 1, |
| 1834 {InstanceType::FIXED_ARRAY_TYPE}, | 2052 {InstanceType::FIXED_ARRAY_TYPE}, |
| 1835 }, | 2053 }, |
| 1836 }; | 2054 }; |
| 2055 // clang-format on |
| 1837 | 2056 |
| 1838 for (size_t i = 0; i < arraysize(snippets); i++) { | 2057 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1839 Handle<BytecodeArray> bytecode_array = | 2058 Handle<BytecodeArray> bytecode_array = |
| 1840 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 2059 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 1841 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2060 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1842 } | 2061 } |
| 1843 } | 2062 } |
| 1844 | 2063 |
| 1845 | 2064 |
| 1846 TEST(IfConditions) { | 2065 TEST(IfConditions) { |
| 1847 InitializedHandleScope handle_scope; | 2066 InitializedHandleScope handle_scope; |
| 1848 BytecodeGeneratorHelper helper; | 2067 BytecodeGeneratorHelper helper; |
| 1849 | 2068 |
| 1850 Handle<Object> unused = helper.factory()->undefined_value(); | 2069 Handle<Object> unused = helper.factory()->undefined_value(); |
| 1851 | 2070 |
| 2071 // clang-format off |
| 1852 ExpectedSnippet<Handle<Object>> snippets[] = { | 2072 ExpectedSnippet<Handle<Object>> snippets[] = { |
| 1853 {"function f() { if (0) { return 1; } else { return -1; } } f()", | 2073 {"function f() { if (0) { return 1; } else { return -1; } } f()", |
| 1854 0, | 2074 0, |
| 1855 1, | 2075 1, |
| 1856 3, | 2076 4, |
| 1857 { | 2077 { |
| 2078 B(StackCheck), // |
| 1858 B(LdaSmi8), U8(-1), // | 2079 B(LdaSmi8), U8(-1), // |
| 1859 B(Return), // | 2080 B(Return), // |
| 1860 }, | 2081 }, |
| 1861 0, | 2082 0, |
| 1862 {unused, unused, unused, unused, unused, unused}}, | 2083 {unused, unused, unused, unused, unused, unused}}, |
| 1863 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", | 2084 {"function f() { if ('lucky') { return 1; } else { return -1; } } f();", |
| 1864 0, | 2085 0, |
| 1865 1, | 2086 1, |
| 1866 3, | 2087 4, |
| 1867 { | 2088 { |
| 2089 B(StackCheck), // |
| 1868 B(LdaSmi8), U8(1), // | 2090 B(LdaSmi8), U8(1), // |
| 1869 B(Return), // | 2091 B(Return), // |
| 1870 }, | 2092 }, |
| 1871 0, | 2093 0, |
| 1872 {unused, unused, unused, unused, unused, unused}}, | 2094 {unused, unused, unused, unused, unused, unused}}, |
| 1873 {"function f() { if (false) { return 1; } else { return -1; } } f();", | 2095 {"function f() { if (false) { return 1; } else { return -1; } } f();", |
| 1874 0, | 2096 0, |
| 1875 1, | 2097 1, |
| 1876 3, | 2098 4, |
| 1877 { | 2099 { |
| 2100 B(StackCheck), // |
| 1878 B(LdaSmi8), U8(-1), // | 2101 B(LdaSmi8), U8(-1), // |
| 1879 B(Return), // | 2102 B(Return), // |
| 1880 }, | 2103 }, |
| 1881 0, | 2104 0, |
| 1882 {unused, unused, unused, unused, unused, unused}}, | 2105 {unused, unused, unused, unused, unused, unused}}, |
| 1883 {"function f() { if (false) { return 1; } } f();", | 2106 {"function f() { if (false) { return 1; } } f();", |
| 1884 0, | 2107 0, |
| 1885 1, | 2108 1, |
| 1886 2, | 2109 3, |
| 1887 { | 2110 { |
| 2111 B(StackCheck), // |
| 1888 B(LdaUndefined), // | 2112 B(LdaUndefined), // |
| 1889 B(Return), // | 2113 B(Return), // |
| 1890 }, | 2114 }, |
| 1891 0, | 2115 0, |
| 1892 {unused, unused, unused, unused, unused, unused}}, | 2116 {unused, unused, unused, unused, unused, unused}}, |
| 1893 {"function f() { var a = 1; if (a) { a += 1; } else { return 2; } } f();", | 2117 {"function f() { var a = 1; if (a) { a += 1; } else { return 2; } } f();", |
| 1894 2 * kPointerSize, | 2118 2 * kPointerSize, |
| 1895 1, | 2119 1, |
| 1896 23, | 2120 24, |
| 1897 { | 2121 { |
| 2122 B(StackCheck), // |
| 1898 B(LdaSmi8), U8(1), // | 2123 B(LdaSmi8), U8(1), // |
| 1899 B(Star), R(0), // | 2124 B(Star), R(0), // |
| 1900 B(JumpIfToBooleanFalse), U8(14), // | 2125 B(JumpIfToBooleanFalse), U8(14), // |
| 1901 B(Ldar), R(0), // | 2126 B(Ldar), R(0), // |
| 1902 B(Star), R(1), // | 2127 B(Star), R(1), // |
| 1903 B(LdaSmi8), U8(1), // | 2128 B(LdaSmi8), U8(1), // |
| 1904 B(Add), R(1), // | 2129 B(Add), R(1), // |
| 1905 B(Star), R(0), // | 2130 B(Star), R(0), // |
| 1906 B(Jump), U8(5), // | 2131 B(Jump), U8(5), // |
| 1907 B(LdaSmi8), U8(2), // | 2132 B(LdaSmi8), U8(2), // |
| 1908 B(Return), // | 2133 B(Return), // |
| 1909 B(LdaUndefined), // | 2134 B(LdaUndefined), // |
| 1910 B(Return), // | 2135 B(Return), // |
| 1911 }, | 2136 }, |
| 1912 0, | 2137 0, |
| 1913 {unused, unused, unused, unused, unused, unused}}, | 2138 {unused, unused, unused, unused, unused, unused}}, |
| 1914 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" | 2139 {"function f(a) { if (a <= 0) { return 200; } else { return -200; } }" |
| 1915 "f(99);", | 2140 "f(99);", |
| 1916 kPointerSize, | 2141 kPointerSize, |
| 1917 2, | 2142 2, |
| 1918 17, | 2143 18, |
| 1919 { | 2144 { |
| 2145 B(StackCheck), // |
| 1920 B(Ldar), A(1, 2), // | 2146 B(Ldar), A(1, 2), // |
| 1921 B(Star), R(0), // | 2147 B(Star), R(0), // |
| 1922 B(LdaZero), // | 2148 B(LdaZero), // |
| 1923 B(TestLessThanOrEqual), R(0), // | 2149 B(TestLessThanOrEqual), R(0), // |
| 1924 B(JumpIfFalse), U8(5), // | 2150 B(JumpIfFalse), U8(5), // |
| 1925 B(LdaConstant), U8(0), // | 2151 B(LdaConstant), U8(0), // |
| 1926 B(Return), // | 2152 B(Return), // |
| 1927 B(LdaConstant), U8(1), // | 2153 B(LdaConstant), U8(1), // |
| 1928 B(Return), // | 2154 B(Return), // |
| 1929 B(LdaUndefined), // | 2155 B(LdaUndefined), // |
| 1930 B(Return), // | 2156 B(Return), // |
| 1931 }, | 2157 }, |
| 1932 2, | 2158 2, |
| 1933 {helper.factory()->NewNumberFromInt(200), | 2159 {helper.factory()->NewNumberFromInt(200), |
| 1934 helper.factory()->NewNumberFromInt(-200), unused, unused, unused, | 2160 helper.factory()->NewNumberFromInt(-200), unused, unused, unused, |
| 1935 unused}}, | 2161 unused}}, |
| 1936 {"function f(a, b) { if (a in b) { return 200; } }" | 2162 {"function f(a, b) { if (a in b) { return 200; } }" |
| 1937 "f('prop', { prop: 'yes'});", | 2163 "f('prop', { prop: 'yes'});", |
| 1938 kPointerSize, | 2164 kPointerSize, |
| 1939 3, | 2165 3, |
| 1940 15, | 2166 16, |
| 1941 { | 2167 { |
| 2168 B(StackCheck), // |
| 1942 B(Ldar), A(1, 3), // | 2169 B(Ldar), A(1, 3), // |
| 1943 B(Star), R(0), // | 2170 B(Star), R(0), // |
| 1944 B(Ldar), A(2, 3), // | 2171 B(Ldar), A(2, 3), // |
| 1945 B(TestIn), R(0), // | 2172 B(TestIn), R(0), // |
| 1946 B(JumpIfFalse), U8(5), // | 2173 B(JumpIfFalse), U8(5), // |
| 1947 B(LdaConstant), U8(0), // | 2174 B(LdaConstant), U8(0), // |
| 1948 B(Return), // | 2175 B(Return), // |
| 1949 B(LdaUndefined), // | 2176 B(LdaUndefined), // |
| 1950 B(Return), // | 2177 B(Return), // |
| 1951 }, | 2178 }, |
| 1952 1, | 2179 1, |
| 1953 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, | 2180 {helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused, |
| 1954 unused}}, | 2181 unused}}, |
| 1955 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " | 2182 {"function f(z) { var a = 0; var b = 0; if (a === 0.01) { " |
| 1956 REPEAT_64(SPACE, "b = a; a = b; ") | 2183 REPEAT_64(SPACE, "b = a; a = b; ") |
| 1957 " return 200; } else { return -200; } } f(0.001)", | 2184 " return 200; } else { return -200; } } f(0.001)", |
| 1958 3 * kPointerSize, | 2185 3 * kPointerSize, |
| 1959 2, | 2186 2, |
| 1960 282, | 2187 283, |
| 1961 { | 2188 { |
| 2189 B(StackCheck), // |
| 1962 B(LdaZero), // | 2190 B(LdaZero), // |
| 1963 B(Star), R(0), // | 2191 B(Star), R(0), // |
| 1964 B(LdaZero), // | 2192 B(LdaZero), // |
| 1965 B(Star), R(1), // | 2193 B(Star), R(1), // |
| 1966 B(Ldar), R(0), // | 2194 B(Ldar), R(0), // |
| 1967 B(Star), R(2), // | 2195 B(Star), R(2), // |
| 1968 B(LdaConstant), U8(0), // | 2196 B(LdaConstant), U8(0), // |
| 1969 B(TestEqualStrict), R(2), // | 2197 B(TestEqualStrict), R(2), // |
| 1970 B(JumpIfFalseConstant), U8(2), // | 2198 B(JumpIfFalseConstant), U8(2), // |
| 1971 B(Ldar), R(0), // | 2199 B(Ldar), R(0), // |
| 1972 REPEAT_64(COMMA, // | 2200 REPEAT_64(COMMA, // |
| 1973 B(Star), R(1), // | 2201 B(Star), R(1), // |
| 1974 B(Star), R(0)), // | 2202 B(Star), R(0)), // |
| 1975 B(LdaConstant), U8(1), // | 2203 B(LdaConstant), U8(1), // |
| 1976 B(Return), // | 2204 B(Return), // |
| 1977 B(LdaConstant), U8(3), // | 2205 B(LdaConstant), U8(3), // |
| 1978 B(Return), // | 2206 B(Return), // |
| 1979 B(LdaUndefined), // | 2207 B(LdaUndefined), // |
| 1980 B(Return)}, // | 2208 B(Return)}, // |
| 1981 4, | 2209 4, |
| 1982 {helper.factory()->NewHeapNumber(0.01), | 2210 {helper.factory()->NewHeapNumber(0.01), |
| 1983 helper.factory()->NewNumberFromInt(200), | 2211 helper.factory()->NewNumberFromInt(200), |
| 1984 helper.factory()->NewNumberFromInt(263), | 2212 helper.factory()->NewNumberFromInt(263), |
| 1985 helper.factory()->NewNumberFromInt(-200), unused, unused}}, | 2213 helper.factory()->NewNumberFromInt(-200), unused, unused}}, |
| 1986 {"function f() { var a = 0; var b = 0; if (a) { " | 2214 {"function f() { var a = 0; var b = 0; if (a) { " |
| 1987 REPEAT_64(SPACE, "b = a; a = b; ") | 2215 REPEAT_64(SPACE, "b = a; a = b; ") |
| 1988 " return 200; } else { return -200; } } f()", | 2216 " return 200; } else { return -200; } } f()", |
| 1989 2 * kPointerSize, | 2217 2 * kPointerSize, |
| 1990 1, | 2218 1, |
| 1991 276, | 2219 277, |
| 1992 { | 2220 { |
| 2221 B(StackCheck), // |
| 1993 B(LdaZero), // | 2222 B(LdaZero), // |
| 1994 B(Star), R(0), // | 2223 B(Star), R(0), // |
| 1995 B(LdaZero), // | 2224 B(LdaZero), // |
| 1996 B(Star), R(1), // | 2225 B(Star), R(1), // |
| 1997 B(Ldar), R(0), // | 2226 B(Ldar), R(0), // |
| 1998 B(JumpIfToBooleanFalseConstant), U8(1), // | 2227 B(JumpIfToBooleanFalseConstant), U8(1), // |
| 1999 B(Ldar), R(0), // | 2228 B(Ldar), R(0), // |
| 2000 REPEAT_64(COMMA, // | 2229 REPEAT_64(COMMA, // |
| 2001 B(Star), R(1), // | 2230 B(Star), R(1), // |
| 2002 B(Star), R(0)), // | 2231 B(Star), R(0)), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2017 " if (a < b) { return 1; }\n" | 2246 " if (a < b) { return 1; }\n" |
| 2018 " if (a > b) { return 1; }\n" | 2247 " if (a > b) { return 1; }\n" |
| 2019 " if (a <= b) { return 1; }\n" | 2248 " if (a <= b) { return 1; }\n" |
| 2020 " if (a >= b) { return 1; }\n" | 2249 " if (a >= b) { return 1; }\n" |
| 2021 " if (a in b) { return 1; }\n" | 2250 " if (a in b) { return 1; }\n" |
| 2022 " if (a instanceof b) { return 1; }\n" | 2251 " if (a instanceof b) { return 1; }\n" |
| 2023 " return 0;\n" | 2252 " return 0;\n" |
| 2024 "} f(1, 1);", | 2253 "} f(1, 1);", |
| 2025 kPointerSize, | 2254 kPointerSize, |
| 2026 3, | 2255 3, |
| 2027 106, | 2256 107, |
| 2028 { | 2257 { |
| 2029 #define IF_CONDITION_RETURN(condition) \ | 2258 #define IF_CONDITION_RETURN(condition) \ |
| 2030 B(Ldar), A(1, 3), \ | 2259 B(Ldar), A(1, 3), \ |
| 2031 B(Star), R(0), \ | 2260 B(Star), R(0), \ |
| 2032 B(Ldar), A(2, 3), \ | 2261 B(Ldar), A(2, 3), \ |
| 2033 B(condition), R(0), \ | 2262 B(condition), R(0), \ |
| 2034 B(JumpIfFalse), U8(5), \ | 2263 B(JumpIfFalse), U8(5), \ |
| 2035 B(LdaSmi8), U8(1), \ | 2264 B(LdaSmi8), U8(1), \ |
| 2036 B(Return), | 2265 B(Return), |
| 2266 B(StackCheck), // |
| 2037 IF_CONDITION_RETURN(TestEqual) // | 2267 IF_CONDITION_RETURN(TestEqual) // |
| 2038 IF_CONDITION_RETURN(TestEqualStrict) // | 2268 IF_CONDITION_RETURN(TestEqualStrict) // |
| 2039 IF_CONDITION_RETURN(TestLessThan) // | 2269 IF_CONDITION_RETURN(TestLessThan) // |
| 2040 IF_CONDITION_RETURN(TestGreaterThan) // | 2270 IF_CONDITION_RETURN(TestGreaterThan) // |
| 2041 IF_CONDITION_RETURN(TestLessThanOrEqual) // | 2271 IF_CONDITION_RETURN(TestLessThanOrEqual) // |
| 2042 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // | 2272 IF_CONDITION_RETURN(TestGreaterThanOrEqual) // |
| 2043 IF_CONDITION_RETURN(TestIn) // | 2273 IF_CONDITION_RETURN(TestIn) // |
| 2044 IF_CONDITION_RETURN(TestInstanceOf) // | 2274 IF_CONDITION_RETURN(TestInstanceOf) // |
| 2045 B(LdaZero), // | 2275 B(LdaZero), // |
| 2046 B(Return)}, // | 2276 B(Return)}, // |
| 2047 #undef IF_CONDITION_RETURN | 2277 #undef IF_CONDITION_RETURN |
| 2048 0, | 2278 0, |
| 2049 {unused, unused, unused, unused, unused, unused}}, | 2279 {unused, unused, unused, unused, unused, unused}}, |
| 2050 {"function f() {" | 2280 {"function f() {" |
| 2051 " var a = 0;" | 2281 " var a = 0;" |
| 2052 " if (a) {" | 2282 " if (a) {" |
| 2053 " return 20;" | 2283 " return 20;" |
| 2054 "} else {" | 2284 "} else {" |
| 2055 " return -20;}" | 2285 " return -20;}" |
| 2056 "};" | 2286 "};" |
| 2057 "f();", | 2287 "f();", |
| 2058 1 * kPointerSize, | 2288 1 * kPointerSize, |
| 2059 1, | 2289 1, |
| 2060 13, | 2290 14, |
| 2061 { | 2291 { |
| 2292 B(StackCheck), // |
| 2062 B(LdaZero), // | 2293 B(LdaZero), // |
| 2063 B(Star), R(0), // | 2294 B(Star), R(0), // |
| 2064 B(JumpIfToBooleanFalse), U8(5), // | 2295 B(JumpIfToBooleanFalse), U8(5), // |
| 2065 B(LdaSmi8), U8(20), // | 2296 B(LdaSmi8), U8(20), // |
| 2066 B(Return), // | 2297 B(Return), // |
| 2067 B(LdaSmi8), U8(-20), // | 2298 B(LdaSmi8), U8(-20), // |
| 2068 B(Return), // | 2299 B(Return), // |
| 2069 B(LdaUndefined), // | 2300 B(LdaUndefined), // |
| 2070 B(Return) | 2301 B(Return) |
| 2071 }, | 2302 }, |
| 2072 0, | 2303 0, |
| 2073 {unused, unused, unused, unused, unused, unused}}}; | 2304 {unused, unused, unused, unused, unused, unused}} |
| 2305 }; |
| 2306 // clang-format on |
| 2074 | 2307 |
| 2075 for (size_t i = 0; i < arraysize(snippets); i++) { | 2308 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2076 Handle<BytecodeArray> bytecode_array = | 2309 Handle<BytecodeArray> bytecode_array = |
| 2077 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 2310 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
| 2078 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2311 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2079 } | 2312 } |
| 2080 } | 2313 } |
| 2081 | 2314 |
| 2082 | 2315 |
| 2083 TEST(DeclareGlobals) { | 2316 TEST(DeclareGlobals) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2094 Handle<i::TypeFeedbackVector> store_vector = | 2327 Handle<i::TypeFeedbackVector> store_vector = |
| 2095 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_stores); | 2328 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_stores); |
| 2096 | 2329 |
| 2097 FeedbackVectorSpec feedback_spec_loads(&zone); | 2330 FeedbackVectorSpec feedback_spec_loads(&zone); |
| 2098 FeedbackVectorSlot load_slot_1 = feedback_spec_loads.AddLoadICSlot(); | 2331 FeedbackVectorSlot load_slot_1 = feedback_spec_loads.AddLoadICSlot(); |
| 2099 FeedbackVectorSlot call_slot_1 = feedback_spec_loads.AddCallICSlot(); | 2332 FeedbackVectorSlot call_slot_1 = feedback_spec_loads.AddCallICSlot(); |
| 2100 | 2333 |
| 2101 Handle<i::TypeFeedbackVector> load_vector = | 2334 Handle<i::TypeFeedbackVector> load_vector = |
| 2102 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_loads); | 2335 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_loads); |
| 2103 | 2336 |
| 2337 // clang-format off |
| 2104 ExpectedSnippet<InstanceType> snippets[] = { | 2338 ExpectedSnippet<InstanceType> snippets[] = { |
| 2105 {"var a = 1;", | 2339 {"var a = 1;", |
| 2106 4 * kPointerSize, | 2340 4 * kPointerSize, |
| 2107 1, | 2341 1, |
| 2108 30, | 2342 31, |
| 2109 { | 2343 { |
| 2110 B(LdaConstant), U8(0), // | 2344 B(LdaConstant), U8(0), // |
| 2111 B(Star), R(1), // | 2345 B(Star), R(1), // |
| 2112 B(LdaZero), // | 2346 B(LdaZero), // |
| 2113 B(Star), R(2), // | 2347 B(Star), R(2), // |
| 2114 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 2348 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
| 2349 B(StackCheck), // |
| 2115 B(LdaConstant), U8(1), // | 2350 B(LdaConstant), U8(1), // |
| 2116 B(Star), R(1), // | 2351 B(Star), R(1), // |
| 2117 B(LdaZero), // | 2352 B(LdaZero), // |
| 2118 B(Star), R(2), // | 2353 B(Star), R(2), // |
| 2119 B(LdaSmi8), U8(1), // | 2354 B(LdaSmi8), U8(1), // |
| 2120 B(Star), R(3), // | 2355 B(Star), R(3), // |
| 2121 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // | 2356 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // |
| 2122 B(LdaUndefined), // | 2357 B(LdaUndefined), // |
| 2123 B(Return) // | 2358 B(Return) // |
| 2124 }, | 2359 }, |
| 2125 2, | 2360 2, |
| 2126 {InstanceType::FIXED_ARRAY_TYPE, | 2361 {InstanceType::FIXED_ARRAY_TYPE, |
| 2127 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 2362 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2128 {"function f() {}", | 2363 {"function f() {}", |
| 2129 2 * kPointerSize, | 2364 2 * kPointerSize, |
| 2130 1, | 2365 1, |
| 2131 14, | 2366 15, |
| 2132 { | 2367 { |
| 2133 B(LdaConstant), U8(0), // | 2368 B(LdaConstant), U8(0), // |
| 2134 B(Star), R(0), // | 2369 B(Star), R(0), // |
| 2135 B(LdaZero), // | 2370 B(LdaZero), // |
| 2136 B(Star), R(1), // | 2371 B(Star), R(1), // |
| 2137 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(0), U8(2), // | 2372 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(0), U8(2), // |
| 2373 B(StackCheck), // |
| 2138 B(LdaUndefined), // | 2374 B(LdaUndefined), // |
| 2139 B(Return) // | 2375 B(Return) // |
| 2140 }, | 2376 }, |
| 2141 1, | 2377 1, |
| 2142 {InstanceType::FIXED_ARRAY_TYPE}}, | 2378 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 2143 {"var a = 1;\na=2;", | 2379 {"var a = 1;\na=2;", |
| 2144 4 * kPointerSize, | 2380 4 * kPointerSize, |
| 2145 1, | 2381 1, |
| 2146 36, | 2382 37, |
| 2147 { | 2383 { |
| 2148 B(LdaConstant), U8(0), // | 2384 B(LdaConstant), U8(0), // |
| 2149 B(Star), R(1), // | 2385 B(Star), R(1), // |
| 2150 B(LdaZero), // | 2386 B(LdaZero), // |
| 2151 B(Star), R(2), // | 2387 B(Star), R(2), // |
| 2152 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 2388 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
| 2389 B(StackCheck), // |
| 2153 B(LdaConstant), U8(1), // | 2390 B(LdaConstant), U8(1), // |
| 2154 B(Star), R(1), // | 2391 B(Star), R(1), // |
| 2155 B(LdaZero), // | 2392 B(LdaZero), // |
| 2156 B(Star), R(2), // | 2393 B(Star), R(2), // |
| 2157 B(LdaSmi8), U8(1), // | 2394 B(LdaSmi8), U8(1), // |
| 2158 B(Star), R(3), // | 2395 B(Star), R(3), // |
| 2159 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // | 2396 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // |
| 2160 B(LdaSmi8), U8(2), // | 2397 B(LdaSmi8), U8(2), // |
| 2161 B(StaGlobalSloppy), U8(1), // | 2398 B(StaGlobalSloppy), U8(1), // |
| 2162 U8(store_vector->GetIndex(store_slot_2)), // | 2399 /* */ U8(store_vector->GetIndex(store_slot_2)), // |
| 2163 B(Star), R(0), // | 2400 B(Star), R(0), // |
| 2164 B(Return) // | 2401 B(Return) // |
| 2165 }, | 2402 }, |
| 2166 2, | 2403 2, |
| 2167 {InstanceType::FIXED_ARRAY_TYPE, | 2404 {InstanceType::FIXED_ARRAY_TYPE, |
| 2168 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 2405 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2169 {"function f() {}\nf();", | 2406 {"function f() {}\nf();", |
| 2170 3 * kPointerSize, | 2407 3 * kPointerSize, |
| 2171 1, | 2408 1, |
| 2172 28, | 2409 29, |
| 2173 { | 2410 { |
| 2174 B(LdaConstant), U8(0), // | 2411 B(LdaConstant), U8(0), // |
| 2175 B(Star), R(1), // | 2412 B(Star), R(1), // |
| 2176 B(LdaZero), // | 2413 B(LdaZero), // |
| 2177 B(Star), R(2), // | 2414 B(Star), R(2), // |
| 2178 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 2415 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
| 2416 B(StackCheck), // |
| 2179 B(LdaUndefined), // | 2417 B(LdaUndefined), // |
| 2180 B(Star), R(2), // | 2418 B(Star), R(2), // |
| 2181 B(LdaGlobalSloppy), U8(1), // | 2419 B(LdaGlobalSloppy), U8(1), // |
| 2182 U8(load_vector->GetIndex(load_slot_1)), // | 2420 /* */ U8(load_vector->GetIndex(load_slot_1)), // |
| 2183 B(Star), R(1), // | 2421 B(Star), R(1), // |
| 2184 B(Call), R(1), R(2), U8(1), // | 2422 B(Call), R(1), R(2), U8(1), // |
| 2185 U8(load_vector->GetIndex(call_slot_1)), // | 2423 /* */ U8(load_vector->GetIndex(call_slot_1)), // |
| 2186 B(Star), R(0), // | 2424 B(Star), R(0), // |
| 2187 B(Return) // | 2425 B(Return) // |
| 2188 }, | 2426 }, |
| 2189 2, | 2427 2, |
| 2190 {InstanceType::FIXED_ARRAY_TYPE, | 2428 {InstanceType::FIXED_ARRAY_TYPE, |
| 2191 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 2429 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2192 }; | 2430 }; |
| 2431 // clang-format on |
| 2193 | 2432 |
| 2194 for (size_t i = 0; i < arraysize(snippets); i++) { | 2433 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2195 Handle<BytecodeArray> bytecode_array = | 2434 Handle<BytecodeArray> bytecode_array = |
| 2196 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 2435 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
| 2197 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2436 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2198 } | 2437 } |
| 2199 } | 2438 } |
| 2200 | 2439 |
| 2201 | 2440 |
| 2202 TEST(BreakableBlocks) { | 2441 TEST(BreakableBlocks) { |
| 2203 InitializedHandleScope handle_scope; | 2442 InitializedHandleScope handle_scope; |
| 2204 BytecodeGeneratorHelper helper; | 2443 BytecodeGeneratorHelper helper; |
| 2205 | 2444 |
| 2206 int closure = Register::function_closure().index(); | 2445 int closure = Register::function_closure().index(); |
| 2207 int context = Register::current_context().index(); | 2446 int context = Register::current_context().index(); |
| 2208 | 2447 |
| 2448 // clang-format off |
| 2209 ExpectedSnippet<InstanceType> snippets[] = { | 2449 ExpectedSnippet<InstanceType> snippets[] = { |
| 2210 {"var x = 0;\n" | 2450 {"var x = 0;\n" |
| 2211 "label: {\n" | 2451 "label: {\n" |
| 2212 " x = x + 1;\n" | 2452 " x = x + 1;\n" |
| 2213 " break label;\n" | 2453 " break label;\n" |
| 2214 " x = x + 1;\n" | 2454 " x = x + 1;\n" |
| 2215 "}\n" | 2455 "}\n" |
| 2216 "return x;", | 2456 "return x;", |
| 2217 2 * kPointerSize, | 2457 2 * kPointerSize, |
| 2218 1, | 2458 1, |
| 2219 16, | 2459 17, |
| 2220 { | 2460 { |
| 2461 B(StackCheck), // |
| 2221 B(LdaZero), // | 2462 B(LdaZero), // |
| 2222 B(Star), R(0), // | 2463 B(Star), R(0), // |
| 2223 B(Star), R(1), // | 2464 B(Star), R(1), // |
| 2224 B(LdaSmi8), U8(1), // | 2465 B(LdaSmi8), U8(1), // |
| 2225 B(Add), R(1), // | 2466 B(Add), R(1), // |
| 2226 B(Star), R(0), // | 2467 B(Star), R(0), // |
| 2227 B(Jump), U8(2), // | 2468 B(Jump), U8(2), // |
| 2228 B(Ldar), R(0), // | 2469 B(Ldar), R(0), // |
| 2229 B(Return) // | 2470 B(Return) // |
| 2230 }}, | 2471 }}, |
| 2231 {"var sum = 0;\n" | 2472 {"var sum = 0;\n" |
| 2232 "outer: {\n" | 2473 "outer: {\n" |
| 2233 " for (var x = 0; x < 10; ++x) {\n" | 2474 " for (var x = 0; x < 10; ++x) {\n" |
| 2234 " for (var y = 0; y < 3; ++y) {\n" | 2475 " for (var y = 0; y < 3; ++y) {\n" |
| 2235 " ++sum;\n" | 2476 " ++sum;\n" |
| 2236 " if (x + y == 12) { break outer; }\n" | 2477 " if (x + y == 12) { break outer; }\n" |
| 2237 " }\n" | 2478 " }\n" |
| 2238 " }\n" | 2479 " }\n" |
| 2239 "}\n" | 2480 "}\n" |
| 2240 "return sum;", | 2481 "return sum;", |
| 2241 5 * kPointerSize, | 2482 5 * kPointerSize, |
| 2242 1, | 2483 1, |
| 2243 72, | 2484 75, |
| 2244 { | 2485 { |
| 2486 B(StackCheck), // |
| 2245 B(LdaZero), // | 2487 B(LdaZero), // |
| 2246 B(Star), R(0), // | 2488 B(Star), R(0), // |
| 2247 B(LdaZero), // | 2489 B(LdaZero), // |
| 2248 B(Star), R(1), // | 2490 B(Star), R(1), // |
| 2249 B(Ldar), R(1), // | 2491 B(Ldar), R(1), // |
| 2250 B(Star), R(3), // | 2492 B(Star), R(3), // |
| 2251 B(LdaSmi8), U8(10), // | 2493 B(LdaSmi8), U8(10), // |
| 2252 B(TestLessThan), R(3), // | 2494 B(TestLessThan), R(3), // |
| 2253 B(JumpIfFalse), U8(55), // | 2495 B(JumpIfFalse), U8(57), // |
| 2496 B(StackCheck), // |
| 2254 B(LdaZero), // | 2497 B(LdaZero), // |
| 2255 B(Star), R(2), // | 2498 B(Star), R(2), // |
| 2256 B(Ldar), R(2), // | 2499 B(Ldar), R(2), // |
| 2257 B(Star), R(3), // | 2500 B(Star), R(3), // |
| 2258 B(LdaSmi8), U8(3), // | 2501 B(LdaSmi8), U8(3), // |
| 2259 B(TestLessThan), R(3), // | 2502 B(TestLessThan), R(3), // |
| 2260 B(JumpIfFalse), U8(34), // | 2503 B(JumpIfFalse), U8(35), // |
| 2504 B(StackCheck), // |
| 2261 B(Ldar), R(0), // | 2505 B(Ldar), R(0), // |
| 2262 B(ToNumber), // | 2506 B(ToNumber), // |
| 2263 B(Inc), // | 2507 B(Inc), // |
| 2264 B(Star), R(0), // | 2508 B(Star), R(0), // |
| 2265 B(Ldar), R(1), // | 2509 B(Ldar), R(1), // |
| 2266 B(Star), R(3), // | 2510 B(Star), R(3), // |
| 2267 B(Ldar), R(2), // | 2511 B(Ldar), R(2), // |
| 2268 B(Add), R(3), // | 2512 B(Add), R(3), // |
| 2269 B(Star), R(4), // | 2513 B(Star), R(4), // |
| 2270 B(LdaSmi8), U8(12), // | 2514 B(LdaSmi8), U8(12), // |
| 2271 B(TestEqual), R(4), // | 2515 B(TestEqual), R(4), // |
| 2272 B(JumpIfFalse), U8(4), // | 2516 B(JumpIfFalse), U8(4), // |
| 2273 B(Jump), U8(18), // | 2517 B(Jump), U8(18), // |
| 2274 B(Ldar), R(2), // | 2518 B(Ldar), R(2), // |
| 2275 B(ToNumber), // | 2519 B(ToNumber), // |
| 2276 B(Inc), // | 2520 B(Inc), // |
| 2277 B(Star), R(2), // | 2521 B(Star), R(2), // |
| 2278 B(Jump), U8(-40), // | 2522 B(Jump), U8(-41), // |
| 2279 B(Ldar), R(1), // | 2523 B(Ldar), R(1), // |
| 2280 B(ToNumber), // | 2524 B(ToNumber), // |
| 2281 B(Inc), // | 2525 B(Inc), // |
| 2282 B(Star), R(1), // | 2526 B(Star), R(1), // |
| 2283 B(Jump), U8(-61), // | 2527 B(Jump), U8(-63), // |
| 2284 B(Ldar), R(0), // | 2528 B(Ldar), R(0), // |
| 2285 B(Return), // | 2529 B(Return), // |
| 2286 }}, | 2530 }}, |
| 2287 {"outer: {\n" | 2531 {"outer: {\n" |
| 2288 " let y = 10;" | 2532 " let y = 10;" |
| 2289 " function f() { return y; }\n" | 2533 " function f() { return y; }\n" |
| 2290 " break outer;\n" | 2534 " break outer;\n" |
| 2291 "}\n", | 2535 "}\n", |
| 2292 5 * kPointerSize, | 2536 5 * kPointerSize, |
| 2293 1, | 2537 1, |
| 2294 39, | 2538 40, |
| 2295 { | 2539 { |
| 2540 B(StackCheck), // |
| 2296 B(LdaConstant), U8(0), // | 2541 B(LdaConstant), U8(0), // |
| 2297 B(Star), R(3), // | 2542 B(Star), R(3), // |
| 2298 B(Ldar), R(closure), // | 2543 B(Ldar), R(closure), // |
| 2299 B(Star), R(4), // | 2544 B(Star), R(4), // |
| 2300 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // | 2545 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // |
| 2301 B(PushContext), R(2), // | 2546 B(PushContext), R(2), // |
| 2302 B(LdaTheHole), // | 2547 B(LdaTheHole), // |
| 2303 B(StaContextSlot), R(context), U8(4), // | 2548 B(StaContextSlot), R(context), U8(4), // |
| 2304 B(CreateClosure), U8(1), U8(0), // | 2549 B(CreateClosure), U8(1), U8(0), // |
| 2305 B(Star), R(0), // | 2550 B(Star), R(0), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2320 " inner: {\n" | 2565 " inner: {\n" |
| 2321 " let y = 2;\n" | 2566 " let y = 2;\n" |
| 2322 " function f() { return x + y; }\n" | 2567 " function f() { return x + y; }\n" |
| 2323 " if (y) break outer;\n" | 2568 " if (y) break outer;\n" |
| 2324 " y = 3;\n" | 2569 " y = 3;\n" |
| 2325 " }\n" | 2570 " }\n" |
| 2326 "}\n" | 2571 "}\n" |
| 2327 "x = 4;", | 2572 "x = 4;", |
| 2328 6 * kPointerSize, | 2573 6 * kPointerSize, |
| 2329 1, | 2574 1, |
| 2330 72, | 2575 73, |
| 2331 { | 2576 { |
| 2332 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 2577 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 2333 U8(1), // | 2578 /* */ U8(1), // |
| 2334 B(PushContext), R(2), // | 2579 B(PushContext), R(2), // |
| 2335 B(LdaTheHole), // | 2580 B(LdaTheHole), // |
| 2336 B(StaContextSlot), R(context), U8(4), // | 2581 B(StaContextSlot), R(context), U8(4), // |
| 2582 B(StackCheck), // |
| 2337 B(LdaSmi8), U8(1), // | 2583 B(LdaSmi8), U8(1), // |
| 2338 B(StaContextSlot), R(context), U8(4), // | 2584 B(StaContextSlot), R(context), U8(4), // |
| 2339 B(LdaConstant), U8(0), // | 2585 B(LdaConstant), U8(0), // |
| 2340 B(Star), R(4), // | 2586 B(Star), R(4), // |
| 2341 B(Ldar), R(closure), // | 2587 B(Ldar), R(closure), // |
| 2342 B(Star), R(5), // | 2588 B(Star), R(5), // |
| 2343 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // | 2589 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| 2344 B(PushContext), R(3), // | 2590 B(PushContext), R(3), // |
| 2345 B(LdaTheHole), // | 2591 B(LdaTheHole), // |
| 2346 B(StaContextSlot), R(context), U8(4), // | 2592 B(StaContextSlot), R(context), U8(4), // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2359 B(PopContext), R(3), // | 2605 B(PopContext), R(3), // |
| 2360 B(LdaSmi8), U8(4), // | 2606 B(LdaSmi8), U8(4), // |
| 2361 B(StaContextSlot), R(context), U8(4), // | 2607 B(StaContextSlot), R(context), U8(4), // |
| 2362 B(LdaUndefined), // | 2608 B(LdaUndefined), // |
| 2363 B(Return), // | 2609 B(Return), // |
| 2364 }, | 2610 }, |
| 2365 2, | 2611 2, |
| 2366 {InstanceType::FIXED_ARRAY_TYPE, | 2612 {InstanceType::FIXED_ARRAY_TYPE, |
| 2367 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2613 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2368 }; | 2614 }; |
| 2615 // clang-format on |
| 2369 | 2616 |
| 2370 for (size_t i = 0; i < arraysize(snippets); i++) { | 2617 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2371 Handle<BytecodeArray> bytecode_array = | 2618 Handle<BytecodeArray> bytecode_array = |
| 2372 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2619 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2373 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2620 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2374 } | 2621 } |
| 2375 } | 2622 } |
| 2376 | 2623 |
| 2377 | 2624 |
| 2378 TEST(BasicLoops) { | 2625 TEST(BasicLoops) { |
| 2379 InitializedHandleScope handle_scope; | 2626 InitializedHandleScope handle_scope; |
| 2380 BytecodeGeneratorHelper helper; | 2627 BytecodeGeneratorHelper helper; |
| 2381 | 2628 |
| 2382 int closure = Register::function_closure().index(); | 2629 int closure = Register::function_closure().index(); |
| 2383 int context = Register::current_context().index(); | 2630 int context = Register::current_context().index(); |
| 2384 | 2631 |
| 2632 // clang-format off |
| 2385 ExpectedSnippet<InstanceType> snippets[] = { | 2633 ExpectedSnippet<InstanceType> snippets[] = { |
| 2386 {"var x = 0;\n" | 2634 {"var x = 0;\n" |
| 2387 "while (false) { x = 99; break; continue; }\n" | 2635 "while (false) { x = 99; break; continue; }\n" |
| 2388 "return x;", | 2636 "return x;", |
| 2389 1 * kPointerSize, | 2637 1 * kPointerSize, |
| 2390 1, | 2638 1, |
| 2391 4, | 2639 5, |
| 2392 { | 2640 { |
| 2641 B(StackCheck), // |
| 2393 B(LdaZero), // | 2642 B(LdaZero), // |
| 2394 B(Star), R(0), // | 2643 B(Star), R(0), // |
| 2395 B(Return) // | 2644 B(Return) // |
| 2396 }}, | 2645 }}, |
| 2397 {"var x = 0;" | 2646 {"var x = 0;" |
| 2398 "while (false) {" | 2647 "while (false) {" |
| 2399 " x = x + 1;" | 2648 " x = x + 1;" |
| 2400 "};" | 2649 "};" |
| 2401 "return x;", | 2650 "return x;", |
| 2402 1 * kPointerSize, | 2651 1 * kPointerSize, |
| 2403 1, | 2652 1, |
| 2404 4, | 2653 5, |
| 2405 { | 2654 { |
| 2655 B(StackCheck), // |
| 2406 B(LdaZero), // | 2656 B(LdaZero), // |
| 2407 B(Star), R(0), // | 2657 B(Star), R(0), // |
| 2408 B(Return), // | 2658 B(Return), // |
| 2409 }, | 2659 }, |
| 2410 0}, | 2660 0}, |
| 2411 {"var x = 0;" | 2661 {"var x = 0;" |
| 2412 "var y = 1;" | 2662 "var y = 1;" |
| 2413 "while (x < 10) {" | 2663 "while (x < 10) {" |
| 2414 " y = y * 12;" | 2664 " y = y * 12;" |
| 2415 " x = x + 1;" | 2665 " x = x + 1;" |
| 2416 " if (x == 3) continue;" | 2666 " if (x == 3) continue;" |
| 2417 " if (x == 4) break;" | 2667 " if (x == 4) break;" |
| 2418 "}" | 2668 "}" |
| 2419 "return y;", | 2669 "return y;", |
| 2420 3 * kPointerSize, | 2670 3 * kPointerSize, |
| 2421 1, | 2671 1, |
| 2422 64, | 2672 66, |
| 2423 { | 2673 { |
| 2674 B(StackCheck), // |
| 2424 B(LdaZero), // | 2675 B(LdaZero), // |
| 2425 B(Star), R(0), // | 2676 B(Star), R(0), // |
| 2426 B(LdaSmi8), U8(1), // | 2677 B(LdaSmi8), U8(1), // |
| 2427 B(Star), R(1), // | 2678 B(Star), R(1), // |
| 2428 B(Ldar), R(0), // | 2679 B(Ldar), R(0), // |
| 2429 B(Star), R(2), // | 2680 B(Star), R(2), // |
| 2430 B(LdaSmi8), U8(10), // | 2681 B(LdaSmi8), U8(10), // |
| 2431 B(TestLessThan), R(2), // | 2682 B(TestLessThan), R(2), // |
| 2432 B(JumpIfFalse), U8(46), // | 2683 B(JumpIfFalse), U8(47), // |
| 2684 B(StackCheck), // |
| 2433 B(Ldar), R(1), // | 2685 B(Ldar), R(1), // |
| 2434 B(Star), R(2), // | 2686 B(Star), R(2), // |
| 2435 B(LdaSmi8), U8(12), // | 2687 B(LdaSmi8), U8(12), // |
| 2436 B(Mul), R(2), // | 2688 B(Mul), R(2), // |
| 2437 B(Star), R(1), // | 2689 B(Star), R(1), // |
| 2438 B(Ldar), R(0), // | 2690 B(Ldar), R(0), // |
| 2439 B(Star), R(2), // | 2691 B(Star), R(2), // |
| 2440 B(LdaSmi8), U8(1), // | 2692 B(LdaSmi8), U8(1), // |
| 2441 B(Add), R(2), // | 2693 B(Add), R(2), // |
| 2442 B(Star), R(0), // | 2694 B(Star), R(0), // |
| 2443 B(Star), R(2), // | 2695 B(Star), R(2), // |
| 2444 B(LdaSmi8), U8(3), // | 2696 B(LdaSmi8), U8(3), // |
| 2445 B(TestEqual), R(2), // | 2697 B(TestEqual), R(2), // |
| 2446 B(JumpIfFalse), U8(4), // | 2698 B(JumpIfFalse), U8(4), // |
| 2447 B(Jump), U8(-38), // | 2699 B(Jump), U8(-39), // |
| 2448 B(Ldar), R(0), // | 2700 B(Ldar), R(0), // |
| 2449 B(Star), R(2), // | 2701 B(Star), R(2), // |
| 2450 B(LdaSmi8), U8(4), // | 2702 B(LdaSmi8), U8(4), // |
| 2451 B(TestEqual), R(2), // | 2703 B(TestEqual), R(2), // |
| 2452 B(JumpIfFalse), U8(4), // | 2704 B(JumpIfFalse), U8(4), // |
| 2453 B(Jump), U8(4), // | 2705 B(Jump), U8(4), // |
| 2454 B(Jump), U8(-52), // | 2706 B(Jump), U8(-53), // |
| 2455 B(Ldar), R(1), // | 2707 B(Ldar), R(1), // |
| 2456 B(Return), // | 2708 B(Return), // |
| 2457 }, | 2709 }, |
| 2458 0}, | 2710 0}, |
| 2459 {"var i = 0;" | 2711 {"var i = 0;" |
| 2460 "while (true) {" | 2712 "while (true) {" |
| 2461 " if (i < 0) continue;" | 2713 " if (i < 0) continue;" |
| 2462 " if (i == 3) break;" | 2714 " if (i == 3) break;" |
| 2463 " if (i == 4) break;" | 2715 " if (i == 4) break;" |
| 2464 " if (i == 10) continue;" | 2716 " if (i == 10) continue;" |
| 2465 " if (i == 5) break;" | 2717 " if (i == 5) break;" |
| 2466 " i = i + 1;" | 2718 " i = i + 1;" |
| 2467 "}" | 2719 "}" |
| 2468 "return i;", | 2720 "return i;", |
| 2469 2 * kPointerSize, | 2721 2 * kPointerSize, |
| 2470 1, | 2722 1, |
| 2471 77, | 2723 79, |
| 2472 { | 2724 { |
| 2725 B(StackCheck), // |
| 2473 B(LdaZero), // | 2726 B(LdaZero), // |
| 2474 B(Star), R(0), // | 2727 B(Star), R(0), // |
| 2728 B(StackCheck), // |
| 2475 B(Ldar), R(0), // | 2729 B(Ldar), R(0), // |
| 2476 B(Star), R(1), // | 2730 B(Star), R(1), // |
| 2477 B(LdaZero), // | 2731 B(LdaZero), // |
| 2478 B(TestLessThan), R(1), // | 2732 B(TestLessThan), R(1), // |
| 2479 B(JumpIfFalse), U8(4), // | 2733 B(JumpIfFalse), U8(4), // |
| 2480 B(Jump), U8(-9), // | 2734 B(Jump), U8(-10), // |
| 2481 B(Ldar), R(0), // | 2735 B(Ldar), R(0), // |
| 2482 B(Star), R(1), // | 2736 B(Star), R(1), // |
| 2483 B(LdaSmi8), U8(3), // | 2737 B(LdaSmi8), U8(3), // |
| 2484 B(TestEqual), R(1), // | 2738 B(TestEqual), R(1), // |
| 2485 B(JumpIfFalse), U8(4), // | 2739 B(JumpIfFalse), U8(4), // |
| 2486 B(Jump), U8(50), // | 2740 B(Jump), U8(50), // |
| 2487 B(Ldar), R(0), // | 2741 B(Ldar), R(0), // |
| 2488 B(Star), R(1), // | 2742 B(Star), R(1), // |
| 2489 B(LdaSmi8), U8(4), // | 2743 B(LdaSmi8), U8(4), // |
| 2490 B(TestEqual), R(1), // | 2744 B(TestEqual), R(1), // |
| 2491 B(JumpIfFalse), U8(4), // | 2745 B(JumpIfFalse), U8(4), // |
| 2492 B(Jump), U8(38), // | 2746 B(Jump), U8(38), // |
| 2493 B(Ldar), R(0), // | 2747 B(Ldar), R(0), // |
| 2494 B(Star), R(1), // | 2748 B(Star), R(1), // |
| 2495 B(LdaSmi8), U8(10), // | 2749 B(LdaSmi8), U8(10), // |
| 2496 B(TestEqual), R(1), // | 2750 B(TestEqual), R(1), // |
| 2497 B(JumpIfFalse), U8(4), // | 2751 B(JumpIfFalse), U8(4), // |
| 2498 B(Jump), U8(-45), // | 2752 B(Jump), U8(-46), // |
| 2499 B(Ldar), R(0), // | 2753 B(Ldar), R(0), // |
| 2500 B(Star), R(1), // | 2754 B(Star), R(1), // |
| 2501 B(LdaSmi8), U8(5), // | 2755 B(LdaSmi8), U8(5), // |
| 2502 B(TestEqual), R(1), // | 2756 B(TestEqual), R(1), // |
| 2503 B(JumpIfFalse), U8(4), // | 2757 B(JumpIfFalse), U8(4), // |
| 2504 B(Jump), U8(14), // | 2758 B(Jump), U8(14), // |
| 2505 B(Ldar), R(0), // | 2759 B(Ldar), R(0), // |
| 2506 B(Star), R(1), // | 2760 B(Star), R(1), // |
| 2507 B(LdaSmi8), U8(1), // | 2761 B(LdaSmi8), U8(1), // |
| 2508 B(Add), R(1), // | 2762 B(Add), R(1), // |
| 2509 B(Star), R(0), // | 2763 B(Star), R(0), // |
| 2510 B(Jump), U8(-69), // | 2764 B(Jump), U8(-70), // |
| 2511 B(Ldar), R(0), // | 2765 B(Ldar), R(0), // |
| 2512 B(Return), // | 2766 B(Return), // |
| 2513 }, | 2767 }, |
| 2514 0}, | 2768 0}, |
| 2515 {"var i = 0;" | 2769 {"var i = 0;" |
| 2516 "while (true) {" | 2770 "while (true) {" |
| 2517 " while (i < 3) {" | 2771 " while (i < 3) {" |
| 2518 " if (i == 2) break;" | 2772 " if (i == 2) break;" |
| 2519 " i = i + 1;" | 2773 " i = i + 1;" |
| 2520 " }" | 2774 " }" |
| 2521 " i = i + 1;" | 2775 " i = i + 1;" |
| 2522 " break;" | 2776 " break;" |
| 2523 "}" | 2777 "}" |
| 2524 "return i;", | 2778 "return i;", |
| 2525 2 * kPointerSize, | 2779 2 * kPointerSize, |
| 2526 1, | 2780 1, |
| 2527 54, | 2781 57, |
| 2528 { | 2782 { |
| 2783 B(StackCheck), // |
| 2529 B(LdaZero), // | 2784 B(LdaZero), // |
| 2530 B(Star), R(0), // | 2785 B(Star), R(0), // |
| 2786 B(StackCheck), // |
| 2531 B(Ldar), R(0), // | 2787 B(Ldar), R(0), // |
| 2532 B(Star), R(1), // | 2788 B(Star), R(1), // |
| 2533 B(LdaSmi8), U8(3), // | 2789 B(LdaSmi8), U8(3), // |
| 2534 B(TestLessThan), R(1), // | 2790 B(TestLessThan), R(1), // |
| 2535 B(JumpIfFalse), U8(26), // | 2791 B(JumpIfFalse), U8(27), // |
| 2792 B(StackCheck), // |
| 2536 B(Ldar), R(0), // | 2793 B(Ldar), R(0), // |
| 2537 B(Star), R(1), // | 2794 B(Star), R(1), // |
| 2538 B(LdaSmi8), U8(2), // | 2795 B(LdaSmi8), U8(2), // |
| 2539 B(TestEqual), R(1), // | 2796 B(TestEqual), R(1), // |
| 2540 B(JumpIfFalse), U8(4), // | 2797 B(JumpIfFalse), U8(4), // |
| 2541 B(Jump), U8(14), // | 2798 B(Jump), U8(14), // |
| 2542 B(Ldar), R(0), // | 2799 B(Ldar), R(0), // |
| 2543 B(Star), R(1), // | 2800 B(Star), R(1), // |
| 2544 B(LdaSmi8), U8(1), // | 2801 B(LdaSmi8), U8(1), // |
| 2545 B(Add), R(1), // | 2802 B(Add), R(1), // |
| 2546 B(Star), R(0), // | 2803 B(Star), R(0), // |
| 2547 B(Jump), U8(-32), // | 2804 B(Jump), U8(-33), // |
| 2548 B(Ldar), R(0), // | 2805 B(Ldar), R(0), // |
| 2549 B(Star), R(1), // | 2806 B(Star), R(1), // |
| 2550 B(LdaSmi8), U8(1), // | 2807 B(LdaSmi8), U8(1), // |
| 2551 B(Add), R(1), // | 2808 B(Add), R(1), // |
| 2552 B(Star), R(0), // | 2809 B(Star), R(0), // |
| 2553 B(Jump), U8(4), // | 2810 B(Jump), U8(4), // |
| 2554 B(Jump), U8(-46), // | 2811 B(Jump), U8(-48), // |
| 2555 B(Ldar), R(0), // | 2812 B(Ldar), R(0), // |
| 2556 B(Return), // | 2813 B(Return), // |
| 2557 }, | 2814 }, |
| 2558 0}, | 2815 0}, |
| 2559 {"var x = 10;" | 2816 {"var x = 10;" |
| 2560 "var y = 1;" | 2817 "var y = 1;" |
| 2561 "while (x) {" | 2818 "while (x) {" |
| 2562 " y = y * 12;" | 2819 " y = y * 12;" |
| 2563 " x = x - 1;" | 2820 " x = x - 1;" |
| 2564 "}" | 2821 "}" |
| 2565 "return y;", | 2822 "return y;", |
| 2566 3 * kPointerSize, | 2823 3 * kPointerSize, |
| 2567 1, | 2824 1, |
| 2568 37, | 2825 39, |
| 2569 { | 2826 { |
| 2827 B(StackCheck), // |
| 2570 B(LdaSmi8), U8(10), // | 2828 B(LdaSmi8), U8(10), // |
| 2571 B(Star), R(0), // | 2829 B(Star), R(0), // |
| 2572 B(LdaSmi8), U8(1), // | 2830 B(LdaSmi8), U8(1), // |
| 2573 B(Star), R(1), // | 2831 B(Star), R(1), // |
| 2574 B(Ldar), R(0), // | 2832 B(Ldar), R(0), // |
| 2575 B(JumpIfToBooleanFalse), U8(24), // | 2833 B(JumpIfToBooleanFalse), U8(25), // |
| 2834 B(StackCheck), // |
| 2576 B(Ldar), R(1), // | 2835 B(Ldar), R(1), // |
| 2577 B(Star), R(2), // | 2836 B(Star), R(2), // |
| 2578 B(LdaSmi8), U8(12), // | 2837 B(LdaSmi8), U8(12), // |
| 2579 B(Mul), R(2), // | 2838 B(Mul), R(2), // |
| 2580 B(Star), R(1), // | 2839 B(Star), R(1), // |
| 2581 B(Ldar), R(0), // | 2840 B(Ldar), R(0), // |
| 2582 B(Star), R(2), // | 2841 B(Star), R(2), // |
| 2583 B(LdaSmi8), U8(1), // | 2842 B(LdaSmi8), U8(1), // |
| 2584 B(Sub), R(2), // | 2843 B(Sub), R(2), // |
| 2585 B(Star), R(0), // | 2844 B(Star), R(0), // |
| 2586 B(Jump), U8(-24), // | 2845 B(Jump), U8(-25), // |
| 2587 B(Ldar), R(1), // | 2846 B(Ldar), R(1), // |
| 2588 B(Return), // | 2847 B(Return), // |
| 2589 }, | 2848 }, |
| 2590 0}, | 2849 0}, |
| 2591 {"var x = 0; var y = 1;" | 2850 {"var x = 0; var y = 1;" |
| 2592 "do {" | 2851 "do {" |
| 2593 " y = y * 10;" | 2852 " y = y * 10;" |
| 2594 " if (x == 5) break;" | 2853 " if (x == 5) break;" |
| 2595 " if (x == 6) continue;" | 2854 " if (x == 6) continue;" |
| 2596 " x = x + 1;" | 2855 " x = x + 1;" |
| 2597 "} while (x < 10);" | 2856 "} while (x < 10);" |
| 2598 "return y;", | 2857 "return y;", |
| 2599 3 * kPointerSize, | 2858 3 * kPointerSize, |
| 2600 1, | 2859 1, |
| 2601 64, | 2860 66, |
| 2602 { | 2861 { |
| 2862 B(StackCheck), // |
| 2603 B(LdaZero), // | 2863 B(LdaZero), // |
| 2604 B(Star), R(0), // | 2864 B(Star), R(0), // |
| 2605 B(LdaSmi8), U8(1), // | 2865 B(LdaSmi8), U8(1), // |
| 2606 B(Star), R(1), // | 2866 B(Star), R(1), // |
| 2867 B(StackCheck), // |
| 2607 B(Ldar), R(1), // | 2868 B(Ldar), R(1), // |
| 2608 B(Star), R(2), // | 2869 B(Star), R(2), // |
| 2609 B(LdaSmi8), U8(10), // | 2870 B(LdaSmi8), U8(10), // |
| 2610 B(Mul), R(2), // | 2871 B(Mul), R(2), // |
| 2611 B(Star), R(1), // | 2872 B(Star), R(1), // |
| 2612 B(Ldar), R(0), // | 2873 B(Ldar), R(0), // |
| 2613 B(Star), R(2), // | 2874 B(Star), R(2), // |
| 2614 B(LdaSmi8), U8(5), // | 2875 B(LdaSmi8), U8(5), // |
| 2615 B(TestEqual), R(2), // | 2876 B(TestEqual), R(2), // |
| 2616 B(JumpIfFalse), U8(4), // | 2877 B(JumpIfFalse), U8(4), // |
| 2617 B(Jump), U8(34), // | 2878 B(Jump), U8(34), // |
| 2618 B(Ldar), R(0), // | 2879 B(Ldar), R(0), // |
| 2619 B(Star), R(2), // | 2880 B(Star), R(2), // |
| 2620 B(LdaSmi8), U8(6), // | 2881 B(LdaSmi8), U8(6), // |
| 2621 B(TestEqual), R(2), // | 2882 B(TestEqual), R(2), // |
| 2622 B(JumpIfFalse), U8(4), // | 2883 B(JumpIfFalse), U8(4), // |
| 2623 B(Jump), U8(12), // | 2884 B(Jump), U8(12), // |
| 2624 B(Ldar), R(0), // | 2885 B(Ldar), R(0), // |
| 2625 B(Star), R(2), // | 2886 B(Star), R(2), // |
| 2626 B(LdaSmi8), U8(1), // | 2887 B(LdaSmi8), U8(1), // |
| 2627 B(Add), R(2), // | 2888 B(Add), R(2), // |
| 2628 B(Star), R(0), // | 2889 B(Star), R(0), // |
| 2629 B(Ldar), R(0), // | 2890 B(Ldar), R(0), // |
| 2630 B(Star), R(2), // | 2891 B(Star), R(2), // |
| 2631 B(LdaSmi8), U8(10), // | 2892 B(LdaSmi8), U8(10), // |
| 2632 B(TestLessThan), R(2), // | 2893 B(TestLessThan), R(2), // |
| 2633 B(JumpIfTrue), U8(-52), // | 2894 B(JumpIfTrue), U8(-53), // |
| 2634 B(Ldar), R(1), // | 2895 B(Ldar), R(1), // |
| 2635 B(Return), // | 2896 B(Return), // |
| 2636 }, | 2897 }, |
| 2637 0}, | 2898 0}, |
| 2638 {"var x = 10;" | 2899 {"var x = 10;" |
| 2639 "var y = 1;" | 2900 "var y = 1;" |
| 2640 "do {" | 2901 "do {" |
| 2641 " y = y * 12;" | 2902 " y = y * 12;" |
| 2642 " x = x - 1;" | 2903 " x = x - 1;" |
| 2643 "} while (x);" | 2904 "} while (x);" |
| 2644 "return y;", | 2905 "return y;", |
| 2645 3 * kPointerSize, | 2906 3 * kPointerSize, |
| 2646 1, | 2907 1, |
| 2647 35, | 2908 37, |
| 2648 { | 2909 { |
| 2910 B(StackCheck), // |
| 2649 B(LdaSmi8), U8(10), // | 2911 B(LdaSmi8), U8(10), // |
| 2650 B(Star), R(0), // | 2912 B(Star), R(0), // |
| 2651 B(LdaSmi8), U8(1), // | 2913 B(LdaSmi8), U8(1), // |
| 2652 B(Star), R(1), // | 2914 B(Star), R(1), // |
| 2915 B(StackCheck), // |
| 2653 B(Ldar), R(1), // | 2916 B(Ldar), R(1), // |
| 2654 B(Star), R(2), // | 2917 B(Star), R(2), // |
| 2655 B(LdaSmi8), U8(12), // | 2918 B(LdaSmi8), U8(12), // |
| 2656 B(Mul), R(2), // | 2919 B(Mul), R(2), // |
| 2657 B(Star), R(1), // | 2920 B(Star), R(1), // |
| 2658 B(Ldar), R(0), // | 2921 B(Ldar), R(0), // |
| 2659 B(Star), R(2), // | 2922 B(Star), R(2), // |
| 2660 B(LdaSmi8), U8(1), // | 2923 B(LdaSmi8), U8(1), // |
| 2661 B(Sub), R(2), // | 2924 B(Sub), R(2), // |
| 2662 B(Star), R(0), // | 2925 B(Star), R(0), // |
| 2663 B(Ldar), R(0), // | 2926 B(Ldar), R(0), // |
| 2664 B(JumpIfToBooleanTrue), U8(-22), // | 2927 B(JumpIfToBooleanTrue), U8(-23), // |
| 2665 B(Ldar), R(1), // | 2928 B(Ldar), R(1), // |
| 2666 B(Return), // | 2929 B(Return), // |
| 2667 }, | 2930 }, |
| 2668 0}, | 2931 0}, |
| 2669 {"var x = 0; var y = 1;" | 2932 {"var x = 0; var y = 1;" |
| 2670 "do {" | 2933 "do {" |
| 2671 " y = y * 10;" | 2934 " y = y * 10;" |
| 2672 " if (x == 5) break;" | 2935 " if (x == 5) break;" |
| 2673 " x = x + 1;" | 2936 " x = x + 1;" |
| 2674 " if (x == 6) continue;" | 2937 " if (x == 6) continue;" |
| 2675 "} while (false);" | 2938 "} while (false);" |
| 2676 "return y;", | 2939 "return y;", |
| 2677 3 * kPointerSize, | 2940 3 * kPointerSize, |
| 2678 1, | 2941 1, |
| 2679 52, | 2942 54, |
| 2680 { | 2943 { |
| 2944 B(StackCheck), // |
| 2681 B(LdaZero), // | 2945 B(LdaZero), // |
| 2682 B(Star), R(0), // | 2946 B(Star), R(0), // |
| 2683 B(LdaSmi8), U8(1), // | 2947 B(LdaSmi8), U8(1), // |
| 2684 B(Star), R(1), // | 2948 B(Star), R(1), // |
| 2949 B(StackCheck), // |
| 2685 B(Ldar), R(1), // | 2950 B(Ldar), R(1), // |
| 2686 B(Star), R(2), // | 2951 B(Star), R(2), // |
| 2687 B(LdaSmi8), U8(10), // | 2952 B(LdaSmi8), U8(10), // |
| 2688 B(Mul), R(2), // | 2953 B(Mul), R(2), // |
| 2689 B(Star), R(1), // | 2954 B(Star), R(1), // |
| 2690 B(Ldar), R(0), // | 2955 B(Ldar), R(0), // |
| 2691 B(Star), R(2), // | 2956 B(Star), R(2), // |
| 2692 B(LdaSmi8), U8(5), // | 2957 B(LdaSmi8), U8(5), // |
| 2693 B(TestEqual), R(2), // | 2958 B(TestEqual), R(2), // |
| 2694 B(JumpIfFalse), U8(4), // | 2959 B(JumpIfFalse), U8(4), // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2710 {"var x = 0; var y = 1;" | 2975 {"var x = 0; var y = 1;" |
| 2711 "do {" | 2976 "do {" |
| 2712 " y = y * 10;" | 2977 " y = y * 10;" |
| 2713 " if (x == 5) break;" | 2978 " if (x == 5) break;" |
| 2714 " x = x + 1;" | 2979 " x = x + 1;" |
| 2715 " if (x == 6) continue;" | 2980 " if (x == 6) continue;" |
| 2716 "} while (true);" | 2981 "} while (true);" |
| 2717 "return y;", | 2982 "return y;", |
| 2718 3 * kPointerSize, | 2983 3 * kPointerSize, |
| 2719 1, | 2984 1, |
| 2720 54, | 2985 56, |
| 2721 { | 2986 { |
| 2987 B(StackCheck), // |
| 2722 B(LdaZero), // | 2988 B(LdaZero), // |
| 2723 B(Star), R(0), // | 2989 B(Star), R(0), // |
| 2724 B(LdaSmi8), U8(1), // | 2990 B(LdaSmi8), U8(1), // |
| 2725 B(Star), R(1), // | 2991 B(Star), R(1), // |
| 2992 B(StackCheck), // |
| 2726 B(Ldar), R(1), // | 2993 B(Ldar), R(1), // |
| 2727 B(Star), R(2), // | 2994 B(Star), R(2), // |
| 2728 B(LdaSmi8), U8(10), // | 2995 B(LdaSmi8), U8(10), // |
| 2729 B(Mul), R(2), // | 2996 B(Mul), R(2), // |
| 2730 B(Star), R(1), // | 2997 B(Star), R(1), // |
| 2731 B(Ldar), R(0), // | 2998 B(Ldar), R(0), // |
| 2732 B(Star), R(2), // | 2999 B(Star), R(2), // |
| 2733 B(LdaSmi8), U8(5), // | 3000 B(LdaSmi8), U8(5), // |
| 2734 B(TestEqual), R(2), // | 3001 B(TestEqual), R(2), // |
| 2735 B(JumpIfFalse), U8(4), // | 3002 B(JumpIfFalse), U8(4), // |
| 2736 B(Jump), U8(24), // | 3003 B(Jump), U8(24), // |
| 2737 B(Ldar), R(0), // | 3004 B(Ldar), R(0), // |
| 2738 B(Star), R(2), // | 3005 B(Star), R(2), // |
| 2739 B(LdaSmi8), U8(1), // | 3006 B(LdaSmi8), U8(1), // |
| 2740 B(Add), R(2), // | 3007 B(Add), R(2), // |
| 2741 B(Star), R(0), // | 3008 B(Star), R(0), // |
| 2742 B(Star), R(2), // | 3009 B(Star), R(2), // |
| 2743 B(LdaSmi8), U8(6), // | 3010 B(LdaSmi8), U8(6), // |
| 2744 B(TestEqual), R(2), // | 3011 B(TestEqual), R(2), // |
| 2745 B(JumpIfFalse), U8(4), // | 3012 B(JumpIfFalse), U8(4), // |
| 2746 B(Jump), U8(-40), // | 3013 B(Jump), U8(-41), // |
| 2747 B(Jump), U8(-42), // | 3014 B(Jump), U8(-43), // |
| 2748 B(Ldar), R(1), // | 3015 B(Ldar), R(1), // |
| 2749 B(Return), // | 3016 B(Return), // |
| 2750 }, | 3017 }, |
| 2751 0}, | 3018 0}, |
| 2752 {"var x = 0; " | 3019 {"var x = 0; " |
| 2753 "for (;;) {" | 3020 "for (;;) {" |
| 2754 " if (x == 1) break;" | 3021 " if (x == 1) break;" |
| 2755 " if (x == 2) continue;" | 3022 " if (x == 2) continue;" |
| 2756 " x = x + 1;" | 3023 " x = x + 1;" |
| 2757 "}", | 3024 "}", |
| 2758 2 * kPointerSize, | 3025 2 * kPointerSize, |
| 2759 1, | 3026 1, |
| 2760 41, | 3027 43, |
| 2761 { | 3028 { |
| 3029 B(StackCheck), // |
| 2762 B(LdaZero), // | 3030 B(LdaZero), // |
| 2763 B(Star), R(0), // | 3031 B(Star), R(0), // |
| 3032 B(StackCheck), // |
| 2764 B(Ldar), R(0), // | 3033 B(Ldar), R(0), // |
| 2765 B(Star), R(1), // | 3034 B(Star), R(1), // |
| 2766 B(LdaSmi8), U8(1), // | 3035 B(LdaSmi8), U8(1), // |
| 2767 B(TestEqual), R(1), // | 3036 B(TestEqual), R(1), // |
| 2768 B(JumpIfFalse), U8(4), // | 3037 B(JumpIfFalse), U8(4), // |
| 2769 B(Jump), U8(26), // | 3038 B(Jump), U8(26), // |
| 2770 B(Ldar), R(0), // | 3039 B(Ldar), R(0), // |
| 2771 B(Star), R(1), // | 3040 B(Star), R(1), // |
| 2772 B(LdaSmi8), U8(2), // | 3041 B(LdaSmi8), U8(2), // |
| 2773 B(TestEqual), R(1), // | 3042 B(TestEqual), R(1), // |
| 2774 B(JumpIfFalse), U8(4), // | 3043 B(JumpIfFalse), U8(4), // |
| 2775 B(Jump), U8(-22), // | 3044 B(Jump), U8(-23), // |
| 2776 B(Ldar), R(0), // | 3045 B(Ldar), R(0), // |
| 2777 B(Star), R(1), // | 3046 B(Star), R(1), // |
| 2778 B(LdaSmi8), U8(1), // | 3047 B(LdaSmi8), U8(1), // |
| 2779 B(Add), R(1), // | 3048 B(Add), R(1), // |
| 2780 B(Star), R(0), // | 3049 B(Star), R(0), // |
| 2781 B(Jump), U8(-34), // | 3050 B(Jump), U8(-35), // |
| 2782 B(LdaUndefined), // | 3051 B(LdaUndefined), // |
| 2783 B(Return), // | 3052 B(Return), // |
| 2784 }, | 3053 }, |
| 2785 0}, | 3054 0}, |
| 2786 {"for (var x = 0;;) {" | 3055 {"for (var x = 0;;) {" |
| 2787 " if (x == 1) break;" | 3056 " if (x == 1) break;" |
| 2788 " if (x == 2) continue;" | 3057 " if (x == 2) continue;" |
| 2789 " x = x + 1;" | 3058 " x = x + 1;" |
| 2790 "}", | 3059 "}", |
| 2791 2 * kPointerSize, | 3060 2 * kPointerSize, |
| 2792 1, | 3061 1, |
| 2793 41, | 3062 43, |
| 2794 { | 3063 { |
| 3064 B(StackCheck), // |
| 2795 B(LdaZero), // | 3065 B(LdaZero), // |
| 2796 B(Star), R(0), // | 3066 B(Star), R(0), // |
| 3067 B(StackCheck), // |
| 2797 B(Ldar), R(0), // | 3068 B(Ldar), R(0), // |
| 2798 B(Star), R(1), // | 3069 B(Star), R(1), // |
| 2799 B(LdaSmi8), U8(1), // | 3070 B(LdaSmi8), U8(1), // |
| 2800 B(TestEqual), R(1), // | 3071 B(TestEqual), R(1), // |
| 2801 B(JumpIfFalse), U8(4), // | 3072 B(JumpIfFalse), U8(4), // |
| 2802 B(Jump), U8(26), // | 3073 B(Jump), U8(26), // |
| 2803 B(Ldar), R(0), // | 3074 B(Ldar), R(0), // |
| 2804 B(Star), R(1), // | 3075 B(Star), R(1), // |
| 2805 B(LdaSmi8), U8(2), // | 3076 B(LdaSmi8), U8(2), // |
| 2806 B(TestEqual), R(1), // | 3077 B(TestEqual), R(1), // |
| 2807 B(JumpIfFalse), U8(4), // | 3078 B(JumpIfFalse), U8(4), // |
| 2808 B(Jump), U8(-22), // | 3079 B(Jump), U8(-23), // |
| 2809 B(Ldar), R(0), // | 3080 B(Ldar), R(0), // |
| 2810 B(Star), R(1), // | 3081 B(Star), R(1), // |
| 2811 B(LdaSmi8), U8(1), // | 3082 B(LdaSmi8), U8(1), // |
| 2812 B(Add), R(1), // | 3083 B(Add), R(1), // |
| 2813 B(Star), R(0), // | 3084 B(Star), R(0), // |
| 2814 B(Jump), U8(-34), // | 3085 B(Jump), U8(-35), // |
| 2815 B(LdaUndefined), // | 3086 B(LdaUndefined), // |
| 2816 B(Return), // | 3087 B(Return), // |
| 2817 }, | 3088 }, |
| 2818 0}, | 3089 0}, |
| 2819 {"var x = 0; " | 3090 {"var x = 0; " |
| 2820 "for (;; x = x + 1) {" | 3091 "for (;; x = x + 1) {" |
| 2821 " if (x == 1) break;" | 3092 " if (x == 1) break;" |
| 2822 " if (x == 2) continue;" | 3093 " if (x == 2) continue;" |
| 2823 "}", | 3094 "}", |
| 2824 2 * kPointerSize, | 3095 2 * kPointerSize, |
| 2825 1, | 3096 1, |
| 2826 41, | 3097 43, |
| 2827 { | 3098 { |
| 3099 B(StackCheck), // |
| 2828 B(LdaZero), // | 3100 B(LdaZero), // |
| 2829 B(Star), R(0), // | 3101 B(Star), R(0), // |
| 3102 B(StackCheck), // |
| 2830 B(Ldar), R(0), // | 3103 B(Ldar), R(0), // |
| 2831 B(Star), R(1), // | 3104 B(Star), R(1), // |
| 2832 B(LdaSmi8), U8(1), // | 3105 B(LdaSmi8), U8(1), // |
| 2833 B(TestEqual), R(1), // | 3106 B(TestEqual), R(1), // |
| 2834 B(JumpIfFalse), U8(4), // | 3107 B(JumpIfFalse), U8(4), // |
| 2835 B(Jump), U8(26), // | 3108 B(Jump), U8(26), // |
| 2836 B(Ldar), R(0), // | 3109 B(Ldar), R(0), // |
| 2837 B(Star), R(1), // | 3110 B(Star), R(1), // |
| 2838 B(LdaSmi8), U8(2), // | 3111 B(LdaSmi8), U8(2), // |
| 2839 B(TestEqual), R(1), // | 3112 B(TestEqual), R(1), // |
| 2840 B(JumpIfFalse), U8(4), // | 3113 B(JumpIfFalse), U8(4), // |
| 2841 B(Jump), U8(2), // | 3114 B(Jump), U8(2), // |
| 2842 B(Ldar), R(0), // | 3115 B(Ldar), R(0), // |
| 2843 B(Star), R(1), // | 3116 B(Star), R(1), // |
| 2844 B(LdaSmi8), U8(1), // | 3117 B(LdaSmi8), U8(1), // |
| 2845 B(Add), R(1), // | 3118 B(Add), R(1), // |
| 2846 B(Star), R(0), // | 3119 B(Star), R(0), // |
| 2847 B(Jump), U8(-34), // | 3120 B(Jump), U8(-35), // |
| 2848 B(LdaUndefined), // | 3121 B(LdaUndefined), // |
| 2849 B(Return), // | 3122 B(Return), // |
| 2850 }, | 3123 }, |
| 2851 0}, | 3124 0}, |
| 2852 {"for (var x = 0;; x = x + 1) {" | 3125 {"for (var x = 0;; x = x + 1) {" |
| 2853 " if (x == 1) break;" | 3126 " if (x == 1) break;" |
| 2854 " if (x == 2) continue;" | 3127 " if (x == 2) continue;" |
| 2855 "}", | 3128 "}", |
| 2856 2 * kPointerSize, | 3129 2 * kPointerSize, |
| 2857 1, | 3130 1, |
| 2858 41, | 3131 43, |
| 2859 { | 3132 { |
| 3133 B(StackCheck), // |
| 2860 B(LdaZero), // | 3134 B(LdaZero), // |
| 2861 B(Star), R(0), // | 3135 B(Star), R(0), // |
| 3136 B(StackCheck), // |
| 2862 B(Ldar), R(0), // | 3137 B(Ldar), R(0), // |
| 2863 B(Star), R(1), // | 3138 B(Star), R(1), // |
| 2864 B(LdaSmi8), U8(1), // | 3139 B(LdaSmi8), U8(1), // |
| 2865 B(TestEqual), R(1), // | 3140 B(TestEqual), R(1), // |
| 2866 B(JumpIfFalse), U8(4), // | 3141 B(JumpIfFalse), U8(4), // |
| 2867 B(Jump), U8(26), // | 3142 B(Jump), U8(26), // |
| 2868 B(Ldar), R(0), // | 3143 B(Ldar), R(0), // |
| 2869 B(Star), R(1), // | 3144 B(Star), R(1), // |
| 2870 B(LdaSmi8), U8(2), // | 3145 B(LdaSmi8), U8(2), // |
| 2871 B(TestEqual), R(1), // | 3146 B(TestEqual), R(1), // |
| 2872 B(JumpIfFalse), U8(4), // | 3147 B(JumpIfFalse), U8(4), // |
| 2873 B(Jump), U8(2), // | 3148 B(Jump), U8(2), // |
| 2874 B(Ldar), R(0), // | 3149 B(Ldar), R(0), // |
| 2875 B(Star), R(1), // | 3150 B(Star), R(1), // |
| 2876 B(LdaSmi8), U8(1), // | 3151 B(LdaSmi8), U8(1), // |
| 2877 B(Add), R(1), // | 3152 B(Add), R(1), // |
| 2878 B(Star), R(0), // | 3153 B(Star), R(0), // |
| 2879 B(Jump), U8(-34), // | 3154 B(Jump), U8(-35), // |
| 2880 B(LdaUndefined), // | 3155 B(LdaUndefined), // |
| 2881 B(Return), // | 3156 B(Return), // |
| 2882 }, | 3157 }, |
| 2883 0}, | 3158 0}, |
| 2884 {"var u = 0;" | 3159 {"var u = 0;" |
| 2885 "for (var i = 0; i < 100; i = i + 1) {" | 3160 "for (var i = 0; i < 100; i = i + 1) {" |
| 2886 " u = u + 1;" | 3161 " u = u + 1;" |
| 2887 " continue;" | 3162 " continue;" |
| 2888 "}", | 3163 "}", |
| 2889 3 * kPointerSize, | 3164 3 * kPointerSize, |
| 2890 1, | 3165 1, |
| 2891 42, | 3166 44, |
| 2892 { | 3167 { |
| 3168 B(StackCheck), // |
| 2893 B(LdaZero), // | 3169 B(LdaZero), // |
| 2894 B(Star), R(0), // | 3170 B(Star), R(0), // |
| 2895 B(LdaZero), // | 3171 B(LdaZero), // |
| 2896 B(Star), R(1), // | 3172 B(Star), R(1), // |
| 2897 B(Ldar), R(1), // | 3173 B(Ldar), R(1), // |
| 2898 B(Star), R(2), // | 3174 B(Star), R(2), // |
| 2899 B(LdaSmi8), U8(100), // | 3175 B(LdaSmi8), U8(100), // |
| 2900 B(TestLessThan), R(2), // | 3176 B(TestLessThan), R(2), // |
| 2901 B(JumpIfFalse), U8(26), // | 3177 B(JumpIfFalse), U8(27), // |
| 3178 B(StackCheck), // |
| 2902 B(Ldar), R(0), // | 3179 B(Ldar), R(0), // |
| 2903 B(Star), R(2), // | 3180 B(Star), R(2), // |
| 2904 B(LdaSmi8), U8(1), // | 3181 B(LdaSmi8), U8(1), // |
| 2905 B(Add), R(2), // | 3182 B(Add), R(2), // |
| 2906 B(Star), R(0), // | 3183 B(Star), R(0), // |
| 2907 B(Jump), U8(2), // | 3184 B(Jump), U8(2), // |
| 2908 B(Ldar), R(1), // | 3185 B(Ldar), R(1), // |
| 2909 B(Star), R(2), // | 3186 B(Star), R(2), // |
| 2910 B(LdaSmi8), U8(1), // | 3187 B(LdaSmi8), U8(1), // |
| 2911 B(Add), R(2), // | 3188 B(Add), R(2), // |
| 2912 B(Star), R(1), // | 3189 B(Star), R(1), // |
| 2913 B(Jump), U8(-32), // | 3190 B(Jump), U8(-33), // |
| 2914 B(LdaUndefined), // | 3191 B(LdaUndefined), // |
| 2915 B(Return), // | 3192 B(Return), // |
| 2916 }, | 3193 }, |
| 2917 0}, | 3194 0}, |
| 2918 {"var y = 1;" | 3195 {"var y = 1;" |
| 2919 "for (var x = 10; x; --x) {" | 3196 "for (var x = 10; x; --x) {" |
| 2920 " y = y * 12;" | 3197 " y = y * 12;" |
| 2921 "}" | 3198 "}" |
| 2922 "return y;", | 3199 "return y;", |
| 2923 3 * kPointerSize, | 3200 3 * kPointerSize, |
| 2924 1, | 3201 1, |
| 2925 33, | 3202 35, |
| 2926 { | 3203 { |
| 3204 B(StackCheck), // |
| 2927 B(LdaSmi8), U8(1), // | 3205 B(LdaSmi8), U8(1), // |
| 2928 B(Star), R(0), // | 3206 B(Star), R(0), // |
| 2929 B(LdaSmi8), U8(10), // | 3207 B(LdaSmi8), U8(10), // |
| 2930 B(Star), R(1), // | 3208 B(Star), R(1), // |
| 2931 B(Ldar), R(1), // | 3209 B(Ldar), R(1), // |
| 2932 B(JumpIfToBooleanFalse), U8(20), // | 3210 B(JumpIfToBooleanFalse), U8(21), // |
| 3211 B(StackCheck), // |
| 2933 B(Ldar), R(0), // | 3212 B(Ldar), R(0), // |
| 2934 B(Star), R(2), // | 3213 B(Star), R(2), // |
| 2935 B(LdaSmi8), U8(12), // | 3214 B(LdaSmi8), U8(12), // |
| 2936 B(Mul), R(2), // | 3215 B(Mul), R(2), // |
| 2937 B(Star), R(0), // | 3216 B(Star), R(0), // |
| 2938 B(Ldar), R(1), // | 3217 B(Ldar), R(1), // |
| 2939 B(ToNumber), // | 3218 B(ToNumber), // |
| 2940 B(Dec), // | 3219 B(Dec), // |
| 2941 B(Star), R(1), // | 3220 B(Star), R(1), // |
| 2942 B(Jump), U8(-20), // | 3221 B(Jump), U8(-21), // |
| 2943 B(Ldar), R(0), // | 3222 B(Ldar), R(0), // |
| 2944 B(Return), // | 3223 B(Return), // |
| 2945 }, | 3224 }, |
| 2946 0}, | 3225 0}, |
| 2947 {"var x = 0;" | 3226 {"var x = 0;" |
| 2948 "for (var i = 0; false; i++) {" | 3227 "for (var i = 0; false; i++) {" |
| 2949 " x = x + 1;" | 3228 " x = x + 1;" |
| 2950 "};" | 3229 "};" |
| 2951 "return x;", | 3230 "return x;", |
| 2952 2 * kPointerSize, | 3231 2 * kPointerSize, |
| 2953 1, | 3232 1, |
| 2954 9, | 3233 10, |
| 2955 { | 3234 { |
| 3235 B(StackCheck), // |
| 2956 B(LdaZero), // | 3236 B(LdaZero), // |
| 2957 B(Star), R(0), // | 3237 B(Star), R(0), // |
| 2958 B(LdaZero), // | 3238 B(LdaZero), // |
| 2959 B(Star), R(1), // | 3239 B(Star), R(1), // |
| 2960 B(Ldar), R(0), // | 3240 B(Ldar), R(0), // |
| 2961 B(Return), // | 3241 B(Return), // |
| 2962 }, | 3242 }, |
| 2963 0}, | 3243 0}, |
| 2964 {"var x = 0;" | 3244 {"var x = 0;" |
| 2965 "for (var i = 0; true; ++i) {" | 3245 "for (var i = 0; true; ++i) {" |
| 2966 " x = x + 1;" | 3246 " x = x + 1;" |
| 2967 " if (x == 20) break;" | 3247 " if (x == 20) break;" |
| 2968 "};" | 3248 "};" |
| 2969 "return x;", | 3249 "return x;", |
| 2970 3 * kPointerSize, | 3250 3 * kPointerSize, |
| 2971 1, | 3251 1, |
| 2972 37, | 3252 39, |
| 2973 { | 3253 { |
| 3254 B(StackCheck), // |
| 2974 B(LdaZero), // | 3255 B(LdaZero), // |
| 2975 B(Star), R(0), // | 3256 B(Star), R(0), // |
| 2976 B(LdaZero), // | 3257 B(LdaZero), // |
| 2977 B(Star), R(1), // | 3258 B(Star), R(1), // |
| 3259 B(StackCheck), // |
| 2978 B(Ldar), R(0), // | 3260 B(Ldar), R(0), // |
| 2979 B(Star), R(2), // | 3261 B(Star), R(2), // |
| 2980 B(LdaSmi8), U8(1), // | 3262 B(LdaSmi8), U8(1), // |
| 2981 B(Add), R(2), // | 3263 B(Add), R(2), // |
| 2982 B(Star), R(0), // | 3264 B(Star), R(0), // |
| 2983 B(Star), R(2), // | 3265 B(Star), R(2), // |
| 2984 B(LdaSmi8), U8(20), // | 3266 B(LdaSmi8), U8(20), // |
| 2985 B(TestEqual), R(2), // | 3267 B(TestEqual), R(2), // |
| 2986 B(JumpIfFalse), U8(4), // | 3268 B(JumpIfFalse), U8(4), // |
| 2987 B(Jump), U8(10), // | 3269 B(Jump), U8(10), // |
| 2988 B(Ldar), R(1), // | 3270 B(Ldar), R(1), // |
| 2989 B(ToNumber), // | 3271 B(ToNumber), // |
| 2990 B(Inc), // | 3272 B(Inc), // |
| 2991 B(Star), R(1), // | 3273 B(Star), R(1), // |
| 2992 B(Jump), U8(-26), // | 3274 B(Jump), U8(-27), // |
| 2993 B(Ldar), R(0), // | 3275 B(Ldar), R(0), // |
| 2994 B(Return), // | 3276 B(Return), // |
| 2995 }, | 3277 }, |
| 2996 0}, | 3278 0}, |
| 2997 {"var a = 0;\n" | 3279 {"var a = 0;\n" |
| 2998 "while (a) {\n" | 3280 "while (a) {\n" |
| 2999 " { \n" | 3281 " { \n" |
| 3000 " let z = 1;\n" | 3282 " let z = 1;\n" |
| 3001 " function f() { z = 2; }\n" | 3283 " function f() { z = 2; }\n" |
| 3002 " if (z) continue;\n" | 3284 " if (z) continue;\n" |
| 3003 " z++;\n" | 3285 " z++;\n" |
| 3004 " }\n" | 3286 " }\n" |
| 3005 "}\n", | 3287 "}\n", |
| 3006 6 * kPointerSize, | 3288 6 * kPointerSize, |
| 3007 1, | 3289 1, |
| 3008 65, | 3290 67, |
| 3009 { | 3291 { |
| 3292 B(StackCheck), // |
| 3010 B(LdaZero), // | 3293 B(LdaZero), // |
| 3011 B(Star), R(1), // | 3294 B(Star), R(1), // |
| 3012 B(Ldar), R(1), // | 3295 B(Ldar), R(1), // |
| 3013 B(JumpIfToBooleanFalse), U8(58), // | 3296 B(JumpIfToBooleanFalse), U8(59), // |
| 3297 B(StackCheck), // |
| 3014 B(LdaConstant), U8(0), // | 3298 B(LdaConstant), U8(0), // |
| 3015 B(Star), R(4), // | 3299 B(Star), R(4), // |
| 3016 B(Ldar), R(closure), // | 3300 B(Ldar), R(closure), // |
| 3017 B(Star), R(5), // | 3301 B(Star), R(5), // |
| 3018 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // | 3302 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| 3019 B(PushContext), R(3), // | 3303 B(PushContext), R(3), // |
| 3020 B(LdaTheHole), // | 3304 B(LdaTheHole), // |
| 3021 B(StaContextSlot), R(context), U8(4), // | 3305 B(StaContextSlot), R(context), U8(4), // |
| 3022 B(CreateClosure), U8(1), U8(0), // | 3306 B(CreateClosure), U8(1), U8(0), // |
| 3023 B(Star), R(0), // | 3307 B(Star), R(0), // |
| 3024 B(LdaSmi8), U8(1), // | 3308 B(LdaSmi8), U8(1), // |
| 3025 B(StaContextSlot), R(context), U8(4), // | 3309 B(StaContextSlot), R(context), U8(4), // |
| 3026 B(Ldar), R(0), // | 3310 B(Ldar), R(0), // |
| 3027 B(Star), R(2), // | 3311 B(Star), R(2), // |
| 3028 B(LdaContextSlot), R(context), U8(4), // | 3312 B(LdaContextSlot), R(context), U8(4), // |
| 3029 B(JumpIfToBooleanFalse), U8(6), // | 3313 B(JumpIfToBooleanFalse), U8(6), // |
| 3030 B(PopContext), R(3), // | 3314 B(PopContext), R(3), // |
| 3031 B(Jump), U8(-44), // | 3315 B(Jump), U8(-45), // |
| 3032 B(LdaContextSlot), R(context), U8(4), // | 3316 B(LdaContextSlot), R(context), U8(4), // |
| 3033 B(ToNumber), // | 3317 B(ToNumber), // |
| 3034 B(Star), R(4), // | 3318 B(Star), R(4), // |
| 3035 B(Inc), // | 3319 B(Inc), // |
| 3036 B(StaContextSlot), R(context), U8(4), // | 3320 B(StaContextSlot), R(context), U8(4), // |
| 3037 B(PopContext), R(3), // | 3321 B(PopContext), R(3), // |
| 3038 B(Jump), U8(-58), // | 3322 B(Jump), U8(-59), // |
| 3039 B(LdaUndefined), // | 3323 B(LdaUndefined), // |
| 3040 B(Return), // | 3324 B(Return), // |
| 3041 }, | 3325 }, |
| 3042 2, | 3326 2, |
| 3043 {InstanceType::FIXED_ARRAY_TYPE, | 3327 {InstanceType::FIXED_ARRAY_TYPE, |
| 3044 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3328 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3045 }; | 3329 }; |
| 3330 // clang-format on |
| 3046 | 3331 |
| 3047 for (size_t i = 0; i < arraysize(snippets); i++) { | 3332 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3048 Handle<BytecodeArray> bytecode_array = | 3333 Handle<BytecodeArray> bytecode_array = |
| 3049 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3334 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3050 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3335 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3051 } | 3336 } |
| 3052 } | 3337 } |
| 3053 | 3338 |
| 3054 | 3339 |
| 3055 TEST(JumpsRequiringConstantWideOperands) { | 3340 TEST(JumpsRequiringConstantWideOperands) { |
| 3056 InitializedHandleScope handle_scope; | 3341 InitializedHandleScope handle_scope; |
| 3057 BytecodeGeneratorHelper helper; | 3342 BytecodeGeneratorHelper helper; |
| 3058 | 3343 |
| 3059 int constant_count = 0; | 3344 int constant_count = 0; |
| 3345 // clang-format off |
| 3060 ExpectedSnippet<Handle<Object>, 316> snippets[] = { | 3346 ExpectedSnippet<Handle<Object>, 316> snippets[] = { |
| 3061 { | 3347 { |
| 3062 REPEAT_256(SPACE, "var x = 0.1;") | 3348 REPEAT_256(SPACE, "var x = 0.1;") |
| 3063 REPEAT_32(SPACE, "var x = 0.2;") | 3349 REPEAT_32(SPACE, "var x = 0.2;") |
| 3064 REPEAT_16(SPACE, "var x = 0.3;") | 3350 REPEAT_16(SPACE, "var x = 0.3;") |
| 3065 REPEAT_8(SPACE, "var x = 0.4;") | 3351 REPEAT_8(SPACE, "var x = 0.4;") |
| 3066 "for (var i = 0; i < 3; i++) {\n" | 3352 "for (var i = 0; i < 3; i++) {\n" |
| 3067 " if (i == 1) continue;\n" | 3353 " if (i == 1) continue;\n" |
| 3068 " if (i == 2) break;\n" | 3354 " if (i == 2) break;\n" |
| 3069 "}\n" | 3355 "}\n" |
| 3070 "return 3;", | 3356 "return 3;", |
| 3071 kPointerSize * 3, | 3357 kPointerSize * 3, |
| 3072 1, | 3358 1, |
| 3073 1359, | 3359 1361, |
| 3074 { | 3360 { |
| 3361 B(StackCheck), // |
| 3075 #define L(c) B(LdaConstant), U8(c), B(Star), R(0) | 3362 #define L(c) B(LdaConstant), U8(c), B(Star), R(0) |
| 3076 REPEAT_256(COMMA, L(constant_count++)), | 3363 REPEAT_256(COMMA, L(constant_count++)), |
| 3077 #undef L | 3364 #undef L |
| 3078 #define LW(c) B(LdaConstantWide), U16I(c), B(Star), R(0) | 3365 #define LW(c) B(LdaConstantWide), U16I(c), B(Star), R(0) |
| 3079 REPEAT_32(COMMA, LW(constant_count)), | 3366 REPEAT_32(COMMA, LW(constant_count)), |
| 3080 REPEAT_16(COMMA, LW(constant_count)), | 3367 REPEAT_16(COMMA, LW(constant_count)), |
| 3081 REPEAT_8(COMMA, LW(constant_count)), | 3368 REPEAT_8(COMMA, LW(constant_count)), |
| 3082 #undef LW | 3369 #undef LW |
| 3083 B(LdaZero), // | 3370 B(LdaZero), // |
| 3084 B(Star), R(1), // | 3371 B(Star), R(1), // |
| 3085 B(Ldar), R(1), // | 3372 B(Ldar), R(1), // |
| 3086 B(Star), R(2), // | 3373 B(Star), R(2), // |
| 3087 B(LdaSmi8), U8(3), // | 3374 B(LdaSmi8), U8(3), // |
| 3088 B(TestLessThan), R(2), // | 3375 B(TestLessThan), R(2), // |
| 3089 B(JumpIfFalseConstantWide), U16(313), // | 3376 B(JumpIfFalseConstantWide), U16(313), // |
| 3377 B(StackCheck), // |
| 3090 B(Ldar), R(1), // | 3378 B(Ldar), R(1), // |
| 3091 B(Star), R(2), // | 3379 B(Star), R(2), // |
| 3092 B(LdaSmi8), U8(1), // | 3380 B(LdaSmi8), U8(1), // |
| 3093 B(TestEqual), R(2), // | 3381 B(TestEqual), R(2), // |
| 3094 B(JumpIfFalseConstantWide), U16(312), // | 3382 B(JumpIfFalseConstantWide), U16(312), // |
| 3095 B(JumpConstantWide), U16(315), // | 3383 B(JumpConstantWide), U16(315), // |
| 3096 B(Ldar), R(1), // | 3384 B(Ldar), R(1), // |
| 3097 B(Star), R(2), // | 3385 B(Star), R(2), // |
| 3098 B(LdaSmi8), U8(2), // | 3386 B(LdaSmi8), U8(2), // |
| 3099 B(TestEqual), R(2), // | 3387 B(TestEqual), R(2), // |
| 3100 B(JumpIfFalseConstantWide), U16(312), // | 3388 B(JumpIfFalseConstantWide), U16(312), // |
| 3101 B(JumpConstantWide), U16(314), // | 3389 B(JumpConstantWide), U16(314), // |
| 3102 B(Ldar), R(1), // | 3390 B(Ldar), R(1), // |
| 3103 B(ToNumber), // | 3391 B(ToNumber), // |
| 3104 B(Star), R(2), // | 3392 B(Star), R(2), // |
| 3105 B(Inc), // | 3393 B(Inc), // |
| 3106 B(Star), R(1), // | 3394 B(Star), R(1), // |
| 3107 B(Jump), U8(-47), // | 3395 B(Jump), U8(-48), // |
| 3108 B(LdaSmi8), U8(3), // | 3396 B(LdaSmi8), U8(3), // |
| 3109 B(Return) // | 3397 B(Return) // |
| 3110 }, | 3398 }, |
| 3111 316, | 3399 316, |
| 3112 { | 3400 { |
| 3113 #define S(x) CcTest::i_isolate()->factory()->NewNumber(x) | 3401 #define S(x) CcTest::i_isolate()->factory()->NewNumber(x) |
| 3114 REPEAT_256(COMMA, S(0.1)), | 3402 REPEAT_256(COMMA, S(0.1)), |
| 3115 REPEAT_32(COMMA, S(0.2)), | 3403 REPEAT_32(COMMA, S(0.2)), |
| 3116 REPEAT_16(COMMA, S(0.3)), | 3404 REPEAT_16(COMMA, S(0.3)), |
| 3117 REPEAT_8(COMMA, S(0.4)), | 3405 REPEAT_8(COMMA, S(0.4)), |
| 3118 #undef S | 3406 #undef S |
| 3119 #define N(x) CcTest::i_isolate()->factory()->NewNumberFromInt(x) | 3407 #define N(x) CcTest::i_isolate()->factory()->NewNumberFromInt(x) |
| 3120 N(6), N(41), N(13), N(17) | 3408 N(6), N(42), N(13), N(17) |
| 3121 #undef N | 3409 #undef N |
| 3122 }}}; | 3410 }} |
| 3411 }; |
| 3412 // clang-format on |
| 3123 | 3413 |
| 3124 for (size_t i = 0; i < arraysize(snippets); i++) { | 3414 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3125 Handle<BytecodeArray> bytecode_array = | 3415 Handle<BytecodeArray> bytecode_array = |
| 3126 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3416 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3127 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3417 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3128 } | 3418 } |
| 3129 } | 3419 } |
| 3130 | 3420 |
| 3131 | 3421 |
| 3132 TEST(UnaryOperators) { | 3422 TEST(UnaryOperators) { |
| 3133 InitializedHandleScope handle_scope; | 3423 InitializedHandleScope handle_scope; |
| 3134 BytecodeGeneratorHelper helper; | 3424 BytecodeGeneratorHelper helper; |
| 3135 | 3425 |
| 3426 // clang-format off |
| 3136 ExpectedSnippet<int> snippets[] = { | 3427 ExpectedSnippet<int> snippets[] = { |
| 3137 {"var x = 0;" | 3428 {"var x = 0;" |
| 3138 "while (x != 10) {" | 3429 "while (x != 10) {" |
| 3139 " x = x + 10;" | 3430 " x = x + 10;" |
| 3140 "}" | 3431 "}" |
| 3141 "return x;", | 3432 "return x;", |
| 3142 2 * kPointerSize, | 3433 2 * kPointerSize, |
| 3143 1, | 3434 1, |
| 3144 29, | 3435 31, |
| 3145 { | 3436 { |
| 3437 B(StackCheck), // |
| 3146 B(LdaZero), // | 3438 B(LdaZero), // |
| 3147 B(Star), R(0), // | 3439 B(Star), R(0), // |
| 3148 B(Ldar), R(0), // | 3440 B(Ldar), R(0), // |
| 3149 B(Star), R(1), // | 3441 B(Star), R(1), // |
| 3150 B(LdaSmi8), U8(10), // | 3442 B(LdaSmi8), U8(10), // |
| 3151 B(TestEqual), R(1), // | 3443 B(TestEqual), R(1), // |
| 3152 B(LogicalNot), // | 3444 B(LogicalNot), // |
| 3153 B(JumpIfFalse), U8(14), // | 3445 B(JumpIfFalse), U8(15), // |
| 3446 B(StackCheck), // |
| 3154 B(Ldar), R(0), // | 3447 B(Ldar), R(0), // |
| 3155 B(Star), R(1), // | 3448 B(Star), R(1), // |
| 3156 B(LdaSmi8), U8(10), // | 3449 B(LdaSmi8), U8(10), // |
| 3157 B(Add), R(1), // | 3450 B(Add), R(1), // |
| 3158 B(Star), R(0), // | 3451 B(Star), R(0), // |
| 3159 B(Jump), U8(-21), // | 3452 B(Jump), U8(-22), // |
| 3160 B(Ldar), R(0), // | 3453 B(Ldar), R(0), // |
| 3161 B(Return), // | 3454 B(Return), // |
| 3162 }, | 3455 }, |
| 3163 0}, | 3456 0}, |
| 3164 {"var x = false;" | 3457 {"var x = false;" |
| 3165 "do {" | 3458 "do {" |
| 3166 " x = !x;" | 3459 " x = !x;" |
| 3167 "} while(x == false);" | 3460 "} while(x == false);" |
| 3168 "return x;", | 3461 "return x;", |
| 3169 2 * kPointerSize, | 3462 2 * kPointerSize, |
| 3170 1, | 3463 1, |
| 3171 20, | 3464 22, |
| 3172 { | 3465 { |
| 3173 B(LdaFalse), // | 3466 B(StackCheck), // |
| 3174 B(Star), R(0), // | 3467 B(LdaFalse), // |
| 3175 B(Ldar), R(0), // | 3468 B(Star), R(0), // |
| 3176 B(LogicalNot), // | 3469 B(StackCheck), // |
| 3177 B(Star), R(0), // | 3470 B(Ldar), R(0), // |
| 3178 B(Ldar), R(0), // | 3471 B(LogicalNot), // |
| 3179 B(Star), R(1), // | 3472 B(Star), R(0), // |
| 3180 B(LdaFalse), // | 3473 B(Ldar), R(0), // |
| 3181 B(TestEqual), R(1), // | 3474 B(Star), R(1), // |
| 3182 B(JumpIfTrue), U8(-12), // | 3475 B(LdaFalse), // |
| 3183 B(Ldar), R(0), // | 3476 B(TestEqual), R(1), // |
| 3184 B(Return), // | 3477 B(JumpIfTrue), U8(-13), // |
| 3478 B(Ldar), R(0), // |
| 3479 B(Return), // |
| 3185 }, | 3480 }, |
| 3186 0}, | 3481 0}, |
| 3187 {"var x = 101;" | 3482 {"var x = 101;" |
| 3188 "return void(x * 3);", | 3483 "return void(x * 3);", |
| 3189 2 * kPointerSize, | 3484 2 * kPointerSize, |
| 3190 1, | 3485 1, |
| 3191 12, | 3486 13, |
| 3192 { | 3487 { |
| 3488 B(StackCheck), // |
| 3193 B(LdaSmi8), U8(101), // | 3489 B(LdaSmi8), U8(101), // |
| 3194 B(Star), R(0), // | 3490 B(Star), R(0), // |
| 3195 B(Star), R(1), // | 3491 B(Star), R(1), // |
| 3196 B(LdaSmi8), U8(3), // | 3492 B(LdaSmi8), U8(3), // |
| 3197 B(Mul), R(1), // | 3493 B(Mul), R(1), // |
| 3198 B(LdaUndefined), // | 3494 B(LdaUndefined), // |
| 3199 B(Return), // | 3495 B(Return), // |
| 3200 }, | 3496 }, |
| 3201 0}, | 3497 0}, |
| 3202 {"var x = 1234;" | 3498 {"var x = 1234;" |
| 3203 "var y = void (x * x - 1);" | 3499 "var y = void (x * x - 1);" |
| 3204 "return y;", | 3500 "return y;", |
| 3205 4 * kPointerSize, | 3501 4 * kPointerSize, |
| 3206 1, | 3502 1, |
| 3207 20, | 3503 21, |
| 3208 { | 3504 { |
| 3505 B(StackCheck), // |
| 3209 B(LdaConstant), U8(0), // | 3506 B(LdaConstant), U8(0), // |
| 3210 B(Star), R(0), // | 3507 B(Star), R(0), // |
| 3211 B(Star), R(2), // | 3508 B(Star), R(2), // |
| 3212 B(Ldar), R(0), // | 3509 B(Ldar), R(0), // |
| 3213 B(Mul), R(2), // | 3510 B(Mul), R(2), // |
| 3214 B(Star), R(3), // | 3511 B(Star), R(3), // |
| 3215 B(LdaSmi8), U8(1), // | 3512 B(LdaSmi8), U8(1), // |
| 3216 B(Sub), R(3), // | 3513 B(Sub), R(3), // |
| 3217 B(LdaUndefined), // | 3514 B(LdaUndefined), // |
| 3218 B(Star), R(1), // | 3515 B(Star), R(1), // |
| 3219 B(Return), // | 3516 B(Return), // |
| 3220 }, | 3517 }, |
| 3221 1, | 3518 1, |
| 3222 {1234}}, | 3519 {1234}}, |
| 3223 {"var x = 13;" | 3520 {"var x = 13;" |
| 3224 "return ~x;", | 3521 "return ~x;", |
| 3225 2 * kPointerSize, | 3522 2 * kPointerSize, |
| 3226 1, | 3523 1, |
| 3227 11, | 3524 12, |
| 3228 { | 3525 { |
| 3526 B(StackCheck), // |
| 3229 B(LdaSmi8), U8(13), // | 3527 B(LdaSmi8), U8(13), // |
| 3230 B(Star), R(0), // | 3528 B(Star), R(0), // |
| 3231 B(Star), R(1), // | 3529 B(Star), R(1), // |
| 3232 B(LdaSmi8), U8(-1), // | 3530 B(LdaSmi8), U8(-1), // |
| 3233 B(BitwiseXor), R(1), // | 3531 B(BitwiseXor), R(1), // |
| 3234 B(Return), // | 3532 B(Return), // |
| 3235 }, | 3533 }, |
| 3236 0}, | 3534 0}, |
| 3237 {"var x = 13;" | 3535 {"var x = 13;" |
| 3238 "return +x;", | 3536 "return +x;", |
| 3239 2 * kPointerSize, | 3537 2 * kPointerSize, |
| 3240 1, | 3538 1, |
| 3241 11, | 3539 12, |
| 3242 { | 3540 { |
| 3541 B(StackCheck), // |
| 3243 B(LdaSmi8), U8(13), // | 3542 B(LdaSmi8), U8(13), // |
| 3244 B(Star), R(0), // | 3543 B(Star), R(0), // |
| 3245 B(Star), R(1), // | 3544 B(Star), R(1), // |
| 3246 B(LdaSmi8), U8(1), // | 3545 B(LdaSmi8), U8(1), // |
| 3247 B(Mul), R(1), // | 3546 B(Mul), R(1), // |
| 3248 B(Return), // | 3547 B(Return), // |
| 3249 }, | 3548 }, |
| 3250 0}, | 3549 0}, |
| 3251 {"var x = 13;" | 3550 {"var x = 13;" |
| 3252 "return -x;", | 3551 "return -x;", |
| 3253 2 * kPointerSize, | 3552 2 * kPointerSize, |
| 3254 1, | 3553 1, |
| 3255 11, | 3554 12, |
| 3256 { | 3555 { |
| 3556 B(StackCheck), // |
| 3257 B(LdaSmi8), U8(13), // | 3557 B(LdaSmi8), U8(13), // |
| 3258 B(Star), R(0), // | 3558 B(Star), R(0), // |
| 3259 B(Star), R(1), // | 3559 B(Star), R(1), // |
| 3260 B(LdaSmi8), U8(-1), // | 3560 B(LdaSmi8), U8(-1), // |
| 3261 B(Mul), R(1), // | 3561 B(Mul), R(1), // |
| 3262 B(Return), // | 3562 B(Return), // |
| 3263 }, | 3563 }, |
| 3264 0}}; | 3564 0} |
| 3565 }; |
| 3566 // clang-format on |
| 3265 | 3567 |
| 3266 for (size_t i = 0; i < arraysize(snippets); i++) { | 3568 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3267 Handle<BytecodeArray> bytecode_array = | 3569 Handle<BytecodeArray> bytecode_array = |
| 3268 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3570 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3269 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3571 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3270 } | 3572 } |
| 3271 } | 3573 } |
| 3272 | 3574 |
| 3273 | 3575 |
| 3274 TEST(Typeof) { | 3576 TEST(Typeof) { |
| 3275 InitializedHandleScope handle_scope; | 3577 InitializedHandleScope handle_scope; |
| 3276 BytecodeGeneratorHelper helper; | 3578 BytecodeGeneratorHelper helper; |
| 3277 Zone zone; | 3579 Zone zone; |
| 3278 | 3580 |
| 3279 FeedbackVectorSpec feedback_spec(&zone); | 3581 FeedbackVectorSpec feedback_spec(&zone); |
| 3280 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 3582 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 3281 | 3583 |
| 3282 Handle<i::TypeFeedbackVector> vector = | 3584 Handle<i::TypeFeedbackVector> vector = |
| 3283 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 3585 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3284 | 3586 |
| 3587 // clang-format off |
| 3285 ExpectedSnippet<const char*> snippets[] = { | 3588 ExpectedSnippet<const char*> snippets[] = { |
| 3286 {"function f() {\n" | 3589 {"function f() {\n" |
| 3287 " var x = 13;\n" | 3590 " var x = 13;\n" |
| 3288 " return typeof(x);\n" | 3591 " return typeof(x);\n" |
| 3289 "}; f();", | 3592 "}; f();", |
| 3290 kPointerSize, | 3593 kPointerSize, |
| 3291 1, | 3594 1, |
| 3292 6, | 3595 7, |
| 3293 { | 3596 { |
| 3597 B(StackCheck), // |
| 3294 B(LdaSmi8), U8(13), // | 3598 B(LdaSmi8), U8(13), // |
| 3295 B(Star), R(0), // | 3599 B(Star), R(0), // |
| 3296 B(TypeOf), // | 3600 B(TypeOf), // |
| 3297 B(Return), // | 3601 B(Return), // |
| 3298 }}, | 3602 }}, |
| 3299 {"var x = 13;\n" | 3603 {"var x = 13;\n" |
| 3300 "function f() {\n" | 3604 "function f() {\n" |
| 3301 " return typeof(x);\n" | 3605 " return typeof(x);\n" |
| 3302 "}; f();", | 3606 "}; f();", |
| 3303 0, | 3607 0, |
| 3304 1, | 3608 1, |
| 3305 5, | 3609 6, |
| 3306 { | 3610 { |
| 3611 B(StackCheck), // |
| 3307 B(LdaGlobalInsideTypeofSloppy), U8(0), // | 3612 B(LdaGlobalInsideTypeofSloppy), U8(0), // |
| 3308 U8(vector->GetIndex(slot)), // | 3613 /* */ U8(vector->GetIndex(slot)), // |
| 3309 B(TypeOf), // | 3614 B(TypeOf), // |
| 3310 B(Return), // | 3615 B(Return), // |
| 3311 }, | 3616 }, |
| 3312 1, | 3617 1, |
| 3313 {"x"}}, | 3618 {"x"}}, |
| 3314 {"var x = 13;\n" | 3619 {"var x = 13;\n" |
| 3315 "function f() {\n" | 3620 "function f() {\n" |
| 3316 " 'use strict';\n" | 3621 " 'use strict';\n" |
| 3317 " return typeof(x);\n" | 3622 " return typeof(x);\n" |
| 3318 "}; f();", | 3623 "}; f();", |
| 3319 0, | 3624 0, |
| 3320 1, | 3625 1, |
| 3321 5, | 3626 6, |
| 3322 { | 3627 { |
| 3628 B(StackCheck), // |
| 3323 B(LdaGlobalInsideTypeofStrict), U8(0), // | 3629 B(LdaGlobalInsideTypeofStrict), U8(0), // |
| 3324 U8(vector->GetIndex(slot)), // | 3630 /* */ U8(vector->GetIndex(slot)), // |
| 3325 B(TypeOf), // | 3631 B(TypeOf), // |
| 3326 B(Return), // | 3632 B(Return), // |
| 3327 }, | 3633 }, |
| 3328 1, | 3634 1, |
| 3329 {"x"}}, | 3635 {"x"}}, |
| 3330 }; | 3636 }; |
| 3637 // clang-format on |
| 3331 | 3638 |
| 3332 for (size_t i = 0; i < arraysize(snippets); i++) { | 3639 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3333 Handle<BytecodeArray> bytecode_array = | 3640 Handle<BytecodeArray> bytecode_array = |
| 3334 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 3641 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 3335 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3642 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3336 } | 3643 } |
| 3337 } | 3644 } |
| 3338 | 3645 |
| 3339 | 3646 |
| 3340 TEST(Delete) { | 3647 TEST(Delete) { |
| 3341 InitializedHandleScope handle_scope; | 3648 InitializedHandleScope handle_scope; |
| 3342 BytecodeGeneratorHelper helper; | 3649 BytecodeGeneratorHelper helper; |
| 3343 | 3650 |
| 3344 int deep_elements_flags = | 3651 int deep_elements_flags = |
| 3345 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 3652 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 3346 int closure = Register::function_closure().index(); | 3653 int closure = Register::function_closure().index(); |
| 3347 int context = Register::current_context().index(); | 3654 int context = Register::current_context().index(); |
| 3348 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 3655 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 3349 | 3656 |
| 3657 // clang-format off |
| 3350 ExpectedSnippet<InstanceType> snippets[] = { | 3658 ExpectedSnippet<InstanceType> snippets[] = { |
| 3351 {"var a = {x:13, y:14}; return delete a.x;", | 3659 {"var a = {x:13, y:14}; return delete a.x;", |
| 3352 2 * kPointerSize, | 3660 2 * kPointerSize, |
| 3353 1, | 3661 1, |
| 3354 15, | 3662 16, |
| 3355 {B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 3663 { |
| 3664 B(StackCheck), // |
| 3665 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3356 B(Star), R(1), // | 3666 B(Star), R(1), // |
| 3357 B(Star), R(0), // | 3667 B(Star), R(0), // |
| 3358 B(Star), R(1), // | 3668 B(Star), R(1), // |
| 3359 B(LdaConstant), U8(1), // | 3669 B(LdaConstant), U8(1), // |
| 3360 B(DeletePropertySloppy), R(1), // | 3670 B(DeletePropertySloppy), R(1), // |
| 3361 B(Return)}, | 3671 B(Return)}, |
| 3362 2, | 3672 2, |
| 3363 {InstanceType::FIXED_ARRAY_TYPE, | 3673 {InstanceType::FIXED_ARRAY_TYPE, |
| 3364 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3674 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3365 {"'use strict'; var a = {x:13, y:14}; return delete a.x;", | 3675 {"'use strict'; var a = {x:13, y:14}; return delete a.x;", |
| 3366 2 * kPointerSize, | 3676 2 * kPointerSize, |
| 3367 1, | 3677 1, |
| 3368 15, | 3678 16, |
| 3369 {B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 3679 {B(StackCheck), // |
| 3680 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3370 B(Star), R(1), // | 3681 B(Star), R(1), // |
| 3371 B(Star), R(0), // | 3682 B(Star), R(0), // |
| 3372 B(Star), R(1), // | 3683 B(Star), R(1), // |
| 3373 B(LdaConstant), U8(1), // | 3684 B(LdaConstant), U8(1), // |
| 3374 B(DeletePropertyStrict), R(1), // | 3685 B(DeletePropertyStrict), R(1), // |
| 3375 B(Return)}, | 3686 B(Return)}, |
| 3376 2, | 3687 2, |
| 3377 {InstanceType::FIXED_ARRAY_TYPE, | 3688 {InstanceType::FIXED_ARRAY_TYPE, |
| 3378 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3689 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3379 {"var a = {1:13, 2:14}; return delete a[2];", | 3690 {"var a = {1:13, 2:14}; return delete a[2];", |
| 3380 2 * kPointerSize, | 3691 2 * kPointerSize, |
| 3381 1, | 3692 1, |
| 3382 15, | 3693 16, |
| 3383 {B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 3694 {B(StackCheck), // |
| 3695 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3384 B(Star), R(1), // | 3696 B(Star), R(1), // |
| 3385 B(Star), R(0), // | 3697 B(Star), R(0), // |
| 3386 B(Star), R(1), // | 3698 B(Star), R(1), // |
| 3387 B(LdaSmi8), U8(2), // | 3699 B(LdaSmi8), U8(2), // |
| 3388 B(DeletePropertySloppy), R(1), // | 3700 B(DeletePropertySloppy), R(1), // |
| 3389 B(Return)}, | 3701 B(Return)}, |
| 3390 1, | 3702 1, |
| 3391 {InstanceType::FIXED_ARRAY_TYPE}}, | 3703 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3392 {"var a = 10; return delete a;", | 3704 {"var a = 10; return delete a;", |
| 3393 1 * kPointerSize, | 3705 1 * kPointerSize, |
| 3394 1, | 3706 1, |
| 3395 6, | 3707 7, |
| 3396 {B(LdaSmi8), U8(10), // | 3708 {B(StackCheck), // |
| 3709 B(LdaSmi8), U8(10), // |
| 3397 B(Star), R(0), // | 3710 B(Star), R(0), // |
| 3398 B(LdaFalse), // | 3711 B(LdaFalse), // |
| 3399 B(Return)}, | 3712 B(Return)}, |
| 3400 0}, | 3713 0}, |
| 3401 {"'use strict';" | 3714 {"'use strict';" |
| 3402 "var a = {1:10};" | 3715 "var a = {1:10};" |
| 3403 "(function f1() {return a;});" | 3716 "(function f1() {return a;});" |
| 3404 "return delete a[1];", | 3717 "return delete a[1];", |
| 3405 2 * kPointerSize, | 3718 2 * kPointerSize, |
| 3406 1, | 3719 1, |
| 3407 29, | 3720 30, |
| 3408 {B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 3721 {B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 3409 R(closure), U8(1), // | 3722 /* */ R(closure), U8(1), // |
| 3410 B(PushContext), R(0), // | 3723 B(PushContext), R(0), // |
| 3724 B(StackCheck), // |
| 3411 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 3725 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3412 B(Star), R(1), // | 3726 B(Star), R(1), // |
| 3413 B(StaContextSlot), R(context), U8(first_context_slot), // | 3727 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 3414 B(CreateClosure), U8(1), U8(0), // | 3728 B(CreateClosure), U8(1), U8(0), // |
| 3415 B(LdaContextSlot), R(context), U8(first_context_slot), // | 3729 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 3416 B(Star), R(1), // | 3730 B(Star), R(1), // |
| 3417 B(LdaSmi8), U8(1), // | 3731 B(LdaSmi8), U8(1), // |
| 3418 B(DeletePropertyStrict), R(1), // | 3732 B(DeletePropertyStrict), R(1), // |
| 3419 B(Return)}, | 3733 B(Return)}, |
| 3420 2, | 3734 2, |
| 3421 {InstanceType::FIXED_ARRAY_TYPE, | 3735 {InstanceType::FIXED_ARRAY_TYPE, |
| 3422 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3736 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3423 {"return delete 'test';", | 3737 {"return delete 'test';", |
| 3424 0 * kPointerSize, | 3738 0 * kPointerSize, |
| 3425 1, | 3739 1, |
| 3426 2, | 3740 3, |
| 3427 {B(LdaTrue), // | 3741 {B(StackCheck), // |
| 3742 B(LdaTrue), // |
| 3428 B(Return)}, | 3743 B(Return)}, |
| 3429 0}, | 3744 0}, |
| 3430 }; | 3745 }; |
| 3746 // clang-format on |
| 3431 | 3747 |
| 3432 for (size_t i = 0; i < arraysize(snippets); i++) { | 3748 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3433 Handle<BytecodeArray> bytecode_array = | 3749 Handle<BytecodeArray> bytecode_array = |
| 3434 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3750 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3435 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3751 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3436 } | 3752 } |
| 3437 } | 3753 } |
| 3438 | 3754 |
| 3439 | 3755 |
| 3440 TEST(GlobalDelete) { | 3756 TEST(GlobalDelete) { |
| 3441 InitializedHandleScope handle_scope; | 3757 InitializedHandleScope handle_scope; |
| 3442 BytecodeGeneratorHelper helper; | 3758 BytecodeGeneratorHelper helper; |
| 3443 Zone zone; | 3759 Zone zone; |
| 3444 | 3760 |
| 3445 int context = Register::current_context().index(); | 3761 int context = Register::current_context().index(); |
| 3446 int native_context_index = Context::NATIVE_CONTEXT_INDEX; | 3762 int native_context_index = Context::NATIVE_CONTEXT_INDEX; |
| 3447 int global_context_index = Context::EXTENSION_INDEX; | 3763 int global_context_index = Context::EXTENSION_INDEX; |
| 3448 FeedbackVectorSpec feedback_spec(&zone); | 3764 FeedbackVectorSpec feedback_spec(&zone); |
| 3449 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 3765 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 3450 | 3766 |
| 3451 Handle<i::TypeFeedbackVector> vector = | 3767 Handle<i::TypeFeedbackVector> vector = |
| 3452 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 3768 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3453 | 3769 |
| 3770 // clang-format off |
| 3454 ExpectedSnippet<InstanceType> snippets[] = { | 3771 ExpectedSnippet<InstanceType> snippets[] = { |
| 3455 {"var a = {x:13, y:14};\n function f() { return delete a.x; };\n f();", | 3772 {"var a = {x:13, y:14};\n function f() { return delete a.x; };\n f();", |
| 3456 1 * kPointerSize, | 3773 1 * kPointerSize, |
| 3457 1, | 3774 1, |
| 3458 10, | 3775 11, |
| 3459 {B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // | 3776 {B(StackCheck), // |
| 3777 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 3460 B(Star), R(0), // | 3778 B(Star), R(0), // |
| 3461 B(LdaConstant), U8(1), // | 3779 B(LdaConstant), U8(1), // |
| 3462 B(DeletePropertySloppy), R(0), // | 3780 B(DeletePropertySloppy), R(0), // |
| 3463 B(Return)}, | 3781 B(Return)}, |
| 3464 2, | 3782 2, |
| 3465 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 3783 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 3466 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3784 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3467 {"a = {1:13, 2:14};\n" | 3785 {"a = {1:13, 2:14};\n" |
| 3468 "function f() {'use strict'; return delete a[1];};\n f();", | 3786 "function f() {'use strict'; return delete a[1];};\n f();", |
| 3469 1 * kPointerSize, | 3787 1 * kPointerSize, |
| 3470 1, | 3788 1, |
| 3471 10, | 3789 11, |
| 3472 {B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // | 3790 {B(StackCheck), // |
| 3791 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // |
| 3473 B(Star), R(0), // | 3792 B(Star), R(0), // |
| 3474 B(LdaSmi8), U8(1), // | 3793 B(LdaSmi8), U8(1), // |
| 3475 B(DeletePropertyStrict), R(0), // | 3794 B(DeletePropertyStrict), R(0), // |
| 3476 B(Return)}, | 3795 B(Return)}, |
| 3477 1, | 3796 1, |
| 3478 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3797 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3479 {"var a = {x:13, y:14};\n function f() { return delete a; };\n f();", | 3798 {"var a = {x:13, y:14};\n function f() { return delete a; };\n f();", |
| 3480 2 * kPointerSize, | 3799 2 * kPointerSize, |
| 3481 1, | 3800 1, |
| 3482 15, | 3801 16, |
| 3483 {B(LdaContextSlot), R(context), U8(native_context_index), // | 3802 {B(StackCheck), // |
| 3803 B(LdaContextSlot), R(context), U8(native_context_index), // |
| 3484 B(Star), R(0), // | 3804 B(Star), R(0), // |
| 3485 B(LdaContextSlot), R(0), U8(global_context_index), // | 3805 B(LdaContextSlot), R(0), U8(global_context_index), // |
| 3486 B(Star), R(1), // | 3806 B(Star), R(1), // |
| 3487 B(LdaConstant), U8(0), // | 3807 B(LdaConstant), U8(0), // |
| 3488 B(DeletePropertySloppy), R(1), // | 3808 B(DeletePropertySloppy), R(1), // |
| 3489 B(Return)}, | 3809 B(Return)}, |
| 3490 1, | 3810 1, |
| 3491 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3811 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3492 {"b = 30;\n function f() { return delete b; };\n f();", | 3812 {"b = 30;\n function f() { return delete b; };\n f();", |
| 3493 2 * kPointerSize, | 3813 2 * kPointerSize, |
| 3494 1, | 3814 1, |
| 3495 15, | 3815 16, |
| 3496 {B(LdaContextSlot), R(context), U8(native_context_index), // | 3816 {B(StackCheck), // |
| 3817 B(LdaContextSlot), R(context), U8(native_context_index), // |
| 3497 B(Star), R(0), // | 3818 B(Star), R(0), // |
| 3498 B(LdaContextSlot), R(0), U8(global_context_index), // | 3819 B(LdaContextSlot), R(0), U8(global_context_index), // |
| 3499 B(Star), R(1), // | 3820 B(Star), R(1), // |
| 3500 B(LdaConstant), U8(0), // | 3821 B(LdaConstant), U8(0), // |
| 3501 B(DeletePropertySloppy), R(1), // | 3822 B(DeletePropertySloppy), R(1), // |
| 3502 B(Return)}, | 3823 B(Return)}, |
| 3503 1, | 3824 1, |
| 3504 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}}; | 3825 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}} |
| 3826 }; |
| 3827 // clang-format on |
| 3505 | 3828 |
| 3506 for (size_t i = 0; i < arraysize(snippets); i++) { | 3829 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3507 Handle<BytecodeArray> bytecode_array = | 3830 Handle<BytecodeArray> bytecode_array = |
| 3508 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 3831 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 3509 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3832 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3510 } | 3833 } |
| 3511 } | 3834 } |
| 3512 | 3835 |
| 3513 | 3836 |
| 3514 TEST(FunctionLiterals) { | 3837 TEST(FunctionLiterals) { |
| 3515 InitializedHandleScope handle_scope; | 3838 InitializedHandleScope handle_scope; |
| 3516 BytecodeGeneratorHelper helper; | 3839 BytecodeGeneratorHelper helper; |
| 3517 Zone zone; | 3840 Zone zone; |
| 3518 | 3841 |
| 3519 FeedbackVectorSpec feedback_spec(&zone); | 3842 FeedbackVectorSpec feedback_spec(&zone); |
| 3520 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); | 3843 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); |
| 3521 | 3844 |
| 3522 Handle<i::TypeFeedbackVector> vector = | 3845 Handle<i::TypeFeedbackVector> vector = |
| 3523 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 3846 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3524 | 3847 |
| 3848 // clang-format off |
| 3525 ExpectedSnippet<InstanceType> snippets[] = { | 3849 ExpectedSnippet<InstanceType> snippets[] = { |
| 3526 {"return function(){ }", | 3850 {"return function(){ }", |
| 3527 0, | 3851 0, |
| 3528 1, | 3852 1, |
| 3529 4, | 3853 5, |
| 3530 { | 3854 { |
| 3855 B(StackCheck), // |
| 3531 B(CreateClosure), U8(0), U8(0), // | 3856 B(CreateClosure), U8(0), U8(0), // |
| 3532 B(Return) // | 3857 B(Return) // |
| 3533 }, | 3858 }, |
| 3534 1, | 3859 1, |
| 3535 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3860 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3536 {"return (function(){ })()", | 3861 {"return (function(){ })()", |
| 3537 2 * kPointerSize, | 3862 2 * kPointerSize, |
| 3538 1, | 3863 1, |
| 3539 14, | 3864 15, |
| 3540 { | 3865 { |
| 3866 B(StackCheck), // |
| 3541 B(LdaUndefined), // | 3867 B(LdaUndefined), // |
| 3542 B(Star), R(1), // | 3868 B(Star), R(1), // |
| 3543 B(CreateClosure), U8(0), U8(0), // | 3869 B(CreateClosure), U8(0), U8(0), // |
| 3544 B(Star), R(0), // | 3870 B(Star), R(0), // |
| 3545 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot)), // | 3871 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot)), // |
| 3546 B(Return) // | 3872 B(Return) // |
| 3547 }, | 3873 }, |
| 3548 1, | 3874 1, |
| 3549 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3875 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3550 {"return (function(x){ return x; })(1)", | 3876 {"return (function(x){ return x; })(1)", |
| 3551 3 * kPointerSize, | 3877 3 * kPointerSize, |
| 3552 1, | 3878 1, |
| 3553 18, | 3879 19, |
| 3554 { | 3880 { |
| 3881 B(StackCheck), // |
| 3555 B(LdaUndefined), // | 3882 B(LdaUndefined), // |
| 3556 B(Star), R(1), // | 3883 B(Star), R(1), // |
| 3557 B(CreateClosure), U8(0), U8(0), // | 3884 B(CreateClosure), U8(0), U8(0), // |
| 3558 B(Star), R(0), // | 3885 B(Star), R(0), // |
| 3559 B(LdaSmi8), U8(1), // | 3886 B(LdaSmi8), U8(1), // |
| 3560 B(Star), R(2), // | 3887 B(Star), R(2), // |
| 3561 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot)), // | 3888 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot)), // |
| 3562 B(Return) // | 3889 B(Return) // |
| 3563 }, | 3890 }, |
| 3564 1, | 3891 1, |
| 3565 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3892 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3566 }; | 3893 }; |
| 3894 // clang-format on |
| 3567 | 3895 |
| 3568 for (size_t i = 0; i < arraysize(snippets); i++) { | 3896 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3569 Handle<BytecodeArray> bytecode_array = | 3897 Handle<BytecodeArray> bytecode_array = |
| 3570 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3898 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3571 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3899 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3572 } | 3900 } |
| 3573 } | 3901 } |
| 3574 | 3902 |
| 3575 | 3903 |
| 3576 TEST(RegExpLiterals) { | 3904 TEST(RegExpLiterals) { |
| 3577 InitializedHandleScope handle_scope; | 3905 InitializedHandleScope handle_scope; |
| 3578 BytecodeGeneratorHelper helper; | 3906 BytecodeGeneratorHelper helper; |
| 3579 Zone zone; | 3907 Zone zone; |
| 3580 | 3908 |
| 3581 FeedbackVectorSpec feedback_spec(&zone); | 3909 FeedbackVectorSpec feedback_spec(&zone); |
| 3582 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); | 3910 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
| 3583 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 3911 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 3584 uint8_t i_flags = JSRegExp::kIgnoreCase; | 3912 uint8_t i_flags = JSRegExp::kIgnoreCase; |
| 3585 | 3913 |
| 3586 Handle<i::TypeFeedbackVector> vector = | 3914 Handle<i::TypeFeedbackVector> vector = |
| 3587 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 3915 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3588 | 3916 |
| 3917 // clang-format off |
| 3589 ExpectedSnippet<const char*> snippets[] = { | 3918 ExpectedSnippet<const char*> snippets[] = { |
| 3590 {"return /ab+d/;", | 3919 {"return /ab+d/;", |
| 3591 0 * kPointerSize, | 3920 0 * kPointerSize, |
| 3592 1, | 3921 1, |
| 3593 5, | 3922 6, |
| 3594 { | 3923 { |
| 3924 B(StackCheck), // |
| 3595 B(CreateRegExpLiteral), U8(0), U8(0), U8(0), // | 3925 B(CreateRegExpLiteral), U8(0), U8(0), U8(0), // |
| 3596 B(Return), // | 3926 B(Return), // |
| 3597 }, | 3927 }, |
| 3598 1, | 3928 1, |
| 3599 {"ab+d"}}, | 3929 {"ab+d"}}, |
| 3600 {"return /(\\w+)\\s(\\w+)/i;", | 3930 {"return /(\\w+)\\s(\\w+)/i;", |
| 3601 0 * kPointerSize, | 3931 0 * kPointerSize, |
| 3602 1, | 3932 1, |
| 3603 5, | 3933 6, |
| 3604 { | 3934 { |
| 3935 B(StackCheck), // |
| 3605 B(CreateRegExpLiteral), U8(0), U8(0), U8(i_flags), // | 3936 B(CreateRegExpLiteral), U8(0), U8(0), U8(i_flags), // |
| 3606 B(Return), // | 3937 B(Return), // |
| 3607 }, | 3938 }, |
| 3608 1, | 3939 1, |
| 3609 {"(\\w+)\\s(\\w+)"}}, | 3940 {"(\\w+)\\s(\\w+)"}}, |
| 3610 {"return /ab+d/.exec('abdd');", | 3941 {"return /ab+d/.exec('abdd');", |
| 3611 3 * kPointerSize, | 3942 3 * kPointerSize, |
| 3612 1, | 3943 1, |
| 3613 22, | 3944 23, |
| 3614 { | 3945 { |
| 3946 B(StackCheck), // |
| 3615 B(CreateRegExpLiteral), U8(0), U8(0), U8(0), // | 3947 B(CreateRegExpLiteral), U8(0), U8(0), U8(0), // |
| 3616 B(Star), R(1), // | 3948 B(Star), R(1), // |
| 3617 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // | 3949 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // |
| 3618 B(Star), R(0), // | 3950 B(Star), R(0), // |
| 3619 B(LdaConstant), U8(2), // | 3951 B(LdaConstant), U8(2), // |
| 3620 B(Star), R(2), // | 3952 B(Star), R(2), // |
| 3621 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), // | 3953 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), // |
| 3622 B(Return), // | 3954 B(Return), // |
| 3623 }, | 3955 }, |
| 3624 3, | 3956 3, |
| 3625 {"ab+d", "exec", "abdd"}}, | 3957 {"ab+d", "exec", "abdd"}}, |
| 3626 }; | 3958 }; |
| 3959 // clang-format on |
| 3627 | 3960 |
| 3628 for (size_t i = 0; i < arraysize(snippets); i++) { | 3961 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3629 Handle<BytecodeArray> bytecode_array = | 3962 Handle<BytecodeArray> bytecode_array = |
| 3630 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3963 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3631 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3964 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3632 } | 3965 } |
| 3633 } | 3966 } |
| 3634 | 3967 |
| 3635 | 3968 |
| 3636 TEST(RegExpLiteralsWide) { | 3969 TEST(RegExpLiteralsWide) { |
| 3637 InitializedHandleScope handle_scope; | 3970 InitializedHandleScope handle_scope; |
| 3638 BytecodeGeneratorHelper helper; | 3971 BytecodeGeneratorHelper helper; |
| 3639 Zone zone; | 3972 Zone zone; |
| 3640 | 3973 |
| 3641 int wide_idx = 0; | 3974 int wide_idx = 0; |
| 3642 | 3975 |
| 3976 // clang-format off |
| 3643 ExpectedSnippet<InstanceType, 257> snippets[] = { | 3977 ExpectedSnippet<InstanceType, 257> snippets[] = { |
| 3644 {"var a;" REPEAT_256(SPACE, "a = 1.23;") "return /ab+d/;", | 3978 {"var a;" REPEAT_256(SPACE, "a = 1.23;") "return /ab+d/;", |
| 3645 1 * kPointerSize, | 3979 1 * kPointerSize, |
| 3646 1, | 3980 1, |
| 3647 1031, | 3981 1032, |
| 3648 { | 3982 { |
| 3983 B(StackCheck), // |
| 3649 REPEAT_256(COMMA, // | 3984 REPEAT_256(COMMA, // |
| 3650 B(LdaConstant), U8(wide_idx++), // | 3985 B(LdaConstant), U8(wide_idx++), // |
| 3651 B(Star), R(0)), // | 3986 B(Star), R(0)), // |
| 3652 B(CreateRegExpLiteralWide), U16(256), U16(0), U8(0), // | 3987 B(CreateRegExpLiteralWide), U16(256), U16(0), U8(0), // |
| 3653 B(Return) // | 3988 B(Return) // |
| 3654 }, | 3989 }, |
| 3655 257, | 3990 257, |
| 3656 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 3991 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 3657 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 3992 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3658 }; | 3993 }; |
| 3994 // clang-format on |
| 3659 | 3995 |
| 3660 for (size_t i = 0; i < arraysize(snippets); i++) { | 3996 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3661 Handle<BytecodeArray> bytecode_array = | 3997 Handle<BytecodeArray> bytecode_array = |
| 3662 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3998 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3663 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3999 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3664 } | 4000 } |
| 3665 } | 4001 } |
| 3666 | 4002 |
| 3667 | 4003 |
| 3668 TEST(ArrayLiterals) { | 4004 TEST(ArrayLiterals) { |
| 3669 InitializedHandleScope handle_scope; | 4005 InitializedHandleScope handle_scope; |
| 3670 BytecodeGeneratorHelper helper; | 4006 BytecodeGeneratorHelper helper; |
| 3671 Zone zone; | 4007 Zone zone; |
| 3672 | 4008 |
| 3673 FeedbackVectorSpec feedback_spec(&zone); | 4009 FeedbackVectorSpec feedback_spec(&zone); |
| 3674 FeedbackVectorSlot slot1 = feedback_spec.AddKeyedStoreICSlot(); | 4010 FeedbackVectorSlot slot1 = feedback_spec.AddKeyedStoreICSlot(); |
| 3675 FeedbackVectorSlot slot2 = feedback_spec.AddKeyedStoreICSlot(); | 4011 FeedbackVectorSlot slot2 = feedback_spec.AddKeyedStoreICSlot(); |
| 3676 FeedbackVectorSlot slot3 = feedback_spec.AddKeyedStoreICSlot(); | 4012 FeedbackVectorSlot slot3 = feedback_spec.AddKeyedStoreICSlot(); |
| 3677 | 4013 |
| 3678 Handle<i::TypeFeedbackVector> vector = | 4014 Handle<i::TypeFeedbackVector> vector = |
| 3679 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 4015 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3680 | 4016 |
| 3681 int simple_flags = | 4017 int simple_flags = |
| 3682 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; | 4018 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; |
| 3683 int deep_elements_flags = ArrayLiteral::kDisableMementos; | 4019 int deep_elements_flags = ArrayLiteral::kDisableMementos; |
| 4020 // clang-format off |
| 3684 ExpectedSnippet<InstanceType> snippets[] = { | 4021 ExpectedSnippet<InstanceType> snippets[] = { |
| 3685 {"return [ 1, 2 ];", | 4022 {"return [ 1, 2 ];", |
| 3686 0, | 4023 0, |
| 3687 1, | 4024 1, |
| 3688 5, | 4025 6, |
| 3689 { | 4026 { |
| 4027 B(StackCheck), // |
| 3690 B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), // | 4028 B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), // |
| 3691 B(Return) // | 4029 B(Return) // |
| 3692 }, | 4030 }, |
| 3693 1, | 4031 1, |
| 3694 {InstanceType::FIXED_ARRAY_TYPE}}, | 4032 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3695 {"var a = 1; return [ a, a + 1 ];", | 4033 {"var a = 1; return [ a, a + 1 ];", |
| 3696 4 * kPointerSize, | 4034 4 * kPointerSize, |
| 3697 1, | 4035 1, |
| 3698 38, | 4036 39, |
| 3699 { | 4037 { |
| 4038 B(StackCheck), // |
| 3700 B(LdaSmi8), U8(1), // | 4039 B(LdaSmi8), U8(1), // |
| 3701 B(Star), R(0), // | 4040 B(Star), R(0), // |
| 3702 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // | 4041 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // |
| 3703 B(Star), R(2), // | 4042 B(Star), R(2), // |
| 3704 B(LdaZero), // | 4043 B(LdaZero), // |
| 3705 B(Star), R(1), // | 4044 B(Star), R(1), // |
| 3706 B(Ldar), R(0), // | 4045 B(Ldar), R(0), // |
| 3707 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // | 4046 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // |
| 3708 B(LdaSmi8), U8(1), // | 4047 B(LdaSmi8), U8(1), // |
| 3709 B(Star), R(1), // | 4048 B(Star), R(1), // |
| 3710 B(Ldar), R(0), // | 4049 B(Ldar), R(0), // |
| 3711 B(Star), R(3), // | 4050 B(Star), R(3), // |
| 3712 B(LdaSmi8), U8(1), // | 4051 B(LdaSmi8), U8(1), // |
| 3713 B(Add), R(3), // | 4052 B(Add), R(3), // |
| 3714 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // | 4053 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot1)), // |
| 3715 B(Ldar), R(2), // | 4054 B(Ldar), R(2), // |
| 3716 B(Return), // | 4055 B(Return), // |
| 3717 }, | 4056 }, |
| 3718 1, | 4057 1, |
| 3719 {InstanceType::FIXED_ARRAY_TYPE}}, | 4058 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3720 {"return [ [ 1, 2 ], [ 3 ] ];", | 4059 {"return [ [ 1, 2 ], [ 3 ] ];", |
| 3721 0, | 4060 0, |
| 3722 1, | 4061 1, |
| 3723 5, | 4062 6, |
| 3724 { | 4063 { |
| 4064 B(StackCheck), // |
| 3725 B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), // | 4065 B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), // |
| 3726 B(Return) // | 4066 B(Return) // |
| 3727 }, | 4067 }, |
| 3728 1, | 4068 1, |
| 3729 {InstanceType::FIXED_ARRAY_TYPE}}, | 4069 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3730 {"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];", | 4070 {"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];", |
| 3731 6 * kPointerSize, | 4071 6 * kPointerSize, |
| 3732 1, | 4072 1, |
| 3733 68, | 4073 69, |
| 3734 { | 4074 { |
| 4075 B(StackCheck), // |
| 3735 B(LdaSmi8), U8(1), // | 4076 B(LdaSmi8), U8(1), // |
| 3736 B(Star), R(0), // | 4077 B(Star), R(0), // |
| 3737 B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), // | 4078 B(CreateArrayLiteral), U8(0), U8(2), U8(deep_elements_flags), // |
| 3738 B(Star), R(2), // | 4079 B(Star), R(2), // |
| 3739 B(LdaZero), // | 4080 B(LdaZero), // |
| 3740 B(Star), R(1), // | 4081 B(Star), R(1), // |
| 3741 B(CreateArrayLiteral), U8(1), U8(0), U8(simple_flags), // | 4082 B(CreateArrayLiteral), U8(1), U8(0), U8(simple_flags), // |
| 3742 B(Star), R(4), // | 4083 B(Star), R(4), // |
| 3743 B(LdaZero), // | 4084 B(LdaZero), // |
| 3744 B(Star), R(3), // | 4085 B(Star), R(3), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3759 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot2)), // | 4100 B(KeyedStoreICSloppy), R(4), R(3), U8(vector->GetIndex(slot2)), // |
| 3760 B(Ldar), R(4), // | 4101 B(Ldar), R(4), // |
| 3761 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), // | 4102 B(KeyedStoreICSloppy), R(2), R(1), U8(vector->GetIndex(slot3)), // |
| 3762 B(Ldar), R(2), // | 4103 B(Ldar), R(2), // |
| 3763 B(Return), // | 4104 B(Return), // |
| 3764 }, | 4105 }, |
| 3765 3, | 4106 3, |
| 3766 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, | 4107 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, |
| 3767 InstanceType::FIXED_ARRAY_TYPE}}, | 4108 InstanceType::FIXED_ARRAY_TYPE}}, |
| 3768 }; | 4109 }; |
| 4110 // clang-format on |
| 3769 | 4111 |
| 3770 for (size_t i = 0; i < arraysize(snippets); i++) { | 4112 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3771 Handle<BytecodeArray> bytecode_array = | 4113 Handle<BytecodeArray> bytecode_array = |
| 3772 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4114 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3773 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4115 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3774 } | 4116 } |
| 3775 } | 4117 } |
| 3776 | 4118 |
| 3777 | 4119 |
| 3778 TEST(ArrayLiteralsWide) { | 4120 TEST(ArrayLiteralsWide) { |
| 3779 InitializedHandleScope handle_scope; | 4121 InitializedHandleScope handle_scope; |
| 3780 BytecodeGeneratorHelper helper; | 4122 BytecodeGeneratorHelper helper; |
| 3781 Zone zone; | 4123 Zone zone; |
| 3782 | 4124 |
| 3783 int wide_idx = 0; | 4125 int wide_idx = 0; |
| 3784 int simple_flags = | 4126 int simple_flags = |
| 3785 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; | 4127 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; |
| 3786 | 4128 |
| 4129 // clang-format off |
| 3787 ExpectedSnippet<InstanceType, 257> snippets[] = { | 4130 ExpectedSnippet<InstanceType, 257> snippets[] = { |
| 3788 {"var a;" REPEAT_256(SPACE, "a = 1.23;") "return [ 1 , 2 ];", | 4131 {"var a;" REPEAT_256(SPACE, "a = 1.23;") "return [ 1 , 2 ];", |
| 3789 1 * kPointerSize, | 4132 1 * kPointerSize, |
| 3790 1, | 4133 1, |
| 3791 1031, | 4134 1032, |
| 3792 { | 4135 { |
| 4136 B(StackCheck), // |
| 3793 REPEAT_256(COMMA, // | 4137 REPEAT_256(COMMA, // |
| 3794 B(LdaConstant), U8(wide_idx++), // | 4138 B(LdaConstant), U8(wide_idx++), // |
| 3795 B(Star), R(0)), // | 4139 B(Star), R(0)), // |
| 3796 B(CreateArrayLiteralWide), U16(256), U16(0), U8(simple_flags), // | 4140 B(CreateArrayLiteralWide), U16(256), U16(0), U8(simple_flags), // |
| 3797 B(Return) // | 4141 B(Return) // |
| 3798 }, | 4142 }, |
| 3799 257, | 4143 257, |
| 3800 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 4144 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 3801 InstanceType::FIXED_ARRAY_TYPE}}, | 4145 InstanceType::FIXED_ARRAY_TYPE}}, |
| 3802 }; | 4146 }; |
| 4147 // clang-format on |
| 3803 | 4148 |
| 3804 for (size_t i = 0; i < arraysize(snippets); i++) { | 4149 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3805 Handle<BytecodeArray> bytecode_array = | 4150 Handle<BytecodeArray> bytecode_array = |
| 3806 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4151 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3807 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4152 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3808 } | 4153 } |
| 3809 } | 4154 } |
| 3810 | 4155 |
| 3811 | 4156 |
| 3812 TEST(ObjectLiterals) { | 4157 TEST(ObjectLiterals) { |
| 3813 InitializedHandleScope handle_scope; | 4158 InitializedHandleScope handle_scope; |
| 3814 BytecodeGeneratorHelper helper; | 4159 BytecodeGeneratorHelper helper; |
| 3815 Zone zone; | 4160 Zone zone; |
| 3816 | 4161 |
| 3817 FeedbackVectorSpec feedback_spec(&zone); | 4162 FeedbackVectorSpec feedback_spec(&zone); |
| 3818 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); | 4163 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); |
| 3819 | 4164 |
| 3820 Handle<i::TypeFeedbackVector> vector = | 4165 Handle<i::TypeFeedbackVector> vector = |
| 3821 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 4166 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 3822 | 4167 |
| 3823 int simple_flags = ObjectLiteral::kFastElements | | 4168 int simple_flags = ObjectLiteral::kFastElements | |
| 3824 ObjectLiteral::kShallowProperties | | 4169 ObjectLiteral::kShallowProperties | |
| 3825 ObjectLiteral::kDisableMementos; | 4170 ObjectLiteral::kDisableMementos; |
| 3826 int deep_elements_flags = | 4171 int deep_elements_flags = |
| 3827 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 4172 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 4173 // clang-format off |
| 3828 ExpectedSnippet<InstanceType> snippets[] = { | 4174 ExpectedSnippet<InstanceType> snippets[] = { |
| 3829 {"return { };", | 4175 {"return { };", |
| 3830 kPointerSize, | 4176 kPointerSize, |
| 3831 1, | 4177 1, |
| 3832 7, | 4178 8, |
| 3833 { | 4179 { |
| 4180 B(StackCheck), // |
| 3834 B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), // | 4181 B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), // |
| 3835 B(Star), R(0), // | 4182 B(Star), R(0), // |
| 3836 B(Return) // | 4183 B(Return) // |
| 3837 }, | 4184 }, |
| 3838 1, | 4185 1, |
| 3839 {InstanceType::FIXED_ARRAY_TYPE}}, | 4186 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3840 {"return { name: 'string', val: 9.2 };", | 4187 {"return { name: 'string', val: 9.2 };", |
| 3841 kPointerSize, | 4188 kPointerSize, |
| 3842 1, | 4189 1, |
| 3843 7, | 4190 8, |
| 3844 { | 4191 { |
| 4192 B(StackCheck), // |
| 3845 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4193 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3846 B(Star), R(0), // | 4194 B(Star), R(0), // |
| 3847 B(Return) // | 4195 B(Return) // |
| 3848 }, | 4196 }, |
| 3849 1, | 4197 1, |
| 3850 {InstanceType::FIXED_ARRAY_TYPE}}, | 4198 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 3851 {"var a = 1; return { name: 'string', val: a };", | 4199 {"var a = 1; return { name: 'string', val: a };", |
| 3852 2 * kPointerSize, | 4200 2 * kPointerSize, |
| 3853 1, | 4201 1, |
| 3854 19, | 4202 20, |
| 3855 { | 4203 { |
| 4204 B(StackCheck), // |
| 3856 B(LdaSmi8), U8(1), // | 4205 B(LdaSmi8), U8(1), // |
| 3857 B(Star), R(0), // | 4206 B(Star), R(0), // |
| 3858 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4207 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3859 B(Star), R(1), // | 4208 B(Star), R(1), // |
| 3860 B(Ldar), R(0), // | 4209 B(Ldar), R(0), // |
| 3861 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 4210 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 3862 B(Ldar), R(1), // | 4211 B(Ldar), R(1), // |
| 3863 B(Return), // | 4212 B(Return), // |
| 3864 }, | 4213 }, |
| 3865 2, | 4214 2, |
| 3866 {InstanceType::FIXED_ARRAY_TYPE, | 4215 {InstanceType::FIXED_ARRAY_TYPE, |
| 3867 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4216 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3868 {"var a = 1; return { val: a, val: a + 1 };", | 4217 {"var a = 1; return { val: a, val: a + 1 };", |
| 3869 3 * kPointerSize, | 4218 3 * kPointerSize, |
| 3870 1, | 4219 1, |
| 3871 25, | 4220 26, |
| 3872 { | 4221 { |
| 4222 B(StackCheck), // |
| 3873 B(LdaSmi8), U8(1), // | 4223 B(LdaSmi8), U8(1), // |
| 3874 B(Star), R(0), // | 4224 B(Star), R(0), // |
| 3875 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4225 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3876 B(Star), R(1), // | 4226 B(Star), R(1), // |
| 3877 B(Ldar), R(0), // | 4227 B(Ldar), R(0), // |
| 3878 B(Star), R(2), // | 4228 B(Star), R(2), // |
| 3879 B(LdaSmi8), U8(1), // | 4229 B(LdaSmi8), U8(1), // |
| 3880 B(Add), R(2), // | 4230 B(Add), R(2), // |
| 3881 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 4231 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 3882 B(Ldar), R(1), // | 4232 B(Ldar), R(1), // |
| 3883 B(Return), // | 4233 B(Return), // |
| 3884 }, | 4234 }, |
| 3885 2, | 4235 2, |
| 3886 {InstanceType::FIXED_ARRAY_TYPE, | 4236 {InstanceType::FIXED_ARRAY_TYPE, |
| 3887 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4237 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3888 {"return { func: function() { } };", | 4238 {"return { func: function() { } };", |
| 3889 1 * kPointerSize, | 4239 1 * kPointerSize, |
| 3890 1, | 4240 1, |
| 3891 16, | 4241 17, |
| 3892 { | 4242 { |
| 4243 B(StackCheck), // |
| 3893 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4244 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3894 B(Star), R(0), // | 4245 B(Star), R(0), // |
| 3895 B(CreateClosure), U8(1), U8(0), // | 4246 B(CreateClosure), U8(1), U8(0), // |
| 3896 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), // | 4247 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), // |
| 3897 B(Ldar), R(0), // | 4248 B(Ldar), R(0), // |
| 3898 B(Return), // | 4249 B(Return), // |
| 3899 }, | 4250 }, |
| 3900 3, | 4251 3, |
| 3901 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, | 4252 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 3902 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4253 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3903 {"return { func(a) { return a; } };", | 4254 {"return { func(a) { return a; } };", |
| 3904 1 * kPointerSize, | 4255 1 * kPointerSize, |
| 3905 1, | 4256 1, |
| 3906 16, | 4257 17, |
| 3907 { | 4258 { |
| 4259 B(StackCheck), // |
| 3908 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4260 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3909 B(Star), R(0), // | 4261 B(Star), R(0), // |
| 3910 B(CreateClosure), U8(1), U8(0), // | 4262 B(CreateClosure), U8(1), U8(0), // |
| 3911 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), // | 4263 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot1)), // |
| 3912 B(Ldar), R(0), // | 4264 B(Ldar), R(0), // |
| 3913 B(Return), // | 4265 B(Return), // |
| 3914 }, | 4266 }, |
| 3915 3, | 4267 3, |
| 3916 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, | 4268 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 3917 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4269 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 3918 {"return { get a() { return 2; } };", | 4270 {"return { get a() { return 2; } };", |
| 3919 6 * kPointerSize, | 4271 6 * kPointerSize, |
| 3920 1, | 4272 1, |
| 3921 32, | 4273 33, |
| 3922 { | 4274 { |
| 4275 B(StackCheck), // |
| 3923 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4276 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3924 B(Star), R(0), // | 4277 B(Star), R(0), // |
| 3925 B(Mov), R(0), R(1), // | 4278 B(Mov), R(0), R(1), // |
| 3926 B(LdaConstant), U8(1), // | 4279 B(LdaConstant), U8(1), // |
| 3927 B(Star), R(2), // | 4280 B(Star), R(2), // |
| 3928 B(CreateClosure), U8(2), U8(0), // | 4281 B(CreateClosure), U8(2), U8(0), // |
| 3929 B(Star), R(3), // | 4282 B(Star), R(3), // |
| 3930 B(LdaNull), // | 4283 B(LdaNull), // |
| 3931 B(Star), R(4), // | 4284 B(Star), R(4), // |
| 3932 B(LdaZero), // | 4285 B(LdaZero), // |
| 3933 B(Star), R(5), // | 4286 B(Star), R(5), // |
| 3934 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // | 4287 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
| 3935 R(1), U8(5), // | 4288 /* */ R(1), U8(5), // |
| 3936 B(Ldar), R(0), // | 4289 B(Ldar), R(0), // |
| 3937 B(Return), // | 4290 B(Return), // |
| 3938 }, | 4291 }, |
| 3939 3, | 4292 3, |
| 3940 {InstanceType::FIXED_ARRAY_TYPE, | 4293 {InstanceType::FIXED_ARRAY_TYPE, |
| 3941 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4294 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 3942 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4295 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3943 {"return { get a() { return this.x; }, set a(val) { this.x = val } };", | 4296 {"return { get a() { return this.x; }, set a(val) { this.x = val } };", |
| 3944 6 * kPointerSize, | 4297 6 * kPointerSize, |
| 3945 1, | 4298 1, |
| 3946 34, | 4299 35, |
| 3947 { | 4300 { |
| 4301 B(StackCheck), // |
| 3948 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4302 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3949 B(Star), R(0), // | 4303 B(Star), R(0), // |
| 3950 B(Mov), R(0), R(1), // | 4304 B(Mov), R(0), R(1), // |
| 3951 B(LdaConstant), U8(1), // | 4305 B(LdaConstant), U8(1), // |
| 3952 B(Star), R(2), // | 4306 B(Star), R(2), // |
| 3953 B(CreateClosure), U8(2), U8(0), // | 4307 B(CreateClosure), U8(2), U8(0), // |
| 3954 B(Star), R(3), // | 4308 B(Star), R(3), // |
| 3955 B(CreateClosure), U8(3), U8(0), // | 4309 B(CreateClosure), U8(3), U8(0), // |
| 3956 B(Star), R(4), // | 4310 B(Star), R(4), // |
| 3957 B(LdaZero), // | 4311 B(LdaZero), // |
| 3958 B(Star), R(5), // | 4312 B(Star), R(5), // |
| 3959 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // | 4313 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
| 3960 R(1), U8(5), // | 4314 /* */ R(1), U8(5), // |
| 3961 B(Ldar), R(0), // | 4315 B(Ldar), R(0), // |
| 3962 B(Return), // | 4316 B(Return), // |
| 3963 }, | 4317 }, |
| 3964 4, | 4318 4, |
| 3965 {InstanceType::FIXED_ARRAY_TYPE, | 4319 {InstanceType::FIXED_ARRAY_TYPE, |
| 3966 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4320 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 3967 InstanceType::SHARED_FUNCTION_INFO_TYPE, | 4321 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 3968 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4322 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3969 {"return { set b(val) { this.y = val } };", | 4323 {"return { set b(val) { this.y = val } };", |
| 3970 6 * kPointerSize, | 4324 6 * kPointerSize, |
| 3971 1, | 4325 1, |
| 3972 32, | 4326 33, |
| 3973 { | 4327 { |
| 4328 B(StackCheck), // |
| 3974 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4329 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 3975 B(Star), R(0), // | 4330 B(Star), R(0), // |
| 3976 B(Mov), R(0), R(1), // | 4331 B(Mov), R(0), R(1), // |
| 3977 B(LdaConstant), U8(1), // | 4332 B(LdaConstant), U8(1), // |
| 3978 B(Star), R(2), // | 4333 B(Star), R(2), // |
| 3979 B(LdaNull), // | 4334 B(LdaNull), // |
| 3980 B(Star), R(3), // | 4335 B(Star), R(3), // |
| 3981 B(CreateClosure), U8(2), U8(0), // | 4336 B(CreateClosure), U8(2), U8(0), // |
| 3982 B(Star), R(4), // | 4337 B(Star), R(4), // |
| 3983 B(LdaZero), // | 4338 B(LdaZero), // |
| 3984 B(Star), R(5), // | 4339 B(Star), R(5), // |
| 3985 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // | 4340 B(CallRuntime), U16(Runtime::kDefineAccessorPropertyUnchecked), // |
| 3986 R(1), U8(5), // | 4341 /* */ R(1), U8(5), // |
| 3987 B(Ldar), R(0), // | 4342 B(Ldar), R(0), // |
| 3988 B(Return), // | 4343 B(Return), // |
| 3989 }, | 4344 }, |
| 3990 3, | 4345 3, |
| 3991 {InstanceType::FIXED_ARRAY_TYPE, | 4346 {InstanceType::FIXED_ARRAY_TYPE, |
| 3992 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4347 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 3993 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4348 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 3994 {"var a = 1; return { 1: a };", | 4349 {"var a = 1; return { 1: a };", |
| 3995 6 * kPointerSize, | 4350 6 * kPointerSize, |
| 3996 1, | 4351 1, |
| 3997 32, | 4352 33, |
| 3998 { | 4353 { |
| 4354 B(StackCheck), // |
| 3999 B(LdaSmi8), U8(1), // | 4355 B(LdaSmi8), U8(1), // |
| 4000 B(Star), R(0), // | 4356 B(Star), R(0), // |
| 4001 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 4357 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 4002 B(Star), R(1), // | 4358 B(Star), R(1), // |
| 4003 B(Mov), R(1), R(2), // | 4359 B(Mov), R(1), R(2), // |
| 4004 B(LdaSmi8), U8(1), // | 4360 B(LdaSmi8), U8(1), // |
| 4005 B(Star), R(3), // | 4361 B(Star), R(3), // |
| 4006 B(Ldar), R(0), // | 4362 B(Ldar), R(0), // |
| 4007 B(Star), R(4), // | 4363 B(Star), R(4), // |
| 4008 B(LdaZero), // | 4364 B(LdaZero), // |
| 4009 B(Star), R(5), // | 4365 B(Star), R(5), // |
| 4010 B(CallRuntime), U16(Runtime::kSetProperty), R(2), U8(4), // | 4366 B(CallRuntime), U16(Runtime::kSetProperty), R(2), U8(4), // |
| 4011 B(Ldar), R(1), // | 4367 B(Ldar), R(1), // |
| 4012 B(Return), // | 4368 B(Return), // |
| 4013 }, | 4369 }, |
| 4014 1, | 4370 1, |
| 4015 {InstanceType::FIXED_ARRAY_TYPE}}, | 4371 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 4016 {"return { __proto__: null }", | 4372 {"return { __proto__: null }", |
| 4017 3 * kPointerSize, | 4373 3 * kPointerSize, |
| 4018 1, | 4374 1, |
| 4019 20, | 4375 21, |
| 4020 { | 4376 { |
| 4377 B(StackCheck), // |
| 4021 B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), // | 4378 B(CreateObjectLiteral), U8(0), U8(0), U8(simple_flags), // |
| 4022 B(Star), R(0), // | 4379 B(Star), R(0), // |
| 4023 B(Mov), R(0), R(1), // | 4380 B(Mov), R(0), R(1), // |
| 4024 B(LdaNull), B(Star), R(2), // | 4381 B(LdaNull), B(Star), R(2), // |
| 4025 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), // | 4382 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(1), U8(2), // |
| 4026 B(Ldar), R(0), // | 4383 B(Ldar), R(0), // |
| 4027 B(Return), // | 4384 B(Return), // |
| 4028 }, | 4385 }, |
| 4029 1, | 4386 1, |
| 4030 {InstanceType::FIXED_ARRAY_TYPE}}, | 4387 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 4031 {"var a = 'test'; return { [a]: 1 }", | 4388 {"var a = 'test'; return { [a]: 1 }", |
| 4032 6 * kPointerSize, | 4389 6 * kPointerSize, |
| 4033 1, | 4390 1, |
| 4034 33, | 4391 34, |
| 4035 { | 4392 { |
| 4393 B(StackCheck), // |
| 4036 B(LdaConstant), U8(0), // | 4394 B(LdaConstant), U8(0), // |
| 4037 B(Star), R(0), // | 4395 B(Star), R(0), // |
| 4038 B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), // | 4396 B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), // |
| 4039 B(Star), R(1), // | 4397 B(Star), R(1), // |
| 4040 B(Mov), R(1), R(2), // | 4398 B(Mov), R(1), R(2), // |
| 4041 B(Ldar), R(0), // | 4399 B(Ldar), R(0), // |
| 4042 B(ToName), // | 4400 B(ToName), // |
| 4043 B(Star), R(3), // | 4401 B(Star), R(3), // |
| 4044 B(LdaSmi8), U8(1), // | 4402 B(LdaSmi8), U8(1), // |
| 4045 B(Star), R(4), // | 4403 B(Star), R(4), // |
| 4046 B(LdaZero), // | 4404 B(LdaZero), // |
| 4047 B(Star), R(5), // | 4405 B(Star), R(5), // |
| 4048 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // | 4406 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // |
| 4049 U8(4), // | 4407 /* */ U8(4), // |
| 4050 B(Ldar), R(1), // | 4408 B(Ldar), R(1), // |
| 4051 B(Return), // | 4409 B(Return), // |
| 4052 }, | 4410 }, |
| 4053 2, | 4411 2, |
| 4054 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4412 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4055 InstanceType::FIXED_ARRAY_TYPE}}, | 4413 InstanceType::FIXED_ARRAY_TYPE}}, |
| 4056 {"var a = 'test'; return { val: a, [a]: 1 }", | 4414 {"var a = 'test'; return { val: a, [a]: 1 }", |
| 4057 6 * kPointerSize, | 4415 6 * kPointerSize, |
| 4058 1, | 4416 1, |
| 4059 39, | 4417 40, |
| 4060 { | 4418 { |
| 4419 B(StackCheck), // |
| 4061 B(LdaConstant), U8(0), // | 4420 B(LdaConstant), U8(0), // |
| 4062 B(Star), R(0), // | 4421 B(Star), R(0), // |
| 4063 B(CreateObjectLiteral), U8(1), U8(0), U8(deep_elements_flags), // | 4422 B(CreateObjectLiteral), U8(1), U8(0), U8(deep_elements_flags), // |
| 4064 B(Star), R(1), // | 4423 B(Star), R(1), // |
| 4065 B(Ldar), R(0), // | 4424 B(Ldar), R(0), // |
| 4066 B(StoreICSloppy), R(1), U8(2), U8(vector->GetIndex(slot1)), // | 4425 B(StoreICSloppy), R(1), U8(2), U8(vector->GetIndex(slot1)), // |
| 4067 B(Mov), R(1), R(2), // | 4426 B(Mov), R(1), R(2), // |
| 4068 B(Ldar), R(0), // | 4427 B(Ldar), R(0), // |
| 4069 B(ToName), // | 4428 B(ToName), // |
| 4070 B(Star), R(3), // | 4429 B(Star), R(3), // |
| 4071 B(LdaSmi8), U8(1), // | 4430 B(LdaSmi8), U8(1), // |
| 4072 B(Star), R(4), // | 4431 B(Star), R(4), // |
| 4073 B(LdaZero), // | 4432 B(LdaZero), // |
| 4074 B(Star), R(5), // | 4433 B(Star), R(5), // |
| 4075 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // | 4434 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // |
| 4076 U8(4), // | 4435 /* */ U8(4), // |
| 4077 B(Ldar), R(1), // | 4436 B(Ldar), R(1), // |
| 4078 B(Return), // | 4437 B(Return), // |
| 4079 }, | 4438 }, |
| 4080 3, | 4439 3, |
| 4081 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4440 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4082 InstanceType::FIXED_ARRAY_TYPE, | 4441 InstanceType::FIXED_ARRAY_TYPE, |
| 4083 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4442 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4084 {"var a = 'test'; return { [a]: 1, __proto__: {} }", | 4443 {"var a = 'test'; return { [a]: 1, __proto__: {} }", |
| 4085 6 * kPointerSize, | 4444 6 * kPointerSize, |
| 4086 1, | 4445 1, |
| 4087 49, | 4446 50, |
| 4088 { | 4447 { |
| 4448 B(StackCheck), // |
| 4089 B(LdaConstant), U8(0), // | 4449 B(LdaConstant), U8(0), // |
| 4090 B(Star), R(0), // | 4450 B(Star), R(0), // |
| 4091 B(CreateObjectLiteral), U8(1), U8(1), U8(simple_flags), // | 4451 B(CreateObjectLiteral), U8(1), U8(1), U8(simple_flags), // |
| 4092 B(Star), R(1), // | 4452 B(Star), R(1), // |
| 4093 B(Mov), R(1), R(2), // | 4453 B(Mov), R(1), R(2), // |
| 4094 B(Ldar), R(0), // | 4454 B(Ldar), R(0), // |
| 4095 B(ToName), // | 4455 B(ToName), // |
| 4096 B(Star), R(3), // | 4456 B(Star), R(3), // |
| 4097 B(LdaSmi8), U8(1), // | 4457 B(LdaSmi8), U8(1), // |
| 4098 B(Star), R(4), // | 4458 B(Star), R(4), // |
| 4099 B(LdaZero), // | 4459 B(LdaZero), // |
| 4100 B(Star), R(5), // | 4460 B(Star), R(5), // |
| 4101 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // | 4461 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // |
| 4102 U8(4), // | 4462 /* */ U8(4), // |
| 4103 B(Mov), R(1), R(2), // | 4463 B(Mov), R(1), R(2), // |
| 4104 B(CreateObjectLiteral), U8(1), U8(0), U8(13), // | 4464 B(CreateObjectLiteral), U8(1), U8(0), U8(13), // |
| 4105 B(Star), R(4), // | 4465 B(Star), R(4), // |
| 4106 B(Star), R(3), // | 4466 B(Star), R(3), // |
| 4107 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(2), U8(2), // | 4467 B(CallRuntime), U16(Runtime::kInternalSetPrototype), R(2), U8(2), // |
| 4108 B(Ldar), R(1), // | 4468 B(Ldar), R(1), // |
| 4109 B(Return), // | 4469 B(Return), // |
| 4110 }, | 4470 }, |
| 4111 2, | 4471 2, |
| 4112 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4472 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4113 InstanceType::FIXED_ARRAY_TYPE}}, | 4473 InstanceType::FIXED_ARRAY_TYPE}}, |
| 4114 {"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };", | 4474 {"var n = 'name'; return { [n]: 'val', get a() { }, set a(b) {} };", |
| 4115 6 * kPointerSize, | 4475 6 * kPointerSize, |
| 4116 1, | 4476 1, |
| 4117 73, | 4477 74, |
| 4118 { | 4478 { |
| 4479 B(StackCheck), // |
| 4119 B(LdaConstant), U8(0), // | 4480 B(LdaConstant), U8(0), // |
| 4120 B(Star), R(0), // | 4481 B(Star), R(0), // |
| 4121 B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), // | 4482 B(CreateObjectLiteral), U8(1), U8(0), U8(simple_flags), // |
| 4122 B(Star), R(1), // | 4483 B(Star), R(1), // |
| 4123 B(Mov), R(1), R(2), // | 4484 B(Mov), R(1), R(2), // |
| 4124 B(Ldar), R(0), // | 4485 B(Ldar), R(0), // |
| 4125 B(ToName), // | 4486 B(ToName), // |
| 4126 B(Star), R(3), // | 4487 B(Star), R(3), // |
| 4127 B(LdaConstant), U8(2), // | 4488 B(LdaConstant), U8(2), // |
| 4128 B(Star), R(4), // | 4489 B(Star), R(4), // |
| 4129 B(LdaZero), // | 4490 B(LdaZero), // |
| 4130 B(Star), R(5), // | 4491 B(Star), R(5), // |
| 4131 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // | 4492 B(CallRuntime), U16(Runtime::kDefineDataPropertyUnchecked), R(2), // |
| 4132 U8(4), // | 4493 /* */ U8(4), // |
| 4133 B(Mov), R(1), R(2), // | 4494 B(Mov), R(1), R(2), // |
| 4134 B(LdaConstant), U8(3), // | 4495 B(LdaConstant), U8(3), // |
| 4135 B(Star), R(3), // | 4496 B(Star), R(3), // |
| 4136 B(CreateClosure), U8(4), U8(0), // | 4497 B(CreateClosure), U8(4), U8(0), // |
| 4137 B(Star), R(4), // | 4498 B(Star), R(4), // |
| 4138 B(LdaZero), // | 4499 B(LdaZero), // |
| 4139 B(Star), R(5), // | 4500 B(Star), R(5), // |
| 4140 B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), // | 4501 B(CallRuntime), U16(Runtime::kDefineGetterPropertyUnchecked), // |
| 4141 R(2), U8(4), // | 4502 /* */ R(2), U8(4), // |
| 4142 B(Mov), R(1), R(2), // | 4503 B(Mov), R(1), R(2), // |
| 4143 B(LdaConstant), U8(3), // | 4504 B(LdaConstant), U8(3), // |
| 4144 B(Star), R(3), // | 4505 B(Star), R(3), // |
| 4145 B(CreateClosure), U8(5), U8(0), // | 4506 B(CreateClosure), U8(5), U8(0), // |
| 4146 B(Star), R(4), // | 4507 B(Star), R(4), // |
| 4147 B(LdaZero), // | 4508 B(LdaZero), // |
| 4148 B(Star), R(5), // | 4509 B(Star), R(5), // |
| 4149 B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), // | 4510 B(CallRuntime), U16(Runtime::kDefineSetterPropertyUnchecked), // |
| 4150 R(2), U8(4), // | 4511 /* */ R(2), U8(4), // |
| 4151 B(Ldar), R(1), // | 4512 B(Ldar), R(1), // |
| 4152 B(Return), // | 4513 B(Return), // |
| 4153 }, | 4514 }, |
| 4154 6, | 4515 6, |
| 4155 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4516 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4156 InstanceType::FIXED_ARRAY_TYPE, | 4517 InstanceType::FIXED_ARRAY_TYPE, |
| 4157 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4518 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4158 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4519 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4159 InstanceType::SHARED_FUNCTION_INFO_TYPE, | 4520 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 4160 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4521 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4161 }; | 4522 }; |
| 4523 // clang-format on |
| 4162 | 4524 |
| 4163 for (size_t i = 0; i < arraysize(snippets); i++) { | 4525 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4164 Handle<BytecodeArray> bytecode_array = | 4526 Handle<BytecodeArray> bytecode_array = |
| 4165 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4527 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4166 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4528 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4167 } | 4529 } |
| 4168 } | 4530 } |
| 4169 | 4531 |
| 4170 | 4532 |
| 4171 TEST(ObjectLiteralsWide) { | 4533 TEST(ObjectLiteralsWide) { |
| 4172 InitializedHandleScope handle_scope; | 4534 InitializedHandleScope handle_scope; |
| 4173 BytecodeGeneratorHelper helper; | 4535 BytecodeGeneratorHelper helper; |
| 4174 Zone zone; | 4536 Zone zone; |
| 4175 | 4537 |
| 4176 int deep_elements_flags = | 4538 int deep_elements_flags = |
| 4177 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 4539 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 4178 int wide_idx = 0; | 4540 int wide_idx = 0; |
| 4179 | 4541 |
| 4542 // clang-format off |
| 4180 ExpectedSnippet<InstanceType, 257> snippets[] = { | 4543 ExpectedSnippet<InstanceType, 257> snippets[] = { |
| 4181 {"var a;" REPEAT_256(SPACE, | 4544 {"var a;" REPEAT_256(SPACE, |
| 4182 "a = 1.23;") "return { name: 'string', val: 9.2 };", | 4545 "a = 1.23;") "return { name: 'string', val: 9.2 };", |
| 4183 2 * kPointerSize, | 4546 2 * kPointerSize, |
| 4184 1, | 4547 1, |
| 4185 1033, | 4548 1034, |
| 4186 { | 4549 { |
| 4187 REPEAT_256(COMMA, // | 4550 B(StackCheck), // |
| 4188 B(LdaConstant), U8(wide_idx++), // | 4551 REPEAT_256(COMMA, // |
| 4189 B(Star), R(0)), // | 4552 B(LdaConstant), U8(wide_idx++), // |
| 4190 B(CreateObjectLiteralWide), | 4553 B(Star), R(0)), // |
| 4191 U16(256), U16(0), // | 4554 B(CreateObjectLiteralWide), U16(256), U16(0), // |
| 4192 U8(deep_elements_flags), // | 4555 /* */ U8(deep_elements_flags), // |
| 4193 B(Star), R(1), // | 4556 B(Star), R(1), // |
| 4194 B(Return) // | 4557 B(Return) // |
| 4195 }, | 4558 }, |
| 4196 257, | 4559 257, |
| 4197 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 4560 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 4198 InstanceType::FIXED_ARRAY_TYPE}}, | 4561 InstanceType::FIXED_ARRAY_TYPE}}, |
| 4199 }; | 4562 }; |
| 4563 // clang-format on |
| 4200 | 4564 |
| 4201 for (size_t i = 0; i < arraysize(snippets); i++) { | 4565 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4202 Handle<BytecodeArray> bytecode_array = | 4566 Handle<BytecodeArray> bytecode_array = |
| 4203 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4567 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4204 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4568 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4205 } | 4569 } |
| 4206 } | 4570 } |
| 4207 | 4571 |
| 4208 | 4572 |
| 4209 TEST(TopLevelObjectLiterals) { | 4573 TEST(TopLevelObjectLiterals) { |
| 4210 InitializedHandleScope handle_scope; | 4574 InitializedHandleScope handle_scope; |
| 4211 BytecodeGeneratorHelper helper; | 4575 BytecodeGeneratorHelper helper; |
| 4212 | 4576 |
| 4213 int has_function_flags = ObjectLiteral::kFastElements | | 4577 int has_function_flags = ObjectLiteral::kFastElements | |
| 4214 ObjectLiteral::kHasFunction | | 4578 ObjectLiteral::kHasFunction | |
| 4215 ObjectLiteral::kDisableMementos; | 4579 ObjectLiteral::kDisableMementos; |
| 4580 // clang-format off |
| 4216 ExpectedSnippet<InstanceType> snippets[] = { | 4581 ExpectedSnippet<InstanceType> snippets[] = { |
| 4217 {"var a = { func: function() { } };", | 4582 {"var a = { func: function() { } };", |
| 4218 5 * kPointerSize, | 4583 5 * kPointerSize, |
| 4219 1, | 4584 1, |
| 4220 48, | 4585 49, |
| 4221 { | 4586 { |
| 4222 B(LdaConstant), U8(0), // | 4587 B(LdaConstant), U8(0), // |
| 4223 B(Star), R(1), // | 4588 B(Star), R(1), // |
| 4224 B(LdaZero), // | 4589 B(LdaZero), // |
| 4225 B(Star), R(2), // | 4590 B(Star), R(2), // |
| 4226 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 4591 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
| 4592 B(StackCheck), // |
| 4227 B(LdaConstant), U8(1), // | 4593 B(LdaConstant), U8(1), // |
| 4228 B(Star), R(1), // | 4594 B(Star), R(1), // |
| 4229 B(LdaZero), // | 4595 B(LdaZero), // |
| 4230 B(Star), R(2), // | 4596 B(Star), R(2), // |
| 4231 B(CreateObjectLiteral), U8(2), U8(0), U8(has_function_flags), // | 4597 B(CreateObjectLiteral), U8(2), U8(0), U8(has_function_flags), // |
| 4232 B(Star), R(4), // | 4598 B(Star), R(4), // |
| 4233 B(CreateClosure), U8(3), U8(1), // | 4599 B(CreateClosure), U8(3), U8(1), // |
| 4234 B(StoreICSloppy), R(4), U8(4), U8(3), // | 4600 B(StoreICSloppy), R(4), U8(4), U8(3), // |
| 4235 B(CallRuntime), U16(Runtime::kToFastProperties), R(4), U8(1), // | 4601 B(CallRuntime), U16(Runtime::kToFastProperties), R(4), U8(1), // |
| 4236 B(Ldar), R(4), // | 4602 B(Ldar), R(4), // |
| 4237 B(Star), R(3), // | 4603 B(Star), R(3), // |
| 4238 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // | 4604 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3), // |
| 4239 B(LdaUndefined), // | 4605 B(LdaUndefined), // |
| 4240 B(Return), // | 4606 B(Return), // |
| 4241 }, | 4607 }, |
| 4242 5, | 4608 5, |
| 4243 {InstanceType::FIXED_ARRAY_TYPE, | 4609 {InstanceType::FIXED_ARRAY_TYPE, |
| 4244 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 4610 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 4245 InstanceType::FIXED_ARRAY_TYPE, | 4611 InstanceType::FIXED_ARRAY_TYPE, |
| 4246 InstanceType::SHARED_FUNCTION_INFO_TYPE, | 4612 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 4247 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4613 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4248 }; | 4614 }; |
| 4615 // clang-format on |
| 4249 | 4616 |
| 4250 for (size_t i = 0; i < arraysize(snippets); i++) { | 4617 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4251 Handle<BytecodeArray> bytecode_array = | 4618 Handle<BytecodeArray> bytecode_array = |
| 4252 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 4619 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
| 4253 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4620 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4254 } | 4621 } |
| 4255 } | 4622 } |
| 4256 | 4623 |
| 4257 | 4624 |
| 4258 TEST(TryCatch) { | 4625 TEST(TryCatch) { |
| 4259 InitializedHandleScope handle_scope; | 4626 InitializedHandleScope handle_scope; |
| 4260 BytecodeGeneratorHelper helper; | 4627 BytecodeGeneratorHelper helper; |
| 4261 | 4628 |
| 4262 int closure = Register::function_closure().index(); | 4629 int closure = Register::function_closure().index(); |
| 4263 | 4630 |
| 4631 // clang-format off |
| 4264 ExpectedSnippet<const char*> snippets[] = { | 4632 ExpectedSnippet<const char*> snippets[] = { |
| 4265 {"try { return 1; } catch(e) { return 2; }", | 4633 {"try { return 1; } catch(e) { return 2; }", |
| 4266 5 * kPointerSize, | 4634 5 * kPointerSize, |
| 4267 1, | 4635 1, |
| 4268 36, | 4636 37, |
| 4269 { | 4637 { |
| 4638 B(StackCheck), // |
| 4270 B(LdaSmi8), U8(1), // | 4639 B(LdaSmi8), U8(1), // |
| 4271 B(Return), // | 4640 B(Return), // |
| 4272 B(Star), R(3), // | 4641 B(Star), R(3), // |
| 4273 B(LdaConstant), U8(0), // | 4642 B(LdaConstant), U8(0), // |
| 4274 B(Star), R(2), // | 4643 B(Star), R(2), // |
| 4275 B(Ldar), R(closure), // | 4644 B(Ldar), R(closure), // |
| 4276 B(Star), R(4), // | 4645 B(Star), R(4), // |
| 4277 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // | 4646 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // |
| 4278 B(Star), R(1), // | 4647 B(Star), R(1), // |
| 4279 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4648 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4280 /* */ R(0), U8(0), // | 4649 /* */ R(0), U8(0), // |
| 4281 B(Ldar), R(1), // | 4650 B(Ldar), R(1), // |
| 4282 B(PushContext), R(0), // | 4651 B(PushContext), R(0), // |
| 4283 B(LdaSmi8), U8(2), // | 4652 B(LdaSmi8), U8(2), // |
| 4284 B(PopContext), R(0), // | 4653 B(PopContext), R(0), // |
| 4285 B(Return), // | 4654 B(Return), // |
| 4286 // TODO(mstarzinger): Potential optimization, elide next bytes. | 4655 // TODO(mstarzinger): Potential optimization, elide next bytes. |
| 4287 B(LdaUndefined), // | 4656 B(LdaUndefined), // |
| 4288 B(Return), // | 4657 B(Return), // |
| 4289 }, | 4658 }, |
| 4290 1, | 4659 1, |
| 4291 {"e"}, | 4660 {"e"}, |
| 4292 1, | 4661 1, |
| 4293 {{0, 3, 3}}}, | 4662 {{1, 4, 4}}}, |
| 4294 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", | 4663 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", |
| 4295 6 * kPointerSize, | 4664 6 * kPointerSize, |
| 4296 1, | 4665 1, |
| 4297 74, | 4666 75, |
| 4298 { | 4667 { |
| 4668 B(StackCheck), // |
| 4299 B(LdaSmi8), U8(1), // | 4669 B(LdaSmi8), U8(1), // |
| 4300 B(Star), R(0), // | 4670 B(Star), R(0), // |
| 4301 B(Jump), U8(30), // | 4671 B(Jump), U8(30), // |
| 4302 B(Star), R(4), // | 4672 B(Star), R(4), // |
| 4303 B(LdaConstant), U8(0), // | 4673 B(LdaConstant), U8(0), // |
| 4304 B(Star), R(3), // | 4674 B(Star), R(3), // |
| 4305 B(Ldar), R(closure), // | 4675 B(Ldar), R(closure), // |
| 4306 B(Star), R(5), // | 4676 B(Star), R(5), // |
| 4307 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4677 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4308 B(Star), R(2), // | 4678 B(Star), R(2), // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4327 B(PushContext), R(1), // | 4697 B(PushContext), R(1), // |
| 4328 B(LdaSmi8), U8(3), // | 4698 B(LdaSmi8), U8(3), // |
| 4329 B(Star), R(0), // | 4699 B(Star), R(0), // |
| 4330 B(PopContext), R(1), // | 4700 B(PopContext), R(1), // |
| 4331 B(LdaUndefined), // | 4701 B(LdaUndefined), // |
| 4332 B(Return), // | 4702 B(Return), // |
| 4333 }, | 4703 }, |
| 4334 2, | 4704 2, |
| 4335 {"e1", "e2"}, | 4705 {"e1", "e2"}, |
| 4336 2, | 4706 2, |
| 4337 {{0, 4, 6}, {34, 38, 40}}}, | 4707 {{1, 5, 7}, {35, 39, 41}}}, |
| 4338 }; | 4708 }; |
| 4709 // clang-format on |
| 4339 | 4710 |
| 4340 for (size_t i = 0; i < arraysize(snippets); i++) { | 4711 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4341 Handle<BytecodeArray> bytecode_array = | 4712 Handle<BytecodeArray> bytecode_array = |
| 4342 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4713 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4343 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4714 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4344 } | 4715 } |
| 4345 } | 4716 } |
| 4346 | 4717 |
| 4347 | 4718 |
| 4348 TEST(TryFinally) { | 4719 TEST(TryFinally) { |
| 4349 InitializedHandleScope handle_scope; | 4720 InitializedHandleScope handle_scope; |
| 4350 BytecodeGeneratorHelper helper; | 4721 BytecodeGeneratorHelper helper; |
| 4351 | 4722 |
| 4352 int closure = Register::function_closure().index(); | 4723 int closure = Register::function_closure().index(); |
| 4353 | 4724 |
| 4725 // clang-format off |
| 4354 ExpectedSnippet<const char*> snippets[] = { | 4726 ExpectedSnippet<const char*> snippets[] = { |
| 4355 {"var a = 1; try { a = 2; } finally { a = 3; }", | 4727 {"var a = 1; try { a = 2; } finally { a = 3; }", |
| 4356 4 * kPointerSize, | 4728 4 * kPointerSize, |
| 4357 1, | 4729 1, |
| 4358 47, | 4730 48, |
| 4359 { | 4731 { |
| 4732 B(StackCheck), // |
| 4360 B(LdaSmi8), U8(1), // | 4733 B(LdaSmi8), U8(1), // |
| 4361 B(Star), R(0), // | 4734 B(Star), R(0), // |
| 4362 B(LdaSmi8), U8(2), // | 4735 B(LdaSmi8), U8(2), // |
| 4363 B(Star), R(0), // | 4736 B(Star), R(0), // |
| 4364 B(LdaSmi8), U8(-1), // | 4737 B(LdaSmi8), U8(-1), // |
| 4365 B(Star), R(1), // | 4738 B(Star), R(1), // |
| 4366 B(Jump), U8(7), // | 4739 B(Jump), U8(7), // |
| 4367 B(Star), R(2), // | 4740 B(Star), R(2), // |
| 4368 B(LdaZero), // | 4741 B(LdaZero), // |
| 4369 B(Star), R(1), // | 4742 B(Star), R(1), // |
| 4370 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4743 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4371 /* */ R(0), U8(0), // | 4744 /* */ R(0), U8(0), // |
| 4372 B(Star), R(3), // | 4745 B(Star), R(3), // |
| 4373 B(LdaSmi8), U8(3), // | 4746 B(LdaSmi8), U8(3), // |
| 4374 B(Star), R(0), // | 4747 B(Star), R(0), // |
| 4375 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // | 4748 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4376 /* */ R(3), U8(1), // | 4749 /* */ R(3), U8(1), // |
| 4377 B(LdaZero), // | 4750 B(LdaZero), // |
| 4378 B(TestEqualStrict), R(1), // | 4751 B(TestEqualStrict), R(1), // |
| 4379 B(JumpIfTrue), U8(4), // | 4752 B(JumpIfTrue), U8(4), // |
| 4380 B(Jump), U8(5), // | 4753 B(Jump), U8(5), // |
| 4381 B(Ldar), R(2), // | 4754 B(Ldar), R(2), // |
| 4382 B(ReThrow), // | 4755 B(ReThrow), // |
| 4383 B(LdaUndefined), // | 4756 B(LdaUndefined), // |
| 4384 B(Return), // | 4757 B(Return), // |
| 4385 }, | 4758 }, |
| 4386 0, | 4759 0, |
| 4387 {}, | 4760 {}, |
| 4388 1, | 4761 1, |
| 4389 {{4, 8, 14}}}, | 4762 {{5, 9, 15}}}, |
| 4390 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4763 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4391 9 * kPointerSize, | 4764 9 * kPointerSize, |
| 4392 1, | 4765 1, |
| 4393 81, | 4766 82, |
| 4394 { | 4767 { |
| 4768 B(StackCheck), // |
| 4395 B(LdaSmi8), U8(1), // | 4769 B(LdaSmi8), U8(1), // |
| 4396 B(Star), R(0), // | 4770 B(Star), R(0), // |
| 4397 B(LdaSmi8), U8(2), // | 4771 B(LdaSmi8), U8(2), // |
| 4398 B(Star), R(0), // | 4772 B(Star), R(0), // |
| 4399 B(Jump), U8(34), // | 4773 B(Jump), U8(34), // |
| 4400 B(Star), R(7), // | 4774 B(Star), R(7), // |
| 4401 B(LdaConstant), U8(0), // | 4775 B(LdaConstant), U8(0), // |
| 4402 B(Star), R(6), // | 4776 B(Star), R(6), // |
| 4403 B(Ldar), R(closure), // | 4777 B(Ldar), R(closure), // |
| 4404 B(Star), R(8), // | 4778 B(Star), R(8), // |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4429 B(JumpIfTrue), U8(4), // | 4803 B(JumpIfTrue), U8(4), // |
| 4430 B(Jump), U8(5), // | 4804 B(Jump), U8(5), // |
| 4431 B(Ldar), R(3), // | 4805 B(Ldar), R(3), // |
| 4432 B(ReThrow), // | 4806 B(ReThrow), // |
| 4433 B(LdaUndefined), // | 4807 B(LdaUndefined), // |
| 4434 B(Return), // | 4808 B(Return), // |
| 4435 }, | 4809 }, |
| 4436 1, | 4810 1, |
| 4437 {"e"}, | 4811 {"e"}, |
| 4438 2, | 4812 2, |
| 4439 {{4, 42, 48}, {4, 8, 10}}}, | 4813 {{5, 43, 49}, {5, 9, 11}}}, |
| 4440 {"var a; try {" | 4814 {"var a; try {" |
| 4441 " try { a = 1 } catch(e) { a = 2 }" | 4815 " try { a = 1 } catch(e) { a = 2 }" |
| 4442 "} catch(e) { a = 20 } finally { a = 3; }", | 4816 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4443 10 * kPointerSize, | 4817 10 * kPointerSize, |
| 4444 1, | 4818 1, |
| 4445 111, | 4819 112, |
| 4446 { | 4820 { |
| 4821 B(StackCheck), // |
| 4447 B(LdaSmi8), U8(1), // | 4822 B(LdaSmi8), U8(1), // |
| 4448 B(Star), R(0), // | 4823 B(Star), R(0), // |
| 4449 B(Jump), U8(34), // | 4824 B(Jump), U8(34), // |
| 4450 B(Star), R(8), // | 4825 B(Star), R(8), // |
| 4451 B(LdaConstant), U8(0), // | 4826 B(LdaConstant), U8(0), // |
| 4452 B(Star), R(7), // | 4827 B(Star), R(7), // |
| 4453 B(Ldar), R(closure), // | 4828 B(Ldar), R(closure), // |
| 4454 B(Star), R(9), // | 4829 B(Star), R(9), // |
| 4455 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // | 4830 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // |
| 4456 B(Star), R(6), // | 4831 B(Star), R(6), // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4494 B(JumpIfTrue), U8(4), // | 4869 B(JumpIfTrue), U8(4), // |
| 4495 B(Jump), U8(5), // | 4870 B(Jump), U8(5), // |
| 4496 B(Ldar), R(3), // | 4871 B(Ldar), R(3), // |
| 4497 B(ReThrow), // | 4872 B(ReThrow), // |
| 4498 B(LdaUndefined), // | 4873 B(LdaUndefined), // |
| 4499 B(Return), // | 4874 B(Return), // |
| 4500 }, | 4875 }, |
| 4501 1, | 4876 1, |
| 4502 {"e"}, | 4877 {"e"}, |
| 4503 3, | 4878 3, |
| 4504 {{0, 72, 78}, {0, 38, 40}, {0, 4, 6}}}, | 4879 {{1, 73, 79}, {1, 39, 41}, {1, 5, 7}}}, |
| 4505 }; | 4880 }; |
| 4881 // clang-format on |
| 4506 | 4882 |
| 4507 for (size_t i = 0; i < arraysize(snippets); i++) { | 4883 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4508 Handle<BytecodeArray> bytecode_array = | 4884 Handle<BytecodeArray> bytecode_array = |
| 4509 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4510 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4886 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4511 } | 4887 } |
| 4512 } | 4888 } |
| 4513 | 4889 |
| 4514 | 4890 |
| 4515 TEST(Throw) { | 4891 TEST(Throw) { |
| 4516 InitializedHandleScope handle_scope; | 4892 InitializedHandleScope handle_scope; |
| 4517 BytecodeGeneratorHelper helper; | 4893 BytecodeGeneratorHelper helper; |
| 4518 | 4894 |
| 4895 // clang-format off |
| 4519 ExpectedSnippet<const char*> snippets[] = { | 4896 ExpectedSnippet<const char*> snippets[] = { |
| 4520 {"throw 1;", | 4897 {"throw 1;", |
| 4521 0, | 4898 0, |
| 4522 1, | 4899 1, |
| 4523 3, | 4900 4, |
| 4524 { | 4901 { |
| 4902 B(StackCheck), // |
| 4525 B(LdaSmi8), U8(1), // | 4903 B(LdaSmi8), U8(1), // |
| 4526 B(Throw), // | 4904 B(Throw), // |
| 4527 }, | 4905 }, |
| 4528 0}, | 4906 0}, |
| 4529 {"throw 'Error';", | 4907 {"throw 'Error';", |
| 4530 0, | 4908 0, |
| 4531 1, | 4909 1, |
| 4532 3, | 4910 4, |
| 4533 { | 4911 { |
| 4912 B(StackCheck), // |
| 4534 B(LdaConstant), U8(0), // | 4913 B(LdaConstant), U8(0), // |
| 4535 B(Throw), // | 4914 B(Throw), // |
| 4536 }, | 4915 }, |
| 4537 1, | 4916 1, |
| 4538 {"Error"}}, | 4917 {"Error"}}, |
| 4539 {"var a = 1; if (a) { throw 'Error'; };", | 4918 {"var a = 1; if (a) { throw 'Error'; };", |
| 4540 1 * kPointerSize, | 4919 1 * kPointerSize, |
| 4541 1, | 4920 1, |
| 4542 11, | 4921 12, |
| 4543 { | 4922 { |
| 4923 B(StackCheck), // |
| 4544 B(LdaSmi8), U8(1), // | 4924 B(LdaSmi8), U8(1), // |
| 4545 B(Star), R(0), // | 4925 B(Star), R(0), // |
| 4546 B(JumpIfToBooleanFalse), U8(5), // | 4926 B(JumpIfToBooleanFalse), U8(5), // |
| 4547 B(LdaConstant), U8(0), // | 4927 B(LdaConstant), U8(0), // |
| 4548 B(Throw), // | 4928 B(Throw), // |
| 4549 B(LdaUndefined), // | 4929 B(LdaUndefined), // |
| 4550 B(Return), // | 4930 B(Return), // |
| 4551 }, | 4931 }, |
| 4552 1, | 4932 1, |
| 4553 {"Error"}}, | 4933 {"Error"}}, |
| 4554 }; | 4934 }; |
| 4935 // clang-format on |
| 4555 | 4936 |
| 4556 for (size_t i = 0; i < arraysize(snippets); i++) { | 4937 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4557 Handle<BytecodeArray> bytecode_array = | 4938 Handle<BytecodeArray> bytecode_array = |
| 4558 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4939 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4559 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4940 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4560 } | 4941 } |
| 4561 } | 4942 } |
| 4562 | 4943 |
| 4563 | 4944 |
| 4564 TEST(CallNew) { | 4945 TEST(CallNew) { |
| 4565 InitializedHandleScope handle_scope; | 4946 InitializedHandleScope handle_scope; |
| 4566 BytecodeGeneratorHelper helper; | 4947 BytecodeGeneratorHelper helper; |
| 4567 Zone zone; | 4948 Zone zone; |
| 4568 | 4949 |
| 4569 FeedbackVectorSpec feedback_spec(&zone); | 4950 FeedbackVectorSpec feedback_spec(&zone); |
| 4570 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 4951 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
| 4571 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 4952 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 4572 USE(slot1); | 4953 USE(slot1); |
| 4573 | 4954 |
| 4574 Handle<i::TypeFeedbackVector> vector = | 4955 Handle<i::TypeFeedbackVector> vector = |
| 4575 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 4956 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 4576 | 4957 |
| 4958 // clang-format off |
| 4577 ExpectedSnippet<InstanceType> snippets[] = { | 4959 ExpectedSnippet<InstanceType> snippets[] = { |
| 4578 {"function bar() { this.value = 0; }\n" | 4960 {"function bar() { this.value = 0; }\n" |
| 4579 "function f() { return new bar(); }\n" | 4961 "function f() { return new bar(); }\n" |
| 4580 "f()", | 4962 "f()", |
| 4581 1 * kPointerSize, | 4963 1 * kPointerSize, |
| 4582 1, | 4964 1, |
| 4583 10, | 4965 11, |
| 4584 { | 4966 { |
| 4967 B(StackCheck), // |
| 4585 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 4968 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 4586 B(Star), R(0), // | 4969 B(Star), R(0), // |
| 4587 B(New), R(0), R(0), U8(0), // | 4970 B(New), R(0), R(0), U8(0), // |
| 4588 B(Return), // | 4971 B(Return), // |
| 4589 }, | 4972 }, |
| 4590 1, | 4973 1, |
| 4591 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4974 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4592 {"function bar(x) { this.value = 18; this.x = x;}\n" | 4975 {"function bar(x) { this.value = 18; this.x = x;}\n" |
| 4593 "function f() { return new bar(3); }\n" | 4976 "function f() { return new bar(3); }\n" |
| 4594 "f()", | 4977 "f()", |
| 4595 2 * kPointerSize, | 4978 2 * kPointerSize, |
| 4596 1, | 4979 1, |
| 4597 14, | 4980 15, |
| 4598 { | 4981 { |
| 4982 B(StackCheck), // |
| 4599 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 4983 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 4600 B(Star), R(0), // | 4984 B(Star), R(0), // |
| 4601 B(LdaSmi8), U8(3), // | 4985 B(LdaSmi8), U8(3), // |
| 4602 B(Star), R(1), // | 4986 B(Star), R(1), // |
| 4603 B(New), R(0), R(1), U8(1), // | 4987 B(New), R(0), R(1), U8(1), // |
| 4604 B(Return), // | 4988 B(Return), // |
| 4605 }, | 4989 }, |
| 4606 1, | 4990 1, |
| 4607 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 4991 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4608 {"function bar(w, x, y, z) {\n" | 4992 {"function bar(w, x, y, z) {\n" |
| 4609 " this.value = 18;\n" | 4993 " this.value = 18;\n" |
| 4610 " this.x = x;\n" | 4994 " this.x = x;\n" |
| 4611 " this.y = y;\n" | 4995 " this.y = y;\n" |
| 4612 " this.z = z;\n" | 4996 " this.z = z;\n" |
| 4613 "}\n" | 4997 "}\n" |
| 4614 "function f() { return new bar(3, 4, 5); }\n" | 4998 "function f() { return new bar(3, 4, 5); }\n" |
| 4615 "f()", | 4999 "f()", |
| 4616 4 * kPointerSize, | 5000 4 * kPointerSize, |
| 4617 1, | 5001 1, |
| 4618 22, | 5002 23, |
| 4619 { | 5003 { |
| 5004 B(StackCheck), // |
| 4620 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5005 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 4621 B(Star), R(0), // | 5006 B(Star), R(0), // |
| 4622 B(LdaSmi8), U8(3), // | 5007 B(LdaSmi8), U8(3), // |
| 4623 B(Star), R(1), // | 5008 B(Star), R(1), // |
| 4624 B(LdaSmi8), U8(4), // | 5009 B(LdaSmi8), U8(4), // |
| 4625 B(Star), R(2), // | 5010 B(Star), R(2), // |
| 4626 B(LdaSmi8), U8(5), // | 5011 B(LdaSmi8), U8(5), // |
| 4627 B(Star), R(3), // | 5012 B(Star), R(3), // |
| 4628 B(New), R(0), R(1), U8(3), // | 5013 B(New), R(0), R(1), U8(3), // |
| 4629 B(Return), // | 5014 B(Return), // |
| 4630 }, | 5015 }, |
| 4631 1, | 5016 1, |
| 4632 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 5017 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4633 }; | 5018 }; |
| 5019 // clang-format on |
| 4634 | 5020 |
| 4635 for (size_t i = 0; i < arraysize(snippets); i++) { | 5021 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4636 Handle<BytecodeArray> bytecode_array = | 5022 Handle<BytecodeArray> bytecode_array = |
| 4637 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 5023 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 4638 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5024 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4639 } | 5025 } |
| 4640 } | 5026 } |
| 4641 | 5027 |
| 4642 | 5028 |
| 4643 TEST(ContextVariables) { | 5029 TEST(ContextVariables) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4655 int context = Register::current_context().index(); | 5041 int context = Register::current_context().index(); |
| 4656 int new_target = Register::new_target().index(); | 5042 int new_target = Register::new_target().index(); |
| 4657 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5043 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 4658 | 5044 |
| 4659 // The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this | 5045 // The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this |
| 4660 // ever changes, the REPEAT_XXX should be changed to output the correct number | 5046 // ever changes, the REPEAT_XXX should be changed to output the correct number |
| 4661 // of unique variables to trigger the wide slot load / store. | 5047 // of unique variables to trigger the wide slot load / store. |
| 4662 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256); | 5048 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256); |
| 4663 int wide_slot = first_context_slot + 3; | 5049 int wide_slot = first_context_slot + 3; |
| 4664 | 5050 |
| 5051 // clang-format off |
| 4665 ExpectedSnippet<InstanceType> snippets[] = { | 5052 ExpectedSnippet<InstanceType> snippets[] = { |
| 4666 {"var a; return function() { a = 1; };", | 5053 {"var a; return function() { a = 1; };", |
| 4667 1 * kPointerSize, | 5054 1 * kPointerSize, |
| 4668 1, | 5055 1, |
| 4669 11, | 5056 12, |
| 4670 { | 5057 { |
| 4671 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5058 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4672 R(closure), U8(1), // | 5059 /* */ R(closure), U8(1), // |
| 4673 B(PushContext), R(0), // | 5060 B(PushContext), R(0), // |
| 5061 B(StackCheck), // |
| 4674 B(CreateClosure), U8(0), U8(0), // | 5062 B(CreateClosure), U8(0), U8(0), // |
| 4675 B(Return), // | 5063 B(Return), // |
| 4676 }, | 5064 }, |
| 4677 1, | 5065 1, |
| 4678 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5066 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4679 {"var a = 1; return function() { a = 2; };", | 5067 {"var a = 1; return function() { a = 2; };", |
| 4680 1 * kPointerSize, | 5068 1 * kPointerSize, |
| 4681 1, | 5069 1, |
| 4682 16, | 5070 17, |
| 4683 { | 5071 { |
| 4684 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5072 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4685 R(closure), U8(1), // | 5073 /* */ R(closure), U8(1), // |
| 4686 B(PushContext), R(0), // | 5074 B(PushContext), R(0), // |
| 5075 B(StackCheck), // |
| 4687 B(LdaSmi8), U8(1), // | 5076 B(LdaSmi8), U8(1), // |
| 4688 B(StaContextSlot), R(context), U8(first_context_slot), // | 5077 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4689 B(CreateClosure), U8(0), U8(0), // | 5078 B(CreateClosure), U8(0), U8(0), // |
| 4690 B(Return), // | 5079 B(Return), // |
| 4691 }, | 5080 }, |
| 4692 1, | 5081 1, |
| 4693 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5082 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4694 {"var a = 1; var b = 2; return function() { a = 2; b = 3 };", | 5083 {"var a = 1; var b = 2; return function() { a = 2; b = 3 };", |
| 4695 1 * kPointerSize, | 5084 1 * kPointerSize, |
| 4696 1, | 5085 1, |
| 4697 21, | 5086 22, |
| 4698 { | 5087 { |
| 4699 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5088 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4700 R(closure), U8(1), // | 5089 /* */ R(closure), U8(1), // |
| 4701 B(PushContext), R(0), // | 5090 B(PushContext), R(0), // |
| 5091 B(StackCheck), // |
| 4702 B(LdaSmi8), U8(1), // | 5092 B(LdaSmi8), U8(1), // |
| 4703 B(StaContextSlot), R(context), U8(first_context_slot), // | 5093 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4704 B(LdaSmi8), U8(2), // | 5094 B(LdaSmi8), U8(2), // |
| 4705 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 5095 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 4706 B(CreateClosure), U8(0), U8(0), // | 5096 B(CreateClosure), U8(0), U8(0), // |
| 4707 B(Return), // | 5097 B(Return), // |
| 4708 }, | 5098 }, |
| 4709 1, | 5099 1, |
| 4710 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5100 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4711 {"var a; (function() { a = 2; })(); return a;", | 5101 {"var a; (function() { a = 2; })(); return a;", |
| 4712 3 * kPointerSize, | 5102 3 * kPointerSize, |
| 4713 1, | 5103 1, |
| 4714 24, | 5104 25, |
| 4715 { | 5105 { |
| 4716 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5106 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4717 R(closure), U8(1), // | 5107 /* */ R(closure), U8(1), // |
| 4718 B(PushContext), R(0), // | 5108 B(PushContext), R(0), // |
| 5109 B(StackCheck), // |
| 4719 B(LdaUndefined), // | 5110 B(LdaUndefined), // |
| 4720 B(Star), R(2), // | 5111 B(Star), R(2), // |
| 4721 B(CreateClosure), U8(0), U8(0), // | 5112 B(CreateClosure), U8(0), U8(0), // |
| 4722 B(Star), R(1), // | 5113 B(Star), R(1), // |
| 4723 B(Call), R(1), R(2), U8(1), U8(vector->GetIndex(slot)), // | 5114 B(Call), R(1), R(2), U8(1), U8(vector->GetIndex(slot)), // |
| 4724 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5115 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 4725 B(Return), // | 5116 B(Return), // |
| 4726 }, | 5117 }, |
| 4727 1, | 5118 1, |
| 4728 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5119 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4729 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", | 5120 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", |
| 4730 4 * kPointerSize, | 5121 4 * kPointerSize, |
| 4731 1, | 5122 1, |
| 4732 46, | 5123 47, |
| 4733 { | 5124 { |
| 4734 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5125 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4735 R(closure), U8(1), // | 5126 /* */ R(closure), U8(1), // |
| 4736 B(PushContext), R(0), // | 5127 B(PushContext), R(0), // |
| 4737 B(LdaTheHole), // | 5128 B(LdaTheHole), // |
| 4738 B(StaContextSlot), R(context), U8(first_context_slot), // | 5129 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5130 B(StackCheck), // |
| 4739 B(LdaSmi8), U8(1), // | 5131 B(LdaSmi8), U8(1), // |
| 4740 B(StaContextSlot), R(context), U8(first_context_slot), // | 5132 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4741 B(LdaConstant), U8(0), // | 5133 B(LdaConstant), U8(0), // |
| 4742 B(Star), R(2), // | 5134 B(Star), R(2), // |
| 4743 B(Ldar), R(closure), // | 5135 B(Ldar), R(closure), // |
| 4744 B(Star), R(3), // | 5136 B(Star), R(3), // |
| 4745 B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), // | 5137 B(CallRuntime), U16(Runtime::kPushBlockContext), R(2), U8(2), // |
| 4746 B(PushContext), R(1), // | 5138 B(PushContext), R(1), // |
| 4747 B(LdaTheHole), // | 5139 B(LdaTheHole), // |
| 4748 B(StaContextSlot), R(context), U8(first_context_slot), // | 5140 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4749 B(LdaSmi8), U8(2), // | 5141 B(LdaSmi8), U8(2), // |
| 4750 B(StaContextSlot), R(context), U8(first_context_slot), // | 5142 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4751 B(CreateClosure), U8(1), U8(0), // | 5143 B(CreateClosure), U8(1), U8(0), // |
| 4752 B(PopContext), R(0), // | 5144 B(PopContext), R(0), // |
| 4753 B(Return), // | 5145 B(Return), // |
| 4754 }, | 5146 }, |
| 4755 2, | 5147 2, |
| 4756 {InstanceType::FIXED_ARRAY_TYPE, | 5148 {InstanceType::FIXED_ARRAY_TYPE, |
| 4757 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5149 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4758 {"'use strict';\n" | 5150 {"'use strict';\n" |
| 4759 REPEAT_249_UNIQUE_VARS() | 5151 REPEAT_249_UNIQUE_VARS() |
| 4760 "eval();" | 5152 "eval();" |
| 4761 "var b = 100;" | 5153 "var b = 100;" |
| 4762 "return b", | 5154 "return b", |
| 4763 3 * kPointerSize, | 5155 3 * kPointerSize, |
| 4764 1, | 5156 1, |
| 4765 1041, | 5157 1042, |
| 4766 { | 5158 { |
| 4767 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5159 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 4768 U8(1), // | 5160 /* */ U8(1), // |
| 4769 B(PushContext), R(0), // | 5161 B(PushContext), R(0), // |
| 4770 B(Ldar), THIS(1), // | 5162 B(Ldar), THIS(1), // |
| 4771 B(StaContextSlot), R(context), U8(first_context_slot), // | 5163 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4772 B(CreateUnmappedArguments), // | 5164 B(CreateUnmappedArguments), // |
| 4773 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 5165 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 4774 B(Ldar), R(new_target), // | 5166 B(Ldar), R(new_target), // |
| 4775 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 5167 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 5168 B(StackCheck), // |
| 4776 REPEAT_249(COMMA, // | 5169 REPEAT_249(COMMA, // |
| 4777 B(LdaZero), // | 5170 B(LdaZero), // |
| 4778 B(StaContextSlot), R(context), U8(wide_slot++)), // | 5171 B(StaContextSlot), R(context), U8(wide_slot++)), // |
| 4779 B(LdaUndefined), // | 5172 B(LdaUndefined), // |
| 4780 B(Star), R(2), // | 5173 B(Star), R(2), // |
| 4781 B(LdaGlobalStrict), U8(0), U8(1), // | 5174 B(LdaGlobalStrict), U8(0), U8(1), // |
| 4782 B(Star), R(1), // | 5175 B(Star), R(1), // |
| 4783 B(Call), R(1), R(2), U8(1), U8(0), // | 5176 B(Call), R(1), R(2), U8(1), U8(0), // |
| 4784 B(LdaSmi8), U8(100), // | 5177 B(LdaSmi8), U8(100), // |
| 4785 B(StaContextSlotWide), R(context), U16(256), // | 5178 B(StaContextSlotWide), R(context), U16(256), // |
| 4786 B(LdaContextSlotWide), R(context), U16(256), // | 5179 B(LdaContextSlotWide), R(context), U16(256), // |
| 4787 B(Return), // | 5180 B(Return), // |
| 4788 }, | 5181 }, |
| 4789 1, | 5182 1, |
| 4790 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 5183 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4791 }; | 5184 }; |
| 5185 // clang-format on |
| 4792 | 5186 |
| 4793 for (size_t i = 0; i < arraysize(snippets); i++) { | 5187 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4794 Handle<BytecodeArray> bytecode_array = | 5188 Handle<BytecodeArray> bytecode_array = |
| 4795 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5189 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4796 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5190 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4797 } | 5191 } |
| 4798 } | 5192 } |
| 4799 | 5193 |
| 4800 | 5194 |
| 4801 TEST(ContextParameters) { | 5195 TEST(ContextParameters) { |
| 4802 InitializedHandleScope handle_scope; | 5196 InitializedHandleScope handle_scope; |
| 4803 BytecodeGeneratorHelper helper; | 5197 BytecodeGeneratorHelper helper; |
| 4804 | 5198 |
| 4805 int closure = Register::function_closure().index(); | 5199 int closure = Register::function_closure().index(); |
| 4806 int context = Register::current_context().index(); | 5200 int context = Register::current_context().index(); |
| 4807 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5201 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 4808 | 5202 |
| 5203 // clang-format off |
| 4809 ExpectedSnippet<InstanceType> snippets[] = { | 5204 ExpectedSnippet<InstanceType> snippets[] = { |
| 4810 {"function f(arg1) { return function() { arg1 = 2; }; }", | 5205 {"function f(arg1) { return function() { arg1 = 2; }; }", |
| 4811 1 * kPointerSize, | 5206 1 * kPointerSize, |
| 4812 2, | 5207 2, |
| 4813 16, | 5208 17, |
| 4814 { | 5209 { |
| 4815 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5210 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4816 R(closure), U8(1), // | 5211 /* */ R(closure), U8(1), // |
| 4817 B(PushContext), R(0), // | 5212 B(PushContext), R(0), // |
| 4818 B(Ldar), R(helper.kLastParamIndex), // | 5213 B(Ldar), R(helper.kLastParamIndex), // |
| 4819 B(StaContextSlot), R(context), U8(first_context_slot), // | 5214 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5215 B(StackCheck), // |
| 4820 B(CreateClosure), U8(0), U8(0), // | 5216 B(CreateClosure), U8(0), U8(0), // |
| 4821 B(Return), // | 5217 B(Return), // |
| 4822 }, | 5218 }, |
| 4823 1, | 5219 1, |
| 4824 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5220 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4825 {"function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }", | 5221 {"function f(arg1) { var a = function() { arg1 = 2; }; return arg1; }", |
| 4826 2 * kPointerSize, | 5222 2 * kPointerSize, |
| 4827 2, | 5223 2, |
| 4828 21, | 5224 22, |
| 4829 { | 5225 { |
| 4830 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5226 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4831 R(closure), U8(1), // | 5227 /* */ R(closure), U8(1), // |
| 4832 B(PushContext), R(1), // | 5228 B(PushContext), R(1), // |
| 4833 B(Ldar), R(helper.kLastParamIndex), // | 5229 B(Ldar), R(helper.kLastParamIndex), // |
| 4834 B(StaContextSlot), R(context), U8(first_context_slot), // | 5230 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5231 B(StackCheck), // |
| 4835 B(CreateClosure), U8(0), U8(0), // | 5232 B(CreateClosure), U8(0), U8(0), // |
| 4836 B(Star), R(0), // | 5233 B(Star), R(0), // |
| 4837 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5234 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 4838 B(Return), // | 5235 B(Return), // |
| 4839 }, | 5236 }, |
| 4840 1, | 5237 1, |
| 4841 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5238 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4842 {"function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }", | 5239 {"function f(a1, a2, a3, a4) { return function() { a1 = a3; }; }", |
| 4843 1 * kPointerSize, | 5240 1 * kPointerSize, |
| 4844 5, | 5241 5, |
| 4845 21, | 5242 22, |
| 4846 { | 5243 { |
| 4847 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5244 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4848 R(closure), U8(1), // | 5245 /* */ R(closure), U8(1), // |
| 4849 B(PushContext), R(0), // | 5246 B(PushContext), R(0), // |
| 4850 B(Ldar), R(helper.kLastParamIndex - 3), // | 5247 B(Ldar), R(helper.kLastParamIndex - 3), // |
| 4851 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 5248 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 4852 B(Ldar), R(helper.kLastParamIndex -1), // | 5249 B(Ldar), R(helper.kLastParamIndex -1), // |
| 4853 B(StaContextSlot), R(context), U8(first_context_slot), // | 5250 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5251 B(StackCheck), // |
| 4854 B(CreateClosure), U8(0), U8(0), // | 5252 B(CreateClosure), U8(0), U8(0), // |
| 4855 B(Return), // | 5253 B(Return), // |
| 4856 }, | 5254 }, |
| 4857 1, | 5255 1, |
| 4858 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5256 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4859 {"function f() { var self = this; return function() { self = 2; }; }", | 5257 {"function f() { var self = this; return function() { self = 2; }; }", |
| 4860 1 * kPointerSize, | 5258 1 * kPointerSize, |
| 4861 1, | 5259 1, |
| 4862 16, | 5260 17, |
| 4863 { | 5261 { |
| 4864 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 5262 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4865 R(closure), U8(1), // | 5263 /* */ R(closure), U8(1), // |
| 4866 B(PushContext), R(0), // | 5264 B(PushContext), R(0), // |
| 5265 B(StackCheck), // |
| 4867 B(Ldar), R(helper.kLastParamIndex), // | 5266 B(Ldar), R(helper.kLastParamIndex), // |
| 4868 B(StaContextSlot), R(context), U8(first_context_slot), // | 5267 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 4869 B(CreateClosure), U8(0), U8(0), // | 5268 B(CreateClosure), U8(0), U8(0), // |
| 4870 B(Return), // | 5269 B(Return), // |
| 4871 }, | 5270 }, |
| 4872 1, | 5271 1, |
| 4873 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5272 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4874 }; | 5273 }; |
| 5274 // clang-format on |
| 4875 | 5275 |
| 4876 for (size_t i = 0; i < arraysize(snippets); i++) { | 5276 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4877 Handle<BytecodeArray> bytecode_array = | 5277 Handle<BytecodeArray> bytecode_array = |
| 4878 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 5278 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 4879 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5279 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4880 } | 5280 } |
| 4881 } | 5281 } |
| 4882 | 5282 |
| 4883 | 5283 |
| 4884 TEST(OuterContextVariables) { | 5284 TEST(OuterContextVariables) { |
| 4885 InitializedHandleScope handle_scope; | 5285 InitializedHandleScope handle_scope; |
| 4886 BytecodeGeneratorHelper helper; | 5286 BytecodeGeneratorHelper helper; |
| 4887 | 5287 |
| 4888 int context = Register::current_context().index(); | 5288 int context = Register::current_context().index(); |
| 4889 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5289 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 4890 | 5290 |
| 5291 // clang-format off |
| 4891 ExpectedSnippet<InstanceType> snippets[] = { | 5292 ExpectedSnippet<InstanceType> snippets[] = { |
| 4892 {"function Outer() {" | 5293 {"function Outer() {" |
| 4893 " var outerVar = 1;" | 5294 " var outerVar = 1;" |
| 4894 " function Inner(innerArg) {" | 5295 " function Inner(innerArg) {" |
| 4895 " this.innerFunc = function() { return outerVar * innerArg; }" | 5296 " this.innerFunc = function() { return outerVar * innerArg; }" |
| 4896 " }" | 5297 " }" |
| 4897 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }" | 5298 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }" |
| 4898 "}" | 5299 "}" |
| 4899 "var f = new Outer().getInnerFunc();", | 5300 "var f = new Outer().getInnerFunc();", |
| 4900 2 * kPointerSize, | 5301 2 * kPointerSize, |
| 4901 1, | 5302 1, |
| 4902 20, | 5303 21, |
| 4903 { | 5304 { |
| 5305 B(StackCheck), // |
| 4904 B(Ldar), R(context), // | 5306 B(Ldar), R(context), // |
| 4905 B(Star), R(0), // | 5307 B(Star), R(0), // |
| 4906 B(LdaContextSlot), R(0), U8(Context::PREVIOUS_INDEX), // | 5308 B(LdaContextSlot), R(0), U8(Context::PREVIOUS_INDEX), // |
| 4907 B(Star), R(0), // | 5309 B(Star), R(0), // |
| 4908 B(LdaContextSlot), R(0), U8(first_context_slot), // | 5310 B(LdaContextSlot), R(0), U8(first_context_slot), // |
| 4909 B(Star), R(1), // | 5311 B(Star), R(1), // |
| 4910 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5312 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 4911 B(Mul), R(1), // | 5313 B(Mul), R(1), // |
| 4912 B(Return), // | 5314 B(Return), // |
| 4913 }}, | 5315 }}, |
| 4914 {"function Outer() {" | 5316 {"function Outer() {" |
| 4915 " var outerVar = 1;" | 5317 " var outerVar = 1;" |
| 4916 " function Inner(innerArg) {" | 5318 " function Inner(innerArg) {" |
| 4917 " this.innerFunc = function() { outerVar = innerArg; }" | 5319 " this.innerFunc = function() { outerVar = innerArg; }" |
| 4918 " }" | 5320 " }" |
| 4919 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }" | 5321 " this.getInnerFunc = function() { return new Inner(1).innerFunc; }" |
| 4920 "}" | 5322 "}" |
| 4921 "var f = new Outer().getInnerFunc();", | 5323 "var f = new Outer().getInnerFunc();", |
| 4922 2 * kPointerSize, | 5324 2 * kPointerSize, |
| 4923 1, | 5325 1, |
| 4924 21, | 5326 22, |
| 4925 { | 5327 { |
| 5328 B(StackCheck), // |
| 4926 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5329 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 4927 B(Star), R(0), // | 5330 B(Star), R(0), // |
| 4928 B(Ldar), R(context), // | 5331 B(Ldar), R(context), // |
| 4929 B(Star), R(1), // | 5332 B(Star), R(1), // |
| 4930 B(LdaContextSlot), R(1), U8(Context::PREVIOUS_INDEX), // | 5333 B(LdaContextSlot), R(1), U8(Context::PREVIOUS_INDEX), // |
| 4931 B(Star), R(1), // | 5334 B(Star), R(1), // |
| 4932 B(Ldar), R(0), // | 5335 B(Ldar), R(0), // |
| 4933 B(StaContextSlot), R(1), U8(first_context_slot), // | 5336 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 4934 B(LdaUndefined), // | 5337 B(LdaUndefined), // |
| 4935 B(Return), // | 5338 B(Return), // |
| 4936 }}, | 5339 }}, |
| 4937 }; | 5340 }; |
| 5341 // clang-format on |
| 4938 | 5342 |
| 4939 for (size_t i = 0; i < arraysize(snippets); i++) { | 5343 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4940 Handle<BytecodeArray> bytecode_array = | 5344 Handle<BytecodeArray> bytecode_array = |
| 4941 helper.MakeBytecodeForFunctionNoFilter(snippets[i].code_snippet); | 5345 helper.MakeBytecodeForFunctionNoFilter(snippets[i].code_snippet); |
| 4942 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5346 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4943 } | 5347 } |
| 4944 } | 5348 } |
| 4945 | 5349 |
| 4946 | 5350 |
| 4947 TEST(CountOperators) { | 5351 TEST(CountOperators) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4962 | 5366 |
| 4963 int closure = Register::function_closure().index(); | 5367 int closure = Register::function_closure().index(); |
| 4964 int context = Register::current_context().index(); | 5368 int context = Register::current_context().index(); |
| 4965 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5369 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 4966 | 5370 |
| 4967 int object_literal_flags = | 5371 int object_literal_flags = |
| 4968 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 5372 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 4969 int array_literal_flags = | 5373 int array_literal_flags = |
| 4970 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; | 5374 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; |
| 4971 | 5375 |
| 5376 // clang-format off |
| 4972 ExpectedSnippet<InstanceType> snippets[] = { | 5377 ExpectedSnippet<InstanceType> snippets[] = { |
| 4973 {"var a = 1; return ++a;", | 5378 {"var a = 1; return ++a;", |
| 4974 1 * kPointerSize, | 5379 1 * kPointerSize, |
| 4975 1, | 5380 1, |
| 4976 9, | 5381 10, |
| 4977 { | 5382 { |
| 5383 B(StackCheck), // |
| 4978 B(LdaSmi8), U8(1), // | 5384 B(LdaSmi8), U8(1), // |
| 4979 B(Star), R(0), // | 5385 B(Star), R(0), // |
| 4980 B(ToNumber), // | 5386 B(ToNumber), // |
| 4981 B(Inc), // | 5387 B(Inc), // |
| 4982 B(Star), R(0), // | 5388 B(Star), R(0), // |
| 4983 B(Return), // | 5389 B(Return), // |
| 4984 }}, | 5390 }}, |
| 4985 {"var a = 1; return a++;", | 5391 {"var a = 1; return a++;", |
| 4986 2 * kPointerSize, | 5392 2 * kPointerSize, |
| 4987 1, | 5393 1, |
| 4988 13, | 5394 14, |
| 4989 { | 5395 { |
| 5396 B(StackCheck), // |
| 4990 B(LdaSmi8), U8(1), // | 5397 B(LdaSmi8), U8(1), // |
| 4991 B(Star), R(0), // | 5398 B(Star), R(0), // |
| 4992 B(ToNumber), // | 5399 B(ToNumber), // |
| 4993 B(Star), R(1), // | 5400 B(Star), R(1), // |
| 4994 B(Inc), // | 5401 B(Inc), // |
| 4995 B(Star), R(0), // | 5402 B(Star), R(0), // |
| 4996 B(Ldar), R(1), // | 5403 B(Ldar), R(1), // |
| 4997 B(Return), // | 5404 B(Return), // |
| 4998 }}, | 5405 }}, |
| 4999 {"var a = 1; return --a;", | 5406 {"var a = 1; return --a;", |
| 5000 1 * kPointerSize, | 5407 1 * kPointerSize, |
| 5001 1, | 5408 1, |
| 5002 9, | 5409 10, |
| 5003 { | 5410 { |
| 5411 B(StackCheck), // |
| 5004 B(LdaSmi8), U8(1), // | 5412 B(LdaSmi8), U8(1), // |
| 5005 B(Star), R(0), // | 5413 B(Star), R(0), // |
| 5006 B(ToNumber), // | 5414 B(ToNumber), // |
| 5007 B(Dec), // | 5415 B(Dec), // |
| 5008 B(Star), R(0), // | 5416 B(Star), R(0), // |
| 5009 B(Return), // | 5417 B(Return), // |
| 5010 }}, | 5418 }}, |
| 5011 {"var a = 1; return a--;", | 5419 {"var a = 1; return a--;", |
| 5012 2 * kPointerSize, | 5420 2 * kPointerSize, |
| 5013 1, | 5421 1, |
| 5014 13, | 5422 14, |
| 5015 { | 5423 { |
| 5424 B(StackCheck), // |
| 5016 B(LdaSmi8), U8(1), // | 5425 B(LdaSmi8), U8(1), // |
| 5017 B(Star), R(0), // | 5426 B(Star), R(0), // |
| 5018 B(ToNumber), // | 5427 B(ToNumber), // |
| 5019 B(Star), R(1), // | 5428 B(Star), R(1), // |
| 5020 B(Dec), // | 5429 B(Dec), // |
| 5021 B(Star), R(0), // | 5430 B(Star), R(0), // |
| 5022 B(Ldar), R(1), // | 5431 B(Ldar), R(1), // |
| 5023 B(Return), // | 5432 B(Return), // |
| 5024 }}, | 5433 }}, |
| 5025 {"var a = { val: 1 }; return a.val++;", | 5434 {"var a = { val: 1 }; return a.val++;", |
| 5026 3 * kPointerSize, | 5435 3 * kPointerSize, |
| 5027 1, | 5436 1, |
| 5028 25, | 5437 26, |
| 5029 { | 5438 { |
| 5439 B(StackCheck), // |
| 5030 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // | 5440 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // |
| 5031 B(Star), R(1), // | 5441 B(Star), R(1), // |
| 5032 B(Star), R(0), // | 5442 B(Star), R(0), // |
| 5033 B(Star), R(1), // | 5443 B(Star), R(1), // |
| 5034 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 5444 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 5035 B(ToNumber), // | 5445 B(ToNumber), // |
| 5036 B(Star), R(2), // | 5446 B(Star), R(2), // |
| 5037 B(Inc), // | 5447 B(Inc), // |
| 5038 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // | 5448 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // |
| 5039 B(Ldar), R(2), // | 5449 B(Ldar), R(2), // |
| 5040 B(Return), // | 5450 B(Return), // |
| 5041 }, | 5451 }, |
| 5042 2, | 5452 2, |
| 5043 {InstanceType::FIXED_ARRAY_TYPE, | 5453 {InstanceType::FIXED_ARRAY_TYPE, |
| 5044 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 5454 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5045 {"var a = { val: 1 }; return --a.val;", | 5455 {"var a = { val: 1 }; return --a.val;", |
| 5046 2 * kPointerSize, | 5456 2 * kPointerSize, |
| 5047 1, | 5457 1, |
| 5048 21, | 5458 22, |
| 5049 { | 5459 { |
| 5460 B(StackCheck), // |
| 5050 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // | 5461 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // |
| 5051 B(Star), R(1), // | 5462 B(Star), R(1), // |
| 5052 B(Star), R(0), // | 5463 B(Star), R(0), // |
| 5053 B(Star), R(1), // | 5464 B(Star), R(1), // |
| 5054 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 5465 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 5055 B(ToNumber), // | 5466 B(ToNumber), // |
| 5056 B(Dec), // | 5467 B(Dec), // |
| 5057 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // | 5468 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // |
| 5058 B(Return), // | 5469 B(Return), // |
| 5059 }, | 5470 }, |
| 5060 2, | 5471 2, |
| 5061 {InstanceType::FIXED_ARRAY_TYPE, | 5472 {InstanceType::FIXED_ARRAY_TYPE, |
| 5062 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 5473 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5063 {"var name = 'var'; var a = { val: 1 }; return a[name]--;", | 5474 {"var name = 'var'; var a = { val: 1 }; return a[name]--;", |
| 5064 5 * kPointerSize, | 5475 5 * kPointerSize, |
| 5065 1, | 5476 1, |
| 5066 32, | 5477 33, |
| 5067 { | 5478 { |
| 5479 B(StackCheck), // |
| 5068 B(LdaConstant), U8(0), // | 5480 B(LdaConstant), U8(0), // |
| 5069 B(Star), R(0), // | 5481 B(Star), R(0), // |
| 5070 B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), // | 5482 B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), // |
| 5071 B(Star), R(2), // | 5483 B(Star), R(2), // |
| 5072 B(Star), R(1), // | 5484 B(Star), R(1), // |
| 5073 B(Star), R(2), // | 5485 B(Star), R(2), // |
| 5074 B(Ldar), R(0), // | 5486 B(Ldar), R(0), // |
| 5075 B(Star), R(3), // | 5487 B(Star), R(3), // |
| 5076 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), // | 5488 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), // |
| 5077 B(ToNumber), // | 5489 B(ToNumber), // |
| 5078 B(Star), R(4), // | 5490 B(Star), R(4), // |
| 5079 B(Dec), // | 5491 B(Dec), // |
| 5080 B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), // | 5492 B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), // |
| 5081 B(Ldar), R(4), // | 5493 B(Ldar), R(4), // |
| 5082 B(Return), // | 5494 B(Return), // |
| 5083 }, | 5495 }, |
| 5084 2, | 5496 2, |
| 5085 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 5497 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5086 InstanceType::FIXED_ARRAY_TYPE}}, | 5498 InstanceType::FIXED_ARRAY_TYPE}}, |
| 5087 {"var name = 'var'; var a = { val: 1 }; return ++a[name];", | 5499 {"var name = 'var'; var a = { val: 1 }; return ++a[name];", |
| 5088 4 * kPointerSize, | 5500 4 * kPointerSize, |
| 5089 1, | 5501 1, |
| 5090 28, | 5502 29, |
| 5091 { | 5503 { |
| 5504 B(StackCheck), // |
| 5092 B(LdaConstant), U8(0), // | 5505 B(LdaConstant), U8(0), // |
| 5093 B(Star), R(0), // | 5506 B(Star), R(0), // |
| 5094 B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), // | 5507 B(CreateObjectLiteral), U8(1), U8(0), U8(object_literal_flags), // |
| 5095 B(Star), R(2), // | 5508 B(Star), R(2), // |
| 5096 B(Star), R(1), // | 5509 B(Star), R(1), // |
| 5097 B(Star), R(2), // | 5510 B(Star), R(2), // |
| 5098 B(Ldar), R(0), // | 5511 B(Ldar), R(0), // |
| 5099 B(Star), R(3), // | 5512 B(Star), R(3), // |
| 5100 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), // | 5513 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot1)), // |
| 5101 B(ToNumber), // | 5514 B(ToNumber), // |
| 5102 B(Inc), // | 5515 B(Inc), // |
| 5103 B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), // | 5516 B(KeyedStoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), // |
| 5104 B(Return), // | 5517 B(Return), // |
| 5105 }, | 5518 }, |
| 5106 2, | 5519 2, |
| 5107 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 5520 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5108 InstanceType::FIXED_ARRAY_TYPE}}, | 5521 InstanceType::FIXED_ARRAY_TYPE}}, |
| 5109 {"var a = 1; var b = function() { return a }; return ++a;", | 5522 {"var a = 1; var b = function() { return a }; return ++a;", |
| 5110 2 * kPointerSize, | 5523 2 * kPointerSize, |
| 5111 1, | 5524 1, |
| 5112 26, | 5525 27, |
| 5113 { | 5526 { |
| 5114 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5527 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 5115 U8(1), // | 5528 /* */ U8(1), // |
| 5116 B(PushContext), R(1), // | 5529 B(PushContext), R(1), // |
| 5530 B(StackCheck), // |
| 5117 B(LdaSmi8), U8(1), // | 5531 B(LdaSmi8), U8(1), // |
| 5118 B(StaContextSlot), R(context), U8(first_context_slot), // | 5532 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5119 B(CreateClosure), U8(0), U8(0), // | 5533 B(CreateClosure), U8(0), U8(0), // |
| 5120 B(Star), R(0), // | 5534 B(Star), R(0), // |
| 5121 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5535 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 5122 B(ToNumber), // | 5536 B(ToNumber), // |
| 5123 B(Inc), // | 5537 B(Inc), // |
| 5124 B(StaContextSlot), R(context), U8(first_context_slot), // | 5538 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5125 B(Return), // | 5539 B(Return), // |
| 5126 }, | 5540 }, |
| 5127 1, | 5541 1, |
| 5128 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5542 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 5129 {"var a = 1; var b = function() { return a }; return a--;", | 5543 {"var a = 1; var b = function() { return a }; return a--;", |
| 5130 3 * kPointerSize, | 5544 3 * kPointerSize, |
| 5131 1, | 5545 1, |
| 5132 30, | 5546 31, |
| 5133 { | 5547 { |
| 5134 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5548 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 5135 U8(1), // | 5549 /* */ U8(1), // |
| 5136 B(PushContext), R(1), // | 5550 B(PushContext), R(1), // |
| 5551 B(StackCheck), // |
| 5137 B(LdaSmi8), U8(1), // | 5552 B(LdaSmi8), U8(1), // |
| 5138 B(StaContextSlot), R(context), U8(first_context_slot), // | 5553 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5139 B(CreateClosure), U8(0), U8(0), // | 5554 B(CreateClosure), U8(0), U8(0), // |
| 5140 B(Star), R(0), // | 5555 B(Star), R(0), // |
| 5141 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5556 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 5142 B(ToNumber), // | 5557 B(ToNumber), // |
| 5143 B(Star), R(2), // | 5558 B(Star), R(2), // |
| 5144 B(Dec), // | 5559 B(Dec), // |
| 5145 B(StaContextSlot), R(context), U8(first_context_slot), // | 5560 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5146 B(Ldar), R(2), // | 5561 B(Ldar), R(2), // |
| 5147 B(Return), // | 5562 B(Return), // |
| 5148 }, | 5563 }, |
| 5149 1, | 5564 1, |
| 5150 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5565 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 5151 {"var idx = 1; var a = [1, 2]; return a[idx++] = 2;", | 5566 {"var idx = 1; var a = [1, 2]; return a[idx++] = 2;", |
| 5152 4 * kPointerSize, | 5567 4 * kPointerSize, |
| 5153 1, | 5568 1, |
| 5154 27, | 5569 28, |
| 5155 { | 5570 { |
| 5156 B(LdaSmi8), U8(1), // | 5571 B(StackCheck), // |
| 5157 B(Star), R(0), // | 5572 B(LdaSmi8), U8(1), // |
| 5158 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // | 5573 B(Star), R(0), // |
| 5159 B(Star), R(1), // | 5574 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // |
| 5160 B(Star), R(2), // | 5575 B(Star), R(1), // |
| 5161 B(Ldar), R(0), // | 5576 B(Star), R(2), // |
| 5162 B(ToNumber), // | 5577 B(Ldar), R(0), // |
| 5163 B(Star), R(3), // | 5578 B(ToNumber), // |
| 5164 B(Inc), // | 5579 B(Star), R(3), // |
| 5165 B(Star), R(0), // | 5580 B(Inc), // |
| 5166 B(LdaSmi8), U8(2), // | 5581 B(Star), R(0), // |
| 5167 B(KeyedStoreICSloppy), R(2), R(3), // | 5582 B(LdaSmi8), U8(2), // |
| 5168 U8(store_vector->GetIndex(store_slot)), // | 5583 B(KeyedStoreICSloppy), R(2), R(3), // |
| 5169 B(Return), // | 5584 /* */ U8(store_vector->GetIndex(store_slot)), // |
| 5585 B(Return), // |
| 5170 }, | 5586 }, |
| 5171 1, | 5587 1, |
| 5172 {InstanceType::FIXED_ARRAY_TYPE}}, | 5588 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 5173 }; | 5589 }; |
| 5590 // clang-format on |
| 5174 | 5591 |
| 5175 for (size_t i = 0; i < arraysize(snippets); i++) { | 5592 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5176 Handle<BytecodeArray> bytecode_array = | 5593 Handle<BytecodeArray> bytecode_array = |
| 5177 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5594 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5178 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5595 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5179 } | 5596 } |
| 5180 } | 5597 } |
| 5181 | 5598 |
| 5182 | 5599 |
| 5183 TEST(GlobalCountOperators) { | 5600 TEST(GlobalCountOperators) { |
| 5184 InitializedHandleScope handle_scope; | 5601 InitializedHandleScope handle_scope; |
| 5185 BytecodeGeneratorHelper helper; | 5602 BytecodeGeneratorHelper helper; |
| 5186 Zone zone; | 5603 Zone zone; |
| 5187 | 5604 |
| 5188 FeedbackVectorSpec feedback_spec(&zone); | 5605 FeedbackVectorSpec feedback_spec(&zone); |
| 5189 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 5606 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 5190 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); | 5607 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
| 5191 | 5608 |
| 5192 Handle<i::TypeFeedbackVector> vector = | 5609 Handle<i::TypeFeedbackVector> vector = |
| 5193 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 5610 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5194 | 5611 |
| 5612 // clang-format off |
| 5195 ExpectedSnippet<const char*> snippets[] = { | 5613 ExpectedSnippet<const char*> snippets[] = { |
| 5196 {"var global = 1;\nfunction f() { return ++global; }\nf()", | 5614 {"var global = 1;\nfunction f() { return ++global; }\nf()", |
| 5197 0, | 5615 0, |
| 5198 1, | 5616 1, |
| 5199 9, | 5617 10, |
| 5200 { | 5618 { |
| 5619 B(StackCheck), // |
| 5201 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // | 5620 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // |
| 5202 B(ToNumber), // | 5621 B(ToNumber), // |
| 5203 B(Inc), // | 5622 B(Inc), // |
| 5204 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5623 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 5205 B(Return), // | 5624 B(Return), // |
| 5206 }, | 5625 }, |
| 5207 1, | 5626 1, |
| 5208 {"global"}}, | 5627 {"global"}}, |
| 5209 {"var global = 1;\nfunction f() { return global--; }\nf()", | 5628 {"var global = 1;\nfunction f() { return global--; }\nf()", |
| 5210 1 * kPointerSize, | 5629 1 * kPointerSize, |
| 5211 1, | 5630 1, |
| 5212 13, | 5631 14, |
| 5213 { | 5632 { |
| 5633 B(StackCheck), // |
| 5214 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // | 5634 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // |
| 5215 B(ToNumber), // | 5635 B(ToNumber), // |
| 5216 B(Star), R(0), // | 5636 B(Star), R(0), // |
| 5217 B(Dec), // | 5637 B(Dec), // |
| 5218 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5638 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 5219 B(Ldar), R(0), // | 5639 B(Ldar), R(0), // |
| 5220 B(Return), | 5640 B(Return), |
| 5221 }, | 5641 }, |
| 5222 1, | 5642 1, |
| 5223 {"global"}}, | 5643 {"global"}}, |
| 5224 {"unallocated = 1;\nfunction f() { 'use strict'; return --unallocated; }" | 5644 {"unallocated = 1;\nfunction f() { 'use strict'; return --unallocated; }" |
| 5225 "f()", | 5645 "f()", |
| 5226 0, | 5646 0, |
| 5227 1, | 5647 1, |
| 5228 9, | 5648 10, |
| 5229 { | 5649 { |
| 5650 B(StackCheck), // |
| 5230 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot1)), // | 5651 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot1)), // |
| 5231 B(ToNumber), // | 5652 B(ToNumber), // |
| 5232 B(Dec), // | 5653 B(Dec), // |
| 5233 B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot2)), // | 5654 B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot2)), // |
| 5234 B(Return), // | 5655 B(Return), // |
| 5235 }, | 5656 }, |
| 5236 1, | 5657 1, |
| 5237 {"unallocated"}}, | 5658 {"unallocated"}}, |
| 5238 {"unallocated = 1;\nfunction f() { return unallocated++; }\nf()", | 5659 {"unallocated = 1;\nfunction f() { return unallocated++; }\nf()", |
| 5239 1 * kPointerSize, | 5660 1 * kPointerSize, |
| 5240 1, | 5661 1, |
| 5241 13, | 5662 14, |
| 5242 { | 5663 { |
| 5664 B(StackCheck), // |
| 5243 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // | 5665 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // |
| 5244 B(ToNumber), // | 5666 B(ToNumber), // |
| 5245 B(Star), R(0), // | 5667 B(Star), R(0), // |
| 5246 B(Inc), // | 5668 B(Inc), // |
| 5247 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5669 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 5248 B(Ldar), R(0), // | 5670 B(Ldar), R(0), // |
| 5249 B(Return), | 5671 B(Return), |
| 5250 }, | 5672 }, |
| 5251 1, | 5673 1, |
| 5252 {"unallocated"}}, | 5674 {"unallocated"}}, |
| 5253 }; | 5675 }; |
| 5676 // clang-format on |
| 5254 | 5677 |
| 5255 for (size_t i = 0; i < arraysize(snippets); i++) { | 5678 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5256 Handle<BytecodeArray> bytecode_array = | 5679 Handle<BytecodeArray> bytecode_array = |
| 5257 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 5680 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 5258 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5681 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5259 } | 5682 } |
| 5260 } | 5683 } |
| 5261 | 5684 |
| 5262 | 5685 |
| 5263 TEST(CompoundExpressions) { | 5686 TEST(CompoundExpressions) { |
| 5264 InitializedHandleScope handle_scope; | 5687 InitializedHandleScope handle_scope; |
| 5265 BytecodeGeneratorHelper helper; | 5688 BytecodeGeneratorHelper helper; |
| 5266 Zone zone; | 5689 Zone zone; |
| 5267 | 5690 |
| 5268 int closure = Register::function_closure().index(); | 5691 int closure = Register::function_closure().index(); |
| 5269 int context = Register::current_context().index(); | 5692 int context = Register::current_context().index(); |
| 5270 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5693 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 5271 | 5694 |
| 5272 FeedbackVectorSpec feedback_spec(&zone); | 5695 FeedbackVectorSpec feedback_spec(&zone); |
| 5273 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 5696 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 5274 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); | 5697 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
| 5275 | 5698 |
| 5276 Handle<i::TypeFeedbackVector> vector = | 5699 Handle<i::TypeFeedbackVector> vector = |
| 5277 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 5700 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5278 | 5701 |
| 5279 int object_literal_flags = | 5702 int object_literal_flags = |
| 5280 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 5703 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 5704 |
| 5705 // clang-format off |
| 5281 ExpectedSnippet<InstanceType> snippets[] = { | 5706 ExpectedSnippet<InstanceType> snippets[] = { |
| 5282 {"var a = 1; a += 2;", | 5707 {"var a = 1; a += 2;", |
| 5283 2 * kPointerSize, | 5708 2 * kPointerSize, |
| 5284 1, | 5709 1, |
| 5285 14, | 5710 15, |
| 5286 { | 5711 { |
| 5712 B(StackCheck), // |
| 5287 B(LdaSmi8), U8(1), // | 5713 B(LdaSmi8), U8(1), // |
| 5288 B(Star), R(0), // | 5714 B(Star), R(0), // |
| 5289 B(Star), R(1), // | 5715 B(Star), R(1), // |
| 5290 B(LdaSmi8), U8(2), // | 5716 B(LdaSmi8), U8(2), // |
| 5291 B(Add), R(1), // | 5717 B(Add), R(1), // |
| 5292 B(Star), R(0), // | 5718 B(Star), R(0), // |
| 5293 B(LdaUndefined), // | 5719 B(LdaUndefined), // |
| 5294 B(Return), // | 5720 B(Return), // |
| 5295 }}, | 5721 }}, |
| 5296 {"var a = 1; a /= 2;", | 5722 {"var a = 1; a /= 2;", |
| 5297 2 * kPointerSize, | 5723 2 * kPointerSize, |
| 5298 1, | 5724 1, |
| 5299 14, | 5725 15, |
| 5300 { | 5726 { |
| 5727 B(StackCheck), // |
| 5301 B(LdaSmi8), U8(1), // | 5728 B(LdaSmi8), U8(1), // |
| 5302 B(Star), R(0), // | 5729 B(Star), R(0), // |
| 5303 B(Star), R(1), // | 5730 B(Star), R(1), // |
| 5304 B(LdaSmi8), U8(2), // | 5731 B(LdaSmi8), U8(2), // |
| 5305 B(Div), R(1), // | 5732 B(Div), R(1), // |
| 5306 B(Star), R(0), // | 5733 B(Star), R(0), // |
| 5307 B(LdaUndefined), // | 5734 B(LdaUndefined), // |
| 5308 B(Return), // | 5735 B(Return), // |
| 5309 }}, | 5736 }}, |
| 5310 {"var a = { val: 2 }; a.name *= 2;", | 5737 {"var a = { val: 2 }; a.name *= 2;", |
| 5311 3 * kPointerSize, | 5738 3 * kPointerSize, |
| 5312 1, | 5739 1, |
| 5313 26, | 5740 27, |
| 5314 { | 5741 { |
| 5742 B(StackCheck), // |
| 5315 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // | 5743 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // |
| 5316 B(Star), R(1), // | 5744 B(Star), R(1), // |
| 5317 B(Star), R(0), // | 5745 B(Star), R(0), // |
| 5318 B(Star), R(1), // | 5746 B(Star), R(1), // |
| 5319 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // | 5747 B(LoadICSloppy), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
| 5320 B(Star), R(2), // | 5748 B(Star), R(2), // |
| 5321 B(LdaSmi8), U8(2), // | 5749 B(LdaSmi8), U8(2), // |
| 5322 B(Mul), R(2), // | 5750 B(Mul), R(2), // |
| 5323 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // | 5751 B(StoreICSloppy), R(1), U8(1), U8(vector->GetIndex(slot2)), // |
| 5324 B(LdaUndefined), // | 5752 B(LdaUndefined), // |
| 5325 B(Return), // | 5753 B(Return), // |
| 5326 }, | 5754 }, |
| 5327 2, | 5755 2, |
| 5328 {InstanceType::FIXED_ARRAY_TYPE, | 5756 {InstanceType::FIXED_ARRAY_TYPE, |
| 5329 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 5757 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5330 {"var a = { 1: 2 }; a[1] ^= 2;", | 5758 {"var a = { 1: 2 }; a[1] ^= 2;", |
| 5331 4 * kPointerSize, | 5759 4 * kPointerSize, |
| 5332 1, | 5760 1, |
| 5333 29, | 5761 30, |
| 5334 { | 5762 { |
| 5763 B(StackCheck), // |
| 5335 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // | 5764 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // |
| 5336 B(Star), R(1), // | 5765 B(Star), R(1), // |
| 5337 B(Star), R(0), // | 5766 B(Star), R(0), // |
| 5338 B(Star), R(1), // | 5767 B(Star), R(1), // |
| 5339 B(LdaSmi8), U8(1), // | 5768 B(LdaSmi8), U8(1), // |
| 5340 B(Star), R(2), // | 5769 B(Star), R(2), // |
| 5341 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // | 5770 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // |
| 5342 B(Star), R(3), // | 5771 B(Star), R(3), // |
| 5343 B(LdaSmi8), U8(2), // | 5772 B(LdaSmi8), U8(2), // |
| 5344 B(BitwiseXor), R(3), // | 5773 B(BitwiseXor), R(3), // |
| 5345 B(KeyedStoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), // | 5774 B(KeyedStoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), // |
| 5346 B(LdaUndefined), // | 5775 B(LdaUndefined), // |
| 5347 B(Return), // | 5776 B(Return), // |
| 5348 }, | 5777 }, |
| 5349 1, | 5778 1, |
| 5350 {InstanceType::FIXED_ARRAY_TYPE}}, | 5779 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 5351 {"var a = 1; (function f() { return a; }); a |= 24;", | 5780 {"var a = 1; (function f() { return a; }); a |= 24;", |
| 5352 2 * kPointerSize, | 5781 2 * kPointerSize, |
| 5353 1, | 5782 1, |
| 5354 29, | 5783 30, |
| 5355 { | 5784 { |
| 5356 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5785 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 5357 U8(1), // | 5786 /* */ U8(1), // |
| 5358 B(PushContext), R(0), // | 5787 B(PushContext), R(0), // |
| 5788 B(StackCheck), // |
| 5359 B(LdaSmi8), U8(1), // | 5789 B(LdaSmi8), U8(1), // |
| 5360 B(StaContextSlot), R(context), U8(first_context_slot), // | 5790 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5361 B(CreateClosure), U8(0), U8(0), // | 5791 B(CreateClosure), U8(0), U8(0), // |
| 5362 B(LdaContextSlot), R(context), U8(first_context_slot), // | 5792 B(LdaContextSlot), R(context), U8(first_context_slot), // |
| 5363 B(Star), R(1), // | 5793 B(Star), R(1), // |
| 5364 B(LdaSmi8), U8(24), // | 5794 B(LdaSmi8), U8(24), // |
| 5365 B(BitwiseOr), R(1), // | 5795 B(BitwiseOr), R(1), // |
| 5366 B(StaContextSlot), R(context), U8(first_context_slot), // | 5796 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5367 B(LdaUndefined), // | 5797 B(LdaUndefined), // |
| 5368 B(Return), // | 5798 B(Return), // |
| 5369 }, | 5799 }, |
| 5370 1, | 5800 1, |
| 5371 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 5801 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 5372 }; | 5802 }; |
| 5803 // clang-format on |
| 5373 | 5804 |
| 5374 for (size_t i = 0; i < arraysize(snippets); i++) { | 5805 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5375 Handle<BytecodeArray> bytecode_array = | 5806 Handle<BytecodeArray> bytecode_array = |
| 5376 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5807 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5377 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5808 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5378 } | 5809 } |
| 5379 } | 5810 } |
| 5380 | 5811 |
| 5381 | 5812 |
| 5382 TEST(GlobalCompoundExpressions) { | 5813 TEST(GlobalCompoundExpressions) { |
| 5383 InitializedHandleScope handle_scope; | 5814 InitializedHandleScope handle_scope; |
| 5384 BytecodeGeneratorHelper helper; | 5815 BytecodeGeneratorHelper helper; |
| 5385 Zone zone; | 5816 Zone zone; |
| 5386 | 5817 |
| 5387 FeedbackVectorSpec feedback_spec(&zone); | 5818 FeedbackVectorSpec feedback_spec(&zone); |
| 5388 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 5819 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 5389 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); | 5820 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
| 5390 | 5821 |
| 5391 Handle<i::TypeFeedbackVector> vector = | 5822 Handle<i::TypeFeedbackVector> vector = |
| 5392 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 5823 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5393 | 5824 |
| 5825 // clang-format off |
| 5394 ExpectedSnippet<const char*> snippets[] = { | 5826 ExpectedSnippet<const char*> snippets[] = { |
| 5395 {"var global = 1;\nfunction f() { return global &= 1; }\nf()", | 5827 {"var global = 1;\nfunction f() { return global &= 1; }\nf()", |
| 5396 1 * kPointerSize, | 5828 1 * kPointerSize, |
| 5397 1, | 5829 1, |
| 5398 13, | 5830 14, |
| 5399 { | 5831 { |
| 5832 B(StackCheck), // |
| 5400 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // | 5833 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // |
| 5401 B(Star), R(0), // | 5834 B(Star), R(0), // |
| 5402 B(LdaSmi8), U8(1), // | 5835 B(LdaSmi8), U8(1), // |
| 5403 B(BitwiseAnd), R(0), // | 5836 B(BitwiseAnd), R(0), // |
| 5404 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5837 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 5405 B(Return), // | 5838 B(Return), // |
| 5406 }, | 5839 }, |
| 5407 1, | 5840 1, |
| 5408 {"global"}}, | 5841 {"global"}}, |
| 5409 {"unallocated = 1;\nfunction f() { return unallocated += 1; }\nf()", | 5842 {"unallocated = 1;\nfunction f() { return unallocated += 1; }\nf()", |
| 5410 1 * kPointerSize, | 5843 1 * kPointerSize, |
| 5411 1, | 5844 1, |
| 5412 13, | 5845 14, |
| 5413 { | 5846 { |
| 5847 B(StackCheck), // |
| 5414 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // | 5848 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), // |
| 5415 B(Star), R(0), // | 5849 B(Star), R(0), // |
| 5416 B(LdaSmi8), U8(1), // | 5850 B(LdaSmi8), U8(1), // |
| 5417 B(Add), R(0), // | 5851 B(Add), R(0), // |
| 5418 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 5852 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
| 5419 B(Return), // | 5853 B(Return), // |
| 5420 }, | 5854 }, |
| 5421 1, | 5855 1, |
| 5422 {"unallocated"}}, | 5856 {"unallocated"}}, |
| 5423 }; | 5857 }; |
| 5858 // clang-format on |
| 5424 | 5859 |
| 5425 for (size_t i = 0; i < arraysize(snippets); i++) { | 5860 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5426 Handle<BytecodeArray> bytecode_array = | 5861 Handle<BytecodeArray> bytecode_array = |
| 5427 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 5862 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 5428 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5863 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5429 } | 5864 } |
| 5430 } | 5865 } |
| 5431 | 5866 |
| 5432 | 5867 |
| 5433 TEST(CreateArguments) { | 5868 TEST(CreateArguments) { |
| 5434 InitializedHandleScope handle_scope; | 5869 InitializedHandleScope handle_scope; |
| 5435 BytecodeGeneratorHelper helper; | 5870 BytecodeGeneratorHelper helper; |
| 5436 Zone zone; | 5871 Zone zone; |
| 5437 | 5872 |
| 5438 int closure = Register::function_closure().index(); | 5873 int closure = Register::function_closure().index(); |
| 5439 int context = Register::current_context().index(); | 5874 int context = Register::current_context().index(); |
| 5440 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5875 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 5441 | 5876 |
| 5442 FeedbackVectorSpec feedback_spec(&zone); | 5877 FeedbackVectorSpec feedback_spec(&zone); |
| 5443 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 5878 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
| 5444 | 5879 |
| 5445 Handle<i::TypeFeedbackVector> vector = | 5880 Handle<i::TypeFeedbackVector> vector = |
| 5446 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 5881 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5447 | 5882 |
| 5883 // clang-format off |
| 5448 ExpectedSnippet<const char*> snippets[] = { | 5884 ExpectedSnippet<const char*> snippets[] = { |
| 5449 {"function f() { return arguments; }", | 5885 {"function f() { return arguments; }", |
| 5450 1 * kPointerSize, | 5886 1 * kPointerSize, |
| 5451 1, | 5887 1, |
| 5452 4, | 5888 7, |
| 5453 { | 5889 { |
| 5454 B(CreateMappedArguments), // | 5890 B(CreateMappedArguments), // |
| 5455 B(Star), R(0), // | 5891 B(Star), R(0), // |
| 5892 B(StackCheck), // |
| 5893 B(Ldar), R(0), // |
| 5456 B(Return), // | 5894 B(Return), // |
| 5457 }}, | 5895 }}, |
| 5458 {"function f() { return arguments[0]; }", | 5896 {"function f() { return arguments[0]; }", |
| 5459 2 * kPointerSize, | 5897 2 * kPointerSize, |
| 5460 1, | 5898 1, |
| 5461 10, | 5899 13, |
| 5462 { | 5900 { |
| 5463 B(CreateMappedArguments), // | 5901 B(CreateMappedArguments), // |
| 5464 B(Star), R(0), // | 5902 B(Star), R(0), // |
| 5903 B(StackCheck), // |
| 5904 B(Ldar), R(0), // |
| 5465 B(Star), R(1), // | 5905 B(Star), R(1), // |
| 5466 B(LdaZero), // | 5906 B(LdaZero), // |
| 5467 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot)), // | 5907 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot)), // |
| 5468 B(Return), // | 5908 B(Return), // |
| 5469 }}, | 5909 }}, |
| 5470 {"function f() { 'use strict'; return arguments; }", | 5910 {"function f() { 'use strict'; return arguments; }", |
| 5471 1 * kPointerSize, | 5911 1 * kPointerSize, |
| 5472 1, | 5912 1, |
| 5473 4, | 5913 7, |
| 5474 { | 5914 { |
| 5475 B(CreateUnmappedArguments), // | 5915 B(CreateUnmappedArguments), // |
| 5476 B(Star), R(0), // | 5916 B(Star), R(0), // |
| 5917 B(StackCheck), // |
| 5918 B(Ldar), R(0), // |
| 5477 B(Return), // | 5919 B(Return), // |
| 5478 }}, | 5920 }}, |
| 5479 {"function f(a) { return arguments[0]; }", | 5921 {"function f(a) { return arguments[0]; }", |
| 5480 3 * kPointerSize, | 5922 3 * kPointerSize, |
| 5481 2, | 5923 2, |
| 5482 22, | 5924 25, |
| 5483 { | 5925 { |
| 5484 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5926 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 5485 U8(1), // | 5927 /* */ U8(1), // |
| 5486 B(PushContext), R(1), // | 5928 B(PushContext), R(1), // |
| 5487 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), // | 5929 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), // |
| 5488 B(StaContextSlot), R(context), U8(first_context_slot), // | 5930 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5489 B(CreateMappedArguments), // | 5931 B(CreateMappedArguments), // |
| 5490 B(Star), R(0), // | 5932 B(Star), R(0), // |
| 5933 B(StackCheck), // |
| 5934 B(Ldar), R(0), // |
| 5491 B(Star), R(2), // | 5935 B(Star), R(2), // |
| 5492 B(LdaZero), // | 5936 B(LdaZero), // |
| 5493 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), // | 5937 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), // |
| 5494 B(Return), // | 5938 B(Return), // |
| 5495 }}, | 5939 }}, |
| 5496 {"function f(a, b, c) { return arguments; }", | 5940 {"function f(a, b, c) { return arguments; }", |
| 5497 2 * kPointerSize, | 5941 2 * kPointerSize, |
| 5498 4, | 5942 4, |
| 5499 26, | 5943 29, |
| 5500 { | 5944 { |
| 5501 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5945 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 5502 U8(1), // | 5946 /* */ U8(1), // |
| 5503 B(PushContext), R(1), // | 5947 B(PushContext), R(1), // |
| 5504 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 2), // | 5948 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 2), // |
| 5505 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 5949 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 5506 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 1), // | 5950 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex - 1), // |
| 5507 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 5951 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 5508 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), // | 5952 B(Ldar), R(BytecodeGeneratorHelper::kLastParamIndex), // |
| 5509 B(StaContextSlot), R(context), U8(first_context_slot), // | 5953 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 5510 B(CreateMappedArguments), // | 5954 B(CreateMappedArguments), // |
| 5511 B(Star), R(0), // | 5955 B(Star), R(0), // |
| 5956 B(StackCheck), // |
| 5957 B(Ldar), R(0), // |
| 5512 B(Return), // | 5958 B(Return), // |
| 5513 }}, | 5959 }}, |
| 5514 {"function f(a, b, c) { 'use strict'; return arguments; }", | 5960 {"function f(a, b, c) { 'use strict'; return arguments; }", |
| 5515 1 * kPointerSize, | 5961 1 * kPointerSize, |
| 5516 4, | 5962 4, |
| 5517 4, | 5963 7, |
| 5518 { | 5964 { |
| 5519 B(CreateUnmappedArguments), // | 5965 B(CreateUnmappedArguments), // |
| 5520 B(Star), R(0), // | 5966 B(Star), R(0), // |
| 5967 B(StackCheck), // |
| 5968 B(Ldar), R(0), // |
| 5521 B(Return), // | 5969 B(Return), // |
| 5522 }}, | 5970 }}, |
| 5523 }; | 5971 }; |
| 5972 // clang-format on |
| 5524 | 5973 |
| 5525 for (size_t i = 0; i < arraysize(snippets); i++) { | 5974 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5526 Handle<BytecodeArray> bytecode_array = | 5975 Handle<BytecodeArray> bytecode_array = |
| 5527 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 5976 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 5528 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5977 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5529 } | 5978 } |
| 5530 } | 5979 } |
| 5531 | 5980 |
| 5532 TEST(CreateRestArguments) { | 5981 TEST(CreateRestArguments) { |
| 5533 InitializedHandleScope handle_scope; | 5982 InitializedHandleScope handle_scope; |
| 5534 BytecodeGeneratorHelper helper; | 5983 BytecodeGeneratorHelper helper; |
| 5535 Zone zone; | 5984 Zone zone; |
| 5536 | 5985 |
| 5537 FeedbackVectorSpec feedback_spec(&zone); | 5986 FeedbackVectorSpec feedback_spec(&zone); |
| 5538 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 5987 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
| 5539 FeedbackVectorSlot slot1 = feedback_spec.AddKeyedLoadICSlot(); | 5988 FeedbackVectorSlot slot1 = feedback_spec.AddKeyedLoadICSlot(); |
| 5540 | 5989 |
| 5541 Handle<i::TypeFeedbackVector> vector = | 5990 Handle<i::TypeFeedbackVector> vector = |
| 5542 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 5991 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5543 | 5992 |
| 5993 // clang-format off |
| 5544 ExpectedSnippet<int> snippets[] = { | 5994 ExpectedSnippet<int> snippets[] = { |
| 5545 {"function f(...restArgs) { return restArgs; }", | 5995 {"function f(...restArgs) { return restArgs; }", |
| 5546 1 * kPointerSize, | 5996 1 * kPointerSize, |
| 5547 2, | 5997 2, |
| 5548 5, | 5998 8, |
| 5549 { | 5999 { |
| 5550 B(CreateRestArguments), U8(0), // | 6000 B(CreateRestArguments), U8(0), // |
| 5551 B(Star), R(0), // | 6001 B(Star), R(0), // |
| 6002 B(StackCheck), // |
| 6003 B(Ldar), R(0), // |
| 5552 B(Return), // | 6004 B(Return), // |
| 5553 }, | 6005 }, |
| 5554 1, | 6006 1, |
| 5555 {0}}, | 6007 {0}}, |
| 5556 {"function f(a, ...restArgs) { return restArgs; }", | 6008 {"function f(a, ...restArgs) { return restArgs; }", |
| 5557 2 * kPointerSize, | 6009 2 * kPointerSize, |
| 5558 3, | 6010 3, |
| 5559 14, | 6011 15, |
| 5560 { | 6012 { |
| 5561 B(CreateRestArguments), U8(0), // | 6013 B(CreateRestArguments), U8(0), // |
| 5562 B(Star), R(0), // | 6014 B(Star), R(0), // |
| 5563 B(LdaTheHole), // | 6015 B(LdaTheHole), // |
| 5564 B(Star), R(1), // | 6016 B(Star), R(1), // |
| 6017 B(StackCheck), // |
| 5565 B(Ldar), A(1, 3), // | 6018 B(Ldar), A(1, 3), // |
| 5566 B(Star), R(1), // | 6019 B(Star), R(1), // |
| 5567 B(Ldar), R(0), // | 6020 B(Ldar), R(0), // |
| 5568 B(Return), // | 6021 B(Return), // |
| 5569 }, | 6022 }, |
| 5570 1, | 6023 1, |
| 5571 {1}}, | 6024 {1}}, |
| 5572 {"function f(a, ...restArgs) { return restArgs[0]; }", | 6025 {"function f(a, ...restArgs) { return restArgs[0]; }", |
| 5573 3 * kPointerSize, | 6026 3 * kPointerSize, |
| 5574 3, | 6027 3, |
| 5575 20, | 6028 21, |
| 5576 { | 6029 { |
| 5577 B(CreateRestArguments), U8(0), // | 6030 B(CreateRestArguments), U8(0), // |
| 5578 B(Star), R(0), // | 6031 B(Star), R(0), // |
| 5579 B(LdaTheHole), // | 6032 B(LdaTheHole), // |
| 5580 B(Star), R(1), // | 6033 B(Star), R(1), // |
| 6034 B(StackCheck), // |
| 5581 B(Ldar), A(1, 3), // | 6035 B(Ldar), A(1, 3), // |
| 5582 B(Star), R(1), // | 6036 B(Star), R(1), // |
| 5583 B(Ldar), R(0), // | 6037 B(Ldar), R(0), // |
| 5584 B(Star), R(2), // | 6038 B(Star), R(2), // |
| 5585 B(LdaZero), // | 6039 B(LdaZero), // |
| 5586 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), // | 6040 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), // |
| 5587 B(Return), // | 6041 B(Return), // |
| 5588 }, | 6042 }, |
| 5589 1, | 6043 1, |
| 5590 {1}}, | 6044 {1}}, |
| 5591 {"function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }", | 6045 {"function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }", |
| 5592 5 * kPointerSize, | 6046 5 * kPointerSize, |
| 5593 3, | 6047 3, |
| 5594 35, | 6048 36, |
| 5595 { | 6049 { |
| 5596 B(CreateUnmappedArguments), // | 6050 B(CreateUnmappedArguments), // |
| 5597 B(Star), R(0), // | 6051 B(Star), R(0), // |
| 5598 B(CreateRestArguments), U8(0), // | 6052 B(CreateRestArguments), U8(0), // |
| 5599 B(Star), R(1), // | 6053 B(Star), R(1), // |
| 5600 B(LdaTheHole), // | 6054 B(LdaTheHole), // |
| 5601 B(Star), R(2), // | 6055 B(Star), R(2), // |
| 6056 B(StackCheck), // |
| 5602 B(Ldar), A(1, 3), // | 6057 B(Ldar), A(1, 3), // |
| 5603 B(Star), R(2), // | 6058 B(Star), R(2), // |
| 5604 B(Ldar), R(1), // | 6059 B(Ldar), R(1), // |
| 5605 B(Star), R(3), // | 6060 B(Star), R(3), // |
| 5606 B(LdaZero), // | 6061 B(LdaZero), // |
| 5607 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot)), // | 6062 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot)), // |
| 5608 B(Star), R(4), // | 6063 B(Star), R(4), // |
| 5609 B(Ldar), R(0), // | 6064 B(Ldar), R(0), // |
| 5610 B(Star), R(3), // | 6065 B(Star), R(3), // |
| 5611 B(LdaZero), // | 6066 B(LdaZero), // |
| 5612 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot1)), // | 6067 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot1)), // |
| 5613 B(Add), R(4), // | 6068 B(Add), R(4), // |
| 5614 B(Return), // | 6069 B(Return), // |
| 5615 }, | 6070 }, |
| 5616 1, | 6071 1, |
| 5617 {1}}, | 6072 {1}}, |
| 5618 }; | 6073 }; |
| 6074 // clang-format on |
| 5619 | 6075 |
| 5620 for (size_t i = 0; i < arraysize(snippets); i++) { | 6076 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5621 Handle<BytecodeArray> bytecode_array = | 6077 Handle<BytecodeArray> bytecode_array = |
| 5622 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 6078 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 5623 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6079 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5624 } | 6080 } |
| 5625 } | 6081 } |
| 5626 | 6082 |
| 5627 TEST(IllegalRedeclaration) { | 6083 TEST(IllegalRedeclaration) { |
| 5628 InitializedHandleScope handle_scope; | 6084 InitializedHandleScope handle_scope; |
| 5629 BytecodeGeneratorHelper helper; | 6085 BytecodeGeneratorHelper helper; |
| 5630 | 6086 |
| 5631 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); | 6087 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); |
| 5632 // Must adapt bytecode if this changes. | 6088 // Must adapt bytecode if this changes. |
| 5633 | 6089 |
| 6090 // clang-format off |
| 5634 ExpectedSnippet<Handle<Object>, 2> snippets[] = { | 6091 ExpectedSnippet<Handle<Object>, 2> snippets[] = { |
| 5635 {"const a = 1; { var a = 2; }", | 6092 {"const a = 1; { var a = 2; }", |
| 5636 3 * kPointerSize, | 6093 3 * kPointerSize, |
| 5637 1, | 6094 1, |
| 5638 14, | 6095 14, |
| 5639 { | 6096 { |
| 5640 B(LdaConstant), U8(0), // | 6097 B(LdaConstant), U8(0), // |
| 5641 B(Star), R(1), // | 6098 B(Star), R(1), // |
| 5642 B(LdaConstant), U8(1), // | 6099 B(LdaConstant), U8(1), // |
| 5643 B(Star), R(2), // | 6100 B(Star), R(2), // |
| 5644 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // | 6101 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // |
| 5645 B(Throw), // | 6102 B(Throw), // |
| 5646 }, | 6103 }, |
| 5647 2, | 6104 2, |
| 5648 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), | 6105 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), |
| 5649 helper.factory()->NewStringFromAsciiChecked("a")}}, | 6106 helper.factory()->NewStringFromAsciiChecked("a")}}, |
| 5650 }; | 6107 }; |
| 6108 // clang-format on |
| 5651 | 6109 |
| 5652 for (size_t i = 0; i < arraysize(snippets); i++) { | 6110 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5653 Handle<BytecodeArray> bytecode_array = | 6111 Handle<BytecodeArray> bytecode_array = |
| 5654 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6112 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5655 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6113 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5656 } | 6114 } |
| 5657 } | 6115 } |
| 5658 | 6116 |
| 5659 | 6117 |
| 5660 TEST(ForIn) { | 6118 TEST(ForIn) { |
| 5661 InitializedHandleScope handle_scope; | 6119 InitializedHandleScope handle_scope; |
| 5662 BytecodeGeneratorHelper helper; | 6120 BytecodeGeneratorHelper helper; |
| 5663 Zone zone; | 6121 Zone zone; |
| 5664 | 6122 |
| 5665 int simple_flags = | 6123 int simple_flags = |
| 5666 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; | 6124 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; |
| 5667 int deep_elements_flags = | 6125 int deep_elements_flags = |
| 5668 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 6126 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 5669 | 6127 |
| 5670 FeedbackVectorSpec feedback_spec(&zone); | 6128 FeedbackVectorSpec feedback_spec(&zone); |
| 5671 feedback_spec.AddStoreICSlot(); | 6129 feedback_spec.AddStoreICSlot(); |
| 5672 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); | 6130 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
| 5673 FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot(); | 6131 FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot(); |
| 5674 FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot(); | 6132 FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot(); |
| 5675 Handle<i::TypeFeedbackVector> vector = | 6133 Handle<i::TypeFeedbackVector> vector = |
| 5676 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 6134 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5677 | 6135 |
| 6136 // clang-format off |
| 5678 ExpectedSnippet<InstanceType> snippets[] = { | 6137 ExpectedSnippet<InstanceType> snippets[] = { |
| 5679 {"for (var p in null) {}", | 6138 {"for (var p in null) {}", |
| 5680 2 * kPointerSize, | 6139 2 * kPointerSize, |
| 5681 1, | 6140 1, |
| 5682 2, | 6141 3, |
| 5683 {B(LdaUndefined), B(Return)}, | 6142 { |
| 6143 B(StackCheck), // |
| 6144 B(LdaUndefined), // |
| 6145 B(Return) // |
| 6146 }, |
| 5684 0}, | 6147 0}, |
| 5685 {"for (var p in undefined) {}", | 6148 {"for (var p in undefined) {}", |
| 5686 2 * kPointerSize, | 6149 2 * kPointerSize, |
| 5687 1, | 6150 1, |
| 5688 2, | 6151 3, |
| 5689 {B(LdaUndefined), B(Return)}, | 6152 { |
| 6153 B(StackCheck), // |
| 6154 B(LdaUndefined), // |
| 6155 B(Return) // |
| 6156 }, |
| 5690 0}, | 6157 0}, |
| 5691 {"for (var p in undefined) {}", | 6158 {"for (var p in undefined) {}", |
| 5692 2 * kPointerSize, | 6159 2 * kPointerSize, |
| 5693 1, | 6160 1, |
| 5694 2, | 6161 3, |
| 5695 {B(LdaUndefined), B(Return)}, | 6162 { |
| 6163 B(StackCheck), // |
| 6164 B(LdaUndefined), // |
| 6165 B(Return) // |
| 6166 }, |
| 5696 0}, | 6167 0}, |
| 5697 {"var x = 'potatoes';\n" | 6168 {"var x = 'potatoes';\n" |
| 5698 "for (var p in x) { return p; }", | 6169 "for (var p in x) { return p; }", |
| 5699 8 * kPointerSize, | 6170 8 * kPointerSize, |
| 5700 1, | 6171 1, |
| 5701 42, | 6172 46, |
| 5702 { | 6173 { |
| 6174 B(StackCheck), // |
| 5703 B(LdaConstant), U8(0), // | 6175 B(LdaConstant), U8(0), // |
| 5704 B(Star), R(1), // | 6176 B(Star), R(1), // |
| 5705 B(JumpIfUndefined), U8(36), // | 6177 B(JumpIfUndefined), U8(39), // |
| 6178 B(JumpIfNull), U8(37), // |
| 6179 B(ToObject), // |
| 5706 B(JumpIfNull), U8(34), // | 6180 B(JumpIfNull), U8(34), // |
| 5707 B(ToObject), // | |
| 5708 B(JumpIfNull), U8(31), // | |
| 5709 B(Star), R(3), // | 6181 B(Star), R(3), // |
| 5710 B(ForInPrepare), R(4), // | 6182 B(ForInPrepare), R(4), // |
| 5711 B(LdaZero), // | 6183 B(LdaZero), // |
| 5712 B(Star), R(7), // | 6184 B(Star), R(7), // |
| 5713 B(ForInDone), R(7), R(6), // | 6185 B(ForInDone), R(7), R(6), // |
| 5714 B(JumpIfTrue), U8(19), // | 6186 B(JumpIfTrue), U8(22), // |
| 5715 B(ForInNext), R(3), R(7), R(4), // | 6187 B(ForInNext), R(3), R(7), R(4), // |
| 5716 B(JumpIfUndefined), U8(7), // | 6188 B(JumpIfUndefined), U8(10), // |
| 5717 B(Star), R(0), // | 6189 B(Star), R(0), // |
| 6190 B(StackCheck), // |
| 6191 B(Ldar), R(0), // |
| 5718 B(Star), R(2), // | 6192 B(Star), R(2), // |
| 5719 B(Return), // | 6193 B(Return), // |
| 5720 B(ForInStep), R(7), // | 6194 B(ForInStep), R(7), // |
| 5721 B(Star), R(7), // | 6195 B(Star), R(7), // |
| 5722 B(Jump), U8(-20), // | 6196 B(Jump), U8(-23), // |
| 5723 B(LdaUndefined), // | 6197 B(LdaUndefined), // |
| 5724 B(Return), // | 6198 B(Return), // |
| 5725 }, | 6199 }, |
| 5726 1, | 6200 1, |
| 5727 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6201 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5728 {"var x = 0;\n" | 6202 {"var x = 0;\n" |
| 5729 "for (var p in [1,2,3]) { x += p; }", | 6203 "for (var p in [1,2,3]) { x += p; }", |
| 5730 9 * kPointerSize, | 6204 9 * kPointerSize, |
| 5731 1, | 6205 1, |
| 5732 54, | 6206 58, |
| 5733 { | 6207 { |
| 6208 B(StackCheck), // |
| 5734 B(LdaZero), // | 6209 B(LdaZero), // |
| 5735 B(Star), R(1), // | 6210 B(Star), R(1), // |
| 5736 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // | 6211 B(CreateArrayLiteral), U8(0), U8(0), U8(3), // |
| 5737 B(JumpIfUndefined), U8(45), // | 6212 B(JumpIfUndefined), U8(48), // |
| 6213 B(JumpIfNull), U8(46), // |
| 6214 B(ToObject), // |
| 5738 B(JumpIfNull), U8(43), // | 6215 B(JumpIfNull), U8(43), // |
| 5739 B(ToObject), // | |
| 5740 B(JumpIfNull), U8(40), // | |
| 5741 B(Star), R(3), // | 6216 B(Star), R(3), // |
| 5742 B(ForInPrepare), R(4), // | 6217 B(ForInPrepare), R(4), // |
| 5743 B(LdaZero), // | 6218 B(LdaZero), // |
| 5744 B(Star), R(7), // | 6219 B(Star), R(7), // |
| 5745 B(ForInDone), R(7), R(6), // | 6220 B(ForInDone), R(7), R(6), // |
| 5746 B(JumpIfTrue), U8(28), // | 6221 B(JumpIfTrue), U8(31), // |
| 5747 B(ForInNext), R(3), R(7), R(4), // | 6222 B(ForInNext), R(3), R(7), R(4), // |
| 5748 B(JumpIfUndefined), U8(16), // | 6223 B(JumpIfUndefined), U8(19), // |
| 5749 B(Star), R(0), // | 6224 B(Star), R(0), // |
| 6225 B(StackCheck), // |
| 6226 B(Ldar), R(0), // |
| 5750 B(Star), R(2), // | 6227 B(Star), R(2), // |
| 5751 B(Ldar), R(1), // | 6228 B(Ldar), R(1), // |
| 5752 B(Star), R(8), // | 6229 B(Star), R(8), // |
| 5753 B(Ldar), R(2), // | 6230 B(Ldar), R(2), // |
| 5754 B(Add), R(8), // | 6231 B(Add), R(8), // |
| 5755 B(Star), R(1), // | 6232 B(Star), R(1), // |
| 5756 B(ForInStep), R(7), // | 6233 B(ForInStep), R(7), // |
| 5757 B(Star), R(7), // | 6234 B(Star), R(7), // |
| 5758 B(Jump), U8(-29), // | 6235 B(Jump), U8(-32), // |
| 5759 B(LdaUndefined), // | 6236 B(LdaUndefined), // |
| 5760 B(Return), // | 6237 B(Return), // |
| 5761 }, | 6238 }, |
| 5762 1, | 6239 1, |
| 5763 {InstanceType::FIXED_ARRAY_TYPE}}, | 6240 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 5764 {"var x = { 'a': 1, 'b': 2 };\n" | 6241 {"var x = { 'a': 1, 'b': 2 };\n" |
| 5765 "for (x['a'] in [10, 20, 30]) {\n" | 6242 "for (x['a'] in [10, 20, 30]) {\n" |
| 5766 " if (x['a'] == 10) continue;\n" | 6243 " if (x['a'] == 10) continue;\n" |
| 5767 " if (x['a'] == 20) break;\n" | 6244 " if (x['a'] == 20) break;\n" |
| 5768 "}", | 6245 "}", |
| 5769 8 * kPointerSize, | 6246 8 * kPointerSize, |
| 5770 1, | 6247 1, |
| 5771 93, | 6248 95, |
| 5772 { | 6249 { |
| 6250 B(StackCheck), // |
| 5773 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 6251 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 5774 B(Star), R(1), // | 6252 B(Star), R(1), // |
| 5775 B(Star), R(0), // | 6253 B(Star), R(0), // |
| 5776 B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), // | 6254 B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), // |
| 5777 B(JumpIfUndefined), U8(79), // | 6255 B(JumpIfUndefined), U8(80), // |
| 5778 B(JumpIfNull), U8(77), // | 6256 B(JumpIfNull), U8(78), // |
| 5779 B(ToObject), // | 6257 B(ToObject), // |
| 5780 B(JumpIfNull), U8(74), // | 6258 B(JumpIfNull), U8(75), // |
| 5781 B(Star), R(1), // | 6259 B(Star), R(1), // |
| 5782 B(ForInPrepare), R(2), // | 6260 B(ForInPrepare), R(2), // |
| 5783 B(LdaZero), // | 6261 B(LdaZero), // |
| 5784 B(Star), R(5), // | 6262 B(Star), R(5), // |
| 5785 B(ForInDone), R(5), R(4), // | 6263 B(ForInDone), R(5), R(4), // |
| 5786 B(JumpIfTrue), U8(62), // | 6264 B(JumpIfTrue), U8(63), // |
| 5787 B(ForInNext), R(1), R(5), R(2), // | 6265 B(ForInNext), R(1), R(5), R(2), // |
| 5788 B(JumpIfUndefined), U8(50), // | 6266 B(JumpIfUndefined), U8(51), // |
| 5789 B(Star), R(6), // | 6267 B(Star), R(6), // |
| 5790 B(Ldar), R(0), // | 6268 B(Ldar), R(0), // |
| 5791 B(Star), R(7), // | 6269 B(Star), R(7), // |
| 5792 B(Ldar), R(6), // | 6270 B(Ldar), R(6), // |
| 5793 B(StoreICSloppy), R(7), U8(2), U8(vector->GetIndex(slot4)), // | 6271 B(StoreICSloppy), R(7), U8(2), U8(vector->GetIndex(slot4)), // |
| 6272 B(StackCheck), // |
| 5794 B(Ldar), R(0), // | 6273 B(Ldar), R(0), // |
| 5795 B(Star), R(6), // | 6274 B(Star), R(6), // |
| 5796 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot2)), // | 6275 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot2)), // |
| 5797 B(Star), R(7), // | 6276 B(Star), R(7), // |
| 5798 B(LdaSmi8), U8(10), // | 6277 B(LdaSmi8), U8(10), // |
| 5799 B(TestEqual), R(7), // | 6278 B(TestEqual), R(7), // |
| 5800 B(JumpIfFalse), U8(4), // | 6279 B(JumpIfFalse), U8(4), // |
| 5801 B(Jump), U8(20), // | 6280 B(Jump), U8(20), // |
| 5802 B(Ldar), R(0), // | 6281 B(Ldar), R(0), // |
| 5803 B(Star), R(6), // | 6282 B(Star), R(6), // |
| 5804 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot3)), // | 6283 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot3)), // |
| 5805 B(Star), R(7), // | 6284 B(Star), R(7), // |
| 5806 B(LdaSmi8), U8(20), // | 6285 B(LdaSmi8), U8(20), // |
| 5807 B(TestEqual), R(7), // | 6286 B(TestEqual), R(7), // |
| 5808 B(JumpIfFalse), U8(4), // | 6287 B(JumpIfFalse), U8(4), // |
| 5809 B(Jump), U8(8), // | 6288 B(Jump), U8(8), // |
| 5810 B(ForInStep), R(5), // | 6289 B(ForInStep), R(5), // |
| 5811 B(Star), R(5), // | 6290 B(Star), R(5), // |
| 5812 B(Jump), U8(-63), // | 6291 B(Jump), U8(-64), // |
| 5813 B(LdaUndefined), // | 6292 B(LdaUndefined), // |
| 5814 B(Return), // | 6293 B(Return), // |
| 5815 }, | 6294 }, |
| 5816 3, | 6295 3, |
| 5817 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, | 6296 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, |
| 5818 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6297 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5819 {"var x = [ 10, 11, 12 ] ;\n" | 6298 {"var x = [ 10, 11, 12 ] ;\n" |
| 5820 "for (x[0] in [1,2,3]) { return x[3]; }", | 6299 "for (x[0] in [1,2,3]) { return x[3]; }", |
| 5821 9 * kPointerSize, | 6300 9 * kPointerSize, |
| 5822 1, | 6301 1, |
| 5823 68, | 6302 70, |
| 5824 { | 6303 { |
| 6304 B(StackCheck), // |
| 5825 B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), // | 6305 B(CreateArrayLiteral), U8(0), U8(0), U8(simple_flags), // |
| 5826 B(Star), R(0), // | 6306 B(Star), R(0), // |
| 5827 B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), // | 6307 B(CreateArrayLiteral), U8(1), U8(1), U8(simple_flags), // |
| 5828 B(JumpIfUndefined), U8(56), // | 6308 B(JumpIfUndefined), U8(57), // |
| 5829 B(JumpIfNull), U8(54), // | 6309 B(JumpIfNull), U8(55), // |
| 5830 B(ToObject), // | 6310 B(ToObject), // |
| 5831 B(JumpIfNull), U8(51), // | 6311 B(JumpIfNull), U8(52), // |
| 5832 B(Star), R(1), // | 6312 B(Star), R(1), // |
| 5833 B(ForInPrepare), R(2), // | 6313 B(ForInPrepare), R(2), // |
| 5834 B(LdaZero), // | 6314 B(LdaZero), // |
| 5835 B(Star), R(5), // | 6315 B(Star), R(5), // |
| 5836 B(ForInDone), R(5), R(4), // | 6316 B(ForInDone), R(5), R(4), // |
| 5837 B(JumpIfTrue), U8(39), // | 6317 B(JumpIfTrue), U8(40), // |
| 5838 B(ForInNext), R(1), R(5), R(2), // | 6318 B(ForInNext), R(1), R(5), R(2), // |
| 5839 B(JumpIfUndefined), U8(27), // | 6319 B(JumpIfUndefined), U8(28), // |
| 5840 B(Star), R(6), // | 6320 B(Star), R(6), // |
| 5841 B(Ldar), R(0), // | 6321 B(Ldar), R(0), // |
| 5842 B(Star), R(7), // | 6322 B(Star), R(7), // |
| 5843 B(LdaZero), // | 6323 B(LdaZero), // |
| 5844 B(Star), R(8), // | 6324 B(Star), R(8), // |
| 5845 B(Ldar), R(6), // | 6325 B(Ldar), R(6), // |
| 5846 B(KeyedStoreICSloppy), R(7), R(8), U8(vector->GetIndex(slot3)), // | 6326 B(KeyedStoreICSloppy), R(7), R(8), U8(vector->GetIndex(slot3)), // |
| 6327 B(StackCheck), // |
| 5847 B(Ldar), R(0), // | 6328 B(Ldar), R(0), // |
| 5848 B(Star), R(6), // | 6329 B(Star), R(6), // |
| 5849 B(LdaSmi8), U8(3), // | 6330 B(LdaSmi8), U8(3), // |
| 5850 B(KeyedLoadICSloppy), R(6), U8(vector->GetIndex(slot2)), // | 6331 B(KeyedLoadICSloppy), R(6), U8(vector->GetIndex(slot2)), // |
| 5851 B(Return), // | 6332 B(Return), // |
| 5852 B(ForInStep), R(5), // | 6333 B(ForInStep), R(5), // |
| 5853 B(Star), R(5), // | 6334 B(Star), R(5), // |
| 5854 B(Jump), U8(-40), // | 6335 B(Jump), U8(-41), // |
| 5855 B(LdaUndefined), // | 6336 B(LdaUndefined), // |
| 5856 B(Return), // | 6337 B(Return), // |
| 5857 }, | 6338 }, |
| 5858 2, | 6339 2, |
| 5859 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, | 6340 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, |
| 5860 }; | 6341 }; |
| 6342 // clang-format on |
| 5861 | 6343 |
| 5862 for (size_t i = 0; i < arraysize(snippets); i++) { | 6344 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5863 Handle<BytecodeArray> bytecode_array = | 6345 Handle<BytecodeArray> bytecode_array = |
| 5864 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6346 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 5865 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6347 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5866 } | 6348 } |
| 5867 } | 6349 } |
| 5868 | 6350 |
| 5869 | 6351 |
| 5870 TEST(ForOf) { | 6352 TEST(ForOf) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5882 FeedbackVectorSlot slot2 = feedback_spec.AddKeyedLoadICSlot(); | 6364 FeedbackVectorSlot slot2 = feedback_spec.AddKeyedLoadICSlot(); |
| 5883 FeedbackVectorSlot slot3 = feedback_spec.AddCallICSlot(); | 6365 FeedbackVectorSlot slot3 = feedback_spec.AddCallICSlot(); |
| 5884 FeedbackVectorSlot slot4 = feedback_spec.AddLoadICSlot(); | 6366 FeedbackVectorSlot slot4 = feedback_spec.AddLoadICSlot(); |
| 5885 FeedbackVectorSlot slot5 = feedback_spec.AddLoadICSlot(); | 6367 FeedbackVectorSlot slot5 = feedback_spec.AddLoadICSlot(); |
| 5886 FeedbackVectorSlot slot6 = feedback_spec.AddLoadICSlot(); | 6368 FeedbackVectorSlot slot6 = feedback_spec.AddLoadICSlot(); |
| 5887 FeedbackVectorSlot slot7 = feedback_spec.AddStoreICSlot(); | 6369 FeedbackVectorSlot slot7 = feedback_spec.AddStoreICSlot(); |
| 5888 FeedbackVectorSlot slot8 = feedback_spec.AddLoadICSlot(); | 6370 FeedbackVectorSlot slot8 = feedback_spec.AddLoadICSlot(); |
| 5889 Handle<i::TypeFeedbackVector> vector = | 6371 Handle<i::TypeFeedbackVector> vector = |
| 5890 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 6372 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5891 | 6373 |
| 6374 // clang-format off |
| 5892 ExpectedSnippet<InstanceType, 8> snippets[] = { | 6375 ExpectedSnippet<InstanceType, 8> snippets[] = { |
| 5893 {"for (var p of [0, 1, 2]) {}", | 6376 {"for (var p of [0, 1, 2]) {}", |
| 5894 7 * kPointerSize, | 6377 7 * kPointerSize, |
| 5895 1, | 6378 1, |
| 5896 82, | 6379 86, |
| 5897 { | 6380 { |
| 6381 B(StackCheck), // |
| 5898 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // | 6382 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // |
| 5899 B(Star), R(5), // | 6383 B(Star), R(5), // |
| 5900 B(LdaConstant), U8(1), // | 6384 B(LdaConstant), U8(1), // |
| 5901 B(KeyedLoadICSloppy), R(5), U8(vector->GetIndex(slot2)), // | 6385 B(KeyedLoadICSloppy), R(5), U8(vector->GetIndex(slot2)), // |
| 5902 B(Star), R(4), // | 6386 B(Star), R(4), // |
| 5903 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot1)), // | 6387 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot1)), // |
| 5904 B(Star), R(1), // | 6388 B(Star), R(1), // |
| 5905 B(Ldar), R(1), // | 6389 B(Ldar), R(1), // |
| 5906 B(Star), R(6), // | 6390 B(Star), R(6), // |
| 5907 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot4)), // | 6391 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot4)), // |
| 5908 B(Star), R(5), // | 6392 B(Star), R(5), // |
| 5909 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot3)), // | 6393 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot3)), // |
| 5910 B(Star), R(2), // | 6394 B(Star), R(2), // |
| 5911 B(Star), R(4), // | 6395 B(Star), R(4), // |
| 5912 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(4), U8(1), // | 6396 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(4), U8(1), // |
| 5913 B(LogicalNot), // | 6397 B(LogicalNot), // |
| 5914 B(JumpIfFalse), U8(11), // | 6398 B(JumpIfFalse), U8(11), // |
| 5915 B(Ldar), R(2), // | 6399 B(Ldar), R(2), // |
| 5916 B(Star), R(4), // | 6400 B(Star), R(4), // |
| 5917 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // | 6401 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // |
| 5918 R(4), U8(1), // | 6402 /* */ R(4), U8(1), // |
| 5919 B(Ldar), R(2), // | 6403 B(Ldar), R(2), // |
| 5920 B(Star), R(4), // | 6404 B(Star), R(4), // |
| 5921 B(LoadICSloppy), R(4), U8(3), U8(vector->GetIndex(slot5)), // | 6405 B(LoadICSloppy), R(4), U8(3), U8(vector->GetIndex(slot5)), // |
| 5922 B(JumpIfToBooleanTrue), U8(16), // | 6406 B(JumpIfToBooleanTrue), U8(19), // |
| 5923 B(Ldar), R(2), // | 6407 B(Ldar), R(2), // |
| 5924 B(Star), R(4), // | 6408 B(Star), R(4), // |
| 5925 B(LoadICSloppy), R(4), U8(4), U8(vector->GetIndex(slot6)), // | 6409 B(LoadICSloppy), R(4), U8(4), U8(vector->GetIndex(slot6)), // |
| 5926 B(Star), R(0), // | 6410 B(Star), R(0), // |
| 6411 B(StackCheck), // |
| 6412 B(Ldar), R(0), // |
| 5927 B(Star), R(3), // | 6413 B(Star), R(3), // |
| 5928 B(Jump), U8(-58), // | 6414 B(Jump), U8(-61), // |
| 5929 B(LdaUndefined), // | 6415 B(LdaUndefined), // |
| 5930 B(Return), // | 6416 B(Return), // |
| 5931 }, | 6417 }, |
| 5932 5, | 6418 5, |
| 5933 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SYMBOL_TYPE, | 6419 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SYMBOL_TYPE, |
| 5934 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6420 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5935 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6421 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5936 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6422 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5937 {"var x = 'potatoes';\n" | 6423 {"var x = 'potatoes';\n" |
| 5938 "for (var p of x) { return p; }", | 6424 "for (var p of x) { return p; }", |
| 5939 8 * kPointerSize, | 6425 8 * kPointerSize, |
| 5940 1, | 6426 1, |
| 5941 81, | 6427 85, |
| 5942 { | 6428 { |
| 6429 B(StackCheck), // |
| 5943 B(LdaConstant), U8(0), // | 6430 B(LdaConstant), U8(0), // |
| 5944 B(Star), R(3), // | 6431 B(Star), R(3), // |
| 5945 B(Star), R(6), // | 6432 B(Star), R(6), // |
| 5946 B(LdaConstant), U8(1), // | 6433 B(LdaConstant), U8(1), // |
| 5947 B(KeyedLoadICSloppy), R(6), U8(vector->GetIndex(slot2)), // | 6434 B(KeyedLoadICSloppy), R(6), U8(vector->GetIndex(slot2)), // |
| 5948 B(Star), R(5), // | 6435 B(Star), R(5), // |
| 5949 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot1)), // | 6436 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot1)), // |
| 5950 B(Star), R(1), // | 6437 B(Star), R(1), // |
| 5951 B(Ldar), R(1), // | 6438 B(Ldar), R(1), // |
| 5952 B(Star), R(7), // | 6439 B(Star), R(7), // |
| 5953 B(LoadICSloppy), R(7), U8(2), U8(vector->GetIndex(slot4)), // | 6440 B(LoadICSloppy), R(7), U8(2), U8(vector->GetIndex(slot4)), // |
| 5954 B(Star), R(6), // | 6441 B(Star), R(6), // |
| 5955 B(Call), R(6), R(7), U8(1), U8(vector->GetIndex(slot3)), // | 6442 B(Call), R(6), R(7), U8(1), U8(vector->GetIndex(slot3)), // |
| 5956 B(Star), R(2), // | 6443 B(Star), R(2), // |
| 5957 B(Star), R(5), // | 6444 B(Star), R(5), // |
| 5958 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(5), U8(1), // | 6445 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(5), U8(1), // |
| 5959 B(LogicalNot), // | 6446 B(LogicalNot), // |
| 5960 B(JumpIfFalse), U8(11), // | 6447 B(JumpIfFalse), U8(11), // |
| 5961 B(Ldar), R(2), // | 6448 B(Ldar), R(2), // |
| 5962 B(Star), R(5), // | 6449 B(Star), R(5), // |
| 5963 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // | 6450 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // |
| 5964 R(5), U8(1), // | 6451 /* */ R(5), U8(1), // |
| 5965 B(Ldar), R(2), // | 6452 B(Ldar), R(2), // |
| 5966 B(Star), R(5), // | 6453 B(Star), R(5), // |
| 5967 B(LoadICSloppy), R(5), U8(3), U8(vector->GetIndex(slot5)), // | 6454 B(LoadICSloppy), R(5), U8(3), U8(vector->GetIndex(slot5)), // |
| 5968 B(JumpIfToBooleanTrue), U8(15), // | 6455 B(JumpIfToBooleanTrue), U8(18), // |
| 5969 B(Ldar), R(2), // | 6456 B(Ldar), R(2), // |
| 5970 B(Star), R(5), // | 6457 B(Star), R(5), // |
| 5971 B(LoadICSloppy), R(5), U8(4), U8(vector->GetIndex(slot6)), // | 6458 B(LoadICSloppy), R(5), U8(4), U8(vector->GetIndex(slot6)), // |
| 5972 B(Star), R(0), // | 6459 B(Star), R(0), // |
| 6460 B(StackCheck), // |
| 6461 B(Ldar), R(0), // |
| 5973 B(Star), R(4), // | 6462 B(Star), R(4), // |
| 5974 B(Return), // | 6463 B(Return), // |
| 5975 B(LdaUndefined), // | 6464 B(LdaUndefined), // |
| 5976 B(Return), // | 6465 B(Return), // |
| 5977 }, | 6466 }, |
| 5978 5, | 6467 5, |
| 5979 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6468 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5980 InstanceType::SYMBOL_TYPE, | 6469 InstanceType::SYMBOL_TYPE, |
| 5981 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6470 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5982 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6471 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 5983 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6472 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5984 {"for (var x of [10, 20, 30]) {\n" | 6473 {"for (var x of [10, 20, 30]) {\n" |
| 5985 " if (x == 10) continue;\n" | 6474 " if (x == 10) continue;\n" |
| 5986 " if (x == 20) break;\n" | 6475 " if (x == 20) break;\n" |
| 5987 "}", | 6476 "}", |
| 5988 7 * kPointerSize, | 6477 7 * kPointerSize, |
| 5989 1, | 6478 1, |
| 5990 104, | 6479 108, |
| 5991 { | 6480 { |
| 6481 B(StackCheck), // |
| 5992 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // | 6482 B(CreateArrayLiteral), U8(0), U8(0), U8(array_literal_flags), // |
| 5993 B(Star), R(5), // | 6483 B(Star), R(5), // |
| 5994 B(LdaConstant), U8(1), // | 6484 B(LdaConstant), U8(1), // |
| 5995 B(KeyedLoadICSloppy), R(5), U8(vector->GetIndex(slot2)), // | 6485 B(KeyedLoadICSloppy), R(5), U8(vector->GetIndex(slot2)), // |
| 5996 B(Star), R(4), // | 6486 B(Star), R(4), // |
| 5997 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot1)), // | 6487 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot1)), // |
| 5998 B(Star), R(1), // | 6488 B(Star), R(1), // |
| 5999 B(Ldar), R(1), // | 6489 B(Ldar), R(1), // |
| 6000 B(Star), R(6), // | 6490 B(Star), R(6), // |
| 6001 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot4)), // | 6491 B(LoadICSloppy), R(6), U8(2), U8(vector->GetIndex(slot4)), // |
| 6002 B(Star), R(5), // | 6492 B(Star), R(5), // |
| 6003 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot3)), // | 6493 B(Call), R(5), R(6), U8(1), U8(vector->GetIndex(slot3)), // |
| 6004 B(Star), R(2), // | 6494 B(Star), R(2), // |
| 6005 B(Star), R(4), // | 6495 B(Star), R(4), // |
| 6006 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(4), U8(1), // | 6496 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(4), U8(1), // |
| 6007 B(LogicalNot), // | 6497 B(LogicalNot), // |
| 6008 B(JumpIfFalse), U8(11), // | 6498 B(JumpIfFalse), U8(11), // |
| 6009 B(Ldar), R(2), // | 6499 B(Ldar), R(2), // |
| 6010 B(Star), R(4), // | 6500 B(Star), R(4), // |
| 6011 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // | 6501 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // |
| 6012 R(4), U8(1), // | 6502 /* */ R(4), U8(1), // |
| 6013 B(Ldar), R(2), // | 6503 B(Ldar), R(2), // |
| 6014 B(Star), R(4), // | 6504 B(Star), R(4), // |
| 6015 B(LoadICSloppy), R(4), U8(3), U8(vector->GetIndex(slot5)), // | 6505 B(LoadICSloppy), R(4), U8(3), U8(vector->GetIndex(slot5)), // |
| 6016 B(JumpIfToBooleanTrue), U8(38), // | 6506 B(JumpIfToBooleanTrue), U8(41), // |
| 6017 B(Ldar), R(2), // | 6507 B(Ldar), R(2), // |
| 6018 B(Star), R(4), // | 6508 B(Star), R(4), // |
| 6019 B(LoadICSloppy), R(4), U8(4), U8(vector->GetIndex(slot6)), // | 6509 B(LoadICSloppy), R(4), U8(4), U8(vector->GetIndex(slot6)), // |
| 6020 B(Star), R(0), // | 6510 B(Star), R(0), // |
| 6511 B(StackCheck), // |
| 6512 B(Ldar), R(0), // |
| 6021 B(Star), R(3), // | 6513 B(Star), R(3), // |
| 6022 B(Star), R(4), // | 6514 B(Star), R(4), // |
| 6023 B(LdaSmi8), U8(10), // | 6515 B(LdaSmi8), U8(10), // |
| 6024 B(TestEqual), R(4), // | 6516 B(TestEqual), R(4), // |
| 6025 B(JumpIfFalse), U8(4), // | 6517 B(JumpIfFalse), U8(4), // |
| 6026 B(Jump), U8(-66), // | 6518 B(Jump), U8(-69), // |
| 6027 B(Ldar), R(3), // | 6519 B(Ldar), R(3), // |
| 6028 B(Star), R(4), // | 6520 B(Star), R(4), // |
| 6029 B(LdaSmi8), U8(20), // | 6521 B(LdaSmi8), U8(20), // |
| 6030 B(TestEqual), R(4), // | 6522 B(TestEqual), R(4), // |
| 6031 B(JumpIfFalse), U8(4), // | 6523 B(JumpIfFalse), U8(4), // |
| 6032 B(Jump), U8(4), // | 6524 B(Jump), U8(4), // |
| 6033 B(Jump), U8(-80), // | 6525 B(Jump), U8(-83), // |
| 6034 B(LdaUndefined), // | 6526 B(LdaUndefined), // |
| 6035 B(Return), // | 6527 B(Return), // |
| 6036 }, | 6528 }, |
| 6037 5, | 6529 5, |
| 6038 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SYMBOL_TYPE, | 6530 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SYMBOL_TYPE, |
| 6039 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6531 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6040 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6532 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6041 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6533 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 6042 {"var x = { 'a': 1, 'b': 2 };\n" | 6534 {"var x = { 'a': 1, 'b': 2 };\n" |
| 6043 "for (x['a'] of [1,2,3]) { return x['a']; }", | 6535 "for (x['a'] of [1,2,3]) { return x['a']; }", |
| 6044 6 * kPointerSize, | 6536 6 * kPointerSize, |
| 6045 1, | 6537 1, |
| 6046 101, | 6538 103, |
| 6047 { | 6539 { |
| 6540 B(StackCheck), // |
| 6048 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // | 6541 B(CreateObjectLiteral), U8(0), U8(0), U8(object_literal_flags), // |
| 6049 B(Star), R(3), // | 6542 B(Star), R(3), // |
| 6050 B(Star), R(2), // | 6543 B(Star), R(2), // |
| 6051 B(CreateArrayLiteral), U8(1), U8(1), U8(array_literal_flags), // | 6544 B(CreateArrayLiteral), U8(1), U8(1), U8(array_literal_flags), // |
| 6052 B(Star), R(4), // | 6545 B(Star), R(4), // |
| 6053 B(LdaConstant), U8(2), // | 6546 B(LdaConstant), U8(2), // |
| 6054 B(KeyedLoadICSloppy), R(4), U8(vector->GetIndex(slot2)), // | 6547 B(KeyedLoadICSloppy), R(4), U8(vector->GetIndex(slot2)), // |
| 6055 B(Star), R(3), // | 6548 B(Star), R(3), // |
| 6056 B(Call), R(3), R(4), U8(1), U8(vector->GetIndex(slot1)), // | 6549 B(Call), R(3), R(4), U8(1), U8(vector->GetIndex(slot1)), // |
| 6057 B(Star), R(0), // | 6550 B(Star), R(0), // |
| 6058 B(Ldar), R(0), // | 6551 B(Ldar), R(0), // |
| 6059 B(Star), R(5), // | 6552 B(Star), R(5), // |
| 6060 B(LoadICSloppy), R(5), U8(3), U8(vector->GetIndex(slot4)), // | 6553 B(LoadICSloppy), R(5), U8(3), U8(vector->GetIndex(slot4)), // |
| 6061 B(Star), R(4), // | 6554 B(Star), R(4), // |
| 6062 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot3)), // | 6555 B(Call), R(4), R(5), U8(1), U8(vector->GetIndex(slot3)), // |
| 6063 B(Star), R(1), // | 6556 B(Star), R(1), // |
| 6064 B(Star), R(3), // | 6557 B(Star), R(3), // |
| 6065 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(3), U8(1), // | 6558 B(CallRuntime), U16(Runtime::kInlineIsJSReceiver), R(3), U8(1), // |
| 6066 B(LogicalNot), // | 6559 B(LogicalNot), // |
| 6067 B(JumpIfFalse), U8(11), // | 6560 B(JumpIfFalse), U8(11), // |
| 6068 B(Ldar), R(1), // | 6561 B(Ldar), R(1), // |
| 6069 B(Star), R(3), // | 6562 B(Star), R(3), // |
| 6070 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // | 6563 B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), // |
| 6071 R(3), U8(1), // | 6564 /* */ R(3), U8(1), // |
| 6072 B(Ldar), R(1), // | 6565 B(Ldar), R(1), // |
| 6073 B(Star), R(3), // | 6566 B(Star), R(3), // |
| 6074 B(LoadICSloppy), R(3), U8(4), U8(vector->GetIndex(slot5)), // | 6567 B(LoadICSloppy), R(3), U8(4), U8(vector->GetIndex(slot5)), // |
| 6075 B(JumpIfToBooleanTrue), U8(27), // | 6568 B(JumpIfToBooleanTrue), U8(28), // |
| 6076 B(Ldar), R(2), // | 6569 B(Ldar), R(2), // |
| 6077 B(Star), R(3), // | 6570 B(Star), R(3), // |
| 6078 B(Ldar), R(1), // | 6571 B(Ldar), R(1), // |
| 6079 B(Star), R(4), // | 6572 B(Star), R(4), // |
| 6080 B(LoadICSloppy), R(4), U8(5), U8(vector->GetIndex(slot6)), // | 6573 B(LoadICSloppy), R(4), U8(5), U8(vector->GetIndex(slot6)), // |
| 6081 B(StoreICSloppy), R(3), U8(6), U8(vector->GetIndex(slot7)), // | 6574 B(StoreICSloppy), R(3), U8(6), U8(vector->GetIndex(slot7)), // |
| 6575 B(StackCheck), // |
| 6082 B(Ldar), R(2), // | 6576 B(Ldar), R(2), // |
| 6083 B(Star), R(3), // | 6577 B(Star), R(3), // |
| 6084 B(LoadICSloppy), R(3), U8(6), U8(vector->GetIndex(slot8)), // | 6578 B(LoadICSloppy), R(3), U8(6), U8(vector->GetIndex(slot8)), // |
| 6085 B(Return), // | 6579 B(Return), // |
| 6086 B(LdaUndefined), // | 6580 B(LdaUndefined), // |
| 6087 B(Return), // | 6581 B(Return), // |
| 6088 }, | 6582 }, |
| 6089 7, | 6583 7, |
| 6090 {InstanceType::FIXED_ARRAY_TYPE, | 6584 {InstanceType::FIXED_ARRAY_TYPE, |
| 6091 InstanceType::FIXED_ARRAY_TYPE, | 6585 InstanceType::FIXED_ARRAY_TYPE, |
| 6092 InstanceType::SYMBOL_TYPE, | 6586 InstanceType::SYMBOL_TYPE, |
| 6093 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6587 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6094 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6588 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6095 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 6589 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6096 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 6590 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 6097 }; | 6591 }; |
| 6592 // clang-format on |
| 6098 | 6593 |
| 6099 for (size_t i = 0; i < arraysize(snippets); i++) { | 6594 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6100 Handle<BytecodeArray> bytecode_array = | 6595 Handle<BytecodeArray> bytecode_array = |
| 6101 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6596 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6102 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6597 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6103 } | 6598 } |
| 6104 } | 6599 } |
| 6105 | 6600 |
| 6106 | 6601 |
| 6107 TEST(Conditional) { | 6602 TEST(Conditional) { |
| 6108 InitializedHandleScope handle_scope; | 6603 InitializedHandleScope handle_scope; |
| 6109 BytecodeGeneratorHelper helper; | 6604 BytecodeGeneratorHelper helper; |
| 6110 | 6605 |
| 6606 // clang-format off |
| 6111 ExpectedSnippet<int> snippets[] = { | 6607 ExpectedSnippet<int> snippets[] = { |
| 6112 {"return 1 ? 2 : 3;", | 6608 {"return 1 ? 2 : 3;", |
| 6113 0, | 6609 0, |
| 6114 1, | 6610 1, |
| 6115 11, | 6611 12, |
| 6116 { | 6612 { |
| 6613 B(StackCheck), // |
| 6117 B(LdaSmi8), U8(1), // | 6614 B(LdaSmi8), U8(1), // |
| 6118 B(JumpIfToBooleanFalse), U8(6), // | 6615 B(JumpIfToBooleanFalse), U8(6), // |
| 6119 B(LdaSmi8), U8(2), // | 6616 B(LdaSmi8), U8(2), // |
| 6120 B(Jump), U8(4), // | 6617 B(Jump), U8(4), // |
| 6121 B(LdaSmi8), U8(3), // | 6618 B(LdaSmi8), U8(3), // |
| 6122 B(Return), // | 6619 B(Return), // |
| 6123 }}, | 6620 }}, |
| 6124 {"return 1 ? 2 ? 3 : 4 : 5;", | 6621 {"return 1 ? 2 ? 3 : 4 : 5;", |
| 6125 0, | 6622 0, |
| 6126 1, | 6623 1, |
| 6127 19, | 6624 20, |
| 6128 { | 6625 { |
| 6626 B(StackCheck), // |
| 6129 B(LdaSmi8), U8(1), // | 6627 B(LdaSmi8), U8(1), // |
| 6130 B(JumpIfToBooleanFalse), U8(14), // | 6628 B(JumpIfToBooleanFalse), U8(14), // |
| 6131 B(LdaSmi8), U8(2), // | 6629 B(LdaSmi8), U8(2), // |
| 6132 B(JumpIfToBooleanFalse), U8(6), // | 6630 B(JumpIfToBooleanFalse), U8(6), // |
| 6133 B(LdaSmi8), U8(3), // | 6631 B(LdaSmi8), U8(3), // |
| 6134 B(Jump), U8(4), // | 6632 B(Jump), U8(4), // |
| 6135 B(LdaSmi8), U8(4), // | 6633 B(LdaSmi8), U8(4), // |
| 6136 B(Jump), U8(4), // | 6634 B(Jump), U8(4), // |
| 6137 B(LdaSmi8), U8(5), // | 6635 B(LdaSmi8), U8(5), // |
| 6138 B(Return), // | 6636 B(Return), // |
| 6139 }}, | 6637 }}, |
| 6140 }; | 6638 }; |
| 6639 // clang-format on |
| 6141 | 6640 |
| 6142 for (size_t i = 0; i < arraysize(snippets); i++) { | 6641 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6143 Handle<BytecodeArray> bytecode_array = | 6642 Handle<BytecodeArray> bytecode_array = |
| 6144 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6643 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6145 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6644 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6146 } | 6645 } |
| 6147 } | 6646 } |
| 6148 | 6647 |
| 6149 | 6648 |
| 6150 TEST(Switch) { | 6649 TEST(Switch) { |
| 6151 InitializedHandleScope handle_scope; | 6650 InitializedHandleScope handle_scope; |
| 6152 BytecodeGeneratorHelper helper; | 6651 BytecodeGeneratorHelper helper; |
| 6153 | 6652 |
| 6653 // clang-format off |
| 6154 ExpectedSnippet<int> snippets[] = { | 6654 ExpectedSnippet<int> snippets[] = { |
| 6155 {"var a = 1;\n" | 6655 {"var a = 1;\n" |
| 6156 "switch(a) {\n" | 6656 "switch(a) {\n" |
| 6157 " case 1: return 2;\n" | 6657 " case 1: return 2;\n" |
| 6158 " case 2: return 3;\n" | 6658 " case 2: return 3;\n" |
| 6159 "}\n", | 6659 "}\n", |
| 6160 3 * kPointerSize, | 6660 3 * kPointerSize, |
| 6161 1, | 6661 1, |
| 6162 30, | 6662 31, |
| 6163 { | 6663 { |
| 6664 B(StackCheck), // |
| 6164 B(LdaSmi8), U8(1), // | 6665 B(LdaSmi8), U8(1), // |
| 6165 B(Star), R(1), // The tag variable is allocated as a | 6666 B(Star), R(1), // The tag variable is allocated as a |
| 6166 B(Star), R(0), // local by the parser, hence the store | 6667 B(Star), R(0), // local by the parser, hence the store |
| 6167 B(Star), R(2), // to another local register. | 6668 B(Star), R(2), // to another local register. |
| 6168 B(LdaSmi8), U8(1), // | 6669 B(LdaSmi8), U8(1), // |
| 6169 B(TestEqualStrict), R(2), // | 6670 B(TestEqualStrict), R(2), // |
| 6170 B(JumpIfTrue), U8(10), // | 6671 B(JumpIfTrue), U8(10), // |
| 6171 B(LdaSmi8), U8(2), // | 6672 B(LdaSmi8), U8(2), // |
| 6172 B(TestEqualStrict), R(2), // | 6673 B(TestEqualStrict), R(2), // |
| 6173 B(JumpIfTrue), U8(7), // | 6674 B(JumpIfTrue), U8(7), // |
| 6174 B(Jump), U8(8), // | 6675 B(Jump), U8(8), // |
| 6175 B(LdaSmi8), U8(2), // | 6676 B(LdaSmi8), U8(2), // |
| 6176 B(Return), // | 6677 B(Return), // |
| 6177 B(LdaSmi8), U8(3), // | 6678 B(LdaSmi8), U8(3), // |
| 6178 B(Return), // | 6679 B(Return), // |
| 6179 B(LdaUndefined), // | 6680 B(LdaUndefined), // |
| 6180 B(Return), // | 6681 B(Return), // |
| 6181 }}, | 6682 }}, |
| 6182 {"var a = 1;\n" | 6683 {"var a = 1;\n" |
| 6183 "switch(a) {\n" | 6684 "switch(a) {\n" |
| 6184 " case 1: a = 2; break;\n" | 6685 " case 1: a = 2; break;\n" |
| 6185 " case 2: a = 3; break;\n" | 6686 " case 2: a = 3; break;\n" |
| 6186 "}\n", | 6687 "}\n", |
| 6187 3 * kPointerSize, | 6688 3 * kPointerSize, |
| 6188 1, | 6689 1, |
| 6189 36, | 6690 37, |
| 6190 { | 6691 { |
| 6692 B(StackCheck), // |
| 6191 B(LdaSmi8), U8(1), // | 6693 B(LdaSmi8), U8(1), // |
| 6192 B(Star), R(1), // | 6694 B(Star), R(1), // |
| 6193 B(Star), R(0), // | 6695 B(Star), R(0), // |
| 6194 B(Star), R(2), // | 6696 B(Star), R(2), // |
| 6195 B(LdaSmi8), U8(1), // | 6697 B(LdaSmi8), U8(1), // |
| 6196 B(TestEqualStrict), R(2), // | 6698 B(TestEqualStrict), R(2), // |
| 6197 B(JumpIfTrue), U8(10), // | 6699 B(JumpIfTrue), U8(10), // |
| 6198 B(LdaSmi8), U8(2), // | 6700 B(LdaSmi8), U8(2), // |
| 6199 B(TestEqualStrict), R(2), // | 6701 B(TestEqualStrict), R(2), // |
| 6200 B(JumpIfTrue), U8(10), // | 6702 B(JumpIfTrue), U8(10), // |
| 6201 B(Jump), U8(14), // | 6703 B(Jump), U8(14), // |
| 6202 B(LdaSmi8), U8(2), // | 6704 B(LdaSmi8), U8(2), // |
| 6203 B(Star), R(1), // | 6705 B(Star), R(1), // |
| 6204 B(Jump), U8(8), // | 6706 B(Jump), U8(8), // |
| 6205 B(LdaSmi8), U8(3), // | 6707 B(LdaSmi8), U8(3), // |
| 6206 B(Star), R(1), // | 6708 B(Star), R(1), // |
| 6207 B(Jump), U8(2), // | 6709 B(Jump), U8(2), // |
| 6208 B(LdaUndefined), // | 6710 B(LdaUndefined), // |
| 6209 B(Return), // | 6711 B(Return), // |
| 6210 }}, | 6712 }}, |
| 6211 {"var a = 1;\n" | 6713 {"var a = 1;\n" |
| 6212 "switch(a) {\n" | 6714 "switch(a) {\n" |
| 6213 " case 1: a = 2; // fall-through\n" | 6715 " case 1: a = 2; // fall-through\n" |
| 6214 " case 2: a = 3; break;\n" | 6716 " case 2: a = 3; break;\n" |
| 6215 "}\n", | 6717 "}\n", |
| 6216 3 * kPointerSize, | 6718 3 * kPointerSize, |
| 6217 1, | 6719 1, |
| 6218 34, | 6720 35, |
| 6219 { | 6721 { |
| 6722 B(StackCheck), // |
| 6220 B(LdaSmi8), U8(1), // | 6723 B(LdaSmi8), U8(1), // |
| 6221 B(Star), R(1), // | 6724 B(Star), R(1), // |
| 6222 B(Star), R(0), // | 6725 B(Star), R(0), // |
| 6223 B(Star), R(2), // | 6726 B(Star), R(2), // |
| 6224 B(LdaSmi8), U8(1), // | 6727 B(LdaSmi8), U8(1), // |
| 6225 B(TestEqualStrict), R(2), // | 6728 B(TestEqualStrict), R(2), // |
| 6226 B(JumpIfTrue), U8(10), // | 6729 B(JumpIfTrue), U8(10), // |
| 6227 B(LdaSmi8), U8(2), // | 6730 B(LdaSmi8), U8(2), // |
| 6228 B(TestEqualStrict), R(2), // | 6731 B(TestEqualStrict), R(2), // |
| 6229 B(JumpIfTrue), U8(8), // | 6732 B(JumpIfTrue), U8(8), // |
| 6230 B(Jump), U8(12), // | 6733 B(Jump), U8(12), // |
| 6231 B(LdaSmi8), U8(2), // | 6734 B(LdaSmi8), U8(2), // |
| 6232 B(Star), R(1), // | 6735 B(Star), R(1), // |
| 6233 B(LdaSmi8), U8(3), // | 6736 B(LdaSmi8), U8(3), // |
| 6234 B(Star), R(1), // | 6737 B(Star), R(1), // |
| 6235 B(Jump), U8(2), // | 6738 B(Jump), U8(2), // |
| 6236 B(LdaUndefined), // | 6739 B(LdaUndefined), // |
| 6237 B(Return), // | 6740 B(Return), // |
| 6238 }}, | 6741 }}, |
| 6239 {"var a = 1;\n" | 6742 {"var a = 1;\n" |
| 6240 "switch(a) {\n" | 6743 "switch(a) {\n" |
| 6241 " case 2: break;\n" | 6744 " case 2: break;\n" |
| 6242 " case 3: break;\n" | 6745 " case 3: break;\n" |
| 6243 " default: a = 1; break;\n" | 6746 " default: a = 1; break;\n" |
| 6244 "}\n", | 6747 "}\n", |
| 6245 3 * kPointerSize, | 6748 3 * kPointerSize, |
| 6246 1, | 6749 1, |
| 6247 34, | 6750 35, |
| 6248 { | 6751 { |
| 6752 B(StackCheck), // |
| 6249 B(LdaSmi8), U8(1), // | 6753 B(LdaSmi8), U8(1), // |
| 6250 B(Star), R(1), // | 6754 B(Star), R(1), // |
| 6251 B(Star), R(0), // | 6755 B(Star), R(0), // |
| 6252 B(Star), R(2), // | 6756 B(Star), R(2), // |
| 6253 B(LdaSmi8), U8(2), // | 6757 B(LdaSmi8), U8(2), // |
| 6254 B(TestEqualStrict), R(2), // | 6758 B(TestEqualStrict), R(2), // |
| 6255 B(JumpIfTrue), U8(10), // | 6759 B(JumpIfTrue), U8(10), // |
| 6256 B(LdaSmi8), U8(3), // | 6760 B(LdaSmi8), U8(3), // |
| 6257 B(TestEqualStrict), R(2), // | 6761 B(TestEqualStrict), R(2), // |
| 6258 B(JumpIfTrue), U8(6), // | 6762 B(JumpIfTrue), U8(6), // |
| 6259 B(Jump), U8(6), // | 6763 B(Jump), U8(6), // |
| 6260 B(Jump), U8(10), // | 6764 B(Jump), U8(10), // |
| 6261 B(Jump), U8(8), // | 6765 B(Jump), U8(8), // |
| 6262 B(LdaSmi8), U8(1), // | 6766 B(LdaSmi8), U8(1), // |
| 6263 B(Star), R(1), // | 6767 B(Star), R(1), // |
| 6264 B(Jump), U8(2), // | 6768 B(Jump), U8(2), // |
| 6265 B(LdaUndefined), // | 6769 B(LdaUndefined), // |
| 6266 B(Return), // | 6770 B(Return), // |
| 6267 }}, | 6771 }}, |
| 6268 {"var a = 1;\n" | 6772 {"var a = 1;\n" |
| 6269 "switch(typeof(a)) {\n" | 6773 "switch(typeof(a)) {\n" |
| 6270 " case 2: a = 1; break;\n" | 6774 " case 2: a = 1; break;\n" |
| 6271 " case 3: a = 2; break;\n" | 6775 " case 3: a = 2; break;\n" |
| 6272 " default: a = 3; break;\n" | 6776 " default: a = 3; break;\n" |
| 6273 "}\n", | 6777 "}\n", |
| 6274 3 * kPointerSize, | 6778 3 * kPointerSize, |
| 6275 1, | 6779 1, |
| 6276 43, | 6780 44, |
| 6277 { | 6781 { |
| 6782 B(StackCheck), // |
| 6278 B(LdaSmi8), U8(1), // | 6783 B(LdaSmi8), U8(1), // |
| 6279 B(Star), R(1), // | 6784 B(Star), R(1), // |
| 6280 B(TypeOf), // | 6785 B(TypeOf), // |
| 6281 B(Star), R(0), // | 6786 B(Star), R(0), // |
| 6282 B(Star), R(2), // | 6787 B(Star), R(2), // |
| 6283 B(LdaSmi8), U8(2), // | 6788 B(LdaSmi8), U8(2), // |
| 6284 B(TestEqualStrict), R(2), // | 6789 B(TestEqualStrict), R(2), // |
| 6285 B(JumpIfTrue), U8(10), // | 6790 B(JumpIfTrue), U8(10), // |
| 6286 B(LdaSmi8), U8(3), // | 6791 B(LdaSmi8), U8(3), // |
| 6287 B(TestEqualStrict), R(2), // | 6792 B(TestEqualStrict), R(2), // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6299 B(LdaUndefined), // | 6804 B(LdaUndefined), // |
| 6300 B(Return), // | 6805 B(Return), // |
| 6301 }}, | 6806 }}, |
| 6302 {"var a = 1;\n" | 6807 {"var a = 1;\n" |
| 6303 "switch(a) {\n" | 6808 "switch(a) {\n" |
| 6304 " case typeof(a): a = 1; break;\n" | 6809 " case typeof(a): a = 1; break;\n" |
| 6305 " default: a = 2; break;\n" | 6810 " default: a = 2; break;\n" |
| 6306 "}\n", | 6811 "}\n", |
| 6307 3 * kPointerSize, | 6812 3 * kPointerSize, |
| 6308 1, | 6813 1, |
| 6309 31, | 6814 32, |
| 6310 { | 6815 { |
| 6816 B(StackCheck), // |
| 6311 B(LdaSmi8), U8(1), // | 6817 B(LdaSmi8), U8(1), // |
| 6312 B(Star), R(1), // | 6818 B(Star), R(1), // |
| 6313 B(Star), R(0), // | 6819 B(Star), R(0), // |
| 6314 B(Star), R(2), // | 6820 B(Star), R(2), // |
| 6315 B(Ldar), R(1), // | 6821 B(Ldar), R(1), // |
| 6316 B(TypeOf), // | 6822 B(TypeOf), // |
| 6317 B(TestEqualStrict), R(2), // | 6823 B(TestEqualStrict), R(2), // |
| 6318 B(JumpIfTrue), U8(4), // | 6824 B(JumpIfTrue), U8(4), // |
| 6319 B(Jump), U8(8), // | 6825 B(Jump), U8(8), // |
| 6320 B(LdaSmi8), U8(1), // | 6826 B(LdaSmi8), U8(1), // |
| 6321 B(Star), R(1), // | 6827 B(Star), R(1), // |
| 6322 B(Jump), U8(8), // | 6828 B(Jump), U8(8), // |
| 6323 B(LdaSmi8), U8(2), // | 6829 B(LdaSmi8), U8(2), // |
| 6324 B(Star), R(1), // | 6830 B(Star), R(1), // |
| 6325 B(Jump), U8(2), // | 6831 B(Jump), U8(2), // |
| 6326 B(LdaUndefined), // | 6832 B(LdaUndefined), // |
| 6327 B(Return), // | 6833 B(Return), // |
| 6328 }}, | 6834 }}, |
| 6329 {"var a = 1;\n" | 6835 {"var a = 1;\n" |
| 6330 "switch(a) {\n" | 6836 "switch(a) {\n" |
| 6331 " case 1:\n" REPEAT_64(SPACE, " a = 2;") | 6837 " case 1:\n" REPEAT_64(SPACE, " a = 2;") |
| 6332 "break;\n" | 6838 "break;\n" |
| 6333 " case 2: a = 3; break;" | 6839 " case 2: a = 3; break;" |
| 6334 "}\n", | 6840 "}\n", |
| 6335 3 * kPointerSize, | 6841 3 * kPointerSize, |
| 6336 1, | 6842 1, |
| 6337 288, | 6843 289, |
| 6338 { | 6844 { |
| 6845 B(StackCheck), // |
| 6339 B(LdaSmi8), U8(1), // | 6846 B(LdaSmi8), U8(1), // |
| 6340 B(Star), R(1), // | 6847 B(Star), R(1), // |
| 6341 B(Star), R(0), // | 6848 B(Star), R(0), // |
| 6342 B(Star), R(2), // | 6849 B(Star), R(2), // |
| 6343 B(LdaSmi8), U8(1), // | 6850 B(LdaSmi8), U8(1), // |
| 6344 B(TestEqualStrict), R(2), // | 6851 B(TestEqualStrict), R(2), // |
| 6345 B(JumpIfTrue), U8(10), // | 6852 B(JumpIfTrue), U8(10), // |
| 6346 B(LdaSmi8), U8(2), // | 6853 B(LdaSmi8), U8(2), // |
| 6347 B(TestEqualStrict), R(2), // | 6854 B(TestEqualStrict), R(2), // |
| 6348 B(JumpIfTrueConstant), U8(0), // | 6855 B(JumpIfTrueConstant), U8(0), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6363 "switch(a) {\n" | 6870 "switch(a) {\n" |
| 6364 " case 1: \n" | 6871 " case 1: \n" |
| 6365 " switch(a + 1) {\n" | 6872 " switch(a + 1) {\n" |
| 6366 " case 2 : a = 1; break;\n" | 6873 " case 2 : a = 1; break;\n" |
| 6367 " default : a = 2; break;\n" | 6874 " default : a = 2; break;\n" |
| 6368 " } // fall-through\n" | 6875 " } // fall-through\n" |
| 6369 " case 2: a = 3;\n" | 6876 " case 2: a = 3;\n" |
| 6370 "}\n", | 6877 "}\n", |
| 6371 5 * kPointerSize, | 6878 5 * kPointerSize, |
| 6372 1, | 6879 1, |
| 6373 60, | 6880 61, |
| 6374 { | 6881 { |
| 6882 B(StackCheck), // |
| 6375 B(LdaSmi8), U8(1), // | 6883 B(LdaSmi8), U8(1), // |
| 6376 B(Star), R(2), // | 6884 B(Star), R(2), // |
| 6377 B(Star), R(0), // | 6885 B(Star), R(0), // |
| 6378 B(Star), R(3), // | 6886 B(Star), R(3), // |
| 6379 B(LdaSmi8), U8(1), // | 6887 B(LdaSmi8), U8(1), // |
| 6380 B(TestEqualStrict), R(3), // | 6888 B(TestEqualStrict), R(3), // |
| 6381 B(JumpIfTrue), U8(10), // | 6889 B(JumpIfTrue), U8(10), // |
| 6382 B(LdaSmi8), U8(2), // | 6890 B(LdaSmi8), U8(2), // |
| 6383 B(TestEqualStrict), R(3), // | 6891 B(TestEqualStrict), R(3), // |
| 6384 B(JumpIfTrue), U8(36), // | 6892 B(JumpIfTrue), U8(36), // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6398 B(Jump), U8(8), // | 6906 B(Jump), U8(8), // |
| 6399 B(LdaSmi8), U8(2), // | 6907 B(LdaSmi8), U8(2), // |
| 6400 B(Star), R(2), // | 6908 B(Star), R(2), // |
| 6401 B(Jump), U8(2), // | 6909 B(Jump), U8(2), // |
| 6402 B(LdaSmi8), U8(3), // | 6910 B(LdaSmi8), U8(3), // |
| 6403 B(Star), R(2), // | 6911 B(Star), R(2), // |
| 6404 B(LdaUndefined), // | 6912 B(LdaUndefined), // |
| 6405 B(Return), // | 6913 B(Return), // |
| 6406 }}, | 6914 }}, |
| 6407 }; | 6915 }; |
| 6916 // clang-format on |
| 6408 | 6917 |
| 6409 for (size_t i = 0; i < arraysize(snippets); i++) { | 6918 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6410 Handle<BytecodeArray> bytecode_array = | 6919 Handle<BytecodeArray> bytecode_array = |
| 6411 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6920 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6412 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6921 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6413 } | 6922 } |
| 6414 } | 6923 } |
| 6415 | 6924 |
| 6416 | 6925 |
| 6417 TEST(BasicBlockToBoolean) { | 6926 TEST(BasicBlockToBoolean) { |
| 6418 InitializedHandleScope handle_scope; | 6927 InitializedHandleScope handle_scope; |
| 6419 BytecodeGeneratorHelper helper; | 6928 BytecodeGeneratorHelper helper; |
| 6420 | 6929 |
| 6421 // Check that we generate JumpIfToBoolean if they are at the start of basic | 6930 // Check that we generate JumpIfToBoolean if they are at the start of basic |
| 6422 // blocks. | 6931 // blocks. |
| 6932 // clang-format off |
| 6423 ExpectedSnippet<int> snippets[] = { | 6933 ExpectedSnippet<int> snippets[] = { |
| 6424 {"var a = 1; if (a || a < 0) { return 1; }", | 6934 {"var a = 1; if (a || a < 0) { return 1; }", |
| 6425 2 * kPointerSize, | 6935 2 * kPointerSize, |
| 6426 1, | 6936 1, |
| 6427 20, | 6937 21, |
| 6428 { | 6938 { |
| 6939 B(StackCheck), // |
| 6429 B(LdaSmi8), U8(1), // | 6940 B(LdaSmi8), U8(1), // |
| 6430 B(Star), R(0), // | 6941 B(Star), R(0), // |
| 6431 B(JumpIfToBooleanTrue), U8(9), // | 6942 B(JumpIfToBooleanTrue), U8(9), // |
| 6432 B(Ldar), R(0), // | 6943 B(Ldar), R(0), // |
| 6433 B(Star), R(1), // | 6944 B(Star), R(1), // |
| 6434 B(LdaZero), // | 6945 B(LdaZero), // |
| 6435 B(TestLessThan), R(1), // | 6946 B(TestLessThan), R(1), // |
| 6436 B(JumpIfToBooleanFalse), U8(5), // | 6947 B(JumpIfToBooleanFalse), U8(5), // |
| 6437 B(LdaSmi8), U8(1), // | 6948 B(LdaSmi8), U8(1), // |
| 6438 B(Return), // | 6949 B(Return), // |
| 6439 B(LdaUndefined), // | 6950 B(LdaUndefined), // |
| 6440 B(Return), // | 6951 B(Return), // |
| 6441 }}, | 6952 }}, |
| 6442 {"var a = 1; if (a && a < 0) { return 1; }", | 6953 {"var a = 1; if (a && a < 0) { return 1; }", |
| 6443 2 * kPointerSize, | 6954 2 * kPointerSize, |
| 6444 1, | 6955 1, |
| 6445 20, | 6956 21, |
| 6446 { | 6957 { |
| 6958 B(StackCheck), // |
| 6447 B(LdaSmi8), U8(1), // | 6959 B(LdaSmi8), U8(1), // |
| 6448 B(Star), R(0), // | 6960 B(Star), R(0), // |
| 6449 B(JumpIfToBooleanFalse), U8(9), // | 6961 B(JumpIfToBooleanFalse), U8(9), // |
| 6450 B(Ldar), R(0), // | 6962 B(Ldar), R(0), // |
| 6451 B(Star), R(1), // | 6963 B(Star), R(1), // |
| 6452 B(LdaZero), // | 6964 B(LdaZero), // |
| 6453 B(TestLessThan), R(1), // | 6965 B(TestLessThan), R(1), // |
| 6454 B(JumpIfToBooleanFalse), U8(5), // | 6966 B(JumpIfToBooleanFalse), U8(5), // |
| 6455 B(LdaSmi8), U8(1), // | 6967 B(LdaSmi8), U8(1), // |
| 6456 B(Return), // | 6968 B(Return), // |
| 6457 B(LdaUndefined), // | 6969 B(LdaUndefined), // |
| 6458 B(Return), // | 6970 B(Return), // |
| 6459 }}, | 6971 }}, |
| 6460 {"var a = 1; a = (a || a < 0) ? 2 : 3;", | 6972 {"var a = 1; a = (a || a < 0) ? 2 : 3;", |
| 6461 2 * kPointerSize, | 6973 2 * kPointerSize, |
| 6462 1, | 6974 1, |
| 6463 25, | 6975 26, |
| 6464 { | 6976 { |
| 6977 B(StackCheck), // |
| 6465 B(LdaSmi8), U8(1), // | 6978 B(LdaSmi8), U8(1), // |
| 6466 B(Star), R(0), // | 6979 B(Star), R(0), // |
| 6467 B(JumpIfToBooleanTrue), U8(9), // | 6980 B(JumpIfToBooleanTrue), U8(9), // |
| 6468 B(Ldar), R(0), // | 6981 B(Ldar), R(0), // |
| 6469 B(Star), R(1), // | 6982 B(Star), R(1), // |
| 6470 B(LdaZero), // | 6983 B(LdaZero), // |
| 6471 B(TestLessThan), R(1), // | 6984 B(TestLessThan), R(1), // |
| 6472 B(JumpIfToBooleanFalse), U8(6), // | 6985 B(JumpIfToBooleanFalse), U8(6), // |
| 6473 B(LdaSmi8), U8(2), // | 6986 B(LdaSmi8), U8(2), // |
| 6474 B(Jump), U8(4), // | 6987 B(Jump), U8(4), // |
| 6475 B(LdaSmi8), U8(3), // | 6988 B(LdaSmi8), U8(3), // |
| 6476 B(Star), R(0), // | 6989 B(Star), R(0), // |
| 6477 B(LdaUndefined), // | 6990 B(LdaUndefined), // |
| 6478 B(Return), // | 6991 B(Return), // |
| 6479 }}, | 6992 }}, |
| 6480 }; | 6993 }; |
| 6994 // clang-format on |
| 6481 | 6995 |
| 6482 for (size_t i = 0; i < arraysize(snippets); i++) { | 6996 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6483 Handle<BytecodeArray> bytecode_array = | 6997 Handle<BytecodeArray> bytecode_array = |
| 6484 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6998 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6485 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6999 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6486 } | 7000 } |
| 6487 } | 7001 } |
| 6488 | 7002 |
| 6489 | 7003 |
| 6490 TEST(DeadCodeRemoval) { | 7004 TEST(DeadCodeRemoval) { |
| 6491 InitializedHandleScope handle_scope; | 7005 InitializedHandleScope handle_scope; |
| 6492 BytecodeGeneratorHelper helper; | 7006 BytecodeGeneratorHelper helper; |
| 6493 | 7007 |
| 7008 // clang-format off |
| 6494 ExpectedSnippet<int> snippets[] = { | 7009 ExpectedSnippet<int> snippets[] = { |
| 6495 {"return; var a = 1; a();", | 7010 {"return; var a = 1; a();", |
| 6496 1 * kPointerSize, | 7011 1 * kPointerSize, |
| 6497 1, | 7012 1, |
| 6498 2, | 7013 3, |
| 6499 { | 7014 { |
| 7015 B(StackCheck), // |
| 6500 B(LdaUndefined), // | 7016 B(LdaUndefined), // |
| 6501 B(Return), // | 7017 B(Return), // |
| 6502 }}, | 7018 }}, |
| 6503 {"if (false) { return; }; var a = 1;", | 7019 {"if (false) { return; }; var a = 1;", |
| 6504 1 * kPointerSize, | 7020 1 * kPointerSize, |
| 6505 1, | 7021 1, |
| 6506 6, | 7022 7, |
| 6507 { | 7023 { |
| 7024 B(StackCheck), // |
| 6508 B(LdaSmi8), U8(1), // | 7025 B(LdaSmi8), U8(1), // |
| 6509 B(Star), R(0), // | 7026 B(Star), R(0), // |
| 6510 B(LdaUndefined), // | 7027 B(LdaUndefined), // |
| 6511 B(Return), // | 7028 B(Return), // |
| 6512 }}, | 7029 }}, |
| 6513 {"if (true) { return 1; } else { return 2; };", | 7030 {"if (true) { return 1; } else { return 2; };", |
| 6514 0, | 7031 0, |
| 6515 1, | 7032 1, |
| 6516 3, | 7033 4, |
| 6517 { | 7034 { |
| 7035 B(StackCheck), // |
| 6518 B(LdaSmi8), U8(1), // | 7036 B(LdaSmi8), U8(1), // |
| 6519 B(Return), // | 7037 B(Return), // |
| 6520 }}, | 7038 }}, |
| 6521 {"var a = 1; if (a) { return 1; }; return 2;", | 7039 {"var a = 1; if (a) { return 1; }; return 2;", |
| 6522 1 * kPointerSize, | 7040 1 * kPointerSize, |
| 6523 1, | 7041 1, |
| 6524 12, | 7042 13, |
| 6525 { | 7043 { |
| 7044 B(StackCheck), // |
| 6526 B(LdaSmi8), U8(1), // | 7045 B(LdaSmi8), U8(1), // |
| 6527 B(Star), R(0), // | 7046 B(Star), R(0), // |
| 6528 B(JumpIfToBooleanFalse), U8(5), // | 7047 B(JumpIfToBooleanFalse), U8(5), // |
| 6529 B(LdaSmi8), U8(1), // | 7048 B(LdaSmi8), U8(1), // |
| 6530 B(Return), // | 7049 B(Return), // |
| 6531 B(LdaSmi8), U8(2), // | 7050 B(LdaSmi8), U8(2), // |
| 6532 B(Return), // | 7051 B(Return), // |
| 6533 }}, | 7052 }}, |
| 6534 }; | 7053 }; |
| 7054 // clang-format on |
| 6535 | 7055 |
| 6536 for (size_t i = 0; i < arraysize(snippets); i++) { | 7056 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6537 Handle<BytecodeArray> bytecode_array = | 7057 Handle<BytecodeArray> bytecode_array = |
| 6538 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7058 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6539 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7059 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6540 } | 7060 } |
| 6541 } | 7061 } |
| 6542 | 7062 |
| 6543 | 7063 |
| 6544 TEST(ThisFunction) { | 7064 TEST(ThisFunction) { |
| 6545 InitializedHandleScope handle_scope; | 7065 InitializedHandleScope handle_scope; |
| 6546 BytecodeGeneratorHelper helper; | 7066 BytecodeGeneratorHelper helper; |
| 6547 | 7067 |
| 6548 int closure = Register::function_closure().index(); | 7068 int closure = Register::function_closure().index(); |
| 6549 | 7069 |
| 7070 // clang-format off |
| 6550 ExpectedSnippet<int> snippets[] = { | 7071 ExpectedSnippet<int> snippets[] = { |
| 6551 {"var f;\n f = function f() { }", | 7072 {"var f;\n f = function f() { }", |
| 6552 1 * kPointerSize, | 7073 1 * kPointerSize, |
| 6553 1, | 7074 1, |
| 6554 9, | 7075 10, |
| 6555 { | 7076 { |
| 6556 B(LdaTheHole), // | 7077 B(LdaTheHole), // |
| 6557 B(Star), R(0), // | 7078 B(Star), R(0), // |
| 7079 B(StackCheck), // |
| 6558 B(Ldar), R(closure), // | 7080 B(Ldar), R(closure), // |
| 6559 B(Star), R(0), // | 7081 B(Star), R(0), // |
| 6560 B(LdaUndefined), // | 7082 B(LdaUndefined), // |
| 6561 B(Return), // | 7083 B(Return), // |
| 6562 }}, | 7084 }}, |
| 6563 {"var f;\n f = function f() { return f; }", | 7085 {"var f;\n f = function f() { return f; }", |
| 6564 1 * kPointerSize, | 7086 1 * kPointerSize, |
| 6565 1, | 7087 1, |
| 6566 8, | 7088 9, |
| 6567 { | 7089 { |
| 6568 B(LdaTheHole), // | 7090 B(LdaTheHole), // |
| 6569 B(Star), R(0), // | 7091 B(Star), R(0), // |
| 7092 B(StackCheck), // |
| 6570 B(Ldar), R(closure), // | 7093 B(Ldar), R(closure), // |
| 6571 B(Star), R(0), // | 7094 B(Star), R(0), // |
| 6572 B(Return), // | 7095 B(Return), // |
| 6573 }}, | 7096 }}, |
| 6574 }; | 7097 }; |
| 7098 // clang-format on |
| 6575 | 7099 |
| 6576 for (size_t i = 0; i < arraysize(snippets); i++) { | 7100 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6577 Handle<BytecodeArray> bytecode_array = | 7101 Handle<BytecodeArray> bytecode_array = |
| 6578 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 7102 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 6579 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7103 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6580 } | 7104 } |
| 6581 } | 7105 } |
| 6582 | 7106 |
| 6583 | 7107 |
| 6584 TEST(NewTarget) { | 7108 TEST(NewTarget) { |
| 6585 InitializedHandleScope handle_scope; | 7109 InitializedHandleScope handle_scope; |
| 6586 BytecodeGeneratorHelper helper; | 7110 BytecodeGeneratorHelper helper; |
| 6587 | 7111 |
| 6588 int new_target = Register::new_target().index(); | 7112 int new_target = Register::new_target().index(); |
| 6589 | 7113 |
| 7114 // clang-format off |
| 6590 ExpectedSnippet<int> snippets[] = { | 7115 ExpectedSnippet<int> snippets[] = { |
| 6591 {"return new.target;", | 7116 {"return new.target;", |
| 6592 1 * kPointerSize, | 7117 1 * kPointerSize, |
| 6593 1, | 7118 1, |
| 6594 5, | 7119 8, |
| 6595 { | 7120 { |
| 6596 B(Ldar), R(new_target), // | 7121 B(Ldar), R(new_target), // |
| 6597 B(Star), R(0), // | 7122 B(Star), R(0), // |
| 7123 B(StackCheck), // |
| 7124 B(Ldar), R(0), // |
| 6598 B(Return), // | 7125 B(Return), // |
| 6599 }}, | 7126 }}, |
| 6600 {"new.target;", | 7127 {"new.target;", |
| 6601 1 * kPointerSize, | 7128 1 * kPointerSize, |
| 6602 1, | 7129 1, |
| 6603 6, | 7130 9, |
| 6604 { | 7131 { |
| 6605 B(Ldar), R(new_target), // | 7132 B(Ldar), R(new_target), // |
| 6606 B(Star), R(0), // | 7133 B(Star), R(0), // |
| 7134 B(StackCheck), // |
| 7135 B(Ldar), R(0), // |
| 6607 B(LdaUndefined), // | 7136 B(LdaUndefined), // |
| 6608 B(Return), // | 7137 B(Return), // |
| 6609 }}, | 7138 }}, |
| 6610 }; | 7139 }; |
| 7140 // clang-format on |
| 6611 | 7141 |
| 6612 for (size_t i = 0; i < arraysize(snippets); i++) { | 7142 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6613 Handle<BytecodeArray> bytecode_array = | 7143 Handle<BytecodeArray> bytecode_array = |
| 6614 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7144 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6615 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7145 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6616 } | 7146 } |
| 6617 } | 7147 } |
| 6618 | 7148 |
| 6619 | 7149 |
| 6620 TEST(RemoveRedundantLdar) { | 7150 TEST(RemoveRedundantLdar) { |
| 6621 InitializedHandleScope handle_scope; | 7151 InitializedHandleScope handle_scope; |
| 6622 BytecodeGeneratorHelper helper; | 7152 BytecodeGeneratorHelper helper; |
| 6623 | 7153 |
| 7154 // clang-format off |
| 6624 ExpectedSnippet<int> snippets[] = { | 7155 ExpectedSnippet<int> snippets[] = { |
| 6625 {"var ld_a = 1;\n" // This test is to check Ldar does not | 7156 {"var ld_a = 1;\n" // This test is to check Ldar does not |
| 6626 "while(true) {\n" // get removed if the preceding Star is | 7157 "while(true) {\n" // get removed if the preceding Star is |
| 6627 " ld_a = ld_a + ld_a;\n" // in a different basicblock. | 7158 " ld_a = ld_a + ld_a;\n" // in a different basicblock. |
| 6628 " if (ld_a > 10) break;\n" | 7159 " if (ld_a > 10) break;\n" |
| 6629 "}\n" | 7160 "}\n" |
| 6630 "return ld_a;", | 7161 "return ld_a;", |
| 6631 2 * kPointerSize, | 7162 2 * kPointerSize, |
| 6632 1, | 7163 1, |
| 6633 29, | 7164 31, |
| 6634 {B(LdaSmi8), U8(1), // | 7165 {B(StackCheck), // |
| 7166 B(LdaSmi8), U8(1), // |
| 6635 B(Star), R(0), // | 7167 B(Star), R(0), // |
| 7168 B(StackCheck), // |
| 6636 B(Ldar), R(0), // This load should not be removed as it | 7169 B(Ldar), R(0), // This load should not be removed as it |
| 6637 B(Star), R(1), // is the target of the branch. | 7170 B(Star), R(1), // is the target of the branch. |
| 6638 B(Ldar), R(0), // | 7171 B(Ldar), R(0), // |
| 6639 B(Add), R(1), // | 7172 B(Add), R(1), // |
| 6640 B(Star), R(0), // | 7173 B(Star), R(0), // |
| 6641 B(Star), R(1), // | 7174 B(Star), R(1), // |
| 6642 B(LdaSmi8), U8(10), // | 7175 B(LdaSmi8), U8(10), // |
| 6643 B(TestGreaterThan), R(1), // | 7176 B(TestGreaterThan), R(1), // |
| 6644 B(JumpIfFalse), U8(4), // | 7177 B(JumpIfFalse), U8(4), // |
| 6645 B(Jump), U8(4), // | 7178 B(Jump), U8(4), // |
| 6646 B(Jump), U8(-20), // | 7179 B(Jump), U8(-21), // |
| 6647 B(Ldar), R(0), // | 7180 B(Ldar), R(0), // |
| 6648 B(Return)}}, | 7181 B(Return)}}, |
| 6649 {"var ld_a = 1;\n" | 7182 {"var ld_a = 1;\n" |
| 6650 "do {\n" | 7183 "do {\n" |
| 6651 " ld_a = ld_a + ld_a;\n" | 7184 " ld_a = ld_a + ld_a;\n" |
| 6652 " if (ld_a > 10) continue;\n" | 7185 " if (ld_a > 10) continue;\n" |
| 6653 "} while(false);\n" | 7186 "} while(false);\n" |
| 6654 "return ld_a;", | 7187 "return ld_a;", |
| 6655 2 * kPointerSize, | 7188 2 * kPointerSize, |
| 6656 1, | 7189 1, |
| 6657 27, | 7190 29, |
| 6658 {B(LdaSmi8), U8(1), // | 7191 {B(StackCheck), // |
| 7192 B(LdaSmi8), U8(1), // |
| 6659 B(Star), R(0), // | 7193 B(Star), R(0), // |
| 7194 B(StackCheck), // |
| 6660 B(Ldar), R(0), // | 7195 B(Ldar), R(0), // |
| 6661 B(Star), R(1), // | 7196 B(Star), R(1), // |
| 6662 B(Ldar), R(0), // | 7197 B(Ldar), R(0), // |
| 6663 B(Add), R(1), // | 7198 B(Add), R(1), // |
| 6664 B(Star), R(0), // | 7199 B(Star), R(0), // |
| 6665 B(Star), R(1), // | 7200 B(Star), R(1), // |
| 6666 B(LdaSmi8), U8(10), // | 7201 B(LdaSmi8), U8(10), // |
| 6667 B(TestGreaterThan), R(1), // | 7202 B(TestGreaterThan), R(1), // |
| 6668 B(JumpIfFalse), U8(4), // | 7203 B(JumpIfFalse), U8(4), // |
| 6669 B(Jump), U8(2), // | 7204 B(Jump), U8(2), // |
| 6670 B(Ldar), R(0), // | 7205 B(Ldar), R(0), // |
| 6671 B(Return)}}, | 7206 B(Return)}}, |
| 6672 {"var ld_a = 1;\n" | 7207 {"var ld_a = 1;\n" |
| 6673 " ld_a = ld_a + ld_a;\n" | 7208 " ld_a = ld_a + ld_a;\n" |
| 6674 " return ld_a;", | 7209 " return ld_a;", |
| 6675 2 * kPointerSize, | 7210 2 * kPointerSize, |
| 6676 1, | 7211 1, |
| 6677 13, | 7212 14, |
| 6678 { | 7213 { |
| 7214 B(StackCheck), // |
| 6679 B(LdaSmi8), U8(1), // | 7215 B(LdaSmi8), U8(1), // |
| 6680 B(Star), R(0), // | 7216 B(Star), R(0), // |
| 6681 B(Star), R(1), // | 7217 B(Star), R(1), // |
| 6682 B(Ldar), R(0), // | 7218 B(Ldar), R(0), // |
| 6683 B(Add), R(1), // | 7219 B(Add), R(1), // |
| 6684 B(Star), R(0), // | 7220 B(Star), R(0), // |
| 6685 B(Return) // | 7221 B(Return) // |
| 6686 }}, | 7222 }}, |
| 6687 }; | 7223 }; |
| 7224 // clang-format on |
| 6688 | 7225 |
| 6689 for (size_t i = 0; i < arraysize(snippets); i++) { | 7226 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6690 Handle<BytecodeArray> bytecode_array = | 7227 Handle<BytecodeArray> bytecode_array = |
| 6691 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7228 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6692 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7229 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6693 } | 7230 } |
| 6694 } | 7231 } |
| 6695 | 7232 |
| 6696 | 7233 |
| 6697 TEST(AssignmentsInBinaryExpression) { | 7234 TEST(AssignmentsInBinaryExpression) { |
| 6698 InitializedHandleScope handle_scope; | 7235 InitializedHandleScope handle_scope; |
| 6699 BytecodeGeneratorHelper helper; | 7236 BytecodeGeneratorHelper helper; |
| 6700 | 7237 |
| 7238 // clang-format off |
| 6701 ExpectedSnippet<const char*> snippets[] = { | 7239 ExpectedSnippet<const char*> snippets[] = { |
| 6702 {"var x = 0, y = 1;\n" | 7240 {"var x = 0, y = 1;\n" |
| 6703 "return (x = 2, y = 3, x = 4, y = 5)", | 7241 "return (x = 2, y = 3, x = 4, y = 5)", |
| 6704 2 * kPointerSize, | 7242 2 * kPointerSize, |
| 6705 1, | 7243 1, |
| 6706 24, | 7244 25, |
| 6707 { | 7245 { |
| 7246 B(StackCheck), // |
| 6708 B(LdaZero), B(Star), R(0), // | 7247 B(LdaZero), B(Star), R(0), // |
| 6709 B(LdaSmi8), U8(1), // | 7248 B(LdaSmi8), U8(1), // |
| 6710 B(Star), R(1), // | 7249 B(Star), R(1), // |
| 6711 B(LdaSmi8), U8(2), // | 7250 B(LdaSmi8), U8(2), // |
| 6712 B(Star), R(0), // | 7251 B(Star), R(0), // |
| 6713 B(LdaSmi8), U8(3), // | 7252 B(LdaSmi8), U8(3), // |
| 6714 B(Star), R(1), // | 7253 B(Star), R(1), // |
| 6715 B(LdaSmi8), U8(4), // | 7254 B(LdaSmi8), U8(4), // |
| 6716 B(Star), R(0), // | 7255 B(Star), R(0), // |
| 6717 B(LdaSmi8), U8(5), // | 7256 B(LdaSmi8), U8(5), // |
| 6718 B(Star), R(1), // | 7257 B(Star), R(1), // |
| 6719 B(Return), // | 7258 B(Return), // |
| 6720 }, | 7259 }, |
| 6721 0}, | 7260 0}, |
| 6722 {"var x = 55;\n" | 7261 {"var x = 55;\n" |
| 6723 "var y = (x = 100);\n" | 7262 "var y = (x = 100);\n" |
| 6724 "return y", | 7263 "return y", |
| 6725 2 * kPointerSize, | 7264 2 * kPointerSize, |
| 6726 1, | 7265 1, |
| 6727 11, | 7266 12, |
| 6728 { | 7267 { |
| 7268 B(StackCheck), // |
| 6729 B(LdaSmi8), U8(55), // | 7269 B(LdaSmi8), U8(55), // |
| 6730 B(Star), R(0), // | 7270 B(Star), R(0), // |
| 6731 B(LdaSmi8), U8(100), // | 7271 B(LdaSmi8), U8(100), // |
| 6732 B(Star), R(0), // | 7272 B(Star), R(0), // |
| 6733 B(Star), R(1), // | 7273 B(Star), R(1), // |
| 6734 B(Return), // | 7274 B(Return), // |
| 6735 }, | 7275 }, |
| 6736 0}, | 7276 0}, |
| 6737 {"var x = 55;\n" | 7277 {"var x = 55;\n" |
| 6738 "x = x + (x = 100) + (x = 101);\n" | 7278 "x = x + (x = 100) + (x = 101);\n" |
| 6739 "return x;", | 7279 "return x;", |
| 6740 3 * kPointerSize, | 7280 3 * kPointerSize, |
| 6741 1, | 7281 1, |
| 6742 23, | 7282 24, |
| 6743 { | 7283 { |
| 7284 B(StackCheck), // |
| 6744 B(LdaSmi8), U8(55), // | 7285 B(LdaSmi8), U8(55), // |
| 6745 B(Star), R(0), // | 7286 B(Star), R(0), // |
| 6746 B(Star), R(1), // | 7287 B(Star), R(1), // |
| 6747 B(LdaSmi8), U8(100), // | 7288 B(LdaSmi8), U8(100), // |
| 6748 B(Star), R(0), // | 7289 B(Star), R(0), // |
| 6749 B(Add), R(1), // | 7290 B(Add), R(1), // |
| 6750 B(Star), R(2), // | 7291 B(Star), R(2), // |
| 6751 B(LdaSmi8), U8(101), // | 7292 B(LdaSmi8), U8(101), // |
| 6752 B(Star), R(0), // | 7293 B(Star), R(0), // |
| 6753 B(Add), R(2), // | 7294 B(Add), R(2), // |
| 6754 B(Star), R(0), // | 7295 B(Star), R(0), // |
| 6755 B(Return), // | 7296 B(Return), // |
| 6756 }, | 7297 }, |
| 6757 0}, | 7298 0}, |
| 6758 {"var x = 55;\n" | 7299 {"var x = 55;\n" |
| 6759 "x = (x = 56) - x + (x = 57);\n" | 7300 "x = (x = 56) - x + (x = 57);\n" |
| 6760 "x++;\n" | 7301 "x++;\n" |
| 6761 "return x;", | 7302 "return x;", |
| 6762 3 * kPointerSize, | 7303 3 * kPointerSize, |
| 6763 1, | 7304 1, |
| 6764 31, | 7305 32, |
| 6765 { | 7306 { |
| 7307 B(StackCheck), // |
| 6766 B(LdaSmi8), U8(55), // | 7308 B(LdaSmi8), U8(55), // |
| 6767 B(Star), R(0), // | 7309 B(Star), R(0), // |
| 6768 B(LdaSmi8), U8(56), // | 7310 B(LdaSmi8), U8(56), // |
| 6769 B(Star), R(0), // | 7311 B(Star), R(0), // |
| 6770 B(Star), R(1), // | 7312 B(Star), R(1), // |
| 6771 B(Ldar), R(0), // | 7313 B(Ldar), R(0), // |
| 6772 B(Sub), R(1), // | 7314 B(Sub), R(1), // |
| 6773 B(Star), R(2), // | 7315 B(Star), R(2), // |
| 6774 B(LdaSmi8), U8(57), // | 7316 B(LdaSmi8), U8(57), // |
| 6775 B(Star), R(0), // | 7317 B(Star), R(0), // |
| 6776 B(Add), R(2), // | 7318 B(Add), R(2), // |
| 6777 B(Star), R(0), // | 7319 B(Star), R(0), // |
| 6778 B(ToNumber), // | 7320 B(ToNumber), // |
| 6779 B(Star), R(1), // | 7321 B(Star), R(1), // |
| 6780 B(Inc), // | 7322 B(Inc), // |
| 6781 B(Star), R(0), // | 7323 B(Star), R(0), // |
| 6782 B(Return), // | 7324 B(Return), // |
| 6783 }, | 7325 }, |
| 6784 0}, | 7326 0}, |
| 6785 {"var x = 55;\n" | 7327 {"var x = 55;\n" |
| 6786 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" | 7328 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" |
| 6787 "return y;", | 7329 "return y;", |
| 6788 4 * kPointerSize, | 7330 4 * kPointerSize, |
| 6789 1, | 7331 1, |
| 6790 31, | 7332 32, |
| 6791 { | 7333 { |
| 7334 B(StackCheck), // |
| 6792 B(LdaSmi8), U8(55), // | 7335 B(LdaSmi8), U8(55), // |
| 6793 B(Star), R(0), // | 7336 B(Star), R(0), // |
| 6794 B(Star), R(2), // | 7337 B(Star), R(2), // |
| 6795 B(LdaSmi8), U8(1), // | 7338 B(LdaSmi8), U8(1), // |
| 6796 B(Star), R(0), // | 7339 B(Star), R(0), // |
| 6797 B(Add), R(2), // | 7340 B(Add), R(2), // |
| 6798 B(Star), R(3), // | 7341 B(Star), R(3), // |
| 6799 B(LdaSmi8), U8(2), // | 7342 B(LdaSmi8), U8(2), // |
| 6800 B(Star), R(0), // | 7343 B(Star), R(0), // |
| 6801 B(Add), R(3), // | 7344 B(Add), R(3), // |
| 6802 B(Star), R(2), // | 7345 B(Star), R(2), // |
| 6803 B(LdaSmi8), U8(3), // | 7346 B(LdaSmi8), U8(3), // |
| 6804 B(Star), R(0), // | 7347 B(Star), R(0), // |
| 6805 B(Add), R(2), // | 7348 B(Add), R(2), // |
| 6806 B(Star), R(1), // | 7349 B(Star), R(1), // |
| 6807 B(Return), // | 7350 B(Return), // |
| 6808 }, | 7351 }, |
| 6809 0}, | 7352 0}, |
| 6810 {"var x = 55;\n" | 7353 {"var x = 55;\n" |
| 6811 "var x = x + (x = 1) + (x = 2) + (x = 3);\n" | 7354 "var x = x + (x = 1) + (x = 2) + (x = 3);\n" |
| 6812 "return x;", | 7355 "return x;", |
| 6813 3 * kPointerSize, | 7356 3 * kPointerSize, |
| 6814 1, | 7357 1, |
| 6815 31, | 7358 32, |
| 6816 { | 7359 { |
| 7360 B(StackCheck), // |
| 6817 B(LdaSmi8), U8(55), // | 7361 B(LdaSmi8), U8(55), // |
| 6818 B(Star), R(0), // | 7362 B(Star), R(0), // |
| 6819 B(Star), R(1), // | 7363 B(Star), R(1), // |
| 6820 B(LdaSmi8), U8(1), // | 7364 B(LdaSmi8), U8(1), // |
| 6821 B(Star), R(0), // | 7365 B(Star), R(0), // |
| 6822 B(Add), R(1), // | 7366 B(Add), R(1), // |
| 6823 B(Star), R(2), // | 7367 B(Star), R(2), // |
| 6824 B(LdaSmi8), U8(2), // | 7368 B(LdaSmi8), U8(2), // |
| 6825 B(Star), R(0), // | 7369 B(Star), R(0), // |
| 6826 B(Add), R(2), // | 7370 B(Add), R(2), // |
| 6827 B(Star), R(1), // | 7371 B(Star), R(1), // |
| 6828 B(LdaSmi8), U8(3), // | 7372 B(LdaSmi8), U8(3), // |
| 6829 B(Star), R(0), // | 7373 B(Star), R(0), // |
| 6830 B(Add), R(1), // | 7374 B(Add), R(1), // |
| 6831 B(Star), R(0), // | 7375 B(Star), R(0), // |
| 6832 B(Return), // | 7376 B(Return), // |
| 6833 }, | 7377 }, |
| 6834 0}, | 7378 0}, |
| 6835 {"var x = 10, y = 20;\n" | 7379 {"var x = 10, y = 20;\n" |
| 6836 "return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + " | 7380 "return x + (x = 1) + (x + 1) * (y = 2) + (y = 3) + (x = 4) + (y = 5) + " |
| 6837 "y;\n", | 7381 "y;\n", |
| 6838 5 * kPointerSize, | 7382 5 * kPointerSize, |
| 6839 1, | 7383 1, |
| 6840 69, | 7384 70, |
| 6841 { | 7385 { |
| 7386 B(StackCheck), // |
| 6842 B(LdaSmi8), U8(10), // | 7387 B(LdaSmi8), U8(10), // |
| 6843 B(Star), R(0), // | 7388 B(Star), R(0), // |
| 6844 B(LdaSmi8), U8(20), // | 7389 B(LdaSmi8), U8(20), // |
| 6845 B(Star), R(1), // | 7390 B(Star), R(1), // |
| 6846 B(Ldar), R(0), // | 7391 B(Ldar), R(0), // |
| 6847 B(Star), R(2), // | 7392 B(Star), R(2), // |
| 6848 B(LdaSmi8), U8(1), // | 7393 B(LdaSmi8), U8(1), // |
| 6849 B(Star), R(0), // | 7394 B(Star), R(0), // |
| 6850 B(Add), R(2), // | 7395 B(Add), R(2), // |
| 6851 B(Star), R(3), // | 7396 B(Star), R(3), // |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6873 B(Star), R(3), // | 7418 B(Star), R(3), // |
| 6874 B(Ldar), R(1), // | 7419 B(Ldar), R(1), // |
| 6875 B(Add), R(3), // | 7420 B(Add), R(3), // |
| 6876 B(Return), // | 7421 B(Return), // |
| 6877 }, | 7422 }, |
| 6878 0}, | 7423 0}, |
| 6879 {"var x = 17;\n" | 7424 {"var x = 17;\n" |
| 6880 "return 1 + x + (x++) + (++x);\n", | 7425 "return 1 + x + (x++) + (++x);\n", |
| 6881 4 * kPointerSize, | 7426 4 * kPointerSize, |
| 6882 1, | 7427 1, |
| 6883 37, | 7428 38, |
| 6884 { | 7429 { |
| 7430 B(StackCheck), // |
| 6885 B(LdaSmi8), U8(17), // | 7431 B(LdaSmi8), U8(17), // |
| 6886 B(Star), R(0), // | 7432 B(Star), R(0), // |
| 6887 B(LdaSmi8), U8(1), // | 7433 B(LdaSmi8), U8(1), // |
| 6888 B(Star), R(1), // | 7434 B(Star), R(1), // |
| 6889 B(Ldar), R(0), // | 7435 B(Ldar), R(0), // |
| 6890 B(Add), R(1), // | 7436 B(Add), R(1), // |
| 6891 B(Star), R(2), // | 7437 B(Star), R(2), // |
| 6892 B(Ldar), R(0), // | 7438 B(Ldar), R(0), // |
| 6893 B(ToNumber), // | 7439 B(ToNumber), // |
| 6894 B(Star), R(1), // | 7440 B(Star), R(1), // |
| 6895 B(Inc), // | 7441 B(Inc), // |
| 6896 B(Star), R(0), // | 7442 B(Star), R(0), // |
| 6897 B(Ldar), R(1), // | 7443 B(Ldar), R(1), // |
| 6898 B(Add), R(2), // | 7444 B(Add), R(2), // |
| 6899 B(Star), R(3), // | 7445 B(Star), R(3), // |
| 6900 B(Ldar), R(0), // | 7446 B(Ldar), R(0), // |
| 6901 B(ToNumber), // | 7447 B(ToNumber), // |
| 6902 B(Inc), // | 7448 B(Inc), // |
| 6903 B(Star), R(0), // | 7449 B(Star), R(0), // |
| 6904 B(Add), R(3), // | 7450 B(Add), R(3), // |
| 6905 B(Return), // | 7451 B(Return), // |
| 6906 }, | 7452 }, |
| 6907 0}}; | 7453 0} |
| 7454 }; |
| 7455 // clang-format on |
| 6908 | 7456 |
| 6909 for (size_t i = 0; i < arraysize(snippets); i++) { | 7457 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6910 Handle<BytecodeArray> bytecode_array = | 7458 Handle<BytecodeArray> bytecode_array = |
| 6911 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7459 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6912 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7460 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6913 } | 7461 } |
| 6914 } | 7462 } |
| 6915 | 7463 |
| 6916 | 7464 |
| 6917 TEST(Eval) { | 7465 TEST(Eval) { |
| 6918 InitializedHandleScope handle_scope; | 7466 InitializedHandleScope handle_scope; |
| 6919 BytecodeGeneratorHelper helper; | 7467 BytecodeGeneratorHelper helper; |
| 6920 Zone zone; | 7468 Zone zone; |
| 6921 | 7469 |
| 6922 int closure = Register::function_closure().index(); | 7470 int closure = Register::function_closure().index(); |
| 6923 int context = Register::current_context().index(); | 7471 int context = Register::current_context().index(); |
| 6924 int new_target = Register::new_target().index(); | 7472 int new_target = Register::new_target().index(); |
| 6925 | 7473 |
| 6926 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 7474 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 6927 | 7475 |
| 7476 // clang-format off |
| 6928 ExpectedSnippet<const char*> snippets[] = { | 7477 ExpectedSnippet<const char*> snippets[] = { |
| 6929 {"return eval('1;');", | 7478 {"return eval('1;');", |
| 6930 9 * kPointerSize, | 7479 9 * kPointerSize, |
| 6931 1, | 7480 1, |
| 6932 67, | 7481 68, |
| 6933 { | 7482 { |
| 6934 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 7483 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 6935 U8(1), // | 7484 /* */ U8(1), // |
| 6936 B(PushContext), R(0), // | 7485 B(PushContext), R(0), // |
| 6937 B(Ldar), THIS(1), // | 7486 B(Ldar), THIS(1), // |
| 6938 B(StaContextSlot), R(context), U8(first_context_slot), // | 7487 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 6939 B(CreateMappedArguments), // | 7488 B(CreateMappedArguments), // |
| 6940 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 7489 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 6941 B(Ldar), R(new_target), // | 7490 B(Ldar), R(new_target), // |
| 6942 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 7491 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 7492 B(StackCheck), // |
| 6943 B(Mov), R(context), R(3), // | 7493 B(Mov), R(context), R(3), // |
| 6944 B(LdaConstant), U8(0), // | 7494 B(LdaConstant), U8(0), // |
| 6945 B(Star), R(4), // | 7495 B(Star), R(4), // |
| 6946 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 7496 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 6947 R(3), U8(2), R(1), // | 7497 /* */ R(3), U8(2), R(1), // |
| 6948 B(LdaConstant), U8(1), // | 7498 B(LdaConstant), U8(1), // |
| 6949 B(Star), R(3), // | 7499 B(Star), R(3), // |
| 6950 B(Mov), R(1), R(4), // | 7500 B(Mov), R(1), R(4), // |
| 6951 B(Mov), R(3), R(5), // | 7501 B(Mov), R(3), R(5), // |
| 6952 B(Mov), R(closure), R(6), // | 7502 B(Mov), R(closure), R(6), // |
| 6953 B(LdaZero), // | 7503 B(LdaZero), // |
| 6954 B(Star), R(7), // | 7504 B(Star), R(7), // |
| 6955 B(LdaSmi8), U8(10), // | 7505 B(LdaSmi8), U8(10), // |
| 6956 B(Star), R(8), // | 7506 B(Star), R(8), // |
| 6957 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 7507 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
| 6958 U8(5), // | 7508 /* */ U8(5), // |
| 6959 B(Star), R(1), // | 7509 B(Star), R(1), // |
| 6960 B(Call), R(1), R(2), U8(2), U8(0), // | 7510 B(Call), R(1), R(2), U8(2), U8(0), // |
| 6961 B(Return), // | 7511 B(Return), // |
| 6962 }, | 7512 }, |
| 6963 2, | 7513 2, |
| 6964 {"eval", "1;"}}, | 7514 {"eval", "1;"}}, |
| 6965 }; | 7515 }; |
| 7516 // clang-format on |
| 6966 | 7517 |
| 6967 for (size_t i = 0; i < arraysize(snippets); i++) { | 7518 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6968 Handle<BytecodeArray> bytecode_array = | 7519 Handle<BytecodeArray> bytecode_array = |
| 6969 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7520 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6970 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7521 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6971 } | 7522 } |
| 6972 } | 7523 } |
| 6973 | 7524 |
| 6974 | 7525 |
| 6975 TEST(LookupSlot) { | 7526 TEST(LookupSlot) { |
| 6976 InitializedHandleScope handle_scope; | 7527 InitializedHandleScope handle_scope; |
| 6977 BytecodeGeneratorHelper helper; | 7528 BytecodeGeneratorHelper helper; |
| 6978 | 7529 |
| 6979 int closure = Register::function_closure().index(); | 7530 int closure = Register::function_closure().index(); |
| 6980 int context = Register::current_context().index(); | 7531 int context = Register::current_context().index(); |
| 6981 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 7532 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 6982 int new_target = Register::new_target().index(); | 7533 int new_target = Register::new_target().index(); |
| 6983 | 7534 |
| 7535 // clang-format off |
| 6984 ExpectedSnippet<const char*> snippets[] = { | 7536 ExpectedSnippet<const char*> snippets[] = { |
| 6985 {"eval('var x = 10;'); return x;", | 7537 {"eval('var x = 10;'); return x;", |
| 6986 9 * kPointerSize, | 7538 9 * kPointerSize, |
| 6987 1, | 7539 1, |
| 6988 69, | 7540 70, |
| 6989 { | 7541 { |
| 6990 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 7542 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 6991 U8(1), // | 7543 /* */ U8(1), // |
| 6992 B(PushContext), R(0), // | 7544 B(PushContext), R(0), // |
| 6993 B(Ldar), THIS(1), // | 7545 B(Ldar), THIS(1), // |
| 6994 B(StaContextSlot), R(context), U8(first_context_slot), // | 7546 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 6995 B(CreateMappedArguments), // | 7547 B(CreateMappedArguments), // |
| 6996 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 7548 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 6997 B(Ldar), R(new_target), // | 7549 B(Ldar), R(new_target), // |
| 6998 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 7550 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 7551 B(StackCheck), // |
| 6999 B(Mov), R(context), R(3), // | 7552 B(Mov), R(context), R(3), // |
| 7000 B(LdaConstant), U8(0), // | 7553 B(LdaConstant), U8(0), // |
| 7001 B(Star), R(4), // | 7554 B(Star), R(4), // |
| 7002 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 7555 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 7003 R(3), U8(2), R(1), // | 7556 R(3), U8(2), R(1), // |
| 7004 B(LdaConstant), U8(1), // | 7557 B(LdaConstant), U8(1), // |
| 7005 B(Star), R(3), // | 7558 B(Star), R(3), // |
| 7006 B(Mov), R(1), R(4), // | 7559 B(Mov), R(1), R(4), // |
| 7007 B(Mov), R(3), R(5), // | 7560 B(Mov), R(3), R(5), // |
| 7008 B(Mov), R(closure), R(6), // | 7561 B(Mov), R(closure), R(6), // |
| 7009 B(LdaZero), // | 7562 B(LdaZero), // |
| 7010 B(Star), R(7), // | 7563 B(Star), R(7), // |
| 7011 B(LdaSmi8), U8(10), // | 7564 B(LdaSmi8), U8(10), // |
| 7012 B(Star), R(8), // | 7565 B(Star), R(8), // |
| 7013 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 7566 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
| 7014 U8(5), // | 7567 U8(5), // |
| 7015 B(Star), R(1), // | 7568 B(Star), R(1), // |
| 7016 B(Call), R(1), R(2), U8(2), U8(0), // | 7569 B(Call), R(1), R(2), U8(2), U8(0), // |
| 7017 B(LdaLookupSlot), U8(2), // | 7570 B(LdaLookupSlot), U8(2), // |
| 7018 B(Return), // | 7571 B(Return), // |
| 7019 }, | 7572 }, |
| 7020 3, | 7573 3, |
| 7021 {"eval", "var x = 10;", "x"}}, | 7574 {"eval", "var x = 10;", "x"}}, |
| 7022 {"eval('var x = 10;'); return typeof x;", | 7575 {"eval('var x = 10;'); return typeof x;", |
| 7023 9 * kPointerSize, | 7576 9 * kPointerSize, |
| 7024 1, | 7577 1, |
| 7025 70, | 7578 71, |
| 7026 { | 7579 { |
| 7027 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 7580 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7028 U8(1), // | 7581 /* */ U8(1), // |
| 7029 B(PushContext), R(0), // | 7582 B(PushContext), R(0), // |
| 7030 B(Ldar), THIS(1), // | 7583 B(Ldar), THIS(1), // |
| 7031 B(StaContextSlot), R(context), U8(first_context_slot), // | 7584 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 7032 B(CreateMappedArguments), // | 7585 B(CreateMappedArguments), // |
| 7033 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 7586 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 7034 B(Ldar), R(new_target), // | 7587 B(Ldar), R(new_target), // |
| 7035 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 7588 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 7589 B(StackCheck), // |
| 7036 B(Mov), R(context), R(3), // | 7590 B(Mov), R(context), R(3), // |
| 7037 B(LdaConstant), U8(0), // | 7591 B(LdaConstant), U8(0), // |
| 7038 B(Star), R(4), // | 7592 B(Star), R(4), // |
| 7039 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 7593 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 7040 R(3), U8(2), R(1), // | 7594 /* */ R(3), U8(2), R(1), // |
| 7041 B(LdaConstant), U8(1), // | 7595 B(LdaConstant), U8(1), // |
| 7042 B(Star), R(3), // | 7596 B(Star), R(3), // |
| 7043 B(Mov), R(1), R(4), // | 7597 B(Mov), R(1), R(4), // |
| 7044 B(Mov), R(3), R(5), // | 7598 B(Mov), R(3), R(5), // |
| 7045 B(Mov), R(closure), R(6), // | 7599 B(Mov), R(closure), R(6), // |
| 7046 B(LdaZero), // | 7600 B(LdaZero), // |
| 7047 B(Star), R(7), // | 7601 B(Star), R(7), // |
| 7048 B(LdaSmi8), U8(10), // | 7602 B(LdaSmi8), U8(10), // |
| 7049 B(Star), R(8), // | 7603 B(Star), R(8), // |
| 7050 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 7604 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
| 7051 U8(5), // | 7605 /* */ U8(5), // |
| 7052 B(Star), R(1), // | 7606 B(Star), R(1), // |
| 7053 B(Call), R(1), R(2), U8(2), U8(0), // | 7607 B(Call), R(1), R(2), U8(2), U8(0), // |
| 7054 B(LdaLookupSlotInsideTypeof), U8(2), // | 7608 B(LdaLookupSlotInsideTypeof), U8(2), // |
| 7055 B(TypeOf), // | 7609 B(TypeOf), // |
| 7056 B(Return), // | 7610 B(Return), // |
| 7057 }, | 7611 }, |
| 7058 3, | 7612 3, |
| 7059 {"eval", "var x = 10;", "x"}}, | 7613 {"eval", "var x = 10;", "x"}}, |
| 7060 {"x = 20; return eval('');", | 7614 {"x = 20; return eval('');", |
| 7061 9 * kPointerSize, | 7615 9 * kPointerSize, |
| 7062 1, | 7616 1, |
| 7063 71, | 7617 72, |
| 7064 { | 7618 { |
| 7065 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 7619 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7066 U8(1), // | 7620 U8(1), // |
| 7067 B(PushContext), R(0), // | 7621 B(PushContext), R(0), // |
| 7068 B(Ldar), THIS(1), // | 7622 B(Ldar), THIS(1), // |
| 7069 B(StaContextSlot), R(context), U8(first_context_slot), // | 7623 B(StaContextSlot), R(context), U8(first_context_slot), // |
| 7070 B(CreateMappedArguments), // | 7624 B(CreateMappedArguments), // |
| 7071 B(StaContextSlot), R(context), U8(first_context_slot + 1), // | 7625 B(StaContextSlot), R(context), U8(first_context_slot + 1), // |
| 7072 B(Ldar), R(new_target), // | 7626 B(Ldar), R(new_target), // |
| 7073 B(StaContextSlot), R(context), U8(first_context_slot + 2), // | 7627 B(StaContextSlot), R(context), U8(first_context_slot + 2), // |
| 7628 B(StackCheck), // |
| 7074 B(LdaSmi8), U8(20), // | 7629 B(LdaSmi8), U8(20), // |
| 7075 B(StaLookupSlotSloppy), U8(0), // | 7630 B(StaLookupSlotSloppy), U8(0), // |
| 7076 B(Mov), R(context), R(3), // | 7631 B(Mov), R(context), R(3), // |
| 7077 B(LdaConstant), U8(1), // | 7632 B(LdaConstant), U8(1), // |
| 7078 B(Star), R(4), // | 7633 B(Star), R(4), // |
| 7079 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 7634 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 7080 R(3), U8(2), R(1), // | 7635 /* */ R(3), U8(2), R(1), // |
| 7081 B(LdaConstant), U8(2), // | 7636 B(LdaConstant), U8(2), // |
| 7082 B(Star), R(3), // | 7637 B(Star), R(3), // |
| 7083 B(Mov), R(1), R(4), // | 7638 B(Mov), R(1), R(4), // |
| 7084 B(Mov), R(3), R(5), // | 7639 B(Mov), R(3), R(5), // |
| 7085 B(Mov), R(closure), R(6), // | 7640 B(Mov), R(closure), R(6), // |
| 7086 B(LdaZero), // | 7641 B(LdaZero), // |
| 7087 B(Star), R(7), // | 7642 B(Star), R(7), // |
| 7088 B(LdaSmi8), U8(10), // | 7643 B(LdaSmi8), U8(10), // |
| 7089 B(Star), R(8), // | 7644 B(Star), R(8), // |
| 7090 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 7645 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
| 7091 U8(5), // | 7646 /* */ U8(5), // |
| 7092 B(Star), R(1), // | 7647 B(Star), R(1), // |
| 7093 B(Call), R(1), R(2), U8(2), U8(0), // | 7648 B(Call), R(1), R(2), U8(2), U8(0), // |
| 7094 B(Return), // | 7649 B(Return), // |
| 7095 }, | 7650 }, |
| 7096 3, | 7651 3, |
| 7097 {"x", "eval", ""}}, | 7652 {"x", "eval", ""}}, |
| 7098 }; | 7653 }; |
| 7654 // clang-format on |
| 7099 | 7655 |
| 7100 for (size_t i = 0; i < arraysize(snippets); i++) { | 7656 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7101 Handle<BytecodeArray> bytecode_array = | 7657 Handle<BytecodeArray> bytecode_array = |
| 7102 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7658 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7103 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7659 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7104 } | 7660 } |
| 7105 } | 7661 } |
| 7106 | 7662 |
| 7107 | 7663 |
| 7108 TEST(CallLookupSlot) { | 7664 TEST(CallLookupSlot) { |
| 7109 InitializedHandleScope handle_scope; | 7665 InitializedHandleScope handle_scope; |
| 7110 BytecodeGeneratorHelper helper; | 7666 BytecodeGeneratorHelper helper; |
| 7111 Zone zone; | 7667 Zone zone; |
| 7112 | 7668 |
| 7113 FeedbackVectorSpec feedback_spec(&zone); | 7669 FeedbackVectorSpec feedback_spec(&zone); |
| 7114 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 7670 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 7115 FeedbackVectorSlot slot2 = feedback_spec.AddCallICSlot(); | 7671 FeedbackVectorSlot slot2 = feedback_spec.AddCallICSlot(); |
| 7116 USE(slot1); | 7672 USE(slot1); |
| 7117 | 7673 |
| 7118 Handle<i::TypeFeedbackVector> vector = | 7674 Handle<i::TypeFeedbackVector> vector = |
| 7119 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 7675 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 7120 | 7676 |
| 7121 int closure = Register::function_closure().index(); | 7677 int closure = Register::function_closure().index(); |
| 7122 int context = Register::current_context().index(); | 7678 int context = Register::current_context().index(); |
| 7123 int new_target = Register::new_target().index(); | 7679 int new_target = Register::new_target().index(); |
| 7124 | 7680 |
| 7681 // clang-format off |
| 7125 ExpectedSnippet<InstanceType> snippets[] = { | 7682 ExpectedSnippet<InstanceType> snippets[] = { |
| 7126 {"g = function(){}; eval(''); return g();", | 7683 {"g = function(){}; eval(''); return g();", |
| 7127 9 * kPointerSize, | 7684 9 * kPointerSize, |
| 7128 1, | 7685 1, |
| 7129 90, | 7686 91, |
| 7130 { | 7687 { |
| 7131 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 7688 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7132 U8(1), // | 7689 /* */ U8(1), // |
| 7133 B(PushContext), R(0), // | 7690 B(PushContext), R(0), // |
| 7134 B(Ldar), THIS(1), // | 7691 B(Ldar), THIS(1), // |
| 7135 B(StaContextSlot), R(context), U8(4), // | 7692 B(StaContextSlot), R(context), U8(4), // |
| 7136 B(CreateMappedArguments), // | 7693 B(CreateMappedArguments), // |
| 7137 B(StaContextSlot), R(context), U8(5), // | 7694 B(StaContextSlot), R(context), U8(5), // |
| 7138 B(Ldar), R(new_target), // | 7695 B(Ldar), R(new_target), // |
| 7139 B(StaContextSlot), R(context), U8(6), // | 7696 B(StaContextSlot), R(context), U8(6), // |
| 7697 B(StackCheck), // |
| 7140 B(CreateClosure), U8(0), U8(0), // | 7698 B(CreateClosure), U8(0), U8(0), // |
| 7141 B(StaLookupSlotSloppy), U8(1), // | 7699 B(StaLookupSlotSloppy), U8(1), // |
| 7142 B(Mov), R(context), R(3), // | 7700 B(Mov), R(context), R(3), // |
| 7143 B(LdaConstant), U8(2), // | 7701 B(LdaConstant), U8(2), // |
| 7144 B(Star), R(4), // | 7702 B(Star), R(4), // |
| 7145 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 7703 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 7146 R(3), U8(2), R(1), // | 7704 R(3), U8(2), R(1), // |
| 7147 B(LdaConstant), U8(3), // | 7705 B(LdaConstant), U8(3), // |
| 7148 B(Star), R(3), // | 7706 B(Star), R(3), // |
| 7149 B(Mov), R(1), R(4), // | 7707 B(Mov), R(1), R(4), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7164 R(3), U8(2), R(1), // | 7722 R(3), U8(2), R(1), // |
| 7165 B(Call), R(1), R(2), U8(1), U8(vector->GetIndex(slot2)), // | 7723 B(Call), R(1), R(2), U8(1), U8(vector->GetIndex(slot2)), // |
| 7166 B(Return), // | 7724 B(Return), // |
| 7167 }, | 7725 }, |
| 7168 4, | 7726 4, |
| 7169 {InstanceType::SHARED_FUNCTION_INFO_TYPE, | 7727 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7170 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 7728 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 7171 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 7729 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 7172 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 7730 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7173 }; | 7731 }; |
| 7732 // clang-format on |
| 7174 | 7733 |
| 7175 for (size_t i = 0; i < arraysize(snippets); i++) { | 7734 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7176 Handle<BytecodeArray> bytecode_array = | 7735 Handle<BytecodeArray> bytecode_array = |
| 7177 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7736 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7178 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7737 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7179 } | 7738 } |
| 7180 } | 7739 } |
| 7181 | 7740 |
| 7182 | 7741 |
| 7183 // TODO(mythria): tests for variable/function declaration in lookup slots. | 7742 // TODO(mythria): tests for variable/function declaration in lookup slots. |
| 7184 | 7743 |
| 7185 TEST(LookupSlotInEval) { | 7744 TEST(LookupSlotInEval) { |
| 7186 InitializedHandleScope handle_scope; | 7745 InitializedHandleScope handle_scope; |
| 7187 BytecodeGeneratorHelper helper; | 7746 BytecodeGeneratorHelper helper; |
| 7188 | 7747 |
| 7189 const char* function_prologue = "var f;" | 7748 const char* function_prologue = "var f;" |
| 7190 "var x = 1;" | 7749 "var x = 1;" |
| 7191 "function f1() {" | 7750 "function f1() {" |
| 7192 " eval(\"function t() {"; | 7751 " eval(\"function t() {"; |
| 7193 const char* function_epilogue = " }; f = t; f();\");" | 7752 const char* function_epilogue = " }; f = t; f();\");" |
| 7194 "}" | 7753 "}" |
| 7195 "f1();"; | 7754 "f1();"; |
| 7196 | 7755 |
| 7756 // clang-format off |
| 7197 ExpectedSnippet<const char*> snippets[] = { | 7757 ExpectedSnippet<const char*> snippets[] = { |
| 7198 {"return x;", | 7758 {"return x;", |
| 7199 0 * kPointerSize, | 7759 0 * kPointerSize, |
| 7200 1, | 7760 1, |
| 7201 3, | 7761 4, |
| 7202 { | 7762 { |
| 7763 B(StackCheck), // |
| 7203 B(LdaLookupSlot), U8(0), // | 7764 B(LdaLookupSlot), U8(0), // |
| 7204 B(Return) // | 7765 B(Return) // |
| 7205 }, | 7766 }, |
| 7206 1, | 7767 1, |
| 7207 {"x"}}, | 7768 {"x"}}, |
| 7208 {"x = 10;", | 7769 {"x = 10;", |
| 7209 0 * kPointerSize, | 7770 0 * kPointerSize, |
| 7210 1, | 7771 1, |
| 7211 6, | 7772 7, |
| 7212 { | 7773 { |
| 7774 B(StackCheck), // |
| 7213 B(LdaSmi8), U8(10), // | 7775 B(LdaSmi8), U8(10), // |
| 7214 B(StaLookupSlotSloppy), U8(0), // | 7776 B(StaLookupSlotSloppy), U8(0), // |
| 7215 B(LdaUndefined), // | 7777 B(LdaUndefined), // |
| 7216 B(Return), // | 7778 B(Return), // |
| 7217 }, | 7779 }, |
| 7218 1, | 7780 1, |
| 7219 {"x"}}, | 7781 {"x"}}, |
| 7220 {"'use strict'; x = 10;", | 7782 {"'use strict'; x = 10;", |
| 7221 0 * kPointerSize, | 7783 0 * kPointerSize, |
| 7222 1, | 7784 1, |
| 7223 6, | 7785 7, |
| 7224 { | 7786 { |
| 7787 B(StackCheck), // |
| 7225 B(LdaSmi8), U8(10), // | 7788 B(LdaSmi8), U8(10), // |
| 7226 B(StaLookupSlotStrict), U8(0), // | 7789 B(StaLookupSlotStrict), U8(0), // |
| 7227 B(LdaUndefined), // | 7790 B(LdaUndefined), // |
| 7228 B(Return), // | 7791 B(Return), // |
| 7229 }, | 7792 }, |
| 7230 1, | 7793 1, |
| 7231 {"x"}}, | 7794 {"x"}}, |
| 7232 {"return typeof x;", | 7795 {"return typeof x;", |
| 7233 0 * kPointerSize, | 7796 0 * kPointerSize, |
| 7234 1, | 7797 1, |
| 7235 4, | 7798 5, |
| 7236 { | 7799 { |
| 7800 B(StackCheck), // |
| 7237 B(LdaLookupSlotInsideTypeof), U8(0), // | 7801 B(LdaLookupSlotInsideTypeof), U8(0), // |
| 7238 B(TypeOf), // | 7802 B(TypeOf), // |
| 7239 B(Return), // | 7803 B(Return), // |
| 7240 }, | 7804 }, |
| 7241 1, | 7805 1, |
| 7242 {"x"}}, | 7806 {"x"}}, |
| 7243 }; | 7807 }; |
| 7808 // clang-format on |
| 7244 | 7809 |
| 7245 for (size_t i = 0; i < arraysize(snippets); i++) { | 7810 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7246 std::string script = std::string(function_prologue) + | 7811 std::string script = std::string(function_prologue) + |
| 7247 std::string(snippets[i].code_snippet) + | 7812 std::string(snippets[i].code_snippet) + |
| 7248 std::string(function_epilogue); | 7813 std::string(function_epilogue); |
| 7249 Handle<BytecodeArray> bytecode_array = | 7814 Handle<BytecodeArray> bytecode_array = |
| 7250 helper.MakeBytecode(script.c_str(), "*", "f"); | 7815 helper.MakeBytecode(script.c_str(), "*", "f"); |
| 7251 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7816 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7252 } | 7817 } |
| 7253 } | 7818 } |
| 7254 | 7819 |
| 7255 | 7820 |
| 7256 TEST(LookupSlotWideInEval) { | 7821 TEST(LookupSlotWideInEval) { |
| 7257 InitializedHandleScope handle_scope; | 7822 InitializedHandleScope handle_scope; |
| 7258 BytecodeGeneratorHelper helper; | 7823 BytecodeGeneratorHelper helper; |
| 7259 | 7824 |
| 7260 const char* function_prologue = | 7825 const char* function_prologue = |
| 7261 "var f;" | 7826 "var f;" |
| 7262 "var x = 1;" | 7827 "var x = 1;" |
| 7263 "function f1() {" | 7828 "function f1() {" |
| 7264 " eval(\"function t() {"; | 7829 " eval(\"function t() {"; |
| 7265 const char* function_epilogue = | 7830 const char* function_epilogue = |
| 7266 " }; f = t; f();\");" | 7831 " }; f = t; f();\");" |
| 7267 "}" | 7832 "}" |
| 7268 "f1();"; | 7833 "f1();"; |
| 7269 | 7834 |
| 7270 int const_count[] = {0, 0, 0, 0}; | 7835 int const_count[] = {0, 0, 0, 0}; |
| 7836 // clang-format off |
| 7271 ExpectedSnippet<InstanceType, 257> snippets[] = { | 7837 ExpectedSnippet<InstanceType, 257> snippets[] = { |
| 7272 {REPEAT_256(SPACE, "var y = 2.3;") | 7838 {REPEAT_256(SPACE, "var y = 2.3;") |
| 7273 "return x;", | 7839 "return x;", |
| 7274 1 * kPointerSize, | 7840 1 * kPointerSize, |
| 7275 1, | 7841 1, |
| 7276 1028, | 7842 1029, |
| 7277 { | 7843 { |
| 7844 B(StackCheck), // |
| 7278 REPEAT_256(SPACE, // | 7845 REPEAT_256(SPACE, // |
| 7279 B(LdaConstant), U8(const_count[0]++), // | 7846 B(LdaConstant), U8(const_count[0]++), // |
| 7280 B(Star), R(0), ) // | 7847 B(Star), R(0), ) // |
| 7281 B(LdaLookupSlotWide), U16(256), // | 7848 B(LdaLookupSlotWide), U16(256), // |
| 7282 B(Return) // | 7849 B(Return) // |
| 7283 }, | 7850 }, |
| 7284 257, | 7851 257, |
| 7285 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 7852 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 7286 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 7853 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7287 {REPEAT_256(SPACE, "var y = 2.3;") | 7854 {REPEAT_256(SPACE, "var y = 2.3;") |
| 7288 "return typeof x;", | 7855 "return typeof x;", |
| 7289 1 * kPointerSize, | 7856 1 * kPointerSize, |
| 7290 1, | 7857 1, |
| 7291 1029, | 7858 1030, |
| 7292 { | 7859 { |
| 7860 B(StackCheck), // |
| 7293 REPEAT_256(SPACE, // | 7861 REPEAT_256(SPACE, // |
| 7294 B(LdaConstant), U8(const_count[1]++), // | 7862 B(LdaConstant), U8(const_count[1]++), // |
| 7295 B(Star), R(0), ) // | 7863 B(Star), R(0), ) // |
| 7296 B(LdaLookupSlotInsideTypeofWide), U16(256), // | 7864 B(LdaLookupSlotInsideTypeofWide), U16(256), // |
| 7297 B(TypeOf), // | 7865 B(TypeOf), // |
| 7298 B(Return) // | 7866 B(Return) // |
| 7299 }, | 7867 }, |
| 7300 257, | 7868 257, |
| 7301 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 7869 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 7302 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 7870 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7303 {REPEAT_256(SPACE, "var y = 2.3;") | 7871 {REPEAT_256(SPACE, "var y = 2.3;") |
| 7304 "x = 10;", | 7872 "x = 10;", |
| 7305 1 * kPointerSize, | 7873 1 * kPointerSize, |
| 7306 1, | 7874 1, |
| 7307 1031, | 7875 1032, |
| 7308 { | 7876 { |
| 7877 B(StackCheck), // |
| 7309 REPEAT_256(SPACE, // | 7878 REPEAT_256(SPACE, // |
| 7310 B(LdaConstant), U8(const_count[2]++), // | 7879 B(LdaConstant), U8(const_count[2]++), // |
| 7311 B(Star), R(0), ) // | 7880 B(Star), R(0), ) // |
| 7312 B(LdaSmi8), U8(10), // | 7881 B(LdaSmi8), U8(10), // |
| 7313 B(StaLookupSlotSloppyWide), U16(256), // | 7882 B(StaLookupSlotSloppyWide), U16(256), // |
| 7314 B(LdaUndefined), // | 7883 B(LdaUndefined), // |
| 7315 B(Return) // | 7884 B(Return) // |
| 7316 }, | 7885 }, |
| 7317 257, | 7886 257, |
| 7318 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 7887 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 7319 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 7888 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7320 {"'use strict';" | 7889 {"'use strict';" |
| 7321 REPEAT_256(SPACE, "var y = 2.3;") | 7890 REPEAT_256(SPACE, "var y = 2.3;") |
| 7322 "x = 10;", | 7891 "x = 10;", |
| 7323 1 * kPointerSize, | 7892 1 * kPointerSize, |
| 7324 1, | 7893 1, |
| 7325 1031, | 7894 1032, |
| 7326 { | 7895 { |
| 7327 REPEAT_256(SPACE, | 7896 B(StackCheck), // |
| 7897 REPEAT_256(SPACE, // |
| 7328 B(LdaConstant), U8(const_count[3]++), // | 7898 B(LdaConstant), U8(const_count[3]++), // |
| 7329 B(Star), R(0), ) // | 7899 B(Star), R(0), ) // |
| 7330 B(LdaSmi8), U8(10), // | 7900 B(LdaSmi8), U8(10), // |
| 7331 B(StaLookupSlotStrictWide), U16(256), // | 7901 B(StaLookupSlotStrictWide), U16(256), // |
| 7332 B(LdaUndefined), // | 7902 B(LdaUndefined), // |
| 7333 B(Return) // | 7903 B(Return) // |
| 7334 }, | 7904 }, |
| 7335 257, | 7905 257, |
| 7336 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), | 7906 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 7337 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 7907 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7338 }; | 7908 }; |
| 7909 // clang-format on |
| 7339 | 7910 |
| 7340 for (size_t i = 0; i < arraysize(snippets); i++) { | 7911 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7341 std::string script = std::string(function_prologue) + | 7912 std::string script = std::string(function_prologue) + |
| 7342 std::string(snippets[i].code_snippet) + | 7913 std::string(snippets[i].code_snippet) + |
| 7343 std::string(function_epilogue); | 7914 std::string(function_epilogue); |
| 7344 Handle<BytecodeArray> bytecode_array = | 7915 Handle<BytecodeArray> bytecode_array = |
| 7345 helper.MakeBytecode(script.c_str(), "*", "f"); | 7916 helper.MakeBytecode(script.c_str(), "*", "f"); |
| 7346 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7917 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7347 } | 7918 } |
| 7348 } | 7919 } |
| 7349 | 7920 |
| 7350 | 7921 |
| 7351 TEST(DeleteLookupSlotInEval) { | 7922 TEST(DeleteLookupSlotInEval) { |
| 7352 InitializedHandleScope handle_scope; | 7923 InitializedHandleScope handle_scope; |
| 7353 BytecodeGeneratorHelper helper; | 7924 BytecodeGeneratorHelper helper; |
| 7354 | 7925 |
| 7355 const char* function_prologue = "var f;" | 7926 const char* function_prologue = "var f;" |
| 7356 "var x = 1;" | 7927 "var x = 1;" |
| 7357 "z = 10;" | 7928 "z = 10;" |
| 7358 "function f1() {" | 7929 "function f1() {" |
| 7359 " var y;" | 7930 " var y;" |
| 7360 " eval(\"function t() {"; | 7931 " eval(\"function t() {"; |
| 7361 const char* function_epilogue = " }; f = t; f();\");" | 7932 const char* function_epilogue = " }; f = t; f();\");" |
| 7362 "}" | 7933 "}" |
| 7363 "f1();"; | 7934 "f1();"; |
| 7364 | 7935 |
| 7936 // clang-format off |
| 7365 ExpectedSnippet<const char*> snippets[] = { | 7937 ExpectedSnippet<const char*> snippets[] = { |
| 7366 {"delete x;", | 7938 {"delete x;", |
| 7367 0 * kPointerSize, | 7939 0 * kPointerSize, |
| 7368 1, | 7940 1, |
| 7369 5, | 7941 6, |
| 7370 { | 7942 { |
| 7943 B(StackCheck), // |
| 7371 B(LdaConstant), U8(0), // | 7944 B(LdaConstant), U8(0), // |
| 7372 B(DeleteLookupSlot), // | 7945 B(DeleteLookupSlot), // |
| 7373 B(LdaUndefined), // | 7946 B(LdaUndefined), // |
| 7374 B(Return) // | 7947 B(Return) // |
| 7375 }, | 7948 }, |
| 7376 1, | 7949 1, |
| 7377 {"x"}}, | 7950 {"x"}}, |
| 7378 {"return delete y;", | 7951 {"return delete y;", |
| 7379 0 * kPointerSize, | 7952 0 * kPointerSize, |
| 7380 1, | 7953 1, |
| 7381 2, | 7954 3, |
| 7382 { | 7955 { |
| 7956 B(StackCheck), // |
| 7383 B(LdaFalse), // | 7957 B(LdaFalse), // |
| 7384 B(Return) // | 7958 B(Return) // |
| 7385 }, | 7959 }, |
| 7386 0}, | 7960 0}, |
| 7387 {"return delete z;", | 7961 {"return delete z;", |
| 7388 0 * kPointerSize, | 7962 0 * kPointerSize, |
| 7389 1, | 7963 1, |
| 7390 4, | 7964 5, |
| 7391 { | 7965 { |
| 7966 B(StackCheck), // |
| 7392 B(LdaConstant), U8(0), // | 7967 B(LdaConstant), U8(0), // |
| 7393 B(DeleteLookupSlot), // | 7968 B(DeleteLookupSlot), // |
| 7394 B(Return) // | 7969 B(Return) // |
| 7395 }, | 7970 }, |
| 7396 1, | 7971 1, |
| 7397 {"z"}}, | 7972 {"z"}}, |
| 7398 }; | 7973 }; |
| 7974 // clang-format on |
| 7399 | 7975 |
| 7400 for (size_t i = 0; i < arraysize(snippets); i++) { | 7976 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7401 std::string script = std::string(function_prologue) + | 7977 std::string script = std::string(function_prologue) + |
| 7402 std::string(snippets[i].code_snippet) + | 7978 std::string(snippets[i].code_snippet) + |
| 7403 std::string(function_epilogue); | 7979 std::string(function_epilogue); |
| 7404 Handle<BytecodeArray> bytecode_array = | 7980 Handle<BytecodeArray> bytecode_array = |
| 7405 helper.MakeBytecode(script.c_str(), "*", "f"); | 7981 helper.MakeBytecode(script.c_str(), "*", "f"); |
| 7406 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7982 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7407 } | 7983 } |
| 7408 } | 7984 } |
| 7409 | 7985 |
| 7410 TEST(WideRegisters) { | 7986 TEST(WideRegisters) { |
| 7411 // Prepare prologue that creates frame for lots of registers. | 7987 // Prepare prologue that creates frame for lots of registers. |
| 7412 std::ostringstream os; | 7988 std::ostringstream os; |
| 7413 for (size_t i = 0; i < 157; ++i) { | 7989 for (size_t i = 0; i < 157; ++i) { |
| 7414 os << "var x" << i << ";\n"; | 7990 os << "var x" << i << ";\n"; |
| 7415 } | 7991 } |
| 7416 std::string prologue(os.str()); | 7992 std::string prologue(os.str()); |
| 7417 | 7993 |
| 7994 // clang-format off |
| 7418 ExpectedSnippet<int> snippets[] = { | 7995 ExpectedSnippet<int> snippets[] = { |
| 7419 {"x0 = x127;\n" | 7996 {"x0 = x127;\n" |
| 7420 "return x0;\n", | 7997 "return x0;\n", |
| 7421 161 * kPointerSize, | 7998 161 * kPointerSize, |
| 7422 1, | 7999 1, |
| 7423 10, | 8000 11, |
| 7424 { | 8001 { |
| 8002 B(StackCheck), // |
| 7425 B(MovWide), R16(131), R16(125), // | 8003 B(MovWide), R16(131), R16(125), // |
| 7426 B(Ldar), R(125), // | 8004 B(Ldar), R(125), // |
| 7427 B(Star), R(0), // | 8005 B(Star), R(0), // |
| 7428 B(Return), // | 8006 B(Return), // |
| 7429 }}, | 8007 }}, |
| 7430 {"x127 = x126;\n" | 8008 {"x127 = x126;\n" |
| 7431 "return x127;\n", | 8009 "return x127;\n", |
| 7432 161 * kPointerSize, | 8010 161 * kPointerSize, |
| 7433 1, | 8011 1, |
| 7434 22, | 8012 23, |
| 7435 { | 8013 { |
| 8014 B(StackCheck), // |
| 7436 B(MovWide), R16(130), R16(125), // | 8015 B(MovWide), R16(130), R16(125), // |
| 7437 B(Ldar), R(125), // | 8016 B(Ldar), R(125), // |
| 7438 B(Star), R(125), // | 8017 B(Star), R(125), // |
| 7439 B(MovWide), R16(125), R16(131), // | 8018 B(MovWide), R16(125), R16(131), // |
| 7440 B(MovWide), R16(131), R16(125), // | 8019 B(MovWide), R16(131), R16(125), // |
| 7441 B(Ldar), R(125), // | 8020 B(Ldar), R(125), // |
| 7442 B(Return), // | 8021 B(Return), // |
| 7443 }}, | 8022 }}, |
| 7444 {"if (x2 > 3) { return x129; }\n" | 8023 {"if (x2 > 3) { return x129; }\n" |
| 7445 "return x128;\n", | 8024 "return x128;\n", |
| 7446 162 * kPointerSize, | 8025 162 * kPointerSize, |
| 7447 1, | 8026 1, |
| 7448 36, | 8027 37, |
| 7449 { | 8028 { |
| 8029 B(StackCheck), // |
| 7450 B(Ldar), R(2), // | 8030 B(Ldar), R(2), // |
| 7451 B(Star), R(125), // | 8031 B(Star), R(125), // |
| 7452 B(MovWide), R16(125), R16(161), // | 8032 B(MovWide), R16(125), R16(161), // |
| 7453 B(LdaSmi8), U8(3), // | 8033 B(LdaSmi8), U8(3), // |
| 7454 B(MovWide), R16(161), R16(125), // | 8034 B(MovWide), R16(161), R16(125), // |
| 7455 B(TestGreaterThan), R(125), // | 8035 B(TestGreaterThan), R(125), // |
| 7456 B(JumpIfFalse), U8(10), // | 8036 B(JumpIfFalse), U8(10), // |
| 7457 B(MovWide), R16(133), R16(125), // | 8037 B(MovWide), R16(133), R16(125), // |
| 7458 B(Ldar), R(125), // | 8038 B(Ldar), R(125), // |
| 7459 B(Return), // | 8039 B(Return), // |
| 7460 B(MovWide), R16(132), R16(125), // | 8040 B(MovWide), R16(132), R16(125), // |
| 7461 B(Ldar), R(125), // | 8041 B(Ldar), R(125), // |
| 7462 B(Return), // | 8042 B(Return), // |
| 7463 }}, | 8043 }}, |
| 7464 {"var x0 = 0;\n" | 8044 {"var x0 = 0;\n" |
| 7465 "if (x129 == 3) { var x129 = x0; }\n" | 8045 "if (x129 == 3) { var x129 = x0; }\n" |
| 7466 "if (x2 > 3) { return x0; }\n" | 8046 "if (x2 > 3) { return x0; }\n" |
| 7467 "return x129;\n", | 8047 "return x129;\n", |
| 7468 162 * kPointerSize, | 8048 162 * kPointerSize, |
| 7469 1, | 8049 1, |
| 7470 68, | 8050 69, |
| 7471 { | 8051 { |
| 8052 B(StackCheck), // |
| 7472 B(LdaZero), // | 8053 B(LdaZero), // |
| 7473 B(Star), R(0), // | 8054 B(Star), R(0), // |
| 7474 B(MovWide), R16(133), R16(125), // | 8055 B(MovWide), R16(133), R16(125), // |
| 7475 B(Ldar), R(125), // | 8056 B(Ldar), R(125), // |
| 7476 B(Star), R(125), // | 8057 B(Star), R(125), // |
| 7477 B(MovWide), R16(125), R16(161), // | 8058 B(MovWide), R16(125), R16(161), // |
| 7478 B(LdaSmi8), U8(3), // | 8059 B(LdaSmi8), U8(3), // |
| 7479 B(MovWide), R16(161), R16(125), // | 8060 B(MovWide), R16(161), R16(125), // |
| 7480 B(TestEqual), R(125), // | 8061 B(TestEqual), R(125), // |
| 7481 B(JumpIfFalse), U8(11), // | 8062 B(JumpIfFalse), U8(11), // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7496 B(Return), // | 8077 B(Return), // |
| 7497 }}, | 8078 }}, |
| 7498 {"var x0 = 0;\n" | 8079 {"var x0 = 0;\n" |
| 7499 "var x1 = 0;\n" | 8080 "var x1 = 0;\n" |
| 7500 "for (x128 = 0; x128 < 64; x128++) {" | 8081 "for (x128 = 0; x128 < 64; x128++) {" |
| 7501 " x1 += x128;" | 8082 " x1 += x128;" |
| 7502 "}" | 8083 "}" |
| 7503 "return x128;\n", | 8084 "return x128;\n", |
| 7504 162 * kPointerSize, | 8085 162 * kPointerSize, |
| 7505 1, | 8086 1, |
| 7506 97, | 8087 99, |
| 7507 { | 8088 { |
| 8089 B(StackCheck), // |
| 7508 B(LdaZero), // | 8090 B(LdaZero), // |
| 7509 B(Star), R(0), // | 8091 B(Star), R(0), // |
| 7510 B(LdaZero), // | 8092 B(LdaZero), // |
| 7511 B(Star), R(1), // | 8093 B(Star), R(1), // |
| 7512 B(LdaZero), // | 8094 B(LdaZero), // |
| 7513 B(Star), R(125), // | 8095 B(Star), R(125), // |
| 7514 B(MovWide), R16(125), R16(132), // | 8096 B(MovWide), R16(125), R16(132), // |
| 7515 B(MovWide), R16(132), R16(125), // | 8097 B(MovWide), R16(132), R16(125), // |
| 7516 B(Ldar), R(125), // | 8098 B(Ldar), R(125), // |
| 7517 B(Star), R(125), // | 8099 B(Star), R(125), // |
| 7518 B(MovWide), R16(125), R16(161), // | 8100 B(MovWide), R16(125), R16(161), // |
| 7519 B(LdaSmi8), U8(64), // | 8101 B(LdaSmi8), U8(64), // |
| 7520 B(MovWide), R16(161), R16(125), // | 8102 B(MovWide), R16(161), R16(125), // |
| 7521 B(TestLessThan), R(125), // | 8103 B(TestLessThan), R(125), // |
| 7522 B(JumpIfFalse), U8(52), // | 8104 B(JumpIfFalse), U8(53), // |
| 8105 B(StackCheck), // |
| 7523 B(Ldar), R(1), // | 8106 B(Ldar), R(1), // |
| 7524 B(Star), R(125), // | 8107 B(Star), R(125), // |
| 7525 B(MovWide), R16(125), R16(161), // | 8108 B(MovWide), R16(125), R16(161), // |
| 7526 B(MovWide), R16(132), R16(125), // | 8109 B(MovWide), R16(132), R16(125), // |
| 7527 B(Ldar), R(125), // | 8110 B(Ldar), R(125), // |
| 7528 B(MovWide), R16(161), R16(125), // | 8111 B(MovWide), R16(161), R16(125), // |
| 7529 B(Add), R(125), // | 8112 B(Add), R(125), // |
| 7530 B(Star), R(1), // | 8113 B(Star), R(1), // |
| 7531 B(MovWide), R16(132), R16(125), // | 8114 B(MovWide), R16(132), R16(125), // |
| 7532 B(Ldar), R(125), // | 8115 B(Ldar), R(125), // |
| 7533 B(ToNumber), // | 8116 B(ToNumber), // |
| 7534 B(Star), R(125), // | 8117 B(Star), R(125), // |
| 7535 B(MovWide), R16(125), R16(161), // | 8118 B(MovWide), R16(125), R16(161), // |
| 7536 B(Inc), // | 8119 B(Inc), // |
| 7537 B(Star), R(125), // | 8120 B(Star), R(125), // |
| 7538 B(MovWide), R16(125), R16(132), // | 8121 B(MovWide), R16(125), R16(132), // |
| 7539 B(Jump), U8(-73), // | 8122 B(Jump), U8(-74), // |
| 7540 B(MovWide), R16(132), R16(125), // | 8123 B(MovWide), R16(132), R16(125), // |
| 7541 B(Ldar), R(125), // | 8124 B(Ldar), R(125), // |
| 7542 B(Return), // | 8125 B(Return), // |
| 7543 }}, | 8126 }}, |
| 7544 {"var x0 = 1234;\n" | 8127 {"var x0 = 1234;\n" |
| 7545 "var x1 = 0;\n" | 8128 "var x1 = 0;\n" |
| 7546 "for (x128 in x0) {" | 8129 "for (x128 in x0) {" |
| 7547 " x1 += x128;" | 8130 " x1 += x128;" |
| 7548 "}" | 8131 "}" |
| 7549 "return x1;\n", | 8132 "return x1;\n", |
| 7550 167 * kPointerSize, | 8133 167 * kPointerSize, |
| 7551 1, | 8134 1, |
| 7552 109, | 8135 111, |
| 7553 { | 8136 { |
| 8137 B(StackCheck), // |
| 7554 B(LdaConstant), U8(0), // | 8138 B(LdaConstant), U8(0), // |
| 7555 B(Star), R(0), // | 8139 B(Star), R(0), // |
| 7556 B(LdaZero), // | 8140 B(LdaZero), // |
| 7557 B(Star), R(1), // | 8141 B(Star), R(1), // |
| 7558 B(Ldar), R(0), // | 8142 B(Ldar), R(0), // |
| 7559 B(JumpIfUndefined), U8(97), // | 8143 B(JumpIfUndefined), U8(98), // |
| 7560 B(JumpIfNull), U8(95), // | 8144 B(JumpIfNull), U8(96), // |
| 7561 B(ToObject), // | 8145 B(ToObject), // |
| 7562 B(JumpIfNull), U8(92), // | 8146 B(JumpIfNull), U8(93), // |
| 7563 B(Star), R(125), // | 8147 B(Star), R(125), // |
| 7564 B(MovWide), R16(125), R16(161), // | 8148 B(MovWide), R16(125), R16(161), // |
| 7565 B(ForInPrepareWide), R16(162), // | 8149 B(ForInPrepareWide), R16(162), // |
| 7566 B(LdaZero), // | 8150 B(LdaZero), // |
| 7567 B(Star), R(125), // | 8151 B(Star), R(125), // |
| 7568 B(MovWide), R16(125), R16(165), // | 8152 B(MovWide), R16(125), R16(165), // |
| 7569 B(MovWide), R16(165), R16(125), // | 8153 B(MovWide), R16(165), R16(125), // |
| 7570 B(MovWide), R16(164), R16(126), // | 8154 B(MovWide), R16(164), R16(126), // |
| 7571 B(ForInDone), R(125), R(126), // | 8155 B(ForInDone), R(125), R(126), // |
| 7572 B(JumpIfTrue), U8(59), // | 8156 B(JumpIfTrue), U8(60), // |
| 7573 B(ForInNextWide), R16(161), R16(165), R16(162), // | 8157 B(ForInNextWide), R16(161), R16(165), R16(162), // |
| 7574 B(JumpIfUndefined), U8(34), // | 8158 B(JumpIfUndefined), U8(35), // |
| 7575 B(Star), R(125), // | 8159 B(Star), R(125), // |
| 7576 B(MovWide), R16(125), R16(132), // | 8160 B(MovWide), R16(125), R16(132), // |
| 8161 B(StackCheck), // |
| 7577 B(Ldar), R(1), // | 8162 B(Ldar), R(1), // |
| 7578 B(Star), R(125), // | 8163 B(Star), R(125), // |
| 7579 B(MovWide), R16(125), R16(166), // | 8164 B(MovWide), R16(125), R16(166), // |
| 7580 B(MovWide), R16(132), R16(125), // | 8165 B(MovWide), R16(132), R16(125), // |
| 7581 B(Ldar), R(125), // | 8166 B(Ldar), R(125), // |
| 7582 B(MovWide), R16(166), R16(125), // | 8167 B(MovWide), R16(166), R16(125), // |
| 7583 B(Add), R(125), // | 8168 B(Add), R(125), // |
| 7584 B(Star), R(1), // | 8169 B(Star), R(1), // |
| 7585 B(MovWide), R16(165), R16(125), // | 8170 B(MovWide), R16(165), R16(125), // |
| 7586 B(ForInStep), R(125), // | 8171 B(ForInStep), R(125), // |
| 7587 B(Star), R(125), // | 8172 B(Star), R(125), // |
| 7588 B(MovWide), R16(125), R16(165), // | 8173 B(MovWide), R16(125), R16(165), // |
| 7589 B(Jump), U8(-70), // | 8174 B(Jump), U8(-71), // |
| 7590 B(Ldar), R(1), // | 8175 B(Ldar), R(1), // |
| 7591 B(Return), // | 8176 B(Return), // |
| 7592 }, | 8177 }, |
| 7593 1, | 8178 1, |
| 7594 {1234}}, | 8179 {1234}}, |
| 7595 {"x0 = %Add(x64, x63);\n" | 8180 {"x0 = %Add(x64, x63);\n" |
| 7596 "x1 = %Add(x27, x143);\n" | 8181 "x1 = %Add(x27, x143);\n" |
| 7597 "%TheHole();\n" | 8182 "%TheHole();\n" |
| 7598 "return x1;\n", | 8183 "return x1;\n", |
| 7599 163 * kPointerSize, | 8184 163 * kPointerSize, |
| 7600 1, | 8185 1, |
| 7601 65, | 8186 66, |
| 7602 { | 8187 { |
| 8188 B(StackCheck), // |
| 7603 B(Ldar), R(64), // | 8189 B(Ldar), R(64), // |
| 7604 B(Star), R(125), // | 8190 B(Star), R(125), // |
| 7605 B(MovWide), R16(125), R16(161), // | 8191 B(MovWide), R16(125), R16(161), // |
| 7606 B(Ldar), R(63), // | 8192 B(Ldar), R(63), // |
| 7607 B(Star), R(125), // | 8193 B(Star), R(125), // |
| 7608 B(MovWide), R16(125), R16(162), // | 8194 B(MovWide), R16(125), R16(162), // |
| 7609 B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), // | 8195 B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), // |
| 7610 B(Star), R(0), // | 8196 B(Star), R(0), // |
| 7611 B(Ldar), R(27), // | 8197 B(Ldar), R(27), // |
| 7612 B(Star), R(125), // | 8198 B(Star), R(125), // |
| 7613 B(MovWide), R16(125), R16(161), // | 8199 B(MovWide), R16(125), R16(161), // |
| 7614 B(MovWide), R16(147), R16(125), // | 8200 B(MovWide), R16(147), R16(125), // |
| 7615 B(Ldar), R(125), // | 8201 B(Ldar), R(125), // |
| 7616 B(Star), R(125), // | 8202 B(Star), R(125), // |
| 7617 B(MovWide), R16(125), R16(162), // | 8203 B(MovWide), R16(125), R16(162), // |
| 7618 B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), // | 8204 B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), // |
| 7619 B(Star), R(1), // | 8205 B(Star), R(1), // |
| 7620 B(CallRuntime), U16(Runtime::kTheHole), R(0), U8(0), // | 8206 B(CallRuntime), U16(Runtime::kTheHole), R(0), U8(0), // |
| 7621 B(Ldar), R(1), // | 8207 B(Ldar), R(1), // |
| 7622 B(Return), // | 8208 B(Return), // |
| 7623 }}}; | 8209 }} |
| 8210 }; |
| 8211 // clang-format on |
| 7624 | 8212 |
| 7625 InitializedHandleScope handle_scope; | 8213 InitializedHandleScope handle_scope; |
| 7626 BytecodeGeneratorHelper helper; | 8214 BytecodeGeneratorHelper helper; |
| 7627 | 8215 |
| 7628 for (size_t i = 0; i < arraysize(snippets); ++i) { | 8216 for (size_t i = 0; i < arraysize(snippets); ++i) { |
| 7629 std::string body = prologue + snippets[i].code_snippet; | 8217 std::string body = prologue + snippets[i].code_snippet; |
| 7630 Handle<BytecodeArray> bytecode_array = | 8218 Handle<BytecodeArray> bytecode_array = |
| 7631 helper.MakeBytecodeForFunctionBody(body.c_str()); | 8219 helper.MakeBytecodeForFunctionBody(body.c_str()); |
| 7632 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 8220 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7633 } | 8221 } |
| 7634 } | 8222 } |
| 7635 | 8223 |
| 7636 TEST(DoExpression) { | 8224 TEST(DoExpression) { |
| 7637 bool old_flag = FLAG_harmony_do_expressions; | 8225 bool old_flag = FLAG_harmony_do_expressions; |
| 7638 FLAG_harmony_do_expressions = true; | 8226 FLAG_harmony_do_expressions = true; |
| 7639 | 8227 |
| 7640 InitializedHandleScope handle_scope; | 8228 InitializedHandleScope handle_scope; |
| 7641 BytecodeGeneratorHelper helper; | 8229 BytecodeGeneratorHelper helper; |
| 7642 | 8230 |
| 8231 // clang-format off |
| 7643 ExpectedSnippet<const char*> snippets[] = { | 8232 ExpectedSnippet<const char*> snippets[] = { |
| 7644 {"var a = do { }; return a;", | 8233 {"var a = do { }; return a;", |
| 7645 2 * kPointerSize, | 8234 2 * kPointerSize, |
| 7646 1, | 8235 1, |
| 7647 5, | 8236 6, |
| 7648 { | 8237 { |
| 8238 B(StackCheck), // |
| 7649 B(Ldar), R(0), // | 8239 B(Ldar), R(0), // |
| 7650 B(Star), R(1), // | 8240 B(Star), R(1), // |
| 7651 B(Return) // | 8241 B(Return) // |
| 7652 }, | 8242 }, |
| 7653 0}, | 8243 0}, |
| 7654 {"var a = do { var x = 100; }; return a;", | 8244 {"var a = do { var x = 100; }; return a;", |
| 7655 3 * kPointerSize, | 8245 3 * kPointerSize, |
| 7656 1, | 8246 1, |
| 7657 10, | 8247 11, |
| 7658 { | 8248 { |
| 8249 B(StackCheck), // |
| 7659 B(LdaSmi8), U8(100), // | 8250 B(LdaSmi8), U8(100), // |
| 7660 B(Star), R(1), // | 8251 B(Star), R(1), // |
| 7661 B(LdaUndefined), // | 8252 B(LdaUndefined), // |
| 7662 B(Star), R(0), // | 8253 B(Star), R(0), // |
| 7663 B(Star), R(2), // | 8254 B(Star), R(2), // |
| 7664 B(Return) // | 8255 B(Return) // |
| 7665 }, | 8256 }, |
| 7666 0}, | 8257 0}, |
| 7667 {"while(true) { var a = 10; a = do { ++a; break; }; a = 20; }", | 8258 {"while(true) { var a = 10; a = do { ++a; break; }; a = 20; }", |
| 7668 2 * kPointerSize, | 8259 2 * kPointerSize, |
| 7669 1, | 8260 1, |
| 7670 24, | 8261 26, |
| 7671 { | 8262 { |
| 7672 B(LdaSmi8), U8(10), // | 8263 B(StackCheck), // |
| 7673 B(Star), R(1), // | 8264 B(StackCheck), // |
| 8265 B(LdaSmi8), U8(10), // |
| 8266 B(Star), R(1), // |
| 7674 B(ToNumber), // | 8267 B(ToNumber), // |
| 7675 B(Inc), // | 8268 B(Inc), // |
| 7676 B(Star), R(1), // | 8269 B(Star), R(1), // |
| 7677 B(Star), R(0), // | 8270 B(Star), R(0), // |
| 7678 B(Jump), U8(12), // | 8271 B(Jump), U8(12), // |
| 7679 B(Ldar), R(0), // | 8272 B(Ldar), R(0), // |
| 7680 B(Star), R(1), // | 8273 B(Star), R(1), // |
| 7681 B(LdaSmi8), U8(20), // | 8274 B(LdaSmi8), U8(20), // |
| 7682 B(Star), R(1), // | 8275 B(Star), R(1), // |
| 7683 B(Jump), U8(-20), // | 8276 B(Jump), U8(-21), // |
| 7684 B(LdaUndefined), // | 8277 B(LdaUndefined), // |
| 7685 B(Return), // | 8278 B(Return), // |
| 7686 }, | 8279 }, |
| 7687 0}, | 8280 0}, |
| 7688 }; | 8281 }; |
| 8282 // clang-format on |
| 7689 | 8283 |
| 7690 for (size_t i = 0; i < arraysize(snippets); i++) { | 8284 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7691 Handle<BytecodeArray> bytecode_array = | 8285 Handle<BytecodeArray> bytecode_array = |
| 7692 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 8286 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7693 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 8287 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7694 } | 8288 } |
| 7695 FLAG_harmony_do_expressions = old_flag; | 8289 FLAG_harmony_do_expressions = old_flag; |
| 7696 } | 8290 } |
| 7697 | 8291 |
| 7698 TEST(WithStatement) { | 8292 TEST(WithStatement) { |
| 7699 InitializedHandleScope handle_scope; | 8293 InitializedHandleScope handle_scope; |
| 7700 BytecodeGeneratorHelper helper; | 8294 BytecodeGeneratorHelper helper; |
| 7701 | 8295 |
| 7702 int deep_elements_flags = | 8296 int deep_elements_flags = |
| 7703 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; | 8297 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 7704 int context = Register::current_context().index(); | 8298 int context = Register::current_context().index(); |
| 7705 int closure = Register::function_closure().index(); | 8299 int closure = Register::function_closure().index(); |
| 7706 int new_target = Register::new_target().index(); | 8300 int new_target = Register::new_target().index(); |
| 7707 | 8301 |
| 8302 // clang-format off |
| 7708 ExpectedSnippet<InstanceType> snippets[] = { | 8303 ExpectedSnippet<InstanceType> snippets[] = { |
| 7709 {"with ({x:42}) { return x; }", | 8304 {"with ({x:42}) { return x; }", |
| 7710 5 * kPointerSize, | 8305 5 * kPointerSize, |
| 7711 1, | 8306 1, |
| 7712 46, | 8307 47, |
| 7713 { | 8308 { |
| 7714 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 8309 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7715 U8(1), // | 8310 /* */ U8(1), // |
| 7716 B(PushContext), R(0), // | 8311 B(PushContext), R(0), // |
| 7717 B(Ldar), THIS(1), // | 8312 B(Ldar), THIS(1), // |
| 7718 B(StaContextSlot), R(context), U8(4), // | 8313 B(StaContextSlot), R(context), U8(4), // |
| 7719 B(CreateMappedArguments), // | 8314 B(CreateMappedArguments), // |
| 7720 B(StaContextSlot), R(context), U8(5), // | 8315 B(StaContextSlot), R(context), U8(5), // |
| 7721 B(Ldar), R(new_target), // | 8316 B(Ldar), R(new_target), // |
| 7722 B(StaContextSlot), R(context), U8(6), // | 8317 B(StaContextSlot), R(context), U8(6), // |
| 8318 B(StackCheck), // |
| 7723 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // | 8319 B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), // |
| 7724 B(Star), R(2), // | 8320 B(Star), R(2), // |
| 7725 B(ToObject), // | 8321 B(ToObject), // |
| 7726 B(Star), R(3), // | 8322 B(Star), R(3), // |
| 7727 B(Ldar), R(closure), // | 8323 B(Ldar), R(closure), // |
| 7728 B(Star), R(4), // | 8324 B(Star), R(4), // |
| 7729 B(CallRuntime), U16(Runtime::kPushWithContext), R(3), U8(2), // | 8325 B(CallRuntime), U16(Runtime::kPushWithContext), R(3), U8(2), // |
| 7730 B(PushContext), R(1), // | 8326 B(PushContext), R(1), // |
| 7731 B(LdaLookupSlot), U8(1), // | 8327 B(LdaLookupSlot), U8(1), // |
| 7732 B(PopContext), R(0), // | 8328 B(PopContext), R(0), // |
| 7733 B(Return), // | 8329 B(Return), // |
| 7734 }, | 8330 }, |
| 7735 2, | 8331 2, |
| 7736 {InstanceType::FIXED_ARRAY_TYPE, | 8332 {InstanceType::FIXED_ARRAY_TYPE, |
| 7737 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 8333 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7738 }; | 8334 }; |
| 8335 // clang-format on |
| 7739 | 8336 |
| 7740 for (size_t i = 0; i < arraysize(snippets); i++) { | 8337 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7741 Handle<BytecodeArray> bytecode_array = | 8338 Handle<BytecodeArray> bytecode_array = |
| 7742 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 8339 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7743 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 8340 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7744 } | 8341 } |
| 7745 } | 8342 } |
| 7746 | 8343 |
| 7747 } // namespace interpreter | 8344 } // namespace interpreter |
| 7748 } // namespace internal | 8345 } // namespace internal |
| 7749 } // namespace v8 | 8346 } // namespace v8 |
| OLD | NEW |