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

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: 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
new file mode 100644
index 0000000000000000000000000000000000000000..921984101e5fc4c0b117e3ff175577a668c9bdd9
--- /dev/null
+++ b/Source/bindings/scripts/v8_dictionary.py
@@ -0,0 +1,133 @@
+# 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.
+"""
+
+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
Nils Barth (inactive) 2014/07/18 21:52:34 Bug number? http://crbug.com/321462
bashi 2014/07/22 02:33:57 Done.
+ '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
Nils Barth (inactive) 2014/07/18 21:52:34 Caps: V8
bashi 2014/07/22 02:33:57 Done.
+
+
+def dictionary_context_v8(dictionary):
+ includes.clear()
+ includes.update(DICTIONARY_CPP_INCLUDES_V8)
+ header_includes = set(DICTIONARY_H_INCLUDES_V8)
Nils Barth (inactive) 2014/07/18 21:52:34 inline?
bashi 2014/07/22 02:33:57 Done.
+ sorted_members = sorted(dictionary.members,
Nils Barth (inactive) 2014/07/18 21:52:34 inline?
bashi 2014/07/22 02:33:57 Done.
+ key=lambda member: member.name)
Nils Barth (inactive) 2014/07/18 21:52:34 An alternative is: key=operator.attrgetter('name')
bashi 2014/07/22 02:33:57 Done.
+ return {
+ 'header_includes': header_includes,
Nils Barth (inactive) 2014/07/18 21:52:34 Alpha
bashi 2014/07/22 02:33:58 Done.
+ 'cpp_class': v8_utilities.cpp_name(dictionary),
+ 'members': [member_context_v8(member) for member in sorted_members],
+ 'v8_class': v8_utilities.v8_class_name(dictionary),
+ }
+
+
+def member_context_v8(member):
+ member.idl_type.add_includes_for_type()
Nils Barth (inactive) 2014/07/18 21:52:34 Move below idl_type = ...
bashi 2014/07/22 02:33:58 Done.
+ idl_type = member.idl_type
+ base_idl_type = idl_type.base_type
+ cpp_value = 'impl->%s()' % member.name
+ cpp_value_to_v8_value = idl_type.cpp_value_to_v8_value(
Nils Barth (inactive) 2014/07/18 21:52:34 Inline?
bashi 2014/07/22 02:33:57 Done.
+ cpp_value=cpp_value, isolate='isolate',
+ creation_context='creationContext',
+ extended_attributes=member.extended_attributes)
+ default_value = None
Nils Barth (inactive) 2014/07/18 21:52:34 How about just default_value = str(member.default_
bashi 2014/07/22 02:33:57 str(None) results in 'None' and |default_value| is
+ v8_default_value = None
+ if member.default_value:
+ 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 {
+ 'cpp_type': idl_type.cpp_type,
+ 'cpp_value_to_v8_value': cpp_value_to_v8_value,
+ '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(base_idl_type),
+ }
+
+
+# Context for implementation classes
+
+
+def dictionary_context_impl(dictionary, interfaces_info):
+ includes.clear()
+ header_includes = set(['platform/heap/Handle.h'])
+ members = [member_context_impl(member, interfaces_info,
Nils Barth (inactive) 2014/07/18 21:52:34 Inline this?
bashi 2014/07/22 02:33:57 Done.
+ header_includes)
+ for member in dictionary.members]
+ return {
+ 'header_includes': header_includes,
+ 'cpp_name': v8_utilities.cpp_name(dictionary),
+ 'members': members,
+ }
+
+
+# FIXME: We may want to put this in v8_types.py
+def impl_includes_for_type(idl_type, interfaces_info):
+ idl_type = idl_type.preprocessed_type
+
+ native_array_element_type = idl_type.native_array_element_type
+ if native_array_element_type:
+ includes_for_type = impl_includes_for_type(
+ native_array_element_type, interfaces_info)
+ includes_for_type.update(set(['wtf/Vector.h']))
+ return includes_for_type
+
+ if idl_type.is_string_type:
+ return set(['wtf/text/WTFString.h'])
+ if idl_type.name in interfaces_info:
+ interface_info = interfaces_info[idl_type.name]
+ return set([interface_info['include_path']])
+ return set()
+
+
+def member_context_impl(member, interfaces_info, header_includes):
+ idl_type = member.idl_type
+ includes_for_member = impl_includes_for_type(idl_type, interfaces_info)
+ header_includes.update(includes_for_member)
+ argument_cpp_type = idl_type.cpp_type_args(used_as_argument=True)
Nils Barth (inactive) 2014/07/18 21:52:34 You can inline these into the dictionary display;
bashi 2014/07/22 02:33:57 Done.
+ getter_cpp_type = idl_type.cpp_type_args(used_as_return_type=True)
+ member_cpp_type = idl_type.cpp_type_args(used_as_member=True)
+ is_traceable = (idl_type.is_garbage_collected or
+ idl_type.is_will_be_garbage_collected)
+ return {
+ 'argument_cpp_type': argument_cpp_type,
+ 'cpp_type': idl_type.cpp_type,
+ 'getter_cpp_type': getter_cpp_type,
+ 'has_name': has_name_for_dictionary_member(member),
+ 'is_traceable': is_traceable,
+ '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