2016-02-24 17:12:31 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
2016-06-28 05:51:09 +00:00
|
|
|
#include "src/source-position-table.h"
|
2016-02-24 17:12:31 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
|
|
|
class SourcePositionTableTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
|
|
|
SourcePositionTableTest() {}
|
|
|
|
~SourcePositionTableTest() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Some random offsets, mostly at 'suspicious' bit boundaries.
|
|
|
|
static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32,
|
|
|
|
33, 62, 63, 64, 65, 126, 127, 128,
|
|
|
|
129, 250, 1000, 9999, 12000, 31415926};
|
|
|
|
|
|
|
|
TEST_F(SourcePositionTableTest, EncodeStatement) {
|
|
|
|
SourcePositionTableBuilder builder(isolate(), zone());
|
|
|
|
for (int i = 0; i < arraysize(offsets); i++) {
|
2016-05-12 19:18:07 +00:00
|
|
|
builder.AddPosition(offsets[i], offsets[i], true);
|
2016-02-24 17:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// To test correctness, we rely on the assertions in ToSourcePositionTable().
|
|
|
|
// (Also below.)
|
|
|
|
CHECK(!builder.ToSourcePositionTable().is_null());
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:26:27 +00:00
|
|
|
TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) {
|
|
|
|
SourcePositionTableBuilder builder(isolate(), zone());
|
|
|
|
for (int i = 0; i < arraysize(offsets); i++) {
|
2016-05-12 19:18:07 +00:00
|
|
|
builder.AddPosition(offsets[i], offsets[i], true);
|
|
|
|
builder.AddPosition(offsets[i], offsets[i] + 1, true);
|
2016-03-15 08:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// To test correctness, we rely on the assertions in ToSourcePositionTable().
|
|
|
|
// (Also below.)
|
|
|
|
CHECK(!builder.ToSourcePositionTable().is_null());
|
|
|
|
}
|
|
|
|
|
2016-02-24 17:12:31 +00:00
|
|
|
TEST_F(SourcePositionTableTest, EncodeExpression) {
|
|
|
|
SourcePositionTableBuilder builder(isolate(), zone());
|
|
|
|
for (int i = 0; i < arraysize(offsets); i++) {
|
2016-05-12 19:18:07 +00:00
|
|
|
builder.AddPosition(offsets[i], offsets[i], false);
|
2016-02-24 17:12:31 +00:00
|
|
|
}
|
|
|
|
CHECK(!builder.ToSourcePositionTable().is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SourcePositionTableTest, EncodeAscending) {
|
|
|
|
SourcePositionTableBuilder builder(isolate(), zone());
|
|
|
|
|
2016-06-22 09:06:17 +00:00
|
|
|
int code_offset = 0;
|
|
|
|
int source_position = 0;
|
2016-02-24 17:12:31 +00:00
|
|
|
for (int i = 0; i < arraysize(offsets); i++) {
|
2016-06-22 09:06:17 +00:00
|
|
|
code_offset += offsets[i];
|
|
|
|
source_position += offsets[i];
|
2016-02-24 17:12:31 +00:00
|
|
|
if (i % 2) {
|
2016-06-22 09:06:17 +00:00
|
|
|
builder.AddPosition(code_offset, source_position, true);
|
2016-02-24 17:12:31 +00:00
|
|
|
} else {
|
2016-06-22 09:06:17 +00:00
|
|
|
builder.AddPosition(code_offset, source_position, false);
|
2016-02-24 17:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 09:06:17 +00:00
|
|
|
// Also test negative offsets for source positions:
|
2016-02-24 17:12:31 +00:00
|
|
|
for (int i = 0; i < arraysize(offsets); i++) {
|
2016-06-22 09:06:17 +00:00
|
|
|
code_offset += offsets[i];
|
|
|
|
source_position -= offsets[i];
|
2016-02-24 17:12:31 +00:00
|
|
|
if (i % 2) {
|
2016-06-22 09:06:17 +00:00
|
|
|
builder.AddPosition(code_offset, source_position, true);
|
2016-02-24 17:12:31 +00:00
|
|
|
} else {
|
2016-06-22 09:06:17 +00:00
|
|
|
builder.AddPosition(code_offset, source_position, false);
|
2016-02-24 17:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(!builder.ToSourcePositionTable().is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|