Skip to content

Commit

Permalink
[DevTools] Follow up with cleanups for InjectedScript::Scope.
Browse files Browse the repository at this point in the history
BUG=none
TBR=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/1877203004

Cr-Commit-Position: refs/heads/master@{#387135}
  • Loading branch information
dgozman authored and Commit bot committed Apr 13, 2016
1 parent be3c5bc commit ff97735
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 192 deletions.
2 changes: 0 additions & 2 deletions third_party/WebKit/Source/platform/blink_platform.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

This file was deleted.

108 changes: 64 additions & 44 deletions third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,17 @@ InjectedScript::~InjectedScript()
{
}

v8::Isolate* InjectedScript::isolate() const
{
return m_context->isolate();
}

void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Object> object, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnPtr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDetails>* 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);
function.appendArgument(ownProperties);
function.appendArgument(accessorPropertiesOnly);
function.appendArgument(generatePreview);

v8::TryCatch tryCatch(isolate());
v8::TryCatch tryCatch(m_context->isolate());
v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
if (tryCatch.HasCaught()) {
*exceptionDetails = createExceptionDetails(tryCatch.Message());
Expand Down Expand Up @@ -170,7 +165,7 @@ void InjectedScript::releaseObject(const String16& objectId)

PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(ErrorString* errorString, v8::Local<v8::Value> 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<v8::Value> wrappedObject;
if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview).ToLocal(&wrappedObject))
Expand Down Expand Up @@ -240,7 +235,7 @@ v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* errorString, v8

PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<v8::Value> table, v8::Local<v8::Value> 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);
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -293,15 +288,15 @@ void InjectedScript::setCustomObjectFormatterEnabled(bool enabled)

bool InjectedScript::canAccessInspectedWindow() const
{
v8::Local<v8::Context> callingContext = isolate()->GetCallingContext();
v8::Local<v8::Context> callingContext = m_context->isolate()->GetCallingContext();
if (callingContext.IsEmpty())
return true;
return m_context->debugger()->client()->callingContextCanAccessContext(callingContext, m_context->context());
}

v8::Local<v8::Value> InjectedScript::v8Value() const
{
return m_value.Get(isolate());
return m_value.Get(m_context->isolate());
}

bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local<v8::Value> value)
Expand Down Expand Up @@ -333,36 +328,13 @@ v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error
if (callArgument->getType(String16()) == "number")
value = "Number(" + value + ")";
v8::Local<v8::Value> 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<v8::Value>();
}
return object;
}
return v8::Undefined(isolate());
}

v8::MaybeLocal<v8::Object> InjectedScript::commandLineAPI(ErrorString* errorString) const
{
V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value(), "commandLineAPI");
return callFunctionReturnObject(errorString, function);
}

v8::MaybeLocal<v8::Object> 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<v8::Object> InjectedScript::callFunctionReturnObject(ErrorString* errorString, V8FunctionCall& function) const
{
bool hadException = false;
v8::Local<v8::Value> result = function.call(hadException, false);
v8::Local<v8::Object> resultObject;
if (hasInternalError(errorString, hadException || result.IsEmpty() || !result->ToObject(m_context->context()).ToLocal(&resultObject)))
return v8::MaybeLocal<v8::Object>();
return resultObject;
return v8::Undefined(m_context->isolate());
}

PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionDetails(v8::Local<v8::Message> message)
Expand Down Expand Up @@ -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)
{
}

Expand All @@ -438,16 +412,58 @@ bool InjectedScript::Scope::initialize()
return true;
}

void InjectedScript::Scope::installGlobalObjectExtension(v8::MaybeLocal<v8::Object> extension)
bool InjectedScript::Scope::installCommandLineAPI()
{
v8::Local<v8::Object> 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<v8::Value> 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<v8::Object> 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()
Expand All @@ -466,6 +482,10 @@ void InjectedScript::Scope::cleanup()

InjectedScript::Scope::~Scope()
{
if (m_ignoreExceptionsAndMuteConsole) {
setPauseOnExceptionsState(m_previousPauseOnExceptionsState);
m_debugger->client()->unmuteConsole();
}
cleanup();
}

Expand Down
27 changes: 13 additions & 14 deletions third_party/WebKit/Source/platform/v8_inspector/InjectedScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <v8.h>
Expand All @@ -58,31 +59,23 @@ class InjectedScript final {
static PassOwnPtr<InjectedScript> create(InspectedContext*, InjectedScriptHost*);
~InjectedScript();

InspectedContext* context() const { return m_context; }

void getProperties(ErrorString*, v8::Local<v8::Object>, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, Maybe<protocol::Runtime::ExceptionDetails>*);
void releaseObject(const String16& objectId);

PassOwnPtr<protocol::Runtime::RemoteObject> wrapObject(ErrorString*, v8::Local<v8::Value>, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const;
bool wrapObjectProperty(ErrorString*, v8::Local<v8::Object>, v8::Local<v8::Value> key, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const;
bool wrapPropertyInArray(ErrorString*, v8::Local<v8::Array>, v8::Local<v8::String> property, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const;
bool wrapObjectsInArray(ErrorString*, v8::Local<v8::Array>, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const;

PassOwnPtr<protocol::Runtime::RemoteObject> wrapTable(v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const;

bool findObject(ErrorString*, const RemoteObjectId&, v8::Local<v8::Value>*) 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::Value>);
v8::MaybeLocal<v8::Value> resolveCallArgument(ErrorString*, protocol::Runtime::CallArgument*);

v8::MaybeLocal<v8::Object> commandLineAPI(ErrorString*) const;
v8::MaybeLocal<v8::Object> remoteObjectAPI(ErrorString*, const String16& groupName) const;

PassOwnPtr<protocol::Runtime::ExceptionDetails> createExceptionDetails(v8::Local<v8::Message>);
void wrapEvaluateResult(ErrorString*,
v8::MaybeLocal<v8::Value> maybeResultValue,
Expand All @@ -97,7 +90,9 @@ class InjectedScript final {
class Scope {
public:
bool initialize();
void installGlobalObjectExtension(v8::MaybeLocal<v8::Object> extension);
bool installCommandLineAPI();
bool installRemoteObjectAPI(const String16& objectGroupName);
void ignoreExceptionsAndMuteConsole();
v8::Local<v8::Context> context() const { return m_context; }
InjectedScript* injectedScript() const { return m_injectedScript; }
const v8::TryCatch& tryCatch() const { return m_tryCatch; }
Expand All @@ -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<v8::Context> m_context;
v8::Local<v8::Symbol> m_extensionSymbol;
v8::MaybeLocal<v8::Object> m_global;
bool m_ignoreExceptionsAndMuteConsole;
V8DebuggerImpl::PauseOnExceptionsState m_previousPauseOnExceptionsState;
};

class ContextScope: public Scope {
Expand Down Expand Up @@ -160,10 +159,10 @@ class InjectedScript final {

private:
InjectedScript(InspectedContext*, v8::Local<v8::Object>, PassOwnPtr<InjectedScriptNative>);

bool canAccessInspectedWindow() const;
bool setLastEvaluationResult(ErrorString*, v8::Local<v8::Value>);
v8::Local<v8::Value> v8Value() const;
v8::MaybeLocal<v8::Value> wrapValue(ErrorString*, v8::Local<v8::Value>, const String16& groupName, bool forceValueType, bool generatePreview) const;
v8::MaybeLocal<v8::Object> callFunctionReturnObject(ErrorString*, V8FunctionCall&) const;

InspectedContext* m_context;
v8::Global<v8::Value> m_value;
Expand Down
36 changes: 0 additions & 36 deletions third_party/WebKit/Source/platform/v8_inspector/MuteConsoleScope.h

This file was deleted.

Loading

0 comments on commit ff97735

Please sign in to comment.