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 7531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7542 }}}; | 7542 }}}; |
7543 | 7543 |
7544 for (size_t i = 0; i < arraysize(snippets); ++i) { | 7544 for (size_t i = 0; i < arraysize(snippets); ++i) { |
7545 std::string body = prologue + snippets[i].code_snippet; | 7545 std::string body = prologue + snippets[i].code_snippet; |
7546 Handle<BytecodeArray> bytecode_array = | 7546 Handle<BytecodeArray> bytecode_array = |
7547 helper.MakeBytecodeForFunctionBody(body.c_str()); | 7547 helper.MakeBytecodeForFunctionBody(body.c_str()); |
7548 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7548 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
7549 } | 7549 } |
7550 } | 7550 } |
7551 | 7551 |
| 7552 TEST(DoExpression) { |
| 7553 bool old_flag = FLAG_harmony_do_expressions; |
| 7554 FLAG_harmony_do_expressions = true; |
| 7555 |
| 7556 InitializedHandleScope handle_scope; |
| 7557 BytecodeGeneratorHelper helper; |
| 7558 |
| 7559 ExpectedSnippet<const char*> snippets[] = { |
| 7560 {"var a = do { }; return a;", |
| 7561 2 * kPointerSize, |
| 7562 1, |
| 7563 5, |
| 7564 { |
| 7565 B(Ldar), R(0), // |
| 7566 B(Star), R(1), // |
| 7567 B(Return) // |
| 7568 }, |
| 7569 0}, |
| 7570 {"var a = do { var x = 100; }; return a;", |
| 7571 3 * kPointerSize, |
| 7572 1, |
| 7573 10, |
| 7574 { |
| 7575 B(LdaSmi8), U8(100), // |
| 7576 B(Star), R(1), // |
| 7577 B(LdaUndefined), // |
| 7578 B(Star), R(0), // |
| 7579 B(Star), R(2), // |
| 7580 B(Return) // |
| 7581 }, |
| 7582 0}, |
| 7583 {"while(true) { var a = 10; a = do { ++a; break; }; a = 20; }", |
| 7584 2 * kPointerSize, |
| 7585 1, |
| 7586 24, |
| 7587 { |
| 7588 B(LdaSmi8), U8(10), // |
| 7589 B(Star), R(1), // |
| 7590 B(ToNumber), // |
| 7591 B(Inc), // |
| 7592 B(Star), R(1), // |
| 7593 B(Star), R(0), // |
| 7594 B(Jump), U8(12), // |
| 7595 B(Ldar), R(0), // |
| 7596 B(Star), R(1), // |
| 7597 B(LdaSmi8), U8(20), // |
| 7598 B(Star), R(1), // |
| 7599 B(Jump), U8(-20), // |
| 7600 B(LdaUndefined), // |
| 7601 B(Return), // |
| 7602 }, |
| 7603 0}, |
| 7604 }; |
| 7605 |
| 7606 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7607 Handle<BytecodeArray> bytecode_array = |
| 7608 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7609 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7610 } |
| 7611 FLAG_harmony_do_expressions = old_flag; |
| 7612 } |
| 7613 |
7552 } // namespace interpreter | 7614 } // namespace interpreter |
7553 } // namespace internal | 7615 } // namespace internal |
7554 } // namespace v8 | 7616 } // namespace v8 |
OLD | NEW |