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

Side by Side Diff: src/runtime/runtime-collections.cc

Issue 1157453002: Add basic API support for Map & Set (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/runtime/runtime-utils.h" 8 #include "src/runtime/runtime-utils.h"
9 9
10 10
(...skipping 27 matching lines...) Expand all
38 38
39 RUNTIME_FUNCTION(Runtime_GenericHash) { 39 RUNTIME_FUNCTION(Runtime_GenericHash) {
40 HandleScope scope(isolate); 40 HandleScope scope(isolate);
41 DCHECK(args.length() == 1); 41 DCHECK(args.length() == 1);
42 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 42 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
43 Handle<Smi> hash = Object::GetOrCreateHash(isolate, object); 43 Handle<Smi> hash = Object::GetOrCreateHash(isolate, object);
44 return *hash; 44 return *hash;
45 } 45 }
46 46
47 47
48 void Runtime::JSSetInitialize(Isolate* isolate, Handle<JSSet> set) {
49 Handle<OrderedHashSet> table = isolate->factory()->NewOrderedHashSet();
50 set->set_table(*table);
51 }
52
53
48 RUNTIME_FUNCTION(Runtime_SetInitialize) { 54 RUNTIME_FUNCTION(Runtime_SetInitialize) {
49 HandleScope scope(isolate); 55 HandleScope scope(isolate);
50 DCHECK(args.length() == 1); 56 DCHECK(args.length() == 1);
51 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); 57 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
52 Handle<OrderedHashSet> table = isolate->factory()->NewOrderedHashSet(); 58 Runtime::JSSetInitialize(isolate, holder);
53 holder->set_table(*table);
54 return *holder; 59 return *holder;
55 } 60 }
56 61
57 62
58 RUNTIME_FUNCTION(Runtime_SetGrow) { 63 RUNTIME_FUNCTION(Runtime_SetGrow) {
59 HandleScope scope(isolate); 64 HandleScope scope(isolate);
60 DCHECK(args.length() == 1); 65 DCHECK(args.length() == 1);
61 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); 66 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
62 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table())); 67 Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
63 table = OrderedHashSet::EnsureGrowable(table); 68 table = OrderedHashSet::EnsureGrowable(table);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(args.length() == 1); 141 DCHECK(args.length() == 1);
137 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0); 142 CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0);
138 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); 143 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4);
139 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); 144 details->set(0, isolate->heap()->ToBoolean(holder->HasMore()));
140 details->set(1, holder->index()); 145 details->set(1, holder->index());
141 details->set(2, holder->kind()); 146 details->set(2, holder->kind());
142 return *isolate->factory()->NewJSArrayWithElements(details); 147 return *isolate->factory()->NewJSArrayWithElements(details);
143 } 148 }
144 149
145 150
151 void Runtime::JSMapInitialize(Isolate* isolate, Handle<JSMap> map) {
152 Handle<OrderedHashMap> table = isolate->factory()->NewOrderedHashMap();
153 map->set_table(*table);
154 }
155
156
146 RUNTIME_FUNCTION(Runtime_MapInitialize) { 157 RUNTIME_FUNCTION(Runtime_MapInitialize) {
147 HandleScope scope(isolate); 158 HandleScope scope(isolate);
148 DCHECK(args.length() == 1); 159 DCHECK(args.length() == 1);
149 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); 160 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
150 Handle<OrderedHashMap> table = isolate->factory()->NewOrderedHashMap(); 161 Runtime::JSMapInitialize(isolate, holder);
151 holder->set_table(*table);
152 return *holder; 162 return *holder;
153 } 163 }
154 164
155 165
156 RUNTIME_FUNCTION(Runtime_MapShrink) { 166 RUNTIME_FUNCTION(Runtime_MapShrink) {
157 HandleScope scope(isolate); 167 HandleScope scope(isolate);
158 DCHECK(args.length() == 1); 168 DCHECK(args.length() == 1);
159 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0); 169 CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
160 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table())); 170 Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
161 table = OrderedHashMap::Shrink(table); 171 table = OrderedHashMap::Shrink(table);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 425
416 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) { 426 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) {
417 HandleScope scope(isolate); 427 HandleScope scope(isolate);
418 DCHECK(args.length() == 0); 428 DCHECK(args.length() == 0);
419 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); 429 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
420 Runtime::WeakCollectionInitialize(isolate, weakmap); 430 Runtime::WeakCollectionInitialize(isolate, weakmap);
421 return *weakmap; 431 return *weakmap;
422 } 432 }
423 } // namespace internal 433 } // namespace internal
424 } // namespace v8 434 } // namespace v8
OLDNEW
« src/bootstrapper.cc ('K') | « src/runtime/runtime.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698