| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 String publicInstanceMethodNameByArity(SourceString name, int arity) { | 173 String publicInstanceMethodNameByArity(SourceString name, int arity) { |
| 174 name = Elements.operatorNameToIdentifier(name); | 174 name = Elements.operatorNameToIdentifier(name); |
| 175 assert(!name.isPrivate()); | 175 assert(!name.isPrivate()); |
| 176 var base = name.slowToString(); | 176 var base = name.slowToString(); |
| 177 // We don't mangle the closure invoking function name because it | 177 // We don't mangle the closure invoking function name because it |
| 178 // is generated by string concatenation in applyFunction from | 178 // is generated by string concatenation in applyFunction from |
| 179 // js_helper.dart. | 179 // js_helper.dart. |
| 180 var proposedName = '$base\$$arity'; | 180 var proposedName = '$base\$$arity'; |
| 181 if (base == closureInvocationSelectorName) return proposedName; | 181 if (name == closureInvocationSelectorName) return proposedName; |
| 182 return getMappedInstanceName(proposedName); | 182 return getMappedInstanceName(proposedName); |
| 183 } | 183 } |
| 184 | 184 |
| 185 String invocationName(Selector selector) { | 185 String invocationName(Selector selector) { |
| 186 if (selector.isGetter()) { | 186 if (selector.isGetter()) { |
| 187 String proposedName = privateName(selector.library, selector.name); | 187 String proposedName = privateName(selector.library, selector.name); |
| 188 return 'get\$${getMappedInstanceName(proposedName)}'; | 188 return 'get\$${getMappedInstanceName(proposedName)}'; |
| 189 } else if (selector.isSetter()) { | 189 } else if (selector.isSetter()) { |
| 190 String proposedName = privateName(selector.library, selector.name); | 190 String proposedName = privateName(selector.library, selector.name); |
| 191 return 'set\$${getMappedInstanceName(proposedName)}'; | 191 return 'set\$${getMappedInstanceName(proposedName)}'; |
| 192 } else { | 192 } else { |
| 193 SourceString name = Elements.operatorNameToIdentifier(selector.name); | 193 SourceString name = Elements.operatorNameToIdentifier(selector.name); |
| 194 StringBuffer buffer = new StringBuffer(); | 194 StringBuffer buffer = new StringBuffer(); |
| 195 for (SourceString argumentName in selector.getOrderedNamedArguments()) { | 195 for (SourceString argumentName in selector.getOrderedNamedArguments()) { |
| 196 buffer.add(r'$'); | 196 buffer.add(r'$'); |
| 197 argumentName.printOn(buffer); | 197 argumentName.printOn(buffer); |
| 198 } | 198 } |
| 199 String suffix = '\$${selector.argumentCount}$buffer'; | 199 String suffix = '\$${selector.argumentCount}$buffer'; |
| 200 // We don't mangle the closure invoking function name because it | 200 // We don't mangle the closure invoking function name because it |
| 201 // is generated by string concatenation in applyFunction from | 201 // is generated by string concatenation in applyFunction from |
| 202 // js_helper.dart. | 202 // js_helper.dart. |
| 203 if (selector.isClosureCall()) return "$name$suffix"; | 203 if (selector.isCall() && name == closureInvocationSelectorName) { |
| 204 return "$name$suffix"; |
| 205 } |
| 204 String proposedName = privateName(selector.library, name); | 206 String proposedName = privateName(selector.library, name); |
| 205 return getMappedInstanceName('$proposedName$suffix'); | 207 return getMappedInstanceName('$proposedName$suffix'); |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 | 210 |
| 209 /** | 211 /** |
| 210 * Returns the internal name used for an invocation mirror of this selector. | 212 * Returns the internal name used for an invocation mirror of this selector. |
| 211 */ | 213 */ |
| 212 String invocationMirrorInternalName(Selector selector) | 214 String invocationMirrorInternalName(Selector selector) |
| 213 => invocationName(selector); | 215 => invocationName(selector); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 470 } |
| 469 | 471 |
| 470 String safeName(String name) { | 472 String safeName(String name) { |
| 471 if (jsReserved.contains(name) || name.startsWith('\$')) { | 473 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 472 name = "\$$name"; | 474 name = "\$$name"; |
| 473 assert(!jsReserved.contains(name)); | 475 assert(!jsReserved.contains(name)); |
| 474 } | 476 } |
| 475 return name; | 477 return name; |
| 476 } | 478 } |
| 477 } | 479 } |
| OLD | NEW |