| 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 27 matching lines...) Expand all Loading... |
| 38 from v8_globals import includes | 38 from v8_globals import includes |
| 39 import v8_types | 39 import v8_types |
| 40 import v8_utilities | 40 import v8_utilities |
| 41 | 41 |
| 42 CALLBACK_INTERFACE_H_INCLUDES = set([ | 42 CALLBACK_INTERFACE_H_INCLUDES = set([ |
| 43 'bindings/v8/ActiveDOMCallback.h', | 43 'bindings/v8/ActiveDOMCallback.h', |
| 44 'bindings/v8/DOMWrapperWorld.h', | 44 'bindings/v8/DOMWrapperWorld.h', |
| 45 'bindings/v8/ScopedPersistent.h', | 45 'bindings/v8/ScopedPersistent.h', |
| 46 ]) | 46 ]) |
| 47 CALLBACK_INTERFACE_CPP_INCLUDES = set([ | 47 CALLBACK_INTERFACE_CPP_INCLUDES = set([ |
| 48 'core/dom/ExecutionContext.h', | |
| 49 'bindings/v8/V8Binding.h', | 48 'bindings/v8/V8Binding.h', |
| 50 'bindings/v8/V8Callback.h', | 49 'bindings/v8/V8Callback.h', |
| 50 'core/dom/ExecutionContext.h', |
| 51 'wtf/Assertions.h', | 51 'wtf/Assertions.h', |
| 52 ]) | 52 ]) |
| 53 | 53 |
| 54 | 54 |
| 55 def cpp_to_v8_conversion(idl_type, name): | 55 def cpp_to_v8_conversion(idl_type, name): |
| 56 # FIXME: setting creation_context=v8::Handle<v8::Object>() is wrong, | 56 # FIXME: setting creation_context=v8::Handle<v8::Object>() is wrong, |
| 57 # as toV8 then implicitly uses the current context, which causes leaks | 57 # as toV8 then implicitly uses the current context, which causes leaks |
| 58 # between isolate worlds if a different context should be used. | 58 # between isolate worlds if a different context should be used. |
| 59 cpp_value_to_v8_value = v8_types.cpp_value_to_v8_value(idl_type, name, | 59 cpp_value_to_v8_value = v8_types.cpp_value_to_v8_value(idl_type, name, |
| 60 isolate='isolate', creation_context='v8::Handle<v8::Object>()') | 60 isolate='isolate', creation_context='v8::Handle<v8::Object>()') |
| 61 return 'v8::Handle<v8::Value> {name}Handle = {cpp_to_v8};'.format( | 61 return 'v8::Handle<v8::Value> {name}Handle = {cpp_to_v8};'.format( |
| 62 name=name, cpp_to_v8=cpp_value_to_v8_value) | 62 name=name, cpp_to_v8=cpp_value_to_v8_value) |
| 63 | 63 |
| 64 | 64 |
| 65 def cpp_type(idl_type): | 65 def cpp_type(idl_type): |
| 66 # FIXME: remove this function by making callback types consistent | 66 # FIXME: remove this function by making callback types consistent |
| 67 # (always use usual v8_types.cpp_type) | 67 # (always use usual v8_types.cpp_type) |
| 68 if idl_type == 'DOMString': | 68 if idl_type == 'DOMString': |
| 69 return 'const String&' | 69 return 'const String&' |
| 70 if idl_type == 'void': |
| 71 return 'void' |
| 70 # Callbacks use raw pointers, so used_as_argument=True | 72 # Callbacks use raw pointers, so used_as_argument=True |
| 71 usual_cpp_type = v8_types.cpp_type(idl_type, used_as_argument=True) | 73 usual_cpp_type = v8_types.cpp_type(idl_type, used_as_argument=True) |
| 72 if usual_cpp_type.startswith('Vector'): | 74 if usual_cpp_type.startswith('Vector'): |
| 73 return 'const %s&' % usual_cpp_type | 75 return 'const %s&' % usual_cpp_type |
| 74 return usual_cpp_type | 76 return usual_cpp_type |
| 75 | 77 |
| 76 | 78 |
| 77 def generate_callback_interface(callback_interface): | 79 def generate_callback_interface(callback_interface): |
| 78 includes.clear() | 80 includes.clear() |
| 79 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) | 81 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 93 | 95 |
| 94 def add_includes_for_operation(operation): | 96 def add_includes_for_operation(operation): |
| 95 v8_types.add_includes_for_type(operation.idl_type) | 97 v8_types.add_includes_for_type(operation.idl_type) |
| 96 for argument in operation.arguments: | 98 for argument in operation.arguments: |
| 97 v8_types.add_includes_for_type(argument.idl_type) | 99 v8_types.add_includes_for_type(argument.idl_type) |
| 98 | 100 |
| 99 | 101 |
| 100 def generate_method(operation): | 102 def generate_method(operation): |
| 101 extended_attributes = operation.extended_attributes | 103 extended_attributes = operation.extended_attributes |
| 102 idl_type = operation.idl_type | 104 idl_type = operation.idl_type |
| 103 if idl_type != 'boolean': | 105 if idl_type not in ['boolean', 'void']: |
| 104 raise Exception("We don't yet support callbacks that return non-boolean
values.") | 106 raise Exception('We only support callbacks that return boolean or void v
alues.') |
| 105 is_custom = 'Custom' in extended_attributes | 107 is_custom = 'Custom' in extended_attributes |
| 106 if not is_custom: | 108 if not is_custom: |
| 107 add_includes_for_operation(operation) | 109 add_includes_for_operation(operation) |
| 108 call_with = extended_attributes.get('CallWith') | 110 call_with = extended_attributes.get('CallWith') |
| 109 call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_
with, 'ThisValue') | 111 call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_
with, 'ThisValue') |
| 110 contents = { | 112 contents = { |
| 111 'call_with_this_handle': call_with_this_handle, | 113 'call_with_this_handle': call_with_this_handle, |
| 112 'custom': is_custom, | 114 'custom': is_custom, |
| 113 'name': operation.name, | 115 'name': operation.name, |
| 114 'return_cpp_type': cpp_type(idl_type), | 116 'return_cpp_type': cpp_type(idl_type), |
| 117 'return_idl_type': idl_type, |
| 115 } | 118 } |
| 116 contents.update(generate_arguments_contents(operation.arguments, call_with_t
his_handle)) | 119 contents.update(generate_arguments_contents(operation.arguments, call_with_t
his_handle)) |
| 117 return contents | 120 return contents |
| 118 | 121 |
| 119 | 122 |
| 120 def generate_arguments_contents(arguments, call_with_this_handle): | 123 def generate_arguments_contents(arguments, call_with_this_handle): |
| 121 def generate_argument(argument): | 124 def generate_argument(argument): |
| 122 return { | 125 return { |
| 123 'name': argument.name, | 126 'name': argument.name, |
| 124 'cpp_to_v8_conversion': cpp_to_v8_conversion(argument.idl_type, argu
ment.name), | 127 'cpp_to_v8_conversion': cpp_to_v8_conversion(argument.idl_type, argu
ment.name), |
| 125 } | 128 } |
| 126 | 129 |
| 127 argument_declarations = [ | 130 argument_declarations = [ |
| 128 '%s %s' % (cpp_type(argument.idl_type), argument.name) | 131 '%s %s' % (cpp_type(argument.idl_type), argument.name) |
| 129 for argument in arguments] | 132 for argument in arguments] |
| 130 if call_with_this_handle: | 133 if call_with_this_handle: |
| 131 argument_declarations.insert(0, 'ScriptValue thisValue') | 134 argument_declarations.insert(0, 'ScriptValue thisValue') |
| 132 return { | 135 return { |
| 133 'argument_declarations': argument_declarations, | 136 'argument_declarations': argument_declarations, |
| 134 'arguments': [generate_argument(argument) for argument in arguments], | 137 'arguments': [generate_argument(argument) for argument in arguments], |
| 135 'handles': ['%sHandle' % argument.name for argument in arguments], | 138 'handles': ['%sHandle' % argument.name for argument in arguments], |
| 136 } | 139 } |
| OLD | NEW |