Changeset 74266 in webkit
- Timestamp:
- Dec 17, 2010 7:10:21 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r74263 r74266 1 2010-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 1 13 2010-12-17 Sergio Villar Senin <svillar@igalia.com> 2 14 -
trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt
r72771 r74266 99 99 store = transaction.objectStore('storeName') 100 100 Try 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 101 store.add({x: 'foo'}, testDate) 104 102 Try to insert a value not handled by structured clone: 105 103 store.add({x: 'bar', y: document.getElementById('console')}, 'bar') … … 107 105 PASS code is DOMException.NOT_SUPPORTED_ERR 108 106 Try 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 107 store.add({x: new Date(), y: 'value'}, 'key') 117 108 addSuccess(): 118 109 Success event fired: … … 128 119 129 120 PASS event.result is "key" 130 event.source.add({x: ' value'}, 'zzz')121 event.source.add({x: 'foo'}, 'zzz') 131 122 PASS 'onsuccess' in result is true 132 123 PASS 'onerror' in result is true … … 209 200 PASS event.target.readyState is event.target.DONE 210 201 211 PASS event.result. xis "value"202 PASS event.result.y is "value" 212 203 store = event.source 204 store.get(testDate) 205 getSuccessDateKey(): 206 Success event fired: 207 PASS 'result' in event is true 208 PASS 'code' in event is false 209 PASS 'message' in event is false 210 PASS 'source' in event is true 211 PASS event.source != null is true 212 PASS 'onsuccess' in event.target is true 213 PASS 'onerror' in event.target is true 214 PASS 'readyState' in event.target is true 215 PASS event.target.readyState is event.target.DONE 216 217 PASS event.result.x is "foo" 213 218 store.delete('key') 214 219 PASS 'onsuccess' in result is true -
trunk/LayoutTests/storage/indexeddb/objectstore-basics.html
r72771 r74266 137 137 } 138 138 139 var testDate = new Date("August 25, 1991 20:57:08"); 139 140 140 141 function addData() … … 145 146 146 147 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 153 function addDateSuccess() 154 { 158 155 debug("Try to insert a value not handled by structured clone:"); 159 156 try { … … 167 164 } 168 165 169 // FIXME: This should work in the future.170 166 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')"); 182 168 result.onsuccess = addSuccess; 183 169 result.onerror = unexpectedErrorCallback; … … 190 176 shouldBeEqualToString("event.result", "key"); 191 177 192 result = evalAndLog("event.source.add({x: ' value'}, 'zzz')");178 result = evalAndLog("event.source.add({x: 'foo'}, 'zzz')"); 193 179 verifyResult(result); 194 180 result.onsuccess = unexpectedSuccessCallback; … … 249 235 debug("getSuccess():"); 250 236 verifySuccessEvent(event); 251 shouldBeEqualToString("event.result.x", "value"); 237 shouldBeEqualToString("event.result.y", "value"); 238 252 239 var store = evalAndLog("store = event.source"); 240 result = evalAndLog("store.get(testDate)"); 241 result.onsuccess = getSuccessDateKey; 242 result.onerror = unexpectedErrorCallback; 243 } 244 245 function getSuccessDateKey() 246 { 247 debug("getSuccessDateKey():"); 248 verifySuccessEvent(event); 249 shouldBeEqualToString("event.result.x", "foo"); 253 250 254 251 result = evalAndLog("store.delete('key')"); -
trunk/WebCore/ChangeLog
r74261 r74266 1 2010-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 1 34 2010-12-17 Pavel Podivilov <podivilov@chromium.org> 2 35 -
trunk/WebCore/bindings/v8/IDBBindingUtilities.cpp
r73697 r74266 41 41 { 42 42 if (value->IsNull()) 43 return IDBKey::create ();43 return IDBKey::createNull(); 44 44 if (value->IsNumber()) 45 return IDBKey::create (value->NumberValue());45 return IDBKey::createNumber(value->NumberValue()); 46 46 if (value->IsString()) 47 return IDBKey::create (v8ValueToWebCoreString(value));47 return IDBKey::createString(v8ValueToWebCoreString(value)); 48 48 if (value->IsDate()) 49 return 0; // Signals type error. FIXME: Implement dates.49 return IDBKey::createDate(value->NumberValue()); 50 50 51 51 return 0; // Signals type error. -
trunk/WebCore/bindings/v8/custom/V8IDBKeyCustom.cpp
r73697 r74266 49 49 case IDBKey::StringType: 50 50 return v8String(key->string()); 51 // FIXME: Implement dates. 51 case IDBKey::DateType: 52 return v8::Date::New(key->date()); 52 53 } 53 54 -
trunk/WebCore/storage/IDBKey.cpp
r73697 r74266 39 39 } 40 40 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 53 41 IDBKey::~IDBKey() 54 42 { … … 58 46 { 59 47 if (!query.isColumnNull(baseColumn)) 60 return IDBKey::create (query.getColumnText(baseColumn));48 return IDBKey::createString(query.getColumnText(baseColumn)); 61 49 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)); 66 52 67 53 if (!query.isColumnNull(baseColumn + 2)) 68 return IDBKey::create (query.getColumnDouble(baseColumn + 2));54 return IDBKey::createNumber(query.getColumnDouble(baseColumn + 2)); 69 55 70 return IDBKey::create (); // Null.56 return IDBKey::createNull(); 71 57 } 72 58 … … 79 65 case StringType: 80 66 return other->m_string == m_string; 81 // FIXME: Implement dates. 67 case DateType: 68 return other->m_date == m_date; 82 69 case NumberType: 83 70 return other->m_number == m_number; … … 97 84 case IDBKey::NumberType: 98 85 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 "; 100 88 case IDBKey::NullType: 101 89 return qualifiedTableName + "keyString IS NULL AND " + qualifiedTableName + "keyDate IS NULL AND " + qualifiedTableName + "keyNumber IS NULL "; … … 111 99 case StringType: 112 100 return "? " + comparisonOperator + " " + qualifiedTableName + "keyString AND "; 113 // FIXME: Implement date. 101 case DateType: 102 return "(? " + comparisonOperator + " " + qualifiedTableName + "keyDate OR NOT " + qualifiedTableName + "keyString IS NULL) AND "; 114 103 case NumberType: 115 104 return "(? " + comparisonOperator + " " + qualifiedTableName + "keyNumber OR NOT " + qualifiedTableName + "keyString IS NULL OR NOT " + qualifiedTableName + "keyDate IS NULL) AND "; … … 128 117 case StringType: 129 118 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 "; 131 121 case NumberType: 132 122 return "(" + qualifiedTableName + "keyNumber " + comparisonOperator + " ? OR " + qualifiedTableName + "keyNumber IS NULL) AND " + qualifiedTableName + "keyString IS NULL AND " + qualifiedTableName + "keyDate IS NULL AND "; … … 146 136 case IDBKey::StringType: 147 137 query.bindText(column, m_string); 138 return 1; 139 case IDBKey::DateType: 140 query.bindDouble(column, m_date); 148 141 return 1; 149 142 case IDBKey::NumberType: … … 166 159 query.bindNull(baseColumn + 2); 167 160 break; 161 case IDBKey::DateType: 162 query.bindNull(baseColumn + 0); 163 query.bindDouble(baseColumn + 1, m_date); 164 query.bindNull(baseColumn + 2); 165 break; 168 166 case IDBKey::NumberType: 169 167 query.bindNull(baseColumn + 0); -
trunk/WebCore/storage/IDBKey.h
r73697 r74266 37 37 class SQLiteStatement; 38 38 39 // FIXME: Add dates.40 39 class IDBKey : public ThreadSafeShared<IDBKey> { 41 40 public: 42 static PassRefPtr<IDBKey> create ()41 static PassRefPtr<IDBKey> createNull() 43 42 { 44 return adoptRef(new IDBKey()); 43 RefPtr<IDBKey> idbKey(new IDBKey()); 44 idbKey->m_type = NullType; 45 return idbKey.release(); 45 46 } 46 static PassRefPtr<IDBKey> create(double number) 47 48 static PassRefPtr<IDBKey> createNumber(double number) 47 49 { 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(); 49 54 } 50 static PassRefPtr<IDBKey> create(const String& string) 55 56 static PassRefPtr<IDBKey> createString(const String& string) 51 57 { 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(); 53 62 } 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 54 72 ~IDBKey(); 55 73 … … 58 76 NullType = 0, // FIXME: Phase out support for null keys. 59 77 StringType, 78 DateType, 60 79 NumberType 61 80 }; … … 67 86 ASSERT(m_type == StringType); 68 87 return m_string; 88 } 89 90 double date() const 91 { 92 ASSERT(m_type == DateType); 93 return m_date; 69 94 } 70 95 … … 89 114 private: 90 115 IDBKey(); 91 explicit IDBKey(double);92 explicit IDBKey(const String&);93 116 94 117 Type m_type; 95 118 String m_string; 119 double m_date; 96 120 double m_number; 97 121 }; -
trunk/WebKit/chromium/ChangeLog
r74241 r74266 1 2010-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 1 26 2010-12-17 James Simonsen <simonjam@chromium.org> 2 27 -
trunk/WebKit/chromium/public/WebIDBKey.h
r73697 r74266 45 45 46 46 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); 47 50 WEBKIT_API static WebIDBKey createInvalid(); 48 51 WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&); 49 52 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 52 57 WebIDBKey(const WebIDBKey& e) { assign(e); } 53 58 WebIDBKey& operator=(const WebIDBKey& e) … … 59 64 WEBKIT_API void assign(const WebIDBKey&); 60 65 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); 63 69 WEBKIT_API void assignInvalid(); 64 70 WEBKIT_API void reset(); … … 67 73 NullType = 0, 68 74 StringType, 75 DateType, 69 76 NumberType, 70 77 // Types not in WebCore::IDBKey: … … 74 81 WEBKIT_API Type type() const; 75 82 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. 77 85 78 86 #if WEBKIT_IMPLEMENTATION -
trunk/WebKit/chromium/src/AssertMatchingEnums.cpp
r72624 r74266 366 366 COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NullType, IDBKey::NullType); 367 367 COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::StringType, IDBKey::StringType); 368 COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::DateType, IDBKey::DateType); 368 369 COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NumberType, IDBKey::NumberType); 369 370 -
trunk/WebKit/chromium/src/WebIDBKey.cpp
r73697 r74266 49 49 } 50 50 51 WebIDBKey WebIDBKey::createString(const WebString& string) 52 { 53 WebIDBKey key; 54 key.assignString(string); 55 return key; 56 } 57 58 WebIDBKey WebIDBKey::createDate(double date) 59 { 60 WebIDBKey key; 61 key.assignDate(date); 62 return key; 63 } 64 65 WebIDBKey WebIDBKey::createNumber(double number) 66 { 67 WebIDBKey key; 68 key.assignNumber(number); 69 return key; 70 } 71 51 72 WebIDBKey WebIDBKey::createInvalid() 52 73 { … … 70 91 void WebIDBKey::assignNull() 71 92 { 72 m_private = IDBKey::create ();93 m_private = IDBKey::createNull(); 73 94 } 74 95 75 void WebIDBKey::assign (const WebString& string)96 void WebIDBKey::assignString(const WebString& string) 76 97 { 77 m_private = IDBKey::create (string);98 m_private = IDBKey::createString(string); 78 99 } 79 100 80 void WebIDBKey::assign (double number)101 void WebIDBKey::assignDate(double date) 81 102 { 82 m_private = IDBKey::create(number); 103 m_private = IDBKey::createDate(date); 104 } 105 106 void WebIDBKey::assignNumber(double number) 107 { 108 m_private = IDBKey::createNumber(number); 83 109 } 84 110 … … 103 129 { 104 130 return m_private->string(); 131 } 132 133 double WebIDBKey::date() const 134 { 135 return m_private->date(); 105 136 } 106 137
Note: See TracChangeset
for help on using the changeset viewer.