| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 21 matching lines...) Expand all Loading... |
| 32 #define V8DOMWrapper_h | 32 #define V8DOMWrapper_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/DOMDataStore.h" | 34 #include "bindings/core/v8/DOMDataStore.h" |
| 35 #include "wtf/PassRefPtr.h" | 35 #include "wtf/PassRefPtr.h" |
| 36 #include "wtf/RawPtr.h" | 36 #include "wtf/RawPtr.h" |
| 37 #include "wtf/text/AtomicString.h" | 37 #include "wtf/text/AtomicString.h" |
| 38 #include <v8.h> | 38 #include <v8.h> |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class ScriptWrappableBase; |
| 42 struct WrapperTypeInfo; | 43 struct WrapperTypeInfo; |
| 43 | 44 |
| 44 class V8DOMWrapper { | 45 class V8DOMWrapper { |
| 45 public: | 46 public: |
| 46 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creationCo
ntext, const WrapperTypeInfo*, void*, v8::Isolate*); | 47 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creationCo
ntext, const WrapperTypeInfo*, ScriptWrappableBase* internalPointer, v8::Isolate
*); |
| 47 | 48 |
| 48 template<typename V8T, typename T> | 49 template<typename V8T, typename T> |
| 49 static inline v8::Handle<v8::Object> associateObjectWithWrapper(PassRefPtr<T
>, const WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfigur
ation::Lifetime); | 50 static inline v8::Handle<v8::Object> associateObjectWithWrapper(PassRefPtr<T
>, const WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfigur
ation::Lifetime); |
| 50 template<typename V8T, typename T> | 51 template<typename V8T, typename T> |
| 51 static inline v8::Handle<v8::Object> associateObjectWithWrapper(RawPtr<T> ob
ject, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8
::Isolate* isolate, WrapperConfiguration::Lifetime lifetime) | 52 static inline v8::Handle<v8::Object> associateObjectWithWrapper(RawPtr<T> ob
ject, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8
::Isolate* isolate, WrapperConfiguration::Lifetime lifetime) |
| 52 { | 53 { |
| 53 return associateObjectWithWrapper<V8T, T>(object.get(), wrapperTypeInfo,
wrapper, isolate, lifetime); | 54 return associateObjectWithWrapper<V8T, T>(object.get(), wrapperTypeInfo,
wrapper, isolate, lifetime); |
| 54 } | 55 } |
| 55 template<typename V8T, typename T> | 56 template<typename V8T, typename T> |
| 56 static inline v8::Handle<v8::Object> associateObjectWithWrapper(T*, const Wr
apperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfiguration::Life
time); | 57 static inline v8::Handle<v8::Object> associateObjectWithWrapper(T*, const Wr
apperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfiguration::Life
time); |
| 57 static inline void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeIn
fo*, void*); | 58 static inline void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeIn
fo*, ScriptWrappableBase* internalPointer); |
| 58 static inline void setNativeInfoForHiddenWrapper(v8::Handle<v8::Object>, con
st WrapperTypeInfo*, void*); | 59 static inline void setNativeInfoForHiddenWrapper(v8::Handle<v8::Object>, con
st WrapperTypeInfo*, ScriptWrappableBase* internalPointer); |
| 59 static inline void setNativeInfoWithPersistentHandle(v8::Handle<v8::Object>,
const WrapperTypeInfo*, void*, PersistentNode*); | 60 static inline void setNativeInfoWithPersistentHandle(v8::Handle<v8::Object>,
const WrapperTypeInfo*, ScriptWrappableBase* internalPointer, PersistentNode*); |
| 60 static inline void clearNativeInfo(v8::Handle<v8::Object>, const WrapperType
Info*); | 61 static inline void clearNativeInfo(v8::Handle<v8::Object>, const WrapperType
Info*); |
| 61 | 62 |
| 62 static bool isDOMWrapper(v8::Handle<v8::Value>); | 63 static bool isDOMWrapper(v8::Handle<v8::Value>); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr
apperTypeInfo* wrapperTypeInfo, void* object) | 66 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr
apperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* internalPointer) |
| 66 { | 67 { |
| 67 ASSERT(wrapper->InternalFieldCount() >= 2); | 68 ASSERT(wrapper->InternalFieldCount() >= 2); |
| 68 ASSERT(object); | 69 ASSERT(internalPointer); |
| 69 ASSERT(wrapperTypeInfo); | 70 ASSERT(wrapperTypeInfo); |
| 70 #if ENABLE(OILPAN) | 71 #if ENABLE(OILPAN) |
| 71 ASSERT(wrapperTypeInfo->gcType == RefCountedObject); | 72 ASSERT(wrapperTypeInfo->gcType == RefCountedObject); |
| 72 #else | 73 #else |
| 73 ASSERT(wrapperTypeInfo->gcType == RefCountedObject || wrapperTypeInfo->gcTyp
e == WillBeGarbageCollectedObject); | 74 ASSERT(wrapperTypeInfo->gcType == RefCountedObject || wrapperTypeInfo->gcTyp
e == WillBeGarbageCollectedObject); |
| 74 #endif | 75 #endif |
| 75 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, object); | 76 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP
ointer); |
| 76 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 77 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 inline void V8DOMWrapper::setNativeInfoForHiddenWrapper(v8::Handle<v8::Object> w
rapper, const WrapperTypeInfo* wrapperTypeInfo, void* object) | 80 inline void V8DOMWrapper::setNativeInfoForHiddenWrapper(v8::Handle<v8::Object> w
rapper, const WrapperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* internalPoi
nter) |
| 80 { | 81 { |
| 81 // see V8WindowShell::installDOMWindow() comment for why this version is nee
ded and safe. | 82 // see V8WindowShell::installDOMWindow() comment for why this version is nee
ded and safe. |
| 82 ASSERT(wrapper->InternalFieldCount() >= 2); | 83 ASSERT(wrapper->InternalFieldCount() >= 2); |
| 83 ASSERT(object); | 84 ASSERT(internalPointer); |
| 84 ASSERT(wrapperTypeInfo); | 85 ASSERT(wrapperTypeInfo); |
| 85 #if ENABLE(OILPAN) | 86 #if ENABLE(OILPAN) |
| 86 ASSERT(wrapperTypeInfo->gcType != RefCountedObject); | 87 ASSERT(wrapperTypeInfo->gcType != RefCountedObject); |
| 87 #else | 88 #else |
| 88 ASSERT(wrapperTypeInfo->gcType == RefCountedObject || wrapperTypeInfo->gcTyp
e == WillBeGarbageCollectedObject); | 89 ASSERT(wrapperTypeInfo->gcType == RefCountedObject || wrapperTypeInfo->gcTyp
e == WillBeGarbageCollectedObject); |
| 89 #endif | 90 #endif |
| 90 | 91 |
| 91 // Clear out the last internal field, which is assumed to contain a valid pe
rsistent pointer value. | 92 // Clear out the last internal field, which is assumed to contain a valid pe
rsistent pointer value. |
| 92 if (wrapperTypeInfo->gcType == GarbageCollectedObject) { | 93 if (wrapperTypeInfo->gcType == GarbageCollectedObject) { |
| 93 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount()
- 1, 0); | 94 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount()
- 1, 0); |
| 94 } else if (wrapperTypeInfo->gcType == WillBeGarbageCollectedObject) { | 95 } else if (wrapperTypeInfo->gcType == WillBeGarbageCollectedObject) { |
| 95 #if ENABLE(OILPAN) | 96 #if ENABLE(OILPAN) |
| 96 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount()
- 1, 0); | 97 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount()
- 1, 0); |
| 97 #endif | 98 #endif |
| 98 } | 99 } |
| 99 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, object); | 100 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP
ointer); |
| 100 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 101 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 101 } | 102 } |
| 102 | 103 |
| 103 inline void V8DOMWrapper::setNativeInfoWithPersistentHandle(v8::Handle<v8::Objec
t> wrapper, const WrapperTypeInfo* wrapperTypeInfo, void* object, PersistentNode
* handle) | 104 inline void V8DOMWrapper::setNativeInfoWithPersistentHandle(v8::Handle<v8::Objec
t> wrapper, const WrapperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* interna
lPointer, PersistentNode* handle) |
| 104 { | 105 { |
| 105 ASSERT(wrapper->InternalFieldCount() >= 3); | 106 ASSERT(wrapper->InternalFieldCount() >= 3); |
| 106 ASSERT(object); | 107 ASSERT(internalPointer); |
| 107 ASSERT(wrapperTypeInfo); | 108 ASSERT(wrapperTypeInfo); |
| 108 ASSERT(wrapperTypeInfo->gcType != RefCountedObject); | 109 ASSERT(wrapperTypeInfo->gcType != RefCountedObject); |
| 109 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, object); | 110 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP
ointer); |
| 110 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 111 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 111 // Persistent handle is stored in the last internal field. | 112 // Persistent handle is stored in the last internal field. |
| 112 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount() - 1,
handle); | 113 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount() - 1,
handle); |
| 113 } | 114 } |
| 114 | 115 |
| 115 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const
WrapperTypeInfo* wrapperTypeInfo) | 116 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const
WrapperTypeInfo* wrapperTypeInfo) |
| 116 { | 117 { |
| 117 ASSERT(wrapper->InternalFieldCount() >= 2); | 118 ASSERT(wrapper->InternalFieldCount() >= 2); |
| 118 ASSERT(wrapperTypeInfo); | 119 ASSERT(wrapperTypeInfo); |
| 119 // clearNativeInfo() is used only by NP objects, which are not garbage colle
cted. | 120 // clearNativeInfo() is used only by NP objects, which are not garbage colle
cted. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 v8::Handle<v8::Context> context() const { return m_context; } | 173 v8::Handle<v8::Context> context() const { return m_context; } |
| 173 | 174 |
| 174 private: | 175 private: |
| 175 bool m_didEnterContext; | 176 bool m_didEnterContext; |
| 176 v8::Handle<v8::Context> m_context; | 177 v8::Handle<v8::Context> m_context; |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 } // namespace blink | 180 } // namespace blink |
| 180 | 181 |
| 181 #endif // V8DOMWrapper_h | 182 #endif // V8DOMWrapper_h |
| OLD | NEW |