X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/81345200c95645a1b0d2635520f96ad55dfde63f..HEAD:/inspector/InjectedScript.cpp?ds=sidebyside diff --git a/inspector/InjectedScript.cpp b/inspector/InjectedScript.cpp index 785dad0..492060e 100644 --- a/inspector/InjectedScript.cpp +++ b/inspector/InjectedScript.cpp @@ -32,15 +32,13 @@ #include "config.h" #include "InjectedScript.h" -#if ENABLE(INSPECTOR) - #include "InspectorValues.h" #include "JSCInlines.h" #include "ScriptFunctionCall.h" #include "ScriptObject.h" #include -using Inspector::TypeBuilder::Array; +using Inspector::Protocol::Array; namespace Inspector { @@ -58,7 +56,7 @@ InjectedScript::~InjectedScript() { } -void InjectedScript::evaluate(ErrorString* errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, RefPtr* result, Inspector::TypeBuilder::OptOutput* wasThrown) +void InjectedScript::evaluate(ErrorString& errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, bool saveResult, RefPtr* result, Inspector::Protocol::OptOutput* wasThrown, Inspector::Protocol::OptOutput* savedResultIndex) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("evaluate"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(expression); @@ -66,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* result, Inspector::TypeBuilder::OptOutput* wasThrown) +void InjectedScript::callFunctionOn(ErrorString& errorString, const String& objectId, const String& expression, const String& arguments, bool returnByValue, bool generatePreview, RefPtr* result, Inspector::Protocol::OptOutput* wasThrown) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("callFunctionOn"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); @@ -80,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* result, Inspector::TypeBuilder::OptOutput* 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, bool saveResult, RefPtr* result, Inspector::Protocol::OptOutput* wasThrown, Inspector::Protocol::OptOutput* savedResultIndex) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("evaluateOnCallFrame"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(callFrames); @@ -90,59 +89,112 @@ 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* result) +void InjectedScript::getFunctionDetails(ErrorString& errorString, const String& functionId, RefPtr* result) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getFunctionDetails"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(functionId); RefPtr 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::runtimeCast(WTF::move(resultValue)); } -void InjectedScript::getProperties(ErrorString* errorString, const String& objectId, bool ownProperties, RefPtr>* properties) +void InjectedScript::getProperties(ErrorString& errorString, const String& objectId, bool ownProperties, bool generatePreview, RefPtr>* properties) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getProperties"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); function.appendArgument(ownProperties); + function.appendArgument(generatePreview); + + RefPtr result; + makeCall(function, &result); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); + return; + } + + *properties = BindingTraits>::runtimeCast(WTF::move(result)); +} + +void InjectedScript::getDisplayableProperties(ErrorString& errorString, const String& objectId, bool generatePreview, RefPtr>* properties) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getDisplayableProperties"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(objectId); + function.appendArgument(generatePreview); RefPtr 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::runtimeCast(result); + *properties = BindingTraits>::runtimeCast(WTF::move(result)); } -void InjectedScript::getInternalProperties(ErrorString* errorString, const String& objectId, RefPtr>* properties) +void InjectedScript::getInternalProperties(ErrorString& errorString, const String& objectId, bool generatePreview, RefPtr>* properties) { Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getInternalProperties"), inspectorEnvironment()->functionCallHandler()); function.appendArgument(objectId); + function.appendArgument(generatePreview); RefPtr 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 = Array::runtimeCast(result); - if (array->length() > 0) - *properties = array; + auto array = BindingTraits>::runtimeCast(WTF::move(result)); + *properties = array->length() > 0 ? array : nullptr; } -PassRefPtr> InjectedScript::wrapCallFrames(const Deprecated::ScriptValue& callFrames) +void InjectedScript::getCollectionEntries(ErrorString& errorString, const String& objectId, const String& objectGroup, int startIndex, int numberToFetch, RefPtr>* entries) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getCollectionEntries"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(objectId); + function.appendArgument(objectGroup); + function.appendArgument(startIndex); + function.appendArgument(numberToFetch); + + RefPtr result; + makeCall(function, &result); + if (!result || result->type() != InspectorValue::Type::Array) { + errorString = ASCIILiteral("Internal error"); + return; + } + + *entries = BindingTraits>::runtimeCast(WTF::move(result)); +} + +void InjectedScript::saveResult(ErrorString& errorString, const String& callArgumentJSON, Inspector::Protocol::OptOutput* savedResultIndex) +{ + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("saveResult"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(callArgumentJSON); + + RefPtr 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> InjectedScript::wrapCallFrames(const Deprecated::ScriptValue& callFrames) { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("wrapCallFrames"), inspectorEnvironment()->functionCallHandler()); @@ -152,13 +204,13 @@ PassRefPtr> InjectedScript::w Deprecated::ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException); ASSERT(!hadException); RefPtr result = callFramesValue.toInspectorValue(scriptState()); - if (result->type() == InspectorValue::TypeArray) - return Array::runtimeCast(result); + if (result->type() == InspectorValue::Type::Array) + return BindingTraits>::runtimeCast(WTF::move(result)).releaseNonNull(); - return Array::create(); + return Array::create(); } -PassRefPtr InjectedScript::wrapObject(const Deprecated::ScriptValue& value, const String& groupName, bool generatePreview) const +RefPtr InjectedScript::wrapObject(const Deprecated::ScriptValue& value, const String& groupName, bool generatePreview) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("wrapObject"), inspectorEnvironment()->functionCallHandler()); @@ -172,11 +224,14 @@ PassRefPtr InjectedScript::wrapOb if (hadException) return nullptr; - RefPtr rawResult = r.toInspectorValue(scriptState())->asObject(); - return Inspector::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); + RefPtr resultObject; + bool castSucceeded = r.toInspectorValue(scriptState())->asObject(resultObject); + ASSERT_UNUSED(castSucceeded, castSucceeded); + + return BindingTraits::runtimeCast(resultObject); } -PassRefPtr InjectedScript::wrapTable(const Deprecated::ScriptValue& table, const Deprecated::ScriptValue& columns) const +RefPtr InjectedScript::wrapTable(const Deprecated::ScriptValue& table, const Deprecated::ScriptValue& columns) const { ASSERT(!hasNoValue()); Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("wrapTable"), inspectorEnvironment()->functionCallHandler()); @@ -192,8 +247,28 @@ PassRefPtr InjectedScript::wrapTa if (hadException) return nullptr; - RefPtr rawResult = r.toInspectorValue(scriptState())->asObject(); - return Inspector::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); + RefPtr resultObject; + bool castSucceeded = r.toInspectorValue(scriptState())->asObject(resultObject); + ASSERT_UNUSED(castSucceeded, castSucceeded); + + return BindingTraits::runtimeCast(resultObject); +} + +void InjectedScript::setExceptionValue(const Deprecated::ScriptValue& value) +{ + ASSERT(!hasNoValue()); + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("setExceptionValue"), inspectorEnvironment()->functionCallHandler()); + function.appendArgument(value); + RefPtr result; + makeCall(function, &result); +} + +void InjectedScript::clearExceptionValue() +{ + ASSERT(!hasNoValue()); + Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("clearExceptionValue"), inspectorEnvironment()->functionCallHandler()); + RefPtr result; + makeCall(function, &result); } Deprecated::ScriptValue InjectedScript::findObjectById(const String& objectId) const @@ -239,4 +314,3 @@ void InjectedScript::releaseObjectGroup(const String& objectGroup) } // namespace Inspector -#endif // ENABLE(INSPECTOR)