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

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

Issue 1161463009: bindings: Supports [LenientThis] extended attributes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added a layout test for [LenientThis]. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {% from 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_l ocal_cpp_value %} 1 {% from 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_l ocal_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 %}
11 const v8::PropertyCallbackInfo<v8::Value>& info 11 const v8::PropertyCallbackInfo<v8::Value>& info
12 {%- endif %}) 12 {%- endif %})
13 { 13 {
14 {% if attribute.is_reflect and not attribute.is_url 14 {% if attribute.is_reflect and not attribute.is_url
15 and attribute.idl_type == 'DOMString' and is_node 15 and attribute.idl_type == 'DOMString' and is_node
16 and not attribute.is_implemented_in_private_script %} 16 and not attribute.is_implemented_in_private_script %}
17 {% set cpp_class, v8_class = 'Element', 'V8Element' %} 17 {% set cpp_class, v8_class = 'Element', 'V8Element' %}
18 {% endif %} 18 {% endif %}
19 {# holder #} 19 {# holder #}
20 {% if not attribute.is_static %} 20 {% if not attribute.is_static %}
21 {% if attribute.is_lenient_this %}
22 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(in fo.This(), info.GetIsolate());
23 if (holder.IsEmpty())
24 return; // Return silently because of [LenientThis].
25 // Note that it's okay to use |holder|, but |info.Holder()| is still unsafe
26 // and must not be used.
27 {% else %}
21 v8::Local<v8::Object> holder = info.Holder(); 28 v8::Local<v8::Object> holder = info.Holder();
22 {% endif %} 29 {% endif %}
30 {% endif %}
23 {# impl #} 31 {# impl #}
24 {% if attribute.cached_attribute_validation_method %} 32 {% if attribute.cached_attribute_validation_method %}
25 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}"); 33 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}");
26 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 34 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
27 if (!impl->{{attribute.cached_attribute_validation_method}}()) { 35 if (!impl->{{attribute.cached_attribute_validation_method}}()) {
28 v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(info.GetIso late(), holder, propertyName); 36 v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(info.GetIso late(), holder, propertyName);
29 if (!v8Value.IsEmpty()) { 37 if (!v8Value.IsEmpty()) {
30 v8SetReturnValue(info, v8Value); 38 v8SetReturnValue(info, v8Value);
31 return; 39 return;
32 } 40 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 attribute.is_check_security_for_window)) %} 259 attribute.is_check_security_for_window)) %}
252 {% set raise_exception = 1 %} 260 {% set raise_exception = 1 %}
253 {% else %} 261 {% else %}
254 {% set raise_exception = 0 %} 262 {% set raise_exception = 0 %}
255 {% endif %} 263 {% endif %}
256 {# Local variables #} 264 {# Local variables #}
257 {% if (not attribute.is_static and 265 {% if (not attribute.is_static and
258 not attribute.is_replaceable and 266 not attribute.is_replaceable and
259 not attribute.constructor_type) or 267 not attribute.constructor_type) or
260 raise_exception %} 268 raise_exception %}
269 {% if attribute.is_lenient_this %}
270 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(in fo.This(), info.GetIsolate());
271 if (holder.IsEmpty())
272 return; // Return silently because of [LenientThis].
273 // Note that it's okay to use |holder|, but |info.Holder()| is still unsafe
274 // and must not be used.
275 {% else %}
261 v8::Local<v8::Object> holder = info.Holder(); 276 v8::Local<v8::Object> holder = info.Holder();
262 {% endif %} 277 {% endif %}
278 {% endif %}
263 {% if raise_exception %} 279 {% if raise_exception %}
264 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate()); 280 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, info.GetIsolate());
265 {% endif %} 281 {% endif %}
266 {% if attribute.is_replaceable or 282 {% if attribute.is_replaceable or
267 attribute.constructor_type %} 283 attribute.constructor_type %}
268 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}"); 284 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}");
269 {% endif %} 285 {% endif %}
270 {# impl #} 286 {# impl #}
271 {% if attribute.is_put_forwards %} 287 {% if attribute.is_put_forwards %}
272 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder); 288 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ' | '.join(attribute.access_control_list) %} 524 ' | '.join(attribute.access_control_list) %}
509 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' % 525 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' %
510 ' | '.join(attribute.property_attributes) %} 526 ' | '.join(attribute.property_attributes) %}
511 {% set only_exposed_to_private_script = 527 {% set only_exposed_to_private_script =
512 'V8DOMConfiguration::OnlyExposedToPrivateScript' 528 'V8DOMConfiguration::OnlyExposedToPrivateScript'
513 if attribute.only_exposed_to_private_script else 529 if attribute.only_exposed_to_private_script else
514 'V8DOMConfiguration::ExposedToAllScripts' %} 530 'V8DOMConfiguration::ExposedToAllScripts' %}
515 {% set on_prototype = 'V8DOMConfiguration::OnPrototype' 531 {% set on_prototype = 'V8DOMConfiguration::OnPrototype'
516 if interface_name == 'Window' and attribute.idl_type == 'EventHandler' 532 if interface_name == 'Window' and attribute.idl_type == 'EventHandler'
517 else 'V8DOMConfiguration::OnInstance' %} 533 else 'V8DOMConfiguration::OnInstance' %}
534 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder'
535 if attribute.is_lenient_this else 'V8DOMConfiguration::CheckHolder' %}
518 {% set attribute_configuration_list = [ 536 {% set attribute_configuration_list = [
519 '"%s"' % attribute.name, 537 '"%s"' % attribute.name,
520 getter_callback, 538 getter_callback,
521 setter_callback, 539 setter_callback,
522 getter_callback_for_main_world, 540 getter_callback_for_main_world,
523 setter_callback_for_main_world, 541 setter_callback_for_main_world,
524 wrapper_type_info, 542 wrapper_type_info,
525 access_control, 543 access_control,
526 property_attribute, 544 property_attribute,
527 only_exposed_to_private_script, 545 only_exposed_to_private_script,
528 ] %} 546 ] %}
529 {% if not attribute.is_expose_js_accessors %} 547 {% if attribute.is_expose_js_accessors %}
548 {% set attribute_configuration_list = attribute_configuration_list
549 + [holder_check] %}
550 {% else %}
530 {% set attribute_configuration_list = attribute_configuration_list 551 {% set attribute_configuration_list = attribute_configuration_list
531 + [on_prototype] %} 552 + [on_prototype] %}
532 {% endif %} 553 {% endif %}
533 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}} 554 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
534 {%- endmacro %} 555 {%- endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/core/TestInterface.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698