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 18 matching lines...) Expand all Loading... | |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "bindings/core/v8/V8DOMConfiguration.h" | 30 #include "bindings/core/v8/V8DOMConfiguration.h" |
| 31 | 31 |
| 32 #include "bindings/core/v8/V8ObjectConstructor.h" | 32 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 33 #include "platform/TraceEvent.h" | 33 #include "platform/TraceEvent.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 void setAccessor(v8::Isolate* isolate, v8::Local<v8::Object> target, v8::Local<v 8::Name> name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSetterCall back setter, v8::Local<v8::Value> data, v8::AccessControl settings, v8::Property Attribute attribute) | 39 void installAttributeInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate > instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8DOM Configuration::AttributeConfiguration& attribute, const DOMWrapperWorld& world) |
| 40 { | |
| 41 v8::Maybe<bool> result = target->SetAccessor(isolate->GetCurrentContext(), n ame, getter, setter, v8::MaybeLocal<v8::Value>(data), settings, attribute); | |
| 42 ASSERT_UNUSED(result, result.FromJust()); | |
| 43 } | |
| 44 | |
| 45 void setAccessor(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> target, v8: :Local<v8::Name> name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSe tterCallback setter, v8::Local<v8::Value> data, v8::AccessControl settings, v8:: PropertyAttribute attribute) | |
| 46 { | |
| 47 target->SetAccessor(name, getter, setter, data, settings, attribute); | |
| 48 } | |
| 49 | |
| 50 template<class ObjectOrTemplate> | |
| 51 void installAttributeInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> instanceOrTemplate, v8::Local<ObjectOrTemplate> prototypeOrTemplate, const V8DOM Configuration::AttributeConfiguration& attribute, const DOMWrapperWorld& world) | |
| 52 { | 40 { |
| 53 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript | 41 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript |
| 54 && !world.isPrivateScriptIsolatedWorld()) | 42 && !world.isPrivateScriptIsolatedWorld()) |
| 55 return; | 43 return; |
| 56 | 44 |
| 45 v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name); | |
| 57 v8::AccessorNameGetterCallback getter = attribute.getter; | 46 v8::AccessorNameGetterCallback getter = attribute.getter; |
| 58 v8::AccessorNameSetterCallback setter = attribute.setter; | 47 v8::AccessorNameSetterCallback setter = attribute.setter; |
| 59 if (world.isMainWorld()) { | 48 if (world.isMainWorld()) { |
| 60 if (attribute.getterForMainWorld) | 49 if (attribute.getterForMainWorld) |
| 61 getter = attribute.getterForMainWorld; | 50 getter = attribute.getterForMainWorld; |
| 62 if (attribute.setterForMainWorld) | 51 if (attribute.setterForMainWorld) |
| 63 setter = attribute.setterForMainWorld; | 52 setter = attribute.setterForMainWorld; |
| 64 } | 53 } |
| 65 v8::Local<ObjectOrTemplate> target = | 54 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(attribute.data)); |
| 66 attribute.instanceOrPrototypeConfiguration == V8DOMConfiguration::OnProt otype ? | 55 |
| 67 prototypeOrTemplate : | 56 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance ) |
| 68 instanceOrTemplate; | 57 instanceTemplate->SetAccessor(name, getter, setter, data, attribute.sett ings, attribute.attribute); |
| 69 setAccessor(isolate, target, v8AtomicString(isolate, attribute.name), getter , setter, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data )), attribute.settings, attribute.attribute); | 58 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp e) |
|
haraken
2015/06/17 16:31:21
if => else if?
Yuki
2015/06/18 07:44:40
No, I'd like to make attribute.propertyLocationCon
| |
| 59 prototypeTemplate->SetAccessor(name, getter, setter, data, attribute.set tings, attribute.attribute); | |
| 60 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac e) | |
|
haraken
2015/06/17 16:31:21
if => else if?
| |
| 61 ASSERT_NOT_REACHED(); | |
| 70 } | 62 } |
| 71 | 63 |
| 72 v8::Local<v8::FunctionTemplate> functionOrTemplate(v8::Isolate* isolate, v8::Fun ctionCallback callback, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Si gnature> signature, int length, v8::Local<v8::ObjectTemplate> prototypeTemplateF orOverloadResolution) | 64 v8::Local<v8::FunctionTemplate> createAccessorFunctionTemplate(v8::Isolate* isol ate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Sig nature> signature, int length) |
| 73 { | 65 { |
| 74 v8::Local<v8::FunctionTemplate> functionTemplate; | 66 v8::Local<v8::FunctionTemplate> functionTemplate; |
| 75 if (callback) { | 67 if (callback) { |
| 76 functionTemplate = v8::FunctionTemplate::New(isolate, callback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(wrapperTypeInfo)), signature, le ngth); | 68 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, si gnature, length); |
| 77 if (!functionTemplate.IsEmpty()) { | 69 if (!functionTemplate.IsEmpty()) { |
| 78 functionTemplate->RemovePrototype(); | 70 functionTemplate->RemovePrototype(); |
| 79 functionTemplate->SetAcceptAnyReceiver(false); | 71 functionTemplate->SetAcceptAnyReceiver(false); |
| 80 } | 72 } |
| 81 } | 73 } |
| 82 return functionTemplate; | 74 return functionTemplate; |
| 83 } | 75 } |
| 84 | 76 |
| 85 v8::Local<v8::Function> functionOrTemplate(v8::Isolate* isolate, v8::FunctionCal lback callback, const WrapperTypeInfo*, v8::Local<v8::Signature>, int length, v8 ::Local<v8::Object> prototypeForOverloadResolution) | 77 void installAccessorInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8 ::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const V8DOMConfiguration::AccessorConfiguration& accessor, const DOMWrapperWorld& wor ld) |
| 86 { | |
| 87 return callback ? v8::Function::New(isolate, callback, v8::Local<v8::Value>( ), length) : v8::Local<v8::Function>(); | |
| 88 } | |
| 89 | |
| 90 template<class ObjectOrTemplate> | |
| 91 void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> p rototypeOrTemplate, v8::Local<v8::Signature> signature, const V8DOMConfiguration ::AccessorConfiguration& accessor, const DOMWrapperWorld& world) | |
| 92 { | 78 { |
| 93 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script | 79 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script |
| 94 && !world.isPrivateScriptIsolatedWorld()) | 80 && !world.isPrivateScriptIsolatedWorld()) |
| 95 return; | 81 return; |
| 96 | 82 |
| 83 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); | |
| 97 v8::FunctionCallback getterCallback = accessor.getter; | 84 v8::FunctionCallback getterCallback = accessor.getter; |
| 98 v8::FunctionCallback setterCallback = accessor.setter; | 85 v8::FunctionCallback setterCallback = accessor.setter; |
| 99 if (world.isMainWorld()) { | 86 if (world.isMainWorld()) { |
| 100 if (accessor.getterForMainWorld) | 87 if (accessor.getterForMainWorld) |
| 101 getterCallback = accessor.getterForMainWorld; | 88 getterCallback = accessor.getterForMainWorld; |
| 102 if (accessor.setterForMainWorld) | 89 if (accessor.setterForMainWorld) |
| 103 setterCallback = accessor.setterForMainWorld; | 90 setterCallback = accessor.setterForMainWorld; |
| 104 } | 91 } |
| 105 // Support [LenientThis] by not specifying the signature. V8 does not do | 92 // Support [LenientThis] by not specifying the signature. V8 does not do |
| 106 // the type checking against holder if no signature is specified. Note that | 93 // the type checking against holder if no signature is specified. Note that |
| 107 // info.Holder() passed to callbacks will be *unsafe*. | 94 // info.Holder() passed to callbacks will be *unsafe*. |
| 108 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) | 95 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) |
| 109 signature = v8::Local<v8::Signature>(); | 96 signature = v8::Local<v8::Signature>(); |
| 110 prototypeOrTemplate->SetAccessorProperty( | 97 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); |
| 111 v8AtomicString(isolate, accessor.name), | 98 v8::Local<v8::FunctionTemplate> getter = createAccessorFunctionTemplate(isol ate, getterCallback, data, signature, 0); |
| 112 functionOrTemplate(isolate, getterCallback, accessor.data, signature, 0, prototypeOrTemplate), | 99 v8::Local<v8::FunctionTemplate> setter = createAccessorFunctionTemplate(isol ate, setterCallback, data, signature, 1); |
| 113 functionOrTemplate(isolate, setterCallback, accessor.data, signature, 1, prototypeOrTemplate), | 100 |
| 114 accessor.attribute, | 101 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) |
| 115 accessor.settings); | 102 instanceTemplate->SetAccessorProperty(name, getter, setter, accessor.att ribute, accessor.settings); |
| 103 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype ) | |
|
haraken
2015/06/17 16:31:21
Ditto.
| |
| 104 prototypeTemplate->SetAccessorProperty(name, getter, setter, accessor.at tribute, accessor.settings); | |
| 105 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) | |
|
haraken
2015/06/17 16:31:21
Ditto.
| |
| 106 interfaceTemplate->SetAccessorProperty(name, getter, setter, accessor.at tribute, accessor.settings); | |
|
bashi
2015/06/18 02:16:26
Add ASSERT()?
Yuki
2015/06/18 07:44:40
Added ASSERT(accessor.propertyLocationConfiguratio
| |
| 116 } | 107 } |
| 117 | 108 |
| 118 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant) | 109 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant) |
| 119 { | 110 { |
| 120 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); | 111 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); |
| 121 v8::PropertyAttribute attributes = | 112 v8::PropertyAttribute attributes = |
| 122 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 113 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 123 v8::Local<v8::Primitive> value; | 114 v8::Local<v8::Primitive> value; |
| 124 switch (constant.type) { | 115 switch (constant.type) { |
| 125 case V8DOMConfiguration::ConstantTypeShort: | 116 case V8DOMConfiguration::ConstantTypeShort: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 for (size_t i = 0; i < attributeCount; ++i) | 165 for (size_t i = 0; i < attributeCount; ++i) |
| 175 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world); | 166 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world); |
| 176 } | 167 } |
| 177 | 168 |
| 178 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob jectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeConfiguration& attribute) | 169 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob jectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const AttributeConfiguration& attribute) |
| 179 { | 170 { |
| 180 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 171 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 181 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attri bute, world); | 172 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attri bute, world); |
| 182 } | 173 } |
| 183 | 174 |
| 184 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob ject> instance, v8::Local<v8::Object> prototype, const AttributeConfiguration& a ttribute) | 175 void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Local<v8::Ob jectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> sig nature, const AccessorConfiguration* accessors, size_t accessorCount) |
| 185 { | |
| 186 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | |
| 187 installAttributeInternal(isolate, instance, prototype, attribute, world); | |
| 188 } | |
| 189 | |
| 190 void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Local<v8::Ob jectTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const Acces sorConfiguration* accessors, size_t accessorCount) | |
| 191 { | 176 { |
| 192 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 177 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 193 for (size_t i = 0; i < accessorCount; ++i) | 178 for (size_t i = 0; i < accessorCount; ++i) |
| 194 installAccessorInternal(isolate, prototypeTemplate, signature, accessors [i], world); | 179 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, in terfaceTemplate, signature, accessors[i], world); |
| 195 } | 180 } |
| 196 | 181 |
| 197 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ectTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const Access orConfiguration& accessor) | 182 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> sign ature, const AccessorConfiguration& accessor) |
| 198 { | 183 { |
| 199 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 184 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 200 installAccessorInternal(isolate, prototypeTemplate, signature, accessor, wor ld); | 185 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interf aceTemplate, signature, accessor, world); |
| 201 } | |
| 202 | |
| 203 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ect> prototype, const AccessorConfiguration& accessor) | |
| 204 { | |
| 205 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | |
| 206 installAccessorInternal(isolate, prototype, v8::Local<v8::Signature>(), acce ssor, world); | |
| 207 } | 186 } |
| 208 | 187 |
| 209 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempl ate, const ConstantConfiguration* constants, size_t constantCount) | 188 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempl ate, const ConstantConfiguration* constants, size_t constantCount) |
| 210 { | 189 { |
| 211 for (size_t i = 0; i < constantCount; ++i) | 190 for (size_t i = 0; i < constantCount; ++i) |
| 212 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]); | 191 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]); |
| 213 } | 192 } |
| 214 | 193 |
| 215 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration& constant) | 194 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration& constant) |
| 216 { | 195 { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 // Marks the prototype object as one of native-backed objects. | 244 // Marks the prototype object as one of native-backed objects. |
| 266 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. | 245 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. |
| 267 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. | 246 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. |
| 268 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 247 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
| 269 } | 248 } |
| 270 | 249 |
| 271 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); | 250 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); |
| 272 if (attributeCount) | 251 if (attributeCount) |
| 273 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); | 252 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount); |
| 274 if (accessorCount) | 253 if (accessorCount) |
| 275 installAccessors(isolate, prototypeTemplate, defaultSignature, accessors , accessorCount); | 254 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD escriptor, defaultSignature, accessors, accessorCount); |
| 276 if (callbackCount) | 255 if (callbackCount) |
| 277 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast <v8::PropertyAttribute>(v8::None), callbacks, callbackCount); | 256 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast <v8::PropertyAttribute>(v8::None), callbacks, callbackCount); |
| 278 return defaultSignature; | 257 return defaultSignature; |
| 279 } | 258 } |
| 280 | 259 |
| 281 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) | 260 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate * isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v 8::Local<v8::FunctionTemplate>, v8::Isolate*)) |
| 282 { | 261 { |
| 283 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 262 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 284 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); | 263 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); |
| 285 if (!result.IsEmpty()) | 264 if (!result.IsEmpty()) |
| 286 return result; | 265 return result; |
| 287 | 266 |
| 288 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); | 267 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); |
| 289 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); | 268 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); |
| 290 configureDOMClassTemplate(result, isolate); | 269 configureDOMClassTemplate(result, isolate); |
| 291 data->setDOMTemplate(wrapperTypeInfo, result); | 270 data->setDOMTemplate(wrapperTypeInfo, result); |
| 292 return result; | 271 return result; |
| 293 } | 272 } |
| 294 | 273 |
| 295 } // namespace blink | 274 } // namespace blink |
| OLD | NEW |