Commit a9017cb0 authored by clemensh's avatar clemensh Committed by Commit bot

[inspector] Split V8DebuggerScript implementation for wasm

Make some methods on V8DebuggerScript virtual and provide the
implementations ActualScript for scripts which are backed by scripts on
V8's side, and WasmVirtualScript for wasm scripts.

The added test case ensures that we at least don't crash on the attempt
to get breakable locations for wasm "scripts", which we did previously.
Returning a reasonable result for wasm will be implemented in a
follow-up commit.

R=yangguo@chromium.org, jgruber@chromium.org
BUG=chromium:667767,chromium:613110

Review-Url: https://codereview.chromium.org/2532433003
Cr-Commit-Position: refs/heads/master@{#41527}
parent 9c9c8d7b
This diff is collapsed.
......@@ -32,6 +32,7 @@
#include "src/base/macros.h"
#include "src/inspector/string-16.h"
#include "src/inspector/string-util.h"
#include "include/v8.h"
#include "src/debug/debug-interface.h"
......@@ -40,42 +41,46 @@ namespace v8_inspector {
class V8DebuggerScript {
public:
V8DebuggerScript(v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
bool isLiveEdit);
V8DebuggerScript(String16 id, String16 url, String16 source);
~V8DebuggerScript();
static std::unique_ptr<V8DebuggerScript> Create(
v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
bool isLiveEdit);
static std::unique_ptr<V8DebuggerScript> CreateWasm(
v8::Isolate* isolate, v8::Local<v8::debug::WasmScript> underlyingScript,
String16 id, String16 url, String16 source);
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;
const String16& sourceMappingURL() const { return m_sourceMappingURL; }
String16 source(v8::Isolate*) const;
virtual const String16& sourceMappingURL() const = 0;
virtual String16 source(v8::Isolate*) const { return m_source; }
const String16& hash(v8::Isolate*) const;
int startLine() const { return m_startLine; }
int startColumn() const { return m_startColumn; }
int endLine() const { return m_endLine; }
int endColumn() const { return m_endColumn; }
int executionContextId() const { return m_executionContextId; }
const String16& executionContextAuxData() const {
return m_executionContextAuxData;
}
bool isLiveEdit() const { return m_isLiveEdit; }
virtual const String16& executionContextAuxData() const = 0;
virtual bool isLiveEdit() const = 0;
void setSourceURL(const String16&);
void setSourceMappingURL(const String16&);
void setSource(v8::Local<v8::String>);
virtual void setSourceMappingURL(const String16&) = 0;
virtual void setSource(v8::Local<v8::String> source) {
m_source = toProtocolString(source);
}
bool getPossibleBreakpoints(const v8::debug::Location& start,
const v8::debug::Location& end,
std::vector<v8::debug::Location>* locations);
virtual bool getPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
std::vector<v8::debug::Location>* locations) = 0;
protected:
V8DebuggerScript(v8::Isolate*, String16 id, String16 url);
private:
String16 m_id;
String16 m_url;
String16 m_sourceURL;
String16 m_sourceMappingURL;
v8::Global<v8::String> m_sourceObj;
String16 m_source;
mutable String16 m_hash;
int m_startLine = 0;
......@@ -83,12 +88,10 @@ class V8DebuggerScript {
int m_endLine = 0;
int m_endColumn = 0;
int m_executionContextId = 0;
String16 m_executionContextAuxData;
bool m_isLiveEdit = false;
v8::Isolate* m_isolate;
v8::Global<v8::debug::Script> m_script;
private:
DISALLOW_COPY_AND_ASSIGN(V8DebuggerScript);
};
......
......@@ -127,8 +127,7 @@ void V8Debugger::getCompiledScripts(
if (!script->ContextData().ToLocal(&v8ContextData)) continue;
String16 contextData = toProtocolString(v8ContextData);
if (contextData.find(contextPrefix) != 0) continue;
result.push_back(std::unique_ptr<V8DebuggerScript>(
new V8DebuggerScript(m_isolate, script, false)));
result.push_back(V8DebuggerScript::Create(m_isolate, script, false));
}
}
......@@ -590,8 +589,7 @@ void V8Debugger::handleV8DebugEvent(
m_wasmTranslation.AddScript(script.As<v8::debug::WasmScript>(), agent);
} else if (m_ignoreScriptParsedEventsCounter == 0) {
agent->didParseSource(
std::unique_ptr<V8DebuggerScript>(
new V8DebuggerScript(m_isolate, script, inLiveEditScope)),
V8DebuggerScript::Create(m_isolate, script, inLiveEditScope),
event == v8::AfterCompile);
}
} else if (event == v8::Exception) {
......
......@@ -167,17 +167,18 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
String16 fake_script_id = GetFakeScriptId(underlyingScriptId, func_idx);
String16 fake_script_url = GetFakeScriptUrl(isolate, func_idx);
v8::Local<debug::WasmScript> script = script_.Get(isolate);
// TODO(clemensh): Generate disassembly lazily when queried by the frontend.
debug::WasmDisassembly disassembly =
script_.Get(isolate)->DisassembleFunction(func_idx);
debug::WasmDisassembly disassembly = script->DisassembleFunction(func_idx);
DCHECK_EQ(0, offset_tables_.count(func_idx));
offset_tables_.insert(
std::make_pair(func_idx, std::move(disassembly.offset_table)));
String16 source(disassembly.disassembly.data(),
disassembly.disassembly.length());
std::unique_ptr<V8DebuggerScript> fake_script(new V8DebuggerScript(
fake_script_id, std::move(fake_script_url), source));
std::unique_ptr<V8DebuggerScript> fake_script =
V8DebuggerScript::CreateWasm(isolate, script, fake_script_id,
std::move(fake_script_url), source);
translation->AddFakeScript(fake_script->scriptId(), this);
agent->didParseSource(std::move(fake_script), true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment