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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "src/compiler/pipeline.h" | 7 #include "src/compiler/pipeline.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/interpreter/bytecode-array-builder.h" | 10 #include "src/interpreter/bytecode-array-builder.h" |
(...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2596 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); | 2596 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
2597 static const int results[] = {11, 12, 2}; | 2597 static const int results[] = {11, 12, 2}; |
2598 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 2598 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
2599 } | 2599 } |
2600 } | 2600 } |
2601 } | 2601 } |
2602 | 2602 |
2603 TEST(BytecodeGraphBuilderDoExpressions) { | 2603 TEST(BytecodeGraphBuilderDoExpressions) { |
2604 bool old_flag = FLAG_harmony_do_expressions; | 2604 bool old_flag = FLAG_harmony_do_expressions; |
2605 FLAG_harmony_do_expressions = true; | 2605 FLAG_harmony_do_expressions = true; |
2606 | |
2607 HandleAndZoneScope scope; | 2606 HandleAndZoneScope scope; |
2608 Isolate* isolate = scope.main_isolate(); | 2607 Isolate* isolate = scope.main_isolate(); |
2609 Zone* zone = scope.main_zone(); | 2608 Zone* zone = scope.main_zone(); |
2610 Factory* factory = isolate->factory(); | 2609 Factory* factory = isolate->factory(); |
2611 ExpectedSnippet<0> snippets[] = { | 2610 ExpectedSnippet<0> snippets[] = { |
2612 {"var a = do {}; return a;", {factory->undefined_value()}}, | 2611 {"var a = do {}; return a;", {factory->undefined_value()}}, |
2613 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, | 2612 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
2614 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, | 2613 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
2615 {"var a = do { var x = 100; x++; }; return a;", | 2614 {"var a = do { var x = 100; x++; }; return a;", |
2616 {handle(Smi::FromInt(100), isolate)}}, | 2615 {handle(Smi::FromInt(100), isolate)}}, |
2617 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" | 2616 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" |
2618 "return i;", | 2617 "return i;", |
2619 {handle(Smi::FromInt(3), isolate)}}, | 2618 {handle(Smi::FromInt(3), isolate)}}, |
2620 }; | 2619 }; |
2621 | 2620 |
2622 for (size_t i = 0; i < arraysize(snippets); i++) { | 2621 for (size_t i = 0; i < arraysize(snippets); i++) { |
2623 ScopedVector<char> script(1024); | 2622 ScopedVector<char> script(1024); |
2624 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2623 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2625 snippets[i].code_snippet, kFunctionName); | 2624 snippets[i].code_snippet, kFunctionName); |
2626 | 2625 |
2627 BytecodeGraphTester tester(isolate, zone, script.start()); | 2626 BytecodeGraphTester tester(isolate, zone, script.start()); |
2628 auto callable = tester.GetCallable<>(); | 2627 auto callable = tester.GetCallable<>(); |
2629 Handle<Object> return_value = callable().ToHandleChecked(); | 2628 Handle<Object> return_value = callable().ToHandleChecked(); |
2630 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2629 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2631 } | 2630 } |
2632 | 2631 |
2633 FLAG_harmony_do_expressions = old_flag; | 2632 FLAG_harmony_do_expressions = old_flag; |
2634 } | 2633 } |
2635 | 2634 |
2635 TEST(JumpOnHole) { | |
rmcilroy
2016/02/03 12:28:26
Could you replicate the test-interpreter tests her
mythria
2016/02/04 10:28:53
Done. Now I have a 1500 line cl :)
| |
2636 HandleAndZoneScope scope; | |
2637 Isolate* isolate = scope.main_isolate(); | |
2638 Zone* zone = scope.main_zone(); | |
2639 Factory* factory = isolate->factory(); | |
2640 // TODO(mythria): Add tests to check JumpIfHole. Initializing 'this' via super | |
2641 // calls uses JumpIfHole. | |
2642 ExpectedSnippet<0> snippets[] = { | |
2643 {"let x = 1; x = 2; return x;", {factory->NewNumberFromInt(2)}}, | |
2644 {"const x = 3; return x;", {factory->NewNumberFromInt(3)}}, | |
2645 }; | |
2646 | |
2647 for (size_t i = 0; i < arraysize(snippets); i++) { | |
2648 ScopedVector<char> script(1024); | |
2649 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | |
2650 snippets[i].code_snippet, kFunctionName); | |
2651 | |
2652 BytecodeGraphTester tester(isolate, zone, script.start()); | |
2653 auto callable = tester.GetCallable<>(); | |
2654 Handle<Object> return_value = callable().ToHandleChecked(); | |
2655 CHECK(return_value->SameValue(*snippets[i].return_value())); | |
2656 } | |
2657 } | |
2658 | |
2636 } // namespace compiler | 2659 } // namespace compiler |
2637 } // namespace internal | 2660 } // namespace internal |
2638 } // namespace v8 | 2661 } // namespace v8 |
OLD | NEW |