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

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

Issue 2474693002: [wrapper-tracing] Support for incrementally tracing ScopedPersistent (Closed)
Patch Set: 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..13b852fa3ada9cc2fc5a2072aadf71004ae554ce 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,45 @@ 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
haraken 2016/11/03 05:55:25 I'm just curious but how hard would it be to imple
Michael Lippautz 2016/11/03 08:59:53 What I have in mind is a new handle type on the V8
+ * tracing semantics, i.e., only hold strongly on to an object if reached
+ * trough tracing.
+ */
+template <typename T>
+class TraceWrapperScopedPersistent : public ScopedPersistent<T> {
Michael Lippautz 2016/11/02 16:00:03 The name doesn't really fit. I am all open for any
Marcel Hlopko 2016/11/02 16:44:51 TracedV8Reference? It's neither scoped nor persist
Michael Lippautz 2016/11/02 17:07:55 +1 for TracedV8Reference. haraken?
haraken 2016/11/03 05:55:25 I want to keep a "TraceWrapper" prefix at least. T
Michael Lippautz 2016/11/03 08:59:53 Done.
+ 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) {}
+
+ TraceWrapperScopedPersistent(void* parent,
+ v8::Isolate* isolate,
+ v8::MaybeLocal<T> maybe)
+ : ScopedPersistent<T>(isolate, maybe), m_parent(parent) {}
+
+ 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