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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 """Functions shared by various parts of the code generator. | 29 """Functions shared by various parts of the code generator. |
30 | 30 |
31 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 31 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
32 """ | 32 """ |
33 | 33 |
34 import re | 34 import re |
35 | 35 |
36 from idl_types import IdlTypeBase | 36 from idl_types import IdlTypeBase |
37 import idl_types | 37 import idl_types |
38 from idl_definitions import Exposure, IdlInterface, IdlAttribute, IdlOperation | 38 from idl_definitions import Exposure, IdlInterface, IdlAttribute |
39 from v8_globals import includes | 39 from v8_globals import includes |
40 | 40 |
41 ACRONYMS = [ | 41 ACRONYMS = [ |
42 'CSSOM', # must come *before* CSS to match full acronym | 42 'CSSOM', # must come *before* CSS to match full acronym |
43 'CSS', | 43 'CSS', |
44 'HTML', | 44 'HTML', |
45 'IME', | 45 'IME', |
46 'JS', | 46 'JS', |
47 'SVG', | 47 'SVG', |
48 'URL', | 48 'URL', |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 def scoped_name(interface, definition, base_name): | 119 def scoped_name(interface, definition, base_name): |
120 if 'ImplementedInPrivateScript' in definition.extended_attributes: | 120 if 'ImplementedInPrivateScript' in definition.extended_attributes: |
121 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) | 121 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) |
122 # partial interfaces are implemented as separate classes, with their members | 122 # partial interfaces are implemented as separate classes, with their members |
123 # implemented as static member functions | 123 # implemented as static member functions |
124 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') | 124 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') |
125 if partial_interface_implemented_as: | 125 if partial_interface_implemented_as: |
126 return '%s::%s' % (partial_interface_implemented_as, base_name) | 126 return '%s::%s' % (partial_interface_implemented_as, base_name) |
127 if (definition.is_static or | 127 if (definition.is_static or |
128 definition.name in ('Constructor', 'NamedConstructor')): | 128 definition.name in ('Constructor', 'NamedConstructor')): |
129 return '%s::%s' % (cpp_name(interface), base_name) | 129 return '%s::%s' % (cpp_name(interface), base_name) |
130 return 'impl->%s' % base_name | 130 return 'impl->%s' % base_name |
131 | 131 |
132 | 132 |
133 def v8_class_name(interface): | 133 def v8_class_name(interface): |
134 return 'V8' + interface.name | 134 return 'V8' + interface.name |
135 | 135 |
136 | 136 |
137 def v8_class_name_or_partial(interface): | 137 def v8_class_name_or_partial(interface): |
138 class_name = v8_class_name(interface) | 138 class_name = v8_class_name(interface) |
(...skipping 30 matching lines...) Expand all Loading... |
169 """Returns if an isolated world check is required when generating activity | 169 """Returns if an isolated world check is required when generating activity |
170 logging code. | 170 logging code. |
171 | 171 |
172 The check is required when there is no per-world binding code and logging is | 172 The check is required when there is no per-world binding code and logging is |
173 required only for isolated world. | 173 required only for isolated world. |
174 """ | 174 """ |
175 extended_attributes = member.extended_attributes | 175 extended_attributes = member.extended_attributes |
176 if 'LogActivity' not in extended_attributes: | 176 if 'LogActivity' not in extended_attributes: |
177 return False | 177 return False |
178 if ('PerWorldBindings' not in extended_attributes and | 178 if ('PerWorldBindings' not in extended_attributes and |
179 'LogAllWorlds' not in extended_attributes): | 179 'LogAllWorlds' not in extended_attributes): |
180 return True | 180 return True |
181 return False | 181 return False |
182 | 182 |
183 | 183 |
184 # [CallWith] | 184 # [CallWith] |
185 CALL_WITH_ARGUMENTS = { | 185 CALL_WITH_ARGUMENTS = { |
186 'ScriptState': 'scriptState', | 186 'ScriptState': 'scriptState', |
187 'ExecutionContext': 'executionContext', | 187 'ExecutionContext': 'executionContext', |
188 'ScriptArguments': 'scriptArguments.release()', | 188 'ScriptArguments': 'scriptArguments.release()', |
189 'ActiveWindow': 'callingDOMWindow(info.GetIsolate())', | 189 'ActiveWindow': 'callingDOMWindow(info.GetIsolate())', |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 414 |
415 # [Unforgeable], [Global], [PrimaryGlobal] | 415 # [Unforgeable], [Global], [PrimaryGlobal] |
416 def on_instance(interface, member): | 416 def on_instance(interface, member): |
417 """Returns True if the interface's member needs to be defined on every | 417 """Returns True if the interface's member needs to be defined on every |
418 instance object. | 418 instance object. |
419 | 419 |
420 The following members must be defiend on an instance object. | 420 The following members must be defiend on an instance object. |
421 - [Unforgeable] members | 421 - [Unforgeable] members |
422 - regular members of [Global] or [PrimaryGlobal] interfaces | 422 - regular members of [Global] or [PrimaryGlobal] interfaces |
423 """ | 423 """ |
424 # TODO(yukishiino): Implement this function following the spec. | |
425 if member.is_static: | 424 if member.is_static: |
426 return False | 425 return False |
427 return not on_prototype(interface, member) | 426 |
| 427 # TODO(yukishiino): Remove a hack for toString once we support |
| 428 # Symbol.toStringTag. |
| 429 if (interface.name == 'Window' and member.name == 'toString'): |
| 430 return False |
| 431 |
| 432 # TODO(yukishiino): Implement "interface object" and its [[Call]] method |
| 433 # in a better way. Then we can get rid of this hack. |
| 434 if is_constructor_attribute(member): |
| 435 return True |
| 436 |
| 437 if ('PrimaryGlobal' in interface.extended_attributes or |
| 438 'Global' in interface.extended_attributes or |
| 439 'Unforgeable' in member.extended_attributes or |
| 440 'Unforgeable' in interface.extended_attributes): |
| 441 return True |
| 442 return False |
428 | 443 |
429 | 444 |
430 def on_prototype(interface, member): | 445 def on_prototype(interface, member): |
431 """Returns True if the interface's member needs to be defined on the | 446 """Returns True if the interface's member needs to be defined on the |
432 prototype object. | 447 prototype object. |
433 | 448 |
434 Most members are defined on the prototype object. Exceptions are as | 449 Most members are defined on the prototype object. Exceptions are as |
435 follows. | 450 follows. |
436 - constant members | |
437 - static members (optional) | 451 - static members (optional) |
438 - [Unforgeable] members | 452 - [Unforgeable] members |
439 - members of [Global] or [PrimaryGlobal] interfaces | 453 - members of [Global] or [PrimaryGlobal] interfaces |
440 - named properties of [Global] or [PrimaryGlobal] interfaces | 454 - named properties of [Global] or [PrimaryGlobal] interfaces |
441 """ | 455 """ |
442 # TODO(yukishiino): Implement this function following the spec. | 456 if member.is_static: |
443 | |
444 # These members must not be placed on prototype chains. | |
445 if (is_constructor_attribute(member) or | |
446 member.is_static or | |
447 is_unforgeable(interface, member)): | |
448 return False | 457 return False |
449 | 458 |
450 # TODO(yukishiino): We should handle [Global] and [PrimaryGlobal] instead of | 459 # TODO(yukishiino): Remove a hack for toString once we support |
451 # Window. | 460 # Symbol.toStringTag. |
452 if (interface.name == 'Window'): | 461 if (interface.name == 'Window' and member.name == 'toString'): |
453 return (member.idl_type.name == 'EventHandler' or | 462 return True |
454 type(member) == IdlOperation) | |
455 | 463 |
| 464 # TODO(yukishiino): Implement "interface object" and its [[Call]] method |
| 465 # in a better way. Then we can get rid of this hack. |
| 466 if is_constructor_attribute(member): |
| 467 return False |
| 468 |
| 469 if ('PrimaryGlobal' in interface.extended_attributes or |
| 470 'Global' in interface.extended_attributes or |
| 471 'Unforgeable' in member.extended_attributes or |
| 472 'Unforgeable' in interface.extended_attributes): |
| 473 return False |
456 return True | 474 return True |
457 | 475 |
458 | 476 |
459 # static, const | 477 # static, const |
460 def on_interface(interface, member): | 478 def on_interface(interface, member): |
461 """Returns True if the interface's member needs to be defined on the | 479 """Returns True if the interface's member needs to be defined on the |
462 interface object. | 480 interface object. |
463 | 481 |
464 The following members must be defiend on an interface object. | 482 The following members must be defiend on an interface object. |
465 - constant members | |
466 - static members | 483 - static members |
467 """ | 484 """ |
468 # TODO(yukishiino): Implement this function following the spec. | |
469 if member.is_static: | 485 if member.is_static: |
470 return True | 486 return True |
471 return False | 487 return False |
472 | 488 |
473 | 489 |
474 ################################################################################ | 490 ################################################################################ |
475 # Indexed properties | 491 # Indexed properties |
476 # http://heycam.github.io/webidl/#idl-indexed-properties | 492 # http://heycam.github.io/webidl/#idl-indexed-properties |
477 ################################################################################ | 493 ################################################################################ |
478 | 494 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 except StopIteration: | 582 except StopIteration: |
567 return None | 583 return None |
568 | 584 |
569 | 585 |
570 IdlInterface.indexed_property_getter = property(indexed_property_getter) | 586 IdlInterface.indexed_property_getter = property(indexed_property_getter) |
571 IdlInterface.indexed_property_setter = property(indexed_property_setter) | 587 IdlInterface.indexed_property_setter = property(indexed_property_setter) |
572 IdlInterface.indexed_property_deleter = property(indexed_property_deleter) | 588 IdlInterface.indexed_property_deleter = property(indexed_property_deleter) |
573 IdlInterface.named_property_getter = property(named_property_getter) | 589 IdlInterface.named_property_getter = property(named_property_getter) |
574 IdlInterface.named_property_setter = property(named_property_setter) | 590 IdlInterface.named_property_setter = property(named_property_setter) |
575 IdlInterface.named_property_deleter = property(named_property_deleter) | 591 IdlInterface.named_property_deleter = property(named_property_deleter) |
OLD | NEW |