OLD | NEW |
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 13 matching lines...) Expand all Loading... |
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 WrapperTypeInfo_h | 31 #ifndef WrapperTypeInfo_h |
32 #define WrapperTypeInfo_h | 32 #define WrapperTypeInfo_h |
33 | 33 |
| 34 #include "bindings/core/v8/ActiveScriptWrappable.h" |
34 #include "gin/public/wrapper_info.h" | 35 #include "gin/public/wrapper_info.h" |
35 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
36 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
37 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
38 #include <v8.h> | 39 #include <v8.h> |
39 | 40 |
40 namespace blink { | 41 namespace blink { |
41 | 42 |
42 class EventTarget; | 43 class EventTarget; |
43 class ScriptWrappable; | 44 class ScriptWrappable; |
44 | 45 |
45 ScriptWrappable* toScriptWrappable(const v8::PersistentBase<v8::Object>& wrapper
); | 46 ScriptWrappable* toScriptWrappable(const v8::PersistentBase<v8::Object>& wrapper
); |
46 | 47 |
47 static const int v8DOMWrapperTypeIndex = static_cast<int>(gin::kWrapperInfoIndex
); | 48 static const int v8DOMWrapperTypeIndex = static_cast<int>(gin::kWrapperInfoIndex
); |
48 static const int v8DOMWrapperObjectIndex = static_cast<int>(gin::kEncodedValueIn
dex); | 49 static const int v8DOMWrapperObjectIndex = static_cast<int>(gin::kEncodedValueIn
dex); |
49 static const int v8DefaultWrapperInternalFieldCount = static_cast<int>(gin::kNum
berOfInternalFields); | 50 static const int v8DefaultWrapperInternalFieldCount = static_cast<int>(gin::kNum
berOfInternalFields); |
50 static const int v8PrototypeTypeIndex = 0; | 51 static const int v8PrototypeTypeIndex = 0; |
51 static const int v8PrototypeInternalFieldcount = 1; | 52 static const int v8PrototypeInternalFieldcount = 1; |
52 | 53 |
53 typedef v8::Local<v8::FunctionTemplate> (*DomTemplateFunction)(v8::Isolate*); | 54 typedef v8::Local<v8::FunctionTemplate> (*DomTemplateFunction)(v8::Isolate*); |
54 typedef void (*RefObjectFunction)(ScriptWrappable*); | 55 typedef void (*RefObjectFunction)(ScriptWrappable*); |
55 typedef void (*DerefObjectFunction)(ScriptWrappable*); | 56 typedef void (*DerefObjectFunction)(ScriptWrappable*); |
56 typedef void (*TraceFunction)(Visitor*, ScriptWrappable*); | 57 typedef void (*TraceFunction)(Visitor*, ScriptWrappable*); |
| 58 typedef ActiveScriptWrappable* (*ToActiveScriptWrappableFunction)(v8::Local<v8::
Object>); |
57 typedef void (*ResolveWrapperReachabilityFunction)(v8::Isolate*, ScriptWrappable
*, const v8::Persistent<v8::Object>&); | 59 typedef void (*ResolveWrapperReachabilityFunction)(v8::Isolate*, ScriptWrappable
*, const v8::Persistent<v8::Object>&); |
58 typedef void (*PreparePrototypeAndInterfaceObjectFunction)(v8::Local<v8::Context
>, v8::Local<v8::Object>, v8::Local<v8::Function>, v8::Local<v8::FunctionTemplat
e>); | 60 typedef void (*PreparePrototypeAndInterfaceObjectFunction)(v8::Local<v8::Context
>, v8::Local<v8::Object>, v8::Local<v8::Function>, v8::Local<v8::FunctionTemplat
e>); |
59 typedef void (*InstallConditionallyEnabledPropertiesFunction)(v8::Local<v8::Obje
ct>, v8::Isolate*); | 61 typedef void (*InstallConditionallyEnabledPropertiesFunction)(v8::Local<v8::Obje
ct>, v8::Isolate*); |
60 | 62 |
61 inline void setObjectGroup(v8::Isolate* isolate, ScriptWrappable* scriptWrappabl
e, const v8::Persistent<v8::Object>& wrapper) | 63 inline void setObjectGroup(v8::Isolate* isolate, ScriptWrappable* scriptWrappabl
e, const v8::Persistent<v8::Object>& wrapper) |
62 { | 64 { |
63 isolate->SetObjectGroupId(wrapper, v8::UniqueId(reinterpret_cast<intptr_t>(s
criptWrappable))); | 65 isolate->SetObjectGroupId(wrapper, v8::UniqueId(reinterpret_cast<intptr_t>(s
criptWrappable))); |
64 } | 66 } |
65 | 67 |
66 // This struct provides a way to store a bunch of information that is helpful wh
en unwrapping | 68 // This struct provides a way to store a bunch of information that is helpful wh
en unwrapping |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (preparePrototypeAndInterfaceObjectFunction) | 176 if (preparePrototypeAndInterfaceObjectFunction) |
175 preparePrototypeAndInterfaceObjectFunction(context, prototypeObject,
interfaceObject, interfaceTemplate); | 177 preparePrototypeAndInterfaceObjectFunction(context, prototypeObject,
interfaceObject, interfaceTemplate); |
176 } | 178 } |
177 | 179 |
178 void installConditionallyEnabledProperties(v8::Local<v8::Object> prototypeOb
ject, v8::Isolate* isolate) const | 180 void installConditionallyEnabledProperties(v8::Local<v8::Object> prototypeOb
ject, v8::Isolate* isolate) const |
179 { | 181 { |
180 if (installConditionallyEnabledPropertiesFunction) | 182 if (installConditionallyEnabledPropertiesFunction) |
181 installConditionallyEnabledPropertiesFunction(prototypeObject, isola
te); | 183 installConditionallyEnabledPropertiesFunction(prototypeObject, isola
te); |
182 } | 184 } |
183 | 185 |
| 186 ActiveScriptWrappable* toActiveScriptWrappable(v8::Local<v8::Object> object)
const |
| 187 { |
| 188 if (!toActiveScriptWrappableFunction) |
| 189 return nullptr; |
| 190 return toActiveScriptWrappableFunction(object); |
| 191 } |
| 192 |
| 193 bool hasPendingActivity(v8::Local<v8::Object> object) const |
| 194 { |
| 195 return !toActiveScriptWrappableFunction ? false : toActiveScriptWrappabl
eFunction(object)->hasPendingActivity(); |
| 196 } |
| 197 |
184 EventTarget* toEventTarget(v8::Local<v8::Object>) const; | 198 EventTarget* toEventTarget(v8::Local<v8::Object>) const; |
185 | 199 |
186 void visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable* scriptWrappable,
const v8::Persistent<v8::Object>& wrapper) const | 200 void visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable* scriptWrappable,
const v8::Persistent<v8::Object>& wrapper) const |
187 { | 201 { |
188 if (!visitDOMWrapperFunction) | 202 if (!visitDOMWrapperFunction) |
189 setObjectGroup(isolate, scriptWrappable, wrapper); | 203 setObjectGroup(isolate, scriptWrappable, wrapper); |
190 else | 204 else |
191 visitDOMWrapperFunction(isolate, scriptWrappable, wrapper); | 205 visitDOMWrapperFunction(isolate, scriptWrappable, wrapper); |
192 } | 206 } |
193 | 207 |
194 // This field must be the first member of the struct WrapperTypeInfo. This i
s also checked by a static_assert() below. | 208 // This field must be the first member of the struct WrapperTypeInfo. This i
s also checked by a static_assert() below. |
195 const gin::GinEmbedder ginEmbedder; | 209 const gin::GinEmbedder ginEmbedder; |
196 | 210 |
197 DomTemplateFunction domTemplateFunction; | 211 DomTemplateFunction domTemplateFunction; |
198 const RefObjectFunction refObjectFunction; | 212 const RefObjectFunction refObjectFunction; |
199 const DerefObjectFunction derefObjectFunction; | 213 const DerefObjectFunction derefObjectFunction; |
200 const TraceFunction traceFunction; | 214 const TraceFunction traceFunction; |
| 215 const ToActiveScriptWrappableFunction toActiveScriptWrappableFunction; |
201 const ResolveWrapperReachabilityFunction visitDOMWrapperFunction; | 216 const ResolveWrapperReachabilityFunction visitDOMWrapperFunction; |
202 PreparePrototypeAndInterfaceObjectFunction preparePrototypeAndInterfaceObjec
tFunction; | 217 PreparePrototypeAndInterfaceObjectFunction preparePrototypeAndInterfaceObjec
tFunction; |
203 const InstallConditionallyEnabledPropertiesFunction installConditionallyEnab
ledPropertiesFunction; | 218 const InstallConditionallyEnabledPropertiesFunction installConditionallyEnab
ledPropertiesFunction; |
204 const char* const interfaceName; | 219 const char* const interfaceName; |
205 const WrapperTypeInfo* parentClass; | 220 const WrapperTypeInfo* parentClass; |
206 const unsigned wrapperTypePrototype : 1; // WrapperTypePrototype | 221 const unsigned wrapperTypePrototype : 1; // WrapperTypePrototype |
207 const unsigned wrapperClassId : 2; // WrapperClassId | 222 const unsigned wrapperClassId : 2; // WrapperClassId |
208 const unsigned eventTargetInheritance : 1; // EventTargetInheritance | 223 const unsigned eventTargetInheritance : 1; // EventTargetInheritance |
209 const unsigned lifetime : 1; // Lifetime | 224 const unsigned lifetime : 1; // Lifetime |
210 const unsigned gcType : 2; // GCType | 225 const unsigned gcType : 2; // GCType |
(...skipping 29 matching lines...) Expand all Loading... |
240 } | 255 } |
241 | 256 |
242 inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Local<v8::Object> wrapper) | 257 inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Local<v8::Object> wrapper) |
243 { | 258 { |
244 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper); | 259 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper); |
245 } | 260 } |
246 | 261 |
247 } // namespace blink | 262 } // namespace blink |
248 | 263 |
249 #endif // WrapperTypeInfo_h | 264 #endif // WrapperTypeInfo_h |
OLD | NEW |