#ifndef V8DOMConfiguration_h
#define V8DOMConfiguration_h
#include "bindings/v8/V8DOMWrapper.h"
#include <v8.h>
namespace WebCore {
class V8DOMConfiguration {
public:
struct AttributeConfiguration {
const char* const name;
v8::AccessorGetterCallback getter;
v8::AccessorSetterCallback setter;
v8::AccessorGetterCallback getterForMainWorld;
v8::AccessorSetterCallback setterForMainWorld;
const WrapperTypeInfo* data;
v8::AccessControl settings;
v8::PropertyAttribute attribute;
bool onPrototype;
};
struct AccessorConfiguration {
const char* const name;
v8::FunctionCallback getter;
v8::FunctionCallback setter;
v8::FunctionCallback getterForMainWorld;
v8::FunctionCallback setterForMainWorld;
const WrapperTypeInfo* data;
v8::AccessControl settings;
v8::PropertyAttribute attribute;
};
static void installAttributes(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::ObjectTemplate>, const AttributeConfiguration*, size_t attributeCount, v8::Isolate*);
template<class ObjectOrTemplate>
static inline void installAttribute(v8::Handle<ObjectOrTemplate> instanceTemplate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute, v8::Isolate* isolate)
{
v8::AccessorGetterCallback getter = attribute.getter;
v8::AccessorSetterCallback setter = attribute.setter;
if (DOMWrapperWorld::current(isolate).isMainWorld()) {
if (attribute.getterForMainWorld)
getter = attribute.getterForMainWorld;
if (attribute.setterForMainWorld)
setter = attribute.setterForMainWorld;
}
(attribute.onPrototype ? prototype : instanceTemplate)->SetAccessor(v8::String::NewFromUtf8(isolate, attribute.name, v8::String::kInternalizedString),
getter,
setter,
v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)),
attribute.settings,
attribute.attribute);
}
struct ConstantConfiguration {
const char* const name;
int value;
};
static void installConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8::ObjectTemplate>, const ConstantConfiguration*, size_t constantCount, v8::Isolate*);
struct MethodConfiguration {
const char* const name;
v8::FunctionCallback callback;
v8::FunctionCallback callbackForMainWorld;
int length;
};
static void installCallbacks(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Signature>, v8::PropertyAttribute, const MethodConfiguration*, size_t callbackCount, v8::Isolate*);
static void installAccessors(v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Signature>, const AccessorConfiguration*, size_t accessorCount, v8::Isolate*);
static v8::Local<v8::Signature> installDOMClassTemplate(v8::Handle<v8::FunctionTemplate>, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parentClass, size_t fieldCount,
const AttributeConfiguration*, size_t attributeCount,
const AccessorConfiguration*, size_t accessorCount,
const MethodConfiguration*, size_t callbackCount,
v8::Isolate*);
};
}
#endif