| 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:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../compiler.dart' as api; | 9 import '../compiler.dart' as api; |
| 10 import 'dart2jslib.dart' as leg; | 10 import 'dart2jslib.dart' as leg; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 Uri resourceUri = translateUri(readableUri, node); | 170 Uri resourceUri = translateUri(readableUri, node); |
| 171 String text = ""; | 171 String text = ""; |
| 172 try { | 172 try { |
| 173 // TODO(ahe): We expect the future to be complete and call value | 173 // TODO(ahe): We expect the future to be complete and call value |
| 174 // directly. In effect, we don't support truly asynchronous API. | 174 // directly. In effect, we don't support truly asynchronous API. |
| 175 text = deprecatedFutureValue(provider(resourceUri)); | 175 text = deprecatedFutureValue(provider(resourceUri)); |
| 176 } catch (exception) { | 176 } catch (exception) { |
| 177 if (node != null) { | 177 if (node != null) { |
| 178 cancel("$exception", node: node); | 178 cancel("$exception", node: node); |
| 179 } else { | 179 } else { |
| 180 reportDiagnostic(null, "$exception", api.Diagnostic.ERROR); | 180 reportError( |
| 181 null, |
| 182 leg.MessageKind.GENERIC, {'text': 'Error: $exception'}); |
| 181 throw new leg.CompilerCancelledException("$exception"); | 183 throw new leg.CompilerCancelledException("$exception"); |
| 182 } | 184 } |
| 183 } | 185 } |
| 184 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text); | 186 SourceFile sourceFile = new SourceFile(resourceUri.toString(), text); |
| 185 // We use [readableUri] as the URI for the script since need to preserve | 187 // We use [readableUri] as the URI for the script since need to preserve |
| 186 // the scheme in the script because [Script.uri] is used for resolving | 188 // the scheme in the script because [Script.uri] is used for resolving |
| 187 // relative URIs mentioned in the script. See the comment on | 189 // relative URIs mentioned in the script. See the comment on |
| 188 // [LibraryLoader] for more details. | 190 // [LibraryLoader] for more details. |
| 189 return new leg.Script(readableUri, sourceFile); | 191 return new leg.Script(readableUri, sourceFile); |
| 190 }); | 192 }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 212 if (importingLibrary != null) { | 214 if (importingLibrary != null) { |
| 213 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { | 215 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { |
| 214 allowInternalLibraryAccess = true; | 216 allowInternalLibraryAccess = true; |
| 215 } else if (importingLibrary.canonicalUri.path.contains( | 217 } else if (importingLibrary.canonicalUri.path.contains( |
| 216 'dart/tests/compiler/dart2js_native')) { | 218 'dart/tests/compiler/dart2js_native')) { |
| 217 allowInternalLibraryAccess = true; | 219 allowInternalLibraryAccess = true; |
| 218 } | 220 } |
| 219 } | 221 } |
| 220 if (!allowInternalLibraryAccess) { | 222 if (!allowInternalLibraryAccess) { |
| 221 if (node != null && importingLibrary != null) { | 223 if (node != null && importingLibrary != null) { |
| 222 reportDiagnostic(spanFromNode(node), | 224 reportError( |
| 223 'Error: Internal library $resolvedUri is not accessible from ' | 225 node, |
| 224 '${importingLibrary.canonicalUri}.', | 226 leg.MessageKind.GENERIC, |
| 225 api.Diagnostic.ERROR); | 227 {'text': |
| 228 'Error: Internal library $resolvedUri is not accessible from ' |
| 229 '${importingLibrary.canonicalUri}.'}); |
| 226 } else { | 230 } else { |
| 227 reportDiagnostic(null, | 231 reportError( |
| 228 'Error: Internal library $resolvedUri is not accessible.', | 232 null, |
| 229 api.Diagnostic.ERROR); | 233 leg.MessageKind.GENERIC, |
| 234 {'text': |
| 235 'Error: Internal library $resolvedUri is not accessible.'}); |
| 230 } | 236 } |
| 231 //path = null; | |
| 232 } | 237 } |
| 233 } | 238 } |
| 234 if (path == null) { | 239 if (path == null) { |
| 235 if (node != null) { | 240 if (node != null) { |
| 236 reportError(node, 'library not found ${resolvedUri}'); | 241 reportError( |
| 242 node, |
| 243 leg.MessageKind.GENERIC, |
| 244 {'text': 'Error: Library not found ${resolvedUri}.'}); |
| 237 } else { | 245 } else { |
| 238 reportDiagnostic(null, 'library not found ${resolvedUri}', | 246 reportError( |
| 239 api.Diagnostic.ERROR); | 247 null, |
| 248 leg.MessageKind.GENERIC, |
| 249 {'text': 'Error: Library not found ${resolvedUri}.'}); |
| 240 } | 250 } |
| 241 return null; | 251 return null; |
| 242 } | 252 } |
| 243 if (resolvedUri.path == 'html' || | 253 if (resolvedUri.path == 'html' || |
| 244 resolvedUri.path == 'io') { | 254 resolvedUri.path == 'io') { |
| 245 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 255 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
| 246 // supports this use case better. | 256 // supports this use case better. |
| 247 mockableLibraryUsed = true; | 257 mockableLibraryUsed = true; |
| 248 } | 258 } |
| 249 return libraryRoot.resolve(path); | 259 return libraryRoot.resolve(path); |
| 250 } | 260 } |
| 251 | 261 |
| 252 Uri resolvePatchUri(String dartLibraryPath) { | 262 Uri resolvePatchUri(String dartLibraryPath) { |
| 253 String patchPath = lookupPatchPath(dartLibraryPath); | 263 String patchPath = lookupPatchPath(dartLibraryPath); |
| 254 if (patchPath == null) return null; | 264 if (patchPath == null) return null; |
| 255 return libraryRoot.resolve(patchPath); | 265 return libraryRoot.resolve(patchPath); |
| 256 } | 266 } |
| 257 | 267 |
| 258 Uri translatePackageUri(Uri uri, tree.Node node) { | 268 Uri translatePackageUri(Uri uri, tree.Node node) { |
| 259 if (packageRoot == null) { | 269 if (packageRoot == null) { |
| 260 if (node != null) { | 270 reportFatalError( |
| 261 reportErrorCode(node, | 271 node, leg.MessageKind.PACKAGE_ROOT_NOT_SET, {'uri': uri}); |
| 262 leg.MessageKind.PACKAGE_ROOT_NOT_SET, | |
| 263 {'uri': uri}); | |
| 264 } else { | |
| 265 reportDiagnostic(null, | |
| 266 leg.MessageKind.PACKAGE_ROOT_NOT_SET.error({'uri': uri}).toString(), | |
| 267 api.Diagnostic.ERROR); | |
| 268 } | |
| 269 throw new leg.CompilerCancelledException("Package root not set."); | |
| 270 } | 272 } |
| 271 return packageRoot.resolve(uri.path); | 273 return packageRoot.resolve(uri.path); |
| 272 } | 274 } |
| 273 | 275 |
| 274 bool run(Uri uri) { | 276 bool run(Uri uri) { |
| 275 log('Allowed library categories: $allowedLibraryCategories'); | 277 log('Allowed library categories: $allowedLibraryCategories'); |
| 276 bool success = super.run(uri); | 278 bool success = super.run(uri); |
| 277 int cumulated = 0; | 279 int cumulated = 0; |
| 278 for (final task in tasks) { | 280 for (final task in tasks) { |
| 279 cumulated += task.timing; | 281 cumulated += task.timing; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 299 handler(translateUri(span.uri, null), span.begin, span.end, | 301 handler(translateUri(span.uri, null), span.begin, span.end, |
| 300 message, kind); | 302 message, kind); |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 bool get isMockCompilation { | 306 bool get isMockCompilation { |
| 305 return mockableLibraryUsed | 307 return mockableLibraryUsed |
| 306 && (options.indexOf('--allow-mock-compilation') != -1); | 308 && (options.indexOf('--allow-mock-compilation') != -1); |
| 307 } | 309 } |
| 308 } | 310 } |
| OLD | NEW |