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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart

Issue 11590018: Avoid known native field names when minifying method names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
OLDNEW
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 13 matching lines...) Expand all
24 * Map from top-level or static elements to their unique identifiers provided 24 * Map from top-level or static elements to their unique identifiers provided
25 * by [getName]. 25 * by [getName].
26 * 26 *
27 * Invariant: Keys must be declaration elements. 27 * Invariant: Keys must be declaration elements.
28 */ 28 */
29 final Compiler compiler; 29 final Compiler compiler;
30 final Map<Element, String> globals; 30 final Map<Element, String> globals;
31 final Map<String, LibraryElement> shortPrivateNameOwners; 31 final Map<String, LibraryElement> shortPrivateNameOwners;
32 final Set<String> usedGlobalNames; 32 final Set<String> usedGlobalNames;
33 final Set<String> usedInstanceNames; 33 final Set<String> usedInstanceNames;
34 final Map<String, String> globalNameMap;
34 final Map<String, String> instanceNameMap; 35 final Map<String, String> instanceNameMap;
35 final Map<String, String> globalNameMap;
36 final Map<String, int> popularNameCounters; 36 final Map<String, int> popularNameCounters;
37 37
38 /** 38 /**
39 * A cache of names used for bailout methods. We make sure two 39 * A cache of names used for bailout methods. We make sure two
40 * bailout methods cannot have the same name because if the two 40 * bailout methods cannot have the same name because if the two
41 * bailout methods are in a class and a subclass, we would 41 * bailout methods are in a class and a subclass, we would
42 * call the wrong bailout method at runtime. To make it 42 * call the wrong bailout method at runtime. To make it
43 * simple, we don't keep track of inheritance and always avoid 43 * simple, we don't keep track of inheritance and always avoid
44 * similar names. 44 * similar names.
45 */ 45 */
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 // Construct a new name for the element based on the library and class it is 229 // Construct a new name for the element based on the library and class it is
230 // in. The name here is not important, we just need to make sure it is 230 // in. The name here is not important, we just need to make sure it is
231 // unique. If we are minifying, we actually construct the name from the 231 // unique. If we are minifying, we actually construct the name from the
232 // minified versions of the class and instance names, but the result is 232 // minified versions of the class and instance names, but the result is
233 // minified once again, so that is not visible in the end result. 233 // minified once again, so that is not visible in the end result.
234 String shadowedFieldName(Element fieldElement) { 234 String shadowedFieldName(Element fieldElement) {
235 // Check for following situation: Native field ${fieldElement.name} has 235 // Check for following situation: Native field ${fieldElement.name} has
236 // fixed JSName ${fieldElement.nativeName()}, but a subclass shadows this 236 // fixed JSName ${fieldElement.nativeName()}, but a subclass shadows this
237 // name. We normally handle that by renaming the superclass field, but we 237 // name. We normally handle that by renaming the superclass field, but we
238 // can't do that because native fields have fixed JSNames. In practice 238 // can't do that because native fields have fixed JsNames. In practice
239 // this can't happen because we can't inherit from native classes. 239 // this can't happen because we can't inherit from native classes.
240 assert (!fieldElement.hasFixedBackendName()); 240 assert (!fieldElement.hasFixedBackendName());
241 241
242 ClassElement cls = fieldElement.getEnclosingClass(); 242 ClassElement cls = fieldElement.getEnclosingClass();
243 LibraryElement libraryElement = fieldElement.getLibrary(); 243 LibraryElement libraryElement = fieldElement.getLibrary();
244 String libName = getName(libraryElement); 244 String libName = getName(libraryElement);
245 String clsName = getName(cls); 245 String clsName = getName(cls);
246 String instanceName = instanceFieldName(libraryElement, fieldElement.name); 246 String instanceName = instanceFieldName(libraryElement, fieldElement.name);
247 return getMappedInstanceName('$libName\$$clsName\$$instanceName'); 247 return getMappedInstanceName('$libName\$$clsName\$$instanceName');
248 } 248 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 479 }
480 480
481 String safeName(String name) { 481 String safeName(String name) {
482 if (jsReserved.contains(name) || name.startsWith('\$')) { 482 if (jsReserved.contains(name) || name.startsWith('\$')) {
483 name = "\$$name"; 483 name = "\$$name";
484 assert(!jsReserved.contains(name)); 484 assert(!jsReserved.contains(name));
485 } 485 }
486 return name; 486 return name;
487 } 487 }
488 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698