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

Unified Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1318043005: Support user generated custom native JS classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: PTAL 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/elements/modelx.dart
diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart
index 65742316c66ff25e990a162e3b8f69e1f1b68f9f..e0be992817bbf3f14c19ad2e136952472584839e 100644
--- a/pkg/compiler/lib/src/elements/modelx.dart
+++ b/pkg/compiler/lib/src/elements/modelx.dart
@@ -225,9 +225,30 @@ abstract class ElementX extends Element with ElementCommon {
String _fixedBackendName = null;
bool _isNative = false;
- bool get isNative => _isNative;
- bool get hasFixedBackendName => _fixedBackendName != null;
- String get fixedBackendName => _fixedBackendName;
+ String _jsInteropName = null;
+ String get jsInteropName => _jsInteropName;
+
+ bool get isJsInterop => _jsInteropName != null;
+
+ void setJsInterop(String name) { _jsInteropName = name; }
+
+ bool get isNative => _isNative || isJsInterop;
+ bool get hasFixedBackendName => fixedBackendName != null || isJsInterop;
+
+ String _jsNameHelper(Element e) {
+ if (e._jsInteropName != null && e._jsInteropName.isNotEmpty)
+ return e._jsInteropName;
+ return e.isLibrary ? 'self' : e.name;
+ }
+
+ String get fixedBackendName {
+ if (_fixedBackendName != null) return _fixedBackendName;
+ if (isJsInterop) {
+ return _jsNameHelper(isConstructor ? enclosingClass : this);
+ }
+ return null;
+ }
+
// Marks this element as a native element.
void setNative(String name) {
_isNative = true;
@@ -1802,6 +1823,20 @@ abstract class BaseFunctionElementX
return functionSignatureCache;
}
+ /**
+ * An function is part of JsInterop if it has a jsInteropName annotation or it
+ * is an external class or top level member of a class or library tagged as
+ * JsInterop.
+ */
+ bool get isJsInterop {
+ if (!isExternal) return false;
+
+ if (super.isJsInterop) return true;
+ if (isClassMember) return contextClass.isJsInterop;
+ if (isTopLevel) return library.isJsInterop;
+ return false;
+ }
+
List<ParameterElement> get parameters {
// TODO(johnniwinther): Store the list directly, possibly by using List
// instead of Link in FunctionSignature.
@@ -2419,7 +2454,7 @@ abstract class BaseClassElementX extends ElementX
return asInstanceOf(compiler.functionClass) != null || callType != null;
}
- bool get isNative => nativeTagInfo != null;
+ bool get isNative => nativeTagInfo != null || isJsInterop;
void setNative(String name) {
// TODO(johnniwinther): Assert that this is only called once. The memory

Powered by Google App Engine
This is Rietveld 408576698