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

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

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: sequence and array support 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
« no previous file with comments | « Source/bindings/scripts/utilities.py ('k') | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/v8_dictionary.py
diff --git a/Source/bindings/scripts/v8_dictionary.py b/Source/bindings/scripts/v8_dictionary.py
new file mode 100644
index 0000000000000000000000000000000000000000..b398dba8232582dfc0796bc222991024357d39f0
--- /dev/null
+++ b/Source/bindings/scripts/v8_dictionary.py
@@ -0,0 +1,167 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Generate template contexts of dictionaries for both v8 bindings and
+implementation classes that are used by blink's core/modules.
+"""
+
+import operator
+from v8_globals import includes
+import v8_types
+import v8_utilities
+
+
+DICTIONARY_H_INCLUDES_V8 = frozenset([
+ 'bindings/core/v8/V8Binding.h',
+ 'platform/heap/Handle.h',
+])
+
+DICTIONARY_CPP_INCLUDES_V8 = frozenset([
+ # 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)
+
+
+def has_name_for_dictionary_member(member):
+ return 'has%s' % v8_utilities.capitalize(member.name)
+
+
+# Context for V8 bindings
+
+
+def dictionary_context_v8(dictionary):
+ includes.clear()
+ includes.update(DICTIONARY_CPP_INCLUDES_V8)
+ return {
+ 'cpp_class': v8_utilities.cpp_name(dictionary),
+ 'header_includes': set(DICTIONARY_H_INCLUDES_V8),
+ 'members': [member_context_v8(member)
+ for member in sorted(dictionary.members,
+ key=operator.attrgetter('name'))],
+ 'v8_class': v8_utilities.v8_class_name(dictionary),
+ }
+
+
+def member_context_v8(member):
+ idl_type = member.idl_type
+ idl_type.add_includes_for_type()
+
+ def default_values():
+ if not member.default_value:
+ return None, None
+ if member.default_value.is_null:
+ return None, 'v8::Null(isolate)'
+ default_value = str(member.default_value)
+ v8_default_value = idl_type.cpp_value_to_v8_value(
+ cpp_value=default_value, isolate='isolate',
+ creation_context='creationContext',
+ extended_attributes=member.extended_attributes)
+ return default_value, v8_default_value
+
+ default_value, v8_default_value = default_values()
+
+ return {
+ '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',
+ creation_context='creationContext',
+ extended_attributes=member.extended_attributes),
+ 'default_value': default_value,
+ 'has_name': has_name_for_dictionary_member(member),
+ 'name': member.name,
+ 'setter_name': setter_name_for_dictionary_member(member),
+ 'v8_default_value': v8_default_value,
+ 'v8_type': v8_types.v8_type(idl_type.base_type),
+ }
+
+
+# Context for implementation classes
+
+
+def dictionary_context_impl(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_context_impl(member, interfaces_info,
+ header_includes)
+ for member in dictionary.members],
+ }
+
+
+# FIXME: We may want to put this in v8_types.py
+def impl_includes_for_type(idl_type, interfaces_info):
+ includes_for_type = set()
+ if idl_type.is_primitive_type:
+ 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(impl_includes_for_type(
+ native_array_element_type, interfaces_info))
+ 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 member_context_impl(member, interfaces_info, header_includes):
+ idl_type = member.idl_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 idl_type.is_primitive_type:
+ return 'm_%s.get()' % member.name
+ return 'm_%s' % member.name
+
+ def has_method_expression():
+ if idl_type.is_sequence or idl_type.is_array:
+ return '!m_%s.isEmpty()' % member.name
+ elif idl_type.is_primitive_type or idl_type.is_string_type:
+ return '!m_%s.isNull()' % member.name
+ else:
+ return 'm_%s' % member.name
+
+ def member_cpp_type():
+ member_cpp_type = idl_type.cpp_type_args(used_as_member=True)
+ if idl_type.is_primitive_type:
+ return v8_types.cpp_template_type('Nullable', member_cpp_type)
+ return member_cpp_type
+
+ includes_for_member = impl_includes_for_type(idl_type, interfaces_info)
+ header_includes.update(includes_for_member)
+ 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),
+ }
« no previous file with comments | « Source/bindings/scripts/utilities.py ('k') | Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698