Chromium Code Reviews| 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 (hadException || extension.IsEmpty() || !extension->IsObject()) { | |
| 390 *errorString = "Internal error"; | |
|
dgozman
2016/04/25 20:55:08
nit: hasInternalError
kozy
2016/04/25 21:33:58
Done.
| |
| 391 return v8::MaybeLocal<v8::Object>(); | |
| 392 } | |
| 393 m_commandLineAPI.Reset(isolate, extension.As<v8::Object>()); | |
| 394 } | |
| 395 return m_commandLineAPI.Get(m_context->isolate()); | |
| 396 } | |
| 397 | |
| 380 InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger, int contextGroupId) | 398 InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger, int contextGroupId) |
| 381 : m_errorString(errorString) | 399 : m_errorString(errorString) |
| 382 , m_debugger(debugger) | 400 , m_debugger(debugger) |
| 383 , m_contextGroupId(contextGroupId) | 401 , m_contextGroupId(contextGroupId) |
| 384 , m_injectedScript(nullptr) | 402 , m_injectedScript(nullptr) |
| 385 , m_handleScope(debugger->isolate()) | 403 , m_handleScope(debugger->isolate()) |
| 386 , m_tryCatch(debugger->isolate()) | 404 , m_tryCatch(debugger->isolate()) |
| 387 , m_ignoreExceptionsAndMuteConsole(false) | 405 , m_ignoreExceptionsAndMuteConsole(false) |
| 388 , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) | 406 , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) |
| 389 { | 407 { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 402 if (!m_injectedScript) | 420 if (!m_injectedScript) |
| 403 return false; | 421 return false; |
| 404 m_context = m_injectedScript->context()->context(); | 422 m_context = m_injectedScript->context()->context(); |
| 405 m_context->Enter(); | 423 m_context->Enter(); |
| 406 return true; | 424 return true; |
| 407 } | 425 } |
| 408 | 426 |
| 409 bool InjectedScript::Scope::installCommandLineAPI() | 427 bool InjectedScript::Scope::installCommandLineAPI() |
| 410 { | 428 { |
| 411 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 429 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 412 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "commandLineAPI"); | |
| 413 v8::Local<v8::Object> extensionObject; | 430 v8::Local<v8::Object> extensionObject; |
| 414 if (!installGlobalObjectExtension(function).ToLocal(&extensionObject)) | 431 if (!m_injectedScript->commandLineAPI(m_errorString).ToLocal(&extensionObjec t)) |
| 415 return false; | 432 return false; |
| 416 return extensionObject->Set(m_context, toV8StringInternalized(m_context->Get Isolate(), "$_"), m_injectedScript->lastEvaluationResult()).FromMaybe(false); | 433 return installGlobalObjectExtension(extensionObject); |
| 417 } | 434 } |
| 418 | 435 |
| 419 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa me) | 436 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa me) |
| 420 { | 437 { |
| 421 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 438 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 422 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "remoteObjectAPI"); | 439 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "remoteObjectAPI"); |
| 423 function.appendArgument(objectGroupName); | 440 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; | 441 bool hadException = false; |
| 431 v8::Local<v8::Value> extension = function.call(hadException, false); | 442 v8::Local<v8::Value> extension = function.call(hadException, false); |
| 432 if (hadException || extension.IsEmpty() || !extension->IsObject()) { | 443 if (hadException || extension.IsEmpty() || !extension->IsObject()) { |
| 433 *m_errorString = "Internal error"; | 444 *m_errorString = "Internal error"; |
| 434 return v8::MaybeLocal<v8::Object>(); | 445 return false; |
| 435 } | 446 } |
| 447 v8::Local<v8::Object> extensionObject = extension.As<v8::Object>(); | |
| 448 return installGlobalObjectExtension(extensionObject); | |
| 449 } | |
| 436 | 450 |
| 451 bool InjectedScript::Scope::installGlobalObjectExtension(v8::Local<v8::Object> e xtension) | |
| 452 { | |
| 437 ASSERT(m_global.IsEmpty()); | 453 ASSERT(m_global.IsEmpty()); |
| 438 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); | 454 m_extensionPrivate = V8Debugger::scopeExtensionPrivate(m_debugger->isolate() ); |
| 439 v8::Local<v8::Object> global = m_context->Global(); | 455 v8::Local<v8::Object> global = m_context->Global(); |
| 440 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false)) { | 456 if (!global->SetPrivate(m_context, m_extensionPrivate, extension).FromMaybe( false)) { |
| 441 *m_errorString = "Internal error"; | 457 *m_errorString = "Internal error"; |
| 442 return v8::MaybeLocal<v8::Object>(); | 458 return false; |
| 443 } | 459 } |
| 444 | |
| 445 m_global = global; | 460 m_global = global; |
| 446 return extension.As<v8::Object>(); | 461 return true; |
| 447 } | 462 } |
| 448 | 463 |
| 449 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() | 464 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() |
| 450 { | 465 { |
| 451 ASSERT(!m_ignoreExceptionsAndMuteConsole); | 466 ASSERT(!m_ignoreExceptionsAndMuteConsole); |
| 452 m_ignoreExceptionsAndMuteConsole = true; | 467 m_ignoreExceptionsAndMuteConsole = true; |
| 453 m_debugger->client()->muteConsole(); | 468 m_debugger->client()->muteConsole(); |
| 454 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl: :DontPauseOnExceptions); | 469 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl: :DontPauseOnExceptions); |
| 455 } | 470 } |
| 456 | 471 |
| 457 V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptio nsState(V8DebuggerImpl::PauseOnExceptionsState newState) | 472 V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptio nsState(V8DebuggerImpl::PauseOnExceptionsState newState) |
| 458 { | 473 { |
| 459 if (!m_debugger->enabled()) | 474 if (!m_debugger->enabled()) |
| 460 return newState; | 475 return newState; |
| 461 V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOn ExceptionsState(); | 476 V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOn ExceptionsState(); |
| 462 if (presentState != newState) | 477 if (presentState != newState) |
| 463 m_debugger->setPauseOnExceptionsState(newState); | 478 m_debugger->setPauseOnExceptionsState(newState); |
| 464 return presentState; | 479 return presentState; |
| 465 } | 480 } |
| 466 | 481 |
| 467 void InjectedScript::Scope::cleanup() | 482 void InjectedScript::Scope::cleanup() |
| 468 { | 483 { |
| 469 v8::Local<v8::Object> global; | 484 v8::Local<v8::Object> global; |
| 470 if (m_global.ToLocal(&global)) { | 485 if (m_global.ToLocal(&global)) { |
| 471 ASSERT(!m_context.IsEmpty()); | 486 ASSERT(!m_context.IsEmpty()); |
| 472 global->Delete(m_context, m_extensionSymbol); | 487 global->DeletePrivate(m_context, m_extensionPrivate); |
| 473 m_global = v8::MaybeLocal<v8::Object>(); | 488 m_global = v8::MaybeLocal<v8::Object>(); |
| 474 } | 489 } |
| 475 if (!m_context.IsEmpty()) { | 490 if (!m_context.IsEmpty()) { |
| 476 m_context->Exit(); | 491 m_context->Exit(); |
| 477 m_context.Clear(); | 492 m_context.Clear(); |
| 478 } | 493 } |
| 479 } | 494 } |
| 480 | 495 |
| 481 InjectedScript::Scope::~Scope() | 496 InjectedScript::Scope::~Scope() |
| 482 { | 497 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session) | 554 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session) |
| 540 { | 555 { |
| 541 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); | 556 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); |
| 542 if (!remoteId) | 557 if (!remoteId) |
| 543 return; | 558 return; |
| 544 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 559 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
| 545 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() ); | 560 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() ); |
| 546 } | 561 } |
| 547 | 562 |
| 548 } // namespace blink | 563 } // namespace blink |
| OLD | NEW |