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

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

Issue 618373003: [bindings] partial interfaces should not violate componentization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed patch conflict Created 6 years, 2 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 {##############################################################################} 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 {% endif %} 374 {% endif %}
375 {# First resolve by length #} 375 {# First resolve by length #}
376 {# 2. Initialize argcount to be min(maxarg, n). #} 376 {# 2. Initialize argcount to be min(maxarg, n). #}
377 switch (std::min({{overloads.maxarg}}, info.Length())) { 377 switch (std::min({{overloads.maxarg}}, info.Length())) {
378 {# 3. Remove from S all entries whose type list is not of length argcount. # } 378 {# 3. Remove from S all entries whose type list is not of length argcount. # }
379 {% for length, tests_methods in overloads.length_tests_methods %} 379 {% for length, tests_methods in overloads.length_tests_methods %}
380 {# 10. If i = d, then: #} 380 {# 10. If i = d, then: #}
381 case {{length}}: 381 case {{length}}:
382 {# Then resolve by testing argument #} 382 {# Then resolve by testing argument #}
383 {% for test, method in tests_methods %} 383 {% for test, method in tests_methods %}
384 {% if method.visible %}
384 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and 385 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and
385 method.runtime_enabled_function) %} 386 method.runtime_enabled_function) %}
386 if ({{test}}) { 387 if ({{test}}) {
387 {% if method.measure_as and not overloads.measure_all_as %} 388 {% if method.measure_as and not overloads.measure_all_as %}
388 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecut ionContext(info.GetIsolate()), UseCounter::{{method.measure_as}}); 389 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecut ionContext(info.GetIsolate()), UseCounter::{{method.measure_as}});
389 {% endif %} 390 {% endif %}
390 {% if method.deprecate_as and not overloads.deprecate_all_as %} 391 {% if method.deprecate_as and not overloads.deprecate_all_as %}
391 UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), ca llingExecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}}); 392 UseCounter::countDeprecationIfNotPrivateScript(info.GetIsolate(), ca llingExecutionContext(info.GetIsolate()), UseCounter::{{method.deprecate_as}});
392 {% endif %} 393 {% endif %}
393 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info) ; 394 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info) ;
394 return; 395 return;
395 } 396 }
396 {% endfilter %} 397 {% endfilter %}
398 {% endif %}
397 {% endfor %} 399 {% endfor %}
398 break; 400 break;
399 {% endfor %} 401 {% endfor %}
402 {% if is_partial or not overloads.has_partial_overloads %}
400 default: 403 default:
404 {# If methods are overloaded between interface and partial interface #}
405 {# definitions, need to invoke methods defined in the partial #}
406 {# interface. #}
407 {# FIXME: we do not need to always generate this code. #}
401 {# Invalid arity, throw error #} 408 {# Invalid arity, throw error #}
402 {# Report full list of valid arities if gaps and above minimum #} 409 {# Report full list of valid arities if gaps and above minimum #}
403 {% if overloads.valid_arities %} 410 {% if overloads.valid_arities %}
404 if (info.Length() >= {{overloads.minarg}}) { 411 if (info.Length() >= {{overloads.minarg}}) {
405 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); 412 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length());
406 exceptionState.throwIfNeeded(); 413 exceptionState.throwIfNeeded();
407 return; 414 return;
408 } 415 }
409 {% endif %} 416 {% endif %}
410 {# Otherwise just report "not enough arguments" #} 417 {# Otherwise just report "not enough arguments" #}
411 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.minarg}}, info.Length())); 418 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.minarg}}, info.Length()));
412 exceptionState.throwIfNeeded(); 419 exceptionState.throwIfNeeded();
413 return; 420 return;
421 {% endif %}
414 } 422 }
423 {% if not is_partial and overloads.has_partial_overloads %}
424 ASSERT({{overloads.name}}MethodForPartialInterface);
425 ({{overloads.name}}MethodForPartialInterface)(info);
426 {% else %}
415 {# No match, throw error #} 427 {# No match, throw error #}
416 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); 428 exceptionState.throwTypeError("No function was found that matched the signat ure provided.");
417 exceptionState.throwIfNeeded(); 429 exceptionState.throwIfNeeded();
430 {% endif %}
418 } 431 }
419 {% endmacro %} 432 {% endmacro %}
420 433
421 434
422 {##############################################################################} 435 {##############################################################################}
423 {% macro method_callback(method, world_suffix) %} 436 {% macro method_callback(method, world_suffix) %}
424 {% filter conditional(method.conditional_string) %} 437 {% filter conditional(method.conditional_string) %}
425 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info) 438 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info)
426 { 439 {
427 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 440 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
(...skipping 14 matching lines...) Expand all
442 if (contextData && contextData->activityLogger()) { 455 if (contextData && contextData->activityLogger()) {
443 {% endif %} 456 {% endif %}
444 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{metho d.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 457 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{metho d.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
445 Vector<v8::Handle<v8::Value> > loggerArgs = toImplArguments<v8::Handle<v 8::Value> >(info, 0, exceptionState); 458 Vector<v8::Handle<v8::Value> > loggerArgs = toImplArguments<v8::Handle<v 8::Value> >(info, 0, exceptionState);
446 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.na me}}", info.Length(), loggerArgs.data()); 459 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.na me}}", info.Length(), loggerArgs.data());
447 } 460 }
448 {% endif %} 461 {% endif %}
449 {% if method.is_custom %} 462 {% if method.is_custom %}
450 {{v8_class}}::{{method.name}}MethodCustom(info); 463 {{v8_class}}::{{method.name}}MethodCustom(info);
451 {% else %} 464 {% else %}
452 {{cpp_class}}V8Internal::{{method.name}}Method{{world_suffix}}(info); 465 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(in fo);
453 {% endif %} 466 {% endif %}
454 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 467 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
455 } 468 }
456 {% endfilter %} 469 {% endfilter %}
457 {% endmacro %} 470 {% endmacro %}
458 471
459 472
460 {##############################################################################} 473 {##############################################################################}
461 {% macro origin_safe_method_getter(method, world_suffix) %} 474 {% macro origin_safe_method_getter(method, world_suffix) %}
462 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) 475 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate()); 609 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate());
597 {% endif %} 610 {% endif %}
598 {% endif %} 611 {% endif %}
599 v8SetReturnValue(info, wrapper); 612 v8SetReturnValue(info, wrapper);
600 {% endmacro %} 613 {% endmacro %}
601 614
602 615
603 {##############################################################################} 616 {##############################################################################}
604 {% macro method_configuration(method) %} 617 {% macro method_configuration(method) %}
605 {% set method_callback = 618 {% set method_callback =
606 '%sV8Internal::%sMethodCallback' % (cpp_class, method.name) %} 619 '%sV8Internal::%sMethodCallback' % (cpp_class_or_partial, method.name) %}
607 {% set method_callback_for_main_world = 620 {% set method_callback_for_main_world =
608 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class, method.name) 621 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class_or_partial, method. name)
609 if method.is_per_world_bindings else '0' %} 622 if method.is_per_world_bindings else '0' %}
610 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 623 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
611 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{only_exposed_to_private_script}}} 624 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{only_exposed_to_private_script}}}
612 {%- endmacro %} 625 {%- endmacro %}
613 626
614 627
615 {######################################} 628 {######################################}
616 {% macro install_custom_signature(method) %} 629 {% macro install_custom_signature(method) %}
617 {% set method_callback = '%sV8Internal::%sMethodCallback' % (cpp_class, method.n ame) %} 630 {% set method_callback = '%sV8Internal::%sMethodCallback' % (cpp_class_or_partia l, method.name) %}
618 {% set method_callback_for_main_world = '%sForMainWorld' % method_callback 631 {% set method_callback_for_main_world = '%sForMainWorld' % method_callback
619 if method.is_per_world_bindings else '0' %} 632 if method.is_per_world_bindings else '0' %}
620 {% set property_attribute = 633 {% set property_attribute =
621 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es) 634 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es)
622 if method.property_attributes else 'v8::None' %} 635 if method.property_attributes else 'v8::None' %}
623 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 636 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
624 static const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfig uration = { 637 static const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfig uration = {
625 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.length}}, {{only_exposed_to_private_script}}, 638 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.length}}, {{only_exposed_to_private_script}},
626 }; 639 };
627 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate); 640 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate);
628 {%- endmacro %} 641 {%- endmacro %}
642
643 {######################################}
644 {% macro install_conditionally_enabled_methods() %}
645 void {{v8_class_or_partial}}::installConditionallyEnabledMethods(v8::Handle<v8:: Object> prototypeObject, v8::Isolate* isolate)
646 {
647 {% if is_partial %}
648 {{v8_class}}::installConditionallyEnabledMethods(prototypeObject, isolate);
649 {% endif %}
650 {% if conditionally_enabled_methods %}
651 {# Define per-context enabled operations #}
652 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, domT emplate(isolate));
653 ExecutionContext* context = toExecutionContext(prototypeObject->CreationCont ext());
654 ASSERT(context);
655
656 {% for method in conditionally_enabled_methods %}
657 {% filter per_context_enabled(method.per_context_enabled_function) %}
658 {% filter exposed(method.exposed_test) %}
659 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());
660 {% endfilter %}
661 {% endfilter %}
662 {% endfor %}
663 {% endif %}
664 }
665 {%- endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/templates/interface_base.cpp ('k') | Source/bindings/templates/partial_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698