OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-debugger-script.h" | 5 #include "src/inspector/v8-debugger-script.h" |
6 | 6 |
7 #include "src/inspector/inspected-context.h" | 7 #include "src/inspector/inspected-context.h" |
8 #include "src/inspector/string-util.h" | 8 #include "src/inspector/string-util.h" |
9 #include "src/inspector/wasm-translation.h" | 9 #include "src/inspector/wasm-translation.h" |
10 | 10 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 m_endColumn = m_startColumn; | 126 m_endColumn = m_startColumn; |
127 } | 127 } |
128 | 128 |
129 v8::Local<v8::Value> contextData; | 129 v8::Local<v8::Value> contextData; |
130 if (script->ContextData().ToLocal(&contextData) && contextData->IsInt32()) { | 130 if (script->ContextData().ToLocal(&contextData) && contextData->IsInt32()) { |
131 m_executionContextId = | 131 m_executionContextId = |
132 static_cast<int>(contextData.As<v8::Int32>()->Value()); | 132 static_cast<int>(contextData.As<v8::Int32>()->Value()); |
133 } | 133 } |
134 | 134 |
135 if (script->Source().ToLocal(&tmp)) { | 135 if (script->Source().ToLocal(&tmp)) { |
136 m_sourceObj.Reset(m_isolate, tmp); | 136 m_source = toProtocolString(tmp); |
137 String16 source = toProtocolString(tmp); | |
138 // V8 will not count last line if script source ends with \n. | 137 // V8 will not count last line if script source ends with \n. |
139 if (source.length() > 1 && source[source.length() - 1] == '\n') { | 138 if (m_source.length() > 1 && m_source[m_source.length() - 1] == '\n') { |
140 m_endLine++; | 139 m_endLine++; |
141 m_endColumn = 0; | 140 m_endColumn = 0; |
142 } | 141 } |
143 } | 142 } |
144 | 143 |
145 m_isModule = script->IsModule(); | 144 m_isModule = script->IsModule(); |
146 | 145 |
147 m_script.Reset(m_isolate, script); | 146 m_script.Reset(m_isolate, script); |
148 } | 147 } |
149 | 148 |
150 bool isLiveEdit() const override { return m_isLiveEdit; } | 149 bool isLiveEdit() const override { return m_isLiveEdit; } |
151 bool isModule() const override { return m_isModule; } | 150 bool isModule() const override { return m_isModule; } |
152 | 151 |
153 const String16& sourceMappingURL() const override { | 152 const String16& sourceMappingURL() const override { |
154 return m_sourceMappingURL; | 153 return m_sourceMappingURL; |
155 } | 154 } |
156 | 155 |
157 String16 source(v8::Isolate* isolate) const override { | |
158 if (!m_sourceObj.IsEmpty()) | |
159 return toProtocolString(m_sourceObj.Get(isolate)); | |
160 return V8DebuggerScript::source(isolate); | |
161 } | |
162 | |
163 void setSourceMappingURL(const String16& sourceMappingURL) override { | 156 void setSourceMappingURL(const String16& sourceMappingURL) override { |
164 m_sourceMappingURL = sourceMappingURL; | 157 m_sourceMappingURL = sourceMappingURL; |
165 } | 158 } |
166 | 159 |
167 void setSource(v8::Local<v8::String> source) override { | |
168 m_source = String16(); | |
169 m_sourceObj.Reset(m_isolate, source); | |
170 m_hash = String16(); | |
171 } | |
172 | |
173 bool getPossibleBreakpoints( | 160 bool getPossibleBreakpoints( |
174 const v8::debug::Location& start, const v8::debug::Location& end, | 161 const v8::debug::Location& start, const v8::debug::Location& end, |
175 std::vector<v8::debug::Location>* locations) override { | 162 std::vector<v8::debug::Location>* locations) override { |
176 v8::HandleScope scope(m_isolate); | 163 v8::HandleScope scope(m_isolate); |
177 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 164 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
178 return script->GetPossibleBreakpoints(start, end, locations); | 165 return script->GetPossibleBreakpoints(start, end, locations); |
179 } | 166 } |
180 | 167 |
181 void resetBlackboxedStateCache() override { | 168 void resetBlackboxedStateCache() override { |
182 v8::HandleScope scope(m_isolate); | 169 v8::HandleScope scope(m_isolate); |
183 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); | 170 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); |
184 } | 171 } |
185 | 172 |
| 173 int offset(int lineNumber, int columnNumber) const override { |
| 174 v8::HandleScope scope(m_isolate); |
| 175 return m_script.Get(m_isolate)->Offset( |
| 176 v8::debug::Location(lineNumber, columnNumber)); |
| 177 } |
| 178 |
| 179 v8::debug::Location position(int offset) const override { |
| 180 v8::HandleScope scope(m_isolate); |
| 181 return m_script.Get(m_isolate)->Position(offset); |
| 182 } |
| 183 |
186 private: | 184 private: |
187 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { | 185 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { |
188 v8::Local<v8::String> name; | 186 v8::Local<v8::String> name; |
189 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) | 187 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) |
190 return toProtocolString(name); | 188 return toProtocolString(name); |
191 return String16(); | 189 return String16(); |
192 } | 190 } |
193 | 191 |
194 String16 m_sourceMappingURL; | 192 String16 m_sourceMappingURL; |
195 v8::Global<v8::String> m_sourceObj; | |
196 bool m_isLiveEdit = false; | 193 bool m_isLiveEdit = false; |
197 bool m_isModule = false; | 194 bool m_isModule = false; |
198 v8::Global<v8::debug::Script> m_script; | 195 v8::Global<v8::debug::Script> m_script; |
199 }; | 196 }; |
200 | 197 |
201 class WasmVirtualScript : public V8DebuggerScript { | 198 class WasmVirtualScript : public V8DebuggerScript { |
202 friend class V8DebuggerScript; | 199 friend class V8DebuggerScript; |
203 | 200 |
204 public: | 201 public: |
205 WasmVirtualScript(v8::Isolate* isolate, WasmTranslation* wasmTranslation, | 202 WasmVirtualScript(v8::Isolate* isolate, WasmTranslation* wasmTranslation, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 translatedEnd, locations); | 248 translatedEnd, locations); |
252 for (v8::debug::Location& loc : *locations) { | 249 for (v8::debug::Location& loc : *locations) { |
253 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, | 250 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, |
254 scriptId()); | 251 scriptId()); |
255 } | 252 } |
256 return success; | 253 return success; |
257 } | 254 } |
258 | 255 |
259 void resetBlackboxedStateCache() override {} | 256 void resetBlackboxedStateCache() override {} |
260 | 257 |
| 258 int offset(int lineNumber, int columnNumber) const override { |
| 259 return kNoOffset; |
| 260 } |
| 261 |
| 262 v8::debug::Location position(int offset) const override { |
| 263 return v8::debug::Location(); |
| 264 } |
| 265 |
261 private: | 266 private: |
262 static const String16& emptyString() { | 267 static const String16& emptyString() { |
263 static const String16 singleEmptyString; | 268 static const String16 singleEmptyString; |
264 return singleEmptyString; | 269 return singleEmptyString; |
265 } | 270 } |
266 | 271 |
267 v8::Global<v8::debug::WasmScript> m_script; | 272 v8::Global<v8::debug::WasmScript> m_script; |
268 WasmTranslation* m_wasmTranslation; | 273 WasmTranslation* m_wasmTranslation; |
269 }; | 274 }; |
270 | 275 |
(...skipping 18 matching lines...) Expand all Loading... |
289 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, | 294 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, |
290 String16 url) | 295 String16 url) |
291 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {} | 296 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {} |
292 | 297 |
293 V8DebuggerScript::~V8DebuggerScript() {} | 298 V8DebuggerScript::~V8DebuggerScript() {} |
294 | 299 |
295 const String16& V8DebuggerScript::sourceURL() const { | 300 const String16& V8DebuggerScript::sourceURL() const { |
296 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 301 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
297 } | 302 } |
298 | 303 |
299 const String16& V8DebuggerScript::hash(v8::Isolate* isolate) const { | 304 const String16& V8DebuggerScript::hash() const { |
300 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); | 305 if (m_hash.isEmpty()) m_hash = calculateHash(source()); |
301 DCHECK(!m_hash.isEmpty()); | 306 DCHECK(!m_hash.isEmpty()); |
302 return m_hash; | 307 return m_hash; |
303 } | 308 } |
304 | 309 |
305 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 310 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
306 m_sourceURL = sourceURL; | 311 m_sourceURL = sourceURL; |
307 } | 312 } |
308 | 313 |
309 } // namespace v8_inspector | 314 } // namespace v8_inspector |
OLD | NEW |