// If both left and right are defined, then use left. Otherwise return // +left or -right depending on which is defined. static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) { float lead = node->style.position[leading[axis]]; if (!isUndefined(lead)) { return lead; } return -getPosition(node, trailing[axis]); }
void SandboxUtils::ifLocalSandboxRunningElse(std::function<void()> localSandboxRunningDoThis, std::function<void()> localSandboxNotRunningDoThat) { QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); QNetworkRequest sandboxStatus(SANDBOX_STATUS_URL); sandboxStatus.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); sandboxStatus.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); QNetworkReply* reply = networkAccessManager.get(sandboxStatus); connect(reply, &QNetworkReply::finished, this, [reply, localSandboxRunningDoThis, localSandboxNotRunningDoThat]() { if (reply->error() == QNetworkReply::NoError) { auto statusData = reply->readAll(); auto statusJson = QJsonDocument::fromJson(statusData); if (!statusJson.isEmpty()) { auto statusObject = statusJson.object(); auto serversValue = statusObject.value("servers"); if (!serversValue.isUndefined() && serversValue.isObject()) { auto serversObject = serversValue.toObject(); auto serversCount = serversObject.size(); const int MINIMUM_EXPECTED_SERVER_COUNT = 5; if (serversCount >= MINIMUM_EXPECTED_SERVER_COUNT) { localSandboxRunningDoThis(); return; } } } } localSandboxNotRunningDoThat(); }); }
void MinusCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { double number1 = atof(variable1.getValue().c_str()); double number2 = atof(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 - number2)); vm.setReturnToken(variable1.getTokenType()); } else { // Exception minus requires 2 numbers throwCustomError("cannot subtract " + variable1.getValue() + " by " + variable2.getValue(), vm, supergeheimeToken); return; } }
static float getPosition(css_node_t *node, css_position_t position) { float result = node->style.position[position]; if (!isUndefined(result)) { return result; } return 0; }
void ModuloCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { int number1 = atoi(variable1.getValue().c_str()); int number2 = atoi(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 % number2)); vm.setReturnToken(variable1.getTokenType()); } else { throwCustomError("cannot get remainder (modulo) " + variable1.getValue() + " from " + variable2.getValue(), vm,supergeheimeToken); return; } }
char* JSValue::description() { static const size_t size = 32; static char description[size]; if (!*this) snprintf(description, size, "<JSValue()>"); else if (isInt32()) snprintf(description, size, "Int32: %d", asInt32()); else if (isDouble()) snprintf(description, size, "Double: %lf", asDouble()); else if (isCell()) snprintf(description, size, "Cell: %p", asCell()); else if (isTrue()) snprintf(description, size, "True"); else if (isFalse()) snprintf(description, size, "False"); else if (isNull()) snprintf(description, size, "Null"); else { ASSERT(isUndefined()); snprintf(description, size, "Undefined"); } return description; }
static float getTrailingMargin(css_node_t *node, css_flex_direction_t axis) { if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_END])) { return node->style.margin[CSS_END]; } return node->style.margin[trailing[axis]]; }
void Promise::MaybeReportRejected() { if (mState != Rejected || mHadRejectCallback || mResult.isUndefined()) { return; } JSErrorReport* report = js::ErrorFromException(mResult); if (!report) { return; } MOZ_ASSERT(mResult.isObject(), "How did we get a JSErrorReport?"); nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(&mResult.toObject())); // Now post an event to do the real reporting async NS_DispatchToCurrentThread( new AsyncErrorReporter(JS_GetObjectRuntime(&mResult.toObject()), report, nullptr, nsContentUtils::GetObjectPrincipal(&mResult.toObject()), win)); }
void InstagramClient::loginFinished(QNetworkReply *reply) { QByteArray response = reply->readAll(); qDebug() << qPrintable(response); QJsonParseError error; auto json = QJsonDocument::fromJson(response, &error).toVariant(); auto jsonMap = json.toMap(); InstagramAccount *account = 0; if (reply->error() == QNetworkReply::NoError && error.error == QJsonParseError::NoError && jsonMap["status"].toString() == "ok") { auto loggedInUserObj = jsonMap["logged_in_user"].toMap(); auto userID = loggedInUserObj["pk"].toLongLong(); auto userName = loggedInUserObj["username"].toString(); auto fullName = loggedInUserObj["full_name"].toString(); bool hadAccount = InstagramAccountManager::instance()->allAccounts().count() > 0; account = InstagramAccountManager::instance()->createAccount(userID, userName, fullName, qobject_cast<DConfCookieJar*>(reply->manager()->cookieJar()), !hadAccount); } QUuid key = reply->request().attribute(QNetworkRequest::User).value<QUuid>(); auto cb = this->callbacks->take(key); if (!cb.isUndefined()) cb.call(QJSValueList {cb.engine()->toScriptValue(json), cb.engine()->toScriptValue(account)}); }
static float getLeadingMargin(css_node_t *node, css_flex_direction_t axis) { if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_START])) { return node->style.margin[CSS_START]; } return node->style.margin[leading[axis]]; }
void DecorationsModel::init() { beginResetModel(); m_plugins.clear(); const auto plugins = KPluginTrader::self()->query(s_pluginName, s_pluginName); for (const auto &info : plugins) { KPluginLoader loader(info.libraryPath()); KPluginFactory *factory = loader.factory(); if (!factory) { continue; } auto metadata = loader.metaData().value(QStringLiteral("MetaData")).toObject().value(s_pluginName); bool config = false; if (!metadata.isUndefined()) { const auto decoSettingsMap = metadata.toObject().toVariantMap(); const QString &kns = findKNewStuff(decoSettingsMap); if (!kns.isEmpty()) { m_knsProvides.insert(kns, info.name().isEmpty() ? info.pluginName() : info.name()); } if (isThemeEngine(decoSettingsMap)) { const QString keyword = themeListKeyword(decoSettingsMap); if (keyword.isNull()) { // We cannot list the themes continue; } QScopedPointer<QObject> themeFinder(factory->create<QObject>(keyword)); if (themeFinder.isNull()) { continue; } QVariant themes = themeFinder->property("themes"); if (!themes.isValid()) { continue; } const auto themesMap = themes.toMap(); for (auto it = themesMap.begin(); it != themesMap.end(); ++it) { Data d; d.pluginName = info.pluginName(); d.themeName = it.value().toString(); d.visibleName = it.key(); QMetaObject::invokeMethod(themeFinder.data(), "hasConfiguration", Q_RETURN_ARG(bool, d.configuration), Q_ARG(QString, d.themeName)); m_plugins.emplace_back(std::move(d)); } // it's a theme engine, we don't want to show this entry continue; } config = isConfigureable(decoSettingsMap); } Data data; data.pluginName = info.pluginName(); data.visibleName = info.name().isEmpty() ? info.pluginName() : info.name(); data.configuration = config; m_plugins.emplace_back(std::move(data)); } endResetModel(); }
T GridField<T>::valueAtIndex(int i) const{ if(isUndefined(i)){ std::stringstream ss; ss << "Försökte komma åt ett odefinierat index (" << i << ") i GridField::valueAtIndex(int i)"; throw std::out_of_range (ss.str()); } return _data[i]; }
bool RtValue::toBool2()const{ if(isObject()){ return value.value_obj->toBool(); }else if(isVoid() || isUndefined()){ return false; }else{ return true; } }
double JSValue::toNumberSlowCase(ExecState* exec) const { ASSERT(!isInt32() && !isDouble()); if (isCell()) return asCell()->toNumber(exec); if (isTrue()) return 1.0; return isUndefined() ? PNaN : 0; // null and false both convert to 0. }
void PlusCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { double number1 = atof(variable1.getValue().c_str()); double number2 = atof(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 + number2)); vm.setReturnToken(variable1.getTokenType()); } else if (variable1.getTokenType() == IToken::TYPE_FACT && variable2.getTokenType() == IToken::TYPE_FACT) { bool bool1 = (variable1.getValue() == "true") ? true : false; bool bool2 = (variable2.getValue() == "true") ? true : false; bool outcome = bool1 + bool2; if (outcome) { vm.setReturnValue("true"); } else { vm.setReturnValue("false"); } vm.setReturnToken(variable1.getTokenType()); } else { string var1 = variable1.getValue(); string var2 = variable2.getValue(); if (variable1.getTokenType() == IToken::TYPE_NUMBER) { var1 = removeUnnecessaryDotsAndZeros(var1); } if (variable1.getTokenType() == IToken::TYPE_NUMBER) { var2 = removeUnnecessaryDotsAndZeros(var2); } vm.setReturnValue(var1 + var2); vm.setReturnToken(IToken::TYPE_TEXT); } }
State buildState (QJsonObject const &stateObj) { State state; state.name = stateObj.value("name").toString(); auto transitionsValue = stateObj.value("transitions"); if (!transitionsValue.isUndefined()) { state.transitions = buildTransitionList(transitionsValue.toArray()); } auto typeValue = stateObj.value("type"); if (!typeValue.isUndefined()) { state.type = typeValue.toString(); } auto commandValue = stateObj.value("command"); if (!commandValue.isUndefined()) { state.command = commandValue.toString(); } return state; }
static float getTrailingBorder(css_node_t *node, css_flex_direction_t axis) { if (isRowDirection(axis) && !isUndefined(node->style.border[CSS_END]) && node->style.border[CSS_END] >= 0) { return node->style.border[CSS_END]; } if (node->style.border[trailing[axis]] >= 0) { return node->style.border[trailing[axis]]; } return 0; }
static float getLeadingBorder(css_node_t *node, css_flex_direction_t axis) { if (isRowDirection(axis) && !isUndefined(node->style.border[CSS_START]) && node->style.border[CSS_START] >= 0) { return node->style.border[CSS_START]; } if (node->style.border[leading[axis]] >= 0) { return node->style.border[leading[axis]]; } return 0; }
std::optional<double> JSValue::toNumberFromPrimitive() const { if (isEmpty()) return std::nullopt; if (isNumber()) return asNumber(); if (isBoolean()) return asBoolean(); if (isUndefined()) return PNaN; if (isNull()) return 0; return std::nullopt; }
optional<Error> setVisibility(Layer& layer, const V& value) { if (isUndefined(value)) { layer.setVisibility(VisibilityType::Visible); return {}; } Result<VisibilityType> visibility = convert<VisibilityType>(value); if (!visibility) { return visibility.error(); } layer.setVisibility(*visibility); return {}; }
static float boundAxis(css_node_t *node, css_flex_direction_t axis, float value) { float min = CSS_UNDEFINED; float max = CSS_UNDEFINED; if (isColumnDirection(axis)) { min = node->style.minDimensions[CSS_HEIGHT]; max = node->style.maxDimensions[CSS_HEIGHT]; } else if (isRowDirection(axis)) { min = node->style.minDimensions[CSS_WIDTH]; max = node->style.maxDimensions[CSS_WIDTH]; } float boundValue = value; if (!isUndefined(max) && max >= 0.0 && boundValue > max) { boundValue = max; } if (!isUndefined(min) && min >= 0.0 && boundValue < min) { boundValue = min; } return boundValue; }
// When the user specifically sets a value for width or height static void setDimensionFromStyle(css_node_t *node, css_flex_direction_t axis) { // The parent already computed us a width or height. We just skip it if (!isUndefined(node->layout.dimensions[dim[axis]])) { return; } // We only run if there's a width or height defined if (!isDimDefined(node, axis)) { return; } // The dimensions can never be smaller than the padding and border node->layout.dimensions[dim[axis]] = fmaxf( boundAxis(node, axis, node->style.dimensions[dim[axis]]), getPaddingAndBorderAxis(node, axis) ); }
T GridField<T>::valueAtIndex(int i,int j,int k) const{ if (_extrapolate && isUndefined(i, j, k)){ if(_extrapolation == nullptr){ std::stringstream ss; ss << "Försökte komma åt ett odefinierat index (" << i; ss << "), (" << j << "), (" << k; ss << ") i GridField::valueAtIndex(int i,int j,int k)."; ss << "En möjlig anledning kan vara att GridField._extrapolation är NULL"; throw std::out_of_range(ss.str()); } return _extrapolation->extrapolate(*this,i,j,k); }else{ return valueAtIndex(indexAt(i, j, k)); } }
String JSValue::toWTFStringSlowCase(ExecState* exec) const { VM& vm = exec->vm(); if (isInt32()) return vm.numericStrings.add(asInt32()); if (isDouble()) return vm.numericStrings.add(asDouble()); if (isTrue()) return vm.propertyNames->trueKeyword.string(); if (isFalse()) return vm.propertyNames->falseKeyword.string(); if (isNull()) return vm.propertyNames->nullKeyword.string(); if (isUndefined()) return vm.propertyNames->undefinedKeyword.string(); return toString(exec)->value(exec); }
Result<PropertyValue<T>> operator()(const V& value) const { if (isUndefined(value)) { return {}; } else if (isObject(value)) { Result<Function<T>> function = convert<Function<T>>(value); if (!function) { return function.error(); } return *function; } else { Result<T> constant = convert<T>(value); if (!constant) { return constant.error(); } return *constant; } }
JSString* JSValue::toStringSlowCase(ExecState* exec, bool returnEmptyStringOnError) const { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto errorValue = [&] () -> JSString* { if (returnEmptyStringOnError) return jsEmptyString(exec); return nullptr; }; ASSERT(!isString()); if (isInt32()) { auto integer = asInt32(); if (static_cast<unsigned>(integer) <= 9) return vm.smallStrings.singleCharacterString(integer + '0'); return jsNontrivialString(&vm, vm.numericStrings.add(integer)); } if (isDouble()) return jsString(&vm, vm.numericStrings.add(asDouble())); if (isTrue()) return vm.smallStrings.trueString(); if (isFalse()) return vm.smallStrings.falseString(); if (isNull()) return vm.smallStrings.nullString(); if (isUndefined()) return vm.smallStrings.undefinedString(); if (isSymbol()) { throwTypeError(exec, scope, ASCIILiteral("Cannot convert a symbol to a string")); return errorValue(); } ASSERT(isCell()); JSValue value = asCell()->toPrimitive(exec, PreferString); if (vm.exception()) return errorValue(); ASSERT(!value.isObject()); JSString* result = value.toString(exec); if (vm.exception()) return errorValue(); return result; }
void InstagramClient::apiRequestFinished(QNetworkReply *reply) { qDebug() << qPrintable("Request finished"); auto response = QString::fromUtf8(reply->readAll()); auto json = QtJson::parse(response); //qDebug() << reply->rawHeaderPairs(); //qDebug() << response; QUuid key = reply->request().attribute(QNetworkRequest::User).value<QUuid>(); auto cb = this->callbacks->take(key); if (!cb.isUndefined()) cb.call(QJSValueList {cb.engine()->toScriptValue(json)}); auto statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (statusCode != 200) this->handleRequestError(json.toMap()["message"].toString()); }
void JSValue::dumpForBacktrace(PrintStream& out) const { if (!*this) out.print("<JSValue()>"); else if (isInt32()) out.printf("%d", asInt32()); else if (isDouble()) out.printf("%lf", asDouble()); else if (isCell()) { if (asCell()->inherits(JSString::info())) { JSString* string = jsCast<JSString*>(asCell()); const StringImpl* impl = string->tryGetValueImpl(); if (impl) out.print("\"", impl, "\""); else out.print("(unresolved string)"); } else if (asCell()->inherits(Structure::info())) { out.print("Structure[ ", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } else { out.print("Cell[", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } } else if (isTrue()) out.print("True"); else if (isFalse()) out.print("False"); else if (isNull()) out.print("Null"); else if (isUndefined()) out.print("Undefined"); else out.print("INVALID"); }
std::string getJSONType(const Convertible& value) { if (isUndefined(value)) { return "null"; } if (isArray(value)) { return "array"; } if (isObject(value)) { return "object"; } optional<mbgl::Value> v = toValue(value); // Since we've already checked the non-atomic types above, value must then // be a string, number, or boolean -- thus, assume that the toValue() // conversion succeeds. assert(v); return v->match( [&] (const std::string&) { return "string"; }, [&] (bool) { return "boolean"; }, [&] (auto) { return "number"; } ); }
void SmallerEqualsToCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { double number1 = atof(variable1.getValue().c_str()); double number2 = atof(variable2.getValue().c_str()); if (number1 <= number2) { vm.setReturnValue("true"); } else { vm.setReturnValue("false"); } vm.setReturnToken(IToken::TYPE_FACT); } else { // Exception "cannot compare different types than numbers" throwCustomError("cannot compare " + variable1.getValue() + " with " + variable2.getValue(), vm, supergeheimeToken); return; } }