Changeset 243039 in webkit


Ignore:
Timestamp:
Mar 16, 2019 1:57:22 AM (5 years ago)
Author:
sihui_liu@apple.com
Message:

Layout tests imported/w3c/web-platform-tests/IndexedDB/*-exception-order.html are failing
https://bugs.webkit.org/show_bug.cgi?id=195650

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Updated test expectations to PASS.

  • web-platform-tests/IndexedDB/idbdatabase-createObjectStore-exception-order-expected.txt:
  • web-platform-tests/IndexedDB/idbdatabase-transaction-exception-order-expected.txt:
  • web-platform-tests/IndexedDB/idbindex-query-exception-order-expected.txt:
  • web-platform-tests/IndexedDB/idbobjectstore-delete-exception-order-expected.txt:
  • web-platform-tests/IndexedDB/idbobjectstore-query-exception-order-expected.txt:

Source/WebCore:

Fix some exception orders in IDB.

  • Modules/indexeddb/IDBDatabase.cpp:

(WebCore::IDBDatabase::createObjectStore):
Step 6 of https://www.w3.org/TR/IndexedDB-2/#dom-idbdatabase-createobjectstore.

(WebCore::IDBDatabase::transaction):
Step 1 of https://www.w3.org/TR/IndexedDB-2/#dom-idbdatabase-transaction.

  • Modules/indexeddb/IDBIndex.cpp:

(WebCore::IDBIndex::doOpenCursor):
(WebCore::IDBIndex::openCursor):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-opencursor.

(WebCore::IDBIndex::doOpenKeyCursor):
(WebCore::IDBIndex::openKeyCursor):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-openkeycursor.

(WebCore::IDBIndex::count):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-count.

(WebCore::IDBIndex::doCount):
(WebCore::IDBIndex::get):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-get.

(WebCore::IDBIndex::doGet):
(WebCore::IDBIndex::getKey):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getkey.

(WebCore::IDBIndex::doGetKey):
(WebCore::IDBIndex::doGetAll):
(WebCore::IDBIndex::getAll):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getkey.
(WebCore::IDBIndex::doGetAllKeys):
(WebCore::IDBIndex::getAllKeys):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getallkeys.

  • Modules/indexeddb/IDBIndex.h:
  • Modules/indexeddb/IDBObjectStore.cpp:

(WebCore::IDBObjectStore::doOpenCursor):
(WebCore::IDBObjectStore::openCursor):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-opencursor.

(WebCore::IDBObjectStore::doOpenKeyCursor):
(WebCore::IDBObjectStore::openKeyCursor):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-openkeycursor.

(WebCore::IDBObjectStore::deleteFunction):
(WebCore::IDBObjectStore::doDelete):
(WebCore::IDBObjectStore::count):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-count.

(WebCore::IDBObjectStore::doCount):
(WebCore::IDBObjectStore::doGetAll):
(WebCore::IDBObjectStore::getAll):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-getall.

(WebCore::IDBObjectStore::doGetAllKeys):
(WebCore::IDBObjectStore::getAllKeys):
Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-getallkeys.

  • Modules/indexeddb/IDBObjectStore.h:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r242818 r243039  
     12019-03-16  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Layout tests imported/w3c/web-platform-tests/IndexedDB/*-exception-order.html are failing
     4        https://bugs.webkit.org/show_bug.cgi?id=195650
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Updated test expectations to PASS.
     9
     10        * web-platform-tests/IndexedDB/idbdatabase-createObjectStore-exception-order-expected.txt:
     11        * web-platform-tests/IndexedDB/idbdatabase-transaction-exception-order-expected.txt:
     12        * web-platform-tests/IndexedDB/idbindex-query-exception-order-expected.txt:
     13        * web-platform-tests/IndexedDB/idbobjectstore-delete-exception-order-expected.txt:
     14        * web-platform-tests/IndexedDB/idbobjectstore-query-exception-order-expected.txt:
     15
    1162019-03-12  Sihui Liu  <sihui_liu@apple.com>
    217
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbdatabase-createObjectStore-exception-order-expected.txt

    r219663 r243039  
    22PASS IDBDatabase.createObjectStore exception order: InvalidStateError vs. TransactionInactiveError
    33PASS IDBDatabase.createObjectStore exception order: TransactionInactiveError vs. SyntaxError
    4 FAIL IDBDatabase.createObjectStore exception order: SyntaxError vs. ConstraintError assert_throws: "Invalid key path" check (SyntaxError) should precede "duplicate store name" check (ConstraintError) function "() => {
    5       db.createObjectStore('s', {keyPath: 'not a valid key path'});
    6     }" threw object "ConstraintError: Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists." that is not a DOMException SyntaxError: property "code" is equal to 0, expected 12
     4PASS IDBDatabase.createObjectStore exception order: SyntaxError vs. ConstraintError
    75PASS IDBDatabase.createObjectStore exception order: ConstraintError vs. InvalidAccessError
    86
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbdatabase-transaction-exception-order-expected.txt

    r215164 r243039  
    22PASS IDBDatabase.transaction exception order: InvalidStateError vs. NotFoundError
    33PASS IDBDatabase.transaction exception order: InvalidStateError vs. InvalidAccessError
    4 FAIL IDBDatabase.transaction exception order: NotFoundError vs. TypeError assert_throws: "No such store" check (NotFoundError) should precede "invalid mode" check (TypeError) function "() => {
    5       db.transaction('no-such-store', 'versionchange');
    6     }" threw object "TypeError: Type error" that is not a DOMException NotFoundError: property "code" is equal to undefined, expected 8
     4PASS IDBDatabase.transaction exception order: NotFoundError vs. TypeError
    75
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbindex-query-exception-order-expected.txt

    r219663 r243039  
    11
    22PASS IDBIndex.get exception order: InvalidStateError vs. TransactionInactiveError
    3 FAIL IDBIndex.get exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     3PASS IDBIndex.get exception order: TransactionInactiveError vs. DataError
    44PASS IDBIndex.getAll exception order: InvalidStateError vs. TransactionInactiveError
    5 FAIL IDBIndex.getAll exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'getAll' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     5PASS IDBIndex.getAll exception order: TransactionInactiveError vs. DataError
    66PASS IDBIndex.getAllKeys exception order: InvalidStateError vs. TransactionInactiveError
    7 FAIL IDBIndex.getAllKeys exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'getAllKeys' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     7PASS IDBIndex.getAllKeys exception order: TransactionInactiveError vs. DataError
    88PASS IDBIndex.count exception order: InvalidStateError vs. TransactionInactiveError
    9 FAIL IDBIndex.count exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'count' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     9PASS IDBIndex.count exception order: TransactionInactiveError vs. DataError
    1010PASS IDBIndex.openCursor exception order: InvalidStateError vs. TransactionInactiveError
    11 FAIL IDBIndex.openCursor exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'openCursor' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     11PASS IDBIndex.openCursor exception order: TransactionInactiveError vs. DataError
    1212PASS IDBIndex.openKeyCursor exception order: InvalidStateError vs. TransactionInactiveError
    13 FAIL IDBIndex.openKeyCursor exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { index[method]({}); }" threw object "DataError: Failed to execute 'openKeyCursor' on 'IDBIndex': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     13PASS IDBIndex.openKeyCursor exception order: TransactionInactiveError vs. DataError
    1414
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbobjectstore-delete-exception-order-expected.txt

    r219663 r243039  
    22PASS IDBObjectStore.delete exception order: InvalidStateError vs. TransactionInactiveError
    33PASS IDBObjectStore.delete exception order: TransactionInactiveError vs. ReadOnlyError
    4 FAIL IDBObjectStore.delete exception order: ReadOnlyError vs. DataError assert_throws: "read only" check (ReadOnlyError) should precede key/data check (DataError) function "() => { store.delete({}); }" threw object "DataError: Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key." that is not a DOMException ReadOnlyError: property "name" is equal to "DataError", expected "ReadOnlyError"
     4PASS IDBObjectStore.delete exception order: ReadOnlyError vs. DataError
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbobjectstore-query-exception-order-expected.txt

    r219663 r243039  
    33PASS IDBObjectStore.get exception order: TransactionInactiveError vs. DataError
    44PASS IDBObjectStore.getAll exception order: InvalidStateError vs. TransactionInactiveError
    5 FAIL IDBObjectStore.getAll exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { store[method]({}); }" threw object "DataError: Failed to execute 'getAll' on 'IDBObjectStore': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     5PASS IDBObjectStore.getAll exception order: TransactionInactiveError vs. DataError
    66PASS IDBObjectStore.getAllKeys exception order: InvalidStateError vs. TransactionInactiveError
    7 FAIL IDBObjectStore.getAllKeys exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { store[method]({}); }" threw object "DataError: Failed to execute 'getAllKeys' on 'IDBObjectStore': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     7PASS IDBObjectStore.getAllKeys exception order: TransactionInactiveError vs. DataError
    88PASS IDBObjectStore.count exception order: InvalidStateError vs. TransactionInactiveError
    9 FAIL IDBObjectStore.count exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { store[method]({}); }" threw object "DataError: Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     9PASS IDBObjectStore.count exception order: TransactionInactiveError vs. DataError
    1010PASS IDBObjectStore.openCursor exception order: InvalidStateError vs. TransactionInactiveError
    11 FAIL IDBObjectStore.openCursor exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { store[method]({}); }" threw object "DataError: Failed to execute 'openCursor' on 'IDBObjectStore': The parameter is not a valid key." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     11PASS IDBObjectStore.openCursor exception order: TransactionInactiveError vs. DataError
    1212PASS IDBObjectStore.openKeyCursor exception order: InvalidStateError vs. TransactionInactiveError
    13 FAIL IDBObjectStore.openKeyCursor exception order: TransactionInactiveError vs. DataError assert_throws: "not active" check (TransactionInactiveError) should precede query check (DataError) function "() => { store[method]({}); }" threw object "DataError: Failed to execute 'openKeyCursor' on 'IDBObjectStore': The parameter is not a valid key or key range." that is not a DOMException TransactionInactiveError: property "name" is equal to "DataError", expected "TransactionInactiveError"
     13PASS IDBObjectStore.openKeyCursor exception order: TransactionInactiveError vs. DataError
    1414
  • trunk/Source/WebCore/ChangeLog

    r243037 r243039  
     12019-03-16  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Layout tests imported/w3c/web-platform-tests/IndexedDB/*-exception-order.html are failing
     4        https://bugs.webkit.org/show_bug.cgi?id=195650
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Fix some exception orders in IDB.
     9
     10        * Modules/indexeddb/IDBDatabase.cpp:
     11        (WebCore::IDBDatabase::createObjectStore):
     12        Step 6 of https://www.w3.org/TR/IndexedDB-2/#dom-idbdatabase-createobjectstore.
     13
     14        (WebCore::IDBDatabase::transaction):
     15        Step 1 of https://www.w3.org/TR/IndexedDB-2/#dom-idbdatabase-transaction.
     16
     17        * Modules/indexeddb/IDBIndex.cpp:
     18        (WebCore::IDBIndex::doOpenCursor):
     19        (WebCore::IDBIndex::openCursor):
     20        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-opencursor.
     21
     22        (WebCore::IDBIndex::doOpenKeyCursor):
     23        (WebCore::IDBIndex::openKeyCursor):
     24        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-openkeycursor.
     25
     26        (WebCore::IDBIndex::count):
     27        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-count.
     28
     29        (WebCore::IDBIndex::doCount):
     30        (WebCore::IDBIndex::get):
     31        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-get.
     32
     33        (WebCore::IDBIndex::doGet):
     34        (WebCore::IDBIndex::getKey):
     35        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getkey.
     36
     37        (WebCore::IDBIndex::doGetKey):
     38        (WebCore::IDBIndex::doGetAll):
     39        (WebCore::IDBIndex::getAll):
     40        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getkey.
     41        (WebCore::IDBIndex::doGetAllKeys):
     42        (WebCore::IDBIndex::getAllKeys):
     43        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbindex-getallkeys.
     44
     45        * Modules/indexeddb/IDBIndex.h:
     46        * Modules/indexeddb/IDBObjectStore.cpp:
     47        (WebCore::IDBObjectStore::doOpenCursor):
     48        (WebCore::IDBObjectStore::openCursor):
     49        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-opencursor.
     50
     51        (WebCore::IDBObjectStore::doOpenKeyCursor):
     52        (WebCore::IDBObjectStore::openKeyCursor):
     53        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-openkeycursor.
     54
     55        (WebCore::IDBObjectStore::deleteFunction):
     56        (WebCore::IDBObjectStore::doDelete):
     57        (WebCore::IDBObjectStore::count):
     58        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-count.
     59
     60        (WebCore::IDBObjectStore::doCount):
     61        (WebCore::IDBObjectStore::doGetAll):
     62        (WebCore::IDBObjectStore::getAll):
     63        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-getall.
     64
     65        (WebCore::IDBObjectStore::doGetAllKeys):
     66        (WebCore::IDBObjectStore::getAllKeys):
     67        Step 5 of https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-getallkeys.
     68        * Modules/indexeddb/IDBObjectStore.h:
     69
    1702019-03-16  Ryosuke Niwa  <rniwa@webkit.org>
    271
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp

    r242110 r243039  
    145145        return Exception { TransactionInactiveError };
    146146
    147     if (m_info.hasObjectStore(name))
    148         return Exception { ConstraintError, "Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists."_s };
    149 
    150147    auto& keyPath = parameters.keyPath;
    151148    if (keyPath && !isIDBKeyPathValid(keyPath.value()))
    152149        return Exception { SyntaxError, "Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path."_s };
    153150
     151    if (m_info.hasObjectStore(name))
     152        return Exception { ConstraintError, "Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists."_s };
     153
    154154    if (keyPath && parameters.autoIncrement && ((WTF::holds_alternative<String>(keyPath.value()) && WTF::get<String>(keyPath.value()).isEmpty()) || WTF::holds_alternative<Vector<String>>(keyPath.value())))
    155155        return Exception { InvalidAccessError, "Failed to execute 'createObjectStore' on 'IDBDatabase': The autoIncrement option was set but the keyPath option was empty or an array."_s };
     
    167167
    168168    ASSERT(&originThread() == &Thread::current());
     169
     170    if (m_versionChangeTransaction && !m_versionChangeTransaction->isFinishedOrFinishing())
     171        return Exception { InvalidStateError, "Failed to execute 'transaction' on 'IDBDatabase': A version change transaction is running."_s };
    169172
    170173    if (m_closePending)
     
    177180        objectStores.append(WTFMove(WTF::get<String>(storeNames)));
    178181
    179     if (objectStores.isEmpty())
    180         return Exception { InvalidAccessError, "Failed to execute 'transaction' on 'IDBDatabase': The storeNames parameter was empty."_s };
    181 
    182     if (mode != IDBTransactionMode::Readonly && mode != IDBTransactionMode::Readwrite)
    183         return Exception { TypeError };
    184 
    185     if (m_versionChangeTransaction && !m_versionChangeTransaction->isFinishedOrFinishing())
    186         return Exception { InvalidStateError, "Failed to execute 'transaction' on 'IDBDatabase': A version change transaction is running."_s };
    187 
    188182    // It is valid for javascript to pass in a list of object store names with the same name listed twice,
    189183    // so we need to put them all in a set to get a unique list.
     
    199193        return Exception { NotFoundError, "Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found."_s };
    200194    }
     195
     196    if (objectStores.isEmpty())
     197        return Exception { InvalidAccessError, "Failed to execute 'transaction' on 'IDBDatabase': The storeNames parameter was empty."_s };
     198
     199    if (mode != IDBTransactionMode::Readonly && mode != IDBTransactionMode::Readwrite)
     200        return Exception { TypeError };
    201201
    202202    auto info = IDBTransactionInfo::clientTransaction(m_connectionProxy.get(), objectStores, mode);
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndex.cpp

    r239427 r243039  
    149149}
    150150
    151 ExceptionOr<Ref<IDBRequest>> IDBIndex::openCursor(ExecState& execState, IDBKeyRange* range, IDBCursorDirection direction)
     151ExceptionOr<Ref<IDBRequest>> IDBIndex::doOpenCursor(ExecState& execState, IDBCursorDirection direction, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    152152{
    153153    LOG(IndexedDB, "IDBIndex::openCursor");
     
    160160        return Exception { TransactionInactiveError, "Failed to execute 'openCursor' on 'IDBIndex': The transaction is inactive or finished."_s };
    161161
    162     IDBKeyRangeData rangeData = range;
     162    auto keyRange = function();
     163    if (keyRange.hasException())
     164        return keyRange.releaseException();
     165
     166    IDBKeyRangeData rangeData = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
    163167    if (rangeData.lowerKey.isNull())
    164168        rangeData.lowerKey = IDBKeyData::minimum();
     
    170174}
    171175
     176ExceptionOr<Ref<IDBRequest>> IDBIndex::openCursor(ExecState& execState, RefPtr<IDBKeyRange>&& range, IDBCursorDirection direction)
     177{
     178    return doOpenCursor(execState, direction, [range=WTFMove(range)]() {
     179        return range;
     180    });
     181}
     182
    172183ExceptionOr<Ref<IDBRequest>> IDBIndex::openCursor(ExecState& execState, JSValue key, IDBCursorDirection direction)
    173184{
    174     LOG(IndexedDB, "IDBIndex::openCursor");
    175     ASSERT(&m_objectStore.transaction().database().originThread() == &Thread::current());
    176 
    177     auto keyRange = IDBKeyRange::only(execState, key);
    178     if (keyRange.hasException())
    179         return Exception { DataError, "Failed to execute 'openCursor' on 'IDBIndex': The parameter is not a valid key."_s };
    180 
    181     return openCursor(execState, keyRange.releaseReturnValue().ptr(), direction);
    182 }
    183 
    184 ExceptionOr<Ref<IDBRequest>> IDBIndex::openKeyCursor(ExecState& execState, IDBKeyRange* range, IDBCursorDirection direction)
     185    return doOpenCursor(execState, direction, [state=&execState, key]() {
     186        auto onlyResult = IDBKeyRange::only(*state, key);
     187        if (onlyResult.hasException())
     188            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'openCursor' on 'IDBIndex': The parameter is not a valid key."_s) };
     189
     190        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     191    });
     192}
     193
     194ExceptionOr<Ref<IDBRequest>> IDBIndex::doOpenKeyCursor(ExecState& execState, IDBCursorDirection direction, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    185195{
    186196    LOG(IndexedDB, "IDBIndex::openKeyCursor");
     
    193203        return Exception { TransactionInactiveError, "Failed to execute 'openKeyCursor' on 'IDBIndex': The transaction is inactive or finished."_s };
    194204
    195     auto info = IDBCursorInfo::indexCursor(m_objectStore.transaction(), m_objectStore.info().identifier(), m_info.identifier(), range, direction, IndexedDB::CursorType::KeyOnly);
     205    auto keyRange = function();
     206    if (keyRange.hasException())
     207        return keyRange.releaseException();
     208
     209    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     210    auto info = IDBCursorInfo::indexCursor(m_objectStore.transaction(), m_objectStore.info().identifier(), m_info.identifier(), keyRangePointer, direction, IndexedDB::CursorType::KeyOnly);
    196211    return m_objectStore.transaction().requestOpenCursor(execState, *this, info);
    197212}
    198213
     214ExceptionOr<Ref<IDBRequest>> IDBIndex::openKeyCursor(ExecState& execState, RefPtr<IDBKeyRange>&& range, IDBCursorDirection direction)
     215{
     216    return doOpenKeyCursor(execState, direction, [range=WTFMove(range)]() {
     217        return range;
     218    });
     219}
     220
    199221ExceptionOr<Ref<IDBRequest>> IDBIndex::openKeyCursor(ExecState& execState, JSValue key, IDBCursorDirection direction)
    200222{
    201     LOG(IndexedDB, "IDBIndex::openKeyCursor");
    202 
    203     auto keyRange = IDBKeyRange::only(execState, key);
    204     if (keyRange.hasException())
    205         return Exception { DataError, "Failed to execute 'openKeyCursor' on 'IDBIndex': The parameter is not a valid key."_s };
    206     return openKeyCursor(execState, keyRange.releaseReturnValue().ptr(), direction);
     223    return doOpenKeyCursor(execState, direction, [state=&execState, key]() {
     224        auto onlyResult = IDBKeyRange::only(*state, key);
     225        if (onlyResult.hasException())
     226            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'openKeyCursor' on 'IDBIndex': The parameter is not a valid key."_s) };
     227
     228        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     229    });
    207230}
    208231
     
    219242
    220243    auto idbKey = scriptValueToIDBKey(execState, key);
    221     if (!idbKey->isValid())
    222         return Exception { DataError, "Failed to execute 'count' on 'IDBIndex': The parameter is not a valid key."_s };
    223 
    224     return doCount(execState, IDBKeyRangeData(idbKey.ptr()));
     244    auto* idbKeyPointer = idbKey->isValid() ? idbKey.ptr() : nullptr;
     245
     246    return doCount(execState, IDBKeyRangeData(idbKeyPointer));
    225247}
    226248
     
    231253    if (m_deleted || m_objectStore.isDeleted())
    232254        return Exception { InvalidStateError, "Failed to execute 'count' on 'IDBIndex': The index or its object store has been deleted."_s };
    233 
    234     if (!range.isValid())
    235         return Exception { DataError };
    236255
    237256    auto& transaction = m_objectStore.transaction();
     
    239258        return Exception { TransactionInactiveError, "Failed to execute 'count' on 'IDBIndex': The transaction is inactive or finished."_s };
    240259
     260    if (!range.isValid())
     261        return Exception { DataError, "Failed to execute 'count' on 'IDBIndex': The parameter is not a valid key."_s };
     262
    241263    return transaction.requestCount(execState, *this, range);
    242264}
     
    255277    auto idbKey = scriptValueToIDBKey(execState, key);
    256278    if (!idbKey->isValid())
    257         return Exception { DataError, "Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key."_s };
     279        return doGet(execState, Exception(DataError, "Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key."_s));
    258280
    259281    return doGet(execState, IDBKeyRangeData(idbKey.ptr()));
    260282}
    261283
    262 ExceptionOr<Ref<IDBRequest>> IDBIndex::doGet(ExecState& execState, const IDBKeyRangeData& range)
     284ExceptionOr<Ref<IDBRequest>> IDBIndex::doGet(ExecState& execState, ExceptionOr<IDBKeyRangeData> range)
    263285{
    264286    ASSERT(&m_objectStore.transaction().database().originThread() == &Thread::current());
     
    266288    if (m_deleted || m_objectStore.isDeleted())
    267289        return Exception { InvalidStateError, "Failed to execute 'get' on 'IDBIndex': The index or its object store has been deleted."_s };
    268 
    269     if (range.isNull)
    270         return Exception { DataError };
    271290
    272291    auto& transaction = m_objectStore.transaction();
     
    274293        return Exception { TransactionInactiveError, "Failed to execute 'get' on 'IDBIndex': The transaction is inactive or finished."_s };
    275294
    276     return transaction.requestGetValue(execState, *this, range);
     295    if (range.hasException())
     296        return range.releaseException();
     297    auto keyRange = range.releaseReturnValue();
     298
     299    if (keyRange.isNull)
     300        return Exception { DataError };
     301
     302    return transaction.requestGetValue(execState, *this, keyRange);
    277303}
    278304
     
    290316    auto idbKey = scriptValueToIDBKey(execState, key);
    291317    if (!idbKey->isValid())
    292         return Exception { DataError, "Failed to execute 'getKey' on 'IDBIndex': The parameter is not a valid key."_s };
     318        return doGetKey(execState, Exception(DataError, "Failed to execute 'getKey' on 'IDBIndex': The parameter is not a valid key."_s));
    293319
    294320    return doGetKey(execState, IDBKeyRangeData(idbKey.ptr()));
    295321}
    296322
    297 ExceptionOr<Ref<IDBRequest>> IDBIndex::doGetKey(ExecState& execState, const IDBKeyRangeData& range)
     323ExceptionOr<Ref<IDBRequest>> IDBIndex::doGetKey(ExecState& execState, ExceptionOr<IDBKeyRangeData> range)
    298324{
    299325    ASSERT(&m_objectStore.transaction().database().originThread() == &Thread::current());
     
    301327    if (m_deleted || m_objectStore.isDeleted())
    302328        return Exception { InvalidStateError, "Failed to execute 'getKey' on 'IDBIndex': The index or its object store has been deleted."_s };
    303 
    304     if (range.isNull)
    305         return Exception { DataError };
    306329
    307330    auto& transaction = m_objectStore.transaction();
     
    309332        return Exception { TransactionInactiveError, "Failed to execute 'getKey' on 'IDBIndex': The transaction is inactive or finished."_s };
    310333
    311     return transaction.requestGetKey(execState, *this, range);
    312 }
    313 
    314 ExceptionOr<Ref<IDBRequest>> IDBIndex::getAll(ExecState& execState, RefPtr<IDBKeyRange> range, Optional<uint32_t> count)
     334    if (range.hasException())
     335        return range.releaseException();
     336    auto keyRange = range.releaseReturnValue();
     337   
     338    if (keyRange.isNull)
     339        return Exception { DataError };
     340
     341    return transaction.requestGetKey(execState, *this, keyRange);
     342}
     343
     344ExceptionOr<Ref<IDBRequest>> IDBIndex::doGetAll(ExecState& execState, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    315345{
    316346    LOG(IndexedDB, "IDBIndex::getAll");
     
    323353        return Exception { TransactionInactiveError, "Failed to execute 'getAll' on 'IDBIndex': The transaction is inactive or finished."_s };
    324354
    325     return m_objectStore.transaction().requestGetAllIndexRecords(execState, *this, range.get(), IndexedDB::GetAllType::Values, count);
     355    auto keyRange = function();
     356    if (keyRange.hasException())
     357        return keyRange.releaseException();
     358
     359    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     360    return m_objectStore.transaction().requestGetAllIndexRecords(execState, *this, keyRangePointer, IndexedDB::GetAllType::Values, count);
     361}
     362
     363ExceptionOr<Ref<IDBRequest>> IDBIndex::getAll(ExecState& execState, RefPtr<IDBKeyRange>&& range, Optional<uint32_t> count)
     364{
     365    return doGetAll(execState, count, [range = WTFMove(range)]() {
     366        return range;
     367    });
    326368}
    327369
    328370ExceptionOr<Ref<IDBRequest>> IDBIndex::getAll(ExecState& execState, JSValue key, Optional<uint32_t> count)
    329371{
    330     auto onlyResult = IDBKeyRange::only(execState, key);
    331     if (onlyResult.hasException())
    332         return Exception { DataError, "Failed to execute 'getAll' on 'IDBIndex': The parameter is not a valid key."_s };
    333 
    334     return getAll(execState, onlyResult.releaseReturnValue(), count);
    335 }
    336 
    337 ExceptionOr<Ref<IDBRequest>> IDBIndex::getAllKeys(ExecState& execState, RefPtr<IDBKeyRange> range, Optional<uint32_t> count)
     372    return doGetAll(execState, count, [state=&execState, key]() {
     373        auto onlyResult = IDBKeyRange::only(*state, key);
     374        if (onlyResult.hasException())
     375            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'getAll' on 'IDBIndex': The parameter is not a valid key."_s) };
     376
     377        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     378    });
     379}
     380
     381ExceptionOr<Ref<IDBRequest>> IDBIndex::doGetAllKeys(ExecState& execState, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    338382{
    339383    LOG(IndexedDB, "IDBIndex::getAllKeys");
     
    346390        return Exception { TransactionInactiveError, "Failed to execute 'getAllKeys' on 'IDBIndex': The transaction is inactive or finished."_s };
    347391
    348     return m_objectStore.transaction().requestGetAllIndexRecords(execState, *this, range.get(), IndexedDB::GetAllType::Keys, count);
     392    auto keyRange = function();
     393    if (keyRange.hasException())
     394        return keyRange.releaseException();
     395
     396    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     397    return m_objectStore.transaction().requestGetAllIndexRecords(execState, *this, keyRangePointer, IndexedDB::GetAllType::Keys, count);
     398}
     399
     400ExceptionOr<Ref<IDBRequest>> IDBIndex::getAllKeys(ExecState& execState, RefPtr<IDBKeyRange>&& range, Optional<uint32_t> count)
     401{
     402    return doGetAllKeys(execState, count, [range = WTFMove(range)]() {
     403        return range;
     404    });
    349405}
    350406
    351407ExceptionOr<Ref<IDBRequest>> IDBIndex::getAllKeys(ExecState& execState, JSValue key, Optional<uint32_t> count)
    352408{
    353     auto onlyResult = IDBKeyRange::only(execState, key);
    354     if (onlyResult.hasException())
    355         return Exception { DataError, "Failed to execute 'getAllKeys' on 'IDBIndex': The parameter is not a valid key."_s };
    356 
    357     return getAllKeys(execState, onlyResult.releaseReturnValue(), count);
     409    return doGetAllKeys(execState, count, [state=&execState, key]() {
     410        auto onlyResult = IDBKeyRange::only(*state, key);
     411        if (onlyResult.hasException())
     412            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'getAllKeys' on 'IDBIndex': The parameter is not a valid key."_s) };
     413
     414        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     415    });
    358416}
    359417
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndex.h

    r239427 r243039  
    5959    void rollbackInfoForVersionChangeAbort();
    6060
    61     ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, IDBKeyRange*, IDBCursorDirection);
     61    ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
    6262    ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
    63     ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, IDBKeyRange*, IDBCursorDirection);
     63    ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
    6464    ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
    6565
     
    7272    ExceptionOr<Ref<IDBRequest>> getKey(JSC::ExecState&, JSC::JSValue key);
    7373
    74     ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, RefPtr<IDBKeyRange>, Optional<uint32_t> count);
     74    ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
    7575    ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
    76     ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, RefPtr<IDBKeyRange>, Optional<uint32_t> count);
     76    ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
    7777    ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
    7878
     
    8989private:
    9090    ExceptionOr<Ref<IDBRequest>> doCount(JSC::ExecState&, const IDBKeyRangeData&);
    91     ExceptionOr<Ref<IDBRequest>> doGet(JSC::ExecState&, const IDBKeyRangeData&);
    92     ExceptionOr<Ref<IDBRequest>> doGetKey(JSC::ExecState&, const IDBKeyRangeData&);
     91    ExceptionOr<Ref<IDBRequest>> doGet(JSC::ExecState&, ExceptionOr<IDBKeyRangeData>);
     92    ExceptionOr<Ref<IDBRequest>> doGetKey(JSC::ExecState&, ExceptionOr<IDBKeyRangeData>);
     93    ExceptionOr<Ref<IDBRequest>> doOpenCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
     94    ExceptionOr<Ref<IDBRequest>> doOpenKeyCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
     95    ExceptionOr<Ref<IDBRequest>> doGetAll(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
     96    ExceptionOr<Ref<IDBRequest>> doGetAllKeys(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
    9397
    9498    const char* activeDOMObjectName() const final;
  • trunk/Source/WebCore/Modules/indexeddb/IDBKey.h

    r236007 r243039  
    8686            }
    8787        }
    88         Ref<IDBKey> idbKey = adoptRef(*new IDBKey(result, sizeEstimate));
     88        auto idbKey = adoptRef(*new IDBKey(result, sizeEstimate));
    8989        ASSERT(idbKey->isValid());
    9090        return idbKey;
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp

    r241196 r243039  
    150150}
    151151
    152 ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openCursor(ExecState& execState, RefPtr<IDBKeyRange> range, IDBCursorDirection direction)
     152ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doOpenCursor(ExecState& execState, IDBCursorDirection direction, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    153153{
    154154    LOG(IndexedDB, "IDBObjectStore::openCursor");
     
    161161        return Exception { TransactionInactiveError, "Failed to execute 'openCursor' on 'IDBObjectStore': The transaction is inactive or finished."_s };
    162162
    163     auto info = IDBCursorInfo::objectStoreCursor(m_transaction, m_info.identifier(), range.get(), direction, IndexedDB::CursorType::KeyAndValue);
     163    auto keyRange = function();
     164    if (keyRange.hasException())
     165        return keyRange.releaseException();
     166    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     167
     168    auto info = IDBCursorInfo::objectStoreCursor(m_transaction, m_info.identifier(), keyRangePointer, direction, IndexedDB::CursorType::KeyAndValue);
    164169    return m_transaction.requestOpenCursor(execState, *this, info);
    165170}
    166171
     172ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openCursor(ExecState& execState, RefPtr<IDBKeyRange>&& range, IDBCursorDirection direction)
     173{
     174    return doOpenCursor(execState, direction, [range = WTFMove(range)]() {
     175        return range;
     176    });
     177}
     178
    167179ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openCursor(ExecState& execState, JSValue key, IDBCursorDirection direction)
    168180{
    169     auto onlyResult = IDBKeyRange::only(execState, key);
    170     if (onlyResult.hasException())
    171         return Exception { DataError, "Failed to execute 'openCursor' on 'IDBObjectStore': The parameter is not a valid key."_s };
    172 
    173     return openCursor(execState, onlyResult.releaseReturnValue(), direction);
    174 }
    175 
    176 ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openKeyCursor(ExecState& execState, RefPtr<IDBKeyRange> range, IDBCursorDirection direction)
    177 {
    178     LOG(IndexedDB, "IDBObjectStore::openCursor");
     181    return doOpenCursor(execState, direction, [state=&execState, key]() {
     182        auto onlyResult = IDBKeyRange::only(*state, key);
     183        if (onlyResult.hasException())
     184            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'openCursor' on 'IDBObjectStore': The parameter is not a valid key."_s) };
     185
     186        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     187    });
     188}
     189
     190ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doOpenKeyCursor(ExecState& execState, IDBCursorDirection direction, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
     191{
     192    LOG(IndexedDB, "IDBObjectStore::openKeyCursor");
    179193    ASSERT(&m_transaction.database().originThread() == &Thread::current());
    180194
     
    185199        return Exception { TransactionInactiveError, "Failed to execute 'openKeyCursor' on 'IDBObjectStore': The transaction is inactive or finished."_s };
    186200
    187     auto info = IDBCursorInfo::objectStoreCursor(m_transaction, m_info.identifier(), range.get(), direction, IndexedDB::CursorType::KeyOnly);
     201    auto keyRange = function();
     202    if (keyRange.hasException())
     203        return keyRange.releaseException();
     204
     205    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     206    auto info = IDBCursorInfo::objectStoreCursor(m_transaction, m_info.identifier(), keyRangePointer, direction, IndexedDB::CursorType::KeyOnly);
    188207    return m_transaction.requestOpenCursor(execState, *this, info);
    189208}
    190209
     210ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openKeyCursor(ExecState& execState, RefPtr<IDBKeyRange>&& range, IDBCursorDirection direction)
     211{
     212    return doOpenKeyCursor(execState, direction, [range = WTFMove(range)]() {
     213        return range;
     214    });
     215}
     216
    191217ExceptionOr<Ref<IDBRequest>> IDBObjectStore::openKeyCursor(ExecState& execState, JSValue key, IDBCursorDirection direction)
    192218{
    193     auto onlyResult = IDBKeyRange::only(execState, key);
    194     if (onlyResult.hasException())
    195         return Exception { DataError, "Failed to execute 'openKeyCursor' on 'IDBObjectStore': The parameter is not a valid key or key range."_s };
    196 
    197     return openKeyCursor(execState, onlyResult.releaseReturnValue(), direction);
     219    return doOpenCursor(execState, direction, [state=&execState, key]() {
     220        auto onlyResult = IDBKeyRange::only(*state, key);
     221        if (onlyResult.hasException())
     222            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'openKeyCursor' on 'IDBObjectStore': The parameter is not a valid key."_s) };
     223
     224        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     225    });
    198226}
    199227
     
    363391ExceptionOr<Ref<IDBRequest>> IDBObjectStore::deleteFunction(ExecState& execState, IDBKeyRange* keyRange)
    364392{
    365     return doDelete(execState, keyRange);
    366 }
    367 
    368 ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doDelete(ExecState& execState, IDBKeyRange* keyRange)
     393    return doDelete(execState, [keyRange]() {
     394        return makeRefPtr(keyRange);
     395    });
     396}
     397
     398ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doDelete(ExecState& execState, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    369399{
    370400    LOG(IndexedDB, "IDBObjectStore::deleteFunction");
     
    385415        return Exception { ReadonlyError, "Failed to execute 'delete' on 'IDBObjectStore': The transaction is read-only."_s };
    386416
    387     IDBKeyRangeData keyRangeData(keyRange);
     417    auto keyRange = function();
     418    if (keyRange.hasException())
     419        return keyRange.releaseException();
     420
     421    IDBKeyRangeData keyRangeData = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
    388422    if (!keyRangeData.isValid())
    389423        return Exception { DataError, "Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key range."_s };
     
    394428ExceptionOr<Ref<IDBRequest>> IDBObjectStore::deleteFunction(ExecState& execState, JSValue key)
    395429{
    396     Ref<IDBKey> idbKey = scriptValueToIDBKey(execState, key);
    397     if (!idbKey->isValid())
    398         return Exception { DataError, "Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key."_s };
    399     return doDelete(execState, IDBKeyRange::create(WTFMove(idbKey)).ptr());
     430    return doDelete(execState, [state=&execState, key]() {
     431        auto idbKey = scriptValueToIDBKey(*state, key);
     432        if (!idbKey->isValid())
     433            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'delete' on 'IDBObjectStore': The parameter is not a valid key."_s) };
     434        return ExceptionOr<RefPtr<IDBKeyRange>> { (IDBKeyRange::create(WTFMove(idbKey))).ptr() };
     435    });
    400436}
    401437
     
    536572    LOG(IndexedDB, "IDBObjectStore::count");
    537573
    538     Ref<IDBKey> idbKey = scriptValueToIDBKey(execState, key);
    539     if (!idbKey->isValid())
    540         return Exception { DataError, "Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key."_s };
    541 
    542     return doCount(execState, IDBKeyRangeData(idbKey.ptr()));
     574    auto idbKey = scriptValueToIDBKey(execState, key);
     575
     576    return doCount(execState, IDBKeyRangeData(idbKey->isValid() ? idbKey.ptr() : nullptr));
    543577}
    544578
     
    566600
    567601    if (!range.isValid())
    568         return Exception { DataError };
     602        return Exception { DataError, "Failed to execute 'count' on 'IDBObjectStore': The parameter is not a valid key."_s };
    569603
    570604    return m_transaction.requestCount(execState, *this, range);
    571605}
    572606
    573 ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAll(ExecState& execState, RefPtr<IDBKeyRange> range, Optional<uint32_t> count)
     607ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doGetAll(ExecState& execState, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    574608{
    575609    LOG(IndexedDB, "IDBObjectStore::getAll");
     
    582616        return Exception { TransactionInactiveError, "Failed to execute 'getAll' on 'IDBObjectStore': The transaction is inactive or finished."_s };
    583617
    584     return m_transaction.requestGetAllObjectStoreRecords(execState, *this, range.get(), IndexedDB::GetAllType::Values, count);
     618    auto keyRange = function();
     619    if (keyRange.hasException())
     620        return keyRange.releaseException();
     621
     622    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     623    return m_transaction.requestGetAllObjectStoreRecords(execState, *this, keyRangePointer, IndexedDB::GetAllType::Values, count);
     624}
     625
     626ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAll(ExecState& execState, RefPtr<IDBKeyRange>&& range, Optional<uint32_t> count)
     627{
     628    return doGetAll(execState, count, [range = WTFMove(range)]() {
     629        return range;
     630    });
    585631}
    586632
    587633ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAll(ExecState& execState, JSValue key, Optional<uint32_t> count)
    588634{
    589     auto onlyResult = IDBKeyRange::only(execState, key);
    590     if (onlyResult.hasException())
    591         return Exception { DataError, "Failed to execute 'getAll' on 'IDBObjectStore': The parameter is not a valid key."_s };
    592 
    593     return getAll(execState, onlyResult.releaseReturnValue(), count);
    594 }
    595 
    596 ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAllKeys(ExecState& execState, RefPtr<IDBKeyRange> range, Optional<uint32_t> count)
     635    return doGetAll(execState, count, [state=&execState, key]() {
     636        auto onlyResult = IDBKeyRange::only(*state, key);
     637        if (onlyResult.hasException())
     638            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'getAll' on 'IDBObjectStore': The parameter is not a valid key."_s) };
     639
     640        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     641    });
     642}
     643
     644ExceptionOr<Ref<IDBRequest>> IDBObjectStore::doGetAllKeys(ExecState& execState, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&& function)
    597645{
    598646    LOG(IndexedDB, "IDBObjectStore::getAllKeys");
     
    605653        return Exception { TransactionInactiveError, "Failed to execute 'getAllKeys' on 'IDBObjectStore': The transaction is inactive or finished."_s };
    606654
    607     return m_transaction.requestGetAllObjectStoreRecords(execState, *this, range.get(), IndexedDB::GetAllType::Keys, count);
     655    auto keyRange = function();
     656    if (keyRange.hasException())
     657        return keyRange.releaseException();
     658
     659    auto* keyRangePointer = keyRange.returnValue() ? keyRange.releaseReturnValue().get() : nullptr;
     660    return m_transaction.requestGetAllObjectStoreRecords(execState, *this, keyRangePointer, IndexedDB::GetAllType::Keys, count);
     661}
     662
     663ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAllKeys(ExecState& execState, RefPtr<IDBKeyRange>&& range, Optional<uint32_t> count)
     664{
     665    return doGetAllKeys(execState, count, [range = WTFMove(range)]() {
     666        return range;
     667    });
    608668}
    609669
    610670ExceptionOr<Ref<IDBRequest>> IDBObjectStore::getAllKeys(ExecState& execState, JSValue key, Optional<uint32_t> count)
    611671{
    612     auto onlyResult = IDBKeyRange::only(execState, key);
    613     if (onlyResult.hasException())
    614         return Exception { DataError, "Failed to execute 'getAllKeys' on 'IDBObjectStore': The parameter is not a valid key."_s };
    615 
    616     return getAllKeys(execState, onlyResult.releaseReturnValue(), count);
     672    return doGetAllKeys(execState, count, [state=&execState, key]() {
     673        auto onlyResult = IDBKeyRange::only(*state, key);
     674        if (onlyResult.hasException())
     675            return ExceptionOr<RefPtr<IDBKeyRange>>{ Exception(DataError, "Failed to execute 'getAllKeys' on 'IDBObjectStore': The parameter is not a valid key."_s) };
     676
     677        return ExceptionOr<RefPtr<IDBKeyRange>> { onlyResult.releaseReturnValue() };
     678    });
    617679}
    618680
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h

    r241196 r243039  
    7474    };
    7575
    76     ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, RefPtr<IDBKeyRange>, IDBCursorDirection);
     76    ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
    7777    ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
    78     ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, RefPtr<IDBKeyRange>, IDBCursorDirection);
     78    ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, RefPtr<IDBKeyRange>&&, IDBCursorDirection);
    7979    ExceptionOr<Ref<IDBRequest>> openKeyCursor(JSC::ExecState&, JSC::JSValue key, IDBCursorDirection);
    8080    ExceptionOr<Ref<IDBRequest>> get(JSC::ExecState&, JSC::JSValue key);
     
    9292    ExceptionOr<Ref<IDBRequest>> count(JSC::ExecState&, IDBKeyRange*);
    9393    ExceptionOr<Ref<IDBRequest>> count(JSC::ExecState&, JSC::JSValue key);
    94     ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, RefPtr<IDBKeyRange>, Optional<uint32_t> count);
     94    ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
    9595    ExceptionOr<Ref<IDBRequest>> getAll(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
    96     ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, RefPtr<IDBKeyRange>, Optional<uint32_t> count);
     96    ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, RefPtr<IDBKeyRange>&&, Optional<uint32_t> count);
    9797    ExceptionOr<Ref<IDBRequest>> getAllKeys(JSC::ExecState&, JSC::JSValue key, Optional<uint32_t> count);
    9898
     
    116116    ExceptionOr<Ref<IDBRequest>> putOrAdd(JSC::ExecState&, JSC::JSValue, RefPtr<IDBKey>, IndexedDB::ObjectStoreOverwriteMode, InlineKeyCheck);
    117117    ExceptionOr<Ref<IDBRequest>> doCount(JSC::ExecState&, const IDBKeyRangeData&);
    118     ExceptionOr<Ref<IDBRequest>> doDelete(JSC::ExecState&, IDBKeyRange*);
     118    ExceptionOr<Ref<IDBRequest>> doDelete(JSC::ExecState&, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
     119    ExceptionOr<Ref<IDBRequest>> doOpenCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&&);
     120    ExceptionOr<Ref<IDBRequest>> doOpenKeyCursor(JSC::ExecState&, IDBCursorDirection, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()>&&);
     121    ExceptionOr<Ref<IDBRequest>> doGetAll(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
     122    ExceptionOr<Ref<IDBRequest>> doGetAllKeys(JSC::ExecState&, Optional<uint32_t> count, WTF::Function<ExceptionOr<RefPtr<IDBKeyRange>>()> &&);
    119123
    120124    const char* activeDOMObjectName() const final;
Note: See TracChangeset for help on using the changeset viewer.