Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/v8.h" | |
| 6 | |
| 7 #include "src/interpreter/source-position-table.h" | |
| 8 #include "test/unittests/test-utils.h" | |
| 9 | |
| 10 namespace v8 { | |
| 11 namespace internal { | |
| 12 namespace interpreter { | |
| 13 | |
| 14 class SourcePositionTableTest : public TestWithIsolateAndZone { | |
| 15 public: | |
| 16 SourcePositionTableTest() {} | |
| 17 ~SourcePositionTableTest() override {} | |
| 18 }; | |
| 19 | |
| 20 // Some random offsets, mostly at 'suspicious' bit boundaries. | |
| 21 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, | |
| 22 33, 62, 63, 64, 65, 126, 127, 128, | |
| 23 129, 250, 1000, 9999, 12000, 31415926}; | |
|
Yang
2016/02/17 19:54:51
Since we are encoding the delta, these are not rea
vogelheim
2016/02/18 13:06:09
I disagree. Your feedback is correct for the first
Yang
2016/02/19 08:28:02
I see. Ok.
| |
| 24 | |
| 25 TEST_F(SourcePositionTableTest, EncodeStatement) { | |
| 26 SourcePositionTableBuilder builder(isolate(), zone()); | |
| 27 for (int i = 0; i < arraysize(offsets); i++) { | |
| 28 builder.AddStatementPosition(offsets[i], offsets[i]); | |
| 29 } | |
| 30 | |
| 31 // To test correctness, we rely on the assertions in ToSourcePositionTable(). | |
| 32 // (Also below.) | |
| 33 CHECK(!builder.ToSourcePositionTable().is_null()); | |
| 34 } | |
| 35 | |
| 36 TEST_F(SourcePositionTableTest, EncodeExpression) { | |
| 37 SourcePositionTableBuilder builder(isolate(), zone()); | |
| 38 for (int i = 0; i < arraysize(offsets); i++) { | |
| 39 builder.AddExpressionPosition(offsets[i], offsets[i]); | |
| 40 } | |
| 41 CHECK(!builder.ToSourcePositionTable().is_null()); | |
| 42 } | |
| 43 | |
| 44 TEST_F(SourcePositionTableTest, EncodeAscending) { | |
| 45 SourcePositionTableBuilder builder(isolate(), zone()); | |
| 46 | |
| 47 int accumulator = 0; | |
| 48 for (int i = 0; i < arraysize(offsets); i++) { | |
| 49 accumulator += offsets[i]; | |
| 50 if (i % 2) { | |
| 51 builder.AddStatementPosition(accumulator, accumulator); | |
| 52 } else { | |
| 53 builder.AddExpressionPosition(accumulator, accumulator); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // Also test negative offsets: | |
| 58 for (int i = 0; i < arraysize(offsets); i++) { | |
| 59 accumulator -= offsets[i]; | |
| 60 if (i % 2) { | |
| 61 builder.AddStatementPosition(accumulator, accumulator); | |
| 62 } else { | |
| 63 builder.AddExpressionPosition(accumulator, accumulator); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 CHECK(!builder.ToSourcePositionTable().is_null()); | |
| 68 } | |
| 69 | |
| 70 TEST_F(SourcePositionTableTest, EncodeRevert) { | |
| 71 SourcePositionTableBuilder builder(isolate(), zone()); | |
| 72 | |
| 73 int accumulator = 0; | |
| 74 for (int i = 0; i < arraysize(offsets); i++) { | |
| 75 accumulator += offsets[i]; | |
| 76 builder.AddStatementPosition(accumulator, accumulator); | |
| 77 | |
| 78 // Every other position is reverted. Among these, every other position | |
| 79 // is reverted with the same bytecode offset. | |
| 80 if (i % 4 == 1) { | |
| 81 builder.RevertPosition(accumulator); | |
| 82 } else if (i % 4 == 3) { | |
| 83 builder.RevertPosition(accumulator + 1); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 CHECK(!builder.ToSourcePositionTable().is_null()); | |
| 88 } | |
| 89 | |
| 90 } // namespace interpreter | |
| 91 } // namespace internal | |
| 92 } // namespace v8 | |
| OLD | NEW |