| Index: sdk/lib/_internal/lib/js_helper.dart
|
| diff --git a/sdk/lib/_internal/lib/js_helper.dart b/sdk/lib/_internal/lib/js_helper.dart
|
| index 58ab7a9bd38952268a2382c967b5a4dace7af1ed..fe0ca6027a58ea9997649878dc92e277c8c6fa49 100644
|
| --- a/sdk/lib/_internal/lib/js_helper.dart
|
| +++ b/sdk/lib/_internal/lib/js_helper.dart
|
| @@ -2723,6 +2723,13 @@ checkMalformedType(value, message) {
|
| throw new TypeErrorImplementation.fromMessage(message);
|
| }
|
|
|
| +@NoInline()
|
| +void checkDeferredIsLoaded(String loadId, String uri) {
|
| + if (!_loadedLibraries.contains(loadId)) {
|
| + throw new DeferredNotLoadedError(uri);
|
| + }
|
| +}
|
| +
|
| /**
|
| * Special interface recognized by the compiler and implemented by DOM
|
| * objects that support integer indexing. This interface is not
|
| @@ -2815,6 +2822,16 @@ class RuntimeError extends Error {
|
| String toString() => "RuntimeError: $message";
|
| }
|
|
|
| +class DeferredNotLoadedError extends Error {
|
| + String libraryName;
|
| +
|
| + DeferredNotLoadedError(this.libraryName);
|
| +
|
| + String toString() {
|
| + return "Deferred library $libraryName was not loaded.";
|
| + }
|
| +}
|
| +
|
| abstract class RuntimeType {
|
| const RuntimeType();
|
|
|
| @@ -3228,7 +3245,8 @@ LoadLibraryFunctionType _loadLibraryWrapper(String loadId) {
|
| return () => loadDeferredLibrary(loadId);
|
| }
|
|
|
| -final Map<String, Future<bool>> _loadedLibraries = <String, Future<bool>>{};
|
| +final Map<String, Future<bool>> _loadingLibraries = <String, Future<bool>>{};
|
| +final Set<String> _loadedLibraries = new Set<String>();
|
|
|
| Future<bool> loadDeferredLibrary(String loadId, [String uri]) {
|
| List hunkNames = new List();
|
| @@ -3245,14 +3263,14 @@ Future<bool> loadDeferredLibrary(String loadId, [String uri]) {
|
| hunkNames.map((hunkName) => _loadHunk(hunkName, uri));
|
| return Future.wait(allLoads).then((results) {
|
| return results.any((x) => x);
|
| - });
|
| + }).then((_) => _loadedLibraries.add(loadId));
|
| }
|
|
|
| Future<bool> _loadHunk(String hunkName, String uri) {
|
| // TODO(ahe): Validate libraryName. Kasper points out that you want
|
| // to be able to experiment with the effect of toggling @DeferLoad,
|
| // so perhaps we should silently ignore "bad" library names.
|
| - Future<bool> future = _loadedLibraries[hunkName];
|
| + Future<bool> future = _loadingLibraries[hunkName];
|
| if (future != null) {
|
| return future.then((_) => false);
|
| }
|
| @@ -3266,7 +3284,7 @@ Future<bool> _loadHunk(String hunkName, String uri) {
|
| if (Primitives.isJsshell || Primitives.isD8) {
|
| // TODO(ahe): Move this code to a JavaScript command helper script that is
|
| // not included in generated output.
|
| - return _loadedLibraries[hunkName] = new Future<bool>(() {
|
| + return _loadingLibraries[hunkName] = new Future<bool>(() {
|
| try {
|
| // Create a new function to avoid getting access to current function
|
| // context.
|
| @@ -3278,7 +3296,7 @@ Future<bool> _loadHunk(String hunkName, String uri) {
|
| });
|
| } else if (isWorker()) {
|
| // We are in a web worker. Load the code with an XMLHttpRequest.
|
| - return _loadedLibraries[hunkName] = new Future<bool>(() {
|
| + return _loadingLibraries[hunkName] = new Future<bool>(() {
|
| Completer completer = new Completer<bool>();
|
| enterJsAsync();
|
| Future<bool> leavingFuture = completer.future.whenComplete(() {
|
| @@ -3320,7 +3338,7 @@ Future<bool> _loadHunk(String hunkName, String uri) {
|
| });
|
| }
|
| // We are in a dom-context.
|
| - return _loadedLibraries[hunkName] = new Future<bool>(() {
|
| + return _loadingLibraries[hunkName] = new Future<bool>(() {
|
| Completer completer = new Completer<bool>();
|
| // Inject a script tag.
|
| var script = JS('', 'document.createElement("script")');
|
|
|