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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 return option.substring('--force-strip='.length).split(','); | 59 return option.substring('--force-strip='.length).split(','); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 return []; | 62 return []; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static bool hasOption(List<String> options, String option) { | 65 static bool hasOption(List<String> options, String option) { |
| 66 return options.indexOf(option) >= 0; | 66 return options.indexOf(option) >= 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // TODO(johnniwinther): Merge better with [translateDartUri] when | |
|
ahe
2013/01/23 12:08:23
I don't understand this comment.
Johnni Winther
2013/01/24 13:04:59
The lookup into LIBRARIES is done both here and in
| |
| 70 // [scanBuiltinLibrary] is removed. | |
| 69 String lookupLibraryPath(String dartLibraryName) { | 71 String lookupLibraryPath(String dartLibraryName) { |
| 70 LibraryInfo info = LIBRARIES[dartLibraryName]; | 72 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 71 if (info == null) return null; | 73 if (info == null) return null; |
| 72 if (!info.isDart2jsLibrary) return null; | 74 if (!info.isDart2jsLibrary) return null; |
| 73 String path = info.dart2jsPath; | 75 String path = info.dart2jsPath; |
| 74 if (path == null) { | 76 if (path == null) { |
| 75 path = info.path; | 77 path = info.path; |
| 76 } | 78 } |
| 77 return "lib/$path"; | 79 return "lib/$path"; |
| 78 } | 80 } |
| 79 | 81 |
| 80 String lookupPatchPath(String dartLibraryName) { | 82 String lookupPatchPath(String dartLibraryName) { |
| 81 LibraryInfo info = LIBRARIES[dartLibraryName]; | 83 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 82 if (info == null) return null; | 84 if (info == null) return null; |
| 83 if (!info.isDart2jsLibrary) return null; | 85 if (!info.isDart2jsLibrary) return null; |
| 84 String path = info.dart2jsPatchPath; | 86 String path = info.dart2jsPatchPath; |
| 85 if (path == null) return null; | 87 if (path == null) return null; |
| 86 return "lib/$path"; | 88 return "lib/$path"; |
| 87 } | 89 } |
| 88 | 90 |
| 89 elements.LibraryElement scanBuiltinLibrary(String path) { | 91 elements.LibraryElement scanBuiltinLibrary(String path) { |
| 90 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); | 92 Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); |
| 91 Uri canonicalUri = null; | 93 Uri canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
| 92 if (!path.startsWith("_")) { | |
| 93 canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); | |
| 94 } | |
| 95 elements.LibraryElement library = | 94 elements.LibraryElement library = |
| 96 libraryLoader.loadLibrary(uri, null, canonicalUri); | 95 libraryLoader.loadLibrary(uri, null, canonicalUri); |
| 97 return library; | 96 return library; |
| 98 } | 97 } |
| 99 | 98 |
| 100 void log(message) { | 99 void log(message) { |
| 101 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); | 100 handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
| 102 } | 101 } |
| 103 | 102 |
| 104 leg.Script readScript(Uri uri, [tree.Node node]) { | 103 Uri resolveAbsoluteUri(elements.LibraryElement importingLibrary, |
|
ahe
2013/01/24 10:00:57
Actually, this method name doesn't really make sen
ahe
2013/01/24 10:00:57
I think it would be nice with a documentation comm
Johnni Winther
2013/01/24 13:04:59
Done.
Johnni Winther
2013/01/24 13:04:59
Good idea. Couldn't come up with a good name.
| |
| 104 Uri absoluteUri, tree.Node node) { | |
| 105 if (absoluteUri.scheme == 'dart') { | |
| 106 return translateDartUri(importingLibrary, absoluteUri, node); | |
| 107 } | |
| 108 return absoluteUri; | |
| 109 } | |
| 110 | |
| 111 /** | |
| 112 * Reads the script designated by [readableUri]. | |
| 113 */ | |
| 114 leg.Script readScript(Uri readableUri, [tree.Node node]) { | |
| 115 if (!readableUri.isAbsolute()) { | |
| 116 internalError('Relative uri $readableUri provided to readScript(Uri)', | |
| 117 node: node); | |
| 118 } | |
| 105 return fileReadingTask.measure(() { | 119 return fileReadingTask.measure(() { |
| 106 if (uri.scheme == 'dart') uri = translateDartUri(uri, node); | 120 Uri resourceUri = translateUri(readableUri, node); |
| 107 var translated = translateUri(uri, node); | |
| 108 String text = ""; | 121 String text = ""; |
| 109 try { | 122 try { |
| 110 // TODO(ahe): We expect the future to be complete and call value | 123 // TODO(ahe): We expect the future to be complete and call value |
| 111 // directly. In effect, we don't support truly asynchronous API. | 124 // directly. In effect, we don't support truly asynchronous API. |
| 112 text = deprecatedFutureValue(provider(translated)); | 125 text = deprecatedFutureValue(provider(resourceUri)); |
| 113 } catch (exception) { | 126 } catch (exception) { |
| 114 if (node != null) { | 127 if (node != null) { |
| 115 cancel("$exception", node: node); | 128 cancel("$exception", node: node); |
| 116 } else { | 129 } else { |
| 117 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); | 130 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); |
| 118 throw new leg.CompilerCancelledException("$exception"); | 131 throw new leg.CompilerCancelledException("$exception"); |
| 119 } | 132 } |
| 120 } | 133 } |
| 121 SourceFile sourceFile = new SourceFile(translated.toString(), text); | 134 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text); |
| 122 return new leg.Script(uri, sourceFile); | 135 return new leg.Script(readableUri, sourceFile); |
|
ahe
2013/01/24 10:00:57
Do you know why we use the "readableUri" here? I s
Johnni Winther
2013/01/24 13:04:59
We need to preserve the scheme in the script since
| |
| 123 }); | 136 }); |
| 124 } | 137 } |
| 125 | 138 |
| 126 Uri translateUri(Uri uri, tree.Node node) { | 139 /** |
| 127 switch (uri.scheme) { | 140 * Translates a readable URI into a resource URI. |
| 128 case 'package': return translatePackageUri(uri, node); | 141 * |
| 129 default: return uri; | 142 * See [LibraryLoader] for terminology on URIs. |
| 143 */ | |
| 144 Uri translateUri(Uri readableUri, tree.Node node) { | |
| 145 switch (readableUri.scheme) { | |
| 146 case 'package': return translatePackageUri(readableUri, node); | |
| 147 default: return readableUri; | |
| 130 } | 148 } |
| 131 } | 149 } |
| 132 | 150 |
| 133 Uri translateDartUri(Uri uri, tree.Node node) { | 151 Uri translateDartUri(elements.LibraryElement importingLibrary, |
| 134 String path = lookupLibraryPath(uri.path); | 152 Uri absoluteUri, tree.Node node) { |
| 135 if (path == null || LIBRARIES[uri.path].category == "Internal") { | 153 LibraryInfo libraryInfo = LIBRARIES[absoluteUri.path]; |
| 154 String path = lookupLibraryPath(absoluteUri.path); | |
| 155 if (libraryInfo != null && | |
| 156 libraryInfo.category == "Internal") { | |
| 157 bool allowInternalLibraryAccess = false; | |
| 158 if (importingLibrary != null) { | |
| 159 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { | |
| 160 allowInternalLibraryAccess = true; | |
| 161 } else if (importingLibrary.canonicalUri.path.contains( | |
| 162 'dart/tests/compiler/dart2js_native')) { | |
| 163 allowInternalLibraryAccess = true; | |
| 164 } | |
| 165 } | |
| 166 if (!allowInternalLibraryAccess) { | |
| 167 if (node != null && importingLibrary != null) { | |
| 168 reportError(node, | |
|
ahe
2013/01/24 10:00:57
Could this be reportDiagnostic?
Johnni Winther
2013/01/24 13:04:59
Done.
| |
| 169 'Internal library $absoluteUri is not accessible from ' | |
| 170 '${importingLibrary.canonicalUri}'); | |
| 171 } else { | |
| 172 reportError(null, 'Internal library $absoluteUri is not accessible'); | |
| 173 } | |
| 174 path = null; | |
|
ahe
2013/01/24 10:00:57
How about not setting path to null? The compiler w
Johnni Winther
2013/01/24 13:04:59
Done.
| |
| 175 } | |
| 176 } | |
| 177 if (path == null) { | |
| 136 if (node != null) { | 178 if (node != null) { |
| 137 reportError(node, 'library not found ${uri}'); | 179 reportError(node, 'library not found ${absoluteUri}'); |
| 138 } else { | 180 } else { |
| 139 reportDiagnostic(null, 'library not found ${uri}', | 181 reportDiagnostic(null, 'library not found ${absoluteUri}', |
| 140 api.Diagnostic.ERROR); | 182 api.Diagnostic.ERROR); |
| 141 } | 183 } |
| 142 return null; | 184 return null; |
| 143 } | 185 } |
| 144 if (uri.path == 'html' || | 186 if (absoluteUri.path == 'html' || |
| 145 uri.path == 'io') { | 187 absoluteUri.path == 'io') { |
| 146 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 188 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
| 147 // supports this use case better. | 189 // supports this use case better. |
| 148 mockableLibraryUsed = true; | 190 mockableLibraryUsed = true; |
| 149 } | 191 } |
| 150 return libraryRoot.resolve(path); | 192 return libraryRoot.resolve(path); |
| 151 } | 193 } |
| 152 | 194 |
| 153 Uri resolvePatchUri(String dartLibraryPath) { | 195 Uri resolvePatchUri(String dartLibraryPath) { |
| 154 String patchPath = lookupPatchPath(dartLibraryPath); | 196 String patchPath = lookupPatchPath(dartLibraryPath); |
| 155 if (patchPath == null) return null; | 197 if (patchPath == null) return null; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 185 handler(translateUri(span.uri, null), span.begin, span.end, | 227 handler(translateUri(span.uri, null), span.begin, span.end, |
| 186 message, kind); | 228 message, kind); |
| 187 } | 229 } |
| 188 } | 230 } |
| 189 | 231 |
| 190 bool get isMockCompilation { | 232 bool get isMockCompilation { |
| 191 return mockableLibraryUsed | 233 return mockableLibraryUsed |
| 192 && (options.indexOf('--allow-mock-compilation') != -1); | 234 && (options.indexOf('--allow-mock-compilation') != -1); |
| 193 } | 235 } |
| 194 } | 236 } |
| OLD | NEW |