| 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 22 matching lines...) Expand all Loading... |
| 33 #include "modules/indexeddb/IDBDatabase.h" | 33 #include "modules/indexeddb/IDBDatabase.h" |
| 34 | 34 |
| 35 namespace WebCore { | 35 namespace WebCore { |
| 36 | 36 |
| 37 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) | 37 PassRefPtr<IDBKeyRange> IDBKeyRange::create(PassRefPtr<IDBKey> prpKey) |
| 38 { | 38 { |
| 39 RefPtr<IDBKey> key = prpKey; | 39 RefPtr<IDBKey> key = prpKey; |
| 40 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); | 40 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 PassRefPtr<IDBKeyRange> IDBKeyRange::fromScriptValue(ExecutionContext* context,
const ScriptValue& value, ExceptionState& es) | 43 PassRefPtr<IDBKeyRange> IDBKeyRange::fromScriptValue(ExecutionContext* context,
const ScriptValue& value, ExceptionState& exceptionState) |
| 44 { | 44 { |
| 45 DOMRequestState requestState(context); | 45 DOMRequestState requestState(context); |
| 46 if (value.isUndefined() || value.isNull()) | 46 if (value.isUndefined() || value.isNull()) |
| 47 return 0; | 47 return 0; |
| 48 | 48 |
| 49 RefPtr<IDBKeyRange> range = scriptValueToIDBKeyRange(&requestState, value); | 49 RefPtr<IDBKeyRange> range = scriptValueToIDBKeyRange(&requestState, value); |
| 50 if (range) | 50 if (range) |
| 51 return range.release(); | 51 return range.release(); |
| 52 | 52 |
| 53 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, value); | 53 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, value); |
| 54 if (!key || !key->isValid()) { | 54 if (!key || !key->isValid()) { |
| 55 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 55 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 56 return 0; | 56 return 0; |
| 57 } | 57 } |
| 58 | 58 |
| 59 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); | 59 return adoptRef(new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed
)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 IDBKeyRange::IDBKeyRange(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, Low
erBoundType lowerType, UpperBoundType upperType) | 62 IDBKeyRange::IDBKeyRange(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, Low
erBoundType lowerType, UpperBoundType upperType) |
| 63 : m_lower(lower) | 63 : m_lower(lower) |
| 64 , m_upper(upper) | 64 , m_upper(upper) |
| 65 , m_lowerType(lowerType) | 65 , m_lowerType(lowerType) |
| 66 , m_upperType(upperType) | 66 , m_upperType(upperType) |
| 67 { | 67 { |
| 68 ScriptWrappable::init(this); | 68 ScriptWrappable::init(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ScriptValue IDBKeyRange::lowerValue(ExecutionContext* context) const | 71 ScriptValue IDBKeyRange::lowerValue(ExecutionContext* context) const |
| 72 { | 72 { |
| 73 DOMRequestState requestState(context); | 73 DOMRequestState requestState(context); |
| 74 return idbKeyToScriptValue(&requestState, m_lower); | 74 return idbKeyToScriptValue(&requestState, m_lower); |
| 75 } | 75 } |
| 76 | 76 |
| 77 ScriptValue IDBKeyRange::upperValue(ExecutionContext* context) const | 77 ScriptValue IDBKeyRange::upperValue(ExecutionContext* context) const |
| 78 { | 78 { |
| 79 DOMRequestState requestState(context); | 79 DOMRequestState requestState(context); |
| 80 return idbKeyToScriptValue(&requestState, m_upper); | 80 return idbKeyToScriptValue(&requestState, m_upper); |
| 81 } | 81 } |
| 82 | 82 |
| 83 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionSt
ate& es) | 83 PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpKey, ExceptionSt
ate& exceptionState) |
| 84 { | 84 { |
| 85 RefPtr<IDBKey> key = prpKey; | 85 RefPtr<IDBKey> key = prpKey; |
| 86 if (!key || !key->isValid()) { | 86 if (!key || !key->isValid()) { |
| 87 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 87 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 88 return 0; | 88 return 0; |
| 89 } | 89 } |
| 90 | 90 |
| 91 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 91 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
| 92 } | 92 } |
| 93 | 93 |
| 94 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ExecutionContext* context, const Scrip
tValue& keyValue, ExceptionState& es) | 94 PassRefPtr<IDBKeyRange> IDBKeyRange::only(ExecutionContext* context, const Scrip
tValue& keyValue, ExceptionState& exceptionState) |
| 95 { | 95 { |
| 96 DOMRequestState requestState(context); | 96 DOMRequestState requestState(context); |
| 97 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); | 97 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue); |
| 98 if (!key || !key->isValid()) { | 98 if (!key || !key->isValid()) { |
| 99 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 99 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 100 return 0; | 100 return 0; |
| 101 } | 101 } |
| 102 | 102 |
| 103 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); | 103 return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed); |
| 104 } | 104 } |
| 105 | 105 |
| 106 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ExecutionContext* context, const
ScriptValue& boundValue, bool open, ExceptionState& es) | 106 PassRefPtr<IDBKeyRange> IDBKeyRange::lowerBound(ExecutionContext* context, const
ScriptValue& boundValue, bool open, ExceptionState& exceptionState) |
| 107 { | 107 { |
| 108 DOMRequestState requestState(context); | 108 DOMRequestState requestState(context); |
| 109 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 109 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
| 110 if (!bound || !bound->isValid()) { | 110 if (!bound || !bound->isValid()) { |
| 111 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 111 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 112 return 0; | 112 return 0; |
| 113 } | 113 } |
| 114 | 114 |
| 115 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); | 115 return IDBKeyRange::create(bound, 0, open ? LowerBoundOpen : LowerBoundClose
d, UpperBoundOpen); |
| 116 } | 116 } |
| 117 | 117 |
| 118 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ExecutionContext* context, const
ScriptValue& boundValue, bool open, ExceptionState& es) | 118 PassRefPtr<IDBKeyRange> IDBKeyRange::upperBound(ExecutionContext* context, const
ScriptValue& boundValue, bool open, ExceptionState& exceptionState) |
| 119 { | 119 { |
| 120 DOMRequestState requestState(context); | 120 DOMRequestState requestState(context); |
| 121 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); | 121 RefPtr<IDBKey> bound = scriptValueToIDBKey(&requestState, boundValue); |
| 122 if (!bound || !bound->isValid()) { | 122 if (!bound || !bound->isValid()) { |
| 123 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 123 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 124 return 0; | 124 return 0; |
| 125 } | 125 } |
| 126 | 126 |
| 127 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); | 127 return IDBKeyRange::create(0, bound, LowerBoundOpen, open ? UpperBoundOpen :
UpperBoundClosed); |
| 128 } | 128 } |
| 129 | 129 |
| 130 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ExecutionContext* context, const Scri
ptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool upperOp
en, ExceptionState& es) | 130 PassRefPtr<IDBKeyRange> IDBKeyRange::bound(ExecutionContext* context, const Scri
ptValue& lowerValue, const ScriptValue& upperValue, bool lowerOpen, bool upperOp
en, ExceptionState& exceptionState) |
| 131 { | 131 { |
| 132 DOMRequestState requestState(context); | 132 DOMRequestState requestState(context); |
| 133 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); | 133 RefPtr<IDBKey> lower = scriptValueToIDBKey(&requestState, lowerValue); |
| 134 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); | 134 RefPtr<IDBKey> upper = scriptValueToIDBKey(&requestState, upperValue); |
| 135 | 135 |
| 136 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { | 136 if (!lower || !lower->isValid() || !upper || !upper->isValid()) { |
| 137 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); | 137 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 138 return 0; | 138 return 0; |
| 139 } | 139 } |
| 140 if (upper->isLessThan(lower.get())) { | 140 if (upper->isLessThan(lower.get())) { |
| 141 es.throwDOMException(DataError, "The lower key is greater than the upper
key."); | 141 exceptionState.throwDOMException(DataError, "The lower key is greater th
an the upper key."); |
| 142 return 0; | 142 return 0; |
| 143 } | 143 } |
| 144 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { | 144 if (upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) { |
| 145 es.throwDOMException(DataError, "The lower key and upper key are equal a
nd one of the bounds is open."); | 145 exceptionState.throwDOMException(DataError, "The lower key and upper key
are equal and one of the bounds is open."); |
| 146 return 0; | 146 return 0; |
| 147 } | 147 } |
| 148 | 148 |
| 149 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); | 149 return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerB
oundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool IDBKeyRange::isOnlyKey() const | 152 bool IDBKeyRange::isOnlyKey() const |
| 153 { | 153 { |
| 154 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) | 154 if (m_lowerType != LowerBoundClosed || m_upperType != UpperBoundClosed) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 ASSERT(m_lower); | 157 ASSERT(m_lower); |
| 158 ASSERT(m_upper); | 158 ASSERT(m_upper); |
| 159 return m_lower->isEqual(m_upper.get()); | 159 return m_lower->isEqual(m_upper.get()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace WebCore | 162 } // namespace WebCore |
| OLD | NEW |