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 { | 9 { |
10 {% set define_exception_state -%} | 10 {% set define_exception_state -%} |
11 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}"); | 11 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}"); |
12 {%- endset %} | 12 {%- endset %} |
13 | 13 |
14 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} | 14 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} |
15 | 15 |
16 {% if 'exceptionState' in function_call %} | 16 {% if 'exceptionState' in function_call or |
17 (method.returns_promise and not method.is_static) %} | |
17 {{define_exception_state}} | 18 {{define_exception_state}} |
18 {% if method.returns_promise %} | 19 {% if method.returns_promise %} |
19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); | 20 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
20 {% endif %} | 21 {% endif %} |
21 {% endif %} | 22 {% endif %} |
22 | 23 |
24 {% set holder = 'info.Holder()' %} | |
25 {% if method.returns_promise and not method.is_static %} | |
26 // V8DOMConfiguration::DoNotCheckHolder | |
27 // Make sure that info.Holder() really points to an instance of the type. | |
28 {% if is_global or interface_name == 'WorkerGlobalScope' %} | |
29 // The empty v8::Signature makes info.Holder() the global proxy object | |
30 // instead of the global object, thus we need to retrieve the global object | |
31 // as the prototype object of the global proxy object. | |
32 v8::Local<v8::Object> holder = | |
33 info.Holder()->GetPrototype().As<v8::Object>(); | |
haraken
2016/10/21 08:11:28
Can we remove the additional complexity by using V
Yuki
2016/10/21 10:11:19
I tried it, and I found it didn't work as expected
| |
34 {% set holder = 'holder' %} | |
35 {% endif %} | |
36 if (!{{v8_class}}::hasInstance({{holder}}, info.GetIsolate())) { | |
37 {{throw_type_error(method, '"Illegal invocation"')}} | |
38 return; | |
39 } | |
40 {% endif %} | |
41 | |
23 {% if not method.is_static %} | 42 {% if not method.is_static %} |
24 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 43 {{cpp_class}}* impl = {{v8_class}}::toImpl({{holder}}); |
25 {% endif %} | 44 {% endif %} |
26 | 45 |
27 {# Security checks #} | 46 {# Security checks #} |
28 {% if method.is_check_security_for_receiver %} | 47 {% if method.is_check_security_for_receiver %} |
29 {{define_exception_state}} | 48 {{define_exception_state}} |
30 {% if interface_name == 'EventTarget' %} | 49 {% if interface_name == 'EventTarget' %} |
31 // Performance hack for EventTarget. Checking whether it's a Window or not | 50 // Performance hack for EventTarget. Checking whether it's a Window or not |
32 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% | 51 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% |
33 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE | 52 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE |
34 // didn't work in this case. | 53 // didn't work in this case. |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 {% from 'utilities.cpp.tmpl' import property_location %} | 635 {% from 'utilities.cpp.tmpl' import property_location %} |
617 {% set method_callback = | 636 {% set method_callback = |
618 '%sV8Internal::%sMethodCallback' % (cpp_class_or_partial, method.name) %} | 637 '%sV8Internal::%sMethodCallback' % (cpp_class_or_partial, method.name) %} |
619 {% set method_callback_for_main_world = | 638 {% set method_callback_for_main_world = |
620 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class_or_partial, met hod.name) | 639 '%sV8Internal::%sMethodCallbackForMainWorld' % (cpp_class_or_partial, met hod.name) |
621 if method.is_per_world_bindings else '0' %} | 640 if method.is_per_world_bindings else '0' %} |
622 {% set property_attribute = | 641 {% set property_attribute = |
623 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) | 642 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) |
624 if method.property_attributes else 'v8::None' %} | 643 if method.property_attributes else 'v8::None' %} |
625 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} | 644 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} |
626 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr operty_location(method)}}} | 645 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' |
646 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} | |
647 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{only_exposed_to_private_script}}, {{pr operty_location(method)}}, {{holder_check}}} | |
627 {%- endmacro %} | 648 {%- endmacro %} |
628 | 649 |
629 | 650 |
630 {######################################} | 651 {######################################} |
631 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} | 652 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} |
632 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; | 653 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; |
633 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); | 654 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); |
634 {%- endmacro %} | 655 {%- endmacro %} |
635 | 656 |
636 | 657 |
(...skipping 15 matching lines...) Expand all Loading... | |
652 if method.overloads else | 673 if method.overloads else |
653 method.runtime_enabled_function) %} | 674 method.runtime_enabled_function) %} |
654 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; | 675 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; |
655 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); | 676 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); |
656 {% endfilter %}{# runtime_enabled() #} | 677 {% endfilter %}{# runtime_enabled() #} |
657 {% endfilter %}{# exposed() #} | 678 {% endfilter %}{# exposed() #} |
658 {% endfilter %}{# secure_context() #} | 679 {% endfilter %}{# secure_context() #} |
659 {% endfor %} | 680 {% endfor %} |
660 {% endif %} | 681 {% endif %} |
661 {%- endmacro %} | 682 {%- endmacro %} |
OLD | NEW |