| Index: Source/bindings/templates/attributes_wip.cpp
|
| diff --git a/Source/bindings/templates/attributes_wip.cpp b/Source/bindings/templates/attributes_wip.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f6f9433cf2eee7194a8cdee9053d3fd545f895d2
|
| --- /dev/null
|
| +++ b/Source/bindings/templates/attributes_wip.cpp
|
| @@ -0,0 +1,257 @@
|
| +{% from 'macros.cpp' import activity_logging, feature_observation, deprecation_notification, custom_element_invocation with context %}
|
| +
|
| +{% macro attribute_getter(attribute, for_main_world_suffix) %}
|
| +{% if not attribute.has_custom_getter %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| +static void {{attribute.name}}AttrGetter{{for_main_world_suffix}}(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
|
| +{
|
| +{% if attribute.compact_getter %}{## Generate super-compact call for regular attribute getter. FIXME: remove. this is dirty. #}
|
| + Element* imp = V8Element::toNative(info.Holder());
|
| + v8SetReturnValueString(info, {{attribute.getter_native_value_expression}}, info.GetIsolate());
|
| + return;
|
| +{% else %}{# compact getter #}
|
| +{% if not attribute.is_static %}
|
| + {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(info.Holder());
|
| +{% endif %}
|
| +{% if attribute.check_security_for_node %}
|
| + if (!BindingSecurity::shouldAllowAccessToNode(imp->{{attribute.cpp_name}}())) {
|
| + v8SetReturnValueNull(info);
|
| + return;
|
| + }
|
| +{% endif %}
|
| +{% if attribute.getter_use_exceptions %}
|
| + ExceptionState es(info.GetIsolate());
|
| +{% endif %}
|
| +{% if attribute.is_nullable %}
|
| + bool isNull = false;
|
| +{% endif %}
|
| +{% if attribute.script_execution_context %}
|
| + ScriptExecutionContext* scriptContext = getScriptExecutionContext();
|
| +{% endif %}
|
| +{% if attribute.is_nullable or attribute.getter_use_exceptions %}
|
| + {{attribute.assign_native_value_to_local_variable_statement | indent}}
|
| +{% endif %}
|
| +{% if attribute.is_nullable %}
|
| + if (isNull) {
|
| + v8SetReturnValueNull(info);
|
| + return;
|
| + }
|
| +{% endif %}
|
| +{% if attribute.getter_use_exceptions %}
|
| + if (UNLIKELY(es.throwIfNeeded()))
|
| + return;
|
| +{% endif %}
|
| +{% if attribute.should_keep_attribute_alive %}{###### should_keep_attribute_alive #}
|
| +{# FIXME: still partly Perl here: ${getterString} #}
|
| +{% if attribute.array_type %}
|
| + v8SetReturnValue(info, v8Array(${getterString}, info.GetIsolate()));
|
| + return;
|
| +{% else %}
|
| + {{attribute.native_type}} result = {{attribute.getter_native_value_expression}};
|
| +{% if for_main_world_suffix %}
|
| + v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper{{for_main_world_suffix}}(result.get())) : v8Undefined();
|
| +{% else %}
|
| + v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper<V8{{attribute.type}}>(result.get(), info.GetIsolate())) : v8Undefined();
|
| +{% endif %}
|
| + if (wrapper.IsEmpty()) {
|
| +{# FIXME: Could use wrap here since the wrapper is empty. #}
|
| + wrapper = toV8(result.get(), info.Holder(), info.GetIsolate());
|
| + if (!wrapper.IsEmpty())
|
| + V8HiddenPropertyName::setNamedHiddenReference(info.Holder(), "{{attribute.name}}", wrapper);
|
| + }
|
| + v8SetReturnValue(info, wrapper);
|
| + return;
|
| +{% endif %}{# array_type #}
|
| +{% else %}{# should_keep_attribute_alive #}
|
| +{% if (attribute.svg_animated_type or interface_name == "SVGViewSpec") and attribute.svg_type_needing_tear_off %}
|
| +{# Convert from abstract SVGProperty to real type, so the right toJS() method can be invoked. #}
|
| +{% if for_main_world_suffix == "ForMainWorld" %}
|
| + v8SetReturnValue(info, toV8ForMainWorld(static_cast<{{attribute.svg_type_needing_tear_off}}*>({{attribute.getter_native_value_expression}}), info.Holder(), info.GetIsolate()));
|
| +{% else %}
|
| + v8SetReturnValue(info, toV8Fast(static_cast<{{attribute.svg_type_needing_tear_off}}*>({{attribute.getter_native_value_expression}}), info, imp));
|
| +{% endif %}
|
| + return;
|
| +{% elif attribute.tear_off_and_not_list %}
|
| +{% if for_main_world_suffix == "ForMainWorld" %}
|
| + v8SetReturnValue(info, toV8ForMainWorld({{attribute.wrapped_value}}, info.Holder(), info.GetIsolate()));
|
| +{% else %}
|
| + v8SetReturnValue(info, toV8Fast({{attribute.wrapped_value}}, info, imp));
|
| +{% endif %}
|
| + return;
|
| +{% elif attribute.type == "SerializedScriptValue" and attribute.cached_attribute %}
|
| + RefPtr<SerializedScriptValue> serialized = imp->{{getter_function}}();
|
| + value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8::Null(info.GetIsolate()));
|
| + info.Holder()->SetHiddenValue(propertyName, value);
|
| + v8SetReturnValue(info, value);
|
| + return;
|
| +{% elif attribute.type == "EventListener" %}
|
| + EventListener* listener = imp->{{attribute.getter_function}}(isolatedWorldForIsolate(info.GetIsolate()));
|
| + v8SetReturnValue(info, listener ? v8::Handle<v8::Value>(V8AbstractEventListener::cast(listener)->getListenerObject(imp->scriptExecutionContext())) : v8::Handle<v8::Value>(v8::Null(info.GetIsolate())));
|
| + return;
|
| +{% else %}{# Main case #}
|
| + {{attribute.return_js_value_statements[for_main_world_suffix] | indent}}
|
| + return;
|
| +{% endif %}
|
| +{% endif %}{# should_keep_attribute_alive #}
|
| +{% endif %}{# compact getter #}
|
| +}
|
| +
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}
|
| +{% endif %}
|
| +{% endif %}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{##############################################################################}
|
| +{% macro attribute_getter_callback(attribute, for_main_world_suffix) %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| +static void {{attribute.name}}AttrGetterCallback{{for_main_world_suffix}}(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
|
| +{
|
| + TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
|
| +{{- feature_observation(attribute.measure_as)}}
|
| +{{- deprecation_notification(attribute.deprecate_as)}}
|
| +{% if for_main_world_suffix in attribute.getter_activity_logging %}
|
| +{{activity_logging("Getter", attribute.name)}}
|
| +{% endif %}
|
| +{% if attribute.has_custom_getter %}
|
| + {{v8_class_name}}::{{attribute.name}}AttrGetterCustom(name, info);
|
| +{% else %}
|
| + {{cpp_class_name}}V8Internal::{{attribute.name}}AttrGetter{{for_main_world_suffix}}(name, info);
|
| +{% endif %}
|
| + TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
|
| +}
|
| +
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}
|
| +{% endif %}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{##############################################################################}
|
| +{% macro attribute_setter(attribute, for_main_world_suffix) %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| +static void {{attribute.name}}AttrSetter{{for_main_world_suffix}}(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
| +{
|
| +{% if attribute.compact_setter %}{## Generate super-compact call for regular attribute setter. FIXME: remove. this is dirty. #}
|
| + Element* imp = V8Element::toNative(info.Holder());
|
| + V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, stringResource, value);
|
| + imp->setAttribute({{attribute.compact_setter_namespace}}::{{attribute.compact_setter_content_attribute_name}}Attr, stringResource);
|
| +{% else %}{# Compact setter #}
|
| +{% if not attribute.is_static %}
|
| + {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(info.Holder());
|
| +{% endif %}
|
| +{% if attribute.type == "EventListener" %}
|
| +{% if interface_name == "Window" %}
|
| + if (!imp->document())
|
| + return;
|
| +{% endif %}
|
| +{% else %}
|
| + {{attribute.assign_js_value_to_local_variable_statement | indent}}
|
| +{% endif %}
|
| +{{custom_element_invocation(attribute.custom_element_invocation_scope) -}}
|
| +{% if attribute.setter_use_exceptions %}
|
| + ExceptionState es(info.GetIsolate());
|
| +{% endif %}
|
| +{% if attribute.script_execution_context %}
|
| + ScriptExecutionContext* scriptContext = getScriptExecutionContext();
|
| +{% endif %}
|
| +{% if False %}{# TODO SVGNumber #}
|
| +{% elif attribute.type == "EventListener" %}{########### EventListener hack #}
|
| +{% if attribute.not_inherits_node %}
|
| + transferHiddenDependency(info.Holder(), imp->{{attribute.event_listener_setter_function_name_not_inherits_node}}(isolatedWorldForIsolate(info.GetIsolate())), value, {{v8_class_name}}::eventListenerCacheIndex, info.GetIsolate());
|
| +{% endif %}
|
| +{% if attribute.event_listener_on_error %}
|
| + imp->set{{attribute.event_listener_setter_function_name}}(V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(value, true), isolatedWorldForIsolate(info.GetIsolate()));
|
| +{% else %}
|
| + imp->set{{attribute.event_listener_setter_function_name}}(V8EventListenerList::getEventListener(value, true, ListenerFindOrCreate), isolatedWorldForIsolate(info.GetIsolate()));
|
| +{% endif %}
|
| +{% else %}
|
| + {{attribute.set_value_statement | indent}}
|
| +{% endif %}
|
| +{% if attribute.setter_use_exceptions %}
|
| + es.throwIfNeeded();
|
| +{% endif %}
|
| + return;
|
| +{% endif %}{# Compact setter #}
|
| +}
|
| +
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}
|
| +{% endif %}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{##############################################################################}
|
| +{% macro attribute_setter_callback(attribute, for_main_world_suffix) %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| +static void {{attribute.name}}AttrSetterCallback{{for_main_world_suffix}}(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
| +{
|
| + TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
|
| +{{feature_observation(attribute.measure_as) -}}
|
| +{{deprecation_notification(attribute.deprecate_as) -}}
|
| +{% if for_main_world_suffix in attribute.setter_activity_logging %}
|
| +{{activity_logging("Setter", attribute.name) -}}
|
| +{% endif %}
|
| +{{custom_element_invocation(attribute.custom_element_invocation_scope) -}}
|
| +{% if attribute.has_custom_setter %}
|
| + {{v8_class_name}}::{{attribute.name}}AttrSetterCustom(name, value, info);
|
| +{% else %}
|
| + {{cpp_class_name}}V8Internal::{{attribute.name}}AttrSetter{{for_main_world_suffix}}(name, value, info);
|
| +{% endif %}
|
| + TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
|
| +}
|
| +
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}
|
| +{% endif %}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{##############################################################################}
|
| +{# FIXME: instead pass a list of normal_attributes #}
|
| +{% macro batched_attribute() %}
|
| +static const V8DOMConfiguration::BatchedAttribute {{v8_class_name}}Attrs[] = {
|
| +{% for attribute in attributes %}
|
| +{% if attribute.is_normal %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| + // Attribute '{{attribute.name}}'
|
| + {{attribute.batched_attribute}}
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}
|
| +{% endif %}
|
| +{% endif %}
|
| +{% endfor %}
|
| +};
|
| +{% endmacro %}
|
| +
|
| +
|
| +{##############################################################################}
|
| +{# FIXME: instead pass a list of enabled_at_runtime_attributes #}
|
| +{% macro enabled_at_runtime_batched_attribute() %}
|
| +{% for attribute in attributes %}
|
| +{% if attribute.enabled_at_runtime %}
|
| +{% if attribute.conditional_string %}
|
| +#if {{attribute.conditional_string}}
|
| +{% endif %}
|
| + if ({{attribute.enable_function}}()) {
|
| + static const V8DOMConfiguration::BatchedAttribute attrData =\
|
| + // Attribute '{{attribute.name}}'
|
| + {{attribute.batched_attribute}}
|
| + V8DOMConfiguration::configureAttribute(instance, proto, attrData, isolate, currentWorldType);
|
| + }
|
| +{% if attribute.conditional_string %}
|
| +#endif // {{attribute.conditional_string}}{% endif %}
|
| +{% endif %}
|
| +{% endfor %}
|
| +{% endmacro %}
|
|
|