From ff9773576b5d1c78ec942d9d737ab70780965f08 Mon Sep 17 00:00:00 2001 From: dgozman Date: Wed, 13 Apr 2016 15:43:22 -0700 Subject: [PATCH] [DevTools] Follow up with cleanups for InjectedScript::Scope. BUG=none TBR=pfeldman@chromium.org Review URL: https://codereview.chromium.org/1877203004 Cr-Commit-Position: refs/heads/master@{#387135} --- .../Source/platform/blink_platform.gypi | 2 - .../v8_inspector/IgnoreExceptionsScope.h | 46 -------- .../platform/v8_inspector/InjectedScript.cpp | 108 +++++++++++------- .../platform/v8_inspector/InjectedScript.h | 27 +++-- .../platform/v8_inspector/MuteConsoleScope.h | 36 ------ .../v8_inspector/V8DebuggerAgentImpl.cpp | 40 +++---- .../v8_inspector/V8RuntimeAgentImpl.cpp | 38 ++---- 7 files changed, 105 insertions(+), 192 deletions(-) delete mode 100644 third_party/WebKit/Source/platform/v8_inspector/IgnoreExceptionsScope.h delete mode 100644 third_party/WebKit/Source/platform/v8_inspector/MuteConsoleScope.h diff --git a/third_party/WebKit/Source/platform/blink_platform.gypi b/third_party/WebKit/Source/platform/blink_platform.gypi index 5c6c7b9ffc0136..db7e83b15f626c 100644 --- a/third_party/WebKit/Source/platform/blink_platform.gypi +++ b/third_party/WebKit/Source/platform/blink_platform.gypi @@ -1040,7 +1040,6 @@ 'v8_inspector/Atomics.h', 'v8_inspector/InspectorWrapper.cpp', 'v8_inspector/InspectorWrapper.h', - 'v8_inspector/IgnoreExceptionsScope.h', 'v8_inspector/InjectedScript.cpp', 'v8_inspector/InjectedScript.h', 'v8_inspector/InjectedScriptNative.cpp', @@ -1051,7 +1050,6 @@ 'v8_inspector/InspectedContext.h', 'v8_inspector/JavaScriptCallFrame.cpp', 'v8_inspector/JavaScriptCallFrame.h', - 'v8_inspector/MuteConsoleScope.h', 'v8_inspector/ScriptBreakpoint.h', 'v8_inspector/RemoteObjectId.cpp', 'v8_inspector/RemoteObjectId.h', diff --git a/third_party/WebKit/Source/platform/v8_inspector/IgnoreExceptionsScope.h b/third_party/WebKit/Source/platform/v8_inspector/IgnoreExceptionsScope.h deleted file mode 100644 index 5b3f1517944e1d..00000000000000 --- a/third_party/WebKit/Source/platform/v8_inspector/IgnoreExceptionsScope.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef IgnoreExceptionsScope_h -#define IgnoreExceptionsScope_h - -#include "platform/inspector_protocol/Allocator.h" -#include "platform/v8_inspector/V8DebuggerImpl.h" -#include "wtf/OwnPtr.h" - -namespace blink { - -class IgnoreExceptionsScope { - PROTOCOL_DISALLOW_COPY(IgnoreExceptionsScope); -public: - explicit IgnoreExceptionsScope(V8DebuggerImpl* debugger) - : m_debugger(debugger) - , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) - { - m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions); - } - - ~IgnoreExceptionsScope() - { - setPauseOnExceptionsState(m_previousPauseOnExceptionsState); - } - -private: - V8DebuggerImpl::PauseOnExceptionsState setPauseOnExceptionsState(V8DebuggerImpl::PauseOnExceptionsState newState) - { - if (!m_debugger || !m_debugger->enabled()) - return newState; - V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOnExceptionsState(); - if (presentState != newState) - m_debugger->setPauseOnExceptionsState(newState); - return presentState; - } - - V8DebuggerImpl* m_debugger; - V8DebuggerImpl::PauseOnExceptionsState m_previousPauseOnExceptionsState; -}; - -} // namespace blink - -#endif // IgnoreExceptionsScope_h diff --git a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp index 88f8d25ba6ace5..395c11b7e68d8f 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp @@ -121,14 +121,9 @@ InjectedScript::~InjectedScript() { } -v8::Isolate* InjectedScript::isolate() const -{ - return m_context->isolate(); -} - void InjectedScript::getProperties(ErrorString* errorString, v8::Local object, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnPtr>* properties, Maybe* exceptionDetails) { - v8::HandleScope handles(isolate()); + v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "getProperties"); function.appendArgument(object); function.appendArgument(groupName); @@ -136,7 +131,7 @@ void InjectedScript::getProperties(ErrorString* errorString, v8::Localisolate()); v8::Local resultValue = function.callWithoutExceptionHandling(); if (tryCatch.HasCaught()) { *exceptionDetails = createExceptionDetails(tryCatch.Message()); @@ -170,7 +165,7 @@ void InjectedScript::releaseObject(const String16& objectId) PassOwnPtr InjectedScript::wrapObject(ErrorString* errorString, v8::Local value, const String16& groupName, bool forceValueType, bool generatePreview) const { - v8::HandleScope handles(isolate()); + v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "wrapObject"); v8::Local wrappedObject; if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview).ToLocal(&wrappedObject)) @@ -240,7 +235,7 @@ v8::MaybeLocal InjectedScript::wrapValue(ErrorString* errorString, v8 PassOwnPtr InjectedScript::wrapTable(v8::Local table, v8::Local columns) const { - v8::HandleScope handles(isolate()); + v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "wrapTable"); function.appendArgument(canAccessInspectedWindow()); function.appendArgument(table); @@ -271,7 +266,7 @@ String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const void InjectedScript::releaseObjectGroup(const String16& objectGroup) { - v8::HandleScope handles(isolate()); + v8::HandleScope handles(m_context->isolate()); m_native->releaseObjectGroup(objectGroup); if (objectGroup == "console") { V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "clearLastEvaluationResult"); @@ -283,7 +278,7 @@ void InjectedScript::releaseObjectGroup(const String16& objectGroup) void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) { - v8::HandleScope handles(isolate()); + v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "setCustomObjectFormatterEnabled"); function.appendArgument(enabled); bool hadException = false; @@ -293,7 +288,7 @@ void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) bool InjectedScript::canAccessInspectedWindow() const { - v8::Local callingContext = isolate()->GetCallingContext(); + v8::Local callingContext = m_context->isolate()->GetCallingContext(); if (callingContext.IsEmpty()) return true; return m_context->debugger()->client()->callingContextCanAccessContext(callingContext, m_context->context()); @@ -301,7 +296,7 @@ bool InjectedScript::canAccessInspectedWindow() const v8::Local InjectedScript::v8Value() const { - return m_value.Get(isolate()); + return m_value.Get(m_context->isolate()); } bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local value) @@ -333,36 +328,13 @@ v8::MaybeLocal InjectedScript::resolveCallArgument(ErrorString* error if (callArgument->getType(String16()) == "number") value = "Number(" + value + ")"; v8::Local object; - if (!m_context->debugger()->compileAndRunInternalScript(m_context->context(), toV8String(isolate(), value)).ToLocal(&object)) { + if (!m_context->debugger()->compileAndRunInternalScript(m_context->context(), toV8String(m_context->isolate(), value)).ToLocal(&object)) { *errorString = "Couldn't parse value object in call argument"; return v8::MaybeLocal(); } return object; } - return v8::Undefined(isolate()); -} - -v8::MaybeLocal InjectedScript::commandLineAPI(ErrorString* errorString) const -{ - V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "commandLineAPI"); - return callFunctionReturnObject(errorString, function); -} - -v8::MaybeLocal InjectedScript::remoteObjectAPI(ErrorString* errorString, const String16& groupName) const -{ - V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "remoteObjectAPI"); - function.appendArgument(groupName); - return callFunctionReturnObject(errorString, function); -} - -v8::MaybeLocal InjectedScript::callFunctionReturnObject(ErrorString* errorString, V8FunctionCall& function) const -{ - bool hadException = false; - v8::Local result = function.call(hadException, false); - v8::Local resultObject; - if (hasInternalError(errorString, hadException || result.IsEmpty() || !result->ToObject(m_context->context()).ToLocal(&resultObject))) - return v8::MaybeLocal(); - return resultObject; + return v8::Undefined(m_context->isolate()); } PassOwnPtr InjectedScript::createExceptionDetails(v8::Local message) @@ -418,6 +390,8 @@ InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger, , m_injectedScript(nullptr) , m_handleScope(debugger->isolate()) , m_tryCatch(debugger->isolate()) + , m_ignoreExceptionsAndMuteConsole(false) + , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) { } @@ -438,16 +412,58 @@ bool InjectedScript::Scope::initialize() return true; } -void InjectedScript::Scope::installGlobalObjectExtension(v8::MaybeLocal extension) +bool InjectedScript::Scope::installCommandLineAPI() { - v8::Local extensionObject; - if (m_context.IsEmpty() || !extension.ToLocal(&extensionObject)) - return; + ASSERT(m_injectedScript && !m_context.IsEmpty()); + V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "commandLineAPI"); + return installGlobalObjectExtension(function); +} + +bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupName) +{ + ASSERT(m_injectedScript && !m_context.IsEmpty()); + V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "remoteObjectAPI"); + function.appendArgument(objectGroupName); + return installGlobalObjectExtension(function); +} +bool InjectedScript::Scope::installGlobalObjectExtension(V8FunctionCall& function) +{ + bool hadException = false; + v8::Local extension = function.call(hadException, false); + if (hadException || extension.IsEmpty()) { + *m_errorString = "Internal error"; + return false; + } + + ASSERT(m_global.IsEmpty()); m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); v8::Local global = m_context->Global(); - if (global->Set(m_context, m_extensionSymbol, extensionObject).FromMaybe(false)) - m_global = global; + if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false)) { + *m_errorString = "Internal error"; + return false; + } + + m_global = global; + return true; +} + +void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() +{ + ASSERT(!m_ignoreExceptionsAndMuteConsole); + m_ignoreExceptionsAndMuteConsole = true; + m_debugger->client()->muteConsole(); + m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions); +} + +V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptionsState(V8DebuggerImpl::PauseOnExceptionsState newState) +{ + if (!m_debugger->enabled()) + return newState; + V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOnExceptionsState(); + if (presentState != newState) + m_debugger->setPauseOnExceptionsState(newState); + return presentState; } void InjectedScript::Scope::cleanup() @@ -466,6 +482,10 @@ void InjectedScript::Scope::cleanup() InjectedScript::Scope::~Scope() { + if (m_ignoreExceptionsAndMuteConsole) { + setPauseOnExceptionsState(m_previousPauseOnExceptionsState); + m_debugger->client()->unmuteConsole(); + } cleanup(); } diff --git a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.h b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.h index 0033b56d8d69aa..e05aa97ac1c500 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.h +++ b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.h @@ -35,6 +35,7 @@ #include "platform/inspector_protocol/TypeBuilder.h" #include "platform/v8_inspector/InjectedScriptNative.h" #include "platform/v8_inspector/InspectedContext.h" +#include "platform/v8_inspector/V8DebuggerImpl.h" #include "wtf/PassOwnPtr.h" #include @@ -58,6 +59,8 @@ class InjectedScript final { static PassOwnPtr create(InspectedContext*, InjectedScriptHost*); ~InjectedScript(); + InspectedContext* context() const { return m_context; } + void getProperties(ErrorString*, v8::Local, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnPtr>* result, Maybe*); void releaseObject(const String16& objectId); @@ -65,24 +68,14 @@ class InjectedScript final { bool wrapObjectProperty(ErrorString*, v8::Local, v8::Local key, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const; bool wrapPropertyInArray(ErrorString*, v8::Local, v8::Local property, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const; bool wrapObjectsInArray(ErrorString*, v8::Local, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const; - PassOwnPtr wrapTable(v8::Local table, v8::Local columns) const; + bool findObject(ErrorString*, const RemoteObjectId&, v8::Local*) const; String16 objectGroupName(const RemoteObjectId&) const; void releaseObjectGroup(const String16&); - void setCustomObjectFormatterEnabled(bool); - - InspectedContext* context() const { return m_context; } - v8::Isolate* isolate() const; - bool canAccessInspectedWindow() const; - - bool setLastEvaluationResult(ErrorString*, v8::Local); v8::MaybeLocal resolveCallArgument(ErrorString*, protocol::Runtime::CallArgument*); - v8::MaybeLocal commandLineAPI(ErrorString*) const; - v8::MaybeLocal remoteObjectAPI(ErrorString*, const String16& groupName) const; - PassOwnPtr createExceptionDetails(v8::Local); void wrapEvaluateResult(ErrorString*, v8::MaybeLocal maybeResultValue, @@ -97,7 +90,9 @@ class InjectedScript final { class Scope { public: bool initialize(); - void installGlobalObjectExtension(v8::MaybeLocal extension); + bool installCommandLineAPI(); + bool installRemoteObjectAPI(const String16& objectGroupName); + void ignoreExceptionsAndMuteConsole(); v8::Local context() const { return m_context; } InjectedScript* injectedScript() const { return m_injectedScript; } const v8::TryCatch& tryCatch() const { return m_tryCatch; } @@ -114,12 +109,16 @@ class InjectedScript final { private: void cleanup(); + V8DebuggerImpl::PauseOnExceptionsState setPauseOnExceptionsState(V8DebuggerImpl::PauseOnExceptionsState); + bool installGlobalObjectExtension(V8FunctionCall&); v8::HandleScope m_handleScope; v8::TryCatch m_tryCatch; v8::Local m_context; v8::Local m_extensionSymbol; v8::MaybeLocal m_global; + bool m_ignoreExceptionsAndMuteConsole; + V8DebuggerImpl::PauseOnExceptionsState m_previousPauseOnExceptionsState; }; class ContextScope: public Scope { @@ -160,10 +159,10 @@ class InjectedScript final { private: InjectedScript(InspectedContext*, v8::Local, PassOwnPtr); - + bool canAccessInspectedWindow() const; + bool setLastEvaluationResult(ErrorString*, v8::Local); v8::Local v8Value() const; v8::MaybeLocal wrapValue(ErrorString*, v8::Local, const String16& groupName, bool forceValueType, bool generatePreview) const; - v8::MaybeLocal callFunctionReturnObject(ErrorString*, V8FunctionCall&) const; InspectedContext* m_context; v8::Global m_value; diff --git a/third_party/WebKit/Source/platform/v8_inspector/MuteConsoleScope.h b/third_party/WebKit/Source/platform/v8_inspector/MuteConsoleScope.h deleted file mode 100644 index 31fa4194d1aac9..00000000000000 --- a/third_party/WebKit/Source/platform/v8_inspector/MuteConsoleScope.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MuteConsoleScope_h -#define MuteConsoleScope_h - -#include "platform/inspector_protocol/Allocator.h" -#include "platform/v8_inspector/V8DebuggerImpl.h" -#include "platform/v8_inspector/public/V8DebuggerClient.h" - -namespace blink { - -class MuteConsoleScope { - PROTOCOL_DISALLOW_COPY(MuteConsoleScope); -public: - explicit MuteConsoleScope(V8DebuggerImpl* debugger) - : m_debugger(debugger) - { - if (m_debugger) - m_debugger->client()->muteConsole(); - } - - ~MuteConsoleScope() - { - if (m_debugger) - m_debugger->client()->unmuteConsole(); - } - -private: - V8DebuggerImpl* m_debugger; -}; - -} // namespace blink - -#endif // MuteConsoleScope_h diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp index 7e0bbe6e84b2d4..5ae6ce42f24f9f 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp @@ -6,11 +6,9 @@ #include "platform/inspector_protocol/String16.h" #include "platform/inspector_protocol/Values.h" -#include "platform/v8_inspector/IgnoreExceptionsScope.h" #include "platform/v8_inspector/InjectedScript.h" #include "platform/v8_inspector/InspectedContext.h" #include "platform/v8_inspector/JavaScriptCallFrame.h" -#include "platform/v8_inspector/MuteConsoleScope.h" #include "platform/v8_inspector/RemoteObjectId.h" #include "platform/v8_inspector/ScriptBreakpoint.h" #include "platform/v8_inspector/V8InspectorSessionImpl.h" @@ -677,7 +675,7 @@ void V8DebuggerAgentImpl::getFunctionDetails(ErrorString* errorString, const Str v8::Local scopes; if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValue->IsArray()) { scopes = scopesValue.As(); - if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, toV8StringInternalized(m_debugger->isolate(), "object"), scope.objectGroupName())) + if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, toV8StringInternalized(m_isolate, "object"), scope.objectGroupName())) return; } @@ -748,9 +746,9 @@ void V8DebuggerAgentImpl::getCollectionEntries(ErrorString* errorString, const S if (hasInternalError(errorString, !entriesValue->IsArray())) return; v8::Local entriesArray = entriesValue.As(); - if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_debugger->isolate(), "key"), scope.objectGroupName())) + if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_isolate, "key"), scope.objectGroupName())) return; - if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_debugger->isolate(), "value"), scope.objectGroupName())) + if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_isolate, "value"), scope.objectGroupName())) return; protocol::ErrorSupport errors; OwnPtr> entries = protocol::Array::parse(toProtocolValue(scope.context(), entriesArray).get(), &errors); @@ -923,17 +921,12 @@ void V8DebuggerAgentImpl::evaluateOnCallFrame(ErrorString* errorString, return; } - if (includeCommandLineAPI.fromMaybe(false)) { - v8::MaybeLocal commandLineAPI = scope.injectedScript()->commandLineAPI(errorString); - if (commandLineAPI.IsEmpty()) - return; - scope.installGlobalObjectExtension(commandLineAPI); - } - - IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); - MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); + if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()) + return; + if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) + scope.ignoreExceptionsAndMuteConsole(); - v8::MaybeLocal maybeResultValue = m_pausedCallFrames[scope.frameOrdinal()].get()->evaluate(toV8String(m_debugger->isolate(), expression)); + v8::MaybeLocal maybeResultValue = m_pausedCallFrames[scope.frameOrdinal()].get()->evaluate(toV8String(m_isolate, expression)); // Re-initialize after running client's code, as it could have destroyed context or session. if (!scope.initialize()) @@ -1156,12 +1149,11 @@ PassOwnPtr> V8DebuggerAgentImpl::currentCallFrames(ErrorString* return Array::create(); } - v8::Isolate* isolate = topFrameInjectedScript->isolate(); - v8::HandleScope handles(isolate); + v8::HandleScope handles(m_isolate); v8::Local context = topFrameInjectedScript->context()->context(); v8::Context::Scope contextScope(context); - v8::Local objects = v8::Array::New(isolate); + v8::Local objects = v8::Array::New(m_isolate); for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++frameOrdinal) { JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal].get(); @@ -1175,21 +1167,21 @@ PassOwnPtr> V8DebuggerAgentImpl::currentCallFrames(ErrorString* injectedScript = topFrameInjectedScript; String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->context()->contextId(), frameOrdinal); - if (hasInternalError(errorString, !details->Set(context, toV8StringInternalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(false))) + if (hasInternalError(errorString, !details->Set(context, toV8StringInternalized(m_isolate, "callFrameId"), toV8String(m_isolate, callFrameId)).FromMaybe(false))) return Array::create(); v8::Local scopeChain; - if (hasInternalError(errorString, !details->Get(context, toV8StringInternalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray())) + if (hasInternalError(errorString, !details->Get(context, toV8StringInternalized(m_isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray())) return Array::create(); v8::Local scopeChainArray = scopeChain.As(); - if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, toV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGroup)) + if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, toV8StringInternalized(m_isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGroup)) return Array::create(); - if (!injectedScript->wrapObjectProperty(errorString, details, toV8StringInternalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) + if (!injectedScript->wrapObjectProperty(errorString, details, toV8StringInternalized(m_isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) return Array::create(); - if (details->Has(context, toV8StringInternalized(isolate, "returnValue")).FromMaybe(false)) { - if (!injectedScript->wrapObjectProperty(errorString, details, toV8StringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGroup)) + if (details->Has(context, toV8StringInternalized(m_isolate, "returnValue")).FromMaybe(false)) { + if (!injectedScript->wrapObjectProperty(errorString, details, toV8StringInternalized(m_isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGroup)) return Array::create(); } diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp index cf359432dd797a..d1b70a436e7ba1 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp @@ -31,10 +31,8 @@ #include "platform/v8_inspector/V8RuntimeAgentImpl.h" #include "platform/inspector_protocol/Values.h" -#include "platform/v8_inspector/IgnoreExceptionsScope.h" #include "platform/v8_inspector/InjectedScript.h" #include "platform/v8_inspector/InspectedContext.h" -#include "platform/v8_inspector/MuteConsoleScope.h" #include "platform/v8_inspector/RemoteObjectId.h" #include "platform/v8_inspector/V8DebuggerImpl.h" #include "platform/v8_inspector/V8InspectorSessionImpl.h" @@ -99,15 +97,11 @@ void V8RuntimeAgentImpl::evaluate( if (!scope.initialize()) return; - IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); - MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); + if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) + scope.ignoreExceptionsAndMuteConsole(); - if (includeCommandLineAPI.fromMaybe(false)) { - v8::MaybeLocal commandLineAPI = scope.injectedScript()->commandLineAPI(errorString); - if (commandLineAPI.IsEmpty()) - return; - scope.installGlobalObjectExtension(commandLineAPI); - } + if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()) + return; bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed(); // Temporarily enable allow evals for inspector. @@ -160,8 +154,8 @@ void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, } } - IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); - MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); + if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) + scope.ignoreExceptionsAndMuteConsole(); v8::MaybeLocal maybeFunctionValue = m_debugger->compileAndRunInternalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression + ")")); // Re-initialize after running client's code, as it could have destroyed context or session. @@ -179,10 +173,8 @@ void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, return; } - v8::MaybeLocal remoteObjectAPI = scope.injectedScript()->remoteObjectAPI(errorString, scope.objectGroupName()); - if (remoteObjectAPI.IsEmpty()) + if (!scope.installRemoteObjectAPI(scope.objectGroupName())) return; - scope.installGlobalObjectExtension(remoteObjectAPI); v8::MaybeLocal maybeResultValue = m_debugger->callFunction(functionValue.As(), scope.context(), scope.object(), argc, argv.get()); // Re-initialize after running client's code, as it could have destroyed context or session. @@ -208,9 +200,7 @@ void V8RuntimeAgentImpl::getProperties( if (!scope.initialize()) return; - IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); - MuteConsoleScope muteConsoleScope(m_debugger); - + scope.ignoreExceptionsAndMuteConsole(); if (!scope.object()->IsObject()) { *errorString = "Value with given id is not an object"; return; @@ -335,8 +325,8 @@ void V8RuntimeAgentImpl::runScript(ErrorString* errorString, if (!scope.initialize()) return; - IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); - MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); + if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) + scope.ignoreExceptionsAndMuteConsole(); OwnPtr> scriptWrapper = m_compiledScripts.take(scriptId); v8::Local script = scriptWrapper->Get(m_debugger->isolate()); @@ -345,12 +335,8 @@ void V8RuntimeAgentImpl::runScript(ErrorString* errorString, return; } - if (includeCommandLineAPI.fromMaybe(false)) { - v8::MaybeLocal commandLineAPI = scope.injectedScript()->commandLineAPI(errorString); - if (commandLineAPI.IsEmpty()) - return; - scope.installGlobalObjectExtension(commandLineAPI); - } + if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()) + return; v8::MaybeLocal maybeResultValue = m_debugger->runCompiledScript(scope.context(), script);