Merge pull request #6508 from gunnarbeutner/feature/dictionary-clear

Implement the Dictionary#clear script function
This commit is contained in:
Jean Flach 2018-08-02 10:30:08 +02:00 committed by GitHub
commit 065bc23d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -1428,6 +1428,14 @@ Signature:
Removes the item with the specified `key`. Trying to remove an item which does not exist
is a no-op.
### Dictionary#clear <a id="dictionary-clear"></a>
Signature:
function clear();
Removes all items from the dictionary.
### Dictionary#set <a id="dictionary-set"></a>
Signature:

View File

@ -57,6 +57,14 @@ static void DictionaryRemove(const String& key)
self->Remove(key);
}
static void DictionaryClear()
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
self->Clear();
}
static bool DictionaryContains(const String& key)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@ -115,6 +123,7 @@ Object::Ptr Dictionary::GetPrototype()
{ "set", new Function("Dictionary#set", DictionarySet, { "key", "value" }) },
{ "get", new Function("Dictionary#get", DictionaryGet, { "key" }) },
{ "remove", new Function("Dictionary#remove", DictionaryRemove, { "key" }) },
{ "clear", new Function("Dictionary#clear", DictionaryClear, {}) },
{ "contains", new Function("Dictionary#contains", DictionaryContains, { "key" }, true) },
{ "shallow_clone", new Function("Dictionary#shallow_clone", DictionaryShallowClone, {}, true) },
{ "keys", new Function("Dictionary#keys", DictionaryKeys, {}, true) },