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

Side by Side Diff: src/inspector/v8-console.cc

Issue 2795003003: Revert of [inspector] move console to builtins (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-inspector-impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ConsoleHelper(const v8::debug::ConsoleCallArguments& info, 28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
29 V8InspectorImpl* inspector) 29 V8InspectorImpl* inspector)
30 : m_info(info), 30 : m_info(info),
31 m_isolate(inspector->isolate()), 31 m_isolate(info.GetIsolate()),
32 m_context(m_isolate->GetCurrentContext()), 32 m_context(info.GetIsolate()->GetCurrentContext()),
33 m_inspector(inspector), 33 m_inspector(inspector),
34 m_contextId(InspectedContext::contextId(m_context)), 34 m_contextId(InspectedContext::contextId(m_context)),
35 m_groupId(m_inspector->contextGroupId(m_contextId)) {} 35 m_groupId(m_inspector->contextGroupId(m_contextId)) {}
36 36
37 int contextId() const { return m_contextId; } 37 int contextId() const { return m_contextId; }
38 int groupId() const { return m_groupId; } 38 int groupId() const { return m_groupId; }
39 39
40 InjectedScript* injectedScript() { 40 InjectedScript* injectedScript() {
41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); 41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
42 if (!context) return nullptr; 42 if (!context) return nullptr;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return session->debuggerAgent(); 138 return session->debuggerAgent();
139 } 139 }
140 return nullptr; 140 return nullptr;
141 } 141 }
142 142
143 V8InspectorSessionImpl* currentSession() { 143 V8InspectorSessionImpl* currentSession() {
144 return m_inspector->sessionForContextGroup(m_groupId); 144 return m_inspector->sessionForContextGroup(m_groupId);
145 } 145 }
146 146
147 private: 147 private:
148 const v8::debug::ConsoleCallArguments& m_info; 148 const v8::FunctionCallbackInfo<v8::Value>& m_info;
149 v8::Isolate* m_isolate; 149 v8::Isolate* m_isolate;
150 v8::Local<v8::Context> m_context; 150 v8::Local<v8::Context> m_context;
151 V8InspectorImpl* m_inspector = nullptr; 151 V8InspectorImpl* m_inspector = nullptr;
152 int m_contextId; 152 int m_contextId;
153 int m_groupId; 153 int m_groupId;
154 154
155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); 155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper);
156 }; 156 };
157 157
158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
(...skipping 24 matching lines...) Expand all
183 context->GetIsolate(), "toString"), 183 context->GetIsolate(), "toString"),
184 toStringFunction); 184 toStringFunction);
185 } 185 }
186 createDataProperty(context, console, funcName, func); 186 createDataProperty(context, console, funcName, func);
187 } 187 }
188 188
189 } // namespace 189 } // namespace
190 190
191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} 191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
192 192
193 void V8Console::Debug(const v8::debug::ConsoleCallArguments& info) { 193 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug); 194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
195 } 195 }
196 196
197 void V8Console::Error(const v8::debug::ConsoleCallArguments& info) { 197 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError); 198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
199 } 199 }
200 200
201 void V8Console::Info(const v8::debug::ConsoleCallArguments& info) { 201 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo); 202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
203 } 203 }
204 204
205 void V8Console::Log(const v8::debug::ConsoleCallArguments& info) { 205 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog); 206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
207 } 207 }
208 208
209 void V8Console::Warn(const v8::debug::ConsoleCallArguments& info) { 209 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning); 210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
211 } 211 }
212 212
213 void V8Console::Dir(const v8::debug::ConsoleCallArguments& info) { 213 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir); 214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
215 } 215 }
216 216
217 void V8Console::DirXml(const v8::debug::ConsoleCallArguments& info) { 217 void V8Console::dirxmlCallback(
218 const v8::FunctionCallbackInfo<v8::Value>& info) {
218 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML); 219 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
219 } 220 }
220 221
221 void V8Console::Table(const v8::debug::ConsoleCallArguments& info) { 222 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
222 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable); 223 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
223 } 224 }
224 225
225 void V8Console::Trace(const v8::debug::ConsoleCallArguments& info) { 226 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
226 ConsoleHelper(info, m_inspector) 227 ConsoleHelper(info, m_inspector)
227 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace, 228 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
228 String16("console.trace")); 229 String16("console.trace"));
229 } 230 }
230 231
231 void V8Console::Group(const v8::debug::ConsoleCallArguments& info) { 232 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
232 ConsoleHelper(info, m_inspector) 233 ConsoleHelper(info, m_inspector)
233 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, 234 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
234 String16("console.group")); 235 String16("console.group"));
235 } 236 }
236 237
237 void V8Console::GroupCollapsed(const v8::debug::ConsoleCallArguments& info) { 238 void V8Console::groupCollapsedCallback(
239 const v8::FunctionCallbackInfo<v8::Value>& info) {
238 ConsoleHelper(info, m_inspector) 240 ConsoleHelper(info, m_inspector)
239 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, 241 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
240 String16("console.groupCollapsed")); 242 String16("console.groupCollapsed"));
241 } 243 }
242 244
243 void V8Console::GroupEnd(const v8::debug::ConsoleCallArguments& info) { 245 void V8Console::groupEndCallback(
246 const v8::FunctionCallbackInfo<v8::Value>& info) {
244 ConsoleHelper(info, m_inspector) 247 ConsoleHelper(info, m_inspector)
245 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, 248 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
246 String16("console.groupEnd")); 249 String16("console.groupEnd"));
247 } 250 }
248 251
249 void V8Console::Clear(const v8::debug::ConsoleCallArguments& info) { 252 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
250 ConsoleHelper helper(info, m_inspector); 253 ConsoleHelper helper(info, m_inspector);
251 if (!helper.groupId()) return; 254 if (!helper.groupId()) return;
252 m_inspector->client()->consoleClear(helper.groupId()); 255 m_inspector->client()->consoleClear(helper.groupId());
253 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, 256 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
254 String16("console.clear")); 257 String16("console.clear"));
255 } 258 }
256 259
257 void V8Console::Count(const v8::debug::ConsoleCallArguments& info) { 260 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
258 ConsoleHelper helper(info, m_inspector); 261 ConsoleHelper helper(info, m_inspector);
259 String16 title = helper.firstArgToString(String16()); 262 String16 title = helper.firstArgToString(String16());
260 String16 identifier; 263 String16 identifier;
261 if (title.isEmpty()) { 264 if (title.isEmpty()) {
262 std::unique_ptr<V8StackTraceImpl> stackTrace = 265 std::unique_ptr<V8StackTraceImpl> stackTrace =
263 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1); 266 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1);
264 if (stackTrace && !stackTrace->isEmpty()) { 267 if (stackTrace && !stackTrace->isEmpty()) {
265 identifier = toString16(stackTrace->topSourceURL()) + ":" + 268 identifier = toString16(stackTrace->topSourceURL()) + ":" +
266 String16::fromInteger(stackTrace->topLineNumber()); 269 String16::fromInteger(stackTrace->topLineNumber());
267 } 270 }
268 } else { 271 } else {
269 identifier = title + "@"; 272 identifier = title + "@";
270 } 273 }
271 274
272 int count = 275 int count =
273 helper.consoleMessageStorage()->count(helper.contextId(), identifier); 276 helper.consoleMessageStorage()->count(helper.contextId(), identifier);
274 String16 countString = String16::fromInteger(count); 277 String16 countString = String16::fromInteger(count);
275 helper.reportCallWithArgument( 278 helper.reportCallWithArgument(
276 ConsoleAPIType::kCount, 279 ConsoleAPIType::kCount,
277 title.isEmpty() ? countString : (title + ": " + countString)); 280 title.isEmpty() ? countString : (title + ": " + countString));
278 } 281 }
279 282
280 void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) { 283 void V8Console::assertCallback(
284 const v8::FunctionCallbackInfo<v8::Value>& info) {
281 ConsoleHelper helper(info, m_inspector); 285 ConsoleHelper helper(info, m_inspector);
282 if (helper.firstArgToBoolean(false)) return; 286 if (helper.firstArgToBoolean(false)) return;
283 287
284 std::vector<v8::Local<v8::Value>> arguments; 288 std::vector<v8::Local<v8::Value>> arguments;
285 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); 289 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]);
286 if (info.Length() < 2) 290 if (info.Length() < 2)
287 arguments.push_back( 291 arguments.push_back(
288 toV8String(m_inspector->isolate(), String16("console.assert"))); 292 toV8String(info.GetIsolate(), String16("console.assert")));
289 helper.reportCall(ConsoleAPIType::kAssert, arguments); 293 helper.reportCall(ConsoleAPIType::kAssert, arguments);
290 294
291 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) 295 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
292 debuggerAgent->breakProgramOnException( 296 debuggerAgent->breakProgramOnException(
293 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); 297 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr);
294 } 298 }
295 299
296 void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) { 300 void V8Console::markTimelineCallback(
301 const v8::FunctionCallbackInfo<v8::Value>& info) {
297 ConsoleHelper(info, m_inspector) 302 ConsoleHelper(info, m_inspector)
298 .reportDeprecatedCall("V8Console#markTimelineDeprecated", 303 .reportDeprecatedCall("V8Console#markTimelineDeprecated",
299 "'console.markTimeline' is " 304 "'console.markTimeline' is "
300 "deprecated. Please use " 305 "deprecated. Please use "
301 "'console.timeStamp' instead."); 306 "'console.timeStamp' instead.");
302 TimeStamp(info); 307 timeStampCallback(info);
303 } 308 }
304 309
305 void V8Console::Profile(const v8::debug::ConsoleCallArguments& info) { 310 void V8Console::profileCallback(
311 const v8::FunctionCallbackInfo<v8::Value>& info) {
306 ConsoleHelper helper(info, m_inspector); 312 ConsoleHelper helper(info, m_inspector);
307 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) 313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
308 profilerAgent->consoleProfile(helper.firstArgToString(String16())); 314 profilerAgent->consoleProfile(helper.firstArgToString(String16()));
309 } 315 }
310 316
311 void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info) { 317 void V8Console::profileEndCallback(
318 const v8::FunctionCallbackInfo<v8::Value>& info) {
312 ConsoleHelper helper(info, m_inspector); 319 ConsoleHelper helper(info, m_inspector);
313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) 320 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
314 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); 321 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
315 } 322 }
316 323
317 static void timeFunction(const v8::debug::ConsoleCallArguments& info, 324 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
318 bool timelinePrefix, V8InspectorImpl* inspector) { 325 bool timelinePrefix, V8InspectorImpl* inspector) {
319 ConsoleHelper helper(info, inspector); 326 ConsoleHelper helper(info, inspector);
320 String16 protocolTitle = helper.firstArgToString("default"); 327 String16 protocolTitle = helper.firstArgToString("default");
321 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 328 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
322 inspector->client()->consoleTime(toStringView(protocolTitle)); 329 inspector->client()->consoleTime(toStringView(protocolTitle));
323 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); 330 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
324 } 331 }
325 332
326 static void timeEndFunction(const v8::debug::ConsoleCallArguments& info, 333 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
327 bool timelinePrefix, V8InspectorImpl* inspector) { 334 bool timelinePrefix, V8InspectorImpl* inspector) {
328 ConsoleHelper helper(info, inspector); 335 ConsoleHelper helper(info, inspector);
329 String16 protocolTitle = helper.firstArgToString("default"); 336 String16 protocolTitle = helper.firstArgToString("default");
330 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 337 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
331 inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); 338 inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
332 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), 339 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
333 protocolTitle); 340 protocolTitle);
334 String16 message = 341 String16 message =
335 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; 342 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
336 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); 343 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
337 } 344 }
338 345
339 void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info) { 346 void V8Console::timelineCallback(
347 const v8::FunctionCallbackInfo<v8::Value>& info) {
340 ConsoleHelper(info, m_inspector) 348 ConsoleHelper(info, m_inspector)
341 .reportDeprecatedCall("V8Console#timeline", 349 .reportDeprecatedCall("V8Console#timeline",
342 "'console.timeline' is deprecated. Please use " 350 "'console.timeline' is deprecated. Please use "
343 "'console.time' instead."); 351 "'console.time' instead.");
344 timeFunction(info, true, m_inspector); 352 timeFunction(info, true, m_inspector);
345 } 353 }
346 354
347 void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info) { 355 void V8Console::timelineEndCallback(
356 const v8::FunctionCallbackInfo<v8::Value>& info) {
348 ConsoleHelper(info, m_inspector) 357 ConsoleHelper(info, m_inspector)
349 .reportDeprecatedCall("V8Console#timelineEnd", 358 .reportDeprecatedCall("V8Console#timelineEnd",
350 "'console.timelineEnd' is " 359 "'console.timelineEnd' is "
351 "deprecated. Please use " 360 "deprecated. Please use "
352 "'console.timeEnd' instead."); 361 "'console.timeEnd' instead.");
353 timeEndFunction(info, true, m_inspector); 362 timeEndFunction(info, true, m_inspector);
354 } 363 }
355 364
356 void V8Console::Time(const v8::debug::ConsoleCallArguments& info) { 365 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
357 timeFunction(info, false, m_inspector); 366 timeFunction(info, false, m_inspector);
358 } 367 }
359 368
360 void V8Console::TimeEnd(const v8::debug::ConsoleCallArguments& info) { 369 void V8Console::timeEndCallback(
370 const v8::FunctionCallbackInfo<v8::Value>& info) {
361 timeEndFunction(info, false, m_inspector); 371 timeEndFunction(info, false, m_inspector);
362 } 372 }
363 373
364 void V8Console::TimeStamp(const v8::debug::ConsoleCallArguments& info) { 374 void V8Console::timeStampCallback(
375 const v8::FunctionCallbackInfo<v8::Value>& info) {
365 ConsoleHelper helper(info, m_inspector); 376 ConsoleHelper helper(info, m_inspector);
366 String16 title = helper.firstArgToString(String16()); 377 String16 title = helper.firstArgToString(String16());
367 m_inspector->client()->consoleTimeStamp(toStringView(title)); 378 m_inspector->client()->consoleTimeStamp(toStringView(title));
368 } 379 }
369 380
370 void V8Console::memoryGetterCallback( 381 void V8Console::memoryGetterCallback(
371 const v8::FunctionCallbackInfo<v8::Value>& info) { 382 const v8::FunctionCallbackInfo<v8::Value>& info) {
372 v8::Local<v8::Value> memoryValue; 383 v8::Local<v8::Value> memoryValue;
373 if (!m_inspector->client() 384 if (!m_inspector->client()
374 ->memoryInfo(info.GetIsolate(), 385 ->memoryInfo(info.GetIsolate(),
375 info.GetIsolate()->GetCurrentContext()) 386 info.GetIsolate()->GetCurrentContext())
376 .ToLocal(&memoryValue)) 387 .ToLocal(&memoryValue))
377 return; 388 return;
378 info.GetReturnValue().Set(memoryValue); 389 info.GetReturnValue().Set(memoryValue);
379 } 390 }
380 391
381 void V8Console::memorySetterCallback( 392 void V8Console::memorySetterCallback(
382 const v8::FunctionCallbackInfo<v8::Value>& info) { 393 const v8::FunctionCallbackInfo<v8::Value>& info) {
383 // We can't make the attribute readonly as it breaks existing code that relies 394 // We can't make the attribute readonly as it breaks existing code that relies
384 // on being able to assign to console.memory in strict mode. Instead, the 395 // on being able to assign to console.memory in strict mode. Instead, the
385 // setter just ignores the passed value. http://crbug.com/468611 396 // setter just ignores the passed value. http://crbug.com/468611
386 } 397 }
387 398
388 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 399 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
389 v8::Isolate* isolate = info.GetIsolate(); 400 v8::Isolate* isolate = info.GetIsolate();
390 info.GetReturnValue().Set(v8::Array::New(isolate)); 401 info.GetReturnValue().Set(v8::Array::New(isolate));
391 402
392 v8::debug::ConsoleCallArguments args(info); 403 ConsoleHelper helper(info, m_inspector);
393 ConsoleHelper helper(args, m_inspector);
394 v8::Local<v8::Object> obj; 404 v8::Local<v8::Object> obj;
395 if (!helper.firstArgAsObject().ToLocal(&obj)) return; 405 if (!helper.firstArgAsObject().ToLocal(&obj)) return;
396 v8::Local<v8::Array> names; 406 v8::Local<v8::Array> names;
397 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) 407 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names))
398 return; 408 return;
399 info.GetReturnValue().Set(names); 409 info.GetReturnValue().Set(names);
400 } 410 }
401 411
402 void V8Console::valuesCallback( 412 void V8Console::valuesCallback(
403 const v8::FunctionCallbackInfo<v8::Value>& info) { 413 const v8::FunctionCallbackInfo<v8::Value>& info) {
404 v8::Isolate* isolate = info.GetIsolate(); 414 v8::Isolate* isolate = info.GetIsolate();
405 info.GetReturnValue().Set(v8::Array::New(isolate)); 415 info.GetReturnValue().Set(v8::Array::New(isolate));
406 416
407 v8::debug::ConsoleCallArguments args(info); 417 ConsoleHelper helper(info, m_inspector);
408 ConsoleHelper helper(args, m_inspector);
409 v8::Local<v8::Object> obj; 418 v8::Local<v8::Object> obj;
410 if (!helper.firstArgAsObject().ToLocal(&obj)) return; 419 if (!helper.firstArgAsObject().ToLocal(&obj)) return;
411 v8::Local<v8::Array> names; 420 v8::Local<v8::Array> names;
412 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 421 v8::Local<v8::Context> context = isolate->GetCurrentContext();
413 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; 422 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return;
414 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); 423 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length());
415 for (uint32_t i = 0; i < names->Length(); ++i) { 424 for (uint32_t i = 0; i < names->Length(); ++i) {
416 v8::Local<v8::Value> key; 425 v8::Local<v8::Value> key;
417 if (!names->Get(context, i).ToLocal(&key)) continue; 426 if (!names->Get(context, i).ToLocal(&key)) continue;
418 v8::Local<v8::Value> value; 427 v8::Local<v8::Value> value;
(...skipping 18 matching lines...) Expand all
437 if (enable) 446 if (enable)
438 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, 447 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source,
439 condition); 448 condition);
440 else 449 else
441 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, 450 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber,
442 source); 451 source);
443 } 452 }
444 453
445 void V8Console::debugFunctionCallback( 454 void V8Console::debugFunctionCallback(
446 const v8::FunctionCallbackInfo<v8::Value>& info) { 455 const v8::FunctionCallbackInfo<v8::Value>& info) {
447 v8::debug::ConsoleCallArguments args(info); 456 ConsoleHelper helper(info, m_inspector);
448 ConsoleHelper helper(args, m_inspector);
449 v8::Local<v8::Function> function; 457 v8::Local<v8::Function> function;
450 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 458 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
451 setFunctionBreakpoint(helper, function, 459 setFunctionBreakpoint(helper, function,
452 V8DebuggerAgentImpl::DebugCommandBreakpointSource, 460 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
453 String16(), true); 461 String16(), true);
454 } 462 }
455 463
456 void V8Console::undebugFunctionCallback( 464 void V8Console::undebugFunctionCallback(
457 const v8::FunctionCallbackInfo<v8::Value>& info) { 465 const v8::FunctionCallbackInfo<v8::Value>& info) {
458 v8::debug::ConsoleCallArguments args(info); 466 ConsoleHelper helper(info, m_inspector);
459 ConsoleHelper helper(args, m_inspector);
460 v8::Local<v8::Function> function; 467 v8::Local<v8::Function> function;
461 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 468 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
462 setFunctionBreakpoint(helper, function, 469 setFunctionBreakpoint(helper, function,
463 V8DebuggerAgentImpl::DebugCommandBreakpointSource, 470 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
464 String16(), false); 471 String16(), false);
465 } 472 }
466 473
467 void V8Console::monitorFunctionCallback( 474 void V8Console::monitorFunctionCallback(
468 const v8::FunctionCallbackInfo<v8::Value>& info) { 475 const v8::FunctionCallbackInfo<v8::Value>& info) {
469 v8::debug::ConsoleCallArguments args(info); 476 ConsoleHelper helper(info, m_inspector);
470 ConsoleHelper helper(args, m_inspector);
471 v8::Local<v8::Function> function; 477 v8::Local<v8::Function> function;
472 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 478 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
473 v8::Local<v8::Value> name = function->GetName(); 479 v8::Local<v8::Value> name = function->GetName();
474 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) 480 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
475 name = function->GetInferredName(); 481 name = function->GetInferredName();
476 String16 functionName = toProtocolStringWithTypeCheck(name); 482 String16 functionName = toProtocolStringWithTypeCheck(name);
477 String16Builder builder; 483 String16Builder builder;
478 builder.append("console.log(\"function "); 484 builder.append("console.log(\"function ");
479 if (functionName.isEmpty()) 485 if (functionName.isEmpty())
480 builder.append("(anonymous function)"); 486 builder.append("(anonymous function)");
481 else 487 else
482 builder.append(functionName); 488 builder.append(functionName);
483 builder.append( 489 builder.append(
484 " called\" + (arguments.length > 0 ? \" with arguments: \" + " 490 " called\" + (arguments.length > 0 ? \" with arguments: \" + "
485 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); 491 "Array.prototype.join.call(arguments, \", \") : \"\")) && false");
486 setFunctionBreakpoint(helper, function, 492 setFunctionBreakpoint(helper, function,
487 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, 493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
488 builder.toString(), true); 494 builder.toString(), true);
489 } 495 }
490 496
491 void V8Console::unmonitorFunctionCallback( 497 void V8Console::unmonitorFunctionCallback(
492 const v8::FunctionCallbackInfo<v8::Value>& info) { 498 const v8::FunctionCallbackInfo<v8::Value>& info) {
493 v8::debug::ConsoleCallArguments args(info); 499 ConsoleHelper helper(info, m_inspector);
494 ConsoleHelper helper(args, m_inspector);
495 v8::Local<v8::Function> function; 500 v8::Local<v8::Function> function;
496 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 501 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
497 setFunctionBreakpoint(helper, function, 502 setFunctionBreakpoint(helper, function,
498 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, 503 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
499 String16(), false); 504 String16(), false);
500 } 505 }
501 506
502 void V8Console::lastEvaluationResultCallback( 507 void V8Console::lastEvaluationResultCallback(
503 const v8::FunctionCallbackInfo<v8::Value>& info) { 508 const v8::FunctionCallbackInfo<v8::Value>& info) {
504 v8::debug::ConsoleCallArguments args(info); 509 ConsoleHelper helper(info, m_inspector);
505 ConsoleHelper helper(args, m_inspector);
506 InjectedScript* injectedScript = helper.injectedScript(); 510 InjectedScript* injectedScript = helper.injectedScript();
507 if (!injectedScript) return; 511 if (!injectedScript) return;
508 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); 512 info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
509 } 513 }
510 514
511 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, 515 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
512 bool copyToClipboard, V8InspectorImpl* inspector) { 516 bool copyToClipboard, V8InspectorImpl* inspector) {
513 if (info.Length() < 1) return; 517 if (info.Length() < 1) return;
514 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); 518 if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
515 519
516 v8::debug::ConsoleCallArguments args(info); 520 ConsoleHelper helper(info, inspector);
517 ConsoleHelper helper(args, inspector);
518 InjectedScript* injectedScript = helper.injectedScript(); 521 InjectedScript* injectedScript = helper.injectedScript();
519 if (!injectedScript) return; 522 if (!injectedScript) return;
520 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; 523 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
521 protocol::Response response = 524 protocol::Response response =
522 injectedScript->wrapObject(info[0], "", false /** forceValueType */, 525 injectedScript->wrapObject(info[0], "", false /** forceValueType */,
523 false /** generatePreview */, &wrappedObject); 526 false /** generatePreview */, &wrappedObject);
524 if (!response.isSuccess()) return; 527 if (!response.isSuccess()) return;
525 528
526 std::unique_ptr<protocol::DictionaryValue> hints = 529 std::unique_ptr<protocol::DictionaryValue> hints =
527 protocol::DictionaryValue::create(); 530 protocol::DictionaryValue::create();
528 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); 531 if (copyToClipboard) hints->setBoolean("copyToClipboard", true);
529 if (V8InspectorSessionImpl* session = helper.currentSession()) { 532 if (V8InspectorSessionImpl* session = helper.currentSession()) {
530 session->runtimeAgent()->inspect(std::move(wrappedObject), 533 session->runtimeAgent()->inspect(std::move(wrappedObject),
531 std::move(hints)); 534 std::move(hints));
532 } 535 }
533 } 536 }
534 537
535 void V8Console::inspectCallback( 538 void V8Console::inspectCallback(
536 const v8::FunctionCallbackInfo<v8::Value>& info) { 539 const v8::FunctionCallbackInfo<v8::Value>& info) {
537 inspectImpl(info, false, m_inspector); 540 inspectImpl(info, false, m_inspector);
538 } 541 }
539 542
540 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 543 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
541 inspectImpl(info, true, m_inspector); 544 inspectImpl(info, true, m_inspector);
542 } 545 }
543 546
544 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, 547 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
545 unsigned num) { 548 unsigned num) {
546 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); 549 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
547 v8::debug::ConsoleCallArguments args(info); 550 ConsoleHelper helper(info, m_inspector);
548 ConsoleHelper helper(args, m_inspector);
549 if (V8InspectorSessionImpl* session = helper.currentSession()) { 551 if (V8InspectorSessionImpl* session = helper.currentSession()) {
550 V8InspectorSession::Inspectable* object = session->inspectedObject(num); 552 V8InspectorSession::Inspectable* object = session->inspectedObject(num);
551 v8::Isolate* isolate = info.GetIsolate(); 553 v8::Isolate* isolate = info.GetIsolate();
552 if (object) 554 if (object)
553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); 555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext()));
554 else 556 else
555 info.GetReturnValue().Set(v8::Undefined(isolate)); 557 info.GetReturnValue().Set(v8::Undefined(isolate));
556 } 558 }
557 } 559 }
558 560
561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) {
562 v8::Context::Scope contextScope(context);
563 v8::Isolate* isolate = context->GetIsolate();
564 v8::MicrotasksScope microtasksScope(isolate,
565 v8::MicrotasksScope::kDoNotRunMicrotasks);
566
567 v8::Local<v8::Object> console = v8::Object::New(isolate);
568 bool success =
569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false);
570 DCHECK(success);
571 USE(success);
572
573 v8::Local<v8::External> data = v8::External::New(isolate, this);
574 createBoundFunctionProperty(context, console, data, "debug",
575 &V8Console::call<&V8Console::debugCallback>);
576 createBoundFunctionProperty(context, console, data, "error",
577 &V8Console::call<&V8Console::errorCallback>);
578 createBoundFunctionProperty(context, console, data, "info",
579 &V8Console::call<&V8Console::infoCallback>);
580 createBoundFunctionProperty(context, console, data, "log",
581 &V8Console::call<&V8Console::logCallback>);
582 createBoundFunctionProperty(context, console, data, "warn",
583 &V8Console::call<&V8Console::warnCallback>);
584 createBoundFunctionProperty(context, console, data, "dir",
585 &V8Console::call<&V8Console::dirCallback>);
586 createBoundFunctionProperty(context, console, data, "dirxml",
587 &V8Console::call<&V8Console::dirxmlCallback>);
588 createBoundFunctionProperty(context, console, data, "table",
589 &V8Console::call<&V8Console::tableCallback>);
590 createBoundFunctionProperty(context, console, data, "trace",
591 &V8Console::call<&V8Console::traceCallback>);
592 createBoundFunctionProperty(context, console, data, "group",
593 &V8Console::call<&V8Console::groupCallback>);
594 createBoundFunctionProperty(
595 context, console, data, "groupCollapsed",
596 &V8Console::call<&V8Console::groupCollapsedCallback>);
597 createBoundFunctionProperty(context, console, data, "groupEnd",
598 &V8Console::call<&V8Console::groupEndCallback>);
599 createBoundFunctionProperty(context, console, data, "clear",
600 &V8Console::call<&V8Console::clearCallback>);
601 createBoundFunctionProperty(context, console, data, "count",
602 &V8Console::call<&V8Console::countCallback>);
603 createBoundFunctionProperty(context, console, data, "assert",
604 &V8Console::call<&V8Console::assertCallback>);
605 createBoundFunctionProperty(
606 context, console, data, "markTimeline",
607 &V8Console::call<&V8Console::markTimelineCallback>);
608 createBoundFunctionProperty(context, console, data, "profile",
609 &V8Console::call<&V8Console::profileCallback>);
610 createBoundFunctionProperty(context, console, data, "profileEnd",
611 &V8Console::call<&V8Console::profileEndCallback>);
612 createBoundFunctionProperty(context, console, data, "timeline",
613 &V8Console::call<&V8Console::timelineCallback>);
614 createBoundFunctionProperty(
615 context, console, data, "timelineEnd",
616 &V8Console::call<&V8Console::timelineEndCallback>);
617 createBoundFunctionProperty(context, console, data, "time",
618 &V8Console::call<&V8Console::timeCallback>);
619 createBoundFunctionProperty(context, console, data, "timeEnd",
620 &V8Console::call<&V8Console::timeEndCallback>);
621 createBoundFunctionProperty(context, console, data, "timeStamp",
622 &V8Console::call<&V8Console::timeStampCallback>);
623 return console;
624 }
625
559 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, 626 void V8Console::installMemoryGetter(v8::Local<v8::Context> context,
560 v8::Local<v8::Object> console) { 627 v8::Local<v8::Object> console) {
561 v8::Isolate* isolate = context->GetIsolate(); 628 v8::Isolate* isolate = context->GetIsolate();
562 v8::Local<v8::External> data = v8::External::New(isolate, this); 629 v8::Local<v8::External> data = v8::External::New(isolate, this);
563 console->SetAccessorProperty( 630 console->SetAccessorProperty(
564 toV8StringInternalized(isolate, "memory"), 631 toV8StringInternalized(isolate, "memory"),
565 v8::Function::New(context, 632 v8::Function::New(context,
566 &V8Console::call<&V8Console::memoryGetterCallback>, 633 &V8Console::call<&V8Console::memoryGetterCallback>,
567 data, 0, v8::ConstructorBehavior::kThrow) 634 data, 0, v8::ConstructorBehavior::kThrow)
568 .ToLocalChecked(), 635 .ToLocalChecked(),
(...skipping 11 matching lines...) Expand all
580 v8::MicrotasksScope::kDoNotRunMicrotasks); 647 v8::MicrotasksScope::kDoNotRunMicrotasks);
581 648
582 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); 649 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate);
583 bool success = 650 bool success =
584 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); 651 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false);
585 DCHECK(success); 652 DCHECK(success);
586 USE(success); 653 USE(success);
587 654
588 v8::Local<v8::External> data = v8::External::New(isolate, this); 655 v8::Local<v8::External> data = v8::External::New(isolate, this);
589 createBoundFunctionProperty(context, commandLineAPI, data, "dir", 656 createBoundFunctionProperty(context, commandLineAPI, data, "dir",
590 &V8Console::call<&V8Console::Dir>, 657 &V8Console::call<&V8Console::dirCallback>,
591 "function dir(value) { [Command Line API] }"); 658 "function dir(value) { [Command Line API] }");
592 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", 659 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml",
593 &V8Console::call<&V8Console::DirXml>, 660 &V8Console::call<&V8Console::dirxmlCallback>,
594 "function dirxml(value) { [Command Line API] }"); 661 "function dirxml(value) { [Command Line API] }");
595 createBoundFunctionProperty(context, commandLineAPI, data, "profile", 662 createBoundFunctionProperty(context, commandLineAPI, data, "profile",
596 &V8Console::call<&V8Console::Profile>, 663 &V8Console::call<&V8Console::profileCallback>,
597 "function profile(title) { [Command Line API] }"); 664 "function profile(title) { [Command Line API] }");
598 createBoundFunctionProperty( 665 createBoundFunctionProperty(
599 context, commandLineAPI, data, "profileEnd", 666 context, commandLineAPI, data, "profileEnd",
600 &V8Console::call<&V8Console::ProfileEnd>, 667 &V8Console::call<&V8Console::profileEndCallback>,
601 "function profileEnd(title) { [Command Line API] }"); 668 "function profileEnd(title) { [Command Line API] }");
602 createBoundFunctionProperty(context, commandLineAPI, data, "clear", 669 createBoundFunctionProperty(context, commandLineAPI, data, "clear",
603 &V8Console::call<&V8Console::Clear>, 670 &V8Console::call<&V8Console::clearCallback>,
604 "function clear() { [Command Line API] }"); 671 "function clear() { [Command Line API] }");
605 createBoundFunctionProperty( 672 createBoundFunctionProperty(
606 context, commandLineAPI, data, "table", 673 context, commandLineAPI, data, "table",
607 &V8Console::call<&V8Console::Table>, 674 &V8Console::call<&V8Console::tableCallback>,
608 "function table(data, [columns]) { [Command Line API] }"); 675 "function table(data, [columns]) { [Command Line API] }");
609 676
610 createBoundFunctionProperty(context, commandLineAPI, data, "keys", 677 createBoundFunctionProperty(context, commandLineAPI, data, "keys",
611 &V8Console::call<&V8Console::keysCallback>, 678 &V8Console::call<&V8Console::keysCallback>,
612 "function keys(object) { [Command Line API] }"); 679 "function keys(object) { [Command Line API] }");
613 createBoundFunctionProperty(context, commandLineAPI, data, "values", 680 createBoundFunctionProperty(context, commandLineAPI, data, "values",
614 &V8Console::call<&V8Console::valuesCallback>, 681 &V8Console::call<&V8Console::valuesCallback>,
615 "function values(object) { [Command Line API] }"); 682 "function values(object) { [Command Line API] }");
616 createBoundFunctionProperty( 683 createBoundFunctionProperty(
617 context, commandLineAPI, data, "debug", 684 context, commandLineAPI, data, "debug",
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 ->GetOwnPropertyDescriptor( 818 ->GetOwnPropertyDescriptor(
752 m_context, v8::Local<v8::String>::Cast(name)) 819 m_context, v8::Local<v8::String>::Cast(name))
753 .ToLocal(&descriptor); 820 .ToLocal(&descriptor);
754 DCHECK(success); 821 DCHECK(success);
755 USE(success); 822 USE(success);
756 } 823 }
757 } 824 }
758 } 825 }
759 826
760 } // namespace v8_inspector 827 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-inspector-impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698