Changeset 106827 in webkit


Ignore:
Timestamp:
Feb 6, 2012 11:50:11 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore: IndexedDB createObjectStore should throw if options arg is invalid
Added logic to OptionsObject to determine if an invalid object was created.
Javascript bindings now detect invalid OptionsObject's and throw TypeError when found.
https://bugs.webkit.org/show_bug.cgi?id=58471

Patch by Eugene Girard <girard@chromium.org> on 2012-02-06
Reviewed by Adam Barth.

Test: storage/indexeddb/createObjectStore-bad-options.html

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateParametersCheck):

  • bindings/v8/OptionsObject.cpp:

(WebCore::OptionsObject::isObject):

  • bindings/v8/OptionsObject.h:

LayoutTests: IndexedDB createObjectStore should throw if options arg is invalid (not an object).
Added unit tests to test invalid arguments.
storage/indexddb/transaction-basics was modified only to correct calls that would
now throw.
https://bugs.webkit.org/show_bug.cgi?id=58471

Patch by Eugene Girard <girard@chromium.org> on 2012-02-06
Reviewed by Adam Barth.

  • storage/indexeddb/create-object-store-options-expected.txt:
  • storage/indexeddb/create-object-store-options.html:
  • storage/indexeddb/index-basics-expected.txt:
  • storage/indexeddb/index-basics.html:
  • storage/indexeddb/resources/shared.js:

(evalAndExpectExceptionClass):

  • storage/indexeddb/transaction-basics-expected.txt:
  • storage/indexeddb/transaction-basics.html:
  • storage/indexeddb/tutorial.html:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106825 r106827  
     12012-02-06  Eugene Girard  <girard@chromium.org>
     2
     3        IndexedDB createObjectStore should throw if options arg is invalid (not an object).
     4        Added unit tests to test invalid arguments.
     5        storage/indexddb/transaction-basics was modified only to correct calls that would
     6        now throw.
     7        https://bugs.webkit.org/show_bug.cgi?id=58471
     8
     9        Reviewed by Adam Barth.
     10
     11        * storage/indexeddb/create-object-store-options-expected.txt:
     12        * storage/indexeddb/create-object-store-options.html:
     13        * storage/indexeddb/index-basics-expected.txt:
     14        * storage/indexeddb/index-basics.html:
     15        * storage/indexeddb/resources/shared.js:
     16        (evalAndExpectExceptionClass):
     17        * storage/indexeddb/transaction-basics-expected.txt:
     18        * storage/indexeddb/transaction-basics.html:
     19        * storage/indexeddb/tutorial.html:
     20
    1212012-02-06  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
    222
  • trunk/LayoutTests/storage/indexeddb/create-object-store-options-expected.txt

    r98563 r106827  
    1616PASS trans.mode is webkitIDBTransaction.READ_WRITE
    1717trans.objectStore('a').put({'a': 0})
     18Expecting TypeError exception from db.createObjectStore('d', 'bar');
     19PASS Exception was thrown.
     20PASS db.createObjectStore('d', 'bar'); threw TypeError: Not an object.
     21Expecting TypeError exception from db.createObjectStore('e', false);
     22PASS Exception was thrown.
     23PASS db.createObjectStore('e', false); threw TypeError: Not an object.
    1824trans.objectStore('b').put({'a': 0}, 0)
    1925trans.objectStore('a').get(0)
  • trunk/LayoutTests/storage/indexeddb/create-object-store-options.html

    r99258 r106827  
    4848    req.onsuccess = putB;
    4949    req.onerror = unexpectedErrorCallback;
     50
     51    evalAndExpectExceptionClass("db.createObjectStore('d', 'bar');", "TypeError");
     52    evalAndExpectExceptionClass("db.createObjectStore('e', false);", "TypeError");
    5053}
    5154
  • trunk/LayoutTests/storage/indexeddb/index-basics-expected.txt

    r105137 r106827  
    1313db.createObjectStore('storeName', null)
    1414store.createIndex('indexName', 'x')
    15 store.createIndex('indexName2', 'y', false)
    16 store.createIndex('zIndex', 'z', true)
     15store.createIndex('indexName2', 'y', {unique: false})
     16store.createIndex('zIndex', 'z', {unique: true})
    1717PASS 'name' in indexObject is true
    1818PASS indexObject.name is "indexName"
  • trunk/LayoutTests/storage/indexeddb/index-basics.html

    r105137 r106827  
    4040    window.store = evalAndLog("db.createObjectStore('storeName', null)");
    4141    window.indexObject = evalAndLog("store.createIndex('indexName', 'x')");
    42     window.indexObject2 = evalAndLog("store.createIndex('indexName2', 'y', false)");
    43     window.indexObject3 = evalAndLog("store.createIndex('zIndex', 'z', true)");
     42    window.indexObject2 = evalAndLog("store.createIndex('indexName2', 'y', {unique: false})");
     43    window.indexObject3 = evalAndLog("store.createIndex('zIndex', 'z', {unique: true})");
    4444    addData();
    4545}
  • trunk/LayoutTests/storage/indexeddb/resources/shared.js

    r106392 r106827  
    5151}
    5252
     53function evalAndExpectExceptionClass(cmd, expected)
     54{
     55    debug("Expecting " + expected + " exception from " + cmd);
     56    try {
     57        eval(cmd);
     58        testFailed("No exception thrown!" );
     59    } catch (e) {
     60                testPassed("Exception was thrown.");
     61                if (eval("e instanceof " + expected))
     62                        testPassed(cmd + " threw " + e);
     63                else
     64                        testFailed("Expected " + expected + " but saw " + e);
     65    }
     66}
     67
    5368function deleteAllObjectStores(db)
    5469{
  • trunk/LayoutTests/storage/indexeddb/transaction-basics-expected.txt

    r104840 r106827  
    2424PASS trans !== null is true
    2525store = db.createObjectStore('storeFail', null)
    26 index = store.createIndex('indexFail', 'x', false)
     26index = store.createIndex('indexFail', 'x')
    2727db.deleteObjectStore('storeFail')
    2828store.deleteIndex('indexFail')
     
    3737PASS trans !== null is true
    3838store = db.createObjectStore('storeFail', null)
    39 index = store.createIndex('indexFail', 'x', false)
     39index = store.createIndex('indexFail', 'x')
    4040db.deleteObjectStore('storeFail')
    4141store.deleteIndex('indexFail')
    4242store = db.createObjectStore('storeFail', null)
    43 index = store.createIndex('indexFail', 'x', false)
     43index = store.createIndex('indexFail', 'x')
    4444
    4545testSetVersionAbort3():
     
    5454PASS trans !== null is true
    5555store = db.createObjectStore('storeFail', null)
    56 index = store.createIndex('indexFail', 'x', false)
     56index = store.createIndex('indexFail', 'x')
    5757
    5858testInactiveAbortedTransaction():
     
    100100PASS trans !== null is true
    101101store = db.createObjectStore('storeFail', null)
    102 index = store.createIndex('indexFail', 'x', false)
     102index = store.createIndex('indexFail', 'x')
    103103
    104104testInactiveCompletedTransaction():
  • trunk/LayoutTests/storage/indexeddb/transaction-basics.html

    r104840 r106827  
    5757
    5858    var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
    59     var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
     59    var index = evalAndLog("index = store.createIndex('indexFail', 'x')");
    6060
    6161    evalAndLog("db.deleteObjectStore('storeFail')");
     
    8383
    8484    var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
    85     var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
     85    var index = evalAndLog("index = store.createIndex('indexFail', 'x')");
    8686
    8787    evalAndLog("db.deleteObjectStore('storeFail')");
     
    8989
    9090    var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
    91     var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
     91    var index = evalAndLog("index = store.createIndex('indexFail', 'x')");
    9292
    9393    trans.abort();
     
    114114
    115115    store = evalAndLog("store = db.createObjectStore('storeFail', null)");
    116     index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
     116    index = evalAndLog("index = store.createIndex('indexFail', 'x')");
    117117
    118118    trans.abort();
     
    156156
    157157    store = evalAndLog("store = db.createObjectStore('storeFail', null)");
    158     index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
     158    index = evalAndLog("index = store.createIndex('indexFail', 'x')");
    159159
    160160    trans.oncomplete = testInactiveCompletedTransaction;
  • trunk/LayoutTests/storage/indexeddb/tutorial.html

    r103283 r106827  
    181181    // unique, which is good in the case of names. The first parameter is the name of the index.
    182182    // Second is the key path. The third specifies uniqueness.
    183     var fname = objectStore.createIndex("fname", "fname", false);
    184     var lname = objectStore.createIndex("lname", "lname", false);
     183    var fname = objectStore.createIndex("fname", "fname", { unique: false});
     184    var lname = objectStore.createIndex("lname", "lname", { unique: false});
    185185
    186186    // Note that if you wanted to delete these indexes, you can either call objectStore.deleteIndex
  • trunk/Source/WebCore/ChangeLog

    r106823 r106827  
     12012-02-06  Eugene Girard  <girard@chromium.org>
     2
     3        IndexedDB createObjectStore should throw if options arg is invalid
     4        Added logic to OptionsObject to determine if an invalid object was created.
     5        Javascript bindings now detect invalid OptionsObject's and throw TypeError when found.
     6        https://bugs.webkit.org/show_bug.cgi?id=58471
     7
     8        Reviewed by Adam Barth.
     9
     10        Test: storage/indexeddb/createObjectStore-bad-options.html
     11
     12        * bindings/scripts/CodeGeneratorV8.pm:
     13        (GenerateParametersCheck):
     14        * bindings/v8/OptionsObject.cpp:
     15        (WebCore::OptionsObject::isObject):
     16        * bindings/v8/OptionsObject.h:
     17
    1182012-02-06  Sheriff Bot  <webkit.review.bot@gmail.com>
    219
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r106798 r106827  
    15961596            $parameterCheckString .= "    EXCEPTION_BLOCK($nativeType, $parameterName, " .
    15971597                 JSValueToNative($parameter, "MAYBE_MISSING_PARAMETER(args, $paramIndex, $parameterMissingPolicy)") . ");\n";
     1598            if ($nativeType eq 'OptionsObject') {
     1599               $parameterCheckString .= "    if (args.Length() > $paramIndex && !$parameterName.isUndefinedOrNull() && !$parameterName.isObject()) {\n";
     1600               $parameterCheckString .= "        ec = TYPE_MISMATCH_ERR;\n";
     1601               $parameterCheckString .= "        V8Proxy::setDOMException(ec);\n";
     1602               $parameterCheckString .= "        return throwError(\"Not an object.\", V8Proxy::TypeError);\n";
     1603               $parameterCheckString .= "    }\n";
     1604            }
    15981605        }
    15991606
  • trunk/Source/WebCore/bindings/v8/OptionsObject.cpp

    r101591 r106827  
    6565}
    6666
     67bool OptionsObject::isObject() const
     68{
     69    return !isUndefinedOrNull() && m_options->IsObject();
     70}
     71
    6772bool OptionsObject::isUndefinedOrNull() const
    6873{
  • trunk/Source/WebCore/bindings/v8/OptionsObject.h

    r101591 r106827  
    5050    OptionsObject& operator=(const OptionsObject&);
    5151
     52    bool isObject() const;
    5253    bool isUndefinedOrNull() const;
    5354
Note: See TracChangeset for help on using the changeset viewer.