OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Implementation of the smoke services using mirrors. | 5 /// Implementation of the smoke services using mirrors. |
6 library smoke.mirrors; | 6 library smoke.mirrors; |
7 | 7 |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 import 'package:smoke/smoke.dart'; | 9 import 'package:smoke/smoke.dart'; |
10 import 'package:logging/logging.dart'; | 10 import 'package:logging/logging.dart'; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 | 212 |
213 // TODO(jmesserly): workaround for: | 213 // TODO(jmesserly): workaround for: |
214 // https://code.google.com/p/dart/issues/detail?id=10029 | 214 // https://code.google.com/p/dart/issues/detail?id=10029 |
215 Symbol _setterName(Symbol getter) => | 215 Symbol _setterName(Symbol getter) => |
216 new Symbol('${MirrorSystem.getName(getter)}='); | 216 new Symbol('${MirrorSystem.getName(getter)}='); |
217 | 217 |
218 | 218 |
219 ClassMirror _safeSuperclass(ClassMirror type) { | 219 ClassMirror _safeSuperclass(ClassMirror type) { |
220 try { | 220 try { |
221 var t = type.superclass; | 221 return type.superclass; |
222 // TODO(sigmund): workaround for darbug.com/17779. | |
223 // Interceptor is leaked by dart2js. It has the same methods as Object | |
224 // (including noSuchMethod), and our code above assumes that it doesn't | |
225 // exist. Most queries exclude Object, so they should exclude Interceptor | |
226 // too. We don't check for t.simpleName == #Interceptor because depending on | |
227 // dart2js optimizations it may be #Interceptor or #num/Interceptor. | |
228 // Checking for a private library seems to reliably filter this out. | |
229 if (t != null && t.owner != null && t.owner.isPrivate) { | |
230 t = _objectType; | |
231 } | |
232 return t; | |
233 } on UnsupportedError catch (e) { | 222 } on UnsupportedError catch (e) { |
234 // Note: dart2js throws UnsupportedError when the type is not reflectable. | 223 // Note: dart2js throws UnsupportedError when the type is not reflectable. |
235 return _objectType; | 224 return _objectType; |
236 } | 225 } |
237 } | 226 } |
238 | 227 |
239 MethodMirror _findMethod(ClassMirror type, Symbol name) { | 228 MethodMirror _findMethod(ClassMirror type, Symbol name) { |
240 do { | 229 do { |
241 var member = type.declarations[name]; | 230 var member = type.declarations[name]; |
242 if (member is MethodMirror) return member; | 231 if (member is MethodMirror) return member; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // dartbug.com/16078). | 329 // dartbug.com/16078). |
341 // * having [call] also allows `is` checks to work for functions of 0 | 330 // * having [call] also allows `is` checks to work for functions of 0 |
342 // through 3 arguments. We depend on this in | 331 // through 3 arguments. We depend on this in |
343 // `polymer_expressions/lib/eval.dart` to check whether a function is a | 332 // `polymer_expressions/lib/eval.dart` to check whether a function is a |
344 // filter (takes a single argument). (Note that it's possible to include | 333 // filter (takes a single argument). (Note that it's possible to include |
345 // both [call] and [noSuchMethod], which would make instance-of checks | 334 // both [call] and [noSuchMethod], which would make instance-of checks |
346 // work with the signature of [call], but will allow invoking the function | 335 // work with the signature of [call], but will allow invoking the function |
347 // using [noSuchMethod]. | 336 // using [noSuchMethod]. |
348 call([a, b, c]) => invoke(receiver, methodName, [a, b, c], adjust: true); | 337 call([a, b, c]) => invoke(receiver, methodName, [a, b, c], adjust: true); |
349 } | 338 } |
OLD | NEW |