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

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

Issue 2653883006: [bindings] Move callback functions from V8FooInternal namespace to V8Foo class (Closed)
Patch Set: Revert expose change Created 3 years, 10 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 generate_method(method, world_suffix) %} 4 {% macro generate_method(method, world_suffix) %}
5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) { 5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) {
6 {% filter format_remove_duplicates([ 6 {% filter format_remove_duplicates([
7 'ExceptionState exceptionState', 7 'ExceptionState exceptionState',
8 'ScriptState* scriptState = ']) %} 8 'ScriptState* scriptState = ']) %}
9 {% set define_exception_state -%} 9 {% set define_exception_state -%}
10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}"); 10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}");
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 // FIXME: Only pass context/exceptionState if instance really requires it. 477 // FIXME: Only pass context/exceptionState if instance really requires it.
478 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); 478 ExecutionContext* context = currentExecutionContext(info.GetIsolate());
479 instance->postMessage(context, message.release(), transferables.messagePorts, exceptionState); 479 instance->postMessage(context, message.release(), transferables.messagePorts, exceptionState);
480 } 480 }
481 {% endmacro %} 481 {% endmacro %}
482 482
483 483
484 {##############################################################################} 484 {##############################################################################}
485 {% macro method_callback(method, world_suffix) %} 485 {% macro method_callback(method, world_suffix) %}
486 {{exported}} void {{method.name}}MethodCallback{{world_suffix}}(const v8::Functi onCallbackInfo<v8::Value>& info) { 486 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons t v8::FunctionCallbackInfo<v8::Value>& info) {
487 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #} 487 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #}
488 {% if method.measure_as %} 488 {% if method.measure_as %}
489 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me thod.measure_as('Method')}}); 489 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me thod.measure_as('Method')}});
490 {% endif %} 490 {% endif %}
491 {% if method.deprecate_as %} 491 {% if method.deprecate_as %}
492 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{method.deprecate_as}}); 492 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{method.deprecate_as}});
493 {% endif %} 493 {% endif %}
494 {% endif %}{# not method.overloads #} 494 {% endif %}{# not method.overloads #}
495 {% if world_suffix in method.activity_logging_world_list %} 495 {% if world_suffix in method.activity_logging_world_list %}
496 {% if method.is_static %} 496 {% if method.is_static %}
497 ScriptState* scriptState = ScriptState::forFunctionObject(info); 497 ScriptState* scriptState = ScriptState::forFunctionObject(info);
498 {% else %} 498 {% else %}
499 ScriptState* scriptState = ScriptState::forReceiverObject(info); 499 ScriptState* scriptState = ScriptState::forReceiverObject(info);
500 {% endif %} 500 {% endif %}
501 V8PerContextData* contextData = scriptState->perContextData(); 501 V8PerContextData* contextData = scriptState->perContextData();
502 if (contextData && contextData->activityLogger()) { 502 if (contextData && contextData->activityLogger()) {
503 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}"); 503 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}");
504 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState); 504 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState);
505 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.data()); 505 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.data());
506 } 506 }
507 {% endif %} 507 {% endif %}
508 {% if method.is_ce_reactions %} 508 {% if method.is_ce_reactions %}
509 CEReactionsScope ceReactionsScope; 509 CEReactionsScope ceReactionsScope;
510 {% endif %} 510 {% endif %}
511 {% if method.is_custom %} 511 {% if method.is_custom %}
512 {{v8_class}}::{{method.name}}MethodCustom(info); 512 {{v8_class}}::{{method.name}}MethodCustom(info);
513 {% elif method.is_post_message %} 513 {% elif method.is_post_message %}
514 postMessageImpl("{{interface_name}}", {{v8_class}}::toImpl(info.Holder()), inf o); 514 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8 _class}}::toImpl(info.Holder()), info);
515 {% else %} 515 {% else %}
516 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info ); 516 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info );
517 {% endif %} 517 {% endif %}
518 } 518 }
519 {% endmacro %} 519 {% endmacro %}
520 520
521 521
522 {##############################################################################} 522 {##############################################################################}
523 {% macro origin_safe_method_getter(method, world_suffix) %} 523 {% macro origin_safe_method_getter(method, world_suffix) %}
524 {# TODO(dcheng): Currently, bindings must create a function object for each 524 {# TODO(dcheng): Currently, bindings must create a function object for each
525 realm as a hack to support the incumbent realm. Clean this up when Blink 525 realm as a hack to support the incumbent realm. Clean this up when Blink
526 properly supports the incumbent realm. #} 526 properly supports the incumbent realm. #}
527 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) { 527 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) {
528 static int domTemplateKey; // This address is used for a key to look up the do m template. 528 static int domTemplateKey; // This address is used for a key to look up the do m template.
529 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 529 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate());
530 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu rrentContext()); 530 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu rrentContext());
531 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo); 531 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo);
532 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate); 532 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate);
533 533
534 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe mplate(world, &domTemplateKey, {{cpp_class}}V8Internal::{{method.name}}MethodCal lback{{world_suffix}}, v8Undefined(), signature, {{method.length}}); 534 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal lback{{world_suffix}}, v8Undefined(), signature, {{method.length}});
535 // Return the function by default, unless the user script has overwritten it. 535 // Return the function by default, unless the user script has overwritten it.
536 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked()); 536 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked());
537 537
538 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 538 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
539 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::DoNotReport)) { 539 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::DoNotReport)) {
540 return; 540 return;
541 } 541 }
542 542
543 v8::Local<v8::Value> hiddenValue = V8HiddenValue::getHiddenValue(ScriptState:: current(info.GetIsolate()), v8::Local<v8::Object>::Cast(info.Holder()), v8Atomic String(info.GetIsolate(), "{{method.name}}")); 543 v8::Local<v8::Value> hiddenValue = V8HiddenValue::getHiddenValue(ScriptState:: current(info.GetIsolate()), v8::Local<v8::Object>::Cast(info.Holder()), v8Atomic String(info.GetIsolate(), "{{method.name}}"));
544 if (!hiddenValue.IsEmpty()) { 544 if (!hiddenValue.IsEmpty()) {
545 v8SetReturnValue(info, hiddenValue); 545 v8SetReturnValue(info, hiddenValue);
546 } 546 }
547 } 547 }
548 {% endmacro %}
548 549
549 {{exported}} void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}( v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info) { 550 {% macro origin_safe_method_getter_callback(method, world_suffix) %}
551 void {{v8_class_or_partial}}::{{method.name}}OriginSafeMethodGetterCallback{{wor ld_suffix}}(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info ) {
550 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}} (info); 552 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}} (info);
551 } 553 }
552 {% endmacro %} 554 {% endmacro %}
553 555
554 556
555 {##############################################################################} 557 {##############################################################################}
556 {% macro generate_constructor(constructor) %} 558 {% macro generate_constructor(constructor) %}
557 {% set name = '%sConstructorCallback' % v8_class 559 {% set name = '%sConstructorCallback' % v8_class
558 if constructor.is_named_constructor else 560 if constructor.is_named_constructor else
559 'constructor%s' % (constructor.overload_index or '') %} 561 'constructor%s' % (constructor.overload_index or '') %}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 v8::Local<v8::Object> wrapper = info.Holder(); 594 v8::Local<v8::Object> wrapper = info.Holder();
593 wrapper = impl->associateWithWrapper(info.GetIsolate(), &{{constructor_class}}:: wrapperTypeInfo, wrapper); 595 wrapper = impl->associateWithWrapper(info.GetIsolate(), &{{constructor_class}}:: wrapperTypeInfo, wrapper);
594 v8SetReturnValue(info, wrapper); 596 v8SetReturnValue(info, wrapper);
595 {% endmacro %} 597 {% endmacro %}
596 598
597 599
598 {##############################################################################} 600 {##############################################################################}
599 {% macro method_configuration(method) %} 601 {% macro method_configuration(method) %}
600 {% from 'utilities.cpp.tmpl' import property_location %} 602 {% from 'utilities.cpp.tmpl' import property_location %}
601 {% set method_callback = 603 {% set method_callback =
602 '%sV8Internal::%sMethodCallback' % (cpp_class_or_partial, method.name) %} 604 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %}
603 {% set method_callback_for_main_world = 605 {% set method_callback_for_main_world =
604 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class_or_partial, met hod.name) 606 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name)
605 if method.is_per_world_bindings else '0' %} 607 if method.is_per_world_bindings else 'nullptr' %}
606 {% set property_attribute = 608 {% set property_attribute =
607 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) 609 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes)
608 if method.property_attributes else 'v8::None' %} 610 if method.property_attributes else 'v8::None' %}
609 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' 611 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder'
610 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} 612 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %}
611 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} 613 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}}
612 {%- endmacro %} 614 {%- endmacro %}
613 615
614 616
615 {######################################} 617 {######################################}
(...skipping 21 matching lines...) Expand all
637 if method.overloads else 639 if method.overloads else
638 method.runtime_enabled_feature_name) %} 640 method.runtime_enabled_feature_name) %}
639 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 641 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
640 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 642 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
641 {% endfilter %}{# runtime_enabled() #} 643 {% endfilter %}{# runtime_enabled() #}
642 {% endfilter %}{# exposed() #} 644 {% endfilter %}{# exposed() #}
643 {% endfilter %}{# secure_context() #} 645 {% endfilter %}{# secure_context() #}
644 {% endfor %} 646 {% endfor %}
645 {% endif %} 647 {% endif %}
646 {%- endmacro %} 648 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698