Skip to content

Commit 1ad9b3e

Browse files
stelar7gmta
authored andcommitted
LibWeb/IDB: Implement create_a_sorted_name_list
1 parent 3879391 commit 1ad9b3e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7+
#include <AK/QuickSort.h>
78
#include <LibJS/Runtime/AbstractOperations.h>
89
#include <LibJS/Runtime/Array.h>
910
#include <LibJS/Runtime/ArrayBuffer.h>
@@ -20,6 +21,7 @@
2021
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
2122
#include <LibWeb/IndexedDB/Internal/ConnectionQueueHandler.h>
2223
#include <LibWeb/IndexedDB/Internal/Database.h>
24+
#include <LibWeb/Infra/Strings.h>
2325
#include <LibWeb/StorageAPI/StorageKey.h>
2426
#include <LibWeb/WebIDL/AbstractOperations.h>
2527
#include <LibWeb/WebIDL/Buffers.h>
@@ -621,4 +623,16 @@ bool is_valid_key_path(KeyPath const& path)
621623
});
622624
}
623625

626+
// https://w3c.github.io/IndexedDB/#create-a-sorted-name-list
627+
GC::Ref<HTML::DOMStringList> create_a_sorted_name_list(JS::Realm& realm, Vector<String> names)
628+
{
629+
// 1. Let sorted be names sorted in ascending order with the code unit less than algorithm.
630+
quick_sort(names, [](auto const& a, auto const& b) {
631+
return Infra::code_unit_less_than(a, b);
632+
});
633+
634+
// 2. Return a new DOMStringList associated with sorted.
635+
return HTML::DOMStringList::create(realm, names);
636+
}
637+
624638
}

Libraries/LibWeb/IndexedDB/Internal/Algorithms.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <AK/Variant.h>
1010
#include <LibJS/Runtime/Realm.h>
11+
#include <LibWeb/HTML/DOMStringList.h>
1112
#include <LibWeb/IndexedDB/IDBRequest.h>
1213
#include <LibWeb/IndexedDB/Internal/Key.h>
1314
#include <LibWeb/StorageAPI/StorageKey.h>
@@ -25,5 +26,6 @@ WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm&, StorageAPI::StorageKey, S
2526
void abort_a_transaction(IDBTransaction&, GC::Ptr<WebIDL::DOMException>);
2627
JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref<Key>);
2728
bool is_valid_key_path(KeyPath const&);
29+
GC::Ref<HTML::DOMStringList> create_a_sorted_name_list(JS::Realm&, Vector<String>);
2830

2931
}

0 commit comments

Comments
 (0)