Chromium Code Reviews

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

Issue 185413023: Oilpan: move Touch related objects to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added 2 binding tests + style Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 230 matching lines...)
241 'Dictionary': 'Dictionary', 241 'Dictionary': 'Dictionary',
242 'EventHandler': 'EventListener*', 242 'EventHandler': 'EventListener*',
243 'Promise': 'ScriptPromise', 243 'Promise': 'ScriptPromise',
244 'ScriptValue': 'ScriptValue', 244 'ScriptValue': 'ScriptValue',
245 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 245 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529
246 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', 246 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>',
247 'boolean': 'bool', 247 'boolean': 'bool',
248 } 248 }
249 249
250 250
251 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): 251 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_as _member=False):
252 """Returns C++ type corresponding to IDL type.""" 252 """Returns C++ type corresponding to IDL type.
253
254 Args:
255 used_as_argument: bool, True if idl_type's raw/primitive C++ type
256 should be returned.
257 used_as_member: bool, if idl_type is the type of an array or sequence
258 (which maps to some vector representation in C++.)
haraken 2014/03/05 14:52:46 Instead of |used_as_member|, shall we use |will_be
sof 2014/03/05 16:01:12 I renamed it as will_be_in_heap_object; its the pr
259 """
253 def string_mode(): 260 def string_mode():
254 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', 261 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString',
255 # but we use NullString for performance. 262 # but we use NullString for performance.
256 if extended_attributes.get('TreatNullAs') != 'NullString': 263 if extended_attributes.get('TreatNullAs') != 'NullString':
257 return '' 264 return ''
258 if extended_attributes.get('TreatUndefinedAs') != 'NullString': 265 if extended_attributes.get('TreatUndefinedAs') != 'NullString':
259 return 'WithNullCheck' 266 return 'WithNullCheck'
260 return 'WithUndefinedOrNullCheck' 267 return 'WithUndefinedOrNullCheck'
261 268
262 extended_attributes = extended_attributes or {} 269 extended_attributes = extended_attributes or {}
(...skipping 13 matching lines...)
276 if not used_as_argument: 283 if not used_as_argument:
277 return 'String' 284 return 'String'
278 return 'V8StringResource<%s>' % string_mode() 285 return 'V8StringResource<%s>' % string_mode()
279 if is_union_type(idl_type): 286 if is_union_type(idl_type):
280 # Attribute 'union_member_types' use is ok, but pylint can't infer this 287 # Attribute 'union_member_types' use is ok, but pylint can't infer this
281 # pylint: disable=E1103 288 # pylint: disable=E1103
282 return (cpp_type(union_member_type) 289 return (cpp_type(union_member_type)
283 for union_member_type in idl_type.union_member_types) 290 for union_member_type in idl_type.union_member_types)
284 this_array_or_sequence_type = array_or_sequence_type(idl_type) 291 this_array_or_sequence_type = array_or_sequence_type(idl_type)
285 if this_array_or_sequence_type: 292 if this_array_or_sequence_type:
286 return cpp_template_type('Vector', cpp_type(this_array_or_sequence_type) ) 293 will_be_garbage_collected = is_will_be_garbage_collected(this_array_or_s equence_type)
294 vector_type = 'WillBeHeapVector' if will_be_garbage_collected else 'Vect or'
295 return cpp_template_type(vector_type, cpp_type(this_array_or_sequence_ty pe, used_as_member=will_be_garbage_collected))
287 296
288 if is_typed_array_type(idl_type) and used_as_argument: 297 if is_typed_array_type(idl_type) and used_as_argument:
289 return idl_type + '*' 298 return idl_type + '*'
290 if is_interface_type(idl_type): 299 if is_interface_type(idl_type):
291 implemented_as_class = implemented_as(idl_type) 300 implemented_as_class = implemented_as(idl_type)
292 if used_as_argument: 301 if used_as_argument:
293 return implemented_as_class + '*' 302 return implemented_as_class + '*'
294 if is_will_be_garbage_collected(idl_type): 303 if is_will_be_garbage_collected(idl_type):
295 return cpp_template_type('RefPtrWillBeRawPtr', implemented_as_class) 304 ref_ptr_type = 'RefPtrWillBeMember' if used_as_member else 'RefPtrWi llBeRawPtr'
305 return cpp_template_type(ref_ptr_type, implemented_as_class)
296 return cpp_template_type('RefPtr', implemented_as_class) 306 return cpp_template_type('RefPtr', implemented_as_class)
297 # Default, assume native type is a pointer with same type name as idl type 307 # Default, assume native type is a pointer with same type name as idl type
298 return idl_type + '*' 308 return idl_type + '*'
299 309
300 310
301 def cpp_template_type(template, inner_type): 311 def cpp_template_type(template, inner_type):
302 """Returns C++ template specialized to type, with space added if needed.""" 312 """Returns C++ template specialized to type, with space added if needed."""
303 if inner_type.endswith('>'): 313 if inner_type.endswith('>'):
304 format_string = '{template}<{inner_type} >' 314 format_string = '{template}<{inner_type} >'
305 else: 315 else:
(...skipping 158 matching lines...)
464 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu e, index): 474 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu e, index):
465 # Index is None for setters, index (starting at 0) for method arguments, 475 # Index is None for setters, index (starting at 0) for method arguments,
466 # and is used to provide a human-readable exception message 476 # and is used to provide a human-readable exception message
467 if index is None: 477 if index is None:
468 index = 0 # special case, meaning "setter" 478 index = 0 # special case, meaning "setter"
469 else: 479 else:
470 index += 1 # human-readable index 480 index += 1 # human-readable index
471 if (is_interface_type(this_array_or_sequence_type) and 481 if (is_interface_type(this_array_or_sequence_type) and
472 this_array_or_sequence_type != 'Dictionary'): 482 this_array_or_sequence_type != 'Dictionary'):
473 this_cpp_type = None 483 this_cpp_type = None
474 expression_format = '(toRefPtrNativeArray<{array_or_sequence_type}, V8{a rray_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' 484 ref_ptr_type = 'Member' if is_will_be_garbage_collected(this_array_or_se quence_type) else 'Ref'
485 expression_format = '(to{ref_ptr_type}PtrNativeArray<{array_or_sequence_ type}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))'
haraken 2014/03/05 14:52:46 "MemberPtr" sounds strange. Shall we call it toMem
sof 2014/03/05 16:01:12 Great catch; my typo (the underlying method is cal
475 add_includes_for_type(this_array_or_sequence_type) 486 add_includes_for_type(this_array_or_sequence_type)
476 else: 487 else:
488 ref_ptr_type = None
477 this_cpp_type = cpp_type(this_array_or_sequence_type) 489 this_cpp_type = cpp_type(this_array_or_sequence_type)
478 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' 490 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())'
479 expression = expression_format.format(array_or_sequence_type=this_array_or_s equence_type, cpp_type=this_cpp_type, index=index, v8_value=v8_value) 491 expression = expression_format.format(array_or_sequence_type=this_array_or_s equence_type, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8 _value=v8_value)
480 return expression 492 return expression
481 493
482 494
483 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): 495 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None):
484 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 496 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
485 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True) 497 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True)
486 498
487 idl_type = preprocess_idl_type(idl_type) 499 idl_type = preprocess_idl_type(idl_type)
488 if idl_type == 'DOMString': 500 if idl_type == 'DOMString':
489 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})' 501 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})'
(...skipping 167 matching lines...)
657 669
658 670
659 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): 671 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None):
660 """Returns an expression that converts a C++ value to a V8 value.""" 672 """Returns an expression that converts a C++ value to a V8 value."""
661 # the isolate parameter is needed for callback interfaces 673 # the isolate parameter is needed for callback interfaces
662 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 674 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
663 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) 675 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes)
664 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 676 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
665 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 677 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
666 return statement 678 return statement
OLDNEW

Powered by Google App Engine