Changeset 123112 in webkit


Ignore:
Timestamp:
Jul 19, 2012 9:37:18 AM (12 years ago)
Author:
jsbell@chromium.org
Message:

IndexedDB: Throw native TypeErrors per spec
https://bugs.webkit.org/show_bug.cgi?id=91679

Reviewed by Kentaro Hara.

Source/WebCore:

Per the IDB spec, the advance(), openCursor(), openKeyCursor() and transaction()
methods supposed to throw true native JavaScript TypeError objects as exceptions
rather than DOMException objects. Implement this by adding a special DOMException
code that is tested for in the binding layer.

Tests: storage/indexeddb/cursor-advance.html

storage/indexeddb/index-basics.html
storage/indexeddb/index-basics-workers.html
storage/indexeddb/objectstore-cursor.html
storage/indexeddb/transaction-basics.html

  • Modules/indexeddb/IDBCursor.cpp: Use the new DOMException code.

(WebCore::IDBCursor::advance):
(WebCore::IDBCursor::stringToDirection):
(WebCore::IDBCursor::directionToString):

  • Modules/indexeddb/IDBDatabase.cpp: Ditto.

(WebCore::IDBDatabase::setVersion):

  • Modules/indexeddb/IDBDatabaseException.cpp: Remove temporary cruft/mark as legacy.

(WebCore):

  • Modules/indexeddb/IDBDatabaseException.h: Ditto.
  • Modules/indexeddb/IDBDatabaseException.idl: Ditto.
  • Modules/indexeddb/IDBFactory.cpp: Use the new DOMException code.

(WebCore::IDBFactory::open):
(WebCore::IDBFactory::deleteDatabase):

  • Modules/indexeddb/IDBObjectStore.cpp:

(WebCore::IDBObjectStore::createIndex): Use the new DOMException code.

  • Modules/indexeddb/IDBTransaction.cpp: Use the new DOMException code.

(WebCore::IDBTransaction::stringToMode):
(WebCore::IDBTransaction::modeToString):

  • bindings/js/JSDOMBinding.cpp:

(WebCore::setDOMException): Intercept new DOMException code, throw native TypeError.

  • bindings/v8/V8Proxy.cpp:

(WebCore::V8Proxy::setDOMException): Ditto.

  • dom/ExceptionCode.h: Add new DOMException code.

LayoutTests:

  • storage/indexeddb/cursor-advance-expected.txt:
  • storage/indexeddb/index-basics-expected.txt:
  • storage/indexeddb/index-basics-workers-expected.txt:
  • storage/indexeddb/objectstore-cursor-expected.txt:
  • storage/indexeddb/resources/cursor-advance.js:

(testBadAdvance.advanceBadly):
(testBadAdvance):

  • storage/indexeddb/resources/index-basics.js:

(openKeyCursor):
(openObjectCursor):

  • storage/indexeddb/resources/objectstore-cursor.js:

(deleteExisting):

  • storage/indexeddb/resources/transaction-basics.js:

(testInvalidMode):

  • storage/indexeddb/transaction-basics-expected.txt:
Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r123111 r123112  
     12012-07-19  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Throw native TypeErrors per spec
     4        https://bugs.webkit.org/show_bug.cgi?id=91679
     5
     6        Reviewed by Kentaro Hara.
     7
     8        * storage/indexeddb/cursor-advance-expected.txt:
     9        * storage/indexeddb/index-basics-expected.txt:
     10        * storage/indexeddb/index-basics-workers-expected.txt:
     11        * storage/indexeddb/objectstore-cursor-expected.txt:
     12        * storage/indexeddb/resources/cursor-advance.js:
     13        (testBadAdvance.advanceBadly):
     14        (testBadAdvance):
     15        * storage/indexeddb/resources/index-basics.js:
     16        (openKeyCursor):
     17        (openObjectCursor):
     18        * storage/indexeddb/resources/objectstore-cursor.js:
     19        (deleteExisting):
     20        * storage/indexeddb/resources/transaction-basics.js:
     21        (testInvalidMode):
     22        * storage/indexeddb/transaction-basics-expected.txt:
     23
    1242012-07-19  Tony Chang  <tony@chromium.org>
    225
  • trunk/LayoutTests/storage/indexeddb/cursor-advance-expected.txt

    r120114 r123112  
    134134objectStore = trans.objectStore(objectStoreName)
    135135request = objectStore.openCursor()
    136 Expecting exception from cursor.advance(0)
     136Expecting TypeError exception from cursor.advance(0)
    137137PASS Exception was thrown.
    138 PASS code is IDBDatabaseException.TYPE_ERR
     138PASS cursor.advance(0) threw TypeError: Type error
    139139testDelete()
    140140trans = db.transaction(objectStoreName, 'readwrite')
  • trunk/LayoutTests/storage/indexeddb/index-basics-expected.txt

    r119161 r123112  
    6868indexObject4.getKey('value2')
    6969PASS event.target.result is "key2"
     70
     71Verify that specifying an invalid direction raises an exception:
     72Expecting TypeError exception from indexObject.openKeyCursor(0, 'invalid-direction')
     73PASS Exception was thrown.
     74PASS indexObject.openKeyCursor(0, 'invalid-direction') threw TypeError: Type error
     75
    7076indexObject.openKeyCursor()
    7177PASS event.target.source is indexObject
     
    8793event.target.result.continue()
    8894PASS event.target.result is null
     95
     96Verify that specifying an invalid direction raises an exception:
     97Expecting TypeError exception from indexObject.openCursor(0, 'invalid-direction')
     98PASS Exception was thrown.
     99PASS indexObject.openCursor(0, 'invalid-direction') threw TypeError: Type error
     100
    89101indexObject.openCursor()
    90102PASS event.target.source is indexObject
  • trunk/LayoutTests/storage/indexeddb/index-basics-workers-expected.txt

    r119161 r123112  
    6969[Worker] indexObject4.getKey('value2')
    7070PASS [Worker] event.target.result is "key2"
     71[Worker]
     72[Worker] Verify that specifying an invalid direction raises an exception:
     73[Worker] Expecting TypeError exception from indexObject.openKeyCursor(0, 'invalid-direction')
     74PASS [Worker] Exception was thrown.
     75PASS [Worker] indexObject.openKeyCursor(0, 'invalid-direction') threw TypeError: Type error
     76[Worker]
    7177[Worker] indexObject.openKeyCursor()
    7278PASS [Worker] event.target.source is indexObject
     
    8894[Worker] event.target.result.continue()
    8995PASS [Worker] event.target.result is null
     96[Worker]
     97[Worker] Verify that specifying an invalid direction raises an exception:
     98[Worker] Expecting TypeError exception from indexObject.openCursor(0, 'invalid-direction')
     99PASS [Worker] Exception was thrown.
     100PASS [Worker] indexObject.openCursor(0, 'invalid-direction') threw TypeError: Type error
     101[Worker]
    90102[Worker] indexObject.openCursor()
    91103PASS [Worker] event.target.source is indexObject
  • trunk/LayoutTests/storage/indexeddb/objectstore-cursor-expected.txt

    r117702 r123112  
    1212PASS trans is non-null.
    1313Deleted all object stores.
    14 db.createObjectStore('someObjectStore')
     14objectStore = db.createObjectStore('someObjectStore')
     15
     16Verify that specifying an invalid direction raises an exception:
     17Expecting TypeError exception from objectStore.openCursor(0, 'invalid-direction')
     18PASS Exception was thrown.
     19PASS objectStore.openCursor(0, 'invalid-direction') threw TypeError: Type error
     20
    1521objectStore.add('', testData[nextToAdd])
    1622objectStore.add('', testData[nextToAdd])
  • trunk/LayoutTests/storage/indexeddb/resources/cursor-advance.js

    r120114 r123112  
    330330        cursor = event.target.result;
    331331
    332         evalAndExpectException("cursor.advance(0)", "IDBDatabaseException.TYPE_ERR");
     332        evalAndExpectExceptionClass("cursor.advance(0)", "TypeError");
    333333        testDelete();
    334334    }
  • trunk/LayoutTests/storage/indexeddb/resources/index-basics.js

    r119161 r123112  
    175175    shouldBeEqualToString("event.target.result", "key2");
    176176
     177    debug("");
     178    debug("Verify that specifying an invalid direction raises an exception:");
     179    evalAndExpectExceptionClass("indexObject.openKeyCursor(0, 'invalid-direction')", "TypeError");
     180    debug("");
     181
    177182    self.request = evalAndLog("indexObject.openKeyCursor()");
    178183    request.onsuccess = cursor1Continue;
     
    233238    event = evt;
    234239    shouldBeNull("event.target.result");
     240
     241    debug("");
     242    debug("Verify that specifying an invalid direction raises an exception:");
     243    evalAndExpectExceptionClass("indexObject.openCursor(0, 'invalid-direction')", "TypeError");
     244    debug("");
    235245
    236246    self.request = evalAndLog("indexObject.openCursor()");
  • trunk/LayoutTests/storage/indexeddb/resources/objectstore-cursor.js

    r117702 r123112  
    4242    deleteAllObjectStores(db);
    4343
    44     self.objectStore = evalAndLog("db.createObjectStore('someObjectStore')");
     44    evalAndLog("objectStore = db.createObjectStore('someObjectStore')");
     45
     46    debug("");
     47    debug("Verify that specifying an invalid direction raises an exception:");
     48    evalAndExpectExceptionClass("objectStore.openCursor(0, 'invalid-direction')", "TypeError");
     49    debug("");
     50
    4551    self.nextToAdd = 0;
    4652    addData();
  • trunk/LayoutTests/storage/indexeddb/resources/transaction-basics.js

    r122173 r123112  
    280280    debug("");
    281281    debug("Verify that specifying an invalid mode raises an exception");
    282     evalAndExpectException("db.transaction(['storeName'], 'lsakjdf')", "IDBDatabaseException.TYPE_ERR", "'TypeError'");
     282    evalAndExpectExceptionClass("db.transaction(['storeName'], 'lsakjdf')", "TypeError");
    283283    testDegenerateNames();
    284284}
  • trunk/LayoutTests/storage/indexeddb/transaction-basics-expected.txt

    r122173 r123112  
    199199
    200200Verify that specifying an invalid mode raises an exception
    201 Expecting exception from db.transaction(['storeName'], 'lsakjdf')
    202 PASS Exception was thrown.
    203 PASS code is IDBDatabaseException.TYPE_ERR
    204 PASS ename is 'TypeError'
     201Expecting TypeError exception from db.transaction(['storeName'], 'lsakjdf')
     202PASS Exception was thrown.
     203PASS db.transaction(['storeName'], 'lsakjdf') threw TypeError: Type error
    205204
    206205Test that null and undefined are treated as strings
  • trunk/Source/WebCore/ChangeLog

    r123110 r123112  
     12012-07-19  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Throw native TypeErrors per spec
     4        https://bugs.webkit.org/show_bug.cgi?id=91679
     5
     6        Reviewed by Kentaro Hara.
     7
     8        Per the IDB spec, the advance(), openCursor(), openKeyCursor() and transaction()
     9        methods supposed to throw true native JavaScript TypeError objects as exceptions
     10        rather than DOMException objects. Implement this by adding a special DOMException
     11        code that is tested for in the binding layer.
     12
     13        Tests: storage/indexeddb/cursor-advance.html
     14               storage/indexeddb/index-basics.html
     15               storage/indexeddb/index-basics-workers.html
     16               storage/indexeddb/objectstore-cursor.html
     17               storage/indexeddb/transaction-basics.html
     18
     19        * Modules/indexeddb/IDBCursor.cpp: Use the new DOMException code.
     20        (WebCore::IDBCursor::advance):
     21        (WebCore::IDBCursor::stringToDirection):
     22        (WebCore::IDBCursor::directionToString):
     23        * Modules/indexeddb/IDBDatabase.cpp: Ditto.
     24        (WebCore::IDBDatabase::setVersion):
     25        * Modules/indexeddb/IDBDatabaseException.cpp: Remove temporary cruft/mark as legacy.
     26        (WebCore):
     27        * Modules/indexeddb/IDBDatabaseException.h: Ditto.
     28        * Modules/indexeddb/IDBDatabaseException.idl: Ditto.
     29        * Modules/indexeddb/IDBFactory.cpp: Use the new DOMException code.
     30        (WebCore::IDBFactory::open):
     31        (WebCore::IDBFactory::deleteDatabase):
     32        * Modules/indexeddb/IDBObjectStore.cpp:
     33        (WebCore::IDBObjectStore::createIndex): Use the new DOMException code.
     34        * Modules/indexeddb/IDBTransaction.cpp: Use the new DOMException code.
     35        (WebCore::IDBTransaction::stringToMode):
     36        (WebCore::IDBTransaction::modeToString):
     37        * bindings/js/JSDOMBinding.cpp:
     38        (WebCore::setDOMException): Intercept new DOMException code, throw native TypeError.
     39        * bindings/v8/V8Proxy.cpp:
     40        (WebCore::V8Proxy::setDOMException): Ditto.
     41        * dom/ExceptionCode.h: Add new DOMException code.
     42
    1432012-07-19  Joshua Bell  <jsbell@chromium.org>
    244
  • trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp

    r122779 r123112  
    183183
    184184    if (!count) {
    185         ec = IDBDatabaseException::IDB_TYPE_ERR;
     185        ec = NATIVE_TYPE_ERR;
    186186        return;
    187187    }
     
    307307        return IDBCursor::PREV_NO_DUPLICATE;
    308308
    309     ec = IDBDatabaseException::IDB_TYPE_ERR;
     309    ec = NATIVE_TYPE_ERR;
    310310    return IDBCursor::NEXT;
    311311}
     
    327327
    328328    default:
    329         ec = IDBDatabaseException::IDB_TYPE_ERR;
     329        ec = NATIVE_TYPE_ERR;
    330330        return IDBCursor::directionNext();
    331331    }
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp

    r122173 r123112  
    191191{
    192192    if (version.isNull()) {
    193         ec = IDBDatabaseException::IDB_TYPE_ERR;
     193        ec = NATIVE_TYPE_ERR;
    194194        return 0;
    195195    }
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseException.cpp

    r122905 r123112  
    6363    { "SyntaxError", "The keypath argument contains an invalid key path.", SYNTAX_ERR },
    6464    { "DataCloneError", "The data being stored could not be cloned by the internal structured cloning algorithm.", DATA_CLONE_ERR },
    65     // FIXME: should be a JavaScript TypeError. See https://bugs.webkit.org/show_bug.cgi?id=85513
    66     { "TypeError", "This should be a TypeError", 0 },
     65    { 0, 0, 0 }, // FIXME: Previous/legacy value was IDB_TYPE_ERR.
    6766    { 0, 0, 0 }, // FIXME: Previous/legacy value was IDB_NOT_SUPPORTED_ERR.
    6867};
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseException.h

    r122905 r123112  
    6666        IDB_SYNTAX_ERR,
    6767        IDB_DATA_CLONE_ERR,
    68         IDB_TYPE_ERR, // FIXME: Placeholder until bindings have been updated to throw a JS TypeError. See https://bugs.webkit.org/show_bug.cgi?id=85513
     68        LEGACY_IDB_TYPE_ERR, // FIXME: Placeholder.
    6969        LEGACY_IDB_NOT_SUPPORTED_ERR, // FIXME: Placeholder.
    7070    };
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseException.idl

    r119751 r123112  
    5050        const unsigned short VER_ERR = 12;
    5151
    52         // FIXME: Placeholder until bindings have been updated to throw a JS TypeError.
    53         // See https://bugs.webkit.org/show_bug.cgi?id=85513
    54         const unsigned short TYPE_ERR = 21;
    55        
    5652        const unsigned short NOT_FOUND_ERR = 8;
    5753        const unsigned short ABORT_ERR = 20;
  • trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp

    r122515 r123112  
    109109{
    110110    if (name.isNull()) {
    111         ec = IDBDatabaseException::IDB_TYPE_ERR;
     111        ec = NATIVE_TYPE_ERR;
    112112        return 0;
    113113    }
     
    123123{
    124124    if (name.isNull()) {
    125         ec = IDBDatabaseException::IDB_TYPE_ERR;
     125        ec = NATIVE_TYPE_ERR;
    126126        return 0;
    127127    }
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp

    r123048 r123112  
    273273    }
    274274    if (name.isNull()) {
    275         ec = IDBDatabaseException::IDB_TYPE_ERR;
     275        ec = NATIVE_TYPE_ERR;
    276276        return 0;
    277277    }
  • trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

    r122782 r123112  
    319319    if (modeString == IDBTransaction::modeReadWrite())
    320320        return IDBTransaction::READ_WRITE;
    321     ec = IDBDatabaseException::IDB_TYPE_ERR;
     321    ec = NATIVE_TYPE_ERR;
    322322    return IDBTransaction::READ_ONLY;
    323323}
     
    339339
    340340    default:
    341         ec = IDBDatabaseException::IDB_TYPE_ERR;
     341        ec = NATIVE_TYPE_ERR;
    342342        return IDBTransaction::modeReadOnly();
    343343    }
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp

    r120389 r123112  
    199199        return;
    200200
     201    if (ec == NATIVE_TYPE_ERR) {
     202        throwTypeError(exec);
     203        return;
     204    }
     205
    201206    // FIXME: All callers to setDOMException need to pass in the right global object
    202207    // for now, we're going to assume the lexicalGlobalObject.  Which is wrong in cases like this:
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r121538 r123112  
    594594        return v8::Handle<v8::Value>();
    595595
     596    if (ec == NATIVE_TYPE_ERR) {
     597        const char* message = 0;
     598        return throwTypeError(message, isolate);
     599    }
     600
    596601    ExceptionCodeDescription description(ec);
    597602
  • trunk/Source/WebCore/dom/ExceptionCode.h

    r98715 r123112  
    6464        TIMEOUT_ERR = 23,
    6565        INVALID_NODE_TYPE_ERR = 24,
    66         DATA_CLONE_ERR = 25
     66        DATA_CLONE_ERR = 25,
     67
     68        // Converted to a native TypeError by the script binding layer:
     69        NATIVE_TYPE_ERR = 99
    6770    };
    6871
Note: See TracChangeset for help on using the changeset viewer.