void BackendDispatcher::CallbackBase::sendFailure(const ErrorString& error)
{
    ASSERT(error.length());

    if (m_alreadySent)
        return;

    m_alreadySent = true;

    // Immediately send an error message since this is an async response with a single error.
    m_backendDispatcher->reportProtocolError(m_requestId, ServerError, error);
    m_backendDispatcher->sendPendingErrors();
}
void InspectorBackendDispatcher::sendResponse(long callId, PassRefPtr<InspectorObject> result, const ErrorString& invocationError)
{
    if (!m_inspectorFrontendChannel)
        return;

    if (invocationError.length()) {
        reportProtocolError(&callId, ServerError, invocationError);
        return;
    }

    RefPtr<InspectorObject> responseMessage = InspectorObject::create();
    responseMessage->setObject(ASCIILiteral("result"), result);
    responseMessage->setNumber(ASCIILiteral("id"), callId);
    m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage->toJSONString());
}
예제 #3
0
void InjectedScriptBase::makeEvalCall(ErrorString& errorString, Deprecated::ScriptFunctionCall& function, RefPtr<Protocol::Runtime::RemoteObject>* objectResult, Protocol::OptOutput<bool>* wasThrown, Protocol::OptOutput<int>* savedResultIndex)
{
    RefPtr<JSON::Value> result;
    makeCall(function, &result);
    if (!result) {
        errorString = ASCIILiteral("Internal error: result value is empty");
        return;
    }

    if (result->type() == JSON::Value::Type::String) {
        result->asString(errorString);
        ASSERT(errorString.length());
        return;
    }

    RefPtr<JSON::Object> resultTuple;
    if (!result->asObject(resultTuple)) {
        errorString = ASCIILiteral("Internal error: result is not an Object");
        return;
    }

    RefPtr<JSON::Object> resultObject;
    if (!resultTuple->getObject(ASCIILiteral("result"), resultObject)) {
        errorString = ASCIILiteral("Internal error: result is not a pair of value and wasThrown flag");
        return;
    }

    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;
    }
}
void InspectorBackendDispatcher::CallbackBase::sendFailure(const ErrorString& error)
{
    ASSERT(error.length());
    sendIfActive(nullptr, error);
}