OLD | NEW |
---|---|
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}}"); |
11 {%- endset %} | 11 {%- endset %} |
12 | 12 |
13 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} | 13 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} |
14 | 14 |
15 {% if 'exceptionState' in function_call or | 15 {% if 'exceptionState' in function_call or |
16 (method.returns_promise and not method.is_static) %} | 16 ((method.returns_promise or interface_name == 'Window') and not method.i s_static) %} |
17 {{define_exception_state}} | 17 {{define_exception_state}} |
18 {% if method.returns_promise %} | 18 {% if method.returns_promise %} |
19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); | 19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
20 {% endif %} | 20 {% endif %} |
21 {% endif %} | 21 {% endif %} |
22 | 22 |
23 {% if not method.is_static %} | 23 {% if not method.is_static %} |
24 {% if method.returns_promise %} | 24 {% if method.returns_promise or interface_name == 'Window' %} |
25 // V8DOMConfiguration::DoNotCheckHolder | 25 // V8DOMConfiguration::DoNotCheckHolder |
26 // Make sure that info.Holder() really points to an instance of the type. | 26 // Make sure that info.Holder() really points to an instance of the type. |
27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) { | 27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) { |
28 {{throw_type_error(method, '"Illegal invocation"')}} | 28 {{throw_type_error(method, '"Illegal invocation"')}} |
29 return; | 29 return; |
30 } | 30 } |
31 {% endif %} | 31 {% endif %} |
32 {% set local_dom_window_only = interface_name == 'Window' and not method.is_cr oss_origin %} | 32 {% set local_dom_window_only = interface_name == 'Window' and not method.is_cr oss_origin %} |
33 {% if local_dom_window_only %} | 33 {% if local_dom_window_only %} |
34 {% if method.is_check_security_for_receiver %} | 34 {% if method.is_check_security_for_receiver %} |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 | 540 |
541 {##############################################################################} | 541 {##############################################################################} |
542 {% macro origin_safe_method_getter(method, world_suffix) %} | 542 {% macro origin_safe_method_getter(method, world_suffix) %} |
543 {# TODO(dcheng): Currently, bindings must create a function object for each | 543 {# TODO(dcheng): Currently, bindings must create a function object for each |
544 realm as a hack to support the incumbent realm. Clean this up when Blink | 544 realm as a hack to support the incumbent realm. Clean this up when Blink |
545 properly supports the incumbent realm. #} | 545 properly supports the incumbent realm. #} |
546 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) { | 546 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) { |
547 static int domTemplateKey; // This address is used for a key to look up the do m template. | 547 static int domTemplateKey; // This address is used for a key to look up the do m template. |
548 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); | 548 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); |
549 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu rrentContext()); | 549 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu rrentContext()); |
550 {% if interface_name == 'Window' %} | |
551 // Note: signature is intentionally omitted for functions that use Window as | |
552 // the receiver object. A remote context's global proxy does not have the | |
553 // standard prototype chain set up, so v8 won't be able to find the receiver | |
554 // type in the prototype chain. Instead, the method implementation must do | |
555 // the check manually. | |
556 v8::Local<v8::Signature> signature; | |
haraken
2017/02/16 01:11:19
Why don't we need to have this code for OriginSafe
dcheng
2017/02/16 03:14:07
v8::Signature is only used when instantiating a ne
| |
557 {% else %} | |
550 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo); | 558 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo); |
551 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate); | 559 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate); |
560 {% endif %} | |
552 | 561 |
553 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal lback{{world_suffix}}, v8Undefined(), signature, {{method.length}}); | 562 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal lback{{world_suffix}}, v8Undefined(), signature, {{method.length}}); |
554 // Return the function by default, unless the user script has overwritten it. | 563 // Return the function by default, unless the user script has overwritten it. |
555 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked()); | 564 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked()); |
556 | 565 |
557 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 566 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); |
558 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::DoNotReport)) { | 567 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::DoNotReport)) { |
559 return; | 568 return; |
560 } | 569 } |
561 | 570 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 {% from 'utilities.cpp.tmpl' import property_location %} | 630 {% from 'utilities.cpp.tmpl' import property_location %} |
622 {% set method_callback = | 631 {% set method_callback = |
623 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} | 632 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} |
624 {% set method_callback_for_main_world = | 633 {% set method_callback_for_main_world = |
625 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) | 634 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) |
626 if method.is_per_world_bindings else 'nullptr' %} | 635 if method.is_per_world_bindings else 'nullptr' %} |
627 {% set property_attribute = | 636 {% set property_attribute = |
628 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) | 637 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) |
629 if method.property_attributes else 'v8::None' %} | 638 if method.property_attributes else 'v8::None' %} |
630 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' | 639 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' |
631 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} | 640 if method.returns_promise or interface_name == 'Window' else 'V8DOMConfig uration::CheckHolder' %} |
haraken
2017/02/16 01:11:19
I don't see any change in this CL to add a type ch
dcheng
2017/02/16 03:14:07
We only need to relax the receiver check for funct
| |
632 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} | 641 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} |
633 {%- endmacro %} | 642 {%- endmacro %} |
634 | 643 |
635 | 644 |
636 {######################################} | 645 {######################################} |
637 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} | 646 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} |
638 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; | 647 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; |
639 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); | 648 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); |
640 {%- endmacro %} | 649 {%- endmacro %} |
641 | 650 |
(...skipping 16 matching lines...) Expand all Loading... | |
658 if method.overloads else | 667 if method.overloads else |
659 method.runtime_enabled_feature_name) %} | 668 method.runtime_enabled_feature_name) %} |
660 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; | 669 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; |
661 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); | 670 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); |
662 {% endfilter %}{# runtime_enabled() #} | 671 {% endfilter %}{# runtime_enabled() #} |
663 {% endfilter %}{# exposed() #} | 672 {% endfilter %}{# exposed() #} |
664 {% endfilter %}{# secure_context() #} | 673 {% endfilter %}{# secure_context() #} |
665 {% endfor %} | 674 {% endfor %} |
666 {% endif %} | 675 {% endif %} |
667 {%- endmacro %} | 676 {%- endmacro %} |
OLD | NEW |