GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [inspector] added V8InspectorClient::resourceNameToUrl · v8/v8@dbfcc48

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • include
    • v8-inspector.h
  • src/inspector
    • v8-debugger-agent-impl.cc
    • v8-debugger-script.cc
    • v8-debugger-script.h
    • v8-debugger.cc
    • v8-profiler-agent-impl.cc
    • v8-stack-trace-impl.cc
    • v8-stack-trace-impl.h
  • test/inspector
    • debugger
      • resource-name-to-url-expected.txt
      • resource-name-to-url.js
    • inspector-test.cc
    • isolate-data.cc
    • isolate-data.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎include/v8-inspector.h‎

Copy file name to clipboardExpand all lines: include/v8-inspector.h
+5Lines 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
Collapse file

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

Copy file name to clipboardExpand all lines: src/inspector/v8-debugger-agent-impl.cc
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ void V8DebuggerAgentImpl::didParseSource(
13971397
protocol::StringUtil::parseJSON(inspected->auxData()));
13981398
}
13991399
bool isLiveEdit = script->isLiveEdit();
1400-
bool hasSourceURL = script->hasSourceURL();
1400+
bool hasSourceURLComment = script->hasSourceURLComment();
14011401
bool isModule = script->isModule();
14021402
String16 scriptId = script->scriptId();
14031403
String16 scriptURL = script->sourceURL();
@@ -1417,7 +1417,8 @@ void V8DebuggerAgentImpl::didParseSource(
14171417
Maybe<protocol::DictionaryValue> executionContextAuxDataParam(
14181418
std::move(executionContextAuxData));
14191419
const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
1420-
const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
1420+
const bool* hasSourceURLParam =
1421+
hasSourceURLComment ? &hasSourceURLComment : nullptr;
14211422
const bool* isModuleParam = isModule ? &isModule : nullptr;
14221423
std::unique_ptr<V8StackTraceImpl> stack =
14231424
V8StackTraceImpl::capture(m_inspector->debugger(), contextGroupId, 1);
Collapse file

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

Copy file name to clipboardExpand all lines: src/inspector/v8-debugger-script.cc
+24-17Lines changed: 24 additions & 17 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/v8memory.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(isolate, script)),
116+
GetScriptURL(isolate, script, client)),
116117
m_isLiveEdit(isLiveEdit) {
117118
Initialize(script);
118119
}
@@ -218,11 +219,19 @@ class ActualScript : public V8DebuggerScript {
218219
}
219220

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

@@ -232,8 +241,8 @@ class ActualScript : public V8DebuggerScript {
232241

233242
void Initialize(v8::Local<v8::debug::Script> script) {
234243
v8::Local<v8::String> tmp;
235-
if (script->SourceURL().ToLocal(&tmp))
236-
m_sourceURL = toProtocolString(m_isolate, tmp);
244+
m_hasSourceURLComment =
245+
script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0;
237246
if (script->SourceMappingURL().ToLocal(&tmp))
238247
m_sourceMappingURL = toProtocolString(m_isolate, tmp);
239248
m_startLine = script->LineOffset();
@@ -400,9 +409,9 @@ class WasmVirtualScript : public V8DebuggerScript {
400409

401410
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create(
402411
v8::Isolate* isolate, v8::Local<v8::debug::Script> scriptObj,
403-
bool isLiveEdit) {
412+
bool isLiveEdit, V8InspectorClient* client) {
404413
return std::unique_ptr<ActualScript>(
405-
new ActualScript(isolate, scriptObj, isLiveEdit));
414+
new ActualScript(isolate, scriptObj, isLiveEdit, client));
406415
}
407416

408417
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
@@ -420,18 +429,16 @@ V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id,
420429

421430
V8DebuggerScript::~V8DebuggerScript() {}
422431

423-
const String16& V8DebuggerScript::sourceURL() const {
424-
return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
425-
}
426-
427432
void V8DebuggerScript::setSourceURL(const String16& sourceURL) {
428-
m_sourceURL = sourceURL;
433+
if (sourceURL.length() > 0) {
434+
m_hasSourceURLComment = true;
435+
m_url = sourceURL;
436+
}
429437
}
430438

431439
bool V8DebuggerScript::setBreakpoint(const String16& condition,
432440
v8::debug::Location* loc, int* id) const {
433441
v8::HandleScope scope(m_isolate);
434442
return script()->SetBreakpoint(toV8String(m_isolate, condition), loc, id);
435443
}
436-
437444
} // namespace v8_inspector
Collapse file

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

Copy file name to clipboardExpand all lines: src/inspector/v8-debugger-script.h
+6-5Lines 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;
Collapse file

‎src/inspector/v8-debugger.cc‎

Copy file name to clipboardExpand all lines: src/inspector/v8-debugger.cc
+8-5Lines 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
}
Collapse file

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

Copy file name to clipboardExpand all lines: src/inspector/v8-profiler-agent-impl.cc
+33-15Lines changed: 33 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(inspector->isolate(), 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(isolate, node->GetFunctionName()))
5970
.setScriptId(String16::fromInteger(node->GetScriptId()))
60-
.setUrl(toProtocolString(isolate, 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,11 +332,12 @@ 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 =
327339
protocol::Array<protocol::Profiler::ScriptCoverage>::create();
340+
v8::Isolate* isolate = inspector->isolate();
328341
for (size_t i = 0; i < coverage.ScriptCount(); i++) {
329342
v8::debug::Coverage::ScriptData script_data = coverage.GetScriptData(i);
330343
v8::Local<v8::debug::Script> script = script_data.GetScript();
@@ -362,8 +375,10 @@ Response coverageToProtocol(
362375
}
363376
String16 url;
364377
v8::Local<v8::String> name;
365-
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
378+
if (script->SourceURL().ToLocal(&name) && name->Length()) {
366379
url = toProtocolString(isolate, name);
380+
} else if (script->Name().ToLocal(&name) && name->Length()) {
381+
url = resourceNameToUrl(inspector, name);
367382
}
368383
result->addItem(protocol::Profiler::ScriptCoverage::create()
369384
.setScriptId(String16::fromInteger(script->Id()))
@@ -385,7 +400,7 @@ Response V8ProfilerAgentImpl::takePreciseCoverage(
385400
}
386401
v8::HandleScope handle_scope(m_isolate);
387402
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(m_isolate);
388-
return coverageToProtocol(m_isolate, coverage, out_result);
403+
return coverageToProtocol(m_session->inspector(), coverage, out_result);
389404
}
390405

391406
Response V8ProfilerAgentImpl::getBestEffortCoverage(
@@ -394,15 +409,16 @@ Response V8ProfilerAgentImpl::getBestEffortCoverage(
394409
v8::HandleScope handle_scope(m_isolate);
395410
v8::debug::Coverage coverage =
396411
v8::debug::Coverage::CollectBestEffort(m_isolate);
397-
return coverageToProtocol(m_isolate, coverage, out_result);
412+
return coverageToProtocol(m_session->inspector(), coverage, out_result);
398413
}
399414

400415
namespace {
401416
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
402-
typeProfileToProtocol(v8::Isolate* isolate,
417+
typeProfileToProtocol(V8InspectorImpl* inspector,
403418
const v8::debug::TypeProfile& type_profile) {
404419
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
405420
result = protocol::Array<protocol::Profiler::ScriptTypeProfile>::create();
421+
v8::Isolate* isolate = inspector->isolate();
406422
for (size_t i = 0; i < type_profile.ScriptCount(); i++) {
407423
v8::debug::TypeProfile::ScriptData script_data =
408424
type_profile.GetScriptData(i);
@@ -428,8 +444,10 @@ typeProfileToProtocol(v8::Isolate* isolate,
428444
}
429445
String16 url;
430446
v8::Local<v8::String> name;
431-
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
447+
if (script->SourceURL().ToLocal(&name) && name->Length()) {
432448
url = toProtocolString(isolate, name);
449+
} else if (script->Name().ToLocal(&name) && name->Length()) {
450+
url = resourceNameToUrl(inspector, name);
433451
}
434452
result->addItem(protocol::Profiler::ScriptTypeProfile::create()
435453
.setScriptId(String16::fromInteger(script->Id()))
@@ -464,7 +482,7 @@ Response V8ProfilerAgentImpl::takeTypeProfile(
464482
v8::HandleScope handle_scope(m_isolate);
465483
v8::debug::TypeProfile type_profile =
466484
v8::debug::TypeProfile::Collect(m_isolate);
467-
*out_result = typeProfileToProtocol(m_isolate, type_profile);
485+
*out_result = typeProfileToProtocol(m_session->inspector(), type_profile);
468486
return Response::OK();
469487
}
470488

@@ -493,7 +511,7 @@ std::unique_ptr<protocol::Profiler::Profile> V8ProfilerAgentImpl::stopProfiling(
493511
m_profiler->StopProfiling(toV8String(m_isolate, title));
494512
std::unique_ptr<protocol::Profiler::Profile> result;
495513
if (profile) {
496-
if (serialize) result = createCPUProfile(m_isolate, profile);
514+
if (serialize) result = createCPUProfile(m_session->inspector(), profile);
497515
profile->Delete();
498516
}
499517
--m_startedProfilesCount;

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.