Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / templates / attributes.cpp
index 640fd79..0c2875b 100644 (file)
@@ -20,7 +20,7 @@ const v8::PropertyCallbackInfo<v8::Value>& info
     {# impl #}
     {% if attribute.cached_attribute_validation_method %}
     v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attribute.name}}");
-    {{cpp_class}}* impl = {{v8_class}}::toNative(holder);
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
     if (!impl->{{attribute.cached_attribute_validation_method}}()) {
         v8::Handle<v8::Value> v8Value = V8HiddenValue::getHiddenValue(info.GetIsolate(), holder, propertyName);
         if (!v8Value.IsEmpty()) {
@@ -29,7 +29,7 @@ const v8::PropertyCallbackInfo<v8::Value>& info
         }
     }
     {% elif not attribute.is_static %}
-    {{cpp_class}}* impl = {{v8_class}}::toNative(holder);
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
     {% endif %}
     {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %}
     if (!impl->document())
@@ -225,12 +225,12 @@ v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
     {% endif %}
     {# impl #}
     {% if attribute.put_forwards %}
-    {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(holder);
+    {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
     {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}());
     if (!impl)
         return;
     {% elif not attribute.is_static %}
-    {{cpp_class}}* impl = {{v8_class}}::toNative(holder);
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
     {% endif %}
     {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
     if (!impl->document())
@@ -265,7 +265,7 @@ v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
           (attribute.is_reflect and
            not(attribute.idl_type == 'DOMString' and is_node)) %}
     {# Skip on compact node DOMString getters #}
-    CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
+    CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
     {% endif %}
     {% if attribute.is_call_with_execution_context or
           attribute.is_setter_call_with_execution_context %}
@@ -313,20 +313,11 @@ v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackI
     {% else %}
     if (contextData && contextData->activityLogger()) {
     {% endif %}
-        {% if attribute.activity_logging_include_old_value_for_setter %}
-        {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder());
-        {% if attribute.cpp_value_original %}
-        {{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_original}});
-        {% endif %}
-        v8::Handle<v8::Value> originalValue = {{attribute.cpp_value_to_v8_value}};
-        contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute.name}}", v8Value, originalValue);
-        {% else %}
         contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute.name}}", v8Value);
-        {% endif %}
     }
     {% endif %}
     {% if attribute.is_custom_element_callbacks or attribute.is_reflect %}
-    CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
+    CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
     {% endif %}
     {% if attribute.has_custom_setter %}
     {{v8_class}}::{{attribute.name}}AttributeSetterCustom(v8Value, info);
@@ -347,10 +338,11 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame*
         return false;
     v8::HandleScope handleScope(toIsolate(frame));
     ScriptForbiddenScope::AllowUserAgentScript script;
-    v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
-    if (context.IsEmpty())
+    v8::Handle<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
+    if (contextInPrivateScript.IsEmpty())
         return false;
-    ScriptState* scriptState = ScriptState::from(context);
+    ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
+    ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
     if (!scriptState->executionContext())
         return false;
 
@@ -358,16 +350,9 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame*
     v8::Handle<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
 
     ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
-    v8::TryCatch block;
-    v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder);
-    if (block.HasCaught()) {
-        if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
-            // FIXME: We should support more exceptions.
-            RELEASE_ASSERT_NOT_REACHED();
-        }
-        block.ReThrow();
+    v8::Handle<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder);
+    if (v8Value.IsEmpty())
         return false;
-    }
     {{attribute.private_script_v8_value_to_local_cpp_value}};
     RELEASE_ASSERT(!exceptionState.hadException());
     *result = cppValue;
@@ -383,10 +368,11 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame*
         return false;
     v8::HandleScope handleScope(toIsolate(frame));
     ScriptForbiddenScope::AllowUserAgentScript script;
-    v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
-    if (context.IsEmpty())
+    v8::Handle<v8::Context> contextInPrivateScript = toV8Context(frame, DOMWrapperWorld::privateScriptIsolatedWorld());
+    if (contextInPrivateScript.IsEmpty())
         return false;
-    ScriptState* scriptState = ScriptState::from(context);
+    ScriptState* scriptState = ScriptState::from(contextInPrivateScript);
+    ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
     if (!scriptState->executionContext())
         return false;
 
@@ -394,16 +380,57 @@ bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame*
     v8::Handle<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global(), scriptState->isolate());
 
     ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
-    v8::TryCatch block;
-    PrivateScriptRunner::runDOMAttributeSetter(scriptState, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}});
-    if (block.HasCaught()) {
-        if (!PrivateScriptRunner::rethrowExceptionInPrivateScript(scriptState->isolate(), exceptionState, block)) {
-            // FIXME: We should support more exceptions.
-            RELEASE_ASSERT_NOT_REACHED();
-        }
-        block.ReThrow();
-        return false;
-    }
-    return true;
+    return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_script_cpp_value_to_v8_value}});
 }
 {% endmacro %}
+
+
+{##############################################################################}
+{% macro attribute_configuration(attribute) %}
+{% set getter_callback =
+       '%sV8Internal::%sAttributeGetterCallback' %
+            (cpp_class, attribute.name)
+       if not attribute.constructor_type else
+       ('%sV8Internal::%sConstructorGetterCallback' %
+            (cpp_class, attribute.name)
+        if attribute.needs_constructor_getter_callback else
+       '{0}V8Internal::{0}ConstructorGetter'.format(cpp_class)) %}
+{% set getter_callback_for_main_world =
+       '%sV8Internal::%sAttributeGetterCallbackForMainWorld' %
+            (cpp_class, attribute.name)
+       if attribute.is_per_world_bindings else '0' %}
+{% set setter_callback = attribute.setter_callback %}
+{% set setter_callback_for_main_world =
+       '%sV8Internal::%sAttributeSetterCallbackForMainWorld' %
+           (cpp_class, attribute.name)
+       if attribute.is_per_world_bindings and
+          (not attribute.is_read_only or attribute.put_forwards) else '0' %}
+{% set wrapper_type_info =
+       'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' %
+            attribute.constructor_type
+        if attribute.constructor_type else '0' %}
+{% set access_control = 'static_cast<v8::AccessControl>(%s)' %
+                        ' | '.join(attribute.access_control_list) %}
+{% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
+                            ' | '.join(attribute.property_attributes) %}
+{% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivateScript' if attribute.only_exposed_to_private_script else 'V8DOMConfiguration::ExposedToAllScripts' %}
+{% set on_prototype = 'V8DOMConfiguration::OnPrototype'
+       if interface_name == 'Window' and attribute.idl_type == 'EventHandler'
+       else 'V8DOMConfiguration::OnInstance' %}
+{% set attribute_configuration_list = [
+       '"%s"' % attribute.name,
+       getter_callback,
+       setter_callback,
+       getter_callback_for_main_world,
+       setter_callback_for_main_world,
+       wrapper_type_info,
+       access_control,
+       property_attribute,
+       only_exposed_to_private_script,
+   ] %}
+{% if not attribute.is_expose_js_accessors %}
+{% set attribute_configuration_list = attribute_configuration_list
+                                    + [on_prototype] %}
+{% endif %}
+{{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
+{%- endmacro %}