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

Side by Side Diff: Source/bindings/templates/attributes.cpp

Issue 968593002: bindings: Supports constructor attributes on prototype chains. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {% from 'conversions.cpp' import v8_value_to_local_cpp_value %} 1 {% from 'conversions.cpp' import v8_value_to_local_cpp_value %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% macro attribute_getter(attribute, world_suffix) %} 5 {% macro attribute_getter(attribute, world_suffix) %}
6 {% filter conditional(attribute.conditional_string) %} 6 {% filter conditional(attribute.conditional_string) %}
7 static void {{attribute.name}}AttributeGetter{{world_suffix}}( 7 static void {{attribute.name}}AttributeGetter{{world_suffix}}(
8 {%- if attribute.is_expose_js_accessors %} 8 {%- if attribute.is_expose_js_accessors %}
9 const v8::FunctionCallbackInfo<v8::Value>& info 9 const v8::FunctionCallbackInfo<v8::Value>& info
10 {%- else %} 10 {%- else %}
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 {% endif %} 176 {% endif %}
177 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 177 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
178 } 178 }
179 {% endfilter %} 179 {% endfilter %}
180 {% endmacro %} 180 {% endmacro %}
181 181
182 182
183 {##############################################################################} 183 {##############################################################################}
184 {% macro constructor_getter_callback(attribute, world_suffix) %} 184 {% macro constructor_getter_callback(attribute, world_suffix) %}
185 {% filter conditional(attribute.conditional_string) %} 185 {% filter conditional(attribute.conditional_string) %}
186 static void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(v8::Loca l<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) 186 static void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(
187 {%- if attribute.is_expose_js_accessors %}
188 const v8::FunctionCallbackInfo<v8::Value>& info
189 {%- else %}
190 v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info
191 {%- endif %})
187 { 192 {
188 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 193 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
189 {% if attribute.deprecate_as %} 194 {% if attribute.deprecate_as %}
190 UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), callingExe cutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}}); 195 UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), callingExe cutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
191 {% endif %} 196 {% endif %}
192 {% if attribute.measure_as %} 197 {% if attribute.measure_as %}
193 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionConte xt(info.GetIsolate()), UseCounter::{{attribute.measure_as}}); 198 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionConte xt(info.GetIsolate()), UseCounter::{{attribute.measure_as}});
194 {% endif %} 199 {% endif %}
195 {{cpp_class_or_partial}}V8Internal::{{cpp_class}}ConstructorGetter{{world_su ffix}}(property, info); 200 {% if attribute.is_expose_js_accessors %}
201 v8ConstructorAttributeGetterAsAccessor(info);
202 {% else %}
203 v8ConstructorAttributeGetterAsProperty(property, info);
204 {% endif %}
196 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 205 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
197 } 206 }
198 {% endfilter %} 207 {% endfilter %}
199 {% endmacro %} 208 {% endmacro %}
200 209
201 210
202 {##############################################################################} 211 {##############################################################################}
203 {% macro attribute_setter(attribute, world_suffix) %} 212 {% macro attribute_setter(attribute, world_suffix) %}
204 {% filter conditional(attribute.conditional_string) %} 213 {% filter conditional(attribute.conditional_string) %}
205 static void {{attribute.name}}AttributeSetter{{world_suffix}}( 214 static void {{attribute.name}}AttributeSetter{{world_suffix}}(
206 {%- if attribute.is_expose_js_accessors %} 215 {%- if attribute.is_expose_js_accessors %}
207 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info 216 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info
208 {%- else %} 217 {%- else %}
209 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info 218 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
210 {%- endif %}) 219 {%- endif %})
211 { 220 {
212 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' 221 {% if attribute.is_reflect and attribute.idl_type == 'DOMString'
213 and is_node and not attribute.is_implemented_in_private_script %} 222 and is_node and not attribute.is_implemented_in_private_script %}
214 {% set cpp_class, v8_class = 'Element', 'V8Element' %} 223 {% set cpp_class, v8_class = 'Element', 'V8Element' %}
215 {% endif %} 224 {% endif %}
216 {# Local variables #} 225 {# Local variables #}
217 {% if not attribute.is_static and not attribute.is_replaceable %} 226 {% if not attribute.is_static and
227 not attribute.is_replaceable and
228 not attribute.constructor_type %}
218 v8::Local<v8::Object> holder = info.Holder(); 229 v8::Local<v8::Object> holder = info.Holder();
219 {% endif %} 230 {% endif %}
220 {% if attribute.has_setter_exception_state %} 231 {% if attribute.has_setter_exception_state %}
221 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate()); 232 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate());
222 {% endif %} 233 {% endif %}
234 {% if attribute.is_replaceable or
235 attribute.constructor_type %}
236 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}");
237 {% endif %}
223 {# impl #} 238 {# impl #}
224 {% if attribute.is_put_forwards %} 239 {% if attribute.is_put_forwards %}
225 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder); 240 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
226 {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}()); 241 {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}());
227 if (!impl) 242 if (!impl)
228 return; 243 return;
229 {% elif attribute.is_replaceable %} 244 {% elif not attribute.is_static and
230 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}"); 245 not attribute.is_replaceable and
231 {% elif not attribute.is_static %} 246 not attribute.constructor_type %}
232 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 247 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
233 {% endif %} 248 {% endif %}
234 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} 249 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %}
235 if (!impl->document()) 250 if (!impl->document())
236 return; 251 return;
237 {% endif %} 252 {% endif %}
238 {# Convert JS value to C++ value #} 253 {# Convert JS value to C++ value #}
239 {% if attribute.idl_type != 'EventHandler' %} 254 {% if attribute.idl_type != 'EventHandler' %}
240 {% if v8_value_to_local_cpp_value(attribute) %} 255 {% if v8_value_to_local_cpp_value(attribute) %}
241 {{v8_value_to_local_cpp_value(attribute) | indent}} 256 {{v8_value_to_local_cpp_value(attribute) | indent}}
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateIn UserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_s cript_cpp_value_to_v8_value}}); 400 return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateIn UserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_s cript_cpp_value_to_v8_value}});
386 } 401 }
387 {% endmacro %} 402 {% endmacro %}
388 403
389 404
390 {##############################################################################} 405 {##############################################################################}
391 {% macro attribute_configuration(attribute) %} 406 {% macro attribute_configuration(attribute) %}
392 {% set getter_callback = 407 {% set getter_callback =
393 '%sV8Internal::%sAttributeGetterCallback' % 408 '%sV8Internal::%sAttributeGetterCallback' %
394 (cpp_class_or_partial, attribute.name) 409 (cpp_class_or_partial, attribute.name)
395 if not attribute.constructor_type else 410 if not attribute.constructor_type else (
396 ('%sV8Internal::%sConstructorGetterCallback' % 411 '%sV8Internal::%sConstructorGetterCallback' %
397 (cpp_class_or_partial, attribute.name) 412 (cpp_class_or_partial, attribute.name)
398 if attribute.needs_constructor_getter_callback else 413 if attribute.needs_constructor_getter_callback else (
399 '%sV8Internal::%sConstructorGetter' % (cpp_class_or_partial, cpp_class)) %} 414 'v8ConstructorAttributeGetterAsAccessor'
415 if attribute.is_expose_js_accessors else (
416 'v8ConstructorAttributeGetterAsProperty'))) %}
400 {% set getter_callback_for_main_world = 417 {% set getter_callback_for_main_world =
401 '%sV8Internal::%sAttributeGetterCallbackForMainWorld' % 418 '%sV8Internal::%sAttributeGetterCallbackForMainWorld' %
402 (cpp_class_or_partial, attribute.name) 419 (cpp_class_or_partial, attribute.name)
403 if attribute.is_per_world_bindings else '0' %} 420 if attribute.is_per_world_bindings else '0' %}
404 {% set setter_callback = attribute.setter_callback %} 421 {% set setter_callback =
422 '%sV8Internal::%sAttributeSetterCallback' %
423 (cpp_class_or_partial, attribute.name)
424 if attribute.has_setter else '0' %}
405 {% set setter_callback_for_main_world = 425 {% set setter_callback_for_main_world =
406 '%sV8Internal::%sAttributeSetterCallbackForMainWorld' % 426 '%sV8Internal::%sAttributeSetterCallbackForMainWorld' %
407 (cpp_class_or_partial, attribute.name) 427 (cpp_class_or_partial, attribute.name)
408 if attribute.is_per_world_bindings and attribute.has_setter else '0' %} 428 if attribute.is_per_world_bindings and attribute.has_setter else '0' %}
409 {% set wrapper_type_info = 429 {% set wrapper_type_info =
410 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % 430 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' %
411 attribute.constructor_type 431 attribute.constructor_type
412 if attribute.constructor_type else '0' %} 432 if attribute.constructor_type else '0' %}
413 {% set access_control = 'static_cast<v8::AccessControl>(%s)' % 433 {% set access_control = 'static_cast<v8::AccessControl>(%s)' %
414 ' | '.join(attribute.access_control_list) %} 434 ' | '.join(attribute.access_control_list) %}
(...skipping 13 matching lines...) Expand all
428 access_control, 448 access_control,
429 property_attribute, 449 property_attribute,
430 only_exposed_to_private_script, 450 only_exposed_to_private_script,
431 ] %} 451 ] %}
432 {% if not attribute.is_expose_js_accessors %} 452 {% if not attribute.is_expose_js_accessors %}
433 {% set attribute_configuration_list = attribute_configuration_list 453 {% set attribute_configuration_list = attribute_configuration_list
434 + [on_prototype] %} 454 + [on_prototype] %}
435 {% endif %} 455 {% endif %}
436 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}} 456 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
437 {%- endmacro %} 457 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698