OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:mirrors'; | 7 import 'dart:mirrors'; |
8 import 'dart:_foreign_helper' show JS; | 8 import 'dart:_foreign_helper' show JS; |
9 import 'dart:_internal' as _internal; | 9 import 'dart:_internal' as _internal; |
10 | 10 |
11 String getName(Symbol symbol) { | 11 String getName(Symbol symbol) { |
12 if (symbol is _internal.PrivateSymbol) { | 12 if (symbol is _internal.PrivateSymbol) { |
13 return _internal.PrivateSymbol.getName(symbol); | 13 return _internal.PrivateSymbol.getName(symbol); |
14 } else { | 14 } else { |
15 return _internal.Symbol.getName(symbol as _internal.Symbol); | 15 return _internal.Symbol.getName(symbol as _internal.Symbol); |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 Symbol getSymbol(name, library) => | 19 Symbol getSymbol(name, library) => |
20 throw new UnimplementedError("MirrorSystem.getSymbol unimplemented"); | 20 throw new UnimplementedError("MirrorSystem.getSymbol unimplemented"); |
21 | 21 |
22 final currentJsMirrorSystem = throw new UnimplementedError( | 22 final currentJsMirrorSystem = new JsMirrorSystem(); |
23 "MirrorSystem.currentJsMirrorSystem unimplemented"); | |
24 | 23 |
25 final _typeMirror = JS('', 'Symbol("_typeMirror")'); | 24 final _typeMirror = JS('', 'Symbol("_typeMirror")'); |
26 | 25 |
27 InstanceMirror reflect(reflectee) { | 26 InstanceMirror reflect(reflectee) { |
28 // TODO(vsm): Consider caching the mirror here. Unlike the type below, | 27 // TODO(vsm): Consider caching the mirror here. Unlike the type below, |
29 // reflectee may be a primitive - i.e., we can't just add an expando. | 28 // reflectee may be a primitive - i.e., we can't just add an expando. |
30 if (reflectee is Function) { | 29 if (reflectee is Function) { |
31 return new JsClosureMirror._(reflectee); | 30 return new JsClosureMirror._(reflectee); |
32 } else { | 31 } else { |
33 return new JsInstanceMirror._(reflectee); | 32 return new JsInstanceMirror._(reflectee); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 217 } |
219 | 218 |
220 dynamic _toJsMap(Map<Symbol, dynamic> map) { | 219 dynamic _toJsMap(Map<Symbol, dynamic> map) { |
221 var obj = JS('', '{}'); | 220 var obj = JS('', '{}'); |
222 map.forEach((Symbol key, value) { | 221 map.forEach((Symbol key, value) { |
223 JS('', '#[#] = #', obj, getName(key), value); | 222 JS('', '#[#] = #', obj, getName(key), value); |
224 }); | 223 }); |
225 return obj; | 224 return obj; |
226 } | 225 } |
227 | 226 |
| 227 class JsMirrorSystem implements MirrorSystem { |
| 228 get libraries => const {}; |
| 229 |
| 230 noSuchMethod(Invocation i) { |
| 231 _unimplemented(this.runtimeType, i); |
| 232 } |
| 233 } |
| 234 |
228 class JsMirror implements Mirror { | 235 class JsMirror implements Mirror { |
229 noSuchMethod(Invocation i) { | 236 noSuchMethod(Invocation i) { |
230 _unimplemented(this.runtimeType, i); | 237 _unimplemented(this.runtimeType, i); |
231 } | 238 } |
232 } | 239 } |
233 | 240 |
234 class JsCombinatorMirror extends JsMirror implements CombinatorMirror {} | 241 class JsCombinatorMirror extends JsMirror implements CombinatorMirror {} |
235 | 242 |
236 class JsDeclarationMirror extends JsMirror implements DeclarationMirror {} | 243 class JsDeclarationMirror extends JsMirror implements DeclarationMirror {} |
237 | 244 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 var param = | 673 var param = |
667 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata); | 674 new JsParameterMirror._(new Symbol(''), _wrap(type), metadata); |
668 params[i + args.length] = param; | 675 params[i + args.length] = param; |
669 } | 676 } |
670 | 677 |
671 _params = new List.unmodifiable(params); | 678 _params = new List.unmodifiable(params); |
672 } | 679 } |
673 | 680 |
674 String toString() => "MethodMirror on '$_name'"; | 681 String toString() => "MethodMirror on '$_name'"; |
675 } | 682 } |
OLD | NEW |