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 21 matching lines...) Expand all Loading... | |
32 class methods. | 32 class methods. |
33 | 33 |
34 Spec: | 34 Spec: |
35 http://www.w3.org/TR/WebIDL/#es-type-mapping | 35 http://www.w3.org/TR/WebIDL/#es-type-mapping |
36 | 36 |
37 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 37 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
38 """ | 38 """ |
39 | 39 |
40 import posixpath | 40 import posixpath |
41 | 41 |
42 from idl_types import IdlTypeBase, IdlType, IdlUnionType | 42 from idl_types import IdlTypeBase, IdlType, IdlUnionType, IdlArrayOrSequenceType |
43 import v8_attributes # for IdlType.constructor_type_name | 43 import v8_attributes # for IdlType.constructor_type_name |
44 from v8_globals import includes | 44 from v8_globals import includes |
45 | 45 |
46 | 46 |
47 ################################################################################ | 47 ################################################################################ |
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 'CompareHow', | 52 'CompareHow', |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 return 'TreatNullAsEmptyString' | 145 return 'TreatNullAsEmptyString' |
146 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu llString': | 146 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu llString': |
147 if extended_attributes.get('TreatUndefinedAs') == 'NullString': | 147 if extended_attributes.get('TreatUndefinedAs') == 'NullString': |
148 return 'TreatNullAndUndefinedAsNullString' | 148 return 'TreatNullAndUndefinedAsNullString' |
149 return 'TreatNullAsNullString' | 149 return 'TreatNullAsNullString' |
150 return '' | 150 return '' |
151 | 151 |
152 extended_attributes = extended_attributes or {} | 152 extended_attributes = extended_attributes or {} |
153 idl_type = idl_type.preprocessed_type | 153 idl_type = idl_type.preprocessed_type |
154 | 154 |
155 # Composite types | 155 # Array or sequence types |
156 if used_as_variadic_argument: | 156 if used_as_variadic_argument: |
157 native_array_element_type = idl_type | 157 native_array_element_type = idl_type |
158 else: | 158 else: |
159 native_array_element_type = idl_type.native_array_element_type | 159 native_array_element_type = idl_type.native_array_element_type |
160 if native_array_element_type: | 160 if native_array_element_type: |
161 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.gc_type) | 161 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.gc_type) |
162 vector_template_type = cpp_template_type(vector_type, native_array_eleme nt_type.cpp_type_args(used_in_cpp_sequence=True)) | 162 vector_template_type = cpp_template_type(vector_type, native_array_eleme nt_type.cpp_type_args(used_in_cpp_sequence=True)) |
163 if used_as_rvalue_type: | 163 if used_as_rvalue_type: |
164 return 'const %s&' % vector_template_type | 164 return 'const %s&' % vector_template_type |
165 return vector_template_type | 165 return vector_template_type |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 | 220 |
221 # Allow access as idl_type.cpp_type if no arguments | 221 # Allow access as idl_type.cpp_type if no arguments |
222 IdlTypeBase.cpp_type = property(cpp_type) | 222 IdlTypeBase.cpp_type = property(cpp_type) |
223 IdlTypeBase.cpp_type_initializer = property(cpp_type_initializer) | 223 IdlTypeBase.cpp_type_initializer = property(cpp_type_initializer) |
224 IdlTypeBase.cpp_type_args = cpp_type | 224 IdlTypeBase.cpp_type_args = cpp_type |
225 IdlUnionType.cpp_type = property(cpp_type_union) | 225 IdlUnionType.cpp_type = property(cpp_type_union) |
226 IdlUnionType.cpp_type_initializer = property(cpp_type_initializer_union) | 226 IdlUnionType.cpp_type_initializer = property(cpp_type_initializer_union) |
227 IdlUnionType.cpp_type_args = cpp_type_union | 227 IdlUnionType.cpp_type_args = cpp_type_union |
228 | 228 |
229 | 229 |
230 IdlTypeBase.native_array_element_type = None | |
231 IdlArrayOrSequenceType.native_array_element_type = property( | |
232 lambda self: self.element_type) | |
233 | |
234 | |
230 def cpp_template_type(template, inner_type): | 235 def cpp_template_type(template, inner_type): |
231 """Returns C++ template specialized to type, with space added if needed.""" | 236 """Returns C++ template specialized to type, with space added if needed.""" |
232 if inner_type.endswith('>'): | 237 if inner_type.endswith('>'): |
233 format_string = '{template}<{inner_type} >' | 238 format_string = '{template}<{inner_type} >' |
234 else: | 239 else: |
235 format_string = '{template}<{inner_type}>' | 240 format_string = '{template}<{inner_type}>' |
236 return format_string.format(template=template, inner_type=inner_type) | 241 return format_string.format(template=template, inner_type=inner_type) |
237 | 242 |
238 | 243 |
239 def cpp_ptr_type(old_type, new_type, gc_type): | 244 def cpp_ptr_type(old_type, new_type, gc_type): |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 'core/html/LabelsNodeList.h']), | 345 'core/html/LabelsNodeList.h']), |
341 'Promise': set(['bindings/core/v8/ScriptPromise.h']), | 346 'Promise': set(['bindings/core/v8/ScriptPromise.h']), |
342 'SerializedScriptValue': set(['bindings/core/v8/SerializedScriptValue.h']), | 347 'SerializedScriptValue': set(['bindings/core/v8/SerializedScriptValue.h']), |
343 'ScriptValue': set(['bindings/core/v8/ScriptValue.h']), | 348 'ScriptValue': set(['bindings/core/v8/ScriptValue.h']), |
344 } | 349 } |
345 | 350 |
346 | 351 |
347 def includes_for_type(idl_type): | 352 def includes_for_type(idl_type): |
348 idl_type = idl_type.preprocessed_type | 353 idl_type = idl_type.preprocessed_type |
349 | 354 |
350 # Composite types | |
351 native_array_element_type = idl_type.native_array_element_type | |
haraken
2014/08/14 14:48:58
Why can we remove this code?
| |
352 if native_array_element_type: | |
353 return includes_for_type(native_array_element_type) | |
354 | |
355 # Simple types | 355 # Simple types |
356 base_idl_type = idl_type.base_type | 356 base_idl_type = idl_type.base_type |
357 if base_idl_type in INCLUDES_FOR_TYPE: | 357 if base_idl_type in INCLUDES_FOR_TYPE: |
358 return INCLUDES_FOR_TYPE[base_idl_type] | 358 return INCLUDES_FOR_TYPE[base_idl_type] |
359 if idl_type.is_basic_type: | 359 if idl_type.is_basic_type: |
360 return set() | 360 return set() |
361 if idl_type.is_typed_array_element_type: | 361 if idl_type.is_typed_array_element_type: |
362 return set(['bindings/core/v8/custom/V8%sCustom.h' % base_idl_type]) | 362 return set(['bindings/core/v8/custom/V8%sCustom.h' % base_idl_type]) |
363 if base_idl_type.endswith('ConstructorConstructor'): | 363 if base_idl_type.endswith('ConstructorConstructor'): |
364 # FIXME: rename to NamedConstructor | 364 # FIXME: rename to NamedConstructor |
365 # FIXME: replace with a [NamedConstructorAttribute] extended attribute | 365 # FIXME: replace with a [NamedConstructorAttribute] extended attribute |
366 # Ending with 'ConstructorConstructor' indicates a named constructor, | 366 # Ending with 'ConstructorConstructor' indicates a named constructor, |
367 # and these do not have header files, as they are part of the generated | 367 # and these do not have header files, as they are part of the generated |
368 # bindings for the interface | 368 # bindings for the interface |
369 return set() | 369 return set() |
370 if base_idl_type.endswith('Constructor'): | 370 if base_idl_type.endswith('Constructor'): |
371 # FIXME: replace with a [ConstructorAttribute] extended attribute | 371 # FIXME: replace with a [ConstructorAttribute] extended attribute |
372 base_idl_type = idl_type.constructor_type_name | 372 base_idl_type = idl_type.constructor_type_name |
373 if base_idl_type not in component_dir: | 373 if base_idl_type not in component_dir: |
374 return set() | 374 return set() |
375 return set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], | 375 return set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], |
376 base_idl_type)]) | 376 base_idl_type)]) |
377 | 377 |
378 IdlType.includes_for_type = property(includes_for_type) | 378 IdlType.includes_for_type = property(includes_for_type) |
379 IdlUnionType.includes_for_type = property( | 379 IdlUnionType.includes_for_type = property( |
380 lambda self: set.union(*[includes_for_type(member_type) | 380 lambda self: set.union(*[includes_for_type(member_type) |
381 for member_type in self.member_types])) | 381 for member_type in self.member_types])) |
382 IdlArrayOrSequenceType.includes_for_type = property( | |
383 lambda self: self.element_type.includes_for_type) | |
382 | 384 |
383 | 385 |
384 def add_includes_for_type(idl_type): | 386 def add_includes_for_type(idl_type): |
385 includes.update(idl_type.includes_for_type) | 387 includes.update(idl_type.includes_for_type) |
386 | 388 |
387 IdlTypeBase.add_includes_for_type = add_includes_for_type | 389 IdlTypeBase.add_includes_for_type = add_includes_for_type |
388 | 390 |
389 | 391 |
390 def includes_for_interface(interface_name): | 392 def includes_for_interface(interface_name): |
391 return IdlType(interface_name).includes_for_type | 393 return IdlType(interface_name).includes_for_type |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', | 467 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', |
466 'Window': 'toDOMWindow({v8_value}, {isolate})', | 468 'Window': 'toDOMWindow({v8_value}, {isolate})', |
467 'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})', | 469 'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})', |
468 } | 470 } |
469 | 471 |
470 | 472 |
471 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat e): | 473 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat e): |
472 if idl_type.name == 'void': | 474 if idl_type.name == 'void': |
473 return '' | 475 return '' |
474 | 476 |
475 # Composite types | 477 # Array and sequence types |
haraken
2014/08/14 14:48:58
Nit: and => or (You use "or" in other places.)
| |
476 native_array_element_type = idl_type.native_array_element_type | 478 native_array_element_type = idl_type.native_array_element_type |
477 if native_array_element_type: | 479 if native_array_element_type: |
478 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index) | 480 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index) |
479 | 481 |
480 # Simple types | 482 # Simple types |
481 idl_type = idl_type.preprocessed_type | 483 idl_type = idl_type.preprocessed_type |
482 add_includes_for_type(idl_type) | 484 add_includes_for_type(idl_type) |
483 base_idl_type = idl_type.base_type | 485 base_idl_type = idl_type.base_type |
484 | 486 |
485 if 'EnforceRange' in extended_attributes: | 487 if 'EnforceRange' in extended_attributes: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 | 532 |
531 # FIXME: Support union type. | 533 # FIXME: Support union type. |
532 if idl_type.is_union_type: | 534 if idl_type.is_union_type: |
533 return '' | 535 return '' |
534 | 536 |
535 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) | 537 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) |
536 | 538 |
537 idl_type = idl_type.preprocessed_type | 539 idl_type = idl_type.preprocessed_type |
538 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) | 540 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) |
539 args = [variable_name, cpp_value] | 541 args = [variable_name, cpp_value] |
540 if idl_type.base_type == 'DOMString' and not idl_type.native_array_element_t ype: | 542 if idl_type.base_type == 'DOMString': |
541 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID ' | 543 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID ' |
542 elif idl_type.may_raise_exception_on_conversion: | 544 elif idl_type.may_raise_exception_on_conversion: |
543 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' | 545 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' |
544 args.append('exceptionState') | 546 args.append('exceptionState') |
545 else: | 547 else: |
546 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID ' | 548 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID ' |
547 | 549 |
548 if used_in_private_script: | 550 if used_in_private_script: |
549 args.append('false') | 551 args.append('false') |
550 | 552 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 return idl_type, cpp_value | 607 return idl_type, cpp_value |
606 | 608 |
607 | 609 |
608 def v8_conversion_type(idl_type, extended_attributes): | 610 def v8_conversion_type(idl_type, extended_attributes): |
609 """Returns V8 conversion type, adding any additional includes. | 611 """Returns V8 conversion type, adding any additional includes. |
610 | 612 |
611 The V8 conversion type is used to select the C++ -> V8 conversion function | 613 The V8 conversion type is used to select the C++ -> V8 conversion function |
612 or v8SetReturnValue* function; it can be an idl_type, a cpp_type, or a | 614 or v8SetReturnValue* function; it can be an idl_type, a cpp_type, or a |
613 separate name for the type of conversion (e.g., 'DOMWrapper'). | 615 separate name for the type of conversion (e.g., 'DOMWrapper'). |
614 """ | 616 """ |
615 extended_attributes = extended_attributes or {} | |
616 | 617 |
617 # Composite types | 618 # FIXME: Support union type. |
619 if idl_type.is_union_type: | |
620 return '' | |
621 | |
622 # Array or sequence types | |
618 native_array_element_type = idl_type.native_array_element_type | 623 native_array_element_type = idl_type.native_array_element_type |
619 if native_array_element_type: | 624 if native_array_element_type: |
620 if native_array_element_type.is_interface_type: | 625 if native_array_element_type.is_interface_type: |
621 add_includes_for_type(native_array_element_type) | 626 add_includes_for_type(native_array_element_type) |
622 return 'array' | 627 return 'array' |
623 | 628 |
629 extended_attributes = extended_attributes or {} | |
630 | |
624 # Simple types | 631 # Simple types |
625 base_idl_type = idl_type.base_type | 632 base_idl_type = idl_type.base_type |
626 # Basic types, without additional includes | 633 # Basic types, without additional includes |
627 if base_idl_type in CPP_INT_TYPES: | 634 if base_idl_type in CPP_INT_TYPES: |
628 return 'int' | 635 return 'int' |
629 if base_idl_type in CPP_UNSIGNED_TYPES: | 636 if base_idl_type in CPP_UNSIGNED_TYPES: |
630 return 'unsigned' | 637 return 'unsigned' |
631 if idl_type.is_string_type: | 638 if idl_type.is_string_type: |
632 if idl_type.is_nullable: | 639 if idl_type.is_nullable: |
633 return 'StringOrNull' | 640 return 'StringOrNull' |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 for i, member_type in | 733 for i, member_type in |
727 enumerate(idl_type.member_types)] | 734 enumerate(idl_type.member_types)] |
728 | 735 |
729 IdlTypeBase.v8_set_return_value = v8_set_return_value | 736 IdlTypeBase.v8_set_return_value = v8_set_return_value |
730 IdlUnionType.v8_set_return_value = v8_set_return_value_union | 737 IdlUnionType.v8_set_return_value = v8_set_return_value_union |
731 | 738 |
732 IdlType.release = property(lambda self: self.is_interface_type) | 739 IdlType.release = property(lambda self: self.is_interface_type) |
733 IdlUnionType.release = property( | 740 IdlUnionType.release = property( |
734 lambda self: [member_type.is_interface_type | 741 lambda self: [member_type.is_interface_type |
735 for member_type in self.member_types]) | 742 for member_type in self.member_types]) |
743 IdlArrayOrSequenceType.release = False | |
haraken
2014/08/14 14:48:58
False => None ?
Nils Barth (inactive)
2014/08/14 14:54:56
release is a bool (see above: is_interface_type),
| |
736 | 744 |
737 | 745 |
738 CPP_VALUE_TO_V8_VALUE = { | 746 CPP_VALUE_TO_V8_VALUE = { |
739 # Built-in types | 747 # Built-in types |
740 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', | 748 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', |
741 'DOMString': 'v8String({isolate}, {cpp_value})', | 749 'DOMString': 'v8String({isolate}, {cpp_value})', |
742 'ByteString': 'v8String({isolate}, {cpp_value})', | 750 'ByteString': 'v8String({isolate}, {cpp_value})', |
743 'ScalarValueString': 'v8String({isolate}, {cpp_value})', | 751 'ScalarValueString': 'v8String({isolate}, {cpp_value})', |
744 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 752 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
745 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 753 'int': 'v8::Integer::New({isolate}, {cpp_value})', |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 | 810 |
803 | 811 |
804 def is_explicit_nullable(idl_type): | 812 def is_explicit_nullable(idl_type): |
805 # Nullable type that isn't implicit nullable (see above.) For such types, | 813 # Nullable type that isn't implicit nullable (see above.) For such types, |
806 # we use Nullable<T> or similar explicit ways to represent a null value. | 814 # we use Nullable<T> or similar explicit ways to represent a null value. |
807 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 815 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
808 | 816 |
809 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) | 817 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
810 IdlUnionType.is_implicit_nullable = False | 818 IdlUnionType.is_implicit_nullable = False |
811 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 819 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |