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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 return m_sourceMappingURL; | 148 return m_sourceMappingURL; |
149 } | 149 } |
150 | 150 |
151 void setSourceMappingURL(const String16& sourceMappingURL) override { | 151 void setSourceMappingURL(const String16& sourceMappingURL) override { |
152 m_sourceMappingURL = sourceMappingURL; | 152 m_sourceMappingURL = sourceMappingURL; |
153 } | 153 } |
154 | 154 |
155 bool getPossibleBreakpoints( | 155 bool getPossibleBreakpoints( |
156 const v8::debug::Location& start, const v8::debug::Location& end, | 156 const v8::debug::Location& start, const v8::debug::Location& end, |
157 bool restrictToFunction, | 157 bool restrictToFunction, |
158 std::vector<v8::debug::Location>* locations) override { | 158 std::vector<v8::debug::BreakLocation>* locations) override { |
159 v8::HandleScope scope(m_isolate); | 159 v8::HandleScope scope(m_isolate); |
160 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 160 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
161 return script->GetPossibleBreakpoints(start, end, restrictToFunction, | 161 std::vector<v8::debug::BreakLocation> allLocations; |
162 locations); | 162 if (!script->GetPossibleBreakpoints(start, end, restrictToFunction, |
163 &allLocations)) { | |
164 return false; | |
165 } | |
166 if (!allLocations.size()) return true; | |
167 v8::debug::BreakLocation current = allLocations[0]; | |
168 for (size_t i = 1; i < allLocations.size(); ++i) { | |
169 if (allLocations[i].GetLineNumber() == current.GetLineNumber() && | |
170 allLocations[i].GetColumnNumber() == current.GetColumnNumber()) { | |
171 if (allLocations[i].type() != v8::debug::kCommonBreakLocation) { | |
172 // debugger can returns more then one break location at the same | |
173 // source location, e.g. foo() - in this case there are two break | |
174 // locations before foo: for statement and for function call, we can | |
175 // merge them for inspector and report only one with call type. | |
176 current = allLocations[i]; | |
Yang
2017/03/06 14:41:11
Can we DCHECK that we only overwrite a common brea
kozy
2017/03/06 18:25:25
I added DCHECK and it was failed on generator func
| |
177 } | |
178 } else { | |
179 // we assume that returned break locations are sorted. | |
180 DCHECK( | |
181 allLocations[i].GetLineNumber() > current.GetLineNumber() || | |
182 (allLocations[i].GetColumnNumber() >= current.GetColumnNumber() && | |
183 allLocations[i].GetLineNumber() == current.GetLineNumber())); | |
184 locations->push_back(current); | |
185 current = allLocations[i]; | |
186 } | |
187 } | |
188 locations->push_back(current); | |
189 return true; | |
163 } | 190 } |
164 | 191 |
165 void resetBlackboxedStateCache() override { | 192 void resetBlackboxedStateCache() override { |
166 v8::HandleScope scope(m_isolate); | 193 v8::HandleScope scope(m_isolate); |
167 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); | 194 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); |
168 } | 195 } |
169 | 196 |
170 int offset(int lineNumber, int columnNumber) const override { | 197 int offset(int lineNumber, int columnNumber) const override { |
171 v8::HandleScope scope(m_isolate); | 198 v8::HandleScope scope(m_isolate); |
172 return m_script.Get(m_isolate)->GetSourceOffset( | 199 return m_script.Get(m_isolate)->GetSourceOffset( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 } | 243 } |
217 | 244 |
218 const String16& sourceMappingURL() const override { return emptyString(); } | 245 const String16& sourceMappingURL() const override { return emptyString(); } |
219 bool isLiveEdit() const override { return false; } | 246 bool isLiveEdit() const override { return false; } |
220 bool isModule() const override { return false; } | 247 bool isModule() const override { return false; } |
221 void setSourceMappingURL(const String16&) override {} | 248 void setSourceMappingURL(const String16&) override {} |
222 | 249 |
223 bool getPossibleBreakpoints( | 250 bool getPossibleBreakpoints( |
224 const v8::debug::Location& start, const v8::debug::Location& end, | 251 const v8::debug::Location& start, const v8::debug::Location& end, |
225 bool restrictToFunction, | 252 bool restrictToFunction, |
226 std::vector<v8::debug::Location>* locations) override { | 253 std::vector<v8::debug::BreakLocation>* locations) override { |
227 v8::HandleScope scope(m_isolate); | 254 v8::HandleScope scope(m_isolate); |
228 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 255 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
229 String16 v8ScriptId = String16::fromInteger(script->Id()); | 256 String16 v8ScriptId = String16::fromInteger(script->Id()); |
230 | 257 |
231 v8::debug::Location translatedStart = start; | 258 v8::debug::Location translatedStart = start; |
232 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedStart, | 259 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedStart, |
233 scriptId(), v8ScriptId); | 260 scriptId(), v8ScriptId); |
234 | 261 |
235 v8::debug::Location translatedEnd = end; | 262 v8::debug::Location translatedEnd = end; |
236 if (translatedEnd.IsEmpty()) { | 263 if (translatedEnd.IsEmpty()) { |
237 // Stop before the start of the next function. | 264 // Stop before the start of the next function. |
238 translatedEnd = | 265 translatedEnd = |
239 v8::debug::Location(translatedStart.GetLineNumber() + 1, 0); | 266 v8::debug::Location(translatedStart.GetLineNumber() + 1, 0); |
240 } else { | 267 } else { |
241 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedEnd, | 268 TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedEnd, |
242 scriptId(), v8ScriptId); | 269 scriptId(), v8ScriptId); |
243 } | 270 } |
244 | 271 |
245 bool success = script->GetPossibleBreakpoints( | 272 bool success = script->GetPossibleBreakpoints( |
246 translatedStart, translatedEnd, restrictToFunction, locations); | 273 translatedStart, translatedEnd, restrictToFunction, locations); |
247 for (v8::debug::Location& loc : *locations) { | 274 for (v8::debug::BreakLocation& loc : *locations) { |
248 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, | 275 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, |
249 scriptId()); | 276 scriptId()); |
250 } | 277 } |
251 return success; | 278 return success; |
252 } | 279 } |
253 | 280 |
254 void resetBlackboxedStateCache() override {} | 281 void resetBlackboxedStateCache() override {} |
255 | 282 |
256 int offset(int lineNumber, int columnNumber) const override { | 283 int offset(int lineNumber, int columnNumber) const override { |
257 return kNoOffset; | 284 return kNoOffset; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 if (m_hash.isEmpty()) m_hash = calculateHash(source()); | 330 if (m_hash.isEmpty()) m_hash = calculateHash(source()); |
304 DCHECK(!m_hash.isEmpty()); | 331 DCHECK(!m_hash.isEmpty()); |
305 return m_hash; | 332 return m_hash; |
306 } | 333 } |
307 | 334 |
308 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 335 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
309 m_sourceURL = sourceURL; | 336 m_sourceURL = sourceURL; |
310 } | 337 } |
311 | 338 |
312 } // namespace v8_inspector | 339 } // namespace v8_inspector |
OLD | NEW |