bool Parameter::checkValueIsTheSame(var newValue, var oldValue) { if (oldValue.isArray()) { if (!newValue.isArray()) return false; if (newValue.size() != oldValue.size()) return false; for (int i = 0; i < oldValue.size(); i++) if (oldValue[i] != newValue[i]) return false; return true; } return newValue == oldValue; }
Array<DrawableButton *> AppListComponent::createIconsFromJsonArray(const var &json) { Array<DrawableButton *> buttons; if (json.isArray()) { for (const auto &item : *json.getArray()) { auto name = item["name"]; auto shell = item["shell"]; auto iconPath = item["icon"]; if (name.isString() && shell.isString() && iconPath.isString()) { auto icon = createAndOwnIcon(name, iconPath, shell); if (icon) { buttons.add(icon); } } } } checkShowPageNav(); return buttons; }
bool compare::equality(var& x, var& y) { // 1. If Type(x) is the same as Type(y), then if (x.adapter->type == y.adapter->type) { // 1. If Type(x) is Undefined, return true. if (x.isUndefined()) return true; // 2. If Type(x) is Null, return true. if (x.isNull()) return true; // 3. If Type(x) is Number, then if (x.isNumber()) { // 1. If x is NaN, return false. // 2. If y is NaN, return false. // (TODO: NaN checks?) // 3. If x is the same Number value as y, return true. if (x.numberValue == y.numberValue) return true; // 4. If x is +0 and y is -0, return true. if (x.numberValue == +0 && y.numberValue == -0) return true; // 5. If x is -0 and y is +0, return true. if (x.numberValue == -0 && y.numberValue == +0) return true; // 6. Return false. return false; } // 4. If Type(x) is String, then return true if x and y are exactly the same sequence of characters // (same length and same characters in corresponding positions). Otherwise, return false. if (x.isString()) return x.stringValue == y.stringValue; // 5. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false. if (x.isBoolean()) return x.booleanValue == y.booleanValue; // 6. Return true if x and y refer to the same object. Otherwise, return false. if (x.isObject()) return x.objectValue == y.objectValue; if (x.isArray()) return x.arrayValue == y.arrayValue; return false; } // 2. If x is null and y is undefined, return true. if (x.isNull() && y.isUndefined()) return true; // 3. If x is undefined and y is null, return true. if (x.isUndefined() && y.isNull()) return true; // 4. If Type(x) is Number and Type(y) is String, // return the result of the comparison x == ToNumber(y). if (x.isNumber() && y.isString()) return x == (number) y; // 5. If Type(x) is String and Type(y) is Number, // return the result of the comparison ToNumber(x) == y. if (x.isString() && y.isNumber()) return (var) (number) x == y; // 6. If Type(x) is Boolean, // return the result of the comparison ToNumber(x) == y. if (x.isBoolean()) return (var) (number) x == y; // 7. If Type(y) is Boolean, // return the result of the comparison x == ToNumber(y). if (y.isBoolean()) return x == (number) y; // 8. If Type(x) is either String or Number and Type(y) is Object, // return the result of the comparison x == ToPrimitive(y). if ((x.isString() || x.isNumber()) && (y.isObject() || y.isArray())) return x == (string) y; // 9. If Type(x) is Object and Type(y) is either String or Number, // return the result of the comparison ToPrimitive(x) == y. if ((x.isObject() || x.isArray()) && (y.isString() || y.isNumber())) return (var) (string) x == y; // 10. Return false. return false; }
var compare::toPrimitive(var& x) { if (!(x.isArray() || x.isObject())) return x; return (string) x; }