Chromium Code Reviews| 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 ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 class JsNames { | 7 class JsNames { |
| 8 static const javaScriptKeywords = const <String>[ | 8 static const javaScriptKeywords = const <String>[ |
| 9 // These are current keywords | 9 // These are current keywords |
| 10 "break", "delete", "function", "return", "typeof", "case", "do", "if", | 10 "break", "delete", "function", "return", "typeof", "case", "do", "if", |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 // Identifiers used by JsStackEmulator; later set to obfuscatable | 148 // Identifiers used by JsStackEmulator; later set to obfuscatable |
| 149 "\$stack", "\$stackDepth", "\$location", | 149 "\$stack", "\$stackDepth", "\$location", |
| 150 | 150 |
| 151 // TODO: prove why this is necessary or remove it | 151 // TODO: prove why this is necessary or remove it |
| 152 "call" | 152 "call" |
| 153 ]; | 153 ]; |
| 154 | 154 |
| 155 static const reservedPropertySymbols = | 155 static const reservedPropertySymbols = |
| 156 const <String>["__PROTO__", "prototype", "constructor"]; | 156 const <String>["__PROTO__", "prototype", "constructor"]; |
| 157 | 157 |
| 158 | |
|
ahe
2012/12/17 16:23:25
Remove extra line.
| |
| 158 static Set<String> _reserved; | 159 static Set<String> _reserved; |
| 160 static Set<String> _reservedNativeProperties; | |
| 159 | 161 |
| 160 static Set<String> get reserved { | 162 static Set<String> get reserved { |
| 161 if (_reserved == null) { | 163 if (_reserved == null) { |
| 162 _reserved = new Set<String>(); | 164 _reserved = new Set<String>(); |
| 163 _reserved.addAll(reservedPropertySymbols); | 165 _reserved.addAll(reservedPropertySymbols); |
| 164 _reserved.addAll(reservedGlobalSymbols); | 166 _reserved.addAll(reservedGlobalSymbols); |
| 165 _reserved.addAll(javaScriptKeywords); | 167 _reserved.addAll(javaScriptKeywords); |
| 166 } | 168 } |
| 167 return _reserved; | 169 return _reserved; |
| 168 } | 170 } |
| 169 | 171 |
| 172 static Set<String> get reservedNativeProperties { | |
| 173 // TODO(sra): We need a complete list from the DOM. | |
|
ahe
2012/12/17 16:23:25
Add two spaces of indentation.
| |
| 174 if (_reservedNativeProperties == null) { | |
| 175 const names = const <String>["x", "y", "z"]; | |
|
ngeoffray
2012/12/18 12:34:03
What are those names in the DOM? Is this CL fixing
| |
| 176 _reservedNativeProperties = new Set<String>(); | |
|
ngeoffray
2012/12/18 12:34:03
You can use new Set<String>.from(names).
| |
| 177 _reservedNativeProperties.addAll(names); | |
| 178 } | |
| 179 return _reservedNativeProperties; | |
| 180 } | |
| 181 | |
| 170 // TODO(ngeoffray): only the namer should call this method. | 182 // TODO(ngeoffray): only the namer should call this method. |
| 171 // Eventually move it there. | 183 // Eventually move it there. |
| 172 /* | 184 /* |
| 173 * Returns a name that does not clash with reserved JS keywords, | 185 * Returns a name that does not clash with reserved JS keywords, |
| 174 * and also ensures it won't clash with other identifiers. | 186 * and also ensures it won't clash with other identifiers. |
| 175 */ | 187 */ |
| 176 static String getValid(String name) { | 188 static String getValid(String name) { |
| 177 if (reserved.contains(name)) { | 189 if (reserved.contains(name)) { |
| 178 name = '$name\$'; | 190 name = '$name\$'; |
| 179 assert(!reserved.contains(name)); | 191 assert(!reserved.contains(name)); |
| 180 } else if (name.contains(r'$')) { | 192 } else if (name.contains(r'$')) { |
| 181 name = name.replaceAll(r'$', r'$$'); | 193 name = name.replaceAll(r'$', r'$$'); |
| 182 } | 194 } |
| 183 return name; | 195 return name; |
| 184 } | 196 } |
| 185 } | 197 } |
| OLD | NEW |