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

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

Issue 1173403004: Changed to use JSInterop (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Re-gen'd somehow diffs stopped showing up in CL Created 5 years, 5 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
« no previous file with comments | « tools/dom/scripts/dartdomgenerator.py ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | 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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import json 10 import json
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 def param_name(param_info): 507 def param_name(param_info):
508 if self.requires_named_arguments and param_info.is_optional: 508 if self.requires_named_arguments and param_info.is_optional:
509 return '%s : %s' % (param_info.name, param_info.name) 509 return '%s : %s' % (param_info.name, param_info.name)
510 else: 510 else:
511 return param_info.name 511 return param_info.name
512 512
513 if parameter_count is None: 513 if parameter_count is None:
514 parameter_count = len(self.param_infos) 514 parameter_count = len(self.param_infos)
515 return ', '.join(map(param_name, self.param_infos[:parameter_count])) 515 return ', '.join(map(param_name, self.param_infos[:parameter_count]))
516 516
517 def ParametersAsListOfVariables(self, parameter_count=None): 517 def wrap_unwrap_list_blink(self, return_type, type_registry):
518 """Return True if the type is a List<Node>"""
519 return return_type.startswith('List<Node>')
520
521 def wrap_unwrap_type_blink(self, return_type, type_registry):
522 """Returns True if the type is a blink type that requires wrap_jso or unwrap _jso.
523 Notice we look for any class that starts with HtmlNNNN e.g., HtmlDocument, e tc. """
524 return (type_registry.HasInterface(return_type) or not(return_type) or
525 return_type == 'Object' or return_type.startswith('Html') or
526 return_type == 'MutationObserver')
527
528 def ParametersAsListOfVariables(self, parameter_count=None, type_registry=None ):
518 """Returns a list of the first parameter_count parameter names 529 """Returns a list of the first parameter_count parameter names
519 as raw variables. 530 as raw variables.
520 """ 531 """
521 if parameter_count is None: 532 if parameter_count is None:
522 parameter_count = len(self.param_infos) 533 parameter_count = len(self.param_infos)
523 return [p.name for p in self.param_infos[:parameter_count]] 534 if not type_registry:
535 return [p.name for p in self.param_infos[:parameter_count]]
536 else:
537 parameters = []
538 for p in self.param_infos[:parameter_count]:
539 type_id = p.type_id
540 # Unwrap the type to get the JsObject if Type is:
541 #
542 # - known IDL type
543 # - type_id is None then it's probably a union type or overloaded
544 # it's a dynamic/any type
545 # - type is Object
546 #
547 # JsObject maybe stored in the Dart class.
548 if (self.wrap_unwrap_type_blink(type_id, type_registry)):
549 if type_id == 'EventListener' and (self.name == 'addEventListener' or self.name == 'addListener'):
550 # Events fired need to wrap the Javascript Object passed as a parame ter in event.
551 parameters.append('unwrap_jso((Event event) => %s(wrap_jso(event)))' % p.name)
552 else:
553 parameters.append('unwrap_jso(%s)' % p.name)
554 else:
555 passParam = p.name
556 if type_id == 'Dictionary':
557 # Need to pass the IDL Dictionary from Dart Map to JavaScript object .
558 passParam = '{0} != null ? new js.JsObject.jsify({0}) : {0}'.format( p.name)
559 parameters.append(passParam)
560
561 return parameters
524 562
525 def ParametersAsStringOfVariables(self, parameter_count=None): 563 def ParametersAsStringOfVariables(self, parameter_count=None):
526 """Returns a string containing the first parameter_count parameter names 564 """Returns a string containing the first parameter_count parameter names
527 as raw variables, comma separated. 565 as raw variables, comma separated.
528 """ 566 """
529 return ', '.join(self.ParametersAsListOfVariables(parameter_count)) 567 return ', '.join(self.ParametersAsListOfVariables(parameter_count))
530 568
531 def IsStatic(self): 569 def IsStatic(self):
532 is_static = self.overloads[0].is_static 570 is_static = self.overloads[0].is_static
533 assert any([is_static == o.is_static for o in self.overloads]) 571 assert any([is_static == o.is_static for o in self.overloads])
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 _svg_supplemental_includes = [ 1313 _svg_supplemental_includes = [
1276 '"core/svg/properties/SVGPropertyTraits.h"', 1314 '"core/svg/properties/SVGPropertyTraits.h"',
1277 ] 1315 ]
1278 1316
1279 class TypeRegistry(object): 1317 class TypeRegistry(object):
1280 def __init__(self, database, renamer=None): 1318 def __init__(self, database, renamer=None):
1281 self._database = database 1319 self._database = database
1282 self._renamer = renamer 1320 self._renamer = renamer
1283 self._cache = {} 1321 self._cache = {}
1284 1322
1323 def HasInterface(self, type_name):
1324 return self._database.HasInterface(type_name)
1325
1285 def TypeInfo(self, type_name): 1326 def TypeInfo(self, type_name):
1286 if not type_name in self._cache: 1327 if not type_name in self._cache:
1287 self._cache[type_name] = self._TypeInfo(type_name) 1328 self._cache[type_name] = self._TypeInfo(type_name)
1288 return self._cache[type_name] 1329 return self._cache[type_name]
1289 1330
1290 def DartType(self, type_name): 1331 def DartType(self, type_name):
1291 return self.TypeInfo(type_name).dart_type() 1332 return self.TypeInfo(type_name).dart_type()
1292 1333
1293 def _TypeInfo(self, type_name): 1334 def _TypeInfo(self, type_name):
1294 match = re.match(r'(?:sequence<([\w ]+)>|(\w+)\[\])$', type_name) 1335 match = re.match(r'(?:sequence<([\w ]+)>|(\w+)\[\])$', type_name)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 if type_data.clazz == 'BasicTypedList': 1385 if type_data.clazz == 'BasicTypedList':
1345 if type_name == 'ArrayBuffer': 1386 if type_name == 'ArrayBuffer':
1346 dart_interface_name = 'ByteBuffer' 1387 dart_interface_name = 'ByteBuffer'
1347 else: 1388 else:
1348 dart_interface_name = self._renamer.RenameInterfaceId(type_name) 1389 dart_interface_name = self._renamer.RenameInterfaceId(type_name)
1349 return BasicTypedListIDLTypeInfo( 1390 return BasicTypedListIDLTypeInfo(
1350 type_name, type_data, dart_interface_name, self) 1391 type_name, type_data, dart_interface_name, self)
1351 1392
1352 class_name = '%sIDLTypeInfo' % type_data.clazz 1393 class_name = '%sIDLTypeInfo' % type_data.clazz
1353 return globals()[class_name](type_name, type_data) 1394 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/scripts/dartdomgenerator.py ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698