OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/api.h" | 7 #include "src/api.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/interpreter/bytecode-array-writer.h" | 9 #include "src/interpreter/bytecode-array-writer.h" |
10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
11 #include "src/interpreter/constant-array-builder.h" | 11 #include "src/interpreter/constant-array-builder.h" |
12 #include "src/interpreter/source-position-table.h" | |
13 #include "src/isolate.h" | 12 #include "src/isolate.h" |
| 13 #include "src/source-position-table.h" |
14 #include "src/utils.h" | 14 #include "src/utils.h" |
15 #include "test/unittests/interpreter/bytecode-utils.h" | 15 #include "test/unittests/interpreter/bytecode-utils.h" |
16 #include "test/unittests/test-utils.h" | 16 #include "test/unittests/test-utils.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 namespace interpreter { | 20 namespace interpreter { |
21 | 21 |
22 class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone { | 22 class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone { |
23 public: | 23 public: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); | 138 writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array()); |
139 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); | 139 CHECK_EQ(bytecodes()->size(), arraysize(bytes)); |
140 | 140 |
141 PositionTableEntry expected_positions[] = { | 141 PositionTableEntry expected_positions[] = { |
142 {0, 10, false}, {1, 55, true}, {7, 70, true}}; | 142 {0, 10, false}, {1, 55, true}, {7, 70, true}}; |
143 Handle<ByteArray> source_positions = | 143 Handle<ByteArray> source_positions = |
144 source_position_table_builder()->ToSourcePositionTable(); | 144 source_position_table_builder()->ToSourcePositionTable(); |
145 SourcePositionTableIterator source_iterator(*source_positions); | 145 SourcePositionTableIterator source_iterator(*source_positions); |
146 for (size_t i = 0; i < arraysize(expected_positions); ++i) { | 146 for (size_t i = 0; i < arraysize(expected_positions); ++i) { |
147 const PositionTableEntry& expected = expected_positions[i]; | 147 const PositionTableEntry& expected = expected_positions[i]; |
148 CHECK_EQ(source_iterator.bytecode_offset(), expected.bytecode_offset); | 148 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); |
149 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 149 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
150 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 150 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
151 source_iterator.Advance(); | 151 source_iterator.Advance(); |
152 } | 152 } |
153 CHECK(source_iterator.done()); | 153 CHECK(source_iterator.done()); |
154 } | 154 } |
155 | 155 |
156 TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { | 156 TEST_F(BytecodeArrayWriterUnittest, ComplexExample) { |
157 static const uint8_t expected_bytes[] = { | 157 static const uint8_t expected_bytes[] = { |
158 // clang-format off | 158 // clang-format off |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 for (size_t i = 0; i < arraysize(expected_bytes); ++i) { | 234 for (size_t i = 0; i < arraysize(expected_bytes); ++i) { |
235 CHECK_EQ(static_cast<int>(bytecodes()->at(i)), | 235 CHECK_EQ(static_cast<int>(bytecodes()->at(i)), |
236 static_cast<int>(expected_bytes[i])); | 236 static_cast<int>(expected_bytes[i])); |
237 } | 237 } |
238 | 238 |
239 Handle<ByteArray> source_positions = | 239 Handle<ByteArray> source_positions = |
240 source_position_table_builder()->ToSourcePositionTable(); | 240 source_position_table_builder()->ToSourcePositionTable(); |
241 SourcePositionTableIterator source_iterator(*source_positions); | 241 SourcePositionTableIterator source_iterator(*source_positions); |
242 for (size_t i = 0; i < arraysize(expected_positions); ++i) { | 242 for (size_t i = 0; i < arraysize(expected_positions); ++i) { |
243 const PositionTableEntry& expected = expected_positions[i]; | 243 const PositionTableEntry& expected = expected_positions[i]; |
244 CHECK_EQ(source_iterator.bytecode_offset(), expected.bytecode_offset); | 244 CHECK_EQ(source_iterator.code_offset(), expected.code_offset); |
245 CHECK_EQ(source_iterator.source_position(), expected.source_position); | 245 CHECK_EQ(source_iterator.source_position(), expected.source_position); |
246 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); | 246 CHECK_EQ(source_iterator.is_statement(), expected.is_statement); |
247 source_iterator.Advance(); | 247 source_iterator.Advance(); |
248 } | 248 } |
249 CHECK(source_iterator.done()); | 249 CHECK(source_iterator.done()); |
250 } | 250 } |
251 | 251 |
252 } // namespace interpreter | 252 } // namespace interpreter |
253 } // namespace internal | 253 } // namespace internal |
254 } // namespace v8 | 254 } // namespace v8 |
OLD | NEW |