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

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

Issue 338893004: Extend ScalarValueString handling to include constructors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Common up more string-related type checks Created 6 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 """IDL type handling. 4 """IDL type handling.
5 5
6 Classes: 6 Classes:
7 IdlType 7 IdlType
8 IdlUnionType 8 IdlUnionType
9 """ 9 """
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 'unrestricted float': 'UnrestrictedFloat', 63 'unrestricted float': 'UnrestrictedFloat',
64 'double': 'Double', 64 'double': 'Double',
65 'unrestricted double': 'UnrestrictedDouble', 65 'unrestricted double': 'UnrestrictedDouble',
66 'DOMString': 'String', 66 'DOMString': 'String',
67 'ByteString': 'ByteString', 67 'ByteString': 'ByteString',
68 'ScalarValueString': 'ScalarValueString', 68 'ScalarValueString': 'ScalarValueString',
69 'object': 'Object', 69 'object': 'Object',
70 'Date': 'Date', 70 'Date': 'Date',
71 } 71 }
72 72
73 STRING_TYPES = frozenset([
74 # http://heycam.github.io/webidl/, Section 4.5.1.1 (step 10.11)
Jens Widell 2014/06/20 08:07:06 Add "#es-interface-call" to the link, instead of t
sof 2014/06/20 08:15:09 Done.
75 # (Interface object [[Call]] method's string types.)
76 'String',
77 'ByteString',
78 'ScalarValueString',
79 ])
80
73 81
74 ################################################################################ 82 ################################################################################
75 # Inheritance 83 # Inheritance
76 ################################################################################ 84 ################################################################################
77 85
78 ancestors = defaultdict(list) # interface_name -> ancestors 86 ancestors = defaultdict(list) # interface_name -> ancestors
79 87
80 def inherits_interface(interface_name, ancestor_name): 88 def inherits_interface(interface_name, ancestor_name):
81 return (interface_name == ancestor_name or 89 return (interface_name == ancestor_name or
82 ancestor_name in ancestors[interface_name]) 90 ancestor_name in ancestors[interface_name])
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 # http://www.w3.org/TR/WebIDL/#idl-interface 196 # http://www.w3.org/TR/WebIDL/#idl-interface
189 # In C++ these are RefPtr or PassRefPtr types. 197 # In C++ these are RefPtr or PassRefPtr types.
190 return not(self.is_basic_type or 198 return not(self.is_basic_type or
191 self.is_composite_type or 199 self.is_composite_type or
192 self.is_callback_function or 200 self.is_callback_function or
193 self.is_enum or 201 self.is_enum or
194 self.name == 'Object' or 202 self.name == 'Object' or
195 self.name == 'Promise') # Promise will be basic in future 203 self.name == 'Promise') # Promise will be basic in future
196 204
197 @property 205 @property
206 def is_string_type(self):
207 return self.base_type_name in STRING_TYPES
208
209 @property
210 def may_raise_exception_on_conversion(self):
211 return (self.is_integer_type or
212 self.name in ('ByteString', 'ScalarValueString'))
213
214 @property
198 def is_union_type(self): 215 def is_union_type(self):
199 return isinstance(self, IdlUnionType) 216 return isinstance(self, IdlUnionType)
200 217
201 @property 218 @property
219 def base_type_name(self):
220 base_type = self.base_type
221 return TYPE_NAMES.get(base_type, base_type)
222
223 @property
202 def name(self): 224 def name(self):
203 """Return type name. 225 """Return type name.
204 226
205 http://heycam.github.io/webidl/#dfn-type-name 227 http://heycam.github.io/webidl/#dfn-type-name
206 """ 228 """
207 base_type = self.base_type 229 base_type_name = self.base_type_name
208 base_type_name = TYPE_NAMES.get(base_type, base_type)
209 if self.is_array: 230 if self.is_array:
210 return base_type_name + 'Array' 231 return base_type_name + 'Array'
211 if self.is_sequence: 232 if self.is_sequence:
212 return base_type_name + 'Sequence' 233 return base_type_name + 'Sequence'
213 if self.is_nullable: 234 if self.is_nullable:
214 return base_type_name + 'OrNull' 235 return base_type_name + 'OrNull'
215 return base_type_name 236 return base_type_name
216 237
217 @classmethod 238 @classmethod
218 def set_callback_functions(cls, new_callback_functions): 239 def set_callback_functions(cls, new_callback_functions):
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 333
313 @property 334 @property
314 def name(self): 335 def name(self):
315 return 'Or'.join(member_type.name for member_type in self.member_types) 336 return 'Or'.join(member_type.name for member_type in self.member_types)
316 337
317 def resolve_typedefs(self, typedefs): 338 def resolve_typedefs(self, typedefs):
318 self.member_types = [ 339 self.member_types = [
319 typedefs.get(member_type, member_type) 340 typedefs.get(member_type, member_type)
320 for member_type in self.member_types] 341 for member_type in self.member_types]
321 return self 342 return self
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_attributes.py » ('j') | Source/bindings/scripts/v8_methods.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698