V8 to achieve '==' and '==='

FK V8
FK V8
FK V8

Type* OperationTyper::SameValue(Type* lhs, Type* rhs) {
  if (!JSType(lhs)->Maybe(JSType(rhs))) return singleton_false();
  if (lhs->Is(Type::NaN())) {
    if (rhs->Is(Type::NaN())) return singleton_true();
    if (!rhs->Maybe(Type::NaN())) return singleton_false();
  } else if (rhs->Is(Type::NaN())) {
    if (!lhs->Maybe(Type::NaN())) return singleton_false();
  }
  if (lhs->Is(Type::MinusZero())) {
    if (rhs->Is(Type::MinusZero())) return singleton_true();
    if (!rhs->Maybe(Type::MinusZero())) return singleton_false();
  } else if (rhs->Is(Type::MinusZero())) {
    if (!lhs->Maybe(Type::MinusZero())) return singleton_false();
  }
  if (lhs->Is(Type::OrderedNumber()) && rhs->Is(Type::OrderedNumber()) &&
      (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) {
    return singleton_false();
  }
  return Type::Boolean();
}

Type* OperationTyper::StrictEqual(Type* lhs, Type* rhs) {
  if (!JSType(lhs)->Maybe(JSType(rhs))) return singleton_false();
  if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return singleton_false();
  if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) &&
      (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) {
    return singleton_false();
  }
  if ((lhs->Is(Type::Hole()) || rhs->Is(Type::Hole())) && !lhs->Maybe(rhs)) {
    return singleton_false();
  }
  if (lhs->IsHeapConstant() && rhs->Is(lhs)) {
    // Types are equal and are inhabited only by a single semantic value,
    // which is not nan due to the earlier check.
    return singleton_true();
  }
  return Type::Boolean();
}

你可能感兴趣的:(V8 to achieve '==' and '===')