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

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

Issue 304223007: Use auto-rethrowing v8::TryCatch variant (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: make constructors explicit Created 6 years, 6 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
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/methods.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' 436 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))'
437 add_includes_for_type(array_or_sequence_type) 437 add_includes_for_type(array_or_sequence_type)
438 else: 438 else:
439 ref_ptr_type = None 439 ref_ptr_type = None
440 this_cpp_type = array_or_sequence_type.cpp_type 440 this_cpp_type = array_or_sequence_type.cpp_type
441 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' 441 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())'
442 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) 442 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)
443 return expression 443 return expression
444 444
445 445
446 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): 446 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True):
447 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 447 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
448 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) 448 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True)
449 449
450 idl_type = idl_type.preprocessed_type 450 idl_type = idl_type.preprocessed_type
451 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 451 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex)
452 args = [variable_name, cpp_value] 452 args = [variable_name, cpp_value]
453 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 453 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
454 macro = 'TOSTRING_VOID' 454 macro = 'TOSTRING_VOID'
455 elif idl_type.is_integer_type: 455 elif idl_type.is_integer_type:
456 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 456 macro = 'TONATIVE_VOID_EXCEPTIONSTATE'
457 args.append('exceptionState') 457 args.append('exceptionState')
458 else: 458 else:
459 macro = 'TONATIVE_VOID' 459 macro = 'TONATIVE_VOID'
460 460
461 # Macros come in several variants, to minimize expensive creation of 461 # Macros come in several variants, to minimize expensive creation of
462 # v8::TryCatch. 462 # v8::TryCatch.
463 suffix = '' 463 suffix = ''
464 464
465 if declare_variable: 465 if declare_variable:
466 args.insert(0, this_cpp_type) 466 args.insert(0, this_cpp_type)
467 else: 467 else:
468 suffix += '_INTERNAL' 468 suffix += '_INTERNAL'
469 469
470 # The TOSTRING_VOID_INTERNAL macro comes in two flavors; use the right one
471 # depending on whether the containing method has a v8::TryCatch local
472 # (named 'block') declared or not. If there is such a local, use the block
473 # for avoiding declaring another one for performance and propagate the
474 # exception.
475 if (macro == 'TOSTRING_VOID' and not declare_variable and
476 not method_has_try_catch):
477 suffix += '_NOTRYCATCH'
478
479 return '%s(%s)' % (macro + suffix, ', '.join(args)) 470 return '%s(%s)' % (macro + suffix, ', '.join(args))
480 471
481 472
482 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 473 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
483 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 474 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
484 475
485 476
486 ################################################################################ 477 ################################################################################
487 # C++ -> V8 478 # C++ -> V8
488 ################################################################################ 479 ################################################################################
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): 663 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None):
673 """Returns an expression that converts a C++ value to a V8 value.""" 664 """Returns an expression that converts a C++ value to a V8 value."""
674 # the isolate parameter is needed for callback interfaces 665 # the isolate parameter is needed for callback interfaces
675 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 666 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
676 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 667 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
677 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 668 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
678 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 669 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
679 return statement 670 return statement
680 671
681 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 672 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/methods.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698