Changeset 243348 in webkit


Ignore:
Timestamp:
Mar 21, 2019, 5:03:31 PM (7 years ago)
Author:
sihui_liu@apple.com
Message:

Fix key path extraction code in IndexedDB to check own property
https://bugs.webkit.org/show_bug.cgi?id=196099

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Updated test expectations to PASS.

  • web-platform-tests/IndexedDB/key-conversion-exceptions-expected.txt:
  • web-platform-tests/IndexedDB/keygenerator-inject-expected.txt:
  • web-platform-tests/IndexedDB/keypath-exceptions-expected.txt: Added.
  • web-platform-tests/IndexedDB/wasm-module-value-expected.txt:

Source/WebCore:

Covered by existing tests.

  • Modules/indexeddb/IDBFactory.cpp:

(WebCore::IDBFactory::cmp):
We don't need to check the second parameters if the first is already invalid.

  • Modules/indexeddb/IDBKeyRange.cpp:

(WebCore::IDBKeyRange::bound):
Ditto.

  • Modules/indexeddb/IDBObjectStore.cpp:

(WebCore::IDBObjectStore::putOrAdd):
we should not clear the exception during serialization because the execeptions may be explicitly thrown by parameters.

  • bindings/js/IDBBindingUtilities.cpp:

(WebCore::get):
Fix implementation according to https://www.w3.org/TR/IndexedDB-2/#extract-key-from-value.

(WebCore::canInjectNthValueOnKeyPath):
Check the last identifier.

LayoutTests:

Rebaseline the tests because we will have same exception but different exception messages after the patch.

  • storage/indexeddb/clone-exception-expected.txt:
  • storage/indexeddb/clone-exception-private-expected.txt:
  • storage/indexeddb/exceptions-expected.txt:
  • storage/indexeddb/exceptions-private-expected.txt:
  • storage/indexeddb/objectstore-basics-expected.txt:
  • storage/indexeddb/objectstore-basics-private-expected.txt:
  • storage/indexeddb/objectstore-basics-workers-expected.txt:
  • storage/indexeddb/structured-clone-expected.txt:
  • storage/indexeddb/structured-clone-private-expected.txt:
  • storage/indexeddb/wasm-exceptions-expected.txt:
Location:
trunk
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243347 r243348  
     12019-03-21  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Fix key path extraction code in IndexedDB to check own property
     4        https://bugs.webkit.org/show_bug.cgi?id=196099
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Rebaseline the tests because we will have same exception but different exception messages after the patch.
     9
     10        * storage/indexeddb/clone-exception-expected.txt:
     11        * storage/indexeddb/clone-exception-private-expected.txt:
     12        * storage/indexeddb/exceptions-expected.txt:
     13        * storage/indexeddb/exceptions-private-expected.txt:
     14        * storage/indexeddb/objectstore-basics-expected.txt:
     15        * storage/indexeddb/objectstore-basics-private-expected.txt:
     16        * storage/indexeddb/objectstore-basics-workers-expected.txt:
     17        * storage/indexeddb/structured-clone-expected.txt:
     18        * storage/indexeddb/structured-clone-private-expected.txt:
     19        * storage/indexeddb/wasm-exceptions-expected.txt:
     20
    1212019-03-21  Simon Fraser  <simon.fraser@apple.com>
    222
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r243322 r243348  
     12019-03-21  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Fix key path extraction code in IndexedDB to check own property
     4        https://bugs.webkit.org/show_bug.cgi?id=196099
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Updated test expectations to PASS.
     9
     10        * web-platform-tests/IndexedDB/key-conversion-exceptions-expected.txt:
     11        * web-platform-tests/IndexedDB/keygenerator-inject-expected.txt:
     12        * web-platform-tests/IndexedDB/keypath-exceptions-expected.txt: Added.
     13        * web-platform-tests/IndexedDB/wasm-module-value-expected.txt:
     14
     152019-03-21  Sihui Liu  <sihui_liu@apple.com>
     16
     17        Fix three IDB WPT tests
     18        https://bugs.webkit.org/show_bug.cgi?id=196099
     19
     20        Reviewed by Ryosuke Niwa.
     21
     22        Updated test expectations to PASS.
     23
     24        * web-platform-tests/IndexedDB/key-conversion-exceptions-expected.txt:
     25        * web-platform-tests/IndexedDB/keygenerator-inject-expected.txt:
     26        * web-platform-tests/IndexedDB/keypath-exceptions-expected.txt: Added.
     27
    1282019-03-21  Youenn Fablet  <youenn@apple.com>
    229
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/key-conversion-exceptions-expected.txt

    r234125 r243348  
    11
    2 FAIL IDBFactory cmp() static with throwing/invalid keys assert_throws: first key conversion with invalid key should throw DataError function "() => {
    3             receiver[method](invalid_key, throwing_key('getter 2'));
    4         }" threw object "getter 2: throwing from getter" that is not a DOMException DataError: property "code" is equal to undefined, expected 0
     2PASS IDBFactory cmp() static with throwing/invalid keys
    53PASS IDBCursor continue() method with throwing/invalid keys
    64PASS IndexedDB: Exceptions thrown during key conversion
     
    97PASS IDBKeyRange lowerBound() static with throwing/invalid keys
    108PASS IDBKeyRange upperBound() static with throwing/invalid keys
    11 FAIL IDBKeyRange bound() static with throwing/invalid keys assert_throws: first key conversion with invalid key should throw DataError function "() => {
    12             receiver[method](invalid_key, throwing_key('getter 2'));
    13         }" threw object "getter 2: throwing from getter" that is not a DOMException DataError: property "code" is equal to undefined, expected 0
    14 FAIL IDBObjectStore add() method with throwing/invalid keys assert_throws: key conversion with throwing getter should rethrow function "() => {
    15             out_of_line[method]('value', throwing_key('getter'));
    16         }" threw object "DataCloneError: Failed to store record in an IDBObjectStore: An object could not be cloned." ("DataCloneError") expected object "[object Object]" ("getter")
    17 FAIL IDBObjectStore put() method with throwing/invalid keys assert_throws: key conversion with throwing getter should rethrow function "() => {
    18             out_of_line[method]('value', throwing_key('getter'));
    19         }" threw object "DataCloneError: Failed to store record in an IDBObjectStore: An object could not be cloned." ("DataCloneError") expected object "[object Object]" ("getter")
     9PASS IDBKeyRange bound() static with throwing/invalid keys
     10PASS IDBObjectStore add() method with throwing/invalid keys
     11PASS IDBObjectStore put() method with throwing/invalid keys
    2012PASS IDBObjectStore delete() method with throwing/invalid keys
    2113PASS IDBObjectStore get() method with throwing/invalid keys
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/keygenerator-inject-expected.txt

    r213882 r243348  
    44PASS Key is injected into value - multi-segment path, partially populated
    55PASS put() throws if key cannot be injected - single segment path
    6 FAIL put() throws if key cannot be injected - multi-segment path assert_throws: Key path should be checked against value function "() => {
    7       store.put({a: {b: 123} });
    8     }" did not throw
     6PASS put() throws if key cannot be injected - multi-segment path
    97
  • trunk/LayoutTests/imported/w3c/web-platform-tests/IndexedDB/wasm-module-value-expected.txt

    r232641 r243348  
    11
    2 FAIL WebAssembly module as an IndexedDB value Failed to store record in an IDBObjectStore: An object could not be cloned.
    3 FAIL WebAssembly module in a JavaScript object IndexedDB value Failed to store record in an IDBObjectStore: An object could not be cloned.
    4 FAIL WebAssembly module in an IndexedDB value with an inline key Failed to store record in an IDBObjectStore: An object could not be cloned.
     2FAIL WebAssembly module as an IndexedDB value The object can not be cloned.
     3FAIL WebAssembly module in a JavaScript object IndexedDB value The object can not be cloned.
     4FAIL WebAssembly module in an IndexedDB value with an inline key The object can not be cloned.
    55
  • trunk/LayoutTests/storage/indexeddb/clone-exception-expected.txt

    r195181 r243348  
    1313PASS code is 25
    1414PASS ename is 'DataCloneError'
    15 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     15Exception message: The object can not be cloned.
    1616
    1717doSecondOpen():
     
    2323PASS code is 25
    2424PASS ename is 'DataCloneError'
    25 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     25Exception message: The object can not be cloned.
    2626
    2727doThirdOpen():
     
    3333PASS code is 25
    3434PASS ename is 'DataCloneError'
    35 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     35Exception message: The object can not be cloned.
    3636PASS successfullyParsed is true
    3737
  • trunk/LayoutTests/storage/indexeddb/clone-exception-private-expected.txt

    r195394 r243348  
    1313PASS code is 25
    1414PASS ename is 'DataCloneError'
    15 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     15Exception message: The object can not be cloned.
    1616
    1717doSecondOpen():
     
    2323PASS code is 25
    2424PASS ename is 'DataCloneError'
    25 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     25Exception message: The object can not be cloned.
    2626
    2727doThirdOpen():
     
    3333PASS code is 25
    3434PASS ename is 'DataCloneError'
    35 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     35Exception message: The object can not be cloned.
    3636PASS successfullyParsed is true
    3737
  • trunk/LayoutTests/storage/indexeddb/exceptions-expected.txt

    r210148 r243348  
    160160PASS Exception was thrown.
    161161PASS code is DOMException.DATA_CLONE_ERR
    162 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     162Exception message: The object can not be cloned.
    163163
    164164IDBObjectStore.clear()
     
    273273PASS Exception was thrown.
    274274PASS code is DOMException.DATA_CLONE_ERR
    275 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     275Exception message: The object can not be cloned.
    276276db.close()
    277277ro_transaction.oncomplete = transactionComplete
     
    505505PASS Exception was thrown.
    506506PASS code is DOMException.DATA_CLONE_ERR
    507 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     507Exception message: The object can not be cloned.
    508508The transaction this IDBCursor belongs to is not active.
    509509Expecting exception from cursorFromInactiveTransaction.update({})
  • trunk/LayoutTests/storage/indexeddb/exceptions-private-expected.txt

    r210148 r243348  
    160160PASS Exception was thrown.
    161161PASS code is DOMException.DATA_CLONE_ERR
    162 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     162Exception message: The object can not be cloned.
    163163
    164164IDBObjectStore.clear()
     
    273273PASS Exception was thrown.
    274274PASS code is DOMException.DATA_CLONE_ERR
    275 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     275Exception message: The object can not be cloned.
    276276db.close()
    277277ro_transaction.oncomplete = transactionComplete
     
    505505PASS Exception was thrown.
    506506PASS code is DOMException.DATA_CLONE_ERR
    507 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     507Exception message: The object can not be cloned.
    508508The transaction this IDBCursor belongs to is not active.
    509509Expecting exception from cursorFromInactiveTransaction.update({})
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt

    r195181 r243348  
    9595PASS Exception was thrown.
    9696PASS code is DOMException.DATA_CLONE_ERR
    97 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     97Exception message: The object can not be cloned.
    9898Try to insert data where key path yields a Date key:
    9999store.add({x: testDateB, y: 'value'}, 'key')
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics-private-expected.txt

    r195247 r243348  
    9595PASS Exception was thrown.
    9696PASS code is DOMException.DATA_CLONE_ERR
    97 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     97Exception message: The object can not be cloned.
    9898Try to insert data where key path yields a Date key:
    9999store.add({x: testDateB, y: 'value'}, 'key')
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics-workers-expected.txt

    r200521 r243348  
    9696PASS [Worker] Exception was thrown.
    9797PASS [Worker] code is DOMException.DATA_CLONE_ERR
    98 [Worker] Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     98[Worker] Exception message: The object can not be cloned.
    9999[Worker] Try to insert data where key path yields a Date key:
    100100[Worker] store.add({x: testDateB, y: 'value'}, 'key')
  • trunk/LayoutTests/storage/indexeddb/structured-clone-expected.txt

    r195181 r243348  
    783783PASS Exception was thrown.
    784784PASS code is DOMException.DATA_CLONE_ERR
    785 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     785Exception message: The object can not be cloned.
    786786Expecting exception from store.put(new Function, 'key')
    787787PASS Exception was thrown.
    788788PASS code is DOMException.DATA_CLONE_ERR
    789 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     789Exception message: The object can not be cloned.
    790790
    791791Other host object types:
     
    793793PASS Exception was thrown.
    794794PASS code is DOMException.DATA_CLONE_ERR
    795 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     795Exception message: The object can not be cloned.
    796796Expecting exception from store.put(document, 'key')
    797797PASS Exception was thrown.
    798798PASS code is DOMException.DATA_CLONE_ERR
    799 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     799Exception message: The object can not be cloned.
    800800Expecting exception from store.put(document.body, 'key')
    801801PASS Exception was thrown.
    802802PASS code is DOMException.DATA_CLONE_ERR
    803 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     803Exception message: The object can not be cloned.
    804804PASS successfullyParsed is true
    805805
  • trunk/LayoutTests/storage/indexeddb/structured-clone-private-expected.txt

    r195394 r243348  
    783783PASS Exception was thrown.
    784784PASS code is DOMException.DATA_CLONE_ERR
    785 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     785Exception message: The object can not be cloned.
    786786Expecting exception from store.put(new Function, 'key')
    787787PASS Exception was thrown.
    788788PASS code is DOMException.DATA_CLONE_ERR
    789 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     789Exception message: The object can not be cloned.
    790790
    791791Other host object types:
     
    793793PASS Exception was thrown.
    794794PASS code is DOMException.DATA_CLONE_ERR
    795 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     795Exception message: The object can not be cloned.
    796796Expecting exception from store.put(document, 'key')
    797797PASS Exception was thrown.
    798798PASS code is DOMException.DATA_CLONE_ERR
    799 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     799Exception message: The object can not be cloned.
    800800Expecting exception from store.put(document.body, 'key')
    801801PASS Exception was thrown.
    802802PASS code is DOMException.DATA_CLONE_ERR
    803 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     803Exception message: The object can not be cloned.
    804804PASS successfullyParsed is true
    805805
  • trunk/LayoutTests/storage/indexeddb/wasm-exceptions-expected.txt

    r215353 r243348  
    1212PASS Exception was thrown.
    1313PASS code is DOMException.DATA_CLONE_ERR
    14 Exception message: Failed to store record in an IDBObjectStore: An object could not be cloned.
     14Exception message: The object can not be cloned.
    1515PASS successfullyParsed is true
    1616
  • trunk/Source/WebCore/ChangeLog

    r243346 r243348  
     12019-03-21  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Fix key path extraction code in IndexedDB to check own property
     4        https://bugs.webkit.org/show_bug.cgi?id=196099
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Covered by existing tests.
     9
     10        * Modules/indexeddb/IDBFactory.cpp:
     11        (WebCore::IDBFactory::cmp):
     12        We don't need to check the second parameters if the first is already invalid.
     13
     14        * Modules/indexeddb/IDBKeyRange.cpp:
     15        (WebCore::IDBKeyRange::bound):
     16        Ditto.
     17
     18        * Modules/indexeddb/IDBObjectStore.cpp:
     19        (WebCore::IDBObjectStore::putOrAdd):
     20        we should not clear the exception during serialization because the execeptions may be explicitly thrown by parameters.
     21
     22        * bindings/js/IDBBindingUtilities.cpp:
     23        (WebCore::get):
     24        Fix implementation according to https://www.w3.org/TR/IndexedDB-2/#extract-key-from-value.
     25
     26        (WebCore::canInjectNthValueOnKeyPath):
     27        Check the last identifier.
     28
    1292019-03-21  Antoine Quint  <graouts@apple.com>
    230
  • trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp

    r239461 r243348  
    124124{
    125125    auto first = scriptValueToIDBKey(execState, firstValue);
     126    if (!first->isValid())
     127        return Exception { DataError, "Failed to execute 'cmp' on 'IDBFactory': The parameter is not a valid key."_s };
     128
    126129    auto second = scriptValueToIDBKey(execState, secondValue);
    127 
    128     if (!first->isValid() || !second->isValid())
     130    if (!second->isValid())
    129131        return Exception { DataError, "Failed to execute 'cmp' on 'IDBFactory': The parameter is not a valid key."_s };
    130132
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp

    r228218 r243348  
    9393{
    9494    auto lower = scriptValueToIDBKey(state, lowerValue);
     95    if (!lower->isValid())
     96        return Exception { DataError };
    9597    auto upper = scriptValueToIDBKey(state, upperValue);
    96 
    97     if (!lower->isValid() || !upper->isValid())
     98    if (!upper->isValid())
    9899        return Exception { DataError };
    99100    if (upper->isLessThan(lower.get()))
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp

    r243163 r243348  
    341341
    342342    auto serializedValue = SerializedScriptValue::create(state, value);
    343     if (UNLIKELY(scope.exception())) {
    344         // Clear the DOM exception from the serializer so we can give a more targeted exception.
    345         scope.clearException();
    346 
     343    if (UNLIKELY(scope.exception()))
    347344        return Exception { DataCloneError, "Failed to store record in an IDBObjectStore: An object could not be cloned."_s };
    348     }
    349345
    350346    bool privateBrowsingEnabled = false;
  • trunk/Source/WebCore/bindings/js/IDBBindingUtilities.cpp

    r238632 r243348  
    3838#include "IDBValue.h"
    3939#include "IndexKey.h"
     40#include "JSBlob.h"
    4041#include "JSDOMBinding.h"
    4142#include "JSDOMConvertDate.h"
    4243#include "JSDOMConvertNullable.h"
     44#include "JSFile.h"
    4345#include "Logging.h"
    4446#include "MessagePort.h"
     
    6264    if (!object.isObject())
    6365        return false;
     66
     67    auto* obj = asObject(object);
    6468    Identifier identifier = Identifier::fromString(&exec.vm(), keyPathElement);
    65     if (!asObject(object)->hasProperty(&exec, identifier))
    66         return false;
    67     result = asObject(object)->get(&exec, identifier);
     69    auto& vm = exec.vm();
     70    if (obj->inherits<JSArray>(vm) && keyPathElement == "length") {
     71        result = obj->get(&exec, identifier);
     72        return true;
     73    }
     74    if (obj->inherits<JSBlob>(vm) && (keyPathElement == "size" || keyPathElement == "type")) {
     75        if (keyPathElement == "size") {
     76            result = jsNumber(jsCast<JSBlob*>(obj)->wrapped().size());
     77            return true;
     78        }
     79        if (keyPathElement == "type") {
     80            result = jsString(&vm, jsCast<JSBlob*>(obj)->wrapped().type());
     81            return true;
     82        }
     83    }
     84    if (obj->inherits<JSFile>(vm)) {
     85        if (keyPathElement == "name") {
     86            result = jsString(&vm, jsCast<JSFile*>(obj)->wrapped().name());
     87            return true;
     88        }
     89        if (keyPathElement == "lastModified") {
     90            result = jsNumber(jsCast<JSFile*>(obj)->wrapped().lastModified());
     91            return true;
     92        }
     93        if (keyPathElement == "lastModifiedDate") {
     94            result = jsDate(exec, jsCast<JSFile*>(obj)->wrapped().lastModified());
     95            return true;
     96        }
     97    }
     98
     99    PropertyDescriptor descriptor;
     100    if (!obj->getOwnPropertyDescriptor(&exec, identifier, descriptor))
     101        return false;
     102    if (!descriptor.enumerable())
     103        return false;
     104
     105    result = obj->get(&exec, identifier);
    68106    return true;
    69107}
     
    256294
    257295    ASSERT(index <= keyPathElements.size());
    258     for (size_t i = 0; i < index; ++i) {
     296    for (size_t i = 0; i <= index; ++i) {
    259297        JSValue parentValue(currentValue);
    260298        const String& keyPathElement = keyPathElements[i];
Note: See TracChangeset for help on using the changeset viewer.