OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "modules/indexeddb/IDBKeyRange.h" | 27 #include "modules/indexeddb/IDBKeyRange.h" |
28 | 28 |
29 #include "bindings/v8/DOMRequestState.h" | 29 #include "bindings/v8/DOMRequestState.h" |
30 #include "bindings/v8/ExceptionState.h" | 30 #include "bindings/v8/ExceptionState.h" |
31 #include "bindings/v8/IDBBindingUtilities.h" | 31 #include "bindings/v8/IDBBindingUtilities.h" |
32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "modules/indexeddb/IDBDatabase.h" |
33 #include "modules/indexeddb/IDBKey.h" | 34 #include "modules/indexeddb/IDBKey.h" |
34 | 35 |
35 namespace WebCore { | 36 namespace WebCore { |
36 | 37 |
37 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) | 38 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) |
38 { | 39 { |
39 RefPtr<IDBKey> key = prpKey; | 40 RefPtr<IDBKey> key = prpKey; |
40 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); | 41 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); |
41 } | 42 } |
42 | 43 |
(...skipping 15 matching lines...) Expand all Loading... |
58 ScriptValue IDBKeyRange::upperValue(ScriptExecutionContext* context) const | 59 ScriptValue IDBKeyRange::upperValue(ScriptExecutionContext* context) const |
59 { | 60 { |
60 DOMRequestState requestState(context); | 61 DOMRequestState requestState(context); |
61 return idbKeyToScriptValue(&requestState, m_upper); | 62 return idbKeyToScriptValue(&requestState, m_upper); |
62 } | 63 } |
63 | 64 |
64 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionSt
ate& es) | 65 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionSt
ate& es) |
65 { | 66 { |
66 RefPtr<IDBKey> key = prpKey; | 67 RefPtr<IDBKey> key = prpKey; |
67 if (!key || !key->isValid()) { | 68 if (!key || !key->isValid()) { |
68 es.throwDOMException(DataError); | 69 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
69 return 0; | 70 return 0; |
70 } | 71 } |
71 | 72 |
72 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 73 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
73 } | 74 } |
74 | 75 |
75 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext* context, const
ScriptValue& keyValue, ExceptionState& es) | 76 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext* context, const
ScriptValue& keyValue, ExceptionState& es) |
76 { | 77 { |
77 DOMRequestState requestState(context); | 78 DOMRequestState requestState(context); |
78 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); | 79 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); |
79 if (!key || !key->isValid()) { | 80 if (!key || !key->isValid()) { |
80 es.throwDOMException(DataError); | 81 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
81 return 0; | 82 return 0; |
82 } | 83 } |
83 | 84 |
84 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 85 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
85 } | 86 } |
86 | 87 |
87 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) | 88 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) |
88 { | 89 { |
89 DOMRequestState requestState(context); | 90 DOMRequestState requestState(context); |
90 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 91 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
91 if (!bound || !bound->isValid()) { | 92 if (!bound || !bound->isValid()) { |
92 es.throwDOMException(DataError); | 93 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
93 return 0; | 94 return 0; |
94 } | 95 } |
95 | 96 |
96 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); | 97 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); |
97 } | 98 } |
98 | 99 |
99 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) | 100 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) |
100 { | 101 { |
101 DOMRequestState requestState(context); | 102 DOMRequestState requestState(context); |
102 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 103 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
103 if (!bound || !bound->isValid()) { | 104 if (!bound || !bound->isValid()) { |
104 es.throwDOMException(DataError); | 105 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
105 return 0; | 106 return 0; |
106 } | 107 } |
107 | 108 |
108 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); | 109 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); |
109 } | 110 } |
110 | 111 |
111 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ScriptExecutionContext* context, cons
t ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool u
pperOpen, ExceptionState& es) | 112 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ScriptExecutionContext* context, cons
t ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool u
pperOpen, ExceptionState& es) |
112 { | 113 { |
113 DOMRequestState requestState(context); | 114 DOMRequestState requestState(context); |
114 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); | 115 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); |
115 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); | 116 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); |
116 | 117 |
117 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { | 118 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { |
118 es.throwDOMException(DataError); | 119 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
119 return 0; | 120 return 0; |
120 } | 121 } |
121 if (upper->isLessThan(lower.get())) { | 122 if (upper->isLessThan(lower.get())) { |
122 es.throwDOMException(DataError); | 123 es.throwDOMException(DataError, "The lower key is greater than the upper
key."); |
123 return 0; | 124 return 0; |
124 } | 125 } |
125 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { | 126 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { |
126 es.throwDOMException(DataError); | 127 es.throwDOMException(DataError, "The lower key and upper key are equal a
nd one of the bounds is open."); |
127 return 0; | 128 return 0; |
128 } | 129 } |
129 | 130 |
130 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); | 131 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); |
131 } | 132 } |
132 | 133 |
133 bool IDBKeyRange::isOnlyKey() const | 134 bool IDBKeyRange::isOnlyKey() const |
134 { | 135 { |
135 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) | 136 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) |
136 return false; | 137 return false; |
137 | 138 |
138 ASSERT(m_lower); | 139 ASSERT(m_lower); |
139 ASSERT(m_upper); | 140 ASSERT(m_upper); |
140 return m_lower->isEqual(m_upper.get()); | 141 return m_lower->isEqual(m_upper.get()); |
141 } | 142 } |
142 | 143 |
143 } // namespace WebCore | 144 } // namespace WebCore |
OLD | NEW |