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 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:package_config/packages.dart'; | 10 import 'package:package_config/packages.dart'; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 result.add('Internal'); | 184 result.add('Internal'); |
185 return new Set<String>.from(result); | 185 return new Set<String>.from(result); |
186 } | 186 } |
187 | 187 |
188 static bool hasOption(List<String> options, String option) { | 188 static bool hasOption(List<String> options, String option) { |
189 return options.indexOf(option) >= 0; | 189 return options.indexOf(option) >= 0; |
190 } | 190 } |
191 | 191 |
192 // TODO(johnniwinther): Merge better with [translateDartUri] when | 192 // TODO(johnniwinther): Merge better with [translateDartUri] when |
193 // [scanBuiltinLibrary] is removed. | 193 // [scanBuiltinLibrary] is removed. |
194 String lookupLibraryPath(LibraryInfo info) { | 194 String lookupLibraryPath(Uri uri, LibraryInfo info) { |
195 if (info == null) return null; | 195 if (info == null) return null; |
196 if (!info.isDart2jsLibrary) return null; | 196 if (!info.isDart2jsLibrary) return null; |
197 if (!allowedLibraryCategories.contains(info.category)) return null; | 197 if (!allowedLibraryCategories.contains(info.category)) { |
| 198 registerDisallowedLibraryUse(uri); |
| 199 return null; |
| 200 } |
198 String path = info.dart2jsPath; | 201 String path = info.dart2jsPath; |
199 if (path == null) { | 202 if (path == null) { |
200 path = info.path; | 203 path = info.path; |
201 } | 204 } |
202 return "lib/$path"; | 205 return "lib/$path"; |
203 } | 206 } |
204 | 207 |
205 String lookupPatchPath(String dartLibraryName) { | 208 String lookupPatchPath(String dartLibraryName) { |
206 LibraryInfo info = lookupLibraryInfo(dartLibraryName); | 209 LibraryInfo info = lookupLibraryInfo(dartLibraryName); |
207 if (info == null) return null; | 210 if (info == null) return null; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 Uri translateUri(Spannable node, Uri readableUri) { | 312 Uri translateUri(Spannable node, Uri readableUri) { |
310 switch (readableUri.scheme) { | 313 switch (readableUri.scheme) { |
311 case 'package': return translatePackageUri(node, readableUri); | 314 case 'package': return translatePackageUri(node, readableUri); |
312 default: return readableUri; | 315 default: return readableUri; |
313 } | 316 } |
314 } | 317 } |
315 | 318 |
316 Uri translateDartUri(elements.LibraryElement importingLibrary, | 319 Uri translateDartUri(elements.LibraryElement importingLibrary, |
317 Uri resolvedUri, tree.Node node) { | 320 Uri resolvedUri, tree.Node node) { |
318 LibraryInfo libraryInfo = lookupLibraryInfo(resolvedUri.path); | 321 LibraryInfo libraryInfo = lookupLibraryInfo(resolvedUri.path); |
319 String path = lookupLibraryPath(libraryInfo); | 322 String path = lookupLibraryPath(resolvedUri, libraryInfo); |
320 if (libraryInfo != null && | 323 if (libraryInfo != null && |
321 libraryInfo.category == "Internal") { | 324 libraryInfo.category == "Internal") { |
322 bool allowInternalLibraryAccess = false; | 325 bool allowInternalLibraryAccess = false; |
323 if (importingLibrary != null) { | 326 if (importingLibrary != null) { |
324 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { | 327 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { |
325 allowInternalLibraryAccess = true; | 328 allowInternalLibraryAccess = true; |
326 } else if (importingLibrary.canonicalUri.path.contains( | 329 } else if (importingLibrary.canonicalUri.path.contains( |
327 'sdk/tests/compiler/dart2js_native')) { | 330 'sdk/tests/compiler/dart2js_native')) { |
328 allowInternalLibraryAccess = true; | 331 allowInternalLibraryAccess = true; |
329 } | 332 } |
330 } | 333 } |
331 if (!allowInternalLibraryAccess) { | 334 if (!allowInternalLibraryAccess) { |
332 if (importingLibrary != null) { | 335 if (importingLibrary != null) { |
333 reportError( | 336 reportError( |
334 node, | 337 node, |
335 MessageKind.INTERNAL_LIBRARY_FROM, | 338 MessageKind.INTERNAL_LIBRARY_FROM, |
336 {'resolvedUri': resolvedUri, | 339 {'resolvedUri': resolvedUri, |
337 'importingUri': importingLibrary.canonicalUri}); | 340 'importingUri': importingLibrary.canonicalUri}); |
338 } else { | 341 } else { |
339 reportError( | 342 reportError( |
340 node, | 343 node, |
341 MessageKind.INTERNAL_LIBRARY, | 344 MessageKind.INTERNAL_LIBRARY, |
342 {'resolvedUri': resolvedUri}); | 345 {'resolvedUri': resolvedUri}); |
343 } | 346 } |
344 } | 347 } |
345 } | 348 } |
346 if (path == null) { | 349 if (path == null) { |
347 reportError(node, MessageKind.LIBRARY_NOT_FOUND, | 350 if (libraryInfo == null) { |
348 {'resolvedUri': resolvedUri}); | 351 reportError(node, MessageKind.LIBRARY_NOT_FOUND, |
| 352 {'resolvedUri': resolvedUri}); |
| 353 } else { |
| 354 reportError(node, MessageKind.LIBRARY_NOT_SUPPORTED, |
| 355 {'resolvedUri': resolvedUri}); |
| 356 } |
| 357 // TODO(johnniwinther): Support signaling the error through the returned |
| 358 // value. |
349 return null; | 359 return null; |
350 } | 360 } |
351 if (resolvedUri.path == 'html' || | 361 if (resolvedUri.path == 'html' || |
352 resolvedUri.path == 'io') { | 362 resolvedUri.path == 'io') { |
353 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart | 363 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
354 // supports this use case better. | 364 // supports this use case better. |
355 mockableLibraryUsed = true; | 365 mockableLibraryUsed = true; |
356 } | 366 } |
357 return libraryRoot.resolve(path); | 367 return libraryRoot.resolve(path); |
358 } | 368 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 print('$message: ${tryToString(exception)}'); | 524 print('$message: ${tryToString(exception)}'); |
515 print(tryToString(stackTrace)); | 525 print(tryToString(stackTrace)); |
516 } | 526 } |
517 | 527 |
518 fromEnvironment(String name) => environment[name]; | 528 fromEnvironment(String name) => environment[name]; |
519 | 529 |
520 LibraryInfo lookupLibraryInfo(String libraryName) { | 530 LibraryInfo lookupLibraryInfo(String libraryName) { |
521 return library_info.LIBRARIES[libraryName]; | 531 return library_info.LIBRARIES[libraryName]; |
522 } | 532 } |
523 } | 533 } |
OLD | NEW |