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 // Helpers for writing compiler tests running in browser. | 5 // Helpers for writing compiler tests running in browser. |
6 library trydart.web_compiler_test_case; | 6 library trydart.web_compiler_test_case; |
7 | 7 |
8 import 'dart:async' show | 8 import 'dart:async' show |
9 EventSink, | 9 EventSink, |
10 Future; | 10 Future; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 final String source; | 74 final String source; |
75 | 75 |
76 final Uri mainUri; | 76 final Uri mainUri; |
77 | 77 |
78 final Uri libraryRoot; | 78 final Uri libraryRoot; |
79 | 79 |
80 final Uri packageRoot; | 80 final Uri packageRoot; |
81 | 81 |
82 final Map<Uri, Future> cachedSources = new Map<Uri, Future>(); | 82 final Map<Uri, Future> cachedSources = new Map<Uri, Future>(); |
83 | 83 |
| 84 static final Map<String, Future> cachedRequests = new Map<String, Future>(); |
| 85 |
84 WebInputProvider( | 86 WebInputProvider( |
85 this.source, this.mainUri, this.libraryRoot, this.packageRoot); | 87 this.source, this.mainUri, this.libraryRoot, this.packageRoot); |
86 | 88 |
87 Future call(Uri uri) { | 89 Future call(Uri uri) { |
88 return cachedSources.putIfAbsent(uri, () { | 90 return cachedSources.putIfAbsent(uri, () { |
89 if (uri == mainUri) return new Future.value(source); | 91 if (uri == mainUri) return new Future.value(source); |
90 if (uri.scheme == WEB_SCHEME) { | 92 if (uri.scheme == WEB_SCHEME) { |
91 return HttpRequest.getString('/root_dart${uri.path}'); | 93 return cachedHttpRequest('/root_dart${uri.path}'); |
92 } else { | 94 } else { |
93 return HttpRequest.getString('$uri'); | 95 return cachedHttpRequest('$uri'); |
94 } | 96 } |
95 }); | 97 }); |
96 } | 98 } |
| 99 |
| 100 static Future cachedHttpRequest(String uri) { |
| 101 return cachedRequests.putIfAbsent(uri, () => HttpRequest.getString(uri)); |
| 102 } |
97 } | 103 } |
98 | 104 |
99 /// Output provider which collect output in [output]. | 105 /// Output provider which collect output in [output]. |
100 class OutputProvider { | 106 class OutputProvider { |
101 final Map<String, String> output = new Map<String, String>(); | 107 final Map<String, String> output = new Map<String, String>(); |
102 | 108 |
103 EventSink<String> call(String name, String extension) { | 109 EventSink<String> call(String name, String extension) { |
104 return new StringEventSink((String data) { | 110 return new StringEventSink((String data) { |
105 output['$name.$extension'] = data; | 111 output['$name.$extension'] = data; |
106 }); | 112 }); |
(...skipping 19 matching lines...) Expand all Loading... |
126 throw 'addError($errorEvent, $stackTrace)'; | 132 throw 'addError($errorEvent, $stackTrace)'; |
127 } | 133 } |
128 | 134 |
129 void close() { | 135 void close() { |
130 if (data != null) { | 136 if (data != null) { |
131 onClose(data.join()); | 137 onClose(data.join()); |
132 data = null; | 138 data = null; |
133 } | 139 } |
134 } | 140 } |
135 } | 141 } |
OLD | NEW |