Chromium Code Reviews| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}))' | 516 expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_ type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}))' |
| 517 add_includes_for_type(native_array_element_type) | 517 add_includes_for_type(native_array_element_type) |
| 518 else: | 518 else: |
| 519 ref_ptr_type = None | 519 ref_ptr_type = None |
| 520 this_cpp_type = native_array_element_type.cpp_type | 520 this_cpp_type = native_array_element_type.cpp_type |
| 521 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso late})' | 521 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso late})' |
| 522 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) | 522 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) |
| 523 return expression | 523 return expression |
| 524 | 524 |
| 525 | 525 |
| 526 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): | 526 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, async=False): |
| 527 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" | 527 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" |
| 528 | 528 |
| 529 # FIXME: Support union type. | 529 # FIXME: Support union type. |
| 530 if idl_type.is_union_type: | 530 if idl_type.is_union_type: |
| 531 return '' | 531 return '' |
| 532 | 532 |
| 533 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) | 533 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) |
| 534 | 534 |
| 535 idl_type = idl_type.preprocessed_type | 535 idl_type = idl_type.preprocessed_type |
| 536 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) | 536 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) |
| 537 args = [variable_name, cpp_value] | 537 args = [variable_name, cpp_value] |
| 538 if idl_type.base_type == 'DOMString' and not idl_type.native_array_element_t ype: | 538 if idl_type.base_type == 'DOMString' and not idl_type.native_array_element_t ype: |
| 539 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID ' | 539 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID ' |
| 540 elif idl_type.may_raise_exception_on_conversion: | 540 elif idl_type.may_raise_exception_on_conversion: |
| 541 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' | 541 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' |
| 542 args.append('exceptionState') | 542 args.append('exceptionState') |
| 543 else: | 543 else: |
| 544 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID ' | 544 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID ' |
| 545 | 545 |
| 546 if used_in_private_script: | 546 if used_in_private_script: |
| 547 args.append('false') | 547 args.append('false') |
| 548 | 548 |
| 549 # Macros come in several variants, to minimize expensive creation of | 549 # Macros come in several variants, to minimize expensive creation of |
| 550 # v8::TryCatch. | 550 # v8::TryCatch. |
| 551 suffix = '' | 551 suffix = '' |
| 552 | 552 |
| 553 if async: | |
| 554 suffix += '_ASYNC' | |
| 555 args.append('info') | |
| 556 if macro == 'TONATIVE_VOID_EXCEPTIONSTATE': | |
|
haraken
2014/07/31 07:54:47
A slightly better condition would be:
if idl_ty
yhirano
2014/08/01 02:27:57
That condition can be true when macro is 'TOSTRING
| |
| 557 args.insert(0, 'ScriptState::current(%s)' % isolate) | |
|
haraken
2014/07/31 07:54:47
Can we move the ScriptState argument to the last a
yhirano
2014/08/01 02:27:57
Done.
| |
| 558 | |
| 553 if declare_variable: | 559 if declare_variable: |
| 554 args.insert(0, this_cpp_type) | 560 args.insert(0, this_cpp_type) |
| 555 else: | 561 else: |
| 556 suffix += '_INTERNAL' | 562 suffix += '_INTERNAL' |
| 557 | 563 |
| 558 return '%s(%s)' % (macro + suffix, ', '.join(args)) | 564 return '%s(%s)' % (macro + suffix, ', '.join(args)) |
| 559 | 565 |
| 560 | 566 |
| 561 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 567 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| 562 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 568 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 | 804 |
| 799 def is_explicit_nullable(idl_type): | 805 def is_explicit_nullable(idl_type): |
| 800 # Nullable type that isn't implicit nullable (see above.) For such types, | 806 # Nullable type that isn't implicit nullable (see above.) For such types, |
| 801 # we use Nullable<T> or similar explicit ways to represent a null value. | 807 # we use Nullable<T> or similar explicit ways to represent a null value. |
| 802 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 808 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
| 803 | 809 |
| 804 IdlType.is_implicit_nullable = property(is_implicit_nullable) | 810 IdlType.is_implicit_nullable = property(is_implicit_nullable) |
| 805 IdlType.is_explicit_nullable = property(is_explicit_nullable) | 811 IdlType.is_explicit_nullable = property(is_explicit_nullable) |
| 806 IdlUnionType.is_implicit_nullable = False | 812 IdlUnionType.is_implicit_nullable = False |
| 807 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) | 813 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) |
| OLD | NEW |