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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WrapperTypeInfo.h

Issue 1873323002: Have bindings layer assume and insist that all interface types are GCed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 ScriptWrappable* toScriptWrappable(const v8::PersistentBase<v8::Object>& wrapper ); 46 ScriptWrappable* toScriptWrappable(const v8::PersistentBase<v8::Object>& wrapper );
47 47
48 static const int v8DOMWrapperTypeIndex = static_cast<int>(gin::kWrapperInfoIndex ); 48 static const int v8DOMWrapperTypeIndex = static_cast<int>(gin::kWrapperInfoIndex );
49 static const int v8DOMWrapperObjectIndex = static_cast<int>(gin::kEncodedValueIn dex); 49 static const int v8DOMWrapperObjectIndex = static_cast<int>(gin::kEncodedValueIn dex);
50 static const int v8DefaultWrapperInternalFieldCount = static_cast<int>(gin::kNum berOfInternalFields); 50 static const int v8DefaultWrapperInternalFieldCount = static_cast<int>(gin::kNum berOfInternalFields);
51 static const int v8PrototypeTypeIndex = 0; 51 static const int v8PrototypeTypeIndex = 0;
52 static const int v8PrototypeInternalFieldcount = 1; 52 static const int v8PrototypeInternalFieldcount = 1;
53 53
54 typedef v8::Local<v8::FunctionTemplate> (*DomTemplateFunction)(v8::Isolate*); 54 typedef v8::Local<v8::FunctionTemplate> (*DomTemplateFunction)(v8::Isolate*);
55 typedef void (*RefObjectFunction)(ScriptWrappable*);
56 typedef void (*DerefObjectFunction)(ScriptWrappable*);
57 typedef void (*TraceFunction)(Visitor*, ScriptWrappable*); 55 typedef void (*TraceFunction)(Visitor*, ScriptWrappable*);
58 typedef ActiveScriptWrappable* (*ToActiveScriptWrappableFunction)(v8::Local<v8:: Object>); 56 typedef ActiveScriptWrappable* (*ToActiveScriptWrappableFunction)(v8::Local<v8:: Object>);
59 typedef void (*ResolveWrapperReachabilityFunction)(v8::Isolate*, ScriptWrappable *, const v8::Persistent<v8::Object>&); 57 typedef void (*ResolveWrapperReachabilityFunction)(v8::Isolate*, ScriptWrappable *, const v8::Persistent<v8::Object>&);
60 typedef void (*PreparePrototypeAndInterfaceObjectFunction)(v8::Local<v8::Context >, v8::Local<v8::Object>, v8::Local<v8::Function>, v8::Local<v8::FunctionTemplat e>); 58 typedef void (*PreparePrototypeAndInterfaceObjectFunction)(v8::Local<v8::Context >, v8::Local<v8::Object>, v8::Local<v8::Function>, v8::Local<v8::FunctionTemplat e>);
61 typedef void (*InstallConditionallyEnabledPropertiesFunction)(v8::Local<v8::Obje ct>, v8::Isolate*); 59 typedef void (*InstallConditionallyEnabledPropertiesFunction)(v8::Local<v8::Obje ct>, v8::Isolate*);
62 60
63 inline void setObjectGroup(v8::Isolate* isolate, ScriptWrappable* scriptWrappabl e, const v8::Persistent<v8::Object>& wrapper) 61 inline void setObjectGroup(v8::Isolate* isolate, ScriptWrappable* scriptWrappabl e, const v8::Persistent<v8::Object>& wrapper)
64 { 62 {
65 isolate->SetObjectGroupId(wrapper, v8::UniqueId(reinterpret_cast<intptr_t>(s criptWrappable))); 63 isolate->SetObjectGroupId(wrapper, v8::UniqueId(reinterpret_cast<intptr_t>(s criptWrappable)));
66 } 64 }
(...skipping 16 matching lines...) Expand all
83 enum EventTargetInheritance { 81 enum EventTargetInheritance {
84 NotInheritFromEventTarget, 82 NotInheritFromEventTarget,
85 InheritFromEventTarget, 83 InheritFromEventTarget,
86 }; 84 };
87 85
88 enum Lifetime { 86 enum Lifetime {
89 Dependent, 87 Dependent,
90 Independent, 88 Independent,
91 }; 89 };
92 90
93 enum GCType {
94 GarbageCollectedObject,
95 // TODO(haraken): Remove RefCountedObject. All DOM objects that inherit
96 // from ScriptWrappable must be moved to Oilpan's heap.
97 RefCountedObject,
98 };
99
100 static const WrapperTypeInfo* unwrap(v8::Local<v8::Value> typeInfoWrapper) 91 static const WrapperTypeInfo* unwrap(v8::Local<v8::Value> typeInfoWrapper)
101 { 92 {
102 return reinterpret_cast<const WrapperTypeInfo*>(v8::External::Cast(*type InfoWrapper)->Value()); 93 return reinterpret_cast<const WrapperTypeInfo*>(v8::External::Cast(*type InfoWrapper)->Value());
103 } 94 }
104 95
105 bool equals(const WrapperTypeInfo* that) const 96 bool equals(const WrapperTypeInfo* that) const
106 { 97 {
107 return this == that; 98 return this == that;
108 } 99 }
109 100
(...skipping 12 matching lines...) Expand all
122 wrapper->SetWrapperClassId(wrapperClassId); 113 wrapper->SetWrapperClassId(wrapperClassId);
123 if (lifetime == Independent) 114 if (lifetime == Independent)
124 wrapper->MarkIndependent(); 115 wrapper->MarkIndependent();
125 } 116 }
126 117
127 v8::Local<v8::FunctionTemplate> domTemplate(v8::Isolate* isolate) const 118 v8::Local<v8::FunctionTemplate> domTemplate(v8::Isolate* isolate) const
128 { 119 {
129 return domTemplateFunction(isolate); 120 return domTemplateFunction(isolate);
130 } 121 }
131 122
132 bool isGarbageCollected() const 123 void wrapperCreated() const
133 { 124 {
134 return gcType == GarbageCollectedObject; 125 Heap::heapStats().increaseWrapperCount(1);
135 } 126 }
136 127
137 void refObject(ScriptWrappable* scriptWrappable) const 128 void wrapperDestroyed() const
138 { 129 {
139 if (isGarbageCollected()) {
140 Heap::heapStats().increaseWrapperCount(1);
141 } else {
142 ASSERT(refObjectFunction);
143 refObjectFunction(scriptWrappable);
144 }
145 }
146
147 void derefObject(ScriptWrappable* scriptWrappable) const
148 {
149 if (isGarbageCollected()) {
150 ThreadHeapStats& heapStats = Heap::heapStats();
151 heapStats.decreaseWrapperCount(1);
152 heapStats.increaseCollectedWrapperCount(1);
153 } else {
154 ASSERT(derefObjectFunction);
155 derefObjectFunction(scriptWrappable);
156 }
157 }
158
159 void derefObject() const
160 {
161 ASSERT(isGarbageCollected());
162 ThreadHeapStats& heapStats = Heap::heapStats(); 130 ThreadHeapStats& heapStats = Heap::heapStats();
163 heapStats.decreaseWrapperCount(1); 131 heapStats.decreaseWrapperCount(1);
164 heapStats.increaseCollectedWrapperCount(1); 132 heapStats.increaseCollectedWrapperCount(1);
165 } 133 }
166 134
167 void trace(Visitor* visitor, ScriptWrappable* scriptWrappable) const 135 void trace(Visitor* visitor, ScriptWrappable* scriptWrappable) const
168 { 136 {
169 ASSERT(traceFunction); 137 ASSERT(traceFunction);
170 return traceFunction(visitor, scriptWrappable); 138 return traceFunction(visitor, scriptWrappable);
171 } 139 }
(...skipping 29 matching lines...) Expand all
201 if (!visitDOMWrapperFunction) 169 if (!visitDOMWrapperFunction)
202 setObjectGroup(isolate, scriptWrappable, wrapper); 170 setObjectGroup(isolate, scriptWrappable, wrapper);
203 else 171 else
204 visitDOMWrapperFunction(isolate, scriptWrappable, wrapper); 172 visitDOMWrapperFunction(isolate, scriptWrappable, wrapper);
205 } 173 }
206 174
207 // This field must be the first member of the struct WrapperTypeInfo. This i s also checked by a static_assert() below. 175 // This field must be the first member of the struct WrapperTypeInfo. This i s also checked by a static_assert() below.
208 const gin::GinEmbedder ginEmbedder; 176 const gin::GinEmbedder ginEmbedder;
209 177
210 DomTemplateFunction domTemplateFunction; 178 DomTemplateFunction domTemplateFunction;
211 const RefObjectFunction refObjectFunction;
212 const DerefObjectFunction derefObjectFunction;
213 const TraceFunction traceFunction; 179 const TraceFunction traceFunction;
214 const ToActiveScriptWrappableFunction toActiveScriptWrappableFunction; 180 const ToActiveScriptWrappableFunction toActiveScriptWrappableFunction;
215 const ResolveWrapperReachabilityFunction visitDOMWrapperFunction; 181 const ResolveWrapperReachabilityFunction visitDOMWrapperFunction;
216 PreparePrototypeAndInterfaceObjectFunction preparePrototypeAndInterfaceObjec tFunction; 182 PreparePrototypeAndInterfaceObjectFunction preparePrototypeAndInterfaceObjec tFunction;
217 const InstallConditionallyEnabledPropertiesFunction installConditionallyEnab ledPropertiesFunction; 183 const InstallConditionallyEnabledPropertiesFunction installConditionallyEnab ledPropertiesFunction;
218 const char* const interfaceName; 184 const char* const interfaceName;
219 const WrapperTypeInfo* parentClass; 185 const WrapperTypeInfo* parentClass;
220 const unsigned wrapperTypePrototype : 1; // WrapperTypePrototype 186 const unsigned wrapperTypePrototype : 1; // WrapperTypePrototype
221 const unsigned wrapperClassId : 2; // WrapperClassId 187 const unsigned wrapperClassId : 2; // WrapperClassId
222 const unsigned eventTargetInheritance : 1; // EventTargetInheritance 188 const unsigned eventTargetInheritance : 1; // EventTargetInheritance
223 const unsigned lifetime : 1; // Lifetime 189 const unsigned lifetime : 1; // Lifetime
224 const unsigned gcType : 2; // GCType
225 }; 190 };
226 191
227 template<typename T, int offset> 192 template<typename T, int offset>
228 inline T* getInternalField(const v8::PersistentBase<v8::Object>& persistent) 193 inline T* getInternalField(const v8::PersistentBase<v8::Object>& persistent)
229 { 194 {
230 ASSERT(offset < v8::Object::InternalFieldCount(persistent)); 195 ASSERT(offset < v8::Object::InternalFieldCount(persistent));
231 return reinterpret_cast<T*>(v8::Object::GetAlignedPointerFromInternalField(p ersistent, offset)); 196 return reinterpret_cast<T*>(v8::Object::GetAlignedPointerFromInternalField(p ersistent, offset));
232 } 197 }
233 198
234 template<typename T, int offset> 199 template<typename T, int offset>
(...skipping 19 matching lines...) Expand all
254 } 219 }
255 220
256 inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Local<v8::Object> wrapper) 221 inline const WrapperTypeInfo* toWrapperTypeInfo(v8::Local<v8::Object> wrapper)
257 { 222 {
258 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper); 223 return getInternalField<WrapperTypeInfo, v8DOMWrapperTypeIndex>(wrapper);
259 } 224 }
260 225
261 } // namespace blink 226 } // namespace blink
262 227
263 #endif // WrapperTypeInfo_h 228 #endif // WrapperTypeInfo_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698