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/interpreter/source-position-table.h" | 7 #include "src/interpreter/source-position-table.h" |
8 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 SourcePositionTableBuilder builder(isolate(), zone()); | 49 SourcePositionTableBuilder builder(isolate(), zone()); |
50 for (int i = 0; i < arraysize(offsets); i++) { | 50 for (int i = 0; i < arraysize(offsets); i++) { |
51 builder.AddPosition(offsets[i], offsets[i], false); | 51 builder.AddPosition(offsets[i], offsets[i], false); |
52 } | 52 } |
53 CHECK(!builder.ToSourcePositionTable().is_null()); | 53 CHECK(!builder.ToSourcePositionTable().is_null()); |
54 } | 54 } |
55 | 55 |
56 TEST_F(SourcePositionTableTest, EncodeAscending) { | 56 TEST_F(SourcePositionTableTest, EncodeAscending) { |
57 SourcePositionTableBuilder builder(isolate(), zone()); | 57 SourcePositionTableBuilder builder(isolate(), zone()); |
58 | 58 |
59 int accumulator = 0; | 59 int code_offset = 0; |
| 60 int source_position = 0; |
60 for (int i = 0; i < arraysize(offsets); i++) { | 61 for (int i = 0; i < arraysize(offsets); i++) { |
61 accumulator += offsets[i]; | 62 code_offset += offsets[i]; |
| 63 source_position += offsets[i]; |
62 if (i % 2) { | 64 if (i % 2) { |
63 builder.AddPosition(accumulator, accumulator, true); | 65 builder.AddPosition(code_offset, source_position, true); |
64 } else { | 66 } else { |
65 builder.AddPosition(accumulator, accumulator, false); | 67 builder.AddPosition(code_offset, source_position, false); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 // Also test negative offsets: | 71 // Also test negative offsets for source positions: |
70 for (int i = 0; i < arraysize(offsets); i++) { | 72 for (int i = 0; i < arraysize(offsets); i++) { |
71 accumulator -= offsets[i]; | 73 code_offset += offsets[i]; |
| 74 source_position -= offsets[i]; |
72 if (i % 2) { | 75 if (i % 2) { |
73 builder.AddPosition(accumulator, accumulator, true); | 76 builder.AddPosition(code_offset, source_position, true); |
74 } else { | 77 } else { |
75 builder.AddPosition(accumulator, accumulator, false); | 78 builder.AddPosition(code_offset, source_position, false); |
76 } | 79 } |
77 } | 80 } |
78 | 81 |
79 CHECK(!builder.ToSourcePositionTable().is_null()); | 82 CHECK(!builder.ToSourcePositionTable().is_null()); |
80 } | 83 } |
81 | 84 |
82 } // namespace interpreter | 85 } // namespace interpreter |
83 } // namespace internal | 86 } // namespace internal |
84 } // namespace v8 | 87 } // namespace v8 |
OLD | NEW |