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

Unified Diff: Source/bindings/scripts/v8_dictionary.py

Issue 420763002: IDL: DOM impl class code generation for IDL dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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
Index: Source/bindings/scripts/v8_dictionary.py
diff --git a/Source/bindings/scripts/v8_dictionary.py b/Source/bindings/scripts/v8_dictionary.py
index c9fd904a9e40a735cd075a397bbefb316506c1ff..987c7d59c52265041e7f5c0efeb86afef3b7e5f3 100644
--- a/Source/bindings/scripts/v8_dictionary.py
+++ b/Source/bindings/scripts/v8_dictionary.py
@@ -86,4 +86,85 @@ def member_context(member):
'v8_type': v8_types.v8_type(idl_type.base_type),
}
-# FIXME: Implement context for impl class.
+
+# Context for implementation classes
+
+def dictionary_impl_context(dictionary, interfaces_info):
+ includes.clear()
+ header_includes = set(['platform/heap/Handle.h'])
+ return {
+ 'header_includes': header_includes,
+ 'cpp_class': v8_utilities.cpp_name(dictionary),
+ 'members': [member_impl_context(member, interfaces_info,
+ header_includes)
+ for member in dictionary.members],
+ }
+
+
+def member_impl_context(member, interfaces_info, header_includes):
+ idl_type = member.idl_type
+
+ def should_use_nullable_container():
haraken 2014/07/27 07:46:35 Can we use is_implicit_nullable/is_explicit_nullab
bashi 2014/07/29 03:52:50 It seems that we can't use is_implicit_nullable/is
+ return idl_type.native_array_element_type or idl_type.is_primitive_type
+
+ def collect_includes(idl_type):
haraken 2014/07/27 07:46:35 Can we move this method to v8_types.py? Similarly
bashi 2014/07/29 03:52:50 Done.
+ includes_for_type = set()
+ if should_use_nullable_container():
+ includes_for_type.add('bindings/core/v8/Nullable.h')
+
+ idl_type = idl_type.preprocessed_type
+ native_array_element_type = idl_type.native_array_element_type
+ if native_array_element_type:
+ includes_for_type.update(collect_includes(
+ native_array_element_type))
+ includes_for_type.add('wtf/Vector.h')
+
+ if idl_type.is_string_type:
+ includes_for_type.add('wtf/text/WTFString.h')
+ if idl_type.name in interfaces_info:
+ interface_info = interfaces_info[idl_type.name]
+ includes_for_type.add(interface_info['include_path'])
+ return includes_for_type
+
+ def argument_cpp_type():
+ argument_cpp_type = idl_type.cpp_type_args(used_as_argument=True)
+ if idl_type.native_array_element_type:
+ return 'const %s&' % argument_cpp_type
+ return argument_cpp_type
+
+ def getter_cpp_type():
+ getter_cpp_type = idl_type.cpp_type_args(used_as_return_type=True)
+ if (idl_type.native_array_element_type or idl_type.is_string_type):
+ return 'const %s&' % getter_cpp_type
+ return getter_cpp_type
+
+ def getter_method_expression():
+ if should_use_nullable_container():
+ return 'm_%s.get()' % member.name
+ return 'm_%s' % member.name
+
+ def has_method_expression():
+ if should_use_nullable_container() or idl_type.is_string_type:
+ return '!m_%s.isNull()' % member.name
haraken 2014/07/27 07:46:35 I think we should share this code with property_ge
bashi 2014/07/29 03:52:51 Hmm, the semantics of Nullable usage are different
haraken 2014/07/29 11:09:19 Thanks for the clarification, makes sense!
+ else:
+ return 'm_%s' % member.name
+
+ def member_cpp_type():
+ member_cpp_type = idl_type.cpp_type_args(used_as_member=True)
+ if should_use_nullable_container():
+ return v8_types.cpp_template_type('Nullable', member_cpp_type)
haraken 2014/07/27 07:46:35 Ditto. We can share this code with v8_method.py.
bashi 2014/07/29 03:52:51 I put these functions in this file because these a
+ return member_cpp_type
+
+ header_includes.update(collect_includes(idl_type))
+ return {
+ 'argument_cpp_type': argument_cpp_type(),
+ 'getter_cpp_type': getter_cpp_type(),
+ 'getter_method_expression': getter_method_expression(),
+ 'has_method_expression': has_method_expression(),
+ 'has_name': has_name_for_dictionary_member(member),
+ 'is_traceable': (idl_type.is_garbage_collected or
+ idl_type.is_will_be_garbage_collected),
+ 'member_cpp_type': member_cpp_type(),
+ 'name': member.name,
+ 'setter_name': setter_name_for_dictionary_member(member),
+ }

Powered by Google App Engine
This is Rietveld 408576698