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

Unified Diff: bindings/dart/scripts/dart_dictionary.py

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bindings/dart/scripts/dart_compiler.py ('k') | bindings/dart/scripts/dart_interface.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bindings/dart/scripts/dart_dictionary.py
diff --git a/bindings/scripts/v8_dictionary.py b/bindings/dart/scripts/dart_dictionary.py
similarity index 66%
copy from bindings/scripts/v8_dictionary.py
copy to bindings/dart/scripts/dart_dictionary.py
index 6dc772fdcf99944f5204b50dc7bcc8302e07093a..42a21ba1725b0a15f10969b1d5c20094daee82b7 100644
--- a/bindings/scripts/v8_dictionary.py
+++ b/bindings/dart/scripts/dart_dictionary.py
@@ -6,11 +6,10 @@
implementation classes that are used by blink's core/modules.
"""
-import copy
import operator
from v8_globals import includes
-import v8_types
-import v8_utilities
+import dart_types
+from dart_utilities import DartUtilities
DICTIONARY_H_INCLUDES = frozenset([
@@ -19,45 +18,46 @@ DICTIONARY_H_INCLUDES = frozenset([
])
DICTIONARY_CPP_INCLUDES = frozenset([
+ 'bindings/common/ExceptionState.h',
# FIXME: Remove this, http://crbug.com/321462
'bindings/core/v8/Dictionary.h',
])
def setter_name_for_dictionary_member(member):
- return 'set%s' % v8_utilities.capitalize(member.name)
+ return 'set%s' % DartUtilities.capitalize(member.name)
def has_method_name_for_dictionary_member(member):
- return 'has%s' % v8_utilities.capitalize(member.name)
+ return 'has%s' % DartUtilities.capitalize(member.name)
-# Context for V8 bindings
+def unwrap_nullable_if_needed(idl_type):
+ if idl_type.is_nullable:
+ return idl_type.inner_type
+ return idl_type
+
+
+# Context for Dart bindings
def dictionary_context(dictionary):
includes.clear()
includes.update(DICTIONARY_CPP_INCLUDES)
return {
- 'cpp_class': v8_utilities.cpp_name(dictionary),
+ 'cpp_class': DartUtilities.cpp_name(dictionary),
'header_includes': set(DICTIONARY_H_INCLUDES),
'members': [member_context(member)
for member in sorted(dictionary.members,
key=operator.attrgetter('name'))],
- 'v8_class': v8_utilities.v8_class_name(dictionary),
+ 'dart_class': dart_types.dart_type(dictionary.name),
+
}
def member_context(member):
idl_type = member.idl_type
idl_type.add_includes_for_type()
-
- def idl_type_for_default_value():
- copied_type = copy.copy(idl_type)
- # IdlType for default values shouldn't be nullable. Otherwise,
- # it will generate meaningless expression like
- # 'String("default value").isNull() ? ...'.
- copied_type.is_nullable = False
- return copied_type
+ idl_type = unwrap_nullable_if_needed(idl_type)
def default_values():
if not member.default_value:
@@ -65,24 +65,30 @@ 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
- cpp_default_value, v8_default_value = default_values()
+ cpp_default_value, dart_default_value = default_values()
+
+ dart_enum_expression = idl_type.enum_validation_expression
+ if dart_enum_expression:
+ dart_enum_expression = dart_enum_expression.format(param_name='string')
return {
'cpp_default_value': cpp_default_value,
'cpp_type': idl_type.cpp_type,
- 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
- cpp_value='impl->%s()' % member.name, isolate='isolate',
+ 'cpp_value_to_dart_value': idl_type.cpp_value_to_dart_value(
+ cpp_value='impl->%s()' % member.name,
creation_context='creationContext',
extended_attributes=member.extended_attributes),
+ 'enum_validation_expression': dart_enum_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,
+ 'dart_default_value': dart_default_value,
}
@@ -93,7 +99,7 @@ def dictionary_impl_context(dictionary, interfaces_info):
header_includes = set(['platform/heap/Handle.h'])
return {
'header_includes': header_includes,
- 'cpp_class': v8_utilities.cpp_name(dictionary),
+ 'cpp_class': DartUtilities.cpp_name(dictionary),
'members': [member_impl_context(member, interfaces_info,
header_includes)
for member in dictionary.members],
@@ -101,7 +107,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,23 +116,30 @@ def member_impl_context(member, interfaces_info, header_includes):
return 'm_%s' % member.name
def has_method_expression():
- if (idl_type.impl_should_use_nullable_container or
- idl_type.is_string_type):
+ 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)
else:
return 'm_%s' % member.name
def member_cpp_type():
member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True)
if idl_type.impl_should_use_nullable_container:
- return v8_types.cpp_template_type('Nullable', member_cpp_type)
+ return dart_types.cpp_template_type('Nullable', member_cpp_type)
return member_cpp_type
+ cpp_default_value = None
+ if member.default_value and not member.default_value.is_null:
+ cpp_default_value = str(member.default_value)
+
header_includes.update(idl_type.impl_includes_for_type(interfaces_info))
return {
+ 'cpp_default_value': cpp_default_value,
'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(),
« no previous file with comments | « bindings/dart/scripts/dart_compiler.py ('k') | bindings/dart/scripts/dart_interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698