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

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

Issue 2733763003: Reimplement [PutForwards] per spec (Closed)
Patch Set: avoid using v8::Maybe 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 v8::Local<v8::Value> v8Value, const V8CrossOriginSetterInfo& info 281 v8::Local<v8::Value> v8Value, const V8CrossOriginSetterInfo& info
282 {%- elif attribute.is_data_type_property %} 282 {%- elif attribute.is_data_type_property %}
283 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info 283 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
284 {%- else %} 284 {%- else %}
285 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info 285 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info
286 {%- endif %}) { 286 {%- endif %}) {
287 {% filter format_remove_duplicates(['ExceptionState exceptionState']) %} 287 {% filter format_remove_duplicates(['ExceptionState exceptionState']) %}
288 v8::Isolate* isolate = info.GetIsolate(); 288 v8::Isolate* isolate = info.GetIsolate();
289 ALLOW_UNUSED_LOCAL(isolate); 289 ALLOW_UNUSED_LOCAL(isolate);
290 290
291 v8::Local<v8::Object> holder = info.Holder();
292 ALLOW_UNUSED_LOCAL(holder);
293
291 {% set define_exception_state -%} 294 {% set define_exception_state -%}
292 ExceptionState exceptionState(isolate, ExceptionState::kSetterContext, "{{inte rface_name}}", "{{attribute.name}}"); 295 ExceptionState exceptionState(isolate, ExceptionState::kSetterContext, "{{inte rface_name}}", "{{attribute.name}}");
293 {%- endset %} 296 {%- endset %}
294 297
295 {% if attribute.is_lenient_this %} 298 {% if attribute.is_lenient_this %}
296 // [LenientThis] 299 // [LenientThis]
297 // Make sure that info.Holder() really points to an instance if [LenientThis]. 300 // Make sure that info.Holder() really points to an instance if [LenientThis].
298 if (!{{v8_class}}::hasInstance(info.Holder(), isolate)) 301 if (!{{v8_class}}::hasInstance(holder, isolate))
299 return; // Return silently because of [LenientThis]. 302 return; // Return silently because of [LenientThis].
300 {% endif %} 303 {% endif %}
301 304
302 {% if not attribute.is_static and not attribute.is_replaceable %} 305 {% if not attribute.is_static and not attribute.is_replaceable and not attribu te.is_put_forwards %}
303 v8::Local<v8::Object> holder = info.Holder();
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 %} 306 {% set local_dom_window_only = interface_name == 'Window' and not attribute.ha s_cross_origin_setter %}
311 {% if local_dom_window_only %} 307 {% if local_dom_window_only %}
312 {% if attribute.is_check_security_for_receiver %} 308 {% if attribute.is_check_security_for_receiver %}
313 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(holder); 309 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(holder);
314 {% else %} 310 {% else %}
315 // Same-origin attributes setters are never exposed via the cross-origin 311 // Same-origin attributes setters are never exposed via the cross-origin
316 // interceptors. Since same-origin access requires a LocalDOMWindow, it is 312 // interceptors. Since same-origin access requires a LocalDOMWindow, it is
317 // safe to downcast here. 313 // safe to downcast here.
318 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(holder)); 314 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(holder));
319 {% endif %}{# attribute.is_check_security_for_receiver #} 315 {% endif %}{# attribute.is_check_security_for_receiver #}
320 {% else %} 316 {% else %}
321 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 317 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
322 {% endif %}{# local_dom_window_only #} 318 {% endif %}{# local_dom_window_only #}
323 {% endif %} 319 {% endif %}
324 {% endif %}
325 320
326 {% if attribute.is_check_security_for_receiver and not attribute.is_data_type_ property %} 321 {% if attribute.is_check_security_for_receiver and not attribute.is_data_type_ property %}
327 // Perform a security check for the receiver object. 322 // Perform a security check for the receiver object.
328 {{define_exception_state}} 323 {{define_exception_state}}
329 {% if local_dom_window_only %} 324 {% if local_dom_window_only %}
330 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), unchecked Impl, exceptionState)) { 325 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), unchecked Impl, exceptionState)) {
331 {% else %} 326 {% else %}
332 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, exc eptionState)) { 327 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(isolate), impl, exc eptionState)) {
333 {% endif %}{# local_dom_window_only #} 328 {% endif %}{# local_dom_window_only #}
334 V8SetReturnValue(info, v8Value); 329 V8SetReturnValue(info, v8Value);
335 return; 330 return;
336 } 331 }
337 {% if local_dom_window_only %} 332 {% if local_dom_window_only %}
338 LocalDOMWindow* impl = ToLocalDOMWindow(uncheckedImpl); 333 LocalDOMWindow* impl = ToLocalDOMWindow(uncheckedImpl);
339 {% endif %}{# local_dom_window_only #} 334 {% endif %}{# local_dom_window_only #}
340 {% endif %} 335 {% endif %}
341 336
342 {% if attribute.is_check_security_for_return_value %} 337 {% 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. 338 #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 %} 339 {% endif %}
345 340
341 {% if attribute.is_put_forwards %}
342 // [PutForwards] => {{attribute.name}}.{{attribute.target_attribute_name}}
343 {{define_exception_state}}
344 v8::Local<v8::Value> target;
345 if (!holder->Get(isolate->GetCurrentContext(), V8String(isolate, "{{attribute. name}}")).ToLocal(&target))
346 return;
347 if (!target->IsObject()) {
348 exceptionState.ThrowTypeError("The attribute value is not an object");
349 return;
350 }
351 bool result;
352 if (!target.As<v8::Object>()->Set(isolate->GetCurrentContext(), V8String(isola te, "{{attribute.target_attribute_name}}"), v8Value).To(&result))
353 return;
354 if (!result)
355 return;
356 {% else %}{# attribute.is_put_forwards #}
346 {% if attribute.is_custom_element_callbacks or 357 {% if attribute.is_custom_element_callbacks or
347 (attribute.is_reflect and not (attribute.idl_type == 'DOMString' and is_ node)) %} 358 (attribute.is_reflect and not (attribute.idl_type == 'DOMString' and is_ node)) %}
348 // Skip on compact node DOMString getters. 359 // Skip on compact node DOMString getters.
349 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 360 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
350 {% endif %} 361 {% endif %}
351 362
352 {% if attribute.has_setter_exception_state %} 363 {% if attribute.has_setter_exception_state %}
353 {{define_exception_state}} 364 {{define_exception_state}}
354 {% endif %} 365 {% endif %}
355 366
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 {% endif %} 412 {% endif %}
402 {{attribute.cpp_setter}}; 413 {{attribute.cpp_setter}};
403 414
404 {% if attribute.cached_attribute_validation_method %} 415 {% if attribute.cached_attribute_validation_method %}
405 // [CachedAttribute] 416 // [CachedAttribute]
406 // Invalidate the cached value. 417 // Invalidate the cached value.
407 V8PrivateProperty::GetSymbol( 418 V8PrivateProperty::GetSymbol(
408 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") 419 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}")
409 .DeleteProperty(holder, v8::Undefined(isolate)); 420 .DeleteProperty(holder, v8::Undefined(isolate));
410 {% endif %} 421 {% endif %}
422 {% endif %}{# attribute.is_put_forwards #}
411 } 423 }
412 {% endfilter %}{# format_remove_duplicates #} 424 {% endfilter %}{# format_remove_duplicates #}
413 {% endmacro %} 425 {% endmacro %}
414 426
415 427
416 {##############################################################################} 428 {##############################################################################}
417 {% macro attribute_setter_callback(attribute, world_suffix) %} 429 {% macro attribute_setter_callback(attribute, world_suffix) %}
418 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}( 430 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}(
419 {%- if attribute.is_data_type_property %} 431 {%- if attribute.is_data_type_property %}
420 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info 432 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[] = { 530 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] = {
519 {{attribute_configuration(attribute)}} 531 {{attribute_configuration(attribute)}}
520 }; 532 };
521 for (const auto& accessorConfig : accessorConfiguration) 533 for (const auto& accessorConfig : accessorConfiguration)
522 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig); 534 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig);
523 {% endfilter %}{# runtime_enabled #} 535 {% endfilter %}{# runtime_enabled #}
524 {% endfilter %}{# secure_context #} 536 {% endfilter %}{# secure_context #}
525 {% endfilter %}{# exposed #} 537 {% endfilter %}{# exposed #}
526 {% endfor %} 538 {% endfor %}
527 {% endmacro %} 539 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698