[inspector] Simplify script end position logic.
Don't expose the line end table logic to V8DebuggerScript, but instead use the existing Script::GetPositionInfo() logic to resolve end line and column numbers for scripts. This also avoids having to copy (the potentially huge) line ends tables to std::vector's twice per script. Bug: chromium:1162229 Change-Id: I03365d42c320d462360bacc444f7fa97904a9748 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3494240 Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org> Cr-Commit-Position: refs/heads/main@{#79311}
This commit is contained in:
parent
8f8e037548
commit
7eb22c894c
@ -316,32 +316,44 @@ bool Script::IsEmbedded() const {
|
||||
|
||||
int Script::Id() const { return Utils::OpenHandle(this)->id(); }
|
||||
|
||||
int Script::LineOffset() const {
|
||||
return Utils::OpenHandle(this)->line_offset();
|
||||
}
|
||||
int Script::StartLine() const { return Utils::OpenHandle(this)->line_offset(); }
|
||||
|
||||
int Script::ColumnOffset() const {
|
||||
int Script::StartColumn() const {
|
||||
return Utils::OpenHandle(this)->column_offset();
|
||||
}
|
||||
|
||||
std::vector<int> Script::LineEnds() const {
|
||||
int Script::EndLine() const {
|
||||
i::Handle<i::Script> script = Utils::OpenHandle(this);
|
||||
#if V8_ENABLE_WEBASSEMBLY
|
||||
if (script->type() == i::Script::TYPE_WASM) return {};
|
||||
if (script->type() == i::Script::TYPE_WASM) return 0;
|
||||
#endif // V8_ENABLE_WEBASSEMBLY
|
||||
|
||||
if (!script->source().IsString()) {
|
||||
return script->line_offset();
|
||||
}
|
||||
i::Isolate* isolate = script->GetIsolate();
|
||||
i::HandleScope scope(isolate);
|
||||
i::Script::InitLineEnds(isolate, script);
|
||||
CHECK(script->line_ends().IsFixedArray());
|
||||
i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends()),
|
||||
isolate);
|
||||
std::vector<int> result(line_ends->length());
|
||||
for (int i = 0; i < line_ends->length(); ++i) {
|
||||
i::Smi line_end = i::Smi::cast(line_ends->get(i));
|
||||
result[i] = line_end.value();
|
||||
i::Script::PositionInfo info;
|
||||
i::Script::GetPositionInfo(script, i::String::cast(script->source()).length(),
|
||||
&info, i::Script::WITH_OFFSET);
|
||||
return info.line;
|
||||
}
|
||||
|
||||
int Script::EndColumn() const {
|
||||
i::Handle<i::Script> script = Utils::OpenHandle(this);
|
||||
#if V8_ENABLE_WEBASSEMBLY
|
||||
if (script->type() == i::Script::TYPE_WASM) {
|
||||
return script->wasm_native_module()->wire_bytes().length();
|
||||
}
|
||||
return result;
|
||||
#endif // V8_ENABLE_WEBASSEMBLY
|
||||
if (!script->source().IsString()) {
|
||||
return script->column_offset();
|
||||
}
|
||||
i::Isolate* isolate = script->GetIsolate();
|
||||
i::HandleScope scope(isolate);
|
||||
i::Script::PositionInfo info;
|
||||
i::Script::GetPositionInfo(script, i::String::cast(script->source()).length(),
|
||||
&info, i::Script::WITH_OFFSET);
|
||||
return info.column;
|
||||
}
|
||||
|
||||
MaybeLocal<String> Script::Name() const {
|
||||
|
@ -171,9 +171,10 @@ class V8_EXPORT_PRIVATE Script {
|
||||
bool WasCompiled() const;
|
||||
bool IsEmbedded() const;
|
||||
int Id() const;
|
||||
int LineOffset() const;
|
||||
int ColumnOffset() const;
|
||||
std::vector<int> LineEnds() const;
|
||||
int StartLine() const;
|
||||
int StartColumn() const;
|
||||
int EndLine() const;
|
||||
int EndColumn() const;
|
||||
MaybeLocal<String> Name() const;
|
||||
MaybeLocal<String> SourceURL() const;
|
||||
MaybeLocal<String> SourceMappingURL() const;
|
||||
|
@ -304,29 +304,10 @@ class ActualScript : public V8DebuggerScript {
|
||||
script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0;
|
||||
if (script->SourceMappingURL().ToLocal(&tmp))
|
||||
m_sourceMappingURL = toProtocolString(m_isolate, tmp);
|
||||
m_startLine = script->LineOffset();
|
||||
m_startColumn = script->ColumnOffset();
|
||||
std::vector<int> lineEnds = script->LineEnds();
|
||||
if (lineEnds.size()) {
|
||||
int source_length = lineEnds[lineEnds.size() - 1];
|
||||
m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1;
|
||||
if (lineEnds.size() > 1) {
|
||||
m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1;
|
||||
} else {
|
||||
m_endColumn = source_length + m_startColumn;
|
||||
}
|
||||
#if V8_ENABLE_WEBASSEMBLY
|
||||
} else if (script->IsWasm()) {
|
||||
DCHECK_EQ(0, m_startLine);
|
||||
DCHECK_EQ(0, m_startColumn);
|
||||
m_endLine = 0;
|
||||
m_endColumn = static_cast<int>(
|
||||
v8::debug::WasmScript::Cast(*script)->Bytecode().size());
|
||||
#endif // V8_ENABLE_WEBASSEMBLY
|
||||
} else {
|
||||
m_endLine = m_startLine;
|
||||
m_endColumn = m_startColumn;
|
||||
}
|
||||
m_startLine = script->StartLine();
|
||||
m_startColumn = script->StartColumn();
|
||||
m_endLine = script->EndLine();
|
||||
m_endColumn = script->EndColumn();
|
||||
|
||||
USE(script->ContextId().To(&m_executionContextId));
|
||||
m_language = V8DebuggerScript::Language::JavaScript;
|
||||
|
Loading…
Reference in New Issue
Block a user