int32_t LayoutTestController::cppVariantToInt32(const CppVariant& value) { if (value.isInt32()) return value.toInt32(); if (value.isString()) { int number; if (StringToInt(value.toString(), &number)) return number; } logErrorToConsole("Invalid value for preference. Expected integer value."); return 0; }
// Need these conversions because the format of the value for booleans // may vary - for example, on mac "1" and "0" are used for boolean. bool LayoutTestController::cppVariantToBool(const CppVariant& value) { if (value.isBool()) return value.toBoolean(); if (value.isInt32()) return value.toInt32(); if (value.isString()) { string valueString = value.toString(); if (valueString == "true" || valueString == "1") return true; if (valueString == "false" || valueString == "0") return false; } logErrorToConsole("Invalid value. Expected boolean value."); return false; }