2020-07-07 09:59:51 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef INCLUDE_V8_CPPGC_H_
|
|
|
|
#define INCLUDE_V8_CPPGC_H_
|
|
|
|
|
|
|
|
#include "cppgc/visitor.h"
|
2020-07-10 14:50:36 +00:00
|
|
|
#include "v8-internal.h" // NOLINT(build/include_directory)
|
2020-07-07 09:59:51 +00:00
|
|
|
#include "v8.h" // NOLINT(build/include_directory)
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
class JSVisitor : public cppgc::Visitor {
|
|
|
|
public:
|
|
|
|
explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
|
|
|
|
|
2020-10-27 12:50:20 +00:00
|
|
|
void Trace(const TracedReferenceBase& ref) {
|
2020-10-02 16:28:57 +00:00
|
|
|
if (ref.IsEmptyThreadSafe()) return;
|
2020-07-07 09:59:51 +00:00
|
|
|
Visit(ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
using cppgc::Visitor::Visit;
|
|
|
|
|
2020-10-27 12:50:20 +00:00
|
|
|
virtual void Visit(const TracedReferenceBase& ref) {}
|
2020-07-07 09:59:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
namespace cppgc {
|
|
|
|
|
2020-10-15 09:57:00 +00:00
|
|
|
template <typename T>
|
2020-10-27 12:50:20 +00:00
|
|
|
struct TraceTrait<v8::TracedReference<T>> {
|
|
|
|
static void Trace(Visitor* visitor, const v8::TracedReference<T>* self) {
|
2020-07-07 09:59:51 +00:00
|
|
|
static_cast<v8::JSVisitor*>(visitor)->Trace(*self);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cppgc
|
|
|
|
|
|
|
|
#endif // INCLUDE_V8_CPPGC_H_
|