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

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: 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' 424 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))'
425 add_includes_for_type(array_or_sequence_type) 425 add_includes_for_type(array_or_sequence_type)
426 else: 426 else:
427 ref_ptr_type = None 427 ref_ptr_type = None
428 this_cpp_type = array_or_sequence_type.cpp_type 428 this_cpp_type = array_or_sequence_type.cpp_type
429 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' 429 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())'
430 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) 430 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)
431 return expression 431 return expression
432 432
433 433
434 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): 434 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True):
435 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 435 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
436 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) 436 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True)
437 437
438 idl_type = idl_type.preprocessed_type 438 idl_type = idl_type.preprocessed_type
439 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 439 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex)
440 args = [this_cpp_type, variable_name, cpp_value] 440 args = [variable_name, cpp_value]
441 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 441 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
442 macro = 'TOSTRING_VOID' 442 macro = 'TOSTRING_VOID'
443 elif idl_type.is_integer_type: 443 elif idl_type.is_integer_type:
444 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 444 macro = 'TONATIVE_VOID_EXCEPTIONSTATE'
445 args.append('exceptionState') 445 args.append('exceptionState')
446 else: 446 else:
447 macro = 'TONATIVE_VOID' 447 macro = 'TONATIVE_VOID'
448 448
449 if not declare_variable:
Nils Barth (inactive) 2014/05/07 03:02:19 I prefer to avoid 'not' in if...else, so: if decla
450 # Use a macro that assumes a previously declared local variable.
451 macro += "_NO_DECL"
Nils Barth (inactive) 2014/05/07 03:02:19 ...and single quotes.
452 else:
453 args.insert(0, this_cpp_type)
454
449 return '%s(%s)' % (macro, ', '.join(args)) 455 return '%s(%s)' % (macro, ', '.join(args))
450 456
451 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 457 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
452 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 458 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
453 459
454 460
455 ################################################################################ 461 ################################################################################
456 # C++ -> V8 462 # C++ -> V8
457 ################################################################################ 463 ################################################################################
458 464
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): 647 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None):
642 """Returns an expression that converts a C++ value to a V8 value.""" 648 """Returns an expression that converts a C++ value to a V8 value."""
643 # the isolate parameter is needed for callback interfaces 649 # the isolate parameter is needed for callback interfaces
644 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 650 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
645 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 651 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
646 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 652 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
647 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 653 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
648 return statement 654 return statement
649 655
650 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 656 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698