Chromium Code Reviews| 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 /// Contains logic to initialize polymer apps during development. This | 5 /// Contains logic to initialize polymer apps during development. This |
| 6 /// implementation uses dart:mirrors to load each library as they are discovered | 6 /// implementation uses dart:mirrors to load each library as they are discovered |
| 7 /// through HTML imports. This is only meant to be during development in | 7 /// through HTML imports. This is only meant to be during development in |
| 8 /// dartium, and the polymer transformers replace this implementation with | 8 /// dartium, and the polymer transformers replace this implementation with |
| 9 /// codege generation in the polymer-build steps. | 9 /// codege generation in the polymer-build steps. |
| 10 library polymer.src.mirror_loader; | 10 library polymer.src.mirror_loader; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 return initializers; | 60 return initializers; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /// Walks the HTML import structure to discover all script tags that are | 63 /// Walks the HTML import structure to discover all script tags that are |
| 64 /// implicitly loaded. This code is only used in Dartium and should only be | 64 /// implicitly loaded. This code is only used in Dartium and should only be |
| 65 /// called after all HTML imports are resolved. Polymer ensures this by asking | 65 /// called after all HTML imports are resolved. Polymer ensures this by asking |
| 66 /// users to put their Dart script tags after all HTML imports (this is checked | 66 /// users to put their Dart script tags after all HTML imports (this is checked |
| 67 /// by the linter, and Dartium will otherwise show an error message). | 67 /// by the linter, and Dartium will otherwise show an error message). |
| 68 List<_ScriptInfo> _discoverScripts(Document doc, String baseUri, [_State state]) { | 68 List<_ScriptInfo> _discoverScripts( |
| 69 Document doc, String baseUri, [_State state]) { | |
| 69 if (state == null) state = new _State(); | 70 if (state == null) state = new _State(); |
| 70 if (doc == null) { | 71 if (doc == null) { |
| 71 print('warning: $baseUri not found.'); | 72 print('warning: $baseUri not found.'); |
| 72 return state.scripts; | 73 return state.scripts; |
| 73 } | 74 } |
| 74 if (!state.seen.add(doc)) return state.scripts; | 75 if (!state.seen.add(doc)) return state.scripts; |
| 75 | 76 |
| 76 for (var node in doc.querySelectorAll('script,link[rel="import"]')) { | 77 for (var node in doc.querySelectorAll('script,link[rel="import"]')) { |
| 77 if (node is LinkElement) { | 78 if (node is LinkElement) { |
| 78 _discoverScripts(node.import, node.href, state); | 79 _discoverScripts(node.import, node.href, state); |
| 79 } else if (node is ScriptElement && node.type == 'application/dart') { | 80 } else if (node is ScriptElement && node.type == 'application/dart') { |
| 80 state.scripts.add(_scriptInfoFor(node, baseUri)); | 81 var info = _scriptInfoFor(node, baseUri); |
| 82 // Bail and warn if this script has already been seen. | |
| 83 if (state.scripts.any((s) => s.resolvedUrl == info.resolvedUrl)) { | |
|
Siggi Cherem (dart-lang)
2014/10/21 17:06:03
similarly here, let's avoid the linear lookup. One
jakemac
2014/10/21 18:14:01
Done.
| |
| 84 print('warning: script `${info.resolvedUrl}` included more than once.'); | |
|
Siggi Cherem (dart-lang)
2014/10/21 17:06:03
consider including the short link to the details h
jakemac
2014/10/21 18:14:01
Done.
| |
| 85 continue; | |
| 86 }; | |
| 87 state.scripts.add(info); | |
| 81 } | 88 } |
| 82 } | 89 } |
| 83 return state.scripts; | 90 return state.scripts; |
| 84 } | 91 } |
| 85 | 92 |
| 86 /// Internal state used in [_discoverScripts]. | 93 /// Internal state used in [_discoverScripts]. |
| 87 class _State { | 94 class _State { |
| 88 /// Documents that we have visited thus far. | 95 /// Documents that we have visited thus far. |
| 89 final Set<Document> seen = new Set(); | 96 final Set<Document> seen = new Set(); |
| 90 | 97 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 " ${method.simpleName} is not."); | 274 " ${method.simpleName} is not."); |
| 268 return; | 275 return; |
| 269 } | 276 } |
| 270 if (!method.parameters.where((p) => !p.isOptional).isEmpty) { | 277 if (!method.parameters.where((p) => !p.isOptional).isEmpty) { |
| 271 print("warning: methods marked with @initMethod should take no " | 278 print("warning: methods marked with @initMethod should take no " |
| 272 "arguments, ${method.simpleName} expects some."); | 279 "arguments, ${method.simpleName} expects some."); |
| 273 return; | 280 return; |
| 274 } | 281 } |
| 275 initializers.add(() => obj.invoke(method.simpleName, const [])); | 282 initializers.add(() => obj.invoke(method.simpleName, const [])); |
| 276 } | 283 } |
| OLD | NEW |