Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h

Issue 2474693002: [wrapper-tracing] Support for incrementally tracing ScopedPersistent (Closed)
Patch Set: Addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h b/third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h
index 25333d7e640018e81a364407ee05d57f084327d6..8e8d42202ab83a8fbc052580647184c96913a99d 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h
+++ b/third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h
@@ -31,6 +31,7 @@
#ifndef ScopedPersistent_h
#define ScopedPersistent_h
+#include "bindings/core/v8/ScriptWrappableVisitor.h"
#include "wtf/Allocator.h"
#include "wtf/Noncopyable.h"
#include <memory>
@@ -55,7 +56,7 @@ class ScopedPersistent {
m_handle.Reset(isolate, local);
}
- ~ScopedPersistent() { clear(); }
+ virtual ~ScopedPersistent() { clear(); }
ALWAYS_INLINE v8::Local<T> newLocal(v8::Isolate* isolate) const {
return v8::Local<T>::New(isolate, m_handle);
@@ -79,7 +80,7 @@ class ScopedPersistent {
bool isEmpty() const { return m_handle.IsEmpty(); }
bool isWeak() const { return m_handle.IsWeak(); }
- void set(v8::Isolate* isolate, v8::Local<T> handle) {
+ virtual void set(v8::Isolate* isolate, v8::Local<T> handle) {
m_handle.Reset(isolate, handle);
}
@@ -112,6 +113,51 @@ class ScopedPersistent {
v8::Persistent<T> m_handle;
};
+/**
+ * TraceWrapperScopedPersistent is used to trace from Blink to V8.
+ *
+ * TODO(mlippautz): Once shipped, create a separate type with a more
+ * appropriate handle type than v8::Persistent. The handle should have regular
+ * tracing semantics, i.e., only hold strongly on to an object if reached
+ * trough tracing.
haraken 2016/11/03 05:55:25 through
Michael Lippautz 2016/11/03 08:59:54 Done.
+ */
+template <typename T>
+class TraceWrapperScopedPersistent : public ScopedPersistent<T> {
+ public:
+ TraceWrapperScopedPersistent(void* parent)
+ : ScopedPersistent<T>(), m_parent(parent) {}
+
+ TraceWrapperScopedPersistent(void* parent,
+ v8::Isolate* isolate,
+ v8::Local<T> handle)
+ : ScopedPersistent<T>(isolate, handle), m_parent(parent) {
+ ScriptWrappableVisitor::writeBarrier(m_parent, this);
+ }
+
+ TraceWrapperScopedPersistent(void* parent,
+ v8::Isolate* isolate,
+ v8::MaybeLocal<T> maybe)
+ : ScopedPersistent<T>(isolate, maybe), m_parent(parent) {
+ v8::Local<T> local;
+ if (maybe.ToLocal(&local))
+ ScriptWrappableVisitor::writeBarrier(m_parent, this);
+ }
+
+ void set(v8::Isolate* isolate, v8::Local<T> handle) override {
+ ScriptWrappableVisitor::writeBarrier(m_parent, this);
+ ScopedPersistent<T>::set(isolate, handle);
+ }
+
+ template <typename S>
+ const TraceWrapperScopedPersistent<S>& cast() const {
+ return reinterpret_cast<const TraceWrapperScopedPersistent<S>&>(
+ const_cast<const TraceWrapperScopedPersistent<T>&>(*this));
+ }
+
+ private:
+ void* m_parent;
+};
+
} // namespace blink
#endif // ScopedPersistent_h

Powered by Google App Engine
This is Rietveld 408576698