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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1422033002: [Interpreter] Add support for for..in. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes for 32-bit. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 3475 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 {"a"}}, 3486 {"a"}},
3487 }; 3487 };
3488 3488
3489 for (size_t i = 0; i < arraysize(snippets); i++) { 3489 for (size_t i = 0; i < arraysize(snippets); i++) {
3490 Handle<BytecodeArray> bytecode_array = 3490 Handle<BytecodeArray> bytecode_array =
3491 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3491 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3492 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3492 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3493 } 3493 }
3494 } 3494 }
3495 3495
3496
3497 TEST(ForIn) {
3498 InitializedHandleScope handle_scope;
3499 BytecodeGeneratorHelper helper;
3500 Zone zone;
3501
3502 int simple_flags =
3503 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
3504 int deep_elements_flags =
3505 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
3506
3507 FeedbackVectorSpec feedback_spec(&zone);
3508 feedback_spec.AddStoreICSlot();
3509 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
3510 FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot();
3511 FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot();
3512 Handle<i::TypeFeedbackVector> vector =
3513 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
3514
3515 ExpectedSnippet<InstanceType> snippets[] = {
3516 {"for (var p in null) {}",
3517 2 * kPointerSize,
3518 1,
3519 2,
3520 {B(LdaUndefined), B(Return)},
3521 0},
3522 {"for (var p in undefined) {}",
3523 2 * kPointerSize,
3524 1,
3525 2,
3526 {B(LdaUndefined), B(Return)},
3527 0},
3528 {"var x = 0;\n"
3529 "for (var p in [1,2,3]) { x += p; }",
3530 6 * kPointerSize,
3531 1,
3532 58,
3533 {
3534 B(LdaZero), //
3535 B(Star), R(1), //
3536 B(LdaConstant), U8(0), //
3537 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
3538 B(ForInPrepare), //
3539 B(Star), R(3), //
3540 B(LdaUndefined), //
3541 B(TestEqualStrict), R(3), //
3542 B(JumpIfTrue), U8(42), //
3543 B(LdaZero), //
3544 B(Star), R(4), //
3545 B(ForInDone), R(3), //
3546 B(JumpIfTrue), U8(35), //
3547 B(Ldar), R(4), //
3548 B(ForInNext), R(3), //
3549 B(Star), R(5), //
3550 B(LdaUndefined), //
3551 B(TestEqualStrict), R(5), //
3552 B(JumpIfTrue), U8(16), //
3553 B(Ldar), R(5), //
3554 B(Star), R(0), //
3555 B(Ldar), R(0), //
3556 B(Star), R(2), //
3557 B(Ldar), R(2), //
3558 B(Add), R(1), //
3559 B(Star), R(1), //
3560 B(LdaSmi8), U8(1), //
3561 B(Add), R(4), //
3562 B(Star), R(4), //
3563 B(Jump), U8(-35), //
3564 B(LdaUndefined), //
3565 B(Return), //
3566 },
3567 1,
3568 {InstanceType::FIXED_ARRAY_TYPE}},
3569 {"var x = { 'a': 1, 'b': 2 };\n"
3570 "for (x['a'] in [10, 20, 30]) {\n"
3571 " if (x['a'] == 10) continue;\n"
3572 " if (x['a'] == 20) break;\n"
3573 "}",
3574 5 * kPointerSize,
3575 1,
3576 84,
3577 {
3578 B(LdaConstant), U8(0), //
3579 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
3580 B(Star), R(0), //
3581 B(LdaConstant), U8(1), //
3582 B(CreateArrayLiteral), U8(1), U8(simple_flags), //
3583 B(ForInPrepare), //
3584 B(Star), R(1), //
3585 B(LdaUndefined), //
3586 B(TestEqualStrict), R(1), //
3587 B(JumpIfTrue), U8(64), //
3588 B(LdaZero), //
3589 B(Star), R(2), //
3590 B(ForInDone), R(1), //
3591 B(JumpIfTrue), U8(57), //
3592 B(Ldar), R(2), //
3593 B(ForInNext), R(1), //
3594 B(Star), R(3), //
3595 B(LdaUndefined), //
3596 B(TestEqualStrict), R(3), //
3597 B(JumpIfTrue), U8(38), //
3598 B(Ldar), R(3), //
3599 B(Star), R(4), //
3600 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot4)), //
3601 B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot2)), //
3602 B(Star), R(4), //
3603 B(LdaSmi8), U8(10), //
3604 B(TestEqual), R(4), //
3605 B(JumpIfFalse), U8(4), //
3606 B(Jump), U8(16), //
3607 B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot3)), //
3608 B(Star), R(4), //
3609 B(LdaSmi8), U8(20), //
3610 B(TestEqual), R(4), //
3611 B(JumpIfFalse), U8(4), //
3612 B(Jump), U8(10), //
3613 B(LdaSmi8), U8(1), //
3614 B(Add), R(2), //
3615 B(Star), R(2), //
3616 B(Jump), U8(-57), //
3617 B(LdaUndefined), //
3618 B(Return), //
3619 },
3620 3,
3621 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
3622 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3623 {"var x = [ 10, 11, 12 ] ;\n"
3624 "for (x[0] in [1,2,3]) { return x[3]; }",
3625 6 * kPointerSize,
3626 1,
3627 67,
3628 {B(LdaConstant), U8(0), //
3629 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
3630 B(Star), R(0), //
3631 B(LdaConstant), U8(1), //
3632 B(CreateArrayLiteral), U8(1), U8(simple_flags), //
3633 B(ForInPrepare), //
3634 B(Star), R(1), //
3635 B(LdaUndefined), //
3636 B(TestEqualStrict), R(1), //
3637 B(JumpIfTrue), U8(47), //
3638 B(LdaZero), //
3639 B(Star), R(2), //
3640 B(ForInDone), R(1), //
3641 B(JumpIfTrue), U8(40), //
3642 B(Ldar), R(2), //
3643 B(ForInNext), R(1), //
3644 B(Star), R(3), //
3645 B(LdaUndefined), //
3646 B(TestEqualStrict), R(3), //
3647 B(JumpIfTrue), U8(21), //
3648 B(Ldar), R(3), //
3649 B(Star), R(4), //
3650 B(LdaZero), //
3651 B(Star), R(5), //
3652 B(Ldar), R(4), //
3653 B(KeyedStoreICSloppy), R(0), R(5), U8(vector->GetIndex(slot3)), //
3654 B(LdaSmi8), U8(3), //
3655 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot2)), //
3656 B(Return), //
3657 B(LdaSmi8), U8(1), //
3658 B(Add), R(2), //
3659 B(Star), R(2), //
3660 B(Jump), U8(-40), //
3661 B(LdaUndefined), //
3662 B(Return)},
3663 2,
3664 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}},
3665 };
3666
3667 for (size_t i = 0; i < arraysize(snippets); i++) {
3668 Handle<BytecodeArray> bytecode_array =
3669 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3670 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3671 }
3672 }
3673
3496 } // namespace interpreter 3674 } // namespace interpreter
3497 } // namespace internal 3675 } // namespace internal
3498 } // namespace v8 3676 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698