Implement the Dictionary#values prototype function

This commit is contained in:
Gunnar Beutner 2017-05-15 15:54:48 +02:00
parent 37f7c7a294
commit 1b77f4b336
2 changed files with 21 additions and 0 deletions

View File

@ -1220,6 +1220,14 @@ Signature:
Returns a list of keys for all items that are currently in the dictionary.
### <a id="dictionary-keys"></a> Dictionary#values
Signature:
function values();
Returns a list of values for all items that are currently in the dictionary.
## <a id="scriptfunction-type"></a> Function type
Inherits methods from the [Object type](18-library-reference.md#object-type).

View File

@ -79,6 +79,18 @@ static Array::Ptr DictionaryKeys(void)
return keys;
}
static Array::Ptr DictionaryValues(void)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
Array::Ptr keys = new Array();
ObjectLock olock(self);
for (const Dictionary::Pair& kv : self) {
keys->Add(kv.second);
}
return keys;
}
Object::Ptr Dictionary::GetPrototype(void)
{
static Dictionary::Ptr prototype;
@ -92,6 +104,7 @@ Object::Ptr Dictionary::GetPrototype(void)
prototype->Set("contains", new Function("Dictionary#contains", WrapFunction(DictionaryContains), { "key" }, true));
prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", WrapFunction(DictionaryShallowClone), {}, true));
prototype->Set("keys", new Function("Dictionary#keys", WrapFunction(DictionaryKeys), {}, true));
prototype->Set("values", new Function("Dictionary#values", WrapFunction(DictionaryValues), {}, true));
}
return prototype;