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

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

Issue 1181113006: bindings: Introduces on_{instance,prototype,interface} in the code generator. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed review comments. Created 5 years, 6 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 | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/attributes.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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 219
220 220
221 def conditional_string(definition_or_member): 221 def conditional_string(definition_or_member):
222 extended_attributes = definition_or_member.extended_attributes 222 extended_attributes = definition_or_member.extended_attributes
223 if 'Conditional' not in extended_attributes: 223 if 'Conditional' not in extended_attributes:
224 return None 224 return None
225 return 'ENABLE(%s)' % extended_attributes['Conditional'] 225 return 'ENABLE(%s)' % extended_attributes['Conditional']
226 226
227 227
228 # [Constructor], [NamedConstructor]
229 def is_constructor_attribute(member):
230 # TODO(yukishiino): replace this with [Constructor] and [NamedConstructor] e xtended attribute
231 return member.idl_type.name.endswith('Constructor')
232
233
228 # [DeprecateAs] 234 # [DeprecateAs]
229 def deprecate_as(member): 235 def deprecate_as(member):
230 extended_attributes = member.extended_attributes 236 extended_attributes = member.extended_attributes
231 if 'DeprecateAs' not in extended_attributes: 237 if 'DeprecateAs' not in extended_attributes:
232 return None 238 return None
233 includes.add('core/frame/UseCounter.h') 239 includes.add('core/frame/UseCounter.h')
234 return extended_attributes['DeprecateAs'] 240 return extended_attributes['DeprecateAs']
235 241
236 242
237 # [Exposed] 243 # [Exposed]
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 403
398 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] 404 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking]
399 def is_legacy_interface_type_checking(interface, member): 405 def is_legacy_interface_type_checking(interface, member):
400 if not ('TypeChecking' in interface.extended_attributes or 406 if not ('TypeChecking' in interface.extended_attributes or
401 'TypeChecking' in member.extended_attributes): 407 'TypeChecking' in member.extended_attributes):
402 return True 408 return True
403 if 'LegacyInterfaceTypeChecking' in member.extended_attributes: 409 if 'LegacyInterfaceTypeChecking' in member.extended_attributes:
404 return True 410 return True
405 return False 411 return False
406 412
413
414 # [Unforgeable], [Global], [PrimaryGlobal] and [DoNotExposeJSAccessors]
415 def on_instance(interface, member):
416 """Returns True if the interface's member needs to be defined on every
417 instance object.
418
419 The following members must be defiend on an instance object.
420 - [Unforgeable] members
421 - regular members of [Global] or [PrimaryGlobal] interfaces
422 - members on which [DoNotExposeJSAccessors] is specified
423 """
424 # TODO(yukishiino): Implement this function following the spec.
425 return not on_prototype(interface, member)
426
427
428 # [ExposeJSAccessors]
429 def on_prototype(interface, member):
430 """Returns True if the interface's member needs to be defined on the
431 prototype object.
432
433 Most members are defined on the prototype object. Exceptions are as
434 follows.
435 - constant members
436 - static members (optional)
437 - [Unforgeable] members
438 - members of [Global] or [PrimaryGlobal] interfaces
439 - named properties of [Global] or [PrimaryGlobal] interfaces
440 However, if [ExposeJSAccessors] is specified, the member is defined on the
441 prototype object.
442 """
443 # TODO(yukishiino): Implement this function following the spec.
444
445 if ('ExposeJSAccessors' in interface.extended_attributes and
446 'DoNotExposeJSAccessors' in interface.extended_attributes):
447 raise Exception('Both of ExposeJSAccessors and DoNotExposeJSAccessors ar e specified at a time in an interface: ' + interface.name)
448 if ('ExposeJSAccessors' in member.extended_attributes and
449 'DoNotExposeJSAccessors' in member.extended_attributes):
450 raise Exception('Both of ExposeJSAccessors and DoNotExposeJSAccessors ar e specified at a time on a member: ' + member.name + ' in an interface: ' + inte rface.name)
451
452 # Note that ExposeJSAccessors and DoNotExposeJSAccessors are more powerful
453 # than 'static', [Unforgeable] and [OverrideBuiltins].
454 if 'ExposeJSAccessors' in member.extended_attributes:
455 return True
456 if 'DoNotExposeJSAccessors' in member.extended_attributes:
457 return False
458
459 # These members must not be placed on prototype chains.
460 if (is_constructor_attribute(member) or
461 member.is_static or
462 is_unforgeable(interface, member) or
463 'OverrideBuiltins' in interface.extended_attributes):
464 return False
465
466 # TODO(yukishiino): We should handle [Global] and [PrimaryGlobal] instead of
467 # Window.
468 if (interface.name == 'Window'):
469 return member.idl_type.name == 'EventHandler'
470
471 # TODO(yukishiino): We should move all of the following members to prototype
472 # chains.
473 if 'Custom' in member.extended_attributes:
474 return False
475
476 if 'ExposeJSAccessors' in interface.extended_attributes:
477 return True
478 if 'DoNotExposeJSAccessors' in interface.extended_attributes:
479 return False
480
481 return True
482
483
484 # static, const
485 def on_interface(interface, member):
486 """Returns True if the interface's member needs to be defined on the
487 interface object.
488
489 The following members must be defiend on an interface object.
490 - constant members
491 - static members
492 """
493 # TODO(yukishiino): Implement this function following the spec.
494 return False
495
496
407 ################################################################################ 497 ################################################################################
408 # Indexed properties 498 # Indexed properties
409 # http://heycam.github.io/webidl/#idl-indexed-properties 499 # http://heycam.github.io/webidl/#idl-indexed-properties
410 ################################################################################ 500 ################################################################################
411 501
412 def indexed_property_getter(interface): 502 def indexed_property_getter(interface):
413 try: 503 try:
414 # Find indexed property getter, if present; has form: 504 # Find indexed property getter, if present; has form:
415 # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1) 505 # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1)
416 return next( 506 return next(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 except StopIteration: 589 except StopIteration:
500 return None 590 return None
501 591
502 592
503 IdlInterface.indexed_property_getter = property(indexed_property_getter) 593 IdlInterface.indexed_property_getter = property(indexed_property_getter)
504 IdlInterface.indexed_property_setter = property(indexed_property_setter) 594 IdlInterface.indexed_property_setter = property(indexed_property_setter)
505 IdlInterface.indexed_property_deleter = property(indexed_property_deleter) 595 IdlInterface.indexed_property_deleter = property(indexed_property_deleter)
506 IdlInterface.named_property_getter = property(named_property_getter) 596 IdlInterface.named_property_getter = property(named_property_getter)
507 IdlInterface.named_property_setter = property(named_property_setter) 597 IdlInterface.named_property_setter = property(named_property_setter)
508 IdlInterface.named_property_deleter = property(named_property_deleter) 598 IdlInterface.named_property_deleter = property(named_property_deleter)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698