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

Side by Side Diff: Source/bindings/scripts/unstable/v8_methods.py

Issue 114693005: IDL compiler: sync Python to r164407 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simpler Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/templates/interface.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 43
44 def generate_method(interface, method): 44 def generate_method(interface, method):
45 arguments = method.arguments 45 arguments = method.arguments
46 extended_attributes = method.extended_attributes 46 extended_attributes = method.extended_attributes
47 idl_type = method.idl_type 47 idl_type = method.idl_type
48 is_static = method.is_static 48 is_static = method.is_static
49 name = method.name 49 name = method.name
50 50
51 this_cpp_value = cpp_value(interface, method, len(arguments)) 51 this_cpp_value = cpp_value(interface, method, len(arguments))
52 this_custom_signature = custom_signature(method, arguments)
53 52
54 def function_template(): 53 def function_template():
55 if is_static: 54 if is_static:
56 return 'functionTemplate' 55 return 'functionTemplate'
57 if 'Unforgeable' in extended_attributes: 56 if 'Unforgeable' in extended_attributes:
58 return 'instanceTemplate' 57 return 'instanceTemplate'
59 return 'prototypeTemplate' 58 return 'prototypeTemplate'
60 59
61 def signature():
62 if this_custom_signature:
63 return name + 'Signature'
64 if is_static or 'DoNotCheckSignature' in extended_attributes:
65 return 'v8::Local<v8::Signature>()'
66 return 'defaultSignature'
67
68 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments') 60 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments')
69 if is_call_with_script_arguments: 61 if is_call_with_script_arguments:
70 includes.update(['bindings/v8/ScriptCallStackFactory.h', 62 includes.update(['bindings/v8/ScriptCallStackFactory.h',
71 'core/inspector/ScriptArguments.h']) 63 'core/inspector/ScriptArguments.h'])
72 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') 64 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
73 if is_call_with_script_state: 65 if is_call_with_script_state:
74 includes.add('bindings/v8/ScriptState.h') 66 includes.add('bindings/v8/ScriptState.h')
75 is_check_security_for_node = 'CheckSecurity' in extended_attributes 67 is_check_security_for_node = 'CheckSecurity' in extended_attributes
76 if is_check_security_for_node: 68 if is_check_security_for_node:
77 includes.add('bindings/v8/BindingSecurity.h') 69 includes.add('bindings/v8/BindingSecurity.h')
(...skipping 10 matching lines...) Expand all
88 'DoNotCheckSecurity' not in extended_attributes) 80 'DoNotCheckSecurity' not in extended_attributes)
89 is_raises_exception = 'RaisesException' in extended_attributes 81 is_raises_exception = 'RaisesException' in extended_attributes
90 82
91 contents = { 83 contents = {
92 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 84 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
93 'arguments': [generate_argument(interface, method, argument, index) 85 'arguments': [generate_argument(interface, method, argument, index)
94 for index, argument in enumerate(arguments)], 86 for index, argument in enumerate(arguments)],
95 'conditional_string': v8_utilities.conditional_string(method), 87 'conditional_string': v8_utilities.conditional_string(method),
96 'cpp_type': v8_types.cpp_type(idl_type), 88 'cpp_type': v8_types.cpp_type(idl_type),
97 'cpp_value': this_cpp_value, 89 'cpp_value': this_cpp_value,
98 'custom_signature': this_custom_signature,
99 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 90 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
100 'do_not_check_signature': not(this_custom_signature or is_static or 91 'do_not_check_signature': not(is_static or
101 v8_utilities.has_extended_attribute(method, 92 v8_utilities.has_extended_attribute(method,
102 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', 93 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
103 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), 94 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
104 'function_template': function_template(), 95 'function_template': function_template(),
105 'idl_type': idl_type, 96 'idl_type': idl_type,
106 'has_exception_state': 97 'has_exception_state':
107 is_raises_exception or is_check_security_for_frame or 98 is_raises_exception or is_check_security_for_frame or
108 has_serialized_script_value_argument or 99 has_serialized_script_value_argument or
109 name in ['addEventListener', 'removeEventListener'], 100 name in ['addEventListener', 'removeEventListener'],
110 'has_serialized_script_value_argument': has_serialized_script_value_argu ment, 101 'has_serialized_script_value_argument': has_serialized_script_value_argu ment,
(...skipping 16 matching lines...) Expand all
127 'number_of_arguments': len(arguments), 118 'number_of_arguments': len(arguments),
128 'number_of_required_arguments': len([ 119 'number_of_required_arguments': len([
129 argument for argument in arguments 120 argument for argument in arguments
130 if not (argument.is_optional or argument.is_variadic)]), 121 if not (argument.is_optional or argument.is_variadic)]),
131 'number_of_required_or_variadic_arguments': len([ 122 'number_of_required_or_variadic_arguments': len([
132 argument for argument in arguments 123 argument for argument in arguments
133 if not argument.is_optional]), 124 if not argument.is_optional]),
134 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] 125 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled]
135 'property_attributes': property_attributes(method), 126 'property_attributes': property_attributes(method),
136 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 127 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
137 'signature': signature(), 128 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
138 'v8_set_return_value': v8_set_return_value(method, this_cpp_value), 129 'v8_set_return_value': v8_set_return_value(method, this_cpp_value),
139 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings] 130 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings]
140 } 131 }
141 return contents 132 return contents
142 133
143 134
144 def generate_argument(interface, method, argument, index): 135 def generate_argument(interface, method, argument, index):
145 extended_attributes = argument.extended_attributes 136 extended_attributes = argument.extended_attributes
146 idl_type = argument.idl_type 137 idl_type = argument.idl_type
147 this_cpp_value = cpp_value(interface, method, index) 138 this_cpp_value = cpp_value(interface, method, index)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 def v8_set_return_value(method, cpp_value): 176 def v8_set_return_value(method, cpp_value):
186 idl_type = method.idl_type 177 idl_type = method.idl_type
187 if idl_type == 'void': 178 if idl_type == 'void':
188 return None 179 return None
189 # [CallWith=ScriptState] 180 # [CallWith=ScriptState]
190 if has_extended_attribute_value(method, 'CallWith', 'ScriptState'): 181 if has_extended_attribute_value(method, 'CallWith', 'ScriptState'):
191 cpp_value = 'result' # use local variable for value 182 cpp_value = 'result' # use local variable for value
192 return v8_types.v8_set_return_value(idl_type, cpp_value, method.extended_att ributes) 183 return v8_types.v8_set_return_value(idl_type, cpp_value, method.extended_att ributes)
193 184
194 185
195 def custom_signature(method, arguments):
196 def argument_template(argument):
197 idl_type = argument.idl_type
198 if (v8_types.is_wrapper_type(idl_type) and
199 not v8_types.is_typed_array_type(idl_type) and
200 # Compatibility: all other browsers accepts a callable for
201 # XPathNSResolver, despite it being against spec.
202 not idl_type == 'XPathNSResolver'):
203 return 'V8PerIsolateData::from(isolate)->rawDOMTemplate(&V8{idl_type }::wrapperTypeInfo, currentWorldType)'.format(idl_type=idl_type)
204 return 'v8::Handle<v8::FunctionTemplate>()'
205
206 if (any(argument.is_optional and
207 'Default' not in argument.extended_attributes
208 for argument in arguments) or
209 all(not v8_types.is_wrapper_type(argument.idl_type)
210 for argument in arguments) or
211 # For [StrictTypeChecking], type checking is done in the generated code
212 'StrictTypeChecking' in method.extended_attributes):
213 return None
214 return ', '.join([argument_template(argument) for argument in arguments])
215
216
217 # [NotEnumerable] 186 # [NotEnumerable]
218 def property_attributes(method): 187 def property_attributes(method):
219 extended_attributes = method.extended_attributes 188 extended_attributes = method.extended_attributes
220 property_attributes_list = [] 189 property_attributes_list = []
221 if 'NotEnumerable' in extended_attributes: 190 if 'NotEnumerable' in extended_attributes:
222 property_attributes_list.append('v8::DontEnum') 191 property_attributes_list.append('v8::DontEnum')
223 if 'ReadOnly' in extended_attributes: 192 if 'ReadOnly' in extended_attributes:
224 property_attributes_list.append('v8::ReadOnly') 193 property_attributes_list.append('v8::ReadOnly')
225 if property_attributes_list: 194 if property_attributes_list:
226 property_attributes_list.insert(0, 'v8::DontDelete') 195 property_attributes_list.insert(0, 'v8::DontDelete')
227 return property_attributes_list 196 return property_attributes_list
228 197
229 198
230 def v8_value_to_local_cpp_value(argument, index): 199 def v8_value_to_local_cpp_value(argument, index):
231 extended_attributes = argument.extended_attributes 200 extended_attributes = argument.extended_attributes
232 idl_type = argument.idl_type 201 idl_type = argument.idl_type
233 name = argument.name 202 name = argument.name
234 if argument.is_variadic: 203 if argument.is_variadic:
235 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c pp_type}>(info, {index}))'.format( 204 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c pp_type}>(info, {index}))'.format(
236 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) 205 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index)
237 # [Default=NullString] 206 # [Default=NullString]
238 if (argument.is_optional and idl_type == 'DOMString' and 207 if (argument.is_optional and idl_type == 'DOMString' and
239 extended_attributes.get('Default') == 'NullString'): 208 extended_attributes.get('Default') == 'NullString'):
240 v8_value = 'argumentOrNull(info, %s)' % index 209 v8_value = 'argumentOrNull(info, %s)' % index
241 else: 210 else:
242 v8_value = 'info[%s]' % index 211 v8_value = 'info[%s]' % index
243 return v8_types.v8_value_to_local_cpp_value( 212 return v8_types.v8_value_to_local_cpp_value(
244 idl_type, argument.extended_attributes, v8_value, name, index=index) 213 idl_type, argument.extended_attributes, v8_value, name, index=index)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/templates/interface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698