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

Unified Diff: lib/compiler/implementation/elements/elements.dart

Issue 10947024: Made dart2js constructor lookup logic "private"-aware, fixed 4740 bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated Peter's comments and feedback. Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/elements/elements.dart
diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart
index 9877fe7daba1d0560bf357351123c8c6eca62e66..7132d0763530036cfaeb27c5a1e385ff271991fa 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -1477,24 +1477,42 @@ abstract class ClassElement extends ScopeContainerElement
}
}
- Element lookupConstructor(SourceString className,
- [SourceString constructorName =
- const SourceString(''),
- Element noMatch(Element)]) {
- // TODO(karlklose): have a map from class names to a map of constructors
- // instead of creating the name here?
+ Element validateConstructorLookupResults(Selector selector,
+ Element result,
+ Element noMatch(Element)) {
+ if (result === null
+ || !result.isConstructor()
+ || (selector.name.isPrivate()
+ && result.getLibrary() != selector.library)) {
+ result = noMatch !== null ? noMatch(result) : null;
+ }
+ return result;
+ }
+
+ // TODO(aprelev@gmail.com): Peter believes that it would be great to
+ // make noMatch a required argument. Peter's suspicion is that most
+ // callers of this method would benefit from using the noMatch method.
+ Element lookupConstructor(Selector selector, [Element noMatch(Element)]) {
SourceString normalizedName;
- if (constructorName !== const SourceString('')) {
+ SourceString className = this.name;
+ SourceString constructorName = selector.name;
+ if (constructorName !== const SourceString('') &&
+ ((className === null) ||
+ (constructorName.slowToString() != className.slowToString()))) {
normalizedName = Elements.constructConstructorName(className,
constructorName);
} else {
normalizedName = className;
}
Element result = localLookup(normalizedName);
- if (result === null || !result.isConstructor()) {
- result = noMatch !== null ? noMatch(result) : null;
- }
- return result;
+ return validateConstructorLookupResults(selector, result, noMatch);
+ }
+
+ Element lookupFactoryConstructor(Selector selector,
+ [Element noMatch(Element)]) {
+ SourceString constructorName = selector.name;
+ Element result = localLookup(constructorName);
+ return validateConstructorLookupResults(selector, result, noMatch);
}
bool get hasConstructor {
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698