• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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/builtins/builtins-utils-inl.h"
6 #include "src/logging/counters.h"
7 #include "src/objects/js-weak-refs-inl.h"
8 
9 namespace v8 {
10 namespace internal {
11 
BUILTIN(FinalizationRegistryUnregister)12 BUILTIN(FinalizationRegistryUnregister) {
13   HandleScope scope(isolate);
14   const char* method_name = "FinalizationRegistry.prototype.unregister";
15 
16   // 1. Let finalizationGroup be the this value.
17   //
18   // 2. If Type(finalizationGroup) is not Object, throw a TypeError
19   //    exception.
20   //
21   // 3. If finalizationGroup does not have a [[Cells]] internal slot,
22   //    throw a TypeError exception.
23   CHECK_RECEIVER(JSFinalizationRegistry, finalization_registry, method_name);
24 
25   Handle<Object> unregister_token = args.atOrUndefined(isolate, 1);
26 
27   // 4. If Type(unregisterToken) is not Object, throw a TypeError exception.
28   if (!unregister_token->IsJSReceiver()) {
29     THROW_NEW_ERROR_RETURN_FAILURE(
30         isolate,
31         NewTypeError(MessageTemplate::kWeakRefsUnregisterTokenMustBeObject,
32                      unregister_token));
33   }
34 
35   bool success = JSFinalizationRegistry::Unregister(
36       finalization_registry, Handle<JSReceiver>::cast(unregister_token),
37       isolate);
38 
39   return *isolate->factory()->ToBoolean(success);
40 }
41 
42 }  // namespace internal
43 }  // namespace v8
44