Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 case V8DOMConfiguration::ConstantTypeDouble: | 155 case V8DOMConfiguration::ConstantTypeDouble: |
| 156 value = v8::Number::New(isolate, constant.dvalue); | 156 value = v8::Number::New(isolate, constant.dvalue); |
| 157 break; | 157 break; |
| 158 default: | 158 default: |
| 159 ASSERT_NOT_REACHED(); | 159 ASSERT_NOT_REACHED(); |
| 160 } | 160 } |
| 161 functionDescriptor->Set(constantName, value, attributes); | 161 functionDescriptor->Set(constantName, value, attributes); |
| 162 prototypeTemplate->Set(constantName, value, attributes); | 162 prototypeTemplate->Set(constantName, value, attributes); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void doInstallMethodInternal(v8::Local<v8::ObjectTemplate> target, v8::Local<v8: :Name> name, v8::Local<v8::FunctionTemplate> functionTemplate, v8::PropertyAttri bute attribute) | 165 template<class Configuration> |
| 166 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 { | 167 { |
| 167 target->Set(name, functionTemplate, attribute); | 168 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()) | 169 && !world.isPrivateScriptIsolatedWorld()) |
| 180 return; | 170 return; |
| 181 | 171 |
| 182 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate, callback.callbackForWorld(world), v8Undefined(), signature, callback.l ength); | 172 v8::Local<v8::Name> name = method.methodName(isolate); |
| 183 functionTemplate->RemovePrototype(); | 173 v8::FunctionCallback callback = method.callbackForWorld(world); |
| 184 doInstallMethodInternal(objectOrTemplate, callback.methodName(isolate), func tionTemplate, attribute); | 174 |
| 175 ASSERT(method.propertyLocationConfiguration); | |
| 176 if (method.propertyLocationConfiguration & | |
| 177 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { | |
| 178 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8::Local<v8::Value>(), signature, method.length); | |
| 179 functionTemplate->RemovePrototype(); | |
| 180 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInstanc e) | |
| 181 instanceTemplate->Set(name, functionTemplate, attribute); | |
| 182 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnPrototy pe) | |
| 183 prototypeTemplate->Set(name, functionTemplate, attribute); | |
| 184 } | |
| 185 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) { | |
| 186 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, callback, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), meth od.length); | |
|
haraken
2015/09/08 08:37:11
Just to confirm: You're intentionally using an emp
Yuki
2015/09/08 08:49:46
Yes.
Empty signature means that any object can ca
haraken
2015/09/08 08:57:13
Thanks, maybe worth adding a comment :)
Yuki
2015/09/08 09:49:24
Added comments.
| |
| 187 functionTemplate->RemovePrototype(); | |
| 188 interfaceTemplate->Set(name, functionTemplate, attribute); | |
| 189 } | |
| 185 } | 190 } |
| 186 | 191 |
| 187 } // namespace | 192 } // namespace |
| 188 | 193 |
| 189 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Local<v8::O bjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate , const AttributeConfiguration* attributes, size_t attributeCount) | 194 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Local<v8::O bjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate , const AttributeConfiguration* attributes, size_t attributeCount) |
| 190 { | 195 { |
| 191 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 196 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 192 for (size_t i = 0; i < attributeCount; ++i) | 197 for (size_t i = 0; i < attributeCount; ++i) |
| 193 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world); | 198 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world); |
| 194 } | 199 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 236 |
| 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) | 237 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 { | 238 { |
| 234 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); | 239 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); |
| 235 v8::PropertyAttribute attributes = | 240 v8::PropertyAttribute attributes = |
| 236 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 241 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 237 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Local <v8::Value>(), attributes); | 242 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Local <v8::Value>(), attributes); |
| 238 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); | 243 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); |
| 239 } | 244 } |
| 240 | 245 |
| 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) | 246 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 { | 247 { |
| 243 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 248 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 244 for (size_t i = 0; i < callbackCount; ++i) | 249 for (size_t i = 0; i < methodCount; ++i) |
| 245 installMethodInternal(isolate, prototypeTemplate, signature, attribute, callbacks[i], world); | 250 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, inte rfaceTemplate, signature, attribute, methods[i], world); |
| 246 } | 251 } |
| 247 | 252 |
| 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) | 253 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 { | 254 { |
| 250 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 255 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 251 installMethodInternal(isolate, functionDescriptor, signature, attribute, cal lback, world); | 256 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, interfac eTemplate, signature, attribute, method, world); |
| 252 } | 257 } |
| 253 | 258 |
| 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) | 259 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 { | 260 { |
| 256 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 261 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 257 installMethodInternal(isolate, prototypeTemplate, signature, attribute, call back, world); | 262 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 } | 263 } |
| 265 | 264 |
| 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, | 265 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, | 266 const AttributeConfiguration* attributes, size_t attributeCount, |
| 268 const AccessorConfiguration* accessors, size_t accessorCount, | 267 const AccessorConfiguration* accessors, size_t accessorCount, |
| 269 const MethodConfiguration* callbacks, size_t callbackCount) | 268 const MethodConfiguration* methods, size_t methodCount) |
| 270 { | 269 { |
| 271 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); | 270 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); |
| 272 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); | 271 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); |
| 273 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate(); | 272 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate(); |
| 274 instanceTemplate->SetInternalFieldCount(fieldCount); | 273 instanceTemplate->SetInternalFieldCount(fieldCount); |
| 275 if (!parentClass.IsEmpty()) { | 274 if (!parentClass.IsEmpty()) { |
| 276 functionDescriptor->Inherit(parentClass); | 275 functionDescriptor->Inherit(parentClass); |
| 277 // Marks the prototype object as one of native-backed objects. | 276 // 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. | 277 // 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. | 278 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. |
| 280 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 279 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
| 281 } | 280 } |
| 282 | 281 |
| 283 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); | 282 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); |
| 284 if (attributeCount) | 283 if (attributeCount) |
| 285 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); | 284 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); |
| 286 if (accessorCount) | 285 if (accessorCount) |
| 287 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount); | 286 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount); |
| 288 if (callbackCount) | 287 if (methodCount) |
| 289 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast <v8::PropertyAttribute>(v8::None), callbacks, callbackCount); | 288 installMethods(isolate, instanceTemplate, prototypeTemplate, functionDes criptor, defaultSignature, static_cast<v8::PropertyAttribute>(v8::None), methods , methodCount); |
| 290 return defaultSignature; | 289 return defaultSignature; |
| 291 } | 290 } |
| 292 | 291 |
| 293 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) | 292 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) |
| 294 { | 293 { |
| 295 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 294 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 296 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); | 295 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); |
| 297 if (!result.IsEmpty()) | 296 if (!result.IsEmpty()) |
| 298 return result; | 297 return result; |
| 299 | 298 |
| 300 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); | 299 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); |
| 301 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); | 300 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); |
| 302 configureDOMClassTemplate(result, isolate); | 301 configureDOMClassTemplate(result, isolate); |
| 303 data->setDOMTemplate(wrapperTypeInfo, result); | 302 data->setDOMTemplate(wrapperTypeInfo, result); |
| 304 return result; | 303 return result; |
| 305 } | 304 } |
| 306 | 305 |
| 307 } // namespace blink | 306 } // namespace blink |
| OLD | NEW |