| Index: third_party/pkg/angular/lib/mock/zone.dart
|
| ===================================================================
|
| --- third_party/pkg/angular/lib/mock/zone.dart (revision 33054)
|
| +++ third_party/pkg/angular/lib/mock/zone.dart (working copy)
|
| @@ -2,9 +2,9 @@
|
|
|
| import 'dart:async' as dart_async;
|
|
|
| -final _asyncQueue = <Function>[];
|
| -final _timerQueue = <_TimerSpec>[];
|
| -final _asyncErrors = [];
|
| +List<Function> _asyncQueue = [];
|
| +List<_TimerSpec> _timerQueue = [];
|
| +List _asyncErrors = [];
|
| bool _noMoreAsync = false;
|
|
|
| /**
|
| @@ -34,12 +34,12 @@
|
| while (!_asyncQueue.isEmpty) {
|
| // copy the queue as it may change.
|
| var toRun = new List.from(_asyncQueue);
|
| - _asyncQueue.clear();
|
| + _asyncQueue = [];
|
| // TODO: Support the case where multiple exceptions are thrown.
|
| // e.g. with a throwNextException() method.
|
| assert(_asyncErrors.isEmpty);
|
| toRun.forEach((fn) => fn());
|
| - if (_asyncErrors.isNotEmpty) {
|
| + if (!_asyncErrors.isEmpty) {
|
| var e = _asyncErrors.removeAt(0);
|
| throw ['Async error', e[0], e[1]];
|
| }
|
| @@ -77,55 +77,54 @@
|
| * expect(timerRan).toBe(4);
|
| * }));
|
| */
|
| -void clockTick({int days: 0,
|
| - int hours: 0,
|
| - int minutes: 0,
|
| - int seconds: 0,
|
| - int milliseconds: 0,
|
| - int microseconds: 0}) {
|
| +clockTick({int days: 0,
|
| + int hours: 0,
|
| + int minutes: 0,
|
| + int seconds: 0,
|
| + int milliseconds: 0,
|
| + int microseconds: 0}) {
|
| var tickDuration = new Duration(days: days, hours: hours, minutes: minutes,
|
| seconds: seconds, milliseconds: milliseconds, microseconds: microseconds);
|
|
|
| + var queue = _timerQueue;
|
| var remainingTimers = [];
|
| - var queue = new List.from(_timerQueue);
|
| - _timerQueue.clear();
|
| - queue
|
| - .where((_TimerSpec spec) => spec.isActive)
|
| - .forEach((_TimerSpec spec) {
|
| - if (spec.periodic) {
|
| - // We always add back the periodic timer unless it's cancelled.
|
| - remainingTimers.add(spec);
|
| + _timerQueue = [];
|
| + queue.forEach((_TimerSpec spec) {
|
| + if (!spec.isActive) return; // Skip over inactive timers.
|
| + if (spec.periodic) {
|
| + // We always add back the periodic timer unless it's cancelled.
|
| + remainingTimers.add(spec);
|
|
|
| - // Ignore ZERO duration ticks for periodic timers.
|
| - if (tickDuration == Duration.ZERO) return;
|
| + // Ignore ZERO duration ticks for periodic timers.
|
| + if (tickDuration == Duration.ZERO) return;
|
|
|
| - spec.elapsed += tickDuration;
|
| - // Run the timer as many times as the timer priod fits into the tick.
|
| - while (spec.elapsed >= spec.duration) {
|
| - spec.elapsed -= spec.duration;
|
| - microLeap();
|
| - spec.fn(spec);
|
| - }
|
| + spec.elapsed += tickDuration;
|
| + // Run the timer as many times as the timer priod fits into the tick.
|
| + while (spec.elapsed >= spec.duration) {
|
| + spec.elapsed -= spec.duration;
|
| + microLeap();
|
| + spec.fn(spec);
|
| + }
|
| + } else {
|
| + spec.duration -= tickDuration;
|
| + if (spec.duration <= Duration.ZERO) {
|
| + microLeap();
|
| + spec.fn();
|
| } else {
|
| - spec.duration -= tickDuration;
|
| - if (spec.duration <= Duration.ZERO) {
|
| - microLeap();
|
| - spec.fn();
|
| - } else {
|
| - remainingTimers.add(spec);
|
| - }
|
| + remainingTimers.add(spec);
|
| }
|
| - });
|
| + }
|
| + });
|
| // Remaining timers should come before anything else scheduled after them.
|
| _timerQueue.insertAll(0, remainingTimers);
|
| }
|
|
|
| /**
|
| - * Causes scheduleMicrotask calls to throw exceptions.
|
| - *
|
| - * This function is useful while debugging async tests: the exception
|
| - * is thrown from the scheduleMicrotask call-site instead later in the test.
|
| - */
|
| +* Causes scheduleMicrotask calls to throw exceptions.
|
| +*
|
| +* This function is useful while debugging async tests: the exception
|
| +* is thrown from the scheduleMicrotask call-site instead later in the test.
|
| +*/
|
| noMoreAsync() {
|
| _noMoreAsync = true;
|
| }
|
| @@ -139,10 +138,11 @@
|
| * ...
|
| * }));
|
| */
|
| -async(Function fn) => () {
|
| +async(Function fn) =>
|
| + () {
|
| _noMoreAsync = false;
|
| - _asyncErrors.clear();
|
| - _timerQueue.clear();
|
| + _asyncErrors = [];
|
| + _timerQueue = [];
|
| var zoneSpec = new dart_async.ZoneSpecification(
|
| scheduleMicrotask: (_, __, ___, asyncFn) {
|
| if (_noMoreAsync) {
|
| @@ -167,12 +167,9 @@
|
| throw "During runZoned: ${e[0]}. Stack:\n${e[1]}";
|
| });
|
|
|
| - var activeTimers = _timerQueue.fold(0, (nb, _TimerSpec spec) {
|
| - return spec.isActive ? nb + 1 : nb;
|
| - });
|
| -
|
| - if (activeTimers > 0) {
|
| - throw ["$activeTimers active timer(s) are still in the queue."];
|
| + if (!_timerQueue.isEmpty && _timerQueue.any((_TimerSpec spec) => spec.isActive)) {
|
| + throw ["${_timerQueue.where((_TimerSpec spec) => spec.isActive).length} "
|
| + "active timer(s) are still in the queue."];
|
| }
|
| };
|
|
|
|
|