Index: Source/bindings/core/v8/V8DOMConfiguration.cpp |
diff --git a/Source/bindings/core/v8/V8DOMConfiguration.cpp b/Source/bindings/core/v8/V8DOMConfiguration.cpp |
index 775d9340d5edb3dc42d5e52a844fd7121737f33b..dd00d75801bbb9b15bc339f76bb1025c96b7c809 100644 |
--- a/Source/bindings/core/v8/V8DOMConfiguration.cpp |
+++ b/Source/bindings/core/v8/V8DOMConfiguration.cpp |
@@ -34,102 +34,6 @@ |
namespace blink { |
-void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration* attributes, size_t attributeCount) |
-{ |
- for (size_t i = 0; i < attributeCount; ++i) |
- installAttribute(instanceTemplate, prototype, attributes[i], isolate); |
-} |
- |
-void V8DOMConfiguration::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); |
- for (size_t i = 0; i < accessorCount; ++i) { |
- if (accessors[i].exposeConfiguration == OnlyExposedToPrivateScript && !world.isPrivateScriptIsolatedWorld()) |
- continue; |
- |
- v8::FunctionCallback getterCallback = accessors[i].getter; |
- v8::FunctionCallback setterCallback = accessors[i].setter; |
- if (world.isMainWorld()) { |
- if (accessors[i].getterForMainWorld) |
- getterCallback = accessors[i].getterForMainWorld; |
- if (accessors[i].setterForMainWorld) |
- setterCallback = accessors[i].setterForMainWorld; |
- } |
- |
- v8::Local<v8::FunctionTemplate> getter; |
- if (getterCallback) { |
- getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 0); |
- getter->RemovePrototype(); |
- } |
- v8::Local<v8::FunctionTemplate> setter; |
- if (setterCallback) { |
- setter = v8::FunctionTemplate::New(isolate, setterCallback, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessors[i].data)), signature, 1); |
- setter->RemovePrototype(); |
- } |
- prototype->SetAccessorProperty(v8AtomicString(isolate, accessors[i].name), getter, setter, accessors[i].attribute, accessors[i].settings); |
- } |
-} |
- |
-// Constant installation |
haraken
2015/02/16 13:23:20
Can we keep this comment?
Yuki
2015/02/16 15:02:05
Done.
|
-// |
-// installConstants() is be used for simple constants. It installs constants |
-// using v8::Template::Set(), which results in a property that is much faster to |
-// access from scripts. |
-// installConstant() is used when some C++ code needs to be executed when the |
-// constant is accessed, e.g. to handle deprecation or measuring usage. The |
-// property appears the same to scripts, but is slower to access. |
- |
-void V8DOMConfiguration::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) { |
- const ConstantConfiguration* constant = &constants[i]; |
- v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant->name); |
- switch (constant->type) { |
- case ConstantTypeShort: |
- case ConstantTypeLong: |
- case ConstantTypeUnsignedShort: |
- functionDescriptor->Set(constantName, v8::Integer::New(isolate, constant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- prototype->Set(constantName, v8::Integer::New(isolate, constant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- break; |
- case ConstantTypeUnsignedLong: |
- functionDescriptor->Set(constantName, v8::Integer::NewFromUnsigned(isolate, constant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- prototype->Set(constantName, v8::Integer::NewFromUnsigned(isolate, constant->ivalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- break; |
- case ConstantTypeFloat: |
- case ConstantTypeDouble: |
- functionDescriptor->Set(constantName, v8::Number::New(isolate, constant->dvalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- prototype->Set(constantName, v8::Number::New(isolate, constant->dvalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- break; |
- case ConstantTypeString: |
- functionDescriptor->Set(constantName, v8::String::NewFromUtf8(isolate, constant->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- prototype->Set(constantName, v8::String::NewFromUtf8(isolate, constant->svalue), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- break; |
- default: |
- ASSERT_NOT_REACHED(); |
- } |
- } |
-} |
- |
-void V8DOMConfiguration::installConstant(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); |
- functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Value>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
- prototype->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Value>(), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
-} |
- |
-void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const MethodConfiguration* callbacks, size_t callbackCount) |
-{ |
- for (size_t i = 0; i < callbackCount; ++i) |
- installMethod(prototype, signature, attributes, callbacks[i], isolate); |
-} |
- |
-v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::functionTemplateForCallback(v8::Isolate* isolate, v8::Handle<v8::Signature> signature, v8::FunctionCallback callback, int length) |
-{ |
- v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, callback, v8Undefined(), signature, length); |
- functionTemplate->RemovePrototype(); |
- return functionTemplate; |
-} |
- |
v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Handle<v8::FunctionTemplate> parentClass, size_t fieldCount, |
const AttributeConfiguration* attributes, size_t attributeCount, |
const AccessorConfiguration* accessors, size_t accessorCount, |
@@ -171,4 +75,98 @@ v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat |
return result; |
} |
+template<class ObjectOrTemplate> |
+void V8DOMConfiguration::installAttributeInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> instanceTemplate, v8::Handle<ObjectOrTemplate> prototype, const AttributeConfiguration& attribute, const DOMWrapperWorld& world) |
+{ |
+ if (attribute.exposeConfiguration == OnlyExposedToPrivateScript |
+ && !world.isPrivateScriptIsolatedWorld()) |
+ return; |
+ |
+ 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; |
+ } |
+ v8::Handle<ObjectOrTemplate> target = |
+ attribute.instanceOrPrototypeConfiguration == OnPrototype ? |
+ prototype : |
+ instanceTemplate; |
+ target->SetAccessor( |
+ v8AtomicString(isolate, attribute.name), |
+ getter, |
+ setter, |
+ v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)), |
+ attribute.settings, |
+ attribute.attribute); |
+} |
+ |
+template |
+void V8DOMConfiguration::installAttributeInternal<v8::ObjectTemplate>(v8::Isolate*, v8::Handle<v8::ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration&, const DOMWrapperWorld&); |
+template |
+void V8DOMConfiguration::installAttributeInternal<v8::Object>(v8::Isolate*, v8::Handle<v8::Object> instanceTemplate, v8::Handle<v8::Object> prototype, const AttributeConfiguration&, const DOMWrapperWorld&); |
haraken
2015/02/16 13:23:20
Not related to your CL, I'm wondering why we need
Yuki
2015/02/16 15:02:04
ObjectTemplate version is used for the most cases.
|
+ |
+void V8DOMConfiguration::installAccessorInternal(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorConfiguration& accessor, const DOMWrapperWorld& world) |
+{ |
+ if (accessor.exposeConfiguration == OnlyExposedToPrivateScript |
+ && !world.isPrivateScriptIsolatedWorld()) |
+ return; |
+ |
+ v8::FunctionCallback getterCallback = accessor.getter; |
+ v8::FunctionCallback setterCallback = accessor.setter; |
+ if (world.isMainWorld()) { |
+ if (accessor.getterForMainWorld) |
+ getterCallback = accessor.getterForMainWorld; |
+ if (accessor.setterForMainWorld) |
+ setterCallback = accessor.setterForMainWorld; |
+ } |
+ v8::Local<v8::FunctionTemplate> getter; |
+ if (getterCallback) { |
+ getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 0); |
+ getter->RemovePrototype(); |
+ } |
+ v8::Local<v8::FunctionTemplate> setter; |
+ if (setterCallback) { |
+ setter = v8::FunctionTemplate::New(isolate, setterCallback, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 1); |
+ setter->RemovePrototype(); |
+ } |
+ prototype->SetAccessorProperty( |
+ v8AtomicString(isolate, accessor.name), |
+ getter, |
+ setter, |
+ accessor.attribute, |
+ accessor.settings); |
+} |
+ |
+void V8DOMConfiguration::installConstantInternal(v8::Isolate* isolate, v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const ConstantConfiguration& constant) |
+{ |
+ v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant.name); |
+ v8::PropertyAttribute attributes = |
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
+ v8::Handle<v8::Primitive> value; |
+ switch (constant.type) { |
+ case ConstantTypeShort: |
+ case ConstantTypeLong: |
+ case ConstantTypeUnsignedShort: |
+ value = v8::Integer::New(isolate, constant.ivalue); |
+ break; |
+ case ConstantTypeUnsignedLong: |
+ value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue); |
+ break; |
+ case ConstantTypeFloat: |
+ case ConstantTypeDouble: |
+ value = v8::Number::New(isolate, constant.dvalue); |
+ break; |
+ case ConstantTypeString: |
+ value = v8::String::NewFromUtf8(isolate, constant.svalue); |
+ break; |
+ default: |
+ ASSERT_NOT_REACHED(); |
+ } |
+ functionDescriptor->Set(constantName, value, attributes); |
+ prototype->Set(constantName, value, attributes); |
+} |
+ |
} // namespace blink |