| 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 "modules/indexeddb/IDBKeyRange.h" | 26 #include "modules/indexeddb/IDBKeyRange.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ToV8ForCore.h" | 29 #include "bindings/core/v8/ToV8ForCore.h" |
| 30 #include "bindings/modules/v8/ToV8ForModules.h" | 30 #include "bindings/modules/v8/ToV8ForModules.h" |
| 31 #include "bindings/modules/v8/V8BindingForModules.h" | 31 #include "bindings/modules/v8/V8BindingForModules.h" |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "core/dom/ExecutionContext.h" |
| 33 #include "modules/indexeddb/IDBDatabase.h" | 34 #include "modules/indexeddb/IDBDatabase.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 IDBKeyRange* IDBKeyRange::FromScriptValue(ExecutionContext* context, | 38 IDBKeyRange* IDBKeyRange::FromScriptValue(ExecutionContext* context, |
| 38 const ScriptValue& value, | 39 const ScriptValue& value, |
| 39 ExceptionState& exception_state) { | 40 ExceptionState& exception_state) { |
| 40 if (value.IsUndefined() || value.IsNull()) | 41 if (value.IsUndefined() || value.IsNull()) |
| 41 return nullptr; | 42 return nullptr; |
| 42 | 43 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return nullptr; | 88 return nullptr; |
| 88 } | 89 } |
| 89 | 90 |
| 90 return IDBKeyRange::Create(key, key, kLowerBoundClosed, kUpperBoundClosed); | 91 return IDBKeyRange::Create(key, key, kLowerBoundClosed, kUpperBoundClosed); |
| 91 } | 92 } |
| 92 | 93 |
| 93 IDBKeyRange* IDBKeyRange::only(ScriptState* script_state, | 94 IDBKeyRange* IDBKeyRange::only(ScriptState* script_state, |
| 94 const ScriptValue& key_value, | 95 const ScriptValue& key_value, |
| 95 ExceptionState& exception_state) { | 96 ExceptionState& exception_state) { |
| 96 IDBKey* key = | 97 IDBKey* key = |
| 97 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 98 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 98 key_value, exception_state); | 99 key_value, exception_state); |
| 99 if (exception_state.HadException()) | 100 if (exception_state.HadException()) |
| 100 return nullptr; | 101 return nullptr; |
| 101 if (!key || !key->IsValid()) { | 102 if (!key || !key->IsValid()) { |
| 102 exception_state.ThrowDOMException(kDataError, | 103 exception_state.ThrowDOMException(kDataError, |
| 103 IDBDatabase::kNotValidKeyErrorMessage); | 104 IDBDatabase::kNotValidKeyErrorMessage); |
| 104 return nullptr; | 105 return nullptr; |
| 105 } | 106 } |
| 106 | 107 |
| 107 return IDBKeyRange::Create(key, key, kLowerBoundClosed, kUpperBoundClosed); | 108 return IDBKeyRange::Create(key, key, kLowerBoundClosed, kUpperBoundClosed); |
| 108 } | 109 } |
| 109 | 110 |
| 110 IDBKeyRange* IDBKeyRange::lowerBound(ScriptState* script_state, | 111 IDBKeyRange* IDBKeyRange::lowerBound(ScriptState* script_state, |
| 111 const ScriptValue& bound_value, | 112 const ScriptValue& bound_value, |
| 112 bool open, | 113 bool open, |
| 113 ExceptionState& exception_state) { | 114 ExceptionState& exception_state) { |
| 114 IDBKey* bound = | 115 IDBKey* bound = |
| 115 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 116 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 116 bound_value, exception_state); | 117 bound_value, exception_state); |
| 117 if (exception_state.HadException()) | 118 if (exception_state.HadException()) |
| 118 return nullptr; | 119 return nullptr; |
| 119 if (!bound || !bound->IsValid()) { | 120 if (!bound || !bound->IsValid()) { |
| 120 exception_state.ThrowDOMException(kDataError, | 121 exception_state.ThrowDOMException(kDataError, |
| 121 IDBDatabase::kNotValidKeyErrorMessage); | 122 IDBDatabase::kNotValidKeyErrorMessage); |
| 122 return nullptr; | 123 return nullptr; |
| 123 } | 124 } |
| 124 | 125 |
| 125 return IDBKeyRange::Create(bound, nullptr, | 126 return IDBKeyRange::Create(bound, nullptr, |
| 126 open ? kLowerBoundOpen : kLowerBoundClosed, | 127 open ? kLowerBoundOpen : kLowerBoundClosed, |
| 127 kUpperBoundOpen); | 128 kUpperBoundOpen); |
| 128 } | 129 } |
| 129 | 130 |
| 130 IDBKeyRange* IDBKeyRange::upperBound(ScriptState* script_state, | 131 IDBKeyRange* IDBKeyRange::upperBound(ScriptState* script_state, |
| 131 const ScriptValue& bound_value, | 132 const ScriptValue& bound_value, |
| 132 bool open, | 133 bool open, |
| 133 ExceptionState& exception_state) { | 134 ExceptionState& exception_state) { |
| 134 IDBKey* bound = | 135 IDBKey* bound = |
| 135 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 136 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 136 bound_value, exception_state); | 137 bound_value, exception_state); |
| 137 if (exception_state.HadException()) | 138 if (exception_state.HadException()) |
| 138 return nullptr; | 139 return nullptr; |
| 139 if (!bound || !bound->IsValid()) { | 140 if (!bound || !bound->IsValid()) { |
| 140 exception_state.ThrowDOMException(kDataError, | 141 exception_state.ThrowDOMException(kDataError, |
| 141 IDBDatabase::kNotValidKeyErrorMessage); | 142 IDBDatabase::kNotValidKeyErrorMessage); |
| 142 return nullptr; | 143 return nullptr; |
| 143 } | 144 } |
| 144 | 145 |
| 145 return IDBKeyRange::Create(nullptr, bound, kLowerBoundOpen, | 146 return IDBKeyRange::Create(nullptr, bound, kLowerBoundOpen, |
| 146 open ? kUpperBoundOpen : kUpperBoundClosed); | 147 open ? kUpperBoundOpen : kUpperBoundClosed); |
| 147 } | 148 } |
| 148 | 149 |
| 149 IDBKeyRange* IDBKeyRange::bound(ScriptState* script_state, | 150 IDBKeyRange* IDBKeyRange::bound(ScriptState* script_state, |
| 150 const ScriptValue& lower_value, | 151 const ScriptValue& lower_value, |
| 151 const ScriptValue& upper_value, | 152 const ScriptValue& upper_value, |
| 152 bool lower_open, | 153 bool lower_open, |
| 153 bool upper_open, | 154 bool upper_open, |
| 154 ExceptionState& exception_state) { | 155 ExceptionState& exception_state) { |
| 155 IDBKey* lower = | 156 IDBKey* lower = |
| 156 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 157 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 157 lower_value, exception_state); | 158 lower_value, exception_state); |
| 158 if (exception_state.HadException()) | 159 if (exception_state.HadException()) |
| 159 return nullptr; | 160 return nullptr; |
| 160 if (!lower || !lower->IsValid()) { | 161 if (!lower || !lower->IsValid()) { |
| 161 exception_state.ThrowDOMException(kDataError, | 162 exception_state.ThrowDOMException(kDataError, |
| 162 IDBDatabase::kNotValidKeyErrorMessage); | 163 IDBDatabase::kNotValidKeyErrorMessage); |
| 163 return nullptr; | 164 return nullptr; |
| 164 } | 165 } |
| 165 | 166 |
| 166 IDBKey* upper = | 167 IDBKey* upper = |
| 167 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 168 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 168 upper_value, exception_state); | 169 upper_value, exception_state); |
| 169 if (exception_state.HadException()) | 170 if (exception_state.HadException()) |
| 170 return nullptr; | 171 return nullptr; |
| 171 if (!upper || !upper->IsValid()) { | 172 if (!upper || !upper->IsValid()) { |
| 172 exception_state.ThrowDOMException(kDataError, | 173 exception_state.ThrowDOMException(kDataError, |
| 173 IDBDatabase::kNotValidKeyErrorMessage); | 174 IDBDatabase::kNotValidKeyErrorMessage); |
| 174 return nullptr; | 175 return nullptr; |
| 175 } | 176 } |
| 176 | 177 |
| 177 if (upper->IsLessThan(lower)) { | 178 if (upper->IsLessThan(lower)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 | 189 |
| 189 return IDBKeyRange::Create(lower, upper, | 190 return IDBKeyRange::Create(lower, upper, |
| 190 lower_open ? kLowerBoundOpen : kLowerBoundClosed, | 191 lower_open ? kLowerBoundOpen : kLowerBoundClosed, |
| 191 upper_open ? kUpperBoundOpen : kUpperBoundClosed); | 192 upper_open ? kUpperBoundOpen : kUpperBoundClosed); |
| 192 } | 193 } |
| 193 | 194 |
| 194 bool IDBKeyRange::includes(ScriptState* script_state, | 195 bool IDBKeyRange::includes(ScriptState* script_state, |
| 195 const ScriptValue& key_value, | 196 const ScriptValue& key_value, |
| 196 ExceptionState& exception_state) { | 197 ExceptionState& exception_state) { |
| 197 IDBKey* key = | 198 IDBKey* key = |
| 198 ScriptValue::To<IDBKey*>(ToIsolate(script_state->GetExecutionContext()), | 199 ScriptValue::To<IDBKey*>(ToIsolate(ExecutionContext::From(script_state)), |
| 199 key_value, exception_state); | 200 key_value, exception_state); |
| 200 if (exception_state.HadException()) | 201 if (exception_state.HadException()) |
| 201 return false; | 202 return false; |
| 202 if (!key || !key->IsValid()) { | 203 if (!key || !key->IsValid()) { |
| 203 exception_state.ThrowDOMException(kDataError, | 204 exception_state.ThrowDOMException(kDataError, |
| 204 IDBDatabase::kNotValidKeyErrorMessage); | 205 IDBDatabase::kNotValidKeyErrorMessage); |
| 205 return false; | 206 return false; |
| 206 } | 207 } |
| 207 | 208 |
| 208 if (lower_) { | 209 if (lower_) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 223 return false; | 224 return false; |
| 224 } else { | 225 } else { |
| 225 if (c > 0) | 226 if (c > 0) |
| 226 return false; | 227 return false; |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 return true; | 230 return true; |
| 230 } | 231 } |
| 231 | 232 |
| 232 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |