Chromium Code Reviews| Index: Source/bindings/scripts/v8_types.py |
| diff --git a/Source/bindings/scripts/v8_types.py b/Source/bindings/scripts/v8_types.py |
| index 944db4a604f6a029d45528807efeb4a48f8c9696..7c62f9d55f29d04d49e9ede0ca909a9a75254179 100644 |
| --- a/Source/bindings/scripts/v8_types.py |
| +++ b/Source/bindings/scripts/v8_types.py |
| @@ -193,7 +193,15 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_ |
| if idl_type.is_dictionary: |
| return base_idl_type |
| if idl_type.is_union_type: |
| - return idl_type.name |
| + # Avoid "AOrNullOrB" for cpp type of (A? or B) because we generate |
| + # V8AOrBOrNull to handle nulle for (A? or B), as well as (A or B)? |
|
haraken
2014/11/07 18:06:31
to handle nulle for ... => for (A? or B), (A or B?
bashi
2014/11/08 07:10:34
Done.
|
| + def member_cpp_name(idl_type): |
| + if idl_type.is_nullable: |
| + return idl_type.inner_type.name |
| + return idl_type.name |
| + member_names = "Or".join([member_cpp_name(member) |
|
Jens Widell
2014/11/07 10:58:19
Drop the [] to make it a generator expression inst
bashi
2014/11/08 07:10:34
Done.
|
| + for member in idl_type.member_types]) |
| + return member_names |
| # Default, assume native type is a pointer with same type name as idl type |
| return base_idl_type + '*' |
| @@ -517,7 +525,7 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name |
| # Simple types |
| idl_type = idl_type.preprocessed_type |
| add_includes_for_type(idl_type) |
| - base_idl_type = idl_type.name if idl_type.is_union_type else idl_type.base_type |
| + base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else idl_type.base_type |
| if 'EnforceRange' in extended_attributes: |
| arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
| @@ -534,7 +542,9 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name |
| cpp_expression_format = ( |
| '{v8_value}->Is{idl_type}() ? ' |
| 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') |
| - elif idl_type.is_dictionary or idl_type.is_union_type: |
| + elif idl_type.use_output_parameter_for_result: |
| + if idl_type.includes_nullable_type: |
| + base_idl_type = idl_type.cpp_type + 'OrNull' |
| cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {variable_name}, exceptionState)' |
| elif needs_type_check: |
| cpp_expression_format = ( |
| @@ -860,9 +870,11 @@ def cpp_type_has_null_value(idl_type): |
| # - Enum types, as they are implemented as Strings. |
| # - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as |
| # a null pointer. |
| + # - Union types, as thier container classes can represent null value. |
| # - 'Object' type. We use ScriptValue for object type. |
| return (idl_type.is_string_type or idl_type.is_wrapper_type or |
| - idl_type.is_enum or idl_type.base_type == 'object') |
| + idl_type.is_enum or idl_type.is_union_type |
| + or idl_type.base_type == 'object') |
| IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value) |
| @@ -880,3 +892,27 @@ def is_explicit_nullable(idl_type): |
| IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
| IdlUnionType.is_implicit_nullable = False |
| IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
| + |
| + |
| +def number_of_nullable_member_types_union(idl_type): |
| + # http://heycam.github.io/webidl/#dfn-number-of-nullable-member-types |
| + count = 0 |
| + for member in idl_type.member_types: |
| + if member.is_nullable: |
| + count += 1 |
| + member = member.inner_type |
| + if member.is_union_type: |
| + count += number_of_nullable_member_types_union(member) |
| + return count |
| + |
| +IdlUnionType.number_of_nullable_member_types = property( |
| + number_of_nullable_member_types_union) |
| + |
| + |
| +def includes_nullable_type_union(idl_type): |
| + # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| + return idl_type.number_of_nullable_member_types == 1 |
| + |
| +IdlTypeBase.includes_nullable_type = False |
| +IdlNullableType.includes_nullable_type = True |
| +IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |