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

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

Issue 2021203002: Rename ScriptWrappable::newLocalWrapper to ScriptWrappable::mainWorldWrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Associates this instance with the given |wrapper| if this instance is not 94 // Associates this instance with the given |wrapper| if this instance is not
95 // yet associated with any wrapper. Returns true if the given wrapper is 95 // yet associated with any wrapper. Returns true if the given wrapper is
96 // associated with this instance, or false if this instance is already 96 // associated with this instance, or false if this instance is already
97 // associated with a wrapper. In the latter case, |wrapper| will be updated 97 // associated with a wrapper. In the latter case, |wrapper| will be updated
98 // to the existing wrapper. 98 // to the existing wrapper.
99 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN 99 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN
100 { 100 {
101 ASSERT(!wrapper.IsEmpty()); 101 ASSERT(!wrapper.IsEmpty());
102 if (UNLIKELY(containsWrapper())) { 102 if (UNLIKELY(containsWrapper())) {
103 wrapper = newLocalWrapper(isolate); 103 wrapper = mainWorldWrapper(isolate);
104 return false; 104 return false;
105 } 105 }
106 m_wrapper.Reset(isolate, wrapper); 106 m_mainWorldWrapper.Reset(isolate, wrapper);
107 wrapperTypeInfo->configureWrapper(&m_wrapper); 107 wrapperTypeInfo->configureWrapper(&m_mainWorldWrapper);
108 m_wrapper.SetWeak(); 108 m_mainWorldWrapper.SetWeak();
109 ASSERT(containsWrapper()); 109 ASSERT(containsWrapper());
110 return true; 110 return true;
111 } 111 }
112 112
113 v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const
114 {
115 return v8::Local<v8::Object>::New(isolate, m_wrapper);
116 }
117
118 bool isEqualTo(const v8::Local<v8::Object>& other) const 113 bool isEqualTo(const v8::Local<v8::Object>& other) const
119 { 114 {
120 return m_wrapper == other; 115 return m_mainWorldWrapper == other;
121 } 116 }
122 117
123 // Provides a way to convert Node* to ScriptWrappable* without including 118 // Provides a way to convert Node* to ScriptWrappable* without including
124 // "core/dom/Node.h". 119 // "core/dom/Node.h".
125 // 120 //
126 // Example: 121 // Example:
127 // void foo(const void*) { ... } // [1] 122 // void foo(const void*) { ... } // [1]
128 // void foo(ScriptWrappable*) { ... } // [2] 123 // void foo(ScriptWrappable*) { ... } // [2]
129 // class Node; 124 // class Node;
130 // Node* node; 125 // Node* node;
131 // foo(node); // This calls [1] because there is no definition of Node 126 // foo(node); // This calls [1] because there is no definition of Node
132 // // and compilers do not know that Node is a subclass of 127 // // and compilers do not know that Node is a subclass of
133 // // ScriptWrappable. 128 // // ScriptWrappable.
134 // foo(ScriptWrappable::fromNode(node)); // This calls [2] as expected. 129 // foo(ScriptWrappable::fromNode(node)); // This calls [2] as expected.
135 // 130 //
136 // The definition of fromNode is placed in Node.h because we'd like to 131 // The definition of fromNode is placed in Node.h because we'd like to
137 // inline calls to fromNode as much as possible. 132 // inline calls to fromNode as much as possible.
138 static ScriptWrappable* fromNode(Node*); 133 static ScriptWrappable* fromNode(Node*);
139 134
140 bool setReturnValue(v8::ReturnValue<v8::Value> returnValue) 135 bool setReturnValue(v8::ReturnValue<v8::Value> returnValue)
141 { 136 {
142 returnValue.Set(m_wrapper); 137 returnValue.Set(m_mainWorldWrapper);
143 return containsWrapper(); 138 return containsWrapper();
144 } 139 }
145 140
146 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late) 141 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late)
147 { 142 {
148 isolate->SetReference(parent, m_wrapper); 143 isolate->SetReference(parent, m_mainWorldWrapper);
149 } 144 }
150 145
151 bool containsWrapper() const { return !m_wrapper.IsEmpty(); } 146 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); }
152 147
153 /** 148 /**
154 * Mark wrapper of this ScriptWrappable as alive in V8. Only marks 149 * Mark wrapper of this ScriptWrappable as alive in V8. Only marks
155 * wrapper in the main world. To mark wrappers in all worlds call 150 * wrapper in the main world. To mark wrappers in all worlds call
156 * ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*) 151 * ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*)
157 */ 152 */
158 void markWrapper(v8::Isolate*) const; 153 void markWrapper(v8::Isolate*) const;
159 154
160 DECLARE_VIRTUAL_TRACE_WRAPPERS() {}; 155 DECLARE_VIRTUAL_TRACE_WRAPPERS() {};
161 156
162 // With Oilpan we don't need a ScriptWrappable destructor. 157 // With Oilpan we don't need a ScriptWrappable destructor.
163 // 158 //
164 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee ded 159 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee ded
165 // because Oilpan is not using reference counting at all. If containsWrapper () is true, 160 // because Oilpan is not using reference counting at all. If containsWrapper () is true,
166 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor 161 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor
167 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object. 162 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object.
168 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are 163 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are
169 // already broken), we must not hit the RELEASE_ASSERT. 164 // already broken), we must not hit the RELEASE_ASSERT.
170 165
171 private: 166 private:
172 v8::Persistent<v8::Object> m_wrapper; 167 friend class DOMDataStore;
Yuki 2016/05/31 04:43:11 Maybe, better to comment why these classes are fri
haraken 2016/05/31 04:44:33 Done.
168 friend class V8HiddenValue;
169 friend class V8PrivateProperty;
170 friend class WebGLRenderingContextBase;
171
172 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const
173 {
174 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper);
175 }
176
177 v8::Persistent<v8::Object> m_mainWorldWrapper;
173 }; 178 };
174 179
175 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of 180 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of
176 // the instance. Also declares a static member of type WrapperTypeInfo, of which 181 // the instance. Also declares a static member of type WrapperTypeInfo, of which
177 // the definition is given by the IDL code generator. 182 // the definition is given by the IDL code generator.
178 // 183 //
179 // All the derived classes of ScriptWrappable, regardless of directly or 184 // All the derived classes of ScriptWrappable, regardless of directly or
180 // indirectly, must write this macro in the class definition as long as the 185 // indirectly, must write this macro in the class definition as long as the
181 // class has a corresponding .idl file. 186 // class has a corresponding .idl file.
182 #define DEFINE_WRAPPERTYPEINFO() \ 187 #define DEFINE_WRAPPERTYPEINFO() \
(...skipping 17 matching lines...) Expand all
200 // in X's cpp code, and instantiate X, i.e. "template class X;". 205 // in X's cpp code, and instantiate X, i.e. "template class X;".
201 #define DECLARE_WRAPPERTYPEINFO() \ 206 #define DECLARE_WRAPPERTYPEINFO() \
202 public: \ 207 public: \
203 const WrapperTypeInfo* wrapperTypeInfo() const override; \ 208 const WrapperTypeInfo* wrapperTypeInfo() const override; \
204 private: \ 209 private: \
205 typedef void end_of_define_wrappertypeinfo_not_reached_t 210 typedef void end_of_define_wrappertypeinfo_not_reached_t
206 211
207 } // namespace blink 212 } // namespace blink
208 213
209 #endif // ScriptWrappable_h 214 #endif // ScriptWrappable_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698