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

Side by Side Diff: Source/bindings/dart/scripts/dart_types.py

Issue 469373002: Bindings generation emits (more) correct null checking (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Adding in fixes to binding generation Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 # FIXME(vsm): Why don't we have an entry for Window? V8 does. 392 # FIXME(vsm): Why don't we have an entry for Window? V8 does.
393 # I think I removed this as the Window object is more special in V8 - it's t he 393 # I think I removed this as the Window object is more special in V8 - it's t he
394 # global context as well. Do we need to special case it? 394 # global context as well. Do we need to special case it?
395 'XPathNSResolver': 'nullptr /* FIXME, DART_TO_CPP_VALUE[XPathNSResolver] */' , 395 'XPathNSResolver': 'nullptr /* FIXME, DART_TO_CPP_VALUE[XPathNSResolver] */' ,
396 # FIXME(vsm): This is an enum type (defined in StorageQuota.idl). 396 # FIXME(vsm): This is an enum type (defined in StorageQuota.idl).
397 # We should handle it automatically, but map to a String for now. 397 # We should handle it automatically, but map to a String for now.
398 'StorageType': 'DartUtilities::dartToString(args, {index}, exception, {auto_ scope})', 398 'StorageType': 'DartUtilities::dartToString(args, {index}, exception, {auto_ scope})',
399 } 399 }
400 400
401 401
402 def dart_value_to_cpp_value(idl_type, extended_attributes, variable_name, 402 def dart_value_to_cpp_value(idl_type, interface_extended_attributes, extended_at tributes, variable_name,
403 null_check, index, auto_scope=True): 403 null_check, index, auto_scope=True):
404 # Composite types 404 # Composite types
405 array_or_sequence_type = idl_type.array_or_sequence_type 405 array_or_sequence_type = idl_type.array_or_sequence_type
406 if array_or_sequence_type: 406 if array_or_sequence_type:
407 return dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_name, index) 407 return dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_name, index)
408 408
409 # Simple types 409 # Simple types
410 idl_type = idl_type.preprocessed_type 410 idl_type = idl_type.preprocessed_type
411 add_includes_for_type(idl_type) 411 add_includes_for_type(idl_type)
412 base_idl_type = idl_type.base_type 412 base_idl_type = idl_type.base_type
413 413
414 if 'EnforceRange' in extended_attributes: 414 if 'EnforceRange' in extended_attributes:
415 arguments = ', '.join([variable_name, 'EnforceRange', 'exceptionState']) 415 arguments = ', '.join([variable_name, 'EnforceRange', 'exceptionState'])
416 elif idl_type.is_integer_type: # NormalConversion 416 elif idl_type.is_integer_type: # NormalConversion
417 arguments = ', '.join([variable_name, 'es']) 417 arguments = ', '.join([variable_name, 'es'])
418 else: 418 else:
419 arguments = variable_name 419 arguments = variable_name
420 420
421 if base_idl_type in DART_TO_CPP_VALUE: 421 if base_idl_type in DART_TO_CPP_VALUE:
422 cpp_expression_format = DART_TO_CPP_VALUE[base_idl_type] 422 cpp_expression_format = DART_TO_CPP_VALUE[base_idl_type]
423 elif idl_type.is_typed_array_type: 423 elif idl_type.is_typed_array_type:
424 # FIXME(vsm): V8 generates a type check here as well. Do we need one? 424 # FIXME(vsm): V8 generates a type check here as well. Do we need one?
425 # FIXME(vsm): When do we call the externalized version? E.g., see 425 # FIXME(vsm): When do we call the externalized version? E.g., see
426 # bindings/dart/custom/DartWaveShaperNodeCustom.cpp - it calls 426 # bindings/dart/custom/DartWaveShaperNodeCustom.cpp - it calls
427 # DartUtilities::dartToExternalizedArrayBufferView instead. 427 # DartUtilities::dartToExternalizedArrayBufferView instead.
428 cpp_expression_format = ('DartUtilities::dartTo{idl_type}{null_check}(ar gs, {index}, exception)') 428 # V8 always converts null here
429 cpp_expression_format = ('DartUtilities::dartTo{idl_type}WithNullCheck(a rgs, {index}, exception)')
429 elif idl_type.is_callback_interface: 430 elif idl_type.is_callback_interface:
430 cpp_expression_format = ('Dart{idl_type}::create{null_check}(args, {inde x}, exception)') 431 cpp_expression_format = ('Dart{idl_type}::create{null_check}(args, {inde x}, exception)')
431 else: 432 else:
432 cpp_expression_format = ('Dart{idl_type}::toNative{null_check}(args, {in dex}, exception)') 433 cpp_expression_format = ('Dart{idl_type}::toNative{null_check}(args, {in dex}, exception)')
433 434
434 # We allow the calling context to force a null check to handle 435 # We allow the calling context to force a null check to handle
435 # some cases that require calling context info. V8 handles all 436 # some cases that require calling context info. V8 handles all
436 # of this differently, and we may wish to reconsider this approach 437 # of this differently, and we may wish to reconsider this approach
437 null_check = 'WithNullCheck' \ 438 null_check = 'WithNullCheck' \
438 if null_check or allow_null(idl_type, extended_attributes) else '' 439 if null_check or allow_null(idl_type, interface_extended_attributes, ext ended_attributes) else ''
439
440 return cpp_expression_format.format(null_check=null_check, 440 return cpp_expression_format.format(null_check=null_check,
441 arguments=arguments, 441 arguments=arguments,
442 index=index, 442 index=index,
443 idl_type=base_idl_type, 443 idl_type=base_idl_type,
444 auto_scope=DartUtilities.bool_to_cpp(aut o_scope)) 444 auto_scope=DartUtilities.bool_to_cpp(aut o_scope))
445 445
446 446
447 def dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_n ame, index): 447 def dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_n ame, index):
448 # Index is None for setters, index (starting at 0) for method arguments, 448 # Index is None for setters, index (starting at 0) for method arguments,
449 # and is used to provide a human-readable exception message 449 # and is used to provide a human-readable exception message
(...skipping 12 matching lines...) Expand all
462 else: 462 else:
463 ref_ptr_type = None 463 ref_ptr_type = None
464 this_cpp_type = array_or_sequence_type.cpp_type 464 this_cpp_type = array_or_sequence_type.cpp_type
465 expression_format = 'DartUtilities::toNativeVector<{cpp_type}>(args, {in dex}, {variable_name}, exception)' 465 expression_format = 'DartUtilities::toNativeVector<{cpp_type}>(args, {in dex}, {variable_name}, exception)'
466 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, 466 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name,
467 cpp_type=this_cpp_type, index=index, r ef_ptr_type=ref_ptr_type, 467 cpp_type=this_cpp_type, index=index, r ef_ptr_type=ref_ptr_type,
468 variable_name=variable_name) 468 variable_name=variable_name)
469 return expression 469 return expression
470 470
471 471
472 def dart_value_to_local_cpp_value(idl_type, extended_attributes, variable_name, 472 def dart_value_to_local_cpp_value(idl_type, interface_extended_attributes, exten ded_attributes,
473 null_check, index=None, auto_scope=True): 473 variable_name, null_check, index=None, auto_sc ope=True):
474 """Returns an expression that converts a Dart value to a C++ value as a loca l value.""" 474 """Returns an expression that converts a Dart value to a C++ value as a loca l value."""
475 idl_type = idl_type.preprocessed_type 475 idl_type = idl_type.preprocessed_type
476 476
477 cpp_value = dart_value_to_cpp_value( 477 cpp_value = dart_value_to_cpp_value(
478 idl_type, extended_attributes, variable_name, null_check, index, 478 idl_type, interface_extended_attributes, extended_attributes,
479 auto_scope) 479 variable_name, null_check, index, auto_scope)
480 480
481 return cpp_value 481 return cpp_value
482 482
483 IdlType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value 483 IdlType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value
484 IdlUnionType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value 484 IdlUnionType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value
485 485
486 486
487 # Insure that we don't use C++ reserved names. Today on default is a problem. 487 # Insure that we don't use C++ reserved names. Today on default is a problem.
488 def check_reserved_name(name): 488 def check_reserved_name(name):
489 return 'default_value' if (name == 'default') else name 489 return 'default_value' if (name == 'default') else name
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 if idl_type.is_array: 746 if idl_type.is_array:
747 return base_type_name + 'Array' 747 return base_type_name + 'Array'
748 if idl_type.is_sequence: 748 if idl_type.is_sequence:
749 return base_type_name + 'Sequence' 749 return base_type_name + 'Sequence'
750 return base_type_name 750 return base_type_name
751 751
752 IdlType.name = property(dart_name) 752 IdlType.name = property(dart_name)
753 IdlUnionType.name = property(dart_name) 753 IdlUnionType.name = property(dart_name)
754 754
755 755
756 def typechecked_interface(extended_attributes):
757 return ('TypeChecking' in extended_attributes and\
758 DartUtilities.extended_attribute_value_contains(extended_attributes[ 'TypeChecking'], 'Interface'))
759
760
761 def typechecked_argument(idl_type, interface_extended_attributes, extended_attri butes):
762 return (idl_type.is_wrapper_type and
763 (typechecked_interface(interface_extended_attributes) or
764 (typechecked_interface(extended_attributes))))
765
766
756 # If True use the WithNullCheck version when converting. 767 # If True use the WithNullCheck version when converting.
757 def allow_null(idl_type, extended_attributes): 768 def allow_null(idl_type, interface_extended_attributes, extended_attributes):
769 if idl_type.base_type in ('DOMString', 'ByteString', 'ScalarValueString'):
770 # This logic is in cpp_types in v8_types.py, since they handle
771 # this using the V8StringResource type. We handle it here
772 if (extended_attributes.get('TreatNullAs') == 'NullString' or
773 extended_attributes.get('TreatUndefinedAs') == 'NullString'):
774 return True
758 775
759 # This logic is implemented in the methods.cpp template in V8 776 if extended_attributes.get('Default') == 'NullString':
760 if idl_type.is_nullable: 777 return True
761 return True
762 778
763 if extended_attributes.get('Default') == 'NullString': 779 if extended_attributes.get('Default') == 'Undefined':
764 return True 780 return True
765 781
766 if extended_attributes.get('Default') == 'Undefined': 782 if idl_type.is_nullable:
767 return True 783 return True
768 784
769 # This logic is in cpp_types in v8_types.py, since they handle 785 return False
770 # this using the V8StringResource type. We handle it here 786 else:
771 if (extended_attributes.get('TreatNullAs') == 'NullString' or 787 # This logic is implemented in the methods.cpp template in V8
772 extended_attributes.get('TreatUndefinedAs') == 'NullString'): 788 if (idl_type.is_nullable or
773 return True 789 (not typechecked_argument(idl_type, interface_extended_attributes, ex tended_attributes))):
774 return False 790 return True
791
792 if extended_attributes.get('Default') == 'Undefined':
793 return True
794
795 return False
OLDNEW
« no previous file with comments | « Source/bindings/dart/scripts/dart_methods.py ('k') | Source/bindings/dart/scripts/templates/interface_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698