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

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

Issue 2479133002: [wrapper-tracing] Fix dispatching of TraceWrapperv8Reference (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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TraceWrapperV8Reference_h
6 #define TraceWrapperV8Reference_h
7
8 #include "bindings/core/v8/ScriptWrappableVisitor.h"
9
10 namespace blink {
11
12 /**
13 * TraceWrapperV8Reference is used to trace from Blink to V8. The reference is
14 * weak
15 * unless traced.
haraken 2016/11/07 14:27:58 If the wrapper tracing is disabled, the reference
Michael Lippautz 2016/11/07 15:07:15 Done.
16 *
17 * TODO(mlippautz): Once shipped, create a separate type with a more
18 * appropriate handle type than v8::Persistent. The handle should have regular
19 * tracing semantics, i.e., only hold strongly on to an object if reached
20 * through tracing.
21 */
22 template <typename T>
23 class TraceWrapperV8Reference /*: public ScopedPersistent<T> */ {
haraken 2016/11/07 14:27:58 Remove the comment.
Michael Lippautz 2016/11/07 15:07:15 Done.
24 public:
25 explicit TraceWrapperV8Reference(void* parent) : m_parent(parent) {}
26
27 TraceWrapperV8Reference(v8::Isolate* isolate,
28 void* parent,
29 v8::Local<T> handle)
30 : m_handle(isolate, handle), m_parent(parent) {
haraken 2016/11/07 14:27:58 It would be better to use internalSet. Then you ca
Michael Lippautz 2016/11/07 15:07:15 Done.
31 m_handle.SetWeak();
haraken 2016/11/07 14:27:58 Can we use SetPhantom?
Michael Lippautz 2016/11/07 15:07:15 SetWeak() without callbacks implements the phantom
32 ScriptWrappableVisitor::writeBarrier(m_parent, &cast<v8::Value>());
33 }
34
35 ~TraceWrapperV8Reference() { clear(); }
36
37 void set(v8::Isolate* isolate, v8::Local<T> handle) {
38 internalSet(isolate, handle);
39 m_handle.SetWeak();
haraken 2016/11/07 14:27:58 Can we use SetPhantom?
Michael Lippautz 2016/11/07 15:07:15 See above.
40 }
41
42 template <typename P>
43 void set(v8::Isolate* isolate,
44 v8::Local<T> handle,
45 P* parameters,
46 void (*callback)(const v8::WeakCallbackInfo<P>&),
47 v8::WeakCallbackType type = v8::WeakCallbackType::kParameter) {
48 internalSet(isolate, handle);
49 m_handle.SetWeak(parameters, callback, type);
50 }
51
52 ALWAYS_INLINE v8::Local<T> newLocal(v8::Isolate* isolate) const {
53 return v8::Local<T>::New(isolate, m_handle);
54 }
55
56 bool isEmpty() const { return m_handle.IsEmpty(); }
57 void clear() { m_handle.Reset(); }
58 ALWAYS_INLINE v8::Persistent<T>& get() { return m_handle; }
59
60 void setReference(const v8::Persistent<v8::Object>& parent,
61 v8::Isolate* isolate) {
62 isolate->SetReference(parent, m_handle);
haraken 2016/11/07 14:27:58 This should not be called if the wrapper tracing i
Michael Lippautz 2016/11/07 15:07:15 Done.
63 }
64
65 template <typename S>
66 const TraceWrapperV8Reference<S>& cast() const {
Michael Lippautz 2016/11/07 10:36:13 This cast is not safe when we have vtable + templa
haraken 2016/11/07 14:27:58 Sounds reasonable to me.
67 return reinterpret_cast<const TraceWrapperV8Reference<S>&>(
68 const_cast<const TraceWrapperV8Reference<T>&>(*this));
69 }
70
71 private:
72 inline void internalSet(v8::Isolate* isolate, v8::Local<T> handle) {
73 m_handle.Reset(isolate, handle);
74 ScriptWrappableVisitor::writeBarrier(m_parent, &cast<v8::Value>());
75 }
76
77 v8::Persistent<T> m_handle;
78 void* m_parent;
79 };
80
81 } // namespace blink
82
83 #endif // TraceWrapperV8Reference_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698