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

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

Issue 751223003: IDL: Support runtime enabled overloads affecting Function.length (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: eliminate "info.Length() < 0" branches Created 6 years 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 {##############################################################################} 1 {##############################################################################}
2 {% macro generate_method(method, world_suffix) %} 2 {% macro generate_method(method, world_suffix) %}
3 {% filter conditional(method.conditional_string) %} 3 {% filter conditional(method.conditional_string) %}
4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
5 { 5 {
6 {# Local variables #} 6 {# Local variables #}
7 {% if method.has_exception_state %} 7 {% if method.has_exception_state %}
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
9 {% endif %} 9 {% endif %}
10 {# Overloaded methods have length checked during overload resolution #} 10 {# Overloaded methods have length checked during overload resolution #}
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %} 325 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %}
326 {% if method.is_constructor %} 326 {% if method.is_constructor %}
327 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length()) 327 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length())
328 {%- else %} 328 {%- else %}
329 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length()) 329 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length())
330 {%- endif %} 330 {%- endif %}
331 {%- endmacro %} 331 {%- endmacro %}
332 332
333 333
334 {##############################################################################} 334 {##############################################################################}
335 {% macro runtime_determined_length_method(overloads) %}
336 static int {{overloads.name}}MethodLength()
337 {
338 {% for length, runtime_enabled_functions in overloads.runtime_determined_len gths %}
339 {% for runtime_enabled_function in runtime_enabled_functions %}
340 {% filter runtime_enabled(runtime_enabled_function) %}
341 return {{length}};
342 {% endfilter %}
343 {% endfor %}
344 {% endfor %}
345 }
346 {% endmacro %}
347
348
349 {##############################################################################}
335 {# FIXME: We should return a rejected Promise if an error occurs in this 350 {# FIXME: We should return a rejected Promise if an error occurs in this
336 function when ALL methods in this overload return Promise. In order to do so, 351 function when ALL methods in this overload return Promise. In order to do so,
337 we must ensure either ALL or NO methods in this overload return Promise #} 352 we must ensure either ALL or NO methods in this overload return Promise #}
338 {% macro overload_resolution_method(overloads, world_suffix) %} 353 {% macro overload_resolution_method(overloads, world_suffix) %}
339 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) 354 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info)
340 { 355 {
341 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 356 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
342 {% if overloads.measure_all_as %} 357 {% if overloads.measure_all_as %}
343 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionConte xt(info.GetIsolate()), UseCounter::{{overloads.measure_all_as}}); 358 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionConte xt(info.GetIsolate()), UseCounter::{{overloads.measure_all_as}});
344 {% endif %} 359 {% endif %}
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 {# FIXME: we do not need to always generate this code. #} 395 {# FIXME: we do not need to always generate this code. #}
381 {# Invalid arity, throw error #} 396 {# Invalid arity, throw error #}
382 {# Report full list of valid arities if gaps and above minimum #} 397 {# Report full list of valid arities if gaps and above minimum #}
383 {% if overloads.valid_arities %} 398 {% if overloads.valid_arities %}
384 if (info.Length() >= {{overloads.minarg}}) { 399 if (info.Length() >= {{overloads.minarg}}) {
385 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); 400 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length());
386 {{throw_from_exception_state(overloads)}}; 401 {{throw_from_exception_state(overloads)}};
387 return; 402 return;
388 } 403 }
389 {% endif %} 404 {% endif %}
390 {# Otherwise just report "not enough arguments" #} 405 break;
391 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.minarg}}, info.Length()));
392 {{throw_from_exception_state(overloads)}};
393 return;
394 {% endif %} 406 {% endif %}
395 } 407 }
396 {% if not is_partial and overloads.has_partial_overloads %} 408 {% if not is_partial and overloads.has_partial_overloads %}
397 ASSERT({{overloads.name}}MethodForPartialInterface); 409 ASSERT({{overloads.name}}MethodForPartialInterface);
398 ({{overloads.name}}MethodForPartialInterface)(info); 410 ({{overloads.name}}MethodForPartialInterface)(info);
399 {% else %} 411 {% else %}
412 {% if overloads.length != 0 %}
413 if (info.Length() < {{overloads.length}}) {
414 {# Otherwise just report "not enough arguments" #}
415 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length()));
416 {{throw_from_exception_state(overloads)}};
417 return;
418 }
419 {% endif %}
400 {# No match, throw error #} 420 {# No match, throw error #}
401 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); 421 exceptionState.throwTypeError("No function was found that matched the signat ure provided.");
402 {{throw_from_exception_state(overloads)}}; 422 {{throw_from_exception_state(overloads)}};
403 {% endif %} 423 {% endif %}
404 } 424 }
405 {% endmacro %} 425 {% endmacro %}
406 426
407 427
408 {##############################################################################} 428 {##############################################################################}
409 {% macro method_callback(method, world_suffix) %} 429 {% macro method_callback(method, world_suffix) %}
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 608 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
589 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{only_exposed_to_private_script}}} 609 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{only_exposed_to_private_script}}}
590 {%- endmacro %} 610 {%- endmacro %}
591 611
592 612
593 {######################################} 613 {######################################}
594 {% macro install_custom_signature(method) %} 614 {% macro install_custom_signature(method) %}
595 {% set method_callback = '%sV8Internal::%sMethodCallback' % (cpp_class_or_partia l, method.name) %} 615 {% set method_callback = '%sV8Internal::%sMethodCallback' % (cpp_class_or_partia l, method.name) %}
596 {% set method_callback_for_main_world = '%sForMainWorld' % method_callback 616 {% set method_callback_for_main_world = '%sForMainWorld' % method_callback
597 if method.is_per_world_bindings else '0' %} 617 if method.is_per_world_bindings else '0' %}
618 {% set method_length = method.overloads.length if method.overloads else method.l ength %}
598 {% set property_attribute = 619 {% set property_attribute =
599 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es) 620 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es)
600 if method.property_attributes else 'v8::None' %} 621 if method.property_attributes else 'v8::None' %}
601 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 622 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
602 static const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfig uration = { 623 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {
603 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.length}}, {{only_exposed_to_private_script}}, 624 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method_length}}, {{only_exposed_to_private_script}},
604 }; 625 };
605 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate); 626 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate);
606 {%- endmacro %} 627 {%- endmacro %}
607 628
608 {######################################} 629 {######################################}
609 {% macro install_conditionally_enabled_methods() %} 630 {% macro install_conditionally_enabled_methods() %}
610 void {{v8_class_or_partial}}::installConditionallyEnabledMethods(v8::Handle<v8:: Object> prototypeObject, v8::Isolate* isolate) 631 void {{v8_class_or_partial}}::installConditionallyEnabledMethods(v8::Handle<v8:: Object> prototypeObject, v8::Isolate* isolate)
611 { 632 {
612 {% if is_partial %} 633 {% if is_partial %}
613 {{v8_class}}::installConditionallyEnabledMethods(prototypeObject, isolate); 634 {{v8_class}}::installConditionallyEnabledMethods(prototypeObject, isolate);
614 {% endif %} 635 {% endif %}
615 {% if conditionally_enabled_methods %} 636 {% if conditionally_enabled_methods %}
616 {# Define per-context enabled operations #} 637 {# Define per-context enabled operations #}
617 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, domT emplate(isolate)); 638 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, domT emplate(isolate));
618 ExecutionContext* context = toExecutionContext(prototypeObject->CreationCont ext()); 639 ExecutionContext* context = toExecutionContext(prototypeObject->CreationCont ext());
619 ASSERT(context); 640 ASSERT(context);
620 641
621 {% for method in conditionally_enabled_methods %} 642 {% for method in conditionally_enabled_methods %}
622 {% filter per_context_enabled(method.per_context_enabled_function) %} 643 {% filter per_context_enabled(method.per_context_enabled_function) %}
623 {% filter exposed(method.exposed_test) %} 644 {% filter exposed(method.exposed_test) %}
624 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all if m ethod.overloads else method.runtime_enabled_function) %} 645 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all if m ethod.overloads else method.runtime_enabled_function) %}
625 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction()); 646 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction());
626 {% endfilter %} 647 {% endfilter %}
627 {% endfilter %} 648 {% endfilter %}
628 {% endfilter %} 649 {% endfilter %}
629 {% endfor %} 650 {% endfor %}
630 {% endif %} 651 {% endif %}
631 } 652 }
632 {%- endmacro %} 653 {%- endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/templates/interface_base.cpp ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698