Chromium Code Reviews| 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 library leg_apiimpl; | 5 library leg_apiimpl; |
| 6 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import '../compiler.dart' as api; | 10 import '../compiler.dart' as api; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 LibraryInfo info = LIBRARIES[dartLibraryName]; | 82 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 83 if (info == null) return null; | 83 if (info == null) return null; |
| 84 if (!info.isDart2jsLibrary) return null; | 84 if (!info.isDart2jsLibrary) return null; |
| 85 String path = info.dart2jsPatchPath; | 85 String path = info.dart2jsPatchPath; |
| 86 if (path == null) return null; | 86 if (path == null) return null; |
| 87 return "lib/$path"; | 87 return "lib/$path"; |
| 88 } | 88 } |
| 89 | 89 |
| 90 elements.LibraryElement scanBuiltinLibrary(String path) { | 90 elements.LibraryElement scanBuiltinLibrary(String path) { |
| 91 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); | 91 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); |
| 92 Uri canonicalUri = null; | 92 Uri canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
| 93 if (!path.startsWith("_")) { | |
| 94 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); | |
| 95 } | |
| 96 elements.LibraryElement library = | 93 elements.LibraryElement library = |
| 97 libraryLoader.loadLibrary(uri, null, canonicalUri); | 94 libraryLoader.loadLibrary(uri, null, canonicalUri); |
| 98 return library; | 95 return library; |
| 99 } | 96 } |
| 100 | 97 |
| 101 void log(message) { | 98 void log(message) { |
| 102 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); | 99 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
| 103 } | 100 } |
| 104 | 101 |
| 102 /** | |
| 103 * Resolves the [uri] into a file resource URI. | |
| 104 * | |
| 105 * The [importingUri] holds the canonical uri for the library importing [uri] | |
| 106 * or [:null:] if [uri] is loaded as the main library. The [importingUri] is | |
| 107 * used to grant access to private libraries for platform libraries. | |
|
ahe
2013/01/18 11:03:10
Please document that this method is responsible fo
Johnni Winther
2013/01/21 09:27:54
Done.
| |
| 108 */ | |
| 109 Uri resolveScriptUri(Uri importingUri, Uri uri, [tree.Node node]) { | |
|
ahe
2013/01/18 11:03:10
I like this method.
| |
| 110 if (uri.scheme == 'dart') { | |
| 111 return translateDartUri(importingUri, uri, node); | |
| 112 } | |
| 113 return translateUri(uri, node); | |
| 114 } | |
| 115 | |
| 116 /** | |
| 117 * Reads the script designated by [uri]. | |
| 118 */ | |
| 105 leg.Script readScript(Uri uri, [tree.Node node]) { | 119 leg.Script readScript(Uri uri, [tree.Node node]) { |
| 120 if (!uri.isAbsolute()) throw new ArgumentError(uri); | |
|
ahe
2013/01/18 11:03:10
You should be able to report an (internal) error i
Johnni Winther
2013/01/21 09:27:54
Done.
| |
| 106 return fileReadingTask.measure(() { | 121 return fileReadingTask.measure(() { |
| 107 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); | |
|
ahe
2013/01/18 11:03:10
I really like that you got rid of this.
| |
| 108 var translated = translateUri(uri, node); | |
| 109 String text = ""; | 122 String text = ""; |
| 110 try { | 123 try { |
| 111 // TODO(ahe): We expect the future to be complete and call value | 124 // TODO(ahe): We expect the future to be complete and call value |
| 112 // directly. In effect, we don't support truly asynchronous API. | 125 // directly. In effect, we don't support truly asynchronous API. |
| 113 text = deprecatedFutureValue(provider(translated)); | 126 text = deprecatedFutureValue(provider(uri)); |
| 114 } catch (exception) { | 127 } catch (exception) { |
| 115 if (node != null) { | 128 if (node != null) { |
| 116 cancel("$exception", node: node); | 129 cancel("$exception", node: node); |
| 117 } else { | 130 } else { |
| 118 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); | 131 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); |
| 119 throw new leg.CompilerCancelledException("$exception"); | 132 throw new leg.CompilerCancelledException("$exception"); |
| 120 } | 133 } |
| 121 } | 134 } |
| 122 SourceFile sourceFile = new SourceFile(translated.toString(), text); | 135 SourceFile sourceFile = new SourceFile(uri.toString(), text); |
| 123 return new leg.Script(uri, sourceFile); | 136 return new leg.Script(uri, sourceFile); |
| 124 }); | 137 }); |
| 125 } | 138 } |
| 126 | 139 |
| 127 Uri translateUri(Uri uri, tree.Node node) { | 140 Uri translateUri(Uri uri, tree.Node node) { |
| 128 switch (uri.scheme) { | 141 switch (uri.scheme) { |
| 129 case 'package': return translatePackageUri(uri, node); | 142 case 'package': return translatePackageUri(uri, node); |
| 130 default: return uri; | 143 default: return uri; |
| 131 } | 144 } |
| 132 } | 145 } |
| 133 | 146 |
| 134 Uri translateDartUri(Uri uri, tree.Node node) { | 147 Uri translateDartUri(Uri sourceUri, Uri uri, tree.Node node) { |
| 135 String path = lookupLibraryPath(uri.path); | 148 String path = lookupLibraryPath(uri.path); |
| 136 if (path == null || LIBRARIES[uri.path].category == "Internal") { | 149 if (LIBRARIES[uri.path] != null && |
|
ngeoffray
2013/01/16 15:40:57
Store LIBRARIES[uri.path] in a local variable?
Johnni Winther
2013/01/21 09:27:54
Done.
| |
| 150 LIBRARIES[uri.path].category == "Internal") { | |
| 151 bool allowPrivateLibraryAccess = false; | |
| 152 if (sourceUri != null) { | |
| 153 if (sourceUri.scheme == 'dart' || sourceUri.scheme == 'patch') { | |
|
ahe
2013/01/18 11:03:10
What is the patch scheme?
Johnni Winther
2013/01/21 09:27:54
A new scheme used to provide patch libraries with
ahe
2013/01/21 09:39:38
I don't think it is a good idea to invent new sche
Johnni Winther
2013/01/21 09:45:55
Then I'll have to encode it in the path, like dart
ahe
2013/01/21 10:08:25
I was hoping we could get rid of encoding this inf
Johnni Winther
2013/01/21 10:15:15
Then I think I'd rather go back to having no canon
ahe
2013/01/21 10:18:09
SGTM
| |
| 154 allowPrivateLibraryAccess = true; | |
| 155 } | |
| 156 if (sourceUri.path.contains('dart/tests/compiler/dart2js_native')) { | |
| 157 allowPrivateLibraryAccess = true; | |
| 158 } | |
| 159 } | |
| 160 if (!allowPrivateLibraryAccess) { | |
| 161 log('Internal library $uri is not accessible ' | |
|
ngeoffray
2013/01/16 15:40:57
Why do you log that? Isn't that something that the
ahe
2013/01/18 11:03:10
The user will see an error message like this:
fis
Johnni Winther
2013/01/21 09:27:54
Changed to [reportError].
| |
| 162 '${sourceUri != null ? 'from $sourceUri' : ''}'); | |
| 163 path = null; | |
| 164 } | |
| 165 } | |
| 166 if (path == null) { | |
| 137 if (node != null) { | 167 if (node != null) { |
| 138 reportError(node, 'library not found ${uri}'); | 168 reportError(node, 'library not found ${uri}'); |
| 139 } else { | 169 } else { |
| 140 reportDiagnostic(null, 'library not found ${uri}', | 170 reportDiagnostic(null, 'library not found ${uri}', |
| 141 api.Diagnostic.ERROR); | 171 api.Diagnostic.ERROR); |
| 142 } | 172 } |
| 143 return null; | 173 return null; |
| 144 } | 174 } |
| 145 if (uri.path == 'html' || | 175 if (uri.path == 'html' || |
| 146 uri.path == 'io') { | 176 uri.path == 'io') { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 handler(translateUri(span.uri, null), span.begin, span.end, | 216 handler(translateUri(span.uri, null), span.begin, span.end, |
| 187 message, kind); | 217 message, kind); |
| 188 } | 218 } |
| 189 } | 219 } |
| 190 | 220 |
| 191 bool get isMockCompilation { | 221 bool get isMockCompilation { |
| 192 return mockableLibraryUsed | 222 return mockableLibraryUsed |
| 193 && (options.indexOf('--allow-mock-compilation') != -1); | 223 && (options.indexOf('--allow-mock-compilation') != -1); |
| 194 } | 224 } |
| 195 } | 225 } |
| OLD | NEW |