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

Side by Side Diff: Source/bindings/scripts/v8_union.py

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import v8_utilities
5 6
6 def union_context(union_types): 7
8 UNION_H_INCLUDES = frozenset([
9 'bindings/core/v8/ExceptionState.h',
10 'bindings/core/v8/V8Binding.h',
11 'platform/heap/Handle.h',
12 ])
13
14 cpp_includes = set()
15 header_forward_decls = set()
16
17
18 def union_context(union_types, interfaces_info):
7 return { 19 return {
8 'containers': [container_context(union_type) 20 'containers': [container_context(union_type, interfaces_info)
9 for union_type in union_types], 21 for union_type in union_types],
22 'cpp_includes': sorted(cpp_includes),
23 'header_forward_decls': sorted(header_forward_decls),
24 'header_includes': sorted(UNION_H_INCLUDES),
10 } 25 }
11 26
12 27
13 def container_context(union_type): 28 def container_context(union_type, interfaces_info):
29 members = []
30
31 # These variables refer member contexts if the given union type has
32 # corresponding types. They are used for V8 -> impl conversion.
33 boolean_type = None
34 dictionary_type = None
35 interface_types = []
36 numeric_type = None
37 string_type = None
38 for member in union_type.member_types:
39 context = member_context(member, interfaces_info)
40 members.append(context)
41 if member.is_interface_type:
42 interface_types.append(context)
43 elif member.is_dictionary:
44 if dictionary_type:
45 raise Exception('%s is ambiguous.' % union_type.name)
46 dictionary_type = context
47 elif member.base_type == 'boolean':
48 if boolean_type:
49 raise Exception('%s is ambiguous.' % union_type.name)
50 boolean_type = context
51 elif member.is_numeric_type:
52 if numeric_type:
53 raise Exception('%s is ambiguous.' % union_type.name)
54 numeric_type = context
55 elif member.is_string_type:
56 if string_type:
57 raise Exception('%s is ambiguous.' % union_type.name)
58 string_type = context
59 else:
60 # FIXME: An exception should be thrown for unsupported types,
61 # but run-bindings-tests will fail when we throw an exception
62 # here. This FIXME should be removed shortly.
63 pass
64
14 return { 65 return {
66 'boolean_type': boolean_type,
15 'cpp_class': union_type.name, 67 'cpp_class': union_type.name,
68 'dictionary_type': dictionary_type,
69 'interface_types': interface_types,
70 'members': members,
71 'numeric_type': numeric_type,
72 'string_type': string_type,
16 } 73 }
74
75
76 def member_context(member, interfaces_info):
77 cpp_includes.update(member.includes_for_type)
78 interface_info = interfaces_info.get(member.name, None)
79 if interface_info:
80 cpp_includes.update(interface_info.get('dependencies_include_paths', []) )
81 header_forward_decls.add(member.name)
82 return {
83 'cpp_name': v8_utilities.uncapitalize(member.name),
84 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
85 'cpp_local_type': member.cpp_type,
86 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
87 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
88 creation_context='creationContext'),
89 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
90 'specific_type_enum': 'SpecificType' + member.name,
91 'type_name': member.name,
92 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
93 {}, 'v8Value', 'cppValue'),
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698