Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Unified Diff: Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 1181113006: bindings: Introduces on_{instance,prototype,interface} in the code generator. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/V8DOMConfiguration.cpp
diff --git a/Source/bindings/core/v8/V8DOMConfiguration.cpp b/Source/bindings/core/v8/V8DOMConfiguration.cpp
index ad487a8acca735300a0ec4bc8b706eb710bc32e7..46b46f5be8c8d3e9ca169bb3fb9127decb585590 100644
--- a/Source/bindings/core/v8/V8DOMConfiguration.cpp
+++ b/Source/bindings/core/v8/V8DOMConfiguration.cpp
@@ -36,24 +36,13 @@ namespace blink {
namespace {
-void setAccessor(v8::Isolate* isolate, v8::Local<v8::Object> target, v8::Local<v8::Name> name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSetterCallback setter, v8::Local<v8::Value> data, v8::AccessControl settings, v8::PropertyAttribute attribute)
-{
- v8::Maybe<bool> result = target->SetAccessor(isolate->GetCurrentContext(), name, getter, setter, v8::MaybeLocal<v8::Value>(data), settings, attribute);
- ASSERT_UNUSED(result, result.FromJust());
-}
-
-void setAccessor(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> target, v8::Local<v8::Name> name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSetterCallback setter, v8::Local<v8::Value> data, v8::AccessControl settings, v8::PropertyAttribute attribute)
-{
- target->SetAccessor(name, getter, setter, data, settings, attribute);
-}
-
-template<class ObjectOrTemplate>
-void installAttributeInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> instanceOrTemplate, v8::Local<ObjectOrTemplate> prototypeOrTemplate, const V8DOMConfiguration::AttributeConfiguration& attribute, const DOMWrapperWorld& world)
+void installAttributeInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8DOMConfiguration::AttributeConfiguration& attribute, const DOMWrapperWorld& world)
{
if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateScript
&& !world.isPrivateScriptIsolatedWorld())
return;
+ v8::Local<v8::Name> name = v8AtomicString(isolate, attribute.name);
v8::AccessorNameGetterCallback getter = attribute.getter;
v8::AccessorNameSetterCallback setter = attribute.setter;
if (world.isMainWorld()) {
@@ -62,18 +51,21 @@ void installAttributeInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate>
if (attribute.setterForMainWorld)
setter = attribute.setterForMainWorld;
}
- v8::Local<ObjectOrTemplate> target =
- attribute.instanceOrPrototypeConfiguration == V8DOMConfiguration::OnPrototype ?
- prototypeOrTemplate :
- instanceOrTemplate;
- setAccessor(isolate, target, v8AtomicString(isolate, attribute.name), getter, setter, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)), attribute.settings, attribute.attribute);
+ v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data));
+
+ if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance)
+ instanceTemplate->SetAccessor(name, getter, setter, data, attribute.settings, attribute.attribute);
+ if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype)
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
+ prototypeTemplate->SetAccessor(name, getter, setter, data, attribute.settings, attribute.attribute);
+ if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface)
haraken 2015/06/17 16:31:21 if => else if?
+ ASSERT_NOT_REACHED();
}
-v8::Local<v8::FunctionTemplate> functionOrTemplate(v8::Isolate* isolate, v8::FunctionCallback callback, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Signature> signature, int length, v8::Local<v8::ObjectTemplate> prototypeTemplateForOverloadResolution)
+v8::Local<v8::FunctionTemplate> createAccessorFunctionTemplate(v8::Isolate* isolate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
{
v8::Local<v8::FunctionTemplate> functionTemplate;
if (callback) {
- functionTemplate = v8::FunctionTemplate::New(isolate, callback, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(wrapperTypeInfo)), signature, length);
+ functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, signature, length);
if (!functionTemplate.IsEmpty()) {
functionTemplate->RemovePrototype();
functionTemplate->SetAcceptAnyReceiver(false);
@@ -82,18 +74,13 @@ v8::Local<v8::FunctionTemplate> functionOrTemplate(v8::Isolate* isolate, v8::Fun
return functionTemplate;
}
-v8::Local<v8::Function> functionOrTemplate(v8::Isolate* isolate, v8::FunctionCallback callback, const WrapperTypeInfo*, v8::Local<v8::Signature>, int length, v8::Local<v8::Object> prototypeForOverloadResolution)
-{
- return callback ? v8::Function::New(isolate, callback, v8::Local<v8::Value>(), length) : v8::Local<v8::Function>();
-}
-
-template<class ObjectOrTemplate>
-void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> prototypeOrTemplate, v8::Local<v8::Signature> signature, const V8DOMConfiguration::AccessorConfiguration& accessor, const DOMWrapperWorld& world)
+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& world)
{
if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateScript
&& !world.isPrivateScriptIsolatedWorld())
return;
+ v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name);
v8::FunctionCallback getterCallback = accessor.getter;
v8::FunctionCallback setterCallback = accessor.setter;
if (world.isMainWorld()) {
@@ -107,12 +94,16 @@ void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> p
// info.Holder() passed to callbacks will be *unsafe*.
if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder)
signature = v8::Local<v8::Signature>();
- prototypeOrTemplate->SetAccessorProperty(
- v8AtomicString(isolate, accessor.name),
- functionOrTemplate(isolate, getterCallback, accessor.data, signature, 0, prototypeOrTemplate),
- functionOrTemplate(isolate, setterCallback, accessor.data, signature, 1, prototypeOrTemplate),
- accessor.attribute,
- accessor.settings);
+ v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data));
+ v8::Local<v8::FunctionTemplate> getter = createAccessorFunctionTemplate(isolate, getterCallback, data, signature, 0);
+ v8::Local<v8::FunctionTemplate> setter = createAccessorFunctionTemplate(isolate, setterCallback, data, signature, 1);
+
+ if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance)
+ instanceTemplate->SetAccessorProperty(name, getter, setter, accessor.attribute, accessor.settings);
+ if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype)
haraken 2015/06/17 16:31:21 Ditto.
+ prototypeTemplate->SetAccessorProperty(name, getter, setter, accessor.attribute, accessor.settings);
+ if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface)
haraken 2015/06/17 16:31:21 Ditto.
+ interfaceTemplate->SetAccessorProperty(name, getter, setter, accessor.attribute, accessor.settings);
bashi 2015/06/18 02:16:26 Add ASSERT()?
Yuki 2015/06/18 07:44:40 Added ASSERT(accessor.propertyLocationConfiguratio
}
void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8DOMConfiguration::ConstantConfiguration& constant)
@@ -181,29 +172,17 @@ void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Ob
installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attribute, world);
}
-void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Local<v8::Object> instance, v8::Local<v8::Object> prototype, const AttributeConfiguration& attribute)
-{
- const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
- installAttributeInternal(isolate, instance, prototype, attribute, world);
-}
-
-void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount)
+void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount)
{
const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
for (size_t i = 0; i < accessorCount; ++i)
- installAccessorInternal(isolate, prototypeTemplate, signature, accessors[i], world);
-}
-
-void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::Signature> signature, const AccessorConfiguration& accessor)
-{
- const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
- installAccessorInternal(isolate, prototypeTemplate, signature, accessor, world);
+ installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, accessors[i], world);
}
-void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Object> prototype, const AccessorConfiguration& accessor)
+void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const AccessorConfiguration& accessor)
{
const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
- installAccessorInternal(isolate, prototype, v8::Local<v8::Signature>(), accessor, world);
+ installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, accessor, world);
}
void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const ConstantConfiguration* constants, size_t constantCount)
@@ -272,7 +251,7 @@ v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate
if (attributeCount)
installAttributes(isolate, instanceTemplate, prototypeTemplate, attributes, attributeCount);
if (accessorCount)
- installAccessors(isolate, prototypeTemplate, defaultSignature, accessors, accessorCount);
+ installAccessors(isolate, instanceTemplate, prototypeTemplate, functionDescriptor, defaultSignature, accessors, accessorCount);
if (callbackCount)
installMethods(isolate, prototypeTemplate, defaultSignature, static_cast<v8::PropertyAttribute>(v8::None), callbacks, callbackCount);
return defaultSignature;

Powered by Google App Engine
This is Rietveld 408576698