| Index: runtime/lib/lib_prefix.dart
|
| diff --git a/runtime/lib/lib_prefix.dart b/runtime/lib/lib_prefix.dart
|
| index 9d5af287e9e25e79f56e8ca99c2cb7e8318687c3..269542660d759ae7577f435d2f3162e7cec4dd68 100644
|
| --- a/runtime/lib/lib_prefix.dart
|
| +++ b/runtime/lib/lib_prefix.dart
|
| @@ -32,7 +32,7 @@ class _LibraryPrefix {
|
| // prefix. If that is the case, we must invalidate the dependent
|
| // code and complete the future now since there will be no callback
|
| // from the VM.
|
| - if (hasCompleted) {
|
| + if (hasCompleted && !completer.isCompleted) {
|
| _invalidateDependentCode();
|
| completer.complete(true);
|
| _outstandingLoadRequests.remove(pair);
|
| @@ -53,19 +53,27 @@ _completeDeferredLoads() {
|
| // which have not completed, remember them for next time in
|
| // stillOutstandingLoadRequests.
|
| var stillOutstandingLoadRequests = new List<List>();
|
| - for (int i = 0; i < _outstandingLoadRequests.length; i++) {
|
| - var prefix = _outstandingLoadRequests[i][0];
|
| - if (prefix._load()) {
|
| - var completer = _outstandingLoadRequests[i][1];
|
| - var error = prefix._loadError();
|
| - if (error != null) {
|
| - completer.completeError(error);
|
| - } else {
|
| - prefix._invalidateDependentCode();
|
| - completer.complete(true);
|
| - }
|
| + var completedLoadRequests = new List<List>();
|
| +
|
| + // Make a copy of the outstandingRequests because the call to _load below
|
| + // may recursively trigger another call to |_completeDeferredLoads|, which
|
| + // can cause |_outstandingLoadRequests| to be modified.
|
| + var outstandingRequests = _outstandingLoadRequests.toList();
|
| + for (int i = 0; i < outstandingRequests.length; i++) {
|
| + var prefix = outstandingRequests[i][0];
|
| + var completer = outstandingRequests[i][1];
|
| + var error = prefix._loadError();
|
| + if (completer.isCompleted) {
|
| + // Already completed. Skip.
|
| + continue;
|
| + }
|
| + if (error != null) {
|
| + completer.completeError(error);
|
| + } else if (prefix._load()) {
|
| + prefix._invalidateDependentCode();
|
| + completer.complete(true);
|
| } else {
|
| - stillOutstandingLoadRequests.add(_outstandingLoadRequests[i]);
|
| + stillOutstandingLoadRequests.add(outstandingRequests[i]);
|
| }
|
| }
|
| _outstandingLoadRequests = stillOutstandingLoadRequests;
|
|
|