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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { | 131 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { |
| 132 // Attributes installed on the interface object must be static | 132 // Attributes installed on the interface object must be static |
| 133 // attributes, so no need to specify a signature, i.e. no need to do | 133 // attributes, so no need to specify a signature, i.e. no need to do |
| 134 // type check against a holder. | 134 // type check against a holder. |
| 135 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 ); | 135 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 ); |
| 136 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 ); | 136 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 ); |
| 137 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); | 137 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant) | 141 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8D OMConfiguration::ConstantConfiguration& constant) |
| 142 { | 142 { |
| 143 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); | 143 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); |
| 144 v8::PropertyAttribute attributes = | 144 v8::PropertyAttribute attributes = |
| 145 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 145 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 146 v8::Local<v8::Primitive> value; | 146 v8::Local<v8::Primitive> value; |
| 147 switch (constant.type) { | 147 switch (constant.type) { |
| 148 case V8DOMConfiguration::ConstantTypeShort: | 148 case V8DOMConfiguration::ConstantTypeShort: |
| 149 case V8DOMConfiguration::ConstantTypeLong: | 149 case V8DOMConfiguration::ConstantTypeLong: |
| 150 case V8DOMConfiguration::ConstantTypeUnsignedShort: | 150 case V8DOMConfiguration::ConstantTypeUnsignedShort: |
| 151 value = v8::Integer::New(isolate, constant.ivalue); | 151 value = v8::Integer::New(isolate, constant.ivalue); |
| 152 break; | 152 break; |
| 153 case V8DOMConfiguration::ConstantTypeUnsignedLong: | 153 case V8DOMConfiguration::ConstantTypeUnsignedLong: |
| 154 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue); | 154 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue); |
| 155 break; | 155 break; |
| 156 case V8DOMConfiguration::ConstantTypeFloat: | 156 case V8DOMConfiguration::ConstantTypeFloat: |
| 157 case V8DOMConfiguration::ConstantTypeDouble: | 157 case V8DOMConfiguration::ConstantTypeDouble: |
| 158 value = v8::Number::New(isolate, constant.dvalue); | 158 value = v8::Number::New(isolate, constant.dvalue); |
| 159 break; | 159 break; |
| 160 default: | 160 default: |
| 161 ASSERT_NOT_REACHED(); | 161 ASSERT_NOT_REACHED(); |
| 162 } | 162 } |
| 163 functionDescriptor->Set(constantName, value, attributes); | 163 interfaceTemplate->Set(constantName, value, attributes); |
| 164 prototypeTemplate->Set(constantName, value, attributes); | 164 prototypeTemplate->Set(constantName, value, attributes); |
| 165 } | 165 } |
| 166 | 166 |
| 167 template<class Configuration> | 167 template<class Configuration> |
| 168 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, const C onfiguration& method, const DOMWrapperWorld& world) | 168 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, const C onfiguration& method, const DOMWrapperWorld& world) |
| 169 { | 169 { |
| 170 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript | 170 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript |
| 171 && !world.isPrivateScriptIsolatedWorld()) | 171 && !world.isPrivateScriptIsolatedWorld()) |
| 172 return; | 172 return; |
| 173 | 173 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 252 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 253 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interf aceTemplate, signature, accessor, world); | 253 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interf aceTemplate, signature, accessor, world); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ect> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interfac e, v8::Local<v8::Signature> signature, const AccessorConfiguration& accessor) | 256 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ect> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interfac e, v8::Local<v8::Signature> signature, const AccessorConfiguration& accessor) |
| 257 { | 257 { |
| 258 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 258 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 259 installAccessorInternal(isolate, instance, prototype, interface, signature, accessor, world); | 259 installAccessorInternal(isolate, instance, prototype, interface, signature, accessor, world); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempl ate, const ConstantConfiguration* constants, size_t constantCount) | 262 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration* constants, size_t constantCount) |
| 263 { | 263 { |
| 264 for (size_t i = 0; i < constantCount; ++i) | 264 for (size_t i = 0; i < constantCount; ++i) |
| 265 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]); | 265 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c onstants[i]); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration& constant) | 268 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat e, const ConstantConfiguration& constant) |
| 269 { | 269 { |
| 270 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, cons tant); | 270 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const ant); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> proto typeTemplate, const char* name, v8::AccessorNameGetterCallback getter) | 273 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> protot ypeTemplate, const char* name, v8::AccessorNameGetterCallback getter) |
| 274 { | 274 { |
| 275 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); | 275 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); |
| 276 v8::PropertyAttribute attributes = | 276 v8::PropertyAttribute attributes = |
| 277 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 277 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 278 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Local <v8::Value>(), attributes); | 278 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); |
| 279 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); | 279 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); |
| 280 } | 280 } |
| 281 | 281 |
| 282 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, const MethodConfiguration* methods, size_t methodCount) | 282 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, const MethodConfiguration* methods, size_t methodCount) |
| 283 { | 283 { |
| 284 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 284 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 285 for (size_t i = 0; i < methodCount; ++i) | 285 for (size_t i = 0; i < methodCount; ++i) |
| 286 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, inte rfaceTemplate, signature, methods[i], world); | 286 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, inte rfaceTemplate, signature, methods[i], world); |
| 287 } | 287 } |
| 288 | 288 |
| 289 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, const MethodConfiguration& method) | 289 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, const MethodConfiguration& method) |
| 290 { | 290 { |
| 291 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 291 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 292 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, interfac eTemplate, signature, method, world); | 292 installMethodInternal(isolate, instanceTemplate, prototypeTemplate, interfac eTemplate, signature, method, world); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec t> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface, v8::Local<v8::Signature> signature, const MethodConfiguration& method) | 295 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec t> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface, v8::Local<v8::Signature> signature, const MethodConfiguration& method) |
| 296 { | 296 { |
| 297 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 297 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 298 installMethodInternal(isolate, instance, prototype, interface, signature, me thod, world); | 298 installMethodInternal(isolate, instance, prototype, interface, signature, me thod, world); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const SymbolKe yedMethodConfiguration& method) | 301 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Local<v8::Objec tTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const SymbolKe yedMethodConfiguration& method) |
| 302 { | 302 { |
| 303 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 303 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 304 installMethodInternal(isolate, v8::Local<v8::ObjectTemplate>(), prototypeTem plate, v8::Local<v8::FunctionTemplate>(), signature, method, world); | 304 installMethodInternal(isolate, v8::Local<v8::ObjectTemplate>(), prototypeTem plate, v8::Local<v8::FunctionTemplate>(), signature, method, world); |
| 305 } | 305 } |
| 306 | 306 |
| 307 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, | 307 void V8DOMConfiguration::initializeDOMInterfaceTemplate(v8::Isolate* isolate, v8 ::Local<v8::FunctionTemplate> interfaceTemplate, const char* interfaceName, v8:: Local<v8::FunctionTemplate> parentInterfaceTemplate, size_t v8InternalFieldCount ) |
| 308 const AttributeConfiguration* attributes, size_t attributeCount, | |
| 309 const AccessorConfiguration* accessors, size_t accessorCount, | |
| 310 const MethodConfiguration* methods, size_t methodCount) | |
| 311 { | 308 { |
| 312 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); | 309 interfaceTemplate->SetClassName(v8AtomicString(isolate, interfaceName)); |
| 313 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); | 310 interfaceTemplate->ReadOnlyPrototype(); |
| 314 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate(); | 311 v8::Local<v8::ObjectTemplate> instanceTemplate = interfaceTemplate->Instance Template(); |
| 315 instanceTemplate->SetInternalFieldCount(fieldCount); | 312 v8::Local<v8::ObjectTemplate> prototypeTemplate = interfaceTemplate->Prototy peTemplate(); |
| 316 if (!parentClass.IsEmpty()) { | 313 instanceTemplate->SetInternalFieldCount(v8InternalFieldCount); |
| 317 functionDescriptor->Inherit(parentClass); | 314 // TODO(yukishiino): We should set the class string to the platform object |
| 315 // (|instanceTemplate|), too. The reason that we don't set it is that | |
| 316 // it prevents minor GC to collect unreachable DOM objects (a layout test | |
| 317 // fast/dom/minor-dom-gc.html fails if we set the class string). | |
| 318 // See also http://heycam.github.io/webidl/#es-platform-objects | |
|
haraken
2016/03/04 10:58:12
Not related to this CL, but this is worth discussi
jochen (gone - plz use gerrit)
2016/03/04 12:43:17
hum, that's surprising. Setting a string on the in
Yuki
2016/03/04 14:35:40
I just observe that, if I added
setClassString
| |
| 319 setClassString(isolate, prototypeTemplate, interfaceName); | |
| 320 if (!parentInterfaceTemplate.IsEmpty()) { | |
| 321 interfaceTemplate->Inherit(parentInterfaceTemplate); | |
| 318 // Marks the prototype object as one of native-backed objects. | 322 // Marks the prototype object as one of native-backed objects. |
| 319 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. | 323 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. |
| 320 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. | 324 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. |
| 321 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 325 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
| 322 } | 326 } |
| 323 | |
| 324 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); | |
| 325 if (attributeCount) | |
| 326 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); | |
| 327 if (accessorCount) | |
| 328 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount); | |
| 329 if (methodCount) | |
| 330 installMethods(isolate, instanceTemplate, prototypeTemplate, functionDes criptor, defaultSignature, methods, methodCount); | |
| 331 return defaultSignature; | |
| 332 } | 327 } |
| 333 | 328 |
| 334 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) | 329 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) |
| 335 { | 330 { |
| 336 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 331 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 337 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); | 332 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); |
| 338 if (!result.IsEmpty()) | 333 if (!result.IsEmpty()) |
| 339 return result; | 334 return result; |
| 340 | 335 |
| 341 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); | 336 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); |
| 342 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); | 337 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); |
| 343 configureDOMClassTemplate(result, isolate); | 338 configureDOMClassTemplate(result, isolate); |
| 344 data->setDOMTemplate(wrapperTypeInfo, result); | 339 data->setDOMTemplate(wrapperTypeInfo, result); |
| 345 return result; | 340 return result; |
| 346 } | 341 } |
| 347 | 342 |
| 348 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) | 343 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) |
| 349 { | 344 { |
| 350 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); | 345 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); |
| 351 } | 346 } |
| 352 | 347 |
| 353 } // namespace blink | 348 } // namespace blink |
| OLD | NEW |