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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library elements.modelx; 5 library elements.modelx;
6 6
7 import '../compiler.dart' show 7 import '../compiler.dart' show
8 Compiler; 8 Compiler;
9 import '../constants/constant_constructors.dart'; 9 import '../constants/constant_constructors.dart';
10 import '../constants/constructors.dart'; 10 import '../constants/constructors.dart';
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ? enclosingElement.name 218 ? enclosingElement.name
219 : '${enclosingElement.kind}?'; 219 : '${enclosingElement.kind}?';
220 return '$kind($holderName#${nameText})'; 220 return '$kind($holderName#${nameText})';
221 } else { 221 } else {
222 return '$kind(${nameText})'; 222 return '$kind(${nameText})';
223 } 223 }
224 } 224 }
225 225
226 String _fixedBackendName = null; 226 String _fixedBackendName = null;
227 bool _isNative = false; 227 bool _isNative = false;
228 bool get isNative => _isNative; 228 String _jsInteropName = null;
229 bool get hasFixedBackendName => _fixedBackendName != null; 229 String get jsInteropName => _jsInteropName;
230 String get fixedBackendName => _fixedBackendName; 230
231 bool get isJsInterop => _jsInteropName != null;
232
233 void setJsInterop(String name) { _jsInteropName = name; }
234
235 bool get isNative => _isNative || isJsInterop;
236 bool get hasFixedBackendName => fixedBackendName != null || isJsInterop;
237
238 String _jsNameHelper(Element e) {
239 if (e._jsInteropName != null && e._jsInteropName.isNotEmpty)
240 return e._jsInteropName;
241 return e.isLibrary ? 'self' : e.name;
242 }
243
244 String get fixedBackendName {
245 if (_fixedBackendName != null) return _fixedBackendName;
246 if (isJsInterop) {
247 return _jsNameHelper(isConstructor ? enclosingClass : this);
248 }
249 return null;
250 }
251
231 // Marks this element as a native element. 252 // Marks this element as a native element.
232 void setNative(String name) { 253 void setNative(String name) {
233 _isNative = true; 254 _isNative = true;
234 _fixedBackendName = name; 255 _fixedBackendName = name;
235 } 256 }
236 257
237 FunctionElement asFunctionElement() => null; 258 FunctionElement asFunctionElement() => null;
238 259
239 bool get isAbstract => modifiers.isAbstract; 260 bool get isAbstract => modifiers.isAbstract;
240 261
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 }); 1816 });
1796 return functionSignatureCache; 1817 return functionSignatureCache;
1797 } 1818 }
1798 1819
1799 FunctionSignature get functionSignature { 1820 FunctionSignature get functionSignature {
1800 assert(invariant(this, functionSignatureCache != null, 1821 assert(invariant(this, functionSignatureCache != null,
1801 message: "Function signature has not been computed for $this.")); 1822 message: "Function signature has not been computed for $this."));
1802 return functionSignatureCache; 1823 return functionSignatureCache;
1803 } 1824 }
1804 1825
1826 /**
1827 * An function is part of JsInterop if it has a jsInteropName annotation or it
1828 * is an external class or top level member of a class or library tagged as
1829 * JsInterop.
1830 */
1831 bool get isJsInterop {
1832 if (!isExternal) return false;
1833
1834 if (super.isJsInterop) return true;
1835 if (isClassMember) return contextClass.isJsInterop;
1836 if (isTopLevel) return library.isJsInterop;
1837 return false;
1838 }
1839
1805 List<ParameterElement> get parameters { 1840 List<ParameterElement> get parameters {
1806 // TODO(johnniwinther): Store the list directly, possibly by using List 1841 // TODO(johnniwinther): Store the list directly, possibly by using List
1807 // instead of Link in FunctionSignature. 1842 // instead of Link in FunctionSignature.
1808 List<ParameterElement> list = <ParameterElement>[]; 1843 List<ParameterElement> list = <ParameterElement>[];
1809 functionSignature.forEachParameter((e) => list.add(e)); 1844 functionSignature.forEachParameter((e) => list.add(e));
1810 return list; 1845 return list;
1811 } 1846 }
1812 1847
1813 FunctionType computeType(Compiler compiler) { 1848 FunctionType computeType(Compiler compiler) {
1814 if (typeCache != null) return typeCache; 1849 if (typeCache != null) return typeCache;
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 } 2447 }
2413 2448
2414 void forEachBackendMember(void f(Element member)) { 2449 void forEachBackendMember(void f(Element member)) {
2415 backendMembers.forEach(f); 2450 backendMembers.forEach(f);
2416 } 2451 }
2417 2452
2418 bool implementsFunction(Compiler compiler) { 2453 bool implementsFunction(Compiler compiler) {
2419 return asInstanceOf(compiler.functionClass) != null || callType != null; 2454 return asInstanceOf(compiler.functionClass) != null || callType != null;
2420 } 2455 }
2421 2456
2422 bool get isNative => nativeTagInfo != null; 2457 bool get isNative => nativeTagInfo != null || isJsInterop;
2423 2458
2424 void setNative(String name) { 2459 void setNative(String name) {
2425 // TODO(johnniwinther): Assert that this is only called once. The memory 2460 // TODO(johnniwinther): Assert that this is only called once. The memory
2426 // compiler copies pre-processed elements into a new compiler through 2461 // compiler copies pre-processed elements into a new compiler through
2427 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this 2462 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this
2428 // method. 2463 // method.
2429 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, 2464 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name,
2430 message: "Native tag info set inconsistently on $this: " 2465 message: "Native tag info set inconsistently on $this: "
2431 "Existing name '$nativeTagInfo', new name '$name'.")); 2466 "Existing name '$nativeTagInfo', new name '$name'."));
2432 nativeTagInfo = name; 2467 nativeTagInfo = name;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 AstElement get definingElement; 2949 AstElement get definingElement;
2915 2950
2916 bool get hasResolvedAst => definingElement.hasTreeElements; 2951 bool get hasResolvedAst => definingElement.hasTreeElements;
2917 2952
2918 ResolvedAst get resolvedAst { 2953 ResolvedAst get resolvedAst {
2919 return new ResolvedAst(declaration, 2954 return new ResolvedAst(declaration,
2920 definingElement.node, definingElement.treeElements); 2955 definingElement.node, definingElement.treeElements);
2921 } 2956 }
2922 2957
2923 } 2958 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698