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

Side by Side Diff: third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl

Issue 2733763003: Reimplement [PutForwards] per spec (Closed)
Patch Set: rebase Created 3 years, 7 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
OLDNEW
1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %}
2 2
3 {##############################################################################} 3 {##############################################################################}
4 {% macro attribute_getter(attribute, world_suffix) %} 4 {% macro attribute_getter(attribute, world_suffix) %}
5 static void {{attribute.name}}AttributeGetter{{world_suffix}}( 5 static void {{attribute.name}}AttributeGetter{{world_suffix}}(
6 {%- if attribute.is_data_type_property %} 6 {%- if attribute.is_data_type_property %}
7 const v8::PropertyCallbackInfo<v8::Value>& info 7 const v8::PropertyCallbackInfo<v8::Value>& info
8 {%- else %} 8 {%- else %}
9 const v8::FunctionCallbackInfo<v8::Value>& info 9 const v8::FunctionCallbackInfo<v8::Value>& info
10 {%- endif %}) { 10 {%- endif %}) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 ExceptionState exceptionState(isolate, ExceptionState::kSetterContext, "{{inte rface_name}}", "{{attribute.name}}"); 292 ExceptionState exceptionState(isolate, ExceptionState::kSetterContext, "{{inte rface_name}}", "{{attribute.name}}");
293 {%- endset %} 293 {%- endset %}
294 294
295 {% if attribute.is_lenient_this %} 295 {% if attribute.is_lenient_this %}
296 // [LenientThis] 296 // [LenientThis]
297 // Make sure that info.Holder() really points to an instance if [LenientThis]. 297 // Make sure that info.Holder() really points to an instance if [LenientThis].
298 if (!{{v8_class}}::hasInstance(info.Holder(), isolate)) 298 if (!{{v8_class}}::hasInstance(info.Holder(), isolate))
299 return; // Return silently because of [LenientThis]. 299 return; // Return silently because of [LenientThis].
300 {% endif %} 300 {% endif %}
301 301
302 {% if not attribute.is_static and not attribute.is_replaceable %} 302 {% set check_security_for_receiver = attribute.is_check_security_for_receiver and not attribute.is_data_type_property %}
Yuki 2017/05/08 09:31:19 nit: If this is not a big deal, I'd prefer not ali
303
304 {% if not attribute.is_static and not attribute.is_replaceable and
305 (not attribute.is_put_forwards or check_security_for_receiver) %}
303 v8::Local<v8::Object> holder = info.Holder(); 306 v8::Local<v8::Object> holder = info.Holder();
Yuki 2017/05/08 09:31:19 Personally, I'd prefer the previous code rather th
304 {% if attribute.is_put_forwards %}
305 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
306 {{attribute.cpp_type}} impl = WTF::GetPtr(proxyImpl->{{attribute.name}}());
307 if (!impl)
308 return;
309 {% else %}
310 {% set local_dom_window_only = interface_name == 'Window' and not attribute.ha s_cross_origin_setter %} 307 {% set local_dom_window_only = interface_name == 'Window' and not attribute.ha s_cross_origin_setter %}
311 {% if local_dom_window_only %} 308 {% if local_dom_window_only %}
312 {% if attribute.is_check_security_for_receiver %} 309 {% if attribute.is_check_security_for_receiver %}
313 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(holder); 310 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(holder);
314 {% else %} 311 {% else %}
315 // Same-origin attributes setters are never exposed via the cross-origin 312 // Same-origin attributes setters are never exposed via the cross-origin
316 // interceptors. Since same-origin access requires a LocalDOMWindow, it is 313 // interceptors. Since same-origin access requires a LocalDOMWindow, it is
317 // safe to downcast here. 314 // safe to downcast here.
318 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(holder)); 315 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(holder));
319 {% endif %}{# attribute.is_check_security_for_receiver #} 316 {% endif %}{# attribute.is_check_security_for_receiver #}
320 {% else %} 317 {% else %}
321 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 318 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
322 {% endif %}{# local_dom_window_only #} 319 {% endif %}{# local_dom_window_only #}
323 {% endif %} 320 {% endif %}
324 {% endif %}
325 321
326 {% if attribute.is_check_security_for_receiver and not attribute.is_data_type_ property %} 322 {% if check_security_for_receiver %}
327 // Perform a security check for the receiver object. 323 // Perform a security check for the receiver object.
328 {{define_exception_state}} 324 {{define_exception_state}}
329 {% if local_dom_window_only %} 325 {% if local_dom_window_only %}
330 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), unchecked Impl, exceptionState)) { 326 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), unchecked Impl, exceptionState)) {
331 {% else %} 327 {% else %}
332 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, exc eptionState)) { 328 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, exc eptionState)) {
333 {% endif %}{# local_dom_window_only #} 329 {% endif %}{# local_dom_window_only #}
334 V8SetReturnValue(info, v8Value); 330 V8SetReturnValue(info, v8Value);
335 return; 331 return;
336 } 332 }
337 {% if local_dom_window_only %} 333 {% if local_dom_window_only %}
338 LocalDOMWindow* impl = ToLocalDOMWindow(uncheckedImpl); 334 LocalDOMWindow* impl = ToLocalDOMWindow(uncheckedImpl);
339 {% endif %}{# local_dom_window_only #} 335 {% endif %}{# local_dom_window_only #}
340 {% endif %} 336 {% endif %}
341 337
342 {% if attribute.is_check_security_for_return_value %} 338 {% if attribute.is_check_security_for_return_value %}
343 #error Attribute setter with the security check for the return value is not supp orted. Since the return value is the given value to be set, it\'s meaningless t o perform the security check for the return value. 339 #error Attribute setter with the security check for the return value is not supp orted. Since the return value is the given value to be set, it\'s meaningless t o perform the security check for the return value.
344 {% endif %} 340 {% endif %}
345 341
342 {% if attribute.is_put_forwards %}
343 {{define_exception_state}}
344 v8::Local<v8::Value> target;
345 if (!info.Holder()->Get(info.GetIsolate()->GetCurrentContext(), V8String(info. GetIsolate(), "{{attribute.name}}")).ToLocal(&target))
Yuki 2017/05/08 09:31:19 nit: You could use |holder| instead of |info.GetHo
346 return;
347 if (!target->IsObject()) {
348 exceptionState.ThrowTypeError("The attribute value is not an object");
349 return;
350 }
351 target.As<v8::Object>()->Set(info.GetIsolate()->GetCurrentContext(), V8String( info.GetIsolate(), "{{attribute.target_attribute_name}}"), v8Value).IsNothing();
Yuki 2017/05/08 09:31:19 IsNothing() doesn't make sense here. IIUC, you sh
352 {% else %}
Yuki 2017/05/08 09:31:19 nit: {% else %}{# attribute.is_put_forwards %}
346 {% if attribute.is_custom_element_callbacks or 353 {% if attribute.is_custom_element_callbacks or
347 (attribute.is_reflect and not (attribute.idl_type == 'DOMString' and is_ node)) %} 354 (attribute.is_reflect and not (attribute.idl_type == 'DOMString' and is_ node)) %}
348 // Skip on compact node DOMString getters. 355 // Skip on compact node DOMString getters.
349 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 356 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
350 {% endif %} 357 {% endif %}
351 358
352 {% if attribute.has_setter_exception_state %} 359 {% if attribute.has_setter_exception_state %}
353 {{define_exception_state}} 360 {{define_exception_state}}
354 {% endif %} 361 {% endif %}
355 362
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 {% endif %} 408 {% endif %}
402 {{attribute.cpp_setter}}; 409 {{attribute.cpp_setter}};
403 410
404 {% if attribute.cached_attribute_validation_method %} 411 {% if attribute.cached_attribute_validation_method %}
405 // [CachedAttribute] 412 // [CachedAttribute]
406 // Invalidate the cached value. 413 // Invalidate the cached value.
407 V8PrivateProperty::GetSymbol( 414 V8PrivateProperty::GetSymbol(
408 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") 415 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}")
409 .DeleteProperty(holder, v8::Undefined(isolate)); 416 .DeleteProperty(holder, v8::Undefined(isolate));
410 {% endif %} 417 {% endif %}
418 {% endif %}{# is_put_forwards #}
Yuki 2017/05/08 09:31:19 nit: {# attribute.is_put_forwards #}
411 } 419 }
412 {% endfilter %}{# format_remove_duplicates #} 420 {% endfilter %}{# format_remove_duplicates #}
413 {% endmacro %} 421 {% endmacro %}
414 422
415 423
416 {##############################################################################} 424 {##############################################################################}
417 {% macro attribute_setter_callback(attribute, world_suffix) %} 425 {% macro attribute_setter_callback(attribute, world_suffix) %}
418 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}( 426 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}(
419 {%- if attribute.is_data_type_property %} 427 {%- if attribute.is_data_type_property %}
420 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info 428 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] = { 526 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] = {
519 {{attribute_configuration(attribute)}} 527 {{attribute_configuration(attribute)}}
520 }; 528 };
521 for (const auto& accessorConfig : accessorConfiguration) 529 for (const auto& accessorConfig : accessorConfiguration)
522 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig); 530 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig);
523 {% endfilter %}{# runtime_enabled #} 531 {% endfilter %}{# runtime_enabled #}
524 {% endfilter %}{# secure_context #} 532 {% endfilter %}{# secure_context #}
525 {% endfilter %}{# exposed #} 533 {% endfilter %}{# exposed #}
526 {% endfor %} 534 {% endfor %}
527 {% endmacro %} 535 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698