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 5473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5484 }}, | 5484 }}, |
5485 }; | 5485 }; |
5486 | 5486 |
5487 for (size_t i = 0; i < arraysize(snippets); i++) { | 5487 for (size_t i = 0; i < arraysize(snippets); i++) { |
5488 Handle<BytecodeArray> bytecode_array = | 5488 Handle<BytecodeArray> bytecode_array = |
5489 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 5489 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
5490 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5490 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5491 } | 5491 } |
5492 } | 5492 } |
5493 | 5493 |
| 5494 TEST(CreateRestArguments) { |
| 5495 InitializedHandleScope handle_scope; |
| 5496 BytecodeGeneratorHelper helper; |
| 5497 Zone zone; |
| 5498 |
| 5499 FeedbackVectorSpec feedback_spec(&zone); |
| 5500 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
| 5501 FeedbackVectorSlot slot1 = feedback_spec.AddKeyedLoadICSlot(); |
| 5502 |
| 5503 Handle<i::TypeFeedbackVector> vector = |
| 5504 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 5505 |
| 5506 ExpectedSnippet<int> snippets[] = { |
| 5507 {"function f(...restArgs) { return restArgs; }", |
| 5508 1 * kPointerSize, |
| 5509 2, |
| 5510 5, |
| 5511 { |
| 5512 B(CreateRestArguments), U8(0), // |
| 5513 B(Star), R(0), // |
| 5514 B(Return), // |
| 5515 }, |
| 5516 1, |
| 5517 {0}}, |
| 5518 {"function f(a, ...restArgs) { return restArgs; }", |
| 5519 2 * kPointerSize, |
| 5520 3, |
| 5521 14, |
| 5522 { |
| 5523 B(CreateRestArguments), U8(0), // |
| 5524 B(Star), R(0), // |
| 5525 B(LdaTheHole), // |
| 5526 B(Star), R(1), // |
| 5527 B(Ldar), A(1, 3), // |
| 5528 B(Star), R(1), // |
| 5529 B(Ldar), R(0), // |
| 5530 B(Return), // |
| 5531 }, |
| 5532 1, |
| 5533 {1}}, |
| 5534 {"function f(a, ...restArgs) { return restArgs[0]; }", |
| 5535 3 * kPointerSize, |
| 5536 3, |
| 5537 20, |
| 5538 { |
| 5539 B(CreateRestArguments), U8(0), // |
| 5540 B(Star), R(0), // |
| 5541 B(LdaTheHole), // |
| 5542 B(Star), R(1), // |
| 5543 B(Ldar), A(1, 3), // |
| 5544 B(Star), R(1), // |
| 5545 B(Ldar), R(0), // |
| 5546 B(Star), R(2), // |
| 5547 B(LdaZero), // |
| 5548 B(KeyedLoadICSloppy), R(2), U8(vector->GetIndex(slot)), // |
| 5549 B(Return), // |
| 5550 }, |
| 5551 1, |
| 5552 {1}}, |
| 5553 {"function f(a, ...restArgs) { return restArgs[0] + arguments[0]; }", |
| 5554 5 * kPointerSize, |
| 5555 3, |
| 5556 35, |
| 5557 { |
| 5558 B(CreateUnmappedArguments), // |
| 5559 B(Star), R(0), // |
| 5560 B(CreateRestArguments), U8(0), // |
| 5561 B(Star), R(1), // |
| 5562 B(LdaTheHole), // |
| 5563 B(Star), R(2), // |
| 5564 B(Ldar), A(1, 3), // |
| 5565 B(Star), R(2), // |
| 5566 B(Ldar), R(1), // |
| 5567 B(Star), R(3), // |
| 5568 B(LdaZero), // |
| 5569 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot)), // |
| 5570 B(Star), R(4), // |
| 5571 B(Ldar), R(0), // |
| 5572 B(Star), R(3), // |
| 5573 B(LdaZero), // |
| 5574 B(KeyedLoadICSloppy), R(3), U8(vector->GetIndex(slot1)), // |
| 5575 B(Add), R(4), // |
| 5576 B(Return), // |
| 5577 }, |
| 5578 1, |
| 5579 {1}}, |
| 5580 }; |
| 5581 |
| 5582 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5583 Handle<BytecodeArray> bytecode_array = |
| 5584 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
| 5585 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5586 } |
| 5587 } |
5494 | 5588 |
5495 TEST(IllegalRedeclaration) { | 5589 TEST(IllegalRedeclaration) { |
5496 InitializedHandleScope handle_scope; | 5590 InitializedHandleScope handle_scope; |
5497 BytecodeGeneratorHelper helper; | 5591 BytecodeGeneratorHelper helper; |
5498 | 5592 |
5499 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); | 5593 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); |
5500 // Must adapt bytecode if this changes. | 5594 // Must adapt bytecode if this changes. |
5501 | 5595 |
5502 ExpectedSnippet<Handle<Object>, 2> snippets[] = { | 5596 ExpectedSnippet<Handle<Object>, 2> snippets[] = { |
5503 {"const a = 1; { var a = 2; }", | 5597 {"const a = 1; { var a = 2; }", |
(...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7559 Handle<BytecodeArray> bytecode_array = | 7653 Handle<BytecodeArray> bytecode_array = |
7560 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 7654 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
7561 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7655 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
7562 } | 7656 } |
7563 FLAG_harmony_do_expressions = old_flag; | 7657 FLAG_harmony_do_expressions = old_flag; |
7564 } | 7658 } |
7565 | 7659 |
7566 } // namespace interpreter | 7660 } // namespace interpreter |
7567 } // namespace internal | 7661 } // namespace internal |
7568 } // namespace v8 | 7662 } // namespace v8 |
OLD | NEW |