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

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: 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
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/inferrer/type_graph_nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0109684f7ba6c14cfd741405f579e2bf3cf3ff8c..6dfd7511605d8e24d9c4548f1c1b529cca755b6f 100644
--- a/pkg/compiler/lib/src/elements/modelx.dart
+++ b/pkg/compiler/lib/src/elements/modelx.dart
@@ -234,9 +234,54 @@ 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;
+ bool _isJsInterop = false;
+
+ /// Whether the element is implemented via typed JavaScript interop.
+ bool get isJsInterop => _isJsInterop;
+ /// JavaScript name for the element if it is implemented via typed JavaScript
+ /// interop.
+ String get jsInteropName => _jsInteropName;
+
+ void markAsJsInterop() {
+ _isJsInterop = true;
+ }
+
+ void setJsInteropName(String name) {
+ assert(invariant(this,
+ _isJsInterop,
+ message: 'Element is not js interop but given a js interop name.'));
+ _jsInteropName = name;
+ }
+
+ /// Whether the element corresponds to a native JavaScript construct either
+ /// through the existing [setNative] mechanism which is only allowed
+ /// for internal libraries or via the new typed JavaScriptInterop mechanism
+ /// which is allowed for user libraries.
+ bool get isNative => _isNative || isJsInterop;
+ bool get hasFixedBackendName => fixedBackendName != null || isJsInterop;
+
+ String _jsNameHelper(Element e) {
+ assert(invariant(this,
+ !(_isJsInterop && _jsInteropName == null),
+ message:
+ 'Element is js interop but js interop name has not yet been'
+ 'computed.'));
+ if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) {
+ return e.jsInteropName;
+ }
+ return e.isLibrary ? 'self' : e.name;
+ }
+
+ String get fixedBackendName {
+ if (_fixedBackendName == null && isJsInterop) {
+ // If an element isJsInterop but _isJsInterop is false that means it is
+ // considered interop as the parent class is interop.
+ _fixedBackendName = _jsNameHelper(isConstructor ? enclosingClass : this);
+ }
+ return _fixedBackendName;
+ }
+
// Marks this element as a native element.
void setNative(String name) {
_isNative = true;
@@ -2008,6 +2053,18 @@ abstract class BaseFunctionElementX
typeCache = _functionSignatureCache.type;
}
+ /// An function is part of JsInterop in the following cases:
+ /// * It has a jsInteropName annotation
+ /// * It is external 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.
@@ -2628,7 +2685,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
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/inferrer/type_graph_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698