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 {% if method.has_exception_state %} | 6 {% if method.has_exception_state %} |
7 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 7 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
8 {% endif %} | 8 {% endif %} |
9 {% if method.number_of_required_arguments %} | 9 {% if method.number_of_required_arguments %} |
10 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 10 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
(...skipping 19 matching lines...) Expand all Loading... | |
30 } | 30 } |
31 {% endif %} | 31 {% endif %} |
32 {% if method.is_check_security_for_node %} | 32 {% if method.is_check_security_for_node %} |
33 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { | 33 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { |
34 v8SetReturnValueNull(info); | 34 v8SetReturnValueNull(info); |
35 exceptionState.throwIfNeeded(); | 35 exceptionState.throwIfNeeded(); |
36 return; | 36 return; |
37 } | 37 } |
38 {% endif %} | 38 {% endif %} |
39 {# Call method #} | 39 {# Call method #} |
40 {% if interface_name == 'EventTarget' and | |
Nils Barth (inactive)
2014/03/18 07:20:36
Moved down, so now arguments are always generated
| |
41 method.name in ['addEventListener', 'removeEventListener'] %} | |
42 {{add_event_listener_remove_event_listener_method(method.name) | indent}} | |
43 {% else %} | |
44 {% for argument in method.arguments %} | 40 {% for argument in method.arguments %} |
45 {{generate_argument(method, argument, world_suffix) | indent}} | 41 {{generate_argument(method, argument, world_suffix) | indent}} |
46 {% endfor %} | 42 {% endfor %} |
43 {% if interface_name == 'EventTarget' and | |
44 method.name in ['addEventListener', 'removeEventListener'] %} | |
45 {# FIXME: can we move this |listener| check into Blink and | |
46 hidden_dependency_action? I.e., "if (!listener) return;" in Blink | |
47 and "if (listener && !impl->toNode())" in hidden_dependency_action} #} | |
48 if (!listener) | |
49 return; | |
50 {% endif %} | |
47 {% if world_suffix %} | 51 {% if world_suffix %} |
48 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} | 52 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} |
49 {% else %} | 53 {% else %} |
50 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} | 54 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} |
51 {% endif %} | 55 {% endif %} |
52 {% endif %}{# addEventListener, removeEventListener #} | 56 {% if interface_name == 'EventTarget' and |
57 method.name in ['addEventListener', 'removeEventListener'] %} | |
58 {{hidden_dependency_action(method.name) | indent}} | |
59 {% endif %} | |
53 } | 60 } |
54 {% endfilter %} | 61 {% endfilter %} |
55 {% endmacro %} | 62 {% endmacro %} |
56 | 63 |
57 | 64 |
58 {######################################} | 65 {######################################} |
59 {% macro event_target_check_security_for_frame() %} | 66 {% macro event_target_check_security_for_frame() %} |
60 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} | 67 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} |
61 if (DOMWindow* window = impl->toDOMWindow()) { | 68 if (DOMWindow* window = impl->toDOMWindow()) { |
62 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr ame(), exceptionState)) { | 69 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr ame(), exceptionState)) { |
63 exceptionState.throwIfNeeded(); | 70 exceptionState.throwIfNeeded(); |
64 return; | 71 return; |
65 } | 72 } |
66 if (!window->document()) | 73 if (!window->document()) |
67 return; | 74 return; |
68 } | 75 } |
69 {% endmacro %} | 76 {% endmacro %} |
70 | 77 |
71 | 78 |
72 {######################################} | 79 {######################################} |
73 {% macro add_event_listener_remove_event_listener_method(method_name) %} | 80 {% macro hidden_dependency_action(method_name) %} |
Nils Barth (inactive)
2014/03/18 07:20:36
Much simpler, because now only the really special
| |
74 {# Set template values for addEventListener vs. removeEventListener #} | 81 if (!impl->toNode()) |
75 {% set listener_lookup_type, listener, hidden_dependency_action = | 82 {% if method_name == 'addEventListener' %} |
76 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') | 83 addHiddenValueToArray(info.Holder(), info[1], {{v8_class}}::eventListenerCac heIndex, info.GetIsolate()); |
77 if method_name == 'addEventListener' else | 84 {% else %}{# method_name == 'removeEventListener' #} |
78 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') | 85 removeHiddenValueFromArray(info.Holder(), info[1], {{v8_class}}::eventListen erCacheIndex, info.GetIsolate()); |
79 %} | 86 {% endif %} |
80 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, {{listener_lookup_type}}); | |
81 if (listener) { | |
82 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN ame, info[0]); | |
83 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); | |
84 if (!impl->toNode()) | |
85 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event ListenerCacheIndex, info.GetIsolate()); | |
86 } | |
87 {% endmacro %} | 87 {% endmacro %} |
88 | 88 |
89 | 89 |
90 {######################################} | 90 {######################################} |
91 {% macro generate_argument(method, argument, world_suffix) %} | 91 {% macro generate_argument(method, argument, world_suffix) %} |
92 {% if argument.is_optional and not argument.has_default and | 92 {% if argument.is_optional and not argument.has_default and |
93 argument.idl_type != 'Dictionary' and | 93 argument.idl_type != 'Dictionary' and |
94 not argument.is_callback_interface %} | 94 not argument.is_callback_interface %} |
95 {# Optional arguments without a default value generate an early call with | 95 {# Optional arguments without a default value generate an early call with |
96 fewer arguments if they are omitted. | 96 fewer arguments if they are omitted. |
97 Optional Dictionary arguments default to empty dictionary. #} | 97 Optional Dictionary arguments default to empty dictionary. #} |
98 if (UNLIKELY(info.Length() <= {{argument.index}})) { | 98 if (UNLIKELY(info.Length() <= {{argument.index}})) { |
99 {% if interface_name == 'EventTarget' %} | |
100 {# FIXME: can we move this |listener| check into Blink? (see above) #} | |
101 if (!listener) | |
102 return; | |
103 {% endif %} | |
99 {% if world_suffix %} | 104 {% if world_suffix %} |
100 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}} | 105 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}} |
101 {% else %} | 106 {% else %} |
102 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}} | 107 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}} |
103 {% endif %} | 108 {% endif %} |
109 {% if interface_name == 'EventTarget' %} | |
110 {{hidden_dependency_action(method.name) | indent}} | |
111 {% endif %} | |
104 return; | 112 return; |
105 } | 113 } |
106 {% endif %} | 114 {% endif %} |
107 {% if method.is_strict_type_checking and argument.is_wrapper_type %} | 115 {% if method.is_strict_type_checking and argument.is_wrapper_type %} |
108 {# Type checking for wrapper interface types (if interface not implemented, | 116 {# Type checking for wrapper interface types (if interface not implemented, |
109 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 117 throw TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
110 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())) { | 118 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())) { |
111 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 119 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
112 (argument.index + 1, argument.idl_type)) | indent }} | 120 (argument.index + 1, argument.idl_type)) | indent }} |
113 return; | 121 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 {% elif argument.is_variadic_wrapper_type %} | 157 {% elif argument.is_variadic_wrapper_type %} |
150 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; | 158 {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; |
151 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 159 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
152 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 160 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
153 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 161 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
154 (argument.index + 1, argument.idl_type)) | in dent(8)}} | 162 (argument.index + 1, argument.idl_type)) | in dent(8)}} |
155 return; | 163 return; |
156 } | 164 } |
157 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i]))); | 165 {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Ob ject>::Cast(info[i]))); |
158 } | 166 } |
167 {# FIXME: remove EventListener special case | |
Nils Barth (inactive)
2014/03/18 07:20:36
This is really ugly, and it's all because we want
| |
168 (just for ListenerFindOrCreate/ListenerFindOnly argument) #} | |
169 {% elif argument.idl_type == 'EventListener' and | |
170 interface_name == 'EventTarget' and | |
171 method.name == 'addEventListener' %} | |
172 V8TRYCATCH_VOID(RefPtr<EventListener>, {{argument.name}}, V8EventListenerList::g etEventListener(info[{{argument.index}}], false, ListenerFindOrCreate)); | |
173 {% elif argument.idl_type == 'EventListener' and | |
174 interface_name == 'EventTarget' and | |
175 method.name == 'removeEventListener' %} | |
176 V8TRYCATCH_VOID(RefPtr<EventListener>, {{argument.name}}, V8EventListenerList::g etEventListener(info[{{argument.index}}], false, ListenerFindOnly)); | |
159 {% else %} | 177 {% else %} |
160 {{argument.v8_value_to_local_cpp_value}}; | 178 {{argument.v8_value_to_local_cpp_value}}; |
161 {% endif %} | 179 {% endif %} |
162 {% if argument.enum_validation_expression %} | 180 {% if argument.enum_validation_expression %} |
163 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 181 {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
164 String string = {{argument.name}}; | 182 String string = {{argument.name}}; |
165 if (!({{argument.enum_validation_expression}})) { | 183 if (!({{argument.enum_validation_expression}})) { |
166 {{throw_type_error(method, | 184 {{throw_type_error(method, |
167 '"parameter %s (\'" + string + "\') is not a valid enum value."' % | 185 '"parameter %s (\'" + string + "\') is not a valid enum value."' % |
168 (argument.index + 1)) | indent}} | 186 (argument.index + 1)) | indent}} |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 v8::Handle<v8::Object> wrapper = info.Holder(); | 453 v8::Handle<v8::Object> wrapper = info.Holder(); |
436 {% if is_constructor_raises_exception %} | 454 {% if is_constructor_raises_exception %} |
437 if (exceptionState.throwIfNeeded()) | 455 if (exceptionState.throwIfNeeded()) |
438 return; | 456 return; |
439 {% endif %} | 457 {% endif %} |
440 | 458 |
441 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu ration::Dependent); | 459 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8 _class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu ration::Dependent); |
442 v8SetReturnValue(info, wrapper); | 460 v8SetReturnValue(info, wrapper); |
443 } | 461 } |
444 {% endmacro %} | 462 {% endmacro %} |
OLD | NEW |