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

Side by Side Diff: tools/dom/scripts/htmldartgenerator.py

Issue 15138002: Added tests to previously broken functionality and added null checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: I think this is good now. Created 7 years, 7 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
« no previous file with comments | « tests/html/canvasrenderingcontext2d_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the system to generate 6 """This module provides shared functionality for the system to generate
7 dart:html APIs from the IDL database.""" 7 dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 from generator import AnalyzeOperation, ConstantOutputOrder, \ 10 from generator import AnalyzeOperation, ConstantOutputOrder, \
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 227
228 if is_void: 228 if is_void:
229 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n') 229 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n')
230 else: 230 else:
231 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n') 231 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n')
232 232
233 version[0] += 1 233 version[0] += 1
234 generate_call(stmts_emitter, call_emitter, 234 generate_call(stmts_emitter, call_emitter,
235 version[0], signature_index, argument_count) 235 version[0], signature_index, argument_count)
236 236
237 def IsDartTypeNullable(type_signature):
238 return type_signature not in ['int', 'double', 'num', 'bool']
239
237 def GenerateChecksAndCall(signature_index, argument_count): 240 def GenerateChecksAndCall(signature_index, argument_count):
238 checks = [] 241 checks = []
239 for i in range(0, argument_count): 242 for i in range(0, argument_count):
240 argument = signatures[signature_index][i] 243 argument = signatures[signature_index][i]
241 parameter_name = parameter_names[i] 244 parameter_name = parameter_names[i]
242 test_type = self._DartType(argument.type.id) 245 test_type = self._DartType(argument.type.id)
246 nullable = argument.type.nullable
247
243 if test_type in ['dynamic', 'Object']: 248 if test_type in ['dynamic', 'Object']:
244 checks.append('?%s' % parameter_name) 249 checks.append('?%s' % parameter_name)
245 elif not can_omit_type_check(test_type, i): 250 elif not can_omit_type_check(test_type, i):
251 nullable = True
246 checks.append('(%s is %s || %s == null)' % ( 252 checks.append('(%s is %s || %s == null)' % (
247 parameter_name, test_type, parameter_name)) 253 parameter_name, test_type, parameter_name))
254
255 if not nullable and not IsDartTypeNullable(test_type):
256 for signature in signatures:
257 if (len(signature) <= i or signature[i].id not in parameter_name):
Anton Muhin 2013/05/22 12:27:33 in parameter_name or == parameter_name?
Andrei Mouravski 2013/05/22 12:37:42 This is to handle the case of merged types. On 20
Anton Muhin 2013/05/22 12:50:56 I am really concerned with the cases like (hypothe
Andrei Mouravski 2013/05/22 14:40:10 Agreed. I'll run a regex instead or else split on
Andrei Mouravski 2013/05/23 09:53:27 Done.
258
259 checks.append('%s != null' % parameter_name)
Anton Muhin 2013/05/22 12:27:33 still, I do not understand why this check is neede
Andrei Mouravski 2013/05/22 12:37:42 Because other logic does some dumb things and if t
Anton Muhin 2013/05/22 12:50:56 May you, please, provide an exact example: which c
Andrei Mouravski 2013/05/22 14:40:10 Please take a look at the tests added in this CL.
260 break
261
248 # There can be multiple presence checks. We need them all since a later 262 # There can be multiple presence checks. We need them all since a later
249 # optional argument could have been passed by name, leaving 'holes'. 263 # optional argument could have been passed by name, leaving 'holes'.
250 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) 264 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] )
251 265
252 GenerateCall(signature_index, argument_count, checks) 266 GenerateCall(signature_index, argument_count, checks)
253 267
254 # TODO: Optimize the dispatch to avoid repeated checks. 268 # TODO: Optimize the dispatch to avoid repeated checks.
255 if len(signatures) > 1: 269 if len(signatures) > 1:
256 index_swaps = {} 270 index_swaps = {}
257 for signature_index, signature in enumerate(signatures): 271 for signature_index, signature in enumerate(signatures):
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if interface.parents: 594 if interface.parents:
581 parent = interface.parents[0] 595 parent = interface.parents[0]
582 if IsPureInterface(parent.type.id): 596 if IsPureInterface(parent.type.id):
583 walk(interface.parents) 597 walk(interface.parents)
584 else: 598 else:
585 walk(interface.parents[1:]) 599 walk(interface.parents[1:])
586 return result 600 return result
587 601
588 def _DartType(self, type_name): 602 def _DartType(self, type_name):
589 return self._type_registry.DartType(type_name) 603 return self._type_registry.DartType(type_name)
OLDNEW
« no previous file with comments | « tests/html/canvasrenderingcontext2d_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698