Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBIndex.cpp

Issue 2808763007: IndexedDB: Clean up boilerplate when throwing TransactionInactiveError (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 exception_state.ThrowDOMException( 70 exception_state.ThrowDOMException(
71 kInvalidStateError, 71 kInvalidStateError,
72 IDBDatabase::kNotVersionChangeTransactionErrorMessage); 72 IDBDatabase::kNotVersionChangeTransactionErrorMessage);
73 return; 73 return;
74 } 74 }
75 if (IsDeleted()) { 75 if (IsDeleted()) {
76 exception_state.ThrowDOMException(kInvalidStateError, 76 exception_state.ThrowDOMException(kInvalidStateError,
77 IDBDatabase::kIndexDeletedErrorMessage); 77 IDBDatabase::kIndexDeletedErrorMessage);
78 return; 78 return;
79 } 79 }
80 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
81 exception_state.ThrowDOMException(
82 kTransactionInactiveError,
83 IDBDatabase::kTransactionFinishedErrorMessage);
84 return;
85 }
86 if (!transaction_->IsActive()) { 80 if (!transaction_->IsActive()) {
87 exception_state.ThrowDOMException( 81 exception_state.ThrowDOMException(kTransactionInactiveError,
88 kTransactionInactiveError, 82 transaction_->InactiveErrorMessage());
89 IDBDatabase::kTransactionInactiveErrorMessage);
90 return; 83 return;
91 } 84 }
92 85
93 if (this->name() == name) 86 if (this->name() == name)
94 return; 87 return;
95 if (object_store_->ContainsIndex(name)) { 88 if (object_store_->ContainsIndex(name)) {
96 exception_state.ThrowDOMException(kConstraintError, 89 exception_state.ThrowDOMException(kConstraintError,
97 IDBDatabase::kIndexNameTakenErrorMessage); 90 IDBDatabase::kIndexNameTakenErrorMessage);
98 return; 91 return;
99 } 92 }
(...skipping 21 matching lines...) Expand all
121 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, 114 IDBRequest* IDBIndex::openCursor(ScriptState* script_state,
122 const ScriptValue& range, 115 const ScriptValue& range,
123 const String& direction_string, 116 const String& direction_string,
124 ExceptionState& exception_state) { 117 ExceptionState& exception_state) {
125 IDB_TRACE("IDBIndex::openCursor"); 118 IDB_TRACE("IDBIndex::openCursor");
126 if (IsDeleted()) { 119 if (IsDeleted()) {
127 exception_state.ThrowDOMException(kInvalidStateError, 120 exception_state.ThrowDOMException(kInvalidStateError,
128 IDBDatabase::kIndexDeletedErrorMessage); 121 IDBDatabase::kIndexDeletedErrorMessage);
129 return nullptr; 122 return nullptr;
130 } 123 }
131 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
132 exception_state.ThrowDOMException(
133 kTransactionInactiveError,
134 IDBDatabase::kTransactionFinishedErrorMessage);
135 return nullptr;
136 }
137 if (!transaction_->IsActive()) { 124 if (!transaction_->IsActive()) {
138 exception_state.ThrowDOMException( 125 exception_state.ThrowDOMException(kTransactionInactiveError,
139 kTransactionInactiveError, 126 transaction_->InactiveErrorMessage());
140 IDBDatabase::kTransactionInactiveErrorMessage);
141 return nullptr; 127 return nullptr;
142 } 128 }
143 WebIDBCursorDirection direction = 129 WebIDBCursorDirection direction =
144 IDBCursor::StringToDirection(direction_string); 130 IDBCursor::StringToDirection(direction_string);
145 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 131 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
146 ExecutionContext::From(script_state), range, exception_state); 132 ExecutionContext::From(script_state), range, exception_state);
147 if (exception_state.HadException()) 133 if (exception_state.HadException())
148 return nullptr; 134 return nullptr;
149 135
150 if (!BackendDB()) { 136 if (!BackendDB()) {
(...skipping 19 matching lines...) Expand all
170 156
171 IDBRequest* IDBIndex::count(ScriptState* script_state, 157 IDBRequest* IDBIndex::count(ScriptState* script_state,
172 const ScriptValue& range, 158 const ScriptValue& range,
173 ExceptionState& exception_state) { 159 ExceptionState& exception_state) {
174 IDB_TRACE("IDBIndex::count"); 160 IDB_TRACE("IDBIndex::count");
175 if (IsDeleted()) { 161 if (IsDeleted()) {
176 exception_state.ThrowDOMException(kInvalidStateError, 162 exception_state.ThrowDOMException(kInvalidStateError,
177 IDBDatabase::kIndexDeletedErrorMessage); 163 IDBDatabase::kIndexDeletedErrorMessage);
178 return nullptr; 164 return nullptr;
179 } 165 }
180 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
181 exception_state.ThrowDOMException(
182 kTransactionInactiveError,
183 IDBDatabase::kTransactionFinishedErrorMessage);
184 return nullptr;
185 }
186 if (!transaction_->IsActive()) { 166 if (!transaction_->IsActive()) {
187 exception_state.ThrowDOMException( 167 exception_state.ThrowDOMException(kTransactionInactiveError,
188 kTransactionInactiveError, 168 transaction_->InactiveErrorMessage());
189 IDBDatabase::kTransactionInactiveErrorMessage);
190 return nullptr; 169 return nullptr;
191 } 170 }
192 171
193 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 172 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
194 ExecutionContext::From(script_state), range, exception_state); 173 ExecutionContext::From(script_state), range, exception_state);
195 if (exception_state.HadException()) 174 if (exception_state.HadException())
196 return nullptr; 175 return nullptr;
197 176
198 if (!BackendDB()) { 177 if (!BackendDB()) {
199 exception_state.ThrowDOMException(kInvalidStateError, 178 exception_state.ThrowDOMException(kInvalidStateError,
(...skipping 11 matching lines...) Expand all
211 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state, 190 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state,
212 const ScriptValue& range, 191 const ScriptValue& range,
213 const String& direction_string, 192 const String& direction_string,
214 ExceptionState& exception_state) { 193 ExceptionState& exception_state) {
215 IDB_TRACE("IDBIndex::openKeyCursor"); 194 IDB_TRACE("IDBIndex::openKeyCursor");
216 if (IsDeleted()) { 195 if (IsDeleted()) {
217 exception_state.ThrowDOMException(kInvalidStateError, 196 exception_state.ThrowDOMException(kInvalidStateError,
218 IDBDatabase::kIndexDeletedErrorMessage); 197 IDBDatabase::kIndexDeletedErrorMessage);
219 return nullptr; 198 return nullptr;
220 } 199 }
221 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
222 exception_state.ThrowDOMException(
223 kTransactionInactiveError,
224 IDBDatabase::kTransactionFinishedErrorMessage);
225 return nullptr;
226 }
227 if (!transaction_->IsActive()) { 200 if (!transaction_->IsActive()) {
228 exception_state.ThrowDOMException( 201 exception_state.ThrowDOMException(kTransactionInactiveError,
229 kTransactionInactiveError, 202 transaction_->InactiveErrorMessage());
230 IDBDatabase::kTransactionInactiveErrorMessage);
231 return nullptr; 203 return nullptr;
232 } 204 }
233 WebIDBCursorDirection direction = 205 WebIDBCursorDirection direction =
234 IDBCursor::StringToDirection(direction_string); 206 IDBCursor::StringToDirection(direction_string);
235 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 207 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
236 ExecutionContext::From(script_state), range, exception_state); 208 ExecutionContext::From(script_state), range, exception_state);
237 if (exception_state.HadException()) 209 if (exception_state.HadException())
238 return nullptr; 210 return nullptr;
239 if (!BackendDB()) { 211 if (!BackendDB()) {
240 exception_state.ThrowDOMException(kInvalidStateError, 212 exception_state.ThrowDOMException(kInvalidStateError,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 270
299 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state, 271 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state,
300 const ScriptValue& key, 272 const ScriptValue& key,
301 ExceptionState& exception_state, 273 ExceptionState& exception_state,
302 bool key_only) { 274 bool key_only) {
303 if (IsDeleted()) { 275 if (IsDeleted()) {
304 exception_state.ThrowDOMException(kInvalidStateError, 276 exception_state.ThrowDOMException(kInvalidStateError,
305 IDBDatabase::kIndexDeletedErrorMessage); 277 IDBDatabase::kIndexDeletedErrorMessage);
306 return nullptr; 278 return nullptr;
307 } 279 }
308 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
309 exception_state.ThrowDOMException(
310 kTransactionInactiveError,
311 IDBDatabase::kTransactionFinishedErrorMessage);
312 return nullptr;
313 }
314 if (!transaction_->IsActive()) { 280 if (!transaction_->IsActive()) {
315 exception_state.ThrowDOMException( 281 exception_state.ThrowDOMException(kTransactionInactiveError,
316 kTransactionInactiveError, 282 transaction_->InactiveErrorMessage());
317 IDBDatabase::kTransactionInactiveErrorMessage);
318 return nullptr; 283 return nullptr;
319 } 284 }
320 285
321 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 286 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
322 ExecutionContext::From(script_state), key, exception_state); 287 ExecutionContext::From(script_state), key, exception_state);
323 if (exception_state.HadException()) 288 if (exception_state.HadException())
324 return nullptr; 289 return nullptr;
325 if (!key_range) { 290 if (!key_range) {
326 exception_state.ThrowDOMException( 291 exception_state.ThrowDOMException(
327 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); 292 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage);
(...skipping 18 matching lines...) Expand all
346 ExceptionState& exception_state, 311 ExceptionState& exception_state,
347 bool key_only) { 312 bool key_only) {
348 if (!max_count) 313 if (!max_count)
349 max_count = std::numeric_limits<uint32_t>::max(); 314 max_count = std::numeric_limits<uint32_t>::max();
350 315
351 if (IsDeleted()) { 316 if (IsDeleted()) {
352 exception_state.ThrowDOMException(kInvalidStateError, 317 exception_state.ThrowDOMException(kInvalidStateError,
353 IDBDatabase::kIndexDeletedErrorMessage); 318 IDBDatabase::kIndexDeletedErrorMessage);
354 return nullptr; 319 return nullptr;
355 } 320 }
356 if (transaction_->IsFinished() || transaction_->IsFinishing()) {
357 exception_state.ThrowDOMException(
358 kTransactionInactiveError,
359 IDBDatabase::kTransactionFinishedErrorMessage);
360 return nullptr;
361 }
362 if (!transaction_->IsActive()) { 321 if (!transaction_->IsActive()) {
363 exception_state.ThrowDOMException( 322 exception_state.ThrowDOMException(kTransactionInactiveError,
364 kTransactionInactiveError, 323 transaction_->InactiveErrorMessage());
365 IDBDatabase::kTransactionInactiveErrorMessage);
366 return nullptr; 324 return nullptr;
367 } 325 }
368 326
369 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 327 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
370 ExecutionContext::From(script_state), range, exception_state); 328 ExecutionContext::From(script_state), range, exception_state);
371 if (exception_state.HadException()) 329 if (exception_state.HadException())
372 return nullptr; 330 return nullptr;
373 if (!BackendDB()) { 331 if (!BackendDB()) {
374 exception_state.ThrowDOMException(kInvalidStateError, 332 exception_state.ThrowDOMException(kInvalidStateError,
375 IDBDatabase::kDatabaseClosedErrorMessage); 333 IDBDatabase::kDatabaseClosedErrorMessage);
376 return nullptr; 334 return nullptr;
377 } 335 }
378 336
379 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 337 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this),
380 transaction_.Get()); 338 transaction_.Get());
381 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range, 339 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range,
382 max_count, key_only, 340 max_count, key_only,
383 request->CreateWebCallbacks().release()); 341 request->CreateWebCallbacks().release());
384 return request; 342 return request;
385 } 343 }
386 344
387 WebIDBDatabase* IDBIndex::BackendDB() const { 345 WebIDBDatabase* IDBIndex::BackendDB() const {
388 return transaction_->BackendDB(); 346 return transaction_->BackendDB();
389 } 347 }
390 348
391 } // namespace blink 349 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698