OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 import idl_definitions | 39 import idl_definitions |
40 from idl_definitions import IdlOperation | 40 from idl_definitions import IdlOperation |
41 import idl_types | 41 import idl_types |
42 from idl_types import IdlType, inherits_interface | 42 from idl_types import IdlType, inherits_interface |
43 import v8_attributes | 43 import v8_attributes |
44 from v8_globals import includes | 44 from v8_globals import includes |
45 import v8_methods | 45 import v8_methods |
46 import v8_types | 46 import v8_types |
47 from v8_types import cpp_ptr_type, cpp_template_type | 47 from v8_types import cpp_ptr_type, cpp_template_type |
48 import v8_utilities | 48 import v8_utilities |
49 from v8_utilities import capitalize, conditional_string, cpp_name, gc_type, has_
extended_attribute_value, runtime_enabled_function_name | 49 from v8_utilities import (capitalize, conditional_string, cpp_name, gc_type, |
| 50 has_extended_attribute_value, runtime_enabled_function
_name, |
| 51 extended_attribute_value_as_list) |
50 | 52 |
51 | 53 |
52 INTERFACE_H_INCLUDES = frozenset([ | 54 INTERFACE_H_INCLUDES = frozenset([ |
53 'bindings/common/ScriptWrappable.h', | 55 'bindings/common/ScriptWrappable.h', |
54 'bindings/core/v8/V8Binding.h', | 56 'bindings/core/v8/V8Binding.h', |
55 'bindings/core/v8/V8DOMWrapper.h', | 57 'bindings/core/v8/V8DOMWrapper.h', |
56 'bindings/core/v8/WrapperTypeInfo.h', | 58 'bindings/core/v8/WrapperTypeInfo.h', |
57 'platform/heap/Handle.h', | 59 'platform/heap/Handle.h', |
58 ]) | 60 ]) |
59 INTERFACE_CPP_INCLUDES = frozenset([ | 61 INTERFACE_CPP_INCLUDES = frozenset([ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 is_active_dom_object = 'ActiveDOMObject' in extended_attributes | 96 is_active_dom_object = 'ActiveDOMObject' in extended_attributes |
95 | 97 |
96 # [CheckSecurity] | 98 # [CheckSecurity] |
97 is_check_security = 'CheckSecurity' in extended_attributes | 99 is_check_security = 'CheckSecurity' in extended_attributes |
98 if is_check_security: | 100 if is_check_security: |
99 includes.add('bindings/common/BindingSecurity.h') | 101 includes.add('bindings/common/BindingSecurity.h') |
100 | 102 |
101 # [DependentLifetime] | 103 # [DependentLifetime] |
102 is_dependent_lifetime = 'DependentLifetime' in extended_attributes | 104 is_dependent_lifetime = 'DependentLifetime' in extended_attributes |
103 | 105 |
| 106 # [Iterable] |
| 107 iterator_method = None |
| 108 if 'Iterable' in extended_attributes: |
| 109 iterator_operation = IdlOperation(interface.idl_name) |
| 110 iterator_operation.name = 'iterator' |
| 111 iterator_operation.idl_type = IdlType('Iterator') |
| 112 iterator_operation.extended_attributes['RaisesException'] = None |
| 113 iterator_operation.extended_attributes['CallWith'] = 'ScriptState' |
| 114 iterator_method = v8_methods.method_context(interface, |
| 115 iterator_operation) |
| 116 |
104 # [MeasureAs] | 117 # [MeasureAs] |
105 is_measure_as = 'MeasureAs' in extended_attributes | 118 is_measure_as = 'MeasureAs' in extended_attributes |
106 if is_measure_as: | 119 if is_measure_as: |
107 includes.add('core/frame/UseCounter.h') | 120 includes.add('core/frame/UseCounter.h') |
108 | 121 |
109 # [SetWrapperReferenceFrom] | 122 # [SetWrapperReferenceFrom] |
110 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') | 123 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') |
111 if reachable_node_function: | 124 if reachable_node_function: |
112 includes.update(['bindings/core/v8/V8GCController.h', | 125 includes.update(['bindings/core/v8/V8GCController.h', |
113 'core/dom/Element.h']) | 126 'core/dom/Element.h']) |
114 | 127 |
115 # [SetWrapperReferenceTo] | 128 # [SetWrapperReferenceTo] |
116 set_wrapper_reference_to_list = [{ | 129 set_wrapper_reference_to_list = [{ |
117 'name': argument.name, | 130 'name': argument.name, |
118 # FIXME: properly should be: | 131 # FIXME: properly should be: |
119 # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), | 132 # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), |
120 # (if type is non-wrapper type like NodeFilter, normally RefPtr) | 133 # (if type is non-wrapper type like NodeFilter, normally RefPtr) |
121 # Raw pointers faster though, and NodeFilter hacky anyway. | 134 # Raw pointers faster though, and NodeFilter hacky anyway. |
122 'cpp_type': argument.idl_type.implemented_as + '*', | 135 'cpp_type': argument.idl_type.implemented_as + '*', |
123 'idl_type': argument.idl_type, | 136 'idl_type': argument.idl_type, |
124 'v8_type': v8_types.v8_type(argument.idl_type.name), | 137 'v8_type': v8_types.v8_type(argument.idl_type.name), |
125 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] | 138 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] |
126 for set_wrapper_reference_to in set_wrapper_reference_to_list: | 139 for set_wrapper_reference_to in set_wrapper_reference_to_list: |
127 set_wrapper_reference_to['idl_type'].add_includes_for_type() | 140 set_wrapper_reference_to['idl_type'].add_includes_for_type() |
128 | 141 |
| 142 # [NotScriptWrappable] |
| 143 is_script_wrappable = 'NotScriptWrappable' not in extended_attributes |
| 144 |
129 # [SpecialWrapFor] | 145 # [SpecialWrapFor] |
130 if 'SpecialWrapFor' in extended_attributes: | 146 if 'SpecialWrapFor' in extended_attributes: |
131 special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') | 147 special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialW
rapFor') |
132 else: | 148 else: |
133 special_wrap_for = [] | 149 special_wrap_for = [] |
134 for special_wrap_interface in special_wrap_for: | 150 for special_wrap_interface in special_wrap_for: |
135 v8_types.add_includes_for_interface(special_wrap_interface) | 151 v8_types.add_includes_for_interface(special_wrap_interface) |
136 | 152 |
137 # [Custom=Wrap], [SetWrapperReferenceFrom] | 153 # [Custom=Wrap], [SetWrapperReferenceFrom] |
138 has_visit_dom_wrapper = ( | 154 has_visit_dom_wrapper = ( |
139 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or | 155 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or |
140 reachable_node_function or | 156 reachable_node_function or |
141 set_wrapper_reference_to_list) | 157 set_wrapper_reference_to_list) |
142 | 158 |
143 this_gc_type = gc_type(interface) | 159 this_gc_type = gc_type(interface) |
144 | 160 |
| 161 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod
e') else 'ObjectClassId') |
| 162 |
145 context = { | 163 context = { |
146 'conditional_string': conditional_string(interface), # [Conditional] | 164 'conditional_string': conditional_string(interface), # [Conditional] |
147 'cpp_class': cpp_name(interface), | 165 'cpp_class': cpp_name(interface), |
148 'gc_type': this_gc_type, | 166 'gc_type': this_gc_type, |
| 167 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 |
| 168 'has_access_check_callbacks': (is_check_security and |
| 169 interface.name != 'Window' and |
| 170 interface.name != 'EventTarget'), |
149 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] | 171 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] |
150 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T
oV8'), # [Custom=ToV8] | 172 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T
oV8'), # [Custom=ToV8] |
151 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr
ap'), # [Custom=Wrap] | 173 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr
ap'), # [Custom=Wrap] |
152 'has_visit_dom_wrapper': has_visit_dom_wrapper, | 174 'has_visit_dom_wrapper': has_visit_dom_wrapper, |
153 'header_includes': header_includes, | 175 'header_includes': header_includes, |
154 'interface_name': interface.name, | 176 'interface_name': interface.name, |
155 'is_active_dom_object': is_active_dom_object, | 177 'is_active_dom_object': is_active_dom_object, |
156 'is_audio_buffer': is_audio_buffer, | 178 'is_audio_buffer': is_audio_buffer, |
157 'is_check_security': is_check_security, | 179 'is_check_security': is_check_security, |
158 'is_dependent_lifetime': is_dependent_lifetime, | 180 'is_dependent_lifetime': is_dependent_lifetime, |
159 'is_document': is_document, | 181 'is_document': is_document, |
160 'is_event_target': inherits_interface(interface.name, 'EventTarget'), | 182 'is_event_target': inherits_interface(interface.name, 'EventTarget'), |
161 'is_exception': interface.is_exception, | 183 'is_exception': interface.is_exception, |
162 'is_node': inherits_interface(interface.name, 'Node'), | 184 'is_node': inherits_interface(interface.name, 'Node'), |
| 185 'is_script_wrappable': is_script_wrappable, |
| 186 'iterator_method': iterator_method, |
| 187 'lifetime': 'Dependent' |
| 188 if (has_visit_dom_wrapper or |
| 189 is_active_dom_object or |
| 190 is_dependent_lifetime) |
| 191 else 'Independent', |
163 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] | 192 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] |
164 'parent_interface': parent_interface, | 193 'parent_interface': parent_interface, |
165 'pass_cpp_type': cpp_template_type( | 194 'pass_cpp_type': cpp_template_type( |
166 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), | 195 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), |
167 cpp_name(interface)), | 196 cpp_name(interface)), |
168 'reachable_node_function': reachable_node_function, | 197 'reachable_node_function': reachable_node_function, |
169 'runtime_enabled_function': runtime_enabled_function_name(interface), #
[RuntimeEnabled] | 198 'runtime_enabled_function': runtime_enabled_function_name(interface), #
[RuntimeEnabled] |
170 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, | 199 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, |
171 'special_wrap_for': special_wrap_for, | 200 'special_wrap_for': special_wrap_for, |
172 'v8_class': v8_utilities.v8_class_name(interface), | 201 'v8_class': v8_utilities.v8_class_name(interface), |
173 'wrapper_configuration': 'WrapperConfiguration::Dependent' | 202 'wrapper_class_id': wrapper_class_id, |
174 if (has_visit_dom_wrapper or | |
175 is_active_dom_object or | |
176 is_dependent_lifetime) | |
177 else 'WrapperConfiguration::Independent', | |
178 } | 203 } |
179 | 204 |
180 # Constructors | 205 # Constructors |
181 constructors = [constructor_context(interface, constructor) | 206 constructors = [constructor_context(interface, constructor) |
182 for constructor in interface.constructors | 207 for constructor in interface.constructors |
183 # FIXME: shouldn't put named constructors with constructors | 208 # FIXME: shouldn't put named constructors with constructors |
184 # (currently needed for Perl compatibility) | 209 # (currently needed for Perl compatibility) |
185 # Handle named constructors separately | 210 # Handle named constructors separately |
186 if constructor.name == 'Constructor'] | 211 if constructor.name == 'Constructor'] |
187 if len(constructors) > 1: | 212 if len(constructors) > 1: |
(...skipping 26 matching lines...) Expand all Loading... |
214 'any_type_attributes': any_type_attributes, | 239 'any_type_attributes': any_type_attributes, |
215 'constructors': constructors, | 240 'constructors': constructors, |
216 'has_custom_constructor': bool(custom_constructors), | 241 'has_custom_constructor': bool(custom_constructors), |
217 'has_event_constructor': has_event_constructor, | 242 'has_event_constructor': has_event_constructor, |
218 'interface_length': | 243 'interface_length': |
219 interface_length(interface, constructors + custom_constructors), | 244 interface_length(interface, constructors + custom_constructors), |
220 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] | 245 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept
ion') == 'Constructor', # [RaisesException=Constructor] |
221 'named_constructor': named_constructor, | 246 'named_constructor': named_constructor, |
222 }) | 247 }) |
223 | 248 |
| 249 constants = [constant_context(constant) for constant in interface.constants] |
| 250 |
| 251 special_getter_constants = [] |
| 252 runtime_enabled_constants = [] |
| 253 constant_configuration_constants = [] |
| 254 |
| 255 for constant in constants: |
| 256 if constant['measure_as'] or constant['deprecate_as']: |
| 257 special_getter_constants.append(constant) |
| 258 continue |
| 259 if constant['runtime_enabled_function']: |
| 260 runtime_enabled_constants.append(constant) |
| 261 continue |
| 262 constant_configuration_constants.append(constant) |
| 263 |
224 # Constants | 264 # Constants |
225 context.update({ | 265 context.update({ |
226 'constants': [constant_context(constant) | 266 'constant_configuration_constants': constant_configuration_constants, |
227 for constant in interface.constants], | 267 'constants': constants, |
228 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, | 268 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, |
| 269 'has_constant_configuration': any( |
| 270 not constant['runtime_enabled_function'] |
| 271 for constant in constants), |
| 272 'runtime_enabled_constants': runtime_enabled_constants, |
| 273 'special_getter_constants': special_getter_constants, |
229 }) | 274 }) |
230 | 275 |
231 # Attributes | 276 # Attributes |
232 attributes = [v8_attributes.attribute_context(interface, attribute) | 277 attributes = [v8_attributes.attribute_context(interface, attribute) |
233 for attribute in interface.attributes | 278 for attribute in interface.attributes |
234 if not v8_utilities.dart_custom_method(attribute.extended_attr
ibutes)] | 279 if not v8_utilities.dart_custom_method(attribute.extended_attr
ibutes)] |
235 context.update({ | 280 context.update({ |
236 'attributes': attributes, | 281 'attributes': attributes, |
237 'has_accessors': any(attribute['is_expose_js_accessors'] and attribute['
should_be_exposed_to_script'] for attribute in attributes), | 282 'has_accessors': any(attribute['is_expose_js_accessors'] and attribute['
should_be_exposed_to_script'] for attribute in attributes), |
238 'has_attribute_configuration': any( | 283 'has_attribute_configuration': any( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 'named_property_getter': named_property_getter(interface), | 377 'named_property_getter': named_property_getter(interface), |
333 'named_property_setter': named_property_setter(interface), | 378 'named_property_setter': named_property_setter(interface), |
334 'named_property_deleter': named_property_deleter(interface), | 379 'named_property_deleter': named_property_deleter(interface), |
335 }) | 380 }) |
336 | 381 |
337 return context | 382 return context |
338 | 383 |
339 | 384 |
340 # [DeprecateAs], [Reflect], [RuntimeEnabled] | 385 # [DeprecateAs], [Reflect], [RuntimeEnabled] |
341 def constant_context(constant): | 386 def constant_context(constant): |
342 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted | |
343 # in C++. | |
344 if constant.idl_type.name == 'String': | |
345 value = '"%s"' % constant.value | |
346 else: | |
347 value = constant.value | |
348 | |
349 extended_attributes = constant.extended_attributes | 387 extended_attributes = constant.extended_attributes |
350 return { | 388 return { |
351 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 389 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
| 390 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] |
352 'idl_type': constant.idl_type.name, | 391 'idl_type': constant.idl_type.name, |
| 392 'measure_as': v8_utilities.measure_as(constant), # [MeasureAs] |
353 'name': constant.name, | 393 'name': constant.name, |
354 # FIXME: use 'reflected_name' as correct 'name' | 394 # FIXME: use 'reflected_name' as correct 'name' |
355 'reflected_name': extended_attributes.get('Reflect', constant.name), | 395 'reflected_name': extended_attributes.get('Reflect', constant.name), |
356 'runtime_enabled_function': runtime_enabled_function_name(constant), | 396 'runtime_enabled_function': runtime_enabled_function_name(constant), |
357 'value': value, | 397 'value': constant.value, |
358 } | 398 } |
359 | 399 |
360 | 400 |
361 ################################################################################ | 401 ################################################################################ |
362 # Overloads | 402 # Overloads |
363 ################################################################################ | 403 ################################################################################ |
364 | 404 |
365 def compute_method_overloads_context(methods): | 405 def compute_method_overloads_context(methods): |
366 # Regular methods | 406 # Regular methods |
367 compute_method_overloads_context_by_type([method for method in methods | 407 compute_method_overloads_context_by_type([method for method in methods |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 # of the extended attributes in question. | 475 # of the extended attributes in question. |
436 if not overloads[0].get('is_constructor'): | 476 if not overloads[0].get('is_constructor'): |
437 overload_extended_attributes = [ | 477 overload_extended_attributes = [ |
438 method['custom_registration_extended_attributes'] | 478 method['custom_registration_extended_attributes'] |
439 for method in overloads] | 479 for method in overloads] |
440 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB
UTES: | 480 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB
UTES: |
441 if common_key(overload_extended_attributes, extended_attribute) is N
one: | 481 if common_key(overload_extended_attributes, extended_attribute) is N
one: |
442 raise ValueError('Overloads of %s have conflicting extended attr
ibute %s' | 482 raise ValueError('Overloads of %s have conflicting extended attr
ibute %s' |
443 % (name, extended_attribute)) | 483 % (name, extended_attribute)) |
444 | 484 |
| 485 # Check and fail if overloads disagree about whether the return type |
| 486 # is a Promise or not. |
| 487 promise_overload_count = sum(1 for method in overloads if method.get('idl_ty
pe') == 'Promise') |
| 488 if promise_overload_count not in (0, len(overloads)): |
| 489 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t
ypes' |
| 490 % (name)) |
| 491 |
445 return { | 492 return { |
446 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] | 493 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] |
447 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed
] | 494 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed
] |
448 'has_custom_registration_all': common_value(overloads, 'has_custom_regis
tration'), | 495 'has_custom_registration_all': common_value(overloads, 'has_custom_regis
tration'), |
449 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), | 496 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), |
450 # 1. Let maxarg be the length of the longest type list of the | 497 # 1. Let maxarg be the length of the longest type list of the |
451 # entries in S. | 498 # entries in S. |
452 'maxarg': lengths[-1], | 499 'maxarg': lengths[-1], |
453 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 500 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
454 'minarg': lengths[0], | 501 'minarg': lengths[0], |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 test = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.forma
t(idl_type=idl_type.base_type, cpp_value=cpp_value) | 776 test = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.forma
t(idl_type=idl_type.base_type, cpp_value=cpp_value) |
730 yield test, method | 777 yield test, method |
731 | 778 |
732 # 8. Otherwise: if V is any kind of object except for a native Date object, | 779 # 8. Otherwise: if V is any kind of object except for a native Date object, |
733 # a native RegExp object, and there is an entry in S that has one of the | 780 # a native RegExp object, and there is an entry in S that has one of the |
734 # following types at position i of its type list, | 781 # following types at position i of its type list, |
735 # • an array type | 782 # • an array type |
736 # • a sequence type | 783 # • a sequence type |
737 # ... | 784 # ... |
738 # • a dictionary | 785 # • a dictionary |
739 try: | 786 # |
740 # FIXME: IDL dictionary not implemented, so use Blink Dictionary | 787 # FIXME: |
741 # http://crbug.com/321462 | 788 # We don't strictly follow the algorithm here. The algorithm says "remove |
742 idl_type, method = next((idl_type, method) | 789 # all other entries" if there is "one entry" matching, but we yield all |
743 for idl_type, method in idl_types_methods | 790 # entries to support following constructors: |
744 if (idl_type.native_array_element_type or | 791 # [constructor(sequence<DOMString> arg), constructor(Dictionary arg)] |
745 idl_type.name == 'Dictionary')) | 792 # interface I { ... } |
| 793 # (Need to check array types before objects because an array is an object) |
| 794 for idl_type, method in idl_types_methods: |
746 if idl_type.native_array_element_type: | 795 if idl_type.native_array_element_type: |
747 # (We test for Array instead of generic Object to type-check.) | 796 # (We test for Array instead of generic Object to type-check.) |
748 # FIXME: test for Object during resolution, then have type check for | 797 # FIXME: test for Object during resolution, then have type check for |
749 # Array in overloaded method: http://crbug.com/262383 | 798 # Array in overloaded method: http://crbug.com/262383 |
750 test = '%s->IsArray()' % cpp_value | 799 yield '%s->IsArray()' % cpp_value, method |
751 else: | 800 for idl_type, method in idl_types_methods: |
| 801 if idl_type.is_dictionary or idl_type.name == 'Dictionary': |
752 # FIXME: should be '{1}->IsObject() && !{1}->IsDate() && !{1}->IsReg
Exp()'.format(cpp_value) | 802 # FIXME: should be '{1}->IsObject() && !{1}->IsDate() && !{1}->IsReg
Exp()'.format(cpp_value) |
753 # FIXME: the IsDate and IsRegExp checks can be skipped if we've | 803 # FIXME: the IsDate and IsRegExp checks can be skipped if we've |
754 # already generated tests for them. | 804 # already generated tests for them. |
755 test = '%s->IsObject()' % cpp_value | 805 yield '%s->IsObject()' % cpp_value, method |
756 yield test, method | |
757 except StopIteration: | |
758 pass | |
759 | 806 |
760 # (Check for exact type matches before performing automatic type conversion; | 807 # (Check for exact type matches before performing automatic type conversion; |
761 # only needed if distinguishing between primitive types.) | 808 # only needed if distinguishing between primitive types.) |
762 if len([idl_type.is_primitive_type for idl_type in idl_types]) > 1: | 809 if len([idl_type.is_primitive_type for idl_type in idl_types]) > 1: |
763 # (Only needed if match in step 11, otherwise redundant.) | 810 # (Only needed if match in step 11, otherwise redundant.) |
764 if any(idl_type.is_string_type or idl_type.is_enum | 811 if any(idl_type.is_string_type or idl_type.is_enum |
765 for idl_type in idl_types): | 812 for idl_type in idl_types): |
766 # 10. Otherwise: if V is a Number value, and there is an entry in S | 813 # 10. Otherwise: if V is a Number value, and there is an entry in S |
767 # that has one of the following types at position i of its type | 814 # that has one of the following types at position i of its type |
768 # list, | 815 # list, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 l.sort(key=key) | 898 l.sort(key=key) |
852 return ((k, list(g)) for k, g in itertools.groupby(l, key)) | 899 return ((k, list(g)) for k, g in itertools.groupby(l, key)) |
853 | 900 |
854 | 901 |
855 ################################################################################ | 902 ################################################################################ |
856 # Constructors | 903 # Constructors |
857 ################################################################################ | 904 ################################################################################ |
858 | 905 |
859 # [Constructor] | 906 # [Constructor] |
860 def constructor_context(interface, constructor): | 907 def constructor_context(interface, constructor): |
861 arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument,
return_promise=False) | |
862 for argument in constructor.arguments) | |
863 | |
864 # [RaisesException=Constructor] | 908 # [RaisesException=Constructor] |
865 is_constructor_raises_exception = \ | 909 is_constructor_raises_exception = \ |
866 interface.extended_attributes.get('RaisesException') == 'Constructor' | 910 interface.extended_attributes.get('RaisesException') == 'Constructor' |
867 | 911 |
868 return { | 912 return { |
869 'arguments': [v8_methods.argument_context(interface, constructor, argume
nt, index) | 913 'arguments': [v8_methods.argument_context(interface, constructor, argume
nt, index) |
870 for index, argument in enumerate(constructor.arguments)], | 914 for index, argument in enumerate(constructor.arguments)], |
871 'arguments_need_try_catch': arguments_need_try_catch, | |
872 'cpp_type': cpp_template_type( | 915 'cpp_type': cpp_template_type( |
873 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), | 916 cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), |
874 cpp_name(interface)), | 917 cpp_name(interface)), |
875 'cpp_value': v8_methods.cpp_value( | 918 'cpp_value': v8_methods.cpp_value( |
876 interface, constructor, len(constructor.arguments)), | 919 interface, constructor, len(constructor.arguments)), |
877 'has_exception_state': | 920 'has_exception_state': |
878 is_constructor_raises_exception or | 921 is_constructor_raises_exception or |
879 any(argument for argument in constructor.arguments | 922 any(argument for argument in constructor.arguments |
880 if argument.idl_type.name == 'SerializedScriptValue' or | 923 if argument.idl_type.name == 'SerializedScriptValue' or |
881 argument.idl_type.may_raise_exception_on_conversion), | 924 argument.idl_type.v8_conversion_needs_exception_state), |
882 'is_call_with_document': | 925 'is_call_with_document': |
883 # [ConstructorCallWith=Document] | 926 # [ConstructorCallWith=Document] |
884 has_extended_attribute_value(interface, | 927 has_extended_attribute_value(interface, |
885 'ConstructorCallWith', 'Document'), | 928 'ConstructorCallWith', 'Document'), |
886 'is_call_with_execution_context': | 929 'is_call_with_execution_context': |
887 # [ConstructorCallWith=ExecutionContext] | 930 # [ConstructorCallWith=ExecutionContext] |
888 has_extended_attribute_value(interface, | 931 has_extended_attribute_value(interface, |
889 'ConstructorCallWith', 'ExecutionContext'), | 932 'ConstructorCallWith', 'ExecutionContext'), |
890 'is_constructor': True, | 933 'is_constructor': True, |
891 'is_named_constructor': False, | 934 'is_named_constructor': False, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 def property_setter(setter): | 1028 def property_setter(setter): |
986 idl_type = setter.arguments[1].idl_type | 1029 idl_type = setter.arguments[1].idl_type |
987 extended_attributes = setter.extended_attributes | 1030 extended_attributes = setter.extended_attributes |
988 is_raises_exception = 'RaisesException' in extended_attributes | 1031 is_raises_exception = 'RaisesException' in extended_attributes |
989 return { | 1032 return { |
990 'has_type_checking_interface': | 1033 'has_type_checking_interface': |
991 has_extended_attribute_value(setter, 'TypeChecking', 'Interface') an
d | 1034 has_extended_attribute_value(setter, 'TypeChecking', 'Interface') an
d |
992 idl_type.is_wrapper_type, | 1035 idl_type.is_wrapper_type, |
993 'idl_type': idl_type.base_type, | 1036 'idl_type': idl_type.base_type, |
994 'is_custom': 'Custom' in extended_attributes, | 1037 'is_custom': 'Custom' in extended_attributes, |
995 'has_exception_state': is_raises_exception or | 1038 'has_exception_state': (is_raises_exception or |
996 idl_type.is_integer_type, | 1039 idl_type.v8_conversion_needs_exception_state), |
997 'is_raises_exception': is_raises_exception, | 1040 'is_raises_exception': is_raises_exception, |
998 'name': cpp_name(setter), | 1041 'name': cpp_name(setter), |
999 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( | 1042 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
1000 extended_attributes, 'v8Value', 'propertyValue'), | 1043 extended_attributes, 'v8Value', 'propertyValue'), |
1001 } | 1044 } |
1002 | 1045 |
1003 | 1046 |
1004 def property_deleter(deleter): | 1047 def property_deleter(deleter): |
1005 idl_type = deleter.idl_type | 1048 idl_type = deleter.idl_type |
1006 if str(idl_type) != 'boolean': | 1049 if str(idl_type) != 'boolean': |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 deleter = next( | 1156 deleter = next( |
1114 method | 1157 method |
1115 for method in interface.operations | 1158 for method in interface.operations |
1116 if ('deleter' in method.specials and | 1159 if ('deleter' in method.specials and |
1117 len(method.arguments) == 1 and | 1160 len(method.arguments) == 1 and |
1118 str(method.arguments[0].idl_type) == 'DOMString')) | 1161 str(method.arguments[0].idl_type) == 'DOMString')) |
1119 except StopIteration: | 1162 except StopIteration: |
1120 return None | 1163 return None |
1121 | 1164 |
1122 return property_deleter(deleter) | 1165 return property_deleter(deleter) |
OLD | NEW |