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 "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 Loading... | |
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) { | |
Michael Starzinger
2015/10/09 13:19:00
nit: How would you feel about s/CheckConstant/Chec
rmcilroy
2015/10/12 17:00:15
This would require rewriting the CheckBytecodeArra
Michael Starzinger
2015/10/13 07:56:14
Acknowledged. Yep, fine with me.
| |
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 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1737 }; | 1742 }; |
1738 | 1743 |
1739 for (size_t i = 0; i < arraysize(snippets); i++) { | 1744 for (size_t i = 0; i < arraysize(snippets); i++) { |
1740 Handle<BytecodeArray> bytecode_array = | 1745 Handle<BytecodeArray> bytecode_array = |
1741 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1746 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
1742 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1747 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1743 } | 1748 } |
1744 } | 1749 } |
1745 | 1750 |
1746 | 1751 |
1752 TEST(FunctionLiterals) { | |
1753 InitializedHandleScope handle_scope; | |
1754 BytecodeGeneratorHelper helper; | |
1755 | |
1756 ExpectedSnippet<InstanceType> snippets[] = { | |
1757 {"return function(){ }", | |
1758 0, | |
1759 1, | |
1760 5, | |
1761 { | |
1762 B(LdaConstant), U8(0), // | |
1763 B(CreateClosure), U8(0), // | |
1764 B(Return) // | |
1765 }, | |
1766 1, | |
1767 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | |
1768 {"return (function(){ })()", | |
1769 2 * kPointerSize, | |
1770 1, | |
1771 14, | |
1772 { | |
1773 B(LdaConstant), U8(0), // | |
1774 B(CreateClosure), U8(0), // | |
1775 B(Star), R(0), // | |
1776 B(LdaUndefined), // | |
1777 B(Star), R(1), // | |
1778 B(Call), R(0), R(1), U8(0), // | |
1779 B(Return) // | |
1780 }, | |
1781 1, | |
1782 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | |
1783 {"return (function(x){ return x; })(1)", | |
1784 3 * kPointerSize, | |
1785 1, | |
1786 18, | |
1787 { | |
1788 B(LdaConstant), U8(0), // | |
1789 B(CreateClosure), U8(0), // | |
1790 B(Star), R(0), // | |
1791 B(LdaUndefined), // | |
1792 B(Star), R(1), // | |
1793 B(LdaSmi8), U8(1), // | |
1794 B(Star), R(2), // | |
1795 B(Call), R(0), R(1), U8(1), // | |
1796 B(Return) // | |
1797 }, | |
1798 1, | |
1799 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | |
1800 }; | |
1801 | |
1802 for (size_t i = 0; i < arraysize(snippets); i++) { | |
1803 Handle<BytecodeArray> bytecode_array = | |
1804 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | |
1805 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | |
1806 } | |
1807 } | |
1808 | |
1747 } // namespace interpreter | 1809 } // namespace interpreter |
1748 } // namespace internal | 1810 } // namespace internal |
1749 } // namespace v8 | 1811 } // namespace v8 |
OLD | NEW |