| OLD | NEW |
| 1 {##############################################################################} | 1 {##############################################################################} |
| 2 {# FIXME: We should return a rejected Promise if an error occurs in this |
| 3 function when ALL methods in this overload return Promise. In order to do so, |
| 4 we must ensure either ALL or NO methods in this overload return Promise #} |
| 5 {% macro overload_resolution_method(method) %} |
| 6 {% set overloads = method.overloads %} |
| 7 {% if method.is_static %} |
| 8 {% set offset = 0 %} |
| 9 {% else %} |
| 10 {% set offset = 1 %} |
| 11 {% endif %} |
| 12 static void {{static_method_name(overloads.name)}}Dispatcher(Dart_NativeArgument
s args) |
| 13 { |
| 14 Dart_Handle exception = 0; |
| 15 const int argOffset = {{offset}}; |
| 16 int argCount = Dart_GetNativeArgumentCount(args) - argOffset; |
| 17 |
| 18 {# First resolve by length #} |
| 19 {# 2. Initialize argcount to be min(maxarg, n). #} |
| 20 switch (std::min({{overloads.maxarg}}, argCount)) { |
| 21 {# 3. Remove from S all entries whose type list is not of length argcount. #
} |
| 22 {% for length, tests_methods in overloads.length_tests_methods %} |
| 23 {# 10. If i = d, then: #} |
| 24 case {{length}}: |
| 25 {# Then resolve by testing argument #} |
| 26 {% for test, method in tests_methods %} |
| 27 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and |
| 28 method.runtime_enabled_function) %} |
| 29 if ({{test}}) { |
| 30 {% if method.is_custom %} |
| 31 {{static_method_name(method.name)}}(args); |
| 32 {% else %} |
| 33 {{static_method_name(method.name, method.overload_index)}}(args); |
| 34 {% endif %} |
| 35 return; |
| 36 } |
| 37 {% endfilter %} |
| 38 {% endfor %} |
| 39 break; |
| 40 {% endfor %} |
| 41 default: |
| 42 {# Invalid arity, throw error #} |
| 43 {# Report full list of valid arities if gaps and above minimum #} |
| 44 {% if overloads.valid_arities %} |
| 45 if (argCount >= {{overloads.minarg}}) { |
| 46 const String message = "Wrong arity, expected one of {{overloads.val
id_arities}}"; |
| 47 exception = DartUtilities::coreArgumentErrorException(message); |
| 48 goto fail; |
| 49 } |
| 50 {% endif %} |
| 51 {# Otherwise just report "not enough arguments" #} |
| 52 { |
| 53 const String message = "Not enough arguments (at least {{overloads.m
inarg}} required)"; |
| 54 exception = DartUtilities::coreArgumentErrorException(message); |
| 55 goto fail; |
| 56 } |
| 57 return; |
| 58 } |
| 59 { |
| 60 const String message = "No function was found that matched the signature
provided."; |
| 61 exception = DartUtilities::coreArgumentErrorException(message); |
| 62 goto fail; |
| 63 } |
| 64 return; |
| 65 fail: |
| 66 Dart_ThrowException(exception); |
| 67 ASSERT_NOT_REACHED(); |
| 68 } |
| 69 {% endmacro %} |
| 70 |
| 71 |
| 72 {##############################################################################} |
| 2 {# arguments_count is normal method.number_of_arguments however for optional #} | 73 {# arguments_count is normal method.number_of_arguments however for optional #} |
| 3 {# arguments then number_of_required_arguments is passed (sans optional). #} | 74 {# arguments then number_of_required_arguments is passed (sans optional). #} |
| 4 {# overload in the index if overloaded. #} | 75 {# overload in the index if overloaded. #} |
| 5 {# interface is specified signals that it's a constructor being called the #} | 76 {# interface is specified signals that it's a constructor being called the #} |
| 6 {# delegation to the create is emitted. | 77 {# delegation to the create is emitted. |
| 7 {##############################################################################} | 78 {##############################################################################} |
| 8 {% macro generate_method(method, arguments_count, overload='', constructor=False
) %} | 79 {% macro generate_method(method, arguments_count) %} |
| 9 {% if overload == '' %} | 80 {% set overload_index = method.overload_index %} |
| 10 {% set overload_index = method.overload_index %} | |
| 11 {% else %} | |
| 12 {% set overload_index = overload %} | |
| 13 {% endif %} | |
| 14 static void {{static_method_name(method.name, overload_index)}}(Dart_NativeArgum
ents args) | 81 static void {{static_method_name(method.name, overload_index)}}(Dart_NativeArgum
ents args) |
| 15 { | 82 { |
| 16 {% if not method.is_static %} | 83 {% if not method.is_static %} |
| 17 {% if cpp_class == "EventTarget" %} | 84 {% if cpp_class == "EventTarget" %} |
| 18 {{cpp_class}}* receiver = DartDOMWrapper::receiverToEventTarget(args); | 85 {{cpp_class}}* receiver = DartDOMWrapper::receiverToEventTarget(args); |
| 19 {% else %} | 86 {% else %} |
| 20 {{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = DartDO
MWrapper::receiver< {{cpp_class}} >(args); | 87 {{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = DartDO
MWrapper::receiver< {{cpp_class}} >(args); |
| 21 {% endif %} | 88 {% endif %} |
| 22 {% endif %} | 89 {% endif %} |
| 23 {% if method.is_custom_element_callbacks %} | 90 {% if method.is_custom_element_callbacks %} |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 not argument.is_callback_interface %} | 189 not argument.is_callback_interface %} |
| 123 {# Optional arguments without a default value generate an early call with | 190 {# Optional arguments without a default value generate an early call with |
| 124 fewer arguments if they are omitted. #} | 191 fewer arguments if they are omitted. #} |
| 125 if (UNLIKELY(argCount <= {{argument.arg_index}})) { | 192 if (UNLIKELY(argCount <= {{argument.arg_index}})) { |
| 126 {{callback_return(method, argument.dart_set_return_value, argument.cpp_value
)}} | 193 {{callback_return(method, argument.dart_set_return_value, argument.cpp_value
)}} |
| 127 if (exception) | 194 if (exception) |
| 128 goto fail; | 195 goto fail; |
| 129 return; | 196 return; |
| 130 } | 197 } |
| 131 {% endif %} | 198 {% endif %} |
| 199 {% if argument.is_callback_interface %} |
| 200 {# Callback functions must be functions: |
| 201 http://www.w3.org/TR/WebIDL/#es-callback-function #} |
| 202 {% if argument.is_optional %} |
| 203 {{argument.local_cpp_type}} {{argument.name}}; |
| 204 if (argCount > {{argument.arg_index}}) { |
| 205 {{argument.name}} = Dart{{argument.idl_type}}::createWithNullCheck(args, {{a
rgument.arg_index}}, exception); |
| 206 } |
| 207 {% else %}{# argument.is_optional #} |
| 208 {{argument.local_cpp_type}} {{argument.name}} = Dart{{argument.idl_type}}::creat
eWithNullCheck(args, {{argument.arg_index}}, exception); |
| 209 {% endif %}{# argument.is_optional #} |
| 210 {% else %}{# argument.is_callback_interface #} |
| 132 {% if argument.is_optional and argument.default_value -%} | 211 {% if argument.is_optional and argument.default_value -%} |
| 133 {{argument.local_cpp_type}} {{argument.name}} = | 212 {{argument.local_cpp_type}} {{argument.name}} = |
| 134 (argCount <= {{argument.arg_index}}) ? ({{argument.default_value}}) : {{argu
ment.dart_value_to_local_cpp_value}}; | 213 (argCount <= {{argument.arg_index}}) ? ({{argument.default_value}}) : {{argu
ment.dart_value_to_local_cpp_value}}; |
| 135 {% elif argument.is_optional and argument.idl_type == 'Dictionary' %} | 214 {% elif argument.is_optional and argument.idl_type == 'Dictionary' %} |
| 136 {{argument.local_cpp_type}} {{argument.name}}; | 215 {{argument.local_cpp_type}} {{argument.name}}; |
| 137 if (UNLIKELY(argCount <= {{argument.arg_index}})) { | 216 if (UNLIKELY(argCount <= {{argument.arg_index}})) { |
| 138 {{argument.name}} = Dictionary(); | 217 {{argument.name}} = Dictionary(); |
| 139 } else { | 218 } else { |
| 140 {{argument.name}} = {{argument.dart_value_to_local_cpp_value}}; | 219 {{argument.name}} = {{argument.dart_value_to_local_cpp_value}}; |
| 141 } | 220 } |
| 142 {% elif argument.is_array_or_sequence_type %} | 221 {% elif argument.is_array_or_sequence_type %} |
| 143 {{argument.local_cpp_type}} {{argument.name}}; | 222 {{argument.local_cpp_type}} {{argument.name}}; |
| 144 {{argument.dart_value_to_local_cpp_value}}; | 223 {{argument.dart_value_to_local_cpp_value}}; |
| 145 {% else %} | 224 {% else %} |
| 146 {{argument.local_cpp_type}} {{argument.name}} = {{argument.dart_value_to_local_c
pp_value}}; | 225 {{argument.local_cpp_type}} {{argument.name}} = {{argument.dart_value_to_local_c
pp_value}}; |
| 147 {% endif %} | 226 {% endif %} |
| 227 {% endif %}{# argument.is_callback_interface #} |
| 148 if (exception) | 228 if (exception) |
| 149 goto fail; | 229 goto fail; |
| 150 {% endmacro %} | 230 {% endmacro %} |
| 151 | 231 |
| 152 | 232 |
| 153 {######################################} | 233 {######################################} |
| 154 {% macro generate_arguments(method) %} | 234 {% macro generate_arguments(method) %} |
| 155 {%- for argument in method.arguments -%} | 235 {%- for argument in method.arguments -%} |
| 156 {{generate_argument(method, argument)}} | 236 {{generate_argument(method, argument)}} |
| 157 {%- endfor -%} | 237 {%- endfor -%} |
| 158 {% endmacro %} | 238 {% endmacro %} |
| 159 | 239 |
| 160 {##############################################################################} | 240 {##############################################################################} |
| 161 {% macro static_method_name(name, overload_index) %} | 241 {% macro static_method_name(name, overload_index) %} |
| 162 {% set name = 'constructor' if not name else name -%} | 242 {% set name = 'constructor' if not name else name -%} |
| 163 {% if overload_index -%} | 243 {% if overload_index -%} |
| 164 {{name}}Callback_{{overload_index}} | 244 {{name}}Callback_{{overload_index}} |
| 165 {%- else -%} | 245 {%- else -%} |
| 166 {{name}}Callback | 246 {{name}}Callback |
| 167 {%- endif %} | 247 {%- endif %} |
| 168 {% endmacro -%} | 248 {% endmacro -%} |
| 169 | 249 |
| 170 | 250 |
| 171 {##############################################################################} | 251 {##############################################################################} |
| 172 {% macro generate_resolver_body(dart_class, class_name, method) %} | 252 {% macro generate_resolver_body(dart_class, class_name, method) %} |
| 173 {% for native_entry in method.native_entries %} | 253 {% for native_entry in method.native_entries %} |
| 174 {% set uses_script_args = method.is_call_with_script_arguments %} | 254 {% set uses_script_args = method.is_call_with_script_arguments %} |
| 255 {% if method.overload_index %} |
| 256 {% set method_name = static_method_name(method.name) + "Dispatcher" %} |
| 257 {% else %} |
| 258 {% set method_name = static_method_name(method.name) %} |
| 259 {% endif %} |
| 175 {% if method.is_custom %} | 260 {% if method.is_custom %} |
| 176 {% set method_name = static_method_name(method.name) %} | |
| 177 // FIXME: we are missing changes from dart.idl so we don't always know how many | 261 // FIXME: we are missing changes from dart.idl so we don't always know how many |
| 178 // args custom methods will take so we ignore that check which could hurt perf | 262 // args custom methods will take so we ignore that check which could hurt perf |
| 179 // and security but lets us get everything running quicker. | 263 // and security but lets us get everything running quicker. |
| 180 if (name == "{{native_entry.resolver_string}}") { | 264 if (name == "{{native_entry.resolver_string}}") { |
| 181 *autoSetupScope = {{method.auto_scope}}; | 265 *autoSetupScope = {{method.auto_scope}}; |
| 182 return {{dart_class}}Internal::{{method_name}}; | 266 return {{dart_class}}Internal::{{method_name}}; |
| 183 } | 267 } |
| 184 {% else %} | 268 {% else %} |
| 185 {% set method_name = static_method_name(method.name, method.overload_index) %} | |
| 186 {% set args_one_based = method.number_of_arguments %} | 269 {% set args_one_based = method.number_of_arguments %} |
| 187 {% set args_required_one_based = method.number_of_required_arguments %} | 270 {% set args_required_one_based = method.number_of_required_arguments %} |
| 188 {% if not method.is_static %} | 271 {% if not method.is_static %} |
| 189 {% set args_one_based = args_one_based + 1 %} | 272 {% set args_one_based = args_one_based + 1 %} |
| 190 {% set args_required_one_based = args_required_one_based + 1 %} | 273 {% set args_required_one_based = args_required_one_based + 1 %} |
| 191 {% endif %} | 274 {% endif %} |
| 192 | 275 |
| 193 {% if uses_script_args %} | 276 {% if uses_script_args %} |
| 194 {# FIXME(vsm): At least one script argument is expected. Generalize? #} | 277 {# FIXME(vsm): At least one script argument is expected. Generalize? #} |
| 195 {% set args_one_based = args_one_based + 1 %} | 278 {% set args_one_based = args_one_based + 1 %} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 {% endif %} | 292 {% endif %} |
| 210 {% endif %} | 293 {% endif %} |
| 211 {% endfor %} | 294 {% endfor %} |
| 212 {% endmacro %} | 295 {% endmacro %} |
| 213 | 296 |
| 214 | 297 |
| 215 {##############################################################################} | 298 {##############################################################################} |
| 216 {% macro generate_symbolizer_body(dart_class, class_name, method) %} | 299 {% macro generate_symbolizer_body(dart_class, class_name, method) %} |
| 217 {% for native_entry in method.native_entries %} | 300 {% for native_entry in method.native_entries %} |
| 218 {% set uses_script_args = method.is_call_with_script_arguments %} | 301 {% set uses_script_args = method.is_call_with_script_arguments %} |
| 219 {% if method.is_custom %} | 302 {% if method.overload_index %} |
| 220 {% set method_name = static_method_name(method.name) %} | 303 {% set method_name = static_method_name(method.name) + "Dispatcher" %} |
| 304 {% else %} |
| 305 {% set method_name = static_method_name(method.name) %} |
| 306 {% endif %} |
| 221 if (nf == {{dart_class}}Internal::{{method_name}}) { | 307 if (nf == {{dart_class}}Internal::{{method_name}}) { |
| 222 return reinterpret_cast<const uint8_t*>("{{native_entry.resolver_string}}"); | 308 return reinterpret_cast<const uint8_t*>("{{native_entry.resolver_string}}"); |
| 223 } | 309 } |
| 224 {% else %} | |
| 225 {% set method_name = static_method_name(method.name, method.overload_index) %} | |
| 226 if (nf == {{dart_class}}Internal::{{method_name}}) { | |
| 227 return reinterpret_cast<const uint8_t*>("{{native_entry.resolver_string}}"); | |
| 228 } | |
| 229 {% endif %} | |
| 230 {% endfor %} | 310 {% endfor %} |
| 231 {% endmacro %} | 311 {% endmacro %} |
| 232 | 312 |
| 233 | 313 |
| 234 {##############################################################################} | 314 {##############################################################################} |
| 235 {% macro generate_constructor(constructor, arguments_count, overload='') %} | 315 {% macro generate_constructor(constructor, arguments_count, overload='') %} |
| 236 {% if overload == '' %} | 316 {% if overload == '' %} |
| 237 {% set overload_index = constructor.overload_index %} | 317 {% set overload_index = constructor.overload_index %} |
| 238 {% else %} | 318 {% else %} |
| 239 {% set overload_index = overload %} | 319 {% set overload_index = overload %} |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 {% endif %} | 446 {% endif %} |
| 367 {{dart_class}}::returnToDart(args, event.get()); | 447 {{dart_class}}::returnToDart(args, event.get()); |
| 368 return; | 448 return; |
| 369 } | 449 } |
| 370 fail: | 450 fail: |
| 371 Dart_ThrowException(exception); | 451 Dart_ThrowException(exception); |
| 372 ASSERT_NOT_REACHED(); | 452 ASSERT_NOT_REACHED(); |
| 373 } | 453 } |
| 374 {% endmacro %} | 454 {% endmacro %} |
| 375 | 455 |
| 376 | 456 , |
| 377 {##############################################################################} | 457 {##############################################################################} |
| 378 {% macro generate_resolver_constructor(dart_class, class_name, constructor) %} | 458 {% macro generate_resolver_constructor(dart_class, class_name, constructor) %} |
| 379 {% for native_entry in constructor.native_entries %} | 459 {% for native_entry in constructor.native_entries %} |
| 380 {% set resolver_string = native_entry.resolver_string %} | 460 {% set resolver_string = native_entry.resolver_string %} |
| 461 {% if constructor.overload_index %} |
| 462 {% set constructor_name = static_method_name(constructor.name) + "Dispatcher"
%} |
| 463 {% else %} |
| 464 {% set constructor_name = static_method_name(constructor.name) %} |
| 465 {% endif %} |
| 381 {% if has_custom_constructor %} | 466 {% if has_custom_constructor %} |
| 382 if (name == "{{resolver_string}}") { | 467 if (name == "{{resolver_string}}") { |
| 383 {% elif constructor.number_of_arguments == constructor.number_of_required_argume
nts %} | 468 {% elif constructor.number_of_arguments == constructor.number_of_required_argume
nts %} |
| 384 if (argumentCount == {{constructor.number_of_arguments}} && name == "{{resolver_
string}}") { | 469 if (argumentCount == {{constructor.number_of_arguments}} && name == "{{resolver_
string}}") { |
| 385 {% else %} | 470 {% else %} |
| 386 if (argumentCount >= {{constructor.number_of_required_arguments}} && argumentCou
nt <= {{constructor.number_of_arguments}} && name == "{{resolver_string}}") { | 471 if (argumentCount >= {{constructor.number_of_required_arguments}} && argumentCou
nt <= {{constructor.number_of_arguments}} && name == "{{resolver_string}}") { |
| 387 {% endif %} | 472 {% endif %} |
| 388 *autoSetupScope = {{constructor.auto_scope}}; | 473 *autoSetupScope = {{constructor.auto_scope}}; |
| 389 return {{dart_class}}Internal::{{static_method_name(constructor.name, constr
uctor.overload_index)}}; | 474 return {{dart_class}}Internal::{{constructor_name}}; |
| 390 } | 475 } |
| 391 {% endfor %} | 476 {% endfor %} |
| 392 {% endmacro %} | 477 {% endmacro %} |
| 393 | 478 |
| 394 {##############################################################################} | 479 {##############################################################################} |
| 395 {% macro generate_resolver_event_constructor(dart_class, class_name) %} | 480 {% macro generate_resolver_event_constructor(dart_class, class_name) %} |
| 396 {% set resolver_string = interface_name + "_constructorCallback" %} | 481 {% set resolver_string = interface_name + "_constructorCallback" %} |
| 397 if (argumentCount == 2 && name == "{{resolver_string}}") { | 482 if (argumentCount == 2 && name == "{{resolver_string}}") { |
| 398 *autoSetupScope = 1; | 483 *autoSetupScope = 1; |
| 399 return {{dart_class}}Internal::eventConstructorCallback; | 484 return {{dart_class}}Internal::eventConstructorCallback; |
| 400 } | 485 } |
| 401 {% endmacro %} | 486 {% endmacro %} |
| 402 | 487 |
| 403 {##############################################################################} | 488 {##############################################################################} |
| 404 {% macro generate_symbolizer_constructor(dart_class, class_name, constructor) %} | 489 {% macro generate_symbolizer_constructor(dart_class, class_name, constructor) %} |
| 405 {% for native_entry in constructor.native_entries %} | 490 {% for native_entry in constructor.native_entries %} |
| 406 {% set resolver_string = native_entry.resolver_string %} | 491 {% set resolver_string = native_entry.resolver_string %} |
| 407 if (nf == {{dart_class}}Internal::{{static_method_name(constructor.name, constru
ctor.overload_index)}}) { | 492 if (nf == {{dart_class}}Internal::{{static_method_name(constructor.name, constru
ctor.overload_index)}}) { |
| 408 return reinterpret_cast<const uint8_t*>("{{resolver_string}}"); | 493 return reinterpret_cast<const uint8_t*>("{{resolver_string}}"); |
| 409 } | 494 } |
| 410 {% endfor %} | 495 {% endfor %} |
| 411 {% endmacro %} | 496 {% endmacro %} |
| OLD | NEW |