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

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

Issue 699713003: IDL: ArrayBuffer and ArrayBufferView support for union types (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',
(...skipping 12 matching lines...) Expand all
23 'header_forward_decls': sorted(header_forward_decls), 23 'header_forward_decls': sorted(header_forward_decls),
24 'header_includes': sorted(UNION_H_INCLUDES), 24 'header_includes': sorted(UNION_H_INCLUDES),
25 } 25 }
26 26
27 27
28 def container_context(union_type, interfaces_info): 28 def container_context(union_type, interfaces_info):
29 members = [] 29 members = []
30 30
31 # These variables refer to member contexts if the given union type has 31 # These variables refer to member contexts if the given union type has
32 # corresponding types. They are used for V8 -> impl conversion. 32 # corresponding types. They are used for V8 -> impl conversion.
33 array_buffer_type = None
34 array_buffer_view_type = None
33 boolean_type = None 35 boolean_type = None
34 dictionary_type = None 36 dictionary_type = None
35 interface_types = [] 37 interface_types = []
36 numeric_type = None 38 numeric_type = None
37 string_type = None 39 string_type = None
38 for member in union_type.member_types: 40 for member in union_type.member_types:
39 context = member_context(member, interfaces_info) 41 context = member_context(member, interfaces_info)
40 members.append(context) 42 members.append(context)
41 if member.is_interface_type: 43 if member.base_type == 'ArrayBuffer':
44 if array_buffer_type:
45 raise Exception('%s is ambiguous.' % union_type.name)
46 array_buffer_type = context
47 elif member.base_type == 'ArrayBufferView':
48 if array_buffer_view_type:
49 raise Exception('%s is ambiguous.' % union_type.name)
50 array_buffer_view_type = context
51 elif member.is_interface_type:
42 interface_types.append(context) 52 interface_types.append(context)
43 elif member.is_dictionary: 53 elif member.is_dictionary:
44 if dictionary_type: 54 if dictionary_type:
45 raise Exception('%s is ambiguous.' % union_type.name) 55 raise Exception('%s is ambiguous.' % union_type.name)
46 dictionary_type = context 56 dictionary_type = context
47 elif member.base_type == 'boolean': 57 elif member.base_type == 'boolean':
48 if boolean_type: 58 if boolean_type:
49 raise Exception('%s is ambiguous.' % union_type.name) 59 raise Exception('%s is ambiguous.' % union_type.name)
50 boolean_type = context 60 boolean_type = context
51 elif member.is_numeric_type: 61 elif member.is_numeric_type:
52 if numeric_type: 62 if numeric_type:
53 raise Exception('%s is ambiguous.' % union_type.name) 63 raise Exception('%s is ambiguous.' % union_type.name)
54 numeric_type = context 64 numeric_type = context
55 elif member.is_string_type: 65 elif member.is_string_type:
56 if string_type: 66 if string_type:
57 raise Exception('%s is ambiguous.' % union_type.name) 67 raise Exception('%s is ambiguous.' % union_type.name)
58 string_type = context 68 string_type = context
59 else: 69 else:
60 raise Exception('%s is not supported as an union member.' % member.n ame) 70 raise Exception('%s is not supported as an union member.' % member.n ame)
61 71
62 return { 72 return {
73 'array_buffer_type': array_buffer_type,
74 'array_buffer_view_type': array_buffer_view_type,
63 'boolean_type': boolean_type, 75 'boolean_type': boolean_type,
64 'cpp_class': union_type.name, 76 'cpp_class': union_type.name,
65 'dictionary_type': dictionary_type, 77 'dictionary_type': dictionary_type,
66 'interface_types': interface_types, 78 'interface_types': interface_types,
67 'members': members, 79 'members': members,
68 'needs_trace': any(member['is_traceable'] for member in members), 80 'needs_trace': any(member['is_traceable'] for member in members),
69 'numeric_type': numeric_type, 81 'numeric_type': numeric_type,
70 'string_type': string_type, 82 'string_type': string_type,
71 } 83 }
72 84
73 85
74 def member_context(member, interfaces_info): 86 def member_context(member, interfaces_info):
75 cpp_includes.update(member.includes_for_type) 87 cpp_includes.update(member.includes_for_type)
76 interface_info = interfaces_info.get(member.name, None) 88 interface_info = interfaces_info.get(member.name, None)
77 if interface_info: 89 if interface_info:
78 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) 90 cpp_includes.update(interface_info.get('dependencies_include_paths', []) )
79 header_forward_decls.add(member.name) 91 header_forward_decls.add(member.implemented_as)
80 return { 92 return {
81 'cpp_name': v8_utilities.uncapitalize(member.name), 93 'cpp_name': v8_utilities.uncapitalize(member.name),
82 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), 94 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
83 'cpp_local_type': member.cpp_type, 95 'cpp_local_type': member.cpp_type,
84 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( 96 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
85 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', 97 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
86 creation_context='creationContext'), 98 creation_context='creationContext'),
87 'is_traceable': (member.is_garbage_collected or 99 'is_traceable': (member.is_garbage_collected or
88 member.is_will_be_garbage_collected), 100 member.is_will_be_garbage_collected),
89 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), 101 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
90 'specific_type_enum': 'SpecificType' + member.name, 102 'specific_type_enum': 'SpecificType' + member.name,
91 'type_name': member.name, 103 'type_name': member.name,
92 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( 104 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
93 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True), 105 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True),
94 } 106 }
OLDNEW
« no previous file with comments | « Source/bindings/scripts/compute_interfaces_info_individual.py ('k') | Source/bindings/templates/union.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698