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.name in ['addEventListener', 'removeEventListener', | 9 {# FIXME: remove these special cases: http://crbug.com/353484 #} |
10 'dispatchEvent'] %} | 10 {% if method.number_of_required_arguments and not |
11 {{add_event_listener_remove_event_listener_dispatch_event() | indent}} | 11 method.name in ['addEventListener', 'removeEventListener' ] %} |
12 {% endif %} | |
13 {% if method.name in ['addEventListener', 'removeEventListener'] %} | |
14 {{add_event_listener_remove_event_listener_method(method.name) | indent}} | |
15 {% else %} | |
16 {% if method.number_of_required_arguments %} | |
17 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
18 {{throw_type_error(method, | 13 {{throw_type_error(method, |
19 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | 14 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % |
20 method.number_of_required_arguments) | indent(8)}} | 15 method.number_of_required_arguments) | indent(8)}} |
21 return; | 16 return; |
22 } | 17 } |
23 {% endif %} | 18 {% endif %} |
24 {% if not method.is_static %} | 19 {% if not method.is_static %} |
25 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 20 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); |
26 {% endif %} | 21 {% endif %} |
27 {% if method.is_custom_element_callbacks %} | 22 {% if method.is_custom_element_callbacks %} |
28 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 23 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
29 {% endif %} | 24 {% endif %} |
30 {% if method.is_check_security_for_frame %} | 25 {# Security checks #} |
| 26 {% if interface_name == 'EventTarget' %} |
| 27 {{event_target_check_security_for_frame() | indent }} |
| 28 {% elif method.is_check_security_for_frame %} |
31 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), exceptionState)) { | 29 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), exceptionState)) { |
32 exceptionState.throwIfNeeded(); | 30 exceptionState.throwIfNeeded(); |
33 return; | 31 return; |
34 } | 32 } |
35 {% endif %} | 33 {% endif %} |
36 {% if method.is_check_security_for_node %} | 34 {% if method.is_check_security_for_node %} |
37 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), imp->{{meth
od.name}}(exceptionState), exceptionState)) { | 35 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), imp->{{meth
od.name}}(exceptionState), exceptionState)) { |
38 v8SetReturnValueNull(info); | 36 v8SetReturnValueNull(info); |
39 exceptionState.throwIfNeeded(); | 37 exceptionState.throwIfNeeded(); |
40 return; | 38 return; |
41 } | 39 } |
42 {% endif %} | 40 {% endif %} |
| 41 {# Call method #} |
| 42 {% if interface_name == 'EventTarget' and |
| 43 method.name in ['addEventListener', 'removeEventListener'] %} |
| 44 {{add_event_listener_remove_event_listener_method(method.name) | indent}} |
| 45 {% else %} |
43 {% for argument in method.arguments %} | 46 {% for argument in method.arguments %} |
44 {{generate_argument(method, argument, world_suffix) | indent}} | 47 {{generate_argument(method, argument, world_suffix) | indent}} |
45 {% endfor %} | 48 {% endfor %} |
46 {% if world_suffix %} | 49 {% if world_suffix %} |
47 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 50 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
48 {% else %} | 51 {% else %} |
49 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} | 52 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} |
50 {% endif %} | 53 {% endif %} |
51 {% endif %}{# addEventListener, removeEventListener #} | 54 {% endif %}{# addEventListener, removeEventListener #} |
52 } | 55 } |
53 {% endfilter %} | 56 {% endfilter %} |
54 {% endmacro %} | 57 {% endmacro %} |
55 | 58 |
56 | 59 |
57 {######################################} | 60 {######################################} |
58 {% macro add_event_listener_remove_event_listener_dispatch_event() %} | 61 {% macro event_target_check_security_for_frame() %} |
59 {# FIXME: Clean up: use the normal |imp| above, | 62 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} |
60 use the existing shouldAllowAccessToFrame check if possible. #} | 63 if (DOMWindow* window = imp->toDOMWindow()) { |
61 EventTarget* impl = {{v8_class}}::toNative(info.Holder()); | |
62 if (DOMWindow* window = impl->toDOMWindow()) { | |
63 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr
ame(), exceptionState)) { | 64 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr
ame(), exceptionState)) { |
64 exceptionState.throwIfNeeded(); | 65 exceptionState.throwIfNeeded(); |
65 return; | 66 return; |
66 } | 67 } |
67 if (!window->document()) | 68 if (!window->document()) |
68 return; | 69 return; |
69 } | 70 } |
70 {% endmacro %} | 71 {% endmacro %} |
71 | 72 |
72 | 73 |
73 {######################################} | 74 {######################################} |
74 {% macro add_event_listener_remove_event_listener_method(method_name) %} | 75 {% macro add_event_listener_remove_event_listener_method(method_name) %} |
75 {# Set template values for addEventListener vs. removeEventListener #} | 76 {# Set template values for addEventListener vs. removeEventListener #} |
76 {% set listener_lookup_type, listener, hidden_dependency_action = | 77 {% set listener_lookup_type, listener, hidden_dependency_action = |
77 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') | 78 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') |
78 if method_name == 'addEventListener' else | 79 if method_name == 'addEventListener' else |
79 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') | 80 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') |
80 %} | 81 %} |
81 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1],
false, {{listener_lookup_type}}); | 82 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1],
false, {{listener_lookup_type}}); |
82 if (listener) { | 83 if (listener) { |
83 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); | 84 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); |
84 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); | 85 imp->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); |
85 if (!impl->toNode()) | 86 if (!imp->toNode()) |
86 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); | 87 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); |
87 } | 88 } |
88 {% endmacro %} | 89 {% endmacro %} |
89 | 90 |
90 | 91 |
91 {######################################} | 92 {######################################} |
92 {% macro generate_argument(method, argument, world_suffix) %} | 93 {% macro generate_argument(method, argument, world_suffix) %} |
93 {% if argument.is_optional and not argument.has_default and | 94 {% if argument.is_optional and not argument.has_default and |
94 argument.idl_type != 'Dictionary' and | 95 argument.idl_type != 'Dictionary' and |
95 not argument.is_callback_interface %} | 96 not argument.is_callback_interface %} |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 v8::Handle<v8::Object> wrapper = info.Holder(); | 437 v8::Handle<v8::Object> wrapper = info.Holder(); |
437 {% if is_constructor_raises_exception %} | 438 {% if is_constructor_raises_exception %} |
438 if (exceptionState.throwIfNeeded()) | 439 if (exceptionState.throwIfNeeded()) |
439 return; | 440 return; |
440 {% endif %} | 441 {% endif %} |
441 | 442 |
442 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); | 443 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); |
443 v8SetReturnValue(info, wrapper); | 444 v8SetReturnValue(info, wrapper); |
444 } | 445 } |
445 {% endmacro %} | 446 {% endmacro %} |
OLD | NEW |