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

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

Issue 2474693002: [wrapper-tracing] Support for incrementally tracing ScopedPersistent (Closed)
Patch Set: Added bailout for tests when the flag is off 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef ScopedPersistent_h 31 #ifndef ScopedPersistent_h
32 #define ScopedPersistent_h 32 #define ScopedPersistent_h
33 33
34 #include "bindings/core/v8/ScriptWrappableVisitor.h"
34 #include "wtf/Allocator.h" 35 #include "wtf/Allocator.h"
35 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
36 #include <memory> 37 #include <memory>
37 #include <v8.h> 38 #include <v8.h>
38 39
39 namespace blink { 40 namespace blink {
40 41
41 template <typename T> 42 template <typename T>
42 class ScopedPersistent { 43 class ScopedPersistent {
43 USING_FAST_MALLOC(ScopedPersistent); 44 USING_FAST_MALLOC(ScopedPersistent);
44 WTF_MAKE_NONCOPYABLE(ScopedPersistent); 45 WTF_MAKE_NONCOPYABLE(ScopedPersistent);
45 46
46 public: 47 public:
47 ScopedPersistent() {} 48 ScopedPersistent() {}
48 49
49 ScopedPersistent(v8::Isolate* isolate, v8::Local<T> handle) 50 ScopedPersistent(v8::Isolate* isolate, v8::Local<T> handle)
50 : m_handle(isolate, handle) {} 51 : m_handle(isolate, handle) {}
51 52
52 ScopedPersistent(v8::Isolate* isolate, v8::MaybeLocal<T> maybe) { 53 ScopedPersistent(v8::Isolate* isolate, v8::MaybeLocal<T> maybe) {
53 v8::Local<T> local; 54 v8::Local<T> local;
54 if (maybe.ToLocal(&local)) 55 if (maybe.ToLocal(&local))
55 m_handle.Reset(isolate, local); 56 m_handle.Reset(isolate, local);
56 } 57 }
57 58
58 ~ScopedPersistent() { clear(); } 59 virtual ~ScopedPersistent() { clear(); }
59 60
60 ALWAYS_INLINE v8::Local<T> newLocal(v8::Isolate* isolate) const { 61 ALWAYS_INLINE v8::Local<T> newLocal(v8::Isolate* isolate) const {
61 return v8::Local<T>::New(isolate, m_handle); 62 return v8::Local<T>::New(isolate, m_handle);
62 } 63 }
63 64
64 // If you don't need to get weak callback, use setPhantom instead. 65 // If you don't need to get weak callback, use setPhantom instead.
65 // setPhantom is faster than setWeak. 66 // setPhantom is faster than setWeak.
66 template <typename P> 67 template <typename P>
67 void setWeak(P* parameters, 68 void setWeak(P* parameters,
68 void (*callback)(const v8::WeakCallbackInfo<P>&), 69 void (*callback)(const v8::WeakCallbackInfo<P>&),
69 v8::WeakCallbackType type = v8::WeakCallbackType::kParameter) { 70 v8::WeakCallbackType type = v8::WeakCallbackType::kParameter) {
70 m_handle.SetWeak(parameters, callback, type); 71 m_handle.SetWeak(parameters, callback, type);
71 } 72 }
72 73
73 // Turns this handle into a weak phantom handle without 74 // Turns this handle into a weak phantom handle without
74 // finalization callback. 75 // finalization callback.
75 void setPhantom() { m_handle.SetWeak(); } 76 void setPhantom() { m_handle.SetWeak(); }
76 77
77 void clearWeak() { m_handle.template ClearWeak<void>(); } 78 void clearWeak() { m_handle.template ClearWeak<void>(); }
78 79
79 bool isEmpty() const { return m_handle.IsEmpty(); } 80 bool isEmpty() const { return m_handle.IsEmpty(); }
80 bool isWeak() const { return m_handle.IsWeak(); } 81 bool isWeak() const { return m_handle.IsWeak(); }
81 82
82 void set(v8::Isolate* isolate, v8::Local<T> handle) { 83 virtual void set(v8::Isolate* isolate, v8::Local<T> handle) {
83 m_handle.Reset(isolate, handle); 84 m_handle.Reset(isolate, handle);
84 } 85 }
85 86
86 // Note: This is clear in the std::unique_ptr sense, not the v8::Handle sense. 87 // Note: This is clear in the std::unique_ptr sense, not the v8::Handle sense.
87 void clear() { m_handle.Reset(); } 88 void clear() { m_handle.Reset(); }
88 89
89 void setReference(const v8::Persistent<v8::Object>& parent, 90 void setReference(const v8::Persistent<v8::Object>& parent,
90 v8::Isolate* isolate) { 91 v8::Isolate* isolate) {
91 isolate->SetReference(parent, m_handle); 92 isolate->SetReference(parent, m_handle);
92 } 93 }
(...skipping 12 matching lines...) Expand all
105 template <typename S> 106 template <typename S>
106 const ScopedPersistent<S>& cast() const { 107 const ScopedPersistent<S>& cast() const {
107 return reinterpret_cast<const ScopedPersistent<v8::Object>&>( 108 return reinterpret_cast<const ScopedPersistent<v8::Object>&>(
108 const_cast<const ScopedPersistent<T>&>(*this)); 109 const_cast<const ScopedPersistent<T>&>(*this));
109 } 110 }
110 111
111 private: 112 private:
112 v8::Persistent<T> m_handle; 113 v8::Persistent<T> m_handle;
113 }; 114 };
114 115
116 /**
117 * TraceWrapperV8Reference is used to trace from Blink to V8.
118 *
119 * TODO(mlippautz): Once shipped, create a separate type with a more
120 * appropriate handle type than v8::Persistent. The handle should have regular
121 * tracing semantics, i.e., only hold strongly on to an object if reached
122 * through tracing.
123 */
124 template <typename T>
125 class TraceWrapperV8Reference : public ScopedPersistent<T> {
126 public:
127 explicit TraceWrapperV8Reference(void* parent)
128 : ScopedPersistent<T>(), m_parent(parent) {}
129
130 TraceWrapperV8Reference(v8::Isolate* isolate,
131 void* parent,
132 v8::Local<T> handle)
133 : ScopedPersistent<T>(isolate, handle), m_parent(parent) {
134 ScriptWrappableVisitor::writeBarrier(m_parent, &cast<v8::Value>());
135 }
136
137 void set(v8::Isolate* isolate, v8::Local<T> handle) override {
138 ScopedPersistent<T>::set(isolate, handle);
139 ScriptWrappableVisitor::writeBarrier(m_parent, &cast<v8::Value>());
140 }
141
142 template <typename S>
143 const TraceWrapperV8Reference<S>& cast() const {
144 return reinterpret_cast<const TraceWrapperV8Reference<S>&>(
145 const_cast<const TraceWrapperV8Reference<T>&>(*this));
146 }
147
148 private:
149 void* m_parent;
150 };
151
115 } // namespace blink 152 } // namespace blink
116 153
117 #endif // ScopedPersistent_h 154 #endif // ScopedPersistent_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698