| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "platform/inspector_protocol/Parser.h" | 33 #include "platform/inspector_protocol/Parser.h" |
| 34 #include "platform/inspector_protocol/String16.h" | 34 #include "platform/inspector_protocol/String16.h" |
| 35 #include "platform/inspector_protocol/Values.h" | 35 #include "platform/inspector_protocol/Values.h" |
| 36 #include "platform/v8_inspector/InjectedScriptHost.h" | 36 #include "platform/v8_inspector/InjectedScriptHost.h" |
| 37 #include "platform/v8_inspector/InjectedScriptNative.h" | 37 #include "platform/v8_inspector/InjectedScriptNative.h" |
| 38 #include "platform/v8_inspector/InjectedScriptSource.h" | 38 #include "platform/v8_inspector/InjectedScriptSource.h" |
| 39 #include "platform/v8_inspector/InspectedContext.h" | 39 #include "platform/v8_inspector/InspectedContext.h" |
| 40 #include "platform/v8_inspector/RemoteObjectId.h" | 40 #include "platform/v8_inspector/RemoteObjectId.h" |
| 41 #include "platform/v8_inspector/V8Compat.h" | 41 #include "platform/v8_inspector/V8Compat.h" |
| 42 #include "platform/v8_inspector/V8Console.h" |
| 42 #include "platform/v8_inspector/V8DebuggerImpl.h" | 43 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 43 #include "platform/v8_inspector/V8FunctionCall.h" | 44 #include "platform/v8_inspector/V8FunctionCall.h" |
| 44 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 45 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 45 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 46 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 46 #include "platform/v8_inspector/V8StackTraceImpl.h" | 47 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 47 #include "platform/v8_inspector/V8StringUtil.h" | 48 #include "platform/v8_inspector/V8StringUtil.h" |
| 48 #include "platform/v8_inspector/public/V8Debugger.h" | 49 #include "platform/v8_inspector/public/V8Debugger.h" |
| 49 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 50 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 50 #include "platform/v8_inspector/public/V8ToProtocolValue.h" | 51 #include "platform/v8_inspector/public/V8ToProtocolValue.h" |
| 51 | 52 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 if (!remoteObject) | 371 if (!remoteObject) |
| 371 return; | 372 return; |
| 372 *result = remoteObject.release(); | 373 *result = remoteObject.release(); |
| 373 if (exceptionDetails) | 374 if (exceptionDetails) |
| 374 *exceptionDetails = createExceptionDetails(tryCatch.Message()); | 375 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
| 375 if (wasThrown) | 376 if (wasThrown) |
| 376 *wasThrown = true; | 377 *wasThrown = true; |
| 377 } | 378 } |
| 378 } | 379 } |
| 379 | 380 |
| 381 v8::MaybeLocal<v8::Object> InjectedScript::commandLineAPI(ErrorString* errorStri
ng) |
| 382 { |
| 383 v8::Isolate* isolate = m_context->isolate(); |
| 384 if (m_commandLineAPI.IsEmpty()) { |
| 385 V8FunctionCall function(m_context->debugger(), m_context->context(), v8V
alue(), "installCommandLineAPI"); |
| 386 function.appendArgument(V8Console::createCommandLineAPI(m_context)); |
| 387 bool hadException = false; |
| 388 v8::Local<v8::Value> extension = function.call(hadException, false); |
| 389 if (hasInternalError(errorString, hadException || extension.IsEmpty() ||
!extension->IsObject())) |
| 390 return v8::MaybeLocal<v8::Object>(); |
| 391 m_commandLineAPI.Reset(isolate, extension.As<v8::Object>()); |
| 392 } |
| 393 return m_commandLineAPI.Get(m_context->isolate()); |
| 394 } |
| 395 |
| 380 InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger,
int contextGroupId) | 396 InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger,
int contextGroupId) |
| 381 : m_errorString(errorString) | 397 : m_errorString(errorString) |
| 382 , m_debugger(debugger) | 398 , m_debugger(debugger) |
| 383 , m_contextGroupId(contextGroupId) | 399 , m_contextGroupId(contextGroupId) |
| 384 , m_injectedScript(nullptr) | 400 , m_injectedScript(nullptr) |
| 385 , m_handleScope(debugger->isolate()) | 401 , m_handleScope(debugger->isolate()) |
| 386 , m_tryCatch(debugger->isolate()) | 402 , m_tryCatch(debugger->isolate()) |
| 387 , m_ignoreExceptionsAndMuteConsole(false) | 403 , m_ignoreExceptionsAndMuteConsole(false) |
| 388 , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) | 404 , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) |
| 389 { | 405 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 402 if (!m_injectedScript) | 418 if (!m_injectedScript) |
| 403 return false; | 419 return false; |
| 404 m_context = m_injectedScript->context()->context(); | 420 m_context = m_injectedScript->context()->context(); |
| 405 m_context->Enter(); | 421 m_context->Enter(); |
| 406 return true; | 422 return true; |
| 407 } | 423 } |
| 408 | 424 |
| 409 bool InjectedScript::Scope::installCommandLineAPI() | 425 bool InjectedScript::Scope::installCommandLineAPI() |
| 410 { | 426 { |
| 411 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 427 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 412 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"commandLineAPI"); | |
| 413 v8::Local<v8::Object> extensionObject; | 428 v8::Local<v8::Object> extensionObject; |
| 414 if (!installGlobalObjectExtension(function).ToLocal(&extensionObject)) | 429 if (!m_injectedScript->commandLineAPI(m_errorString).ToLocal(&extensionObjec
t)) |
| 415 return false; | 430 return false; |
| 416 return extensionObject->Set(m_context, toV8StringInternalized(m_context->Get
Isolate(), "$_"), m_injectedScript->lastEvaluationResult()).FromMaybe(false); | 431 return installGlobalObjectExtension(extensionObject); |
| 417 } | 432 } |
| 418 | 433 |
| 419 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa
me) | 434 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa
me) |
| 420 { | 435 { |
| 421 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 436 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 422 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"remoteObjectAPI"); | 437 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"remoteObjectAPI"); |
| 423 function.appendArgument(objectGroupName); | 438 function.appendArgument(objectGroupName); |
| 424 v8::Local<v8::Object> extensionObject; | |
| 425 return installGlobalObjectExtension(function).ToLocal(&extensionObject); | |
| 426 } | |
| 427 | |
| 428 v8::MaybeLocal<v8::Object> InjectedScript::Scope::installGlobalObjectExtension(V
8FunctionCall& function) | |
| 429 { | |
| 430 bool hadException = false; | 439 bool hadException = false; |
| 431 v8::Local<v8::Value> extension = function.call(hadException, false); | 440 v8::Local<v8::Value> extension = function.call(hadException, false); |
| 432 if (hadException || extension.IsEmpty() || !extension->IsObject()) { | 441 if (hadException || extension.IsEmpty() || !extension->IsObject()) { |
| 433 *m_errorString = "Internal error"; | 442 *m_errorString = "Internal error"; |
| 434 return v8::MaybeLocal<v8::Object>(); | 443 return false; |
| 435 } | 444 } |
| 445 v8::Local<v8::Object> extensionObject = extension.As<v8::Object>(); |
| 446 return installGlobalObjectExtension(extensionObject); |
| 447 } |
| 436 | 448 |
| 449 bool InjectedScript::Scope::installGlobalObjectExtension(v8::Local<v8::Object> e
xtension) |
| 450 { |
| 437 ASSERT(m_global.IsEmpty()); | 451 ASSERT(m_global.IsEmpty()); |
| 438 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); | 452 m_extensionPrivate = V8Debugger::scopeExtensionPrivate(m_debugger->isolate()
); |
| 439 v8::Local<v8::Object> global = m_context->Global(); | 453 v8::Local<v8::Object> global = m_context->Global(); |
| 440 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false))
{ | 454 if (!global->SetPrivate(m_context, m_extensionPrivate, extension).FromMaybe(
false)) { |
| 441 *m_errorString = "Internal error"; | 455 *m_errorString = "Internal error"; |
| 442 return v8::MaybeLocal<v8::Object>(); | 456 return false; |
| 443 } | 457 } |
| 444 | |
| 445 m_global = global; | 458 m_global = global; |
| 446 return extension.As<v8::Object>(); | 459 return true; |
| 447 } | 460 } |
| 448 | 461 |
| 449 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() | 462 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() |
| 450 { | 463 { |
| 451 ASSERT(!m_ignoreExceptionsAndMuteConsole); | 464 ASSERT(!m_ignoreExceptionsAndMuteConsole); |
| 452 m_ignoreExceptionsAndMuteConsole = true; | 465 m_ignoreExceptionsAndMuteConsole = true; |
| 453 m_debugger->client()->muteConsole(); | 466 m_debugger->client()->muteConsole(); |
| 454 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl:
:DontPauseOnExceptions); | 467 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl:
:DontPauseOnExceptions); |
| 455 } | 468 } |
| 456 | 469 |
| 457 V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptio
nsState(V8DebuggerImpl::PauseOnExceptionsState newState) | 470 V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptio
nsState(V8DebuggerImpl::PauseOnExceptionsState newState) |
| 458 { | 471 { |
| 459 if (!m_debugger->enabled()) | 472 if (!m_debugger->enabled()) |
| 460 return newState; | 473 return newState; |
| 461 V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOn
ExceptionsState(); | 474 V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOn
ExceptionsState(); |
| 462 if (presentState != newState) | 475 if (presentState != newState) |
| 463 m_debugger->setPauseOnExceptionsState(newState); | 476 m_debugger->setPauseOnExceptionsState(newState); |
| 464 return presentState; | 477 return presentState; |
| 465 } | 478 } |
| 466 | 479 |
| 467 void InjectedScript::Scope::cleanup() | 480 void InjectedScript::Scope::cleanup() |
| 468 { | 481 { |
| 469 v8::Local<v8::Object> global; | 482 v8::Local<v8::Object> global; |
| 470 if (m_global.ToLocal(&global)) { | 483 if (m_global.ToLocal(&global)) { |
| 471 ASSERT(!m_context.IsEmpty()); | 484 ASSERT(!m_context.IsEmpty()); |
| 472 global->Delete(m_context, m_extensionSymbol); | 485 global->DeletePrivate(m_context, m_extensionPrivate); |
| 473 m_global = v8::MaybeLocal<v8::Object>(); | 486 m_global = v8::MaybeLocal<v8::Object>(); |
| 474 } | 487 } |
| 475 if (!m_context.IsEmpty()) { | 488 if (!m_context.IsEmpty()) { |
| 476 m_context->Exit(); | 489 m_context->Exit(); |
| 477 m_context.Clear(); | 490 m_context.Clear(); |
| 478 } | 491 } |
| 479 } | 492 } |
| 480 | 493 |
| 481 InjectedScript::Scope::~Scope() | 494 InjectedScript::Scope::~Scope() |
| 482 { | 495 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) | 552 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) |
| 540 { | 553 { |
| 541 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString,
m_remoteCallFrameId); | 554 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString,
m_remoteCallFrameId); |
| 542 if (!remoteId) | 555 if (!remoteId) |
| 543 return; | 556 return; |
| 544 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 557 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
| 545 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); | 558 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); |
| 546 } | 559 } |
| 547 | 560 |
| 548 } // namespace blink | 561 } // namespace blink |
| OLD | NEW |