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') { |
alph
2017/02/28 00:47:26
nit: > 0
kozy
2017/02/28 01:56:26
Done.
| |
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 bool restrictToFunction, | 162 bool restrictToFunction, |
176 std::vector<v8::debug::Location>* locations) override { | 163 std::vector<v8::debug::Location>* locations) override { |
177 v8::HandleScope scope(m_isolate); | 164 v8::HandleScope scope(m_isolate); |
178 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); | 165 v8::Local<v8::debug::Script> script = m_script.Get(m_isolate); |
179 return script->GetPossibleBreakpoints(start, end, restrictToFunction, | 166 return script->GetPossibleBreakpoints(start, end, restrictToFunction, |
180 locations); | 167 locations); |
181 } | 168 } |
182 | 169 |
183 void resetBlackboxedStateCache() override { | 170 void resetBlackboxedStateCache() override { |
184 v8::HandleScope scope(m_isolate); | 171 v8::HandleScope scope(m_isolate); |
185 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); | 172 v8::debug::ResetBlackboxedStateCache(m_isolate, m_script.Get(m_isolate)); |
186 } | 173 } |
187 | 174 |
175 int offset(int lineNumber, int columnNumber) const override { | |
176 v8::HandleScope scope(m_isolate); | |
177 return m_script.Get(m_isolate)->GetSourceOffset( | |
178 v8::debug::Location(lineNumber, columnNumber)); | |
179 } | |
180 | |
181 v8::debug::Location location(int offset) const override { | |
182 v8::HandleScope scope(m_isolate); | |
183 return m_script.Get(m_isolate)->GetSourceLocation(offset); | |
184 } | |
185 | |
188 private: | 186 private: |
189 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { | 187 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { |
190 v8::Local<v8::String> name; | 188 v8::Local<v8::String> name; |
191 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) | 189 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) |
192 return toProtocolString(name); | 190 return toProtocolString(name); |
193 return String16(); | 191 return String16(); |
194 } | 192 } |
195 | 193 |
196 String16 m_sourceMappingURL; | 194 String16 m_sourceMappingURL; |
197 v8::Global<v8::String> m_sourceObj; | |
198 bool m_isLiveEdit = false; | 195 bool m_isLiveEdit = false; |
199 bool m_isModule = false; | 196 bool m_isModule = false; |
200 v8::Global<v8::debug::Script> m_script; | 197 v8::Global<v8::debug::Script> m_script; |
201 }; | 198 }; |
202 | 199 |
203 class WasmVirtualScript : public V8DebuggerScript { | 200 class WasmVirtualScript : public V8DebuggerScript { |
204 friend class V8DebuggerScript; | 201 friend class V8DebuggerScript; |
205 | 202 |
206 public: | 203 public: |
207 WasmVirtualScript(v8::Isolate* isolate, WasmTranslation* wasmTranslation, | 204 WasmVirtualScript(v8::Isolate* isolate, WasmTranslation* wasmTranslation, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 translatedStart, translatedEnd, restrictToFunction, locations); | 251 translatedStart, translatedEnd, restrictToFunction, locations); |
255 for (v8::debug::Location& loc : *locations) { | 252 for (v8::debug::Location& loc : *locations) { |
256 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, | 253 TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId, |
257 scriptId()); | 254 scriptId()); |
258 } | 255 } |
259 return success; | 256 return success; |
260 } | 257 } |
261 | 258 |
262 void resetBlackboxedStateCache() override {} | 259 void resetBlackboxedStateCache() override {} |
263 | 260 |
261 int offset(int lineNumber, int columnNumber) const override { | |
262 return kNoOffset; | |
263 } | |
264 | |
265 v8::debug::Location location(int offset) const override { | |
266 return v8::debug::Location(); | |
267 } | |
268 | |
264 private: | 269 private: |
265 static const String16& emptyString() { | 270 static const String16& emptyString() { |
266 static const String16 singleEmptyString; | 271 static const String16 singleEmptyString; |
267 return singleEmptyString; | 272 return singleEmptyString; |
268 } | 273 } |
269 | 274 |
270 v8::Global<v8::debug::WasmScript> m_script; | 275 v8::Global<v8::debug::WasmScript> m_script; |
271 WasmTranslation* m_wasmTranslation; | 276 WasmTranslation* m_wasmTranslation; |
272 }; | 277 }; |
273 | 278 |
(...skipping 18 matching lines...) Expand all Loading... | |
292 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, | 297 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, String16 id, |
293 String16 url) | 298 String16 url) |
294 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {} | 299 : m_id(std::move(id)), m_url(std::move(url)), m_isolate(isolate) {} |
295 | 300 |
296 V8DebuggerScript::~V8DebuggerScript() {} | 301 V8DebuggerScript::~V8DebuggerScript() {} |
297 | 302 |
298 const String16& V8DebuggerScript::sourceURL() const { | 303 const String16& V8DebuggerScript::sourceURL() const { |
299 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 304 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
300 } | 305 } |
301 | 306 |
302 const String16& V8DebuggerScript::hash(v8::Isolate* isolate) const { | 307 const String16& V8DebuggerScript::hash() const { |
303 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); | 308 if (m_hash.isEmpty()) m_hash = calculateHash(source()); |
304 DCHECK(!m_hash.isEmpty()); | 309 DCHECK(!m_hash.isEmpty()); |
305 return m_hash; | 310 return m_hash; |
306 } | 311 } |
307 | 312 |
308 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 313 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
309 m_sourceURL = sourceURL; | 314 m_sourceURL = sourceURL; |
310 } | 315 } |
311 | 316 |
312 } // namespace v8_inspector | 317 } // namespace v8_inspector |
OLD | NEW |