Last active
August 29, 2015 14:23
-
-
Save burg/d3a3c97a105f3673a454 to your computer and use it in GitHub Desktop.
Using Optional<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------ Old | |
void DOMBackendDispatcher::performSearch(long callId, const InspectorObject& message) | |
{ | |
auto protocolErrors = Inspector::Protocol::Array<String>::create(); | |
RefPtr<InspectorObject> paramsContainer; | |
message.getObject(ASCIILiteral("params"), paramsContainer); | |
String in_query = BackendDispatcher::getString(paramsContainer.get(), ASCIILiteral("query"), nullptr, protocolErrors.get()); | |
bool opt_in_nodeIds_valueFound = false; | |
RefPtr<Inspector::InspectorArray> opt_in_nodeIds = BackendDispatcher::getArray(paramsContainer.get(), ASCIILiteral("nodeIds"), &opt_in_nodeIds_valueFound, protocolErrors.get()); | |
if (protocolErrors->length()) { | |
String errorMessage = String::format("Some arguments of method '%s' can't be processed", "DOM.performSearch"); | |
m_backendDispatcher->reportProtocolError(&callId, BackendDispatcher::InvalidParams, errorMessage, WTF::move(protocolErrors)); | |
return; | |
} | |
#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) | |
if (m_alternateDispatcher) { | |
m_alternateDispatcher->performSearch(callId, in_query, opt_in_nodeIds_valueFound ? opt_in_nodeIds.get() : nullptr); | |
return; | |
} | |
#endif | |
ErrorString error; | |
Ref<InspectorObject> result = InspectorObject::create(); | |
String out_searchId; | |
int out_resultCount; | |
m_agent->performSearch(error, in_query, opt_in_nodeIds_valueFound ? opt_in_nodeIds.get() : nullptr, &out_searchId, &out_resultCount); | |
if (!error.length()) { | |
result->setString(ASCIILiteral("searchId"), out_searchId); | |
result->setInteger(ASCIILiteral("resultCount"), out_resultCount); | |
} | |
m_backendDispatcher->sendResponse(callId, WTF::move(result), error); | |
} | |
// ----- New | |
void DOMBackendDispatcher::performSearch(long callId, const InspectorObject& parameters, const Inspector::Protocol::Array<String>& protocolErrors) | |
{ | |
Optional<String> in_query = BackendDispatcher::getString(parameters, ASCIILiteral("query"), protocolErrors); | |
if (protocolErrors.length()) | |
return; | |
if (!in_query) { | |
protocolErrors.addItem(String::format("Call to command '%s' must contain required parameter '%s' with type '%s'.", ASCIILiteral("DOM.performSearch"), ASCIILiteral("query"), ASCIILiteral("string"))); | |
return; | |
} | |
RefPtr<Inspector::InspectorArray> opt_in_nodeIds = BackendDispatcher::getArray(parameters, ASCIILiteral("nodeIds"), protocolErrors); | |
if (protocolErrors->length()) | |
return; | |
#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) | |
if (m_alternateDispatcher) { | |
m_alternateDispatcher->performSearch(callId, in_query, opt_in_nodeIds.valueOr(nullptr)); | |
return; | |
} | |
#endif | |
ErrorString errorString; | |
Ref<InspectorObject> result = InspectorObject::create(); | |
String out_searchId; | |
int out_resultCount; | |
m_agent->performSearch(errorString, in_query, opt_in_nodeIds.valueOr(nullptr), out_searchId, out_resultCount); | |
if (!errorString.length()) { | |
result->setString(ASCIILiteral("searchId"), out_searchId); | |
result->setInteger(ASCIILiteral("resultCount"), out_resultCount); | |
} | |
m_backendDispatcher->sendResponse(callId, WTF::move(result), errorString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment