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

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

Issue 1322533002: bindings: Supports to change the method location. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed review comments. Created 5 years, 3 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/V8DOMConfiguration.h ('k') | Source/bindings/scripts/v8_methods.py » ('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) 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (accessor.propertyLocationConfiguration & 123 if (accessor.propertyLocationConfiguration &
124 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { 124 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) {
125 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, signature, 0); 125 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, signature, 0);
126 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, signature, 1); 126 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, signature, 1);
127 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce) 127 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce)
128 instanceOrTemplate->SetAccessorProperty(name, getter, setter, access or.attribute, accessor.settings); 128 instanceOrTemplate->SetAccessorProperty(name, getter, setter, access or.attribute, accessor.settings);
129 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type) 129 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type)
130 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, acces sor.attribute, accessor.settings); 130 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, acces sor.attribute, accessor.settings);
131 } 131 }
132 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { 132 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) {
133 // Attributes installed on the interface object must be static
134 // attributes, so no need to specify a signature, i.e. no need to do
135 // type check against a holder.
133 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 ); 136 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 );
134 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 ); 137 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 );
135 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, accessor. attribute, accessor.settings); 138 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, accessor. attribute, accessor.settings);
136 } 139 }
137 } 140 }
138 141
139 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant) 142 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant)
140 { 143 {
141 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); 144 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name);
142 v8::PropertyAttribute attributes = 145 v8::PropertyAttribute attributes =
(...skipping 12 matching lines...) Expand all
155 case V8DOMConfiguration::ConstantTypeDouble: 158 case V8DOMConfiguration::ConstantTypeDouble:
156 value = v8::Number::New(isolate, constant.dvalue); 159 value = v8::Number::New(isolate, constant.dvalue);
157 break; 160 break;
158 default: 161 default:
159 ASSERT_NOT_REACHED(); 162 ASSERT_NOT_REACHED();
160 } 163 }
161 functionDescriptor->Set(constantName, value, attributes); 164 functionDescriptor->Set(constantName, value, attributes);
162 prototypeTemplate->Set(constantName, value, attributes); 165 prototypeTemplate->Set(constantName, value, attributes);
163 } 166 }
164 167
165 void doInstallMethodInternal(v8::Local<v8::ObjectTemplate> target, v8::Local<v8: :Name> name, v8::Local<v8::FunctionTemplate> functionTemplate, v8::PropertyAttri bute attribute) 168 template<class Configuration>
169 void installMethodInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> i nstanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8:: FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, v8::Pro pertyAttribute attribute, const Configuration& method, const DOMWrapperWorld& wo rld)
166 { 170 {
167 target->Set(name, functionTemplate, attribute); 171 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript
168 }
169
170 void doInstallMethodInternal(v8::Local<v8::FunctionTemplate> target, v8::Local<v 8::Name> name, v8::Local<v8::FunctionTemplate> functionTemplate, v8::PropertyAtt ribute attribute)
171 {
172 target->Set(name, functionTemplate, attribute);
173 }
174
175 template<class ObjectOrTemplate, class Configuration>
176 void installMethodInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> obj ectOrTemplate, v8::Local<v8::Signature> signature, v8::PropertyAttribute attribu te, const Configuration& callback, const DOMWrapperWorld& world)
177 {
178 if (callback.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script
179 && !world.isPrivateScriptIsolatedWorld()) 172 && !world.isPrivateScriptIsolatedWorld())
180 return; 173 return;
181 174
182 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate, callback.callbackForWorld(world), v8Undefined(), signature, callback.l ength); 175 v8::Local<v8::Name> name = method.methodName(isolate);
183 functionTemplate->RemovePrototype(); 176 v8::FunctionCallback callback = method.callbackForWorld(world);
184 doInstallMethodInternal(objectOrTemplate, callback.methodName(isolate), func tionTemplate, attribute); 177
178 ASSERT(method.propertyLocationConfiguration);
179 if (method.propertyLocationConfiguration &
180 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) {
181 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8::Local<v8::Value>(), signature, method.length);
182 functionTemplate->RemovePrototype();
183 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInstanc e)
184 instanceTemplate->Set(name, functionTemplate, attribute);
185 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnPrototy pe)
186 prototypeTemplate->Set(name, functionTemplate, attribute);
187 }
188 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) {
189 // Operations installed on the interface object must be static
190 // operations, so no need to specify a signature, i.e. no need to do
191 // type check against a holder.
192 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), meth od.length);
193 functionTemplate->RemovePrototype();
194 interfaceTemplate->Set(name, functionTemplate, attribute);
195 }
185 } 196 }
186 197
187 } // namespace 198 } // namespace
188 199
189 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Local<v8::O bjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate , const AttributeConfiguration* attributes, size_t attributeCount) 200 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Local<v8::O bjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate , const AttributeConfiguration* attributes, size_t attributeCount)
190 { 201 {
191 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 202 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
192 for (size_t i = 0; i < attributeCount; ++i) 203 for (size_t i = 0; i < attributeCount; ++i)
193 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world); 204 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world);
194 } 205 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 242
232 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> proto typeTemplate, const char* name, v8::AccessorNameGetterCallback getter) 243 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> proto typeTemplate, const char* name, v8::AccessorNameGetterCallback getter)
233 { 244 {
234 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); 245 v8::Local<v8::String> constantName = v8AtomicString(isolate, name);
235 v8::PropertyAttribute attributes = 246 v8::PropertyAttribute attributes =
236 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); 247 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
237 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Local <v8::Value>(), attributes); 248 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Local <v8::Value>(), attributes);
238 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); 249 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes);
239 } 250 }
240 251
241 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, v8::PropertyA ttribute attribute, const MethodConfiguration* callbacks, size_t callbackCount) 252 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v 8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signa ture, v8::PropertyAttribute attribute, const MethodConfiguration* methods, size_ t methodCount)
242 { 253 {
243 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 254 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
244 for (size_t i = 0; i < callbackCount; ++i) 255 for (size_t i = 0; i < methodCount; ++i)
245 installMethodInternal(isolate, prototypeTemplate, signature, attribute, callbacks[i], world); 256 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, inte rfaceTemplate, signature, attribute, methods[i], world);
246 } 257 }
247 258
248 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Funct ionTemplate> functionDescriptor, v8::Local<v8::Signature> signature, v8::Propert yAttribute attribute, const MethodConfiguration& callback) 259 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8 ::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signat ure, v8::PropertyAttribute attribute, const MethodConfiguration& method)
249 { 260 {
250 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 261 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
251 installMethodInternal(isolate, functionDescriptor, signature, attribute, cal lback, world); 262 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, interfac eTemplate, signature, attribute, method, world);
252 } 263 }
253 264
254 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, v8::PropertyAt tribute attribute, const MethodConfiguration& callback) 265 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, v8::PropertyAt tribute attribute, const SymbolKeyedMethodConfiguration& method)
255 { 266 {
256 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 267 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
257 installMethodInternal(isolate, prototypeTemplate, signature, attribute, call back, world); 268 installMethodInternal(isolate, v8::Local<v8::ObjectTemplate>(), prototypeTem plate, v8::Local<v8::FunctionTemplate>(), signature, attribute, method, world);
258 }
259
260 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, v8::PropertyAt tribute attribute, const SymbolKeyedMethodConfiguration& callback)
261 {
262 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
263 installMethodInternal(isolate, prototypeTemplate, signature, attribute, call back, world);
264 } 269 }
265 270
266 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate * isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, const char* inter faceName, v8::Local<v8::FunctionTemplate> parentClass, size_t fieldCount, 271 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate * isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, const char* inter faceName, v8::Local<v8::FunctionTemplate> parentClass, size_t fieldCount,
267 const AttributeConfiguration* attributes, size_t attributeCount, 272 const AttributeConfiguration* attributes, size_t attributeCount,
268 const AccessorConfiguration* accessors, size_t accessorCount, 273 const AccessorConfiguration* accessors, size_t accessorCount,
269 const MethodConfiguration* callbacks, size_t callbackCount) 274 const MethodConfiguration* methods, size_t methodCount)
270 { 275 {
271 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); 276 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName));
272 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); 277 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate();
273 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate(); 278 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate();
274 instanceTemplate->SetInternalFieldCount(fieldCount); 279 instanceTemplate->SetInternalFieldCount(fieldCount);
275 if (!parentClass.IsEmpty()) { 280 if (!parentClass.IsEmpty()) {
276 functionDescriptor->Inherit(parentClass); 281 functionDescriptor->Inherit(parentClass);
277 // Marks the prototype object as one of native-backed objects. 282 // Marks the prototype object as one of native-backed objects.
278 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. 283 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones.
279 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. 284 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure.
280 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); 285 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount);
281 } 286 }
282 287
283 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); 288 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor);
284 if (attributeCount) 289 if (attributeCount)
285 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); 290 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount);
286 if (accessorCount) 291 if (accessorCount)
287 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount); 292 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount);
288 if (callbackCount) 293 if (methodCount)
289 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast <v8::PropertyAttribute>(v8::None), callbacks, callbackCount); 294 installMethods(isolate, instanceTemplate, prototypeTemplate, functionDes criptor, defaultSignature, static_cast<v8::PropertyAttribute>(v8::None), methods , methodCount);
290 return defaultSignature; 295 return defaultSignature;
291 } 296 }
292 297
293 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) 298 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*))
294 { 299 {
295 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 300 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
296 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); 301 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo);
297 if (!result.IsEmpty()) 302 if (!result.IsEmpty())
298 return result; 303 return result;
299 304
300 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); 305 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
301 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); 306 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode);
302 configureDOMClassTemplate(result, isolate); 307 configureDOMClassTemplate(result, isolate);
303 data->setDOMTemplate(wrapperTypeInfo, result); 308 data->setDOMTemplate(wrapperTypeInfo, result);
304 return result; 309 return result;
305 } 310 }
306 311
307 } // namespace blink 312 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8DOMConfiguration.h ('k') | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698