TriState Value::asTriState() const { switch (opcode()) { case Const32: return triState(!!asInt32()); case Const64: return triState(!!asInt64()); case ConstDouble: // Use "!= 0" to really emphasize what this mean with respect to NaN and such. return triState(asDouble() != 0); default: return MixedTriState; } }
TriState ConstFloatValue::equalOrUnorderedConstant(const Value* other) const { if (std::isnan(m_value)) return TrueTriState; if (!other->hasFloat()) return MixedTriState; float otherValue = other->asFloat(); return triState(std::isunordered(m_value, otherValue) || m_value == otherValue); }
static TriState equalToStringImpl(JSValue value, StringImpl* stringImpl) { if (!value.isString()) return FalseTriState; JSString* jsString = asString(value); const StringImpl* string = jsString->tryGetValueImpl(); if (!string) return MixedTriState; return triState(WTF::equal(stringImpl, string)); }
TriState LazyJSValue::strictEqual(const LazyJSValue& other) const { switch (m_kind) { case KnownValue: switch (other.m_kind) { case KnownValue: return JSValue::pureStrictEqual(value(), other.value()); case SingleCharacterString: return equalToSingleCharacter(value(), other.character()); case KnownStringImpl: return equalToStringImpl(value(), other.stringImpl()); } break; case SingleCharacterString: switch (other.m_kind) { case SingleCharacterString: return triState(character() == other.character()); case KnownStringImpl: if (other.stringImpl()->length() != 1) return FalseTriState; return triState(other.stringImpl()->at(0) == character()); default: return other.strictEqual(*this); } break; case KnownStringImpl: switch (other.m_kind) { case KnownStringImpl: return triState(WTF::equal(stringImpl(), other.stringImpl())); default: return other.strictEqual(*this); } break; } RELEASE_ASSERT_NOT_REACHED(); return FalseTriState; }
static TriState equalToSingleCharacter(JSValue value, UChar character) { if (!value.isString()) return FalseTriState; JSString* jsString = asString(value); if (jsString->length() != 1) return FalseTriState; const StringImpl* string = jsString->tryGetValueImpl(); if (!string) return MixedTriState; return triState(string->at(0) == character); }
TriState ConstFloatValue::greaterEqualConstant(const Value* other) const { if (!other->hasFloat()) return MixedTriState; return triState(m_value >= other->asFloat()); }
TriState ConstFloatValue::lessThanConstant(const Value* other) const { if (!other->hasFloat()) return MixedTriState; return triState(m_value < other->asFloat()); }
TriState ConstDoubleValue::greaterEqualConstant(Value* other) const { if (!other->hasDouble()) return MixedTriState; return triState(m_value >= other->asDouble()); }
TriState ConstDoubleValue::lessThanConstant(Value* other) const { if (!other->hasDouble()) return MixedTriState; return triState(m_value < other->asDouble()); }
TriState ConstDoubleValue::lessEqualConstant(const Value* other) const { if (!other->hasDouble()) return MixedTriState; return triState(m_value <= other->asDouble()); }
TriState ConstDoubleValue::greaterThanConstant(const Value* other) const { if (!other->hasDouble()) return MixedTriState; return triState(m_value > other->asDouble()); }