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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 Handle<JSFunction> function_; | 57 Handle<JSFunction> function_; |
58 }; | 58 }; |
59 | 59 |
60 | 60 |
61 class BytecodeGraphTester { | 61 class BytecodeGraphTester { |
62 public: | 62 public: |
63 BytecodeGraphTester(Isolate* isolate, Zone* zone, const char* script) | 63 BytecodeGraphTester(Isolate* isolate, Zone* zone, const char* script) |
64 : isolate_(isolate), zone_(zone), script_(script) { | 64 : isolate_(isolate), zone_(zone), script_(script) { |
65 i::FLAG_ignition = true; | 65 i::FLAG_ignition = true; |
66 i::FLAG_always_opt = false; | 66 i::FLAG_always_opt = false; |
| 67 i::FLAG_allow_natives_syntax = true; |
67 // Set ignition filter flag via SetFlagsFromString to avoid double-free | 68 // Set ignition filter flag via SetFlagsFromString to avoid double-free |
68 // (or potential leak with StrDup() based on ownership confusion). | 69 // (or potential leak with StrDup() based on ownership confusion). |
69 ScopedVector<char> ignition_filter(64); | 70 ScopedVector<char> ignition_filter(64); |
70 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); | 71 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); |
71 FlagList::SetFlagsFromString(ignition_filter.start(), | 72 FlagList::SetFlagsFromString(ignition_filter.start(), |
72 ignition_filter.length()); | 73 ignition_filter.length()); |
73 // Ensure handler table is generated. | 74 // Ensure handler table is generated. |
74 isolate->interpreter()->Initialize(); | 75 isolate->interpreter()->Initialize(); |
75 } | 76 } |
76 virtual ~BytecodeGraphTester() {} | 77 virtual ~BytecodeGraphTester() {} |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 529 |
529 BytecodeGraphTester tester(isolate, zone, script.start()); | 530 BytecodeGraphTester tester(isolate, zone, script.start()); |
530 auto callable = tester.GetCallable<Handle<Object>>(); | 531 auto callable = tester.GetCallable<Handle<Object>>(); |
531 Handle<Object> return_value = | 532 Handle<Object> return_value = |
532 callable(snippets[i].parameter(0)).ToHandleChecked(); | 533 callable(snippets[i].parameter(0)).ToHandleChecked(); |
533 CHECK(return_value->SameValue(*snippets[i].return_value())); | 534 CHECK(return_value->SameValue(*snippets[i].return_value())); |
534 } | 535 } |
535 } | 536 } |
536 | 537 |
537 | 538 |
| 539 TEST(BytecodeGraphBuilderCallNew) { |
| 540 HandleAndZoneScope scope; |
| 541 Isolate* isolate = scope.main_isolate(); |
| 542 Zone* zone = scope.main_zone(); |
| 543 Factory* factory = isolate->factory(); |
| 544 |
| 545 ExpectedSnippet<0> snippets[] = { |
| 546 {"function counter() { this.count = 20; }\n" |
| 547 "function f() {\n" |
| 548 " var c = new counter();\n" |
| 549 " return c.count;\n" |
| 550 "}; f()", |
| 551 {factory->NewNumberFromInt(20)}}, |
| 552 {"function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
| 553 "function f() {\n" |
| 554 " var c = new counter(6);\n" |
| 555 " return c.count + c.x;\n" |
| 556 "}; f()", |
| 557 {factory->NewNumberFromInt(23)}}, |
| 558 {"function counter(arg0, arg1) {\n" |
| 559 " this.count = 17; this.x = arg0; this.y = arg1;\n" |
| 560 "}\n" |
| 561 "function f() {\n" |
| 562 " var c = new counter(3, 5);\n" |
| 563 " return c.count + c.x + c.y;\n" |
| 564 "}; f()", |
| 565 {factory->NewNumberFromInt(25)}}, |
| 566 }; |
| 567 |
| 568 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 569 for (size_t i = 0; i < num_snippets; i++) { |
| 570 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
| 571 auto callable = tester.GetCallable<>(); |
| 572 Handle<Object> return_value = callable().ToHandleChecked(); |
| 573 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 574 } |
| 575 } |
| 576 |
| 577 |
| 578 TEST(BytecodeGraphBuilderCallRuntime) { |
| 579 HandleAndZoneScope scope; |
| 580 Isolate* isolate = scope.main_isolate(); |
| 581 Zone* zone = scope.main_zone(); |
| 582 Factory* factory = isolate->factory(); |
| 583 |
| 584 ExpectedSnippet<1> snippets[] = { |
| 585 {"function f(arg0) { return %MaxSmi(); }\nf()", |
| 586 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}}, |
| 587 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)", |
| 588 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
| 589 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)", |
| 590 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}}, |
| 591 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])", |
| 592 {factory->NewNumberFromInt(3), |
| 593 BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
| 594 }; |
| 595 |
| 596 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
| 597 for (size_t i = 0; i < num_snippets; i++) { |
| 598 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
| 599 auto callable = tester.GetCallable<Handle<Object>>(); |
| 600 Handle<Object> return_value = |
| 601 callable(snippets[i].parameter(0)).ToHandleChecked(); |
| 602 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 603 } |
| 604 } |
| 605 |
| 606 |
538 TEST(BytecodeGraphBuilderGlobals) { | 607 TEST(BytecodeGraphBuilderGlobals) { |
539 HandleAndZoneScope scope; | 608 HandleAndZoneScope scope; |
540 Isolate* isolate = scope.main_isolate(); | 609 Isolate* isolate = scope.main_isolate(); |
541 Zone* zone = scope.main_zone(); | 610 Zone* zone = scope.main_zone(); |
542 Factory* factory = isolate->factory(); | 611 Factory* factory = isolate->factory(); |
543 | 612 |
544 ExpectedSnippet<0> snippets[] = { | 613 ExpectedSnippet<0> snippets[] = { |
545 {"var global = 321;\n function f() { return global; };\n f();", | 614 {"var global = 321;\n function f() { return global; };\n f();", |
546 {factory->NewNumberFromInt(321)}}, | 615 {factory->NewNumberFromInt(321)}}, |
547 {"var global = 321;\n" | 616 {"var global = 321;\n" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 auto callable = tester.GetCallable<Handle<Object>>(); | 758 auto callable = tester.GetCallable<Handle<Object>>(); |
690 Handle<Object> return_value = | 759 Handle<Object> return_value = |
691 callable(snippets[i].parameter(0)).ToHandleChecked(); | 760 callable(snippets[i].parameter(0)).ToHandleChecked(); |
692 CHECK(return_value->SameValue(*snippets[i].return_value())); | 761 CHECK(return_value->SameValue(*snippets[i].return_value())); |
693 } | 762 } |
694 } | 763 } |
695 | 764 |
696 } // namespace compiler | 765 } // namespace compiler |
697 } // namespace internal | 766 } // namespace internal |
698 } // namespace v8 | 767 } // namespace v8 |
OLD | NEW |