OLD | NEW |
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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
7 | 7 |
8 import emitter | 8 import emitter |
9 import idlnode | 9 import idlnode |
10 import logging | 10 import logging |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 def __init__(self, templates, database, emitters, output_dir): | 1021 def __init__(self, templates, database, emitters, output_dir): |
1022 """Prepared for generating wrapping implementation. | 1022 """Prepared for generating wrapping implementation. |
1023 | 1023 |
1024 - Creates emitter for JS code. | 1024 - Creates emitter for JS code. |
1025 - Creates emitter for Dart code. | 1025 - Creates emitter for Dart code. |
1026 """ | 1026 """ |
1027 super(WrappingImplementationSystem, self).__init__( | 1027 super(WrappingImplementationSystem, self).__init__( |
1028 templates, database, emitters, output_dir) | 1028 templates, database, emitters, output_dir) |
1029 self._dart_wrapping_file_paths = [] | 1029 self._dart_wrapping_file_paths = [] |
1030 | 1030 |
1031 js_file_name = os.path.join(output_dir, 'wrapping_dom.js') | |
1032 code = self._emitters.FileEmitter(js_file_name) | |
1033 template = self._templates.Load('wrapping_dom.js') | |
1034 (self._wrapping_js_natives, | |
1035 self._wrapping_map) = code.Emit(template) | |
1036 | |
1037 _logger.info('Started Generating %s' % js_file_name) | |
1038 | |
1039 # Set of (interface, name, kind), kind is 'attribute' or 'operation'. | |
1040 self._wrapping_externs = set() | |
1041 | |
1042 | 1031 |
1043 def InterfaceGenerator(self, | 1032 def InterfaceGenerator(self, |
1044 interface, | 1033 interface, |
1045 common_prefix, | 1034 common_prefix, |
1046 super_interface_name, | 1035 super_interface_name, |
1047 source_filter): | 1036 source_filter): |
1048 """.""" | 1037 """.""" |
1049 interface_name = interface.id | 1038 interface_name = interface.id |
1050 dart_wrapping_file_path = self._FilePathForDartWrappingImpl(interface_name) | 1039 dart_wrapping_file_path = self._FilePathForDartWrappingImpl(interface_name) |
1051 | 1040 |
1052 self._dart_wrapping_file_paths.append(dart_wrapping_file_path) | 1041 self._dart_wrapping_file_paths.append(dart_wrapping_file_path) |
1053 | 1042 |
1054 dart_code = self._emitters.FileEmitter(dart_wrapping_file_path) | 1043 dart_code = self._emitters.FileEmitter(dart_wrapping_file_path) |
1055 dart_code.Emit(self._templates.Load('wrapping_impl.darttemplate')) | 1044 dart_code.Emit(self._templates.Load('wrapping_impl.darttemplate')) |
1056 return WrappingInterfaceGenerator(interface, super_interface_name, | 1045 return WrappingInterfaceGenerator(interface, super_interface_name, |
1057 dart_code, self._wrapping_js_natives, | 1046 dart_code, |
1058 self._wrapping_map, | |
1059 self._wrapping_externs, | |
1060 self._BaseDefines(interface)) | 1047 self._BaseDefines(interface)) |
1061 | 1048 |
1062 def ProcessCallback(self, interface, info): | 1049 def ProcessCallback(self, interface, info): |
1063 pass | 1050 pass |
1064 | 1051 |
1065 def GenerateLibraries(self, lib_dir): | 1052 def GenerateLibraries(self, lib_dir): |
1066 # Library generated for implementation. | 1053 # Library generated for implementation. |
1067 self._GenerateLibFile( | 1054 self._GenerateLibFile( |
1068 'wrapping_dom.darttemplate', | 1055 'wrapping_dom.darttemplate', |
1069 os.path.join(lib_dir, 'wrapping_dom.dart'), | 1056 os.path.join(lib_dir, 'wrapping_dom.dart'), |
1070 (self._interface_system._dart_interface_file_paths + | 1057 (self._interface_system._dart_interface_file_paths + |
1071 self._interface_system._dart_callback_file_paths + | 1058 self._interface_system._dart_callback_file_paths + |
1072 # FIXME: Move the implementation to a separate library. | 1059 # FIXME: Move the implementation to a separate library. |
1073 self._dart_wrapping_file_paths | 1060 self._dart_wrapping_file_paths |
1074 )) | 1061 )) |
1075 | 1062 |
1076 | 1063 |
1077 def Finish(self): | 1064 def Finish(self): |
1078 self._GenerateJavaScriptExternsWrapping(self._database, self._output_dir) | 1065 pass |
1079 | 1066 |
1080 | 1067 |
1081 def _FilePathForDartWrappingImpl(self, interface_name): | 1068 def _FilePathForDartWrappingImpl(self, interface_name): |
1082 """Returns the file path of the Dart wrapping implementation.""" | 1069 """Returns the file path of the Dart wrapping implementation.""" |
1083 return os.path.join(self._output_dir, 'src', 'wrapping', | 1070 return os.path.join(self._output_dir, 'src', 'wrapping', |
1084 '_%sWrappingImplementation.dart' % interface_name) | 1071 '_%sWrappingImplementation.dart' % interface_name) |
1085 | 1072 |
1086 def _GenerateJavaScriptExternsWrapping(self, database, output_dir): | |
1087 """Generates a JavaScript externs file. | |
1088 | |
1089 Generates an externs file that is consistent with generated JavaScript code | |
1090 and Dart APIs for the wrapping implementation. | |
1091 """ | |
1092 externs_file_name = os.path.join(output_dir, 'wrapping_dom_externs.js') | |
1093 code = self._emitters.FileEmitter(externs_file_name) | |
1094 _logger.info('Started generating %s' % externs_file_name) | |
1095 | |
1096 template = self._templates.Load('wrapping_dom_externs.js') | |
1097 namespace = 'dom_externs' | |
1098 members = code.Emit(template, NAMESPACE=namespace) | |
1099 | |
1100 # TODO: Filter out externs that are known to the JavaScript back-end. Some | |
1101 # of the known externs have useful declarations like @nosideeffects that | |
1102 # might improve back-end analysis. | |
1103 | |
1104 names = dict() # maps name to (interface, kind) | |
1105 for (interface, name, kind) in self._wrapping_externs: | |
1106 if name not in _javascript_keywords: | |
1107 if name not in names: | |
1108 names[name] = set() | |
1109 names[name].add((interface, kind)) | |
1110 | |
1111 for name in sorted(names.keys()): | |
1112 # Simply export the property name. | |
1113 extern = emitter.Format('$NAMESPACE.$NAME;', | |
1114 NAMESPACE=namespace, NAME=name) | |
1115 members.EmitRaw(extern) | |
1116 # Add a big comment of all the attributes and operations contributing to | |
1117 # the export. | |
1118 filler = ' ' * (40 - 2 - len(extern)) # '2' for 2 spaces before comment. | |
1119 separator = filler + ' //' | |
1120 for (interface, kind) in sorted(names[name]): | |
1121 members.Emit('$SEP $KIND $INTERFACE.$NAME', | |
1122 NAME=name, INTERFACE=interface, KIND=kind, SEP=separator) | |
1123 separator = ',' | |
1124 members.Emit('\n') | |
1125 | |
1126 # ------------------------------------------------------------------------------ | 1073 # ------------------------------------------------------------------------------ |
1127 | 1074 |
1128 class FrogSystem(System): | 1075 class FrogSystem(System): |
1129 | 1076 |
1130 def __init__(self, templates, database, emitters, output_dir): | 1077 def __init__(self, templates, database, emitters, output_dir): |
1131 super(FrogSystem, self).__init__( | 1078 super(FrogSystem, self).__init__( |
1132 templates, database, emitters, output_dir) | 1079 templates, database, emitters, output_dir) |
1133 self._dart_frog_file_paths = [] | 1080 self._dart_frog_file_paths = [] |
1134 | 1081 |
1135 def InterfaceGenerator(self, | 1082 def InterfaceGenerator(self, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 pass | 1302 pass |
1356 | 1303 |
1357 def AddOperation(self, info): | 1304 def AddOperation(self, info): |
1358 pass | 1305 pass |
1359 | 1306 |
1360 # ------------------------------------------------------------------------------ | 1307 # ------------------------------------------------------------------------------ |
1361 | 1308 |
1362 class WrappingInterfaceGenerator(object): | 1309 class WrappingInterfaceGenerator(object): |
1363 """Generates Dart and JS implementation for one DOM IDL interface.""" | 1310 """Generates Dart and JS implementation for one DOM IDL interface.""" |
1364 | 1311 |
1365 def __init__(self, interface, super_interface, dart_code, js_code, type_map, | 1312 def __init__(self, interface, super_interface, dart_code, base_members): |
1366 externs, base_members): | |
1367 """Generates Dart and JS code for the given interface. | 1313 """Generates Dart and JS code for the given interface. |
1368 | 1314 |
1369 Args: | 1315 Args: |
1370 | 1316 |
1371 interface: an IDLInterface instance. It is assumed that all types have | 1317 interface: an IDLInterface instance. It is assumed that all types have |
1372 been converted to Dart types (e.g. int, String), unless they are in | 1318 been converted to Dart types (e.g. int, String), unless they are in |
1373 the same package as the interface. | 1319 the same package as the interface. |
1374 super_interface: A string or None, the name of the common interface that | 1320 super_interface: A string or None, the name of the common interface that |
1375 this interface implements, if any. | 1321 this interface implements, if any. |
1376 dart_code: an Emitter for the file containing the Dart implementation | 1322 dart_code: an Emitter for the file containing the Dart implementation |
1377 class. | 1323 class. |
1378 js_code: an Emitter for the file containing JS code. | |
1379 type_map: an Emitter for the map from tokens to wrapper factory. | |
1380 externs: a set of (class, property, kind) externs. kind is 'attribute' or | |
1381 'operation'. | |
1382 base_members: a set of names of members defined in a base class. This is | 1324 base_members: a set of names of members defined in a base class. This is |
1383 used to avoid static member 'overriding' in the generated Dart code. | 1325 used to avoid static member 'overriding' in the generated Dart code. |
1384 """ | 1326 """ |
1385 self._interface = interface | 1327 self._interface = interface |
1386 self._super_interface = super_interface | 1328 self._super_interface = super_interface |
1387 self._dart_code = dart_code | 1329 self._dart_code = dart_code |
1388 self._js_code = js_code | |
1389 self._type_map = type_map | |
1390 self._externs = externs | |
1391 self._base_members = base_members | 1330 self._base_members = base_members |
1392 self._current_secondary_parent = None | 1331 self._current_secondary_parent = None |
1393 | 1332 |
1394 | 1333 |
1395 def StartInterface(self): | 1334 def StartInterface(self): |
1396 interface = self._interface | 1335 interface = self._interface |
1397 interface_name = interface.id | 1336 interface_name = interface.id |
1398 | 1337 |
1399 self._class_name = self._ImplClassName(interface_name) | 1338 self._class_name = self._ImplClassName(interface_name) |
1400 self._type_map.Emit(' "$INTERFACE": native_$(CLASS)_create_$(CLASS),\n', | |
1401 INTERFACE=interface_name, CLASS=self._class_name) | |
1402 | 1339 |
1403 base = self._BaseClassName(interface) | 1340 base = self._BaseClassName(interface) |
1404 | 1341 |
1405 (self._members_emitter, | 1342 (self._members_emitter, |
1406 self._top_level_emitter) = self._dart_code.Emit( | 1343 self._top_level_emitter) = self._dart_code.Emit( |
1407 '\n' | 1344 '\n' |
1408 'class $CLASS extends $BASE implements $INTERFACE {\n' | 1345 'class $CLASS extends $BASE implements $INTERFACE {\n' |
1409 ' $CLASS() : super() {}\n' | 1346 ' $CLASS() : super() {}\n' |
1410 '\n' | 1347 '\n' |
1411 ' static create_$CLASS() native {\n' | 1348 ' static create_$CLASS() native {\n' |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 def _AddGetter(self, attr): | 1407 def _AddGetter(self, attr): |
1471 # FIXME: Instead of injecting the interface name into the method when it is | 1408 # FIXME: Instead of injecting the interface name into the method when it is |
1472 # also implemented in the base class, suppress the method altogether if it | 1409 # also implemented in the base class, suppress the method altogether if it |
1473 # has the same signature. I.e., let the JS do the virtual dispatch instead. | 1410 # has the same signature. I.e., let the JS do the virtual dispatch instead. |
1474 method_name = self._MethodName('_get_', attr.id) | 1411 method_name = self._MethodName('_get_', attr.id) |
1475 self._members_emitter.Emit( | 1412 self._members_emitter.Emit( |
1476 '\n' | 1413 '\n' |
1477 ' $TYPE get $NAME() { return $METHOD(this); }\n' | 1414 ' $TYPE get $NAME() { return $METHOD(this); }\n' |
1478 ' static $TYPE $METHOD(var _this) native;\n', | 1415 ' static $TYPE $METHOD(var _this) native;\n', |
1479 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) | 1416 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) |
1480 if (self._interface.id, attr.id) not in _custom_getters: | |
1481 self._js_code.Emit( | |
1482 '\n' | |
1483 'function native_$(CLASS)_$(METHOD)(_this) {\n' | |
1484 ' try {\n' | |
1485 ' return __dom_wrap(_this.$dom.$NAME);\n' | |
1486 ' } catch (e) {\n' | |
1487 ' throw __dom_wrap_exception(e);\n' | |
1488 ' }\n' | |
1489 '}\n', | |
1490 CLASS=self._class_name, NAME=attr.id, METHOD=method_name) | |
1491 self._externs.add((self._interface.id, attr.id, 'attribute')) | |
1492 | 1417 |
1493 def _AddSetter(self, attr): | 1418 def _AddSetter(self, attr): |
1494 # FIXME: See comment on getter. | 1419 # FIXME: See comment on getter. |
1495 method_name = self._MethodName('_set_', attr.id) | 1420 method_name = self._MethodName('_set_', attr.id) |
1496 self._members_emitter.Emit( | 1421 self._members_emitter.Emit( |
1497 '\n' | 1422 '\n' |
1498 ' void set $NAME($TYPE value) { $METHOD(this, value); }\n' | 1423 ' void set $NAME($TYPE value) { $METHOD(this, value); }\n' |
1499 ' static void $METHOD(var _this, $TYPE value) native;\n', | 1424 ' static void $METHOD(var _this, $TYPE value) native;\n', |
1500 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) | 1425 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) |
1501 self._js_code.Emit( | |
1502 '\n' | |
1503 'function native_$(CLASS)_$(METHOD)(_this, value) {\n' | |
1504 ' try {\n' | |
1505 ' _this.$dom.$NAME = __dom_unwrap(value);\n' | |
1506 ' } catch (e) {\n' | |
1507 ' throw __dom_wrap_exception(e);\n' | |
1508 ' }\n' | |
1509 '}\n', | |
1510 CLASS=self._class_name, NAME=attr.id, METHOD=method_name) | |
1511 self._externs.add((self._interface.id, attr.id, 'attribute')) | |
1512 | 1426 |
1513 def AddSecondaryAttribute(self, interface, getter, setter): | 1427 def AddSecondaryAttribute(self, interface, getter, setter): |
1514 self._SecondaryContext(interface) | 1428 self._SecondaryContext(interface) |
1515 self.AddAttribute(getter, setter) | 1429 self.AddAttribute(getter, setter) |
1516 | 1430 |
1517 def AddSecondaryOperation(self, interface, info): | 1431 def AddSecondaryOperation(self, interface, info): |
1518 self._SecondaryContext(interface) | 1432 self._SecondaryContext(interface) |
1519 self.AddOperation(info) | 1433 self.AddOperation(info) |
1520 | 1434 |
1521 def _SecondaryContext(self, interface): | 1435 def _SecondaryContext(self, interface): |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 return ('HasIndexGetter' in interface.ext_attrs or | 1569 return ('HasIndexGetter' in interface.ext_attrs or |
1656 'HasNumericIndexGetter' in interface.ext_attrs) | 1570 'HasNumericIndexGetter' in interface.ext_attrs) |
1657 | 1571 |
1658 def _EmitNativeIndexGetter(self, interface, element_type): | 1572 def _EmitNativeIndexGetter(self, interface, element_type): |
1659 method_name = '_index' | 1573 method_name = '_index' |
1660 self._members_emitter.Emit( | 1574 self._members_emitter.Emit( |
1661 '\n' | 1575 '\n' |
1662 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n' | 1576 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n' |
1663 ' static $TYPE $METHOD(var _this, int index) native;\n', | 1577 ' static $TYPE $METHOD(var _this, int index) native;\n', |
1664 TYPE=element_type, METHOD=method_name) | 1578 TYPE=element_type, METHOD=method_name) |
1665 self._js_code.Emit( | |
1666 '\n' | |
1667 'function native_$(CLASS)_$(METHOD)(_this, index) {\n' | |
1668 ' try {\n' | |
1669 ' return __dom_wrap(_this.$dom[index]);\n' | |
1670 ' } catch (e) {\n' | |
1671 ' throw __dom_wrap_exception(e);\n' | |
1672 ' }\n' | |
1673 '}\n', | |
1674 CLASS=self._class_name, METHOD=method_name) | |
1675 | 1579 |
1676 def _HasNativeIndexSetter(self, interface): | 1580 def _HasNativeIndexSetter(self, interface): |
1677 return 'HasCustomIndexSetter' in interface.ext_attrs | 1581 return 'HasCustomIndexSetter' in interface.ext_attrs |
1678 | 1582 |
1679 def _EmitNativeIndexSetter(self, interface, element_type): | 1583 def _EmitNativeIndexSetter(self, interface, element_type): |
1680 method_name = '_set_index' | 1584 method_name = '_set_index' |
1681 self._members_emitter.Emit( | 1585 self._members_emitter.Emit( |
1682 '\n' | 1586 '\n' |
1683 ' void operator[]=(int index, $TYPE value) {\n' | 1587 ' void operator[]=(int index, $TYPE value) {\n' |
1684 ' return $METHOD(this, index, value);\n' | 1588 ' return $METHOD(this, index, value);\n' |
1685 ' }\n' | 1589 ' }\n' |
1686 ' static $METHOD(_this, index, value) native;\n', | 1590 ' static $METHOD(_this, index, value) native;\n', |
1687 TYPE=element_type, METHOD=method_name) | 1591 TYPE=element_type, METHOD=method_name) |
1688 self._js_code.Emit( | |
1689 '\n' | |
1690 'function native_$(CLASS)_$(METHOD)(_this, index, value) {\n' | |
1691 ' try {\n' | |
1692 ' return _this.$dom[index] = __dom_unwrap(value);\n' | |
1693 ' } catch (e) {\n' | |
1694 ' throw __dom_wrap_exception(e);\n' | |
1695 ' }\n' | |
1696 '}\n', | |
1697 CLASS=self._class_name, METHOD=method_name) | |
1698 | 1592 |
1699 def AddOperation(self, info): | 1593 def AddOperation(self, info): |
1700 """ | 1594 """ |
1701 Arguments: | 1595 Arguments: |
1702 info: An OperationInfo object. | 1596 info: An OperationInfo object. |
1703 """ | 1597 """ |
1704 body = self._members_emitter.Emit( | 1598 body = self._members_emitter.Emit( |
1705 '\n' | 1599 '\n' |
1706 ' $TYPE $NAME($PARAMS) {\n' | 1600 ' $TYPE $NAME($PARAMS) {\n' |
1707 '$!BODY' | 1601 '$!BODY' |
1708 ' }\n', | 1602 ' }\n', |
1709 TYPE=info.type_name, | 1603 TYPE=info.type_name, |
1710 NAME=info.name, | 1604 NAME=info.name, |
1711 PARAMS=info.ParametersImplementationDeclaration()) | 1605 PARAMS=info.ParametersImplementationDeclaration()) |
1712 | 1606 |
1713 # Process in order of ascending number of arguments to ensure missing | 1607 # Process in order of ascending number of arguments to ensure missing |
1714 # optional arguments are processed early. | 1608 # optional arguments are processed early. |
1715 overloads = sorted(info.overloads, | 1609 overloads = sorted(info.overloads, |
1716 key=lambda overload: len(overload.arguments)) | 1610 key=lambda overload: len(overload.arguments)) |
1717 self._native_version = 0 | 1611 self._native_version = 0 |
1718 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) | 1612 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) |
1719 if fallthrough: | 1613 if fallthrough: |
1720 body.Emit(' throw "Incorrect number or type of arguments";\n'); | 1614 body.Emit(' throw "Incorrect number or type of arguments";\n'); |
1721 self._externs.add((self._interface.id, info.js_name, 'operation')) | |
1722 | 1615 |
1723 def GenerateSingleOperation(self, emitter, info, indent, operation): | 1616 def GenerateSingleOperation(self, emitter, info, indent, operation): |
1724 """Generates a call to a single operation. | 1617 """Generates a call to a single operation. |
1725 | 1618 |
1726 Arguments: | 1619 Arguments: |
1727 emitter: an Emitter for the body of a block of code. | 1620 emitter: an Emitter for the body of a block of code. |
1728 info: the compound information about the operation and its overloads. | 1621 info: the compound information about the operation and its overloads. |
1729 indent: an indentation string for generated code. | 1622 indent: an indentation string for generated code. |
1730 operation: the IDLOperation to call. | 1623 operation: the IDLOperation to call. |
1731 """ | 1624 """ |
(...skipping 28 matching lines...) Expand all Loading... |
1760 '$(INDENT)return;\n', | 1653 '$(INDENT)return;\n', |
1761 INDENT=indent, | 1654 INDENT=indent, |
1762 NATIVENAME=native_name, | 1655 NATIVENAME=native_name, |
1763 ARGS=argument_expressions) | 1656 ARGS=argument_expressions) |
1764 | 1657 |
1765 self._members_emitter.Emit(' static $TYPE $NAME($PARAMS) native;\n', | 1658 self._members_emitter.Emit(' static $TYPE $NAME($PARAMS) native;\n', |
1766 NAME=native_name, | 1659 NAME=native_name, |
1767 TYPE=info.type_name, | 1660 TYPE=info.type_name, |
1768 PARAMS=', '.join(['receiver'] + arg_names) ) | 1661 PARAMS=', '.join(['receiver'] + arg_names) ) |
1769 | 1662 |
1770 if (self._interface.id, info.name) not in _custom_methods: | |
1771 alternates = _alternate_methods.get( (self._interface.id, info.name) ) | |
1772 if alternates: | |
1773 (js_name_1, js_name_2) = alternates | |
1774 self._js_code.Emit( | |
1775 '\n' | |
1776 'function native_$(CLASS)_$(NATIVENAME)($PARAMS) {\n' | |
1777 ' try {\n' | |
1778 ' var _method = _this.$dom.$JSNAME1 || _this.$dom.$JSNAME2;\n' | |
1779 ' return __dom_wrap(_method.call($ARGS));\n' | |
1780 ' } catch (e) {\n' | |
1781 ' throw __dom_wrap_exception(e);\n' | |
1782 ' }\n' | |
1783 '}\n', | |
1784 CLASS=self._class_name, | |
1785 NAME=info.name, | |
1786 JSNAME1=js_name_1, | |
1787 JSNAME2=js_name_2, | |
1788 NATIVENAME=native_name, | |
1789 PARAMS=', '.join(['_this'] + arg_names), | |
1790 ARGS=', '.join(['_this.$dom'] + unwrap_args)) | |
1791 else: | |
1792 if info.js_name in _javascript_keywords: | |
1793 access = "['%s']" % info.js_name | |
1794 else: | |
1795 access = ".%s" % info.js_name | |
1796 self._js_code.Emit( | |
1797 '\n' | |
1798 'function native_$(CLASS)_$(NATIVENAME)($PARAMS) {\n' | |
1799 ' try {\n' | |
1800 ' return __dom_wrap(_this.$dom$ACCESS($ARGS));\n' | |
1801 ' } catch (e) {\n' | |
1802 ' throw __dom_wrap_exception(e);\n' | |
1803 ' }\n' | |
1804 '}\n', | |
1805 CLASS=self._class_name, | |
1806 NAME=info.name, | |
1807 ACCESS=access, | |
1808 NATIVENAME=native_name, | |
1809 PARAMS=', '.join(['_this'] + arg_names), | |
1810 ARGS=', '.join(unwrap_args)) | |
1811 | |
1812 | 1663 |
1813 def GenerateDispatch(self, emitter, info, indent, position, overloads): | 1664 def GenerateDispatch(self, emitter, info, indent, position, overloads): |
1814 """Generates a dispatch to one of the overloads. | 1665 """Generates a dispatch to one of the overloads. |
1815 | 1666 |
1816 Arguments: | 1667 Arguments: |
1817 emitter: an Emitter for the body of a block of code. | 1668 emitter: an Emitter for the body of a block of code. |
1818 info: the compound information about the operation and its overloads. | 1669 info: the compound information about the operation and its overloads. |
1819 indent: an indentation string for generated code. | 1670 indent: an indentation string for generated code. |
1820 position: the index of the parameter to dispatch on. | 1671 position: the index of the parameter to dispatch on. |
1821 overloads: a list of the remaining IDLOperations to dispatch. | 1672 overloads: a list of the remaining IDLOperations to dispatch. |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 INDENT=indent, | 2212 INDENT=indent, |
2362 NATIVENAME=native_name, | 2213 NATIVENAME=native_name, |
2363 ARGS=argument_expressions) | 2214 ARGS=argument_expressions) |
2364 | 2215 |
2365 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 2216 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2366 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 2217 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2367 NATIVE_NAME=native_name, | 2218 NATIVE_NAME=native_name, |
2368 TYPE=info.type_name, | 2219 TYPE=info.type_name, |
2369 PARAMS=', '.join(arg_names), | 2220 PARAMS=', '.join(arg_names), |
2370 INTERFACE=self._interface.id) | 2221 INTERFACE=self._interface.id) |
OLD | NEW |