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 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 BytecodeGraphTester tester(isolate, zone, script.c_str()); | 2419 BytecodeGraphTester tester(isolate, zone, script.c_str()); |
2420 auto callable = tester.GetCallable<Handle<Object>>(); | 2420 auto callable = tester.GetCallable<Handle<Object>>(); |
2421 Handle<Object> return_val = | 2421 Handle<Object> return_val = |
2422 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); | 2422 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
2423 static const int results[] = {11, 12, 2}; | 2423 static const int results[] = {11, 12, 2}; |
2424 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 2424 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
2425 } | 2425 } |
2426 } | 2426 } |
2427 } | 2427 } |
2428 | 2428 |
| 2429 TEST(BytecodeGraphBuilderDoExpressions) { |
| 2430 bool old_flag = FLAG_harmony_do_expressions; |
| 2431 FLAG_harmony_do_expressions = true; |
| 2432 |
| 2433 HandleAndZoneScope scope; |
| 2434 Isolate* isolate = scope.main_isolate(); |
| 2435 Zone* zone = scope.main_zone(); |
| 2436 Factory* factory = isolate->factory(); |
| 2437 ExpectedSnippet<0> snippets[] = { |
| 2438 {"var a = do {}; return a;", {factory->undefined_value()}}, |
| 2439 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
| 2440 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
| 2441 {"var a = do { var x = 100; x++; }; return a;", |
| 2442 {handle(Smi::FromInt(100), isolate)}}, |
| 2443 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" |
| 2444 "return i;", |
| 2445 {handle(Smi::FromInt(3), isolate)}}, |
| 2446 }; |
| 2447 |
| 2448 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2449 ScopedVector<char> script(1024); |
| 2450 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
| 2451 snippets[i].code_snippet, kFunctionName); |
| 2452 |
| 2453 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 2454 auto callable = tester.GetCallable<>(); |
| 2455 Handle<Object> return_value = callable().ToHandleChecked(); |
| 2456 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 2457 } |
| 2458 |
| 2459 FLAG_harmony_do_expressions = old_flag; |
| 2460 } |
| 2461 |
2429 } // namespace compiler | 2462 } // namespace compiler |
2430 } // namespace internal | 2463 } // namespace internal |
2431 } // namespace v8 | 2464 } // namespace v8 |
OLD | NEW |