| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 : m_info(info), | 30 : m_info(info), |
| 31 m_isolate(inspector->isolate()), | 31 m_isolate(inspector->isolate()), |
| 32 m_context(m_isolate->GetCurrentContext()), | 32 m_context(m_isolate->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(int sessionId) { |
| 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; |
| 43 return context->getInjectedScript(); | 43 return context->getInjectedScript(sessionId); |
| 44 } |
| 45 |
| 46 V8InspectorSessionImpl* session(int sessionId) { |
| 47 return m_inspector->sessionById(m_groupId, sessionId); |
| 44 } | 48 } |
| 45 | 49 |
| 46 V8ConsoleMessageStorage* consoleMessageStorage() { | 50 V8ConsoleMessageStorage* consoleMessageStorage() { |
| 47 return m_inspector->ensureConsoleMessageStorage(m_groupId); | 51 return m_inspector->ensureConsoleMessageStorage(m_groupId); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void reportCall(ConsoleAPIType type) { | 54 void reportCall(ConsoleAPIType type) { |
| 51 if (!m_info.Length()) return; | 55 if (!m_info.Length()) return; |
| 52 std::vector<v8::Local<v8::Value>> arguments; | 56 std::vector<v8::Local<v8::Value>> arguments; |
| 53 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | 57 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 ConsoleHelper helper(info, m_inspector); | 269 ConsoleHelper helper(info, m_inspector); |
| 266 DCHECK(!helper.firstArgToBoolean(false)); | 270 DCHECK(!helper.firstArgToBoolean(false)); |
| 267 | 271 |
| 268 std::vector<v8::Local<v8::Value>> arguments; | 272 std::vector<v8::Local<v8::Value>> arguments; |
| 269 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); | 273 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); |
| 270 if (info.Length() < 2) | 274 if (info.Length() < 2) |
| 271 arguments.push_back( | 275 arguments.push_back( |
| 272 toV8String(m_inspector->isolate(), String16("console.assert"))); | 276 toV8String(m_inspector->isolate(), String16("console.assert"))); |
| 273 helper.reportCall(ConsoleAPIType::kAssert, arguments); | 277 helper.reportCall(ConsoleAPIType::kAssert, arguments); |
| 274 | 278 |
| 279 // TODO(dgozman): only break once, not per each session. |
| 275 helper.forEachSession([](V8InspectorSessionImpl* session) { | 280 helper.forEachSession([](V8InspectorSessionImpl* session) { |
| 276 if (session->debuggerAgent()->enabled()) { | 281 if (session->debuggerAgent()->enabled()) { |
| 277 session->debuggerAgent()->breakProgramOnException( | 282 session->debuggerAgent()->breakProgramOnException( |
| 278 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); | 283 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); |
| 279 } | 284 } |
| 280 }); | 285 }); |
| 281 } | 286 } |
| 282 | 287 |
| 283 void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) { | 288 void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) { |
| 284 ConsoleHelper(info, m_inspector) | 289 ConsoleHelper(info, m_inspector) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 info.GetReturnValue().Set(memoryValue); | 374 info.GetReturnValue().Set(memoryValue); |
| 370 } | 375 } |
| 371 | 376 |
| 372 void V8Console::memorySetterCallback( | 377 void V8Console::memorySetterCallback( |
| 373 const v8::FunctionCallbackInfo<v8::Value>& info) { | 378 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 374 // We can't make the attribute readonly as it breaks existing code that relies | 379 // We can't make the attribute readonly as it breaks existing code that relies |
| 375 // on being able to assign to console.memory in strict mode. Instead, the | 380 // on being able to assign to console.memory in strict mode. Instead, the |
| 376 // setter just ignores the passed value. http://crbug.com/468611 | 381 // setter just ignores the passed value. http://crbug.com/468611 |
| 377 } | 382 } |
| 378 | 383 |
| 379 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 384 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 385 int sessionId) { |
| 380 v8::Isolate* isolate = info.GetIsolate(); | 386 v8::Isolate* isolate = info.GetIsolate(); |
| 381 info.GetReturnValue().Set(v8::Array::New(isolate)); | 387 info.GetReturnValue().Set(v8::Array::New(isolate)); |
| 382 | 388 |
| 383 v8::debug::ConsoleCallArguments args(info); | 389 v8::debug::ConsoleCallArguments args(info); |
| 384 ConsoleHelper helper(args, m_inspector); | 390 ConsoleHelper helper(args, m_inspector); |
| 385 v8::Local<v8::Object> obj; | 391 v8::Local<v8::Object> obj; |
| 386 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 392 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
| 387 v8::Local<v8::Array> names; | 393 v8::Local<v8::Array> names; |
| 388 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) | 394 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) |
| 389 return; | 395 return; |
| 390 info.GetReturnValue().Set(names); | 396 info.GetReturnValue().Set(names); |
| 391 } | 397 } |
| 392 | 398 |
| 393 void V8Console::valuesCallback( | 399 void V8Console::valuesCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 394 const v8::FunctionCallbackInfo<v8::Value>& info) { | 400 int sessionId) { |
| 395 v8::Isolate* isolate = info.GetIsolate(); | 401 v8::Isolate* isolate = info.GetIsolate(); |
| 396 info.GetReturnValue().Set(v8::Array::New(isolate)); | 402 info.GetReturnValue().Set(v8::Array::New(isolate)); |
| 397 | 403 |
| 398 v8::debug::ConsoleCallArguments args(info); | 404 v8::debug::ConsoleCallArguments args(info); |
| 399 ConsoleHelper helper(args, m_inspector); | 405 ConsoleHelper helper(args, m_inspector); |
| 400 v8::Local<v8::Object> obj; | 406 v8::Local<v8::Object> obj; |
| 401 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 407 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
| 402 v8::Local<v8::Array> names; | 408 v8::Local<v8::Array> names; |
| 403 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 409 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 404 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; | 410 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; |
| 405 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); | 411 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); |
| 406 for (uint32_t i = 0; i < names->Length(); ++i) { | 412 for (uint32_t i = 0; i < names->Length(); ++i) { |
| 407 v8::Local<v8::Value> key; | 413 v8::Local<v8::Value> key; |
| 408 if (!names->Get(context, i).ToLocal(&key)) continue; | 414 if (!names->Get(context, i).ToLocal(&key)) continue; |
| 409 v8::Local<v8::Value> value; | 415 v8::Local<v8::Value> value; |
| 410 if (!obj->Get(context, key).ToLocal(&value)) continue; | 416 if (!obj->Get(context, key).ToLocal(&value)) continue; |
| 411 createDataProperty(context, values, i, value); | 417 createDataProperty(context, values, i, value); |
| 412 } | 418 } |
| 413 info.GetReturnValue().Set(values); | 419 info.GetReturnValue().Set(values); |
| 414 } | 420 } |
| 415 | 421 |
| 416 static void setFunctionBreakpoint(ConsoleHelper& helper, | 422 static void setFunctionBreakpoint(ConsoleHelper& helper, int sessionId, |
| 417 v8::Local<v8::Function> function, | 423 v8::Local<v8::Function> function, |
| 418 V8DebuggerAgentImpl::BreakpointSource source, | 424 V8DebuggerAgentImpl::BreakpointSource source, |
| 419 const String16& condition, bool enable) { | 425 const String16& condition, bool enable) { |
| 420 String16 scriptId = String16::fromInteger(function->ScriptId()); | 426 String16 scriptId = String16::fromInteger(function->ScriptId()); |
| 421 int lineNumber = function->GetScriptLineNumber(); | 427 int lineNumber = function->GetScriptLineNumber(); |
| 422 int columnNumber = function->GetScriptColumnNumber(); | 428 int columnNumber = function->GetScriptColumnNumber(); |
| 423 if (lineNumber == v8::Function::kLineOffsetNotFound || | 429 if (lineNumber == v8::Function::kLineOffsetNotFound || |
| 424 columnNumber == v8::Function::kLineOffsetNotFound) | 430 columnNumber == v8::Function::kLineOffsetNotFound) |
| 425 return; | 431 return; |
| 426 | 432 |
| 427 helper.forEachSession([&enable, &scriptId, &lineNumber, &columnNumber, | 433 if (V8InspectorSessionImpl* session = helper.session(sessionId)) { |
| 428 &source, &condition](V8InspectorSessionImpl* session) { | |
| 429 if (!session->debuggerAgent()->enabled()) return; | 434 if (!session->debuggerAgent()->enabled()) return; |
| 430 if (enable) { | 435 if (enable) { |
| 431 session->debuggerAgent()->setBreakpointAt( | 436 session->debuggerAgent()->setBreakpointAt( |
| 432 scriptId, lineNumber, columnNumber, source, condition); | 437 scriptId, lineNumber, columnNumber, source, condition); |
| 433 } else { | 438 } else { |
| 434 session->debuggerAgent()->removeBreakpointAt(scriptId, lineNumber, | 439 session->debuggerAgent()->removeBreakpointAt(scriptId, lineNumber, |
| 435 columnNumber, source); | 440 columnNumber, source); |
| 436 } | 441 } |
| 437 }); | 442 } |
| 438 } | 443 } |
| 439 | 444 |
| 440 void V8Console::debugFunctionCallback( | 445 void V8Console::debugFunctionCallback( |
| 441 const v8::FunctionCallbackInfo<v8::Value>& info) { | 446 const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { |
| 442 v8::debug::ConsoleCallArguments args(info); | 447 v8::debug::ConsoleCallArguments args(info); |
| 443 ConsoleHelper helper(args, m_inspector); | 448 ConsoleHelper helper(args, m_inspector); |
| 444 v8::Local<v8::Function> function; | 449 v8::Local<v8::Function> function; |
| 445 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 450 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
| 446 setFunctionBreakpoint(helper, function, | 451 setFunctionBreakpoint(helper, sessionId, function, |
| 447 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 452 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
| 448 String16(), true); | 453 String16(), true); |
| 449 } | 454 } |
| 450 | 455 |
| 451 void V8Console::undebugFunctionCallback( | 456 void V8Console::undebugFunctionCallback( |
| 452 const v8::FunctionCallbackInfo<v8::Value>& info) { | 457 const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { |
| 453 v8::debug::ConsoleCallArguments args(info); | 458 v8::debug::ConsoleCallArguments args(info); |
| 454 ConsoleHelper helper(args, m_inspector); | 459 ConsoleHelper helper(args, m_inspector); |
| 455 v8::Local<v8::Function> function; | 460 v8::Local<v8::Function> function; |
| 456 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 461 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
| 457 setFunctionBreakpoint(helper, function, | 462 setFunctionBreakpoint(helper, sessionId, function, |
| 458 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 463 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
| 459 String16(), false); | 464 String16(), false); |
| 460 } | 465 } |
| 461 | 466 |
| 462 void V8Console::monitorFunctionCallback( | 467 void V8Console::monitorFunctionCallback( |
| 463 const v8::FunctionCallbackInfo<v8::Value>& info) { | 468 const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { |
| 464 v8::debug::ConsoleCallArguments args(info); | 469 v8::debug::ConsoleCallArguments args(info); |
| 465 ConsoleHelper helper(args, m_inspector); | 470 ConsoleHelper helper(args, m_inspector); |
| 466 v8::Local<v8::Function> function; | 471 v8::Local<v8::Function> function; |
| 467 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 472 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
| 468 v8::Local<v8::Value> name = function->GetName(); | 473 v8::Local<v8::Value> name = function->GetName(); |
| 469 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | 474 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) |
| 470 name = function->GetInferredName(); | 475 name = function->GetInferredName(); |
| 471 String16 functionName = toProtocolStringWithTypeCheck(name); | 476 String16 functionName = toProtocolStringWithTypeCheck(name); |
| 472 String16Builder builder; | 477 String16Builder builder; |
| 473 builder.append("console.log(\"function "); | 478 builder.append("console.log(\"function "); |
| 474 if (functionName.isEmpty()) | 479 if (functionName.isEmpty()) |
| 475 builder.append("(anonymous function)"); | 480 builder.append("(anonymous function)"); |
| 476 else | 481 else |
| 477 builder.append(functionName); | 482 builder.append(functionName); |
| 478 builder.append( | 483 builder.append( |
| 479 " called\" + (arguments.length > 0 ? \" with arguments: \" + " | 484 " called\" + (arguments.length > 0 ? \" with arguments: \" + " |
| 480 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); | 485 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); |
| 481 setFunctionBreakpoint(helper, function, | 486 setFunctionBreakpoint(helper, sessionId, function, |
| 482 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 487 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
| 483 builder.toString(), true); | 488 builder.toString(), true); |
| 484 } | 489 } |
| 485 | 490 |
| 486 void V8Console::unmonitorFunctionCallback( | 491 void V8Console::unmonitorFunctionCallback( |
| 487 const v8::FunctionCallbackInfo<v8::Value>& info) { | 492 const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { |
| 488 v8::debug::ConsoleCallArguments args(info); | 493 v8::debug::ConsoleCallArguments args(info); |
| 489 ConsoleHelper helper(args, m_inspector); | 494 ConsoleHelper helper(args, m_inspector); |
| 490 v8::Local<v8::Function> function; | 495 v8::Local<v8::Function> function; |
| 491 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 496 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
| 492 setFunctionBreakpoint(helper, function, | 497 setFunctionBreakpoint(helper, sessionId, function, |
| 493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 498 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
| 494 String16(), false); | 499 String16(), false); |
| 495 } | 500 } |
| 496 | 501 |
| 497 void V8Console::lastEvaluationResultCallback( | 502 void V8Console::lastEvaluationResultCallback( |
| 498 const v8::FunctionCallbackInfo<v8::Value>& info) { | 503 const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { |
| 499 v8::debug::ConsoleCallArguments args(info); | 504 v8::debug::ConsoleCallArguments args(info); |
| 500 ConsoleHelper helper(args, m_inspector); | 505 ConsoleHelper helper(args, m_inspector); |
| 501 InjectedScript* injectedScript = helper.injectedScript(); | 506 InjectedScript* injectedScript = helper.injectedScript(sessionId); |
| 502 if (!injectedScript) return; | 507 if (!injectedScript) return; |
| 503 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); | 508 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); |
| 504 } | 509 } |
| 505 | 510 |
| 506 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, | 511 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 507 bool copyToClipboard, V8InspectorImpl* inspector) { | 512 int sessionId, bool copyToClipboard, |
| 513 V8InspectorImpl* inspector) { |
| 508 if (info.Length() < 1) return; | 514 if (info.Length() < 1) return; |
| 509 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); | 515 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); |
| 510 | 516 |
| 511 v8::debug::ConsoleCallArguments args(info); | 517 v8::debug::ConsoleCallArguments args(info); |
| 512 ConsoleHelper helper(args, inspector); | 518 ConsoleHelper helper(args, inspector); |
| 513 InjectedScript* injectedScript = helper.injectedScript(); | 519 InjectedScript* injectedScript = helper.injectedScript(sessionId); |
| 514 if (!injectedScript) return; | 520 if (!injectedScript) return; |
| 515 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; | 521 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; |
| 516 protocol::Response response = | 522 protocol::Response response = |
| 517 injectedScript->wrapObject(info[0], "", false /** forceValueType */, | 523 injectedScript->wrapObject(info[0], "", false /** forceValueType */, |
| 518 false /** generatePreview */, &wrappedObject); | 524 false /** generatePreview */, &wrappedObject); |
| 519 if (!response.isSuccess()) return; | 525 if (!response.isSuccess()) return; |
| 520 | 526 |
| 521 std::unique_ptr<protocol::DictionaryValue> hints = | 527 std::unique_ptr<protocol::DictionaryValue> hints = |
| 522 protocol::DictionaryValue::create(); | 528 protocol::DictionaryValue::create(); |
| 523 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); | 529 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); |
| 524 helper.forEachSession( | 530 if (V8InspectorSessionImpl* session = helper.session(sessionId)) { |
| 525 [&wrappedObject, &hints](V8InspectorSessionImpl* session) { | 531 session->runtimeAgent()->inspect(std::move(wrappedObject), |
| 526 session->runtimeAgent()->inspect(std::move(wrappedObject), | 532 std::move(hints)); |
| 527 std::move(hints)); | 533 } |
| 528 }); | |
| 529 } | 534 } |
| 530 | 535 |
| 531 void V8Console::inspectCallback( | 536 void V8Console::inspectCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 532 const v8::FunctionCallbackInfo<v8::Value>& info) { | 537 int sessionId) { |
| 533 inspectImpl(info, false, m_inspector); | 538 inspectImpl(info, sessionId, false, m_inspector); |
| 534 } | 539 } |
| 535 | 540 |
| 536 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 541 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 537 inspectImpl(info, true, m_inspector); | 542 int sessionId) { |
| 543 inspectImpl(info, sessionId, true, m_inspector); |
| 538 } | 544 } |
| 539 | 545 |
| 540 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, | 546 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 541 unsigned num) { | 547 int sessionId, unsigned num) { |
| 542 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); | 548 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); |
| 543 v8::debug::ConsoleCallArguments args(info); | 549 v8::debug::ConsoleCallArguments args(info); |
| 544 ConsoleHelper helper(args, m_inspector); | 550 ConsoleHelper helper(args, m_inspector); |
| 545 helper.forEachSession([&info, &num](V8InspectorSessionImpl* session) { | 551 if (V8InspectorSessionImpl* session = helper.session(sessionId)) { |
| 546 V8InspectorSession::Inspectable* object = session->inspectedObject(num); | 552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); |
| 547 v8::Isolate* isolate = info.GetIsolate(); | 553 v8::Isolate* isolate = info.GetIsolate(); |
| 548 if (object) | 554 if (object) |
| 549 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); | 555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); |
| 550 else | 556 else |
| 551 info.GetReturnValue().Set(v8::Undefined(isolate)); | 557 info.GetReturnValue().Set(v8::Undefined(isolate)); |
| 552 }); | 558 } |
| 553 } | 559 } |
| 554 | 560 |
| 555 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, | 561 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, |
| 556 v8::Local<v8::Object> console) { | 562 v8::Local<v8::Object> console) { |
| 557 v8::Isolate* isolate = context->GetIsolate(); | 563 v8::Isolate* isolate = context->GetIsolate(); |
| 558 v8::Local<v8::External> data = v8::External::New(isolate, this); | 564 v8::Local<v8::External> data = v8::External::New(isolate, this); |
| 559 console->SetAccessorProperty( | 565 console->SetAccessorProperty( |
| 560 toV8StringInternalized(isolate, "memory"), | 566 toV8StringInternalized(isolate, "memory"), |
| 561 v8::Function::New(context, | 567 v8::Function::New(context, |
| 562 &V8Console::call<&V8Console::memoryGetterCallback>, | 568 &V8Console::call<&V8Console::memoryGetterCallback>, |
| 563 data, 0, v8::ConstructorBehavior::kThrow) | 569 data, 0, v8::ConstructorBehavior::kThrow) |
| 564 .ToLocalChecked(), | 570 .ToLocalChecked(), |
| 565 v8::Function::New(context, | 571 v8::Function::New(context, |
| 566 &V8Console::call<&V8Console::memorySetterCallback>, | 572 &V8Console::call<&V8Console::memorySetterCallback>, |
| 567 data, 0, v8::ConstructorBehavior::kThrow) | 573 data, 0, v8::ConstructorBehavior::kThrow) |
| 568 .ToLocalChecked(), | 574 .ToLocalChecked(), |
| 569 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); | 575 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); |
| 570 } | 576 } |
| 571 | 577 |
| 572 v8::Local<v8::Object> V8Console::createCommandLineAPI( | 578 v8::Local<v8::Object> V8Console::createCommandLineAPI( |
| 573 v8::Local<v8::Context> context) { | 579 v8::Local<v8::Context> context, int sessionId) { |
| 574 v8::Isolate* isolate = context->GetIsolate(); | 580 v8::Isolate* isolate = context->GetIsolate(); |
| 575 v8::MicrotasksScope microtasksScope(isolate, | 581 v8::MicrotasksScope microtasksScope(isolate, |
| 576 v8::MicrotasksScope::kDoNotRunMicrotasks); | 582 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 577 | 583 |
| 578 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); | 584 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); |
| 579 bool success = | 585 bool success = |
| 580 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); | 586 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); |
| 581 DCHECK(success); | 587 DCHECK(success); |
| 582 USE(success); | 588 USE(success); |
| 583 | 589 |
| 584 v8::Local<v8::External> data = v8::External::New(isolate, this); | 590 // TODO(dgozman): this CommandLineAPIData instance leaks. Use PodArray maybe? |
| 591 v8::Local<v8::External> data = |
| 592 v8::External::New(isolate, new CommandLineAPIData(this, sessionId)); |
| 585 createBoundFunctionProperty(context, commandLineAPI, data, "dir", | 593 createBoundFunctionProperty(context, commandLineAPI, data, "dir", |
| 586 &V8Console::call<&V8Console::Dir>, | 594 &V8Console::call<&V8Console::Dir>, |
| 587 "function dir(value) { [Command Line API] }"); | 595 "function dir(value) { [Command Line API] }"); |
| 588 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", | 596 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", |
| 589 &V8Console::call<&V8Console::DirXml>, | 597 &V8Console::call<&V8Console::DirXml>, |
| 590 "function dirxml(value) { [Command Line API] }"); | 598 "function dirxml(value) { [Command Line API] }"); |
| 591 createBoundFunctionProperty(context, commandLineAPI, data, "profile", | 599 createBoundFunctionProperty(context, commandLineAPI, data, "profile", |
| 592 &V8Console::call<&V8Console::Profile>, | 600 &V8Console::call<&V8Console::Profile>, |
| 593 "function profile(title) { [Command Line API] }"); | 601 "function profile(title) { [Command Line API] }"); |
| 594 createBoundFunctionProperty( | 602 createBoundFunctionProperty( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 ->GetOwnPropertyDescriptor( | 755 ->GetOwnPropertyDescriptor( |
| 748 m_context, v8::Local<v8::String>::Cast(name)) | 756 m_context, v8::Local<v8::String>::Cast(name)) |
| 749 .ToLocal(&descriptor); | 757 .ToLocal(&descriptor); |
| 750 DCHECK(success); | 758 DCHECK(success); |
| 751 USE(success); | 759 USE(success); |
| 752 } | 760 } |
| 753 } | 761 } |
| 754 } | 762 } |
| 755 | 763 |
| 756 } // namespace v8_inspector | 764 } // namespace v8_inspector |
| OLD | NEW |