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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 enum WrapperTypePrototype { | 66 enum WrapperTypePrototype { |
67 WrapperTypeObjectPrototype, | 67 WrapperTypeObjectPrototype, |
68 WrapperTypeErrorPrototype | 68 WrapperTypeErrorPrototype |
69 }; | 69 }; |
70 | 70 |
71 // This struct provides a way to store a bunch of information that is helpfu
l when unwrapping | 71 // This struct provides a way to store a bunch of information that is helpfu
l when unwrapping |
72 // v8 objects. Each v8 bindings class has exactly one static WrapperTypeInfo
member, so | 72 // v8 objects. Each v8 bindings class has exactly one static WrapperTypeInfo
member, so |
73 // comparing pointers is a safe way to determine if types match. | 73 // comparing pointers is a safe way to determine if types match. |
74 struct WrapperTypeInfo { | 74 struct WrapperTypeInfo { |
75 | 75 |
76 static WrapperTypeInfo* unwrap(v8::Handle<v8::Value> typeInfoWrapper) | 76 static const WrapperTypeInfo* unwrap(v8::Handle<v8::Value> typeInfoWrapp
er) |
77 { | 77 { |
78 return reinterpret_cast<WrapperTypeInfo*>(v8::External::Cast(*typeIn
foWrapper)->Value()); | 78 return reinterpret_cast<const WrapperTypeInfo*>(v8::External::Cast(*
typeInfoWrapper)->Value()); |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 bool equals(const WrapperTypeInfo* that) const | 82 bool equals(const WrapperTypeInfo* that) const |
83 { | 83 { |
84 return this == that; | 84 return this == that; |
85 } | 85 } |
86 | 86 |
87 bool isSubclass(const WrapperTypeInfo* that) const | 87 bool isSubclass(const WrapperTypeInfo* that) const |
88 { | 88 { |
89 for (const WrapperTypeInfo* current = this; current; current = curre
nt->parentClass) { | 89 for (const WrapperTypeInfo* current = this; current; current = curre
nt->parentClass) { |
90 if (current == that) | 90 if (current == that) |
91 return true; | 91 return true; |
92 } | 92 } |
93 | 93 |
94 return false; | 94 return false; |
95 } | 95 } |
96 | 96 |
97 v8::Handle<v8::FunctionTemplate> getTemplate(v8::Isolate* isolate, Wrapp
erWorldType worldType) { return getTemplateFunction(isolate, worldType); } | 97 v8::Handle<v8::FunctionTemplate> getTemplate(v8::Isolate* isolate, Wrapp
erWorldType worldType) const { return getTemplateFunction(isolate, worldType); } |
98 | 98 |
99 void derefObject(void* object) | 99 void derefObject(void* object) const |
100 { | 100 { |
101 if (derefObjectFunction) | 101 if (derefObjectFunction) |
102 derefObjectFunction(object); | 102 derefObjectFunction(object); |
103 } | 103 } |
104 | 104 |
105 void installPerContextEnabledPrototypeProperties(v8::Handle<v8::Object>
proto, v8::Isolate* isolate) | 105 void installPerContextEnabledPrototypeProperties(v8::Handle<v8::Object>
proto, v8::Isolate* isolate) const |
106 { | 106 { |
107 if (installPerContextEnabledPrototypePropertiesFunction) | 107 if (installPerContextEnabledPrototypePropertiesFunction) |
108 installPerContextEnabledPrototypePropertiesFunction(proto, isola
te); | 108 installPerContextEnabledPrototypePropertiesFunction(proto, isola
te); |
109 } | 109 } |
110 | 110 |
111 ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object> object) | 111 ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object> object) const |
112 { | 112 { |
113 if (!toActiveDOMObjectFunction) | 113 if (!toActiveDOMObjectFunction) |
114 return 0; | 114 return 0; |
115 return toActiveDOMObjectFunction(object); | 115 return toActiveDOMObjectFunction(object); |
116 } | 116 } |
117 | 117 |
118 EventTarget* toEventTarget(v8::Handle<v8::Object> object) | 118 EventTarget* toEventTarget(v8::Handle<v8::Object> object) const |
119 { | 119 { |
120 if (!toEventTargetFunction) | 120 if (!toEventTargetFunction) |
121 return 0; | 121 return 0; |
122 return toEventTargetFunction(object); | 122 return toEventTargetFunction(object); |
123 } | 123 } |
124 | 124 |
125 void* opaqueRootForGC(void* object, v8::Isolate* isolate) | 125 void* opaqueRootForGC(void* object, v8::Isolate* isolate) const |
126 { | 126 { |
127 if (!opaqueRootForGCFunction) | 127 if (!opaqueRootForGCFunction) |
128 return object; | 128 return object; |
129 return opaqueRootForGCFunction(object, isolate); | 129 return opaqueRootForGCFunction(object, isolate); |
130 } | 130 } |
131 | 131 |
132 const GetTemplateFunction getTemplateFunction; | 132 const GetTemplateFunction getTemplateFunction; |
133 const DerefObjectFunction derefObjectFunction; | 133 const DerefObjectFunction derefObjectFunction; |
134 const ToActiveDOMObjectFunction toActiveDOMObjectFunction; | 134 const ToActiveDOMObjectFunction toActiveDOMObjectFunction; |
135 const ToEventTargetFunction toEventTargetFunction; | 135 const ToEventTargetFunction toEventTargetFunction; |
(...skipping 22 matching lines...) Expand all Loading... |
158 inline void* toNative(const v8::Persistent<v8::Object>& object) | 158 inline void* toNative(const v8::Persistent<v8::Object>& object) |
159 { | 159 { |
160 return getInternalField<void, v8DOMWrapperObjectIndex>(object); | 160 return getInternalField<void, v8DOMWrapperObjectIndex>(object); |
161 } | 161 } |
162 | 162 |
163 inline void* toNative(v8::Handle<v8::Object> object) | 163 inline void* toNative(v8::Handle<v8::Object> object) |
164 { | 164 { |
165 return getInternalField<void, v8DOMWrapperObjectIndex>(object); | 165 return getInternalField<void, v8DOMWrapperObjectIndex>(object); |
166 } | 166 } |
167 | 167 |
168 inline WrapperTypeInfo* toWrapperTypeInfo(const v8::Persistent<v8::Object>&
object) | 168 inline const WrapperTypeInfo* toWrapperTypeInfo(const v8::Persistent<v8::Obj
ect>& object) |
169 { | 169 { |
170 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object); | 170 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object); |
171 } | 171 } |
172 | 172 |
173 inline WrapperTypeInfo* toWrapperTypeInfo(v8::Handle<v8::Object> object) | 173 inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Handle<v8::Object> objec
t) |
174 { | 174 { |
175 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object); | 175 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(object); |
176 } | 176 } |
177 | 177 |
178 struct WrapperConfiguration { | 178 struct WrapperConfiguration { |
179 | 179 |
180 enum Lifetime { | 180 enum Lifetime { |
181 Dependent, Independent | 181 Dependent, Independent |
182 }; | 182 }; |
183 | 183 |
(...skipping 20 matching lines...) Expand all Loading... |
204 return configuration; | 204 return configuration; |
205 } | 205 } |
206 | 206 |
207 template<class ElementType> | 207 template<class ElementType> |
208 class WrapperTypeTraits { | 208 class WrapperTypeTraits { |
209 // specialized classes have thier own functions, which are generated by
binding generator. | 209 // specialized classes have thier own functions, which are generated by
binding generator. |
210 }; | 210 }; |
211 } | 211 } |
212 | 212 |
213 #endif // WrapperTypeInfo_h | 213 #endif // WrapperTypeInfo_h |
OLD | NEW |