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

Unified Diff: pkg/compiler/lib/src/js_backend/namer.dart

Issue 1318043005: Support user generated custom native JS classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: about to land Created 5 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
Index: pkg/compiler/lib/src/js_backend/namer.dart
diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart
index 5bb88de8ea935cdcd98a1f62080bc94c0619ee01..783b5181750e069b5d438ec094efa4e723d0f4df 100644
--- a/pkg/compiler/lib/src/js_backend/namer.dart
+++ b/pkg/compiler/lib/src/js_backend/namer.dart
@@ -636,6 +636,32 @@ class Namer {
return invocationName(new Selector.fromElement(method));
}
+ String _jsNameHelper(Element e) {
+ if (e.jsInteropName != null && e.jsInteropName.isNotEmpty)
+ return e.jsInteropName;
+ return e.isLibrary ? 'self' : e.name;
+ }
+
+ /// Returns a JavaScript path specifying the context in which
+ /// [element.fixedBackendName] should be evaluated. Only applicable for
+ /// elements using typed JavaScript interop.
+ /// For example: fixedBackendPath for the static method createMap in the
+ /// Map class of the goog.map JavaScript library would have path
+ /// "goog.maps.Map".
+ String fixedBackendPath(Element element) {
+ if (!element.isJsInterop) return null;
+ if (element.isInstanceMember) return 'this';
+ if (element.isConstructor) return fixedBackendPath(element.enclosingClass);
+ if (element.isLibrary) return 'self';
+ var sb = new StringBuffer();
+ sb..write(_jsNameHelper(element.library));
+
+ if (element.enclosingClass != null && element.enclosingClass != element) {
+ sb..write('.')..write(_jsNameHelper(element.enclosingClass));
+ }
+ return sb.toString();
+ }
+
/// Returns the annotated name for a variant of `call`.
/// The result has the form:
///
@@ -766,11 +792,6 @@ class Namer {
ClassElement enclosingClass = element.enclosingClass;
if (element.hasFixedBackendName) {
- // Certain native fields must be given a specific name. Native names must
- // not contain '$'. We rely on this to avoid clashes.
- assert(enclosingClass.isNative &&
- !element.fixedBackendName.contains(r'$'));
-
return new StringBackedName(element.fixedBackendName);
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_interop_analysis.dart ('k') | pkg/compiler/lib/src/js_backend/patch_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698