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

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

Issue 2725673002: WIP bindings: Expand usage of NativeValueTraits. (Closed)
Patch Set: Created 3 years, 9 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 -%}
10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}"); 9 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}");
11 {%- endset %}
12 10
13 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} 11 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %}
14 12
15 {% if 'exceptionState' in function_call or
16 (method.returns_promise and not method.is_static) %}
17 {{define_exception_state}}
18 {% if method.returns_promise %} 13 {% if method.returns_promise %}
19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); 14 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState);
20 {% endif %} 15 {% endif %}
21 {% endif %}
22 16
23 {% if not method.is_static %} 17 {% if not method.is_static %}
24 {% if method.returns_promise %} 18 {% if method.returns_promise %}
25 // V8DOMConfiguration::DoNotCheckHolder 19 // V8DOMConfiguration::DoNotCheckHolder
26 // Make sure that info.Holder() really points to an instance of the type. 20 // Make sure that info.Holder() really points to an instance of the type.
27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) { 21 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) {
28 {{throw_type_error(method, '"Illegal invocation"')}} 22 {{throw_type_error(method, '"Illegal invocation"')}}
29 return; 23 return;
30 } 24 }
31 {% endif %} 25 {% endif %}
32 {% if interface_name == 'Window' and not method.is_cross_origin %} 26 {% if interface_name == 'Window' and not method.is_cross_origin %}
33 // Same-origin methods are never exposed via the cross-origin interceptors. 27 // Same-origin methods are never exposed via the cross-origin interceptors.
34 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast 28 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast
35 // here. 29 // here.
36 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder())); 30 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder()));
37 {% else %} 31 {% else %}
38 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 32 {{cpp_class}}* impl = NativeValueTraits<{{cpp_class}}>::nativeValue(info.GetIs olate(), info.Holder(), exceptionState);
39 {% endif %}{# interface_name == 'Window' and not method.is_cross_origin #} 33 {% endif %}{# interface_name == 'Window' and not method.is_cross_origin #}
40 {% endif %}{# not method.is_static #} 34 {% endif %}{# not method.is_static #}
41 35
42 {# Security checks #} 36 {# Security checks #}
43 {% if method.is_check_security_for_return_value %} 37 {% if method.is_check_security_for_return_value %}
44 {{define_exception_state}}
45 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) { 38 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) {
46 v8SetReturnValueNull(info); 39 v8SetReturnValueNull(info);
47 return; 40 return;
48 } 41 }
49 {% endif %} 42 {% endif %}
50 43
51 {% if 'scriptState' in function_call %} 44 {% if 'scriptState' in function_call %}
52 {% if method.is_static %} 45 {% if method.is_static %}
53 ScriptState* scriptState = ScriptState::forFunctionObject(info); 46 ScriptState* scriptState = ScriptState::forFunctionObject(info);
54 {% else %} 47 {% else %}
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 if method.overloads else 619 if method.overloads else
627 method.runtime_enabled_feature_name) %} 620 method.runtime_enabled_feature_name) %}
628 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 621 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
629 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 622 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
630 {% endfilter %}{# runtime_enabled() #} 623 {% endfilter %}{# runtime_enabled() #}
631 {% endfilter %}{# exposed() #} 624 {% endfilter %}{# exposed() #}
632 {% endfilter %}{# secure_context() #} 625 {% endfilter %}{# secure_context() #}
633 {% endfor %} 626 {% endfor %}
634 {% endif %} 627 {% endif %}
635 {%- endmacro %} 628 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698