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

Side by Side Diff: Source/bindings/templates/methods.cpp

Issue 53483004: IDL compiler: [Clamp] for arguments (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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) %} 2 {% macro generate_method(method) %}
3 static void {{method.name}}Method(const v8::FunctionCallbackInfo<v8::Value>& arg s) 3 static void {{method.name}}Method(const v8::FunctionCallbackInfo<v8::Value>& arg s)
4 { 4 {
5 {% if method.number_of_required_arguments %} 5 {% if method.number_of_required_arguments %}
6 if (UNLIKELY(args.Length() < {{method.number_of_required_arguments}})) { 6 if (UNLIKELY(args.Length() < {{method.number_of_required_arguments}})) {
7 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_requ ired_arguments}}, args.Length())), args.GetIsolate()); 7 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{ interface_name}}", ExceptionMessages::notEnoughArguments({{method.number_of_requ ired_arguments}}, args.Length())), args.GetIsolate());
8 return; 8 return;
9 } 9 }
10 {% endif %} 10 {% endif %}
11 {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(args.Holder()); 11 {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(args.Holder());
12 {% for argument in method.arguments %} 12 {% for argument in method.arguments %}
13 {% if argument.is_optional %} 13 {% if argument.is_optional %}
14 if (UNLIKELY(args.Length() <= {{argument.index}})) { 14 if (UNLIKELY(args.Length() <= {{argument.index}})) {
15 {{argument.cpp_method}}; 15 {{argument.cpp_method}};
16 return; 16 return;
17 } 17 }
18 {% endif %} 18 {% endif %}
19 {% if argument.idl_type == 'SerializedScriptValue' %} 19 {% if argument.is_clamp %}
20 {# For clamping, IDL type (not C++ type) is used for a C++ variable #}
21 {{argument.idl_type}} {{argument.name}} = 0;
Nils Barth (inactive) 2013/10/31 03:22:44 We might want to use |cpp_type| here, so it's the
Nils Barth (inactive) 2013/10/31 04:18:25 I've put a FIXME here.
22 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, args[{{argument.index} }]->NumberValue());
23 if (!std::isnan({{argument.name}}NativeValue))
24 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}Nati veValue);
Nils Barth (inactive) 2013/10/31 03:22:44 OTOH, we need |idl_type| here for the actual clamp
Nils Barth (inactive) 2013/10/31 04:18:25 I've put a comment here.
25 {% elif argument.idl_type == 'SerializedScriptValue' %}
20 bool {{argument.name}}DidThrow = false; 26 bool {{argument.name}}DidThrow = false;
21 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(args [{{argument.index}}], 0, 0, {{argument.name}}DidThrow, args.GetIsolate()); 27 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(args [{{argument.index}}], 0, 0, {{argument.name}}DidThrow, args.GetIsolate());
22 if ({{argument.name}}DidThrow) 28 if ({{argument.name}}DidThrow)
23 return; 29 return;
24 {% elif argument.is_variadic_wrapper_type %} 30 {% elif argument.is_variadic_wrapper_type %}
25 Vector<{{argument.cpp_type}} > {{argument.name}}; 31 Vector<{{argument.cpp_type}} > {{argument.name}};
26 for (int i = {{argument.index}}; i < args.Length(); ++i) { 32 for (int i = {{argument.index}}; i < args.Length(); ++i) {
27 if (!V8{{argument.idl_type}}::HasInstance(args[i], args.GetIsolate(), wo rldType(args.GetIsolate()))) { 33 if (!V8{{argument.idl_type}}::HasInstance(args[i], args.GetIsolate(), wo rldType(args.GetIsolate()))) {
28 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", "parameter {{argument.index + 1}} is not of type '{{argum ent.idl_type}}'."), args.GetIsolate()); 34 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", "parameter {{argument.index + 1}} is not of type '{{argum ent.idl_type}}'."), args.GetIsolate());
29 return; 35 return;
(...skipping 25 matching lines...) Expand all
55 61
56 {##############################################################################} 62 {##############################################################################}
57 {% macro method_callback(method) %} 63 {% macro method_callback(method) %}
58 static void {{method.name}}MethodCallback(const v8::FunctionCallbackInfo<v8::Val ue>& args) 64 static void {{method.name}}MethodCallback(const v8::FunctionCallbackInfo<v8::Val ue>& args)
59 { 65 {
60 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 66 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
61 {{cpp_class_name}}V8Internal::{{method.name}}Method(args); 67 {{cpp_class_name}}V8Internal::{{method.name}}Method(args);
62 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 68 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
63 } 69 }
64 {% endmacro %} 70 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698