Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index d980d327aa89640d2b44cbef8e08b58be0eb3257..42f319cd422b4e3d8bf544db3f560c448ca3d146 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -1706,6 +1706,52 @@ RUNTIME_FUNCTION(Runtime_MapIteratorInitialize) { |
| } |
| +RUNTIME_FUNCTION(Runtime_GetMapEntries) { |
|
rossberg
2014/07/16 09:51:07
Is this necessary? You can easily get the array of
Alexandra Mikhaylova
2014/07/16 10:21:13
Thanks, I'll use the map iterator to get entries t
|
| + HandleScope scope(isolate); |
| + ASSERT(args.length() == 1); |
| + CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); |
| + Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); |
| + Handle<FixedArray> entries = isolate->factory()->NewFixedArray( |
| + table->NumberOfElements() * 2); |
| + int number_of_non_hole_elements = 0; |
| + { DisallowHeapAllocation no_gc; |
| + for (int i = 0; i < table->UsedCapacity(); i++) { |
| + Handle<Object> key(table->KeyAt(i), isolate); |
| + if (!key->IsTheHole()) { |
| + entries->set(number_of_non_hole_elements * 2, *key); |
| + entries->set(number_of_non_hole_elements * 2 + 1, |
| + table->ValueAt(i)); |
| + number_of_non_hole_elements++; |
| + } |
| + } |
| + } |
| + return *isolate->factory()->NewJSArrayWithElements(entries); |
| +} |
| + |
| + |
| +RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { |
| + HandleScope scope(isolate); |
| + ASSERT(args.length() == 1); |
| + CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); |
| + Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
| + Handle<FixedArray> entries = isolate->factory()->NewFixedArray( |
| + table->NumberOfElements() * 2); |
| + int number_of_non_hole_elements = 0; |
| + { DisallowHeapAllocation no_gc; |
| + for (int i = 0; i < table->Capacity(); i++) { |
| + Handle<Object> key(table->KeyAt(i), isolate); |
|
Yang
2014/07/16 12:10:58
Indentation size is weird. We use 4 spaces for lin
Alexandra Mikhaylova
2014/07/16 17:00:37
Done.
|
| + if (table->IsKey(*key)) { |
| + entries->set(number_of_non_hole_elements * 2, *key); |
| + entries->set(number_of_non_hole_elements * 2 + 1, |
| + table->Lookup(key)); |
| + number_of_non_hole_elements++; |
| + } |
| + } |
| + } |
| + return *isolate->factory()->NewJSArrayWithElements(entries); |
| +} |
| + |
| + |
| RUNTIME_FUNCTION(Runtime_MapIteratorNext) { |
| SealHandleScope shs(isolate); |
| ASSERT(args.length() == 2); |