• 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 #ifndef INCLUDE_V8_CPPGC_H_
6 #define INCLUDE_V8_CPPGC_H_
7 
8 #include "cppgc/visitor.h"
9 #include "v8-internal.h"  // NOLINT(build/include_directory)
10 #include "v8.h"  // NOLINT(build/include_directory)
11 
12 namespace v8 {
13 
14 class JSVisitor : public cppgc::Visitor {
15  public:
JSVisitor(cppgc::Visitor::Key key)16   explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
17 
Trace(const TracedReferenceBase & ref)18   void Trace(const TracedReferenceBase& ref) {
19     if (ref.IsEmptyThreadSafe()) return;
20     Visit(ref);
21   }
22 
23  protected:
24   using cppgc::Visitor::Visit;
25 
Visit(const TracedReferenceBase & ref)26   virtual void Visit(const TracedReferenceBase& ref) {}
27 };
28 
29 }  // namespace v8
30 
31 namespace cppgc {
32 
33 template <typename T>
34 struct TraceTrait<v8::TracedReference<T>> {
35   static void Trace(Visitor* visitor, const v8::TracedReference<T>* self) {
36     static_cast<v8::JSVisitor*>(visitor)->Trace(*self);
37   }
38 };
39 
40 }  // namespace cppgc
41 
42 #endif  // INCLUDE_V8_CPPGC_H_
43