OLD | NEW |
---|---|
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 # V8-specific handling of IDL types | 48 # V8-specific handling of IDL types |
49 ################################################################################ | 49 ################################################################################ |
50 | 50 |
51 NON_WRAPPER_TYPES = frozenset([ | 51 NON_WRAPPER_TYPES = frozenset([ |
52 'Dictionary', | 52 'Dictionary', |
53 'EventHandler', | 53 'EventHandler', |
54 'EventListener', | 54 'EventListener', |
55 'NodeFilter', | 55 'NodeFilter', |
56 'SerializedScriptValue', | 56 'SerializedScriptValue', |
57 ]) | 57 ]) |
58 TYPED_ARRAYS = { | 58 TYPED_ARRAY_TYPES = frozenset([ |
59 # (cpp_type, v8_type), used by constructor templates | 59 'Float32Array', |
60 'ArrayBuffer': None, | 60 'Float64Array', |
61 'ArrayBufferView': None, | 61 'Int8Array', |
62 'Float32Array': ('float', 'v8::kExternalFloatArray'), | 62 'Int16Array', |
63 'Float64Array': ('double', 'v8::kExternalDoubleArray'), | 63 'Int32Array', |
64 'Int8Array': ('signed char', 'v8::kExternalByteArray'), | 64 'Uint8Array', |
65 'Int16Array': ('short', 'v8::kExternalShortArray'), | 65 'Uint8ClampedArray', |
66 'Int32Array': ('int', 'v8::kExternalIntArray'), | 66 'Uint16Array', |
67 'Uint8Array': ('unsigned char', 'v8::kExternalUnsignedByteArray'), | 67 'Uint32Array', |
68 'Uint8ClampedArray': ('unsigned char', 'v8::kExternalPixelArray'), | 68 ]) |
69 'Uint16Array': ('unsigned short', 'v8::kExternalUnsignedShortArray'), | 69 ARRAY_TYPES = TYPED_ARRAY_TYPES.union(frozenset([ |
haraken
2014/10/14 15:11:18
ARRAY_TYPE => ARRAY_BUFFER_TYPE
ARRAY is confusin
Yuki
2014/10/15 09:35:23
Changed to ARRAY_BUFFER_AND_VIEW_TYPES.
| |
70 'Uint32Array': ('unsigned int', 'v8::kExternalUnsignedIntArray'), | 70 'ArrayBuffer', |
71 } | 71 'ArrayBufferView', |
72 'DataView', | |
73 ])) | |
74 | |
75 IdlType.is_array_element_type = property( | |
haraken
2014/10/14 15:11:18
is_array_element_type => is_array_buffer ?
Yuki
2014/10/15 09:35:23
Changed to is_array_buffer_or_view.
| |
76 lambda self: self.base_type in ARRAY_TYPES) | |
72 | 77 |
73 IdlType.is_typed_array_element_type = property( | 78 IdlType.is_typed_array_element_type = property( |
haraken
2014/10/14 15:11:18
is_typed_array_element_type => is_typed_array ?
Yuki
2014/10/15 09:35:23
Done.
| |
74 lambda self: self.base_type in TYPED_ARRAYS) | 79 lambda self: self.base_type in TYPED_ARRAY_TYPES) |
75 | 80 |
76 IdlType.is_wrapper_type = property( | 81 IdlType.is_wrapper_type = property( |
77 lambda self: (self.is_interface_type and | 82 lambda self: (self.is_interface_type and |
78 self.base_type not in NON_WRAPPER_TYPES)) | 83 self.base_type not in NON_WRAPPER_TYPES)) |
79 | 84 |
80 | 85 |
81 ################################################################################ | 86 ################################################################################ |
82 # C++ types | 87 # C++ types |
83 ################################################################################ | 88 ################################################################################ |
84 | 89 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 174 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
170 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 175 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
171 | 176 |
172 if base_idl_type in NON_WRAPPER_TYPES: | 177 if base_idl_type in NON_WRAPPER_TYPES: |
173 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type | 178 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type |
174 if idl_type.is_string_type: | 179 if idl_type.is_string_type: |
175 if not raw_type: | 180 if not raw_type: |
176 return 'String' | 181 return 'String' |
177 return 'V8StringResource<%s>' % string_mode() | 182 return 'V8StringResource<%s>' % string_mode() |
178 | 183 |
179 if idl_type.is_typed_array_element_type and raw_type: | 184 if idl_type.is_array_element_type and raw_type: |
180 return base_idl_type + '*' | 185 return idl_type.implemented_as + '*' |
181 if idl_type.is_interface_type: | 186 if idl_type.is_interface_type: |
182 implemented_as_class = idl_type.implemented_as | 187 implemented_as_class = idl_type.implemented_as |
183 if raw_type: | 188 if raw_type: |
184 return implemented_as_class + '*' | 189 return implemented_as_class + '*' |
185 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 190 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
186 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) | 191 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) |
187 return cpp_template_type(ptr_type, implemented_as_class) | 192 return cpp_template_type(ptr_type, implemented_as_class) |
188 # Default, assume native type is a pointer with same type name as idl type | 193 # Default, assume native type is a pointer with same type name as idl type |
189 return base_idl_type + '*' | 194 return base_idl_type + '*' |
190 | 195 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 | 357 |
353 def includes_for_type(idl_type): | 358 def includes_for_type(idl_type): |
354 idl_type = idl_type.preprocessed_type | 359 idl_type = idl_type.preprocessed_type |
355 | 360 |
356 # Simple types | 361 # Simple types |
357 base_idl_type = idl_type.base_type | 362 base_idl_type = idl_type.base_type |
358 if base_idl_type in INCLUDES_FOR_TYPE: | 363 if base_idl_type in INCLUDES_FOR_TYPE: |
359 return INCLUDES_FOR_TYPE[base_idl_type] | 364 return INCLUDES_FOR_TYPE[base_idl_type] |
360 if idl_type.is_basic_type: | 365 if idl_type.is_basic_type: |
361 return set() | 366 return set() |
362 if idl_type.is_typed_array_element_type: | |
363 return set(['bindings/core/v8/custom/V8%sCustom.h' % base_idl_type]) | |
364 if base_idl_type.endswith('ConstructorConstructor'): | 367 if base_idl_type.endswith('ConstructorConstructor'): |
365 # FIXME: rename to NamedConstructor | 368 # FIXME: rename to NamedConstructor |
366 # FIXME: replace with a [NamedConstructorAttribute] extended attribute | 369 # FIXME: replace with a [NamedConstructorAttribute] extended attribute |
367 # Ending with 'ConstructorConstructor' indicates a named constructor, | 370 # Ending with 'ConstructorConstructor' indicates a named constructor, |
368 # and these do not have header files, as they are part of the generated | 371 # and these do not have header files, as they are part of the generated |
369 # bindings for the interface | 372 # bindings for the interface |
370 return set() | 373 return set() |
371 if base_idl_type.endswith('Constructor'): | 374 if base_idl_type.endswith('Constructor'): |
372 # FIXME: replace with a [ConstructorAttribute] extended attribute | 375 # FIXME: replace with a [ConstructorAttribute] extended attribute |
373 base_idl_type = idl_type.constructor_type_name | 376 base_idl_type = idl_type.constructor_type_name |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 522 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
520 elif 'Clamp' in extended_attributes: | 523 elif 'Clamp' in extended_attributes: |
521 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) | 524 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) |
522 elif idl_type.v8_conversion_needs_exception_state: | 525 elif idl_type.v8_conversion_needs_exception_state: |
523 arguments = ', '.join([v8_value, 'exceptionState']) | 526 arguments = ', '.join([v8_value, 'exceptionState']) |
524 else: | 527 else: |
525 arguments = v8_value | 528 arguments = v8_value |
526 | 529 |
527 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 530 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
528 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 531 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
529 elif idl_type.is_typed_array_element_type: | 532 elif idl_type.is_array_element_type: |
530 cpp_expression_format = ( | 533 cpp_expression_format = ( |
531 '{v8_value}->Is{idl_type}() ? ' | 534 '{v8_value}->Is{idl_type}() ? ' |
532 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') | 535 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') |
533 elif idl_type.is_dictionary: | 536 elif idl_type.is_dictionary: |
534 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, exc eptionState)' | 537 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, exc eptionState)' |
535 else: | 538 else: |
536 cpp_expression_format = ( | 539 cpp_expression_format = ( |
537 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') | 540 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') |
538 | 541 |
539 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, isolate=isolate) | 542 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, isolate=isolate) |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 | 867 |
865 | 868 |
866 def is_explicit_nullable(idl_type): | 869 def is_explicit_nullable(idl_type): |
867 # Nullable type that isn't implicit nullable (see above.) For such types, | 870 # Nullable type that isn't implicit nullable (see above.) For such types, |
868 # we use Nullable<T> or similar explicit ways to represent a null value. | 871 # we use Nullable<T> or similar explicit ways to represent a null value. |
869 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 872 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
870 | 873 |
871 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) | 874 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
872 IdlUnionType.is_implicit_nullable = False | 875 IdlUnionType.is_implicit_nullable = False |
873 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 876 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |