| 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 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/IDBBindingUtilities.h" | 31 #include "bindings/v8/IDBBindingUtilities.h" |
| 31 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 32 #include "modules/indexeddb/IDBKey.h" | 33 #include "modules/indexeddb/IDBKey.h" |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) | 37 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) |
| 37 { | 38 { |
| 38 RefPtr<IDBKey> key = prpKey; | 39 RefPtr<IDBKey> key = prpKey; |
| 39 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); | 40 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 DOMRequestState requestState(context); | 54 DOMRequestState requestState(context); |
| 54 return idbKeyToScriptValue(&requestState, m_lower); | 55 return idbKeyToScriptValue(&requestState, m_lower); |
| 55 } | 56 } |
| 56 | 57 |
| 57 ScriptValue IDBKeyRange::upperValue(ScriptExecutionContext* context) const | 58 ScriptValue IDBKeyRange::upperValue(ScriptExecutionContext* context) const |
| 58 { | 59 { |
| 59 DOMRequestState requestState(context); | 60 DOMRequestState requestState(context); |
| 60 return idbKeyToScriptValue(&requestState, m_upper); | 61 return idbKeyToScriptValue(&requestState, m_upper); |
| 61 } | 62 } |
| 62 | 63 |
| 63 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionCo
de& ec) | 64 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionSt
ate& es) |
| 64 { | 65 { |
| 65 RefPtr<IDBKey> key = prpKey; | 66 RefPtr<IDBKey> key = prpKey; |
| 66 if (!key || !key->isValid()) { | 67 if (!key || !key->isValid()) { |
| 67 ec = DataError; | 68 es.throwDOMException(DataError); |
| 68 return 0; | 69 return 0; |
| 69 } | 70 } |
| 70 | 71 |
| 71 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 72 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
| 72 } | 73 } |
| 73 | 74 |
| 74 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext* context, const
ScriptValue& keyValue, ExceptionCode& ec) | 75 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ScriptExecutionContext* context, const
ScriptValue& keyValue, ExceptionState& es) |
| 75 { | 76 { |
| 76 DOMRequestState requestState(context); | 77 DOMRequestState requestState(context); |
| 77 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); | 78 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); |
| 78 if (!key || !key->isValid()) { | 79 if (!key || !key->isValid()) { |
| 79 ec = DataError; | 80 es.throwDOMException(DataError); |
| 80 return 0; | 81 return 0; |
| 81 } | 82 } |
| 82 | 83 |
| 83 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 84 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
| 84 } | 85 } |
| 85 | 86 |
| 86 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionCode& ec) | 87 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) |
| 87 { | 88 { |
| 88 DOMRequestState requestState(context); | 89 DOMRequestState requestState(context); |
| 89 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 90 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
| 90 if (!bound || !bound->isValid()) { | 91 if (!bound || !bound->isValid()) { |
| 91 ec = DataError; | 92 es.throwDOMException(DataError); |
| 92 return 0; | 93 return 0; |
| 93 } | 94 } |
| 94 | 95 |
| 95 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); | 96 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); |
| 96 } | 97 } |
| 97 | 98 |
| 98 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionCode& ec) | 99 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ScriptExecutionContext* context,
const ScriptValue& boundValue, bool open, ExceptionState& es) |
| 99 { | 100 { |
| 100 DOMRequestState requestState(context); | 101 DOMRequestState requestState(context); |
| 101 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 102 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
| 102 if (!bound || !bound->isValid()) { | 103 if (!bound || !bound->isValid()) { |
| 103 ec = DataError; | 104 es.throwDOMException(DataError); |
| 104 return 0; | 105 return 0; |
| 105 } | 106 } |
| 106 | 107 |
| 107 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); | 108 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); |
| 108 } | 109 } |
| 109 | 110 |
| 110 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ScriptExecutionContext* context, cons
t ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool u
pperOpen, ExceptionCode& ec) | 111 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ScriptExecutionContext* context, cons
t ScriptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool u
pperOpen, ExceptionState& es) |
| 111 { | 112 { |
| 112 DOMRequestState requestState(context); | 113 DOMRequestState requestState(context); |
| 113 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); | 114 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); |
| 114 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); | 115 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); |
| 115 | 116 |
| 116 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { | 117 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { |
| 117 ec = DataError; | 118 es.throwDOMException(DataError); |
| 118 return 0; | 119 return 0; |
| 119 } | 120 } |
| 120 if (upper->isLessThan(lower.get())) { | 121 if (upper->isLessThan(lower.get())) { |
| 121 ec = DataError; | 122 es.throwDOMException(DataError); |
| 122 return 0; | 123 return 0; |
| 123 } | 124 } |
| 124 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { | 125 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { |
| 125 ec = DataError; | 126 es.throwDOMException(DataError); |
| 126 return 0; | 127 return 0; |
| 127 } | 128 } |
| 128 | 129 |
| 129 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); | 130 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); |
| 130 } | 131 } |
| 131 | 132 |
| 132 bool IDBKeyRange::isOnlyKey() const | 133 bool IDBKeyRange::isOnlyKey() const |
| 133 { | 134 { |
| 134 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) | 135 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) |
| 135 return false; | 136 return false; |
| 136 | 137 |
| 137 ASSERT(m_lower); | 138 ASSERT(m_lower); |
| 138 ASSERT(m_upper); | 139 ASSERT(m_upper); |
| 139 return m_lower->isEqual(m_upper.get()); | 140 return m_lower->isEqual(m_upper.get()); |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace WebCore | 143 } // namespace WebCore |
| OLD | NEW |