OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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-console.h" | 5 #include "src/inspector/v8-console.h" |
6 | 6 |
7 #include "src/base/macros.h" | 7 #include "src/base/macros.h" |
8 #include "src/inspector/injected-script.h" | 8 #include "src/inspector/injected-script.h" |
9 #include "src/inspector/inspected-context.h" | 9 #include "src/inspector/inspected-context.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
11 #include "src/inspector/v8-console-message.h" | 11 #include "src/inspector/v8-console-message.h" |
12 #include "src/inspector/v8-debugger-agent-impl.h" | 12 #include "src/inspector/v8-debugger-agent-impl.h" |
13 #include "src/inspector/v8-inspector-impl.h" | 13 #include "src/inspector/v8-inspector-impl.h" |
14 #include "src/inspector/v8-inspector-session-impl.h" | 14 #include "src/inspector/v8-inspector-session-impl.h" |
15 #include "src/inspector/v8-profiler-agent-impl.h" | 15 #include "src/inspector/v8-profiler-agent-impl.h" |
16 #include "src/inspector/v8-runtime-agent-impl.h" | 16 #include "src/inspector/v8-runtime-agent-impl.h" |
17 #include "src/inspector/v8-stack-trace-impl.h" | 17 #include "src/inspector/v8-stack-trace-impl.h" |
18 #include "src/inspector/v8-value-copier.h" | 18 #include "src/inspector/v8-value-copier.h" |
19 | 19 |
20 #include "include/v8-inspector.h" | 20 #include "include/v8-inspector.h" |
21 | 21 |
22 namespace v8_inspector { | 22 namespace v8_inspector { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class ConsoleHelper { | 26 class ConsoleHelper { |
27 public: | 27 public: |
28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info, | 28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info) |
29 V8InspectorImpl* inspector) | |
30 : m_info(info), | 29 : m_info(info), |
31 m_isolate(info.GetIsolate()), | 30 m_isolate(info.GetIsolate()), |
32 m_context(info.GetIsolate()->GetCurrentContext()), | 31 m_context(info.GetIsolate()->GetCurrentContext()), |
33 m_inspector(inspector), | 32 m_contextId(InspectedContext::contextId(m_context)) { |
34 m_contextId(InspectedContext::contextId(m_context)), | 33 m_inspector = static_cast<V8InspectorImpl*>( |
35 m_groupId(m_inspector->contextGroupId(m_contextId)) {} | 34 m_info.Data().As<v8::External>()->Value()); |
| 35 m_groupId = m_inspector->contextGroupId(m_contextId); |
| 36 } |
| 37 |
| 38 V8InspectorImpl* inspector() { return m_inspector; } |
36 | 39 |
37 int contextId() const { return m_contextId; } | 40 int contextId() const { return m_contextId; } |
38 int groupId() const { return m_groupId; } | 41 int groupId() const { return m_groupId; } |
39 | 42 |
40 InjectedScript* injectedScript() { | 43 InjectedScript* injectedScript() { |
41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); | 44 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); |
42 if (!context) return nullptr; | 45 if (!context) return nullptr; |
43 return context->getInjectedScript(); | 46 return context->getInjectedScript(); |
44 } | 47 } |
45 | 48 |
46 V8ConsoleMessageStorage* consoleMessageStorage() { | 49 V8ConsoleMessageStorage* consoleMessageStorage() { |
47 return m_inspector->ensureConsoleMessageStorage(m_groupId); | 50 return inspector()->ensureConsoleMessageStorage(m_groupId); |
48 } | 51 } |
49 | 52 |
50 void reportCall(ConsoleAPIType type) { | 53 void reportCall(ConsoleAPIType type) { |
51 if (!m_info.Length()) return; | 54 if (!m_info.Length()) return; |
52 std::vector<v8::Local<v8::Value>> arguments; | 55 std::vector<v8::Local<v8::Value>> arguments; |
53 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | 56 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); |
54 reportCall(type, arguments); | 57 reportCall(type, arguments); |
55 } | 58 } |
56 | 59 |
57 void reportCallWithDefaultArgument(ConsoleAPIType type, | 60 void reportCallWithDefaultArgument(ConsoleAPIType type, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 144 } |
142 | 145 |
143 V8InspectorSessionImpl* currentSession() { | 146 V8InspectorSessionImpl* currentSession() { |
144 return m_inspector->sessionForContextGroup(m_groupId); | 147 return m_inspector->sessionForContextGroup(m_groupId); |
145 } | 148 } |
146 | 149 |
147 private: | 150 private: |
148 const v8::FunctionCallbackInfo<v8::Value>& m_info; | 151 const v8::FunctionCallbackInfo<v8::Value>& m_info; |
149 v8::Isolate* m_isolate; | 152 v8::Isolate* m_isolate; |
150 v8::Local<v8::Context> m_context; | 153 v8::Local<v8::Context> m_context; |
| 154 v8::Local<v8::Object> m_console; |
151 V8InspectorImpl* m_inspector = nullptr; | 155 V8InspectorImpl* m_inspector = nullptr; |
152 int m_contextId; | 156 int m_contextId; |
153 int m_groupId; | 157 int m_groupId; |
154 | 158 |
155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); | 159 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); |
156 }; | 160 }; |
157 | 161 |
158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 162 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
159 info.GetReturnValue().Set(info.Data()); | 163 info.GetReturnValue().Set(info.Data()); |
160 } | 164 } |
(...skipping 20 matching lines...) Expand all Loading... |
181 .ToLocal(&toStringFunction)) | 185 .ToLocal(&toStringFunction)) |
182 createDataProperty(context, func, toV8StringInternalized( | 186 createDataProperty(context, func, toV8StringInternalized( |
183 context->GetIsolate(), "toString"), | 187 context->GetIsolate(), "toString"), |
184 toStringFunction); | 188 toStringFunction); |
185 } | 189 } |
186 createDataProperty(context, console, funcName, func); | 190 createDataProperty(context, console, funcName, func); |
187 } | 191 } |
188 | 192 |
189 } // namespace | 193 } // namespace |
190 | 194 |
191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} | |
192 | |
193 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 195 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug); | 196 ConsoleHelper(info).reportCall(ConsoleAPIType::kDebug); |
195 } | 197 } |
196 | 198 |
197 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 199 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError); | 200 ConsoleHelper(info).reportCall(ConsoleAPIType::kError); |
199 } | 201 } |
200 | 202 |
201 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 203 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo); | 204 ConsoleHelper(info).reportCall(ConsoleAPIType::kInfo); |
203 } | 205 } |
204 | 206 |
205 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 207 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog); | 208 ConsoleHelper(info).reportCall(ConsoleAPIType::kLog); |
207 } | 209 } |
208 | 210 |
209 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 211 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning); | 212 ConsoleHelper(info).reportCall(ConsoleAPIType::kWarning); |
211 } | 213 } |
212 | 214 |
213 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 215 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir); | 216 ConsoleHelper(info).reportCall(ConsoleAPIType::kDir); |
215 } | 217 } |
216 | 218 |
217 void V8Console::dirxmlCallback( | 219 void V8Console::dirxmlCallback( |
218 const v8::FunctionCallbackInfo<v8::Value>& info) { | 220 const v8::FunctionCallbackInfo<v8::Value>& info) { |
219 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML); | 221 ConsoleHelper(info).reportCall(ConsoleAPIType::kDirXML); |
220 } | 222 } |
221 | 223 |
222 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 224 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
223 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable); | 225 ConsoleHelper(info).reportCall(ConsoleAPIType::kTable); |
224 } | 226 } |
225 | 227 |
226 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 228 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
227 ConsoleHelper(info, m_inspector) | 229 ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kTrace, |
228 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace, | 230 String16("console.trace")); |
229 String16("console.trace")); | |
230 } | 231 } |
231 | 232 |
232 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 233 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
233 ConsoleHelper(info, m_inspector) | 234 ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, |
234 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, | 235 String16("console.group")); |
235 String16("console.group")); | |
236 } | 236 } |
237 | 237 |
238 void V8Console::groupCollapsedCallback( | 238 void V8Console::groupCollapsedCallback( |
239 const v8::FunctionCallbackInfo<v8::Value>& info) { | 239 const v8::FunctionCallbackInfo<v8::Value>& info) { |
240 ConsoleHelper(info, m_inspector) | 240 ConsoleHelper(info).reportCallWithDefaultArgument( |
241 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, | 241 ConsoleAPIType::kStartGroupCollapsed, String16("console.groupCollapsed")); |
242 String16("console.groupCollapsed")); | |
243 } | 242 } |
244 | 243 |
245 void V8Console::groupEndCallback( | 244 void V8Console::groupEndCallback( |
246 const v8::FunctionCallbackInfo<v8::Value>& info) { | 245 const v8::FunctionCallbackInfo<v8::Value>& info) { |
247 ConsoleHelper(info, m_inspector) | 246 ConsoleHelper(info).reportCallWithDefaultArgument( |
248 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, | 247 ConsoleAPIType::kEndGroup, String16("console.groupEnd")); |
249 String16("console.groupEnd")); | |
250 } | 248 } |
251 | 249 |
252 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 250 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
253 ConsoleHelper helper(info, m_inspector); | 251 ConsoleHelper helper(info); |
254 if (!helper.groupId()) return; | 252 if (!helper.groupId()) return; |
255 m_inspector->client()->consoleClear(helper.groupId()); | 253 helper.inspector()->client()->consoleClear(helper.groupId()); |
256 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, | 254 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, |
257 String16("console.clear")); | 255 String16("console.clear")); |
258 } | 256 } |
259 | 257 |
260 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 258 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
261 ConsoleHelper helper(info, m_inspector); | 259 ConsoleHelper helper(info); |
262 String16 title = helper.firstArgToString(String16()); | 260 String16 title = helper.firstArgToString(String16()); |
263 String16 identifier; | 261 String16 identifier; |
264 if (title.isEmpty()) { | 262 if (title.isEmpty()) { |
265 std::unique_ptr<V8StackTraceImpl> stackTrace = | 263 std::unique_ptr<V8StackTraceImpl> stackTrace = |
266 V8StackTraceImpl::capture(nullptr, 0, 1); | 264 V8StackTraceImpl::capture(nullptr, 0, 1); |
267 if (stackTrace && !stackTrace->isEmpty()) { | 265 if (stackTrace && !stackTrace->isEmpty()) { |
268 identifier = toString16(stackTrace->topSourceURL()) + ":" + | 266 identifier = toString16(stackTrace->topSourceURL()) + ":" + |
269 String16::fromInteger(stackTrace->topLineNumber()); | 267 String16::fromInteger(stackTrace->topLineNumber()); |
270 } | 268 } |
271 } else { | 269 } else { |
272 identifier = title + "@"; | 270 identifier = title + "@"; |
273 } | 271 } |
274 | 272 |
275 int count = | 273 int count = |
276 helper.consoleMessageStorage()->count(helper.contextId(), identifier); | 274 helper.consoleMessageStorage()->count(helper.contextId(), identifier); |
277 String16 countString = String16::fromInteger(count); | 275 String16 countString = String16::fromInteger(count); |
278 helper.reportCallWithArgument( | 276 helper.reportCallWithArgument( |
279 ConsoleAPIType::kCount, | 277 ConsoleAPIType::kCount, |
280 title.isEmpty() ? countString : (title + ": " + countString)); | 278 title.isEmpty() ? countString : (title + ": " + countString)); |
281 } | 279 } |
282 | 280 |
283 void V8Console::assertCallback( | 281 void V8Console::assertCallback( |
284 const v8::FunctionCallbackInfo<v8::Value>& info) { | 282 const v8::FunctionCallbackInfo<v8::Value>& info) { |
285 ConsoleHelper helper(info, m_inspector); | 283 ConsoleHelper helper(info); |
286 if (helper.firstArgToBoolean(false)) return; | 284 if (helper.firstArgToBoolean(false)) return; |
287 | 285 |
288 std::vector<v8::Local<v8::Value>> arguments; | 286 std::vector<v8::Local<v8::Value>> arguments; |
289 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); | 287 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); |
290 if (info.Length() < 2) | 288 if (info.Length() < 2) |
291 arguments.push_back( | 289 arguments.push_back( |
292 toV8String(info.GetIsolate(), String16("console.assert"))); | 290 toV8String(info.GetIsolate(), String16("console.assert"))); |
293 helper.reportCall(ConsoleAPIType::kAssert, arguments); | 291 helper.reportCall(ConsoleAPIType::kAssert, arguments); |
294 | 292 |
295 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) | 293 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) |
296 debuggerAgent->breakProgramOnException( | 294 debuggerAgent->breakProgramOnException( |
297 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); | 295 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); |
298 } | 296 } |
299 | 297 |
300 void V8Console::markTimelineCallback( | 298 void V8Console::markTimelineCallback( |
301 const v8::FunctionCallbackInfo<v8::Value>& info) { | 299 const v8::FunctionCallbackInfo<v8::Value>& info) { |
302 ConsoleHelper(info, m_inspector) | 300 ConsoleHelper(info).reportDeprecatedCall("V8Console#markTimelineDeprecated", |
303 .reportDeprecatedCall("V8Console#markTimelineDeprecated", | 301 "'console.markTimeline' is " |
304 "'console.markTimeline' is " | 302 "deprecated. Please use " |
305 "deprecated. Please use " | 303 "'console.timeStamp' instead."); |
306 "'console.timeStamp' instead."); | |
307 timeStampCallback(info); | 304 timeStampCallback(info); |
308 } | 305 } |
309 | 306 |
310 void V8Console::profileCallback( | 307 void V8Console::profileCallback( |
311 const v8::FunctionCallbackInfo<v8::Value>& info) { | 308 const v8::FunctionCallbackInfo<v8::Value>& info) { |
312 ConsoleHelper helper(info, m_inspector); | 309 ConsoleHelper helper(info); |
313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 310 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) |
314 profilerAgent->consoleProfile(helper.firstArgToString(String16())); | 311 profilerAgent->consoleProfile(helper.firstArgToString(String16())); |
315 } | 312 } |
316 | 313 |
317 void V8Console::profileEndCallback( | 314 void V8Console::profileEndCallback( |
318 const v8::FunctionCallbackInfo<v8::Value>& info) { | 315 const v8::FunctionCallbackInfo<v8::Value>& info) { |
319 ConsoleHelper helper(info, m_inspector); | 316 ConsoleHelper helper(info); |
320 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 317 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) |
321 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); | 318 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); |
322 } | 319 } |
323 | 320 |
324 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 321 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
325 bool timelinePrefix, V8InspectorImpl* inspector) { | 322 bool timelinePrefix) { |
326 ConsoleHelper helper(info, inspector); | 323 ConsoleHelper helper(info); |
| 324 V8InspectorClient* client = helper.inspector()->client(); |
327 String16 protocolTitle = helper.firstArgToString("default"); | 325 String16 protocolTitle = helper.firstArgToString("default"); |
328 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 326 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
329 inspector->client()->consoleTime(toStringView(protocolTitle)); | 327 client->consoleTime(toStringView(protocolTitle)); |
330 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); | 328 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); |
331 } | 329 } |
332 | 330 |
333 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 331 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
334 bool timelinePrefix, V8InspectorImpl* inspector) { | 332 bool timelinePrefix) { |
335 ConsoleHelper helper(info, inspector); | 333 ConsoleHelper helper(info); |
| 334 V8InspectorClient* client = helper.inspector()->client(); |
336 String16 protocolTitle = helper.firstArgToString("default"); | 335 String16 protocolTitle = helper.firstArgToString("default"); |
337 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 336 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
338 inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); | 337 client->consoleTimeEnd(toStringView(protocolTitle)); |
339 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), | 338 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), |
340 protocolTitle); | 339 protocolTitle); |
341 String16 message = | 340 String16 message = |
342 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; | 341 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; |
343 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); | 342 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); |
344 } | 343 } |
345 | 344 |
346 void V8Console::timelineCallback( | 345 void V8Console::timelineCallback( |
347 const v8::FunctionCallbackInfo<v8::Value>& info) { | 346 const v8::FunctionCallbackInfo<v8::Value>& info) { |
348 ConsoleHelper(info, m_inspector) | 347 ConsoleHelper(info).reportDeprecatedCall( |
349 .reportDeprecatedCall("V8Console#timeline", | 348 "V8Console#timeline", |
350 "'console.timeline' is deprecated. Please use " | 349 "'console.timeline' is deprecated. Please use 'console.time' instead."); |
351 "'console.time' instead."); | 350 timeFunction(info, true); |
352 timeFunction(info, true, m_inspector); | |
353 } | 351 } |
354 | 352 |
355 void V8Console::timelineEndCallback( | 353 void V8Console::timelineEndCallback( |
356 const v8::FunctionCallbackInfo<v8::Value>& info) { | 354 const v8::FunctionCallbackInfo<v8::Value>& info) { |
357 ConsoleHelper(info, m_inspector) | 355 ConsoleHelper(info).reportDeprecatedCall("V8Console#timelineEnd", |
358 .reportDeprecatedCall("V8Console#timelineEnd", | 356 "'console.timelineEnd' is " |
359 "'console.timelineEnd' is " | 357 "deprecated. Please use " |
360 "deprecated. Please use " | 358 "'console.timeEnd' instead."); |
361 "'console.timeEnd' instead."); | 359 timeEndFunction(info, true); |
362 timeEndFunction(info, true, m_inspector); | |
363 } | 360 } |
364 | 361 |
365 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 362 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
366 timeFunction(info, false, m_inspector); | 363 timeFunction(info, false); |
367 } | 364 } |
368 | 365 |
369 void V8Console::timeEndCallback( | 366 void V8Console::timeEndCallback( |
370 const v8::FunctionCallbackInfo<v8::Value>& info) { | 367 const v8::FunctionCallbackInfo<v8::Value>& info) { |
371 timeEndFunction(info, false, m_inspector); | 368 timeEndFunction(info, false); |
372 } | 369 } |
373 | 370 |
374 void V8Console::timeStampCallback( | 371 void V8Console::timeStampCallback( |
375 const v8::FunctionCallbackInfo<v8::Value>& info) { | 372 const v8::FunctionCallbackInfo<v8::Value>& info) { |
376 ConsoleHelper helper(info, m_inspector); | 373 ConsoleHelper helper(info); |
377 String16 title = helper.firstArgToString(String16()); | 374 String16 title = helper.firstArgToString(String16()); |
378 m_inspector->client()->consoleTimeStamp(toStringView(title)); | 375 helper.inspector()->client()->consoleTimeStamp(toStringView(title)); |
379 } | 376 } |
380 | 377 |
381 void V8Console::memoryGetterCallback( | 378 void V8Console::memoryGetterCallback( |
382 const v8::FunctionCallbackInfo<v8::Value>& info) { | 379 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 380 V8InspectorClient* client = ConsoleHelper(info).inspector()->client(); |
383 v8::Local<v8::Value> memoryValue; | 381 v8::Local<v8::Value> memoryValue; |
384 if (!m_inspector->client() | 382 if (!client |
385 ->memoryInfo(info.GetIsolate(), | 383 ->memoryInfo(info.GetIsolate(), |
386 info.GetIsolate()->GetCurrentContext()) | 384 info.GetIsolate()->GetCurrentContext()) |
387 .ToLocal(&memoryValue)) | 385 .ToLocal(&memoryValue)) |
388 return; | 386 return; |
389 info.GetReturnValue().Set(memoryValue); | 387 info.GetReturnValue().Set(memoryValue); |
390 } | 388 } |
391 | 389 |
392 void V8Console::memorySetterCallback( | 390 void V8Console::memorySetterCallback( |
393 const v8::FunctionCallbackInfo<v8::Value>& info) { | 391 const v8::FunctionCallbackInfo<v8::Value>& info) { |
394 // We can't make the attribute readonly as it breaks existing code that relies | 392 // We can't make the attribute readonly as it breaks existing code that relies |
395 // on being able to assign to console.memory in strict mode. Instead, the | 393 // on being able to assign to console.memory in strict mode. Instead, the |
396 // setter just ignores the passed value. http://crbug.com/468611 | 394 // setter just ignores the passed value. http://crbug.com/468611 |
397 } | 395 } |
398 | 396 |
399 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 397 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
400 v8::Isolate* isolate = info.GetIsolate(); | 398 v8::Isolate* isolate = info.GetIsolate(); |
401 info.GetReturnValue().Set(v8::Array::New(isolate)); | 399 info.GetReturnValue().Set(v8::Array::New(isolate)); |
402 | 400 |
403 ConsoleHelper helper(info, m_inspector); | 401 ConsoleHelper helper(info); |
404 v8::Local<v8::Object> obj; | 402 v8::Local<v8::Object> obj; |
405 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 403 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
406 v8::Local<v8::Array> names; | 404 v8::Local<v8::Array> names; |
407 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) | 405 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) |
408 return; | 406 return; |
409 info.GetReturnValue().Set(names); | 407 info.GetReturnValue().Set(names); |
410 } | 408 } |
411 | 409 |
412 void V8Console::valuesCallback( | 410 void V8Console::valuesCallback( |
413 const v8::FunctionCallbackInfo<v8::Value>& info) { | 411 const v8::FunctionCallbackInfo<v8::Value>& info) { |
414 v8::Isolate* isolate = info.GetIsolate(); | 412 v8::Isolate* isolate = info.GetIsolate(); |
415 info.GetReturnValue().Set(v8::Array::New(isolate)); | 413 info.GetReturnValue().Set(v8::Array::New(isolate)); |
416 | 414 |
417 ConsoleHelper helper(info, m_inspector); | 415 ConsoleHelper helper(info); |
418 v8::Local<v8::Object> obj; | 416 v8::Local<v8::Object> obj; |
419 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 417 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
420 v8::Local<v8::Array> names; | 418 v8::Local<v8::Array> names; |
421 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 419 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
422 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; | 420 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; |
423 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); | 421 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); |
424 for (uint32_t i = 0; i < names->Length(); ++i) { | 422 for (uint32_t i = 0; i < names->Length(); ++i) { |
425 v8::Local<v8::Value> key; | 423 v8::Local<v8::Value> key; |
426 if (!names->Get(context, i).ToLocal(&key)) continue; | 424 if (!names->Get(context, i).ToLocal(&key)) continue; |
427 v8::Local<v8::Value> value; | 425 v8::Local<v8::Value> value; |
(...skipping 18 matching lines...) Expand all Loading... |
446 if (enable) | 444 if (enable) |
447 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, | 445 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, |
448 condition); | 446 condition); |
449 else | 447 else |
450 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, | 448 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, |
451 source); | 449 source); |
452 } | 450 } |
453 | 451 |
454 void V8Console::debugFunctionCallback( | 452 void V8Console::debugFunctionCallback( |
455 const v8::FunctionCallbackInfo<v8::Value>& info) { | 453 const v8::FunctionCallbackInfo<v8::Value>& info) { |
456 ConsoleHelper helper(info, m_inspector); | 454 ConsoleHelper helper(info); |
457 v8::Local<v8::Function> function; | 455 v8::Local<v8::Function> function; |
458 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 456 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
459 setFunctionBreakpoint(helper, function, | 457 setFunctionBreakpoint(helper, function, |
460 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 458 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
461 String16(), true); | 459 String16(), true); |
462 } | 460 } |
463 | 461 |
464 void V8Console::undebugFunctionCallback( | 462 void V8Console::undebugFunctionCallback( |
465 const v8::FunctionCallbackInfo<v8::Value>& info) { | 463 const v8::FunctionCallbackInfo<v8::Value>& info) { |
466 ConsoleHelper helper(info, m_inspector); | 464 ConsoleHelper helper(info); |
467 v8::Local<v8::Function> function; | 465 v8::Local<v8::Function> function; |
468 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 466 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
469 setFunctionBreakpoint(helper, function, | 467 setFunctionBreakpoint(helper, function, |
470 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 468 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
471 String16(), false); | 469 String16(), false); |
472 } | 470 } |
473 | 471 |
474 void V8Console::monitorFunctionCallback( | 472 void V8Console::monitorFunctionCallback( |
475 const v8::FunctionCallbackInfo<v8::Value>& info) { | 473 const v8::FunctionCallbackInfo<v8::Value>& info) { |
476 ConsoleHelper helper(info, m_inspector); | 474 ConsoleHelper helper(info); |
477 v8::Local<v8::Function> function; | 475 v8::Local<v8::Function> function; |
478 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 476 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
479 v8::Local<v8::Value> name = function->GetName(); | 477 v8::Local<v8::Value> name = function->GetName(); |
480 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | 478 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) |
481 name = function->GetInferredName(); | 479 name = function->GetInferredName(); |
482 String16 functionName = toProtocolStringWithTypeCheck(name); | 480 String16 functionName = toProtocolStringWithTypeCheck(name); |
483 String16Builder builder; | 481 String16Builder builder; |
484 builder.append("console.log(\"function "); | 482 builder.append("console.log(\"function "); |
485 if (functionName.isEmpty()) | 483 if (functionName.isEmpty()) |
486 builder.append("(anonymous function)"); | 484 builder.append("(anonymous function)"); |
487 else | 485 else |
488 builder.append(functionName); | 486 builder.append(functionName); |
489 builder.append( | 487 builder.append( |
490 " called\" + (arguments.length > 0 ? \" with arguments: \" + " | 488 " called\" + (arguments.length > 0 ? \" with arguments: \" + " |
491 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); | 489 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); |
492 setFunctionBreakpoint(helper, function, | 490 setFunctionBreakpoint(helper, function, |
493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 491 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
494 builder.toString(), true); | 492 builder.toString(), true); |
495 } | 493 } |
496 | 494 |
497 void V8Console::unmonitorFunctionCallback( | 495 void V8Console::unmonitorFunctionCallback( |
498 const v8::FunctionCallbackInfo<v8::Value>& info) { | 496 const v8::FunctionCallbackInfo<v8::Value>& info) { |
499 ConsoleHelper helper(info, m_inspector); | 497 ConsoleHelper helper(info); |
500 v8::Local<v8::Function> function; | 498 v8::Local<v8::Function> function; |
501 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 499 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
502 setFunctionBreakpoint(helper, function, | 500 setFunctionBreakpoint(helper, function, |
503 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 501 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
504 String16(), false); | 502 String16(), false); |
505 } | 503 } |
506 | 504 |
507 void V8Console::lastEvaluationResultCallback( | 505 void V8Console::lastEvaluationResultCallback( |
508 const v8::FunctionCallbackInfo<v8::Value>& info) { | 506 const v8::FunctionCallbackInfo<v8::Value>& info) { |
509 ConsoleHelper helper(info, m_inspector); | 507 ConsoleHelper helper(info); |
510 InjectedScript* injectedScript = helper.injectedScript(); | 508 InjectedScript* injectedScript = helper.injectedScript(); |
511 if (!injectedScript) return; | 509 if (!injectedScript) return; |
512 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); | 510 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); |
513 } | 511 } |
514 | 512 |
515 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, | 513 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, |
516 bool copyToClipboard, V8InspectorImpl* inspector) { | 514 bool copyToClipboard) { |
517 if (info.Length() < 1) return; | 515 if (info.Length() < 1) return; |
518 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); | 516 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); |
519 | 517 |
520 ConsoleHelper helper(info, inspector); | 518 ConsoleHelper helper(info); |
521 InjectedScript* injectedScript = helper.injectedScript(); | 519 InjectedScript* injectedScript = helper.injectedScript(); |
522 if (!injectedScript) return; | 520 if (!injectedScript) return; |
523 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; | 521 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; |
524 protocol::Response response = | 522 protocol::Response response = |
525 injectedScript->wrapObject(info[0], "", false /** forceValueType */, | 523 injectedScript->wrapObject(info[0], "", false /** forceValueType */, |
526 false /** generatePreview */, &wrappedObject); | 524 false /** generatePreview */, &wrappedObject); |
527 if (!response.isSuccess()) return; | 525 if (!response.isSuccess()) return; |
528 | 526 |
529 std::unique_ptr<protocol::DictionaryValue> hints = | 527 std::unique_ptr<protocol::DictionaryValue> hints = |
530 protocol::DictionaryValue::create(); | 528 protocol::DictionaryValue::create(); |
531 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); | 529 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); |
532 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 530 if (V8InspectorSessionImpl* session = helper.currentSession()) { |
533 session->runtimeAgent()->inspect(std::move(wrappedObject), | 531 session->runtimeAgent()->inspect(std::move(wrappedObject), |
534 std::move(hints)); | 532 std::move(hints)); |
535 } | 533 } |
536 } | 534 } |
537 | 535 |
538 void V8Console::inspectCallback( | 536 void V8Console::inspectCallback( |
539 const v8::FunctionCallbackInfo<v8::Value>& info) { | 537 const v8::FunctionCallbackInfo<v8::Value>& info) { |
540 inspectImpl(info, false, m_inspector); | 538 inspectImpl(info, false); |
541 } | 539 } |
542 | 540 |
543 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 541 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
544 inspectImpl(info, true, m_inspector); | 542 inspectImpl(info, true); |
545 } | 543 } |
546 | 544 |
547 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, | 545 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, |
548 unsigned num) { | 546 unsigned num) { |
549 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); | 547 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); |
550 ConsoleHelper helper(info, m_inspector); | 548 ConsoleHelper helper(info); |
551 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 549 if (V8InspectorSessionImpl* session = helper.currentSession()) { |
552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); | 550 V8InspectorSession::Inspectable* object = session->inspectedObject(num); |
553 v8::Isolate* isolate = info.GetIsolate(); | 551 v8::Isolate* isolate = info.GetIsolate(); |
554 if (object) | 552 if (object) |
555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); | 553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); |
556 else | 554 else |
557 info.GetReturnValue().Set(v8::Undefined(isolate)); | 555 info.GetReturnValue().Set(v8::Undefined(isolate)); |
558 } | 556 } |
559 } | 557 } |
560 | 558 |
561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) { | 559 v8::Local<v8::Object> V8Console::createConsole( |
| 560 InspectedContext* inspectedContext) { |
| 561 v8::Local<v8::Context> context = inspectedContext->context(); |
562 v8::Context::Scope contextScope(context); | 562 v8::Context::Scope contextScope(context); |
563 v8::Isolate* isolate = context->GetIsolate(); | 563 v8::Isolate* isolate = context->GetIsolate(); |
564 v8::MicrotasksScope microtasksScope(isolate, | 564 v8::MicrotasksScope microtasksScope(isolate, |
565 v8::MicrotasksScope::kDoNotRunMicrotasks); | 565 v8::MicrotasksScope::kDoNotRunMicrotasks); |
566 | 566 |
567 v8::Local<v8::Object> console = v8::Object::New(isolate); | 567 v8::Local<v8::Object> console = v8::Object::New(isolate); |
568 bool success = | 568 bool success = |
569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); | 569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); |
570 DCHECK(success); | 570 DCHECK(success); |
571 USE(success); | 571 USE(success); |
572 | 572 |
573 v8::Local<v8::External> data = v8::External::New(isolate, this); | 573 v8::Local<v8::External> data = |
| 574 v8::External::New(isolate, inspectedContext->inspector()); |
574 createBoundFunctionProperty(context, console, data, "debug", | 575 createBoundFunctionProperty(context, console, data, "debug", |
575 &V8Console::call<&V8Console::debugCallback>); | 576 V8Console::debugCallback); |
576 createBoundFunctionProperty(context, console, data, "error", | 577 createBoundFunctionProperty(context, console, data, "error", |
577 &V8Console::call<&V8Console::errorCallback>); | 578 V8Console::errorCallback); |
578 createBoundFunctionProperty(context, console, data, "info", | 579 createBoundFunctionProperty(context, console, data, "info", |
579 &V8Console::call<&V8Console::infoCallback>); | 580 V8Console::infoCallback); |
580 createBoundFunctionProperty(context, console, data, "log", | 581 createBoundFunctionProperty(context, console, data, "log", |
581 &V8Console::call<&V8Console::logCallback>); | 582 V8Console::logCallback); |
582 createBoundFunctionProperty(context, console, data, "warn", | 583 createBoundFunctionProperty(context, console, data, "warn", |
583 &V8Console::call<&V8Console::warnCallback>); | 584 V8Console::warnCallback); |
584 createBoundFunctionProperty(context, console, data, "dir", | 585 createBoundFunctionProperty(context, console, data, "dir", |
585 &V8Console::call<&V8Console::dirCallback>); | 586 V8Console::dirCallback); |
586 createBoundFunctionProperty(context, console, data, "dirxml", | 587 createBoundFunctionProperty(context, console, data, "dirxml", |
587 &V8Console::call<&V8Console::dirxmlCallback>); | 588 V8Console::dirxmlCallback); |
588 createBoundFunctionProperty(context, console, data, "table", | 589 createBoundFunctionProperty(context, console, data, "table", |
589 &V8Console::call<&V8Console::tableCallback>); | 590 V8Console::tableCallback); |
590 createBoundFunctionProperty(context, console, data, "trace", | 591 createBoundFunctionProperty(context, console, data, "trace", |
591 &V8Console::call<&V8Console::traceCallback>); | 592 V8Console::traceCallback); |
592 createBoundFunctionProperty(context, console, data, "group", | 593 createBoundFunctionProperty(context, console, data, "group", |
593 &V8Console::call<&V8Console::groupCallback>); | 594 V8Console::groupCallback); |
594 createBoundFunctionProperty( | 595 createBoundFunctionProperty(context, console, data, "groupCollapsed", |
595 context, console, data, "groupCollapsed", | 596 V8Console::groupCollapsedCallback); |
596 &V8Console::call<&V8Console::groupCollapsedCallback>); | |
597 createBoundFunctionProperty(context, console, data, "groupEnd", | 597 createBoundFunctionProperty(context, console, data, "groupEnd", |
598 &V8Console::call<&V8Console::groupEndCallback>); | 598 V8Console::groupEndCallback); |
599 createBoundFunctionProperty(context, console, data, "clear", | 599 createBoundFunctionProperty(context, console, data, "clear", |
600 &V8Console::call<&V8Console::clearCallback>); | 600 V8Console::clearCallback); |
601 createBoundFunctionProperty(context, console, data, "count", | 601 createBoundFunctionProperty(context, console, data, "count", |
602 &V8Console::call<&V8Console::countCallback>); | 602 V8Console::countCallback); |
603 createBoundFunctionProperty(context, console, data, "assert", | 603 createBoundFunctionProperty(context, console, data, "assert", |
604 &V8Console::call<&V8Console::assertCallback>); | 604 V8Console::assertCallback); |
605 createBoundFunctionProperty( | 605 createBoundFunctionProperty(context, console, data, "markTimeline", |
606 context, console, data, "markTimeline", | 606 V8Console::markTimelineCallback); |
607 &V8Console::call<&V8Console::markTimelineCallback>); | |
608 createBoundFunctionProperty(context, console, data, "profile", | 607 createBoundFunctionProperty(context, console, data, "profile", |
609 &V8Console::call<&V8Console::profileCallback>); | 608 V8Console::profileCallback); |
610 createBoundFunctionProperty(context, console, data, "profileEnd", | 609 createBoundFunctionProperty(context, console, data, "profileEnd", |
611 &V8Console::call<&V8Console::profileEndCallback>); | 610 V8Console::profileEndCallback); |
612 createBoundFunctionProperty(context, console, data, "timeline", | 611 createBoundFunctionProperty(context, console, data, "timeline", |
613 &V8Console::call<&V8Console::timelineCallback>); | 612 V8Console::timelineCallback); |
614 createBoundFunctionProperty( | 613 createBoundFunctionProperty(context, console, data, "timelineEnd", |
615 context, console, data, "timelineEnd", | 614 V8Console::timelineEndCallback); |
616 &V8Console::call<&V8Console::timelineEndCallback>); | |
617 createBoundFunctionProperty(context, console, data, "time", | 615 createBoundFunctionProperty(context, console, data, "time", |
618 &V8Console::call<&V8Console::timeCallback>); | 616 V8Console::timeCallback); |
619 createBoundFunctionProperty(context, console, data, "timeEnd", | 617 createBoundFunctionProperty(context, console, data, "timeEnd", |
620 &V8Console::call<&V8Console::timeEndCallback>); | 618 V8Console::timeEndCallback); |
621 createBoundFunctionProperty(context, console, data, "timeStamp", | 619 createBoundFunctionProperty(context, console, data, "timeStamp", |
622 &V8Console::call<&V8Console::timeStampCallback>); | 620 V8Console::timeStampCallback); |
623 return console; | 621 return console; |
624 } | 622 } |
625 | 623 |
626 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, | 624 void V8Console::installMemoryGetter(V8InspectorImpl* inspector, |
| 625 v8::Local<v8::Context> context, |
627 v8::Local<v8::Object> console) { | 626 v8::Local<v8::Object> console) { |
628 v8::Isolate* isolate = context->GetIsolate(); | 627 v8::Local<v8::External> data = |
629 v8::Local<v8::External> data = v8::External::New(isolate, this); | 628 v8::External::New(inspector->isolate(), inspector); |
630 console->SetAccessorProperty( | 629 console->SetAccessorProperty( |
631 toV8StringInternalized(isolate, "memory"), | 630 toV8StringInternalized(inspector->isolate(), "memory"), |
632 v8::Function::New(context, | 631 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0, |
633 &V8Console::call<&V8Console::memoryGetterCallback>, | 632 v8::ConstructorBehavior::kThrow) |
634 data, 0, v8::ConstructorBehavior::kThrow) | |
635 .ToLocalChecked(), | 633 .ToLocalChecked(), |
636 v8::Function::New(context, | 634 v8::Function::New(context, V8Console::memorySetterCallback, data, 0, |
637 &V8Console::call<&V8Console::memorySetterCallback>, | 635 v8::ConstructorBehavior::kThrow) |
638 data, 0, v8::ConstructorBehavior::kThrow) | |
639 .ToLocalChecked(), | 636 .ToLocalChecked(), |
640 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); | 637 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); |
641 } | 638 } |
642 | 639 |
643 v8::Local<v8::Object> V8Console::createCommandLineAPI( | 640 v8::Local<v8::Object> V8Console::createCommandLineAPI( |
644 v8::Local<v8::Context> context) { | 641 InspectedContext* inspectedContext) { |
| 642 v8::Local<v8::Context> context = inspectedContext->context(); |
645 v8::Isolate* isolate = context->GetIsolate(); | 643 v8::Isolate* isolate = context->GetIsolate(); |
646 v8::MicrotasksScope microtasksScope(isolate, | 644 v8::MicrotasksScope microtasksScope(isolate, |
647 v8::MicrotasksScope::kDoNotRunMicrotasks); | 645 v8::MicrotasksScope::kDoNotRunMicrotasks); |
648 | 646 |
649 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); | 647 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); |
650 bool success = | 648 bool success = |
651 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); | 649 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); |
652 DCHECK(success); | 650 DCHECK(success); |
653 USE(success); | 651 USE(success); |
654 | 652 |
655 v8::Local<v8::External> data = v8::External::New(isolate, this); | 653 v8::Local<v8::External> data = |
| 654 v8::External::New(isolate, inspectedContext->inspector()); |
656 createBoundFunctionProperty(context, commandLineAPI, data, "dir", | 655 createBoundFunctionProperty(context, commandLineAPI, data, "dir", |
657 &V8Console::call<&V8Console::dirCallback>, | 656 V8Console::dirCallback, |
658 "function dir(value) { [Command Line API] }"); | 657 "function dir(value) { [Command Line API] }"); |
659 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", | 658 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", |
660 &V8Console::call<&V8Console::dirxmlCallback>, | 659 V8Console::dirxmlCallback, |
661 "function dirxml(value) { [Command Line API] }"); | 660 "function dirxml(value) { [Command Line API] }"); |
662 createBoundFunctionProperty(context, commandLineAPI, data, "profile", | 661 createBoundFunctionProperty(context, commandLineAPI, data, "profile", |
663 &V8Console::call<&V8Console::profileCallback>, | 662 V8Console::profileCallback, |
664 "function profile(title) { [Command Line API] }"); | 663 "function profile(title) { [Command Line API] }"); |
665 createBoundFunctionProperty( | 664 createBoundFunctionProperty( |
666 context, commandLineAPI, data, "profileEnd", | 665 context, commandLineAPI, data, "profileEnd", |
667 &V8Console::call<&V8Console::profileEndCallback>, | 666 V8Console::profileEndCallback, |
668 "function profileEnd(title) { [Command Line API] }"); | 667 "function profileEnd(title) { [Command Line API] }"); |
669 createBoundFunctionProperty(context, commandLineAPI, data, "clear", | 668 createBoundFunctionProperty(context, commandLineAPI, data, "clear", |
670 &V8Console::call<&V8Console::clearCallback>, | 669 V8Console::clearCallback, |
671 "function clear() { [Command Line API] }"); | 670 "function clear() { [Command Line API] }"); |
672 createBoundFunctionProperty( | 671 createBoundFunctionProperty( |
673 context, commandLineAPI, data, "table", | 672 context, commandLineAPI, data, "table", V8Console::tableCallback, |
674 &V8Console::call<&V8Console::tableCallback>, | |
675 "function table(data, [columns]) { [Command Line API] }"); | 673 "function table(data, [columns]) { [Command Line API] }"); |
676 | 674 |
677 createBoundFunctionProperty(context, commandLineAPI, data, "keys", | 675 createBoundFunctionProperty(context, commandLineAPI, data, "keys", |
678 &V8Console::call<&V8Console::keysCallback>, | 676 V8Console::keysCallback, |
679 "function keys(object) { [Command Line API] }"); | 677 "function keys(object) { [Command Line API] }"); |
680 createBoundFunctionProperty(context, commandLineAPI, data, "values", | 678 createBoundFunctionProperty(context, commandLineAPI, data, "values", |
681 &V8Console::call<&V8Console::valuesCallback>, | 679 V8Console::valuesCallback, |
682 "function values(object) { [Command Line API] }"); | 680 "function values(object) { [Command Line API] }"); |
683 createBoundFunctionProperty( | 681 createBoundFunctionProperty( |
684 context, commandLineAPI, data, "debug", | 682 context, commandLineAPI, data, "debug", V8Console::debugFunctionCallback, |
685 &V8Console::call<&V8Console::debugFunctionCallback>, | |
686 "function debug(function) { [Command Line API] }"); | 683 "function debug(function) { [Command Line API] }"); |
687 createBoundFunctionProperty( | 684 createBoundFunctionProperty( |
688 context, commandLineAPI, data, "undebug", | 685 context, commandLineAPI, data, "undebug", |
689 &V8Console::call<&V8Console::undebugFunctionCallback>, | 686 V8Console::undebugFunctionCallback, |
690 "function undebug(function) { [Command Line API] }"); | 687 "function undebug(function) { [Command Line API] }"); |
691 createBoundFunctionProperty( | 688 createBoundFunctionProperty( |
692 context, commandLineAPI, data, "monitor", | 689 context, commandLineAPI, data, "monitor", |
693 &V8Console::call<&V8Console::monitorFunctionCallback>, | 690 V8Console::monitorFunctionCallback, |
694 "function monitor(function) { [Command Line API] }"); | 691 "function monitor(function) { [Command Line API] }"); |
695 createBoundFunctionProperty( | 692 createBoundFunctionProperty( |
696 context, commandLineAPI, data, "unmonitor", | 693 context, commandLineAPI, data, "unmonitor", |
697 &V8Console::call<&V8Console::unmonitorFunctionCallback>, | 694 V8Console::unmonitorFunctionCallback, |
698 "function unmonitor(function) { [Command Line API] }"); | 695 "function unmonitor(function) { [Command Line API] }"); |
699 createBoundFunctionProperty( | 696 createBoundFunctionProperty( |
700 context, commandLineAPI, data, "inspect", | 697 context, commandLineAPI, data, "inspect", V8Console::inspectCallback, |
701 &V8Console::call<&V8Console::inspectCallback>, | |
702 "function inspect(object) { [Command Line API] }"); | 698 "function inspect(object) { [Command Line API] }"); |
703 createBoundFunctionProperty(context, commandLineAPI, data, "copy", | 699 createBoundFunctionProperty(context, commandLineAPI, data, "copy", |
704 &V8Console::call<&V8Console::copyCallback>, | 700 V8Console::copyCallback, |
705 "function copy(value) { [Command Line API] }"); | 701 "function copy(value) { [Command Line API] }"); |
706 createBoundFunctionProperty( | 702 createBoundFunctionProperty(context, commandLineAPI, data, "$_", |
707 context, commandLineAPI, data, "$_", | 703 V8Console::lastEvaluationResultCallback); |
708 &V8Console::call<&V8Console::lastEvaluationResultCallback>); | |
709 createBoundFunctionProperty(context, commandLineAPI, data, "$0", | 704 createBoundFunctionProperty(context, commandLineAPI, data, "$0", |
710 &V8Console::call<&V8Console::inspectedObject0>); | 705 V8Console::inspectedObject0); |
711 createBoundFunctionProperty(context, commandLineAPI, data, "$1", | 706 createBoundFunctionProperty(context, commandLineAPI, data, "$1", |
712 &V8Console::call<&V8Console::inspectedObject1>); | 707 V8Console::inspectedObject1); |
713 createBoundFunctionProperty(context, commandLineAPI, data, "$2", | 708 createBoundFunctionProperty(context, commandLineAPI, data, "$2", |
714 &V8Console::call<&V8Console::inspectedObject2>); | 709 V8Console::inspectedObject2); |
715 createBoundFunctionProperty(context, commandLineAPI, data, "$3", | 710 createBoundFunctionProperty(context, commandLineAPI, data, "$3", |
716 &V8Console::call<&V8Console::inspectedObject3>); | 711 V8Console::inspectedObject3); |
717 createBoundFunctionProperty(context, commandLineAPI, data, "$4", | 712 createBoundFunctionProperty(context, commandLineAPI, data, "$4", |
718 &V8Console::call<&V8Console::inspectedObject4>); | 713 V8Console::inspectedObject4); |
719 | 714 |
720 m_inspector->client()->installAdditionalCommandLineAPI(context, | 715 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI( |
721 commandLineAPI); | 716 context, commandLineAPI); |
722 return commandLineAPI; | 717 return commandLineAPI; |
723 } | 718 } |
724 | 719 |
725 static bool isCommandLineAPIGetter(const String16& name) { | 720 static bool isCommandLineAPIGetter(const String16& name) { |
726 if (name.length() != 2) return false; | 721 if (name.length() != 2) return false; |
727 // $0 ... $4, $_ | 722 // $0 ... $4, $_ |
728 return name[0] == '$' && | 723 return name[0] == '$' && |
729 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); | 724 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); |
730 } | 725 } |
731 | 726 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 ->GetOwnPropertyDescriptor( | 813 ->GetOwnPropertyDescriptor( |
819 m_context, v8::Local<v8::String>::Cast(name)) | 814 m_context, v8::Local<v8::String>::Cast(name)) |
820 .ToLocal(&descriptor); | 815 .ToLocal(&descriptor); |
821 DCHECK(success); | 816 DCHECK(success); |
822 USE(success); | 817 USE(success); |
823 } | 818 } |
824 } | 819 } |
825 } | 820 } |
826 | 821 |
827 } // namespace v8_inspector | 822 } // namespace v8_inspector |
OLD | NEW |