Changeset 74266 in webkit


Ignore:
Timestamp:
Dec 17, 2010 7:10:21 AM (13 years ago)
Author:
hans@chromium.org
Message:

2010-12-17 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

IndexedDB: Support Date objects as keys.
https://bugs.webkit.org/show_bug.cgi?id=51193

Update layout tests to check that having Date objects as keys work.

  • storage/indexeddb/objectstore-basics-expected.txt:
  • storage/indexeddb/objectstore-basics.html:

2010-12-17 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

IndexedDB: Support Date objects as keys.
https://bugs.webkit.org/show_bug.cgi?id=51193

  • bindings/v8/IDBBindingUtilities.cpp: (WebCore::createIDBKeyFromValue): Use the new IDBKey factory functions, and support Date objects.
  • bindings/v8/custom/V8IDBKeyCustom.cpp: (WebCore::toV8): Create Date objects from DateType keys.
  • storage/IDBKey.cpp: (WebCore::IDBKey::fromQuery): (WebCore::IDBKey::isEqual): (WebCore::IDBKey::whereSyntax): (WebCore::IDBKey::lowerCursorWhereFragment): (WebCore::IDBKey::upperCursorWhereFragment): (WebCore::IDBKey::bind): (WebCore::IDBKey::bindWithNulls): Update all SQL related functions to handle Date keys.
  • storage/IDBKey.h: (WebCore::IDBKey::createNull): (WebCore::IDBKey::createNumber): (WebCore::IDBKey::createString): (WebCore::IDBKey::createDate): Rename the create factories; since both number and date is just a double, function overloading can't be used to discriminate between the factories. (WebCore::IDBKey::date): Add getter for the date value.

2010-12-17 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

IndexedDB: Support Date objects as keys.
https://bugs.webkit.org/show_bug.cgi?id=51193

Update to match the underlying WebCore IDBKey class:
add the DateType, add create() functions for each type,
deprecate the public constructors (will be removed once
Chromium side is updated).

  • public/WebIDBKey.h: (WebKit::WebIDBKey::WebIDBKey):
  • src/AssertMatchingEnums.cpp:
  • src/WebIDBKey.cpp: (WebKit::WebIDBKey::createString): (WebKit::WebIDBKey::createDate): (WebKit::WebIDBKey::createNumber): (WebKit::WebIDBKey::assignNull): (WebKit::WebIDBKey::assignString): (WebKit::WebIDBKey::assignDate): (WebKit::WebIDBKey::assignNumber): (WebKit::WebIDBKey::date):
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r74263 r74266  
     12010-12-17  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        IndexedDB: Support Date objects as keys.
     6        https://bugs.webkit.org/show_bug.cgi?id=51193
     7
     8        Update layout tests to check that having Date objects as keys work.
     9
     10        * storage/indexeddb/objectstore-basics-expected.txt:
     11        * storage/indexeddb/objectstore-basics.html:
     12
    1132010-12-17  Sergio Villar Senin  <svillar@igalia.com>
    214
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt

    r72771 r74266  
    9999store = transaction.objectStore('storeName')
    100100Try to insert data with a Date key:
    101 store.add({x: 'foo'}, new Date())
    102 PASS Exception thrown
    103 PASS code is DOMException.TYPE_MISMATCH_ERR
     101store.add({x: 'foo'}, testDate)
    104102Try to insert a value not handled by structured clone:
    105103store.add({x: 'bar', y: document.getElementById('console')}, 'bar')
     
    107105PASS code is DOMException.NOT_SUPPORTED_ERR
    108106Try to insert data where key path yields a Date key:
    109 store.add({x: new Date()}, 'foo')
    110 PASS Adding data where key path yielded Date key resulted in error.
    111 store.add({x: 'value'}, 'key')
    112 PASS 'onsuccess' in result is true
    113 PASS 'onerror' in result is true
    114 PASS 'readyState' in result is true
    115 An event should fire shortly...
    116 
     107store.add({x: new Date(), y: 'value'}, 'key')
    117108addSuccess():
    118109Success event fired:
     
    128119
    129120PASS event.result is "key"
    130 event.source.add({x: 'value'}, 'zzz')
     121event.source.add({x: 'foo'}, 'zzz')
    131122PASS 'onsuccess' in result is true
    132123PASS 'onerror' in result is true
     
    209200PASS event.target.readyState is event.target.DONE
    210201
    211 PASS event.result.x is "value"
     202PASS event.result.y is "value"
    212203store = event.source
     204store.get(testDate)
     205getSuccessDateKey():
     206Success event fired:
     207PASS 'result' in event is true
     208PASS 'code' in event is false
     209PASS 'message' in event is false
     210PASS 'source' in event is true
     211PASS event.source != null is true
     212PASS 'onsuccess' in event.target is true
     213PASS 'onerror' in event.target is true
     214PASS 'readyState' in event.target is true
     215PASS event.target.readyState is event.target.DONE
     216
     217PASS event.result.x is "foo"
    213218store.delete('key')
    214219PASS 'onsuccess' in result is true
  • trunk/LayoutTests/storage/indexeddb/objectstore-basics.html

    r72771 r74266  
    137137}
    138138
     139var testDate = new Date("August 25, 1991 20:57:08");
    139140
    140141function addData()
     
    145146
    146147    debug("Try to insert data with a Date key:");
    147     // FIXME: This should work in the future.
    148     try {
    149         debug("store.add({x: 'foo'}, new Date())");
    150         store.add({x: 'foo'}, new Date());
    151         testFailed("Passing a Date as key argument should have thrown.");
    152     } catch (err) {
    153         testPassed("Exception thrown");
    154         code = err.code;
    155         shouldBe("code", "DOMException.TYPE_MISMATCH_ERR");
    156     }
    157 
     148    result = evalAndLog("store.add({x: 'foo'}, testDate)");
     149    result.onsuccess = addDateSuccess;
     150    result.onerror = unexpectedErrorCallback;
     151}
     152
     153function addDateSuccess()
     154{
    158155    debug("Try to insert a value not handled by structured clone:");
    159156    try {
     
    167164    }
    168165
    169     // FIXME: This should work in the future.
    170166    debug("Try to insert data where key path yields a Date key:");
    171     result = evalAndLog("store.add({x: new Date()}, 'foo')");
    172     result.onsuccess = unexpectedSuccessCallback;
    173     result.onerror = addKeyPathYieldingDateFailure;
    174 }
    175 
    176 function addKeyPathYieldingDateFailure()
    177 {
    178     testPassed("Adding data where key path yielded Date key resulted in error.");
    179 
    180     result = evalAndLog("store.add({x: 'value'}, 'key')");
    181     verifyResult(result);
     167    result = evalAndLog("store.add({x: new Date(), y: 'value'}, 'key')");
    182168    result.onsuccess = addSuccess;
    183169    result.onerror = unexpectedErrorCallback;
     
    190176    shouldBeEqualToString("event.result", "key");
    191177
    192     result = evalAndLog("event.source.add({x: 'value'}, 'zzz')");
     178    result = evalAndLog("event.source.add({x: 'foo'}, 'zzz')");
    193179    verifyResult(result);
    194180    result.onsuccess = unexpectedSuccessCallback;
     
    249235    debug("getSuccess():");
    250236    verifySuccessEvent(event);
    251     shouldBeEqualToString("event.result.x", "value");
     237    shouldBeEqualToString("event.result.y", "value");
     238
    252239    var store = evalAndLog("store = event.source");
     240    result = evalAndLog("store.get(testDate)");
     241    result.onsuccess = getSuccessDateKey;
     242    result.onerror = unexpectedErrorCallback;
     243}
     244
     245function getSuccessDateKey()
     246{
     247    debug("getSuccessDateKey():");
     248    verifySuccessEvent(event);
     249    shouldBeEqualToString("event.result.x", "foo");
    253250
    254251    result = evalAndLog("store.delete('key')");
  • trunk/WebCore/ChangeLog

    r74261 r74266  
     12010-12-17  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        IndexedDB: Support Date objects as keys.
     6        https://bugs.webkit.org/show_bug.cgi?id=51193
     7
     8        * bindings/v8/IDBBindingUtilities.cpp:
     9        (WebCore::createIDBKeyFromValue):
     10        Use the new IDBKey factory functions, and support Date objects.
     11        * bindings/v8/custom/V8IDBKeyCustom.cpp:
     12        (WebCore::toV8):
     13        Create Date objects from DateType keys.
     14        * storage/IDBKey.cpp:
     15        (WebCore::IDBKey::fromQuery):
     16        (WebCore::IDBKey::isEqual):
     17        (WebCore::IDBKey::whereSyntax):
     18        (WebCore::IDBKey::lowerCursorWhereFragment):
     19        (WebCore::IDBKey::upperCursorWhereFragment):
     20        (WebCore::IDBKey::bind):
     21        (WebCore::IDBKey::bindWithNulls):
     22        Update all SQL related functions to handle Date keys.
     23        * storage/IDBKey.h:
     24        (WebCore::IDBKey::createNull):
     25        (WebCore::IDBKey::createNumber):
     26        (WebCore::IDBKey::createString):
     27        (WebCore::IDBKey::createDate):
     28        Rename the create factories; since both number and date is just a
     29        double, function overloading can't be used to discriminate between
     30        the factories.
     31        (WebCore::IDBKey::date):
     32        Add getter for the date value.
     33
    1342010-12-17  Pavel Podivilov  <podivilov@chromium.org>
    235
  • trunk/WebCore/bindings/v8/IDBBindingUtilities.cpp

    r73697 r74266  
    4141{
    4242    if (value->IsNull())
    43         return IDBKey::create();
     43        return IDBKey::createNull();
    4444    if (value->IsNumber())
    45         return IDBKey::create(value->NumberValue());
     45        return IDBKey::createNumber(value->NumberValue());
    4646    if (value->IsString())
    47         return IDBKey::create(v8ValueToWebCoreString(value));
     47        return IDBKey::createString(v8ValueToWebCoreString(value));
    4848    if (value->IsDate())
    49         return 0; // Signals type error. FIXME: Implement dates.
     49        return IDBKey::createDate(value->NumberValue());
    5050
    5151    return 0; // Signals type error.
  • trunk/WebCore/bindings/v8/custom/V8IDBKeyCustom.cpp

    r73697 r74266  
    4949    case IDBKey::StringType:
    5050        return v8String(key->string());
    51     // FIXME: Implement dates.
     51    case IDBKey::DateType:
     52        return v8::Date::New(key->date());
    5253    }
    5354
  • trunk/WebCore/storage/IDBKey.cpp

    r73697 r74266  
    3939}
    4040
    41 IDBKey::IDBKey(double number)
    42     : m_type(NumberType)
    43     , m_number(number)
    44 {
    45 }
    46 
    47 IDBKey::IDBKey(const String& string)
    48     : m_type(StringType)
    49     , m_string(string.crossThreadString())
    50 {
    51 }
    52 
    5341IDBKey::~IDBKey()
    5442{
     
    5846{
    5947    if (!query.isColumnNull(baseColumn))
    60         return IDBKey::create(query.getColumnText(baseColumn));
     48        return IDBKey::createString(query.getColumnText(baseColumn));
    6149
    62     if (!query.isColumnNull(baseColumn + 1)) {
    63         ASSERT_NOT_REACHED(); // FIXME: Implement date.
    64         return IDBKey::create();
    65     }
     50    if (!query.isColumnNull(baseColumn + 1))
     51        return IDBKey::createDate(query.getColumnDouble(baseColumn + 1));
    6652
    6753    if (!query.isColumnNull(baseColumn + 2))
    68         return IDBKey::create(query.getColumnDouble(baseColumn + 2));
     54        return IDBKey::createNumber(query.getColumnDouble(baseColumn + 2));
    6955
    70     return IDBKey::create(); // Null.
     56    return IDBKey::createNull();
    7157}
    7258
     
    7965    case StringType:
    8066        return other->m_string == m_string;
    81     // FIXME: Implement dates.
     67    case DateType:
     68        return other->m_date == m_date;
    8269    case NumberType:
    8370        return other->m_number == m_number;
     
    9784    case IDBKey::NumberType:
    9885        return qualifiedTableName + "keyString IS NULL  AND  " + qualifiedTableName + "keyDate IS NULL  AND  " + qualifiedTableName + "keyNumber = ?  ";
    99     // FIXME: Implement date.
     86    case IDBKey::DateType:
     87        return qualifiedTableName + "keyString IS NULL  AND  " + qualifiedTableName + "keyDate = ?  AND  " + qualifiedTableName + "keyNumber IS NULL  ";
    10088    case IDBKey::NullType:
    10189        return qualifiedTableName + "keyString IS NULL  AND  " + qualifiedTableName + "keyDate IS NULL  AND  " + qualifiedTableName + "keyNumber IS NULL  ";
     
    11199    case StringType:
    112100        return "? " + comparisonOperator + " " + qualifiedTableName + "keyString  AND  ";
    113     // FIXME: Implement date.
     101    case DateType:
     102        return "(? " + comparisonOperator + " " + qualifiedTableName + "keyDate  OR NOT " + qualifiedTableName + "keyString IS NULL)  AND  ";
    114103    case NumberType:
    115104        return "(? " + comparisonOperator + " " + qualifiedTableName + "keyNumber  OR  NOT " + qualifiedTableName + "keyString IS NULL  OR  NOT " + qualifiedTableName + "keyDate IS NULL)  AND  ";
     
    128117    case StringType:
    129118        return "(" + qualifiedTableName + "keyString " + comparisonOperator + " ?  OR  " + qualifiedTableName + "keyString IS NULL)  AND  ";
    130     // FIXME: Implement date.
     119    case DateType:
     120        return "(" + qualifiedTableName + "keyDate " + comparisonOperator + " ? OR " + qualifiedTableName + "keyDate IS NULL)  AND  " + qualifiedTableName + "keyString IS NULL  AND  ";
    131121    case NumberType:
    132122        return "(" + qualifiedTableName + "keyNumber " + comparisonOperator + " ? OR " + qualifiedTableName + "keyNumber IS NULL)  AND  " + qualifiedTableName + "keyString IS NULL  AND  " + qualifiedTableName + "keyDate IS NULL  AND  ";
     
    146136    case IDBKey::StringType:
    147137        query.bindText(column, m_string);
     138        return 1;
     139    case IDBKey::DateType:
     140        query.bindDouble(column, m_date);
    148141        return 1;
    149142    case IDBKey::NumberType:
     
    166159        query.bindNull(baseColumn + 2);
    167160        break;
     161    case IDBKey::DateType:
     162        query.bindNull(baseColumn + 0);
     163        query.bindDouble(baseColumn + 1, m_date);
     164        query.bindNull(baseColumn + 2);
     165        break;
    168166    case IDBKey::NumberType:
    169167        query.bindNull(baseColumn + 0);
  • trunk/WebCore/storage/IDBKey.h

    r73697 r74266  
    3737class SQLiteStatement;
    3838
    39 // FIXME: Add dates.
    4039class IDBKey : public ThreadSafeShared<IDBKey> {
    4140public:
    42     static PassRefPtr<IDBKey> create()
     41    static PassRefPtr<IDBKey> createNull()
    4342    {
    44         return adoptRef(new IDBKey());
     43        RefPtr<IDBKey> idbKey(new IDBKey());
     44        idbKey->m_type = NullType;
     45        return idbKey.release();
    4546    }
    46     static PassRefPtr<IDBKey> create(double number)
     47
     48    static PassRefPtr<IDBKey> createNumber(double number)
    4749    {
    48         return adoptRef(new IDBKey(number));
     50        RefPtr<IDBKey> idbKey(new IDBKey());
     51        idbKey->m_type = NumberType;
     52        idbKey->m_number = number;
     53        return idbKey.release();
    4954    }
    50     static PassRefPtr<IDBKey> create(const String& string)
     55
     56    static PassRefPtr<IDBKey> createString(const String& string)
    5157    {
    52         return adoptRef(new IDBKey(string));
     58        RefPtr<IDBKey> idbKey(new IDBKey());
     59        idbKey->m_type = StringType;
     60        idbKey->m_string = string;
     61        return idbKey.release();
    5362    }
     63
     64    static PassRefPtr<IDBKey> createDate(double date)
     65    {
     66        RefPtr<IDBKey> idbKey(new IDBKey());
     67        idbKey->m_type = DateType;
     68        idbKey->m_date = date;
     69        return idbKey.release();
     70    }
     71
    5472    ~IDBKey();
    5573
     
    5876        NullType = 0, // FIXME: Phase out support for null keys.
    5977        StringType,
     78        DateType,
    6079        NumberType
    6180    };
     
    6786        ASSERT(m_type == StringType);
    6887        return m_string;
     88    }
     89
     90    double date() const
     91    {
     92        ASSERT(m_type == DateType);
     93        return m_date;
    6994    }
    7095
     
    89114private:
    90115    IDBKey();
    91     explicit IDBKey(double);
    92     explicit IDBKey(const String&);
    93116
    94117    Type m_type;
    95118    String m_string;
     119    double m_date;
    96120    double m_number;
    97121};
  • trunk/WebKit/chromium/ChangeLog

    r74241 r74266  
     12010-12-17  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        IndexedDB: Support Date objects as keys.
     6        https://bugs.webkit.org/show_bug.cgi?id=51193
     7
     8        Update to match the underlying WebCore IDBKey class:
     9        add the DateType, add create() functions for each type,
     10        deprecate the public constructors (will be removed once
     11        Chromium side is updated).
     12
     13        * public/WebIDBKey.h:
     14        (WebKit::WebIDBKey::WebIDBKey):
     15        * src/AssertMatchingEnums.cpp:
     16        * src/WebIDBKey.cpp:
     17        (WebKit::WebIDBKey::createString):
     18        (WebKit::WebIDBKey::createDate):
     19        (WebKit::WebIDBKey::createNumber):
     20        (WebKit::WebIDBKey::assignNull):
     21        (WebKit::WebIDBKey::assignString):
     22        (WebKit::WebIDBKey::assignDate):
     23        (WebKit::WebIDBKey::assignNumber):
     24        (WebKit::WebIDBKey::date):
     25
    1262010-12-17  James Simonsen  <simonjam@chromium.org>
    227
  • trunk/WebKit/chromium/public/WebIDBKey.h

    r73697 r74266  
    4545
    4646    WEBKIT_API static WebIDBKey createNull();
     47    WEBKIT_API static WebIDBKey createString(const WebString&);
     48    WEBKIT_API static WebIDBKey createDate(double);
     49    WEBKIT_API static WebIDBKey createNumber(double);
    4750    WEBKIT_API static WebIDBKey createInvalid();
    4851    WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&);
    4952
    50     WebIDBKey(const WebString& string) { assign(string); }
    51     WebIDBKey(double number) { assign(number); }
     53    // FIXME: Remove these two constructors after Chromium side is done.
     54    WebIDBKey(const WebString& string) { assignString(string); }
     55    WebIDBKey(double number) { assignNumber(number); }
     56
    5257    WebIDBKey(const WebIDBKey& e) { assign(e); }
    5358    WebIDBKey& operator=(const WebIDBKey& e)
     
    5964    WEBKIT_API void assign(const WebIDBKey&);
    6065    WEBKIT_API void assignNull();
    61     WEBKIT_API void assign(const WebString&);
    62     WEBKIT_API void assign(double);
     66    WEBKIT_API void assignString(const WebString&);
     67    WEBKIT_API void assignDate(double);
     68    WEBKIT_API void assignNumber(double);
    6369    WEBKIT_API void assignInvalid();
    6470    WEBKIT_API void reset();
     
    6773        NullType = 0,
    6874        StringType,
     75        DateType,
    6976        NumberType,
    7077        // Types not in WebCore::IDBKey:
     
    7481    WEBKIT_API Type type() const;
    7582    WEBKIT_API WebString string() const; // Only valid for StringType.
    76     WEBKIT_API double number() const; // Only valid for numberType.
     83    WEBKIT_API double date() const; // Only valid for DateType.
     84    WEBKIT_API double number() const; // Only valid for NumberType.
    7785
    7886#if WEBKIT_IMPLEMENTATION
  • trunk/WebKit/chromium/src/AssertMatchingEnums.cpp

    r72624 r74266  
    366366COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NullType, IDBKey::NullType);
    367367COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::StringType, IDBKey::StringType);
     368COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::DateType, IDBKey::DateType);
    368369COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NumberType, IDBKey::NumberType);
    369370
  • trunk/WebKit/chromium/src/WebIDBKey.cpp

    r73697 r74266  
    4949}
    5050
     51WebIDBKey WebIDBKey::createString(const WebString& string)
     52{
     53    WebIDBKey key;
     54    key.assignString(string);
     55    return key;
     56}
     57
     58WebIDBKey WebIDBKey::createDate(double date)
     59{
     60    WebIDBKey key;
     61    key.assignDate(date);
     62    return key;
     63}
     64
     65WebIDBKey WebIDBKey::createNumber(double number)
     66{
     67    WebIDBKey key;
     68    key.assignNumber(number);
     69    return key;
     70}
     71
    5172WebIDBKey WebIDBKey::createInvalid()
    5273{
     
    7091void WebIDBKey::assignNull()
    7192{
    72     m_private = IDBKey::create();
     93    m_private = IDBKey::createNull();
    7394}
    7495
    75 void WebIDBKey::assign(const WebString& string)
     96void WebIDBKey::assignString(const WebString& string)
    7697{
    77     m_private = IDBKey::create(string);
     98    m_private = IDBKey::createString(string);
    7899}
    79100
    80 void WebIDBKey::assign(double number)
     101void WebIDBKey::assignDate(double date)
    81102{
    82     m_private = IDBKey::create(number);
     103    m_private = IDBKey::createDate(date);
     104}
     105
     106void WebIDBKey::assignNumber(double number)
     107{
     108    m_private = IDBKey::createNumber(number);
    83109}
    84110
     
    103129{
    104130    return m_private->string();
     131}
     132
     133double WebIDBKey::date() const
     134{
     135    return m_private->date();
    105136}
    106137
Note: See TracChangeset for help on using the changeset viewer.