| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 import 'dart:_foreign_helper' show JS, JS_CURRENT_ISOLATE; | 10 import 'dart:_foreign_helper' show JS, JS_CURRENT_ISOLATE; |
| 11 import 'dart:_collection-dev' as _symbol_dev; | 11 import 'dart:_collection-dev' as _symbol_dev; |
| 12 import 'dart:_js_helper' show | 12 import 'dart:_js_helper' show |
| 13 BoundClosure, | 13 BoundClosure, |
| 14 Closure, | 14 Closure, |
| 15 JSInvocationMirror, | 15 JSInvocationMirror, |
| 16 Null, | 16 Null, |
| 17 Primitives, | 17 Primitives, |
| 18 RuntimeError, | 18 RuntimeError, |
| 19 createUnmangledInvocationMirror; | 19 createUnmangledInvocationMirror; |
| 20 import 'dart:_interceptors' show Interceptor; | 20 import 'dart:_interceptors' show Interceptor; |
| 21 import 'dart:_js_names'; | 21 import 'dart:_js_names'; |
| 22 | 22 |
| 23 /// No-op method that is called to inform the compiler that | 23 /// No-op method that is called to inform the compiler that tree-shaking needs |
| 24 /// tree-shaking needs to be disabled. | 24 /// to be disabled. |
| 25 disableTreeShaking() => preserveNames(); | 25 disableTreeShaking() => preserveNames(); |
| 26 | 26 |
| 27 /// No-op method that is called to inform the compiler that metadata must be |
| 28 /// preserved at runtime. |
| 29 preserveMetadata() {} |
| 30 |
| 27 String getName(Symbol symbol) { | 31 String getName(Symbol symbol) { |
| 28 preserveNames(); | 32 preserveNames(); |
| 29 return n(symbol); | 33 return n(symbol); |
| 30 } | 34 } |
| 31 | 35 |
| 32 class JsMirrorSystem implements MirrorSystem { | 36 class JsMirrorSystem implements MirrorSystem { |
| 33 TypeMirror get dynamicType => _dynamicType; | 37 TypeMirror get dynamicType => _dynamicType; |
| 34 TypeMirror get voidType => _voidType; | 38 TypeMirror get voidType => _voidType; |
| 35 | 39 |
| 36 final static TypeMirror _dynamicType = | 40 final static TypeMirror _dynamicType = |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 addToResult(Symbol key, Mirror value) { | 182 addToResult(Symbol key, Mirror value) { |
| 179 result[key] = value; | 183 result[key] = value; |
| 180 } | 184 } |
| 181 functions.forEach(addToResult); | 185 functions.forEach(addToResult); |
| 182 getters.forEach(addToResult); | 186 getters.forEach(addToResult); |
| 183 setters.forEach(addToResult); | 187 setters.forEach(addToResult); |
| 184 variables.forEach(addToResult); | 188 variables.forEach(addToResult); |
| 185 return result; | 189 return result; |
| 186 } | 190 } |
| 187 | 191 |
| 188 List<InstanceMirror> get metadata => _metadata.map(reflect).toList(); | 192 List<InstanceMirror> get metadata { |
| 193 preserveMetadata(); |
| 194 return _metadata.map(reflect).toList(); |
| 195 } |
| 189 } | 196 } |
| 190 | 197 |
| 191 String n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 198 String n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
| 192 | 199 |
| 193 Symbol s(String name) { | 200 Symbol s(String name) { |
| 194 if (name == null) return null; | 201 if (name == null) return null; |
| 195 return new _symbol_dev.Symbol.unvalidated(name); | 202 return new _symbol_dev.Symbol.unvalidated(name); |
| 196 } | 203 } |
| 197 | 204 |
| 198 final JsMirrorSystem currentJsMirrorSystem = new JsMirrorSystem(); | 205 final JsMirrorSystem currentJsMirrorSystem = new JsMirrorSystem(); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 String get _prettyName => 'VariableMirror'; | 584 String get _prettyName => 'VariableMirror'; |
| 578 | 585 |
| 579 // TODO(ahe): Improve this information and test it. | 586 // TODO(ahe): Improve this information and test it. |
| 580 TypeMirror get type => JsMirrorSystem._dynamicType; | 587 TypeMirror get type => JsMirrorSystem._dynamicType; |
| 581 | 588 |
| 582 DeclarationMirror get owner => _owner; | 589 DeclarationMirror get owner => _owner; |
| 583 | 590 |
| 584 Symbol get qualifiedName => computeQualifiedName(owner, simpleName); | 591 Symbol get qualifiedName => computeQualifiedName(owner, simpleName); |
| 585 | 592 |
| 586 List<InstanceMirror> get metadata { | 593 List<InstanceMirror> get metadata { |
| 594 preserveMetadata(); |
| 587 if (_metadata == null) { | 595 if (_metadata == null) { |
| 588 _metadata = (_metadataFunction == null) | 596 _metadata = (_metadataFunction == null) |
| 589 ? const [] : JS('', '#()', _metadataFunction); | 597 ? const [] : JS('', '#()', _metadataFunction); |
| 590 } | 598 } |
| 591 return _metadata.map(reflect).toList(); | 599 return _metadata.map(reflect).toList(); |
| 592 } | 600 } |
| 593 | 601 |
| 594 static int fieldCode(int code) { | 602 static int fieldCode(int code) { |
| 595 if (code >= 60 && code <= 64) return code - 59; | 603 if (code >= 60 && code <= 64) return code - 59; |
| 596 if (code >= 123 && code <= 126) return code - 117; | 604 if (code >= 123 && code <= 126) return code - 117; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 } | 719 } |
| 712 | 720 |
| 713 Symbol computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { | 721 Symbol computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { |
| 714 if (owner == null) return simpleName; | 722 if (owner == null) return simpleName; |
| 715 String ownerName = n(owner.qualifiedName); | 723 String ownerName = n(owner.qualifiedName); |
| 716 if (ownerName == '') return simpleName; | 724 if (ownerName == '') return simpleName; |
| 717 return s('$ownerName.${n(simpleName)}'); | 725 return s('$ownerName.${n(simpleName)}'); |
| 718 } | 726 } |
| 719 | 727 |
| 720 List extractMetadata(victim) { | 728 List extractMetadata(victim) { |
| 729 preserveMetadata(); |
| 721 var metadataFunction = JS('', '#["@"]', victim); | 730 var metadataFunction = JS('', '#["@"]', victim); |
| 722 return (metadataFunction == null) | 731 return (metadataFunction == null) |
| 723 ? const [] : JS('', '#()', metadataFunction); | 732 ? const [] : JS('', '#()', metadataFunction); |
| 724 } | 733 } |
| OLD | NEW |