| 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 /** | 5 /** |
| 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 7 */ | 7 */ |
| 8 class Namer { | 8 class Namer { |
| 9 static Set<String> _jsReserved = null; | 9 static Set<String> _jsReserved = null; |
| 10 Set<String> get jsReserved() { | 10 Set<String> get jsReserved() { |
| 11 if (_jsReserved === null) { | 11 if (_jsReserved === null) { |
| 12 _jsReserved = new Set<String>(); | 12 _jsReserved = new Set<String>(); |
| 13 _jsReserved.addAll(JsNames.javaScriptKeywords); | 13 _jsReserved.addAll(JsNames.javaScriptKeywords); |
| 14 _jsReserved.addAll(JsNames.reservedPropertySymbols); | 14 _jsReserved.addAll(JsNames.reservedPropertySymbols); |
| 15 } | 15 } |
| 16 return _jsReserved; | 16 return _jsReserved; |
| 17 } | 17 } |
| 18 | 18 |
| 19 Map<Element, String> globals; | 19 Map<Element, String> globals; |
| 20 Map<String, int> usedGlobals; | 20 Map<String, int> usedGlobals; |
| 21 | 21 |
| 22 Namer() | 22 Namer() |
| 23 : globals = new Map<Element, String>(), | 23 : globals = new Map<Element, String>(), |
| 24 usedGlobals = new Map<String, int>(); | 24 usedGlobals = new Map<String, int>(); |
| 25 | 25 |
| 26 String get currentIsolate() => "\$"; | 26 String get currentIsolate() => "\$"; |
| 27 String get isolate() => "Isolate"; | 27 String get isolate() => "Isolate"; |
| 28 | 28 |
| 29 | 29 |
| 30 String closureInvocationName() { |
| 31 // TODO(floitsch): mangle, while not conflicting with instance names. |
| 32 return '\$call'; |
| 33 } |
| 34 |
| 30 String instanceName(SourceString instanceName) { | 35 String instanceName(SourceString instanceName) { |
| 31 String candidate = '$instanceName'; | 36 String candidate = '$instanceName'; |
| 32 // TODO(floitsch): mangle, while preserving uniqueness. | 37 // TODO(floitsch): mangle, while preserving uniqueness. |
| 33 return candidate; | 38 return candidate; |
| 34 } | 39 } |
| 35 | 40 |
| 36 /** | 41 /** |
| 37 * The constructor-body name is computed from the corresponding | 42 * The constructor-body name is computed from the corresponding |
| 38 * constructor element because, in the case of a super-initialization, the | 43 * constructor element because, in the case of a super-initialization, the |
| 39 * body element is not accessible. | 44 * body element is not accessible. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (jsId === null) jsId = define(element); | 122 if (jsId === null) jsId = define(element); |
| 118 return "$currentIsolate.$jsId"; | 123 return "$currentIsolate.$jsId"; |
| 119 } | 124 } |
| 120 | 125 |
| 121 String isolatePropertyAccess(Element element) { | 126 String isolatePropertyAccess(Element element) { |
| 122 String jsId = globals[element]; | 127 String jsId = globals[element]; |
| 123 if (jsId === null) jsId = define(element); | 128 if (jsId === null) jsId = define(element); |
| 124 return "$isolate.prototype.$jsId"; | 129 return "$isolate.prototype.$jsId"; |
| 125 } | 130 } |
| 126 } | 131 } |
| OLD | NEW |