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

Side by Side Diff: Source/bindings/scripts/unstable/v8_interface.py

Issue 148083004: IDL compiler: anonymous indexed property getters (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 for attribute in interface.attributes] 194 for attribute in interface.attributes]
195 template_contents.update({ 195 template_contents.update({
196 'attributes': attributes, 196 'attributes': attributes,
197 'has_accessors': any(attribute['is_expose_js_accessors'] for attribute i n attributes), 197 'has_accessors': any(attribute['is_expose_js_accessors'] for attribute i n attributes),
198 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), 198 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes),
199 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function'] for attribute in attributes), 199 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function'] for attribute in attributes),
200 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), 200 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes),
201 }) 201 })
202 202
203 methods = [v8_methods.generate_method(interface, method) 203 methods = [v8_methods.generate_method(interface, method)
204 for method in interface.operations] 204 for method in interface.operations
205 if method.name] # Skip anonymous special operations (methods)
205 generate_overloads(methods) 206 generate_overloads(methods)
206 for method in methods: 207 for method in methods:
207 method['do_generate_method_configuration'] = ( 208 method['do_generate_method_configuration'] = (
208 method['do_not_check_signature'] and 209 method['do_not_check_signature'] and
209 not method['per_context_enabled_function'] and 210 not method['per_context_enabled_function'] and
210 # For overloaded methods, only generate one accessor 211 # For overloaded methods, only generate one accessor
211 ('overload_index' not in method or method['overload_index'] == 1)) 212 ('overload_index' not in method or method['overload_index'] == 1))
212 213
213 template_contents.update({ 214 template_contents.update({
214 'has_origin_safe_method_setter': any( 215 'has_origin_safe_method_setter': any(
215 method['is_check_security_for_frame'] and not method['is_read_only'] 216 method['is_check_security_for_frame'] and not method['is_read_only']
216 for method in methods), 217 for method in methods),
217 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods), 218 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods),
218 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods), 219 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods),
219 'methods': methods, 220 'methods': methods,
220 }) 221 })
221 222
223 template_contents.update({
224 'anonymous_indexed_property_getter': generate_anonymous_indexed_property _getter(interface),
225 })
226
222 return template_contents 227 return template_contents
223 228
224 229
225 # [DeprecateAs], [Reflect], [RuntimeEnabled] 230 # [DeprecateAs], [Reflect], [RuntimeEnabled]
226 def generate_constant(constant): 231 def generate_constant(constant):
227 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted 232 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted
228 # in C++. 233 # in C++.
229 if constant.idl_type == 'DOMString': 234 if constant.idl_type == 'DOMString':
230 value = '"%s"' % constant.value 235 value = '"%s"' % constant.value
231 else: 236 else:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 461
457 462
458 def interface_length(interface, constructors): 463 def interface_length(interface, constructors):
459 # Docs: http://heycam.github.io/webidl/#es-interface-call 464 # Docs: http://heycam.github.io/webidl/#es-interface-call
460 if 'EventConstructor' in interface.extended_attributes: 465 if 'EventConstructor' in interface.extended_attributes:
461 return 1 466 return 1
462 if not constructors: 467 if not constructors:
463 return 0 468 return 0
464 return min(constructor['number_of_required_arguments'] 469 return min(constructor['number_of_required_arguments']
465 for constructor in constructors) 470 for constructor in constructors)
471
472
473 ################################################################################
474 # Special operations (methods)
475 # http://heycam.github.io/webidl/#idl-special-operations
476 ################################################################################
477
478 def generate_anonymous_indexed_property_getter(interface):
479 try:
480 getter = next(
haraken 2014/01/27 06:35:32 This looks a bit complicated. Can we avoid using P
Nils Barth (inactive) 2014/01/27 06:59:35 Admittedly this looks a bit weird, but this is the
haraken 2014/01/27 07:04:40 Understood, thanks for the clarification.
481 method
482 for method in interface.operations
483 if ('getter' in method.specials and
484 len(method.arguments) == 1 and
485 method.arguments[0].idl_type == 'unsigned long' and
486 not method.name))
487 except StopIteration:
488 return None
489
490 idl_type = getter.idl_type
491 extended_attributes = getter.extended_attributes
492 return {
493 'cpp_type': v8_types.cpp_type(idl_type),
494 'is_null_expression': getter_is_null_expression(idl_type),
495 'name': extended_attributes['ImplementedAs'],
haraken 2014/01/27 06:35:32 Why do we need to support [ImplementedAs] for "ano
Nils Barth (inactive) 2014/01/27 06:59:35 See other comment: anonymous means there's no name
haraken 2014/01/27 07:04:40 Sounds better.
Nils Barth (inactive) 2014/01/27 07:24:37 Ok, I'll do this in a followup, as it touches real
496 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'element', extended_attributes=extended_attributes, script_wrappable='collection'),
497 }
498
499
500 def getter_is_null_expression(idl_type):
haraken 2014/01/27 06:35:32 Is this method only for getters?
Nils Barth (inactive) 2014/01/27 06:59:35 Yes; I've thus made it explicit.
501 if idl_type == 'DOMString':
502 return 'element.isNull()'
503 return None
haraken 2014/01/27 06:35:32 How can we judge nullability for non-DOMString val
Nils Barth (inactive) 2014/01/27 06:59:35 See GenerateIsNullExpression https://code.google.c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698