2010-06-23 12:46:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 12:32:37 -07:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "IDBKeyRange.h"
|
|
|
|
|
2010-11-10 15:26:00 -08:00
|
|
|
#include "Key.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-09-28 04:25:46 -07:00
|
|
|
#include "mozilla/dom/IDBKeyRangeBinding.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-08-02 02:38:49 -07:00
|
|
|
namespace {
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsresult
|
2011-11-03 08:57:30 -07:00
|
|
|
GetKeyFromJSVal(JSContext* aCx,
|
2014-01-23 11:49:40 -08:00
|
|
|
JS::Handle<JS::Value> aVal,
|
2011-11-03 08:57:30 -07:00
|
|
|
Key& aKey,
|
|
|
|
bool aAllowUnset = false)
|
|
|
|
{
|
|
|
|
nsresult rv = aKey.SetFromJSVal(aCx, aVal);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM_INDEXEDDB);
|
2011-11-03 08:57:30 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aKey.IsUnset() && !aAllowUnset) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-02 02:38:49 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBKeyRange::IDBKeyRange(nsISupports* aGlobal,
|
|
|
|
bool aLowerOpen,
|
|
|
|
bool aUpperOpen,
|
|
|
|
bool aIsOnly)
|
|
|
|
: mGlobal(aGlobal)
|
2015-01-13 23:59:06 -08:00
|
|
|
, mCachedLowerVal(JS::UndefinedValue())
|
|
|
|
, mCachedUpperVal(JS::UndefinedValue())
|
2014-09-26 16:21:57 -07:00
|
|
|
, mLowerOpen(aLowerOpen)
|
|
|
|
, mUpperOpen(aUpperOpen)
|
|
|
|
, mIsOnly(aIsOnly)
|
|
|
|
, mHaveCachedLowerVal(false)
|
|
|
|
, mHaveCachedUpperVal(false)
|
|
|
|
, mRooted(false)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
mOwningThread = PR_GetCurrentThread();
|
|
|
|
#endif
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBKeyRange::~IDBKeyRange()
|
|
|
|
{
|
|
|
|
DropJSObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBKeyRange::AssertIsOnOwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// static
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult
|
|
|
|
IDBKeyRange::FromJSVal(JSContext* aCx,
|
2014-01-23 11:49:40 -08:00
|
|
|
JS::Handle<JS::Value> aVal,
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBKeyRange** aKeyRange)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2011-11-03 08:57:30 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange;
|
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aVal.isNullOrUndefined()) {
|
2011-11-03 08:57:30 -07:00
|
|
|
// undefined and null returns no IDBKeyRange.
|
2013-09-28 04:25:46 -07:00
|
|
|
keyRange.forget(aKeyRange);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-08-02 02:38:49 -07:00
|
|
|
|
2013-11-11 00:04:41 -08:00
|
|
|
JS::Rooted<JSObject*> obj(aCx, aVal.isObject() ? &aVal.toObject() : nullptr);
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aVal.isPrimitive() || JS_IsArrayObject(aCx, obj) ||
|
|
|
|
JS_ObjectIsDate(aCx, obj)) {
|
|
|
|
// A valid key returns an 'only' IDBKeyRange.
|
|
|
|
keyRange = new IDBKeyRange(nullptr, false, false, true);
|
2013-08-02 02:38:49 -07:00
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
nsresult rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2013-09-19 00:54:01 -07:00
|
|
|
}
|
2013-09-28 04:25:46 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
MOZ_ASSERT(aVal.isObject());
|
|
|
|
// An object is not permitted unless it's another IDBKeyRange.
|
2013-11-21 04:51:16 -08:00
|
|
|
if (NS_FAILED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) {
|
2013-09-28 04:25:46 -07:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
|
2013-09-19 00:54:01 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
keyRange.forget(aKeyRange);
|
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBKeyRange>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBKeyRange::FromSerialized(const SerializedKeyRange& aKeyRange)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<IDBKeyRange> keyRange =
|
2013-09-28 04:25:46 -07:00
|
|
|
new IDBKeyRange(nullptr, aKeyRange.lowerOpen(), aKeyRange.upperOpen(),
|
2012-06-01 10:21:12 -07:00
|
|
|
aKeyRange.isOnly());
|
|
|
|
keyRange->Lower() = aKeyRange.lower();
|
|
|
|
if (!keyRange->IsOnly()) {
|
|
|
|
keyRange->Upper() = aKeyRange.upper();
|
|
|
|
}
|
|
|
|
return keyRange.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBKeyRange::ToSerialized(SerializedKeyRange& aKeyRange) const
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
aKeyRange.lowerOpen() = LowerOpen();
|
|
|
|
aKeyRange.upperOpen() = UpperOpen();
|
2012-06-01 10:21:12 -07:00
|
|
|
aKeyRange.isOnly() = IsOnly();
|
|
|
|
|
|
|
|
aKeyRange.lower() = Lower();
|
|
|
|
if (!IsOnly()) {
|
|
|
|
aKeyRange.upper() = Upper();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IDBKeyRange::BindToStatement(mozIStorageStatement* aStatement) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStatement);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");
|
|
|
|
|
|
|
|
if (IsOnly()) {
|
|
|
|
return Lower().BindToStatement(aStatement, lowerKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!Lower().IsUnset()) {
|
|
|
|
rv = Lower().BindToStatement(aStatement, lowerKey);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Upper().IsUnset()) {
|
|
|
|
rv = Upper().BindToStatement(aStatement, NS_LITERAL_CSTRING("upper_key"));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBKeyRange)
|
2013-08-02 00:09:15 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBKeyRange)
|
2013-09-28 04:25:46 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange)
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedLowerVal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedUpperVal)
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange)
|
2013-09-28 04:25:46 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
2012-11-27 17:37:57 -08:00
|
|
|
tmp->DropJSObjects();
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBKeyRange)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBKeyRange)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBKeyRange)
|
|
|
|
|
2012-11-27 17:37:57 -08:00
|
|
|
void
|
|
|
|
IDBKeyRange::DropJSObjects()
|
2012-03-28 07:40:52 -07:00
|
|
|
{
|
2012-11-27 17:37:57 -08:00
|
|
|
if (!mRooted) {
|
|
|
|
return;
|
2012-03-28 07:40:52 -07:00
|
|
|
}
|
2014-09-26 16:21:57 -07:00
|
|
|
mCachedLowerVal.setUndefined();
|
|
|
|
mCachedUpperVal.setUndefined();
|
2012-11-27 17:37:57 -08:00
|
|
|
mHaveCachedLowerVal = false;
|
|
|
|
mHaveCachedUpperVal = false;
|
|
|
|
mRooted = false;
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-11-27 17:37:57 -08:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:56:42 -08:00
|
|
|
bool
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 07:13:32 -07:00
|
|
|
IDBKeyRange::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
|
2013-09-28 04:25:46 -07:00
|
|
|
{
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 07:13:32 -07:00
|
|
|
return IDBKeyRangeBinding::Wrap(aCx, this, aGivenProto, aReflector);
|
2013-09-28 04:25:46 -07:00
|
|
|
}
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
|
|
|
IDBKeyRange::GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveCachedLowerVal) {
|
|
|
|
if (!mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-11-03 08:57:30 -07:00
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
aRv = Lower().ToJSVal(aCx, mCachedLowerVal);
|
|
|
|
if (aRv.Failed()) {
|
2014-06-11 13:26:52 -07:00
|
|
|
return;
|
2013-09-28 04:25:46 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
|
|
|
|
mHaveCachedLowerVal = true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
JS::ExposeValueToActiveJS(mCachedLowerVal);
|
|
|
|
aResult.set(mCachedLowerVal);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
void
|
|
|
|
IDBKeyRange::GetUpper(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!mHaveCachedUpperVal) {
|
|
|
|
if (!mRooted) {
|
2013-08-16 13:10:17 -07:00
|
|
|
mozilla::HoldJSObjects(this);
|
2011-11-03 08:57:30 -07:00
|
|
|
mRooted = true;
|
|
|
|
}
|
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
aRv = Upper().ToJSVal(aCx, mCachedUpperVal);
|
|
|
|
if (aRv.Failed()) {
|
2014-06-11 13:26:52 -07:00
|
|
|
return;
|
2013-09-28 04:25:46 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
|
|
|
|
mHaveCachedUpperVal = true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:26:52 -07:00
|
|
|
JS::ExposeValueToActiveJS(mCachedUpperVal);
|
|
|
|
aResult.set(mCachedUpperVal);
|
2013-08-02 02:38:49 -07:00
|
|
|
}
|
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBKeyRange>
|
2014-06-16 09:52:00 -07:00
|
|
|
IDBKeyRange::Only(const GlobalObject& aGlobal,
|
2014-09-26 16:21:57 -07:00
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
ErrorResult& aRv)
|
2013-08-02 02:38:49 -07:00
|
|
|
{
|
2013-09-28 04:25:46 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange =
|
|
|
|
new IDBKeyRange(aGlobal.GetAsSupports(), false, false, true);
|
|
|
|
|
2014-06-16 09:52:00 -07:00
|
|
|
aRv = GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower());
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyRange.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<IDBKeyRange>
|
2014-06-16 09:52:00 -07:00
|
|
|
IDBKeyRange::LowerBound(const GlobalObject& aGlobal,
|
2014-09-26 16:21:57 -07:00
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
bool aOpen,
|
2013-11-11 00:04:41 -08:00
|
|
|
ErrorResult& aRv)
|
2013-09-28 04:25:46 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<IDBKeyRange> keyRange =
|
|
|
|
new IDBKeyRange(aGlobal.GetAsSupports(), aOpen, true, false);
|
|
|
|
|
2014-06-16 09:52:00 -07:00
|
|
|
aRv = GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower());
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyRange.forget();
|
2013-08-02 02:38:49 -07:00
|
|
|
}
|
|
|
|
|
2013-09-28 04:25:46 -07:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBKeyRange>
|
2014-06-16 09:52:00 -07:00
|
|
|
IDBKeyRange::UpperBound(const GlobalObject& aGlobal,
|
2014-09-26 16:21:57 -07:00
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
bool aOpen,
|
2013-11-11 00:04:41 -08:00
|
|
|
ErrorResult& aRv)
|
2013-09-28 04:25:46 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<IDBKeyRange> keyRange =
|
|
|
|
new IDBKeyRange(aGlobal.GetAsSupports(), true, aOpen, false);
|
2013-08-02 02:38:49 -07:00
|
|
|
|
2014-06-16 09:52:00 -07:00
|
|
|
aRv = GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Upper());
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyRange.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<IDBKeyRange>
|
2014-06-16 09:52:00 -07:00
|
|
|
IDBKeyRange::Bound(const GlobalObject& aGlobal,
|
2014-09-26 16:21:57 -07:00
|
|
|
JS::Handle<JS::Value> aLower,
|
|
|
|
JS::Handle<JS::Value> aUpper,
|
|
|
|
bool aLowerOpen,
|
|
|
|
bool aUpperOpen,
|
|
|
|
ErrorResult& aRv)
|
2013-08-02 02:38:49 -07:00
|
|
|
{
|
2013-09-28 04:25:46 -07:00
|
|
|
nsRefPtr<IDBKeyRange> keyRange =
|
|
|
|
new IDBKeyRange(aGlobal.GetAsSupports(), aLowerOpen, aUpperOpen, false);
|
|
|
|
|
2014-06-16 09:52:00 -07:00
|
|
|
aRv = GetKeyFromJSVal(aGlobal.Context(), aLower, keyRange->Lower());
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-16 09:52:00 -07:00
|
|
|
aRv = GetKeyFromJSVal(aGlobal.Context(), aUpper, keyRange->Upper());
|
2013-09-28 04:25:46 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyRange->Lower() > keyRange->Upper() ||
|
|
|
|
(keyRange->Lower() == keyRange->Upper() && (aLowerOpen || aUpperOpen))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyRange.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|