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 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1831 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1832 snippets[i].code_snippet, kFunctionName); | 1832 snippets[i].code_snippet, kFunctionName); |
1833 | 1833 |
1834 BytecodeGraphTester tester(isolate, zone, script.start()); | 1834 BytecodeGraphTester tester(isolate, zone, script.start()); |
1835 auto callable = tester.GetCallable<>(); | 1835 auto callable = tester.GetCallable<>(); |
1836 Handle<Object> return_value = callable().ToHandleChecked(); | 1836 Handle<Object> return_value = callable().ToHandleChecked(); |
1837 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1837 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1838 } | 1838 } |
1839 } | 1839 } |
1840 | 1840 |
| 1841 |
| 1842 TEST(BytecodeGraphBuilderForIn) { |
| 1843 HandleAndZoneScope scope; |
| 1844 Isolate* isolate = scope.main_isolate(); |
| 1845 Zone* zone = scope.main_zone(); |
| 1846 Factory* factory = isolate->factory(); |
| 1847 ExpectedSnippet<0> snippets[] = { |
| 1848 {"var last = 0;\n" |
| 1849 "for (var x in [ 10, 20, 30 ]) {\n" |
| 1850 " last = x;\n" |
| 1851 "}\n" |
| 1852 "return +last;", |
| 1853 {factory->NewNumberFromInt(2)}}, |
| 1854 {"var first = -1;\n" |
| 1855 "for (var x in [ 10, 20, 30 ]) {\n" |
| 1856 " first = +x;\n" |
| 1857 " if (first > 0) break;\n" |
| 1858 "}\n" |
| 1859 "return first;", |
| 1860 {factory->NewNumberFromInt(1)}}, |
| 1861 {"var first = -1;\n" |
| 1862 "for (var x in [ 10, 20, 30 ]) {\n" |
| 1863 " if (first >= 0) continue;\n" |
| 1864 " first = x;\n" |
| 1865 "}\n" |
| 1866 "return +first;", |
| 1867 {factory->NewNumberFromInt(0)}}, |
| 1868 {"var sum = 0;\n" |
| 1869 "for (var x in [ 10, 20, 30 ]) {\n" |
| 1870 " for (var y in [ 11, 22, 33, 44, 55, 66, 77 ]) {\n" |
| 1871 " sum += 1;\n" |
| 1872 " }\n" |
| 1873 "}\n" |
| 1874 "return sum;", |
| 1875 {factory->NewNumberFromInt(21)}}, |
| 1876 // TODO(oth): test break/continue nested. |
| 1877 }; |
| 1878 |
| 1879 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1880 ScopedVector<char> script(1024); |
| 1881 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
| 1882 snippets[i].code_snippet, kFunctionName); |
| 1883 |
| 1884 BytecodeGraphTester tester(isolate, zone, script.start()); |
| 1885 auto callable = tester.GetCallable<>(); |
| 1886 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1887 CHECK(return_value->SameValue(*snippets[i].return_value())); |
| 1888 } |
| 1889 } |
| 1890 |
| 1891 |
1841 } // namespace compiler | 1892 } // namespace compiler |
1842 } // namespace internal | 1893 } // namespace internal |
1843 } // namespace v8 | 1894 } // namespace v8 |
OLD | NEW |