Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1531693002: [Interpreter] Implement ForIn in bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0009-phi
Patch Set: Re-work ForInPrepare. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 701 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
702 for (size_t i = 0; i < num_snippets; i++) { 702 for (size_t i = 0; i < num_snippets; i++) {
703 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 703 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
704 auto callable = tester.GetCallable<>(); 704 auto callable = tester.GetCallable<>();
705 Handle<Object> return_value = callable().ToHandleChecked(); 705 Handle<Object> return_value = callable().ToHandleChecked();
706 CHECK(return_value->SameValue(*snippets[i].return_value())); 706 CHECK(return_value->SameValue(*snippets[i].return_value()));
707 } 707 }
708 } 708 }
709 709
710 710
711 TEST(BytecodeGraphBuilderToObject) {
712 // TODO(mythria): tests for ToObject. Needs ForIn.
713 }
714
715
716 TEST(BytecodeGraphBuilderToName) { 711 TEST(BytecodeGraphBuilderToName) {
717 HandleAndZoneScope scope; 712 HandleAndZoneScope scope;
718 Isolate* isolate = scope.main_isolate(); 713 Isolate* isolate = scope.main_isolate();
719 Zone* zone = scope.main_zone(); 714 Zone* zone = scope.main_zone();
720 Factory* factory = isolate->factory(); 715 Factory* factory = isolate->factory();
721 716
722 ExpectedSnippet<0> snippets[] = { 717 ExpectedSnippet<0> snippets[] = {
723 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", 718 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;",
724 {factory->NewNumberFromInt(10)}}, 719 {factory->NewNumberFromInt(10)}},
725 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", 720 {"var a = 20; var obj = {[a] : 10}; return obj['20'];",
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1826 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1832 snippets[i].code_snippet, kFunctionName); 1827 snippets[i].code_snippet, kFunctionName);
1833 1828
1834 BytecodeGraphTester tester(isolate, zone, script.start()); 1829 BytecodeGraphTester tester(isolate, zone, script.start());
1835 auto callable = tester.GetCallable<>(); 1830 auto callable = tester.GetCallable<>();
1836 Handle<Object> return_value = callable().ToHandleChecked(); 1831 Handle<Object> return_value = callable().ToHandleChecked();
1837 CHECK(return_value->SameValue(*snippets[i].return_value())); 1832 CHECK(return_value->SameValue(*snippets[i].return_value()));
1838 } 1833 }
1839 } 1834 }
1840 1835
1836
1837 TEST(BytecodeGraphBuilderForIn) {
1838 HandleAndZoneScope scope;
1839 Isolate* isolate = scope.main_isolate();
1840 Zone* zone = scope.main_zone();
1841 Factory* factory = isolate->factory();
1842 ExpectedSnippet<0> snippets[] = {
1843 {"var last = 0;\n"
1844 "for (var x in [ 10, 20, 30 ]) {\n"
1845 " last = x;\n"
1846 "}\n"
1847 "return +last;",
1848 {factory->NewNumberFromInt(2)}},
1849 {"var first = -1;\n"
1850 "for (var x in [ 10, 20, 30 ]) {\n"
1851 " first = +x;\n"
1852 " if (first > 0) break;\n"
1853 "}\n"
1854 "return first;",
1855 {factory->NewNumberFromInt(1)}},
1856 {"var first = -1;\n"
1857 "for (var x in [ 10, 20, 30 ]) {\n"
1858 " if (first >= 0) continue;\n"
1859 " first = x;\n"
1860 "}\n"
1861 "return +first;",
1862 {factory->NewNumberFromInt(0)}},
1863 {"var sum = 0;\n"
1864 "for (var x in [ 10, 20, 30 ]) {\n"
1865 " for (var y in [ 11, 22, 33, 44, 55, 66, 77 ]) {\n"
1866 " sum += 1;\n"
1867 " }\n"
1868 "}\n"
1869 "return sum;",
1870 {factory->NewNumberFromInt(21)}},
1871 // TODO(oth): test break/continue nested.
1872 };
1873
1874 for (size_t i = 0; i < arraysize(snippets); i++) {
1875 ScopedVector<char> script(1024);
1876 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1877 snippets[i].code_snippet, kFunctionName);
1878
1879 BytecodeGraphTester tester(isolate, zone, script.start());
1880 auto callable = tester.GetCallable<>();
1881 Handle<Object> return_value = callable().ToHandleChecked();
1882 CHECK(return_value->SameValue(*snippets[i].return_value()));
1883 }
1884 }
1885
1886
1841 } // namespace compiler 1887 } // namespace compiler
1842 } // namespace internal 1888 } // namespace internal
1843 } // namespace v8 1889 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698