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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1396693003: [Interpreter] Add function literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_newcontext
Patch Set: Review comments Created 5 years, 2 months 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
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(expected); 114 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(expected);
115 CHECK(String::cast(actual)->Equals(*expected_string)); 115 CHECK(String::cast(actual)->Equals(*expected_string));
116 } 116 }
117 117
118 118
119 static void CheckConstant(Handle<Object> expected, Object* actual) { 119 static void CheckConstant(Handle<Object> expected, Object* actual) {
120 CHECK(actual == *expected || expected->StrictEquals(actual)); 120 CHECK(actual == *expected || expected->StrictEquals(actual));
121 } 121 }
122 122
123 123
124 static void CheckConstant(InstanceType expected, Object* actual) {
125 CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type());
126 }
127
128
124 template <typename T> 129 template <typename T>
125 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected, 130 static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected,
126 Handle<BytecodeArray> actual, 131 Handle<BytecodeArray> actual,
127 bool has_unknown = false) { 132 bool has_unknown = false) {
128 CHECK_EQ(actual->frame_size(), expected.frame_size); 133 CHECK_EQ(actual->frame_size(), expected.frame_size);
129 CHECK_EQ(actual->parameter_count(), expected.parameter_count); 134 CHECK_EQ(actual->parameter_count(), expected.parameter_count);
130 CHECK_EQ(actual->length(), expected.bytecode_length); 135 CHECK_EQ(actual->length(), expected.bytecode_length);
131 if (expected.constant_count != -1) { 136 if (expected.constant_count != -1) {
132 if (expected.constant_count == 0) { 137 if (expected.constant_count == 0) {
133 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array()); 138 CHECK_EQ(actual->constant_pool(), CcTest::heap()->empty_fixed_array());
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 }; 1811 };
1807 1812
1808 for (size_t i = 0; i < arraysize(snippets); i++) { 1813 for (size_t i = 0; i < arraysize(snippets); i++) {
1809 Handle<BytecodeArray> bytecode_array = 1814 Handle<BytecodeArray> bytecode_array =
1810 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1815 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1811 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1816 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1812 } 1817 }
1813 } 1818 }
1814 1819
1815 1820
1821 TEST(FunctionLiterals) {
1822 InitializedHandleScope handle_scope;
1823 BytecodeGeneratorHelper helper;
1824
1825 ExpectedSnippet<InstanceType> snippets[] = {
1826 {"return function(){ }",
1827 0,
1828 1,
1829 5,
1830 {
1831 B(LdaConstant), U8(0), //
1832 B(CreateClosure), U8(0), //
1833 B(Return) //
1834 },
1835 1,
1836 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
1837 {"return (function(){ })()",
1838 2 * kPointerSize,
1839 1,
1840 14,
1841 {
1842 B(LdaUndefined), //
1843 B(Star), R(1), //
1844 B(LdaConstant), U8(0), //
1845 B(CreateClosure), U8(0), //
1846 B(Star), R(0), //
1847 B(Call), R(0), R(1), U8(0), //
1848 B(Return) //
1849 },
1850 1,
1851 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
1852 {"return (function(x){ return x; })(1)",
1853 3 * kPointerSize,
1854 1,
1855 18,
1856 {
1857 B(LdaUndefined), //
1858 B(Star), R(1), //
1859 B(LdaConstant), U8(0), //
1860 B(CreateClosure), U8(0), //
1861 B(Star), R(0), //
1862 B(LdaSmi8), U8(1), //
1863 B(Star), R(2), //
1864 B(Call), R(0), R(1), U8(1), //
1865 B(Return) //
1866 },
1867 1,
1868 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
1869 };
1870
1871 for (size_t i = 0; i < arraysize(snippets); i++) {
1872 Handle<BytecodeArray> bytecode_array =
1873 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1874 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1875 }
1876 }
1877
1816 } // namespace interpreter 1878 } // namespace interpreter
1817 } // namespace internal 1879 } // namespace internal
1818 } // namespace v8 1880 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698