static ReturnValueType getPropertyValue(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors, DefaultValueType defaultValue, bool (*asMethod)(InspectorValue*, ValueType*), const char* typeName) { ASSERT(protocolErrors); ValueType value = defaultValue; if (valueFound) *valueFound = false; if (!object) { if (!valueFound) protocolErrors->pushString(String::format("'params' object must contain required parameter '%s' with type '%s'.", name.utf8().data(), typeName)); return value; } InspectorObject::const_iterator end = object->end(); InspectorObject::const_iterator valueIterator = object->find(name); if (valueIterator == end) { if (!valueFound) protocolErrors->pushString(String::format("Parameter '%s' with type '%s' was not found.", name.utf8().data(), typeName)); return value; } if (!asMethod(valueIterator->value.get(), &value)) { protocolErrors->pushString(String::format("Parameter '%s' has wrong type. It must be '%s'.", name.utf8().data(), typeName)); return value; } if (valueFound) *valueFound = true; return value; }
static ReturnValueType getPropertyValue(InspectorObject* object, const String& name, bool* out_optionalValueFound, Inspector::Protocol::Array<String>& protocolErrors, DefaultValueType defaultValue, bool (*asMethod)(InspectorValue&, ValueType&), const char* typeName) { ValueType result = defaultValue; // out_optionalValueFound signals to the caller whether an optional property was found. // if out_optionalValueFound == nullptr, then this is a required property. if (out_optionalValueFound) *out_optionalValueFound = false; if (!object) { if (!out_optionalValueFound) protocolErrors.addItem(String::format("'params' object must contain required parameter '%s' with type '%s'.", name.utf8().data(), typeName)); return result; } auto findResult = object->find(name); if (findResult == object->end()) { if (!out_optionalValueFound) protocolErrors.addItem(String::format("Parameter '%s' with type '%s' was not found.", name.utf8().data(), typeName)); return result; } if (!asMethod(*findResult->value, result)) { protocolErrors.addItem(String::format("Parameter '%s' has wrong type. It must be '%s'.", name.utf8().data(), typeName)); return result; } if (out_optionalValueFound) *out_optionalValueFound = true; return result; }