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

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

Issue 608853008: Canvas2D Performance: fix the bottleneck of hasInstance in JS binding -- TypeChecking Interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: still use toImplWithTypeCheck for nullable arguments for [TypeChecking] methods Created 6 years, 2 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
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_types.py » ('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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 184 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
185 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], 185 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
186 } 186 }
187 187
188 188
189 def argument_context(interface, method, argument, index): 189 def argument_context(interface, method, argument, index):
190 extended_attributes = argument.extended_attributes 190 extended_attributes = argument.extended_attributes
191 idl_type = argument.idl_type 191 idl_type = argument.idl_type
192 this_cpp_value = cpp_value(interface, method, index) 192 this_cpp_value = cpp_value(interface, method, index)
193 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 193 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
194 type_checking_interface = (
195 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or
196 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
197 idl_type.is_wrapper_type)
194 198
195 if ('ImplementedInPrivateScript' in extended_attributes and 199 if ('ImplementedInPrivateScript' in extended_attributes and
196 not idl_type.is_wrapper_type and 200 not idl_type.is_wrapper_type and
197 not idl_type.is_basic_type): 201 not idl_type.is_basic_type):
198 raise Exception('Private scripts supports only primitive types and DOM w rappers.') 202 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
199 203
200 default_cpp_value = argument.default_cpp_value 204 default_cpp_value = argument.default_cpp_value
201 return { 205 return {
202 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, 206 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
203 raw_type=True, 207 raw_type=True,
204 used_as_variadic_argument=argument.is _variadic), 208 used_as_variadic_argument=argument.is _variadic),
205 'cpp_value': this_cpp_value, 209 'cpp_value': this_cpp_value,
206 # FIXME: check that the default value's type is compatible with the argu ment's 210 # FIXME: check that the default value's type is compatible with the argu ment's
207 'default_value': default_cpp_value, 211 'default_value': default_cpp_value,
208 'enum_validation_expression': idl_type.enum_validation_expression, 212 'enum_validation_expression': idl_type.enum_validation_expression,
209 'handle': '%sHandle' % argument.name, 213 'handle': '%sHandle' % argument.name,
210 # FIXME: remove once [Default] removed and just use argument.default_val ue 214 # FIXME: remove once [Default] removed and just use argument.default_val ue
211 'has_default': 'Default' in extended_attributes or default_cpp_value, 215 'has_default': 'Default' in extended_attributes or default_cpp_value,
212 'has_type_checking_interface': 216 'has_type_checking_interface': type_checking_interface,
213 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
214 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
215 idl_type.is_wrapper_type,
216 'has_type_checking_unrestricted': 217 'has_type_checking_unrestricted':
217 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or 218 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or
218 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and 219 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and
219 idl_type.name in ('Float', 'Double'), 220 idl_type.name in ('Float', 'Double'),
220 # Dictionary is special-cased, but arrays and sequences shouldn't be 221 # Dictionary is special-cased, but arrays and sequences shouldn't be
221 'idl_type': idl_type.base_type, 222 'idl_type': idl_type.base_type,
222 'idl_type_object': idl_type, 223 'idl_type_object': idl_type,
223 'index': index, 224 'index': index,
224 'is_callback_interface': idl_type.is_callback_interface, 225 'is_callback_interface': idl_type.is_callback_interface,
225 # FIXME: Remove generic 'Dictionary' special-casing 226 # FIXME: Remove generic 'Dictionary' special-casing
226 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio nary', 227 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio nary',
227 'is_nullable': idl_type.is_nullable, 228 'is_nullable': idl_type.is_nullable,
228 'is_optional': argument.is_optional, 229 'is_optional': argument.is_optional,
229 'is_variadic_wrapper_type': is_variadic_wrapper_type, 230 'is_variadic_wrapper_type': is_variadic_wrapper_type,
230 'is_wrapper_type': idl_type.is_wrapper_type, 231 'is_wrapper_type': idl_type.is_wrapper_type,
231 'name': argument.name, 232 'name': argument.name,
232 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 233 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
233 argument.name, isolate='scriptState->isolate()', 234 argument.name, isolate='scriptState->isolate()',
234 creation_context='scriptState->context()->Global()'), 235 creation_context='scriptState->context()->Global()'),
235 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 236 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
236 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 237 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
237 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, return_promise=method.returns_promise), 238 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, type_checking_interface and not idl_type.is_nullable, return_promise=method. returns_promise),
Jens Widell 2014/10/08 11:51:26 I propose to add type_checked = (type_checking_
yunchao 2014/10/09 04:54:07 Done.
238 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type), 239 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
239 } 240 }
240 241
241 242
242 def argument_declarations_for_private_script(interface, method): 243 def argument_declarations_for_private_script(interface, method):
243 argument_declarations = ['LocalFrame* frame'] 244 argument_declarations = ['LocalFrame* frame']
244 argument_declarations.append('%s* holderImpl' % interface.name) 245 argument_declarations.append('%s* holderImpl' % interface.name)
245 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( 246 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
246 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts]) 247 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts])
247 if method.idl_type.name != 'void': 248 if method.idl_type.name != 'void':
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 356
356 if return_promise: 357 if return_promise:
357 suffix += '_PROMISE' 358 suffix += '_PROMISE'
358 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) 359 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())'])
359 360
360 suffix += '_INTERNAL' 361 suffix += '_INTERNAL'
361 362
362 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) 363 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args))
363 364
364 365
365 def v8_value_to_local_cpp_value(argument, index, return_promise=False): 366 def v8_value_to_local_cpp_value(argument, index, type_checked, return_promise=Fa lse):
366 extended_attributes = argument.extended_attributes 367 extended_attributes = argument.extended_attributes
367 idl_type = argument.idl_type 368 idl_type = argument.idl_type
368 name = argument.name 369 name = argument.name
369 if argument.is_variadic: 370 if argument.is_variadic:
370 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise) 371 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise)
371 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, 372 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
372 name, index=index, declare_varia ble=False, return_promise=return_promise) 373 name, needs_type_check=not type_ checked, index=index, declare_variable=False, return_promise=return_promise)
373 374
374 375
375 ################################################################################ 376 ################################################################################
376 # Auxiliary functions 377 # Auxiliary functions
377 ################################################################################ 378 ################################################################################
378 379
379 # [NotEnumerable] 380 # [NotEnumerable]
380 def property_attributes(method): 381 def property_attributes(method):
381 extended_attributes = method.extended_attributes 382 extended_attributes = method.extended_attributes
382 property_attributes_list = [] 383 property_attributes_list = []
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 442
442 IdlOperation.returns_promise = property(method_returns_promise) 443 IdlOperation.returns_promise = property(method_returns_promise)
443 444
444 445
445 def argument_conversion_needs_exception_state(method, argument): 446 def argument_conversion_needs_exception_state(method, argument):
446 idl_type = argument.idl_type 447 idl_type = argument.idl_type
447 return (idl_type.v8_conversion_needs_exception_state or 448 return (idl_type.v8_conversion_needs_exception_state or
448 argument.is_variadic or 449 argument.is_variadic or
449 (method.returns_promise and (idl_type.is_string_type or 450 (method.returns_promise and (idl_type.is_string_type or
450 idl_type.is_enum))) 451 idl_type.is_enum)))
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698