IndexedDB onupgradeneeded event has incorrect value for oldVersion.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jun 2015 00:17:32 +0000 (00:17 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jun 2015 00:17:32 +0000 (00:17 +0000)
<rdar://problem/18309792> and https://bugs.webkit.org/show_bug.cgi?id=136888

Reviewed by Sam Weinig.

Source/WebCore:

Test: storage/indexeddb/version-change-event-basic.html

"NoIntVersion" is an internal bookkeeping concept that we never should've been passing to Javascript.

This cleans up things by:
- Adjusting an old version of "NoIntVersion" to "0" before making the version change callback.
- Removing the VersionNullness parameter from almost everywhere.
- Removing the nullability of the newVersion parameter from the IDL.

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::onVersionChange):
* Modules/indexeddb/IDBDatabase.h:

* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::runIntVersionChangeTransaction):
(WebCore::IDBDatabaseBackend::deleteDatabase):

* Modules/indexeddb/IDBDatabaseCallbacks.h:
* Modules/indexeddb/IDBDatabaseCallbacksImpl.cpp:
(WebCore::IDBDatabaseCallbacksImpl::onVersionChange):
* Modules/indexeddb/IDBDatabaseCallbacksImpl.h:

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::onBlocked):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):

* Modules/indexeddb/IDBTransactionBackendOperations.cpp:
(WebCore::IDBDatabaseBackend::VersionChangeOperation::perform):

* Modules/indexeddb/IDBVersionChangeEvent.cpp:
(WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):
* Modules/indexeddb/IDBVersionChangeEvent.h:
(WebCore::IDBVersionChangeEvent::create):
(WebCore::IDBVersionChangeEvent::newVersion):
* Modules/indexeddb/IDBVersionChangeEvent.idl:

LayoutTests:

* storage/indexeddb/version-change-event-basic-expected.txt: Added.
* storage/indexeddb/version-change-event-basic.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185480 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/version-change-event-basic-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/version-change-event-basic.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp
Source/WebCore/Modules/indexeddb/IDBDatabaseCallbacks.h
Source/WebCore/Modules/indexeddb/IDBDatabaseCallbacksImpl.cpp
Source/WebCore/Modules/indexeddb/IDBDatabaseCallbacksImpl.h
Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp
Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.cpp
Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.h
Source/WebCore/Modules/indexeddb/IDBVersionChangeEvent.idl

index 6c3b057..ae9bbd7 100644 (file)
@@ -1,3 +1,13 @@
+2015-06-11  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB onupgradeneeded event has incorrect value for oldVersion.
+        <rdar://problem/18309792> and https://bugs.webkit.org/show_bug.cgi?id=136888
+
+        Reviewed by Sam Weinig.
+
+        * storage/indexeddb/version-change-event-basic-expected.txt: Added.
+        * storage/indexeddb/version-change-event-basic.html: Added.
+
 2015-06-11  Dean Jackson  <dino@apple.com>
 
         Add an appearance keyword for wireless playback / airplay icon
diff --git a/LayoutTests/storage/indexeddb/version-change-event-basic-expected.txt b/LayoutTests/storage/indexeddb/version-change-event-basic-expected.txt
new file mode 100644 (file)
index 0000000..e1707f6
--- /dev/null
@@ -0,0 +1,7 @@
+0 version: TypeError: Type error
+Negative version: TypeError: Type error
+String version: TypeError: Type error
+First request: 0 1
+Second request: 0 1
+Third request: 0 2
+
diff --git a/LayoutTests/storage/indexeddb/version-change-event-basic.html b/LayoutTests/storage/indexeddb/version-change-event-basic.html
new file mode 100644 (file)
index 0000000..0a7a81b
--- /dev/null
@@ -0,0 +1,51 @@
+<body>
+<div id="logger"></div>
+<script>
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function log(msg) {
+    document.getElementById("logger").innerHTML += msg + "<br>";
+}
+
+var request1 = indexedDB.open("vceb1");
+request1.onupgradeneeded = function(e) {
+    log("First request: " + e.oldVersion + " " + e.newVersion);
+}
+
+var request2 = indexedDB.open("vceb2", 1);
+request2.onupgradeneeded = function(e) {
+    log("Second request: " + e.oldVersion + " " + e.newVersion);
+}
+
+var request3 = indexedDB.open("vceb3", 2);
+request3.onupgradeneeded = function(e) {
+    log("Third request: " + e.oldVersion + " " + e.newVersion);
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+try {
+    var request = indexedDB.open("vceb4", 0);
+} catch (e) {
+    log("0 version: " + e);
+}
+
+try {
+    var request = indexedDB.open("vceb5", -1);
+} catch (e) {
+    log("Negative version: " + e);
+}
+
+try {
+    var request = indexedDB.open("vceb6", "string");
+} catch (e) {
+    log("String version: " + e);
+}
+
+</script>
+</body>
+</html>
index 2e08004..31c36f1 100644 (file)
@@ -1,3 +1,46 @@
+2015-06-11  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB onupgradeneeded event has incorrect value for oldVersion.
+        <rdar://problem/18309792> and https://bugs.webkit.org/show_bug.cgi?id=136888
+
+        Reviewed by Sam Weinig.
+
+        Test: storage/indexeddb/version-change-event-basic.html
+
+        "NoIntVersion" is an internal bookkeeping concept that we never should've been passing to Javascript.
+        
+        This cleans up things by:
+        - Adjusting an old version of "NoIntVersion" to "0" before making the version change callback.
+        - Removing the VersionNullness parameter from almost everywhere.
+        - Removing the nullability of the newVersion parameter from the IDL.
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::onVersionChange):
+        * Modules/indexeddb/IDBDatabase.h:
+        
+        * Modules/indexeddb/IDBDatabaseBackend.cpp:
+        (WebCore::IDBDatabaseBackend::runIntVersionChangeTransaction):
+        (WebCore::IDBDatabaseBackend::deleteDatabase):
+        
+        * Modules/indexeddb/IDBDatabaseCallbacks.h:
+        * Modules/indexeddb/IDBDatabaseCallbacksImpl.cpp:
+        (WebCore::IDBDatabaseCallbacksImpl::onVersionChange):
+        * Modules/indexeddb/IDBDatabaseCallbacksImpl.h:
+        
+        * Modules/indexeddb/IDBOpenDBRequest.cpp:
+        (WebCore::IDBOpenDBRequest::onBlocked):
+        (WebCore::IDBOpenDBRequest::onUpgradeNeeded):
+        
+        * Modules/indexeddb/IDBTransactionBackendOperations.cpp:
+        (WebCore::IDBDatabaseBackend::VersionChangeOperation::perform):
+        
+        * Modules/indexeddb/IDBVersionChangeEvent.cpp:
+        (WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):
+        * Modules/indexeddb/IDBVersionChangeEvent.h:
+        (WebCore::IDBVersionChangeEvent::create):
+        (WebCore::IDBVersionChangeEvent::newVersion):
+        * Modules/indexeddb/IDBVersionChangeEvent.idl:
+
 2015-06-11  Matt Rajca  <mrajca@apple.com>
 
         Media Session: Add plumbing for media control event delivery.
index 8469519..4eb6818 100644 (file)
@@ -325,7 +325,7 @@ void IDBDatabase::closeConnection()
     m_isClosed = true;
 }
 
-void IDBDatabase::onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness)
+void IDBDatabase::onVersionChange(uint64_t oldVersion, uint64_t newVersion)
 {
     LOG(StorageAPI, "IDBDatabase::onVersionChange");
     if (m_contextStopped || !scriptExecutionContext())
@@ -334,7 +334,8 @@ void IDBDatabase::onVersionChange(uint64_t oldVersion, uint64_t newVersion, Inde
     if (m_closePending)
         return;
 
-    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, newVersion, newVersionNullness, eventNames().versionchangeEvent));
+    ASSERT(newVersion != IDBDatabaseMetadata::NoIntVersion && newVersion != IDBDatabaseMetadata::DefaultIntVersion);
+    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, newVersion, eventNames().versionchangeEvent));
 }
 
 void IDBDatabase::enqueueEvent(PassRefPtr<Event> event)
index 48179b4..4899763 100644 (file)
@@ -72,7 +72,7 @@ public:
     void close();
 
     // IDBDatabaseCallbacks
-    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness);
+    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion);
     virtual void onAbort(int64_t, PassRefPtr<IDBDatabaseError>);
     virtual void onComplete(int64_t);
 
index c21bc30..fc23102 100644 (file)
@@ -500,7 +500,7 @@ void IDBDatabaseBackend::runIntVersionChangeTransaction(PassRefPtr<IDBCallbacks>
     for (auto& callback : m_databaseCallbacksSet) {
         // Front end ensures the event is not fired at connections that have closePending set.
         if (callback != databaseCallbacks)
-            callback->onVersionChange(m_metadata.version, requestedVersion, IndexedDB::VersionNullness::Null);
+            callback->onVersionChange(m_metadata.version, requestedVersion);
     }
     // The spec dictates we wait until all the version change events are
     // delivered and then check m_databaseCallbacks.empty() before proceeding
@@ -533,7 +533,7 @@ void IDBDatabaseBackend::deleteDatabase(PassRefPtr<IDBCallbacks> prpCallbacks)
     if (isDeleteDatabaseBlocked()) {
         for (auto& callback : m_databaseCallbacksSet) {
             // Front end ensures the event is not fired at connections that have closePending set.
-            callback->onVersionChange(m_metadata.version, 0, IndexedDB::VersionNullness::Null);
+            callback->onVersionChange(m_metadata.version, 0);
         }
         // FIXME: Only fire onBlocked if there are open connections after the
         // VersionChangeEvents are received, not just set up to fire.
index 7770abf..70e91c2 100644 (file)
@@ -42,7 +42,7 @@ public:
     virtual ~IDBDatabaseCallbacks() { }
 
     virtual void onForcedClose() = 0;
-    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness) = 0;
+    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion) = 0;
 
     virtual void onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError>) = 0;
     virtual void onComplete(int64_t transactionId) = 0;
index 61f26e9..db43856 100644 (file)
@@ -52,10 +52,10 @@ void IDBDatabaseCallbacksImpl::onForcedClose()
         m_database->forceClose();
 }
 
-void IDBDatabaseCallbacksImpl::onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness)
+void IDBDatabaseCallbacksImpl::onVersionChange(uint64_t oldVersion, uint64_t newVersion)
 {
     if (m_database)
-        m_database->onVersionChange(oldVersion, newVersion, newVersionNullness);
+        m_database->onVersionChange(oldVersion, newVersion);
 }
 
 void IDBDatabaseCallbacksImpl::connect(IDBDatabase* database)
index f7d5a22..56c802b 100644 (file)
@@ -43,7 +43,7 @@ public:
 
     // IDBDatabaseCallbacks
     virtual void onForcedClose() override;
-    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness) override;
+    virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion) override;
 
     virtual void onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError>) override;
     virtual void onComplete(int64_t transactionId) override;
index 5f7041c..637807e 100644 (file)
@@ -69,7 +69,7 @@ void IDBOpenDBRequest::onBlocked(uint64_t oldVersion)
     if (!shouldEnqueueEvent())
         return;
     
-    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, m_versionNullness, eventNames().blockedEvent));
+    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, eventNames().blockedEvent));
 }
 
 void IDBOpenDBRequest::onUpgradeNeeded(uint64_t oldVersion, PassRefPtr<IDBDatabaseBackend> prpDatabaseBackend, const IDBDatabaseMetadata& metadata)
@@ -101,7 +101,7 @@ void IDBOpenDBRequest::onUpgradeNeeded(uint64_t oldVersion, PassRefPtr<IDBDataba
 
     if (m_versionNullness == IndexedDB::VersionNullness::Null)
         m_version = 1;
-    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, m_versionNullness, eventNames().upgradeneededEvent));
+    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, eventNames().upgradeneededEvent));
 }
 
 void IDBOpenDBRequest::onSuccess(PassRefPtr<IDBDatabaseBackend> prpBackend, const IDBDatabaseMetadata& metadata)
index 41c9218..d4f687a 100644 (file)
@@ -238,8 +238,11 @@ void IDBDatabaseBackend::VersionChangeOperation::perform(std::function<void()> c
     LOG(StorageAPI, "VersionChangeOperation");
 
     uint64_t oldVersion = m_transaction->database().metadata().version;
+    if (oldVersion == IDBDatabaseMetadata::NoIntVersion)
+        oldVersion = 0;
+
     RefPtr<IDBDatabaseBackend::VersionChangeOperation> operation(this);
-    ASSERT(static_cast<uint64_t>(m_version) > oldVersion || oldVersion == IDBDatabaseMetadata::NoIntVersion);
+    ASSERT(static_cast<uint64_t>(m_version) > oldVersion);
 
     std::function<void(PassRefPtr<IDBDatabaseError>)> operationCallback = [oldVersion, operation, this, completionCallback](PassRefPtr<IDBDatabaseError> prpError) {
         RefPtr<IDBDatabaseError> error = prpError;
index 94f3c01..d133c6d 100644 (file)
 
 namespace WebCore {
 
-IDBVersionChangeEvent::IDBVersionChangeEvent(unsigned long long oldVersion, unsigned long long newVersion, IndexedDB::VersionNullness newVersionNullness, const AtomicString& eventType)
+IDBVersionChangeEvent::IDBVersionChangeEvent(unsigned long long oldVersion, unsigned long long newVersion, const AtomicString& eventType)
     : Event(eventType, false /*canBubble*/, false /*cancelable*/)
     , m_oldVersion(oldVersion)
     , m_newVersion(newVersion)
-    , m_newVersionNullness(newVersionNullness)
 {
 }
 
index 1b2dd18..dbad5cd 100644 (file)
@@ -38,24 +38,23 @@ namespace WebCore {
 
 class IDBVersionChangeEvent : public Event {
 public:
-    static Ref<IDBVersionChangeEvent> create(unsigned long long oldVersion = 0, unsigned long long newVersion = 0, IndexedDB::VersionNullness newVersionNullness = IndexedDB::VersionNullness::Null, const AtomicString& eventType = AtomicString())
+    static Ref<IDBVersionChangeEvent> create(unsigned long long oldVersion = 0, unsigned long long newVersion = 0, const AtomicString& eventType = AtomicString())
     {
-        return adoptRef(*new IDBVersionChangeEvent(oldVersion, newVersion, newVersionNullness, eventType));
+        return adoptRef(*new IDBVersionChangeEvent(oldVersion, newVersion, eventType));
     }
 
     virtual ~IDBVersionChangeEvent();
 
     virtual unsigned long long oldVersion() { return m_oldVersion; }
-    virtual unsigned long long newVersion(bool& isNull) { isNull = (m_newVersionNullness == IndexedDB::VersionNullness::Null); return m_newVersion; }
+    virtual unsigned long long newVersion() { return m_newVersion; }
 
     virtual EventInterface eventInterface() const;
 
 private:
-    IDBVersionChangeEvent(unsigned long long oldVersion, unsigned long long newVersion, IndexedDB::VersionNullness newVersionNullness, const AtomicString& eventType);
+    IDBVersionChangeEvent(unsigned long long oldVersion, unsigned long long newVersion, const AtomicString& eventType);
 
     unsigned long long m_oldVersion;
     unsigned long long m_newVersion;
-    IndexedDB::VersionNullness m_newVersionNullness;
 };
 
 } // namespace WebCore
index 3349724..54cdc2d 100644 (file)
@@ -28,5 +28,5 @@
     EnabledAtRuntime=IndexedDB,
 ] interface IDBVersionChangeEvent : Event {
     readonly attribute unsigned long long oldVersion;
-    readonly attribute unsigned long long? newVersion;
+    readonly attribute unsigned long long newVersion;
 };