Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 | 10 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 HandleScope scope(isolate); | 219 HandleScope scope(isolate); |
| 220 DCHECK_EQ(1, args.length()); | 220 DCHECK_EQ(1, args.length()); |
| 221 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); | 221 CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0); |
| 222 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); | 222 Handle<FixedArray> details = isolate->factory()->NewFixedArray(4); |
| 223 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); | 223 details->set(0, isolate->heap()->ToBoolean(holder->HasMore())); |
| 224 details->set(1, holder->index()); | 224 details->set(1, holder->index()); |
| 225 details->set(2, holder->kind()); | 225 details->set(2, holder->kind()); |
| 226 return *isolate->factory()->NewJSArrayWithElements(details); | 226 return *isolate->factory()->NewJSArrayWithElements(details); |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 Handle<JSArray> Runtime::GetWeakMapEntries(Isolate* isolate, |
| 230 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { | 230 Handle<JSWeakCollection> holder, |
| 231 HandleScope scope(isolate); | 231 int max_entries) { |
| 232 DCHECK_EQ(2, args.length()); | |
| 233 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | |
| 234 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]); | |
| 235 CHECK(max_entries >= 0); | |
| 236 | |
| 237 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); | 232 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
| 238 if (max_entries == 0 || max_entries > table->NumberOfElements()) { | 233 if (max_entries == 0 || max_entries > table->NumberOfElements()) { |
| 239 max_entries = table->NumberOfElements(); | 234 max_entries = table->NumberOfElements(); |
| 240 } | 235 } |
| 241 Handle<FixedArray> entries = | 236 Handle<FixedArray> entries = |
| 242 isolate->factory()->NewFixedArray(max_entries * 2); | 237 isolate->factory()->NewFixedArray(max_entries * 2); |
| 243 // Allocation can cause GC can delete weak elements. Reload. | 238 // Allocation can cause GC can delete weak elements. Reload. |
| 244 if (max_entries > table->NumberOfElements()) { | 239 if (max_entries > table->NumberOfElements()) { |
| 245 max_entries = table->NumberOfElements(); | 240 max_entries = table->NumberOfElements(); |
| 246 } | 241 } |
| 247 | 242 |
| 248 { | 243 { |
| 249 DisallowHeapAllocation no_gc; | 244 DisallowHeapAllocation no_gc; |
| 250 int count = 0; | 245 int count = 0; |
| 251 for (int i = 0; count / 2 < max_entries && i < table->Capacity(); i++) { | 246 for (int i = 0; count / 2 < max_entries && i < table->Capacity(); i++) { |
| 252 Handle<Object> key(table->KeyAt(i), isolate); | 247 Handle<Object> key(table->KeyAt(i), isolate); |
| 253 if (table->IsKey(isolate, *key)) { | 248 if (table->IsKey(isolate, *key)) { |
| 254 entries->set(count++, *key); | 249 entries->set(count++, *key); |
| 255 Object* value = table->Lookup(key); | 250 Object* value = table->Lookup(key); |
| 256 entries->set(count++, value); | 251 entries->set(count++, value); |
| 257 } | 252 } |
| 258 } | 253 } |
| 259 DCHECK_EQ(max_entries * 2, count); | 254 DCHECK_EQ(max_entries * 2, count); |
| 260 } | 255 } |
| 261 return *isolate->factory()->NewJSArrayWithElements(entries); | 256 return isolate->factory()->NewJSArrayWithElements(entries); |
| 257 } | |
| 258 | |
| 259 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) { | |
|
Yang
2017/02/06 10:41:30
Can we move that to JSWeakMap?
jgruber
2017/02/06 12:40:39
+1
kozy
2017/02/06 18:39:26
Done.
| |
| 260 HandleScope scope(isolate); | |
| 261 DCHECK_EQ(2, args.length()); | |
| 262 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | |
| 263 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]); | |
| 264 CHECK(max_entries >= 0); | |
| 265 return *Runtime::GetWeakMapEntries(isolate, holder, max_entries); | |
| 262 } | 266 } |
| 263 | 267 |
| 264 | 268 |
| 265 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { | 269 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { |
| 266 SealHandleScope shs(isolate); | 270 SealHandleScope shs(isolate); |
| 267 DCHECK_EQ(2, args.length()); | 271 DCHECK_EQ(2, args.length()); |
| 268 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); | 272 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); |
| 269 CONVERT_ARG_CHECKED(JSArray, value_array, 1); | 273 CONVERT_ARG_CHECKED(JSArray, value_array, 1); |
| 270 return holder->Next(value_array); | 274 return holder->Next(value_array); |
| 271 } | 275 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 CHECK(key->IsJSReceiver() || key->IsSymbol()); | 338 CHECK(key->IsJSReceiver() || key->IsSymbol()); |
| 335 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 339 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 336 CONVERT_SMI_ARG_CHECKED(hash, 3) | 340 CONVERT_SMI_ARG_CHECKED(hash, 3) |
| 337 Handle<ObjectHashTable> table( | 341 Handle<ObjectHashTable> table( |
| 338 ObjectHashTable::cast(weak_collection->table())); | 342 ObjectHashTable::cast(weak_collection->table())); |
| 339 CHECK(table->IsKey(isolate, *key)); | 343 CHECK(table->IsKey(isolate, *key)); |
| 340 JSWeakCollection::Set(weak_collection, key, value, hash); | 344 JSWeakCollection::Set(weak_collection, key, value, hash); |
| 341 return *weak_collection; | 345 return *weak_collection; |
| 342 } | 346 } |
| 343 | 347 |
| 344 | 348 Handle<JSArray> Runtime::GetWeakSetEntries(Isolate* isolate, |
|
Yang
2017/02/06 10:41:30
Can we move that to JSWeakSet?
kozy
2017/02/06 18:39:26
Done.
| |
| 345 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { | 349 Handle<JSWeakCollection> holder, |
| 346 HandleScope scope(isolate); | 350 int max_values) { |
| 347 DCHECK_EQ(2, args.length()); | |
| 348 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | |
| 349 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); | |
| 350 CHECK(max_values >= 0); | |
| 351 | |
| 352 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); | 351 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); |
| 353 if (max_values == 0 || max_values > table->NumberOfElements()) { | 352 if (max_values == 0 || max_values > table->NumberOfElements()) { |
| 354 max_values = table->NumberOfElements(); | 353 max_values = table->NumberOfElements(); |
| 355 } | 354 } |
| 356 Handle<FixedArray> values = isolate->factory()->NewFixedArray(max_values); | 355 Handle<FixedArray> values = isolate->factory()->NewFixedArray(max_values); |
| 357 // Recompute max_values because GC could have removed elements from the table. | 356 // Recompute max_values because GC could have removed elements from the table. |
| 358 if (max_values > table->NumberOfElements()) { | 357 if (max_values > table->NumberOfElements()) { |
| 359 max_values = table->NumberOfElements(); | 358 max_values = table->NumberOfElements(); |
| 360 } | 359 } |
| 361 { | 360 { |
| 362 DisallowHeapAllocation no_gc; | 361 DisallowHeapAllocation no_gc; |
| 363 int count = 0; | 362 int count = 0; |
| 364 for (int i = 0; count < max_values && i < table->Capacity(); i++) { | 363 for (int i = 0; count < max_values && i < table->Capacity(); i++) { |
| 365 Object* key = table->KeyAt(i); | 364 Object* key = table->KeyAt(i); |
| 366 if (table->IsKey(isolate, key)) values->set(count++, key); | 365 if (table->IsKey(isolate, key)) values->set(count++, key); |
| 367 } | 366 } |
| 368 DCHECK_EQ(max_values, count); | 367 DCHECK_EQ(max_values, count); |
| 369 } | 368 } |
| 370 return *isolate->factory()->NewJSArrayWithElements(values); | 369 return isolate->factory()->NewJSArrayWithElements(values); |
| 370 } | |
| 371 | |
| 372 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { | |
| 373 HandleScope scope(isolate); | |
| 374 DCHECK_EQ(2, args.length()); | |
| 375 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); | |
| 376 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); | |
| 377 CHECK(max_values >= 0); | |
| 378 return *Runtime::GetWeakSetEntries(isolate, holder, max_values); | |
| 371 } | 379 } |
| 372 } // namespace internal | 380 } // namespace internal |
| 373 } // namespace v8 | 381 } // namespace v8 |
| OLD | NEW |