Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/inspector/v8-debugger-script.cc

Issue 2671193002: [inspector] restore provisional breakpoints smarter (Closed)
Patch Set: addressed comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/search-util.h"
8 #include "src/inspector/string-util.h" 9 #include "src/inspector/string-util.h"
9 #include "src/inspector/wasm-translation.h" 10 #include "src/inspector/wasm-translation.h"
10 11
11 namespace v8_inspector { 12 namespace v8_inspector {
12 13
13 namespace { 14 namespace {
14 15
15 const char hexDigits[17] = "0123456789ABCDEF"; 16 const char hexDigits[17] = "0123456789ABCDEF";
16 17
17 void appendUnsignedAsHex(uint64_t number, String16Builder* destination) { 18 void appendUnsignedAsHex(uint64_t number, String16Builder* destination) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 m_script.Reset(m_isolate, script); 148 m_script.Reset(m_isolate, script);
148 } 149 }
149 150
150 bool isLiveEdit() const override { return m_isLiveEdit; } 151 bool isLiveEdit() const override { return m_isLiveEdit; }
151 bool isModule() const override { return m_isModule; } 152 bool isModule() const override { return m_isModule; }
152 153
153 const String16& sourceMappingURL() const override { 154 const String16& sourceMappingURL() const override {
154 return m_sourceMappingURL; 155 return m_sourceMappingURL;
155 } 156 }
156 157
157 String16 source(v8::Isolate* isolate) const override { 158 String16 source() const override {
159 v8::HandleScope scope(m_isolate);
158 if (!m_sourceObj.IsEmpty()) 160 if (!m_sourceObj.IsEmpty())
159 return toProtocolString(m_sourceObj.Get(isolate)); 161 return toProtocolString(m_sourceObj.Get(m_isolate));
160 return V8DebuggerScript::source(isolate); 162 return V8DebuggerScript::source();
161 } 163 }
162 164
163 void setSourceMappingURL(const String16& sourceMappingURL) override { 165 void setSourceMappingURL(const String16& sourceMappingURL) override {
164 m_sourceMappingURL = sourceMappingURL; 166 m_sourceMappingURL = sourceMappingURL;
165 } 167 }
166 168
167 void setSource(v8::Local<v8::String> source) override { 169 void setSource(v8::Local<v8::String> source) override {
168 m_source = String16(); 170 std::vector<int> empty;
171 m_lineEndings.swap(empty);
169 m_sourceObj.Reset(m_isolate, source); 172 m_sourceObj.Reset(m_isolate, source);
170 m_hash = String16(); 173 m_hash = String16();
171 } 174 }
172 175
173 bool getPossibleBreakpoints( 176 bool getPossibleBreakpoints(
174 const v8::debug::Location& start, const v8::debug::Location& end, 177 const v8::debug::Location& start, const v8::debug::Location& end,
175 std::vector<v8::debug::Location>* locations) override { 178 std::vector<v8::debug::Location>* locations) override {
176 v8::HandleScope scope(m_isolate); 179 v8::HandleScope scope(m_isolate);
177 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); 180 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate);
178 return script->GetPossibleBreakpoints(start, end, locations); 181 return script->GetPossibleBreakpoints(start, end, locations);
179 } 182 }
180 183
181 void resetBlackboxedStateCache() override { 184 void resetBlackboxedStateCache() override {
182 v8::HandleScope scope(m_isolate); 185 v8::HandleScope scope(m_isolate);
183 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); 186 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate));
184 } 187 }
185 188
186 private: 189 private:
190 void calculateLineEndings() override {
191 if (!m_lineEndings.empty()) return;
192 v8::HandleScope scope(m_isolate);
193 m_script.Get(m_isolate)->LineEnds().swap(m_lineEndings);
194 }
195
187 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { 196 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) {
188 v8::Local<v8::String> name; 197 v8::Local<v8::String> name;
189 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) 198 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name))
190 return toProtocolString(name); 199 return toProtocolString(name);
191 return String16(); 200 return String16();
192 } 201 }
193 202
194 String16 m_sourceMappingURL; 203 String16 m_sourceMappingURL;
195 v8::Global<v8::String> m_sourceObj; 204 v8::Global<v8::String> m_sourceObj;
196 bool m_isLiveEdit = false; 205 bool m_isLiveEdit = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 for (v8::debug::Location& loc : *locations) { 261 for (v8::debug::Location& loc : *locations) {
253 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, 262 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId,
254 scriptId()); 263 scriptId());
255 } 264 }
256 return success; 265 return success;
257 } 266 }
258 267
259 void resetBlackboxedStateCache() override {} 268 void resetBlackboxedStateCache() override {}
260 269
261 private: 270 private:
271 void calculateLineEndings() override {
alph 2017/02/08 02:02:08 ensureLineEndings?
272 if (!m_lineEndings.empty()) return;
273 String16 text = source();
274 const String16 lineEndString = "\n";
275 size_t start = 0;
276 while (start < text.length()) {
277 size_t lineEnd = text.find(lineEndString, start);
alph 2017/02/08 02:02:08 nit: find(UChar) should be faster.
278 if (lineEnd == String16::kNotFound) break;
279 m_lineEndings.push_back(static_cast<int>(lineEnd));
280 start = lineEnd + 1;
281 }
282 m_lineEndings.push_back(static_cast<int>(text.length()));
283 }
284
262 static const String16& emptyString() { 285 static const String16& emptyString() {
263 static const String16 singleEmptyString; 286 static const String16 singleEmptyString;
264 return singleEmptyString; 287 return singleEmptyString;
265 } 288 }
266 289
267 v8::Global<v8::debug::WasmScript> m_script; 290 v8::Global<v8::debug::WasmScript> m_script;
268 WasmTranslation* m_wasmTranslation; 291 WasmTranslation* m_wasmTranslation;
269 }; 292 };
270 293
271 } // namespace 294 } // namespace
(...skipping 17 matching lines...) Expand all
289 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, 312 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id,
290 String16 url) 313 String16 url)
291 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {} 314 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {}
292 315
293 V8DebuggerScript::~V8DebuggerScript() {} 316 V8DebuggerScript::~V8DebuggerScript() {}
294 317
295 const String16& V8DebuggerScript::sourceURL() const { 318 const String16& V8DebuggerScript::sourceURL() const {
296 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; 319 return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
297 } 320 }
298 321
299 const String16& V8DebuggerScript::hash(v8::Isolate* isolate) const { 322 const String16& V8DebuggerScript::hash() const {
300 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); 323 if (m_hash.isEmpty()) m_hash = calculateHash(source());
301 DCHECK(!m_hash.isEmpty()); 324 DCHECK(!m_hash.isEmpty());
302 return m_hash; 325 return m_hash;
303 } 326 }
304 327
305 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { 328 void V8DebuggerScript::setSourceURL(const String16& sourceURL) {
306 m_sourceURL = sourceURL; 329 m_sourceURL = sourceURL;
307 } 330 }
308 331
332 String16 V8DebuggerScript::lineAt(int lineNumberWithOffset, int maxLength) {
333 String16 sourceStr = source();
334 calculateLineEndings();
335 int lineNumber = lineNumberWithOffset - m_startLine;
336 if (lineNumber >= static_cast<int>(m_lineEndings.size()) || lineNumber < 0)
alph 2017/02/08 02:02:08 {}
337 return String16();
338 size_t lineEnd = m_lineEndings[lineNumber];
339 size_t lineStart = lineNumber > 0 ? m_lineEndings[lineNumber - 1] + 1 : 0;
340 String16 line = sourceStr.substring(lineStart, lineEnd - lineStart);
341 if (line.length() && line[line.length() - 1] == '\r')
alph 2017/02/08 02:02:08 {}
342 line = line.substring(0, line.length() - 1);
343 if (maxLength) line = line.substring(0, maxLength);
344 return line;
345 }
346
309 } // namespace v8_inspector 347 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698