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

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

Issue 698423002: IDL union: nullable support (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 import v8_utilities
6 6
7 7
8 UNION_H_INCLUDES = frozenset([ 8 UNION_H_INCLUDES = frozenset([
9 'bindings/core/v8/ExceptionState.h', 9 'bindings/core/v8/ExceptionState.h',
10 'bindings/core/v8/V8Binding.h', 10 'bindings/core/v8/V8Binding.h',
11 'platform/heap/Handle.h', 11 'platform/heap/Handle.h',
12 ]) 12 ])
13 13
14 cpp_includes = set() 14 cpp_includes = set()
15 header_forward_decls = set() 15 header_forward_decls = set()
16 16
17 17
18 def union_context(union_types, interfaces_info): 18 def union_context(union_types, interfaces_info):
19 preprocessed_union_types = set()
20 nullable_union_types = set()
21 for union_type in union_types:
22 # Unwrap nullable if needed to avoid "OrNull" containers.
23 preprocessed_type = union_type.as_union_type
24 preprocessed_union_types.add(preprocessed_type)
25 if union_type.includes_nullable_type:
26 nullable_union_types.add(preprocessed_type)
27
28 preprocessed_union_types = sorted(preprocessed_union_types,
29 key=lambda union_type: union_type.name)
30 nullable_union_types = sorted(nullable_union_types,
31 key=lambda union_type: union_type.name)
19 return { 32 return {
20 'containers': [container_context(union_type, interfaces_info) 33 'containers': [container_context(union_type, interfaces_info)
21 for union_type in union_types], 34 for union_type in preprocessed_union_types],
22 'cpp_includes': sorted(cpp_includes), 35 'cpp_includes': sorted(cpp_includes),
23 'header_forward_decls': sorted(header_forward_decls), 36 'header_forward_decls': sorted(header_forward_decls),
24 'header_includes': sorted(UNION_H_INCLUDES), 37 'header_includes': sorted(UNION_H_INCLUDES),
38 'nullable_containers': [nullable_container_context(union_type)
39 for union_type in nullable_union_types],
25 } 40 }
26 41
27 42
28 def container_context(union_type, interfaces_info): 43 def container_context(union_type, interfaces_info):
29 members = [] 44 members = []
30 45
31 # These variables refer to member contexts if the given union type has 46 # These variables refer to member contexts if the given union type has
32 # corresponding types. They are used for V8 -> impl conversion. 47 # corresponding types. They are used for V8 -> impl conversion.
33 array_buffer_type = None 48 array_buffer_type = None
34 array_buffer_view_type = None 49 array_buffer_view_type = None
(...skipping 27 matching lines...) Expand all
62 if numeric_type: 77 if numeric_type:
63 raise Exception('%s is ambiguous.' % union_type.name) 78 raise Exception('%s is ambiguous.' % union_type.name)
64 numeric_type = context 79 numeric_type = context
65 elif member.is_string_type: 80 elif member.is_string_type:
66 if string_type: 81 if string_type:
67 raise Exception('%s is ambiguous.' % union_type.name) 82 raise Exception('%s is ambiguous.' % union_type.name)
68 string_type = context 83 string_type = context
69 else: 84 else:
70 raise Exception('%s is not supported as an union member.' % member.n ame) 85 raise Exception('%s is not supported as an union member.' % member.n ame)
71 86
87 # Nullable restriction checks
88 nullable_members = union_type.number_of_nullable_member_types
89 if nullable_members > 1:
90 raise Exception('%s contains more than one nullable members' % union_typ e.name)
91 if dictionary_type and nullable_members == 1:
92 raise Exception('%s has a dictionary and a nullable member' % union_type .name)
93
72 return { 94 return {
73 'array_buffer_type': array_buffer_type, 95 'array_buffer_type': array_buffer_type,
74 'array_buffer_view_type': array_buffer_view_type, 96 'array_buffer_view_type': array_buffer_view_type,
75 'boolean_type': boolean_type, 97 'boolean_type': boolean_type,
76 'cpp_class': union_type.name, 98 'cpp_class': union_type.cpp_type,
77 'dictionary_type': dictionary_type, 99 'dictionary_type': dictionary_type,
100 'includes_nullable_type': union_type.includes_nullable_type,
78 'interface_types': interface_types, 101 'interface_types': interface_types,
79 'members': members, 102 'members': members,
80 'needs_trace': any(member['is_traceable'] for member in members), 103 'needs_trace': any(member['is_traceable'] for member in members),
81 'numeric_type': numeric_type, 104 'numeric_type': numeric_type,
82 'string_type': string_type, 105 'string_type': string_type,
83 } 106 }
84 107
85 108
86 def member_context(member, interfaces_info): 109 def member_context(member, interfaces_info):
87 cpp_includes.update(member.includes_for_type) 110 cpp_includes.update(member.includes_for_type)
88 interface_info = interfaces_info.get(member.name, None) 111 interface_info = interfaces_info.get(member.name, None)
89 if interface_info: 112 if interface_info:
90 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) 113 cpp_includes.update(interface_info.get('dependencies_include_paths', []) )
91 header_forward_decls.add(member.implemented_as) 114 header_forward_decls.add(member.implemented_as)
92 return { 115 return {
93 'cpp_name': v8_utilities.uncapitalize(member.name), 116 'cpp_name': v8_utilities.uncapitalize(member.name),
94 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), 117 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
95 'cpp_local_type': member.cpp_type, 118 'cpp_local_type': member.cpp_type,
96 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( 119 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
97 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', 120 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
98 creation_context='creationContext'), 121 creation_context='creationContext'),
99 'is_traceable': member.is_traceable, 122 'is_traceable': member.is_traceable,
100 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), 123 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
101 'specific_type_enum': 'SpecificType' + member.name, 124 'specific_type_enum': 'SpecificType' + member.name,
102 'type_name': member.name, 125 'type_name': member.name,
103 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( 126 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
104 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True), 127 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True),
105 } 128 }
129
130
131 def nullable_container_context(union_type):
132 return {
133 'cpp_class': union_type.cpp_type,
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698