Chromium Code Reviews| Index: Source/bindings/scripts/v8_dictionary.py |
| diff --git a/Source/bindings/scripts/v8_dictionary.py b/Source/bindings/scripts/v8_dictionary.py |
| index cbe902b89658739b3d4a08a5c64fc86c1444442c..200356d7061ecfc080305dfa64562866fce2058d 100644 |
| --- a/Source/bindings/scripts/v8_dictionary.py |
| +++ b/Source/bindings/scripts/v8_dictionary.py |
| @@ -32,6 +32,12 @@ def has_method_name_for_dictionary_member(member): |
| return 'has%s' % v8_utilities.capitalize(member.name) |
| +def unwrap_nullable_if_needed(idl_type): |
| + if idl_type.is_nullable: |
| + return idl_type.inner_type |
| + return idl_type |
| + |
| + |
| # Context for V8 bindings |
| def dictionary_context(dictionary): |
| @@ -50,11 +56,7 @@ def dictionary_context(dictionary): |
| def member_context(member): |
| idl_type = member.idl_type |
| idl_type.add_includes_for_type() |
| - |
| - def idl_type_for_default_value(): |
| - if idl_type.is_nullable: |
| - return idl_type.inner_type |
| - return idl_type |
| + idl_type = unwrap_nullable_if_needed(idl_type) |
| def default_values(): |
| if not member.default_value: |
| @@ -62,7 +64,7 @@ def member_context(member): |
| if member.default_value.is_null: |
| return None, 'v8::Null(isolate)' |
| cpp_default_value = str(member.default_value) |
| - v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( |
| + v8_default_value = idl_type.cpp_value_to_v8_value( |
| cpp_value=cpp_default_value, isolate='isolate', |
| creation_context='creationContext') |
| return cpp_default_value, v8_default_value |
| @@ -78,6 +80,7 @@ def member_context(member): |
| extended_attributes=member.extended_attributes), |
| 'enum_validation_expression': idl_type.enum_validation_expression, |
| 'has_method_name': has_method_name_for_dictionary_member(member), |
| + 'is_object': idl_type.name == 'Object', |
| 'name': member.name, |
| 'setter_name': setter_name_for_dictionary_member(member), |
| 'v8_default_value': v8_default_value, |
| @@ -99,7 +102,8 @@ def dictionary_impl_context(dictionary, interfaces_info): |
| def member_impl_context(member, interfaces_info, header_includes): |
| - idl_type = member.idl_type |
| + idl_type = unwrap_nullable_if_needed(member.idl_type) |
| + is_object = idl_type.name == 'Object' |
| def getter_expression(): |
| if idl_type.impl_should_use_nullable_container: |
| @@ -109,6 +113,8 @@ def member_impl_context(member, interfaces_info, header_includes): |
| def has_method_expression(): |
| if idl_type.impl_should_use_nullable_container or idl_type.is_enum or idl_type.is_string_type: |
| return '!m_%s.isNull()' % member.name |
| + elif is_object: |
| + return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'.format(member.name) |
|
haraken
2014/09/24 04:08:56
Just help me understand: Why do we need to check a
bashi
2014/09/24 05:28:55
- Need to check isEmpty() before calling isNull()
|
| else: |
| return 'm_%s' % member.name |
| @@ -128,6 +134,7 @@ def member_impl_context(member, interfaces_info, header_includes): |
| 'getter_expression': getter_expression(), |
| 'has_method_expression': has_method_expression(), |
| 'has_method_name': has_method_name_for_dictionary_member(member), |
| + 'is_object': is_object, |
| 'is_traceable': (idl_type.is_garbage_collected or |
| idl_type.is_will_be_garbage_collected), |
| 'member_cpp_type': member_cpp_type(), |