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}})) { |
11 {{throw_type_error(method, | 11 {{throw_type_error(method, |
12 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | 12 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % |
13 method.number_of_required_arguments) | indent(8)}} | 13 method.number_of_required_arguments) | indent(8)}} |
14 return; | 14 return; |
15 } | 15 } |
16 {% endif %} | 16 {% endif %} |
17 {% if not method.is_static %} | 17 {% if not method.is_static %} |
18 {{cpp_class}}* imp = {{v8_class}}::toNative(info.Holder()); | 18 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
19 {% endif %} | 19 {% endif %} |
20 {% if method.is_custom_element_callbacks %} | 20 {% if method.is_custom_element_callbacks %} |
21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
22 {% endif %} | 22 {% endif %} |
23 {# Security checks #} | 23 {# Security checks #} |
24 {% if interface_name == 'EventTarget' %} | 24 {% if interface_name == 'EventTarget' %} |
25 {{event_target_check_security_for_frame() | indent }} | 25 {{event_target_check_security_for_frame() | indent }} |
26 {% elif method.is_check_security_for_frame %} | 26 {% elif method.is_check_security_for_frame %} |
27 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), exceptionState)) { | 27 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { |
28 exceptionState.throwIfNeeded(); | 28 exceptionState.throwIfNeeded(); |
29 return; | 29 return; |
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(), imp->{{meth
od.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 | 40 {% if interface_name == 'EventTarget' and |
41 method.name in ['addEventListener', 'removeEventListener'] %} | 41 method.name in ['addEventListener', 'removeEventListener'] %} |
42 {{add_event_listener_remove_event_listener_method(method.name) | indent}} | 42 {{add_event_listener_remove_event_listener_method(method.name) | indent}} |
43 {% else %} | 43 {% else %} |
44 {% for argument in method.arguments %} | 44 {% for argument in method.arguments %} |
45 {{generate_argument(method, argument, world_suffix) | indent}} | 45 {{generate_argument(method, argument, world_suffix) | indent}} |
46 {% endfor %} | 46 {% endfor %} |
47 {% if world_suffix %} | 47 {% if world_suffix %} |
48 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 48 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
49 {% else %} | 49 {% else %} |
50 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} | 50 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in
dent}} |
51 {% endif %} | 51 {% endif %} |
52 {% endif %}{# addEventListener, removeEventListener #} | 52 {% endif %}{# addEventListener, removeEventListener #} |
53 } | 53 } |
54 {% endfilter %} | 54 {% endfilter %} |
55 {% endmacro %} | 55 {% endmacro %} |
56 | 56 |
57 | 57 |
58 {######################################} | 58 {######################################} |
59 {% macro event_target_check_security_for_frame() %} | 59 {% macro event_target_check_security_for_frame() %} |
60 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} | 60 {# FIXME: use the existing shouldAllowAccessToFrame check if possible. #} |
61 if (DOMWindow* window = imp->toDOMWindow()) { | 61 if (DOMWindow* window = impl->toDOMWindow()) { |
62 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr
ame(), exceptionState)) { | 62 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->fr
ame(), exceptionState)) { |
63 exceptionState.throwIfNeeded(); | 63 exceptionState.throwIfNeeded(); |
64 return; | 64 return; |
65 } | 65 } |
66 if (!window->document()) | 66 if (!window->document()) |
67 return; | 67 return; |
68 } | 68 } |
69 {% endmacro %} | 69 {% endmacro %} |
70 | 70 |
71 | 71 |
72 {######################################} | 72 {######################################} |
73 {% macro add_event_listener_remove_event_listener_method(method_name) %} | 73 {% macro add_event_listener_remove_event_listener_method(method_name) %} |
74 {# Set template values for addEventListener vs. removeEventListener #} | 74 {# Set template values for addEventListener vs. removeEventListener #} |
75 {% set listener_lookup_type, listener, hidden_dependency_action = | 75 {% set listener_lookup_type, listener, hidden_dependency_action = |
76 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') | 76 ('ListenerFindOrCreate', 'listener', 'addHiddenValueToArray') |
77 if method_name == 'addEventListener' else | 77 if method_name == 'addEventListener' else |
78 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') | 78 ('ListenerFindOnly', 'listener.get()', 'removeHiddenValueFromArray') |
79 %} | 79 %} |
80 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1],
false, {{listener_lookup_type}}); | 80 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1],
false, {{listener_lookup_type}}); |
81 if (listener) { | 81 if (listener) { |
82 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); | 82 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventN
ame, info[0]); |
83 imp->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); | 83 impl->{{method_name}}(eventName, {{listener}}, info[2]->BooleanValue()); |
84 if (!imp->toNode()) | 84 if (!impl->toNode()) |
85 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); | 85 {{hidden_dependency_action}}(info.Holder(), info[1], {{v8_class}}::event
ListenerCacheIndex, info.GetIsolate()); |
86 } | 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 %} |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 (argument.index + 1, argument.name)) | indent}} | 175 (argument.index + 1, argument.name)) | indent}} |
176 return; | 176 return; |
177 } | 177 } |
178 {% endif %} | 178 {% endif %} |
179 {% endmacro %} | 179 {% endmacro %} |
180 | 180 |
181 | 181 |
182 {######################################} | 182 {######################################} |
183 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | 183 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
184 {% if method.is_implemented_by and not method.is_static %} | 184 {% if method.is_implemented_by and not method.is_static %} |
185 ASSERT(imp); | 185 ASSERT(impl); |
186 {% endif %} | 186 {% endif %} |
187 {% if method.is_call_with_script_state %} | 187 {% if method.is_call_with_script_state %} |
188 ScriptState* currentState = ScriptState::current(); | 188 ScriptState* currentState = ScriptState::current(); |
189 if (!currentState) | 189 if (!currentState) |
190 return; | 190 return; |
191 ScriptState& state = *currentState; | 191 ScriptState& state = *currentState; |
192 {% endif %} | 192 {% endif %} |
193 {% if method.is_call_with_execution_context %} | 193 {% if method.is_call_with_execution_context %} |
194 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); | 194 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); |
195 {% endif %} | 195 {% endif %} |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 {# FIXME: 1 case of [DoNotCheckSignature] in Window.idl may differ #} | 323 {# FIXME: 1 case of [DoNotCheckSignature] in Window.idl may differ #} |
324 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTem
plateKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}
, v8Undefined(), {{signature}}, {{method.number_of_required_or_variadic_argument
s}}); | 324 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTem
plateKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}
, v8Undefined(), {{signature}}, {{method.number_of_required_or_variadic_argument
s}}); |
325 | 325 |
326 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i
nfo.This(), info.GetIsolate()); | 326 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i
nfo.This(), info.GetIsolate()); |
327 if (holder.IsEmpty()) { | 327 if (holder.IsEmpty()) { |
328 // This is only reachable via |object.__proto__.func|, in which case it | 328 // This is only reachable via |object.__proto__.func|, in which case it |
329 // has already passed the same origin security check | 329 // has already passed the same origin security check |
330 v8SetReturnValue(info, privateTemplate->GetFunction()); | 330 v8SetReturnValue(info, privateTemplate->GetFunction()); |
331 return; | 331 return; |
332 } | 332 } |
333 {{cpp_class}}* imp = {{v8_class}}::toNative(holder); | 333 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
334 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame
(), DoNotReportSecurityError)) { | 334 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), DoNotReportSecurityError)) { |
335 static int sharedTemplateKey; // This address is used for a key to look
up the dom template. | 335 static int sharedTemplateKey; // This address is used for a key to look
up the dom template. |
336 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sha
redTemplateKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_su
ffix}}, v8Undefined(), {{signature}}, {{method.number_of_required_or_variadic_ar
guments}}); | 336 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sha
redTemplateKey, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_su
ffix}}, v8Undefined(), {{signature}}, {{method.number_of_required_or_variadic_ar
guments}}); |
337 v8SetReturnValue(info, sharedTemplate->GetFunction()); | 337 v8SetReturnValue(info, sharedTemplate->GetFunction()); |
338 return; | 338 return; |
339 } | 339 } |
340 | 340 |
341 v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicStrin
g(info.GetIsolate(), "{{method.name}}")); | 341 v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicStrin
g(info.GetIsolate(), "{{method.name}}")); |
342 if (!hiddenValue.IsEmpty()) { | 342 if (!hiddenValue.IsEmpty()) { |
343 v8SetReturnValue(info, hiddenValue); | 343 v8SetReturnValue(info, hiddenValue); |
344 return; | 344 return; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 v8::Handle<v8::Object> wrapper = info.Holder(); | 435 v8::Handle<v8::Object> wrapper = info.Holder(); |
436 {% if is_constructor_raises_exception %} | 436 {% if is_constructor_raises_exception %} |
437 if (exceptionState.throwIfNeeded()) | 437 if (exceptionState.throwIfNeeded()) |
438 return; | 438 return; |
439 {% endif %} | 439 {% endif %} |
440 | 440 |
441 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); | 441 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfigu
ration::Dependent); |
442 v8SetReturnValue(info, wrapper); | 442 v8SetReturnValue(info, wrapper); |
443 } | 443 } |
444 {% endmacro %} | 444 {% endmacro %} |
OLD | NEW |