Have window.indexedDB.open return an IDBOpenDBRequest.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 04:27:46 +0000 (04:27 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 04:27:46 +0000 (04:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149234

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/opendatabase-request.html

* Modules/indexeddb/client/IDBFactoryImpl.cpp:
(WebCore::IDBClient::IDBFactory::open):
(WebCore::IDBClient::IDBFactory::openInternal):
* Modules/indexeddb/client/IDBFactoryImpl.h:

LayoutTests:

* storage/indexeddb/modern/opendatabase-request-expected.txt: Added.
* storage/indexeddb/modern/opendatabase-request.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/opendatabase-request-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/opendatabase-request.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBFactoryImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBFactoryImpl.h

index 1567d55..3e799c3 100644 (file)
@@ -1,3 +1,13 @@
+2015-09-16  Brady Eidson  <beidson@apple.com>
+
+        Have window.indexedDB.open return an IDBOpenDBRequest.
+        https://bugs.webkit.org/show_bug.cgi?id=149234
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/opendatabase-request-expected.txt: Added.
+        * storage/indexeddb/modern/opendatabase-request.html: Added.
+
 2015-09-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Create a font which can be used for testing font features
diff --git a/LayoutTests/storage/indexeddb/modern/opendatabase-request-expected.txt b/LayoutTests/storage/indexeddb/modern/opendatabase-request-expected.txt
new file mode 100644 (file)
index 0000000..3fad291
--- /dev/null
@@ -0,0 +1,6 @@
+ALERT: [object IDBOpenDBRequest]
+ALERT: [object IDBOpenDBRequest]
+ALERT: TypeError: Not enough arguments
+ALERT: TypeError: Type error
+ALERT: Done
+This test calls open on window.indexedDB in various ways, verifying that IDBOpenDBRequest objects are returned when expected and exceptions are thrown when expected.
diff --git a/LayoutTests/storage/indexeddb/modern/opendatabase-request.html b/LayoutTests/storage/indexeddb/modern/opendatabase-request.html
new file mode 100644 (file)
index 0000000..0f7e7d5
--- /dev/null
@@ -0,0 +1,35 @@
+This test calls open on window.indexedDB in various ways, verifying that IDBOpenDBRequest objects are returned when expected and exceptions are thrown when expected.
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var request = window.indexedDB.open("TestDatabase");
+alert(request);
+
+request = window.indexedDB.open("");
+alert(request);
+
+try {
+       var request = window.indexedDB.open();
+} catch (e) {
+       alert(e);
+}
+
+try {
+       var request = window.indexedDB.open("name", 0);
+} catch (e) {
+       alert(e);
+}
+
+done();
+</script>
index 1b825c8..b952ced 100644 (file)
@@ -1,3 +1,17 @@
+2015-09-16  Brady Eidson  <beidson@apple.com>
+
+        Have window.indexedDB.open return an IDBOpenDBRequest.
+        https://bugs.webkit.org/show_bug.cgi?id=149234
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/opendatabase-request.html
+
+        * Modules/indexeddb/client/IDBFactoryImpl.cpp:
+        (WebCore::IDBClient::IDBFactory::open):
+        (WebCore::IDBClient::IDBFactory::openInternal):
+        * Modules/indexeddb/client/IDBFactoryImpl.h:
+
 2015-09-16  Antti Koivisto  <antti@apple.com>
 
         Turn ChildNodeInsertion/RemovalNotifier classes into functions
index 144f1d6..70fead0 100644 (file)
@@ -73,14 +73,47 @@ PassRefPtr<WebCore::IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionCont
     return nullptr;
 }
 
-PassRefPtr<WebCore::IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext*, const String&, ExceptionCode&)
+PassRefPtr<WebCore::IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
 {
-    return nullptr;
+    LOG(IndexedDB, "IDBFactory::open");
+    
+    return openInternal(context, name, 0, ec).release();
 }
 
-PassRefPtr<WebCore::IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext*, const String&, unsigned long long, ExceptionCode&)
+PassRefPtr<WebCore::IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, unsigned long long version, ExceptionCode& ec)
 {
-    return nullptr;
+    LOG(IndexedDB, "IDBFactory::open");
+    
+    if (!version) {
+        ec = TypeError;
+        return nullptr;
+    }
+
+    return openInternal(context, name, 0, ec).release();
+}
+
+RefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* context, const String& name, unsigned long long, ExceptionCode& ec)
+{
+    if (name.isNull()) {
+        ec = TypeError;
+        return nullptr;
+    }
+
+    if (shouldThrowSecurityException(context)) {
+        ec = SECURITY_ERR;
+        return nullptr;
+    }
+
+    ASSERT(context->securityOrigin());
+    ASSERT(context->topOrigin());
+    IDBDatabaseIdentifier databaseIdentifier(name, *context->securityOrigin(), *context->topOrigin());
+    if (!databaseIdentifier.isValid()) {
+        ec = TypeError;
+        return nullptr;
+    }
+
+    auto request = IDBOpenDBRequest::create(context);
+    return adoptRef(&request.leakRef());
 }
 
 PassRefPtr<WebCore::IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
index 9c709b4..8c215dd 100644 (file)
@@ -33,6 +33,8 @@
 namespace WebCore {
 namespace IDBClient {
 
+class IDBOpenDBRequest;
+
 class IDBFactory : public WebCore::IDBFactory {
 public:
     static Ref<IDBFactory> create();
@@ -47,6 +49,8 @@ public:
 
 private:
     IDBFactory();
+    
+    RefPtr<IDBOpenDBRequest> openInternal(ScriptExecutionContext*, const String& name, unsigned long long version, ExceptionCode&);
 };
 
 } // namespace IDBClient