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

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

Issue 795833004: Use dictionaries for context creation attributes. Eliminate custom bindings. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 708
709 def v8_conversion_type(idl_type, extended_attributes): 709 def v8_conversion_type(idl_type, extended_attributes):
710 """Returns V8 conversion type, adding any additional includes. 710 """Returns V8 conversion type, adding any additional includes.
711 711
712 The V8 conversion type is used to select the C++ -> V8 conversion function 712 The V8 conversion type is used to select the C++ -> V8 conversion function
713 or v8SetReturnValue* function; it can be an idl_type, a cpp_type, or a 713 or v8SetReturnValue* function; it can be an idl_type, a cpp_type, or a
714 separate name for the type of conversion (e.g., 'DOMWrapper'). 714 separate name for the type of conversion (e.g., 'DOMWrapper').
715 """ 715 """
716 extended_attributes = extended_attributes or {} 716 extended_attributes = extended_attributes or {}
717 717
718 # Nullable dictionaries need to be handled differently than either
719 # non-nullable dictionaries or unions.
bashi 2014/12/12 00:35:24 Or we can make IDL dictionaries be 'implicit_nulla
Ken Russell (switch to Gerrit) 2014/12/12 06:59:31 I'd rather not make IDL dictionaries implicit_null
bashi 2014/12/12 08:31:33 Acknowledged.
720 if idl_type.is_dictionary and idl_type.is_nullable:
721 return 'NullableDictionary'
722
718 if idl_type.is_dictionary or idl_type.is_union_type: 723 if idl_type.is_dictionary or idl_type.is_union_type:
719 return 'DictionaryOrUnion' 724 return 'DictionaryOrUnion'
720 725
721 # Array or sequence types 726 # Array or sequence types
722 native_array_element_type = idl_type.native_array_element_type 727 native_array_element_type = idl_type.native_array_element_type
723 if native_array_element_type: 728 if native_array_element_type:
724 if native_array_element_type.is_interface_type: 729 if native_array_element_type.is_interface_type:
725 add_includes_for_type(native_array_element_type) 730 add_includes_for_type(native_array_element_type)
726 return 'array' 731 return 'array'
727 732
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 'Date': 'v8SetReturnValue(info, {cpp_value})', 787 'Date': 'v8SetReturnValue(info, {cpp_value})',
783 'EventHandler': 'v8SetReturnValue(info, {cpp_value})', 788 'EventHandler': 'v8SetReturnValue(info, {cpp_value})',
784 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})', 789 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})',
785 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})', 790 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})',
786 # DOMWrapper 791 # DOMWrapper
787 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, WTF::getPtr({c pp_value}))', 792 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, WTF::getPtr({c pp_value}))',
788 'DOMWrapperFast': 'v8SetReturnValueFast(info, WTF::getPtr({cpp_value}), {scr ipt_wrappable})', 793 'DOMWrapperFast': 'v8SetReturnValueFast(info, WTF::getPtr({cpp_value}), {scr ipt_wrappable})',
789 'DOMWrapperDefault': 'v8SetReturnValue(info, {cpp_value})', 794 'DOMWrapperDefault': 'v8SetReturnValue(info, {cpp_value})',
790 # Generic dictionary type 795 # Generic dictionary type
791 'Dictionary': 'v8SetReturnValue(info, {cpp_value})', 796 'Dictionary': 'v8SetReturnValue(info, {cpp_value})',
797 # Nullable dictionaries
798 'NullableDictionary': 'v8SetReturnValue(info, result.get())',
792 # Union types or dictionaries 799 # Union types or dictionaries
793 'DictionaryOrUnion': 'v8SetReturnValue(info, result)', 800 'DictionaryOrUnion': 'v8SetReturnValue(info, result)',
794 } 801 }
795 802
796 803
797 def v8_set_return_value(idl_type, cpp_value, extended_attributes=None, script_wr appable='', release=False, for_main_world=False): 804 def v8_set_return_value(idl_type, cpp_value, extended_attributes=None, script_wr appable='', release=False, for_main_world=False):
798 """Returns a statement that converts a C++ value to a V8 value and sets it a s a return value. 805 """Returns a statement that converts a C++ value to a V8 value and sets it a s a return value.
799 806
800 """ 807 """
801 def dom_wrapper_conversion_type(): 808 def dom_wrapper_conversion_type():
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 'StringOrNull': '{cpp_value}.isNull() ? v8::Handle<v8::Value>(v8::Null({isol ate})) : v8String({isolate}, {cpp_value})', 853 'StringOrNull': '{cpp_value}.isNull() ? v8::Handle<v8::Value>(v8::Null({isol ate})) : v8String({isolate}, {cpp_value})',
847 'StringOrUndefined': '{cpp_value}.isNull() ? v8Undefined() : v8String({isola te}, {cpp_value})', 854 'StringOrUndefined': '{cpp_value}.isNull() ? v8Undefined() : v8String({isola te}, {cpp_value})',
848 # Special cases 855 # Special cases
849 'Dictionary': '{cpp_value}.v8Value()', 856 'Dictionary': '{cpp_value}.v8Value()',
850 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', 857 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))',
851 'ScriptValue': '{cpp_value}.v8Value()', 858 'ScriptValue': '{cpp_value}.v8Value()',
852 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', 859 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))',
853 # General 860 # General
854 'array': 'toV8({cpp_value}, {creation_context}, {isolate})', 861 'array': 'toV8({cpp_value}, {creation_context}, {isolate})',
855 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', 862 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})',
863 # Passing nullable dictionaries isn't a pattern currently used
864 # anywhere in the web platform, and more work would be needed in
865 # the code generator to distinguish between passing null, and
866 # passing an object which happened to not contain any of the
867 # dictionary's defined attributes. For now, don't define
868 # NullableDictionary here, which will cause an exception to be
869 # thrown during code generation if an argument to a method is a
870 # nullable dictionary type.
871 #
856 # Union types or dictionaries 872 # Union types or dictionaries
857 'DictionaryOrUnion': 'toV8({cpp_value}, {creation_context}, {isolate})', 873 'DictionaryOrUnion': 'toV8({cpp_value}, {creation_context}, {isolate})',
858 } 874 }
859 875
860 876
861 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): 877 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None):
862 """Returns an expression that converts a C++ value to a V8 value.""" 878 """Returns an expression that converts a C++ value to a V8 value."""
863 # the isolate parameter is needed for callback interfaces 879 # the isolate parameter is needed for callback interfaces
864 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 880 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
865 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 881 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 number_of_nullable_member_types_union) 947 number_of_nullable_member_types_union)
932 948
933 949
934 def includes_nullable_type_union(idl_type): 950 def includes_nullable_type_union(idl_type):
935 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 951 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
936 return idl_type.number_of_nullable_member_types == 1 952 return idl_type.number_of_nullable_member_types == 1
937 953
938 IdlTypeBase.includes_nullable_type = False 954 IdlTypeBase.includes_nullable_type = False
939 IdlNullableType.includes_nullable_type = True 955 IdlNullableType.includes_nullable_type = True
940 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 956 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698