• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/execution/arguments-inl.h"
6 #include "src/objects/js-weak-refs-inl.h"
7 #include "src/runtime/runtime-utils.h"
8 
9 namespace v8 {
10 namespace internal {
11 
RUNTIME_FUNCTION(Runtime_ShrinkFinalizationRegistryUnregisterTokenMap)12 RUNTIME_FUNCTION(Runtime_ShrinkFinalizationRegistryUnregisterTokenMap) {
13   HandleScope scope(isolate);
14   DCHECK_EQ(1, args.length());
15   Handle<JSFinalizationRegistry> finalization_registry =
16       args.at<JSFinalizationRegistry>(0);
17 
18   if (!finalization_registry->key_map().IsUndefined(isolate)) {
19     Handle<SimpleNumberDictionary> key_map =
20         handle(SimpleNumberDictionary::cast(finalization_registry->key_map()),
21                isolate);
22     key_map = SimpleNumberDictionary::Shrink(isolate, key_map);
23     finalization_registry->set_key_map(*key_map);
24   }
25 
26   return ReadOnlyRoots(isolate).undefined_value();
27 }
28 
RUNTIME_FUNCTION(Runtime_JSFinalizationRegistryRegisterWeakCellWithUnregisterToken)29 RUNTIME_FUNCTION(
30     Runtime_JSFinalizationRegistryRegisterWeakCellWithUnregisterToken) {
31   HandleScope scope(isolate);
32   DCHECK_EQ(2, args.length());
33   Handle<JSFinalizationRegistry> finalization_registry =
34       args.at<JSFinalizationRegistry>(0);
35   Handle<WeakCell> weak_cell = args.at<WeakCell>(1);
36 
37   JSFinalizationRegistry::RegisterWeakCellWithUnregisterToken(
38       finalization_registry, weak_cell, isolate);
39 
40   return ReadOnlyRoots(isolate).undefined_value();
41 }
42 
RUNTIME_FUNCTION(Runtime_JSWeakRefAddToKeptObjects)43 RUNTIME_FUNCTION(Runtime_JSWeakRefAddToKeptObjects) {
44   HandleScope scope(isolate);
45   DCHECK_EQ(1, args.length());
46   Handle<HeapObject> object = args.at<HeapObject>(0);
47   DCHECK(object->CanBeHeldWeakly());
48 
49   isolate->heap()->KeepDuringJob(object);
50 
51   return ReadOnlyRoots(isolate).undefined_value();
52 }
53 
54 }  // namespace internal
55 }  // namespace v8
56