OLD | NEW |
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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 elif idl_type.may_raise_exception_on_conversion: | 492 elif idl_type.may_raise_exception_on_conversion: |
493 arguments = ', '.join([v8_value, 'exceptionState']) | 493 arguments = ', '.join([v8_value, 'exceptionState']) |
494 else: | 494 else: |
495 arguments = v8_value | 495 arguments = v8_value |
496 | 496 |
497 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 497 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
498 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 498 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
499 elif idl_type.is_typed_array_element_type: | 499 elif idl_type.is_typed_array_element_type: |
500 cpp_expression_format = ( | 500 cpp_expression_format = ( |
501 '{v8_value}->Is{idl_type}() ? ' | 501 '{v8_value}->Is{idl_type}() ? ' |
502 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})
) : 0') | 502 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value}))
: 0') |
503 elif idl_type.is_dictionary: | 503 elif idl_type.is_dictionary: |
504 cpp_expression_format = 'V8{idl_type}::toNative({isolate}, {v8_value})' | 504 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value})' |
505 else: | 505 else: |
506 cpp_expression_format = ( | 506 cpp_expression_format = ( |
507 'V8{idl_type}::toNativeWithTypeCheck({isolate}, {v8_value})') | 507 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') |
508 | 508 |
509 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value, isolate=isolate) | 509 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value, isolate=isolate) |
510 | 510 |
511 | 511 |
512 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value,
index, isolate='info.GetIsolate()'): | 512 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value,
index, isolate='info.GetIsolate()'): |
513 # Index is None for setters, index (starting at 0) for method arguments, | 513 # Index is None for setters, index (starting at 0) for method arguments, |
514 # and is used to provide a human-readable exception message | 514 # and is used to provide a human-readable exception message |
515 if index is None: | 515 if index is None: |
516 index = 0 # special case, meaning "setter" | 516 index = 0 # special case, meaning "setter" |
517 else: | 517 else: |
518 index += 1 # human-readable index | 518 index += 1 # human-readable index |
519 if (native_array_element_type.is_interface_type and | 519 if (native_array_element_type.is_interface_type and |
520 native_array_element_type.name != 'Dictionary'): | 520 native_array_element_type.name != 'Dictionary'): |
521 this_cpp_type = None | 521 this_cpp_type = None |
522 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ
e.gc_type) | 522 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ
e.gc_type) |
523 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_
type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}))' | 523 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_
type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}))' |
524 add_includes_for_type(native_array_element_type) | 524 add_includes_for_type(native_array_element_type) |
525 else: | 525 else: |
526 ref_ptr_type = None | 526 ref_ptr_type = None |
527 this_cpp_type = native_array_element_type.cpp_type | 527 this_cpp_type = native_array_element_type.cpp_type |
528 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso
late})' | 528 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola
te})' |
529 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) | 529 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) |
530 return expression | 530 return expression |
531 | 531 |
532 | 532 |
533 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): | 533 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): |
534 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 534 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
535 | 535 |
536 # FIXME: Support union type. | 536 # FIXME: Support union type. |
537 if idl_type.is_union_type: | 537 if idl_type.is_union_type: |
538 return '' | 538 return '' |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 812 |
813 | 813 |
814 def is_explicit_nullable(idl_type): | 814 def is_explicit_nullable(idl_type): |
815 # Nullable type that isn't implicit nullable (see above.) For such types, | 815 # Nullable type that isn't implicit nullable (see above.) For such types, |
816 # we use Nullable<T> or similar explicit ways to represent a null value. | 816 # we use Nullable<T> or similar explicit ways to represent a null value. |
817 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 817 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
818 | 818 |
819 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) | 819 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) |
820 IdlUnionType.is_implicit_nullable = False | 820 IdlUnionType.is_implicit_nullable = False |
821 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 821 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
OLD | NEW |