Commit 81b83e03 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap/cppgc: Add helpers for Persistent and friends

Bug: chromium:1056170
Change-Id: I3754025e8d935887cdbfa6d2c517c715dabc09d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532080
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827242}
parent 956596ea
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_
#include "base/bind.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
#include "v8/include/cppgc/cross-thread-persistent.h"
#include "v8/include/cppgc/persistent.h" #include "v8/include/cppgc/persistent.h"
#include "v8/include/cppgc/source-location.h"
namespace blink { namespace blink {
...@@ -15,6 +19,68 @@ using Persistent = cppgc::Persistent<T>; ...@@ -15,6 +19,68 @@ using Persistent = cppgc::Persistent<T>;
template <typename T> template <typename T>
using WeakPersistent = cppgc::WeakPersistent<T>; using WeakPersistent = cppgc::WeakPersistent<T>;
template <typename T>
using CrossThreadPersistent = cppgc::subtle::CrossThreadPersistent<T>;
template <typename T>
using CrossThreadWeakPersistent = cppgc::subtle::WeakCrossThreadPersistent<T>;
template <typename T>
Persistent<T> WrapPersistent(
T* value,
const cppgc::SourceLocation& loc = cppgc::SourceLocation::Current()) {
return Persistent<T>(value, loc);
}
template <typename T>
WeakPersistent<T> WrapWeakPersistent(
T* value,
const cppgc::SourceLocation& loc = cppgc::SourceLocation::Current()) {
return WeakPersistent<T>(value, loc);
}
template <typename T>
CrossThreadPersistent<T> WrapCrossthreadPersistent(
T* value,
const cppgc::SourceLocation& loc = cppgc::SourceLocation::Current()) {
return CrossThreadPersistent<T>(value, loc);
}
template <typename T>
CrossThreadWeakPersistent<T> WrapCrossThreadWeakPersistent(
T* value,
const cppgc::SourceLocation& loc = cppgc::SourceLocation::Current()) {
return CrossThreadWeakPersistent<T>(value, loc);
}
template <typename T,
typename = std::enable_if_t<WTF::IsGarbageCollectedType<T>::value>>
Persistent<T> WrapPersistentIfNeeded(T* value) {
return Persistent<T>(value);
}
template <typename T>
T& WrapPersistentIfNeeded(T& value) {
return value;
}
} // namespace blink } // namespace blink
namespace base {
template <typename T>
struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
template <typename T>
struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
template <typename T>
struct BindUnwrapTraits<blink::CrossThreadWeakPersistent<T>> {
static blink::CrossThreadPersistent<T> Unwrap(
const blink::CrossThreadWeakPersistent<T>& wrapped) {
return blink::CrossThreadPersistent<T>(wrapped);
}
};
} // namespace base
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_V8_WRAPPER_PERSISTENT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment