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

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

Issue 1314053003: Move runtime helper for JSWeakCollection onto objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-runtime-helpers-1
Patch Set: Created 5 years, 3 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
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 RUNTIME_FUNCTION(Runtime_MapIteratorNext) { 265 RUNTIME_FUNCTION(Runtime_MapIteratorNext) {
266 SealHandleScope shs(isolate); 266 SealHandleScope shs(isolate);
267 DCHECK(args.length() == 2); 267 DCHECK(args.length() == 2);
268 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0); 268 CONVERT_ARG_CHECKED(JSMapIterator, holder, 0);
269 CONVERT_ARG_CHECKED(JSArray, value_array, 1); 269 CONVERT_ARG_CHECKED(JSArray, value_array, 1);
270 return holder->Next(value_array); 270 return holder->Next(value_array);
271 } 271 }
272 272
273 273
274 void Runtime::WeakCollectionInitialize(
275 Isolate* isolate, Handle<JSWeakCollection> weak_collection) {
276 DCHECK_EQ(0, weak_collection->map()->GetInObjectProperties());
277 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 0);
278 weak_collection->set_table(*table);
279 }
280
281
282 RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) { 274 RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) {
283 HandleScope scope(isolate); 275 HandleScope scope(isolate);
284 DCHECK(args.length() == 1); 276 DCHECK(args.length() == 1);
285 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 277 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
286 Runtime::WeakCollectionInitialize(isolate, weak_collection); 278 JSWeakCollection::Initialize(weak_collection, isolate);
287 return *weak_collection; 279 return *weak_collection;
288 } 280 }
289 281
290 282
291 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { 283 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) {
292 HandleScope scope(isolate); 284 HandleScope scope(isolate);
293 DCHECK(args.length() == 3); 285 DCHECK(args.length() == 3);
294 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 286 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
295 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 287 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
296 CONVERT_SMI_ARG_CHECKED(hash, 2) 288 CONVERT_SMI_ARG_CHECKED(hash, 2)
(...skipping 14 matching lines...) Expand all
311 CONVERT_SMI_ARG_CHECKED(hash, 2) 303 CONVERT_SMI_ARG_CHECKED(hash, 2)
312 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 304 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
313 Handle<ObjectHashTable> table( 305 Handle<ObjectHashTable> table(
314 ObjectHashTable::cast(weak_collection->table())); 306 ObjectHashTable::cast(weak_collection->table()));
315 RUNTIME_ASSERT(table->IsKey(*key)); 307 RUNTIME_ASSERT(table->IsKey(*key));
316 Handle<Object> lookup(table->Lookup(key, hash), isolate); 308 Handle<Object> lookup(table->Lookup(key, hash), isolate);
317 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 309 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
318 } 310 }
319 311
320 312
321 bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
322 Handle<Object> key) {
323 int32_t hash =
324 Object::GetOrCreateHash(weak_collection->GetIsolate(), key)->value();
325 return WeakCollectionDelete(weak_collection, key, hash);
326 }
327
328
329 bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
330 Handle<Object> key, int32_t hash) {
331 DCHECK(key->IsJSReceiver() || key->IsSymbol());
332 Handle<ObjectHashTable> table(
333 ObjectHashTable::cast(weak_collection->table()));
334 DCHECK(table->IsKey(*key));
335 bool was_present = false;
336 Handle<ObjectHashTable> new_table =
337 ObjectHashTable::Remove(table, key, &was_present, hash);
338 weak_collection->set_table(*new_table);
339 if (*table != *new_table) {
340 // Zap the old table since we didn't record slots for its elements.
341 table->FillWithHoles(0, table->length());
342 }
343 return was_present;
344 }
345
346
347 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { 313 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
348 HandleScope scope(isolate); 314 HandleScope scope(isolate);
349 DCHECK(args.length() == 3); 315 DCHECK(args.length() == 3);
350 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 316 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
351 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 317 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
352 CONVERT_SMI_ARG_CHECKED(hash, 2) 318 CONVERT_SMI_ARG_CHECKED(hash, 2)
353 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 319 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
354 Handle<ObjectHashTable> table( 320 Handle<ObjectHashTable> table(
355 ObjectHashTable::cast(weak_collection->table())); 321 ObjectHashTable::cast(weak_collection->table()));
356 RUNTIME_ASSERT(table->IsKey(*key)); 322 RUNTIME_ASSERT(table->IsKey(*key));
357 bool was_present = Runtime::WeakCollectionDelete(weak_collection, key, hash); 323 bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
358 return isolate->heap()->ToBoolean(was_present); 324 return isolate->heap()->ToBoolean(was_present);
359 } 325 }
360 326
361 327
362 void Runtime::WeakCollectionSet(Handle<JSWeakCollection> weak_collection,
363 Handle<Object> key, Handle<Object> value,
364 int32_t hash) {
365 DCHECK(key->IsJSReceiver() || key->IsSymbol());
366 Handle<ObjectHashTable> table(
367 ObjectHashTable::cast(weak_collection->table()));
368 DCHECK(table->IsKey(*key));
369 Handle<ObjectHashTable> new_table =
370 ObjectHashTable::Put(table, key, value, hash);
371 weak_collection->set_table(*new_table);
372 if (*table != *new_table) {
373 // Zap the old table since we didn't record slots for its elements.
374 table->FillWithHoles(0, table->length());
375 }
376 }
377
378
379 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { 328 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
380 HandleScope scope(isolate); 329 HandleScope scope(isolate);
381 DCHECK(args.length() == 4); 330 DCHECK(args.length() == 4);
382 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 331 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
383 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 332 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
384 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 333 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
385 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 334 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
386 CONVERT_SMI_ARG_CHECKED(hash, 3) 335 CONVERT_SMI_ARG_CHECKED(hash, 3)
387 Handle<ObjectHashTable> table( 336 Handle<ObjectHashTable> table(
388 ObjectHashTable::cast(weak_collection->table())); 337 ObjectHashTable::cast(weak_collection->table()));
389 RUNTIME_ASSERT(table->IsKey(*key)); 338 RUNTIME_ASSERT(table->IsKey(*key));
390 Runtime::WeakCollectionSet(weak_collection, key, value, hash); 339 JSWeakCollection::Set(weak_collection, key, value, hash);
391 return *weak_collection; 340 return *weak_collection;
392 } 341 }
393 342
394 343
395 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { 344 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) {
396 HandleScope scope(isolate); 345 HandleScope scope(isolate);
397 DCHECK(args.length() == 2); 346 DCHECK(args.length() == 2);
398 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); 347 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
399 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); 348 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]);
400 RUNTIME_ASSERT(max_values >= 0); 349 RUNTIME_ASSERT(max_values >= 0);
(...skipping 17 matching lines...) Expand all
418 DCHECK_EQ(max_values, count); 367 DCHECK_EQ(max_values, count);
419 } 368 }
420 return *isolate->factory()->NewJSArrayWithElements(values); 369 return *isolate->factory()->NewJSArrayWithElements(values);
421 } 370 }
422 371
423 372
424 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) { 373 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) {
425 HandleScope scope(isolate); 374 HandleScope scope(isolate);
426 DCHECK(args.length() == 0); 375 DCHECK(args.length() == 0);
427 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); 376 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
428 Runtime::WeakCollectionInitialize(isolate, weakmap); 377 JSWeakCollection::Initialize(weakmap, isolate);
429 return *weakmap; 378 return *weakmap;
430 } 379 }
431 } // namespace internal 380 } // namespace internal
432 } // namespace v8 381 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698