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

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

Issue 1832713002: Optimize dartium dart:html bindings so real world application performance is acceptable. Improves d… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: update cached patches Created 4 years, 8 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/generate_blink_file.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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 if parameter_count is None: 536 if parameter_count is None:
537 parameter_count = len(self.param_infos) 537 parameter_count = len(self.param_infos)
538 if not type_registry: 538 if not type_registry:
539 return [p.name for p in self.param_infos[:parameter_count]] 539 return [p.name for p in self.param_infos[:parameter_count]]
540 else: 540 else:
541 parameters = [] 541 parameters = []
542 for p in self.param_infos[:parameter_count]: 542 for p in self.param_infos[:parameter_count]:
543 type_id = p.type_id 543 type_id = p.type_id
544 # Unwrap the type to get the JsObject if Type is: 544 # Unwrap the type to get the JsObject if Type is:
545 # 545 #
546 # - known IDL type
547 # - type_id is None then it's probably a union type or overloaded 546 # - type_id is None then it's probably a union type or overloaded
548 # it's a dynamic/any type 547 # it's a dynamic/any type
549 # - type is Object 548 # - type is Object
550 # 549 #
551 # JsObject maybe stored in the Dart class.
552 if (wrap_unwrap_type_blink(type_id, type_registry)): 550 if (wrap_unwrap_type_blink(type_id, type_registry)):
553 type_is_callback = self.isCallback(type_registry, type_id) 551 type_is_callback = self.isCallback(type_registry, type_id)
554 if (dart_js_interop and type_id == 'EventListener' and 552 if (dart_js_interop and type_id == 'EventListener' and
555 self.name in ['addEventListener', 'removeEventListener']): 553 self.name in ['addEventListener', 'removeEventListener']):
556 # Events fired need use a JsFunction not a anonymous closure to 554 # Events fired need use a JSFunction not a anonymous closure to
557 # insure the event can really be removed. 555 # insure the event can really be removed.
558 parameters.append('unwrap_jso(js.allowInterop(%s))' % p.name) 556 parameters.append('js.allowInterop(%s)' % p.name)
559 elif dart_js_interop and type_id == 'FontFaceSetForEachCallback': 557 # These commented out cases don't actually generate any code.
558 # elif dart_js_interop and type_id == 'FontFaceSetForEachCallback':
560 # forEach is supported in the DOM for FontFaceSet as it iterates 559 # forEach is supported in the DOM for FontFaceSet as it iterates
561 # over the Javascript Object the callback parameters are also 560 # over the Javascript Object the callback parameters are also
562 # Javascript objects and must be wrapped. 561 # Javascript objects and must be wrapped.
563 parameters.append('unwrap_jso((fontFace, fontFaceAgain, set) => %s (wrap_jso(fontFace), wrap_jso(fontFaceAgain), wrap_jso(set)))' % p.name) 562 # parameters.append('(fontFace, fontFaceAgain, set) => %s(fontFace, fontFaceAgain, wrap_jso(set))' % p.name)
564 elif dart_js_interop and type_id == 'HeadersForEachCallback': 563 # elif dart_js_interop and type_id == 'HeadersForEachCallback':
565 # forEach is supported in the DOM for Headers as it iterates 564 # forEach is supported in the DOM for Headers as it iterates
566 # over the Javascript Object the callback parameters are also 565 # over the Javascript Object the callback parameters are also
567 # Javascript objects and must be wrapped. 566 # Javascript objects and must be wrapped.
568 parameters.append('unwrap_jso((String value, String key, map) => % s(value, key, wrap_jso(map)))' % p.name) 567 # parameters.append('(String value, String key, map) => %s(value, k ey, wrap_jso(map))' % p.name)
569 elif dart_js_interop and type_is_callback and not(isRemoveOperation): 568 elif dart_js_interop and type_is_callback and not(isRemoveOperation):
570 # Any remove operation that has a a callback doesn't need wrapping. 569 # Any remove operation that has a a callback doesn't need wrapping.
571 # TODO(terry): Kind of hacky but handles all the cases we care about 570 # TODO(terry): Kind of hacky but handles all the cases we care about
572 callback_type = type_registry._database._all_interfaces[type_id] 571 callback_type = type_registry._database._all_interfaces[type_id]
573 callback_args_decl = [] 572 callback_args_decl = []
574 callback_args_call = [] 573 callback_args_call = []
575 for callback_arg in callback_type.operations[0].arguments: 574 for callback_arg in callback_type.operations[0].arguments:
576 if dart_js_interop: 575 if dart_js_interop:
577 dart_type = '' # For non-primitives we will be passing JsObject for non-primitives, so ignore types 576 dart_type = '' # For non-primitives we will be passing JsObject for non-primitives, so ignore types
578 else: 577 else:
579 dart_type = type_registry.DartType(callback_arg.type.id) + ' ' 578 dart_type = type_registry.DartType(callback_arg.type.id) + ' '
580 callback_args_decl.append('%s%s' % (dart_type, callback_arg.id)) 579 callback_args_decl.append('%s%s' % (dart_type, callback_arg.id))
581 if wrap_unwrap_type_blink(callback_arg.type.id, type_registry): 580 if wrap_unwrap_type_blink(callback_arg.type.id, type_registry):
582 callback_args_call.append('wrap_jso(%s)' % callback_arg.id) 581 callback_args_call.append(callback_arg.id)
583 else: 582 else:
584 callback_args_call.append(callback_arg.id) 583 callback_args_call.append(callback_arg.id)
585 parameters.append('unwrap_jso((%s) => %s(%s))' % 584 parameters.append('(%s) => %s(%s)' %
586 (", ".join(callback_args_decl), 585 (", ".join(callback_args_decl),
587 p.name, 586 p.name,
588 ", ".join(callback_args_call))) 587 ", ".join(callback_args_call)))
589 else: 588 else:
590 parameters.append('unwrap_jso(%s)' % p.name) 589 parameters.append(p.name)
591 else: 590 else:
592 if dart_js_interop: 591 if dart_js_interop:
593 conversion = backend._InputConversion(p.type_id, self.declared_name) 592 conversion = backend._InputConversion(p.type_id, self.declared_name)
594 passParam = p.name 593 passParam = p.name
595 if conversion: 594 if conversion:
596 # Need to pass the IDL Dictionary from Dart Map to JavaScript obje ct. 595 # Need to pass the IDL Dictionary from Dart Map to JavaScript obje ct.
597 passParam = '{0}({1})'.format(conversion.function_name, p.name) 596 passParam = '{0}({1})'.format(conversion.function_name, p.name)
598 else: 597 else:
599 passParam = p.name 598 passParam = p.name
600 parameters.append(passParam) 599 parameters.append(passParam)
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 class_name = '%sIDLTypeInfo' % type_data.clazz 1487 class_name = '%sIDLTypeInfo' % type_data.clazz
1489 return globals()[class_name](type_name, type_data) 1488 return globals()[class_name](type_name, type_data)
1490 1489
1491 def isList(return_type): 1490 def isList(return_type):
1492 return return_type.startswith('List<') if return_type else False 1491 return return_type.startswith('List<') if return_type else False
1493 1492
1494 def get_list_type(return_type): 1493 def get_list_type(return_type):
1495 # Get the list type NNNN inside of List<NNNN> 1494 # Get the list type NNNN inside of List<NNNN>
1496 return return_type[5:-1] if isList(return_type) else return_type 1495 return return_type[5:-1] if isList(return_type) else return_type
1497 1496
1497 # TODO(jacobr): remove these obsolete methods as we don't actually
1498 # perform any wrapping.
1498 def wrap_unwrap_list_blink(return_type, type_registry): 1499 def wrap_unwrap_list_blink(return_type, type_registry):
1499 """Return True if the type is the list type is a blink know 1500 """Return True if the type is the list type is a blink know
1500 type e.g., List<Node>, List<FontFace>, etc.""" 1501 type e.g., List<Node>, List<FontFace>, etc."""
1501 if isList(return_type): 1502 if isList(return_type):
1502 list_type = get_list_type(return_type) 1503 list_type = get_list_type(return_type)
1503 if type_registry.HasInterface(list_type): 1504 if type_registry.HasInterface(list_type):
1504 return True; 1505 return True;
1505 1506
1506 def wrap_unwrap_type_blink(return_type, type_registry): 1507 def wrap_unwrap_type_blink(return_type, type_registry):
1507 """Returns True if the type is a blink type that requires wrap_jso or 1508 """Returns True if the type is a blink type that requires wrap_jso or
1508 unwrap_jso""" 1509 unwrap_jso"""
1509 if return_type and return_type.startswith('Html'): 1510 if return_type and return_type.startswith('Html'):
1510 return_type = return_type.replace('Html', 'HTML', 1) 1511 return_type = return_type.replace('Html', 'HTML', 1)
1511 return (type_registry.HasInterface(return_type) or not(return_type) or 1512 return (not(return_type) or
1512 return_type == 'Object' or 1513 return_type == 'Object' or
1513 return_type == 'dynamic' or 1514 return_type == 'dynamic')
1514 return_type == 'Future' or
1515 return_type == 'SqlDatabase' or # renamed to Database
1516 return_type == 'HTMLElement' or
1517 return_type == 'MutationObserver' or
1518 (return_type.endswith('[]') and return_type != 'DOMString[]'))
1519 1515
1520 def wrap_type_blink(return_type, type_registry): 1516 def wrap_type_blink(return_type, type_registry):
1521 """Returns True if the type is a blink type that requires wrap_jso but 1517 """Returns True if the type is a blink type that requires wrap_jso but
1522 NOT unwrap_jso""" 1518 NOT unwrap_jso"""
1523 return (return_type == 'Map' or 1519 return (return_type == 'Map' or
1524 return_type == 'Rectangle') 1520 return_type == 'Rectangle')
1525 1521
1526 def wrap_return_type_blink(return_type, type_name, type_registry): 1522 def wrap_return_type_blink(return_type, type_name, type_registry):
1527 """Returns True if we should wrap the returned value. This checks 1523 """Returns True if we should wrap the returned value. This checks
1528 a number of different variations, calling the more basic functions 1524 a number of different variations, calling the more basic functions
1529 above.""" 1525 above."""
1530 return (wrap_unwrap_type_blink(return_type, type_registry) or 1526 return (wrap_unwrap_type_blink(return_type, type_registry) or
1531 wrap_unwrap_type_blink(type_name, type_registry) or 1527 wrap_unwrap_type_blink(type_name, type_registry) or
1532 wrap_type_blink(return_type, type_registry) or 1528 wrap_type_blink(return_type, type_registry) or
1533 wrap_unwrap_list_blink(return_type, type_registry)) 1529 wrap_unwrap_list_blink(return_type, type_registry))
OLDNEW
« no previous file with comments | « tools/dom/scripts/generate_blink_file.py ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698