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

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

Issue 2265873003: binding: Moves hasPendingActivity from ActiveScriptWrappable to ScriptWrappable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 4 years, 3 months 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
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/WrapperTypeInfo.h" 34 #include "bindings/core/v8/WrapperTypeInfo.h"
35 #include "core/CoreExport.h" 35 #include "core/CoreExport.h"
36 #include "platform/heap/Handle.h" 36 #include "platform/heap/Handle.h"
37 #include "wtf/Noncopyable.h" 37 #include "wtf/Noncopyable.h"
38 #include "wtf/TypeTraits.h" 38 #include "wtf/TypeTraits.h"
39 #include <v8.h> 39 #include <v8.h>
40 40
41 namespace blink { 41 namespace blink {
42 42
43 /** 43 // ScriptWrappable provides a way to map from/to C++ DOM implementation to/from
44 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 44 // JavaScript object (platform object). toV8() converts a ScriptWrappable to
45 * 45 // a v8::Object and toScriptWrappable() converts a v8::Object back to
46 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a 46 // a ScriptWrappable. v8::Object as platform object is called "wrapper object".
47 * V8 object alive. 47 // The wrapepr object for the main world is stored in ScriptWrappable. Wrapper
48 * 48 // objects for other worlds are stored in DOMWrapperMap.
49 * The state transitions are:
50 * - new: an empty ScriptWrappable.
51 * - setWrapper: install a v8::Persistent (or empty)
52 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter):
53 * remove v8::Persistent and become empty.
54 */
55 class CORE_EXPORT ScriptWrappable { 49 class CORE_EXPORT ScriptWrappable {
56 WTF_MAKE_NONCOPYABLE(ScriptWrappable); 50 WTF_MAKE_NONCOPYABLE(ScriptWrappable);
57 public: 51 public:
58 ScriptWrappable() { } 52 ScriptWrappable() { }
59 53
60 template<typename T> 54 template<typename T>
61 T* toImpl() 55 T* toImpl()
62 { 56 {
63 // All ScriptWrappables are managed by the Blink GC heap; check that 57 // All ScriptWrappables are managed by the Blink GC heap; check that
64 // |T| is a garbage collected type. 58 // |T| is a garbage collected type.
(...skipping 18 matching lines...) Expand all
83 77
84 // Creates and returns a new wrapper object. 78 // Creates and returns a new wrapper object.
85 virtual v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creat ionContext); 79 virtual v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creat ionContext);
86 80
87 // Associates the instance with the given |wrapper| if this instance is not 81 // Associates the instance with the given |wrapper| if this instance is not
88 // yet associated with any wrapper. Returns the wrapper already associated 82 // yet associated with any wrapper. Returns the wrapper already associated
89 // or |wrapper| if not yet associated. 83 // or |wrapper| if not yet associated.
90 // The caller should always use the returned value rather than |wrapper|. 84 // The caller should always use the returned value rather than |wrapper|.
91 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp erTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; 85 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp erTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN;
92 86
87 // Returns true if the instance needs to be kept alive even when the
88 // instance is unreachable from JavaScript.
89 virtual bool hasPendingActivity() const { return false; }
90
93 // Associates this instance with the given |wrapper| if this instance is not 91 // Associates this instance with the given |wrapper| if this instance is not
94 // yet associated with any wrapper. Returns true if the given wrapper is 92 // yet associated with any wrapper. Returns true if the given wrapper is
95 // associated with this instance, or false if this instance is already 93 // associated with this instance, or false if this instance is already
96 // associated with a wrapper. In the latter case, |wrapper| will be updated 94 // associated with a wrapper. In the latter case, |wrapper| will be updated
97 // to the existing wrapper. 95 // to the existing wrapper.
98 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN 96 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN
99 { 97 {
100 ASSERT(!wrapper.IsEmpty()); 98 ASSERT(!wrapper.IsEmpty());
101 if (UNLIKELY(containsWrapper())) { 99 if (UNLIKELY(containsWrapper())) {
102 wrapper = mainWorldWrapper(isolate); 100 wrapper = mainWorldWrapper(isolate);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return containsWrapper(); 135 return containsWrapper();
138 } 136 }
139 137
140 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late) 138 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late)
141 { 139 {
142 isolate->SetReference(parent, m_mainWorldWrapper); 140 isolate->SetReference(parent, m_mainWorldWrapper);
143 } 141 }
144 142
145 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); } 143 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); }
146 144
147 /** 145 // Mark wrapper of this ScriptWrappable as alive in V8. Only marks
148 * Mark wrapper of this ScriptWrappable as alive in V8. Only marks 146 // wrapper in the main world. To mark wrappers in all worlds call
149 * wrapper in the main world. To mark wrappers in all worlds call 147 // ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*)
150 * ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*)
151 */
152 void markWrapper(const WrapperVisitor*) const; 148 void markWrapper(const WrapperVisitor*) const;
153 149
154 DECLARE_VIRTUAL_TRACE_WRAPPERS() {}; 150 DECLARE_VIRTUAL_TRACE_WRAPPERS() {};
155 151
156 // With Oilpan we don't need a ScriptWrappable destructor.
157 //
158 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee ded
159 // because Oilpan is not using reference counting at all. If containsWrapper () is true,
160 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor
161 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object.
162 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are
163 // already broken), we must not hit the RELEASE_ASSERT.
164
165 private: 152 private:
166 // These classes are exceptionally allowed to use mainWorldWrapper(). 153 // These classes are exceptionally allowed to use mainWorldWrapper().
167 friend class DOMDataStore; 154 friend class DOMDataStore;
168 friend class V8HiddenValue; 155 friend class V8HiddenValue;
169 friend class V8PrivateProperty; 156 friend class V8PrivateProperty;
170 friend class WebGLRenderingContextBase; 157 friend class WebGLRenderingContextBase;
171 158
172 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const 159 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const
173 { 160 {
174 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper); 161 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper);
(...skipping 30 matching lines...) Expand all
205 // in X's cpp code, and instantiate X, i.e. "template class X;". 192 // in X's cpp code, and instantiate X, i.e. "template class X;".
206 #define DECLARE_WRAPPERTYPEINFO() \ 193 #define DECLARE_WRAPPERTYPEINFO() \
207 public: \ 194 public: \
208 const WrapperTypeInfo* wrapperTypeInfo() const override; \ 195 const WrapperTypeInfo* wrapperTypeInfo() const override; \
209 private: \ 196 private: \
210 typedef void end_of_define_wrappertypeinfo_not_reached_t 197 typedef void end_of_define_wrappertypeinfo_not_reached_t
211 198
212 } // namespace blink 199 } // namespace blink
213 200
214 #endif // ScriptWrappable_h 201 #endif // ScriptWrappable_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698