|
6 | 6 |
|
7 | 7 | #include "src/inspector/inspected-context.h" |
8 | 8 | #include "src/inspector/string-util.h" |
| 9 | +#include "src/inspector/v8-inspector-impl.h" |
9 | 10 | #include "src/inspector/wasm-translation.h" |
10 | 11 | #include "src/utils.h" |
11 | 12 |
|
@@ -110,41 +111,11 @@ class ActualScript : public V8DebuggerScript { |
110 | 111 |
|
111 | 112 | public: |
112 | 113 | ActualScript(v8::Isolate* isolate, v8::Local<v8::debug::Script> script, |
113 | | - bool isLiveEdit) |
| 114 | + bool isLiveEdit, V8InspectorClient* client) |
114 | 115 | : V8DebuggerScript(isolate, String16::fromInteger(script->Id()), |
115 | | - GetNameOrSourceUrl(script)), |
| 116 | + GetScriptURL(script, client)), |
116 | 117 | m_isLiveEdit(isLiveEdit) { |
117 | | - v8::Local<v8::String> tmp; |
118 | | - if (script->SourceURL().ToLocal(&tmp)) m_sourceURL = toProtocolString(tmp); |
119 | | - if (script->SourceMappingURL().ToLocal(&tmp)) |
120 | | - m_sourceMappingURL = toProtocolString(tmp); |
121 | | - m_startLine = script->LineOffset(); |
122 | | - m_startColumn = script->ColumnOffset(); |
123 | | - std::vector<int> lineEnds = script->LineEnds(); |
124 | | - CHECK(lineEnds.size()); |
125 | | - int source_length = lineEnds[lineEnds.size() - 1]; |
126 | | - if (lineEnds.size()) { |
127 | | - m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1; |
128 | | - if (lineEnds.size() > 1) { |
129 | | - m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1; |
130 | | - } else { |
131 | | - m_endColumn = source_length + m_startColumn; |
132 | | - } |
133 | | - } else { |
134 | | - m_endLine = m_startLine; |
135 | | - m_endColumn = m_startColumn; |
136 | | - } |
137 | | - |
138 | | - USE(script->ContextId().To(&m_executionContextId)); |
139 | | - |
140 | | - if (script->Source().ToLocal(&tmp)) { |
141 | | - m_source = toProtocolString(tmp); |
142 | | - } |
143 | | - |
144 | | - m_isModule = script->IsModule(); |
145 | | - |
146 | | - m_script.Reset(m_isolate, script); |
147 | | - m_script.AnnotateStrongRetainer(kGlobalDebuggerScriptHandleLabel); |
| 118 | + Initialize(script); |
148 | 119 | } |
149 | 120 |
|
150 | 121 | bool isLiveEdit() const override { return m_isLiveEdit; } |
@@ -248,17 +219,60 @@ class ActualScript : public V8DebuggerScript { |
248 | 219 | } |
249 | 220 |
|
250 | 221 | private: |
251 | | - String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { |
252 | | - v8::Local<v8::String> name; |
253 | | - if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) |
254 | | - 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 | + } |
255 | 234 | return String16(); |
256 | 235 | } |
257 | 236 |
|
258 | 237 | v8::Local<v8::debug::Script> script() const override { |
259 | 238 | return m_script.Get(m_isolate); |
260 | 239 | } |
261 | 240 |
|
| 241 | + void Initialize(v8::Local<v8::debug::Script> script) { |
| 242 | + v8::Local<v8::String> tmp; |
| 243 | + m_hasSourceURLComment = |
| 244 | + script->SourceURL().ToLocal(&tmp) && tmp->Length() > 0; |
| 245 | + if (script->SourceMappingURL().ToLocal(&tmp)) |
| 246 | + m_sourceMappingURL = toProtocolString(tmp); |
| 247 | + m_startLine = script->LineOffset(); |
| 248 | + m_startColumn = script->ColumnOffset(); |
| 249 | + std::vector<int> lineEnds = script->LineEnds(); |
| 250 | + CHECK(lineEnds.size()); |
| 251 | + int source_length = lineEnds[lineEnds.size() - 1]; |
| 252 | + if (lineEnds.size()) { |
| 253 | + m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1; |
| 254 | + if (lineEnds.size() > 1) { |
| 255 | + m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1; |
| 256 | + } else { |
| 257 | + m_endColumn = source_length + m_startColumn; |
| 258 | + } |
| 259 | + } else { |
| 260 | + m_endLine = m_startLine; |
| 261 | + m_endColumn = m_startColumn; |
| 262 | + } |
| 263 | + |
| 264 | + USE(script->ContextId().To(&m_executionContextId)); |
| 265 | + |
| 266 | + if (script->Source().ToLocal(&tmp)) { |
| 267 | + m_source = toProtocolString(tmp); |
| 268 | + } |
| 269 | + |
| 270 | + m_isModule = script->IsModule(); |
| 271 | + |
| 272 | + m_script.Reset(m_isolate, script); |
| 273 | + m_script.AnnotateStrongRetainer(kGlobalDebuggerScriptHandleLabel); |
| 274 | + } |
| 275 | + |
262 | 276 | String16 m_sourceMappingURL; |
263 | 277 | bool m_isLiveEdit = false; |
264 | 278 | bool m_isModule = false; |
@@ -392,9 +406,9 @@ class WasmVirtualScript : public V8DebuggerScript { |
392 | 406 |
|
393 | 407 | std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create( |
394 | 408 | v8::Isolate* isolate, v8::Local<v8::debug::Script> scriptObj, |
395 | | - bool isLiveEdit) { |
| 409 | + bool isLiveEdit, V8InspectorClient* client) { |
396 | 410 | return std::unique_ptr<ActualScript>( |
397 | | - new ActualScript(isolate, scriptObj, isLiveEdit)); |
| 411 | + new ActualScript(isolate, scriptObj, isLiveEdit, client)); |
398 | 412 | } |
399 | 413 |
|
400 | 414 | std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm( |
@@ -412,18 +426,16 @@ V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, |
412 | 426 |
|
413 | 427 | V8DebuggerScript::~V8DebuggerScript() {} |
414 | 428 |
|
415 | | -const String16& V8DebuggerScript::sourceURL() const { |
416 | | - return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
417 | | -} |
418 | | - |
419 | 429 | void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
420 | | - m_sourceURL = sourceURL; |
| 430 | + if (sourceURL.length() > 0) { |
| 431 | + m_hasSourceURLComment = true; |
| 432 | + m_url = sourceURL; |
| 433 | + } |
421 | 434 | } |
422 | 435 |
|
423 | 436 | bool V8DebuggerScript::setBreakpoint(const String16& condition, |
424 | 437 | v8::debug::Location* loc, int* id) const { |
425 | 438 | v8::HandleScope scope(m_isolate); |
426 | 439 | return script()->SetBreakpoint(toV8String(m_isolate, condition), loc, id); |
427 | 440 | } |
428 | | - |
429 | 441 | } // namespace v8_inspector |