OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 def overload_check_expression(method, argument_count): | 366 def overload_check_expression(method, argument_count): |
367 overload_checks = ['info.Length() == %s' % argument_count] | 367 overload_checks = ['info.Length() == %s' % argument_count] |
368 arguments = method['arguments'][:argument_count] | 368 arguments = method['arguments'][:argument_count] |
369 overload_checks.extend(overload_check_argument(index, argument) | 369 overload_checks.extend(overload_check_argument(index, argument) |
370 for index, argument in | 370 for index, argument in |
371 enumerate(arguments)) | 371 enumerate(arguments)) |
372 return ' && '.join('(%s)' % check for check in overload_checks if check) | 372 return ' && '.join('(%s)' % check for check in overload_checks if check) |
373 | 373 |
374 | 374 |
375 def overload_check_argument(index, argument): | 375 def overload_check_argument(index, argument): |
| 376 def null_or_optional_check(): |
| 377 # If undefined is passed for an optional argument, the argument should |
| 378 # be treated as missing; otherwise undefined is not allowed. |
| 379 if argument['is_nullable']: |
| 380 if argument['is_optional']: |
| 381 return 'isUndefinedOrNull(%s)' |
| 382 return '%s->IsNull()' |
| 383 if argument['is_optional']: |
| 384 return '%s->IsUndefined()' |
| 385 return None |
| 386 |
376 cpp_value = 'info[%s]' % index | 387 cpp_value = 'info[%s]' % index |
377 idl_type = argument['idl_type'] | 388 idl_type = argument['idl_type'] |
378 # FIXME: proper type checking, sharing code with attributes and methods | 389 # FIXME: proper type checking, sharing code with attributes and methods |
379 if idl_type == 'DOMString' and argument['is_strict_type_checking']: | 390 if idl_type == 'DOMString' and argument['is_strict_type_checking']: |
380 return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value, | 391 return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value, |
381 '%s->IsString()' % cpp_value, | 392 '%s->IsString()' % cpp_value, |
382 '%s->IsObject()' % cpp_value]) | 393 '%s->IsObject()' % cpp_value]) |
383 if v8_types.array_or_sequence_type(idl_type): | 394 if v8_types.array_or_sequence_type(idl_type): |
384 return '%s->IsArray()' % cpp_value | 395 return '%s->IsArray()' % cpp_value |
385 if v8_types.is_callback_interface(idl_type): | 396 if v8_types.is_callback_interface(idl_type): |
386 return ' || '.join(['%s->IsNull()' % cpp_value, | 397 return ' || '.join(['%s->IsNull()' % cpp_value, |
387 '%s->IsFunction()' % cpp_value]) | 398 '%s->IsFunction()' % cpp_value]) |
388 if v8_types.is_wrapper_type(idl_type): | 399 if v8_types.is_wrapper_type(idl_type): |
389 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type, cpp_value=cpp_value) | 400 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type, cpp_value=cpp_value) |
390 if argument['is_nullable']: | 401 if argument['is_nullable']: |
391 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 402 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) |
392 return type_check | 403 return type_check |
393 if is_interface_type(idl_type): | 404 if is_interface_type(idl_type): |
394 # Non-wrapper types are just objects: we don't distinguish type | 405 # Non-wrapper types are just objects: we don't distinguish type |
| 406 # We only allow undefined for non-wrapper types (notably Dictionary), |
| 407 # as we need it for optional Dictionary arguments, but we don't want to |
| 408 # change behavior of existing bindings for other types. |
395 type_check = '%s->IsObject()' % cpp_value | 409 type_check = '%s->IsObject()' % cpp_value |
396 if argument['is_nullable']: | 410 added_check_template = null_or_optional_check() |
397 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 411 if added_check_template: |
| 412 type_check = ' || '.join([added_check_template % cpp_value, |
| 413 type_check]) |
398 return type_check | 414 return type_check |
399 return None | 415 return None |
400 | 416 |
401 | 417 |
402 ################################################################################ | 418 ################################################################################ |
403 # Constructors | 419 # Constructors |
404 ################################################################################ | 420 ################################################################################ |
405 | 421 |
406 # [Constructor] | 422 # [Constructor] |
407 def generate_constructor(interface, constructor): | 423 def generate_constructor(interface, constructor): |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 deleter = next( | 684 deleter = next( |
669 method | 685 method |
670 for method in interface.operations | 686 for method in interface.operations |
671 if ('deleter' in method.specials and | 687 if ('deleter' in method.specials and |
672 len(method.arguments) == 1 and | 688 len(method.arguments) == 1 and |
673 method.arguments[0].idl_type == 'DOMString')) | 689 method.arguments[0].idl_type == 'DOMString')) |
674 except StopIteration: | 690 except StopIteration: |
675 return None | 691 return None |
676 | 692 |
677 return property_deleter(deleter) | 693 return property_deleter(deleter) |
OLD | NEW |