Skip to content

Commit ab15016

Browse files
committed
deps: cherry-pick dbfcc48 from upstream V8
Original commit message: ``` [inspector] added V8InspectorClient::resourceNameToUrl Some clients (see Node.js) use platform path as ScriptOrigin. Reporting platform path in protocol makes using protocol much harder. This CL introduced V8InspectorClient::resourceNameToUrl method that is called for any reported using protocol url. V8Inspector uses url internally as well so protocol client may generate pattern for blackboxing with file urls only and does not need to build complicated regexp that covers files urls and platform paths on different platforms. R=lushnikov@chromium.org TBR=yangguo@chromium.org Bug: none Change-Id: Iff302e7441df922fa5d689fe510f5a9bfd470b9b Reviewed-on: https://chromium-review.googlesource.com/1164624 Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Alexei Filippov <alph@chromium.org> Cr-Commit-Position: refs/heads/master@{#55029} ``` Refs: v8/v8@dbfcc48 PR-URL: #22251 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
1 parent 90c9368 commit ab15016

14 files changed

Lines changed: 318 additions & 49 deletions

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Reset this number to 0 on major V8 upgrades.
3131
# Increment by one for each non-official patch applied to deps/v8.
32-
'v8_embedder_string': '-node.10',
32+
'v8_embedder_string': '-node.11',
3333

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/include/v8-inspector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ class V8_EXPORT V8InspectorClient {
215215
virtual bool canExecuteScripts(int contextGroupId) { return true; }
216216

217217
virtual void maxAsyncCallStackDepthChanged(int depth) {}
218+
219+
virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
220+
const StringView& resourceName) {
221+
return nullptr;
222+
}
218223
};
219224

220225
// These stack trace ids are intended to be passed between debuggers and be

deps/v8/src/inspector/v8-debugger-agent-impl.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ void V8DebuggerAgentImpl::didParseSource(
13961396
protocol::StringUtil::parseJSON(inspected->auxData()));
13971397
}
13981398
bool isLiveEdit = script->isLiveEdit();
1399-
bool hasSourceURL = script->hasSourceURL();
1399+
bool hasSourceURLComment = script->hasSourceURLComment();
14001400
bool isModule = script->isModule();
14011401
String16 scriptId = script->scriptId();
14021402
String16 scriptURL = script->sourceURL();
@@ -1416,7 +1416,8 @@ void V8DebuggerAgentImpl::didParseSource(
14161416
Maybe<protocol::DictionaryValue> executionContextAuxDataParam(
14171417
std::move(executionContextAuxData));
14181418
const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
1419-
const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
1419+
const bool* hasSourceURLParam =
1420+
hasSourceURLComment ? &hasSourceURLComment : nullptr;
14201421
const bool* isModuleParam = isModule ? &isModule : nullptr;
14211422
std::unique_ptr<V8StackTraceImpl> stack =
14221423
V8StackTraceImpl::capture(m_inspector->debugger(), contextGroupId, 1);

deps/v8/src/inspector/v8-debugger-script.cc

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "src/inspector/inspected-context.h"
88
#include "src/inspector/string-util.h"
9+
#include "src/inspector/v8-inspector-impl.h"
910
#include "src/inspector/wasm-translation.h"
1011
#include "src/utils.h"
1112

@@ -110,9 +111,9 @@ class ActualScript : public V8DebuggerScript {
110111

111112
public:
112113
ActualScript(v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
113-
bool isLiveEdit)
114+
bool isLiveEdit, V8InspectorClient* client)
114115
: V8DebuggerScript(isolate, String16::fromInteger(script->Id()),
115-
GetNameOrSourceUrl(script)),
116+
GetScriptURL(script, client)),
116117
m_isLiveEdit(isLiveEdit) {
117118
Initialize(script);
118119
}
@@ -218,10 +219,18 @@ class ActualScript : public V8DebuggerScript {
218219
}
219220

220221
private:
221-
String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) {
222-
v8::Local<v8::String> name;
223-
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name))
224-
return toProtocolString(name);
222+
String16 GetScriptURL(v8::Local<v8::debug::Script> script,
223+
V8InspectorClient* client) {
224+
v8::Local<v8::String> sourceURL;
225+
if (script->SourceURL().ToLocal(&sourceURL) && sourceURL->Length() > 0)
226+
return toProtocolString(sourceURL);
227+
v8::Local<v8::String> v8Name;
228+
if (script->Name().ToLocal(&v8Name) && v8Name->Length() > 0) {
229+
String16 name = toProtocolString(v8Name);
230+
std::unique_ptr<StringBuffer> url =
231+
client->resourceNameToUrl(toStringView(name));
232+
return url ? toString16(url->string()) : name;
233+
}
225234
return String16();
226235
}
227236

@@ -231,7 +240,8 @@ class ActualScript : public V8DebuggerScript {
231240

232241
void Initialize(v8::Local<v8::debug::Script> script) {
233242
v8::Local<v8::String> tmp;
234-
if (script->SourceURL().ToLocal(&tmp)) m_sourceURL = toProtocolString(tmp);
243+
m_hasSourceURLComment =
244+
script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0;
235245
if (script->SourceMappingURL().ToLocal(&tmp))
236246
m_sourceMappingURL = toProtocolString(tmp);
237247
m_startLine = script->LineOffset();
@@ -398,9 +408,9 @@ class WasmVirtualScript : public V8DebuggerScript {
398408

399409
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create(
400410
v8::Isolate* isolate, v8::Local<v8::debug::Script> scriptObj,
401-
bool isLiveEdit) {
411+
bool isLiveEdit, V8InspectorClient* client) {
402412
return std::unique_ptr<ActualScript>(
403-
new ActualScript(isolate, scriptObj, isLiveEdit));
413+
new ActualScript(isolate, scriptObj, isLiveEdit, client));
404414
}
405415

406416
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
@@ -418,18 +428,16 @@ V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id,
418428

419429
V8DebuggerScript::~V8DebuggerScript() {}
420430

421-
const String16& V8DebuggerScript::sourceURL() const {
422-
return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
423-
}
424-
425431
void V8DebuggerScript::setSourceURL(const String16& sourceURL) {
426-
m_sourceURL = sourceURL;
432+
if (sourceURL.length() > 0) {
433+
m_hasSourceURLComment = true;
434+
m_url = sourceURL;
435+
}
427436
}
428437

429438
bool V8DebuggerScript::setBreakpoint(const String16& condition,
430439
v8::debug::Location* loc, int* id) const {
431440
v8::HandleScope scope(m_isolate);
432441
return script()->SetBreakpoint(toV8String(m_isolate, condition), loc, id);
433442
}
434-
435443
} // namespace v8_inspector

deps/v8/src/inspector/v8-debugger-script.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@
4040
namespace v8_inspector {
4141

4242
// Forward declaration.
43+
class V8InspectorClient;
4344
class WasmTranslation;
4445

4546
class V8DebuggerScript {
4647
public:
4748
static std::unique_ptr<V8DebuggerScript> Create(
4849
v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
49-
bool isLiveEdit);
50+
bool isLiveEdit, V8InspectorClient* client);
5051
static std::unique_ptr<V8DebuggerScript> CreateWasm(
5152
v8::Isolate* isolate, WasmTranslation* wasmTranslation,
5253
v8::Local<v8::debug::WasmScript> underlyingScript, String16 id,
@@ -55,9 +56,9 @@ class V8DebuggerScript {
5556
virtual ~V8DebuggerScript();
5657

5758
const String16& scriptId() const { return m_id; }
58-
const String16& url() const { return m_url; }
59-
bool hasSourceURL() const { return !m_sourceURL.isEmpty(); }
60-
const String16& sourceURL() const;
59+
bool hasSourceURLComment() const { return m_hasSourceURLComment; }
60+
const String16& sourceURL() const { return m_url; }
61+
6162
virtual const String16& sourceMappingURL() const = 0;
6263
virtual const String16& source() const = 0;
6364
virtual const String16& hash() const = 0;
@@ -95,7 +96,7 @@ class V8DebuggerScript {
9596

9697
String16 m_id;
9798
String16 m_url;
98-
String16 m_sourceURL;
99+
bool m_hasSourceURLComment = false;
99100
int m_executionContextId = 0;
100101

101102
v8::Isolate* m_isolate;

deps/v8/src/inspector/v8-debugger.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,15 @@ void V8Debugger::getCompiledScripts(
226226
v8::Local<v8::debug::Script> script = scripts.Get(i);
227227
if (!script->WasCompiled()) continue;
228228
if (script->IsEmbedded()) {
229-
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
229+
result.push_back(V8DebuggerScript::Create(m_isolate, script, false,
230+
m_inspector->client()));
230231
continue;
231232
}
232233
int contextId;
233234
if (!script->ContextId().To(&contextId)) continue;
234235
if (m_inspector->contextGroupId(contextId) != contextGroupId) continue;
235-
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
236+
result.push_back(V8DebuggerScript::Create(m_isolate, script, false,
237+
m_inspector->client()));
236238
}
237239
}
238240

@@ -585,13 +587,14 @@ void V8Debugger::ScriptCompiled(v8::Local<v8::debug::Script> script,
585587
});
586588
} else if (m_ignoreScriptParsedEventsCounter == 0) {
587589
v8::Isolate* isolate = m_isolate;
590+
V8InspectorClient* client = m_inspector->client();
588591
m_inspector->forEachSession(
589592
m_inspector->contextGroupId(contextId),
590-
[&isolate, &script, &has_compile_error,
591-
&is_live_edited](V8InspectorSessionImpl* session) {
593+
[&isolate, &script, &has_compile_error, &is_live_edited,
594+
&client](V8InspectorSessionImpl* session) {
592595
if (!session->debuggerAgent()->enabled()) return;
593596
session->debuggerAgent()->didParseSource(
594-
V8DebuggerScript::Create(isolate, script, is_live_edited),
597+
V8DebuggerScript::Create(isolate, script, is_live_edited, client),
595598
!has_compile_error);
596599
});
597600
}

deps/v8/src/inspector/v8-profiler-agent-impl.cc

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88

99
#include "src/base/atomicops.h"
10+
#include "src/debug/debug-interface.h"
1011
#include "src/flags.h" // TODO(jgruber): Remove include and DEPS entry.
1112
#include "src/inspector/protocol/Protocol.h"
1213
#include "src/inspector/string-util.h"
@@ -31,6 +32,15 @@ static const char typeProfileStarted[] = "typeProfileStarted";
3132

3233
namespace {
3334

35+
String16 resourceNameToUrl(V8InspectorImpl* inspector,
36+
v8::Local<v8::String> v8Name) {
37+
String16 name = toProtocolString(v8Name);
38+
if (!inspector) return name;
39+
std::unique_ptr<StringBuffer> url =
40+
inspector->client()->resourceNameToUrl(toStringView(name));
41+
return url ? toString16(url->string()) : name;
42+
}
43+
3444
std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>>
3545
buildInspectorObjectForPositionTicks(const v8::CpuProfileNode* node) {
3646
unsigned lineCount = node->GetHitLineCount();
@@ -51,13 +61,14 @@ buildInspectorObjectForPositionTicks(const v8::CpuProfileNode* node) {
5161
}
5262

5363
std::unique_ptr<protocol::Profiler::ProfileNode> buildInspectorObjectFor(
54-
v8::Isolate* isolate, const v8::CpuProfileNode* node) {
64+
V8InspectorImpl* inspector, const v8::CpuProfileNode* node) {
65+
v8::Isolate* isolate = inspector->isolate();
5566
v8::HandleScope handleScope(isolate);
5667
auto callFrame =
5768
protocol::Runtime::CallFrame::create()
5869
.setFunctionName(toProtocolString(node->GetFunctionName()))
5970
.setScriptId(String16::fromInteger(node->GetScriptId()))
60-
.setUrl(toProtocolString(node->GetScriptResourceName()))
71+
.setUrl(resourceNameToUrl(inspector, node->GetScriptResourceName()))
6172
.setLineNumber(node->GetLineNumber() - 1)
6273
.setColumnNumber(node->GetColumnNumber() - 1)
6374
.build();
@@ -107,18 +118,19 @@ std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(
107118
return array;
108119
}
109120

110-
void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node,
121+
void flattenNodesTree(V8InspectorImpl* inspector,
122+
const v8::CpuProfileNode* node,
111123
protocol::Array<protocol::Profiler::ProfileNode>* list) {
112-
list->addItem(buildInspectorObjectFor(isolate, node));
124+
list->addItem(buildInspectorObjectFor(inspector, node));
113125
const int childrenCount = node->GetChildrenCount();
114126
for (int i = 0; i < childrenCount; i++)
115-
flattenNodesTree(isolate, node->GetChild(i), list);
127+
flattenNodesTree(inspector, node->GetChild(i), list);
116128
}
117129

118130
std::unique_ptr<protocol::Profiler::Profile> createCPUProfile(
119-
v8::Isolate* isolate, v8::CpuProfile* v8profile) {
131+
V8InspectorImpl* inspector, v8::CpuProfile* v8profile) {
120132
auto nodes = protocol::Array<protocol::Profiler::ProfileNode>::create();
121-
flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get());
133+
flattenNodesTree(inspector, v8profile->GetTopDownRoot(), nodes.get());
122134
return protocol::Profiler::Profile::create()
123135
.setNodes(std::move(nodes))
124136
.setStartTime(static_cast<double>(v8profile->GetStartTime()))
@@ -320,7 +332,7 @@ std::unique_ptr<protocol::Profiler::CoverageRange> createCoverageRange(
320332
}
321333

322334
Response coverageToProtocol(
323-
v8::Isolate* isolate, const v8::debug::Coverage& coverage,
335+
V8InspectorImpl* inspector, const v8::debug::Coverage& coverage,
324336
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>*
325337
out_result) {
326338
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> result =
@@ -361,8 +373,10 @@ Response coverageToProtocol(
361373
}
362374
String16 url;
363375
v8::Local<v8::String> name;
364-
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
376+
if (script->SourceURL().ToLocal(&name) && name->Length()) {
365377
url = toProtocolString(name);
378+
} else if (script->Name().ToLocal(&name) && name->Length()) {
379+
url = resourceNameToUrl(inspector, name);
366380
}
367381
result->addItem(protocol::Profiler::ScriptCoverage::create()
368382
.setScriptId(String16::fromInteger(script->Id()))
@@ -384,7 +398,7 @@ Response V8ProfilerAgentImpl::takePreciseCoverage(
384398
}
385399
v8::HandleScope handle_scope(m_isolate);
386400
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(m_isolate);
387-
return coverageToProtocol(m_isolate, coverage, out_result);
401+
return coverageToProtocol(m_session->inspector(), coverage, out_result);
388402
}
389403

390404
Response V8ProfilerAgentImpl::getBestEffortCoverage(
@@ -393,12 +407,12 @@ Response V8ProfilerAgentImpl::getBestEffortCoverage(
393407
v8::HandleScope handle_scope(m_isolate);
394408
v8::debug::Coverage coverage =
395409
v8::debug::Coverage::CollectBestEffort(m_isolate);
396-
return coverageToProtocol(m_isolate, coverage, out_result);
410+
return coverageToProtocol(m_session->inspector(), coverage, out_result);
397411
}
398412

399413
namespace {
400414
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
401-
typeProfileToProtocol(v8::Isolate* isolate,
415+
typeProfileToProtocol(V8InspectorImpl* inspector,
402416
const v8::debug::TypeProfile& type_profile) {
403417
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
404418
result = protocol::Array<protocol::Profiler::ScriptTypeProfile>::create();
@@ -426,8 +440,10 @@ typeProfileToProtocol(v8::Isolate* isolate,
426440
}
427441
String16 url;
428442
v8::Local<v8::String> name;
429-
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
443+
if (script->SourceURL().ToLocal(&name) && name->Length()) {
430444
url = toProtocolString(name);
445+
} else if (script->Name().ToLocal(&name) && name->Length()) {
446+
url = resourceNameToUrl(inspector, name);
431447
}
432448
result->addItem(protocol::Profiler::ScriptTypeProfile::create()
433449
.setScriptId(String16::fromInteger(script->Id()))
@@ -462,7 +478,7 @@ Response V8ProfilerAgentImpl::takeTypeProfile(
462478
v8::HandleScope handle_scope(m_isolate);
463479
v8::debug::TypeProfile type_profile =
464480
v8::debug::TypeProfile::Collect(m_isolate);
465-
*out_result = typeProfileToProtocol(m_isolate, type_profile);
481+
*out_result = typeProfileToProtocol(m_session->inspector(), type_profile);
466482
return Response::OK();
467483
}
468484

@@ -491,7 +507,7 @@ std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling(
491507
m_profiler->StopProfiling(toV8String(m_isolate, title));
492508
std::unique_ptr<protocol::Profiler::Profile> result;
493509
if (profile) {
494-
if (serialize) result = createCPUProfile(m_isolate, profile);
510+
if (serialize) result = createCPUProfile(m_session->inspector(), profile);
495511
profile->Delete();
496512
}
497513
--m_startedProfilesCount;

deps/v8/src/inspector/v8-stack-trace-impl.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <algorithm>
88

99
#include "src/inspector/v8-debugger.h"
10+
#include "src/inspector/v8-inspector-impl.h"
1011
#include "src/inspector/wasm-translation.h"
1112

1213
namespace v8_inspector {
@@ -73,7 +74,10 @@ std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectCommon(
7374
std::unique_ptr<protocol::Array<protocol::Runtime::CallFrame>>
7475
inspectorFrames = protocol::Array<protocol::Runtime::CallFrame>::create();
7576
for (size_t i = 0; i < frames.size(); i++) {
76-
inspectorFrames->addItem(frames[i]->buildInspectorObject());
77+
V8InspectorClient* client = nullptr;
78+
if (debugger && debugger->inspector())
79+
client = debugger->inspector()->client();
80+
inspectorFrames->addItem(frames[i]->buildInspectorObject(client));
7781
}
7882
std::unique_ptr<protocol::Runtime::StackTrace> stackTrace =
7983
protocol::Runtime::StackTrace::create()
@@ -117,7 +121,9 @@ StackFrame::StackFrame(v8::Local<v8::StackFrame> v8Frame)
117121
m_scriptId(String16::fromInteger(v8Frame->GetScriptId())),
118122
m_sourceURL(toProtocolString(v8Frame->GetScriptNameOrSourceURL())),
119123
m_lineNumber(v8Frame->GetLineNumber() - 1),
120-
m_columnNumber(v8Frame->GetColumn() - 1) {
124+
m_columnNumber(v8Frame->GetColumn() - 1),
125+
m_hasSourceURLComment(v8Frame->GetScriptName() !=
126+
v8Frame->GetScriptNameOrSourceURL()) {
121127
DCHECK_NE(v8::Message::kNoLineNumberInfo, m_lineNumber + 1);
122128
DCHECK_NE(v8::Message::kNoColumnInfo, m_columnNumber + 1);
123129
}
@@ -137,12 +143,20 @@ int StackFrame::lineNumber() const { return m_lineNumber; }
137143

138144
int StackFrame::columnNumber() const { return m_columnNumber; }
139145

140-
std::unique_ptr<protocol::Runtime::CallFrame> StackFrame::buildInspectorObject()
141-
const {
146+
std::unique_ptr<protocol::Runtime::CallFrame> StackFrame::buildInspectorObject(
147+
V8InspectorClient* client) const {
148+
String16 frameUrl = m_sourceURL;
149+
if (client && !m_hasSourceURLComment && frameUrl.length() > 0) {
150+
std::unique_ptr<StringBuffer> url =
151+
client->resourceNameToUrl(toStringView(m_sourceURL));
152+
if (url) {
153+
frameUrl = toString16(url->string());
154+
}
155+
}
142156
return protocol::Runtime::CallFrame::create()
143157
.setFunctionName(m_functionName)
144158
.setScriptId(m_scriptId)
145-
.setUrl(m_sourceURL)
159+
.setUrl(frameUrl)
146160
.setLineNumber(m_lineNumber)
147161
.setColumnNumber(m_columnNumber)
148162
.build();

0 commit comments

Comments
 (0)