| 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 {% if method.has_exception_state %} | 7 {% if method.has_exception_state %} |
| 7 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()); |
| 8 {% endif %} | 9 {% endif %} |
| 9 {# FIXME: remove these special cases: http://crbug.com/353484 #} | 10 {% if method.number_of_required_arguments %} |
| 10 {% if method.number_of_required_arguments and not | |
| 11 method.name in ['addEventListener', 'removeEventListener' ] %} | |
| 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 11 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 13 {{throw_type_error(method, | 12 {{throw_type_error(method, |
| 14 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | 13 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % |
| 15 method.number_of_required_arguments) | indent(8)}} | 14 method.number_of_required_arguments) | indent(8)}} |
| 16 return; | 15 return; |
| 17 } | 16 } |
| 18 {% endif %} | 17 {% endif %} |
| 19 {% if not method.is_static %} | 18 {% if not method.is_static %} |
| 20 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 19 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
| 21 {% endif %} | 20 {% endif %} |
| 22 {% if method.is_custom_element_callbacks %} | 21 {% if method.is_custom_element_callbacks %} |
| 23 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 22 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 24 {% endif %} | 23 {% endif %} |
| 25 {# Security checks #} | 24 {# Security checks #} |
| 25 {# FIXME: change to method.is_check_security_for_window #} |
| 26 {% if interface_name == 'EventTarget' %} | 26 {% if interface_name == 'EventTarget' %} |
| 27 {{event_target_check_security_for_frame() | indent }} | 27 if (DOMWindow* window = impl->toDOMWindow()) { |
| 28 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { |
| 29 exceptionState.throwIfNeeded(); |
| 30 return; |
| 31 } |
| 32 if (!window->document()) |
| 33 return; |
| 34 } |
| 28 {% elif method.is_check_security_for_frame %} | 35 {% elif method.is_check_security_for_frame %} |
| 29 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { | 36 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { |
| 30 exceptionState.throwIfNeeded(); | 37 exceptionState.throwIfNeeded(); |
| 31 return; | 38 return; |
| 32 } | 39 } |
| 33 {% endif %} | 40 {% endif %} |
| 34 {% if method.is_check_security_for_node %} | 41 {% if method.is_check_security_for_node %} |
| 35 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { | 42 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met
hod.name}}(exceptionState), exceptionState)) { |
| 36 v8SetReturnValueNull(info); | 43 v8SetReturnValueNull(info); |
| 37 exceptionState.throwIfNeeded(); | 44 exceptionState.throwIfNeeded(); |
| 38 return; | 45 return; |
| 39 } | 46 } |
| 40 {% endif %} | 47 {% endif %} |
| 41 {# Call method #} | 48 {# Call method #} |
| 42 {% for argument in method.arguments %} | 49 {% for argument in method.arguments %} |
| 43 {{generate_argument(method, argument, world_suffix) | indent}} | 50 {{generate_argument(method, argument, world_suffix) | indent}} |
| 44 {% endfor %} | 51 {% endfor %} |
| 45 {% if interface_name == 'EventTarget' and | |
| 46 method.name in ['addEventListener', 'removeEventListener'] %} | |
| 47 {# FIXME: can we move this |listener| check into Blink and | |
| 48 hidden_dependency_action? I.e., "if (!listener) return;" in Blink | |
| 49 and "if (listener && !impl->toNode())" in hidden_dependency_action} #} | |
| 50 if (!listener) | |
| 51 return; | |
| 52 {% endif %} | |
| 53 {% if world_suffix %} | 52 {% if world_suffix %} |
| 54 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 53 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
| 55 {% else %} | 54 {% else %} |
| 56 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} | 55 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} |
| 57 {% endif %} | 56 {% endif %} |
| 58 {% if interface_name == 'EventTarget' and | 57 {# Post-call #} |
| 59 method.name in ['addEventListener', 'removeEventListener'] %} | 58 {% if method.has_event_listener_argument %} |
| 60 {{hidden_dependency_action(method.name) | indent}} | 59 {{hidden_dependency_action(method.name) | indent}} |
| 61 {% endif %} | 60 {% endif %} |
| 62 } | 61 } |
| 63 {% endfilter %} | 62 {% endfilter %} |
| 64 {% endmacro %} | 63 {% endmacro %} |
| 65 | 64 |
| 66 | 65 |
| 67 {######################################} | 66 {######################################} |
| 68 {% macro event_target_check_security_for_frame() %} | |
| 69 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} | |
| 70 if (DOMWindow* window = impl->toDOMWindow()) { | |
| 71 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr
ame(), exceptionState)) { | |
| 72 exceptionState.throwIfNeeded(); | |
| 73 return; | |
| 74 } | |
| 75 if (!window->document()) | |
| 76 return; | |
| 77 } | |
| 78 {% endmacro %} | |
| 79 | |
| 80 | |
| 81 {######################################} | |
| 82 {% macro hidden_dependency_action(method_name) %} | 67 {% macro hidden_dependency_action(method_name) %} |
| 83 if (!impl->toNode()) | 68 if (listener && !impl->toNode()) |
| 84 {% if method_name == 'addEventListener' %} | 69 {% if method_name == 'addEventListener' %} |
| 85 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac
heIndex, info.GetIsolate()); | 70 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac
heIndex, info.GetIsolate()); |
| 86 {% else %}{# method_name == 'removeEventListener' #} | 71 {% else %}{# method_name == 'removeEventListener' #} |
| 87 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen
erCacheIndex, info.GetIsolate()); | 72 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen
erCacheIndex, info.GetIsolate()); |
| 88 {% endif %} | 73 {% endif %} |
| 89 {% endmacro %} | 74 {% endmacro %} |
| 90 | 75 |
| 91 | 76 |
| 92 {######################################} | 77 {######################################} |
| 93 {% macro generate_argument(method, argument, world_suffix) %} | 78 {% macro generate_argument(method, argument, world_suffix) %} |
| 94 {% if argument.is_optional and not argument.has_default and | 79 {% if argument.is_optional and not argument.has_default and |
| 95 argument.idl_type != 'Dictionary' and | 80 argument.idl_type != 'Dictionary' and |
| 96 not argument.is_callback_interface %} | 81 not argument.is_callback_interface %} |
| 97 {# Optional arguments without a default value generate an early call with | 82 {# Optional arguments without a default value generate an early call with |
| 98 fewer arguments if they are omitted. | 83 fewer arguments if they are omitted. |
| 99 Optional Dictionary arguments default to empty dictionary. #} | 84 Optional Dictionary arguments default to empty dictionary. #} |
| 100 if (UNLIKELY(info.Length() <= {{argument.index}})) { | 85 if (UNLIKELY(info.Length() <= {{argument.index}})) { |
| 101 {% if interface_name == 'EventTarget' %} | |
| 102 {# FIXME: can we move this |listener| check into Blink? (see above) #} | |
| 103 if (!listener) | |
| 104 return; | |
| 105 {% endif %} | |
| 106 {% if world_suffix %} | 86 {% if world_suffix %} |
| 107 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} | 87 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum
ent.cpp_value) | indent}} |
| 108 {% else %} | 88 {% else %} |
| 109 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} | 89 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value)
| indent}} |
| 110 {% endif %} | 90 {% endif %} |
| 111 {% if interface_name == 'EventTarget' %} | 91 {% if argument.has_event_listener_argument %} |
| 112 {{hidden_dependency_action(method.name) | indent}} | 92 {{hidden_dependency_action(method.name) | indent}} |
| 113 {% endif %} | 93 {% endif %} |
| 114 return; | 94 return; |
| 115 } | 95 } |
| 116 {% endif %} | 96 {% endif %} |
| 117 {% if method.is_strict_type_checking and argument.is_wrapper_type %} | 97 {% if method.is_strict_type_checking and argument.is_wrapper_type %} |
| 118 {# Type checking for wrapper interface types (if interface not implemented, | 98 {# Type checking for wrapper interface types (if interface not implemented, |
| 119 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 99 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
| 120 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())) { | 100 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())) { |
| 121 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 101 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 173 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
| 194 (argument.index + 1, argument.name)) | indent}} | 174 (argument.index + 1, argument.name)) | indent}} |
| 195 return; | 175 return; |
| 196 } | 176 } |
| 197 {% endif %} | 177 {% endif %} |
| 198 {% endmacro %} | 178 {% endmacro %} |
| 199 | 179 |
| 200 | 180 |
| 201 {######################################} | 181 {######################################} |
| 202 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | 182 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
| 183 {# Local variables #} |
| 203 {% if method.is_implemented_by and not method.is_static %} | 184 {% if method.is_implemented_by and not method.is_static %} |
| 204 ASSERT(impl); | 185 ASSERT(impl); |
| 205 {% endif %} | 186 {% endif %} |
| 206 {% if method.is_call_with_script_state %} | 187 {% if method.is_call_with_script_state %} |
| 207 ScriptState* currentState = ScriptState::current(); | 188 ScriptState* currentState = ScriptState::current(); |
| 208 if (!currentState) | 189 if (!currentState) |
| 209 return; | 190 return; |
| 210 ScriptState& state = *currentState; | 191 ScriptState& state = *currentState; |
| 211 {% endif %} | 192 {% endif %} |
| 212 {% if method.is_call_with_execution_context %} | 193 {% if method.is_call_with_execution_context %} |
| 213 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); | 194 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); |
| 214 {% endif %} | 195 {% endif %} |
| 215 {% if method.is_call_with_script_arguments %} | 196 {% if method.is_call_with_script_arguments %} |
| 216 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); | 197 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); |
| 217 {% endif %} | 198 {% endif %} |
| 199 {# Call #} |
| 218 {% if method.idl_type == 'void' %} | 200 {% if method.idl_type == 'void' %} |
| 219 {{cpp_value}}; | 201 {{cpp_value}}; |
| 220 {% elif method.is_call_with_script_state or method.is_raises_exception %} | 202 {% elif method.is_call_with_script_state or method.is_raises_exception %} |
| 221 {# FIXME: consider always using a local variable #} | 203 {# FIXME: consider always using a local variable #} |
| 222 {{method.cpp_type}} result = {{cpp_value}}; | 204 {{method.cpp_type}} result = {{cpp_value}}; |
| 223 {% endif %} | 205 {% endif %} |
| 206 {# Post-call #} |
| 224 {% if method.is_raises_exception %} | 207 {% if method.is_raises_exception %} |
| 225 if (exceptionState.throwIfNeeded()) | 208 if (exceptionState.throwIfNeeded()) |
| 226 return; | 209 return; |
| 227 {% endif %} | 210 {% endif %} |
| 228 {% if method.is_call_with_script_state %} | 211 {% if method.is_call_with_script_state %} |
| 229 if (state.hadException()) { | 212 if (state.hadException()) { |
| 230 v8::Local<v8::Value> exception = state.exception(); | 213 v8::Local<v8::Value> exception = state.exception(); |
| 231 state.clearException(); | 214 state.clearException(); |
| 232 throwError(exception, info.GetIsolate()); | 215 throwError(exception, info.GetIsolate()); |
| 233 return; | 216 return; |
| 234 } | 217 } |
| 235 {% endif %} | 218 {% endif %} |
| 219 {# Set return value #} |
| 236 {% if method.union_arguments %} | 220 {% if method.union_arguments %} |
| 237 {{union_type_method_call(method)}} | 221 {{union_type_method_call_and_set_return_value(method)}} |
| 238 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} | 222 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} |
| 239 {% endmacro %} | 223 {% endmacro %} |
| 240 | 224 |
| 225 |
| 241 {######################################} | 226 {######################################} |
| 242 {% macro union_type_method_call(method) %} | 227 {% macro union_type_method_call_and_set_return_value(method) %} |
| 243 {% for cpp_type in method.cpp_type %} | 228 {% for cpp_type in method.cpp_type %} |
| 244 bool result{{loop.index0}}Enabled = false; | 229 bool result{{loop.index0}}Enabled = false; |
| 245 {{cpp_type}} result{{loop.index0}}; | 230 {{cpp_type}} result{{loop.index0}}; |
| 246 {% endfor %} | 231 {% endfor %} |
| 247 {{method.cpp_value}}; | 232 {{method.cpp_value}}; |
| 248 {% if method.is_null_expression %}{# used by getters #} | 233 {% if method.is_null_expression %}{# used by getters #} |
| 249 if ({{method.is_null_expression}}) | 234 if ({{method.is_null_expression}}) |
| 250 return; | 235 return; |
| 251 {% endif %} | 236 {% endif %} |
| 252 {% for v8_set_return_value in method.v8_set_return_value %} | 237 {% for v8_set_return_value in method.v8_set_return_value %} |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 v8::Handle<v8::Object> wrapper = info.Holder(); | 439 v8::Handle<v8::Object> wrapper = info.Holder(); |
| 455 {% if is_constructor_raises_exception %} | 440 {% if is_constructor_raises_exception %} |
| 456 if (exceptionState.throwIfNeeded()) | 441 if (exceptionState.throwIfNeeded()) |
| 457 return; | 442 return; |
| 458 {% endif %} | 443 {% endif %} |
| 459 | 444 |
| 460 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); | 445 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); |
| 461 v8SetReturnValue(info, wrapper); | 446 v8SetReturnValue(info, wrapper); |
| 462 } | 447 } |
| 463 {% endmacro %} | 448 {% endmacro %} |
| OLD | NEW |