| OLD | NEW |
| 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 {% if interface_name == 'Window' and not method.is_cross_origin %} | 32 {% if interface_name == 'Window' and not method.is_cross_origin %} |
| 33 // Same-origin methods are never exposed via the cross-origin interceptors. | 33 // Same-origin methods are never exposed via the cross-origin interceptors. |
| 34 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast | 34 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast |
| 35 // here. | 35 // here. |
| 36 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder())); | 36 LocalDOMWindow* impl = ToLocalDOMWindow({{v8_class}}::toImpl(info.Holder())); |
| 37 {% else %} | 37 {% else %} |
| 38 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 38 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); |
| 39 {% endif %}{# interface_name == 'Window' and not method.is_cross_origin #} | 39 {% endif %}{# interface_name == 'Window' and not method.is_cross_origin #} |
| 40 {% endif %}{# not method.is_static #} | 40 {% endif %}{# not method.is_static #} |
| 41 | 41 |
| 42 {# Security checks #} | 42 {# Security checks #} |
| 43 {% if method.is_check_security_for_return_value %} | 43 {% if method.is_check_security_for_return_value %} |
| 44 {{define_exception_state}} | 44 {{define_exception_state}} |
| 45 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()),
{{method.cpp_value}}, exceptionState)) { | 45 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()),
{{method.cpp_value}}, exceptionState)) { |
| 46 v8SetReturnValueNull(info); | 46 V8SetReturnValueNull(info); |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 {% endif %} | 49 {% endif %} |
| 50 | 50 |
| 51 {% if 'scriptState' in function_call %} | 51 {% if 'scriptState' in function_call %} |
| 52 {% if method.is_static %} | 52 {% if method.is_static %} |
| 53 ScriptState* scriptState = ScriptState::forFunctionObject(info); | 53 ScriptState* scriptState = ScriptState::ForFunctionObject(info); |
| 54 {% else %} | 54 {% else %} |
| 55 ScriptState* scriptState = ScriptState::forReceiverObject(info); | 55 ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| 56 {% endif %} | 56 {% endif %} |
| 57 {% endif %} | 57 {% endif %} |
| 58 | 58 |
| 59 {% if method.is_custom_element_callbacks %} | 59 {% if method.is_custom_element_callbacks %} |
| 60 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; | 60 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; |
| 61 {% endif %} | 61 {% endif %} |
| 62 | 62 |
| 63 {{function_call | indent(2)}} | 63 {{function_call | indent(2)}} |
| 64 } | 64 } |
| 65 {% endfilter %} | 65 {% endfilter %} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 78 | 78 |
| 79 | 79 |
| 80 {######################################} | 80 {######################################} |
| 81 {% macro generate_arguments(method, world_suffix) %} | 81 {% macro generate_arguments(method, world_suffix) %} |
| 82 {% if method.arguments %} | 82 {% if method.arguments %} |
| 83 | 83 |
| 84 {# Overloaded methods/constructors have length checked during overload resolutio
n #} | 84 {# Overloaded methods/constructors have length checked during overload resolutio
n #} |
| 85 {% if method.number_of_required_arguments and not method.overload_index %} | 85 {% if method.number_of_required_arguments and not method.overload_index %} |
| 86 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 86 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 87 {{throw_type_error(method, | 87 {{throw_type_error(method, |
| 88 'ExceptionMessages::notEnoughArguments(%(expected)d, info.Length())' | 88 'ExceptionMessages::NotEnoughArguments(%(expected)d, info.Length())' |
| 89 | format(expected=method.number_of_required_arguments))}} | 89 | format(expected=method.number_of_required_arguments))}} |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 {% endif %} | 92 {% endif %} |
| 93 | 93 |
| 94 {% for argument in method.arguments %} | 94 {% for argument in method.arguments %} |
| 95 {{argument.cpp_type}} {{argument.name}}; | 95 {{argument.cpp_type}} {{argument.name}}; |
| 96 {% endfor %} | 96 {% endfor %} |
| 97 {% if method.has_optional_argument_without_default_value %} | 97 {% if method.has_optional_argument_without_default_value %} |
| 98 {# Count the effective number of arguments. (arg1, arg2, undefined) is | 98 {# Count the effective number of arguments. (arg1, arg2, undefined) is |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argumen
t.cpp_value) | indent(2)}} | 132 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argumen
t.cpp_value) | indent(2)}} |
| 133 {% else %} | 133 {% else %} |
| 134 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) |
indent(2)}} | 134 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) |
indent(2)}} |
| 135 {% endif %} | 135 {% endif %} |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 {% endif %} | 138 {% endif %} |
| 139 {% if argument.is_callback_interface %} | 139 {% if argument.is_callback_interface %} |
| 140 {# FIXME: remove EventListener special case #} | 140 {# FIXME: remove EventListener special case #} |
| 141 {% if argument.idl_type == 'EventListener' %} | 141 {% if argument.idl_type == 'EventListener' %} |
| 142 {% if method.name == 'removeEventListener' or method.name == 'removeListener' %} | 142 {% if method.name == 'RemoveEventListener' or method.name == 'RemoveListener' %} |
| 143 {{argument.name}} = V8EventListenerHelper::getEventListener(ScriptState::current
(info.GetIsolate()), info[{{argument.index}}], false, ListenerFindOnly); | 143 {{argument.name}} = V8EventListenerHelper::GetEventListener(ScriptState::Current
(info.GetIsolate()), info[{{argument.index}}], false, kListenerFindOnly); |
| 144 {% else %}{# method.name == 'addEventListener' #} | 144 {% else %}{# method.name == 'AddEventListener' #} |
| 145 {{argument.name}} = V8EventListenerHelper::getEventListener(ScriptState::current
(info.GetIsolate()), info[{{argument.index}}], false, ListenerFindOrCreate); | 145 {{argument.name}} = V8EventListenerHelper::GetEventListener(ScriptState::Current
(info.GetIsolate()), info[{{argument.index}}], false, kListenerFindOrCreate); |
| 146 {% endif %}{# method.name #} | 146 {% endif %}{# method.name #} |
| 147 {% else %}{# argument.idl_type == 'EventListener' #} | 147 {% else %}{# argument.idl_type == 'EventListener' #} |
| 148 {# Callback functions must be functions: | 148 {# Callback functions must be functions: |
| 149 http://www.w3.org/TR/WebIDL/#es-callback-function #} | 149 http://www.w3.org/TR/WebIDL/#es-callback-function #} |
| 150 {% if argument.is_optional %} | 150 {% if argument.is_optional %} |
| 151 if (!isUndefinedOrNull(info[{{argument.index}}])) { | 151 if (!IsUndefinedOrNull(info[{{argument.index}}])) { |
| 152 if (!info[{{argument.index}}]->IsFunction()) { | 152 if (!info[{{argument.index}}]->IsFunction()) { |
| 153 {{throw_argument_error(method, argument, "The callback provided as parameter
%(index)d is not a function.")}} | 153 {{throw_argument_error(method, argument, "The callback provided as parameter
%(index)d is not a function.")}} |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>::C
ast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); | 156 {{argument.name}} = V8{{argument.idl_type}}::Create(v8::Local<v8::Function>::C
ast(info[{{argument.index}}]), ScriptState::Current(info.GetIsolate())); |
| 157 } else { | 157 } else { |
| 158 {{argument.name}} = nullptr; | 158 {{argument.name}} = nullptr; |
| 159 } | 159 } |
| 160 {% else %}{# argument.is_optional #} | 160 {% else %}{# argument.is_optional #} |
| 161 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { | 161 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{
{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %
}info[{{argument.index}}]->IsFunction(){% endif %}) { |
| 162 {{throw_argument_error(method, argument, "The callback provided as parameter %
(index)d is not a function.")}} | 162 {{throw_argument_error(method, argument, "The callback provided as parameter %
(index)d is not a function.")}} |
| 163 return; | 163 return; |
| 164 } | 164 } |
| 165 {{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())); | 165 {{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())); |
| 166 {% endif %}{# argument.is_optional #} | 166 {% endif %}{# argument.is_optional #} |
| 167 {% endif %}{# argument.idl_type == 'EventListener' #} | 167 {% endif %}{# argument.idl_type == 'EventListener' #} |
| 168 {% elif argument.is_callback_function %} | 168 {% elif argument.is_callback_function %} |
| 169 if ({% if argument.is_nullable %}!isUndefinedOrNull(info[{{argument.index}}]) &&
{% endif %}!(info[{{argument.index}}]->IsObject() && v8::Local<v8::Object>::Cas
t(info[{{argument.index}}])->IsCallable())) { | 169 if ({% if argument.is_nullable %}!IsUndefinedOrNull(info[{{argument.index}}]) &&
{% endif %}!(info[{{argument.index}}]->IsObject() && v8::Local<v8::Object>::Cas
t(info[{{argument.index}}])->IsCallable())) { |
| 170 {{throw_argument_error(method, argument, "The callback provided as parameter %
(index)d is not a function.")}} | 170 {{throw_argument_error(method, argument, "The callback provided as parameter %
(index)d is not a function.")}} |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 {{v8_value_to_local_cpp_value(argument)}} | 173 {{v8_value_to_local_cpp_value(argument)}} |
| 174 {% elif argument.is_variadic_wrapper_type %} | 174 {% elif argument.is_variadic_wrapper_type %} |
| 175 for (int i = {{argument.index}}; i < info.Length(); ++i) { | 175 for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| 176 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { | 176 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { |
| 177 {{throw_argument_error(method, argument, "parameter %(index)d is not of type
'%(type)s'.")}} | 177 {{throw_argument_error(method, argument, "parameter %(index)d is not of type
'%(type)s'.")}} |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 {{argument.name}}.push_back(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Obje
ct>::Cast(info[i]))); | 180 {{argument.name}}.push_back(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Obje
ct>::Cast(info[i]))); |
| 181 } | 181 } |
| 182 {% elif argument.is_dictionary %} | 182 {% elif argument.is_dictionary %} |
| 183 {% if not argument.use_permissive_dictionary_conversion %} | 183 {% if not argument.use_permissive_dictionary_conversion %} |
| 184 {# Dictionaries must have type Undefined, Null or Object: | 184 {# Dictionaries must have type Undefined, Null or Object: |
| 185 http://heycam.github.io/webidl/#es-dictionary #} | 185 http://heycam.github.io/webidl/#es-dictionary #} |
| 186 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I
sObject()) { | 186 if (!IsUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I
sObject()) { |
| 187 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is
not an object.")}} | 187 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is
not an object.")}} |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 {% endif %}{# not argument.use_permissive_dictionary_conversion #} | 190 {% endif %}{# not argument.use_permissive_dictionary_conversion #} |
| 191 {{v8_value_to_local_cpp_value(argument)}} | 191 {{v8_value_to_local_cpp_value(argument)}} |
| 192 {% elif argument.is_explicit_nullable %} | 192 {% elif argument.is_explicit_nullable %} |
| 193 if (!isUndefinedOrNull(info[{{argument.index}}])) { | 193 if (!IsUndefinedOrNull(info[{{argument.index}}])) { |
| 194 {{v8_value_to_local_cpp_value(argument) | indent(2)}} | 194 {{v8_value_to_local_cpp_value(argument) | indent(2)}} |
| 195 } | 195 } |
| 196 {% else %}{# argument.is_nullable #} | 196 {% else %}{# argument.is_nullable #} |
| 197 {{v8_value_to_local_cpp_value(argument)}} | 197 {{v8_value_to_local_cpp_value(argument)}} |
| 198 {% endif %}{# argument.is_nullable #} | 198 {% endif %}{# argument.is_nullable #} |
| 199 {# Type checking, possibly throw a TypeError, per: | 199 {# Type checking, possibly throw a TypeError, per: |
| 200 http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 200 http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| 201 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_
type %} | 201 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_
type %} |
| 202 {# Type checking for wrapper interface types (if interface not implemented, | 202 {# Type checking for wrapper interface types (if interface not implemented, |
| 203 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface | 203 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface |
| 204 Note: for variadic arguments, the type checking is done for each matched | 204 Note: for variadic arguments, the type checking is done for each matched |
| 205 argument instead; see argument.is_variadic_wrapper_type code-path above. #} | 205 argument instead; see argument.is_variadic_wrapper_type code-path above. #} |
| 206 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { | 206 if (!{{argument.name}}{% if argument.is_nullable %} && !IsUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { |
| 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 {% elif argument.enum_values %} | 210 {% elif argument.enum_values %} |
| 211 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 211 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
| 212 {% set enum_variable = 'valid' + argument.name[0].upper() + argument.name[1:] +
'Values' %} | 212 {% set enum_variable = 'valid' + argument.name[0].upper() + argument.name[1:] +
'Values' %} |
| 213 {{declare_enum_validation_variable(argument.enum_values, enum_variable)}} | 213 {{declare_enum_validation_variable(argument.enum_values, enum_variable)}} |
| 214 if (!isValidEnum({{argument.name}}, {{enum_variable}}, WTF_ARRAY_LENGTH({{enum_v
ariable}}), "{{argument.enum_type}}", exceptionState)) { | 214 if (!IsValidEnum({{argument.name}}, {{enum_variable}}, WTF_ARRAY_LENGTH({{enum_v
ariable}}), "{{argument.enum_type}}", exceptionState)) { |
| 215 return; | 215 return; |
| 216 } | 216 } |
| 217 {% elif argument.idl_type == 'Promise' %} | 217 {% elif argument.idl_type == 'Promise' %} |
| 218 {# We require this for our implementation of promises, though not in spec: | 218 {# We require this for our implementation of promises, though not in spec: |
| 219 http://heycam.github.io/webidl/#es-promise #} | 219 http://heycam.github.io/webidl/#es-promise #} |
| 220 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 220 if (!{{argument.name}}.IsUndefinedOrNull() && !{{argument.name}}.IsObject()) { |
| 221 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is
not an object.")}} | 221 {{throw_argument_error(method, argument, "parameter %(index)d ('%(name)s') is
not an object.")}} |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 {% endif %} | 224 {% endif %} |
| 225 {% endmacro %} | 225 {% endmacro %} |
| 226 | 226 |
| 227 | 227 |
| 228 {######################################} | 228 {######################################} |
| 229 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} | 229 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} |
| 230 {% if method.is_custom_call_prologue %} | 230 {% if method.is_custom_call_prologue %} |
| 231 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); | 231 {{v8_class}}::{{method.name}}MethodPrologueCustom(info, impl); |
| 232 {% endif %} | 232 {% endif %} |
| 233 {# Local variables #} | 233 {# Local variables #} |
| 234 {% if method.is_call_with_execution_context %} | 234 {% if method.is_call_with_execution_context %} |
| 235 {# [ConstructorCallWith=ExecutionContext] #} | 235 {# [ConstructorCallWith=ExecutionContext] #} |
| 236 {# [CallWith=ExecutionContext] #} | 236 {# [CallWith=ExecutionContext] #} |
| 237 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate()); | 237 ExecutionContext* executionContext = CurrentExecutionContext(info.GetIsolate()); |
| 238 {% endif %} | 238 {% endif %} |
| 239 {% if method.is_call_with_script_arguments %} | 239 {% if method.is_call_with_script_arguments %} |
| 240 {# [CallWith=ScriptArguments] #} | 240 {# [CallWith=ScriptArguments] #} |
| 241 ScriptArguments* scriptArguments(ScriptArguments::create(scriptState, info, {{me
thod.number_of_arguments}})); | 241 ScriptArguments* scriptArguments(ScriptArguments::Create(scriptState, info, {{me
thod.number_of_arguments}})); |
| 242 {% endif %} | 242 {% endif %} |
| 243 {% if method.is_call_with_document %} | 243 {% if method.is_call_with_document %} |
| 244 {# [ConstructorCallWith=Document] #} | 244 {# [ConstructorCallWith=Document] #} |
| 245 Document& document = *toDocument(currentExecutionContext(info.GetIsolate())); | 245 Document& document = *ToDocument(CurrentExecutionContext(info.GetIsolate())); |
| 246 {% endif %} | 246 {% endif %} |
| 247 {# Call #} | 247 {# Call #} |
| 248 {% if method.idl_type == 'void' %} | 248 {% if method.idl_type == 'void' %} |
| 249 {{cpp_value}}; | 249 {{cpp_value}}; |
| 250 {% elif method.use_output_parameter_for_result %} | 250 {% elif method.use_output_parameter_for_result %} |
| 251 {{method.cpp_type}} result; | 251 {{method.cpp_type}} result; |
| 252 {{cpp_value}}; | 252 {{cpp_value}}; |
| 253 {% elif method.is_constructor %} | 253 {% elif method.is_constructor %} |
| 254 {{method.cpp_type}} impl = {{cpp_value}}; | 254 {{method.cpp_type}} impl = {{cpp_value}}; |
| 255 {% elif method.use_local_result %} | 255 {% elif method.use_local_result %} |
| 256 {{method.cpp_type}} result = {{cpp_value}}; | 256 {{method.cpp_type}} result = {{cpp_value}}; |
| 257 {% endif %} | 257 {% endif %} |
| 258 {# Post-call #} | 258 {# Post-call #} |
| 259 {% if method.is_raises_exception %} | 259 {% if method.is_raises_exception %} |
| 260 if (exceptionState.hadException()) { | 260 if (exceptionState.HadException()) { |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 {% endif %} | 263 {% endif %} |
| 264 {# Set return value #} | 264 {# Set return value #} |
| 265 {% if method.is_new_object and not method.do_not_test_new_object %} | 265 {% if method.is_new_object and not method.do_not_test_new_object %} |
| 266 // [NewObject] must always create a new wrapper. Check that a wrapper | 266 // [NewObject] must always create a new wrapper. Check that a wrapper |
| 267 // does not exist yet. | 267 // does not exist yet. |
| 268 DCHECK(!result || DOMDataStore::getWrapper(result, info.GetIsolate()).IsEmpty())
; | 268 DCHECK(!result || DOMDataStore::GetWrapper(result, info.GetIsolate()).IsEmpty())
; |
| 269 {% endif %} | 269 {% endif %} |
| 270 {% if method.is_constructor %} | 270 {% if method.is_constructor %} |
| 271 {{generate_constructor_wrapper(method)}} | 271 {{generate_constructor_wrapper(method)}} |
| 272 {%- elif v8_set_return_value %} | 272 {%- elif v8_set_return_value %} |
| 273 {% if method.is_explicit_nullable %} | 273 {% if method.is_explicit_nullable %} |
| 274 if (result.isNull()) | 274 if (result.IsNull()) |
| 275 v8SetReturnValueNull(info); | 275 V8SetReturnValueNull(info); |
| 276 else | 276 else |
| 277 {{v8_set_return_value}}; | 277 {{v8_set_return_value}}; |
| 278 {% else %} | 278 {% else %} |
| 279 {{v8_set_return_value}}; | 279 {{v8_set_return_value}}; |
| 280 {% endif %} | 280 {% endif %} |
| 281 {%- endif %}{# None for void #} | 281 {%- endif %}{# None for void #} |
| 282 {% if method.is_custom_call_epilogue %} | 282 {% if method.is_custom_call_epilogue %} |
| 283 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); | 283 {{v8_class}}::{{method.name}}MethodEpilogueCustom(info, impl); |
| 284 {% endif %} | 284 {% endif %} |
| 285 {% endmacro %} | 285 {% endmacro %} |
| 286 | 286 |
| 287 | 287 |
| 288 {##############################################################################} | 288 {##############################################################################} |
| 289 {% macro throw_type_error(method, error_message) %} | 289 {% macro throw_type_error(method, error_message) %} |
| 290 {% if method.has_exception_state or method.returns_promise %} | 290 {% if method.has_exception_state or method.returns_promise %} |
| 291 exceptionState.throwTypeError({{error_message}}); | 291 exceptionState.ThrowTypeError({{error_message}}); |
| 292 {%- elif method.is_constructor %} | 292 {%- elif method.is_constructor %} |
| 293 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToC
onstruct("{{interface_name}}", {{error_message}})); | 293 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::FailedToC
onstruct("{{interface_name}}", {{error_message}})); |
| 294 {%- else %} | 294 {%- else %} |
| 295 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToE
xecute("{{method.name}}", "{{interface_name}}", {{error_message}})); | 295 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::FailedToE
xecute("{{method.name}}", "{{interface_name}}", {{error_message}})); |
| 296 {%- endif %} | 296 {%- endif %} |
| 297 {% endmacro %} | 297 {% endmacro %} |
| 298 | 298 |
| 299 | 299 |
| 300 {##############################################################################} | 300 {##############################################################################} |
| 301 {% macro throw_argument_error(method, argument, error_message) %} | 301 {% macro throw_argument_error(method, argument, error_message) %} |
| 302 {% set quoted_message = '"%s"' % (error_message | replace('\"', '\\\"')) %} | 302 {% set quoted_message = '"%s"' % (error_message | replace('\"', '\\\"')) %} |
| 303 {{throw_type_error(method, quoted_message | format(index=(argument.index + 1), n
ame=argument.name, type=argument.idl_type))}} | 303 {{throw_type_error(method, quoted_message | format(index=(argument.index + 1), n
ame=argument.name, type=argument.idl_type))}} |
| 304 {% endmacro %} | 304 {% endmacro %} |
| 305 | 305 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 331 } | 331 } |
| 332 {% endmacro %} | 332 {% endmacro %} |
| 333 | 333 |
| 334 | 334 |
| 335 {##############################################################################} | 335 {##############################################################################} |
| 336 {% macro overload_resolution_method(overloads, world_suffix) %} | 336 {% macro overload_resolution_method(overloads, world_suffix) %} |
| 337 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) { | 337 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) { |
| 338 {% set fall_through_to_partial_overloads = not is_partial and overloads.has_pa
rtial_overloads %} | 338 {% set fall_through_to_partial_overloads = not is_partial and overloads.has_pa
rtial_overloads %} |
| 339 | 339 |
| 340 {% if overloads.measure_all_as %} | 340 {% if overloads.measure_all_as %} |
| 341 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{ov
erloads.measure_all_as}}); | 341 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{o
verloads.measure_all_as}}); |
| 342 {% endif %} | 342 {% endif %} |
| 343 {% if overloads.deprecate_all_as %} | 343 {% if overloads.deprecate_all_as %} |
| 344 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC
ounter::{{overloads.deprecate_all_as}}); | 344 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC
ounter::k{{overloads.deprecate_all_as}}); |
| 345 {% endif %} | 345 {% endif %} |
| 346 | 346 |
| 347 {# First resolve by length #} | 347 {# First resolve by length #} |
| 348 {% if not fall_through_to_partial_overloads %} | 348 {% if not fall_through_to_partial_overloads %} |
| 349 bool isArityError = false; | 349 bool isArityError = false; |
| 350 {% endif %} | 350 {% endif %} |
| 351 {# 2. Initialize argcount to be min(maxarg, n). #} | 351 {# 2. Initialize argcount to be min(maxarg, n). #} |
| 352 switch (std::min({{overloads.maxarg}}, info.Length())) { | 352 switch (std::min({{overloads.maxarg}}, info.Length())) { |
| 353 {# 3. Remove from S all entries whose type list is not of length argcount. #
} | 353 {# 3. Remove from S all entries whose type list is not of length argcount. #
} |
| 354 {% for length, tests_methods in overloads.length_tests_methods %} | 354 {% for length, tests_methods in overloads.length_tests_methods %} |
| 355 {# 10. If i = d, then: #} | 355 {# 10. If i = d, then: #} |
| 356 case {{length}}: | 356 case {{length}}: |
| 357 {# Then resolve by testing argument #} | 357 {# Then resolve by testing argument #} |
| 358 {% for test, method in tests_methods %} | 358 {% for test, method in tests_methods %} |
| 359 {% if method.visible %} | 359 {% if method.visible %} |
| 360 {% filter runtime_enabled(not overloads.runtime_enabled_all and method.run
time_enabled_feature_name) %} | 360 {% filter runtime_enabled(not overloads.runtime_enabled_all and method.run
time_enabled_feature_name) %} |
| 361 if ({{test}}) { | 361 if ({{test}}) { |
| 362 {% if method.measure_as and not overloads.measure_all_as %} | 362 {% if method.measure_as and not overloads.measure_all_as %} |
| 363 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter
::{{method.measure_as('Method')}}); | 363 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter
::k{{method.measure_as('Method')}}); |
| 364 {% endif %} | 364 {% endif %} |
| 365 {% if method.deprecate_as and not overloads.deprecate_all_as %} | 365 {% if method.deprecate_as and not overloads.deprecate_all_as %} |
| 366 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate())
, UseCounter::{{method.deprecate_as}}); | 366 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate())
, UseCounter::k{{method.deprecate_as}}); |
| 367 {% endif %} | 367 {% endif %} |
| 368 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); | 368 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); |
| 369 return; | 369 return; |
| 370 } | 370 } |
| 371 {% endfilter %} | 371 {% endfilter %} |
| 372 {% endif %} | 372 {% endif %} |
| 373 {% endfor %} | 373 {% endfor %} |
| 374 break; | 374 break; |
| 375 {% endfor %}{# length, tests_methods #} | 375 {% endfor %}{# length, tests_methods #} |
| 376 {% if not fall_through_to_partial_overloads %} | 376 {% if not fall_through_to_partial_overloads %} |
| 377 default: | 377 default: |
| 378 {# 4. If S is empty, then throw a TypeError. #} | 378 {# 4. If S is empty, then throw a TypeError. #} |
| 379 isArityError = true; | 379 isArityError = true; |
| 380 {% endif %} | 380 {% endif %} |
| 381 } | 381 } |
| 382 | 382 |
| 383 {% if fall_through_to_partial_overloads %} | 383 {% if fall_through_to_partial_overloads %} |
| 384 | 384 |
| 385 DCHECK({{overloads.name}}MethodForPartialInterface); | 385 DCHECK({{overloads.name}}MethodForPartialInterface); |
| 386 ({{overloads.name}}MethodForPartialInterface)(info); | 386 ({{overloads.name}}MethodForPartialInterface)(info); |
| 387 | 387 |
| 388 {% else %}{# fall_through_to_partial_overloads #} | 388 {% else %}{# fall_through_to_partial_overloads #} |
| 389 | 389 |
| 390 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont
ext, "{{interface_name}}", "{{overloads.name}}"); | 390 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionCon
text, "{{interface_name}}", "{{overloads.name}}"); |
| 391 {% if overloads.returns_promise_all %} | 391 {% if overloads.returns_promise_all %} |
| 392 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); | 392 ExceptionToRejectPromiseScope rejectPromiseScope(info, exceptionState); |
| 393 {% endif %} | 393 {% endif %} |
| 394 | 394 |
| 395 if (isArityError) { | 395 if (isArityError) { |
| 396 {% if overloads.length != 0 %} | 396 {% if overloads.length != 0 %} |
| 397 if (info.Length() < {{overloads.length}}) { | 397 if (info.Length() < {{overloads.length}}) { |
| 398 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{over
loads.length}}, info.Length())); | 398 exceptionState.ThrowTypeError(ExceptionMessages::NotEnoughArguments({{over
loads.length}}, info.Length())); |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 {% endif %} | 401 {% endif %} |
| 402 {% if overloads.valid_arities %} | 402 {% if overloads.valid_arities %} |
| 403 if (info.Length() >= {{overloads.length}}) { | 403 if (info.Length() >= {{overloads.length}}) { |
| 404 exceptionState.throwTypeError(ExceptionMessages::invalidArity("{{overloads
.valid_arities}}", info.Length())); | 404 exceptionState.ThrowTypeError(ExceptionMessages::InvalidArity("{{overloads
.valid_arities}}", info.Length())); |
| 405 return; | 405 return; |
| 406 } | 406 } |
| 407 {% endif %} | 407 {% endif %} |
| 408 } | 408 } |
| 409 exceptionState.throwTypeError("No function was found that matched the signatur
e provided."); | 409 exceptionState.ThrowTypeError("No function was found that matched the signatur
e provided."); |
| 410 | 410 |
| 411 {% endif %}{# fall_through_to_partial_overloads #} | 411 {% endif %}{# fall_through_to_partial_overloads #} |
| 412 } | 412 } |
| 413 {% endmacro %} | 413 {% endmacro %} |
| 414 | 414 |
| 415 | 415 |
| 416 {##############################################################################} | 416 {##############################################################################} |
| 417 {% macro generate_post_message_impl(method) %} | 417 {% macro generate_post_message_impl(method) %} |
| 418 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance,
const v8::FunctionCallbackInfo<v8::Value>& info) { | 418 static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance,
const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 419 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont
ext, interfaceName, "postMessage"); | 419 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionCon
text, interfaceName, "postMessage"); |
| 420 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 420 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
| 421 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{method
.number_of_required_arguments}}, info.Length())); | 421 exceptionState.ThrowTypeError(ExceptionMessages::NotEnoughArguments({{method
.number_of_required_arguments}}, info.Length())); |
| 422 return; | 422 return; |
| 423 } | 423 } |
| 424 | 424 |
| 425 Transferables transferables; | 425 Transferables transferables; |
| 426 if (info.Length() > 1) { | 426 if (info.Length() > 1) { |
| 427 const int transferablesArgIndex = 1; | 427 const int transferablesArgIndex = 1; |
| 428 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info[tra
nsferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { | 428 if (!SerializedScriptValue::ExtractTransferables(info.GetIsolate(), info[tra
nsferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { |
| 429 return; | 429 return; |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 RefPtr<SerializedScriptValue> message; | 433 RefPtr<SerializedScriptValue> message; |
| 434 if (instance->canTransferArrayBuffersAndImageBitmaps()) { | 434 if (instance->CanTransferArrayBuffersAndImageBitmaps()) { |
| 435 // This instance supports sending array buffers by move semantics. | 435 // This instance supports sending array buffers by move semantics. |
| 436 SerializedScriptValue::SerializeOptions options; | 436 SerializedScriptValue::SerializeOptions options; |
| 437 options.transferables = &transferables; | 437 options.transferables = &transferables; |
| 438 message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], optio
ns, exceptionState); | 438 message = SerializedScriptValue::Serialize(info.GetIsolate(), info[0], optio
ns, exceptionState); |
| 439 if (exceptionState.hadException()) | 439 if (exceptionState.HadException()) |
| 440 return; | 440 return; |
| 441 } else { | 441 } else { |
| 442 // This instance doesn't support sending array buffers and image bitmaps | 442 // This instance doesn't support sending array buffers and image bitmaps |
| 443 // by move semantics. Emulate it by copy-and-neuter semantics that sends | 443 // by move semantics. Emulate it by copy-and-neuter semantics that sends |
| 444 // array buffers and image bitmaps via structured clone and then neuters | 444 // array buffers and image bitmaps via structured clone and then neuters |
| 445 // the original objects | 445 // the original objects |
| 446 | 446 |
| 447 // Clear references to array buffers and image bitmaps from transferables | 447 // Clear references to array buffers and image bitmaps from transferables |
| 448 // so that the serializer can consider the array buffers as | 448 // so that the serializer can consider the array buffers as |
| 449 // non-transferable and serialize them into the message. | 449 // non-transferable and serialize them into the message. |
| 450 ArrayBufferArray transferableArrayBuffers = transferables.arrayBuffers; | 450 ArrayBufferArray transferableArrayBuffers = transferables.array_buffers; |
| 451 transferables.arrayBuffers.clear(); | 451 transferables.array_buffers.Clear(); |
| 452 ImageBitmapArray transferableImageBitmaps = transferables.imageBitmaps; | 452 ImageBitmapArray transferableImageBitmaps = transferables.image_bitmaps; |
| 453 transferables.imageBitmaps.clear(); | 453 transferables.image_bitmaps.Clear(); |
| 454 SerializedScriptValue::SerializeOptions options; | 454 SerializedScriptValue::SerializeOptions options; |
| 455 options.transferables = &transferables; | 455 options.transferables = &transferables; |
| 456 message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], optio
ns, exceptionState); | 456 message = SerializedScriptValue::Serialize(info.GetIsolate(), info[0], optio
ns, exceptionState); |
| 457 if (exceptionState.hadException()) | 457 if (exceptionState.HadException()) |
| 458 return; | 458 return; |
| 459 | 459 |
| 460 // Neuter the original array buffers on the sender context. | 460 // Neuter the original array buffers on the sender context. |
| 461 SerializedScriptValue::transferArrayBufferContents(info.GetIsolate(), transf
erableArrayBuffers, exceptionState); | 461 SerializedScriptValue::TransferArrayBufferContents(info.GetIsolate(), transf
erableArrayBuffers, exceptionState); |
| 462 if (exceptionState.hadException()) | 462 if (exceptionState.HadException()) |
| 463 return; | 463 return; |
| 464 // Neuter the original image bitmaps on the sender context. | 464 // Neuter the original image bitmaps on the sender context. |
| 465 SerializedScriptValue::transferImageBitmapContents(info.GetIsolate(), transf
erableImageBitmaps, exceptionState); | 465 SerializedScriptValue::TransferImageBitmapContents(info.GetIsolate(), transf
erableImageBitmaps, exceptionState); |
| 466 if (exceptionState.hadException()) | 466 if (exceptionState.HadException()) |
| 467 return; | 467 return; |
| 468 } | 468 } |
| 469 | 469 |
| 470 // FIXME: Only pass scriptState/exceptionState if instance really requires it. | 470 // FIXME: Only pass scriptState/exceptionState if instance really requires it. |
| 471 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); | 471 ScriptState* scriptState = ScriptState::Current(info.GetIsolate()); |
| 472 message->unregisterMemoryAllocatedWithCurrentScriptContext(); | 472 message->UnregisterMemoryAllocatedWithCurrentScriptContext(); |
| 473 instance->postMessage(scriptState, message.get(), transferables.messagePorts,
exceptionState); | 473 instance->postMessage(scriptState, message.Get(), transferables.message_ports,
exceptionState); |
| 474 } | 474 } |
| 475 {% endmacro %} | 475 {% endmacro %} |
| 476 | 476 |
| 477 | 477 |
| 478 {##############################################################################} | 478 {##############################################################################} |
| 479 {% macro method_callback(method, world_suffix) %} | 479 {% macro method_callback(method, world_suffix) %} |
| 480 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons
t v8::FunctionCallbackInfo<v8::Value>& info) { | 480 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons
t v8::FunctionCallbackInfo<v8::Value>& info) { |
| 481 {% if not method.overloads %}{# Overloaded methods are measured in overload_re
solution_method() #} | 481 {% if not method.overloads %}{# Overloaded methods are measured in overload_re
solution_method() #} |
| 482 {% if method.measure_as %} | 482 {% if method.measure_as %} |
| 483 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me
thod.measure_as('Method')}}); | 483 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{m
ethod.measure_as('Method')}}); |
| 484 {% endif %} | 484 {% endif %} |
| 485 {% if method.deprecate_as %} | 485 {% if method.deprecate_as %} |
| 486 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC
ounter::{{method.deprecate_as}}); | 486 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC
ounter::k{{method.deprecate_as}}); |
| 487 {% endif %} | 487 {% endif %} |
| 488 {% endif %}{# not method.overloads #} | 488 {% endif %}{# not method.overloads #} |
| 489 {% if world_suffix in method.activity_logging_world_list %} | 489 {% if world_suffix in method.activity_logging_world_list %} |
| 490 {% if method.is_static %} | 490 {% if method.is_static %} |
| 491 ScriptState* scriptState = ScriptState::forFunctionObject(info); | 491 ScriptState* scriptState = ScriptState::ForFunctionObject(info); |
| 492 {% else %} | 492 {% else %} |
| 493 ScriptState* scriptState = ScriptState::forReceiverObject(info); | 493 ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| 494 {% endif %} | 494 {% endif %} |
| 495 V8PerContextData* contextData = scriptState->perContextData(); | 495 V8PerContextData* contextData = scriptState->PerContextData(); |
| 496 if (contextData && contextData->activityLogger()) { | 496 if (contextData && contextData->ActivityLogger()) { |
| 497 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo
ntext, "{{interface_name}}", "{{method.name}}"); | 497 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kExecutionC
ontext, "{{interface_name}}", "{{method.name}}"); |
| 498 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v
8::Value>>>(info, 0, exceptionState); | 498 Vector<v8::Local<v8::Value>> loggerArgs = ToImplArguments<Vector<v8::Local<v
8::Value>>>(info, 0, exceptionState); |
| 499 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}}
", info.Length(), loggerArgs.data()); | 499 contextData->ActivityLogger()->LogMethod("{{interface_name}}.{{method.name}}
", info.Length(), loggerArgs.Data()); |
| 500 } | 500 } |
| 501 {% endif %} | 501 {% endif %} |
| 502 {% if method.is_ce_reactions %} | 502 {% if method.is_ce_reactions %} |
| 503 CEReactionsScope ceReactionsScope; | 503 CEReactionsScope ceReactionsScope; |
| 504 {% endif %} | 504 {% endif %} |
| 505 {% if method.is_custom %} | 505 {% if method.is_custom %} |
| 506 {{v8_class}}::{{method.name}}MethodCustom(info); | 506 {{v8_class}}::{{method.name}}MethodCustom(info); |
| 507 {% elif method.is_post_message %} | 507 {% elif method.is_post_message %} |
| 508 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8
_class}}::toImpl(info.Holder()), info); | 508 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8
_class}}::toImpl(info.Holder()), info); |
| 509 {% else %} | 509 {% else %} |
| 510 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info
); | 510 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info
); |
| 511 {% endif %} | 511 {% endif %} |
| 512 } | 512 } |
| 513 {% endmacro %} | 513 {% endmacro %} |
| 514 | 514 |
| 515 | 515 |
| 516 {##############################################################################} | 516 {##############################################################################} |
| 517 {% macro origin_safe_method_getter(method, world_suffix) %} | 517 {% macro origin_safe_method_getter(method, world_suffix) %} |
| 518 {# TODO(dcheng): Currently, bindings must create a function object for each | 518 {# TODO(dcheng): Currently, bindings must create a function object for each |
| 519 realm as a hack to support the incumbent realm. Clean this up when Blink | 519 realm as a hack to support the incumbent realm. Clean this up when Blink |
| 520 properly supports the incumbent realm. #} | 520 properly supports the incumbent realm. #} |
| 521 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop
ertyCallbackInfo<v8::Value>& info) { | 521 static void {{method.name}}OriginSafeMethodGetter{{world_suffix}}(const v8::Prop
ertyCallbackInfo<v8::Value>& info) { |
| 522 static int domTemplateKey; // This address is used for a key to look up the do
m template. | 522 static int domTemplateKey; // This address is used for a key to look up the do
m template. |
| 523 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); | 523 V8PerIsolateData* data = V8PerIsolateData::From(info.GetIsolate()); |
| 524 const DOMWrapperWorld& world = DOMWrapperWorld::world(info.GetIsolate()->GetCu
rrentContext()); | 524 const DOMWrapperWorld& world = DOMWrapperWorld::World(info.GetIsolate()->GetCu
rrentContext()); |
| 525 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->findInterfaceTemplat
e(world, &{{v8_class}}::wrapperTypeInfo); | 525 v8::Local<v8::FunctionTemplate> interfaceTemplate = data->FindInterfaceTemplat
e(world, &{{v8_class}}::wrapperTypeInfo); |
| 526 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int
erfaceTemplate); | 526 v8::Local<v8::Signature> signature = v8::Signature::New(info.GetIsolate(), int
erfaceTemplate); |
| 527 | 527 |
| 528 v8::Local<v8::FunctionTemplate> methodTemplate = data->findOrCreateOperationTe
mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal
lback{{world_suffix}}, v8Undefined(), signature, {{method.length}}); | 528 v8::Local<v8::FunctionTemplate> methodTemplate = data->FindOrCreateOperationTe
mplate(world, &domTemplateKey, {{v8_class_or_partial}}::{{method.name}}MethodCal
lback{{world_suffix}}, V8Undefined(), signature, {{method.length}}); |
| 529 // Return the function by default, unless the user script has overwritten it. | 529 // Return the function by default, unless the user script has overwritten it. |
| 530 v8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre
ntContext()).ToLocalChecked()); | 530 V8SetReturnValue(info, methodTemplate->GetFunction(info.GetIsolate()->GetCurre
ntContext()).ToLocalChecked()); |
| 531 | 531 |
| 532 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); | 532 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); |
| 533 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()),
impl, BindingSecurity::ErrorReportOption::DoNotReport)) { | 533 if (!BindingSecurity::ShouldAllowAccessTo(CurrentDOMWindow(info.GetIsolate()),
impl, BindingSecurity::ErrorReportOption::kDoNotReport)) { |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 | 536 |
| 537 {% raw %} | 537 {% raw %} |
| 538 // {{method.name}} must be same with |methodName| (=name) in | 538 // {{method.name}} must be same with |methodName| (=name) in |
| 539 // {{cpp_class}}OriginSafeMethodSetter defined in interface.cpp.tmpl. | 539 // {{cpp_class}}OriginSafeMethodSetter defined in interface.cpp.tmpl. |
| 540 {% endraw %} | 540 {% endraw %} |
| 541 V8PrivateProperty::Symbol propertySymbol = | 541 V8PrivateProperty::Symbol propertySymbol = |
| 542 V8PrivateProperty::getSymbol(info.GetIsolate(), "{{method.name}}"); | 542 V8PrivateProperty::GetSymbol(info.GetIsolate(), "{{method.name}}"); |
| 543 v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast(info.Holder()); | 543 v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast(info.Holder()); |
| 544 if (propertySymbol.hasValue(holder)) { | 544 if (propertySymbol.HasValue(holder)) { |
| 545 v8SetReturnValue(info, propertySymbol.getOrUndefined(holder)); | 545 V8SetReturnValue(info, propertySymbol.GetOrUndefined(holder)); |
| 546 } | 546 } |
| 547 } | 547 } |
| 548 {% endmacro %} | 548 {% endmacro %} |
| 549 | 549 |
| 550 {% macro origin_safe_method_getter_callback(method, world_suffix) %} | 550 {% macro origin_safe_method_getter_callback(method, world_suffix) %} |
| 551 void {{v8_class_or_partial}}::{{method.name}}OriginSafeMethodGetterCallback{{wor
ld_suffix}}(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info
) { | 551 void {{v8_class_or_partial}}::{{method.name}}OriginSafeMethodGetterCallback{{wor
ld_suffix}}(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info
) { |
| 552 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}}
(info); | 552 {{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter{{world_suffix}}
(info); |
| 553 } | 553 } |
| 554 {% endmacro %} | 554 {% endmacro %} |
| 555 | 555 |
| 556 | 556 |
| 557 {##############################################################################} | 557 {##############################################################################} |
| 558 {% macro generate_constructor(constructor) %} | 558 {% macro generate_constructor(constructor) %} |
| 559 {% set name = '%sConstructorCallback' % v8_class | 559 {% set name = '%sConstructorCallback' % v8_class |
| 560 if constructor.is_named_constructor else | 560 if constructor.is_named_constructor else |
| 561 'constructor%s' % (constructor.overload_index or '') %} | 561 'constructor%s' % (constructor.overload_index or '') %} |
| 562 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) { | 562 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 563 {% set function_call = func_call_with_prep_of_args(constructor) %} | 563 {% set function_call = func_call_with_prep_of_args(constructor) %} |
| 564 | 564 |
| 565 {% if constructor.is_named_constructor %} | 565 {% if constructor.is_named_constructor %} |
| 566 if (!info.IsConstructCall()) { | 566 if (!info.IsConstructCall()) { |
| 567 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::const
ructorNotCallableAsFunction("{{constructor.name}}")); | 567 V8ThrowException::ThrowTypeError(info.GetIsolate(), ExceptionMessages::Const
ructorNotCallableAsFunction("{{constructor.name}}")); |
| 568 return; | 568 return; |
| 569 } | 569 } |
| 570 | 570 |
| 571 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExisti
ngObject) { | 571 if (ConstructorMode::Current(info.GetIsolate()) == ConstructorMode::kWrapExist
ingObject) { |
| 572 v8SetReturnValue(info, info.Holder()); | 572 V8SetReturnValue(info, info.Holder()); |
| 573 return; | 573 return; |
| 574 } | 574 } |
| 575 {% endif %} | 575 {% endif %} |
| 576 | 576 |
| 577 {% if 'exceptionState' in function_call %} | 577 {% if 'exceptionState' in function_call %} |
| 578 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC
ontext, "{{interface_name}}"); | 578 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::kConstruction
Context, "{{interface_name}}"); |
| 579 {% endif %} | 579 {% endif %} |
| 580 {% if 'scriptState' in function_call %} | 580 {% if 'scriptState' in function_call %} |
| 581 ScriptState* scriptState = ScriptState::forReceiverObject(info); | 581 ScriptState* scriptState = ScriptState::ForReceiverObject(info); |
| 582 {% endif %} | 582 {% endif %} |
| 583 | 583 |
| 584 {{function_call | indent(2)}} | 584 {{function_call | indent(2)}} |
| 585 } | 585 } |
| 586 {% endmacro %} | 586 {% endmacro %} |
| 587 | 587 |
| 588 | 588 |
| 589 {##############################################################################} | 589 {##############################################################################} |
| 590 {% macro generate_constructor_wrapper(constructor) %} | 590 {% macro generate_constructor_wrapper(constructor) %} |
| 591 {% set constructor_class = v8_class + ('Constructor' | 591 {% set constructor_class = v8_class + ('Constructor' |
| 592 if constructor.is_named_constructor else | 592 if constructor.is_named_constructor else |
| 593 '') %} | 593 '') %} |
| 594 v8::Local<v8::Object> wrapper = info.Holder(); | 594 v8::Local<v8::Object> wrapper = info.Holder(); |
| 595 wrapper = impl->associateWithWrapper(info.GetIsolate(), &{{constructor_class}}::
wrapperTypeInfo, wrapper); | 595 wrapper = impl->AssociateWithWrapper(info.GetIsolate(), &{{constructor_class}}::
wrapperTypeInfo, wrapper); |
| 596 v8SetReturnValue(info, wrapper); | 596 V8SetReturnValue(info, wrapper); |
| 597 {% endmacro %} | 597 {% endmacro %} |
| 598 | 598 |
| 599 | 599 |
| 600 {##############################################################################} | 600 {##############################################################################} |
| 601 {% macro method_configuration(method) %} | 601 {% macro method_configuration(method) %} |
| 602 {% from 'utilities.cpp.tmpl' import property_location %} | 602 {% from 'utilities.cpp.tmpl' import property_location %} |
| 603 {% set method_callback = | 603 {% set method_callback = |
| 604 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} | 604 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} |
| 605 {% set method_callback_for_main_world = | 605 {% set method_callback_for_main_world = |
| 606 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) | 606 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) |
| 607 if method.is_per_world_bindings else 'nullptr' %} | 607 if method.is_per_world_bindings else 'nullptr' %} |
| 608 {% set property_attribute = | 608 {% set property_attribute = |
| 609 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att
ributes) | 609 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att
ributes) |
| 610 if method.property_attributes else 'v8::None' %} | 610 if method.property_attributes else 'v8::None' %} |
| 611 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' | 611 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder' |
| 612 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} | 612 if method.returns_promise else 'V8DOMConfiguration::kCheckHolder' %} |
| 613 {% set access_check = 'V8DOMConfiguration::CheckAccess' | 613 {% set access_check = 'V8DOMConfiguration::kCheckAccess' |
| 614 if method.is_check_security_for_receiver else 'V8DOMConfiguration::DoNotC
heckAccess' %} | 614 if method.is_check_security_for_receiver else 'V8DOMConfiguration::kDoNot
CheckAccess' %} |
| 615 {% if method.is_per_world_bindings %} | 615 {% if method.is_per_world_bindings %} |
| 616 {% set method_callback_for_main_world = | 616 {% set method_callback_for_main_world = |
| 617 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) %
} | 617 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) %
} |
| 618 {"{{method.name}}", {{method_callback_for_main_world}}, {{method.length}}, {{pro
perty_attribute}}, {{property_location(method)}}, {{holder_check}}, {{access_che
ck}}, V8DOMConfiguration::MainWorld}, | 618 {"{{method.name}}", {{method_callback_for_main_world}}, {{method.length}}, {{pro
perty_attribute}}, {{property_location(method)}}, {{holder_check}}, {{access_che
ck}}, V8DOMConfiguration::kMainWorld}, |
| 619 {"{{method.name}}", {{method_callback}}, {{method.length}}, {{property_attribute
}}, {{property_location(method)}}, {{holder_check}}, {{access_check}}, V8DOMConf
iguration::NonMainWorlds} | 619 {"{{method.name}}", {{method_callback}}, {{method.length}}, {{property_attribute
}}, {{property_location(method)}}, {{holder_check}}, {{access_check}}, V8DOMConf
iguration::kNonMainWorlds} |
| 620 {%- else %} | 620 {%- else %} |
| 621 {"{{method.name}}", {{method_callback}}, {{method.length}}, {{property_attribute
}}, {{property_location(method)}}, {{holder_check}}, {{access_check}}, V8DOMConf
iguration::AllWorlds} | 621 {"{{method.name}}", {{method_callback}}, {{method.length}}, {{property_attribute
}}, {{property_location(method)}}, {{holder_check}}, {{access_check}}, V8DOMConf
iguration::kAllWorlds} |
| 622 {%- endif %} | 622 {%- endif %} |
| 623 {%- endmacro %} | 623 {%- endmacro %} |
| 624 | 624 |
| 625 | 625 |
| 626 {######################################} | 626 {######################################} |
| 627 {% macro install_custom_signature(method, instance_template, prototype_template,
interface_template, signature) %} | 627 {% macro install_custom_signature(method, instance_template, prototype_template,
interface_template, signature) %} |
| 628 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
[] = { | 628 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
[] = { |
| 629 {{method_configuration(method) | indent(2)}} | 629 {{method_configuration(method) | indent(2)}} |
| 630 }; | 630 }; |
| 631 for (const auto& methodConfig : {{method.name}}MethodConfiguration) | 631 for (const auto& methodConfig : {{method.name}}MethodConfiguration) |
| 632 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{pro
totype_template}}, {{interface_template}}, {{signature}}, methodConfig); | 632 V8DOMConfiguration::InstallMethod(isolate, world, {{instance_template}}, {{pro
totype_template}}, {{interface_template}}, {{signature}}, methodConfig); |
| 633 {%- endmacro %} | 633 {%- endmacro %} |
| 634 | 634 |
| 635 | 635 |
| 636 {######################################} | 636 {######################################} |
| 637 {% macro install_conditionally_enabled_methods() %} | 637 {% macro install_conditionally_enabled_methods() %} |
| 638 {% if methods | conditionally_exposed(is_partial) %} | 638 {% if methods | conditionally_exposed(is_partial) %} |
| 639 {% for method in methods | conditionally_exposed(is_partial) %} | 639 {% for method in methods | conditionally_exposed(is_partial) %} |
| 640 {% filter secure_context(method.overloads.secure_context_test_all | 640 {% filter secure_context(method.overloads.secure_context_test_all |
| 641 if method.overloads else | 641 if method.overloads else |
| 642 method.secure_context_test) %} | 642 method.secure_context_test) %} |
| 643 {% filter exposed(method.overloads.exposed_test_all | 643 {% filter exposed(method.overloads.exposed_test_all |
| 644 if method.overloads else | 644 if method.overloads else |
| 645 method.exposed_test) %} | 645 method.exposed_test) %} |
| 646 {% filter runtime_enabled(method.overloads.runtime_enabled_all | 646 {% filter runtime_enabled(method.overloads.runtime_enabled_all |
| 647 if method.overloads else | 647 if method.overloads else |
| 648 method.runtime_enabled_feature_name) %} | 648 method.runtime_enabled_feature_name) %} |
| 649 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
[] = { | 649 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
[] = { |
| 650 {{method_configuration(method) | indent(2)}} | 650 {{method_configuration(method) | indent(2)}} |
| 651 }; | 651 }; |
| 652 for (const auto& methodConfig : {{method.name}}MethodConfiguration) | 652 for (const auto& methodConfig : {{method.name}}MethodConfiguration) |
| 653 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), pro
totypeObject, interfaceObject, signature, methodConfig); | 653 V8DOMConfiguration::InstallMethod(isolate, world, v8::Local<v8::Object>(), pro
totypeObject, interfaceObject, signature, methodConfig); |
| 654 {% endfilter %}{# runtime_enabled() #} | 654 {% endfilter %}{# runtime_enabled() #} |
| 655 {% endfilter %}{# exposed() #} | 655 {% endfilter %}{# exposed() #} |
| 656 {% endfilter %}{# secure_context() #} | 656 {% endfilter %}{# secure_context() #} |
| 657 {% endfor %} | 657 {% endfor %} |
| 658 {% endif %} | 658 {% endif %} |
| 659 {%- endmacro %} | 659 {%- endmacro %} |
| OLD | NEW |