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

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 '../common/resolution.dart' show 7 import '../common/resolution.dart' show
8 Resolution, 8 Resolution,
9 Parsing; 9 Parsing;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 ? enclosingElement.name 234 ? enclosingElement.name
235 : '${enclosingElement.kind}?'; 235 : '${enclosingElement.kind}?';
236 return '$kind($holderName#${nameText})'; 236 return '$kind($holderName#${nameText})';
237 } else { 237 } else {
238 return '$kind(${nameText})'; 238 return '$kind(${nameText})';
239 } 239 }
240 } 240 }
241 241
242 String _fixedBackendName = null; 242 String _fixedBackendName = null;
243 bool _isNative = false; 243 bool _isNative = false;
244 bool get isNative => _isNative; 244 String _jsInteropName = null;
245 bool get hasFixedBackendName => _fixedBackendName != null; 245 bool _isJsInterop = false;
246 String get fixedBackendName => _fixedBackendName; 246
247 /// Whether the element is implemented via typed JavaScript interop.
248 bool get isJsInterop => _isJsInterop;
249 /// JavaScript name for the element if it is implemented via typed JavaScript
250 /// interop.
251 String get jsInteropName => _jsInteropName;
252
253 void markAsJsInterop() {
254 _isJsInterop = true;
255 }
256
257 void setJsInteropName(String name) {
258 assert(invariant(this,
259 _isJsInterop,
260 message: 'Element is not js interop but given a js interop name.'));
261 _jsInteropName = name;
262 }
263
264 /// Whether the element corresponds to a native JavaScript construct either
265 /// through the existing [setNative] mechanism which is only allowed
266 /// for internal libraries or via the new typed JavaScriptInterop mechanism
267 /// which is allowed for user libraries.
268 bool get isNative => _isNative || isJsInterop;
269 bool get hasFixedBackendName => fixedBackendName != null || isJsInterop;
270
271 String _jsNameHelper(Element e) {
272 assert(invariant(this,
273 !(_isJsInterop && _jsInteropName == null),
274 message:
275 'Element is js interop but js interop name has not yet been'
276 'computed.'));
277 if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) {
278 return e.jsInteropName;
279 }
280 return e.isLibrary ? 'self' : e.name;
281 }
282
283 String get fixedBackendName {
284 if (_fixedBackendName == null && isJsInterop) {
285 // If an element isJsInterop but _isJsInterop is false that means it is
286 // considered interop as the parent class is interop.
287 _fixedBackendName = _jsNameHelper(isConstructor ? enclosingClass : this);
288 }
289 return _fixedBackendName;
290 }
291
247 // Marks this element as a native element. 292 // Marks this element as a native element.
248 void setNative(String name) { 293 void setNative(String name) {
249 _isNative = true; 294 _isNative = true;
250 _fixedBackendName = name; 295 _fixedBackendName = name;
251 } 296 }
252 297
253 FunctionElement asFunctionElement() => null; 298 FunctionElement asFunctionElement() => null;
254 299
255 bool get isAbstract => modifiers.isAbstract; 300 bool get isAbstract => modifiers.isAbstract;
256 301
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 functionSignatureCache = resolution.resolveSignature(this); 2024 functionSignatureCache = resolution.resolveSignature(this);
1980 return functionSignatureCache; 2025 return functionSignatureCache;
1981 } 2026 }
1982 2027
1983 FunctionSignature get functionSignature { 2028 FunctionSignature get functionSignature {
1984 assert(invariant(this, functionSignatureCache != null, 2029 assert(invariant(this, functionSignatureCache != null,
1985 message: "Function signature has not been computed for $this.")); 2030 message: "Function signature has not been computed for $this."));
1986 return functionSignatureCache; 2031 return functionSignatureCache;
1987 } 2032 }
1988 2033
2034 /// An function is part of JsInterop in the following cases:
2035 /// * It has a jsInteropName annotation
2036 /// * It is external member of a class or library tagged as JsInterop.
2037 bool get isJsInterop {
2038 if (!isExternal) return false;
2039
2040 if (super.isJsInterop) return true;
2041 if (isClassMember) return contextClass.isJsInterop;
2042 if (isTopLevel) return library.isJsInterop;
2043 return false;
2044 }
2045
1989 List<ParameterElement> get parameters { 2046 List<ParameterElement> get parameters {
1990 // TODO(johnniwinther): Store the list directly, possibly by using List 2047 // TODO(johnniwinther): Store the list directly, possibly by using List
1991 // instead of Link in FunctionSignature. 2048 // instead of Link in FunctionSignature.
1992 List<ParameterElement> list = <ParameterElement>[]; 2049 List<ParameterElement> list = <ParameterElement>[];
1993 functionSignature.forEachParameter((e) => list.add(e)); 2050 functionSignature.forEachParameter((e) => list.add(e));
1994 return list; 2051 return list;
1995 } 2052 }
1996 2053
1997 FunctionType computeType(Resolution resolution) { 2054 FunctionType computeType(Resolution resolution) {
1998 if (typeCache != null) return typeCache; 2055 if (typeCache != null) return typeCache;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 } 2655 }
2599 2656
2600 void forEachBackendMember(void f(Element member)) { 2657 void forEachBackendMember(void f(Element member)) {
2601 backendMembers.forEach(f); 2658 backendMembers.forEach(f);
2602 } 2659 }
2603 2660
2604 bool implementsFunction(Compiler compiler) { 2661 bool implementsFunction(Compiler compiler) {
2605 return asInstanceOf(compiler.functionClass) != null || callType != null; 2662 return asInstanceOf(compiler.functionClass) != null || callType != null;
2606 } 2663 }
2607 2664
2608 bool get isNative => nativeTagInfo != null; 2665 bool get isNative => nativeTagInfo != null || isJsInterop;
2609 2666
2610 void setNative(String name) { 2667 void setNative(String name) {
2611 // TODO(johnniwinther): Assert that this is only called once. The memory 2668 // TODO(johnniwinther): Assert that this is only called once. The memory
2612 // compiler copies pre-processed elements into a new compiler through 2669 // compiler copies pre-processed elements into a new compiler through
2613 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this 2670 // [Compiler.onLibraryScanned] and thereby causes multiple calls to this
2614 // method. 2671 // method.
2615 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name, 2672 assert(invariant(this, nativeTagInfo == null || nativeTagInfo == name,
2616 message: "Native tag info set inconsistently on $this: " 2673 message: "Native tag info set inconsistently on $this: "
2617 "Existing name '$nativeTagInfo', new name '$name'.")); 2674 "Existing name '$nativeTagInfo', new name '$name'."));
2618 nativeTagInfo = name; 2675 nativeTagInfo = name;
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 AstElement get definingElement; 3160 AstElement get definingElement;
3104 3161
3105 bool get hasResolvedAst => definingElement.hasTreeElements; 3162 bool get hasResolvedAst => definingElement.hasTreeElements;
3106 3163
3107 ResolvedAst get resolvedAst { 3164 ResolvedAst get resolvedAst {
3108 return new ResolvedAst(declaration, 3165 return new ResolvedAst(declaration,
3109 definingElement.node, definingElement.treeElements); 3166 definingElement.node, definingElement.treeElements);
3110 } 3167 }
3111 3168
3112 } 3169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698