Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/runtime.cc

Issue 398513005: Expose the content of Maps and WeakMaps through MapMirror. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 || kind == JSMapIterator::kKindValues 1699 || kind == JSMapIterator::kKindValues
1700 || kind == JSMapIterator::kKindEntries); 1700 || kind == JSMapIterator::kKindEntries);
1701 Handle<OrderedHashMap> table(OrderedHashMap::cast(map->table())); 1701 Handle<OrderedHashMap> table(OrderedHashMap::cast(map->table()));
1702 holder->set_table(*table); 1702 holder->set_table(*table);
1703 holder->set_index(Smi::FromInt(0)); 1703 holder->set_index(Smi::FromInt(0));
1704 holder->set_kind(Smi::FromInt(kind)); 1704 holder->set_kind(Smi::FromInt(kind));
1705 return isolate->heap()->undefined_value(); 1705 return isolate->heap()->undefined_value();
1706 } 1706 }
1707 1707
1708 1708
1709 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
1710 HandleScope scope(isolate);
1711 ASSERT(args.length() == 1);
1712 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
1713 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
1714 Handle<FixedArray> entries = isolate->factory()->NewFixedArray(
1715 table->NumberOfElements() * 2);
1716 int number_of_non_hole_elements = 0;
1717 { DisallowHeapAllocation no_gc;
1718 for (int i = 0; i < table->UsedCapacity(); i++) {
1719 Handle<Object> key(table->KeyAt(i), isolate);
1720 if (!key->IsTheHole()) {
1721 entries->set(number_of_non_hole_elements * 2, *key);
1722 entries->set(number_of_non_hole_elements * 2 + 1,
1723 table->ValueAt(i));
1724 number_of_non_hole_elements++;
1725 }
1726 }
1727 }
1728 return *isolate->factory()->NewJSArrayWithElements(entries);
1729 }
1730
1731
1732 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) {
1733 HandleScope scope(isolate);
1734 ASSERT(args.length() == 1);
1735 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
1736 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table()));
1737 Handle<FixedArray> entries = isolate->factory()->NewFixedArray(
1738 table->NumberOfElements() * 2);
1739 int number_of_non_hole_elements = 0;
1740 { DisallowHeapAllocation no_gc;
1741 for (int i = 0; i < table->Capacity(); i++) {
1742 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.
1743 if (table->IsKey(*key)) {
1744 entries->set(number_of_non_hole_elements * 2, *key);
1745 entries->set(number_of_non_hole_elements * 2 + 1,
1746 table->Lookup(key));
1747 number_of_non_hole_elements++;
1748 }
1749 }
1750 }
1751 return *isolate->factory()->NewJSArrayWithElements(entries);
1752 }
1753
1754
1709 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { 1755 RUNTIME_FUNCTION(Runtime_MapIteratorNext) {
1710 SealHandleScope shs(isolate); 1756 SealHandleScope shs(isolate);
1711 ASSERT(args.length() == 2); 1757 ASSERT(args.length() == 2);
1712 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); 1758 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0);
1713 CONVERT_ARG_CHECKED(JSArray, value_array, 1); 1759 CONVERT_ARG_CHECKED(JSArray, value_array, 1);
1714 return holder->Next(value_array); 1760 return holder->Next(value_array);
1715 } 1761 }
1716 1762
1717 1763
1718 static Handle<JSWeakCollection> WeakCollectionInitialize( 1764 static Handle<JSWeakCollection> WeakCollectionInitialize(
(...skipping 13237 matching lines...) Expand 10 before | Expand all | Expand 10 after
14956 } 15002 }
14957 return NULL; 15003 return NULL;
14958 } 15004 }
14959 15005
14960 15006
14961 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15007 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
14962 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15008 return &(kIntrinsicFunctions[static_cast<int>(id)]);
14963 } 15009 }
14964 15010
14965 } } // namespace v8::internal 15011 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698