[inspector] Consistently pass around script ID as integer.

Within the inspector we should be consistent about passing the script ID
always as integer, and only convert to String16 when actually needed.
That (a) saves memory (and some runtime overhead) when stashing away
call frames, for example in case of async stack traces, and (b) reduces
confusion which representation to chose.

Bug: chromium:1162229
Change-Id: I9591931da0a307779372f36aba6e155ec22bbe3d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2876856
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74410}
This commit is contained in:
Benedikt Meurer 2021-05-06 15:21:01 +02:00 committed by V8 LUCI CQ
parent 9bd4492be3
commit 51fe55719c
5 changed files with 12 additions and 23 deletions

View File

@ -105,8 +105,9 @@ class V8_EXPORT V8StackTrace {
virtual StringView topSourceURL() const = 0;
virtual int topLineNumber() const = 0;
virtual int topColumnNumber() const = 0;
virtual StringView topScriptId() const = 0;
virtual int topScriptIdAsInteger() const = 0;
virtual int topScriptId() const = 0;
V8_DEPRECATE_SOON("Use V8::StackTrace::topScriptId() instead.")
int topScriptIdAsInteger() const { return topScriptId(); }
virtual StringView topFunctionName() const = 0;
virtual ~V8StackTrace() = default;

View File

@ -302,7 +302,8 @@ class InjectedScript::ProtocolPromiseHandler {
exceptionDetails->setStackTrace(
stack->buildInspectorObjectImpl(m_inspector->debugger()));
if (stack && !stack->isEmpty())
exceptionDetails->setScriptId(toString16(stack->topScriptId()));
exceptionDetails->setScriptId(
String16::fromInteger(stack->topScriptId()));
callback->sendSuccess(std::move(wrappedValue), std::move(exceptionDetails));
}

View File

@ -150,10 +150,11 @@ std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(
V8InspectorImpl* inspector) {
std::unique_ptr<V8StackTraceImpl> callStack =
inspector->debugger()->captureStackTrace(false /* fullStack */);
auto location = protocol::Debugger::Location::create()
.setScriptId(toString16(callStack->topScriptId()))
.setLineNumber(callStack->topLineNumber())
.build();
auto location =
protocol::Debugger::Location::create()
.setScriptId(String16::fromInteger(callStack->topScriptId()))
.setLineNumber(callStack->topLineNumber())
.build();
location->setColumnNumber(callStack->topColumnNumber());
return location;
}

View File

@ -177,7 +177,6 @@ std::unique_ptr<StringBuffer> V8StackTraceId::ToString() {
StackFrame::StackFrame(v8::Isolate* isolate, v8::Local<v8::StackFrame> v8Frame)
: m_functionName(toProtocolString(isolate, v8Frame->GetFunctionName())),
m_scriptId(v8Frame->GetScriptId()),
m_scriptIdAsString(String16::fromInteger(v8Frame->GetScriptId())),
m_sourceURL(
toProtocolString(isolate, v8Frame->GetScriptNameOrSourceURL())),
m_lineNumber(v8Frame->GetLineNumber() - 1),
@ -192,10 +191,6 @@ const String16& StackFrame::functionName() const { return m_functionName; }
int StackFrame::scriptId() const { return m_scriptId; }
const String16& StackFrame::scriptIdAsString() const {
return m_scriptIdAsString;
}
const String16& StackFrame::sourceURL() const { return m_sourceURL; }
int StackFrame::lineNumber() const { return m_lineNumber; }
@ -324,13 +319,7 @@ int V8StackTraceImpl::topColumnNumber() const {
return m_frames[0]->columnNumber() + 1;
}
StringView V8StackTraceImpl::topScriptId() const {
return toStringView(m_frames[0]->scriptIdAsString());
}
int V8StackTraceImpl::topScriptIdAsInteger() const {
return m_frames[0]->scriptId();
}
int V8StackTraceImpl::topScriptId() const { return m_frames[0]->scriptId(); }
StringView V8StackTraceImpl::topFunctionName() const {
return toStringView(m_frames[0]->functionName());

View File

@ -27,7 +27,6 @@ class StackFrame {
const String16& functionName() const;
int scriptId() const;
const String16& scriptIdAsString() const;
const String16& sourceURL() const;
int lineNumber() const; // 0-based.
int columnNumber() const; // 0-based.
@ -38,7 +37,6 @@ class StackFrame {
private:
String16 m_functionName;
int m_scriptId;
String16 m_scriptIdAsString;
String16 m_sourceURL;
int m_lineNumber; // 0-based.
int m_columnNumber; // 0-based.
@ -75,8 +73,7 @@ class V8StackTraceImpl : public V8StackTrace {
StringView topSourceURL() const override;
int topLineNumber() const override; // 1-based.
int topColumnNumber() const override; // 1-based.
StringView topScriptId() const override;
int topScriptIdAsInteger() const override;
int topScriptId() const override;
StringView topFunctionName() const override;
std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject()
const override;