OLD | NEW |
1 {##############################################################################} | 1 {##############################################################################} |
2 {% macro generate_method(method, world_suffix) %} | 2 {% macro generate_method(method, world_suffix) %} |
3 {% filter conditional(method.conditional_string) %} | 3 {% filter conditional(method.conditional_string) %} |
4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
5 { | 5 { |
6 {# Local variables #} | 6 {# Local variables #} |
7 {% if method.has_exception_state %} | 7 {% if method.has_exception_state %} |
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
9 {% endif %} | 9 {% endif %} |
10 {% if method.number_of_required_arguments %} | 10 {% if method.number_of_required_arguments %} |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 {% endif %} | 38 {% endif %} |
39 {% if method.is_check_security_for_node %} | 39 {% if method.is_check_security_for_node %} |
40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { | 40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { |
41 v8SetReturnValueNull(info); | 41 v8SetReturnValueNull(info); |
42 exceptionState.throwIfNeeded(); | 42 exceptionState.throwIfNeeded(); |
43 return; | 43 return; |
44 } | 44 } |
45 {% endif %} | 45 {% endif %} |
46 {# Call method #} | 46 {# Call method #} |
47 {% for argument in method.arguments %} | 47 {% if method.arguments %} |
48 {{generate_argument(method, argument, world_suffix) | indent}} | 48 {{generate_arguments(method, world_suffix) | indent}} |
49 {% endfor %} | 49 {% endif %} |
50 {% if world_suffix %} | 50 {% if world_suffix %} |
51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
52 {% else %} | 52 {% else %} |
53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} | 53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} |
54 {% endif %} | 54 {% endif %} |
55 {# Post-call #} | 55 {# Post-call #} |
56 {% if method.has_event_listener_argument %} | 56 {% if method.has_event_listener_argument %} |
57 {{hidden_dependency_action(method.name) | indent}} | 57 {{hidden_dependency_action(method.name) | indent}} |
58 {% endif %} | 58 {% endif %} |
59 } | 59 } |
60 {% endfilter %} | 60 {% endfilter %} |
61 {% endmacro %} | 61 {% endmacro %} |
62 | 62 |
63 | 63 |
64 {######################################} | 64 {######################################} |
65 {% macro hidden_dependency_action(method_name) %} | 65 {% macro hidden_dependency_action(method_name) %} |
66 if (listener && !impl->toNode()) | 66 if (listener && !impl->toNode()) |
67 {% if method_name == 'addEventListener' %} | 67 {% if method_name == 'addEventListener' %} |
68 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac
heIndex, info.GetIsolate()); | 68 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac
heIndex, info.GetIsolate()); |
69 {% else %}{# method_name == 'removeEventListener' #} | 69 {% else %}{# method_name == 'removeEventListener' #} |
70 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen
erCacheIndex, info.GetIsolate()); | 70 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen
erCacheIndex, info.GetIsolate()); |
71 {% endif %} | 71 {% endif %} |
72 {% endmacro %} | 72 {% endmacro %} |
73 | 73 |
74 | 74 |
75 {######################################} | 75 {######################################} |
| 76 {% macro generate_arguments(method, world_suffix) %} |
| 77 {% for argument in method.arguments %} |
| 78 {{generate_argument_var_declaration(argument)}}; |
| 79 {% endfor %} |
| 80 { |
| 81 {% if method.arguments_need_try_catch %} |
| 82 v8::TryCatch block; |
| 83 {% endif %} |
| 84 {% for argument in method.arguments %} |
| 85 {{generate_argument(method, argument, world_suffix) | indent}} |
| 86 {% endfor %} |
| 87 } |
| 88 {% endmacro %} |
| 89 |
| 90 |
| 91 {######################################} |
| 92 {% macro generate_argument_var_declaration(argument) %} |
| 93 {% if argument.is_callback_interface %} |
| 94 {# FIXME: remove EventListener special case #} |
| 95 {% if argument.idl_type == 'EventListener' %} |
| 96 RefPtr<{{argument.idl_type}}> {{argument.name}} |
| 97 {%- else %} |
| 98 OwnPtr<{{argument.idl_type}}> {{argument.name}} |
| 99 {%- endif %}{# argument.idl_type == 'EventListener' #} |
| 100 {%- elif argument.is_clamp %}{# argument.is_callback_interface #} |
| 101 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| 102 {{argument.cpp_type}} {{argument.name}} = 0 |
| 103 {%- else %} |
| 104 {{argument.cpp_type}} {{argument.name}} |
| 105 {%- endif %} |
| 106 {% endmacro %} |
| 107 |
| 108 |
| 109 {######################################} |
76 {% macro generate_argument(method, argument, world_suffix) %} | 110 {% macro generate_argument(method, argument, world_suffix) %} |
77 {% if argument.is_optional and not argument.has_default and | 111 {% if argument.is_optional and not argument.has_default and |
78 argument.idl_type != 'Dictionary' and | 112 argument.idl_type != 'Dictionary' and |
79 not argument.is_callback_interface %} | 113 not argument.is_callback_interface %} |
80 {# Optional arguments without a default value generate an early call with | 114 {# Optional arguments without a default value generate an early call with |
81 fewer arguments if they are omitted. | 115 fewer arguments if they are omitted. |
82 Optional Dictionary arguments default to empty dictionary. #} | 116 Optional Dictionary arguments default to empty dictionary. #} |
83 if (UNLIKELY(info.Length() <= {{argument.index}})) { | 117 if (UNLIKELY(info.Length() <= {{argument.index}})) { |
84 {% if world_suffix %} | 118 {% if world_suffix %} |
85 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} | 119 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} |
86 {% else %} | 120 {% else %} |
87 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} | 121 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} |
88 {% endif %} | 122 {% endif %} |
89 {% if argument.has_event_listener_argument %} | 123 {% if argument.has_event_listener_argument %} |
90 {{hidden_dependency_action(method.name) | indent}} | 124 {{hidden_dependency_action(method.name) | indent}} |
91 {% endif %} | 125 {% endif %} |
92 return; | 126 return; |
93 } | 127 } |
94 {% endif %} | 128 {% endif %} |
95 {% if argument.has_type_checking_interface %} | 129 {% if argument.has_type_checking_interface %} |
96 {# Type checking for wrapper interface types (if interface not implemented, | 130 {# Type checking for wrapper interface types (if interface not implemented, |
97 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 131 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
98 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi
nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI
nstance(info[{{argument.index}}], info.GetIsolate())) { | 132 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi
nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI
nstance(info[{{argument.index}}], info.GetIsolate())) { |
99 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 133 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
100 (argument.index + 1, argument.idl_type)) | indent
}} | 134 (argument.index + 1, argument.idl_type)) | indent
}} |
101 return; | 135 return; |
102 } | 136 } |
103 {% endif %} | 137 {% endif %}{# argument.has_type_checking_interface #} |
104 {% if argument.is_callback_interface %} | 138 {% if argument.is_callback_interface %} |
105 {# FIXME: remove EventListener special case #} | 139 {# FIXME: remove EventListener special case #} |
106 {% if argument.idl_type == 'EventListener' %} | 140 {% if argument.idl_type == 'EventListener' %} |
107 {% if method.name == 'removeEventListener' %} | 141 {% if method.name == 'removeEventListener' %} |
108 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL
istener(info[1], false, ListenerFindOnly); | 142 {{argument.name}} = V8EventListenerList::getEventListener(info[1], false, Listen
erFindOnly); |
109 {% else %}{# method.name == 'addEventListener' #} | 143 {% else %}{# method.name == 'addEventListener' #} |
110 RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventL
istener(info[1], false, ListenerFindOrCreate); | 144 {{argument.name}} = V8EventListenerList::getEventListener(info[1], false, Listen
erFindOrCreate); |
111 {% endif %}{# method.name #} | 145 {% endif %}{# method.name #} |
112 {% else %} | 146 {% else %}{# argument.idl_type == 'EventListener' #} |
113 {# Callback functions must be functions: | 147 {# Callback functions must be functions: |
114 http://www.w3.org/TR/WebIDL/#es-callback-function #} | 148 http://www.w3.org/TR/WebIDL/#es-callback-function #} |
115 {% if argument.is_optional %} | 149 {% if argument.is_optional %} |
116 OwnPtr<{{argument.idl_type}}> {{argument.name}}; | |
117 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind
ex}}])) { | 150 if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind
ex}}])) { |
118 if (!info[{{argument.index}}]->IsFunction()) { | 151 if (!info[{{argument.index}}]->IsFunction()) { |
119 {{throw_type_error(method, | 152 {{throw_type_error(method, |
120 '"The callback provided as parameter %s is not a function."' % | 153 '"The callback provided as parameter %s is not a function."' % |
121 (argument.index + 1)) | indent(8)}} | 154 (argument.index + 1)) | indent(8)}} |
122 return; | 155 return; |
123 } | 156 } |
124 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function>
::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate())); | 157 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function>
::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate())); |
125 } | 158 } |
126 {% else %} | 159 {% else %}{# argument.is_optional #} |
127 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { | 160 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { |
128 {{throw_type_error(method, | 161 {{throw_type_error(method, |
129 '"The callback provided as parameter %s is not a function."' % | 162 '"The callback provided as parameter %s is not a function."' % |
130 (argument.index + 1)) | indent }} | 163 (argument.index + 1)) | indent }} |
131 return; | 164 return; |
132 } | 165 } |
133 OwnPtr<{{argument.idl_type}}> {{argument.name}} = {% if argument.is_nullable %}i
nfo[{{argument.index}}]->IsNull() ? nullptr : {% endif %}V8{{argument.idl_type}}
::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), currentExecut
ionContext(info.GetIsolate())); | 166 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul
l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Functi
on>::Cast(info[{{argument.index}}]), currentExecutionContext(info.GetIsolate()))
; |
134 {% endif %}{# argument.is_optional #} | 167 {% endif %}{# argument.is_optional #} |
135 {% endif %}{# argument.idl_type == 'EventListener' #} | 168 {% endif %}{# argument.idl_type == 'EventListener' #} |
136 {% elif argument.is_clamp %}{# argument.is_callback_interface #} | 169 {% elif argument.is_clamp %}{# argument.is_callback_interface #} |
137 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 170 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
138 {{argument.cpp_type}} {{argument.name}} = 0; | 171 double {{argument.name}}NativeValue; |
139 TONATIVE_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->Nu
mberValue()); | 172 TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->N
umberValue()); |
140 if (!std::isnan({{argument.name}}NativeValue)) | 173 if (!std::isnan({{argument.name}}NativeValue)) |
141 {# IDL type is used for clamping, for the right bounds, since different | 174 {# IDL type is used for clamping, for the right bounds, since different |
142 IDL integer types have same internal C++ type (int or unsigned) #} | 175 IDL integer types have same internal C++ type (int or unsigned) #} |
143 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); | 176 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa
lue); |
144 {% elif argument.idl_type == 'SerializedScriptValue' %} | 177 {% elif argument.idl_type == 'SerializedScriptValue' %} |
145 {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{a
rgument.index}}], 0, 0, exceptionState, info.GetIsolate()); | 178 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0
, exceptionState, info.GetIsolate()); |
146 if (exceptionState.throwIfNeeded()) | 179 if (exceptionState.throwIfNeeded()) |
147 return; | 180 return; |
148 {% elif argument.is_variadic_wrapper_type %} | 181 {% elif argument.is_variadic_wrapper_type %} |
149 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; | |
150 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 182 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
151 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 183 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
152 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 184 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
153 (argument.index + 1, argument.idl_type)) | in
dent(8)}} | 185 (argument.index + 1, argument.idl_type)) | in
dent(8)}} |
154 return; | 186 return; |
155 } | 187 } |
156 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); | 188 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob
ject>::Cast(info[i]))); |
157 } | 189 } |
158 {% else %} | 190 {% else %} |
159 {{argument.v8_value_to_local_cpp_value}}; | 191 {{argument.v8_value_to_local_cpp_value}}; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 {% if constructor.has_exception_state %} | 432 {% if constructor.has_exception_state %} |
401 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); | 433 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
402 {% endif %} | 434 {% endif %} |
403 {% if interface_length and not constructor.overload_index %} | 435 {% if interface_length and not constructor.overload_index %} |
404 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} | 436 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} |
405 if (UNLIKELY(info.Length() < {{interface_length}})) { | 437 if (UNLIKELY(info.Length() < {{interface_length}})) { |
406 {{throw_arity_type_error(constructor, interface_length)}}; | 438 {{throw_arity_type_error(constructor, interface_length)}}; |
407 return; | 439 return; |
408 } | 440 } |
409 {% endif %} | 441 {% endif %} |
410 {% for argument in constructor.arguments %} | 442 {% if constructor.arguments %} |
411 {{generate_argument(constructor, argument) | indent}} | 443 {{generate_arguments(constructor) | indent}} |
412 {% endfor %} | 444 {% endif %} |
413 {% if is_constructor_call_with_execution_context %} | 445 {% if is_constructor_call_with_execution_context %} |
414 ExecutionContext* context = currentExecutionContext(isolate); | 446 ExecutionContext* context = currentExecutionContext(isolate); |
415 {% endif %} | 447 {% endif %} |
416 {% if is_constructor_call_with_document %} | 448 {% if is_constructor_call_with_document %} |
417 Document& document = *toDocument(currentExecutionContext(isolate)); | 449 Document& document = *toDocument(currentExecutionContext(isolate)); |
418 {% endif %} | 450 {% endif %} |
419 {{constructor.cpp_type}} impl = {{cpp_class}}::create({{constructor.argument
_list | join(', ')}}); | 451 {{constructor.cpp_type}} impl = {{cpp_class}}::create({{constructor.argument
_list | join(', ')}}); |
420 {% if is_constructor_raises_exception %} | 452 {% if is_constructor_raises_exception %} |
421 if (exceptionState.throwIfNeeded()) | 453 if (exceptionState.throwIfNeeded()) |
422 return; | 454 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 498 |
467 {% if constructor.has_exception_state %} | 499 {% if constructor.has_exception_state %} |
468 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); | 500 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
469 {% endif %} | 501 {% endif %} |
470 {% if constructor.number_of_required_arguments %} | 502 {% if constructor.number_of_required_arguments %} |
471 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ | 503 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ |
472 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; | 504 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; |
473 return; | 505 return; |
474 } | 506 } |
475 {% endif %} | 507 {% endif %} |
476 {% for argument in constructor.arguments %} | 508 {% if constructor.arguments %} |
477 {{generate_argument(constructor, argument) | indent}} | 509 {{generate_arguments(constructor) | indent}} |
478 {% endfor %} | 510 {% endif %} |
479 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); | 511 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); |
480 {% if is_constructor_raises_exception %} | 512 {% if is_constructor_raises_exception %} |
481 if (exceptionState.throwIfNeeded()) | 513 if (exceptionState.throwIfNeeded()) |
482 return; | 514 return; |
483 {% endif %} | 515 {% endif %} |
484 | 516 |
485 {{generate_constructor_wrapper(constructor) | indent}} | 517 {{generate_constructor_wrapper(constructor) | indent}} |
486 } | 518 } |
487 {% endmacro %} | 519 {% endmacro %} |
OLD | NEW |