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

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

Issue 608853008: Canvas2D Performance: fix the bottleneck of hasInstance in JS binding -- TypeChecking Interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update code according to Jens's suggestions Created 6 years, 2 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/tests/idls/core/TestObject.idl » ('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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 494
495 def v8_conversion_is_trivial(idl_type): 495 def v8_conversion_is_trivial(idl_type):
496 # The conversion is a simple expression that returns the converted value and 496 # The conversion is a simple expression that returns the converted value and
497 # cannot raise an exception. 497 # cannot raise an exception.
498 return (idl_type.base_type in TRIVIAL_CONVERSIONS or 498 return (idl_type.base_type in TRIVIAL_CONVERSIONS or
499 idl_type.is_wrapper_type) 499 idl_type.is_wrapper_type)
500 500
501 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) 501 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial)
502 502
503 503
504 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat e): 504 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, needs_type_ch eck, index, isolate):
505 if idl_type.name == 'void': 505 if idl_type.name == 'void':
506 return '' 506 return ''
507 507
508 # Array or sequence types 508 # Array or sequence types
509 native_array_element_type = idl_type.native_array_element_type 509 native_array_element_type = idl_type.native_array_element_type
510 if native_array_element_type: 510 if native_array_element_type:
511 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index) 511 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index)
512 512
513 # Simple types 513 # Simple types
514 idl_type = idl_type.preprocessed_type 514 idl_type = idl_type.preprocessed_type
(...skipping 10 matching lines...) Expand all
525 arguments = v8_value 525 arguments = v8_value
526 526
527 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 527 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
528 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 528 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
529 elif idl_type.is_typed_array_element_type: 529 elif idl_type.is_typed_array_element_type:
530 cpp_expression_format = ( 530 cpp_expression_format = (
531 '{v8_value}->Is{idl_type}() ? ' 531 '{v8_value}->Is{idl_type}() ? '
532 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0') 532 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0')
533 elif idl_type.is_dictionary: 533 elif idl_type.is_dictionary:
534 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, exc eptionState)' 534 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, exc eptionState)'
535 elif needs_type_check:
536 cpp_expression_format = (
537 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
535 else: 538 else:
536 cpp_expression_format = ( 539 cpp_expression_format = (
537 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') 540 'V8{idl_type}::toImpl(v8::Handle<v8::Object>::Cast({v8_value}))')
538 541
539 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, isolate=isolate) 542 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, isolate=isolate)
540 543
541 544
542 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'): 545 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'):
543 # Index is None for setters, index (starting at 0) for method arguments, 546 # Index is None for setters, index (starting at 0) for method arguments,
544 # and is used to provide a human-readable exception message 547 # and is used to provide a human-readable exception message
545 if index is None: 548 if index is None:
546 index = 0 # special case, meaning "setter" 549 index = 0 # special case, meaning "setter"
547 else: 550 else:
548 index += 1 # human-readable index 551 index += 1 # human-readable index
549 if (native_array_element_type.is_interface_type and 552 if (native_array_element_type.is_interface_type and
550 native_array_element_type.name != 'Dictionary'): 553 native_array_element_type.name != 'Dictionary'):
551 this_cpp_type = None 554 this_cpp_type = None
552 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type) 555 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type)
553 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))' 556 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionS tate))'
554 add_includes_for_type(native_array_element_type) 557 add_includes_for_type(native_array_element_type)
555 else: 558 else:
556 ref_ptr_type = None 559 ref_ptr_type = None
557 this_cpp_type = native_array_element_type.cpp_type 560 this_cpp_type = native_array_element_type.cpp_type
558 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' 561 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)'
559 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate) 562 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate)
560 return expression 563 return expression
561 564
562 565
563 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', used_in_ private_script=False, return_promise=False): 566 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, needs_type_check=True, index=None, declare_variable=True, isolate='info. GetIsolate()', used_in_private_script=False, return_promise=False):
564 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 567 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
565 568
566 # FIXME: Support union type. 569 # FIXME: Support union type.
567 if idl_type.is_union_type: 570 if idl_type.is_union_type:
568 return '/* no V8 -> C++ conversion for IDL union type: %s */' % idl_type .name 571 return '/* no V8 -> C++ conversion for IDL union type: %s */' % idl_type .name
569 572
570 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) 573 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True)
571 idl_type = idl_type.preprocessed_type 574 idl_type = idl_type.preprocessed_type
572 575
573 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') : 576 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') :
574 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name 577 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name
575 578
576 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) 579 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, n eeds_type_check, index, isolate)
577 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: 580 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state:
578 # Types that need error handling and use one of a group of (C++) macros 581 # Types that need error handling and use one of a group of (C++) macros
579 # to take care of this. 582 # to take care of this.
580 583
581 args = [variable_name, cpp_value] 584 args = [variable_name, cpp_value]
582 585
583 if idl_type.v8_conversion_needs_exception_state: 586 if idl_type.v8_conversion_needs_exception_state:
584 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' 587 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE'
585 elif return_promise: 588 elif return_promise:
586 macro = 'TOSTRING_VOID_EXCEPTIONSTATE' 589 macro = 'TOSTRING_VOID_EXCEPTIONSTATE'
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 867
865 868
866 def is_explicit_nullable(idl_type): 869 def is_explicit_nullable(idl_type):
867 # Nullable type that isn't implicit nullable (see above.) For such types, 870 # Nullable type that isn't implicit nullable (see above.) For such types,
868 # we use Nullable<T> or similar explicit ways to represent a null value. 871 # we use Nullable<T> or similar explicit ways to represent a null value.
869 return idl_type.is_nullable and not idl_type.is_implicit_nullable 872 return idl_type.is_nullable and not idl_type.is_implicit_nullable
870 873
871 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) 874 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable)
872 IdlUnionType.is_implicit_nullable = False 875 IdlUnionType.is_implicit_nullable = False
873 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) 876 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698