9#include "src/inspector/protocol/Debugger.h"
19const char kGlobalDebuggerScriptHandleLabel[] =
"DevTools debugger";
22 uint32_t length = source->Length();
23 std::unique_ptr<UChar[]> buffer(
new UChar[length]);
24 source->WriteV2(isolate, 0, length,
25 reinterpret_cast<uint16_t*
>(buffer.get()));
27 const uint8_t* data =
nullptr;
28 size_t sizeInBytes =
sizeof(
UChar) * length;
29 data =
reinterpret_cast<const uint8_t*
>(buffer.get());
34 String16Builder formatted_hash;
36 formatted_hash.appendUnsignedAsHex(
static_cast<uint8_t
>(hash[
i]));
38 return formatted_hash.toString();
41class ActualScript :
public V8DebuggerScript {
42 friend class V8DebuggerScript;
46 bool isLiveEdit, V8DebuggerAgentImpl* agent,
47 V8InspectorClient* client)
48 : V8DebuggerScript(isolate, String16::fromInteger(script->Id()),
49 GetScriptURL(isolate, script, client),
50 GetScriptName(isolate, script, client)),
56 bool isLiveEdit()
const override {
return m_isLiveEdit; }
57 bool isModule()
const override {
return m_isModule; }
59 String16
source(
size_t pos,
size_t len)
const override {
65 if (
pos >=
static_cast<size_t>(v8Source->Length()))
return String16();
66 size_t substringLength =
67 std::min(len,
static_cast<size_t>(v8Source->Length()) -
pos);
68 std::unique_ptr<UChar[]> buffer(
new UChar[substringLength]);
70 static_cast<uint32_t
>(substringLength),
71 reinterpret_cast<uint16_t*
>(buffer.get()));
72 return String16(buffer.get(), substringLength);
74 Language getLanguage()
const override {
return m_language; }
76#if V8_ENABLE_WEBASSEMBLY
86 std::vector<v8::debug::WasmScript::DebugSymbols> getDebugSymbols()
88 auto script = this->script();
89 if (!script->IsWasm())
90 return std::vector<v8::debug::WasmScript::DebugSymbols>();
91 return v8::debug::WasmScript::Cast(*script)->GetDebugSymbols();
95 std::vector<int>* function_body_offsets)
const override {
99 v8::debug::WasmScript::Cast(*script)->Disassemble(collector,
100 function_body_offsets);
104 int startLine()
const override {
return m_startLine; }
106 int endLine()
const override {
return m_endLine; }
107 int endColumn()
const override {
return m_endColumn; }
108 int codeOffset()
const override {
109#if V8_ENABLE_WEBASSEMBLY
110 if (script()->IsWasm()) {
111 return v8::debug::WasmScript::Cast(*script())->CodeOffset();
116 int length()
const override {
120 const String16& sourceMappingURL()
const override {
124 void setSourceMappingURL(
const String16& sourceMappingURL)
override {
128 void setSource(
const String16& newSource,
bool preview,
129 bool allowTopFrameLiveEditing,
134 v8Source, preview, allowTopFrameLiveEditing,
result)) {
139 if (preview ||
result->script.IsEmpty())
return;
142 Initialize(scope.Escape(
result->script));
145 bool getPossibleBreakpoints(
147 bool restrictToFunction,
148 std::vector<v8::debug::BreakLocation>* locations)
override {
151 std::vector<v8::debug::BreakLocation> allLocations;
152 if (!script->GetPossibleBreakpoints(
start,
end, restrictToFunction,
156 if (allLocations.empty())
return true;
158 for (
size_t i = 1;
i < allLocations.size(); ++
i) {
159 if (allLocations[
i].GetLineNumber() == current.GetLineNumber() &&
160 allLocations[
i].GetColumnNumber() == current.GetColumnNumber()) {
168 current = allLocations[
i];
173 allLocations[
i].GetLineNumber() > current.GetLineNumber() ||
174 (allLocations[
i].GetColumnNumber() >= current.GetColumnNumber() &&
175 allLocations[
i].GetLineNumber() == current.GetLineNumber()));
176 locations->push_back(current);
177 current = allLocations[
i];
180 locations->push_back(current);
184 void resetBlackboxedStateCache()
override {
201 int*
id)
const override {
207 bool setInstrumentationBreakpoint(
int*
id)
const override {
209 return script()->SetInstrumentationBreakpoint(
id);
212 const String16& hash()
const override {
224 String16 buildId()
const override {
225#if V8_ENABLE_WEBASSEMBLY
228 auto maybe_build_id =
229 v8::debug::WasmScript::Cast(*script)->GetModuleBuildId();
230 if (maybe_build_id.IsJust()) {
232 String16Builder buildIdFormatter;
233 for (
size_t i = 0;
i < buildId.
size();
i++) {
234 buildIdFormatter.appendUnsignedAsHex(
235 static_cast<uint8_t
>(buildId[
i]));
237 return buildIdFormatter.toString();
247 V8InspectorClient* client) {
249 if (script->SourceURL().ToLocal(&sourceURL) && sourceURL->Length() > 0)
251 return GetScriptName(isolate, script, client);
254 static String16 GetScriptName(
v8::Isolate* isolate,
256 V8InspectorClient* client) {
258 if (script->Name().ToLocal(&v8Name) && v8Name->Length() > 0) {
260 std::unique_ptr<StringBuffer> url =
262 return url ?
toString16(url->string()) : name;
273 m_hasSourceURLComment =
274 script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0;
275 if (script->SourceMappingURL().ToLocal(&tmp))
282 USE(script->ContextId().To(&m_executionContextId));
284#if V8_ENABLE_WEBASSEMBLY
285 if (script->IsWasm()) {
292 bool hasHash = script->GetSha256Hash().ToLocal(&tmp) && tmp->Length() > 0;
300 m_scriptSource.AnnotateStrongRetainer(kGlobalDebuggerScriptHandleLabel);
307 data.GetParameter()->WeakCallback();
314 m_agent->ScriptCollected(
this);
336 return std::make_unique<ActualScript>(isolate, scriptObj,
isLiveEdit, agent,
342 : m_id(
std::move(id)),
343 m_url(
std::move(url)),
345 m_embedderName(embedderName) {}
356#if V8_ENABLE_WEBASSEMBLY
357void V8DebuggerScript::removeWasmBreakpoint(
int id) {
359 script()->RemoveWasmBreakpoint(
id);
interpreter::Bytecode bytecode
constexpr size_t size() const
V8_INLINE void AnnotateStrongRetainer(const char *label)
V8_INLINE Local< T > Get(Isolate *isolate) const
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackInfo< P >::Callback callback, WeakCallbackType type)
static V8_INLINE Local< String > Empty(Isolate *isolate)
bool SetScriptSource(v8::Local< v8::String > newSource, bool preview, bool allow_top_frame_live_editing, LiveEditResult *result) const
v8::debug::Location GetSourceLocation(int offset) const
Maybe< int > GetSourceOffset(const debug::Location &location, GetSourceOffsetMode mode=GetSourceOffsetMode::kStrict) const
virtual v8::Local< v8::debug::Script > script() const =0
static std::unique_ptr< V8DebuggerScript > Create(v8::Isolate *isolate, v8::Local< v8::debug::Script > script, bool isLiveEdit, V8DebuggerAgentImpl *agent, V8InspectorClient *client)
virtual bool isLiveEdit() const =0
V8DebuggerScript(const V8DebuggerScript &)=delete
const String16 & sourceURL() const
void setSourceURL(const String16 &)
bool m_hasSourceURLComment
virtual ~V8DebuggerScript()
ZoneVector< RpoNumber > & result
InstructionOperand source
void(*)(const LivenessBroker &, const void *) WeakCallback
void MakeWeak(i::Address *location, void *parameter, WeakCallbackInfo< void >::Callback weak_callback, WeakCallbackType type)
void ResetBlackboxedStateCache(Isolate *v8_isolate, Local< Script > script)
void Disassemble(const WasmModule *module, ModuleWireBytes wire_bytes, NamesProvider *names, v8::debug::DisassemblyCollector *collector, std::vector< int > *function_body_offsets)
const uint8_t * SHA256_hash(const void *data, size_t len, uint8_t *digest)
String16 toProtocolString(v8::Isolate *isolate, v8::Local< v8::String > value)
StringView toStringView(const String16 &string)
v8::Local< v8::String > toV8String(v8::Isolate *isolate, const String16 &string)
String16 toString16(const StringView &string)
Maybe< T > Just(const T &t)
const size_t kSizeOfSha256Digest
#define DCHECK(condition)
v8::Global< v8::debug::ScriptSource > m_scriptSource
String16 m_sourceMappingURL
V8DebuggerAgentImpl * m_agent
v8::Global< v8::debug::Script > m_script