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

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

Issue 808373002: IDL: Simplify [TypeChecking=Interface] code generation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 extended_attributes = argument.extended_attributes 191 extended_attributes = argument.extended_attributes
192 idl_type = argument.idl_type 192 idl_type = argument.idl_type
193 this_cpp_value = cpp_value(interface, method, index) 193 this_cpp_value = cpp_value(interface, method, index)
194 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 194 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
195 195
196 type_checking_interface = ( 196 type_checking_interface = (
197 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or 197 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or
198 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and 198 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
199 idl_type.is_wrapper_type) 199 idl_type.is_wrapper_type)
200 200
201 type_checked = (type_checking_interface and
202 # These allow null and undefined values, so a type-check is still required.
203 not idl_type.is_nullable and
204 not (argument.is_optional and
205 'Default' in extended_attributes))
206
207 if ('ImplementedInPrivateScript' in extended_attributes and 201 if ('ImplementedInPrivateScript' in extended_attributes and
208 not idl_type.is_wrapper_type and 202 not idl_type.is_wrapper_type and
209 not idl_type.is_basic_type): 203 not idl_type.is_basic_type):
210 raise Exception('Private scripts supports only primitive types and DOM w rappers.') 204 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
211 205
212 set_default_value = argument.set_default_value 206 set_default_value = argument.set_default_value
213 return { 207 return {
214 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, 208 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
215 raw_type=True, 209 raw_type=True,
216 used_as_variadic_argument=argument.is _variadic), 210 used_as_variadic_argument=argument.is _variadic),
(...skipping 21 matching lines...) Expand all
238 'is_variadic': argument.is_variadic, 232 'is_variadic': argument.is_variadic,
239 'is_variadic_wrapper_type': is_variadic_wrapper_type, 233 'is_variadic_wrapper_type': is_variadic_wrapper_type,
240 'is_wrapper_type': idl_type.is_wrapper_type, 234 'is_wrapper_type': idl_type.is_wrapper_type,
241 'name': argument.name, 235 'name': argument.name,
242 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 236 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
243 argument.name, isolate='scriptState->isolate()', 237 argument.name, isolate='scriptState->isolate()',
244 creation_context='scriptState->context()->Global()'), 238 creation_context='scriptState->context()->Global()'),
245 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in extended_attributes, 239 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in extended_attributes,
246 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 240 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
247 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 241 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
248 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, type_checked, return_promise=method.returns_promise), 242 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, return_promise=method.returns_promise),
249 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), 243 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
250 } 244 }
251 245
252 246
253 def argument_declarations_for_private_script(interface, method): 247 def argument_declarations_for_private_script(interface, method):
254 argument_declarations = ['LocalFrame* frame'] 248 argument_declarations = ['LocalFrame* frame']
255 argument_declarations.append('%s* holderImpl' % interface.name) 249 argument_declarations.append('%s* holderImpl' % interface.name)
256 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( 250 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
257 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts]) 251 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts])
258 if method.idl_type.name != 'void': 252 if method.idl_type.name != 'void':
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 359
366 if return_promise: 360 if return_promise:
367 suffix += '_PROMISE' 361 suffix += '_PROMISE'
368 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) 362 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())'])
369 363
370 suffix += '_INTERNAL' 364 suffix += '_INTERNAL'
371 365
372 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) 366 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args))
373 367
374 368
375 def v8_value_to_local_cpp_value(argument, index, type_checked, return_promise=Fa lse): 369 def v8_value_to_local_cpp_value(argument, index, return_promise=False):
376 extended_attributes = argument.extended_attributes 370 extended_attributes = argument.extended_attributes
377 idl_type = argument.idl_type 371 idl_type = argument.idl_type
378 name = argument.name 372 name = argument.name
379 if argument.is_variadic: 373 if argument.is_variadic:
380 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise) 374 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise)
381 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, 375 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
382 name, needs_type_check=not type_ checked, index=index, declare_variable=False, return_promise=return_promise) 376 name, index=index, declare_varia ble=False,
377 return_promise=return_promise)
383 378
384 379
385 ################################################################################ 380 ################################################################################
386 # Auxiliary functions 381 # Auxiliary functions
387 ################################################################################ 382 ################################################################################
388 383
389 # [NotEnumerable] 384 # [NotEnumerable]
390 def property_attributes(method): 385 def property_attributes(method):
391 extended_attributes = method.extended_attributes 386 extended_attributes = method.extended_attributes
392 property_attributes_list = [] 387 property_attributes_list = []
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 437
443 IdlOperation.returns_promise = property(method_returns_promise) 438 IdlOperation.returns_promise = property(method_returns_promise)
444 439
445 440
446 def argument_conversion_needs_exception_state(method, argument): 441 def argument_conversion_needs_exception_state(method, argument):
447 idl_type = argument.idl_type 442 idl_type = argument.idl_type
448 return (idl_type.v8_conversion_needs_exception_state or 443 return (idl_type.v8_conversion_needs_exception_state or
449 argument.is_variadic or 444 argument.is_variadic or
450 (method.returns_promise and (idl_type.is_string_type or 445 (method.returns_promise and (idl_type.is_string_type or
451 idl_type.is_enum))) 446 idl_type.is_enum)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698