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

Side by Side Diff: client/dom/scripts/dartgenerator.py

Issue 8784013: Fix CanvasPixelArray's operator[] for the wrapping js dom (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rerun Created 9 years 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 | « client/dom/idl/dart/dart.idl ('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) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 code = self._emitters.FileEmitter(file_path) 454 code = self._emitters.FileEmitter(file_path)
455 455
456 template_file = 'template_callback.darttemplate' 456 template_file = 'template_callback.darttemplate'
457 code.Emit(''.join(open(template_file).readlines())) 457 code.Emit(''.join(open(template_file).readlines()))
458 code.Emit('typedef $TYPE $NAME($ARGS);\n', 458 code.Emit('typedef $TYPE $NAME($ARGS);\n',
459 NAME=interface.id, 459 NAME=interface.id,
460 TYPE=info.type_name, 460 TYPE=info.type_name,
461 ARGS=info.arg_implementation_declaration) 461 ARGS=info.arg_implementation_declaration)
462 462
463 463
464
465 def _ProcessInterface(self, interface, super_interface_name, 464 def _ProcessInterface(self, interface, super_interface_name,
466 source_filter, 465 source_filter,
467 common_prefix): 466 common_prefix):
468 """.""" 467 """."""
469 _logger.info('Generating %s' % interface.id) 468 _logger.info('Generating %s' % interface.id)
470 469
471 dart_interface_generator = self._MakeDartInterfaceGenerator( 470 dart_interface_generator = self._MakeDartInterfaceGenerator(
472 interface, 471 interface,
473 common_prefix, 472 common_prefix,
474 super_interface_name, 473 super_interface_name,
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 # interface Y extends X, List<T> ... 1454 # interface Y extends X, List<T> ...
1456 # 1455 #
1457 # In the non-root case we have to choose between: 1456 # In the non-root case we have to choose between:
1458 # 1457 #
1459 # class YImpl extends XImpl { add List<T> methods; } 1458 # class YImpl extends XImpl { add List<T> methods; }
1460 # 1459 #
1461 # and 1460 # and
1462 # 1461 #
1463 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 1462 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
1464 # 1463 #
1464 if ('HasIndexGetter' in self._interface.ext_attrs or
1465 'HasNumericIndexGetter' in self._interface.ext_attrs):
1466 method_name = '_index'
1467 self._members_emitter.Emit(
1468 '\n'
1469 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n'
1470 ' static $TYPE $METHOD(var _this, int index) native;\n',
1471 TYPE=element_type, METHOD=method_name)
1472 self._js_code.Emit(
1473 '\n'
1474 'function native_$(CLASS)_$(METHOD)(_this, index) {\n'
1475 ' try {\n'
1476 ' return __dom_wrap(_this.$dom[index]);\n'
1477 ' } catch (e) {\n'
1478 ' throw __dom_wrap_exception(e);\n'
1479 ' }\n'
1480 '}\n',
1481 CLASS=self._class_name, METHOD=method_name)
1482 else:
1483 self._members_emitter.Emit(
1484 '\n'
1485 ' $TYPE operator[](int index) {\n'
1486 ' return item(index);\n'
1487 ' }\n',
1488 TYPE=element_type)
1489
1490
1491 if 'HasCustomIndexSetter' in self._interface.ext_attrs:
1492 method_name = '_set_index'
1493 self._members_emitter.Emit(
1494 '\n'
1495 ' void operator[]=(int index, $TYPE value) {\n'
1496 ' return $METHOD(this, index, value);\n'
1497 ' }\n'
1498 ' static $METHOD(_this, index, value) native;\n',
1499 TYPE=element_type, METHOD=method_name)
1500 self._js_code.Emit(
1501 '\n'
1502 'function native_$(CLASS)_$(METHOD)(_this, index, value) {\n'
1503 ' try {\n'
1504 ' return _this.$dom[index] = __dom_unwrap(value);\n'
1505 ' } catch (e) {\n'
1506 ' throw __dom_wrap_exception(e);\n'
1507 ' }\n'
1508 '}\n',
1509 CLASS=self._class_name, METHOD=method_name)
1510 else:
1511 self._members_emitter.Emit(
1512 '\n'
1513 ' void operator[]=(int index, $TYPE value) {\n'
1514 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
1515 ' }\n',
1516 TYPE=element_type)
1517
1465 self._members_emitter.Emit( 1518 self._members_emitter.Emit(
1466 '\n' 1519 '\n'
1467 ' $TYPE operator[](int index) {\n'
1468 ' return item(index);\n'
1469 ' }\n'
1470 '\n'
1471 ' void operator[]=(int index, $TYPE value) {\n'
1472 ' throw new UnsupportedOperationException("Cannot assign element of i mmutable List.");\n'
1473 ' }\n'
1474 '\n'
1475 ' void add($TYPE value) {\n' 1520 ' void add($TYPE value) {\n'
1476 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n' 1521 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n'
1477 ' }\n' 1522 ' }\n'
1478 '\n' 1523 '\n'
1479 ' void addLast($TYPE value) {\n' 1524 ' void addLast($TYPE value) {\n'
1480 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n' 1525 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n'
1481 ' }\n' 1526 ' }\n'
1482 '\n' 1527 '\n'
1483 ' void addAll(Collection<$TYPE> collection) {\n' 1528 ' void addAll(Collection<$TYPE> collection) {\n'
1484 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n' 1529 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n'
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 Arguments: 2169 Arguments:
2125 info: An OperationInfo object. 2170 info: An OperationInfo object.
2126 """ 2171 """
2127 # TODO(vsm): Handle overloads. 2172 # TODO(vsm): Handle overloads.
2128 self._members_emitter.Emit( 2173 self._members_emitter.Emit(
2129 '\n' 2174 '\n'
2130 ' $TYPE $NAME($ARGS) native;\n', 2175 ' $TYPE $NAME($ARGS) native;\n',
2131 TYPE=info.type_name, 2176 TYPE=info.type_name,
2132 NAME=info.name, 2177 NAME=info.name,
2133 ARGS=info.arg_implementation_declaration) 2178 ARGS=info.arg_implementation_declaration)
OLDNEW
« no previous file with comments | « client/dom/idl/dart/dart.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698