| OLD | NEW |
| 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 dart._js_mirrors; | 5 library dart._js_mirrors; |
| 6 | 6 |
| 7 import 'shared/runtime_data.dart' as encoding; | 7 import 'shared/runtime_data.dart' as encoding; |
| 8 | 8 |
| 9 import 'dart:collection' show | 9 import 'dart:collection' show |
| 10 UnmodifiableListView, | 10 UnmodifiableListView, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 TearOffClosure, | 33 TearOffClosure, |
| 34 TypeVariable, | 34 TypeVariable, |
| 35 UnimplementedNoSuchMethodError, | 35 UnimplementedNoSuchMethodError, |
| 36 createRuntimeType, | 36 createRuntimeType, |
| 37 createUnmangledInvocationMirror, | 37 createUnmangledInvocationMirror, |
| 38 getMangledTypeName, | 38 getMangledTypeName, |
| 39 getMetadata, | 39 getMetadata, |
| 40 getRuntimeType, | 40 getRuntimeType, |
| 41 runtimeTypeToString, | 41 runtimeTypeToString, |
| 42 setRuntimeTypeInfo, | 42 setRuntimeTypeInfo, |
| 43 throwInvalidReflectionError; | 43 throwInvalidReflectionError, |
| 44 TypeImpl; |
| 44 | 45 |
| 45 import 'dart:_interceptors' show | 46 import 'dart:_interceptors' show |
| 46 Interceptor, | 47 Interceptor, |
| 47 JSArray, | 48 JSArray, |
| 48 JSExtendableArray, | 49 JSExtendableArray, |
| 49 getInterceptor; | 50 getInterceptor; |
| 50 | 51 |
| 51 import 'dart:_js_names'; | 52 import 'dart:_js_names'; |
| 52 | 53 |
| 53 const String METHODS_WITH_OPTIONAL_ARGUMENTS = r'$methodsWithOptionalArguments'; | 54 const String METHODS_WITH_OPTIONAL_ARGUMENTS = r'$methodsWithOptionalArguments'; |
| (...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 for (int i = 0; i < typeVariables.length; i++) { | 2669 for (int i = 0; i < typeVariables.length; i++) { |
| 2669 if (typeVariables[i].simpleName == s(name)) { | 2670 if (typeVariables[i].simpleName == s(name)) { |
| 2670 return i; | 2671 return i; |
| 2671 } | 2672 } |
| 2672 } | 2673 } |
| 2673 throw new ArgumentError('Type variable not present in list.'); | 2674 throw new ArgumentError('Type variable not present in list.'); |
| 2674 } | 2675 } |
| 2675 | 2676 |
| 2676 TypeMirror typeMirrorFromRuntimeTypeRepresentation( | 2677 TypeMirror typeMirrorFromRuntimeTypeRepresentation( |
| 2677 DeclarationMirror owner, | 2678 DeclarationMirror owner, |
| 2678 var /*int|List|JsFunction*/ type) { | 2679 var /*int|List|JsFunction|TypeImpl*/ type) { |
| 2679 // TODO(ahe): This method might benefit from using convertRtiToRuntimeType | 2680 // TODO(ahe): This method might benefit from using convertRtiToRuntimeType |
| 2680 // instead of working on strings. | 2681 // instead of working on strings. |
| 2681 ClassMirror ownerClass; | 2682 ClassMirror ownerClass; |
| 2682 DeclarationMirror context = owner; | 2683 DeclarationMirror context = owner; |
| 2683 while (context != null) { | 2684 while (context != null) { |
| 2684 if (context is ClassMirror) { | 2685 if (context is ClassMirror) { |
| 2685 ownerClass = context; | 2686 ownerClass = context; |
| 2686 break; | 2687 break; |
| 2687 } | 2688 } |
| 2688 // TODO(ahe): Get type parameters and arguments from typedefs. | 2689 // TODO(ahe): Get type parameters and arguments from typedefs. |
| 2689 if (context is TypedefMirror) break; | 2690 if (context is TypedefMirror) break; |
| 2690 context = context.owner; | 2691 context = context.owner; |
| 2691 } | 2692 } |
| 2692 | 2693 |
| 2693 String representation; | 2694 String representation; |
| 2694 if (type == null) { | 2695 if (type == null) { |
| 2695 return JsMirrorSystem._dynamicType; | 2696 return JsMirrorSystem._dynamicType; |
| 2696 } else if (type is Type) { | 2697 } else if (type is TypeImpl) { |
| 2697 return reflectType(type); | 2698 return reflectType(type); |
| 2698 } else if (ownerClass == null) { | 2699 } else if (ownerClass == null) { |
| 2699 representation = runtimeTypeToString(type); | 2700 representation = runtimeTypeToString(type); |
| 2700 } else if (ownerClass.isOriginalDeclaration) { | 2701 } else if (ownerClass.isOriginalDeclaration) { |
| 2701 if (type is num) { | 2702 if (type is num) { |
| 2702 // [type] represents a type variable so in the context of an original | 2703 // [type] represents a type variable so in the context of an original |
| 2703 // declaration the corresponding type variable should be returned. | 2704 // declaration the corresponding type variable should be returned. |
| 2704 TypeVariable typeVariable = getMetadata(type); | 2705 TypeVariable typeVariable = getMetadata(type); |
| 2705 List<TypeVariableMirror> typeVariables = ownerClass.typeVariables; | 2706 List<TypeVariableMirror> typeVariables = ownerClass.typeVariables; |
| 2706 int index = findTypeVariableIndex(typeVariables, typeVariable.name); | 2707 int index = findTypeVariableIndex(typeVariables, typeVariable.name); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2922 // have a part (following a '.') that starts with '_'. | 2923 // have a part (following a '.') that starts with '_'. |
| 2923 const int UNDERSCORE = 0x5f; | 2924 const int UNDERSCORE = 0x5f; |
| 2924 if (name.isEmpty) return true; | 2925 if (name.isEmpty) return true; |
| 2925 int index = -1; | 2926 int index = -1; |
| 2926 do { | 2927 do { |
| 2927 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; | 2928 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; |
| 2928 index = name.indexOf('.', index + 1); | 2929 index = name.indexOf('.', index + 1); |
| 2929 } while (index >= 0 && index + 1 < name.length); | 2930 } while (index >= 0 && index + 1 < name.length); |
| 2930 return true; | 2931 return true; |
| 2931 } | 2932 } |
| OLD | NEW |