| 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 ASSERT(attribute.propertyLocationConfiguration); |
| 68 instanceOrTemplate; | 57 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance
) |
| 69 setAccessor(isolate, target, v8AtomicString(isolate, attribute.name), getter
, setter, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data
)), attribute.settings, attribute.attribute); | 58 instanceTemplate->SetAccessor(name, getter, setter, data, attribute.sett
ings, attribute.attribute); |
| 59 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp
e) |
| 60 prototypeTemplate->SetAccessor(name, getter, setter, data, attribute.set
tings, attribute.attribute); |
| 61 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac
e) |
| 62 ASSERT_NOT_REACHED(); |
| 70 } | 63 } |
| 71 | 64 |
| 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) | 65 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 { | 66 { |
| 74 v8::Local<v8::FunctionTemplate> functionTemplate; | 67 v8::Local<v8::FunctionTemplate> functionTemplate; |
| 75 if (callback) { | 68 if (callback) { |
| 76 functionTemplate = v8::FunctionTemplate::New(isolate, callback, v8::Exte
rnal::New(isolate, const_cast<WrapperTypeInfo*>(wrapperTypeInfo)), signature, le
ngth); | 69 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, si
gnature, length); |
| 77 if (!functionTemplate.IsEmpty()) { | 70 if (!functionTemplate.IsEmpty()) { |
| 78 functionTemplate->RemovePrototype(); | 71 functionTemplate->RemovePrototype(); |
| 79 functionTemplate->SetAcceptAnyReceiver(false); | 72 functionTemplate->SetAcceptAnyReceiver(false); |
| 80 } | 73 } |
| 81 } | 74 } |
| 82 return functionTemplate; | 75 return functionTemplate; |
| 83 } | 76 } |
| 84 | 77 |
| 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) | 78 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 { | 79 { |
| 93 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate
Script | 80 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate
Script |
| 94 && !world.isPrivateScriptIsolatedWorld()) | 81 && !world.isPrivateScriptIsolatedWorld()) |
| 95 return; | 82 return; |
| 96 | 83 |
| 84 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); |
| 97 v8::FunctionCallback getterCallback = accessor.getter; | 85 v8::FunctionCallback getterCallback = accessor.getter; |
| 98 v8::FunctionCallback setterCallback = accessor.setter; | 86 v8::FunctionCallback setterCallback = accessor.setter; |
| 99 if (world.isMainWorld()) { | 87 if (world.isMainWorld()) { |
| 100 if (accessor.getterForMainWorld) | 88 if (accessor.getterForMainWorld) |
| 101 getterCallback = accessor.getterForMainWorld; | 89 getterCallback = accessor.getterForMainWorld; |
| 102 if (accessor.setterForMainWorld) | 90 if (accessor.setterForMainWorld) |
| 103 setterCallback = accessor.setterForMainWorld; | 91 setterCallback = accessor.setterForMainWorld; |
| 104 } | 92 } |
| 105 // Support [LenientThis] by not specifying the signature. V8 does not do | 93 // Support [LenientThis] by not specifying the signature. V8 does not do |
| 106 // the type checking against holder if no signature is specified. Note that | 94 // the type checking against holder if no signature is specified. Note that |
| 107 // info.Holder() passed to callbacks will be *unsafe*. | 95 // info.Holder() passed to callbacks will be *unsafe*. |
| 108 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde
r) | 96 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde
r) |
| 109 signature = v8::Local<v8::Signature>(); | 97 signature = v8::Local<v8::Signature>(); |
| 110 prototypeOrTemplate->SetAccessorProperty( | 98 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp
eInfo*>(accessor.data)); |
| 111 v8AtomicString(isolate, accessor.name), | 99 v8::Local<v8::FunctionTemplate> getter = createAccessorFunctionTemplate(isol
ate, getterCallback, data, signature, 0); |
| 112 functionOrTemplate(isolate, getterCallback, accessor.data, signature, 0,
prototypeOrTemplate), | 100 v8::Local<v8::FunctionTemplate> setter = createAccessorFunctionTemplate(isol
ate, setterCallback, data, signature, 1); |
| 113 functionOrTemplate(isolate, setterCallback, accessor.data, signature, 1,
prototypeOrTemplate), | 101 |
| 114 accessor.attribute, | 102 ASSERT(accessor.propertyLocationConfiguration); |
| 115 accessor.settings); | 103 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) |
| 104 instanceTemplate->SetAccessorProperty(name, getter, setter, accessor.att
ribute, accessor.settings); |
| 105 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype
) |
| 106 prototypeTemplate->SetAccessorProperty(name, getter, setter, accessor.at
tribute, accessor.settings); |
| 107 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface
) |
| 108 interfaceTemplate->SetAccessorProperty(name, getter, setter, accessor.at
tribute, accessor.settings); |
| 116 } | 109 } |
| 117 | 110 |
| 118 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat
e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8
DOMConfiguration::ConstantConfiguration& constant) | 111 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat
e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8
DOMConfiguration::ConstantConfiguration& constant) |
| 119 { | 112 { |
| 120 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); | 113 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); |
| 121 v8::PropertyAttribute attributes = | 114 v8::PropertyAttribute attributes = |
| 122 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 115 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 123 v8::Local<v8::Primitive> value; | 116 v8::Local<v8::Primitive> value; |
| 124 switch (constant.type) { | 117 switch (constant.type) { |
| 125 case V8DOMConfiguration::ConstantTypeShort: | 118 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) | 167 for (size_t i = 0; i < attributeCount; ++i) |
| 175 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a
ttributes[i], world); | 168 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a
ttributes[i], world); |
| 176 } | 169 } |
| 177 | 170 |
| 178 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob
jectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate,
const AttributeConfiguration& attribute) | 171 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob
jectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate,
const AttributeConfiguration& attribute) |
| 179 { | 172 { |
| 180 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 173 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 181 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attri
bute, world); | 174 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attri
bute, world); |
| 182 } | 175 } |
| 183 | 176 |
| 184 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob
ject> instance, v8::Local<v8::Object> prototype, const AttributeConfiguration& a
ttribute) | 177 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 { | 178 { |
| 192 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 179 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 193 for (size_t i = 0; i < accessorCount; ++i) | 180 for (size_t i = 0; i < accessorCount; ++i) |
| 194 installAccessorInternal(isolate, prototypeTemplate, signature, accessors
[i], world); | 181 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, in
terfaceTemplate, signature, accessors[i], world); |
| 195 } | 182 } |
| 196 | 183 |
| 197 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj
ectTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const Access
orConfiguration& accessor) | 184 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 { | 185 { |
| 199 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); | 186 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
| 200 installAccessorInternal(isolate, prototypeTemplate, signature, accessor, wor
ld); | 187 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 } | 188 } |
| 208 | 189 |
| 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) | 190 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 { | 191 { |
| 211 for (size_t i = 0; i < constantCount; ++i) | 192 for (size_t i = 0; i < constantCount; ++i) |
| 212 installConstantInternal(isolate, functionDescriptor, prototypeTemplate,
constants[i]); | 193 installConstantInternal(isolate, functionDescriptor, prototypeTemplate,
constants[i]); |
| 213 } | 194 } |
| 214 | 195 |
| 215 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun
ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla
te, const ConstantConfiguration& constant) | 196 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun
ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla
te, const ConstantConfiguration& constant) |
| 216 { | 197 { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Marks the prototype object as one of native-backed objects. | 246 // 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. | 247 // 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. | 248 // This doesn't mark kinds "root" classes like Node, where setting this
changes prototype chain structure. |
| 268 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); | 249 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount); |
| 269 } | 250 } |
| 270 | 251 |
| 271 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func
tionDescriptor); | 252 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func
tionDescriptor); |
| 272 if (attributeCount) | 253 if (attributeCount) |
| 273 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut
es, attributeCount); | 254 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut
es, attributeCount); |
| 274 if (accessorCount) | 255 if (accessorCount) |
| 275 installAccessors(isolate, prototypeTemplate, defaultSignature, accessors
, accessorCount); | 256 installAccessors(isolate, instanceTemplate, prototypeTemplate, functionD
escriptor, defaultSignature, accessors, accessorCount); |
| 276 if (callbackCount) | 257 if (callbackCount) |
| 277 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast
<v8::PropertyAttribute>(v8::None), callbacks, callbackCount); | 258 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast
<v8::PropertyAttribute>(v8::None), callbacks, callbackCount); |
| 278 return defaultSignature; | 259 return defaultSignature; |
| 279 } | 260 } |
| 280 | 261 |
| 281 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate
* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v
8::Local<v8::FunctionTemplate>, v8::Isolate*)) | 262 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolate
* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)(v
8::Local<v8::FunctionTemplate>, v8::Isolate*)) |
| 282 { | 263 { |
| 283 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 264 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 284 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy
peInfo); | 265 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy
peInfo); |
| 285 if (!result.IsEmpty()) | 266 if (!result.IsEmpty()) |
| 286 return result; | 267 return result; |
| 287 | 268 |
| 288 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); | 269 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); |
| 289 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons
tructorMode); | 270 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons
tructorMode); |
| 290 configureDOMClassTemplate(result, isolate); | 271 configureDOMClassTemplate(result, isolate); |
| 291 data->setDOMTemplate(wrapperTypeInfo, result); | 272 data->setDOMTemplate(wrapperTypeInfo, result); |
| 292 return result; | 273 return result; |
| 293 } | 274 } |
| 294 | 275 |
| 295 } // namespace blink | 276 } // namespace blink |
| OLD | NEW |