diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/inspector/InjectedScriptBase.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/inspector/InjectedScriptBase.cpp')
-rw-r--r-- | Source/JavaScriptCore/inspector/InjectedScriptBase.cpp | 80 |
1 files changed, 33 insertions, 47 deletions
diff --git a/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp b/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp index c2a494728..9caa4eb93 100644 --- a/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp +++ b/Source/JavaScriptCore/inspector/InjectedScriptBase.cpp @@ -32,9 +32,9 @@ #include "config.h" #include "InjectedScriptBase.h" -#if ENABLE(INSPECTOR) - +#include "DebuggerEvalEnabler.h" #include "InspectorValues.h" +#include "JSCInlines.h" #include "JSGlobalObject.h" #include "ScriptFunctionCall.h" #include <wtf/text/WTFString.h> @@ -58,12 +58,6 @@ InjectedScriptBase::~InjectedScriptBase() { } -void InjectedScriptBase::initialize(Deprecated::ScriptObject injectedScriptObject, InspectorEnvironment* environment) -{ - m_injectedScriptObject = injectedScriptObject; - m_environment = environment; -} - bool InjectedScriptBase::hasAccessToInspectedScriptState() const { return m_environment && m_environment->canAccessInspectedScriptState(m_injectedScriptObject.scriptState()); @@ -74,29 +68,11 @@ const Deprecated::ScriptObject& InjectedScriptBase::injectedScriptObject() const return m_injectedScriptObject; } -Deprecated::ScriptValue InjectedScriptBase::callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall& function, bool& hadException) const +JSC::JSValue InjectedScriptBase::callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall& function, bool& hadException) const { - if (m_environment) - m_environment->willCallInjectedScriptFunction(m_injectedScriptObject.scriptState(), name(), 1); - JSC::ExecState* scriptState = m_injectedScriptObject.scriptState(); - bool evalIsDisabled = false; - if (scriptState) { - evalIsDisabled = !scriptState->lexicalGlobalObject()->evalEnabled(); - // Temporarily enable allow evals for inspector. - if (evalIsDisabled) - scriptState->lexicalGlobalObject()->setEvalEnabled(true); - } - - Deprecated::ScriptValue resultValue = function.call(hadException); - - if (evalIsDisabled) - scriptState->lexicalGlobalObject()->setEvalEnabled(false); - - if (m_environment) - m_environment->didCallInjectedScriptFunction(); - - return resultValue; + JSC::DebuggerEvalEnabler evalEnabler(scriptState); + return function.call(hadException); } void InjectedScriptBase::makeCall(Deprecated::ScriptFunctionCall& function, RefPtr<InspectorValue>* result) @@ -107,49 +83,59 @@ void InjectedScriptBase::makeCall(Deprecated::ScriptFunctionCall& function, RefP } bool hadException = false; - Deprecated::ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException); + auto resultValue = callFunctionWithEvalEnabled(function, hadException); ASSERT(!hadException); if (!hadException) { - *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState()); + *result = toInspectorValue(*m_injectedScriptObject.scriptState(), resultValue); if (!*result) - *result = InspectorString::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth)); + *result = InspectorValue::create(String::format("Object has too long reference chain (must not be longer than %d)", InspectorValue::maxDepth)); } else - *result = InspectorString::create("Exception while making a call."); + *result = InspectorValue::create("Exception while making a call."); } -void InjectedScriptBase::makeEvalCall(ErrorString* errorString, Deprecated::ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder::OptOutput<bool>* wasThrown) +void InjectedScriptBase::makeEvalCall(ErrorString& errorString, Deprecated::ScriptFunctionCall& function, RefPtr<Protocol::Runtime::RemoteObject>* objectResult, Protocol::OptOutput<bool>* wasThrown, Protocol::OptOutput<int>* savedResultIndex) { RefPtr<InspectorValue> result; makeCall(function, &result); if (!result) { - *errorString = ASCIILiteral("Internal error: result value is empty"); + errorString = ASCIILiteral("Internal error: result value is empty"); return; } - if (result->type() == InspectorValue::TypeString) { + if (result->type() == InspectorValue::Type::String) { result->asString(errorString); - ASSERT(errorString->length()); + ASSERT(errorString.length()); return; } - RefPtr<InspectorObject> resultPair = result->asObject(); - if (!resultPair) { - *errorString = ASCIILiteral("Internal error: result is not an Object"); + RefPtr<InspectorObject> resultTuple; + if (!result->asObject(resultTuple)) { + errorString = ASCIILiteral("Internal error: result is not an Object"); return; } - RefPtr<InspectorObject> resultObj = resultPair->getObject(ASCIILiteral("result")); - bool wasThrownVal = false; - if (!resultObj || !resultPair->getBoolean(ASCIILiteral("wasThrown"), &wasThrownVal)) { - *errorString = ASCIILiteral("Internal error: result is not a pair of value and wasThrown flag"); + RefPtr<InspectorObject> resultObject; + if (!resultTuple->getObject(ASCIILiteral("result"), resultObject)) { + errorString = ASCIILiteral("Internal error: result is not a pair of value and wasThrown flag"); return; } - *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); - *wasThrown = wasThrownVal; + bool wasThrownValue = false; + if (!resultTuple->getBoolean(ASCIILiteral("wasThrown"), wasThrownValue)) { + errorString = ASCIILiteral("Internal error: result is not a pair of value and wasThrown flag"); + return; + } + + *objectResult = BindingTraits<Protocol::Runtime::RemoteObject>::runtimeCast(resultObject); + *wasThrown = wasThrownValue; + + if (savedResultIndex) { + int savedIndex = 0; + if (resultTuple->getInteger(ASCIILiteral("savedResultIndex"), savedIndex)) + *savedResultIndex = savedIndex; + } } } // namespace Inspector -#endif // ENABLE(INSPECTOR) |