Changeset 105329 in webkit


Ignore:
Timestamp:
Jan 18, 2012 2:58:56 PM (12 years ago)
Author:
jsbell@chromium.org
Message:

IndexedDB: Invalid keys yielded by key paths should raise exceptions, not error callbacks
https://bugs.webkit.org/show_bug.cgi?id=76075

Reviewed by Tony Chang.

Source/WebCore:

Tests: storage/indexeddb/objectstore-basics.html

  • storage/IDBObjectStoreBackendImpl.cpp:

(WebCore::IDBObjectStoreBackendImpl::put):

LayoutTests:

  • storage/indexeddb/mozilla/bad-keypath-expected.txt:
  • storage/indexeddb/mozilla/bad-keypath.html:
  • storage/indexeddb/objectstore-basics-expected.txt:
  • storage/indexeddb/objectstore-basics.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r105327 r105329  
     12012-01-18  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Invalid keys yielded by key paths should raise exceptions, not error callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=76075
     5
     6        Reviewed by Tony Chang.
     7
     8        * storage/indexeddb/mozilla/bad-keypath-expected.txt:
     9        * storage/indexeddb/mozilla/bad-keypath.html:
     10        * storage/indexeddb/objectstore-basics-expected.txt:
     11        * storage/indexeddb/objectstore-basics.html:
     12
    1132012-01-18  James Robinson  <jamesr@chromium.org>
    214
  • trunk/LayoutTests/storage/indexeddb/mozilla/bad-keypath-expected.txt

    r85121 r105329  
    1414objectStore = db.createObjectStore('foo', { keyPath: 'keyPath' });
    1515request = objectStore.add({ keyPath: 'foo' });
    16 request = objectStore.add({});
    17 PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
     16Expecting exception from request = objectStore.add({});
     17PASS Exception was thrown.
     18PASS code is IDBDatabaseException.DATA_ERR
    1819PASS successfullyParsed is true
    1920
  • trunk/LayoutTests/storage/indexeddb/mozilla/bad-keypath.html

    r99258 r105329  
    5555function addFirstSuccess()
    5656{
    57     request = evalAndLog("request = objectStore.add({});");
    58     request.onsuccess = unexpectedSuccessCallback;
    59     request.onerror = addSecondExpectedError;
    60 }
    61 
    62 function addSecondExpectedError()
    63 {
    64     shouldBe("event.target.errorCode", "IDBDatabaseException.DATA_ERR");
     57    evalAndExpectException("request = objectStore.add({});", "IDBDatabaseException.DATA_ERR");
    6558    done();
    6659}
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt

    r103100 r105329  
    136136PASS Exception was thrown.
    137137PASS code is webkitIDBDatabaseException.DATA_ERR
     138
     139testPreConditions():
     140db.setVersion('precondition version')
     141storeWithInLineKeys = db.createObjectStore('storeWithInLineKeys', {keyPath: 'key'})
     142storeWithOutOfLineKeys = db.createObjectStore('storeWithOutIOfLineKeys')
     143storeWithIndex = db.createObjectStore('storeWithIndex')
     144index = storeWithIndex.createIndex('indexName', 'indexKey')
     145
     146IDBObjectStore.put()
     147The object store uses in-line keys and the key parameter was provided.
     148Expecting exception from storeWithInLineKeys.put({key: 1}, 'key')
     149PASS Exception was thrown.
     150PASS code is webkitIDBDatabaseException.DATA_ERR
     151The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
     152Expecting exception from storeWithOutOfLineKeys.put({})
     153PASS Exception was thrown.
     154PASS code is webkitIDBDatabaseException.DATA_ERR
     155The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.
     156Expecting exception from storeWithInLineKeys.put({key: null})
     157PASS Exception was thrown.
     158PASS code is webkitIDBDatabaseException.DATA_ERR
     159The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.
     160Expecting exception from storeWithInLineKeys.put({})
     161PASS Exception was thrown.
     162PASS code is webkitIDBDatabaseException.DATA_ERR
     163The key parameter was provided but does not contain a valid key.
     164Expecting exception from storeWithOutOfLineKeys.put({}, null)
     165PASS Exception was thrown.
     166PASS code is webkitIDBDatabaseException.DATA_ERR
     167
     168IDBObjectStore.add()
     169The object store uses in-line keys and the key parameter was provided.
     170Expecting exception from storeWithInLineKeys.add({key: 1}, 'key')
     171PASS Exception was thrown.
     172PASS code is webkitIDBDatabaseException.DATA_ERR
     173The object store uses out-of-line keys and has no key generator and the key parameter was not provided.
     174Expecting exception from storeWithOutOfLineKeys.add({})
     175PASS Exception was thrown.
     176PASS code is webkitIDBDatabaseException.DATA_ERR
     177The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.
     178Expecting exception from storeWithInLineKeys.add({key: null})
     179PASS Exception was thrown.
     180PASS code is webkitIDBDatabaseException.DATA_ERR
     181The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.
     182Expecting exception from storeWithInLineKeys.add({})
     183PASS Exception was thrown.
     184PASS code is webkitIDBDatabaseException.DATA_ERR
     185The key parameter was provided but does not contain a valid key.
     186Expecting exception from storeWithOutOfLineKeys.add({}, null)
     187PASS Exception was thrown.
     188PASS code is webkitIDBDatabaseException.DATA_ERR
    138189PASS successfullyParsed is true
    139190
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics.html

    r103100 r105329  
    287287    evalAndExpectException("store.put(null, {})", "webkitIDBDatabaseException.DATA_ERR");
    288288
    289     done();
    290 }
     289    testPreConditions();
     290}
     291
     292function testPreConditions()
     293{
     294    debug("");
     295    debug("testPreConditions():");
     296    request = evalAndLog("db.setVersion('precondition version')");
     297    request.onerror = unexpectedErrorCallback;
     298    request.onsuccess = function() {
     299        storeWithInLineKeys = evalAndLog("storeWithInLineKeys = db.createObjectStore('storeWithInLineKeys', {keyPath: 'key'})");
     300        storeWithOutOfLineKeys = evalAndLog("storeWithOutOfLineKeys = db.createObjectStore('storeWithOutIOfLineKeys')");
     301        storeWithIndex = evalAndLog("storeWithIndex = db.createObjectStore('storeWithIndex')");
     302        index = evalAndLog("index = storeWithIndex.createIndex('indexName', 'indexKey')");
     303
     304        debug("");
     305        debug("IDBObjectStore.put()");
     306        debug("The object store uses in-line keys and the key parameter was provided.");
     307        evalAndExpectException("storeWithInLineKeys.put({key: 1}, 'key')", "webkitIDBDatabaseException.DATA_ERR");
     308
     309        debug("The object store uses out-of-line keys and has no key generator and the key parameter was not provided.");
     310        evalAndExpectException("storeWithOutOfLineKeys.put({})", "webkitIDBDatabaseException.DATA_ERR");
     311
     312        debug("The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.");
     313        evalAndExpectException("storeWithInLineKeys.put({key: null})", "webkitIDBDatabaseException.DATA_ERR");
     314
     315        debug("The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.");
     316        evalAndExpectException("storeWithInLineKeys.put({})", "webkitIDBDatabaseException.DATA_ERR");
     317
     318        debug("The key parameter was provided but does not contain a valid key.");
     319        evalAndExpectException("storeWithOutOfLineKeys.put({}, null)", "webkitIDBDatabaseException.DATA_ERR");
     320
     321        // FIXME: Add precondition checks for put() with index key paths that yield invalid keys.
     322        // https://bugs.webkit.org/show_bug.cgi?id=76487
     323
     324        debug("");
     325        debug("IDBObjectStore.add()");
     326        debug("The object store uses in-line keys and the key parameter was provided.");
     327        evalAndExpectException("storeWithInLineKeys.add({key: 1}, 'key')", "webkitIDBDatabaseException.DATA_ERR");
     328
     329        debug("The object store uses out-of-line keys and has no key generator and the key parameter was not provided.");
     330        evalAndExpectException("storeWithOutOfLineKeys.add({})", "webkitIDBDatabaseException.DATA_ERR");
     331
     332        debug("The object store uses in-line keys and the result of evaluating the object store's key path yields a value and that value is not a valid key.");
     333        evalAndExpectException("storeWithInLineKeys.add({key: null})", "webkitIDBDatabaseException.DATA_ERR");
     334
     335        debug("The object store uses in-line keys but no key generator and the result of evaluating the object store's key path does not yield a value.");
     336        evalAndExpectException("storeWithInLineKeys.add({})", "webkitIDBDatabaseException.DATA_ERR");
     337
     338        debug("The key parameter was provided but does not contain a valid key.");
     339        evalAndExpectException("storeWithOutOfLineKeys.add({}, null)", "webkitIDBDatabaseException.DATA_ERR");
     340
     341        // FIXME: Add precondition checks for add() with index key paths that yield invalid keys.
     342        // https://bugs.webkit.org/show_bug.cgi?id=76487
     343
     344        done();
     345    };
     346}
     347
     348
    291349
    292350test();
  • trunk/Source/WebCore/ChangeLog

    r105328 r105329  
     12012-01-18  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Invalid keys yielded by key paths should raise exceptions, not error callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=76075
     5
     6        Reviewed by Tony Chang.
     7
     8        Tests: storage/indexeddb/objectstore-basics.html
     9
     10        * storage/IDBObjectStoreBackendImpl.cpp:
     11        (WebCore::IDBObjectStoreBackendImpl::put):
     12
    1132012-01-18  Dana Jansens  <danakj@chromium.org>
    214
  • trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp

    r104771 r105329  
    139139    const bool autoIncrement = objectStore->autoIncrement();
    140140    const bool hasKeyPath = !objectStore->m_keyPath.isNull();
    141     if (!key && !autoIncrement && !hasKeyPath) {
    142         ec = IDBDatabaseException::DATA_ERR;
    143         return;
    144     }
    145 
    146     if (key && hasKeyPath && (putMode == AddOnly || putMode == AddOrUpdate)) {
    147         ec = IDBDatabaseException::DATA_ERR;
    148         return;
    149     }
    150 
    151     // FIXME: This should throw a SERIAL_ERR on structured clone problems.
    152     // FIXME: This should throw a DATA_ERR when the wrong key/keyPath data is supplied.
     141
     142    if (putMode != CursorUpdate) {
     143        if (!key && !autoIncrement && !hasKeyPath) {
     144            ec = IDBDatabaseException::DATA_ERR;
     145            return;
     146        }
     147        if (hasKeyPath) {
     148            if (key && key->valid()) {
     149                ec = IDBDatabaseException::DATA_ERR;
     150                return;
     151            }
     152            if (!autoIncrement) {
     153                RefPtr<IDBKey> keyPathKey = fetchKeyFromKeyPath(value.get(), objectStore->m_keyPath);
     154                if (!keyPathKey || !keyPathKey->valid()) {
     155                    ec = IDBDatabaseException::DATA_ERR;
     156                    return;
     157                }
     158            }
     159        }
     160        // FIXME: Add precondition checks for index key paths that yield invalid keys.
     161        // https://bugs.webkit.org/show_bug.cgi?id=76487
     162     }
     163
    153164    if (!transaction->scheduleTask(createCallbackTask(&IDBObjectStoreBackendImpl::putInternal, objectStore, value, key, putMode, callbacks, transaction)))
    154165        ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR;
Note: See TracChangeset for help on using the changeset viewer.