Changeset 106830 in webkit


Ignore:
Timestamp:
Feb 6, 2012 12:00:24 PM (12 years ago)
Author:
jsbell@chromium.org
Message:

IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
https://bugs.webkit.org/show_bug.cgi?id=77374

Source/WebCore:

If a put request will use a key generator, try inserting a dummy key during the sync
put() call to check if the key insertion will succeed so an exception can be raised
early, rather than deferring to the asynchronous task.

Reviewed by Tony Chang.

Test: storage/indexeddb/keypath-edges.html

  • storage/IDBObjectStoreBackendImpl.cpp:

(WebCore::IDBObjectStoreBackendImpl::put):

LayoutTests:

Reviewed by Tony Chang.

  • storage/indexeddb/keypath-edges-expected.txt:
  • storage/indexeddb/keypath-edges.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106829 r106830  
     12012-02-06  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
     4        https://bugs.webkit.org/show_bug.cgi?id=77374
     5
     6        Reviewed by Tony Chang.
     7
     8        * storage/indexeddb/keypath-edges-expected.txt:
     9        * storage/indexeddb/keypath-edges.html:
     10
    1112012-02-06  Julien Chaffraix  <jchaffraix@webkit.org>
    212
  • trunk/LayoutTests/storage/indexeddb/keypath-edges-expected.txt

    r105891 r106830  
    4646store = transaction.objectStore('store-with-path-and-generator')
    4747
    48 Key path doesn't resolve to a value; should yield null, put request should raise error event
    49 store.put(null)
    50 PASS Error event raised: The generated key could not be inserted into the object using the keyPath.
    51 PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
    52 PASS event.cancelable is true
    53 event.preventDefault()
     48Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
     49Expecting exception from store.put(null)
     50PASS Exception was thrown.
     51PASS code is IDBDatabaseException.DATA_ERR
     52
     53Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
     54Expecting exception from store.put('string')
     55PASS Exception was thrown.
     56PASS code is IDBDatabaseException.DATA_ERR
    5457
    5558Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed
  • trunk/LayoutTests/storage/indexeddb/keypath-edges.html

    r105891 r106830  
    8989
    9090    debug("");
    91     debug("Key path doesn't resolve to a value; should yield null, put request should raise error event");
    92     request = evalAndLog("store.put(null)");
    93     request.onerror = function (e) {
    94         testPassed("Error event raised: " + e.target.webkitErrorMessage);
    95         shouldBe("event.target.errorCode", "IDBDatabaseException.DATA_ERR");
    96         shouldBeTrue("event.cancelable");
    97         evalAndLog("event.preventDefault()");
     91    debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
     92    evalAndExpectException("store.put(null)", "IDBDatabaseException.DATA_ERR");
     93
     94    debug("");
     95    debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
     96    evalAndExpectException("store.put('string')", "IDBDatabaseException.DATA_ERR");
     97
     98    debug("");
     99    debug("Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed");
     100    request = evalAndLog("store.put({})");
     101    request.onerror = unexpectedErrorCallback;
     102    request.onsuccess = function () {
     103        testPassed("store.put succeeded");
    98104
    99105        debug("");
    100         debug("Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed");
    101         request = evalAndLog("store.put({})");
     106        debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
     107        evalAndExpectException("store.put({foo: null})", "IDBDatabaseException.DATA_ERR");
     108
     109        debug("");
     110        debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
     111        request = evalAndLog("store.put({foo: 'zoo'})");
    102112        request.onerror = unexpectedErrorCallback;
    103113        request.onsuccess = function () {
    104114            testPassed("store.put succeeded");
    105115
    106             debug("");
    107             debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
    108             evalAndExpectException("store.put({foo: null})", "IDBDatabaseException.DATA_ERR");
    109 
    110             debug("");
    111             debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
    112             request = evalAndLog("store.put({foo: 'zoo'})");
    113             request.onerror = unexpectedErrorCallback;
    114             request.onsuccess = function () {
    115                 testPassed("store.put succeeded");
    116             };
    117116        };
    118117    };
  • trunk/Source/WebCore/ChangeLog

    r106828 r106830  
     12012-02-06  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
     4        https://bugs.webkit.org/show_bug.cgi?id=77374
     5
     6        If a put request will use a key generator, try inserting a dummy key during the sync
     7        put() call to check if the key insertion will succeed so an exception can be raised
     8        early, rather than deferring to the asynchronous task.
     9
     10        Reviewed by Tony Chang.
     11
     12        Test: storage/indexeddb/keypath-edges.html
     13
     14        * storage/IDBObjectStoreBackendImpl.cpp:
     15        (WebCore::IDBObjectStoreBackendImpl::put):
     16
    1172012-02-06  Gustavo Noronha Silva  <gns@gnome.org>
    218
  • trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp

    r106705 r106830  
    154154                return;
    155155            }
     156            if (autoIncrement && !keyPathKey) {
     157                RefPtr<IDBKey> dummyKey = IDBKey::createNumber(-1);
     158                RefPtr<SerializedScriptValue> valueAfterInjection = injectKeyIntoKeyPath(dummyKey, value, objectStore->m_keyPath);
     159                if (!valueAfterInjection) {
     160                    ec = IDBDatabaseException::DATA_ERR;
     161                    return;
     162                }
     163            }
    156164        }
    157165        if (key && !key->valid()) {
     
    209217                RefPtr<IDBKey> autoIncKey = objectStore->genAutoIncrementKey();
    210218                if (hasKeyPath) {
    211                     // FIXME: Add checks in put() to ensure this will always succeed (apart from I/O errors).
    212                     // https://bugs.webkit.org/show_bug.cgi?id=77374
    213219                    RefPtr<SerializedScriptValue> valueAfterInjection = injectKeyIntoKeyPath(autoIncKey, value, objectStore->m_keyPath);
     220                    ASSERT(valueAfterInjection);
    214221                    if (!valueAfterInjection) {
    215222                        objectStore->resetAutoIncrementKeyCache();
    216                         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "The generated key could not be inserted into the object using the keyPath."));
     223                        // Checks in put() ensure this should only happen if I/O error occurs.
     224                        // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
     225                        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error inserting generated key into the object."));
    217226                        return;
    218227                    }
Note: See TracChangeset for help on using the changeset viewer.