| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 enum WrapperWorldType { | 53 enum WrapperWorldType { |
| 54 MainWorld, | 54 MainWorld, |
| 55 IsolatedWorld, | 55 IsolatedWorld, |
| 56 WorkerWorld | 56 WorkerWorld |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 typedef v8::Handle<v8::FunctionTemplate> (*GetTemplateFunction)(v8::Isolate*
, WrapperWorldType); | 59 typedef v8::Handle<v8::FunctionTemplate> (*GetTemplateFunction)(v8::Isolate*
, WrapperWorldType); |
| 60 typedef void (*DerefObjectFunction)(void*); | 60 typedef void (*DerefObjectFunction)(void*); |
| 61 typedef ActiveDOMObject* (*ToActiveDOMObjectFunction)(v8::Handle<v8::Object>
); | 61 typedef ActiveDOMObject* (*ToActiveDOMObjectFunction)(v8::Handle<v8::Object>
); |
| 62 typedef EventTarget* (*ToEventTargetFunction)(v8::Handle<v8::Object>); | 62 typedef EventTarget* (*ToEventTargetFunction)(v8::Handle<v8::Object>); |
| 63 typedef void* (*OpaqueRootForGC)(void*, v8::Isolate*); | 63 typedef void (*ResolveWrapperReachabilityFunction)(void*, const v8::Persiste
nt<v8::Object>&, v8::Isolate*); |
| 64 typedef void (*InstallPerContextEnabledPrototypePropertiesFunction)(v8::Hand
le<v8::Object>, v8::Isolate*); | 64 typedef void (*InstallPerContextEnabledPrototypePropertiesFunction)(v8::Hand
le<v8::Object>, v8::Isolate*); |
| 65 | 65 |
| 66 enum WrapperTypePrototype { | 66 enum WrapperTypePrototype { |
| 67 WrapperTypeObjectPrototype, | 67 WrapperTypeObjectPrototype, |
| 68 WrapperTypeErrorPrototype | 68 WrapperTypeErrorPrototype |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 inline void setObjectGroup(void* object, const v8::Persistent<v8::Object>& w
rapper, v8::Isolate* isolate) |
| 72 { |
| 73 // FIXME: remove reinterpret_cast after http://crrev.com/27512003 has ro
lled. |
| 74 isolate->SetObjectGroupId(reinterpret_cast<const v8::Persistent<v8::Valu
e>&>(wrapper), v8::UniqueId(reinterpret_cast<intptr_t>(object))); |
| 75 } |
| 76 |
| 71 // This struct provides a way to store a bunch of information that is helpfu
l when unwrapping | 77 // 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 | 78 // 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. | 79 // comparing pointers is a safe way to determine if types match. |
| 74 struct WrapperTypeInfo { | 80 struct WrapperTypeInfo { |
| 75 | 81 |
| 76 static const WrapperTypeInfo* unwrap(v8::Handle<v8::Value> typeInfoWrapp
er) | 82 static const WrapperTypeInfo* unwrap(v8::Handle<v8::Value> typeInfoWrapp
er) |
| 77 { | 83 { |
| 78 return reinterpret_cast<const WrapperTypeInfo*>(v8::External::Cast(*
typeInfoWrapper)->Value()); | 84 return reinterpret_cast<const WrapperTypeInfo*>(v8::External::Cast(*
typeInfoWrapper)->Value()); |
| 79 } | 85 } |
| 80 | 86 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return toActiveDOMObjectFunction(object); | 121 return toActiveDOMObjectFunction(object); |
| 116 } | 122 } |
| 117 | 123 |
| 118 EventTarget* toEventTarget(v8::Handle<v8::Object> object) const | 124 EventTarget* toEventTarget(v8::Handle<v8::Object> object) const |
| 119 { | 125 { |
| 120 if (!toEventTargetFunction) | 126 if (!toEventTargetFunction) |
| 121 return 0; | 127 return 0; |
| 122 return toEventTargetFunction(object); | 128 return toEventTargetFunction(object); |
| 123 } | 129 } |
| 124 | 130 |
| 125 void* opaqueRootForGC(void* object, v8::Isolate* isolate) const | 131 void resolveWrapperReachability(void* object, const v8::Persistent<v8::O
bject>& wrapper, v8::Isolate* isolate) const |
| 126 { | 132 { |
| 127 if (!opaqueRootForGCFunction) | 133 if (!resolveWrapperReachabilityFunction) |
| 128 return object; | 134 setObjectGroup(object, wrapper, isolate); |
| 129 return opaqueRootForGCFunction(object, isolate); | 135 else |
| 136 resolveWrapperReachabilityFunction(object, wrapper, isolate); |
| 130 } | 137 } |
| 131 | 138 |
| 132 const GetTemplateFunction getTemplateFunction; | 139 const GetTemplateFunction getTemplateFunction; |
| 133 const DerefObjectFunction derefObjectFunction; | 140 const DerefObjectFunction derefObjectFunction; |
| 134 const ToActiveDOMObjectFunction toActiveDOMObjectFunction; | 141 const ToActiveDOMObjectFunction toActiveDOMObjectFunction; |
| 135 const ToEventTargetFunction toEventTargetFunction; | 142 const ToEventTargetFunction toEventTargetFunction; |
| 136 const OpaqueRootForGC opaqueRootForGCFunction; | 143 const ResolveWrapperReachabilityFunction resolveWrapperReachabilityFunct
ion; |
| 137 const InstallPerContextEnabledPrototypePropertiesFunction installPerCont
extEnabledPrototypePropertiesFunction; | 144 const InstallPerContextEnabledPrototypePropertiesFunction installPerCont
extEnabledPrototypePropertiesFunction; |
| 138 const WrapperTypeInfo* parentClass; | 145 const WrapperTypeInfo* parentClass; |
| 139 const WrapperTypePrototype wrapperTypePrototype; | 146 const WrapperTypePrototype wrapperTypePrototype; |
| 140 }; | 147 }; |
| 141 | 148 |
| 142 template<typename T, int offset> | 149 template<typename T, int offset> |
| 143 inline T* getInternalField(const v8::Persistent<v8::Object>& persistent) | 150 inline T* getInternalField(const v8::Persistent<v8::Object>& persistent) |
| 144 { | 151 { |
| 145 // This would be unsafe, but InternalFieldCount and GetAlignedPointerFro
mInternalField are guaranteed not to allocate | 152 // This would be unsafe, but InternalFieldCount and GetAlignedPointerFro
mInternalField are guaranteed not to allocate |
| 146 const v8::Handle<v8::Object>& object = reinterpret_cast<const v8::Handle
<v8::Object>&>(persistent); | 153 const v8::Handle<v8::Object>& object = reinterpret_cast<const v8::Handle
<v8::Object>&>(persistent); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return configuration; | 211 return configuration; |
| 205 } | 212 } |
| 206 | 213 |
| 207 template<class ElementType> | 214 template<class ElementType> |
| 208 class WrapperTypeTraits { | 215 class WrapperTypeTraits { |
| 209 // specialized classes have thier own functions, which are generated by
binding generator. | 216 // specialized classes have thier own functions, which are generated by
binding generator. |
| 210 }; | 217 }; |
| 211 } | 218 } |
| 212 | 219 |
| 213 #endif // WrapperTypeInfo_h | 220 #endif // WrapperTypeInfo_h |
| OLD | NEW |