Index: lib/src/mirror_loader.dart |
diff --git a/lib/src/mirror_loader.dart b/lib/src/mirror_loader.dart |
index c84721590658482a834bb58caa185ffef41122f6..c58f187c40527d0c768778605ef1b8354f5cc3f2 100644 |
--- a/lib/src/mirror_loader.dart |
+++ b/lib/src/mirror_loader.dart |
@@ -11,8 +11,8 @@ import 'package:initialize/initialize.dart'; |
final _root = currentMirrorSystem().isolate.rootLibrary; |
Queue<Function> loadInitializers( |
- {List<Type> typeFilter, InitializerFilter customFilter}) { |
- return new InitializationCrawler(typeFilter, customFilter).run(); |
+ {List<Type> typeFilter, InitializerFilter customFilter, Uri from}) { |
+ return new InitializationCrawler(typeFilter, customFilter, from: from).run(); |
} |
// Crawls a library and all its dependencies for `Initializer` annotations using |
@@ -30,7 +30,19 @@ class InitializationCrawler { |
// function will be processed. |
final InitializerFilter customFilter; |
- InitializationCrawler(this.typeFilter, this.customFilter); |
+ /// Optional property, if supplied then crawling will run from this library |
+ /// only. |
+ /// |
+ /// Note: This is only supported in the mirror_loader.dart. It is not |
+ /// supported statically. |
+ final LibraryMirror _rootLibrary; |
+ |
+ InitializationCrawler(this.typeFilter, this.customFilter, {Uri from}) |
+ : _rootLibrary = currentMirrorSystem().libraries[from] { |
+ if (from != null && _rootLibrary == null) { |
+ throw 'Unable to find library at $from.'; |
+ } |
+ } |
// The primary function in this class, invoke it to crawl and collect all the |
// annotations into a queue of init functions. |
@@ -39,8 +51,9 @@ class InitializationCrawler { |
var queue = new Queue<Function>(); |
var libraries = currentMirrorSystem().libraries; |
- var trampolineUri = Uri.parse('${_root.uri}\$trampoline'); |
- if (libraries.containsKey(trampolineUri)) { |
+ if (_rootLibrary != null) { |
+ _readLibraryDeclarations(_rootLibrary, librariesSeen, queue); |
+ } else if (libraries.containsKey(Uri.parse('${_root.uri}\$trampoline'))) { |
// In dartium, process all relative libraries in reverse order of when |
// they were seen. |
// TODO(jakemac): This is an approximation of what we actually want. |