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

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp

Issue 1897253003: IndexedDB: Align exception priorities with Firefox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback: more cases, split files, better messages Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp
index c168f0a2ff7fe983074cb31fdf4c940e3dbd2c44..be3602a4c2e2a679cb55389f02c6b2bca0e8c3b5 100644
--- a/third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBCursor.cpp
@@ -94,18 +94,6 @@ IDBRequest* IDBCursor::update(ScriptState* scriptState, const ScriptValue& value
{
IDB_TRACE("IDBCursor::update");
- if (!m_gotValue) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
- return nullptr;
- }
- if (isKeyCursor()) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMessage);
- return nullptr;
- }
- if (isDeleted()) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
- return nullptr;
- }
if (m_transaction->isFinished() || m_transaction->isFinishing()) {
exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
return nullptr;
@@ -118,6 +106,18 @@ IDBRequest* IDBCursor::update(ScriptState* scriptState, const ScriptValue& value
exceptionState.throwDOMException(ReadOnlyError, "The record may not be updated inside a read-only transaction.");
return nullptr;
}
+ if (isDeleted()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
+ return nullptr;
+ }
+ if (!m_gotValue) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
+ return nullptr;
+ }
+ if (isKeyCursor()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMessage);
+ return nullptr;
+ }
IDBObjectStore* objectStore = effectiveObjectStore();
return objectStore->put(scriptState, WebIDBPutModeCursorUpdate, IDBAny::create(this), value, m_primaryKey, exceptionState);
@@ -138,14 +138,14 @@ void IDBCursor::advance(unsigned count, ExceptionState& exceptionState)
exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
return;
}
- if (!m_gotValue) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
- return;
- }
if (isDeleted()) {
exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
return;
}
+ if (!m_gotValue) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
+ return;
+ }
m_request->setPendingCursor(this);
m_gotValue = false;
@@ -155,6 +155,24 @@ void IDBCursor::advance(unsigned count, ExceptionState& exceptionState)
void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& keyValue, ExceptionState& exceptionState)
{
IDB_TRACE("IDBCursor::continue");
+
+ if (m_transaction->isFinished() || m_transaction->isFinishing()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
+ return;
+ }
+ if (!m_transaction->isActive()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
+ return;
+ }
+ if (!m_gotValue) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
+ return;
+ }
+ if (isDeleted()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
+ return;
+ }
+
IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState);
if (exceptionState.hadException())
return;
@@ -168,6 +186,24 @@ void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& ke
void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue& keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState)
{
IDB_TRACE("IDBCursor::continuePrimaryKey");
+
+ if (m_transaction->isFinished() || m_transaction->isFinishing()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
+ return;
+ }
+ if (!m_transaction->isActive()) {
+ exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
+ return;
+ }
+ if (!m_gotValue) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
+ return;
+ }
+ if (isDeleted()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
+ return;
+ }
+
if (m_source->getType() != IDBAny::IDBIndexType) {
exceptionState.throwDOMException(InvalidAccessError, "The cursor's source is not an index.");
return;
@@ -198,29 +234,13 @@ void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
void IDBCursor::continueFunction(IDBKey* key, IDBKey* primaryKey, ExceptionState& exceptionState)
{
- ASSERT(!primaryKey || (key && primaryKey));
-
- if (m_transaction->isFinished() || m_transaction->isFinishing()) {
- exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
- return;
- }
- if (!m_transaction->isActive()) {
- exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
- return;
- }
-
- if (!m_gotValue) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
- return;
- }
-
- if (isDeleted()) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
- return;
- }
+ DCHECK(m_transaction->isActive());
+ DCHECK(m_gotValue);
+ DCHECK(!isDeleted());
+ DCHECK(!primaryKey || (key && primaryKey));
if (key) {
- ASSERT(m_key);
+ DCHECK(m_key);
if (m_direction == WebIDBCursorDirectionNext || m_direction == WebIDBCursorDirectionNextNoDuplicate) {
const bool ok = m_key->isLessThan(key)
|| (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessThan(primaryKey));
@@ -261,7 +281,10 @@ IDBRequest* IDBCursor::deleteFunction(ScriptState* scriptState, ExceptionState&
exceptionState.throwDOMException(ReadOnlyError, "The record may not be deleted inside a read-only transaction.");
return nullptr;
}
-
+ if (isDeleted()) {
+ exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
+ return nullptr;
+ }
if (!m_gotValue) {
exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage);
return nullptr;
@@ -270,10 +293,6 @@ IDBRequest* IDBCursor::deleteFunction(ScriptState* scriptState, ExceptionState&
exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMessage);
return nullptr;
}
- if (isDeleted()) {
- exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorMessage);
- return nullptr;
- }
if (!m_transaction->backendDB()) {
exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databaseClosedErrorMessage);
return nullptr;

Powered by Google App Engine
This is Rietveld 408576698