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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 2873543002: First implementation of lazily cached accessor for DOM attributes. (Closed)
Patch Set: whitespace and renaming fixes Created 3 years, 7 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (attribute.property_location_configuration & 150 if (attribute.property_location_configuration &
151 V8DOMConfiguration::kOnInterface) 151 V8DOMConfiguration::kOnInterface)
152 NOTREACHED(); 152 NOTREACHED();
153 } 153 }
154 154
155 template <class FunctionOrTemplate> 155 template <class FunctionOrTemplate>
156 v8::Local<FunctionOrTemplate> CreateAccessorFunctionOrTemplate( 156 v8::Local<FunctionOrTemplate> CreateAccessorFunctionOrTemplate(
157 v8::Isolate*, 157 v8::Isolate*,
158 v8::FunctionCallback, 158 v8::FunctionCallback,
159 V8DOMConfiguration::CachedPropertyKey, 159 V8DOMConfiguration::CachedPropertyKey,
160 V8DOMConfiguration::CachedAccessorInitCallback,
160 v8::Local<v8::Value> data, 161 v8::Local<v8::Value> data,
161 v8::Local<v8::Signature>, 162 v8::Local<v8::Signature>,
162 int length); 163 int length);
163 164
164 template <> 165 template <>
165 v8::Local<v8::FunctionTemplate> 166 v8::Local<v8::FunctionTemplate>
166 CreateAccessorFunctionOrTemplate<v8::FunctionTemplate>( 167 CreateAccessorFunctionOrTemplate<v8::FunctionTemplate>(
167 v8::Isolate* isolate, 168 v8::Isolate* isolate,
168 v8::FunctionCallback callback, 169 v8::FunctionCallback callback,
169 V8DOMConfiguration::CachedPropertyKey cached_property_key, 170 V8DOMConfiguration::CachedPropertyKey cached_property_key,
171 V8DOMConfiguration::CachedAccessorInitCallback
172 cached_accessor_init_callback,
170 v8::Local<v8::Value> data, 173 v8::Local<v8::Value> data,
171 v8::Local<v8::Signature> signature, 174 v8::Local<v8::Signature> signature,
172 int length) { 175 int length) {
173 v8::Local<v8::FunctionTemplate> function_template; 176 v8::Local<v8::FunctionTemplate> function_template;
174 if (callback) { 177 if (callback) {
175 if (cached_property_key) { 178 if (cached_property_key) {
176 function_template = v8::FunctionTemplate::NewWithCache( 179 if (cached_accessor_init_callback) {
177 isolate, callback, cached_property_key(isolate), data, signature, 180 function_template = v8::FunctionTemplate::NewWithLazyCache(
178 length); 181 isolate, callback, cached_property_key(isolate),
182 cached_accessor_init_callback, data, signature, length);
183 } else {
184 function_template = v8::FunctionTemplate::NewWithCache(
185 isolate, callback, cached_property_key(isolate), data, signature,
186 length);
187 }
179 } else { 188 } else {
180 function_template = 189 function_template =
181 v8::FunctionTemplate::New(isolate, callback, data, signature, length); 190 v8::FunctionTemplate::New(isolate, callback, data, signature, length);
182 } 191 }
183 192
184 if (!function_template.IsEmpty()) { 193 if (!function_template.IsEmpty()) {
185 function_template->RemovePrototype(); 194 function_template->RemovePrototype();
186 function_template->SetAcceptAnyReceiver(false); 195 function_template->SetAcceptAnyReceiver(false);
187 } 196 }
188 } 197 }
189 return function_template; 198 return function_template;
190 } 199 }
191 200
192 template <> 201 template <>
193 v8::Local<v8::Function> CreateAccessorFunctionOrTemplate<v8::Function>( 202 v8::Local<v8::Function> CreateAccessorFunctionOrTemplate<v8::Function>(
194 v8::Isolate* isolate, 203 v8::Isolate* isolate,
195 v8::FunctionCallback callback, 204 v8::FunctionCallback callback,
196 V8DOMConfiguration::CachedPropertyKey, 205 V8DOMConfiguration::CachedPropertyKey,
206 V8DOMConfiguration::CachedAccessorInitCallback,
197 v8::Local<v8::Value> data, 207 v8::Local<v8::Value> data,
198 v8::Local<v8::Signature> signature, 208 v8::Local<v8::Signature> signature,
199 int length) { 209 int length) {
200 if (!callback) 210 if (!callback)
201 return v8::Local<v8::Function>(); 211 return v8::Local<v8::Function>();
202 212
203 v8::Local<v8::FunctionTemplate> function_template = 213 v8::Local<v8::FunctionTemplate> function_template =
204 CreateAccessorFunctionOrTemplate<v8::FunctionTemplate>( 214 CreateAccessorFunctionOrTemplate<v8::FunctionTemplate>(
205 isolate, callback, nullptr, data, signature, length); 215 isolate, callback, nullptr, nullptr, data, signature, length);
206 if (function_template.IsEmpty()) 216 if (function_template.IsEmpty())
207 return v8::Local<v8::Function>(); 217 return v8::Local<v8::Function>();
208 218
209 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 219 v8::Local<v8::Context> context = isolate->GetCurrentContext();
210 v8::Local<v8::Function> function; 220 v8::Local<v8::Function> function;
211 if (!function_template->GetFunction(context).ToLocal(&function)) 221 if (!function_template->GetFunction(context).ToLocal(&function))
212 return v8::Local<v8::Function>(); 222 return v8::Local<v8::Function>();
213 return function; 223 return function;
214 } 224 }
215 225
216 template <class ObjectOrTemplate, class FunctionOrTemplate> 226 template <class ObjectOrTemplate, class FunctionOrTemplate>
217 void InstallAccessorInternal( 227 void InstallAccessorInternal(
218 v8::Isolate* isolate, 228 v8::Isolate* isolate,
219 v8::Local<ObjectOrTemplate> instance_or_template, 229 v8::Local<ObjectOrTemplate> instance_or_template,
220 v8::Local<ObjectOrTemplate> prototype_or_template, 230 v8::Local<ObjectOrTemplate> prototype_or_template,
221 v8::Local<FunctionOrTemplate> interface_or_template, 231 v8::Local<FunctionOrTemplate> interface_or_template,
222 v8::Local<v8::Signature> signature, 232 v8::Local<v8::Signature> signature,
223 const V8DOMConfiguration::AccessorConfiguration& accessor, 233 const V8DOMConfiguration::AccessorConfiguration& accessor,
224 const DOMWrapperWorld& world) { 234 const DOMWrapperWorld& world) {
225 if (!WorldConfigurationApplies(accessor, world)) 235 if (!WorldConfigurationApplies(accessor, world))
226 return; 236 return;
227 v8::Local<v8::Name> name = V8AtomicString(isolate, accessor.name); 237 v8::Local<v8::Name> name = V8AtomicString(isolate, accessor.name);
228 v8::FunctionCallback getter_callback = accessor.getter; 238 v8::FunctionCallback getter_callback = accessor.getter;
229 v8::FunctionCallback setter_callback = accessor.setter; 239 v8::FunctionCallback setter_callback = accessor.setter;
230 V8DOMConfiguration::CachedPropertyKey cached_property_key = nullptr; 240 V8DOMConfiguration::CachedPropertyKey cached_property_key = nullptr;
241 V8DOMConfiguration::CachedAccessorInitCallback cached_accessor_init_callback =
242 nullptr;
231 if (world.IsMainWorld()) { 243 if (world.IsMainWorld()) {
232 cached_property_key = accessor.cached_property_key; 244 cached_property_key = accessor.cached_property_key;
245 cached_accessor_init_callback = accessor.cached_accessor_init_callback;
233 } 246 }
234 247
235 // Support [LenientThis] by not specifying the signature. V8 does not do 248 // Support [LenientThis] by not specifying the signature. V8 does not do
236 // the type checking against holder if no signature is specified. Note that 249 // the type checking against holder if no signature is specified. Note that
237 // info.Holder() passed to callbacks will be *unsafe*. 250 // info.Holder() passed to callbacks will be *unsafe*.
238 if (accessor.holder_check_configuration == 251 if (accessor.holder_check_configuration ==
239 V8DOMConfiguration::kDoNotCheckHolder) 252 V8DOMConfiguration::kDoNotCheckHolder)
240 signature = v8::Local<v8::Signature>(); 253 signature = v8::Local<v8::Signature>();
241 v8::Local<v8::Value> data = 254 v8::Local<v8::Value> data =
242 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); 255 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data));
243 256
244 DCHECK(accessor.property_location_configuration); 257 DCHECK(accessor.property_location_configuration);
245 if (accessor.property_location_configuration & 258 if (accessor.property_location_configuration &
246 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { 259 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) {
247 v8::Local<FunctionOrTemplate> getter = 260 v8::Local<FunctionOrTemplate> getter =
248 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 261 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
249 isolate, getter_callback, cached_property_key, data, signature, 0); 262 isolate, getter_callback, cached_property_key,
263 cached_accessor_init_callback, data, signature, 0);
250 v8::Local<FunctionOrTemplate> setter = 264 v8::Local<FunctionOrTemplate> setter =
251 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 265 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
252 isolate, setter_callback, nullptr, data, signature, 1); 266 isolate, setter_callback, nullptr, nullptr, data, signature, 1);
253 if (accessor.property_location_configuration & 267 if (accessor.property_location_configuration &
254 V8DOMConfiguration::kOnInstance) { 268 V8DOMConfiguration::kOnInstance) {
255 instance_or_template->SetAccessorProperty( 269 instance_or_template->SetAccessorProperty(
256 name, getter, setter, 270 name, getter, setter,
257 static_cast<v8::PropertyAttribute>(accessor.attribute)); 271 static_cast<v8::PropertyAttribute>(accessor.attribute));
258 } 272 }
259 if (accessor.property_location_configuration & 273 if (accessor.property_location_configuration &
260 V8DOMConfiguration::kOnPrototype) { 274 V8DOMConfiguration::kOnPrototype) {
261 prototype_or_template->SetAccessorProperty( 275 prototype_or_template->SetAccessorProperty(
262 name, getter, setter, 276 name, getter, setter,
263 static_cast<v8::PropertyAttribute>(accessor.attribute)); 277 static_cast<v8::PropertyAttribute>(accessor.attribute));
264 } 278 }
265 } 279 }
266 if (accessor.property_location_configuration & 280 if (accessor.property_location_configuration &
267 V8DOMConfiguration::kOnInterface) { 281 V8DOMConfiguration::kOnInterface) {
268 // Attributes installed on the interface object must be static 282 // Attributes installed on the interface object must be static
269 // attributes, so no need to specify a signature, i.e. no need to do 283 // attributes, so no need to specify a signature, i.e. no need to do
270 // type check against a holder. 284 // type check against a holder.
271 v8::Local<FunctionOrTemplate> getter = 285 v8::Local<FunctionOrTemplate> getter =
272 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 286 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
273 isolate, getter_callback, nullptr, data, v8::Local<v8::Signature>(), 287 isolate, getter_callback, nullptr, nullptr, data,
274 0); 288 v8::Local<v8::Signature>(), 0);
275 v8::Local<FunctionOrTemplate> setter = 289 v8::Local<FunctionOrTemplate> setter =
276 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 290 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
277 isolate, setter_callback, nullptr, data, v8::Local<v8::Signature>(), 291 isolate, setter_callback, nullptr, nullptr, data,
278 1); 292 v8::Local<v8::Signature>(), 1);
279 interface_or_template->SetAccessorProperty( 293 interface_or_template->SetAccessorProperty(
280 name, getter, setter, 294 name, getter, setter,
281 static_cast<v8::PropertyAttribute>(accessor.attribute)); 295 static_cast<v8::PropertyAttribute>(accessor.attribute));
282 } 296 }
283 } 297 }
284 298
285 v8::Local<v8::Primitive> ValueForConstant( 299 v8::Local<v8::Primitive> ValueForConstant(
286 v8::Isolate* isolate, 300 v8::Isolate* isolate,
287 const V8DOMConfiguration::ConstantConfiguration& constant) { 301 const V8DOMConfiguration::ConstantConfiguration& constant) {
288 v8::Local<v8::Primitive> value; 302 v8::Local<v8::Primitive> value;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 v8::Isolate* isolate, 708 v8::Isolate* isolate,
695 v8::Local<v8::ObjectTemplate> object_template, 709 v8::Local<v8::ObjectTemplate> object_template,
696 const char* class_string) { 710 const char* class_string) {
697 object_template->Set( 711 object_template->Set(
698 v8::Symbol::GetToStringTag(isolate), 712 v8::Symbol::GetToStringTag(isolate),
699 V8AtomicString(isolate, class_string), 713 V8AtomicString(isolate, class_string),
700 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); 714 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
701 } 715 }
702 716
703 } // namespace blink 717 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698