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

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 # For container classes we strip nullable wrappers. For example,
20 # both (A or B)? and (A? or B) will become AOrB. This should be OK
21 # because container classes can handle null and it seems that
22 # distinguishing (A or B)? and (A? or B) doesn't make sense.
23 container_cpp_types = set()
24 union_types_for_containers = set()
25 nullable_cpp_types = set()
26 for union_type in union_types:
27 cpp_type = union_type.cpp_type
28 if cpp_type not in container_cpp_types:
29 union_types_for_containers.add(union_type.as_union_type)
haraken 2014/11/07 18:06:31 I'm not sure what .as_union_type is for. Can we ju
Jens Widell 2014/11/07 18:15:46 Since container_context() uses union_type.name, it
bashi 2014/11/08 07:10:34 Yes, it only affects exception messages, but just
30 container_cpp_types.add(cpp_type)
31 if union_type.includes_nullable_type:
Jens Widell 2014/11/07 10:58:19 Should this also check union_type.is_nullable?
bashi 2014/11/08 07:10:34 IdlNullableType.includes_nullable_type is True so
32 nullable_cpp_types.add(cpp_type)
33
34 union_types_for_containers = sorted(union_types_for_containers,
35 key=lambda union_type: union_type.name)
Jens Widell 2014/11/07 10:58:19 It doesn't really matter (stable order in the gene
bashi 2014/11/08 07:10:34 Good catch! Then, we should use idl_type.cpp_type
36 nullable_cpp_types = sorted(nullable_cpp_types)
37
19 return { 38 return {
20 'containers': [container_context(union_type, interfaces_info) 39 'containers': [container_context(union_type, interfaces_info)
21 for union_type in union_types], 40 for union_type in union_types_for_containers],
22 'cpp_includes': sorted(cpp_includes), 41 'cpp_includes': sorted(cpp_includes),
23 'header_forward_decls': sorted(header_forward_decls), 42 'header_forward_decls': sorted(header_forward_decls),
24 'header_includes': sorted(UNION_H_INCLUDES), 43 'header_includes': sorted(UNION_H_INCLUDES),
44 'nullable_cpp_types': nullable_cpp_types,
25 } 45 }
26 46
27 47
28 def container_context(union_type, interfaces_info): 48 def container_context(union_type, interfaces_info):
29 members = [] 49 members = []
30 50
31 # These variables refer to member contexts if the given union type has 51 # These variables refer to member contexts if the given union type has
32 # corresponding types. They are used for V8 -> impl conversion. 52 # corresponding types. They are used for V8 -> impl conversion.
33 array_buffer_type = None 53 array_buffer_type = None
34 array_buffer_view_type = None 54 array_buffer_view_type = None
(...skipping 27 matching lines...) Expand all
62 if numeric_type: 82 if numeric_type:
63 raise Exception('%s is ambiguous.' % union_type.name) 83 raise Exception('%s is ambiguous.' % union_type.name)
64 numeric_type = context 84 numeric_type = context
65 elif member.is_string_type: 85 elif member.is_string_type:
66 if string_type: 86 if string_type:
67 raise Exception('%s is ambiguous.' % union_type.name) 87 raise Exception('%s is ambiguous.' % union_type.name)
68 string_type = context 88 string_type = context
69 else: 89 else:
70 raise Exception('%s is not supported as an union member.' % member.n ame) 90 raise Exception('%s is not supported as an union member.' % member.n ame)
71 91
92 # Nullable restriction checks
93 nullable_members = union_type.number_of_nullable_member_types
94 if nullable_members > 1:
95 raise Exception('%s contains more than one nullable members' % union_typ e.name)
96 if dictionary_type and nullable_members == 1:
97 raise Exception('%s has a dictionary and a nullable member' % union_type .name)
98
72 return { 99 return {
73 'array_buffer_type': array_buffer_type, 100 'array_buffer_type': array_buffer_type,
74 'array_buffer_view_type': array_buffer_view_type, 101 'array_buffer_view_type': array_buffer_view_type,
75 'boolean_type': boolean_type, 102 'boolean_type': boolean_type,
76 'cpp_class': union_type.name, 103 'cpp_class': union_type.cpp_type,
77 'dictionary_type': dictionary_type, 104 'dictionary_type': dictionary_type,
105 'includes_nullable_type': union_type.includes_nullable_type,
haraken 2014/11/07 18:06:31 includes_nullable_type => contains_nullable_type ?
bashi 2014/11/08 07:10:34 "includes a nullable type" is what the spec is usi
78 'interface_types': interface_types, 106 'interface_types': interface_types,
79 'members': members, 107 'members': members,
80 'needs_trace': any(member['is_traceable'] for member in members), 108 'needs_trace': any(member['is_traceable'] for member in members),
81 'numeric_type': numeric_type, 109 'numeric_type': numeric_type,
82 'string_type': string_type, 110 'string_type': string_type,
83 } 111 }
84 112
85 113
86 def member_context(member, interfaces_info): 114 def member_context(member, interfaces_info):
87 cpp_includes.update(member.includes_for_type) 115 cpp_includes.update(member.includes_for_type)
88 interface_info = interfaces_info.get(member.name, None) 116 interface_info = interfaces_info.get(member.name, None)
89 if interface_info: 117 if interface_info:
90 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) 118 cpp_includes.update(interface_info.get('dependencies_include_paths', []) )
91 header_forward_decls.add(member.implemented_as) 119 header_forward_decls.add(member.implemented_as)
120 if member.is_nullable:
121 member = member.inner_type
92 return { 122 return {
93 'cpp_name': v8_utilities.uncapitalize(member.name), 123 'cpp_name': v8_utilities.uncapitalize(member.name),
94 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), 124 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
95 'cpp_local_type': member.cpp_type, 125 'cpp_local_type': member.cpp_type,
96 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( 126 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
97 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', 127 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
98 creation_context='creationContext'), 128 creation_context='creationContext'),
99 'is_traceable': member.is_traceable, 129 'is_traceable': member.is_traceable,
100 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), 130 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
101 'specific_type_enum': 'SpecificType' + member.name, 131 'specific_type_enum': 'SpecificType' + member.name,
102 'type_name': member.name, 132 'type_name': member.name,
103 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( 133 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
104 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True), 134 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True),
105 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698