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

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

Issue 265293004: Create fewer local v8::TryCatch objects in generated bindings code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 7 months 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 (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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 'Promise': 'ScriptPromise', 112 'Promise': 'ScriptPromise',
113 'ScriptValue': 'ScriptValue', 113 'ScriptValue': 'ScriptValue',
114 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 114 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529
115 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', 115 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>',
116 'boolean': 'bool', 116 'boolean': 'bool',
117 'unrestricted double': 'double', 117 'unrestricted double': 'double',
118 'unrestricted float': 'float', 118 'unrestricted float': 'float',
119 } 119 }
120 120
121 121
122 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_in _cpp_sequence=False): 122 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_as _variadic_argument=False, used_in_cpp_sequence=False):
123 """Returns C++ type corresponding to IDL type. 123 """Returns C++ type corresponding to IDL type.
124 124
125 |idl_type| argument is of type IdlType, while return value is a string 125 |idl_type| argument is of type IdlType, while return value is a string
126 126
127 Args: 127 Args:
128 idl_type: 128 idl_type:
129 IdlType 129 IdlType
130 used_as_argument: 130 used_as_argument:
131 bool, True if idl_type's raw/primitive C++ type should be returned. 131 bool, True if idl_type's raw/primitive C++ type should be returned.
132 used_in_cpp_sequence: 132 used_in_cpp_sequence:
133 bool, True if the C++ type is used as an element of an array or sequ ence. 133 bool, True if the C++ type is used as an element of an array or sequ ence.
134 """ 134 """
135 def string_mode(): 135 def string_mode():
136 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', 136 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString',
137 # but we use NullString for performance. 137 # but we use NullString for performance.
138 if extended_attributes.get('TreatNullAs') != 'NullString': 138 if extended_attributes.get('TreatNullAs') != 'NullString':
139 return '' 139 return ''
140 if extended_attributes.get('TreatUndefinedAs') != 'NullString': 140 if extended_attributes.get('TreatUndefinedAs') != 'NullString':
141 return 'WithNullCheck' 141 return 'WithNullCheck'
142 return 'WithUndefinedOrNullCheck' 142 return 'WithUndefinedOrNullCheck'
143 143
144 extended_attributes = extended_attributes or {} 144 extended_attributes = extended_attributes or {}
145 idl_type = idl_type.preprocessed_type 145 idl_type = idl_type.preprocessed_type
146 146
147 # Composite types 147 # Composite types
148 array_or_sequence_type = idl_type.array_or_sequence_type 148 if used_as_variadic_argument:
149 array_or_sequence_type = idl_type
150 else:
151 array_or_sequence_type = idl_type.array_or_sequence_type
149 if array_or_sequence_type: 152 if array_or_sequence_type:
150 vector_type = cpp_ptr_type('Vector', 'HeapVector', array_or_sequence_typ e.gc_type) 153 vector_type = cpp_ptr_type('Vector', 'HeapVector', array_or_sequence_typ e.gc_type)
151 return cpp_template_type(vector_type, array_or_sequence_type.cpp_type_ar gs(used_in_cpp_sequence=True)) 154 return cpp_template_type(vector_type, array_or_sequence_type.cpp_type_ar gs(used_in_cpp_sequence=True))
152 155
153 # Simple types 156 # Simple types
154 base_idl_type = idl_type.base_type 157 base_idl_type = idl_type.base_type
155 158
156 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: 159 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE:
157 return base_idl_type 160 return base_idl_type
158 if base_idl_type in CPP_INT_TYPES: 161 if base_idl_type in CPP_INT_TYPES:
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' 428 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))'
426 add_includes_for_type(array_or_sequence_type) 429 add_includes_for_type(array_or_sequence_type)
427 else: 430 else:
428 ref_ptr_type = None 431 ref_ptr_type = None
429 this_cpp_type = array_or_sequence_type.cpp_type 432 this_cpp_type = array_or_sequence_type.cpp_type
430 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' 433 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())'
431 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8 _value=v8_value) 434 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8 _value=v8_value)
432 return expression 435 return expression
433 436
434 437
435 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): 438 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, method_has_try_catch=False):
436 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 439 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
437 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) 440 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True)
438 441
439 idl_type = idl_type.preprocessed_type 442 idl_type = idl_type.preprocessed_type
440 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 443 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex)
441 args = [this_cpp_type, variable_name, cpp_value] 444 args = [variable_name, cpp_value]
442 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 445 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
443 macro = 'TOSTRING_VOID' 446 macro = 'TOSTRING_VOID'
444 elif idl_type.is_integer_type: 447 elif idl_type.is_integer_type:
445 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 448 macro = 'TONATIVE_VOID_EXCEPTIONSTATE'
446 args.append('exceptionState') 449 args.append('exceptionState')
447 else: 450 else:
448 macro = 'TONATIVE_VOID' 451 macro = 'TONATIVE_VOID'
449 452
453 if declare_variable:
454 args.insert(0, this_cpp_type)
455 else:
456 # Use a macro that assumes a previously declared local variable.
457 macro += '_INTERNAL'
458 if method_has_try_catch and macro == 'TOSTRING_VOID_INTERNAL':
haraken 2014/05/21 14:56:45 Would you add a comment about why we need the spec
Jens Widell 2014/05/21 15:07:02 Comment added.
459 macro += '_RETHROW'
460 args.append('block')
461
450 return '%s(%s)' % (macro, ', '.join(args)) 462 return '%s(%s)' % (macro, ', '.join(args))
451 463
452 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 464 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
453 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 465 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
454 466
455 467
456 ################################################################################ 468 ################################################################################
457 # C++ -> V8 469 # C++ -> V8
458 ################################################################################ 470 ################################################################################
459 471
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): 654 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None):
643 """Returns an expression that converts a C++ value to a V8 value.""" 655 """Returns an expression that converts a C++ value to a V8 value."""
644 # the isolate parameter is needed for callback interfaces 656 # the isolate parameter is needed for callback interfaces
645 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 657 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
646 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 658 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
647 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 659 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
648 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 660 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
649 return statement 661 return statement
650 662
651 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 663 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698