This source file includes following definitions.
- fromScriptValue
- m_upperType
- lowerValue
- upperValue
- only
- only
- lowerBound
- upperBound
- bound
#include "config.h"
#include "modules/indexeddb/IDBKeyRange.h"
#include "bindings/v8/DOMRequestState.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/IDBBindingUtilities.h"
#include "core/dom/ExceptionCode.h"
#include "modules/indexeddb/IDBDatabase.h"
namespace WebCore {
PassRefPtr<IDBKeyRange> IDBKeyRange::fromScriptValue(ExecutionContext* context, const ScriptValue& value, ExceptionState& exceptionState)
{
DOMRequestState requestState(context);
if (value.isUndefined() || value.isNull())
return nullptr;
RefPtr<IDBKeyRange> range = scriptValueToIDBKeyRange(&requestState, value);
if (range)
return range.release();
RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, value);
if (!key || !key->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed));
}
IDBKeyRange::IDBKeyRange(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, LowerBoundType lowerType, UpperBoundType upperType)
: m_lower(lower)
, m_upper(upper)
, m_lowerType(lowerType)
, m_upperType(upperType)
{
ScriptWrappable::init(this);
}
ScriptValue IDBKeyRange::lowerValue(ExecutionContext* context) const
{
DOMRequestState requestState(context);
return idbKeyToScriptValue(&requestState, m_lower);
}
ScriptValue IDBKeyRange::upperValue(ExecutionContext* context) const
{
DOMRequestState requestState(context);
return idbKeyToScriptValue(&requestState, m_upper);
}
PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionState& exceptionState)
{
RefPtr<IDBKey> key = prpKey;
if (!key || !key->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed);
}
PassRefPtr<IDBKeyRange> IDBKeyRange::only(ExecutionContext* context, const ScriptValue& keyValue, ExceptionState& exceptionState)
{
DOMRequestState requestState(context);
RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue);
if (!key || !key->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed);
}
PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ExecutionContext* context, const ScriptValue& boundValue, bool open, ExceptionState& exceptionState)
{
DOMRequestState requestState(context);
RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue);
if (!bound || !bound->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
return IDBKeyRange::create(bound, nullptr, open ? LowerBoundOpen : LowerBoundClosed, UpperBoundOpen);
}
PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ExecutionContext* context, const ScriptValue& boundValue, bool open, ExceptionState& exceptionState)
{
DOMRequestState requestState(context);
RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue);
if (!bound || !bound->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
return IDBKeyRange::create(nullptr, bound, LowerBoundOpen, open ? UpperBoundOpen : UpperBoundClosed);
}
PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ExecutionContext* context, const ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool upperOpen, ExceptionState& exceptionState)
{
DOMRequestState requestState(context);
RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue);
RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue);
if (!lower || !lower->isValid() || !upper || !upper->isValid()) {
exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
return nullptr;
}
if (upper->isLessThan(lower.get())) {
exceptionState.throwDOMException(DataError, "The lower key is greater than the upper key.");
return nullptr;
}
if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) {
exceptionState.throwDOMException(DataError, "The lower key and upper key are equal and one of the bounds is open.");
return nullptr;
}
return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerBoundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed);
}
}