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

Side by Side Diff: Source/bindings/core/v8/V8DOMWrapper.h

Issue 651713002: Oilpan: DOM wrappers don't need to keep persistent handles (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/ScriptProfiler.cpp ('k') | Source/bindings/core/v8/V8DOMWrapper.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 template<typename V8T, typename T> 52 template<typename V8T, typename T>
53 static v8::Handle<v8::Object> associateObjectWithWrapper(RawPtr<T> object, c onst WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isola te* isolate) 53 static v8::Handle<v8::Object> associateObjectWithWrapper(RawPtr<T> object, c onst WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isola te* isolate)
54 { 54 {
55 return associateObjectWithWrapper<V8T, T>(object.get(), wrapperTypeInfo, wrapper, isolate); 55 return associateObjectWithWrapper<V8T, T>(object.get(), wrapperTypeInfo, wrapper, isolate);
56 } 56 }
57 template<typename V8T, typename T> 57 template<typename V8T, typename T>
58 static v8::Handle<v8::Object> associateObjectWithWrapper(T*, const WrapperTy peInfo*, v8::Handle<v8::Object>, v8::Isolate*); 58 static v8::Handle<v8::Object> associateObjectWithWrapper(T*, const WrapperTy peInfo*, v8::Handle<v8::Object>, v8::Isolate*);
59 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(ScriptWr appable*, const WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*); 59 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(ScriptWr appable*, const WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*);
60 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(Node*, c onst WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*); 60 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(Node*, c onst WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*);
61 static void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*, Sc riptWrappableBase* internalPointer); 61 static void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*, Sc riptWrappableBase* internalPointer);
62 static void setNativeInfoForHiddenWrapper(v8::Handle<v8::Object>, const Wrap perTypeInfo*, ScriptWrappableBase* internalPointer);
63 static void setNativeInfoWithPersistentHandle(v8::Handle<v8::Object>, const WrapperTypeInfo*, ScriptWrappableBase* internalPointer, WrapperPersistentNode*);
64 static void clearNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*); 62 static void clearNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*);
65 63
66 static bool isDOMWrapper(v8::Handle<v8::Value>); 64 static bool isDOMWrapper(v8::Handle<v8::Value>);
67 }; 65 };
68 66
69 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr apperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* internalPointer) 67 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr apperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* internalPointer)
70 { 68 {
71 ASSERT(wrapper->InternalFieldCount() >= 2); 69 ASSERT(wrapper->InternalFieldCount() >= 2);
72 ASSERT(internalPointer); 70 ASSERT(internalPointer);
73 ASSERT(wrapperTypeInfo); 71 ASSERT(wrapperTypeInfo);
74 #if ENABLE(OILPAN)
75 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject);
76 #else
77 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject || wrapp erTypeInfo->gcType == WrapperTypeInfo::WillBeGarbageCollectedObject);
78 #endif
79 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP ointer); 72 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP ointer);
80 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo)); 73 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo));
81 } 74 }
82 75
83 inline void V8DOMWrapper::setNativeInfoForHiddenWrapper(v8::Handle<v8::Object> w rapper, const WrapperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* internalPoi nter)
84 {
85 // see WindowProxy::installDOMWindow() comment for why this version is neede d and safe.
86 ASSERT(wrapper->InternalFieldCount() >= 2);
87 ASSERT(internalPointer);
88 ASSERT(wrapperTypeInfo);
89 #if ENABLE(OILPAN)
90 ASSERT(wrapperTypeInfo->gcType != WrapperTypeInfo::RefCountedObject);
91 #else
92 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject || wrapp erTypeInfo->gcType == WrapperTypeInfo::WillBeGarbageCollectedObject);
93 #endif
94
95 // Clear out the last internal field, which is assumed to contain a valid pe rsistent pointer value.
96 if (wrapperTypeInfo->gcType == WrapperTypeInfo::GarbageCollectedObject) {
97 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount() - 1, 0);
98 } else if (wrapperTypeInfo->gcType == WrapperTypeInfo::WillBeGarbageCollecte dObject) {
99 #if ENABLE(OILPAN)
100 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount() - 1, 0);
101 #endif
102 }
103 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP ointer);
104 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo));
105 }
106
107 inline void V8DOMWrapper::setNativeInfoWithPersistentHandle(v8::Handle<v8::Objec t> wrapper, const WrapperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* interna lPointer, WrapperPersistentNode* handle)
108 {
109 ASSERT(wrapper->InternalFieldCount() >= 3);
110 ASSERT(internalPointer);
111 ASSERT(wrapperTypeInfo);
112 #if ENABLE(OILPAN)
113 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::WillBeGarbageCollectedObj ect || wrapperTypeInfo->gcType == WrapperTypeInfo::GarbageCollectedObject);
114 #else
115 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::GarbageCollectedObject);
116 #endif
117 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, internalP ointer);
118 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo));
119 // Persistent handle is stored in the last internal field.
120 wrapper->SetAlignedPointerInInternalField(wrapper->InternalFieldCount() - 1, handle);
121 }
122
123 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const WrapperTypeInfo* wrapperTypeInfo) 76 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const WrapperTypeInfo* wrapperTypeInfo)
124 { 77 {
125 ASSERT(wrapper->InternalFieldCount() >= 2); 78 ASSERT(wrapper->InternalFieldCount() >= 2);
126 ASSERT(wrapperTypeInfo); 79 ASSERT(wrapperTypeInfo);
127 // clearNativeInfo() is used only by NP objects, which are not garbage colle cted. 80 // clearNativeInfo() is used only by NP objects, which are not garbage colle cted.
128 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject); 81 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject);
129 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo)); 82 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast< WrapperTypeInfo*>(wrapperTypeInfo));
130 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); 83 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0);
131 } 84 }
132 85
133 template<typename V8T, typename T> 86 template<typename V8T, typename T>
134 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassRefPt r<T> object, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrap per, v8::Isolate* isolate) 87 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassRefPt r<T> object, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrap per, v8::Isolate* isolate)
135 { 88 {
136 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object.ge t())); 89 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object.ge t()));
137 ASSERT(isDOMWrapper(wrapper)); 90 ASSERT(isDOMWrapper(wrapper));
138 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, wrapperTyp eInfo); 91 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, wrapperTyp eInfo);
139 return wrapper; 92 return wrapper;
140 } 93 }
141 94
142 template<typename V8T, typename T> 95 template<typename V8T, typename T>
143 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(T* object , const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Is olate* isolate) 96 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(T* object , const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Is olate* isolate)
144 { 97 {
145 setNativeInfoWithPersistentHandle(wrapper, wrapperTypeInfo, V8T::toScriptWra ppableBase(object), WrapperPersistent<T>::create(object)); 98 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object));
146 ASSERT(isDOMWrapper(wrapper)); 99 ASSERT(isDOMWrapper(wrapper));
147 DOMDataStore::setWrapper<V8T>(object, wrapper, isolate, wrapperTypeInfo); 100 DOMDataStore::setWrapper<V8T>(object, wrapper, isolate, wrapperTypeInfo);
148 return wrapper; 101 return wrapper;
149 } 102 }
150 103
151 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat e(ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8:: Object> wrapper, v8::Isolate* isolate) 104 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat e(ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8:: Object> wrapper, v8::Isolate* isolate)
152 { 105 {
153 wrapperTypeInfo->refObject(impl->toScriptWrappableBase()); 106 wrapperTypeInfo->refObject(impl->toScriptWrappableBase());
154 #if ENABLE(OILPAN) 107 setNativeInfo(wrapper, wrapperTypeInfo, impl->toScriptWrappableBase());
155 if (wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject)
156 setNativeInfo(wrapper, wrapperTypeInfo, impl->toScriptWrappableBase());
157 else
158 setNativeInfoWithPersistentHandle(wrapper, wrapperTypeInfo, impl->toScri ptWrappableBase(), wrapperTypeInfo->createPersistentHandle(impl));
159 #else
160 if (wrapperTypeInfo->gcType != WrapperTypeInfo::GarbageCollectedObject)
161 setNativeInfo(wrapper, wrapperTypeInfo, impl->toScriptWrappableBase());
162 else
163 setNativeInfoWithPersistentHandle(wrapper, wrapperTypeInfo, impl->toScri ptWrappableBase(), wrapperTypeInfo->createPersistentHandle(impl));
164 #endif
165 ASSERT(isDOMWrapper(wrapper)); 108 ASSERT(isDOMWrapper(wrapper));
166 DOMDataStore::setWrapperNonTemplate(impl, wrapper, isolate, wrapperTypeInfo) ; 109 DOMDataStore::setWrapperNonTemplate(impl, wrapper, isolate, wrapperTypeInfo) ;
167 return wrapper; 110 return wrapper;
168 } 111 }
169 112
170 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat e(Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wra pper, v8::Isolate* isolate) 113 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat e(Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wra pper, v8::Isolate* isolate)
171 { 114 {
172 wrapperTypeInfo->refObject(ScriptWrappable::fromObject(node)->toScriptWrappa bleBase()); 115 wrapperTypeInfo->refObject(ScriptWrappable::fromObject(node)->toScriptWrappa bleBase());
173 #if ENABLE(OILPAN) 116 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromObject(node)->t oScriptWrappableBase());
174 if (wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject)
175 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromObject(node )->toScriptWrappableBase());
176 else
177 setNativeInfoWithPersistentHandle(wrapper, wrapperTypeInfo, ScriptWrappa ble::fromObject(node)->toScriptWrappableBase(), wrapperTypeInfo->createPersisten tHandle(ScriptWrappable::fromObject(node)));
178 #else
179 if (wrapperTypeInfo->gcType != WrapperTypeInfo::GarbageCollectedObject)
180 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromObject(node )->toScriptWrappableBase());
181 else
182 setNativeInfoWithPersistentHandle(wrapper, wrapperTypeInfo, ScriptWrappa ble::fromObject(node)->toScriptWrappableBase(), wrapperTypeInfo->createPersisten tHandle(ScriptWrappable::fromObject(node)));
183 #endif
184 ASSERT(isDOMWrapper(wrapper)); 117 ASSERT(isDOMWrapper(wrapper));
185 DOMDataStore::setWrapperNonTemplate(node, wrapper, isolate, wrapperTypeInfo) ; 118 DOMDataStore::setWrapperNonTemplate(node, wrapper, isolate, wrapperTypeInfo) ;
186 return wrapper; 119 return wrapper;
187 } 120 }
188 121
189 class V8WrapperInstantiationScope { 122 class V8WrapperInstantiationScope {
190 public: 123 public:
191 V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext, v8::Isol ate* isolate) 124 V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext, v8::Isol ate* isolate)
192 : m_didEnterContext(false) 125 : m_didEnterContext(false)
193 , m_context(isolate->GetCurrentContext()) 126 , m_context(isolate->GetCurrentContext())
(...skipping 22 matching lines...) Expand all
216 v8::Handle<v8::Context> context() const { return m_context; } 149 v8::Handle<v8::Context> context() const { return m_context; }
217 150
218 private: 151 private:
219 bool m_didEnterContext; 152 bool m_didEnterContext;
220 v8::Handle<v8::Context> m_context; 153 v8::Handle<v8::Context> m_context;
221 }; 154 };
222 155
223 } // namespace blink 156 } // namespace blink
224 157
225 #endif // V8DOMWrapper_h 158 #endif // V8DOMWrapper_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptProfiler.cpp ('k') | Source/bindings/core/v8/V8DOMWrapper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698