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/objects.h" |
7 #include "src/source-position-table.h" | 8 #include "src/source-position-table.h" |
8 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 namespace interpreter { | 13 namespace interpreter { |
13 | 14 |
14 class SourcePositionTableTest : public TestWithIsolateAndZone { | 15 class SourcePositionTableTest : public TestWithIsolateAndZone { |
15 public: | 16 public: |
16 SourcePositionTableTest() {} | 17 SourcePositionTableTest() {} |
17 ~SourcePositionTableTest() override {} | 18 ~SourcePositionTableTest() override {} |
18 }; | 19 }; |
19 | 20 |
20 // Some random offsets, mostly at 'suspicious' bit boundaries. | 21 // Some random offsets, mostly at 'suspicious' bit boundaries. |
21 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, | 22 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, |
22 33, 62, 63, 64, 65, 126, 127, 128, | 23 33, 62, 63, 64, 65, 126, 127, 128, |
23 129, 250, 1000, 9999, 12000, 31415926}; | 24 129, 250, 1000, 9999, 12000, 31415926}; |
24 | 25 |
25 TEST_F(SourcePositionTableTest, EncodeStatement) { | 26 TEST_F(SourcePositionTableTest, EncodeStatement) { |
26 SourcePositionTableBuilder builder(isolate(), zone()); | 27 SourcePositionTableBuilder builder(zone()); |
27 for (int i = 0; i < arraysize(offsets); i++) { | 28 for (int i = 0; i < arraysize(offsets); i++) { |
28 builder.AddPosition(offsets[i], offsets[i], true); | 29 builder.AddPosition(offsets[i], offsets[i], true); |
29 } | 30 } |
30 | 31 |
31 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 32 // To test correctness, we rely on the assertions in ToSourcePositionTable(). |
32 // (Also below.) | 33 // (Also below.) |
33 CHECK(!builder.ToSourcePositionTable().is_null()); | 34 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) |
| 35 .is_null()); |
34 } | 36 } |
35 | 37 |
36 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) { | 38 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) { |
37 SourcePositionTableBuilder builder(isolate(), zone()); | 39 SourcePositionTableBuilder builder(zone()); |
38 for (int i = 0; i < arraysize(offsets); i++) { | 40 for (int i = 0; i < arraysize(offsets); i++) { |
39 builder.AddPosition(offsets[i], offsets[i], true); | 41 builder.AddPosition(offsets[i], offsets[i], true); |
40 builder.AddPosition(offsets[i], offsets[i] + 1, true); | 42 builder.AddPosition(offsets[i], offsets[i] + 1, true); |
41 } | 43 } |
42 | 44 |
43 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | 45 // To test correctness, we rely on the assertions in ToSourcePositionTable(). |
44 // (Also below.) | 46 // (Also below.) |
45 CHECK(!builder.ToSourcePositionTable().is_null()); | 47 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) |
| 48 .is_null()); |
46 } | 49 } |
47 | 50 |
48 TEST_F(SourcePositionTableTest, EncodeExpression) { | 51 TEST_F(SourcePositionTableTest, EncodeExpression) { |
49 SourcePositionTableBuilder builder(isolate(), zone()); | 52 SourcePositionTableBuilder builder(zone()); |
50 for (int i = 0; i < arraysize(offsets); i++) { | 53 for (int i = 0; i < arraysize(offsets); i++) { |
51 builder.AddPosition(offsets[i], offsets[i], false); | 54 builder.AddPosition(offsets[i], offsets[i], false); |
52 } | 55 } |
53 CHECK(!builder.ToSourcePositionTable().is_null()); | 56 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) |
| 57 .is_null()); |
54 } | 58 } |
55 | 59 |
56 TEST_F(SourcePositionTableTest, EncodeAscending) { | 60 TEST_F(SourcePositionTableTest, EncodeAscending) { |
57 SourcePositionTableBuilder builder(isolate(), zone()); | 61 SourcePositionTableBuilder builder(zone()); |
58 | 62 |
59 int code_offset = 0; | 63 int code_offset = 0; |
60 int source_position = 0; | 64 int source_position = 0; |
61 for (int i = 0; i < arraysize(offsets); i++) { | 65 for (int i = 0; i < arraysize(offsets); i++) { |
62 code_offset += offsets[i]; | 66 code_offset += offsets[i]; |
63 source_position += offsets[i]; | 67 source_position += offsets[i]; |
64 if (i % 2) { | 68 if (i % 2) { |
65 builder.AddPosition(code_offset, source_position, true); | 69 builder.AddPosition(code_offset, source_position, true); |
66 } else { | 70 } else { |
67 builder.AddPosition(code_offset, source_position, false); | 71 builder.AddPosition(code_offset, source_position, false); |
68 } | 72 } |
69 } | 73 } |
70 | 74 |
71 // Also test negative offsets for source positions: | 75 // Also test negative offsets for source positions: |
72 for (int i = 0; i < arraysize(offsets); i++) { | 76 for (int i = 0; i < arraysize(offsets); i++) { |
73 code_offset += offsets[i]; | 77 code_offset += offsets[i]; |
74 source_position -= offsets[i]; | 78 source_position -= offsets[i]; |
75 if (i % 2) { | 79 if (i % 2) { |
76 builder.AddPosition(code_offset, source_position, true); | 80 builder.AddPosition(code_offset, source_position, true); |
77 } else { | 81 } else { |
78 builder.AddPosition(code_offset, source_position, false); | 82 builder.AddPosition(code_offset, source_position, false); |
79 } | 83 } |
80 } | 84 } |
81 | 85 |
82 CHECK(!builder.ToSourcePositionTable().is_null()); | 86 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) |
| 87 .is_null()); |
83 } | 88 } |
84 | 89 |
85 } // namespace interpreter | 90 } // namespace interpreter |
86 } // namespace internal | 91 } // namespace internal |
87 } // namespace v8 | 92 } // namespace v8 |
OLD | NEW |