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/string-util.h" | 8 #include "src/inspector/string-util.h" |
8 | 9 |
9 namespace v8_inspector { | 10 namespace v8_inspector { |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 const char hexDigits[17] = "0123456789ABCDEF"; | 14 const char hexDigits[17] = "0123456789ABCDEF"; |
14 | 15 |
15 void appendUnsignedAsHex(uint64_t number, String16Builder* destination) { | 16 void appendUnsignedAsHex(uint64_t number, String16Builder* destination) { |
16 for (size_t i = 0; i < 8; ++i) { | 17 for (size_t i = 0; i < 8; ++i) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (lineEnds.size() > 1) { | 92 if (lineEnds.size() > 1) { |
92 m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1; | 93 m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1; |
93 } else { | 94 } else { |
94 m_endColumn = source_length + m_startColumn; | 95 m_endColumn = source_length + m_startColumn; |
95 } | 96 } |
96 } else { | 97 } else { |
97 m_endLine = m_startLine; | 98 m_endLine = m_startLine; |
98 m_endColumn = m_startColumn; | 99 m_endColumn = m_startColumn; |
99 } | 100 } |
100 | 101 |
101 if (script->ContextData().ToLocal(&tmp)) { | 102 v8::Local<v8::Value> contextData; |
102 String16 contextData = toProtocolString(tmp); | 103 if (script->ContextData().ToLocal(&contextData) && contextData->IsInt32()) { |
103 size_t firstComma = contextData.find(",", 0); | 104 m_executionContextId = |
104 size_t secondComma = firstComma != String16::kNotFound | 105 static_cast<int>(contextData.As<v8::Int32>()->Value()); |
105 ? contextData.find(",", firstComma + 1) | |
106 : String16::kNotFound; | |
107 if (secondComma != String16::kNotFound) { | |
108 String16 executionContextId = | |
109 contextData.substring(firstComma + 1, secondComma - firstComma - 1); | |
110 bool isOk = false; | |
111 m_executionContextId = executionContextId.toInteger(&isOk); | |
112 if (!isOk) m_executionContextId = 0; | |
113 m_executionContextAuxData = contextData.substring(secondComma + 1); | |
114 } | |
115 } | 106 } |
116 | 107 |
117 if (script->Source().ToLocal(&tmp)) { | 108 if (script->Source().ToLocal(&tmp)) { |
118 m_sourceObj.Reset(m_isolate, tmp); | 109 m_sourceObj.Reset(m_isolate, tmp); |
119 String16 source = toProtocolString(tmp); | 110 String16 source = toProtocolString(tmp); |
120 // V8 will not count last line if script source ends with \n. | 111 // V8 will not count last line if script source ends with \n. |
121 if (source.length() > 1 && source[source.length() - 1] == '\n') { | 112 if (source.length() > 1 && source[source.length() - 1] == '\n') { |
122 m_endLine++; | 113 m_endLine++; |
123 m_endColumn = 0; | 114 m_endColumn = 0; |
124 } | 115 } |
125 } | 116 } |
126 | 117 |
127 m_script.Reset(m_isolate, script); | 118 m_script.Reset(m_isolate, script); |
128 } | 119 } |
129 | 120 |
130 bool isLiveEdit() const override { return m_isLiveEdit; } | 121 bool isLiveEdit() const override { return m_isLiveEdit; } |
131 | 122 |
132 const String16& executionContextAuxData() const override { | |
133 return m_executionContextAuxData; | |
134 } | |
135 | |
136 const String16& sourceMappingURL() const override { | 123 const String16& sourceMappingURL() const override { |
137 return m_sourceMappingURL; | 124 return m_sourceMappingURL; |
138 } | 125 } |
139 | 126 |
140 String16 source(v8::Isolate* isolate) const override { | 127 String16 source(v8::Isolate* isolate) const override { |
141 if (!m_sourceObj.IsEmpty()) | 128 if (!m_sourceObj.IsEmpty()) |
142 return toProtocolString(m_sourceObj.Get(isolate)); | 129 return toProtocolString(m_sourceObj.Get(isolate)); |
143 return V8DebuggerScript::source(isolate); | 130 return V8DebuggerScript::source(isolate); |
144 } | 131 } |
145 | 132 |
(...skipping 18 matching lines...) Expand all Loading... |
164 private: | 151 private: |
165 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { | 152 String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) { |
166 v8::Local<v8::String> name; | 153 v8::Local<v8::String> name; |
167 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) | 154 if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) |
168 return toProtocolString(name); | 155 return toProtocolString(name); |
169 return String16(); | 156 return String16(); |
170 } | 157 } |
171 | 158 |
172 String16 m_sourceMappingURL; | 159 String16 m_sourceMappingURL; |
173 v8::Global<v8::String> m_sourceObj; | 160 v8::Global<v8::String> m_sourceObj; |
174 String16 m_executionContextAuxData; | |
175 bool m_isLiveEdit = false; | 161 bool m_isLiveEdit = false; |
176 v8::Global<v8::debug::Script> m_script; | 162 v8::Global<v8::debug::Script> m_script; |
177 }; | 163 }; |
178 | 164 |
179 class WasmVirtualScript : public V8DebuggerScript { | 165 class WasmVirtualScript : public V8DebuggerScript { |
180 friend class V8DebuggerScript; | 166 friend class V8DebuggerScript; |
181 | 167 |
182 public: | 168 public: |
183 WasmVirtualScript(v8::Isolate* isolate, | 169 WasmVirtualScript(v8::Isolate* isolate, |
184 v8::Local<v8::debug::WasmScript> script, String16 id, | 170 v8::Local<v8::debug::WasmScript> script, String16 id, |
185 String16 url, String16 source) | 171 String16 url, String16 source) |
186 : V8DebuggerScript(isolate, std::move(id), std::move(url)), | 172 : V8DebuggerScript(isolate, std::move(id), std::move(url)), |
187 m_script(isolate, script) { | 173 m_script(isolate, script) { |
188 int num_lines = 0; | 174 int num_lines = 0; |
189 int last_newline = -1; | 175 int last_newline = -1; |
190 size_t next_newline = source.find('\n', last_newline + 1); | 176 size_t next_newline = source.find('\n', last_newline + 1); |
191 while (next_newline != String16::kNotFound) { | 177 while (next_newline != String16::kNotFound) { |
192 last_newline = static_cast<int>(next_newline); | 178 last_newline = static_cast<int>(next_newline); |
193 next_newline = source.find('\n', last_newline + 1); | 179 next_newline = source.find('\n', last_newline + 1); |
194 ++num_lines; | 180 ++num_lines; |
195 } | 181 } |
196 m_endLine = num_lines; | 182 m_endLine = num_lines; |
197 m_endColumn = static_cast<int>(source.length()) - last_newline - 1; | 183 m_endColumn = static_cast<int>(source.length()) - last_newline - 1; |
198 m_source = std::move(source); | 184 m_source = std::move(source); |
199 } | 185 } |
200 | 186 |
201 const String16& sourceMappingURL() const override { return emptyString(); } | 187 const String16& sourceMappingURL() const override { return emptyString(); } |
202 const String16& executionContextAuxData() const override { | |
203 return emptyString(); | |
204 } | |
205 bool isLiveEdit() const override { return false; } | 188 bool isLiveEdit() const override { return false; } |
206 void setSourceMappingURL(const String16&) override {} | 189 void setSourceMappingURL(const String16&) override {} |
207 | 190 |
208 bool getPossibleBreakpoints( | 191 bool getPossibleBreakpoints( |
209 const v8::debug::Location& start, const v8::debug::Location& end, | 192 const v8::debug::Location& start, const v8::debug::Location& end, |
210 std::vector<v8::debug::Location>* locations) override { | 193 std::vector<v8::debug::Location>* locations) override { |
211 // TODO(clemensh): Returning false produces the protocol error "Internal | 194 // TODO(clemensh): Returning false produces the protocol error "Internal |
212 // error". Implement and fix expected output of | 195 // error". Implement and fix expected output of |
213 // wasm-get-breakable-locations.js. | 196 // wasm-get-breakable-locations.js. |
214 return false; | 197 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); | 237 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); |
255 DCHECK(!m_hash.isEmpty()); | 238 DCHECK(!m_hash.isEmpty()); |
256 return m_hash; | 239 return m_hash; |
257 } | 240 } |
258 | 241 |
259 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 242 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
260 m_sourceURL = sourceURL; | 243 m_sourceURL = sourceURL; |
261 } | 244 } |
262 | 245 |
263 } // namespace v8_inspector | 246 } // namespace v8_inspector |
OLD | NEW |