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

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

Issue 409373002: IDL: Binding code generation for 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
« no previous file with comments | « Source/bindings/scripts/utilities.py ('k') | Source/bindings/scripts/v8_types.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..c9fd904a9e40a735cd075a397bbefb316506c1ff
--- /dev/null
+++ b/Source/bindings/scripts/v8_dictionary.py
@@ -0,0 +1,89 @@
+# 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 copy
+import operator
+from v8_globals import includes
+import v8_types
+import v8_utilities
+
+
+DICTIONARY_H_INCLUDES = frozenset([
+ 'bindings/core/v8/V8Binding.h',
+ 'platform/heap/Handle.h',
+])
+
+DICTIONARY_CPP_INCLUDES = 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(dictionary):
+ includes.clear()
+ includes.update(DICTIONARY_CPP_INCLUDES)
+ return {
+ 'cpp_class': v8_utilities.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),
+ }
+
+
+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
+
+ def default_values():
+ if not member.default_value:
+ return None, None
+ 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(
+ 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()
+
+ 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',
+ creation_context='creationContext',
+ extended_attributes=member.extended_attributes),
+ '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),
+ }
+
+# FIXME: Implement context for impl class.
« no previous file with comments | « Source/bindings/scripts/utilities.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698