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/InjectedScript.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/inspector/InjectedScript.cpp')
-rw-r--r-- | Source/JavaScriptCore/inspector/InjectedScript.cpp | 194 |
1 files changed, 153 insertions, 41 deletions
diff --git a/Source/JavaScriptCore/inspector/InjectedScript.cpp b/Source/JavaScriptCore/inspector/InjectedScript.cpp index a02f85fb4..f7691afa4 100644 --- a/Source/JavaScriptCore/inspector/InjectedScript.cpp +++ b/Source/JavaScriptCore/inspector/InjectedScript.cpp @@ -32,14 +32,13 @@ #include "config.h" #include "InjectedScript.h" -#if ENABLE(INSPECTOR) - #include "InspectorValues.h" +#include "JSCInlines.h" #include "ScriptFunctionCall.h" #include "ScriptObject.h" #include <wtf/text/WTFString.h> -using Inspector::TypeBuilder::Array; +using Inspector::Protocol::Array; namespace Inspector { @@ -57,7 +56,7 @@ InjectedScript::~InjectedScript() { } -void InjectedScript::evaluate(ErrorString* errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, RefPtr<Inspector::TypeBuilder::Runtime::RemoteObject>* result, Inspector::TypeBuilder::OptOutput<bool>* wasThrown) +void InjectedScript::evaluate(ErrorString& errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, bool saveResult, RefPtr<Inspector::Protocol::Runtime::RemoteObject>* result, Inspector::Protocol::OptOutput<bool>* wasThrown, Inspector::Protocol::OptOutput<int>* savedResultIndex) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("evaluate"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(expression); @@ -65,10 +64,11 @@ void InjectedScript::evaluate(ErrorString* errorString, const String& expression function.appendArgument(includeCommandLineAPI); function.appendArgument(returnByValue); function.appendArgument(generatePreview); - makeEvalCall(errorString, function, result, wasThrown); + function.appendArgument(saveResult); + makeEvalCall(errorString, function, result, wasThrown, savedResultIndex); } -void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, const String& arguments, bool returnByValue, bool generatePreview, RefPtr<Inspector::TypeBuilder::Runtime::RemoteObject>* result, Inspector::TypeBuilder::OptOutput<bool>* wasThrown) +void InjectedScript::callFunctionOn(ErrorString& errorString, const String& objectId, const String& expression, const String& arguments, bool returnByValue, bool generatePreview, RefPtr<Inspector::Protocol::Runtime::RemoteObject>* result, Inspector::Protocol::OptOutput<bool>* wasThrown) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("callFunctionOn"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); @@ -79,7 +79,7 @@ void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje makeEvalCall(errorString, function, result, wasThrown); } -void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Deprecated::ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, RefPtr<Inspector::TypeBuilder::Runtime::RemoteObject>* result, Inspector::TypeBuilder::OptOutput<bool>* wasThrown) +void InjectedScript::evaluateOnCallFrame(ErrorString& errorString, JSC::JSValue callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, bool saveResult, RefPtr<Inspector::Protocol::Runtime::RemoteObject>* result, Inspector::Protocol::OptOutput<bool>* wasThrown, Inspector::Protocol::OptOutput<int>* savedResultIndex) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("evaluateOnCallFrame"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(callFrames); @@ -89,75 +89,147 @@ void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Depreca function.appendArgument(includeCommandLineAPI); function.appendArgument(returnByValue); function.appendArgument(generatePreview); - makeEvalCall(errorString, function, result, wasThrown); + function.appendArgument(saveResult); + makeEvalCall(errorString, function, result, wasThrown, savedResultIndex); } -void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<Inspector::TypeBuilder::Debugger::FunctionDetails>* result) +void InjectedScript::getFunctionDetails(ErrorString& errorString, const String& functionId, RefPtr<Inspector::Protocol::Debugger::FunctionDetails>* result) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getFunctionDetails"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(functionId); RefPtr<InspectorValue> resultValue; makeCall(function, &resultValue); - if (!resultValue || resultValue->type() != InspectorValue::TypeObject) { + if (!resultValue || resultValue->type() != InspectorValue::Type::Object) { if (!resultValue->asString(errorString)) - *errorString = ASCIILiteral("Internal error"); + errorString = ASCIILiteral("Internal error"); return; } - *result = Inspector::TypeBuilder::Debugger::FunctionDetails::runtimeCast(resultValue); + *result = BindingTraits<Inspector::Protocol::Debugger::FunctionDetails>::runtimeCast(WTFMove(resultValue)); } -void InjectedScript::getProperties(ErrorString* errorString, const String& objectId, bool ownProperties, RefPtr<Array<Inspector::TypeBuilder::Runtime::PropertyDescriptor>>* properties) +void InjectedScript::functionDetails(ErrorString& errorString, JSC::JSValue value, RefPtr<Protocol::Debugger::FunctionDetails>* result) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("functionDetails"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(value); + function.appendArgument(true); // Preview only. + + RefPtr<InspectorValue> resultValue; + makeCall(function, &resultValue); + if (!resultValue || resultValue->type() != InspectorValue::Type::Object) { + if (!resultValue->asString(errorString)) + errorString = ASCIILiteral("Internal error"); + return; + } + + *result = BindingTraits<Inspector::Protocol::Debugger::FunctionDetails>::runtimeCast(WTFMove(resultValue)); +} + +void InjectedScript::getProperties(ErrorString& errorString, const String& objectId, bool ownProperties, bool generatePreview, RefPtr<Array<Inspector::Protocol::Runtime::PropertyDescriptor>>* properties) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getProperties"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); function.appendArgument(ownProperties); + function.appendArgument(generatePreview); RefPtr<InspectorValue> result; makeCall(function, &result); - if (!result || result->type() != InspectorValue::TypeArray) { - *errorString = ASCIILiteral("Internal error"); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); return; } - *properties = Array<Inspector::TypeBuilder::Runtime::PropertyDescriptor>::runtimeCast(result); + *properties = BindingTraits<Array<Inspector::Protocol::Runtime::PropertyDescriptor>>::runtimeCast(WTFMove(result)); } -void InjectedScript::getInternalProperties(ErrorString* errorString, const String& objectId, RefPtr<Array<Inspector::TypeBuilder::Runtime::InternalPropertyDescriptor>>* properties) +void InjectedScript::getDisplayableProperties(ErrorString& errorString, const String& objectId, bool generatePreview, RefPtr<Array<Inspector::Protocol::Runtime::PropertyDescriptor>>* properties) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getDisplayableProperties"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(objectId); + function.appendArgument(generatePreview); + + RefPtr<InspectorValue> result; + makeCall(function, &result); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); + return; + } + + *properties = BindingTraits<Array<Inspector::Protocol::Runtime::PropertyDescriptor>>::runtimeCast(WTFMove(result)); +} + +void InjectedScript::getInternalProperties(ErrorString& errorString, const String& objectId, bool generatePreview, RefPtr<Array<Inspector::Protocol::Runtime::InternalPropertyDescriptor>>* properties) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getInternalProperties"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); + function.appendArgument(generatePreview); RefPtr<InspectorValue> result; makeCall(function, &result); - if (!result || result->type() != InspectorValue::TypeArray) { - *errorString = ASCIILiteral("Internal error"); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); return; } - RefPtr<Array<Inspector::TypeBuilder::Runtime::InternalPropertyDescriptor>> array = Array<Inspector::TypeBuilder::Runtime::InternalPropertyDescriptor>::runtimeCast(result); - if (array->length() > 0) - *properties = array; + auto array = BindingTraits<Array<Inspector::Protocol::Runtime::InternalPropertyDescriptor>>::runtimeCast(WTFMove(result)); + *properties = array->length() > 0 ? array : nullptr; } -PassRefPtr<Array<Inspector::TypeBuilder::Debugger::CallFrame>> InjectedScript::wrapCallFrames(const Deprecated::ScriptValue& callFrames) +void InjectedScript::getCollectionEntries(ErrorString& errorString, const String& objectId, const String& objectGroup, int startIndex, int numberToFetch, RefPtr<Protocol::Array<Protocol::Runtime::CollectionEntry>>* entries) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getCollectionEntries"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(objectId); + function.appendArgument(objectGroup); + function.appendArgument(startIndex); + function.appendArgument(numberToFetch); + + RefPtr<InspectorValue> result; + makeCall(function, &result); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); + return; + } + + *entries = BindingTraits<Array<Protocol::Runtime::CollectionEntry>>::runtimeCast(WTFMove(result)); +} + +void InjectedScript::saveResult(ErrorString& errorString, const String& callArgumentJSON, Inspector::Protocol::OptOutput<int>* savedResultIndex) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("saveResult"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(callArgumentJSON); + + RefPtr<InspectorValue> result; + makeCall(function, &result); + if (!result || result->type() != InspectorValue::Type::Integer) { + errorString = ASCIILiteral("Internal error"); + return; + } + + int savedResultIndexInt = 0; + if (result->asInteger(savedResultIndexInt) && savedResultIndexInt > 0) + *savedResultIndex = savedResultIndexInt; +} + +Ref<Array<Inspector::Protocol::Debugger::CallFrame>> InjectedScript::wrapCallFrames(JSC::JSValue callFrames) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("wrapCallFrames"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(callFrames); bool hadException = false; - Deprecated::ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException); + auto callFramesValue = callFunctionWithEvalEnabled(function, hadException); + if (!callFramesValue) + return Array<Inspector::Protocol::Debugger::CallFrame>::create(); ASSERT(!hadException); - RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(scriptState()); - if (result->type() == InspectorValue::TypeArray) - return Array<Inspector::TypeBuilder::Debugger::CallFrame>::runtimeCast(result); + RefPtr<InspectorValue> result = toInspectorValue(*scriptState(), callFramesValue); + if (result->type() == InspectorValue::Type::Array) + return BindingTraits<Array<Inspector::Protocol::Debugger::CallFrame>>::runtimeCast(WTFMove(result)).releaseNonNull(); - return Array<Inspector::TypeBuilder::Debugger::CallFrame>::create(); + return Array<Inspector::Protocol::Debugger::CallFrame>::create(); } -PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(const Deprecated::ScriptValue& value, const String& groupName, bool generatePreview) const +RefPtr<Inspector::Protocol::Runtime::RemoteObject> InjectedScript::wrapObject(JSC::JSValue value, const String& groupName, bool generatePreview) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("wrapObject"), inspectorEnvironment()->functionCallHandler()); @@ -167,48 +239,89 @@ PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapOb wrapFunction.appendArgument(generatePreview); bool hadException = false; - Deprecated::ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); + auto r = callFunctionWithEvalEnabled(wrapFunction, hadException); if (hadException) return nullptr; - RefPtr<InspectorObject> rawResult = r.toInspectorValue(scriptState())->asObject(); - return Inspector::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); + RefPtr<InspectorObject> resultObject; + bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject); + ASSERT_UNUSED(castSucceeded, castSucceeded); + + return BindingTraits<Inspector::Protocol::Runtime::RemoteObject>::runtimeCast(resultObject); } -PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(const Deprecated::ScriptValue& table, const Deprecated::ScriptValue& columns) const +RefPtr<Inspector::Protocol::Runtime::RemoteObject> InjectedScript::wrapTable(JSC::JSValue table, JSC::JSValue columns) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("wrapTable"), inspectorEnvironment()->functionCallHandler()); wrapFunction.appendArgument(hasAccessToInspectedScriptState()); wrapFunction.appendArgument(table); - if (columns.hasNoValue()) + if (!columns) wrapFunction.appendArgument(false); else wrapFunction.appendArgument(columns); bool hadException = false; - Deprecated::ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); + auto r = callFunctionWithEvalEnabled(wrapFunction, hadException); + if (hadException) + return nullptr; + + RefPtr<InspectorObject> resultObject; + bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject); + ASSERT_UNUSED(castSucceeded, castSucceeded); + + return BindingTraits<Inspector::Protocol::Runtime::RemoteObject>::runtimeCast(resultObject); +} + +RefPtr<Inspector::Protocol::Runtime::ObjectPreview> InjectedScript::previewValue(JSC::JSValue value) const +{ + ASSERT(!hasNoValue()); + Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("previewValue"), inspectorEnvironment()->functionCallHandler()); + wrapFunction.appendArgument(value); + + bool hadException = false; + auto r = callFunctionWithEvalEnabled(wrapFunction, hadException); if (hadException) return nullptr; - RefPtr<InspectorObject> rawResult = r.toInspectorValue(scriptState())->asObject(); - return Inspector::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); + RefPtr<InspectorObject> resultObject; + bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject); + ASSERT_UNUSED(castSucceeded, castSucceeded); + + return BindingTraits<Inspector::Protocol::Runtime::ObjectPreview>::runtimeCast(resultObject); +} + +void InjectedScript::setExceptionValue(JSC::JSValue value) +{ + ASSERT(!hasNoValue()); + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("setExceptionValue"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(value); + RefPtr<InspectorValue> result; + makeCall(function, &result); +} + +void InjectedScript::clearExceptionValue() +{ + ASSERT(!hasNoValue()); + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("clearExceptionValue"), inspectorEnvironment()->functionCallHandler()); + RefPtr<InspectorValue> result; + makeCall(function, &result); } -Deprecated::ScriptValue InjectedScript::findObjectById(const String& objectId) const +JSC::JSValue InjectedScript::findObjectById(const String& objectId) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("findObjectById"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); bool hadException = false; - Deprecated::ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException); + auto resultValue = callFunctionWithEvalEnabled(function, hadException); ASSERT(!hadException); return resultValue; } -void InjectedScript::inspectObject(Deprecated::ScriptValue value) +void InjectedScript::inspectObject(JSC::JSValue value) { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("inspectObject"), inspectorEnvironment()->functionCallHandler()); @@ -238,4 +351,3 @@ void InjectedScript::releaseObjectGroup(const String& objectGroup) } // namespace Inspector -#endif // ENABLE(INSPECTOR) |