blob: 16bf8b79d9243955a9af1c48c5fff95d81e35439 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright 2023 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/objects/abstract-code.h"
#include "src/objects/abstract-code-inl.h"
namespace v8 {
namespace internal {
// TODO(cbruni): Move to BytecodeArray
int AbstractCode::SourcePosition(PtrComprCageBase cage_base, int offset) {
CHECK_NE(kind(cage_base), CodeKind::BASELINE);
Tagged<Object> maybe_table = SourcePositionTableInternal(cage_base);
if (IsException(maybe_table)) return kNoSourcePosition;
Tagged<ByteArray> source_position_table = ByteArray::cast(maybe_table);
// Subtract one because the current PC is one instruction after the call site.
if (IsCode(*this, cage_base)) offset--;
int position = 0;
for (SourcePositionTableIterator iterator(
source_position_table, SourcePositionTableIterator::kJavaScriptOnly,
SourcePositionTableIterator::kDontSkipFunctionEntry);
!iterator.done() && iterator.code_offset() <= offset;
iterator.Advance()) {
position = iterator.source_position().ScriptOffset();
}
return position;
}
// TODO(cbruni): Move to BytecodeArray
int AbstractCode::SourceStatementPosition(PtrComprCageBase cage_base,
int offset) {
CHECK_NE(kind(cage_base), CodeKind::BASELINE);
// First find the closest position.
int position = SourcePosition(cage_base, offset);
// Now find the closest statement position before the position.
int statement_position = 0;
for (SourcePositionTableIterator it(SourcePositionTableInternal(cage_base));
!it.done(); it.Advance()) {
if (it.is_statement()) {
int p = it.source_position().ScriptOffset();
if (statement_position < p && p <= position) {
statement_position = p;
}
}
}
return statement_position;
}
} // namespace internal
} // namespace v8
|