| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 String newName = getMappedGlobalName('${getName(element)}\$bailout'); | 662 String newName = getMappedGlobalName('${getName(element)}\$bailout'); |
| 663 return '$CURRENT_ISOLATE.$newName'; | 663 return '$CURRENT_ISOLATE.$newName'; |
| 664 } | 664 } |
| 665 | 665 |
| 666 String isolateLazyInitializerAccess(Element element) { | 666 String isolateLazyInitializerAccess(Element element) { |
| 667 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; | 667 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; |
| 668 } | 668 } |
| 669 | 669 |
| 670 String operatorIsPrefix() => r'$is'; | 670 String operatorIsPrefix() => r'$is'; |
| 671 | 671 |
| 672 String operatorAsPrefix() => r'$as'; |
| 673 |
| 672 String operatorIs(Element element) { | 674 String operatorIs(Element element) { |
| 673 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. | 675 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
| 674 return '${operatorIsPrefix()}${getName(element)}'; | 676 return '${operatorIsPrefix()}${getName(element)}'; |
| 675 } | 677 } |
| 676 | 678 |
| 677 /* | 679 /* |
| 678 * Returns a name that does not clash with reserved JS keywords, | 680 * Returns a name that does not clash with reserved JS keywords, |
| 679 * and also ensures it won't clash with other identifiers. | 681 * and also ensures it won't clash with other identifiers. |
| 680 */ | 682 */ |
| 681 String _safeName(String name, Set<String> reserved) { | 683 String _safeName(String name, Set<String> reserved) { |
| 682 if (reserved.contains(name) || name.startsWith(r'$')) { | 684 if (reserved.contains(name) || name.startsWith(r'$')) { |
| 683 name = '\$$name'; | 685 name = '\$$name'; |
| 684 } | 686 } |
| 685 assert(!reserved.contains(name)); | 687 assert(!reserved.contains(name)); |
| 686 return name; | 688 return name; |
| 687 } | 689 } |
| 688 | 690 |
| 691 String substitutionName(Element element) { |
| 692 return '${operatorAsPrefix()}${getName(element)}'; |
| 693 } |
| 694 |
| 689 String safeName(String name) => _safeName(name, jsReserved); | 695 String safeName(String name) => _safeName(name, jsReserved); |
| 690 String safeVariableName(String name) => _safeName(name, jsVariableReserved); | 696 String safeVariableName(String name) => _safeName(name, jsVariableReserved); |
| 691 | 697 |
| 692 String oneShotInterceptorName(Selector selector) { | 698 String oneShotInterceptorName(Selector selector) { |
| 693 // TODO(ngeoffray): What to do about typed selectors? We could | 699 // TODO(ngeoffray): What to do about typed selectors? We could |
| 694 // filter them out, or keep them and hope the generated one shot | 700 // filter them out, or keep them and hope the generated one shot |
| 695 // interceptor takes advantage of the type. | 701 // interceptor takes advantage of the type. |
| 696 String cached = oneShotInterceptorNames[selector]; | 702 String cached = oneShotInterceptorNames[selector]; |
| 697 if (cached != null) return cached; | 703 if (cached != null) return cached; |
| 698 SourceString name = operatorNameToIdentifier(selector.name); | 704 SourceString name = operatorNameToIdentifier(selector.name); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 return const SourceString(r'$or'); | 751 return const SourceString(r'$or'); |
| 746 } else if (value == '-') { | 752 } else if (value == '-') { |
| 747 return const SourceString(r'$sub'); | 753 return const SourceString(r'$sub'); |
| 748 } else if (value == 'unary-') { | 754 } else if (value == 'unary-') { |
| 749 return const SourceString(r'$negate'); | 755 return const SourceString(r'$negate'); |
| 750 } else { | 756 } else { |
| 751 return name; | 757 return name; |
| 752 } | 758 } |
| 753 } | 759 } |
| 754 } | 760 } |
| OLD | NEW |