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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/idl_definitions.py

Issue 2385073002: HTMLConstructor implementation (Closed)
Patch Set: Renamed V8HTMLElement constructor to HTMLConstructor Created 4 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
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 # Interfaces and Exceptions 288 # Interfaces and Exceptions
289 ################################################################################ 289 ################################################################################
290 290
291 class IdlInterface(object): 291 class IdlInterface(object):
292 def __init__(self, idl_name, node=None): 292 def __init__(self, idl_name, node=None):
293 self.attributes = [] 293 self.attributes = []
294 self.constants = [] 294 self.constants = []
295 self.constructors = [] 295 self.constructors = []
296 self.custom_constructors = [] 296 self.custom_constructors = []
297 self.extended_attributes = {} 297 self.extended_attributes = {}
298 self.html_constructors = []
298 self.operations = [] 299 self.operations = []
299 self.parent = None 300 self.parent = None
300 self.serializer = None 301 self.serializer = None
301 self.stringifier = None 302 self.stringifier = None
302 self.iterable = None 303 self.iterable = None
303 self.has_indexed_elements = False 304 self.has_indexed_elements = False
304 self.maplike = None 305 self.maplike = None
305 self.setlike = None 306 self.setlike = None
306 self.original_interface = None 307 self.original_interface = None
307 self.partial_interfaces = [] 308 self.partial_interfaces = []
(...skipping 16 matching lines...) Expand all
324 child_class = child.GetClass() 325 child_class = child.GetClass()
325 if child_class == 'Attribute': 326 if child_class == 'Attribute':
326 attr = IdlAttribute(idl_name, child) 327 attr = IdlAttribute(idl_name, child)
327 if attr.idl_type.is_integer_type and attr.name == 'length': 328 if attr.idl_type.is_integer_type and attr.name == 'length':
328 has_integer_typed_length = True 329 has_integer_typed_length = True
329 self.attributes.append(attr) 330 self.attributes.append(attr)
330 elif child_class == 'Const': 331 elif child_class == 'Const':
331 self.constants.append(IdlConstant(idl_name, child)) 332 self.constants.append(IdlConstant(idl_name, child))
332 elif child_class == 'ExtAttributes': 333 elif child_class == 'ExtAttributes':
333 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child) 334 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child)
334 self.constructors, self.custom_constructors = ( 335 self.constructors, self.custom_constructors, self.html_construct ors = (
335 extended_attributes_to_constructors(idl_name, extended_attri butes)) 336 extended_attributes_to_constructors(idl_name, extended_attri butes))
336 clear_constructor_attributes(extended_attributes) 337 clear_constructor_attributes(extended_attributes)
337 self.extended_attributes = extended_attributes 338 self.extended_attributes = extended_attributes
338 elif child_class == 'Operation': 339 elif child_class == 'Operation':
339 op = IdlOperation(idl_name, child) 340 op = IdlOperation(idl_name, child)
340 if 'getter' in op.specials and str(op.arguments[0].idl_type) == 'unsigned long': 341 if 'getter' in op.specials and str(op.arguments[0].idl_type) == 'unsigned long':
341 has_indexed_property_getter = True 342 has_indexed_property_getter = True
342 self.operations.append(op) 343 self.operations.append(op)
343 elif child_class == 'Inherit': 344 elif child_class == 'Inherit':
344 self.parent = child.GetName() 345 self.parent = child.GetName()
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 children = node.GetChildren() 428 children = node.GetChildren()
428 for child in children: 429 for child in children:
429 child_class = child.GetClass() 430 child_class = child.GetClass()
430 if child_class == 'Attribute': 431 if child_class == 'Attribute':
431 attribute = IdlAttribute(idl_name, child) 432 attribute = IdlAttribute(idl_name, child)
432 self.attributes.append(attribute) 433 self.attributes.append(attribute)
433 elif child_class == 'Const': 434 elif child_class == 'Const':
434 self.constants.append(IdlConstant(idl_name, child)) 435 self.constants.append(IdlConstant(idl_name, child))
435 elif child_class == 'ExtAttributes': 436 elif child_class == 'ExtAttributes':
436 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child) 437 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child)
437 self.constructors, self.custom_constructors = ( 438 self.constructors, self.custom_constructors, self.html_construct ors = (
438 extended_attributes_to_constructors(idl_name, extended_attri butes)) 439 extended_attributes_to_constructors(idl_name, extended_attri butes))
439 clear_constructor_attributes(extended_attributes) 440 clear_constructor_attributes(extended_attributes)
440 self.extended_attributes = extended_attributes 441 self.extended_attributes = extended_attributes
441 elif child_class == 'ExceptionOperation': 442 elif child_class == 'ExceptionOperation':
442 self.operations.append(IdlOperation.from_exception_operation_nod e(idl_name, child)) 443 self.operations.append(IdlOperation.from_exception_operation_nod e(idl_name, child))
443 else: 444 else:
444 raise ValueError('Unrecognized node class: %s' % child_class) 445 raise ValueError('Unrecognized node class: %s' % child_class)
445 446
446 447
447 ################################################################################ 448 ################################################################################
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 constructor_list = extended_attributes.get('Constructors', []) 962 constructor_list = extended_attributes.get('Constructors', [])
962 constructors = [ 963 constructors = [
963 IdlOperation.constructor_from_arguments_node('Constructor', idl_name, ar guments_node) 964 IdlOperation.constructor_from_arguments_node('Constructor', idl_name, ar guments_node)
964 for arguments_node in constructor_list] 965 for arguments_node in constructor_list]
965 966
966 custom_constructor_list = extended_attributes.get('CustomConstructors', []) 967 custom_constructor_list = extended_attributes.get('CustomConstructors', [])
967 custom_constructors = [ 968 custom_constructors = [
968 IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_na me, arguments_node) 969 IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_na me, arguments_node)
969 for arguments_node in custom_constructor_list] 970 for arguments_node in custom_constructor_list]
970 971
972 if 'HTMLConstructor' in extended_attributes:
973 html_constructors = [IdlOperation.constructor_from_arguments_node('HTMLC onstructor', idl_name, None)]
bashi 2016/10/04 05:53:51 Could you help me understand why we need to use a
974 else:
975 html_constructors = []
976
971 if 'NamedConstructor' in extended_attributes: 977 if 'NamedConstructor' in extended_attributes:
972 # FIXME: support overloaded named constructors, and make homogeneous 978 # FIXME: support overloaded named constructors, and make homogeneous
973 name = 'NamedConstructor' 979 name = 'NamedConstructor'
974 call_node = extended_attributes['NamedConstructor'] 980 call_node = extended_attributes['NamedConstructor']
975 extended_attributes['NamedConstructor'] = call_node.GetName() 981 extended_attributes['NamedConstructor'] = call_node.GetName()
976 children = call_node.GetChildren() 982 children = call_node.GetChildren()
977 if len(children) != 1: 983 if len(children) != 1:
978 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children)) 984 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children))
979 arguments_node = children[0] 985 arguments_node = children[0]
980 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', idl_name, arguments_node) 986 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', idl_name, arguments_node)
981 # FIXME: should return named_constructor separately; appended for Perl 987 # FIXME: should return named_constructor separately; appended for Perl
982 constructors.append(named_constructor) 988 constructors.append(named_constructor)
983 989
984 return constructors, custom_constructors 990 return constructors, custom_constructors, html_constructors
985 991
986 992
987 def clear_constructor_attributes(extended_attributes): 993 def clear_constructor_attributes(extended_attributes):
988 # Deletes Constructor*s* (plural), sets Constructor (singular) 994 # Deletes Constructor*s* (plural), sets Constructor (singular)
989 if 'Constructors' in extended_attributes: 995 if 'Constructors' in extended_attributes:
990 del extended_attributes['Constructors'] 996 del extended_attributes['Constructors']
991 extended_attributes['Constructor'] = None 997 extended_attributes['Constructor'] = None
992 if 'CustomConstructors' in extended_attributes: 998 if 'CustomConstructors' in extended_attributes:
993 del extended_attributes['CustomConstructors'] 999 del extended_attributes['CustomConstructors']
994 extended_attributes['CustomConstructor'] = None 1000 extended_attributes['CustomConstructor'] = None
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 self.visit_typed_object(argument) 1132 self.visit_typed_object(argument)
1127 1133
1128 def visit_iterable(self, iterable): 1134 def visit_iterable(self, iterable):
1129 self.visit_typed_object(iterable) 1135 self.visit_typed_object(iterable)
1130 1136
1131 def visit_maplike(self, maplike): 1137 def visit_maplike(self, maplike):
1132 self.visit_typed_object(maplike) 1138 self.visit_typed_object(maplike)
1133 1139
1134 def visit_setlike(self, setlike): 1140 def visit_setlike(self, setlike):
1135 self.visit_typed_object(setlike) 1141 self.visit_typed_object(setlike)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698