diff --git a/Libraries/LibWeb/IndexedDB/IDBFactory.cpp b/Libraries/LibWeb/IndexedDB/IDBFactory.cpp index 5823bb04e8..2f9b546af7 100644 --- a/Libraries/LibWeb/IndexedDB/IDBFactory.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBFactory.cpp @@ -203,9 +203,10 @@ GC::Ref IDBFactory::databases() auto databases = Database::for_key(storage_key); // 2. Let result be a new list. - auto result = MUST(JS::Array::create(realm, databases.size())); + auto result = MUST(JS::Array::create(realm, 0)); // 3. For each db of databases: + u32 result_index = 0; for (u32 i = 0; i < databases.size(); ++i) { auto& db = databases[i]; @@ -223,7 +224,7 @@ GC::Ref IDBFactory::databases() MUST(info->create_data_property("version"_utf16_fly_string, JS::Value(db->version()))); // 4. Append info to result. - MUST(result->create_data_property_or_throw(i, info)); + MUST(result->create_data_property_or_throw(result_index++, info)); } // 4. Resolve p with result. diff --git a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.txt b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.txt new file mode 100644 index 0000000000..437c614765 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass An abort() in the initial onupgradeneeded sets version back to 0 \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.html b/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.html new file mode 100644 index 0000000000..cb0ded0c82 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.html @@ -0,0 +1,15 @@ + + +IndexedDB + + + + +
+ diff --git a/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.js b/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.js new file mode 100644 index 0000000000..52b33807d0 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/IndexedDB/abort-in-initial-upgradeneeded.any.js @@ -0,0 +1,37 @@ +// META: title=IndexedDB +// META: global=window,worker +// META: script=resources/support.js + +'use strict'; + +async_test(t => { + let db; + let open_rq = createdb(t, undefined, 2); + + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + assert_equals(db.version, 2); + let transaction = e.target.transaction; + transaction.oncomplete = fail(t, 'unexpected transaction.complete'); + transaction.onabort = function(e) { + assert_equals(e.target.db.version, 0); + }; + db.onabort = function() {}; + + transaction.abort(); + }; + + open_rq.onerror = function(e) { + assert_equals(open_rq, e.target); + assert_equals(e.target.result, undefined); + assert_equals(e.target.error.name, 'AbortError'); + assert_equals(db.version, 0); + assert_equals(open_rq.transaction, null); + + indexedDB.databases().then(dbs => { + // The database should be deleted. + assert_equals(dbs.length, 0); + t.done(); + }); + }; +}, 'An abort() in the initial onupgradeneeded sets version back to 0');