Index: Source/bindings/core/v8/V8DOMConfiguration.h |
diff --git a/Source/bindings/core/v8/V8DOMConfiguration.h b/Source/bindings/core/v8/V8DOMConfiguration.h |
index 42d85dcbecd53d7934f031b9d48289849b73708d..0bc95f594bd54361f3952e709cdb02e01dd87cba 100644 |
--- a/Source/bindings/core/v8/V8DOMConfiguration.h |
+++ b/Source/bindings/core/v8/V8DOMConfiguration.h |
@@ -68,6 +68,25 @@ public: |
InstanceOrPrototypeConfiguration instanceOrPrototypeConfiguration; |
}; |
+ static void installAttributes(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration* attributes, size_t attributeCount) |
haraken
2015/02/16 13:23:20
Can we uninline all of these methods? I don't thin
Yuki
2015/02/16 15:02:05
Done.
|
+ { |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ for (size_t i = 0; i < attributeCount; ++i) |
+ installAttributeInternal(isolate, instanceTemplate, prototype, attributes[i], world); |
+ } |
+ |
+ static void installAttribute(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration& attribute) |
+ { |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ installAttributeInternal(isolate, instanceTemplate, prototype, attribute, world); |
+ } |
+ |
+ static void installAttribute(v8::Isolate* isolate, v8::Handle<v8::Object> instanceTemplate, v8::Handle<v8::Object> prototype, const AttributeConfiguration& attribute) |
+ { |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ installAttributeInternal(isolate, instanceTemplate, prototype, attribute, world); |
+ } |
+ |
// AccessorConfiguration translates into calls to SetAccessorProperty() |
// on prototype ObjectTemplate. |
struct AccessorConfiguration { |
@@ -82,29 +101,17 @@ public: |
ExposeConfiguration exposeConfiguration; |
}; |
- static void installAttributes(v8::Isolate*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount); |
- |
- template<class ObjectOrTemplate> |
- static inline void installAttribute(v8::Handle<ObjectOrTemplate> instanceTemplate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute, v8::Isolate* isolate) |
+ static void installAccessors(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount) |
{ |
- DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
- if (attribute.exposeConfiguration == OnlyExposedToPrivateScript && !world.isPrivateScriptIsolatedWorld()) |
- return; |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ for (size_t i = 0; i < accessorCount; ++i) |
+ installAccessorInternal(isolate, prototype, signature, accessors[i], world); |
+ } |
- v8::AccessorGetterCallback getter = attribute.getter; |
- v8::AccessorSetterCallback setter = attribute.setter; |
- if (world.isMainWorld()) { |
- if (attribute.getterForMainWorld) |
- getter = attribute.getterForMainWorld; |
- if (attribute.setterForMainWorld) |
- setter = attribute.setterForMainWorld; |
- } |
- (attribute.instanceOrPrototypeConfiguration == OnPrototype ? prototype : instanceTemplate)->SetAccessor(v8AtomicString(isolate, attribute.name), |
- getter, |
- setter, |
- v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)), |
- attribute.settings, |
- attribute.attribute); |
+ static void installAccessor(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorConfiguration& accessor) |
+ { |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ installAccessorInternal(isolate, prototype, signature, accessor, world); |
} |
enum ConstantType { |
@@ -128,8 +135,25 @@ public: |
ConstantType type; |
}; |
- static void installConstants(v8::Isolate*, v8::Handle<v8::FunctionTemplate>, v8::Handle<v8::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount); |
- static void installConstant(v8::Isolate*, v8::Handle<v8::FunctionTemplate>, v8::Handle<v8::ObjectTemplate>, const char* name, v8::AccessorGetterCallback); |
+ static void installConstants(v8::Isolate* isolate, v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfiguration* constants, size_t constantCount) |
+ { |
+ for (size_t i = 0; i < constantCount; ++i) |
+ installConstantInternal(isolate, functionDescriptor, prototype, constants[i]); |
+ } |
+ |
+ static void installConstant(v8::Isolate* isolate, v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfiguration& constant) |
+ { |
+ installConstantInternal(isolate, functionDescriptor, prototype, constant); |
+ } |
+ |
+ static void installConstantWithGetter(v8::Isolate* isolate, v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const char* name, v8::AccessorGetterCallback getter) |
+ { |
+ v8::Handle<v8::String> constantName = v8AtomicString(isolate, name); |
+ v8::PropertyAttribute attributes = |
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
+ functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Value>(), attributes); |
+ prototype->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Value>(), attributes); |
+ } |
// MethodConfiguration translates into calls to Set() for setting up an |
// object's callbacks. It sets the method on both the FunctionTemplate or |
@@ -162,21 +186,20 @@ public: |
ExposeConfiguration exposeConfiguration; |
}; |
- static void installMethods(v8::Isolate*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCount); |
+ static void installMethods(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute, const MethodConfiguration* callbacks, size_t callbackCount) |
+ { |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ for (size_t i = 0; i < callbackCount; ++i) |
+ installMethodInternal(isolate, prototype, signature, attribute, callbacks[i], world); |
+ } |
template <class ObjectOrTemplate, class Configuration> |
- static void installMethod(v8::Handle<ObjectOrTemplate> objectOrTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute, const Configuration& callback, v8::Isolate* isolate) |
+ static void installMethod(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> objectOrTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute, const Configuration& callback) |
{ |
- DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
- if (callback.exposeConfiguration == OnlyExposedToPrivateScript && !world.isPrivateScriptIsolatedWorld()) |
- return; |
- |
- v8::Local<v8::FunctionTemplate> functionTemplate = functionTemplateForCallback(isolate, signature, callback.callbackForWorld(world), callback.length); |
- setMethod(objectOrTemplate, callback.methodName(isolate), functionTemplate, attribute); |
+ const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); |
+ installMethodInternal(isolate, objectOrTemplate, signature, attribute, callback, world); |
} |
- static void installAccessors(v8::Isolate*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Signature>, const AccessorConfiguration*, size_t accessorCount); |
- |
static v8::Local<v8::Signature> installDOMClassTemplate(v8::Isolate*, v8::Local<v8::FunctionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parentClass, size_t fieldCount, |
const AttributeConfiguration*, size_t attributeCount, |
const AccessorConfiguration*, size_t accessorCount, |
@@ -185,6 +208,25 @@ public: |
static v8::Handle<v8::FunctionTemplate> domClassTemplate(v8::Isolate*, WrapperTypeInfo*, void (*)(v8::Local<v8::FunctionTemplate>, v8::Isolate*)); |
private: |
+ template<class ObjectOrTemplate> |
+ static void installAttributeInternal(v8::Isolate*, v8::Handle<ObjectOrTemplate> instanceTemplate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration&, const DOMWrapperWorld&); |
+ |
+ static void installAccessorInternal(v8::Isolate*, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature>, const AccessorConfiguration&, const DOMWrapperWorld&); |
+ |
+ static void installConstantInternal(v8::Isolate*, v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfiguration&); |
+ |
+ template<class ObjectOrTemplate, class Configuration> |
+ static void installMethodInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> objectOrTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attribute, const Configuration& callback, const DOMWrapperWorld& world) |
+ { |
+ if (callback.exposeConfiguration == OnlyExposedToPrivateScript |
+ && !world.isPrivateScriptIsolatedWorld()) |
+ return; |
+ |
+ v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, callback.callbackForWorld(world), v8Undefined(), signature, callback.length); |
+ functionTemplate->RemovePrototype(); |
+ setMethod(objectOrTemplate, callback.methodName(isolate), functionTemplate, attribute); |
+ } |
+ |
static void setMethod(v8::Handle<v8::Object> target, v8::Handle<v8::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAttribute attribute) |
{ |
target->Set(name, functionTemplate->GetFunction()); |
@@ -197,8 +239,6 @@ private: |
{ |
target->Set(name, functionTemplate, attribute); |
} |
- |
- static v8::Handle<v8::FunctionTemplate> functionTemplateForCallback(v8::Isolate*, v8::Handle<v8::Signature>, v8::FunctionCallback, int length); |
}; |
} // namespace blink |