1 {##############################################################################}
2 {% macro attribute_getter(attribute, world_suffix) %}
3 {% filter conditional(attribute.conditional_string) %}
4 static void {{attribute.name}}AttributeGetter{{world_suffix}}(
5 {%- if attribute.is_expose_js_accessors %}
6 const v8::FunctionCallbackInfo<v8::Value>& info
8 const v8::PropertyCallbackInfo<v8::Value>& info
11 {% if attribute.is_reflect and not attribute.is_url and
12 attribute.idl_type == 'DOMString' and is_node %}
13 {% set cpp_class, v8_class = 'Element', 'V8Element' %}
14 {# FIXME: Perl skips most of function, but this seems unnecessary #}
16 {% if attribute.is_unforgeable %}
17 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain({{v8_class}}::domTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
20 {{cpp_class}}* imp = {{v8_class}}::toNative(holder);
22 {% if attribute.cached_attribute_validation_method %}
23 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attribute.name}}");
24 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
25 if (!imp->{{attribute.cached_attribute_validation_method}}()) {
26 v8::Handle<v8::Value> jsValue = getHiddenValue(info.GetIsolate(), info.Holder(), propertyName);
27 if (!jsValue.IsEmpty()) {
28 v8SetReturnValue(info, jsValue);
32 {% elif not (attribute.is_static or attribute.is_unforgeable) %}
33 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
35 {% if attribute.is_call_with_execution_context %}
36 ExecutionContext* scriptContext = getExecutionContext();
39 {% if attribute.is_check_security_for_node or
40 attribute.is_getter_raises_exception %}
41 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
43 {% if attribute.is_check_security_for_node %}
44 {# FIXME: consider using a local variable to not call getter twice #}
45 if (!BindingSecurity::shouldAllowAccessToNode({{attribute.cpp_value}}, exceptionState)) {
46 v8SetReturnValueNull(info);
47 exceptionState.throwIfNeeded();
51 {% if attribute.is_getter_raises_exception %}
52 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original}};
53 if (UNLIKELY(exceptionState.throwIfNeeded()))
56 {% if attribute.is_nullable %}
58 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original}};
60 v8SetReturnValueNull(info);
63 {% elif attribute.idl_type == 'EventHandler' or
64 attribute.cached_attribute_validation_method %}
65 {# FIXME: consider merging all these assign to local variable statements #}
66 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original}};
68 {% if attribute.cached_attribute_validation_method %}
69 setHiddenValue(info.GetIsolate(), info.Holder(), propertyName, {{attribute.cpp_value}}.v8Value());
71 {# End special cases #}
72 {% if attribute.is_keep_alive_for_gc %}
73 {{attribute.cpp_type}} result = {{attribute.cpp_value}};
74 if (result && DOMDataStore::setReturnValueFromWrapper<{{attribute.v8_type}}>(info.GetReturnValue(), result.get()))
76 v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Holder(), info.GetIsolate());
77 if (!wrapper.IsEmpty()) {
78 setHiddenValue(info.GetIsolate(), info.Holder(), "{{attribute.name}}", wrapper);
79 {{attribute.v8_set_return_value}};
82 {{attribute.v8_set_return_value}};
89 {##############################################################################}
90 {% macro attribute_getter_callback(attribute, world_suffix) %}
91 {% filter conditional(attribute.conditional_string) %}
92 static void {{attribute.name}}AttributeGetterCallback{{world_suffix}}(
93 {%- if attribute.is_expose_js_accessors %}
94 const v8::FunctionCallbackInfo<v8::Value>& info
96 v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info
99 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
100 {% if attribute.deprecate_as %}
101 UseCounter::countDeprecation(activeExecutionContext(), UseCounter::{{attribute.deprecate_as}});
103 {% if attribute.measure_as %}
104 UseCounter::count(activeExecutionContext(), UseCounter::{{attribute.measure_as}});
106 {% if world_suffix in attribute.activity_logging_world_list_for_getter %}
107 V8PerContextData* contextData = V8PerContextData::from(info.GetIsolate()->GetCurrentContext());
108 if (contextData && contextData->activityLogger())
109 contextData->activityLogger()->log("{{interface_name}}.{{attribute.name}}", 0, 0, "Getter");
111 {% if attribute.has_custom_getter %}
112 {{v8_class}}::{{attribute.name}}AttributeGetterCustom(info);
114 {{cpp_class}}V8Internal::{{attribute.name}}AttributeGetter{{world_suffix}}(info);
116 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
122 {##############################################################################}
123 {% macro attribute_setter(attribute, world_suffix) %}
124 {% filter conditional(attribute.conditional_string) %}
125 static void {{attribute.name}}AttributeSetter{{world_suffix}}(
126 {%- if attribute.is_expose_js_accessors %}
127 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info
129 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info
132 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and
134 {% set cpp_class, v8_class = 'Element', 'V8Element' %}
135 {# FIXME: Perl skips most of function, but this seems unnecessary #}
137 {% if attribute.has_setter_exception_state %}
138 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
140 {% if attribute.has_strict_type_checking %}
141 {# Type checking for interface types (if interface not implemented, throw
142 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
143 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(jsValue, info.GetIsolate())) {
144 exceptionState.throwTypeError("The provided value is not of type '{{attribute.idl_type}}'.");
145 exceptionState.throwIfNeeded();
149 {% if attribute.put_forwards %}
150 {{cpp_class}}* proxyImp = {{v8_class}}::toNative(info.Holder());
151 {{attribute.idl_type}}* imp = proxyImp->{{attribute.name}}();
154 {% elif not attribute.is_static %}
155 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder());
157 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
158 if (!imp->document())
161 {% if attribute.idl_type != 'EventHandler' %}
162 {{attribute.v8_value_to_local_cpp_value}};
163 {% elif not is_node %}{# EventHandler hack #}
164 transferHiddenDependency(info.Holder(), {{attribute.event_handler_getter_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate());
166 {% if attribute.enum_validation_expression %}
167 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
168 String string = cppValue;
169 if (!({{attribute.enum_validation_expression}}))
172 {% if attribute.is_reflect and
173 not(attribute.idl_type == 'DOMString' and is_node) %}
174 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
176 {% if attribute.is_call_with_execution_context %}
177 ExecutionContext* scriptContext = getExecutionContext();
179 {{attribute.cpp_setter}};
180 {% if attribute.is_setter_raises_exception %}
181 exceptionState.throwIfNeeded();
183 {% if attribute.cached_attribute_validation_method %}
184 deleteHiddenValue(info.GetIsolate(), info.Holder(), "{{attribute.name}}"); // Invalidate the cached value.
191 {##############################################################################}
192 {% macro attribute_setter_callback(attribute, world_suffix) %}
193 {% filter conditional(attribute.conditional_string) %}
194 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}(
195 {%- if attribute.is_expose_js_accessors %}
196 const v8::FunctionCallbackInfo<v8::Value>& info
198 v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info
201 {% if attribute.is_expose_js_accessors %}
202 v8::Local<v8::Value> jsValue = info[0];
204 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
205 {% if attribute.deprecate_as %}
206 UseCounter::countDeprecation(activeExecutionContext(), UseCounter::{{attribute.deprecate_as}});
208 {% if attribute.measure_as %}
209 UseCounter::count(activeExecutionContext(), UseCounter::{{attribute.measure_as}});
211 {% if world_suffix in attribute.activity_logging_world_list_for_setter %}
212 V8PerContextData* contextData = V8PerContextData::from(info.GetIsolate()->GetCurrentContext());
213 if (contextData && contextData->activityLogger()) {
214 v8::Handle<v8::Value> loggerArg[] = { jsValue };
215 contextData->activityLogger()->log("{{interface_name}}.{{attribute.name}}", 1, &loggerArg[0], "Setter");
218 {% if attribute.is_reflect %}
219 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
221 {% if attribute.has_custom_setter %}
222 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info);
224 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(jsValue, info);
226 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");