Exemplo n.º 1
0
bool
IDBKeyRange::Includes(JSContext* aCx,
                      JS::Handle<JS::Value> aValue,
                      ErrorResult& aRv) const
{
  Key key;
  aRv = GetKeyFromJSVal(aCx, aValue, key);
  if (aRv.Failed()) {
    return false;
  }

  MOZ_ASSERT(!(Lower().IsUnset() && Upper().IsUnset()));
  MOZ_ASSERT_IF(IsOnly(),
    !Lower().IsUnset() && !LowerOpen() &&
    Lower() == Upper() && LowerOpen() == UpperOpen());

  if (!Lower().IsUnset()) {
    switch (Key::CompareKeys(Lower(), key)) {
    case 1:
      return false;
    case 0:
      // Identical keys.
      return !LowerOpen();
    case -1:
      if (IsOnly()) {
        return false;
      }
      break;
    default:
      MOZ_CRASH();
    }
  }

  if (!Upper().IsUnset()) {
    switch (Key::CompareKeys(key, Upper())) {
    case 1:
      return false;
    case 0:
      // Identical keys.
      return !UpperOpen();
    case -1:
      break;
    }
  }

  return true;
}
Exemplo n.º 2
0
void
IDBKeyRange::ToSerialized(SerializedKeyRange& aKeyRange) const
{
  aKeyRange.lowerOpen() = LowerOpen();
  aKeyRange.upperOpen() = UpperOpen();
  aKeyRange.isOnly() = IsOnly();

  aKeyRange.lower() = Lower();
  if (!IsOnly()) {
    aKeyRange.upper() = Upper();
  }
}
Exemplo n.º 3
0
bool
IDBKeyRange::Includes(JSContext* aCx,
                      JS::Handle<JS::Value> aValue,
                      ErrorResult& aRv) const
{
  Key key;
  aRv = GetKeyFromJSVal(aCx, aValue, key);
  if (aRv.Failed()) {
    return false;
  }

  switch (Key::CompareKeys(Lower(), key)) {
  case 1:
    return false;
  case 0:
    // Identical keys.
    if (LowerOpen()) {
      return false;
    }
    break;
  case -1:
    if (IsOnly()) {
      return false;
    }
    break;
  default:
    MOZ_CRASH();
  }

  if (!IsOnly()) {
    switch (Key::CompareKeys(key, Upper())) {
    case 1:
      return false;
    case 0:
      // Identical keys.
      if (UpperOpen()) {
        return false;
      }
      break;
    case -1:
      break;
    }
  } else {
    MOZ_ASSERT(key == Lower());
  }

  return true;
}
Exemplo n.º 4
0
void
IDBKeyRange::GetBindingClause(const nsACString& aKeyColumnName,
                              nsACString& _retval) const
{
  NS_NAMED_LITERAL_CSTRING(andStr, " AND ");
  NS_NAMED_LITERAL_CSTRING(spacecolon, " :");
  NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");

  if (IsOnly()) {
    // Both keys are set and they're equal.
    _retval = andStr + aKeyColumnName + NS_LITERAL_CSTRING(" =") +
              spacecolon + lowerKey;
    return;
  }

  nsAutoCString clause;

  if (!Lower().IsUnset()) {
    // Lower key is set.
    clause.Append(andStr + aKeyColumnName);
    clause.AppendLiteral(" >");
    if (!LowerOpen()) {
      clause.Append('=');
    }
    clause.Append(spacecolon + lowerKey);
  }

  if (!Upper().IsUnset()) {
    // Upper key is set.
    clause.Append(andStr + aKeyColumnName);
    clause.AppendLiteral(" <");
    if (!UpperOpen()) {
      clause.Append('=');
    }
    clause.Append(spacecolon + NS_LITERAL_CSTRING("upper_key"));
  }

  _retval = clause;
}