Skip to content

Commit

Permalink
deps: cherry-pick dbfcc48 from upstream V8
Browse files Browse the repository at this point in the history
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.

[email protected]
[email protected]

Bug: none
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iff302e7441df922fa5d689fe510f5a9bfd470b9b
Reviewed-on: https://chromium-review.googlesource.com/1164624
Commit-Queue: Aleksey Kozyatinskiy <[email protected]>
Reviewed-by: Alexei Filippov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#55029}
```
Refs: v8/v8@dbfcc48

Backport-PR-URL: #22918
PR-URL: #22251
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
  • Loading branch information
alexkozy authored and targos committed Sep 25, 2018
1 parent 109aa63 commit e668815
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 79 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.29',
'v8_embedder_string': '-node.30',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/include/v8-inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ class V8_EXPORT V8InspectorClient {
virtual bool canExecuteScripts(int contextGroupId) { return true; }

virtual void maxAsyncCallStackDepthChanged(int depth) {}

virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
const StringView& resourceName) {
return nullptr;
}
};

// These stack trace ids are intended to be passed between debuggers and be
Expand Down
5 changes: 3 additions & 2 deletions deps/v8/src/inspector/v8-debugger-agent-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ void V8DebuggerAgentImpl::didParseSource(
protocol::StringUtil::parseJSON(inspected->auxData()));
}
bool isLiveEdit = script->isLiveEdit();
bool hasSourceURL = script->hasSourceURL();
bool hasSourceURLComment = script->hasSourceURLComment();
bool isModule = script->isModule();
String16 scriptId = script->scriptId();
String16 scriptURL = script->sourceURL();
Expand All @@ -1464,7 +1464,8 @@ void V8DebuggerAgentImpl::didParseSource(
Maybe<protocol::DictionaryValue> executionContextAuxDataParam(
std::move(executionContextAuxData));
const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
const bool* hasSourceURLParam =
hasSourceURLComment ? &hasSourceURLComment : nullptr;
const bool* isModuleParam = isModule ? &isModule : nullptr;
std::unique_ptr<V8StackTraceImpl> stack =
V8StackTraceImpl::capture(m_inspector->debugger(), contextGroupId, 1);
Expand Down
102 changes: 57 additions & 45 deletions deps/v8/src/inspector/v8-debugger-script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "src/inspector/inspected-context.h"
#include "src/inspector/string-util.h"
#include "src/inspector/v8-inspector-impl.h"
#include "src/inspector/wasm-translation.h"
#include "src/utils.h"

Expand Down Expand Up @@ -110,41 +111,11 @@ class ActualScript : public V8DebuggerScript {

public:
ActualScript(v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
bool isLiveEdit)
bool isLiveEdit, V8InspectorClient* client)
: V8DebuggerScript(isolate, String16::fromInteger(script->Id()),
GetNameOrSourceUrl(script)),
GetScriptURL(script, client)),
m_isLiveEdit(isLiveEdit) {
v8::Local<v8::String> tmp;
if (script->SourceURL().ToLocal(&tmp)) m_sourceURL = toProtocolString(tmp);
if (script->SourceMappingURL().ToLocal(&tmp))
m_sourceMappingURL = toProtocolString(tmp);
m_startLine = script->LineOffset();
m_startColumn = script->ColumnOffset();
std::vector<int> lineEnds = script->LineEnds();
CHECK(lineEnds.size());
int source_length = lineEnds[lineEnds.size() - 1];
if (lineEnds.size()) {
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;
}
} else {
m_endLine = m_startLine;
m_endColumn = m_startColumn;
}

USE(script->ContextId().To(&m_executionContextId));

if (script->Source().ToLocal(&tmp)) {
m_source = toProtocolString(tmp);
}

m_isModule = script->IsModule();

m_script.Reset(m_isolate, script);
m_script.AnnotateStrongRetainer(kGlobalDebuggerScriptHandleLabel);
Initialize(script);
}

bool isLiveEdit() const override { return m_isLiveEdit; }
Expand Down Expand Up @@ -248,17 +219,60 @@ class ActualScript : public V8DebuggerScript {
}

private:
String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) {
v8::Local<v8::String> name;
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name))
return toProtocolString(name);
String16 GetScriptURL(v8::Local<v8::debug::Script> script,
V8InspectorClient* client) {
v8::Local<v8::String> sourceURL;
if (script->SourceURL().ToLocal(&sourceURL) && sourceURL->Length() > 0)
return toProtocolString(sourceURL);
v8::Local<v8::String> v8Name;
if (script->Name().ToLocal(&v8Name) && v8Name->Length() > 0) {
String16 name = toProtocolString(v8Name);
std::unique_ptr<StringBuffer> url =
client->resourceNameToUrl(toStringView(name));
return url ? toString16(url->string()) : name;
}
return String16();
}

v8::Local<v8::debug::Script> script() const override {
return m_script.Get(m_isolate);
}

void Initialize(v8::Local<v8::debug::Script> script) {
v8::Local<v8::String> tmp;
m_hasSourceURLComment =
script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0;
if (script->SourceMappingURL().ToLocal(&tmp))
m_sourceMappingURL = toProtocolString(tmp);
m_startLine = script->LineOffset();
m_startColumn = script->ColumnOffset();
std::vector<int> lineEnds = script->LineEnds();
CHECK(lineEnds.size());
int source_length = lineEnds[lineEnds.size() - 1];
if (lineEnds.size()) {
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;
}
} else {
m_endLine = m_startLine;
m_endColumn = m_startColumn;
}

USE(script->ContextId().To(&m_executionContextId));

if (script->Source().ToLocal(&tmp)) {
m_source = toProtocolString(tmp);
}

m_isModule = script->IsModule();

m_script.Reset(m_isolate, script);
m_script.AnnotateStrongRetainer(kGlobalDebuggerScriptHandleLabel);
}

String16 m_sourceMappingURL;
bool m_isLiveEdit = false;
bool m_isModule = false;
Expand Down Expand Up @@ -392,9 +406,9 @@ class WasmVirtualScript : public V8DebuggerScript {

std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create(
v8::Isolate* isolate, v8::Local<v8::debug::Script> scriptObj,
bool isLiveEdit) {
bool isLiveEdit, V8InspectorClient* client) {
return std::unique_ptr<ActualScript>(
new ActualScript(isolate, scriptObj, isLiveEdit));
new ActualScript(isolate, scriptObj, isLiveEdit, client));
}

std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
Expand All @@ -412,18 +426,16 @@ V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id,

V8DebuggerScript::~V8DebuggerScript() {}

const String16& V8DebuggerScript::sourceURL() const {
return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
}

void V8DebuggerScript::setSourceURL(const String16& sourceURL) {
m_sourceURL = sourceURL;
if (sourceURL.length() > 0) {
m_hasSourceURLComment = true;
m_url = sourceURL;
}
}

bool V8DebuggerScript::setBreakpoint(const String16& condition,
v8::debug::Location* loc, int* id) const {
v8::HandleScope scope(m_isolate);
return script()->SetBreakpoint(toV8String(m_isolate, condition), loc, id);
}

} // namespace v8_inspector
11 changes: 6 additions & 5 deletions deps/v8/src/inspector/v8-debugger-script.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
namespace v8_inspector {

// Forward declaration.
class V8InspectorClient;
class WasmTranslation;

class V8DebuggerScript {
public:
static std::unique_ptr<V8DebuggerScript> Create(
v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
bool isLiveEdit);
bool isLiveEdit, V8InspectorClient* client);
static std::unique_ptr<V8DebuggerScript> CreateWasm(
v8::Isolate* isolate, WasmTranslation* wasmTranslation,
v8::Local<v8::debug::WasmScript> underlyingScript, String16 id,
Expand All @@ -55,9 +56,9 @@ class V8DebuggerScript {
virtual ~V8DebuggerScript();

const String16& scriptId() const { return m_id; }
const String16& url() const { return m_url; }
bool hasSourceURL() const { return !m_sourceURL.isEmpty(); }
const String16& sourceURL() const;
bool hasSourceURLComment() const { return m_hasSourceURLComment; }
const String16& sourceURL() const { return m_url; }

virtual const String16& sourceMappingURL() const = 0;
virtual const String16& source() const = 0;
virtual const String16& hash() const = 0;
Expand Down Expand Up @@ -95,7 +96,7 @@ class V8DebuggerScript {

String16 m_id;
String16 m_url;
String16 m_sourceURL;
bool m_hasSourceURLComment = false;
int m_executionContextId = 0;

v8::Isolate* m_isolate;
Expand Down
13 changes: 8 additions & 5 deletions deps/v8/src/inspector/v8-debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ void V8Debugger::getCompiledScripts(
v8::Local<v8::debug::Script> script = scripts.Get(i);
if (!script->WasCompiled()) continue;
if (script->IsEmbedded()) {
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
result.push_back(V8DebuggerScript::Create(m_isolate, script, false,
m_inspector->client()));
continue;
}
int contextId;
if (!script->ContextId().To(&contextId)) continue;
if (m_inspector->contextGroupId(contextId) != contextGroupId) continue;
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
result.push_back(V8DebuggerScript::Create(m_isolate, script, false,
m_inspector->client()));
}
}

Expand Down Expand Up @@ -542,13 +544,14 @@ void V8Debugger::ScriptCompiled(v8::Local<v8::debug::Script> script,
});
} else if (m_ignoreScriptParsedEventsCounter == 0) {
v8::Isolate* isolate = m_isolate;
V8InspectorClient* client = m_inspector->client();
m_inspector->forEachSession(
m_inspector->contextGroupId(contextId),
[&isolate, &script, &has_compile_error,
&is_live_edited](V8InspectorSessionImpl* session) {
[&isolate, &script, &has_compile_error, &is_live_edited,
&client](V8InspectorSessionImpl* session) {
if (!session->debuggerAgent()->enabled()) return;
session->debuggerAgent()->didParseSource(
V8DebuggerScript::Create(isolate, script, is_live_edited),
V8DebuggerScript::Create(isolate, script, is_live_edited, client),
!has_compile_error);
});
}
Expand Down
Loading

0 comments on commit e668815

Please sign in to comment.