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

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: Comment changes 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 {# FIXME: use C++ type for local variable #}
21 {{argument.idl_type}} {{argument.name}} = 0;
22 V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, args[{{argument.index} }]->NumberValue());
23 if (!std::isnan({{argument.name}}NativeValue))
24 {# IDL type is used for clamping - to get the right bounds - since
25 different IDL types have same internal C++ type (int or unsigned) #}
26 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}Nati veValue);
27 {% elif argument.idl_type == 'SerializedScriptValue' %}
20 bool {{argument.name}}DidThrow = false; 28 bool {{argument.name}}DidThrow = false;
21 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(args [{{argument.index}}], 0, 0, {{argument.name}}DidThrow, args.GetIsolate()); 29 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(args [{{argument.index}}], 0, 0, {{argument.name}}DidThrow, args.GetIsolate());
22 if ({{argument.name}}DidThrow) 30 if ({{argument.name}}DidThrow)
23 return; 31 return;
24 {% elif argument.is_variadic_wrapper_type %} 32 {% elif argument.is_variadic_wrapper_type %}
25 Vector<{{argument.cpp_type}} > {{argument.name}}; 33 Vector<{{argument.cpp_type}} > {{argument.name}};
26 for (int i = {{argument.index}}; i < args.Length(); ++i) { 34 for (int i = {{argument.index}}; i < args.Length(); ++i) {
27 if (!V8{{argument.idl_type}}::HasInstance(args[i], args.GetIsolate(), wo rldType(args.GetIsolate()))) { 35 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()); 36 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", "parameter {{argument.index + 1}} is not of type '{{argum ent.idl_type}}'."), args.GetIsolate());
29 return; 37 return;
(...skipping 25 matching lines...) Expand all
55 63
56 {##############################################################################} 64 {##############################################################################}
57 {% macro method_callback(method) %} 65 {% macro method_callback(method) %}
58 static void {{method.name}}MethodCallback(const v8::FunctionCallbackInfo<v8::Val ue>& args) 66 static void {{method.name}}MethodCallback(const v8::FunctionCallbackInfo<v8::Val ue>& args)
59 { 67 {
60 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 68 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
61 {{cpp_class_name}}V8Internal::{{method.name}}Method(args); 69 {{cpp_class_name}}V8Internal::{{method.name}}Method(args);
62 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution"); 70 TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
63 } 71 }
64 {% endmacro %} 72 {% endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/unstable/v8_methods.py ('k') | Source/bindings/tests/idls/TestObjectPython.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698