Index: sdk/lib/_internal/compiler/implementation/apiimpl.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/apiimpl.dart b/sdk/lib/_internal/compiler/implementation/apiimpl.dart |
index 3297e5229d0374a28f5478ed17a99e5bb1bb5bb7..58c1a6565eb3f1d4fb190f7d24c9ebd51eb82902 100644 |
--- a/sdk/lib/_internal/compiler/implementation/apiimpl.dart |
+++ b/sdk/lib/_internal/compiler/implementation/apiimpl.dart |
@@ -66,6 +66,8 @@ class Compiler extends leg.Compiler { |
return options.indexOf(option) >= 0; |
} |
+ // 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
|
+ // [scanBuiltinLibrary] is removed. |
String lookupLibraryPath(String dartLibraryName) { |
LibraryInfo info = LIBRARIES[dartLibraryName]; |
if (info == null) return null; |
@@ -88,10 +90,7 @@ class Compiler extends leg.Compiler { |
elements.LibraryElement scanBuiltinLibrary(String path) { |
Uri uri = libraryRoot.resolve(lookupLibraryPath(path)); |
- Uri canonicalUri = null; |
- if (!path.startsWith("_")) { |
- canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
- } |
+ Uri canonicalUri = new Uri.fromComponents(scheme: "dart", path: path); |
elements.LibraryElement library = |
libraryLoader.loadLibrary(uri, null, canonicalUri); |
return library; |
@@ -101,15 +100,29 @@ class Compiler extends leg.Compiler { |
handler(null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
} |
- leg.Script readScript(Uri uri, [tree.Node node]) { |
+ 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.
|
+ Uri absoluteUri, tree.Node node) { |
+ if (absoluteUri.scheme == 'dart') { |
+ return translateDartUri(importingLibrary, absoluteUri, node); |
+ } |
+ return absoluteUri; |
+ } |
+ |
+ /** |
+ * Reads the script designated by [readableUri]. |
+ */ |
+ leg.Script readScript(Uri readableUri, [tree.Node node]) { |
+ if (!readableUri.isAbsolute()) { |
+ internalError('Relative uri $readableUri provided to readScript(Uri)', |
+ node: node); |
+ } |
return fileReadingTask.measure(() { |
- if (uri.scheme == 'dart') uri = translateDartUri(uri, node); |
- var translated = translateUri(uri, node); |
+ Uri resourceUri = translateUri(readableUri, node); |
String text = ""; |
try { |
// TODO(ahe): We expect the future to be complete and call value |
// directly. In effect, we don't support truly asynchronous API. |
- text = deprecatedFutureValue(provider(translated)); |
+ text = deprecatedFutureValue(provider(resourceUri)); |
} catch (exception) { |
if (node != null) { |
cancel("$exception", node: node); |
@@ -118,31 +131,60 @@ class Compiler extends leg.Compiler { |
throw new leg.CompilerCancelledException("$exception"); |
} |
} |
- SourceFile sourceFile = new SourceFile(translated.toString(), text); |
- return new leg.Script(uri, sourceFile); |
+ SourceFile sourceFile = new SourceFile(resourceUri.toString(), text); |
+ 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
|
}); |
} |
- Uri translateUri(Uri uri, tree.Node node) { |
- switch (uri.scheme) { |
- case 'package': return translatePackageUri(uri, node); |
- default: return uri; |
+ /** |
+ * Translates a readable URI into a resource URI. |
+ * |
+ * See [LibraryLoader] for terminology on URIs. |
+ */ |
+ Uri translateUri(Uri readableUri, tree.Node node) { |
+ switch (readableUri.scheme) { |
+ case 'package': return translatePackageUri(readableUri, node); |
+ default: return readableUri; |
} |
} |
- Uri translateDartUri(Uri uri, tree.Node node) { |
- String path = lookupLibraryPath(uri.path); |
- if (path == null || LIBRARIES[uri.path].category == "Internal") { |
+ Uri translateDartUri(elements.LibraryElement importingLibrary, |
+ Uri absoluteUri, tree.Node node) { |
+ LibraryInfo libraryInfo = LIBRARIES[absoluteUri.path]; |
+ String path = lookupLibraryPath(absoluteUri.path); |
+ if (libraryInfo != null && |
+ libraryInfo.category == "Internal") { |
+ bool allowInternalLibraryAccess = false; |
+ if (importingLibrary != null) { |
+ if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { |
+ allowInternalLibraryAccess = true; |
+ } else if (importingLibrary.canonicalUri.path.contains( |
+ 'dart/tests/compiler/dart2js_native')) { |
+ allowInternalLibraryAccess = true; |
+ } |
+ } |
+ if (!allowInternalLibraryAccess) { |
+ if (node != null && importingLibrary != null) { |
+ reportError(node, |
ahe
2013/01/24 10:00:57
Could this be reportDiagnostic?
Johnni Winther
2013/01/24 13:04:59
Done.
|
+ 'Internal library $absoluteUri is not accessible from ' |
+ '${importingLibrary.canonicalUri}'); |
+ } else { |
+ reportError(null, 'Internal library $absoluteUri is not accessible'); |
+ } |
+ 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.
|
+ } |
+ } |
+ if (path == null) { |
if (node != null) { |
- reportError(node, 'library not found ${uri}'); |
+ reportError(node, 'library not found ${absoluteUri}'); |
} else { |
- reportDiagnostic(null, 'library not found ${uri}', |
+ reportDiagnostic(null, 'library not found ${absoluteUri}', |
api.Diagnostic.ERROR); |
} |
return null; |
} |
- if (uri.path == 'html' || |
- uri.path == 'io') { |
+ if (absoluteUri.path == 'html' || |
+ absoluteUri.path == 'io') { |
// TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
// supports this use case better. |
mockableLibraryUsed = true; |