| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Patch library for dart:mirrors. | 5 // Patch library for dart:mirrors. |
| 6 | 6 |
| 7 import 'dart:_foreign_helper' show JS; | 7 import 'dart:_foreign_helper' show JS; |
| 8 | 8 |
| 9 // Yeah, seriously: mirrors in dart2js are experimental... | 9 // Yeah, seriously: mirrors in dart2js are experimental... |
| 10 const String _MIRROR_OPT_IN_MESSAGE = """ | 10 const String _MIRROR_OPT_IN_MESSAGE = """ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 throw new UnsupportedError('Named arguments are not implemented'); | 75 throw new UnsupportedError('Named arguments are not implemented'); |
| 76 } | 76 } |
| 77 // Copy the list to ensure that it can safely be passed to | 77 // Copy the list to ensure that it can safely be passed to |
| 78 // JavaScript. | 78 // JavaScript. |
| 79 var jsList = new List.from(positionalArguments); | 79 var jsList = new List.from(positionalArguments); |
| 80 var mangledName = '${memberName}\$${positionalArguments.length}'; | 80 var mangledName = '${memberName}\$${positionalArguments.length}'; |
| 81 var method = JS('var', '#[#]', reflectee, mangledName); | 81 var method = JS('var', '#[#]', reflectee, mangledName); |
| 82 var completer = new Completer<InstanceMirror>(); | 82 var completer = new Completer<InstanceMirror>(); |
| 83 // TODO(ahe): [Completer] or [Future] should have API to create a | 83 // TODO(ahe): [Completer] or [Future] should have API to create a |
| 84 // delayed action. Simulating with a [Timer]. | 84 // delayed action. Simulating with a [Timer]. |
| 85 new Timer(0, (timer) { | 85 Timer.run(() { |
| 86 if (JS('String', 'typeof #', method) == 'function') { | 86 if (JS('String', 'typeof #', method) == 'function') { |
| 87 var result = | 87 var result = |
| 88 JS('var', '#.apply(#, #)', method, reflectee, jsList); | 88 JS('var', '#.apply(#, #)', method, reflectee, jsList); |
| 89 completer.complete(new _InstanceMirror(result)); | 89 completer.complete(new _InstanceMirror(result)); |
| 90 } else { | 90 } else { |
| 91 completer.completeError('not a method $memberName'); | 91 completer.completeError('not a method $memberName'); |
| 92 } | 92 } |
| 93 }); | 93 }); |
| 94 return completer.future; | 94 return completer.future; |
| 95 } | 95 } |
| 96 | 96 |
| 97 String toString() => 'InstanceMirror($reflectee)'; | 97 String toString() => 'InstanceMirror($reflectee)'; |
| 98 } | 98 } |
| 99 | 99 |
| 100 class _ClassMirror extends ClassMirror { | 100 class _ClassMirror extends ClassMirror { |
| 101 final String _name; | 101 final String _name; |
| 102 final _jsConstructor; | 102 final _jsConstructor; |
| 103 | 103 |
| 104 _ClassMirror(this._name, this._jsConstructor) { | 104 _ClassMirror(this._name, this._jsConstructor) { |
| 105 _ensureEnabled(); | 105 _ensureEnabled(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 String toString() => 'ClassMirror($_name)'; | 108 String toString() => 'ClassMirror($_name)'; |
| 109 } | 109 } |
| 110 | 110 |
| 111 _ensureEnabled() { | 111 _ensureEnabled() { |
| 112 if (_mirrorsEnabled) return; | 112 if (_mirrorsEnabled) return; |
| 113 throw new UnsupportedError('dart:mirrors is an experimental feature'); | 113 throw new UnsupportedError('dart:mirrors is an experimental feature'); |
| 114 } | 114 } |
| OLD | NEW |