Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: third_party/WebKit/Source/bindings/templates/methods.cpp.tmpl

Issue 2329463004: ABANDONED CL: Changes needed to make things compile after running rewrite_to_chrome_style tool. (Closed)
Patch Set: Rebasing the fixes... Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %}
2 2
3 {##############################################################################} 3 {##############################################################################}
4 {% macro generate_method(method, world_suffix) %} 4 {% macro generate_method(method, world_suffix) %}
5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) { 5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) {
6 {% filter format_remove_duplicates([ 6 {% filter format_remove_duplicates([
7 'ExceptionState exceptionState', 7 'ExceptionState exceptionState',
8 'ScriptState* scriptState = ']) %} 8 'ScriptState* scriptState = ']) %}
9 {% set define_exception_state -%} 9 {% set define_exception_state -%}
10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}"); 10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionCon text, "{{interface_name}}", "{{method.name}}");
11 {%- endset %} 11 {%- endset %}
12 12
13 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %} 13 {% set function_call = func_call_with_prep_of_args(method, world_suffix) %}
14 14
15 {% if 'exceptionState' in function_call or 15 {% if 'exceptionState' in function_call or
16 (method.returns_promise and not method.is_static) %} 16 (method.returns_promise and not method.is_static) %}
17 {{define_exception_state}} 17 {{define_exception_state}}
18 {% if method.returns_promise %} 18 {% if method.returns_promise %}
19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); 19 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState);
20 {% endif %} 20 {% endif %}
21 {% endif %} 21 {% endif %}
22 22
23 {% if not method.is_static %} 23 {% if not method.is_static %}
24 {% if method.returns_promise %} 24 {% if method.returns_promise %}
25 // V8DOMConfiguration::DoNotCheckHolder 25 // V8DOMConfiguration::kDoNotCheckHolder
26 // Make sure that info.Holder() really points to an instance of the type. 26 // Make sure that info.Holder() really points to an instance of the type.
27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) { 27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) {
28 {{throw_type_error(method, '"Illegal invocation"')}} 28 {{throw_type_error(method, '"Illegal invocation"')}}
29 return; 29 return;
30 } 30 }
31 {% endif %} 31 {% endif %}
32 {% set local_dom_window_only = interface_name == 'Window' and not method.is_cr oss_origin %} 32 {% set local_dom_window_only = interface_name == 'Window' and not method.is_cr oss_origin %}
33 {% if local_dom_window_only %} 33 {% if local_dom_window_only %}
34 {% if method.is_check_security_for_receiver %} 34 {% if method.is_check_security_for_receiver %}
35 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(info.Holder()); 35 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(info.Holder());
36 {% else %} 36 {% else %}
37 // Same-origin methods are never exposed via the cross-origin interceptors. 37 // Same-origin methods are never exposed via the cross-origin interceptors.
38 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast 38 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast
39 // here. 39 // here.
40 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder())); 40 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(info.Holder()));
41 {% endif %}{# method.is_check_security_for_receiver #} 41 {% endif %}{# method.is_check_security_for_receiver #}
42 {% else %} 42 {% else %}
43 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 43 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
44 {% endif %}{# local_dom_window_only #} 44 {% endif %}{# local_dom_window_only #}
45 {% endif %}{# not method.is_static #} 45 {% endif %}{# not method.is_static #}
46 46
47 {# Security checks #} 47 {# Security checks #}
48 {% if method.is_check_security_for_receiver %} 48 {% if method.is_check_security_for_receiver %}
49 {{define_exception_state}} 49 {{define_exception_state}}
50 {% if interface_name == 'EventTarget' %} 50 {% if interface_name == 'EventTarget' %}
51 // Performance hack for EventTarget. Checking whether it's a Window or not 51 // Performance hack for EventTarget. Checking whether it's a Window or not
52 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% 52 // prior to the call to BindingSecurity::ShouldAllowAccessTo increases 30%
53 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE 53 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE
54 // didn't work in this case. 54 // didn't work in this case.
55 if (const DOMWindow* window = impl->toDOMWindow()) { 55 if (const DOMWindow* window = impl->ToDOMWindow()) {
56 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), window, exceptionState)) { 56 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate() ), window, exceptionState)) {
57 return; 57 return;
58 } 58 }
59 } 59 }
60 {% else %}{# interface_name == 'EventTarget' #} 60 {% else %}{# interface_name == 'EventTarget' #}
61 {% if local_dom_window_only %} 61 {% if local_dom_window_only %}
62 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), uncheckedImpl, exceptionState)) { 62 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()), uncheckedImpl, exceptionState)) {
63 {% else %} 63 {% else %}
64 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) { 64 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()), impl, exceptionState)) {
65 {% endif %}{# local_dom_window_only #} 65 {% endif %}{# local_dom_window_only #}
66 return; 66 return;
67 } 67 }
68 {% if local_dom_window_only %} 68 {% if local_dom_window_only %}
69 LocalDOMWindow* impl = toLocalDOMWindow(uncheckedImpl); 69 LocalDOMWindow* impl = ToLocalDOMWindow(uncheckedImpl);
70 {% endif %}{# local_dom_window_only #} 70 {% endif %}{# local_dom_window_only #}
71 {% endif %}{# interface_name == 'EventTarget' #} 71 {% endif %}{# interface_name == 'EventTarget' #}
72 {% endif %}{# method.is_check_security_for_receiver #} 72 {% endif %}{# method.is_check_security_for_receiver #}
73 {% if method.is_check_security_for_return_value %} 73 {% if method.is_check_security_for_return_value %}
74 {{define_exception_state}} 74 {{define_exception_state}}
75 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) { 75 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) {
76 v8SetReturnValueNull(info); 76 V8SetReturnValueNull(info);
77 return; 77 return;
78 } 78 }
79 {% endif %} 79 {% endif %}
80 80
81 {% if 'scriptState' in function_call %} 81 {% if 'scriptState' in function_call %}
82 {% if method.is_static %} 82 {% if method.is_static %}
83 ScriptState* scriptState = ScriptState::forFunctionObject(info); 83 ScriptState* scriptState = ScriptState::ForFunctionObject(info);
84 {% else %} 84 {% else %}
85 ScriptState* scriptState = ScriptState::forReceiverObject(info); 85 ScriptState* scriptState = ScriptState::ForReceiverObject(info);
86 {% endif %} 86 {% endif %}
87 {% endif %} 87 {% endif %}
88 88
89 {% if method.is_custom_element_callbacks %} 89 {% if method.is_custom_element_callbacks %}
90 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 90 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
91 {% endif %} 91 {% endif %}
92 92
93 {{function_call | indent(2)}} 93 {{function_call | indent(2)}}
94 } 94 }
95 {% endfilter %} 95 {% endfilter %}
(...skipping 12 matching lines...) Expand all
108 108
109 109
110 {######################################} 110 {######################################}
111 {% macro generate_arguments(method, world_suffix) %} 111 {% macro generate_arguments(method, world_suffix) %}
112 {% if method.arguments %} 112 {% if method.arguments %}
113 113
114 {# Overloaded methods/constructors have length checked during overload resolutio n #} 114 {# Overloaded methods/constructors have length checked during overload resolutio n #}
115 {% if method.number_of_required_arguments and not method.overload_index %} 115 {% if method.number_of_required_arguments and not method.overload_index %}
116 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 116 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
117 {{throw_type_error(method, 117 {{throw_type_error(method,
118 'ExceptionMessages::notEnoughArguments(%(expected)d, info.Length())' 118 'ExceptionMessages::NotEnoughArguments(%(expected)d, info.Length())'
119 | format(expected=method.number_of_required_arguments))}} 119 | format(expected=method.number_of_required_arguments))}}
120 return; 120 return;
121 } 121 }
122 {% endif %} 122 {% endif %}
123 123
124 {% for argument in method.arguments %} 124 {% for argument in method.arguments %}
125 {{argument.cpp_type}} {{argument.name}}; 125 {{argument.cpp_type}} {{argument.name}};
126 {% endfor %} 126 {% endfor %}
127 {% if method.has_optional_argument_without_default_value %} 127 {% if method.has_optional_argument_without_default_value %}
128 {# Count the effective number of arguments. (arg1, arg2, undefined) is 128 {# Count the effective number of arguments. (arg1, arg2, undefined) is
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argumen t.cpp_value) | indent(2)}} 162 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argumen t.cpp_value) | indent(2)}}
163 {% else %} 163 {% else %}
164 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent(2)}} 164 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent(2)}}
165 {% endif %} 165 {% endif %}
166 return; 166 return;
167 } 167 }
168 {% endif %} 168 {% endif %}
169 {% if argument.is_callback_interface %} 169 {% if argument.is_callback_interface %}
170 {# FIXME: remove EventListener special case #} 170 {# FIXME: remove EventListener special case #}
171 {% if argument.idl_type == 'EventListener' %} 171 {% if argument.idl_type == 'EventListener' %}
172 {% if method.name == 'removeEventListener' or method.name == 'removeListener' %} 172 {% if method.name == 'RemoveEventListener' or method.name == 'RemoveListener' %}
173 {{argument.name}} = V8EventListenerHelper::getEventListener(ScriptState::current (info.GetIsolate()), info[{{argument.index}}], false, ListenerFindOnly); 173 {{argument.name}} = V8EventListenerHelper::GetEventListener(ScriptState::Current (info.GetIsolate()), info[{{argument.index}}], false, kListenerFindOnly);
174 {% else %}{# method.name == 'addEventListener' #} 174 {% else %}{# method.name == 'AddEventListener' #}
175 {{argument.name}} = V8EventListenerHelper::getEventListener(ScriptState::current (info.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate); 175 {{argument.name}} = V8EventListenerHelper::GetEventListener(ScriptState::Current (info.GetIsolate()), info[{{argument.index}}], false, kListenerFindOrCreate);
176 {% endif %}{# method.name #} 176 {% endif %}{# method.name #}
177 {% else %}{# argument.idl_type == 'EventListener' #} 177 {% else %}{# argument.idl_type == 'EventListener' #}
178 {# Callback functions must be functions: 178 {# Callback functions must be functions:
179 http://www.w3.org/TR/WebIDL/#es-callback-function #} 179 http://www.w3.org/TR/WebIDL/#es-callback-function #}
180 {% if argument.is_optional %} 180 {% if argument.is_optional %}
181 if (!isUndefinedOrNull(info[{{argument.index}}])) { 181 if (!IsUndefinedOrNull(info[{{argument.index}}])) {
182 if (!info[{{argument.index}}]->IsFunction()) { 182 if (!info[{{argument.index}}]->IsFunction()) {
183 {{throw_argument_error(method, argument, "The callback provided as parameter %(index)d is not a function.")}} 183 {{throw_argument_error(method, argument, "The callback provided as parameter %(index)d is not a function.")}}
184 return; 184 return;
185 } 185 }
186 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>::C ast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 186 {{argument.name}} = V8{{argument.idl_type}}::Create(v8::Local<v8::Function>::C ast(info[{{argument.index}}]), ScriptState::Current(info.GetIsolate()));
187 } else { 187 } else {
188 {{argument.name}} = nullptr; 188 {{argument.name}} = nullptr;
189 } 189 }
190 {% else %}{# argument.is_optional #} 190 {% else %}{# argument.is_optional #}
191 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 191 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
192 {{throw_argument_error(method, argument, "The callback provided as parameter % (index)d is not a function.")}} 192 {{throw_argument_error(method, argument, "The callback provided as parameter % (index)d is not a function.")}}
193 return; 193 return;
194 } 194 }
195 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 195 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::Create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::Current(info.GetIsolate()));
196 {% endif %}{# argument.is_optional #} 196 {% endif %}{# argument.is_optional #}
197 {% endif %}{# argument.idl_type == 'EventListener' #} 197 {% endif %}{# argument.idl_type == 'EventListener' #}
198 {% elif argument.is_callback_function %} 198 {% elif argument.is_callback_function %}
199 if ({% if argument.is_nullable %}!isUndefinedOrNull(info[{{argument.index}}]) && {% endif %}!(info[{{argument.index}}]->IsObject() && v8::Local<v8::Object>::Cas t(info[{{argument.index}}])->IsCallable())) { 199 if ({% if argument.is_nullable %}!IsUndefinedOrNull(info[{{argument.index}}]) && {% endif %}!(info[{{argument.index}}]->IsObject() && v8::Local<v8::Object>::Cas t(info[{{argument.index}}])->IsCallable())) {
200 {{throw_argument_error(method, argument, "The callback provided as parameter % (index)d is not a function.")}} 200 {{throw_argument_error(method, argument, "The callback provided as parameter % (index)d is not a function.")}}
201 return; 201 return;
202 } 202 }
203 {{v8_value_to_local_cpp_value(argument)}} 203 {{v8_value_to_local_cpp_value(argument)}}
204 {% elif argument.is_variadic_wrapper_type %} 204 {% elif argument.is_variadic_wrapper_type %}
205 for (int i = {{argument.index}}; i < info.Length(); ++i) { 205 for (int i = {{argument.index}}; i < info.Length(); ++i) {
206 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { 206 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
207 {{throw_argument_error(method, argument, "parameter %(index)d is not of type '%(type)s'.")}} 207 {{throw_argument_error(method, argument, "parameter %(index)d is not of type '%(type)s'.")}}
208 return; 208 return;
209 } 209 }
210 {{argument.name}}.push_back(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Obje ct>::Cast(info[i]))); 210 {{argument.name}}.push_back(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Obje ct>::Cast(info[i])));
211 } 211 }
212 {% elif argument.is_dictionary %} 212 {% elif argument.is_dictionary %}
213 {% if not argument.use_permissive_dictionary_conversion %} 213 {% if not argument.use_permissive_dictionary_conversion %}
214 {# Dictionaries must have type Undefined, Null or Object: 214 {# Dictionaries must have type Undefined, Null or Object:
215 http://heycam.github.io/webidl/#es-dictionary #} 215 http://heycam.github.io/webidl/#es-dictionary #}
216 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { 216 if (!IsUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) {
217 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is not an object.")}} 217 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is not an object.")}}
218 return; 218 return;
219 } 219 }
220 {% endif %}{# not argument.use_permissive_dictionary_conversion #} 220 {% endif %}{# not argument.use_permissive_dictionary_conversion #}
221 {{v8_value_to_local_cpp_value(argument)}} 221 {{v8_value_to_local_cpp_value(argument)}}
222 {% elif argument.is_explicit_nullable %} 222 {% elif argument.is_explicit_nullable %}
223 if (!isUndefinedOrNull(info[{{argument.index}}])) { 223 if (!IsUndefinedOrNull(info[{{argument.index}}])) {
224 {{v8_value_to_local_cpp_value(argument) | indent(2)}} 224 {{v8_value_to_local_cpp_value(argument) | indent(2)}}
225 } 225 }
226 {% else %}{# argument.is_nullable #} 226 {% else %}{# argument.is_nullable #}
227 {{v8_value_to_local_cpp_value(argument)}} 227 {{v8_value_to_local_cpp_value(argument)}}
228 {% endif %}{# argument.is_nullable #} 228 {% endif %}{# argument.is_nullable #}
229 {# Type checking, possibly throw a TypeError, per: 229 {# Type checking, possibly throw a TypeError, per:
230 http://www.w3.org/TR/WebIDL/#es-type-mapping #} 230 http://www.w3.org/TR/WebIDL/#es-type-mapping #}
231 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} 231 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %}
232 {# Type checking for wrapper interface types (if interface not implemented, 232 {# Type checking for wrapper interface types (if interface not implemented,
233 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface 233 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
234 Note: for variadic arguments, the type checking is done for each matched 234 Note: for variadic arguments, the type checking is done for each matched
235 argument instead; see argument.is_variadic_wrapper_type code-path above. #} 235 argument instead; see argument.is_variadic_wrapper_type code-path above. #}
236 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { 236 if (!{{argument.name}}{% if argument.is_nullable %} && !IsUndefinedOrNull(info[{ {argument.index}}]){% endif %}) {
237 {{throw_argument_error(method, argument, "parameter %(index)d is not of type ' %(type)s'.")}} 237 {{throw_argument_error(method, argument, "parameter %(index)d is not of type ' %(type)s'.")}}
238 return; 238 return;
239 } 239 }
240 {% elif argument.enum_values %} 240 {% elif argument.enum_values %}
241 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} 241 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
242 {% set enum_variable = 'valid' + argument.name[0].upper() + argument.name[1:] + 'Values' %} 242 {% set enum_variable = 'valid' + argument.name[0].upper() + argument.name[1:] + 'Values' %}
243 {{declare_enum_validation_variable(argument.enum_values, enum_variable)}} 243 {{declare_enum_validation_variable(argument.enum_values, enum_variable)}}
244 if (!isValidEnum({{argument.name}}, {{enum_variable}}, WTF_ARRAY_LENGTH({{enum_v ariable}}), "{{argument.enum_type}}", exceptionState)) { 244 if (!IsValidEnum({{argument.name}}, {{enum_variable}}, WTF_ARRAY_LENGTH({{enum_v ariable}}), "{{argument.enum_type}}", exceptionState)) {
245 return; 245 return;
246 } 246 }
247 {% elif argument.idl_type == 'Promise' %} 247 {% elif argument.idl_type == 'Promise' %}
248 {# We require this for our implementation of promises, though not in spec: 248 {# We require this for our implementation of promises, though not in spec:
249 http://heycam.github.io/webidl/#es-promise #} 249 http://heycam.github.io/webidl/#es-promise #}
250 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 250 if (!{{argument.name}}.IsUndefinedOrNull() && !{{argument.name}}.IsObject()) {
251 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is not an object.")}} 251 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is not an object.")}}
252 return; 252 return;
253 } 253 }
254 {% endif %} 254 {% endif %}
255 {% endmacro %} 255 {% endmacro %}
256 256
257 257
258 {######################################} 258 {######################################}
259 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} 259 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
260 {% if method.is_custom_call_prologue %} 260 {% if method.is_custom_call_prologue %}
261 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); 261 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl);
262 {% endif %} 262 {% endif %}
263 {# Local variables #} 263 {# Local variables #}
264 {% if method.is_call_with_execution_context %} 264 {% if method.is_call_with_execution_context %}
265 {# [ConstructorCallWith=ExecutionContext] #} 265 {# [ConstructorCallWith=ExecutionContext] #}
266 {# [CallWith=ExecutionContext] #} 266 {# [CallWith=ExecutionContext] #}
267 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate()); 267 ExecutionContext* executionContext = CurrentExecutionContext(info.GetIsolate());
268 {% endif %} 268 {% endif %}
269 {% if method.is_call_with_script_arguments %} 269 {% if method.is_call_with_script_arguments %}
270 {# [CallWith=ScriptArguments] #} 270 {# [CallWith=ScriptArguments] #}
271 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me thod.number_of_arguments}})); 271 ScriptArguments* scriptArguments(ScriptArguments::Create(scriptState, info, {{me thod.number_of_arguments}}));
272 {% endif %} 272 {% endif %}
273 {% if method.is_call_with_document %} 273 {% if method.is_call_with_document %}
274 {# [ConstructorCallWith=Document] #} 274 {# [ConstructorCallWith=Document] #}
275 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())); 275 Document& document = *ToDocument(CurrentExecutionContext(info.GetIsolate()));
276 {% endif %} 276 {% endif %}
277 {# Call #} 277 {# Call #}
278 {% if method.idl_type == 'void' %} 278 {% if method.idl_type == 'void' %}
279 {{cpp_value}}; 279 {{cpp_value}};
280 {% elif method.use_output_parameter_for_result %} 280 {% elif method.use_output_parameter_for_result %}
281 {{method.cpp_type}} result; 281 {{method.cpp_type}} result;
282 {{cpp_value}}; 282 {{cpp_value}};
283 {% elif method.is_constructor %} 283 {% elif method.is_constructor %}
284 {{method.cpp_type}} impl = {{cpp_value}}; 284 {{method.cpp_type}} impl = {{cpp_value}};
285 {% elif method.use_local_result %} 285 {% elif method.use_local_result %}
286 {{method.cpp_type}} result = {{cpp_value}}; 286 {{method.cpp_type}} result = {{cpp_value}};
287 {% endif %} 287 {% endif %}
288 {# Post-call #} 288 {# Post-call #}
289 {% if method.is_raises_exception %} 289 {% if method.is_raises_exception %}
290 if (exceptionState.hadException()) { 290 if (exceptionState.HadException()) {
291 return; 291 return;
292 } 292 }
293 {% endif %} 293 {% endif %}
294 {# Set return value #} 294 {# Set return value #}
295 {% if method.is_new_object and not method.do_not_test_new_object %} 295 {% if method.is_new_object and not method.do_not_test_new_object %}
296 // [NewObject] must always create a new wrapper. Check that a wrapper 296 // [NewObject] must always create a new wrapper. Check that a wrapper
297 // does not exist yet. 297 // does not exist yet.
298 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty()) ; 298 DCHECK(!result || DOMDataStore::GetWrapper(result, info.GetIsolate()).IsEmpty()) ;
299 {% endif %} 299 {% endif %}
300 {% if method.is_constructor %} 300 {% if method.is_constructor %}
301 {{generate_constructor_wrapper(method)}} 301 {{generate_constructor_wrapper(method)}}
302 {%- elif v8_set_return_value %} 302 {%- elif v8_set_return_value %}
303 {% if method.is_explicit_nullable %} 303 {% if method.is_explicit_nullable %}
304 if (result.isNull()) 304 if (result.IsNull())
305 v8SetReturnValueNull(info); 305 V8SetReturnValueNull(info);
306 else 306 else
307 {{v8_set_return_value}}; 307 {{v8_set_return_value}};
308 {% else %} 308 {% else %}
309 {{v8_set_return_value}}; 309 {{v8_set_return_value}};
310 {% endif %} 310 {% endif %}
311 {%- endif %}{# None for void #} 311 {%- endif %}{# None for void #}
312 {% if method.is_custom_call_epilogue %} 312 {% if method.is_custom_call_epilogue %}
313 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); 313 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl);
314 {% endif %} 314 {% endif %}
315 {% endmacro %} 315 {% endmacro %}
316 316
317 317
318 {##############################################################################} 318 {##############################################################################}
319 {% macro throw_type_error(method, error_message) %} 319 {% macro throw_type_error(method, error_message) %}
320 {% if method.has_exception_state or method.returns_promise %} 320 {% if method.has_exception_state or method.returns_promise %}
321 exceptionState.throwTypeError({{error_message}}); 321 exceptionState.ThrowTypeError({{error_message}});
322 {%- elif method.is_constructor %} 322 {%- elif method.is_constructor %}
323 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToC onstruct("{{interface_name}}", {{error_message}})); 323 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::FailedToC onstruct("{{interface_name}}", {{error_message}}));
324 {%- else %} 324 {%- else %}
325 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToE xecute("{{method.name}}", "{{interface_name}}", {{error_message}})); 325 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::FailedToE xecute("{{method.name}}", "{{interface_name}}", {{error_message}}));
326 {%- endif %} 326 {%- endif %}
327 {% endmacro %} 327 {% endmacro %}
328 328
329 329
330 {##############################################################################} 330 {##############################################################################}
331 {% macro throw_argument_error(method, argument, error_message) %} 331 {% macro throw_argument_error(method, argument, error_message) %}
332 {% set quoted_message = '"%s"' % (error_message | replace('\"', '\\\"')) %} 332 {% set quoted_message = '"%s"' % (error_message | replace('\"', '\\\"')) %}
333 {{throw_type_error(method, quoted_message | format(index=(argument.index + 1), n ame=argument.name, type=argument.idl_type))}} 333 {{throw_type_error(method, quoted_message | format(index=(argument.index + 1), n ame=argument.name, type=argument.idl_type))}}
334 {% endmacro %} 334 {% endmacro %}
335 335
(...skipping 25 matching lines...) Expand all
361 } 361 }
362 {% endmacro %} 362 {% endmacro %}
363 363
364 364
365 {##############################################################################} 365 {##############################################################################}
366 {% macro overload_resolution_method(overloads, world_suffix) %} 366 {% macro overload_resolution_method(overloads, world_suffix) %}
367 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) { 367 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) {
368 {% set fall_through_to_partial_overloads = not is_partial and overloads.has_pa rtial_overloads %} 368 {% set fall_through_to_partial_overloads = not is_partial and overloads.has_pa rtial_overloads %}
369 369
370 {% if overloads.measure_all_as %} 370 {% if overloads.measure_all_as %}
371 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{ov erloads.measure_all_as}}); 371 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{o verloads.measure_all_as}});
372 {% endif %} 372 {% endif %}
373 {% if overloads.deprecate_all_as %} 373 {% if overloads.deprecate_all_as %}
374 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{overloads.deprecate_all_as}}); 374 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC ounter::k{{overloads.deprecate_all_as}});
375 {% endif %} 375 {% endif %}
376 376
377 {# First resolve by length #} 377 {# First resolve by length #}
378 {% if not fall_through_to_partial_overloads %} 378 {% if not fall_through_to_partial_overloads %}
379 bool isArityError = false; 379 bool isArityError = false;
380 {% endif %} 380 {% endif %}
381 {# 2. Initialize argcount to be min(maxarg, n). #} 381 {# 2. Initialize argcount to be min(maxarg, n). #}
382 switch (std::min({{overloads.maxarg}}, info.Length())) { 382 switch (std::min({{overloads.maxarg}}, info.Length())) {
383 {# 3. Remove from S all entries whose type list is not of length argcount. # } 383 {# 3. Remove from S all entries whose type list is not of length argcount. # }
384 {% for length, tests_methods in overloads.length_tests_methods %} 384 {% for length, tests_methods in overloads.length_tests_methods %}
385 {# 10. If i = d, then: #} 385 {# 10. If i = d, then: #}
386 case {{length}}: 386 case {{length}}:
387 {# Then resolve by testing argument #} 387 {# Then resolve by testing argument #}
388 {% for test, method in tests_methods %} 388 {% for test, method in tests_methods %}
389 {% if method.visible %} 389 {% if method.visible %}
390 {% filter runtime_enabled(not overloads.runtime_enabled_all and method.run time_enabled_feature_name) %} 390 {% filter runtime_enabled(not overloads.runtime_enabled_all and method.run time_enabled_feature_name) %}
391 if ({{test}}) { 391 if ({{test}}) {
392 {% if method.measure_as and not overloads.measure_all_as %} 392 {% if method.measure_as and not overloads.measure_all_as %}
393 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter ::{{method.measure_as('Method')}}); 393 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter ::k{{method.measure_as('Method')}});
394 {% endif %} 394 {% endif %}
395 {% if method.deprecate_as and not overloads.deprecate_all_as %} 395 {% if method.deprecate_as and not overloads.deprecate_all_as %}
396 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()) , UseCounter::{{method.deprecate_as}}); 396 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()) , UseCounter::k{{method.deprecate_as}});
397 {% endif %} 397 {% endif %}
398 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); 398 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info);
399 return; 399 return;
400 } 400 }
401 {% endfilter %} 401 {% endfilter %}
402 {% endif %} 402 {% endif %}
403 {% endfor %} 403 {% endfor %}
404 break; 404 break;
405 {% endfor %}{# length, tests_methods #} 405 {% endfor %}{# length, tests_methods #}
406 {% if not fall_through_to_partial_overloads %} 406 {% if not fall_through_to_partial_overloads %}
407 default: 407 default:
408 {# 4. If S is empty, then throw a TypeError. #} 408 {# 4. If S is empty, then throw a TypeError. #}
409 isArityError = true; 409 isArityError = true;
410 {% endif %} 410 {% endif %}
411 } 411 }
412 412
413 {% if fall_through_to_partial_overloads %} 413 {% if fall_through_to_partial_overloads %}
414 414
415 DCHECK({{overloads.name}}MethodForPartialInterface); 415 DCHECK({{overloads.name}}MethodForPartialInterface);
416 ({{overloads.name}}MethodForPartialInterface)(info); 416 ({{overloads.name}}MethodForPartialInterface)(info);
417 417
418 {% else %}{# fall_through_to_partial_overloads #} 418 {% else %}{# fall_through_to_partial_overloads #}
419 419
420 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{overloads.name}}"); 420 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionCon text, "{{interface_name}}", "{{overloads.name}}");
421 {% if overloads.returns_promise_all %} 421 {% if overloads.returns_promise_all %}
422 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); 422 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState);
423 {% endif %} 423 {% endif %}
424 424
425 if (isArityError) { 425 if (isArityError) {
426 {% if overloads.length != 0 %} 426 {% if overloads.length != 0 %}
427 if (info.Length() < {{overloads.length}}) { 427 if (info.Length() < {{overloads.length}}) {
428 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{over loads.length}}, info.Length())); 428 exceptionState.ThrowTypeError(ExceptionMessages::NotEnoughArguments({{over loads.length}}, info.Length()));
429 return; 429 return;
430 } 430 }
431 {% endif %} 431 {% endif %}
432 {% if overloads.valid_arities %} 432 {% if overloads.valid_arities %}
433 if (info.Length() >= {{overloads.length}}) { 433 if (info.Length() >= {{overloads.length}}) {
434 exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{overloads .valid_arities}}", info.Length())); 434 exceptionState.ThrowTypeError(ExceptionMessages::InvalidArity("{{overloads .valid_arities}}", info.Length()));
435 return; 435 return;
436 } 436 }
437 {% endif %} 437 {% endif %}
438 } 438 }
439 exceptionState.throwTypeError("No function was found that matched the signatur e provided."); 439 exceptionState.ThrowTypeError("No function was found that matched the signatur e provided.");
440 440
441 {% endif %}{# fall_through_to_partial_overloads #} 441 {% endif %}{# fall_through_to_partial_overloads #}
442 } 442 }
443 {% endmacro %} 443 {% endmacro %}
444 444
445 445
446 {##############################################################################} 446 {##############################################################################}
447 {% macro generate_post_message_impl(method) %} 447 {% macro generate_post_message_impl(method) %}
448 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v8::FunctionCallbackInfo<v8::Value>& info) { 448 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v8::FunctionCallbackInfo<v8::Value>& info) {
449 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, interfaceName, "postMessage"); 449 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionCon text, interfaceName, "postMessage");
450 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 450 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
451 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{method .number_of_required_arguments}}, info.Length())); 451 exceptionState.ThrowTypeError(ExceptionMessages::NotEnoughArguments({{method .number_of_required_arguments}}, info.Length()));
452 return; 452 return;
453 } 453 }
454 454
455 Transferables transferables; 455 Transferables transferables;
456 if (info.Length() > 1) { 456 if (info.Length() > 1) {
457 const int transferablesArgIndex = 1; 457 const int transferablesArgIndex = 1;
458 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info[tra nsferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { 458 if (!SerializedScriptValue::ExtractTransferables(info.GetIsolate(), info[tra nsferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) {
459 return; 459 return;
460 } 460 }
461 } 461 }
462 462
463 RefPtr<SerializedScriptValue> message; 463 RefPtr<SerializedScriptValue> message;
464 if (instance->canTransferArrayBuffersAndImageBitmaps()) { 464 if (instance->CanTransferArrayBuffersAndImageBitmaps()) {
465 // This instance supports sending array buffers by move semantics. 465 // This instance supports sending array buffers by move semantics.
466 message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &tran sferables, nullptr, exceptionState); 466 message = SerializedScriptValue::Serialize(info.GetIsolate(), info[0], &tran sferables, nullptr, exceptionState);
467 if (exceptionState.hadException()) 467 if (exceptionState.HadException())
468 return; 468 return;
469 } else { 469 } else {
470 // This instance doesn't support sending array buffers and image bitmaps 470 // This instance doesn't support sending array buffers and image bitmaps
471 // by move semantics. Emulate it by copy-and-neuter semantics that sends 471 // by move semantics. Emulate it by copy-and-neuter semantics that sends
472 // array buffers and image bitmaps via structured clone and then neuters 472 // array buffers and image bitmaps via structured clone and then neuters
473 // the original objects 473 // the original objects
474 474
475 // Clear references to array buffers and image bitmaps from transferables 475 // Clear references to array buffers and image bitmaps from transferables
476 // so that the serializer can consider the array buffers as 476 // so that the serializer can consider the array buffers as
477 // non-transferable and serialize them into the message. 477 // non-transferable and serialize them into the message.
478 ArrayBufferArray transferableArrayBuffers = transferables.arrayBuffers; 478 ArrayBufferArray transferableArrayBuffers = transferables.array_buffers;
479 transferables.arrayBuffers.clear(); 479 transferables.array_buffers.Clear();
480 ImageBitmapArray transferableImageBitmaps = transferables.imageBitmaps; 480 ImageBitmapArray transferableImageBitmaps = transferables.image_bitmaps;
481 transferables.imageBitmaps.clear(); 481 transferables.image_bitmaps.Clear();
482 message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &tran sferables, nullptr, exceptionState); 482 message = SerializedScriptValue::Serialize(info.GetIsolate(), info[0], &tran sferables, nullptr, exceptionState);
483 if (exceptionState.hadException()) 483 if (exceptionState.HadException())
484 return; 484 return;
485 485
486 // Neuter the original array buffers on the sender context. 486 // Neuter the original array buffers on the sender context.
487 SerializedScriptValue::transferArrayBufferContents(info.GetIsolate(), transf erableArrayBuffers, exceptionState); 487 SerializedScriptValue::TransferArrayBufferContents(info.GetIsolate(), transf erableArrayBuffers, exceptionState);
488 if (exceptionState.hadException()) 488 if (exceptionState.HadException())
489 return; 489 return;
490 // Neuter the original image bitmaps on the sender context. 490 // Neuter the original image bitmaps on the sender context.
491 SerializedScriptValue::transferImageBitmapContents(info.GetIsolate(), transf erableImageBitmaps, exceptionState); 491 SerializedScriptValue::TransferImageBitmapContents(info.GetIsolate(), transf erableImageBitmaps, exceptionState);
492 if (exceptionState.hadException()) 492 if (exceptionState.HadException())
493 return; 493 return;
494 } 494 }
495 495
496 // FIXME: Only pass context/exceptionState if instance really requires it. 496 // FIXME: Only pass context/exceptionState if instance really requires it.
497 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); 497 ExecutionContext* context = CurrentExecutionContext(info.GetIsolate());
498 instance->postMessage(context, message.release(), transferables.messagePorts, exceptionState); 498 instance->postMessage(context, message.Release(), transferables.message_ports, exceptionState);
499 } 499 }
500 {% endmacro %} 500 {% endmacro %}
501 501
502 502
503 {##############################################################################} 503 {##############################################################################}
504 {% macro method_callback(method, world_suffix) %} 504 {% macro method_callback(method, world_suffix) %}
505 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons t v8::FunctionCallbackInfo<v8::Value>& info) { 505 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons t v8::FunctionCallbackInfo<v8::Value>& info) {
506 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #} 506 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #}
507 {% if method.measure_as %} 507 {% if method.measure_as %}
508 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me thod.measure_as('Method')}}); 508 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{m ethod.measure_as('Method')}});
509 {% endif %} 509 {% endif %}
510 {% if method.deprecate_as %} 510 {% if method.deprecate_as %}
511 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{method.deprecate_as}}); 511 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC ounter::k{{method.deprecate_as}});
512 {% endif %} 512 {% endif %}
513 {% endif %}{# not method.overloads #} 513 {% endif %}{# not method.overloads #}
514 {% if world_suffix in method.activity_logging_world_list %} 514 {% if world_suffix in method.activity_logging_world_list %}
515 {% if method.is_static %} 515 {% if method.is_static %}
516 ScriptState* scriptState = ScriptState::forFunctionObject(info); 516 ScriptState* scriptState = ScriptState::ForFunctionObject(info);
517 {% else %} 517 {% else %}
518 ScriptState* scriptState = ScriptState::forReceiverObject(info); 518 ScriptState* scriptState = ScriptState::ForReceiverObject(info);
519 {% endif %} 519 {% endif %}
520 V8PerContextData* contextData = scriptState->perContextData(); 520 V8PerContextData* contextData = scriptState->PerContextData();
521 if (contextData && contextData->activityLogger()) { 521 if (contextData && contextData->ActivityLogger()) {
522 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}"); 522 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionC ontext, "{{interface_name}}", "{{method.name}}");
523 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState); 523 Vector<v8::Local<v8::Value>> loggerArgs = ToImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState);
524 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.data()); 524 contextData->ActivityLogger()->LogMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.Data());
525 } 525 }
526 {% endif %} 526 {% endif %}
527 {% if method.is_ce_reactions %} 527 {% if method.is_ce_reactions %}
528 CEReactionsScope ceReactionsScope; 528 CEReactionsScope ceReactionsScope;
529 {% endif %} 529 {% endif %}
530 {% if method.is_custom %} 530 {% if method.is_custom %}
531 {{v8_class}}::{{method.name}}MethodCustom(info); 531 {{v8_class}}::{{method.name}}MethodCustom(info);
532 {% elif method.is_post_message %} 532 {% elif method.is_post_message %}
533 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8 _class}}::toImpl(info.Holder()), info); 533 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8 _class}}::toImpl(info.Holder()), info);
534 {% else %} 534 {% else %}
535 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info ); 535 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info );
536 {% endif %} 536 {% endif %}
537 } 537 }
538 {% endmacro %} 538 {% endmacro %}
539 539
540 540
541 {##############################################################################} 541 {##############################################################################}
542 {% macro origin_safe_method_getter(method, world_suffix) %} 542 {% macro origin_safe_method_getter(method, world_suffix) %}
543 {# TODO(dcheng): Currently, bindings must create a function object for each 543 {# TODO(dcheng): Currently, bindings must create a function object for each
544 realm as a hack to support the incumbent realm. Clean this up when Blink 544 realm as a hack to support the incumbent realm. Clean this up when Blink
545 properly supports the incumbent realm. #} 545 properly supports the incumbent realm. #}
546 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) { 546 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop ertyCallbackInfo<v8::Value>& info) {
547 static int domTemplateKey; // This address is used for a key to look up the do m template. 547 static int domTemplateKey; // This address is used for a key to look up the do m template.
548 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 548 V8PerIsolateData* data = V8PerIsolateData::From(info.GetIsolate());
549 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu rrentContext()); 549 const DOMWrapperWorld& world = DOMWrapperWorld::World(info.GetIsolate()->GetCu rrentContext());
550 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo); 550 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->FindInterfaceTemplat e(world, &{{v8_class}}::wrapperTypeInfo);
551 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate); 551 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int erfaceTemplate);
552 552
553 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal lback{{world_suffix}}, v8Undefined(), signature, {{method.length}}); 553 v8::Local<v8::FunctionTemplate> methodTemplate = data->FindOrCreateOperationTe mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal lback{{world_suffix}}, V8Undefined(), signature, {{method.length}});
554 // Return the function by default, unless the user script has overwritten it. 554 // Return the function by default, unless the user script has overwritten it.
555 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked()); 555 V8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre ntContext()).ToLocalChecked());
556 556
557 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 557 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
558 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::DoNotReport)) { 558 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()), impl, BindingSecurity::ErrorReportOption::kDoNotReport)) {
559 return; 559 return;
560 } 560 }
561 561
562 v8::Local<v8::Value> hiddenValue = V8HiddenValue::getHiddenValue(ScriptState:: current(info.GetIsolate()), v8::Local<v8::Object>::Cast(info.Holder()), v8Atomic String(info.GetIsolate(), "{{method.name}}")); 562 v8::Local<v8::Value> hiddenValue = V8HiddenValue::GetHiddenValue(ScriptState:: Current(info.GetIsolate()), v8::Local<v8::Object>::Cast(info.Holder()), V8Atomic String(info.GetIsolate(), "{{method.name}}"));
563 if (!hiddenValue.IsEmpty()) { 563 if (!hiddenValue.IsEmpty()) {
564 v8SetReturnValue(info, hiddenValue); 564 V8SetReturnValue(info, hiddenValue);
565 } 565 }
566 } 566 }
567 {% endmacro %} 567 {% endmacro %}
568 568
569 {% macro origin_safe_method_getter_callback(method, world_suffix) %} 569 {% macro origin_safe_method_getter_callback(method, world_suffix) %}
570 void {{v8_class_or_partial}}::{{method.name}}OriginSafeMethodGetterCallback{{wor ld_suffix}}(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info ) { 570 void {{v8_class_or_partial}}::{{method.name}}OriginSafeMethodGetterCallback{{wor ld_suffix}}(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info ) {
571 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}} (info); 571 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}} (info);
572 } 572 }
573 {% endmacro %} 573 {% endmacro %}
574 574
575 575
576 {##############################################################################} 576 {##############################################################################}
577 {% macro generate_constructor(constructor) %} 577 {% macro generate_constructor(constructor) %}
578 {% set name = '%sConstructorCallback' % v8_class 578 {% set name = '%sConstructorCallback' % v8_class
579 if constructor.is_named_constructor else 579 if constructor.is_named_constructor else
580 'constructor%s' % (constructor.overload_index or '') %} 580 'constructor%s' % (constructor.overload_index or '') %}
581 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) { 581 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) {
582 {% set function_call = func_call_with_prep_of_args(constructor) %} 582 {% set function_call = func_call_with_prep_of_args(constructor) %}
583 583
584 {% if constructor.is_named_constructor %} 584 {% if constructor.is_named_constructor %}
585 if (!info.IsConstructCall()) { 585 if (!info.IsConstructCall()) {
586 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::const ructorNotCallableAsFunction("{{constructor.name}}")); 586 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::Const ructorNotCallableAsFunction("{{constructor.name}}"));
587 return; 587 return;
588 } 588 }
589 589
590 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExisti ngObject) { 590 if (ConstructorMode::Current(info.GetIsolate()) == ConstructorMode::kWrapExist ingObject) {
591 v8SetReturnValue(info, info.Holder()); 591 V8SetReturnValue(info, info.Holder());
592 return; 592 return;
593 } 593 }
594 {% endif %} 594 {% endif %}
595 595
596 {% if 'exceptionState' in function_call %} 596 {% if 'exceptionState' in function_call %}
597 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); 597 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kConstruction Context, "{{interface_name}}");
598 {% endif %} 598 {% endif %}
599 {% if 'scriptState' in function_call %} 599 {% if 'scriptState' in function_call %}
600 ScriptState* scriptState = ScriptState::forReceiverObject(info); 600 ScriptState* scriptState = ScriptState::ForReceiverObject(info);
601 {% endif %} 601 {% endif %}
602 602
603 {{function_call | indent(2)}} 603 {{function_call | indent(2)}}
604 } 604 }
605 {% endmacro %} 605 {% endmacro %}
606 606
607 607
608 {##############################################################################} 608 {##############################################################################}
609 {% macro generate_constructor_wrapper(constructor) %} 609 {% macro generate_constructor_wrapper(constructor) %}
610 {% set constructor_class = v8_class + ('Constructor' 610 {% set constructor_class = v8_class + ('Constructor'
611 if constructor.is_named_constructor else 611 if constructor.is_named_constructor else
612 '') %} 612 '') %}
613 v8::Local<v8::Object> wrapper = info.Holder(); 613 v8::Local<v8::Object> wrapper = info.Holder();
614 wrapper = impl->associateWithWrapper(info.GetIsolate(), &{{constructor_class}}:: wrapperTypeInfo, wrapper); 614 wrapper = impl->AssociateWithWrapper(info.GetIsolate(), &{{constructor_class}}:: wrapperTypeInfo, wrapper);
615 v8SetReturnValue(info, wrapper); 615 V8SetReturnValue(info, wrapper);
616 {% endmacro %} 616 {% endmacro %}
617 617
618 618
619 {##############################################################################} 619 {##############################################################################}
620 {% macro method_configuration(method) %} 620 {% macro method_configuration(method) %}
621 {% from 'utilities.cpp.tmpl' import property_location %} 621 {% from 'utilities.cpp.tmpl' import property_location %}
622 {% set method_callback = 622 {% set method_callback =
623 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} 623 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %}
624 {% set method_callback_for_main_world = 624 {% set method_callback_for_main_world =
625 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) 625 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name)
626 if method.is_per_world_bindings else 'nullptr' %} 626 if method.is_per_world_bindings else 'nullptr' %}
627 {% set property_attribute = 627 {% set property_attribute =
628 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) 628 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes)
629 if method.property_attributes else 'v8::None' %} 629 if method.property_attributes else 'v8::None' %}
630 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' 630 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder'
631 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} 631 if method.returns_promise else 'V8DOMConfiguration::kCheckHolder' %}
632 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} 632 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}}
633 {%- endmacro %} 633 {%- endmacro %}
634 634
635 635
636 {######################################} 636 {######################################}
637 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} 637 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %}
638 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 638 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
639 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); 639 V8DOMConfiguration::InstallMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration);
640 {%- endmacro %} 640 {%- endmacro %}
641 641
642 642
643 {######################################} 643 {######################################}
644 {% macro install_conditionally_enabled_methods() %} 644 {% macro install_conditionally_enabled_methods() %}
645 {% if methods | conditionally_exposed(is_partial) %} 645 {% if methods | conditionally_exposed(is_partial) %}
646 {# Define operations with limited exposure #} 646 {# Define operations with limited exposure #}
647 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla te); 647 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTempla te);
648 ExecutionContext* executionContext = toExecutionContext(prototypeObject->Creatio nContext()); 648 ExecutionContext* executionContext = ToExecutionContext(prototypeObject->Creatio nContext());
649 DCHECK(executionContext); 649 DCHECK(executionContext);
650 {% for method in methods | conditionally_exposed(is_partial) %} 650 {% for method in methods | conditionally_exposed(is_partial) %}
651 {% filter secure_context(method.overloads.secure_context_test_all 651 {% filter secure_context(method.overloads.secure_context_test_all
652 if method.overloads else 652 if method.overloads else
653 method.secure_context_test) %} 653 method.secure_context_test) %}
654 {% filter exposed(method.overloads.exposed_test_all 654 {% filter exposed(method.overloads.exposed_test_all
655 if method.overloads else 655 if method.overloads else
656 method.exposed_test) %} 656 method.exposed_test) %}
657 {% filter runtime_enabled(method.overloads.runtime_enabled_all 657 {% filter runtime_enabled(method.overloads.runtime_enabled_all
658 if method.overloads else 658 if method.overloads else
659 method.runtime_enabled_feature_name) %} 659 method.runtime_enabled_feature_name) %}
660 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 660 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
661 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 661 V8DOMConfiguration::InstallMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
662 {% endfilter %}{# runtime_enabled() #} 662 {% endfilter %}{# runtime_enabled() #}
663 {% endfilter %}{# exposed() #} 663 {% endfilter %}{# exposed() #}
664 {% endfilter %}{# secure_context() #} 664 {% endfilter %}{# secure_context() #}
665 {% endfor %} 665 {% endfor %}
666 {% endif %} 666 {% endif %}
667 {%- endmacro %} 667 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698