Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add ability to get all the keys from a WKDictionaryRef
https://bugs.webkit.org/show_bug.cgi?id=44221

Reviewed by Adam Roben.

* Shared/ImmutableDictionary.cpp:
(WebKit::ImmutableDictionary::keys):
* Shared/ImmutableDictionary.h:
Add keys function.

* UIProcess/API/C/WKDictionary.cpp:
(WKDictionaryCopyKeys):
* UIProcess/API/C/WKDictionary.h:
Wrap keys function.



Canonical link: https://commits.webkit.org/56455@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@65675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Aug 19, 2010
1 parent 2da6e50 commit 00392a5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions WebKit2/ChangeLog
@@ -1,3 +1,20 @@
2010-08-18 Sam Weinig <sam@webkit.org>

Reviewed by Adam Roben.

Add ability to get all the keys from a WKDictionaryRef
https://bugs.webkit.org/show_bug.cgi?id=44221

* Shared/ImmutableDictionary.cpp:
(WebKit::ImmutableDictionary::keys):
* Shared/ImmutableDictionary.h:
Add keys function.

* UIProcess/API/C/WKDictionary.cpp:
(WKDictionaryCopyKeys):
* UIProcess/API/C/WKDictionary.h:
Wrap keys function.

2010-08-18 Sam Weinig <sam@webkit.org>

Reviewed by Jon Honeycutt.
Expand Down
19 changes: 19 additions & 0 deletions WebKit2/Shared/ImmutableDictionary.cpp
Expand Up @@ -25,6 +25,9 @@

#include "ImmutableDictionary.h"

#include "ImmutableArray.h"
#include "WebString.h"

namespace WebKit {

ImmutableDictionary::ImmutableDictionary()
Expand All @@ -40,4 +43,20 @@ ImmutableDictionary::~ImmutableDictionary()
{
}

PassRefPtr<ImmutableArray> ImmutableDictionary::keys() const
{
if (m_map.isEmpty())
return ImmutableArray::create();

size_t size = m_map.size();
APIObject** array = new APIObject*[size];

MapType::const_iterator::Keys it = m_map.begin().keys();
MapType::const_iterator::Keys end = m_map.end().keys();
for (unsigned i = 0; it != end; ++it, ++i)
array[i] = WebString::create(*it).releaseRef();

return ImmutableArray::adopt(array, size);
}

} // namespace WebKit
4 changes: 4 additions & 0 deletions WebKit2/Shared/ImmutableDictionary.h
Expand Up @@ -34,6 +34,8 @@

namespace WebKit {

class ImmutableArray;

// ImmutableDictionary - An immutable dictionary type suitable for vending to an API.

class ImmutableDictionary : public APIObject {
Expand Down Expand Up @@ -70,6 +72,8 @@ class ImmutableDictionary : public APIObject {
return m_map.get(key).get();
}

PassRefPtr<ImmutableArray> keys() const;

size_t size() { return m_map.size(); }

private:
Expand Down
7 changes: 7 additions & 0 deletions WebKit2/UIProcess/API/C/WKDictionary.cpp
Expand Up @@ -25,6 +25,7 @@

#include "WKDictionary.h"

#include "ImmutableArray.h"
#include "ImmutableDictionary.h"
#include "WKAPICast.h"

Expand All @@ -45,6 +46,12 @@ size_t WKDictionaryGetSize(WKDictionaryRef dictionaryRef)
return toWK(dictionaryRef)->size();
}

WKArrayRef WKDictionaryCopyKeys(WKDictionaryRef dictionaryRef)
{
RefPtr<ImmutableArray> keys = toWK(dictionaryRef)->keys();
return toRef(keys.release().releaseRef());
}

WKDictionaryRef WKDictionaryRetain(WKDictionaryRef dictionaryRef)
{
toWK(dictionaryRef)->ref();
Expand Down
2 changes: 2 additions & 0 deletions WebKit2/UIProcess/API/C/WKDictionary.h
Expand Up @@ -39,6 +39,8 @@ WK_EXPORT WKTypeID WKDictionaryGetTypeID();
WK_EXPORT WKTypeRef WKDictionaryGetItemForKey(WKDictionaryRef dictionary, WKStringRef key);
WK_EXPORT size_t WKDictionaryGetSize(WKDictionaryRef dictionary);

WK_EXPORT WKArrayRef WKDictionaryCopyKeys(WKDictionaryRef dictionary);

WK_EXPORT WKDictionaryRef WKDictionaryRetain(WKDictionaryRef dictionary);
WK_EXPORT void WKDictionaryRelease(WKDictionaryRef dictionary);

Expand Down

0 comments on commit 00392a5

Please sign in to comment.