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

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

Powered by Google App Engine
This is Rietveld 408576698