// Generated by dart2js (fast startup emitter, strong), the Dart to JavaScript compiler version: 2.8.0-292505767.
// The code supports the following hooks:
// dartPrint(message):
//    if this function is defined it is called instead of the Dart [print]
//    method.
//
// dartMainRunner(main, args):
//    if this function is defined, the Dart [main] method will not be invoked
//    directly. Instead, a closure that will invoke [main], and its arguments
//    [args] is passed to [dartMainRunner].
//
// dartDeferredLibraryLoader(uri, successCallback, errorCallback):
//    if this function is defined, it will be called when a deferred library
//    is loaded. It should load and eval the javascript of `uri`, and call
//    successCallback. If it fails to do so, it should call errorCallback with
//    an error.
//
// dartCallInstrumentation(id, qualifiedName):
//    if this function is defined, it will be called at each entry of a
//    method or constructor. Used only when compiling programs with
//    --experiment-call-instrumentation.
(function dartProgram() {
  function copyProperties(from, to) {
    var keys = Object.keys(from);
    for (var i = 0; i < keys.length; i++) {
      var key = keys[i];
      to[key] = from[key];
    }
  }
  var supportsDirectProtoAccess = function() {
    var cls = function() {
    };
    cls.prototype = {p: {}};
    var object = new cls();
    if (!(object.__proto__ && object.__proto__.p === cls.prototype.p))
      return false;
    try {
      if (typeof navigator != "undefined" && typeof navigator.userAgent == "string" && navigator.userAgent.indexOf("Chrome/") >= 0)
        return true;
      if (typeof version == "function" && version.length == 0) {
        var v = version();
        if (/^\d+\.\d+\.\d+\.\d+$/.test(v))
          return true;
      }
    } catch (_) {
    }
    return false;
  }();
  function setFunctionNamesIfNecessary(holders) {
    function t() {
    }
    ;
    if (typeof t.name == "string")
      return;
    for (var i = 0; i < holders.length; i++) {
      var holder = holders[i];
      var keys = Object.keys(holder);
      for (var j = 0; j < keys.length; j++) {
        var key = keys[j];
        var f = holder[key];
        if (typeof f == 'function')
          f.name = key;
      }
    }
  }
  function inherit(cls, sup) {
    cls.prototype.constructor = cls;
    cls.prototype["$is" + cls.name] = cls;
    if (sup != null) {
      if (supportsDirectProtoAccess) {
        cls.prototype.__proto__ = sup.prototype;
        return;
      }
      var clsPrototype = Object.create(sup.prototype);
      copyProperties(cls.prototype, clsPrototype);
      cls.prototype = clsPrototype;
    }
  }
  function inheritMany(sup, classes) {
    for (var i = 0; i < classes.length; i++)
      inherit(classes[i], sup);
  }
  function mixin(cls, mixin) {
    copyProperties(mixin.prototype, cls.prototype);
    cls.prototype.constructor = cls;
  }
  function lazy(holder, name, getterName, initializer) {
    var uninitializedSentinel = holder;
    holder[name] = uninitializedSentinel;
    holder[getterName] = function() {
      holder[getterName] = function() {
        H.throwCyclicInit(name);
      };
      var result;
      var sentinelInProgress = initializer;
      try {
        if (holder[name] === uninitializedSentinel) {
          result = holder[name] = sentinelInProgress;
          result = holder[name] = initializer();
        } else
          result = holder[name];
      } finally {
        if (result === sentinelInProgress)
          holder[name] = null;
        holder[getterName] = function() {
          return this[name];
        };
      }
      return result;
    };
  }
  function makeConstList(list) {
    list.immutable$list = Array;
    list.fixed$length = Array;
    return list;
  }
  function convertToFastObject(properties) {
    function t() {
    }
    t.prototype = properties;
    new t();
    return properties;
  }
  function convertAllToFastObject(arrayOfObjects) {
    for (var i = 0; i < arrayOfObjects.length; ++i)
      convertToFastObject(arrayOfObjects[i]);
  }
  var functionCounter = 0;
  function tearOffGetter(funcs, applyTrampolineIndex, reflectionInfo, name, isIntercepted) {
    return isIntercepted ? new Function("funcs", "applyTrampolineIndex", "reflectionInfo", "name", "H", "c", "return function tearOff_" + name + functionCounter++ + "(receiver) {" + "if (c === null) c = " + "H.closureFromTearOff" + "(" + "this, funcs, applyTrampolineIndex, reflectionInfo, false, true, name);" + "return new c(this, funcs[0], receiver, name);" + "}")(funcs, applyTrampolineIndex, reflectionInfo, name, H, null) : new Function("funcs", "applyTrampolineIndex", "reflectionInfo", "name", "H", "c", "return function tearOff_" + name + functionCounter++ + "() {" + "if (c === null) c = " + "H.closureFromTearOff" + "(" + "this, funcs, applyTrampolineIndex, reflectionInfo, false, false, name);" + "return new c(this, funcs[0], null, name);" + "}")(funcs, applyTrampolineIndex, reflectionInfo, name, H, null);
  }
  function tearOff(funcs, applyTrampolineIndex, reflectionInfo, isStatic, name, isIntercepted) {
    var cache = null;
    return isStatic ? function() {
      if (cache === null)
        cache = H.closureFromTearOff(this, funcs, applyTrampolineIndex, reflectionInfo, true, false, name).prototype;
      return cache;
    } : tearOffGetter(funcs, applyTrampolineIndex, reflectionInfo, name, isIntercepted);
  }
  var typesOffset = 0;
  function installTearOff(container, getterName, isStatic, isIntercepted, requiredParameterCount, optionalParameterDefaultValues, callNames, funsOrNames, funType, applyIndex) {
    var funs = [];
    for (var i = 0; i < funsOrNames.length; i++) {
      var fun = funsOrNames[i];
      if (typeof fun == 'string')
        fun = container[fun];
      fun.$callName = callNames[i];
      funs.push(fun);
    }
    var fun = funs[0];
    fun.$requiredArgCount = requiredParameterCount;
    fun.$defaultValues = optionalParameterDefaultValues;
    var reflectionInfo = funType;
    if (typeof reflectionInfo == "number")
      reflectionInfo += typesOffset;
    var name = funsOrNames[0];
    fun.$stubName = name;
    var getterFunction = tearOff(funs, applyIndex || 0, reflectionInfo, isStatic, name, isIntercepted);
    container[getterName] = getterFunction;
    if (isStatic)
      fun.$tearOff = getterFunction;
  }
  function installStaticTearOff(container, getterName, requiredParameterCount, optionalParameterDefaultValues, callNames, funsOrNames, funType, applyIndex) {
    return installTearOff(container, getterName, true, false, requiredParameterCount, optionalParameterDefaultValues, callNames, funsOrNames, funType, applyIndex);
  }
  function installInstanceTearOff(container, getterName, isIntercepted, requiredParameterCount, optionalParameterDefaultValues, callNames, funsOrNames, funType, applyIndex) {
    return installTearOff(container, getterName, false, isIntercepted, requiredParameterCount, optionalParameterDefaultValues, callNames, funsOrNames, funType, applyIndex);
  }
  function setOrUpdateInterceptorsByTag(newTags) {
    var tags = init.interceptorsByTag;
    if (!tags) {
      init.interceptorsByTag = newTags;
      return;
    }
    copyProperties(newTags, tags);
  }
  function setOrUpdateLeafTags(newTags) {
    var tags = init.leafTags;
    if (!tags) {
      init.leafTags = newTags;
      return;
    }
    copyProperties(newTags, tags);
  }
  function updateTypes(newTypes) {
    var types = init.types;
    var length = types.length;
    types.push.apply(types, newTypes);
    return length;
  }
  function updateHolder(holder, newHolder) {
    copyProperties(newHolder, holder);
    return holder;
  }
  var hunkHelpers = function() {
    var mkInstance = function(isIntercepted, requiredParameterCount, optionalParameterDefaultValues, callNames, applyIndex) {
        return function(container, getterName, name, funType) {
          return installInstanceTearOff(container, getterName, isIntercepted, requiredParameterCount, optionalParameterDefaultValues, callNames, [name], funType, applyIndex);
        };
      },
      mkStatic = function(requiredParameterCount, optionalParameterDefaultValues, callNames, applyIndex) {
        return function(container, getterName, name, funType) {
          return installStaticTearOff(container, getterName, requiredParameterCount, optionalParameterDefaultValues, callNames, [name], funType, applyIndex);
        };
      };
    return {inherit: inherit, inheritMany: inheritMany, mixin: mixin, installStaticTearOff: installStaticTearOff, installInstanceTearOff: installInstanceTearOff, _instance_0u: mkInstance(0, 0, null, ["call$0"], 0), _instance_1u: mkInstance(0, 1, null, ["call$1"], 0), _instance_2u: mkInstance(0, 2, null, ["call$2"], 0), _instance_0i: mkInstance(1, 0, null, ["call$0"], 0), _instance_1i: mkInstance(1, 1, null, ["call$1"], 0), _instance_2i: mkInstance(1, 2, null, ["call$2"], 0), _static_0: mkStatic(0, null, ["call$0"], 0), _static_1: mkStatic(1, null, ["call$1"], 0), _static_2: mkStatic(2, null, ["call$2"], 0), makeConstList: makeConstList, lazy: lazy, updateHolder: updateHolder, convertToFastObject: convertToFastObject, setFunctionNamesIfNecessary: setFunctionNamesIfNecessary, updateTypes: updateTypes, setOrUpdateInterceptorsByTag: setOrUpdateInterceptorsByTag, setOrUpdateLeafTags: setOrUpdateLeafTags};
  }();
  function initializeDeferredHunk(hunk) {
    typesOffset = init.types.length;
    hunk(hunkHelpers, init, holders, $);
  }
  function getGlobalFromName(name) {
    for (var i = 0; i < holders.length; i++) {
      if (holders[i] == C)
        continue;
      if (holders[i][name])
        return holders[i][name];
    }
  }
  var C = {},
  H = {JS_CONST: function JS_CONST() {
    },
    CastIterable_CastIterable: function(source, $S, $T) {
      if ($S._eval$1("EfficientLengthIterable<0>")._is(source))
        return new H._EfficientLengthCastIterable(source, $S._eval$1("@<0>")._bind$1($T)._eval$1("_EfficientLengthCastIterable<1,2>"));
      return new H.CastIterable(source, $S._eval$1("@<0>")._bind$1($T)._eval$1("CastIterable<1,2>"));
    },
    hexDigitValue: function(char) {
      var digit, letter;
      H.assertHelper(char <= 65535);
      digit = char ^ 48;
      if (digit <= 9)
        return digit;
      letter = char | 32;
      if (97 <= letter && letter <= 102)
        return letter - 87;
      return -1;
    },
    SubListIterable$: function(_iterable, _start, _endOrLength, $E) {
      P.RangeError_checkNotNegative(_start, "start");
      if (_endOrLength != null) {
        P.RangeError_checkNotNegative(_endOrLength, "end");
        if (_start > _endOrLength)
          H.throwExpression(P.RangeError$range(_start, 0, _endOrLength, "start", null));
      }
      return new H.SubListIterable(_iterable, _start, _endOrLength, $E._eval$1("SubListIterable<0>"));
    },
    MappedIterable_MappedIterable: function(iterable, $function, $S, $T) {
      if (type$.EfficientLengthIterable_dynamic._is(iterable))
        return new H.EfficientLengthMappedIterable(iterable, $function, $S._eval$1("@<0>")._bind$1($T)._eval$1("EfficientLengthMappedIterable<1,2>"));
      return new H.MappedIterable(iterable, $function, $S._eval$1("@<0>")._bind$1($T)._eval$1("MappedIterable<1,2>"));
    },
    IterableElementError_noElement: function() {
      return new P.StateError("No element");
    },
    IterableElementError_tooMany: function() {
      return new P.StateError("Too many elements");
    },
    IterableElementError_tooFew: function() {
      return new P.StateError("Too few elements");
    },
    _CastIterableBase: function _CastIterableBase() {
    },
    CastIterator: function CastIterator(t0, t1) {
      this._source = t0;
      this.$ti = t1;
    },
    CastIterable: function CastIterable(t0, t1) {
      this._source = t0;
      this.$ti = t1;
    },
    _EfficientLengthCastIterable: function _EfficientLengthCastIterable(t0, t1) {
      this._source = t0;
      this.$ti = t1;
    },
    CastMap: function CastMap(t0, t1) {
      this._source = t0;
      this.$ti = t1;
    },
    CastMap_forEach_closure: function CastMap_forEach_closure(t0, t1) {
      this.$this = t0;
      this.f = t1;
    },
    CodeUnits: function CodeUnits(t0) {
      this._string = t0;
    },
    EfficientLengthIterable: function EfficientLengthIterable() {
    },
    ListIterable: function ListIterable() {
    },
    SubListIterable: function SubListIterable(t0, t1, t2, t3) {
      var _ = this;
      _.__internal$_iterable = t0;
      _.__internal$_start = t1;
      _._endOrLength = t2;
      _.$ti = t3;
    },
    ListIterator: function ListIterator(t0, t1, t2) {
      var _ = this;
      _.__internal$_iterable = t0;
      _.__internal$_length = t1;
      _.__internal$_index = 0;
      _.__internal$_current = null;
      _.$ti = t2;
    },
    MappedIterable: function MappedIterable(t0, t1, t2) {
      this.__internal$_iterable = t0;
      this._f = t1;
      this.$ti = t2;
    },
    EfficientLengthMappedIterable: function EfficientLengthMappedIterable(t0, t1, t2) {
      this.__internal$_iterable = t0;
      this._f = t1;
      this.$ti = t2;
    },
    MappedIterator: function MappedIterator(t0, t1, t2) {
      var _ = this;
      _.__internal$_current = null;
      _._iterator = t0;
      _._f = t1;
      _.$ti = t2;
    },
    MappedListIterable: function MappedListIterable(t0, t1, t2) {
      this._source = t0;
      this._f = t1;
      this.$ti = t2;
    },
    WhereIterable: function WhereIterable(t0, t1, t2) {
      this.__internal$_iterable = t0;
      this._f = t1;
      this.$ti = t2;
    },
    WhereIterator: function WhereIterator(t0, t1, t2) {
      this._iterator = t0;
      this._f = t1;
      this.$ti = t2;
    },
    ExpandIterable: function ExpandIterable(t0, t1, t2) {
      this.__internal$_iterable = t0;
      this._f = t1;
      this.$ti = t2;
    },
    ExpandIterator: function ExpandIterator(t0, t1, t2, t3) {
      var _ = this;
      _._iterator = t0;
      _._f = t1;
      _._currentExpansion = t2;
      _.__internal$_current = null;
      _.$ti = t3;
    },
    SkipWhileIterable: function SkipWhileIterable(t0, t1, t2) {
      this.__internal$_iterable = t0;
      this._f = t1;
      this.$ti = t2;
    },
    SkipWhileIterator: function SkipWhileIterator(t0, t1, t2) {
      var _ = this;
      _._iterator = t0;
      _._f = t1;
      _._hasSkipped = false;
      _.$ti = t2;
    },
    EmptyIterator: function EmptyIterator(t0) {
      this.$ti = t0;
    },
    FixedLengthListMixin: function FixedLengthListMixin() {
    },
    UnmodifiableListMixin: function UnmodifiableListMixin() {
    },
    UnmodifiableListBase: function UnmodifiableListBase() {
    },
    ReversedListIterable: function ReversedListIterable(t0, t1) {
      this._source = t0;
      this.$ti = t1;
    },
    Symbol: function Symbol(t0) {
      this.__internal$_name = t0;
    },
    ConstantMap__throwUnmodifiable: function() {
      throw H.wrapException(P.UnsupportedError$("Cannot modify unmodifiable Map"));
    },
    instantiate1: function(f, T1) {
      var t1 = new H.Instantiation1(f, T1._eval$1("Instantiation1<0>"));
      t1.Instantiation$1(f);
      return t1;
    },
    unminifyOrTag: function(rawClassName) {
      var preserved = H.unmangleGlobalNameIfPreservedAnyways(rawClassName);
      if (typeof preserved == "string")
        return preserved;
      return rawClassName;
    },
    isJsIndexable: function(object, record) {
      var result;
      if (record != null) {
        result = record.x;
        if (result != null)
          return result;
      }
      return type$.JavaScriptIndexingBehavior_dynamic._is(object);
    },
    S: function(value) {
      var res;
      if (typeof value == "string")
        return value;
      if (typeof value == "number") {
        if (value !== 0)
          return "" + value;
      } else if (true === value)
        return "true";
      else if (false === value)
        return "false";
      else if (value == null)
        return "null";
      res = J.toString$0$(value);
      if (typeof res != "string")
        throw H.wrapException(H.argumentErrorValue(value));
      return res;
    },
    Primitives_objectHashCode: function(object) {
      var hash = object.$identityHash;
      if (hash == null) {
        hash = Math.random() * 0x3fffffff | 0;
        object.$identityHash = hash;
      }
      return hash;
    },
    Primitives_parseInt: function(source, radix) {
      var match, decimalMatch, maxCharCode, digitsPart, t1, i, _null = null;
      if (typeof source != "string")
        H.throwExpression(H.argumentErrorValue(source));
      match = /^\s*[+-]?((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$/i.exec(source);
      if (match == null)
        return _null;
      if (3 >= match.length)
        return H.ioore(match, 3);
      decimalMatch = H._checkStringNullable(match[3]);
      if (radix == null) {
        if (decimalMatch != null)
          return parseInt(source, 10);
        if (match[2] != null)
          return parseInt(source, 16);
        return _null;
      }
      if (radix < 2 || radix > 36)
        throw H.wrapException(P.RangeError$range(radix, 2, 36, "radix", _null));
      if (radix === 10 && decimalMatch != null)
        return parseInt(source, 10);
      if (radix < 10 || decimalMatch == null) {
        maxCharCode = radix <= 10 ? 47 + radix : 86 + radix;
        H.assertHelper(typeof match[1] == "string");
        digitsPart = match[1];
        for (t1 = digitsPart.length, i = 0; i < t1; ++i)
          if ((C.JSString_methods._codeUnitAt$1(digitsPart, i) | 32) > maxCharCode)
            return _null;
      }
      return parseInt(source, radix);
    },
    Primitives_objectTypeName: function(object) {
      var t1 = H.Primitives__objectTypeNameNewRti(object);
      return t1;
    },
    Primitives__objectTypeNameNewRti: function(object) {
      var dispatchName, $constructor, constructorName;
      if (object instanceof P.Object)
        return H._rtiToString(H.instanceType(object), null);
      if (J.getInterceptor$(object) === C.Interceptor_methods || type$.UnknownJavaScriptObject._is(object)) {
        dispatchName = C.C_JS_CONST(object);
        if (H.Primitives__saneNativeClassName(dispatchName))
          return dispatchName;
        $constructor = object.constructor;
        if (typeof $constructor == "function") {
          constructorName = $constructor.name;
          if (typeof constructorName == "string" && H.Primitives__saneNativeClassName(constructorName))
            return constructorName;
        }
      }
      return H._rtiToString(H.instanceType(object), null);
    },
    Primitives__saneNativeClassName: function($name) {
      var t1 = $name !== "Object" && $name !== "";
      return t1;
    },
    Primitives_dateNow: function() {
      return Date.now();
    },
    Primitives_initTicker: function() {
      var $window, performance;
      if ($.Primitives_timerFrequency != null)
        return;
      $.Primitives_timerFrequency = 1000;
      $.Primitives_timerTicks = H._js_helper_Primitives_dateNow$closure();
      if (typeof window == "undefined")
        return;
      $window = window;
      if ($window == null)
        return;
      performance = $window.performance;
      if (performance == null)
        return;
      if (typeof performance.now != "function")
        return;
      $.Primitives_timerFrequency = 1000000;
      $.Primitives_timerTicks = new H.Primitives_initTicker_closure(performance);
    },
    Primitives_currentUri: function() {
      if (!!self.location)
        return self.location.href;
      return null;
    },
    Primitives__fromCharCodeApply: function(array) {
      var result, i, i0, chunkEnd,
        end = J.get$length$asx(array);
      if (end <= 500)
        return String.fromCharCode.apply(null, array);
      for (result = "", i = 0; i < end; i = i0) {
        i0 = i + 500;
        chunkEnd = i0 < end ? i0 : end;
        result += String.fromCharCode.apply(null, array.slice(i, chunkEnd));
      }
      return result;
    },
    Primitives_stringFromCodePoints: function(codePoints) {
      var t1, i,
        a = H.setRuntimeTypeInfo([], type$.JSArray_int);
      for (t1 = J.get$iterator$ax(type$.Iterable_dynamic._check(codePoints)); t1.moveNext$0();) {
        i = t1.get$current();
        if (!H._isInt(i))
          throw H.wrapException(H.argumentErrorValue(i));
        if (i <= 65535)
          C.JSArray_methods.add$1(a, i);
        else if (i <= 1114111) {
          C.JSArray_methods.add$1(a, 55296 + (C.JSInt_methods._shrOtherPositive$1(i - 65536, 10) & 1023));
          C.JSArray_methods.add$1(a, 56320 + (i & 1023));
        } else
          throw H.wrapException(H.argumentErrorValue(i));
      }
      return H.Primitives__fromCharCodeApply(a);
    },
    Primitives_stringFromCharCodes: function(charCodes) {
      var t1, i;
      for (type$.Iterable_dynamic._check(charCodes), t1 = J.get$iterator$ax(charCodes); t1.moveNext$0();) {
        i = t1.get$current();
        if (!H._isInt(i))
          throw H.wrapException(H.argumentErrorValue(i));
        if (i < 0)
          throw H.wrapException(H.argumentErrorValue(i));
        if (i > 65535)
          return H.Primitives_stringFromCodePoints(charCodes);
      }
      return H.Primitives__fromCharCodeApply(type$.List_dynamic._check(charCodes));
    },
    Primitives_stringFromNativeUint8List: function(charCodes, start, end) {
      var i, result, i0, chunkEnd;
      if (end <= 500 && start === 0 && end === charCodes.length)
        return String.fromCharCode.apply(null, charCodes);
      for (i = start, result = ""; i < end; i = i0) {
        i0 = i + 500;
        chunkEnd = i0 < end ? i0 : end;
        result += String.fromCharCode.apply(null, charCodes.subarray(i, chunkEnd));
      }
      return result;
    },
    Primitives_stringFromCharCode: function(charCode) {
      var bits;
      if (typeof charCode !== "number")
        return H.iae(charCode);
      if (0 <= charCode) {
        if (charCode <= 65535)
          return String.fromCharCode(charCode);
        if (charCode <= 1114111) {
          bits = charCode - 65536;
          return String.fromCharCode((55296 | C.JSInt_methods._shrOtherPositive$1(bits, 10)) >>> 0, 56320 | bits & 1023);
        }
      }
      throw H.wrapException(P.RangeError$range(charCode, 0, 1114111, null, null));
    },
    Primitives_lazyAsJsDate: function(receiver) {
      if (receiver.date === void 0)
        receiver.date = new Date(receiver._value);
      return receiver.date;
    },
    Primitives_getYear: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCFullYear() + 0;
      return t1;
    },
    Primitives_getMonth: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCMonth() + 1;
      return t1;
    },
    Primitives_getDay: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCDate() + 0;
      return t1;
    },
    Primitives_getHours: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCHours() + 0;
      return t1;
    },
    Primitives_getMinutes: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCMinutes() + 0;
      return t1;
    },
    Primitives_getSeconds: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCSeconds() + 0;
      return t1;
    },
    Primitives_getMilliseconds: function(receiver) {
      var t1 = H.Primitives_lazyAsJsDate(receiver).getUTCMilliseconds() + 0;
      return t1;
    },
    Primitives_getProperty: function(object, key) {
      if (object == null || H._isBool(object) || typeof object == "number" || typeof object == "string")
        throw H.wrapException(H.argumentErrorValue(object));
      return object[key];
    },
    Primitives_setProperty: function(object, key, value) {
      if (object == null || H._isBool(object) || typeof object == "number" || typeof object == "string")
        throw H.wrapException(H.argumentErrorValue(object));
      object[key] = value;
    },
    iae: function(argument) {
      throw H.wrapException(H.argumentErrorValue(argument));
    },
    ioore: function(receiver, index) {
      if (receiver == null)
        J.get$length$asx(receiver);
      throw H.wrapException(H.diagnoseIndexError(receiver, index));
    },
    diagnoseIndexError: function(indexable, index) {
      var $length, t1, _s5_ = "index";
      if (!H._isInt(index))
        return new P.ArgumentError(true, index, _s5_, null);
      $length = H._checkIntNullable(J.get$length$asx(indexable));
      if (!(index < 0)) {
        if (typeof $length !== "number")
          return H.iae($length);
        t1 = index >= $length;
      } else
        t1 = true;
      if (t1)
        return P.IndexError$(index, indexable, _s5_, null, $length);
      return P.RangeError$value(index, _s5_);
    },
    diagnoseRangeError: function(start, end, $length) {
      var _s13_ = "Invalid value";
      if (start < 0 || start > $length)
        return new P.RangeError(0, $length, true, start, "start", _s13_);
      if (end != null)
        if (end < start || end > $length)
          return new P.RangeError(start, $length, true, end, "end", _s13_);
      return new P.ArgumentError(true, end, "end", null);
    },
    argumentErrorValue: function(object) {
      return new P.ArgumentError(true, object, null, null);
    },
    checkNum: function(value) {
      if (typeof value != "number")
        throw H.wrapException(H.argumentErrorValue(value));
      return value;
    },
    wrapException: function(ex) {
      var wrapper;
      if (ex == null)
        ex = new P.NullThrownError();
      wrapper = new Error();
      wrapper.dartException = ex;
      if ("defineProperty" in Object) {
        Object.defineProperty(wrapper, "message", {get: H.toStringWrapper});
        wrapper.name = "";
      } else
        wrapper.toString = H.toStringWrapper;
      return wrapper;
    },
    toStringWrapper: function() {
      return J.toString$0$(this.dartException);
    },
    throwExpression: function(ex) {
      throw H.wrapException(ex);
    },
    throwConcurrentModificationError: function(collection) {
      throw H.wrapException(P.ConcurrentModificationError$(collection));
    },
    TypeErrorDecoder_extractPattern: function(message) {
      var match, $arguments, argumentsExpr, expr, method, receiver;
      message = H.quoteStringForRegExp(message.replace(String({}), '$receiver$'));
      match = message.match(/\\\$[a-zA-Z]+\\\$/g);
      if (match == null)
        match = H.setRuntimeTypeInfo([], type$.JSArray_String);
      $arguments = match.indexOf("\\$arguments\\$");
      argumentsExpr = match.indexOf("\\$argumentsExpr\\$");
      expr = match.indexOf("\\$expr\\$");
      method = match.indexOf("\\$method\\$");
      receiver = match.indexOf("\\$receiver\\$");
      return new H.TypeErrorDecoder(message.replace(new RegExp('\\\\\\$arguments\\\\\\$', 'g'), '((?:x|[^x])*)').replace(new RegExp('\\\\\\$argumentsExpr\\\\\\$', 'g'), '((?:x|[^x])*)').replace(new RegExp('\\\\\\$expr\\\\\\$', 'g'), '((?:x|[^x])*)').replace(new RegExp('\\\\\\$method\\\\\\$', 'g'), '((?:x|[^x])*)').replace(new RegExp('\\\\\\$receiver\\\\\\$', 'g'), '((?:x|[^x])*)'), $arguments, argumentsExpr, expr, method, receiver);
    },
    TypeErrorDecoder_provokeCallErrorOn: function(expression) {
      return function($expr$) {
        var $argumentsExpr$ = '$arguments$';
        try {
          $expr$.$method$($argumentsExpr$);
        } catch (e) {
          return e.message;
        }
      }(expression);
    },
    TypeErrorDecoder_provokePropertyErrorOn: function(expression) {
      return function($expr$) {
        try {
          $expr$.$method$;
        } catch (e) {
          return e.message;
        }
      }(expression);
    },
    NullError$: function(_message, match) {
      return new H.NullError(_message, match == null ? null : match.method);
    },
    JsNoSuchMethodError$: function(_message, match) {
      var t1 = match == null,
        t2 = t1 ? null : match.method;
      return new H.JsNoSuchMethodError(_message, t2, t1 ? null : match.receiver);
    },
    unwrapException: function(ex) {
      var message, number, ieErrorCode, nsme, notClosure, nullCall, nullLiteralCall, undefCall, undefLiteralCall, nullProperty, undefProperty, undefLiteralProperty, match, t2, _null = null,
        t1 = new H.unwrapException_saveStackTrace(ex);
      if (ex == null)
        return _null;
      if (ex instanceof H.ExceptionAndStackTrace)
        return t1.call$1(ex.dartException);
      if (typeof ex !== "object")
        return ex;
      if ("dartException" in ex)
        return t1.call$1(ex.dartException);
      else if (!("message" in ex))
        return ex;
      message = ex.message;
      if ("number" in ex && typeof ex.number == "number") {
        number = ex.number;
        ieErrorCode = number & 65535;
        if ((C.JSInt_methods._shrOtherPositive$1(number, 16) & 8191) === 10)
          switch (ieErrorCode) {
            case 438:
              return t1.call$1(H.JsNoSuchMethodError$(H.S(message) + " (Error " + ieErrorCode + ")", _null));
            case 445:
            case 5007:
              return t1.call$1(H.NullError$(H.S(message) + " (Error " + ieErrorCode + ")", _null));
          }
      }
      if (ex instanceof TypeError) {
        nsme = $.$get$TypeErrorDecoder_noSuchMethodPattern();
        notClosure = $.$get$TypeErrorDecoder_notClosurePattern();
        nullCall = $.$get$TypeErrorDecoder_nullCallPattern();
        nullLiteralCall = $.$get$TypeErrorDecoder_nullLiteralCallPattern();
        undefCall = $.$get$TypeErrorDecoder_undefinedCallPattern();
        undefLiteralCall = $.$get$TypeErrorDecoder_undefinedLiteralCallPattern();
        nullProperty = $.$get$TypeErrorDecoder_nullPropertyPattern();
        $.$get$TypeErrorDecoder_nullLiteralPropertyPattern();
        undefProperty = $.$get$TypeErrorDecoder_undefinedPropertyPattern();
        undefLiteralProperty = $.$get$TypeErrorDecoder_undefinedLiteralPropertyPattern();
        match = nsme.matchTypeError$1(message);
        if (match != null)
          return t1.call$1(H.JsNoSuchMethodError$(H._checkStringNullable(message), match));
        else {
          match = notClosure.matchTypeError$1(message);
          if (match != null) {
            match.method = "call";
            return t1.call$1(H.JsNoSuchMethodError$(H._checkStringNullable(message), match));
          } else {
            match = nullCall.matchTypeError$1(message);
            if (match == null) {
              match = nullLiteralCall.matchTypeError$1(message);
              if (match == null) {
                match = undefCall.matchTypeError$1(message);
                if (match == null) {
                  match = undefLiteralCall.matchTypeError$1(message);
                  if (match == null) {
                    match = nullProperty.matchTypeError$1(message);
                    if (match == null) {
                      match = nullLiteralCall.matchTypeError$1(message);
                      if (match == null) {
                        match = undefProperty.matchTypeError$1(message);
                        if (match == null) {
                          match = undefLiteralProperty.matchTypeError$1(message);
                          t2 = match != null;
                        } else
                          t2 = true;
                      } else
                        t2 = true;
                    } else
                      t2 = true;
                  } else
                    t2 = true;
                } else
                  t2 = true;
              } else
                t2 = true;
            } else
              t2 = true;
            if (t2)
              return t1.call$1(H.NullError$(H._checkStringNullable(message), match));
          }
        }
        return t1.call$1(new H.UnknownJsTypeError(typeof message == "string" ? message : ""));
      }
      if (ex instanceof RangeError) {
        if (typeof message == "string" && message.indexOf("call stack") !== -1)
          return new P.StackOverflowError();
        message = function(ex) {
          try {
            return String(ex);
          } catch (e) {
          }
          return null;
        }(ex);
        return t1.call$1(new P.ArgumentError(false, _null, _null, typeof message == "string" ? message.replace(/^RangeError:\s*/, "") : message));
      }
      if (typeof InternalError == "function" && ex instanceof InternalError)
        if (typeof message == "string" && message === "too much recursion")
          return new P.StackOverflowError();
      return ex;
    },
    getTraceFromException: function(exception) {
      var trace;
      if (exception instanceof H.ExceptionAndStackTrace)
        return exception.stackTrace;
      if (exception == null)
        return new H._StackTrace(exception);
      trace = exception.$cachedTrace;
      if (trace != null)
        return trace;
      return exception.$cachedTrace = new H._StackTrace(exception);
    },
    objectHashCode: function(object) {
      if (object == null || typeof object != 'object')
        return J.get$hashCode$(object);
      else
        return H.Primitives_objectHashCode(object);
    },
    fillLiteralMap: function(keyValuePairs, result) {
      var $length, index, index0, key,
        t1 = Array.isArray(keyValuePairs);
      H.assertHelper(t1);
      $length = keyValuePairs.length;
      for (index = 0; index < $length;) {
        index0 = index + 1;
        H.assertHelper(t1);
        key = keyValuePairs[index];
        index = index0 + 1;
        H.assertHelper(t1);
        result.$indexSet(0, key, keyValuePairs[index0]);
      }
      return result;
    },
    fillLiteralSet: function(values, result) {
      var $length, index,
        t1 = Array.isArray(values);
      H.assertHelper(t1);
      $length = values.length;
      for (index = 0; index < $length; ++index) {
        H.assertHelper(t1);
        result.add$1(0, values[index]);
      }
      return result;
    },
    invokeClosure: function(closure, numberOfArguments, arg1, arg2, arg3, arg4) {
      type$.Function._check(closure);
      switch (H._checkIntNullable(numberOfArguments)) {
        case 0:
          return closure.call$0();
        case 1:
          return closure.call$1(arg1);
        case 2:
          return closure.call$2(arg1, arg2);
        case 3:
          return closure.call$3(arg1, arg2, arg3);
        case 4:
          return closure.call$4(arg1, arg2, arg3, arg4);
      }
      throw H.wrapException(new P._Exception("Unsupported number of arguments for wrapped closure"));
    },
    convertDartClosureToJS: function(closure, arity) {
      var $function;
      if (closure == null)
        return null;
      $function = closure.$identity;
      if (!!$function)
        return $function;
      $function = function(closure, arity, invoke) {
        return function(a1, a2, a3, a4) {
          return invoke(closure, arity, a1, a2, a3, a4);
        };
      }(closure, arity, H.invokeClosure);
      closure.$identity = $function;
      return $function;
    },
    Closure_fromTearOff: function(receiver, functions, applyTrampolineIndex, reflectionInfo, isStatic, isIntercepted, propertyName) {
      var $constructor, t1, trampoline, signatureFunction, applyTrampoline, i, stub, stubCallName, _null = null,
        $function = functions[0],
        callName = $function.$callName,
        $prototype = isStatic ? Object.create(new H.StaticClosure().constructor.prototype) : Object.create(new H.BoundClosure(_null, _null, _null, _null).constructor.prototype);
      $prototype.$initialize = $prototype.constructor;
      if (isStatic)
        $constructor = function static_tear_off() {
          this.$initialize();
        };
      else {
        t1 = $.Closure_functionCounter;
        if (typeof t1 !== "number")
          return t1.$add();
        $.Closure_functionCounter = t1 + 1;
        t1 = new Function("a,b,c,d" + t1, "this.$initialize(a,b,c,d" + t1 + ")");
        $constructor = t1;
      }
      $prototype.constructor = $constructor;
      $constructor.prototype = $prototype;
      if (!isStatic) {
        trampoline = H.Closure_forwardCallTo(receiver, $function, isIntercepted);
        trampoline.$reflectionInfo = reflectionInfo;
      } else {
        $prototype.$static_name = propertyName;
        trampoline = $function;
      }
      signatureFunction = H.Closure__computeSignatureFunctionNewRti(reflectionInfo, isStatic, isIntercepted);
      $prototype.$signature = signatureFunction;
      $prototype[callName] = trampoline;
      for (applyTrampoline = trampoline, i = 1; i < functions.length; ++i) {
        stub = functions[i];
        stubCallName = stub.$callName;
        if (stubCallName != null) {
          stub = isStatic ? stub : H.Closure_forwardCallTo(receiver, stub, isIntercepted);
          $prototype[stubCallName] = stub;
        }
        if (i === applyTrampolineIndex) {
          stub.$reflectionInfo = reflectionInfo;
          applyTrampoline = stub;
        }
      }
      $prototype["call*"] = applyTrampoline;
      $prototype.$requiredArgCount = $function.$requiredArgCount;
      $prototype.$defaultValues = $function.$defaultValues;
      return $constructor;
    },
    Closure__computeSignatureFunctionNewRti: function(functionType, isStatic, isIntercepted) {
      var typeEvalMethod;
      if (typeof functionType == "number")
        return function(getType, t) {
          return function() {
            return getType(t);
          };
        }(H.getTypeFromTypesTable, functionType);
      if (typeof functionType == "string") {
        if (isStatic)
          throw H.wrapException("Cannot compute signature for static tearoff.");
        typeEvalMethod = isIntercepted ? H.BoundClosure_evalRecipeIntercepted : H.BoundClosure_evalRecipe;
        return function(recipe, evalOnReceiver) {
          return function() {
            return evalOnReceiver(this, recipe);
          };
        }(functionType, typeEvalMethod);
      }
      throw H.wrapException("Error in functionType of tearoff");
    },
    Closure_cspForwardCall: function(arity, isSuperCall, stubName, $function) {
      var getSelf = H.BoundClosure_selfOf;
      switch (isSuperCall ? -1 : arity) {
        case 0:
          return function(n, S) {
            return function() {
              return S(this)[n]();
            };
          }(stubName, getSelf);
        case 1:
          return function(n, S) {
            return function(a) {
              return S(this)[n](a);
            };
          }(stubName, getSelf);
        case 2:
          return function(n, S) {
            return function(a, b) {
              return S(this)[n](a, b);
            };
          }(stubName, getSelf);
        case 3:
          return function(n, S) {
            return function(a, b, c) {
              return S(this)[n](a, b, c);
            };
          }(stubName, getSelf);
        case 4:
          return function(n, S) {
            return function(a, b, c, d) {
              return S(this)[n](a, b, c, d);
            };
          }(stubName, getSelf);
        case 5:
          return function(n, S) {
            return function(a, b, c, d, e) {
              return S(this)[n](a, b, c, d, e);
            };
          }(stubName, getSelf);
        default:
          return function(f, s) {
            return function() {
              return f.apply(s(this), arguments);
            };
          }($function, getSelf);
      }
    },
    Closure_forwardCallTo: function(receiver, $function, isIntercepted) {
      var stubName, arity, lookedUpFunction, t1, t2, selfName, $arguments;
      if (isIntercepted)
        return H.Closure_forwardInterceptedCallTo(receiver, $function);
      stubName = $function.$stubName;
      arity = $function.length;
      lookedUpFunction = receiver[stubName];
      t1 = $function == null ? lookedUpFunction == null : $function === lookedUpFunction;
      t2 = !t1 || arity >= 27;
      if (t2)
        return H.Closure_cspForwardCall(arity, !t1, stubName, $function);
      if (arity === 0) {
        t1 = $.Closure_functionCounter;
        if (typeof t1 !== "number")
          return t1.$add();
        $.Closure_functionCounter = t1 + 1;
        selfName = "self" + t1;
        t1 = "return function(){var " + selfName + " = this.";
        t2 = $.BoundClosure_selfFieldNameCache;
        return new Function(t1 + H.S(t2 == null ? $.BoundClosure_selfFieldNameCache = H.BoundClosure_computeFieldNamed("self") : t2) + ";return " + selfName + "." + H.S(stubName) + "();}")();
      }
      H.assertHelper(1 <= arity && arity < 27);
      $arguments = "abcdefghijklmnopqrstuvwxyz".split("").splice(0, arity).join(",");
      t1 = $.Closure_functionCounter;
      if (typeof t1 !== "number")
        return t1.$add();
      $.Closure_functionCounter = t1 + 1;
      $arguments += t1;
      t1 = "return function(" + $arguments + "){return this.";
      t2 = $.BoundClosure_selfFieldNameCache;
      return new Function(t1 + H.S(t2 == null ? $.BoundClosure_selfFieldNameCache = H.BoundClosure_computeFieldNamed("self") : t2) + "." + H.S(stubName) + "(" + $arguments + ");}")();
    },
    Closure_cspForwardInterceptedCall: function(arity, isSuperCall, $name, $function) {
      var getSelf = H.BoundClosure_selfOf,
        getReceiver = H.BoundClosure_receiverOf;
      switch (isSuperCall ? -1 : arity) {
        case 0:
          throw H.wrapException(H.RuntimeError$("Intercepted function with no arguments."));
        case 1:
          return function(n, s, r) {
            return function() {
              return s(this)[n](r(this));
            };
          }($name, getSelf, getReceiver);
        case 2:
          return function(n, s, r) {
            return function(a) {
              return s(this)[n](r(this), a);
            };
          }($name, getSelf, getReceiver);
        case 3:
          return function(n, s, r) {
            return function(a, b) {
              return s(this)[n](r(this), a, b);
            };
          }($name, getSelf, getReceiver);
        case 4:
          return function(n, s, r) {
            return function(a, b, c) {
              return s(this)[n](r(this), a, b, c);
            };
          }($name, getSelf, getReceiver);
        case 5:
          return function(n, s, r) {
            return function(a, b, c, d) {
              return s(this)[n](r(this), a, b, c, d);
            };
          }($name, getSelf, getReceiver);
        case 6:
          return function(n, s, r) {
            return function(a, b, c, d, e) {
              return s(this)[n](r(this), a, b, c, d, e);
            };
          }($name, getSelf, getReceiver);
        default:
          return function(f, s, r, a) {
            return function() {
              a = [r(this)];
              Array.prototype.push.apply(a, arguments);
              return f.apply(s(this), a);
            };
          }($function, getSelf, getReceiver);
      }
    },
    Closure_forwardInterceptedCallTo: function(receiver, $function) {
      var t2, stubName, arity, lookedUpFunction, t3, t4, $arguments,
        t1 = $.BoundClosure_selfFieldNameCache;
      if (t1 == null)
        t1 = $.BoundClosure_selfFieldNameCache = H.BoundClosure_computeFieldNamed("self");
      t2 = $.BoundClosure_receiverFieldNameCache;
      if (t2 == null)
        t2 = $.BoundClosure_receiverFieldNameCache = H.BoundClosure_computeFieldNamed("receiver");
      stubName = $function.$stubName;
      arity = $function.length;
      lookedUpFunction = receiver[stubName];
      t3 = $function == null ? lookedUpFunction == null : $function === lookedUpFunction;
      t4 = !t3 || arity >= 28;
      if (t4)
        return H.Closure_cspForwardInterceptedCall(arity, !t3, stubName, $function);
      if (arity === 1) {
        t1 = "return function(){return this." + H.S(t1) + "." + H.S(stubName) + "(this." + H.S(t2) + ");";
        t2 = $.Closure_functionCounter;
        if (typeof t2 !== "number")
          return t2.$add();
        $.Closure_functionCounter = t2 + 1;
        return new Function(t1 + t2 + "}")();
      }
      H.assertHelper(1 < arity && arity < 28);
      $arguments = "abcdefghijklmnopqrstuvwxyz".split("").splice(0, arity - 1).join(",");
      t1 = "return function(" + $arguments + "){return this." + H.S(t1) + "." + H.S(stubName) + "(this." + H.S(t2) + ", " + $arguments + ");";
      t2 = $.Closure_functionCounter;
      if (typeof t2 !== "number")
        return t2.$add();
      $.Closure_functionCounter = t2 + 1;
      return new Function(t1 + t2 + "}")();
    },
    closureFromTearOff: function(receiver, functions, applyTrampolineIndex, reflectionInfo, isStatic, isIntercepted, $name) {
      return H.Closure_fromTearOff(receiver, functions, applyTrampolineIndex, reflectionInfo, !!isStatic, !!isIntercepted, $name);
    },
    BoundClosure_evalRecipe: function(closure, recipe) {
      return H._Universe_evalInEnvironment(init.typeUniverse, H.instanceType(closure._self), recipe);
    },
    BoundClosure_evalRecipeIntercepted: function(closure, recipe) {
      return H._Universe_evalInEnvironment(init.typeUniverse, H.instanceType(closure._receiver), recipe);
    },
    BoundClosure_selfOf: function(closure) {
      return closure._self;
    },
    BoundClosure_receiverOf: function(closure) {
      return closure._receiver;
    },
    BoundClosure_computeFieldNamed: function(fieldName) {
      var t1, i, $name,
        template = new H.BoundClosure("self", "target", "receiver", "name"),
        names = J.JSArray_markFixedList(Object.getOwnPropertyNames(template));
      for (t1 = names.length, i = 0; i < t1; ++i) {
        $name = names[i];
        if (template[$name] === fieldName)
          return $name;
      }
    },
    boolConversionCheck: function(value) {
      if (value == null)
        H.assertThrow("boolean expression must not be null");
      return value;
    },
    extractFunctionTypeObjectFromInternal: function(o) {
      var signature;
      if ("$signature" in o) {
        signature = o.$signature;
        if (typeof signature == "number")
          return init.types[H._checkIntNullable(signature)];
        else
          return o.$signature();
      }
      return null;
    },
    TypeErrorImplementation$: function(value, type) {
      return new H.TypeErrorImplementation("TypeError: " + P.Error_safeToString(value) + ": type '" + H.S(H._typeDescription(value)) + "' is not a subtype of type '" + type + "'");
    },
    _typeDescription: function(value) {
      var functionTypeObject;
      if (value instanceof H.Closure) {
        functionTypeObject = H.extractFunctionTypeObjectFromInternal(J.getInterceptor$(value));
        if (functionTypeObject != null)
          return H.runtimeTypeToString(functionTypeObject);
        return "Closure";
      }
      return H.Primitives_objectTypeName(value);
    },
    assertTest: function(condition) {
      if (true === condition)
        return false;
      if (H._isBool(condition))
        return !condition;
      throw H.wrapException(H.TypeErrorImplementation$(condition, "bool"));
    },
    assertThrow: function(message) {
      throw H.wrapException(new H._AssertionError(message));
    },
    assertHelper: function(condition) {
      if (H.assertTest(condition))
        throw H.wrapException(P.AssertionError$(null));
    },
    throwCyclicInit: function(staticName) {
      throw H.wrapException(new P.CyclicInitializationError(staticName));
    },
    RuntimeError$: function(message) {
      return new H.RuntimeError(message);
    },
    getIsolateAffinityTag: function($name) {
      return init.getIsolateTag($name);
    },
    setRuntimeTypeInfo: function(target, rti) {
      H.assertHelper(rti != null);
      target.$ti = rti;
      return target;
    },
    getRuntimeTypeInfo: function(target) {
      if (target == null)
        return null;
      return target.$ti;
    },
    getRuntimeTypeArguments: function(interceptor, object, substitutionName) {
      return H.substitute(interceptor["$as" + H.S(substitutionName)], H.getRuntimeTypeInfo(object));
    },
    runtimeTypeToString: function(rti) {
      return H._runtimeTypeToString(rti, null);
    },
    _runtimeTypeToString: function(rti, genericContext) {
      var t1, t2;
      if (rti == null)
        return "dynamic";
      if (rti === -1)
        return "void";
      if (Array.isArray(rti))
        return H.unminifyOrTag(rti[0].name) + H._joinArguments(rti, 1, genericContext);
      if (typeof rti == "function")
        return H.unminifyOrTag(rti.name);
      if (rti === -2)
        return "dynamic";
      H.assertHelper(!(rti === -1));
      if (typeof rti == "number") {
        H._checkIntNullable(rti);
        if (genericContext == null || rti < 0 || rti >= genericContext.length)
          return "unexpected-generic-index:" + rti;
        t1 = genericContext.length;
        t2 = t1 - rti - 1;
        if (t2 < 0 || t2 >= t1)
          return H.ioore(genericContext, t2);
        return H.S(genericContext[t2]);
      }
      t1 = rti != null;
      if (t1)
        t2 = typeof rti == "string";
      else
        t2 = true;
      H.assertHelper(!t2);
      if ('func' in rti)
        return H._functionRtiToString0(rti, genericContext);
      if (t1)
        t2 = typeof rti == "string";
      else
        t2 = true;
      H.assertHelper(!t2);
      if ('futureOr' in rti) {
        if (t1)
          t1 = typeof rti == "string";
        else
          t1 = true;
        H.assertHelper(!t1);
        H.assertHelper('futureOr' in rti);
        return "FutureOr<" + H._runtimeTypeToString("type" in rti ? rti.type : null, genericContext) + ">";
      }
      return "unknown-reified-type";
    },
    _functionRtiToString0: function(rti, genericContext) {
      var boundsRti, outerContextLength, offset, i, i0, typeParameters, typeSep, t1, t2, boundRti, returnTypeText, $arguments, argumentsText, sep, _i, argument, optionalArguments, namedArguments, $name, _s2_ = ", ";
      if ("bounds" in rti) {
        boundsRti = rti.bounds;
        if (genericContext == null) {
          genericContext = H.setRuntimeTypeInfo([], type$.JSArray_String);
          outerContextLength = null;
        } else
          outerContextLength = genericContext.length;
        offset = genericContext.length;
        for (i = boundsRti.length, i0 = i; i0 > 0; --i0)
          C.JSArray_methods.add$1(genericContext, "T" + (offset + i0));
        for (typeParameters = "<", typeSep = "", i0 = 0; i0 < i; ++i0, typeSep = _s2_) {
          typeParameters += typeSep;
          t1 = genericContext.length;
          t2 = t1 - i0 - 1;
          if (t2 < 0)
            return H.ioore(genericContext, t2);
          typeParameters = C.JSString_methods.$add(typeParameters, genericContext[t2]);
          boundRti = boundsRti[i0];
          if (boundRti != null && boundRti !== P.Object)
            typeParameters += " extends " + H._runtimeTypeToString(boundRti, genericContext);
        }
        typeParameters += ">";
      } else {
        typeParameters = "";
        outerContextLength = null;
      }
      returnTypeText = !!rti.v ? "void" : H._runtimeTypeToString(rti.ret, genericContext);
      if ("args" in rti) {
        $arguments = rti.args;
        for (t1 = $arguments.length, argumentsText = "", sep = "", _i = 0; _i < t1; ++_i, sep = _s2_) {
          argument = $arguments[_i];
          argumentsText = argumentsText + sep + H._runtimeTypeToString(argument, genericContext);
        }
      } else {
        argumentsText = "";
        sep = "";
      }
      if ("opt" in rti) {
        optionalArguments = rti.opt;
        argumentsText += sep + "[";
        for (t1 = optionalArguments.length, sep = "", _i = 0; _i < t1; ++_i, sep = _s2_) {
          argument = optionalArguments[_i];
          argumentsText = argumentsText + sep + H._runtimeTypeToString(argument, genericContext);
        }
        argumentsText += "]";
      }
      if ("named" in rti) {
        namedArguments = rti.named;
        argumentsText += sep + "{";
        for (t1 = H.extractKeys(namedArguments), t2 = t1.length, sep = "", _i = 0; _i < t2; ++_i, sep = _s2_) {
          $name = H._checkStringNullable(t1[_i]);
          argumentsText = argumentsText + sep + H._runtimeTypeToString(namedArguments[$name], genericContext) + (" " + H.S($name));
        }
        argumentsText += "}";
      }
      if (outerContextLength != null)
        genericContext.length = outerContextLength;
      return typeParameters + "(" + argumentsText + ") => " + returnTypeText;
    },
    _joinArguments: function(types, startIndex, genericContext) {
      var t1, buffer, index, separator, allDynamic, argument;
      if (types == null)
        return "";
      t1 = Array.isArray(types);
      H.assertHelper(t1);
      buffer = new P.StringBuffer("");
      for (index = startIndex, separator = "", allDynamic = true; H.assertHelper(t1), index < types.length; ++index, separator = ", ") {
        buffer._contents += separator;
        H.assertHelper(t1);
        argument = types[index];
        if (argument != null)
          allDynamic = false;
        buffer._contents += H._runtimeTypeToString(argument, genericContext);
      }
      return "<" + buffer.toString$0(0) + ">";
    },
    getRuntimeType: function(object) {
      var rti = object instanceof H.Closure ? H.closureFunctionType(object) : null;
      return H.createRuntimeType(rti == null ? H.instanceType(object) : rti);
    },
    substitute: function(substitution, $arguments) {
      if (substitution == null)
        return $arguments;
      H.assertHelper(typeof substitution == "function");
      H.assertHelper($arguments == null || Array.isArray($arguments));
      substitution = H.invokeOn(substitution, null, $arguments);
      if (substitution == null)
        return null;
      if (Array.isArray(substitution))
        return substitution;
      if (typeof substitution == "function")
        return H.invokeOn(substitution, null, $arguments);
      return $arguments;
    },
    computeSignature: function(signature, context, contextName) {
      return H.invokeOn(signature, context, H.substitute(J.getInterceptor$(context)["$as" + H.S(contextName)], H.getRuntimeTypeInfo(context)));
    },
    invokeOn: function($function, receiver, $arguments) {
      H.assertHelper(typeof $function == "function");
      H.assertHelper($arguments == null || Array.isArray($arguments));
      return $function.apply(receiver, $arguments);
    },
    defineProperty: function(obj, property, value) {
      Object.defineProperty(obj, property, {value: value, enumerable: false, writable: true, configurable: true});
    },
    lookupAndCacheInterceptor: function(obj) {
      var tag, record, interceptor, interceptorClass, mark, t1;
      H.assertHelper(!(obj instanceof P.Object));
      tag = H._checkStringNullable($.getTagFunction.call$1(obj));
      record = $.dispatchRecordsForInstanceTags[tag];
      if (record != null) {
        Object.defineProperty(obj, init.dispatchPropertyName, {value: record, enumerable: false, writable: true, configurable: true});
        return record.i;
      }
      interceptor = $.interceptorsForUncacheableTags[tag];
      if (interceptor != null)
        return interceptor;
      interceptorClass = init.interceptorsByTag[tag];
      if (interceptorClass == null) {
        tag = H._checkStringNullable($.alternateTagFunction.call$2(obj, tag));
        if (tag != null) {
          record = $.dispatchRecordsForInstanceTags[tag];
          if (record != null) {
            Object.defineProperty(obj, init.dispatchPropertyName, {value: record, enumerable: false, writable: true, configurable: true});
            return record.i;
          }
          interceptor = $.interceptorsForUncacheableTags[tag];
          if (interceptor != null)
            return interceptor;
          interceptorClass = init.interceptorsByTag[tag];
        }
      }
      if (interceptorClass == null)
        return null;
      interceptor = interceptorClass.prototype;
      mark = tag[0];
      if (mark === "!") {
        record = H.makeLeafDispatchRecord(interceptor);
        $.dispatchRecordsForInstanceTags[tag] = record;
        Object.defineProperty(obj, init.dispatchPropertyName, {value: record, enumerable: false, writable: true, configurable: true});
        return record.i;
      }
      if (mark === "~") {
        $.interceptorsForUncacheableTags[tag] = interceptor;
        return interceptor;
      }
      if (mark === "-") {
        t1 = H.makeLeafDispatchRecord(interceptor);
        Object.defineProperty(Object.getPrototypeOf(obj), init.dispatchPropertyName, {value: t1, enumerable: false, writable: true, configurable: true});
        return t1.i;
      }
      if (mark === "+")
        return H.patchInteriorProto(obj, interceptor);
      if (mark === "*")
        throw H.wrapException(P.UnimplementedError$(tag));
      if (init.leafTags[tag] === true) {
        t1 = H.makeLeafDispatchRecord(interceptor);
        Object.defineProperty(Object.getPrototypeOf(obj), init.dispatchPropertyName, {value: t1, enumerable: false, writable: true, configurable: true});
        return t1.i;
      } else
        return H.patchInteriorProto(obj, interceptor);
    },
    patchInteriorProto: function(obj, interceptor) {
      var proto = Object.getPrototypeOf(obj);
      Object.defineProperty(proto, init.dispatchPropertyName, {value: J.makeDispatchRecord(interceptor, proto, null, null), enumerable: false, writable: true, configurable: true});
      return interceptor;
    },
    makeLeafDispatchRecord: function(interceptor) {
      return J.makeDispatchRecord(interceptor, false, null, !!interceptor.$isJavaScriptIndexingBehavior);
    },
    makeDefaultDispatchRecord: function(tag, interceptorClass, proto) {
      var interceptor = interceptorClass.prototype;
      if (init.leafTags[tag] === true)
        return H.makeLeafDispatchRecord(interceptor);
      else
        return J.makeDispatchRecord(interceptor, proto, null, null);
    },
    initNativeDispatch: function() {
      if (true === $.initNativeDispatchFlag)
        return;
      $.initNativeDispatchFlag = true;
      H.initNativeDispatchContinue();
    },
    initNativeDispatchContinue: function() {
      var map, tags, fun, i, tag, proto, record, interceptorClass;
      $.dispatchRecordsForInstanceTags = Object.create(null);
      $.interceptorsForUncacheableTags = Object.create(null);
      H.initHooks();
      map = init.interceptorsByTag;
      tags = Object.getOwnPropertyNames(map);
      if (typeof window != "undefined") {
        window;
        fun = function() {
        };
        for (i = 0; i < tags.length; ++i) {
          tag = tags[i];
          proto = $.prototypeForTagFunction.call$1(tag);
          if (proto != null) {
            record = H.makeDefaultDispatchRecord(tag, map[tag], proto);
            if (record != null) {
              Object.defineProperty(proto, init.dispatchPropertyName, {value: record, enumerable: false, writable: true, configurable: true});
              fun.prototype = proto;
            }
          }
        }
      }
      for (i = 0; i < tags.length; ++i) {
        tag = tags[i];
        if (/^[A-Za-z_]/.test(tag)) {
          interceptorClass = map[tag];
          map["!" + tag] = interceptorClass;
          map["~" + tag] = interceptorClass;
          map["-" + tag] = interceptorClass;
          map["+" + tag] = interceptorClass;
          map["*" + tag] = interceptorClass;
        }
      }
    },
    initHooks: function() {
      var transformers, i, transformer, getTag, getUnknownTag, prototypeForTag,
        hooks = C.C_JS_CONST0();
      hooks = H.applyHooksTransformer(C.C_JS_CONST1, H.applyHooksTransformer(C.C_JS_CONST2, H.applyHooksTransformer(C.C_JS_CONST3, H.applyHooksTransformer(C.C_JS_CONST3, H.applyHooksTransformer(C.C_JS_CONST4, H.applyHooksTransformer(C.C_JS_CONST5, H.applyHooksTransformer(C.C_JS_CONST6(C.C_JS_CONST), hooks)))))));
      if (typeof dartNativeDispatchHooksTransformer != "undefined") {
        transformers = dartNativeDispatchHooksTransformer;
        if (typeof transformers == "function")
          transformers = [transformers];
        if (transformers.constructor == Array)
          for (i = 0; i < transformers.length; ++i) {
            transformer = transformers[i];
            if (typeof transformer == "function")
              hooks = transformer(hooks) || hooks;
          }
      }
      getTag = hooks.getTag;
      getUnknownTag = hooks.getUnknownTag;
      prototypeForTag = hooks.prototypeForTag;
      $.getTagFunction = new H.initHooks_closure(getTag);
      $.alternateTagFunction = new H.initHooks_closure0(getUnknownTag);
      $.prototypeForTagFunction = new H.initHooks_closure1(prototypeForTag);
    },
    applyHooksTransformer: function(transformer, hooks) {
      return transformer(hooks) || hooks;
    },
    JSSyntaxRegExp_makeNative: function(source, multiLine, caseSensitive, unicode, dotAll, global) {
      var m = multiLine ? "m" : "",
        i = caseSensitive ? "" : "i",
        u = unicode ? "u" : "",
        s = dotAll ? "s" : "",
        g = global ? "g" : "",
        regexp = function(source, modifiers) {
          try {
            return new RegExp(source, modifiers);
          } catch (e) {
            return e;
          }
        }(source, m + i + u + s + g);
      if (regexp instanceof RegExp)
        return regexp;
      throw H.wrapException(P.FormatException$("Illegal RegExp pattern (" + String(regexp) + ")", source, null));
    },
    _MatchImplementation$: function(pattern, _match) {
      H.assertHelper(typeof _match.input == "string");
      H.assertHelper(H._isInt(_match.index));
      return new H._MatchImplementation(_match);
    },
    stringContainsUnchecked: function(receiver, other, startIndex) {
      var t1, t2;
      if (typeof other == "string")
        return receiver.indexOf(other, startIndex) >= 0;
      else if (other instanceof H.JSSyntaxRegExp) {
        t1 = C.JSString_methods.substring$1(receiver, startIndex);
        t2 = other._nativeRegExp;
        return t2.test(t1);
      } else {
        t1 = J.allMatches$1$s(other, C.JSString_methods.substring$1(receiver, startIndex));
        return !t1.get$isEmpty(t1);
      }
    },
    escapeReplacement: function(replacement) {
      if (replacement.indexOf("$", 0) >= 0)
        return replacement.replace(/\$/g, "$$$$");
      return replacement;
    },
    stringReplaceFirstRE: function(receiver, regexp, replacement, startIndex) {
      var match = regexp._execGlobal$2(receiver, startIndex);
      if (match == null)
        return receiver;
      return H.stringReplaceRangeUnchecked(receiver, match._match.index, match.get$end(), replacement);
    },
    quoteStringForRegExp: function(string) {
      if (/[[\]{}()*+?.\\^$|]/.test(string))
        return string.replace(/[[\]{}()*+?.\\^$|]/g, "\\$&");
      return string;
    },
    stringReplaceAllUnchecked: function(receiver, pattern, replacement) {
      var nativeRegexp;
      if (typeof pattern == "string")
        return H.stringReplaceAllUncheckedString(receiver, pattern, replacement);
      if (pattern instanceof H.JSSyntaxRegExp) {
        nativeRegexp = pattern.get$_nativeGlobalVersion();
        nativeRegexp.lastIndex = 0;
        return receiver.replace(nativeRegexp, H.escapeReplacement(replacement));
      }
      if (pattern == null)
        H.throwExpression(H.argumentErrorValue(pattern));
      throw H.wrapException("String.replaceAll(Pattern) UNIMPLEMENTED");
    },
    stringReplaceAllUncheckedString: function(receiver, pattern, replacement) {
      var $length, t1, i, index;
      if (pattern === "") {
        if (receiver === "")
          return replacement;
        $length = receiver.length;
        for (t1 = replacement, i = 0; i < $length; ++i)
          t1 = t1 + receiver[i] + replacement;
        return t1.charCodeAt(0) == 0 ? t1 : t1;
      }
      index = receiver.indexOf(pattern, 0);
      if (index < 0)
        return receiver;
      if (receiver.length < 500 || replacement.indexOf("$", 0) >= 0)
        return receiver.split(pattern).join(replacement);
      return receiver.replace(new RegExp(H.quoteStringForRegExp(pattern), 'g'), H.escapeReplacement(replacement));
    },
    _stringIdentity: function(string) {
      return string;
    },
    stringReplaceAllFuncUnchecked: function(receiver, pattern, onMatch, onNonMatch) {
      var t1, startIndex, t2, t3, t4, t5;
      if (!type$.Pattern._is(pattern))
        throw H.wrapException(P.ArgumentError$value(pattern, "pattern", "is not a Pattern"));
      for (t1 = pattern.allMatches$1(0, receiver), t1 = new H._AllMatchesIterator(t1._re, t1.__js_helper$_string, t1._start), startIndex = 0, t2 = ""; t1.moveNext$0(); t2 = t3) {
        t3 = t1.__js_helper$_current;
        t4 = t3._match;
        t5 = t4.index;
        t3 = t2 + H.S(H._stringIdentity(C.JSString_methods.substring$2(receiver, startIndex, t5))) + H.S(onMatch.call$1(t3));
        startIndex = t5 + t4[0].length;
      }
      t1 = t2 + H.S(H._stringIdentity(C.JSString_methods.substring$1(receiver, startIndex)));
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    stringReplaceFirstUnchecked: function(receiver, pattern, replacement, startIndex) {
      var index, t1, matches, match;
      if (typeof pattern == "string") {
        index = receiver.indexOf(pattern, startIndex);
        if (index < 0)
          return receiver;
        return H.stringReplaceRangeUnchecked(receiver, index, index + pattern.length, replacement);
      }
      if (pattern instanceof H.JSSyntaxRegExp)
        return startIndex === 0 ? receiver.replace(pattern._nativeRegExp, H.escapeReplacement(replacement)) : H.stringReplaceFirstRE(receiver, pattern, replacement, startIndex);
      if (pattern == null)
        H.throwExpression(H.argumentErrorValue(pattern));
      t1 = J.allMatches$2$s(pattern, receiver, startIndex);
      matches = type$.Iterator_Match._check(t1.get$iterator(t1));
      if (!matches.moveNext$0())
        return receiver;
      match = matches.get$current();
      return C.JSString_methods.replaceRange$3(receiver, match.get$start(), match.get$end(), replacement);
    },
    stringReplaceRangeUnchecked: function(receiver, start, end, replacement) {
      var prefix = receiver.substring(0, start),
        suffix = receiver.substring(end);
      return prefix + replacement + suffix;
    },
    ConstantMap: function ConstantMap() {
    },
    ConstantMap_map_closure: function ConstantMap_map_closure(t0, t1, t2) {
      this.$this = t0;
      this.transform = t1;
      this.result = t2;
    },
    ConstantStringMap: function ConstantStringMap(t0, t1, t2, t3) {
      var _ = this;
      _.__js_helper$_length = t0;
      _._jsObject = t1;
      _.__js_helper$_keys = t2;
      _.$ti = t3;
    },
    _ConstantMapKeyIterable: function _ConstantMapKeyIterable(t0, t1) {
      this.__js_helper$_map = t0;
      this.$ti = t1;
    },
    Instantiation: function Instantiation() {
    },
    Instantiation1: function Instantiation1(t0, t1) {
      this._genericClosure = t0;
      this.$ti = t1;
    },
    Primitives_initTicker_closure: function Primitives_initTicker_closure(t0) {
      this.performance = t0;
    },
    TypeErrorDecoder: function TypeErrorDecoder(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _._pattern = t0;
      _._arguments = t1;
      _._argumentsExpr = t2;
      _._expr = t3;
      _._method = t4;
      _._receiver = t5;
    },
    NullError: function NullError(t0, t1) {
      this.__js_helper$_message = t0;
      this._method = t1;
    },
    JsNoSuchMethodError: function JsNoSuchMethodError(t0, t1, t2) {
      this.__js_helper$_message = t0;
      this._method = t1;
      this._receiver = t2;
    },
    UnknownJsTypeError: function UnknownJsTypeError(t0) {
      this.__js_helper$_message = t0;
    },
    ExceptionAndStackTrace: function ExceptionAndStackTrace(t0, t1) {
      this.dartException = t0;
      this.stackTrace = t1;
    },
    unwrapException_saveStackTrace: function unwrapException_saveStackTrace(t0) {
      this.ex = t0;
    },
    _StackTrace: function _StackTrace(t0) {
      this._exception = t0;
      this._trace = null;
    },
    Closure: function Closure() {
    },
    TearOffClosure: function TearOffClosure() {
    },
    StaticClosure: function StaticClosure() {
    },
    BoundClosure: function BoundClosure(t0, t1, t2, t3) {
      var _ = this;
      _._self = t0;
      _._target = t1;
      _._receiver = t2;
      _._name = t3;
    },
    TypeErrorImplementation: function TypeErrorImplementation(t0) {
      this.message = t0;
    },
    RuntimeError: function RuntimeError(t0) {
      this.message = t0;
    },
    _AssertionError: function _AssertionError(t0) {
      this.message = t0;
    },
    JsLinkedHashMap: function JsLinkedHashMap(t0) {
      var _ = this;
      _.__js_helper$_length = 0;
      _._last = _._first = _.__js_helper$_rest = _.__js_helper$_nums = _.__js_helper$_strings = null;
      _._modifications = 0;
      _.$ti = t0;
    },
    JsLinkedHashMap_values_closure: function JsLinkedHashMap_values_closure(t0) {
      this.$this = t0;
    },
    JsLinkedHashMap_addAll_closure: function JsLinkedHashMap_addAll_closure(t0) {
      this.$this = t0;
    },
    LinkedHashMapCell: function LinkedHashMapCell(t0, t1) {
      var _ = this;
      _.hashMapCellKey = t0;
      _.hashMapCellValue = t1;
      _._previous = _._next = null;
    },
    LinkedHashMapKeyIterable: function LinkedHashMapKeyIterable(t0, t1) {
      this.__js_helper$_map = t0;
      this.$ti = t1;
    },
    LinkedHashMapKeyIterator: function LinkedHashMapKeyIterator(t0, t1, t2) {
      var _ = this;
      _.__js_helper$_map = t0;
      _._modifications = t1;
      _.__js_helper$_current = _._cell = null;
      _.$ti = t2;
    },
    initHooks_closure: function initHooks_closure(t0) {
      this.getTag = t0;
    },
    initHooks_closure0: function initHooks_closure0(t0) {
      this.getUnknownTag = t0;
    },
    initHooks_closure1: function initHooks_closure1(t0) {
      this.prototypeForTag = t0;
    },
    JSSyntaxRegExp: function JSSyntaxRegExp(t0, t1) {
      var _ = this;
      _.pattern = t0;
      _._nativeRegExp = t1;
      _._nativeAnchoredRegExp = _._nativeGlobalRegExp = null;
    },
    _MatchImplementation: function _MatchImplementation(t0) {
      this._match = t0;
    },
    _AllMatchesIterable: function _AllMatchesIterable(t0, t1, t2) {
      this._re = t0;
      this.__js_helper$_string = t1;
      this._start = t2;
    },
    _AllMatchesIterator: function _AllMatchesIterator(t0, t1, t2) {
      var _ = this;
      _._regExp = t0;
      _.__js_helper$_string = t1;
      _._nextIndex = t2;
      _.__js_helper$_current = null;
    },
    StringMatch: function StringMatch(t0, t1) {
      this.start = t0;
      this.pattern = t1;
    },
    _StringAllMatchesIterable: function _StringAllMatchesIterable(t0, t1, t2) {
      this._input = t0;
      this._pattern = t1;
      this.__js_helper$_index = t2;
    },
    _StringAllMatchesIterator: function _StringAllMatchesIterator(t0, t1, t2) {
      var _ = this;
      _._input = t0;
      _._pattern = t1;
      _.__js_helper$_index = t2;
      _.__js_helper$_current = null;
    },
    _ensureNativeList: function(list) {
      return list;
    },
    NativeInt8List__create1: function(arg) {
      return new Int8Array(arg);
    },
    _checkValidIndex: function(index, list, $length) {
      if (index >>> 0 !== index || index >= $length)
        throw H.wrapException(H.diagnoseIndexError(list, index));
    },
    _checkValidRange: function(start, end, $length) {
      var t1;
      if (!(start >>> 0 !== start))
        if (end == null)
          t1 = start > $length;
        else
          t1 = end >>> 0 !== end || start > end || end > $length;
      else
        t1 = true;
      if (t1)
        throw H.wrapException(H.diagnoseRangeError(start, end, $length));
      if (end == null)
        return $length;
      return end;
    },
    NativeByteBuffer: function NativeByteBuffer() {
    },
    NativeTypedData: function NativeTypedData() {
    },
    NativeByteData: function NativeByteData() {
    },
    NativeTypedArray: function NativeTypedArray() {
    },
    NativeTypedArrayOfDouble: function NativeTypedArrayOfDouble() {
    },
    NativeTypedArrayOfInt: function NativeTypedArrayOfInt() {
    },
    NativeFloat32List: function NativeFloat32List() {
    },
    NativeFloat64List: function NativeFloat64List() {
    },
    NativeInt16List: function NativeInt16List() {
    },
    NativeInt32List: function NativeInt32List() {
    },
    NativeInt8List: function NativeInt8List() {
    },
    NativeUint16List: function NativeUint16List() {
    },
    NativeUint32List: function NativeUint32List() {
    },
    NativeUint8ClampedList: function NativeUint8ClampedList() {
    },
    NativeUint8List: function NativeUint8List() {
    },
    _NativeTypedArrayOfDouble_NativeTypedArray_ListMixin: function _NativeTypedArrayOfDouble_NativeTypedArray_ListMixin() {
    },
    _NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin: function _NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin() {
    },
    _NativeTypedArrayOfInt_NativeTypedArray_ListMixin: function _NativeTypedArrayOfInt_NativeTypedArray_ListMixin() {
    },
    _NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin: function _NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin() {
    },
    Rti__getFutureFromFutureOr: function(universe, rti) {
      var future;
      H.assertHelper(rti._kind === 8);
      future = rti._precomputed1;
      if (future == null) {
        H.assertHelper(rti._kind === 8);
        future = rti._precomputed1 = H._Universe__lookupInterfaceRti(universe, "Future", [rti._primary]);
      }
      return future;
    },
    Rti__isUnionOfFunctionType: function(rti) {
      var kind = rti._kind;
      if (kind === 6 || kind === 7 || kind === 8)
        return H.Rti__isUnionOfFunctionType(rti._primary);
      return kind === 11 || kind === 12;
    },
    Rti__getInterfaceTypeArguments: function(rti) {
      H.assertHelper(rti._kind === 9);
      return rti._rest;
    },
    Rti__getBindingArguments: function(rti) {
      H.assertHelper(rti._kind === 10);
      return rti._rest;
    },
    Rti__getFunctionParameters: function(rti) {
      H.assertHelper(rti._kind === 11);
      return rti._rest;
    },
    Rti__getGenericFunctionBounds: function(rti) {
      H.assertHelper(rti._kind === 12);
      return rti._rest;
    },
    Rti__getCanonicalRecipe: function(rti) {
      var s = rti._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      return s;
    },
    findType: function(recipe) {
      return H._Universe_eval(init.typeUniverse, recipe);
    },
    instantiatedGenericFunctionType: function(genericFunctionRti, instantiationRti) {
      var bounds, typeArguments, cache, s, key, probe, rti;
      if (genericFunctionRti == null)
        return null;
      bounds = H.Rti__getGenericFunctionBounds(genericFunctionRti);
      typeArguments = H.Rti__getInterfaceTypeArguments(instantiationRti);
      H.assertHelper(bounds.length === typeArguments.length);
      cache = genericFunctionRti._bindCache;
      if (cache == null)
        cache = genericFunctionRti._bindCache = new Map();
      s = instantiationRti._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      key = s;
      probe = cache.get(key);
      if (probe != null)
        return probe;
      H.assertHelper(genericFunctionRti._kind === 12);
      rti = H._instantiate(init.typeUniverse, genericFunctionRti._primary, typeArguments, 0);
      cache.set(key, rti);
      return rti;
    },
    _instantiate: function(universe, rti, typeArguments, depth) {
      var baseType, instantiatedBaseType, s, interfaceTypeArguments, instantiatedInterfaceTypeArguments, base, instantiatedBase, $arguments, instantiatedArguments, returnType, instantiatedReturnType, functionParameters, instantiatedFunctionParameters, bounds, instantiatedBounds, index,
        _s24_ = "Missing canonical recipe",
        t1 = rti._kind,
        kind = t1;
      switch (kind) {
        case 5:
        case 1:
        case 2:
        case 3:
        case 4:
          return rti;
        case 6:
          baseType = rti._primary;
          instantiatedBaseType = H._instantiate(universe, baseType, typeArguments, depth);
          if (instantiatedBaseType === baseType)
            return rti;
          s = instantiatedBaseType._canonicalRecipe;
          if (H.assertTest(typeof s == "string"))
            H.assertThrow(_s24_);
          return H._Universe__lookupUnaryRti(universe, 6, instantiatedBaseType, s + "*");
        case 7:
          baseType = rti._primary;
          instantiatedBaseType = H._instantiate(universe, baseType, typeArguments, depth);
          if (instantiatedBaseType === baseType)
            return rti;
          s = instantiatedBaseType._canonicalRecipe;
          if (H.assertTest(typeof s == "string"))
            H.assertThrow(_s24_);
          return H._Universe__lookupUnaryRti(universe, 7, instantiatedBaseType, s + "?");
        case 8:
          baseType = rti._primary;
          instantiatedBaseType = H._instantiate(universe, baseType, typeArguments, depth);
          if (instantiatedBaseType === baseType)
            return rti;
          s = instantiatedBaseType._canonicalRecipe;
          if (H.assertTest(typeof s == "string"))
            H.assertThrow(_s24_);
          return H._Universe__lookupUnaryRti(universe, 8, instantiatedBaseType, s + "/");
        case 9:
          interfaceTypeArguments = H.Rti__getInterfaceTypeArguments(rti);
          instantiatedInterfaceTypeArguments = H._instantiateArray(universe, interfaceTypeArguments, typeArguments, depth);
          if (instantiatedInterfaceTypeArguments === interfaceTypeArguments)
            return rti;
          H.assertHelper(rti._kind === 9);
          return H._Universe__lookupInterfaceRti(universe, rti._primary, instantiatedInterfaceTypeArguments);
        case 10:
          H.assertHelper(t1 === 10);
          base = rti._primary;
          instantiatedBase = H._instantiate(universe, base, typeArguments, depth);
          $arguments = H.Rti__getBindingArguments(rti);
          instantiatedArguments = H._instantiateArray(universe, $arguments, typeArguments, depth);
          if (instantiatedBase === base && instantiatedArguments === $arguments)
            return rti;
          return H._Universe__lookupBindingRti(universe, instantiatedBase, instantiatedArguments);
        case 11:
          H.assertHelper(t1 === 11);
          returnType = rti._primary;
          instantiatedReturnType = H._instantiate(universe, returnType, typeArguments, depth);
          functionParameters = H.Rti__getFunctionParameters(rti);
          instantiatedFunctionParameters = H._instantiateFunctionParameters(universe, functionParameters, typeArguments, depth);
          if (instantiatedReturnType === returnType && instantiatedFunctionParameters === functionParameters)
            return rti;
          return H._Universe__lookupFunctionRti(universe, instantiatedReturnType, instantiatedFunctionParameters);
        case 12:
          bounds = H.Rti__getGenericFunctionBounds(rti);
          depth += bounds.length;
          instantiatedBounds = H._instantiateArray(universe, bounds, typeArguments, depth);
          H.assertHelper(rti._kind === 12);
          base = rti._primary;
          instantiatedBase = H._instantiate(universe, base, typeArguments, depth);
          if (instantiatedBounds === bounds && instantiatedBase === base)
            return rti;
          return H._Universe__lookupGenericFunctionRti(universe, instantiatedBase, instantiatedBounds);
        case 13:
          H.assertHelper(t1 === 13);
          index = rti._primary;
          if (index < depth)
            return null;
          return typeArguments[index - depth];
        default:
          throw H.wrapException(P.AssertionError$("Attempted to instantiate unexpected RTI kind " + kind));
      }
    },
    _instantiateArray: function(universe, rtiArray, typeArguments, depth) {
      var changed, i, rti, instantiatedRti,
        $length = rtiArray.length,
        result = [];
      for (changed = false, i = 0; i < $length; ++i) {
        rti = rtiArray[i];
        instantiatedRti = H._instantiate(universe, rti, typeArguments, depth);
        if (instantiatedRti !== rti)
          changed = true;
        result.push(instantiatedRti);
      }
      return changed ? result : rtiArray;
    },
    _instantiateNamed: function(universe, namedArray, typeArguments, depth) {
      var result, changed, i, t1, rti, instantiatedRti,
        $length = namedArray.length;
      H.assertHelper(($length & 1) === 0);
      result = [];
      for (changed = false, i = 0; i < $length; i += 2) {
        t1 = namedArray[i];
        rti = namedArray[i + 1];
        instantiatedRti = H._instantiate(universe, rti, typeArguments, depth);
        if (instantiatedRti !== rti)
          changed = true;
        result.push(t1);
        result.push(instantiatedRti);
      }
      return changed ? result : namedArray;
    },
    _instantiateFunctionParameters: function(universe, functionParameters, typeArguments, depth) {
      var result,
        requiredPositional = functionParameters._requiredPositional,
        instantiatedRequiredPositional = H._instantiateArray(universe, requiredPositional, typeArguments, depth),
        optionalPositional = functionParameters._optionalPositional,
        instantiatedOptionalPositional = H._instantiateArray(universe, optionalPositional, typeArguments, depth),
        optionalNamed = functionParameters._optionalNamed,
        instantiatedOptionalNamed = H._instantiateNamed(universe, optionalNamed, typeArguments, depth);
      if (instantiatedRequiredPositional === requiredPositional && instantiatedOptionalPositional === optionalPositional && instantiatedOptionalNamed === optionalNamed)
        return functionParameters;
      result = new H._FunctionParameters();
      result._requiredPositional = instantiatedRequiredPositional;
      result._optionalPositional = instantiatedOptionalPositional;
      result._optionalNamed = instantiatedOptionalNamed;
      return result;
    },
    closureFunctionType: function(closure) {
      var signature = closure.$signature;
      if (signature != null) {
        if (typeof signature == "number")
          return H.getTypeFromTypesTable(signature);
        return closure.$signature();
      }
      return null;
    },
    instanceOrFunctionType: function(object, testRti) {
      var rti;
      if (H.Rti__isUnionOfFunctionType(testRti))
        if (object instanceof H.Closure) {
          rti = H.closureFunctionType(object);
          if (rti != null)
            return rti;
        }
      return H.instanceType(object);
    },
    instanceType: function(object) {
      var rti;
      if (object instanceof P.Object) {
        rti = object.$ti;
        return rti != null ? rti : H._instanceTypeFromConstructor(object);
      }
      if (Array.isArray(object))
        return H._arrayInstanceType(object);
      return H._instanceTypeFromConstructor(J.getInterceptor$(object));
    },
    _arrayInstanceType: function(object) {
      var rti = object.$ti,
        defaultRti = type$.JSArray_dynamic;
      if (rti == null)
        return defaultRti;
      if (rti.constructor !== defaultRti.constructor)
        return defaultRti;
      return rti;
    },
    _instanceType: function(object) {
      var rti = object.$ti;
      return rti != null ? rti : H._instanceTypeFromConstructor(object);
    },
    _instanceTypeFromConstructor: function(instance) {
      var $constructor = instance.constructor,
        probe = $constructor.$ccache;
      if (probe != null)
        return probe;
      return H._instanceTypeFromConstructorMiss(instance, $constructor);
    },
    _instanceTypeFromConstructorMiss: function(instance, $constructor) {
      var effectiveConstructor = instance instanceof H.Closure ? instance.__proto__.__proto__.constructor : $constructor,
        rti = H._Universe_findErasedType(init.typeUniverse, effectiveConstructor.name);
      $constructor.$ccache = rti;
      return rti;
    },
    getTypeFromTypesTable: function(_index) {
      var rti,
        index = _index,
        table = init.types,
        type = table[index];
      if (typeof type == "string") {
        rti = H._Universe_eval(init.typeUniverse, type);
        table[index] = rti;
        return rti;
      }
      return type;
    },
    createRuntimeType: function(rti) {
      var type = rti._cachedRuntimeType;
      if (type != null)
        return type;
      return rti._cachedRuntimeType = new H._Type(rti);
    },
    typeLiteral: function(recipe) {
      return H.createRuntimeType(H._Universe_eval(init.typeUniverse, recipe));
    },
    _installSpecializedIsTest: function(object) {
      var s, key, testRti = this,
        t1 = testRti._kind,
        isFn = H._generalIsTestImplementation;
      if (H.isTopType(testRti, true)) {
        isFn = H._isTop;
        testRti._check = testRti._as = H._asTop;
      } else if (t1 === 9) {
        s = testRti._canonicalRecipe;
        if (H.assertTest(typeof s == "string"))
          H.assertThrow("Missing canonical recipe");
        key = s;
        if ("int" === key)
          isFn = H._isInt;
        else if ("double" === key)
          isFn = H._isNum;
        else if ("num" === key)
          isFn = H._isNum;
        else if ("String" === key)
          isFn = H._isString;
        else if ("bool" === key)
          isFn = H._isBool;
        else {
          H.assertHelper(testRti._kind === 9);
          t1 = testRti._primary;
          if (H.Rti__getInterfaceTypeArguments(testRti).every(H.isLegacyTopType)) {
            testRti._specializedTestResource = "$is" + t1;
            isFn = H._isTestViaProperty;
          }
        }
      }
      testRti._is = isFn;
      return testRti._is(object);
    },
    _generalIsTestImplementation: function(object) {
      var testRti = this;
      return H._isSubtype(init.typeUniverse, H.instanceOrFunctionType(object, testRti), null, testRti, null, true);
    },
    _isTestViaProperty: function(object) {
      var tag = this._specializedTestResource;
      if (object instanceof P.Object)
        return !!object[tag];
      return !!J.getInterceptor$(object)[tag];
    },
    _generalAsCheckImplementation: function(object) {
      var testRti;
      if (object == null)
        return object;
      testRti = this;
      if (testRti._is(object))
        return object;
      throw H.wrapException(H._CastError$fromMessage(H._Error_compose(object, H.instanceOrFunctionType(object, testRti), H._rtiToString(testRti, null))));
    },
    _generalTypeCheckImplementation: function(object) {
      var testRti;
      if (object == null)
        return object;
      testRti = this;
      if (testRti._is(object))
        return object;
      throw H.wrapException(H._TypeError$fromMessage(H._Error_compose(object, H.instanceOrFunctionType(object, testRti), H._rtiToString(testRti, null))));
    },
    checkTypeBound: function(type, bound, variable, methodName) {
      var _null = null;
      if (H._isSubtype(init.typeUniverse, type, _null, bound, _null, true))
        return type;
      throw H.wrapException(H._TypeError$fromMessage("The type argument '" + H.S(H._rtiToString(type, _null)) + "' is not a subtype of the type variable bound '" + H.S(H._rtiToString(bound, _null)) + "' of type variable '" + variable + "' in '" + H.S(methodName) + "'."));
    },
    _Error_compose: function(object, objectRti, checkedTypeDescription) {
      var objectDescription = P.Error_safeToString(object),
        objectTypeDescription = H._rtiToString(objectRti == null ? H.instanceType(object) : objectRti, null);
      return objectDescription + ": type '" + H.S(objectTypeDescription) + "' is not a subtype of type '" + H.S(checkedTypeDescription) + "'";
    },
    _CastError$fromMessage: function(message) {
      return new H._CastError("CastError: " + message);
    },
    _CastError__CastError$forType: function(object, type) {
      return new H._CastError("CastError: " + H._Error_compose(object, null, type));
    },
    _TypeError$fromMessage: function(message) {
      return new H._TypeError("TypeError: " + message);
    },
    _TypeError__TypeError$forType: function(object, type) {
      return new H._TypeError("TypeError: " + H._Error_compose(object, null, type));
    },
    _isTop: function(object) {
      return true;
    },
    _asTop: function(object) {
      return object;
    },
    _isBool: function(object) {
      return true === object || false === object;
    },
    _asBoolNullable: function(object) {
      if (true === object || false === object)
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._CastError__CastError$forType(object, "bool"));
    },
    _checkBoolNullable: function(object) {
      if (true === object || false === object)
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._TypeError__TypeError$forType(object, "bool"));
    },
    _asDoubleNullable: function(object) {
      if (typeof object == "number")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._CastError__CastError$forType(object, "double"));
    },
    _checkDoubleNullable: function(object) {
      if (typeof object == "number")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._TypeError__TypeError$forType(object, "double"));
    },
    _isInt: function(object) {
      return typeof object == "number" && Math.floor(object) === object;
    },
    _asIntNullable: function(object) {
      if (typeof object == "number" && Math.floor(object) === object)
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._CastError__CastError$forType(object, "int"));
    },
    _checkIntNullable: function(object) {
      if (typeof object == "number" && Math.floor(object) === object)
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._TypeError__TypeError$forType(object, "int"));
    },
    _isNum: function(object) {
      return typeof object == "number";
    },
    _asNumNullable: function(object) {
      if (typeof object == "number")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._CastError__CastError$forType(object, "num"));
    },
    _checkNumNullable: function(object) {
      if (typeof object == "number")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._TypeError__TypeError$forType(object, "num"));
    },
    _isString: function(object) {
      return typeof object == "string";
    },
    _asStringNullable: function(object) {
      if (typeof object == "string")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._CastError__CastError$forType(object, "String"));
    },
    _checkStringNullable: function(object) {
      if (typeof object == "string")
        return object;
      if (object == null)
        return object;
      throw H.wrapException(H._TypeError__TypeError$forType(object, "String"));
    },
    _rtiArrayToString: function(array, genericContext) {
      var s, sep, i;
      for (s = "", sep = "", i = 0; i < array.length; ++i, sep = ", ")
        s += C.JSString_methods.$add(sep, H._rtiToString(array[i], genericContext));
      return s;
    },
    _functionRtiToString: function(functionType, genericContext, bounds) {
      var boundsLength, outerContextLength, offset, i, typeParametersText, typeSep, t1, t2, boundRti, parameters, requiredPositional, requiredPositionalLength, optionalPositional, optionalPositionalLength, optionalNamed, optionalNamedLength, returnTypeText, argumentsText, sep, _s2_ = ", ";
      if (bounds != null) {
        boundsLength = bounds.length;
        if (genericContext == null) {
          genericContext = H.setRuntimeTypeInfo([], type$.JSArray_String);
          outerContextLength = null;
        } else
          outerContextLength = genericContext.length;
        offset = genericContext.length;
        for (i = boundsLength; i > 0; --i)
          C.JSArray_methods.add$1(genericContext, "T" + (offset + i));
        for (typeParametersText = "<", typeSep = "", i = 0; i < boundsLength; ++i, typeSep = _s2_) {
          typeParametersText += typeSep;
          t1 = genericContext.length;
          t2 = t1 - 1 - i;
          if (t2 < 0)
            return H.ioore(genericContext, t2);
          typeParametersText = C.JSString_methods.$add(typeParametersText, genericContext[t2]);
          boundRti = bounds[i];
          if (!H.isTopType(boundRti, true))
            typeParametersText += C.JSString_methods.$add(" extends ", H._rtiToString(boundRti, genericContext));
        }
        typeParametersText += ">";
      } else {
        typeParametersText = "";
        outerContextLength = null;
      }
      H.assertHelper(functionType._kind === 11);
      t1 = functionType._primary;
      parameters = H.Rti__getFunctionParameters(functionType);
      requiredPositional = parameters._requiredPositional;
      requiredPositionalLength = requiredPositional.length;
      optionalPositional = parameters._optionalPositional;
      optionalPositionalLength = optionalPositional.length;
      optionalNamed = parameters._optionalNamed;
      optionalNamedLength = optionalNamed.length;
      H.assertHelper(optionalPositionalLength === 0 || optionalNamedLength === 0);
      returnTypeText = H._rtiToString(t1, genericContext);
      for (argumentsText = "", sep = "", i = 0; i < requiredPositionalLength; ++i, sep = _s2_)
        argumentsText += C.JSString_methods.$add(sep, H._rtiToString(requiredPositional[i], genericContext));
      if (optionalPositionalLength > 0) {
        argumentsText += sep + "[";
        for (sep = "", i = 0; i < optionalPositionalLength; ++i, sep = _s2_)
          argumentsText += C.JSString_methods.$add(sep, H._rtiToString(optionalPositional[i], genericContext));
        argumentsText += "]";
      }
      if (optionalNamedLength > 0) {
        argumentsText += sep + "{";
        for (sep = "", i = 0; i < optionalNamedLength; i += 2, sep = _s2_)
          argumentsText += C.JSString_methods.$add(sep, H._rtiToString(optionalNamed[i + 1], genericContext)) + " " + optionalNamed[i];
        argumentsText += "}";
      }
      if (outerContextLength != null)
        genericContext.length = outerContextLength;
      return typeParametersText + "(" + argumentsText + ") => " + H.S(returnTypeText);
    },
    _rtiToString: function(rti, genericContext) {
      var $name, $arguments, t2,
        t1 = rti._kind,
        kind = t1;
      if (kind === 5)
        return "erased";
      if (kind === 2)
        return "dynamic";
      if (kind === 3)
        return "void";
      if (kind === 1)
        return "Never";
      if (kind === 4)
        return "any";
      if (kind === 6) {
        H.assertHelper(t1 === 6);
        return H.S(H._rtiToString(rti._primary, genericContext)) + "*";
      }
      if (kind === 7) {
        H.assertHelper(t1 === 7);
        return H.S(H._rtiToString(rti._primary, genericContext)) + "?";
      }
      if (kind === 8) {
        H.assertHelper(t1 === 8);
        return "FutureOr<" + H.S(H._rtiToString(rti._primary, genericContext)) + ">";
      }
      if (kind === 9) {
        H.assertHelper(t1 === 9);
        $name = H._unminifyOrTag(rti._primary);
        $arguments = H.Rti__getInterfaceTypeArguments(rti);
        return $arguments.length !== 0 ? $name + ("<" + H._rtiArrayToString($arguments, genericContext) + ">") : $name;
      }
      if (kind === 11)
        return H._functionRtiToString(rti, genericContext, null);
      if (kind === 12) {
        H.assertHelper(t1 === 12);
        return H._functionRtiToString(rti._primary, genericContext, H.Rti__getGenericFunctionBounds(rti));
      }
      if (kind === 13) {
        H.assertHelper(t1 === 13);
        t1 = rti._primary;
        t2 = genericContext.length;
        t1 = t2 - 1 - t1;
        if (t1 < 0 || t1 >= t2)
          return H.ioore(genericContext, t1);
        return genericContext[t1];
      }
      return "?";
    },
    _unminifyOrTag: function(rawClassName) {
      var preserved = H.unmangleGlobalNameIfPreservedAnyways(rawClassName);
      if (preserved != null)
        return preserved;
      return rawClassName;
    },
    _Universe_findRule: function(universe, targetType) {
      var rule = universe.tR[targetType];
      for (; typeof rule == "string";)
        rule = universe.tR[rule];
      return rule;
    },
    _Universe_findErasedType: function(universe, cls) {
      var $length, erased, $arguments, i, $interface,
        metadata = universe.eT,
        probe = metadata[cls];
      if (probe == null)
        return H._Universe_eval(universe, cls);
      else if (typeof probe == "number") {
        $length = probe;
        erased = H._Universe__lookupTerminalRti(universe, 5, "#");
        $arguments = [];
        for (i = 0; i < $length; ++i)
          $arguments.push(erased);
        $interface = H._Universe__lookupInterfaceRti(universe, cls, $arguments);
        metadata[cls] = $interface;
        return $interface;
      } else
        return probe;
    },
    _Universe_addRules: function(universe, rules) {
      return H._Utils_objectAssign(universe.tR, rules);
    },
    _Universe_addErasedTypes: function(universe, types) {
      return H._Utils_objectAssign(universe.eT, types);
    },
    _Universe_eval: function(universe, recipe) {
      var rti,
        cache = universe.eC,
        probe = cache.get(recipe);
      if (probe != null)
        return probe;
      rti = H._Universe__parseRecipe(universe, null, recipe);
      cache.set(recipe, rti);
      return rti;
    },
    _Universe_evalInEnvironment: function(universe, environment, recipe) {
      var probe, rti,
        cache = environment._evalCache;
      if (cache == null)
        cache = environment._evalCache = new Map();
      probe = cache.get(recipe);
      if (probe != null)
        return probe;
      rti = H._Universe__parseRecipe(universe, environment, recipe);
      cache.set(recipe, rti);
      return rti;
    },
    _Universe_bind: function(universe, environment, argumentsRti) {
      var s, argumentsRecipe, probe, rti,
        cache = environment._bindCache;
      if (cache == null)
        cache = environment._bindCache = new Map();
      s = argumentsRti._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      argumentsRecipe = s;
      probe = cache.get(argumentsRecipe);
      if (probe != null)
        return probe;
      rti = H._Universe__lookupBindingRti(universe, environment, argumentsRti._kind === 10 ? H.Rti__getBindingArguments(argumentsRti) : [argumentsRti]);
      cache.set(argumentsRecipe, rti);
      return rti;
    },
    _Universe__parseRecipe: function(universe, environment, recipe) {
      var rti = H._Parser_parse(H._Parser_create(universe, environment, recipe));
      return rti;
    },
    _Universe__finishRti: function(universe, rti) {
      var s = rti._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      universe.eC.set(s, rti);
      rti._as = H._generalAsCheckImplementation;
      rti._check = H._generalTypeCheckImplementation;
      rti._is = H._installSpecializedIsTest;
      return rti;
    },
    _Universe__lookupTerminalRti: function(universe, kind, canonicalRecipe) {
      var rti,
        probe = universe.eC.get(canonicalRecipe);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = kind;
      rti._canonicalRecipe = canonicalRecipe;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__lookupUnaryRti: function(universe, kind, baseType, canonicalRecipe) {
      var rti,
        probe = universe.eC.get(canonicalRecipe);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = kind;
      rti._primary = baseType;
      rti._canonicalRecipe = canonicalRecipe;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__lookupGenericFunctionParameterRti: function(universe, index) {
      var rti,
        canonicalRecipe = "" + index + "^",
        probe = universe.eC.get(canonicalRecipe);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = 13;
      rti._primary = index;
      rti._canonicalRecipe = canonicalRecipe;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__canonicalRecipeJoin: function($arguments) {
      var s, sep, i, s0,
        $length = $arguments.length;
      for (s = "", sep = "", i = 0; i < $length; ++i, sep = ",") {
        s0 = $arguments[i]._canonicalRecipe;
        if (H.assertTest(typeof s0 == "string"))
          H.assertThrow("Missing canonical recipe");
        s += sep + s0;
      }
      return s;
    },
    _Universe__canonicalRecipeJoinNamed: function($arguments) {
      var s, sep, i, t1, s0,
        $length = $arguments.length;
      H.assertHelper(($length & 1) === 0);
      for (s = "", sep = "", i = 0; i < $length; i += 2, sep = ",") {
        t1 = $arguments[i];
        s0 = $arguments[i + 1]._canonicalRecipe;
        if (H.assertTest(typeof s0 == "string"))
          H.assertThrow("Missing canonical recipe");
        s += sep + t1 + ":" + s0;
      }
      return s;
    },
    _Universe__lookupInterfaceRti: function(universe, $name, $arguments) {
      var s, probe, rti;
      H.assertHelper(typeof $name == "string");
      s = $name;
      if ($arguments.length !== 0)
        s += "<" + H._Universe__canonicalRecipeJoin($arguments) + ">";
      probe = universe.eC.get(s);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = 9;
      rti._primary = $name;
      rti._rest = $arguments;
      if ($arguments.length > 0)
        rti._precomputed1 = $arguments[0];
      rti._canonicalRecipe = s;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__lookupBindingRti: function(universe, base, $arguments) {
      var newBase, newArguments, s, probe, rti,
        t1 = base._kind;
      if (t1 === 10) {
        H.assertHelper(t1 === 10);
        newBase = base._primary;
        newArguments = H.Rti__getBindingArguments(base).concat($arguments);
      } else {
        newArguments = $arguments;
        newBase = base;
      }
      s = newBase._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      s = s + ";" + ("<" + H._Universe__canonicalRecipeJoin(newArguments) + ">");
      probe = universe.eC.get(s);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = 10;
      rti._primary = newBase;
      rti._rest = newArguments;
      rti._canonicalRecipe = s;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__lookupFunctionRti: function(universe, returnType, parameters) {
      var requiredPositional, requiredPositionalLength, optionalPositional, optionalPositionalLength, optionalNamed, optionalNamedLength, recipe, key, probe, rti,
        s = returnType._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      requiredPositional = parameters._requiredPositional;
      requiredPositionalLength = requiredPositional.length;
      optionalPositional = parameters._optionalPositional;
      optionalPositionalLength = optionalPositional.length;
      optionalNamed = parameters._optionalNamed;
      optionalNamedLength = optionalNamed.length;
      H.assertHelper(optionalPositionalLength === 0 || optionalNamedLength === 0);
      recipe = "(" + H._Universe__canonicalRecipeJoin(requiredPositional);
      if (optionalPositionalLength > 0)
        recipe += (requiredPositionalLength > 0 ? "," : "") + "[" + H._Universe__canonicalRecipeJoin(optionalPositional) + "]";
      if (optionalNamedLength > 0)
        recipe += (requiredPositionalLength > 0 ? "," : "") + "{" + H._Universe__canonicalRecipeJoinNamed(optionalNamed) + "}";
      key = s + (recipe + ")");
      probe = universe.eC.get(key);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = 11;
      rti._primary = returnType;
      rti._rest = parameters;
      rti._canonicalRecipe = key;
      return H._Universe__finishRti(universe, rti);
    },
    _Universe__lookupGenericFunctionRti: function(universe, baseFunctionType, bounds) {
      var key, probe, rti,
        s = baseFunctionType._canonicalRecipe;
      if (H.assertTest(typeof s == "string"))
        H.assertThrow("Missing canonical recipe");
      key = s + "<" + H._Universe__canonicalRecipeJoin(bounds) + ">";
      probe = universe.eC.get(key);
      if (probe != null)
        return probe;
      rti = new H.Rti(null, null, null);
      rti._kind = 12;
      rti._primary = baseFunctionType;
      rti._rest = bounds;
      rti._canonicalRecipe = key;
      return H._Universe__finishRti(universe, rti);
    },
    _Parser_create: function(universe, environment, recipe) {
      return {u: universe, e: environment, r: recipe, s: [], p: 0};
    },
    _Parser_parse: function(parser) {
      var t1, i, ch, t2, t3, universe, array, head, base, u, s, parameters, optionalPositional, optionalNamed, item,
        _s24_ = "Missing canonical recipe",
        source = parser.r,
        stack = parser.s;
      for (t1 = source.length, i = 0; i < t1;) {
        ch = source.charCodeAt(i);
        if (ch >= 48 && ch <= 57)
          i = H._Parser_handleDigit(i + 1, ch, source, stack);
        else if ((((ch | 32) >>> 0) - 97 & 65535) < 26 || ch === 95 || ch === 36)
          i = H._Parser_handleIdentifier(parser, i, source, stack, false);
        else if (ch === 46)
          i = H._Parser_handleIdentifier(parser, i, source, stack, true);
        else {
          ++i;
          switch (ch) {
            case 44:
              break;
            case 58:
              break;
            case 59:
              stack.push(H._Parser_toType(parser.u, parser.e, stack.pop()));
              break;
            case 94:
              t2 = parser.u;
              t3 = stack.pop();
              H.assertHelper(typeof t3 == "number");
              stack.push(H._Universe__lookupGenericFunctionParameterRti(t2, t3));
              break;
            case 35:
              stack.push(H._Universe__lookupTerminalRti(parser.u, 5, "#"));
              break;
            case 64:
              stack.push(H._Universe__lookupTerminalRti(parser.u, 2, "@"));
              break;
            case 126:
              stack.push(H._Universe__lookupTerminalRti(parser.u, 3, "~"));
              break;
            case 60:
              stack.push(parser.p);
              parser.p = stack.length;
              break;
            case 62:
              universe = parser.u;
              array = stack.splice(parser.p);
              H._Parser_toTypes(parser.u, parser.e, array);
              parser.p = stack.pop();
              head = stack.pop();
              if (typeof head == "string")
                stack.push(H._Universe__lookupInterfaceRti(universe, head, array));
              else {
                base = H._Parser_toType(universe, parser.e, head);
                switch (base._kind) {
                  case 11:
                    stack.push(H._Universe__lookupGenericFunctionRti(universe, base, array));
                    break;
                  default:
                    stack.push(H._Universe__lookupBindingRti(universe, base, array));
                    break;
                }
              }
              break;
            case 38:
              H._Parser_handleExtendedOperations(parser, stack);
              break;
            case 42:
              u = parser.u;
              t2 = H._Parser_toType(u, parser.e, stack.pop());
              s = t2._canonicalRecipe;
              if (H.assertTest(typeof s == "string"))
                H.assertThrow(_s24_);
              stack.push(H._Universe__lookupUnaryRti(u, 6, t2, s + "*"));
              break;
            case 63:
              u = parser.u;
              t2 = H._Parser_toType(u, parser.e, stack.pop());
              s = t2._canonicalRecipe;
              if (H.assertTest(typeof s == "string"))
                H.assertThrow(_s24_);
              stack.push(H._Universe__lookupUnaryRti(u, 7, t2, s + "?"));
              break;
            case 47:
              u = parser.u;
              t2 = H._Parser_toType(u, parser.e, stack.pop());
              s = t2._canonicalRecipe;
              if (H.assertTest(typeof s == "string"))
                H.assertThrow(_s24_);
              stack.push(H._Universe__lookupUnaryRti(u, 8, t2, s + "/"));
              break;
            case 40:
              stack.push(parser.p);
              parser.p = stack.length;
              break;
            case 41:
              universe = parser.u;
              parameters = new H._FunctionParameters();
              optionalPositional = universe.sEA;
              optionalNamed = universe.sEA;
              head = stack.pop();
              if (typeof head == "number")
                switch (head) {
                  case -1:
                    optionalPositional = stack.pop();
                    break;
                  case -2:
                    optionalNamed = stack.pop();
                    break;
                  default:
                    stack.push(head);
                    break;
                }
              else
                stack.push(head);
              array = stack.splice(parser.p);
              H._Parser_toTypes(parser.u, parser.e, array);
              parser.p = stack.pop();
              parameters._requiredPositional = array;
              parameters._optionalPositional = optionalPositional;
              parameters._optionalNamed = optionalNamed;
              stack.push(H._Universe__lookupFunctionRti(universe, H._Parser_toType(universe, parser.e, stack.pop()), parameters));
              break;
            case 91:
              stack.push(parser.p);
              parser.p = stack.length;
              break;
            case 93:
              array = stack.splice(parser.p);
              H._Parser_toTypes(parser.u, parser.e, array);
              parser.p = stack.pop();
              stack.push(array);
              stack.push(-1);
              break;
            case 123:
              stack.push(parser.p);
              parser.p = stack.length;
              break;
            case 125:
              array = stack.splice(parser.p);
              H._Parser_toTypesNamed(parser.u, parser.e, array);
              parser.p = stack.pop();
              stack.push(array);
              stack.push(-2);
              break;
            default:
              throw "Bad character " + ch;
          }
        }
      }
      item = stack.pop();
      return H._Parser_toType(parser.u, parser.e, item);
    },
    _Parser_handleDigit: function(i, digit, source, stack) {
      var t1, ch,
        value = digit - 48;
      for (t1 = source.length; i < t1; ++i) {
        ch = source.charCodeAt(i);
        if (!(ch >= 48 && ch <= 57))
          break;
        value = value * 10 + (ch - 48);
      }
      stack.push(value);
      return i;
    },
    _Parser_handleIdentifier: function(parser, start, source, stack, hasPeriod) {
      var t1, ch, t2, string, environment, rule, recipe,
        i = start + 1;
      for (t1 = source.length; i < t1; ++i) {
        ch = source.charCodeAt(i);
        if (ch === 46) {
          if (hasPeriod)
            break;
          hasPeriod = true;
        } else {
          if (!((((ch | 32) >>> 0) - 97 & 65535) < 26 || ch === 95 || ch === 36))
            t2 = ch >= 48 && ch <= 57;
          else
            t2 = true;
          if (!t2)
            break;
        }
      }
      string = source.substring(start, i);
      if (hasPeriod) {
        t1 = parser.u;
        environment = parser.e;
        t2 = environment._kind;
        if (t2 === 10) {
          H.assertHelper(t2 === 10);
          environment = environment._primary;
        }
        H.assertHelper(environment._kind === 9);
        rule = H._Universe_findRule(t1, environment._primary);
        H.assertHelper(rule != null);
        recipe = rule[string];
        if (recipe == null)
          H.throwExpression('No "' + string + '" in "' + H.Rti__getCanonicalRecipe(environment) + '"');
        stack.push(H._Universe_evalInEnvironment(t1, environment, recipe));
      } else
        stack.push(string);
      return i;
    },
    _Parser_handleExtendedOperations: function(parser, stack) {
      var $top = stack.pop();
      if (0 === $top) {
        stack.push(H._Universe__lookupTerminalRti(parser.u, 1, "0&"));
        return;
      }
      if (1 === $top) {
        stack.push(H._Universe__lookupTerminalRti(parser.u, 4, "1&"));
        return;
      }
      throw H.wrapException(P.AssertionError$("Unexpected extended operation " + H.S($top)));
    },
    _Parser_toType: function(universe, environment, item) {
      if (typeof item == "string")
        return H._Universe__lookupInterfaceRti(universe, item, universe.sEA);
      else if (typeof item == "number")
        return H._Parser_indexToType(universe, environment, item);
      else
        return item;
    },
    _Parser_toTypes: function(universe, environment, items) {
      var i,
        $length = items.length;
      for (i = 0; i < $length; ++i)
        items[i] = H._Parser_toType(universe, environment, items[i]);
    },
    _Parser_toTypesNamed: function(universe, environment, items) {
      var i,
        $length = items.length;
      H.assertHelper(($length & 1) === 0);
      for (i = 1; i < $length; i += 2)
        items[i] = H._Parser_toType(universe, environment, items[i]);
    },
    _Parser_indexToType: function(universe, environment, index) {
      var typeArguments, len,
        t1 = environment._kind,
        kind = t1;
      if (kind === 10) {
        if (index === 0) {
          H.assertHelper(t1 === 10);
          return environment._primary;
        }
        typeArguments = H.Rti__getBindingArguments(environment);
        len = typeArguments.length;
        if (index <= len)
          return typeArguments[index - 1];
        index -= len;
        H.assertHelper(t1 === 10);
        environment = environment._primary;
        kind = environment._kind;
      } else if (index === 0)
        return environment;
      if (kind !== 9)
        throw H.wrapException(P.AssertionError$("Indexed base must be an interface type"));
      typeArguments = H.Rti__getInterfaceTypeArguments(environment);
      if (index <= typeArguments.length)
        return typeArguments[index - 1];
      throw H.wrapException(P.AssertionError$("Bad index " + index + " for " + environment.toString$0(0)));
    },
    _isSubtype: function(universe, s, sEnv, t, tEnv, isLegacy) {
      var sKind, leftTypeVariable, t1, tKind, sBounds, tBounds;
      if (s === t)
        return true;
      if (H.isTopType(t, true))
        return true;
      sKind = s._kind;
      if (sKind === 4)
        return true;
      if (H.isTopType(s, true))
        return false;
      if (s === type$.Null)
        return true;
      leftTypeVariable = sKind === 13;
      if (leftTypeVariable) {
        H.assertHelper(s._kind === 13);
        if (H._isSubtype(universe, sEnv[s._primary], sEnv, t, tEnv, true))
          return true;
      }
      t1 = t._kind;
      tKind = t1;
      if (sKind === 6) {
        H.assertHelper(s._kind === 6);
        return H._isSubtype(universe, s._primary, sEnv, t, tEnv, true);
      }
      if (tKind === 6) {
        H.assertHelper(t1 === 6);
        t1 = t._primary;
        return H._isSubtype(universe, s, sEnv, t1, tEnv, true);
      }
      if (sKind === 8) {
        H.assertHelper(s._kind === 8);
        if (!H._isSubtype(universe, s._primary, sEnv, t, tEnv, true))
          return false;
        return H._isSubtype(universe, H.Rti__getFutureFromFutureOr(universe, s), sEnv, t, tEnv, true);
      }
      if (sKind === 7) {
        H.assertHelper(s._kind === 7);
        t1 = H._isSubtype(universe, s._primary, sEnv, t, tEnv, true);
        return t1;
      }
      if (tKind === 8) {
        H.assertHelper(t1 === 8);
        if (H._isSubtype(universe, s, sEnv, t._primary, tEnv, true))
          return true;
        return H._isSubtype(universe, s, sEnv, H.Rti__getFutureFromFutureOr(universe, t), tEnv, true);
      }
      if (tKind === 7) {
        H.assertHelper(t1 === 7);
        t1 = H._isSubtype(universe, s, sEnv, t._primary, tEnv, true);
        return t1;
      }
      if (leftTypeVariable)
        return false;
      t1 = sKind !== 11;
      if ((!t1 || sKind === 12) && t === type$.Function)
        return true;
      if (tKind === 12) {
        if (s === type$.JavaScriptFunction)
          return true;
        if (sKind !== 12)
          return false;
        sBounds = H.Rti__getGenericFunctionBounds(s);
        tBounds = H.Rti__getGenericFunctionBounds(t);
        if (!H.typesEqual(sBounds, tBounds, true))
          return false;
        sEnv = sEnv == null ? sBounds : sBounds.concat(sEnv);
        tEnv = tEnv == null ? tBounds : tBounds.concat(tEnv);
        H.assertHelper(s._kind === 12);
        t1 = s._primary;
        H.assertHelper(t._kind === 12);
        return H._isFunctionSubtype(universe, t1, sEnv, t._primary, tEnv, true);
      }
      if (tKind === 11) {
        if (s === type$.JavaScriptFunction)
          return true;
        if (t1)
          return false;
        return H._isFunctionSubtype(universe, s, sEnv, t, tEnv, true);
      }
      if (sKind === 9) {
        if (tKind !== 9)
          return false;
        return H._isInterfaceSubtype(universe, s, sEnv, t, tEnv, true);
      }
      return false;
    },
    _isFunctionSubtype: function(universe, s, sEnv, t, tEnv, isLegacy) {
      var t1, sParameters, tParameters, sRequiredPositional, tRequiredPositional, sRequiredPositionalLength, tRequiredPositionalLength, requiredPositionalDelta, sOptionalPositional, tOptionalPositional, sOptionalPositionalLength, tOptionalPositionalLength, i, sOptionalNamed, tOptionalNamed, sOptionalNamedLength, tOptionalNamedLength, j, tName, sName;
      H.assertHelper(s._kind === 11);
      H.assertHelper(t._kind === 11);
      H.assertHelper(s._kind === 11);
      t1 = s._primary;
      H.assertHelper(t._kind === 11);
      if (!H._isSubtype(universe, t1, sEnv, t._primary, tEnv, true))
        return false;
      sParameters = H.Rti__getFunctionParameters(s);
      tParameters = H.Rti__getFunctionParameters(t);
      sRequiredPositional = sParameters._requiredPositional;
      tRequiredPositional = tParameters._requiredPositional;
      sRequiredPositionalLength = sRequiredPositional.length;
      tRequiredPositionalLength = tRequiredPositional.length;
      if (sRequiredPositionalLength > tRequiredPositionalLength)
        return false;
      requiredPositionalDelta = tRequiredPositionalLength - sRequiredPositionalLength;
      sOptionalPositional = sParameters._optionalPositional;
      tOptionalPositional = tParameters._optionalPositional;
      sOptionalPositionalLength = sOptionalPositional.length;
      tOptionalPositionalLength = tOptionalPositional.length;
      if (sRequiredPositionalLength + sOptionalPositionalLength < tRequiredPositionalLength + tOptionalPositionalLength)
        return false;
      for (i = 0; i < sRequiredPositionalLength; ++i) {
        t1 = sRequiredPositional[i];
        if (!H._isSubtype(universe, tRequiredPositional[i], tEnv, t1, sEnv, true))
          return false;
      }
      for (i = 0; i < requiredPositionalDelta; ++i) {
        t1 = sOptionalPositional[i];
        if (!H._isSubtype(universe, tRequiredPositional[sRequiredPositionalLength + i], tEnv, t1, sEnv, true))
          return false;
      }
      for (i = 0; i < tOptionalPositionalLength; ++i) {
        t1 = sOptionalPositional[requiredPositionalDelta + i];
        if (!H._isSubtype(universe, tOptionalPositional[i], tEnv, t1, sEnv, true))
          return false;
      }
      sOptionalNamed = sParameters._optionalNamed;
      tOptionalNamed = tParameters._optionalNamed;
      sOptionalNamedLength = sOptionalNamed.length;
      tOptionalNamedLength = tOptionalNamed.length;
      for (i = 0, j = 0; j < tOptionalNamedLength; j += 2) {
        tName = tOptionalNamed[j];
        do {
          if (i >= sOptionalNamedLength)
            return false;
          sName = sOptionalNamed[i];
          i += 2;
        } while (sName < tName);
        if (tName < sName)
          return false;
        t1 = sOptionalNamed[i - 1];
        if (!H._isSubtype(universe, tOptionalNamed[j + 1], tEnv, t1, sEnv, true))
          return false;
      }
      return true;
    },
    _isInterfaceSubtype: function(universe, s, sEnv, t, tEnv, isLegacy) {
      var sName, tName, sArgs, tArgs, $length, i, t1, t2, rule, supertypeArgs;
      H.assertHelper(s._kind === 9);
      sName = s._primary;
      H.assertHelper(t._kind === 9);
      tName = t._primary;
      if (sName === tName) {
        sArgs = H.Rti__getInterfaceTypeArguments(s);
        tArgs = H.Rti__getInterfaceTypeArguments(t);
        $length = sArgs.length;
        H.assertHelper($length === tArgs.length);
        for (i = 0; i < $length; ++i) {
          t1 = sArgs[i];
          t2 = tArgs[i];
          if (!H._isSubtype(universe, t1, sEnv, t2, tEnv, true))
            return false;
        }
        return true;
      }
      rule = H._Universe_findRule(universe, sName);
      if (rule == null)
        return false;
      supertypeArgs = rule[tName];
      if (supertypeArgs == null)
        return false;
      $length = supertypeArgs.length;
      tArgs = H.Rti__getInterfaceTypeArguments(t);
      H.assertHelper($length === tArgs.length);
      for (i = 0; i < $length; ++i)
        if (!H._isSubtype(universe, H._Universe_evalInEnvironment(universe, s, supertypeArgs[i]), sEnv, tArgs[i], tEnv, true))
          return false;
      return true;
    },
    typeEqual: function(s, t, isLegacy) {
      var t1, sKind, t2;
      if (s === t)
        return true;
      if (H.isTopType(s, true))
        return H.isTopType(t, true);
      t1 = s._kind;
      sKind = t1;
      if (sKind !== t._kind)
        return false;
      switch (sKind) {
        case 6:
        case 7:
        case 8:
          return H.typeEqual(s._primary, t._primary, true);
        case 9:
          H.assertHelper(t1 === 9);
          t1 = s._primary;
          H.assertHelper(t._kind === 9);
          if (t1 !== t._primary)
            return false;
          return H.typesEqual(H.Rti__getInterfaceTypeArguments(s), H.Rti__getInterfaceTypeArguments(t), true);
        case 10:
          H.assertHelper(t1 === 10);
          t1 = s._primary;
          H.assertHelper(t._kind === 10);
          return H.typeEqual(t1, t._primary, true) && H.typesEqual(H.Rti__getBindingArguments(s), H.Rti__getBindingArguments(t), true);
        case 11:
          H.assertHelper(t1 === 11);
          t1 = s._primary;
          H.assertHelper(t._kind === 11);
          if (H.typeEqual(t1, t._primary, true)) {
            t1 = H.Rti__getFunctionParameters(s);
            t2 = H.Rti__getFunctionParameters(t);
            t1 = H.typesEqual(t1._requiredPositional, t2._requiredPositional, true) && H.typesEqual(t1._optionalPositional, t2._optionalPositional, true) && H.namedTypesEqual(t1._optionalNamed, t2._optionalNamed, true);
          } else
            t1 = false;
          return t1;
        case 12:
          H.assertHelper(t1 === 12);
          t1 = s._primary;
          H.assertHelper(t._kind === 12);
          return H.typeEqual(t1, t._primary, true) && H.typesEqual(H.Rti__getGenericFunctionBounds(s), H.Rti__getGenericFunctionBounds(t), true);
        default:
          return false;
      }
    },
    typesEqual: function(sArray, tArray, isLegacy) {
      var i,
        sLength = sArray.length;
      if (sLength !== tArray.length)
        return false;
      for (i = 0; i < sLength; ++i)
        if (!H.typeEqual(sArray[i], tArray[i], true))
          return false;
      return true;
    },
    namedTypesEqual: function(sArray, tArray, isLegacy) {
      var i, t1,
        sLength = sArray.length,
        tLength = tArray.length;
      H.assertHelper((sLength & 1) === 0);
      H.assertHelper((tLength & 1) === 0);
      if (sLength !== tLength)
        return false;
      for (i = 0; i < sLength; i += 2) {
        if (sArray[i] !== tArray[i])
          return false;
        t1 = i + 1;
        if (!H.typeEqual(sArray[t1], tArray[t1], true))
          return false;
      }
      return true;
    },
    isLegacyTopType: function(t) {
      return H.isTopType(t, true);
    },
    isTopType: function(t, isLegacy) {
      var t1, kind;
      if (t === type$.Object)
        return true;
      t1 = t._kind;
      kind = t1;
      if (kind !== 2)
        if (kind !== 3)
          if (kind !== 4)
            if (kind !== 5)
              if (kind === 8) {
                H.assertHelper(t1 === 8);
                t1 = H.isTopType(t._primary, true);
              } else
                t1 = false;
            else
              t1 = true;
          else
            t1 = true;
        else
          t1 = true;
      else
        t1 = true;
      return t1;
    },
    _Utils_objectAssign: function(o, other) {
      var i, key,
        keys = Object.keys(other),
        $length = keys.length;
      for (i = 0; i < $length; ++i) {
        key = keys[i];
        o[key] = other[key];
      }
    },
    Rti: function Rti(t0, t1, t2) {
      var _ = this;
      _._as = t0;
      _._check = t1;
      _._is = t2;
      _._cachedRuntimeType = _._specializedTestResource = _._precomputed1 = null;
      _._kind = 0;
      _._canonicalRecipe = _._bindCache = _._evalCache = _._rest = _._primary = null;
    },
    _FunctionParameters: function _FunctionParameters() {
      this._optionalNamed = this._optionalPositional = this._requiredPositional = null;
    },
    _Type: function _Type(t0) {
      this._rti = t0;
      this._hashCode = null;
    },
    _Error: function _Error() {
    },
    _CastError: function _CastError(t0) {
      this._message = t0;
    },
    _TypeError: function _TypeError(t0) {
      this._message = t0;
    },
    extractKeys: function(victim) {
      return J.JSArray_JSArray$markFixed(victim ? Object.keys(victim) : [], type$.dynamic);
    },
    unmangleGlobalNameIfPreservedAnyways: function($name) {
      return init.mangledGlobalNames[$name];
    },
    printString: function(string) {
      if (typeof dartPrint == "function") {
        dartPrint(string);
        return;
      }
      if (typeof console == "object" && typeof console.log != "undefined") {
        console.log(string);
        return;
      }
      if (typeof window == "object")
        return;
      if (typeof print == "function") {
        print(string);
        return;
      }
      throw "Unable to print message: " + String(string);
    }
  },
  J = {
    makeDispatchRecord: function(interceptor, proto, extension, indexability) {
      return {i: interceptor, p: proto, e: extension, x: indexability};
    },
    getNativeInterceptor: function(object) {
      var proto, objectProto, $constructor, interceptor,
        record = object[init.dispatchPropertyName];
      if (record == null)
        if ($.initNativeDispatchFlag == null) {
          H.initNativeDispatch();
          record = object[init.dispatchPropertyName];
        }
      if (record != null) {
        proto = record.p;
        if (false === proto)
          return record.i;
        if (true === proto)
          return object;
        objectProto = Object.getPrototypeOf(object);
        if (proto === objectProto)
          return record.i;
        if (record.e === objectProto)
          throw H.wrapException(P.UnimplementedError$("Return interceptor for " + H.S(proto(object, record))));
      }
      $constructor = object.constructor;
      interceptor = $constructor == null ? null : $constructor[$.$get$JS_INTEROP_INTERCEPTOR_TAG()];
      if (interceptor != null)
        return interceptor;
      interceptor = H.lookupAndCacheInterceptor(object);
      if (interceptor != null)
        return interceptor;
      if (typeof object == "function")
        return C.JavaScriptFunction_methods;
      proto = Object.getPrototypeOf(object);
      if (proto == null)
        return C.PlainJavaScriptObject_methods;
      if (proto === Object.prototype)
        return C.PlainJavaScriptObject_methods;
      if (typeof $constructor == "function") {
        Object.defineProperty($constructor, $.$get$JS_INTEROP_INTERCEPTOR_TAG(), {value: C.UnknownJavaScriptObject_methods, enumerable: false, writable: true, configurable: true});
        return C.UnknownJavaScriptObject_methods;
      }
      return C.UnknownJavaScriptObject_methods;
    },
    JSArray_JSArray$fixed: function($length, $E) {
      if (!H._isInt($length))
        throw H.wrapException(P.ArgumentError$value($length, "length", "is not an integer"));
      if ($length < 0 || $length > 4294967295)
        throw H.wrapException(P.RangeError$range($length, 0, 4294967295, "length", null));
      return J.JSArray_JSArray$markFixed(new Array($length), $E);
    },
    JSArray_JSArray$markFixed: function(allocation, $E) {
      return J.JSArray_markFixedList(H.setRuntimeTypeInfo(allocation, $E._eval$1("JSArray<0>")));
    },
    JSArray_markFixedList: function(list) {
      list.fixed$length = Array;
      return list;
    },
    JSString__isWhitespace: function(codeUnit) {
      if (codeUnit < 256)
        switch (codeUnit) {
          case 9:
          case 10:
          case 11:
          case 12:
          case 13:
          case 32:
          case 133:
          case 160:
            return true;
          default:
            return false;
        }
      switch (codeUnit) {
        case 5760:
        case 8192:
        case 8193:
        case 8194:
        case 8195:
        case 8196:
        case 8197:
        case 8198:
        case 8199:
        case 8200:
        case 8201:
        case 8202:
        case 8232:
        case 8233:
        case 8239:
        case 8287:
        case 12288:
        case 65279:
          return true;
        default:
          return false;
      }
    },
    JSString__skipLeadingWhitespace: function(string, index) {
      var t1, codeUnit;
      for (t1 = string.length; index < t1;) {
        codeUnit = C.JSString_methods._codeUnitAt$1(string, index);
        if (codeUnit !== 32 && codeUnit !== 13 && !J.JSString__isWhitespace(codeUnit))
          break;
        ++index;
      }
      return index;
    },
    JSString__skipTrailingWhitespace: function(string, index) {
      var index0, codeUnit;
      for (; index > 0; index = index0) {
        index0 = index - 1;
        codeUnit = C.JSString_methods.codeUnitAt$1(string, index0);
        if (codeUnit !== 32 && codeUnit !== 13 && !J.JSString__isWhitespace(codeUnit))
          break;
      }
      return index;
    },
    getInterceptor$: function(receiver) {
      if (typeof receiver == "number") {
        if (Math.floor(receiver) == receiver)
          return J.JSInt.prototype;
        return J.JSDouble.prototype;
      }
      if (typeof receiver == "string")
        return J.JSString.prototype;
      if (receiver == null)
        return J.JSNull.prototype;
      if (typeof receiver == "boolean")
        return J.JSBool.prototype;
      if (receiver.constructor == Array)
        return J.JSArray.prototype;
      if (typeof receiver != "object") {
        if (typeof receiver == "function")
          return J.JavaScriptFunction.prototype;
        return receiver;
      }
      if (receiver instanceof P.Object)
        return receiver;
      return J.getNativeInterceptor(receiver);
    },
    getInterceptor$ansx: function(receiver) {
      if (typeof receiver == "number")
        return J.JSNumber.prototype;
      if (typeof receiver == "string")
        return J.JSString.prototype;
      if (receiver == null)
        return receiver;
      if (receiver.constructor == Array)
        return J.JSArray.prototype;
      if (typeof receiver != "object") {
        if (typeof receiver == "function")
          return J.JavaScriptFunction.prototype;
        return receiver;
      }
      if (receiver instanceof P.Object)
        return receiver;
      return J.getNativeInterceptor(receiver);
    },
    getInterceptor$asx: function(receiver) {
      if (typeof receiver == "string")
        return J.JSString.prototype;
      if (receiver == null)
        return receiver;
      if (receiver.constructor == Array)
        return J.JSArray.prototype;
      if (typeof receiver != "object") {
        if (typeof receiver == "function")
          return J.JavaScriptFunction.prototype;
        return receiver;
      }
      if (receiver instanceof P.Object)
        return receiver;
      return J.getNativeInterceptor(receiver);
    },
    getInterceptor$ax: function(receiver) {
      if (receiver == null)
        return receiver;
      if (receiver.constructor == Array)
        return J.JSArray.prototype;
      if (typeof receiver != "object") {
        if (typeof receiver == "function")
          return J.JavaScriptFunction.prototype;
        return receiver;
      }
      if (receiver instanceof P.Object)
        return receiver;
      return J.getNativeInterceptor(receiver);
    },
    getInterceptor$n: function(receiver) {
      if (typeof receiver == "number")
        return J.JSNumber.prototype;
      if (receiver == null)
        return receiver;
      if (!(receiver instanceof P.Object))
        return J.UnknownJavaScriptObject.prototype;
      return receiver;
    },
    getInterceptor$s: function(receiver) {
      if (typeof receiver == "string")
        return J.JSString.prototype;
      if (receiver == null)
        return receiver;
      if (!(receiver instanceof P.Object))
        return J.UnknownJavaScriptObject.prototype;
      return receiver;
    },
    getInterceptor$x: function(receiver) {
      if (receiver == null)
        return receiver;
      if (typeof receiver != "object") {
        if (typeof receiver == "function")
          return J.JavaScriptFunction.prototype;
        return receiver;
      }
      if (receiver instanceof P.Object)
        return receiver;
      return J.getNativeInterceptor(receiver);
    },
    get$first$ax: function(receiver) {
      return J.getInterceptor$ax(receiver).get$first(receiver);
    },
    get$hashCode$: function(receiver) {
      return J.getInterceptor$(receiver).get$hashCode(receiver);
    },
    get$isEmpty$asx: function(receiver) {
      return J.getInterceptor$asx(receiver).get$isEmpty(receiver);
    },
    get$iterator$ax: function(receiver) {
      return J.getInterceptor$ax(receiver).get$iterator(receiver);
    },
    get$last$ax: function(receiver) {
      return J.getInterceptor$ax(receiver).get$last(receiver);
    },
    get$length$asx: function(receiver) {
      return J.getInterceptor$asx(receiver).get$length(receiver);
    },
    get$message$x: function(receiver) {
      return J.getInterceptor$x(receiver).get$message(receiver);
    },
    get$runtimeType$: function(receiver) {
      return J.getInterceptor$(receiver).get$runtimeType(receiver);
    },
    get$startsWith$s: function(receiver) {
      return J.getInterceptor$s(receiver).get$startsWith(receiver);
    },
    $add$ansx: function(receiver, a0) {
      if (typeof receiver == "number" && typeof a0 == "number")
        return receiver + a0;
      return J.getInterceptor$ansx(receiver).$add(receiver, a0);
    },
    $eq$: function(receiver, a0) {
      if (receiver == null)
        return a0 == null;
      if (typeof receiver != "object")
        return a0 != null && receiver === a0;
      return J.getInterceptor$(receiver).$eq(receiver, a0);
    },
    $index$asx: function(receiver, a0) {
      if (typeof a0 === "number")
        if (receiver.constructor == Array || typeof receiver == "string" || H.isJsIndexable(receiver, receiver[init.dispatchPropertyName]))
          if (a0 >>> 0 === a0 && a0 < receiver.length)
            return receiver[a0];
      return J.getInterceptor$asx(receiver).$index(receiver, a0);
    },
    $indexSet$ax: function(receiver, a0, a1) {
      return J.getInterceptor$ax(receiver).$indexSet(receiver, a0, a1);
    },
    _codeUnitAt$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver)._codeUnitAt$1(receiver, a0);
    },
    _removeEventListener$3$x: function(receiver, a0, a1, a2) {
      return J.getInterceptor$x(receiver)._removeEventListener$3(receiver, a0, a1, a2);
    },
    addEventListener$3$x: function(receiver, a0, a1, a2) {
      return J.getInterceptor$x(receiver).addEventListener$3(receiver, a0, a1, a2);
    },
    allMatches$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).allMatches$1(receiver, a0);
    },
    allMatches$2$s: function(receiver, a0, a1) {
      return J.getInterceptor$s(receiver).allMatches$2(receiver, a0, a1);
    },
    codeUnitAt$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).codeUnitAt$1(receiver, a0);
    },
    contains$1$asx: function(receiver, a0) {
      return J.getInterceptor$asx(receiver).contains$1(receiver, a0);
    },
    elementAt$1$ax: function(receiver, a0) {
      return J.getInterceptor$ax(receiver).elementAt$1(receiver, a0);
    },
    endsWith$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).endsWith$1(receiver, a0);
    },
    fillRange$3$ax: function(receiver, a0, a1, a2) {
      return J.getInterceptor$ax(receiver).fillRange$3(receiver, a0, a1, a2);
    },
    map$1$1$ax: function(receiver, a0, $T1) {
      return J.getInterceptor$ax(receiver).map$1$1(receiver, a0, $T1);
    },
    matchAsPrefix$2$s: function(receiver, a0, a1) {
      return J.getInterceptor$s(receiver).matchAsPrefix$2(receiver, a0, a1);
    },
    padRight$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).padRight$1(receiver, a0);
    },
    replaceRange$3$asx: function(receiver, a0, a1, a2) {
      return J.getInterceptor$asx(receiver).replaceRange$3(receiver, a0, a1, a2);
    },
    startsWith$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).startsWith$1(receiver, a0);
    },
    startsWith$2$s: function(receiver, a0, a1) {
      return J.getInterceptor$s(receiver).startsWith$2(receiver, a0, a1);
    },
    substring$1$s: function(receiver, a0) {
      return J.getInterceptor$s(receiver).substring$1(receiver, a0);
    },
    substring$2$s: function(receiver, a0, a1) {
      return J.getInterceptor$s(receiver).substring$2(receiver, a0, a1);
    },
    toRadixString$1$n: function(receiver, a0) {
      return J.getInterceptor$n(receiver).toRadixString$1(receiver, a0);
    },
    toSet$0$ax: function(receiver) {
      return J.getInterceptor$ax(receiver).toSet$0(receiver);
    },
    toString$0$: function(receiver) {
      return J.getInterceptor$(receiver).toString$0(receiver);
    },
    trim$0$s: function(receiver) {
      return J.getInterceptor$s(receiver).trim$0(receiver);
    },
    Interceptor: function Interceptor() {
    },
    JSBool: function JSBool() {
    },
    JSNull: function JSNull() {
    },
    JSObject: function JSObject() {
    },
    JavaScriptObject: function JavaScriptObject() {
    },
    PlainJavaScriptObject: function PlainJavaScriptObject() {
    },
    UnknownJavaScriptObject: function UnknownJavaScriptObject() {
    },
    JavaScriptFunction: function JavaScriptFunction() {
    },
    JSArray: function JSArray(t0) {
      this.$ti = t0;
    },
    JSUnmodifiableArray: function JSUnmodifiableArray(t0) {
      this.$ti = t0;
    },
    ArrayIterator: function ArrayIterator(t0, t1, t2) {
      var _ = this;
      _._iterable = t0;
      _._length = t1;
      _._index = 0;
      _._current = null;
      _.$ti = t2;
    },
    JSNumber: function JSNumber() {
    },
    JSInt: function JSInt() {
    },
    JSDouble: function JSDouble() {
    },
    JSString: function JSString() {
    }
  },
  P = {
    _AsyncRun__initializeScheduleImmediate: function() {
      var div, span, t1 = {};
      if (self.scheduleImmediate != null)
        return P.async__AsyncRun__scheduleImmediateJsOverride$closure();
      if (self.MutationObserver != null && self.document != null) {
        div = self.document.createElement("div");
        span = self.document.createElement("span");
        t1.storedCallback = null;
        new self.MutationObserver(H.convertDartClosureToJS(new P._AsyncRun__initializeScheduleImmediate_internalCallback(t1), 1)).observe(div, {childList: true});
        return new P._AsyncRun__initializeScheduleImmediate_closure(t1, div, span);
      } else if (self.setImmediate != null)
        return P.async__AsyncRun__scheduleImmediateWithSetImmediate$closure();
      return P.async__AsyncRun__scheduleImmediateWithTimer$closure();
    },
    _AsyncRun__scheduleImmediateJsOverride: function(callback) {
      self.scheduleImmediate(H.convertDartClosureToJS(new P._AsyncRun__scheduleImmediateJsOverride_internalCallback(type$.void_Function._check(callback)), 0));
    },
    _AsyncRun__scheduleImmediateWithSetImmediate: function(callback) {
      self.setImmediate(H.convertDartClosureToJS(new P._AsyncRun__scheduleImmediateWithSetImmediate_internalCallback(type$.void_Function._check(callback)), 0));
    },
    _AsyncRun__scheduleImmediateWithTimer: function(callback) {
      P.Timer__createTimer(C.Duration_0, type$.void_Function._check(callback));
    },
    Timer__createTimer: function(duration, callback) {
      var milliseconds = C.JSInt_methods._tdivFast$1(duration._duration, 1000);
      return P._TimerImpl$(milliseconds < 0 ? 0 : milliseconds, callback);
    },
    _TimerImpl$: function(milliseconds, callback) {
      var t1 = new P._TimerImpl(true);
      t1._TimerImpl$2(milliseconds, callback);
      return t1;
    },
    _TimerImpl$periodic: function(milliseconds, callback) {
      var t1 = new P._TimerImpl(false);
      t1._TimerImpl$periodic$2(milliseconds, callback);
      return t1;
    },
    _makeAsyncAwaitCompleter: function($T) {
      return new P._AsyncAwaitCompleter(new P._Future($.Zone__current, $T._eval$1("_Future<0>")), $T._eval$1("_AsyncAwaitCompleter<0>"));
    },
    _asyncStartSync: function(bodyFunction, completer) {
      bodyFunction.call$2(0, null);
      completer.isSync = true;
      return completer._future;
    },
    _asyncAwait: function(object, bodyFunction) {
      P._awaitOnObject(object, bodyFunction);
    },
    _asyncReturn: function(object, completer) {
      completer.complete$1(object);
    },
    _asyncRethrow: function(object, completer) {
      completer.completeError$2(H.unwrapException(object), H.getTraceFromException(object));
    },
    _awaitOnObject: function(object, bodyFunction) {
      var t1, future,
        thenCallback = new P._awaitOnObject_closure(bodyFunction),
        errorCallback = new P._awaitOnObject_closure0(bodyFunction);
      if (object instanceof P._Future)
        object._thenAwait$1$2(thenCallback, errorCallback, type$.dynamic);
      else {
        t1 = type$.dynamic;
        if (type$.Future_dynamic._is(object))
          object.then$1$2$onError(thenCallback, errorCallback, t1);
        else {
          future = new P._Future($.Zone__current, type$._Future_dynamic);
          future._state = 4;
          future._resultOrListeners = object;
          future._thenAwait$1$2(thenCallback, null, t1);
        }
      }
    },
    _wrapJsFunctionForAsync: function($function) {
      var $protected = function(fn, ERROR) {
        return function(errorCode, result) {
          while (true)
            try {
              fn(errorCode, result);
              break;
            } catch (error) {
              result = error;
              errorCode = ERROR;
            }
        };
      }($function, 1);
      return $.Zone__current.registerBinaryCallback$3$1(new P._wrapJsFunctionForAsync_closure($protected), type$.Null, type$.int, type$.dynamic);
    },
    Future_Future: function(computation, $T) {
      var result = new P._Future($.Zone__current, $T._eval$1("_Future<0>"));
      P.Timer_Timer(C.Duration_0, new P.Future_Future_closure(result, computation));
      return result;
    },
    Future_Future$microtask: function(computation, $T) {
      var result = new P._Future($.Zone__current, $T._eval$1("_Future<0>"));
      P.scheduleMicrotask(new P.Future_Future$microtask_closure(result, computation));
      return result;
    },
    Future_Future$sync: function(computation, $T) {
      var result, error, stackTrace, future, replacement, t1, t2, exception;
      try {
        result = computation.call$0();
        if ($T._eval$1("Future<0>")._is(result))
          return result;
        else {
          t1 = $T._check(result);
          t2 = new P._Future($.Zone__current, $T._eval$1("_Future<0>"));
          t2._state = 4;
          t2._resultOrListeners = t1;
          return t2;
        }
      } catch (exception) {
        error = H.unwrapException(exception);
        stackTrace = H.getTraceFromException(exception);
        t1 = $.Zone__current;
        future = new P._Future(t1, $T._eval$1("_Future<0>"));
        replacement = t1.errorCallback$2(error, stackTrace);
        if (replacement != null) {
          t1 = replacement.error;
          if (t1 == null)
            t1 = new P.NullThrownError();
          future._asyncCompleteError$2(t1, replacement.stackTrace);
        } else
          future._asyncCompleteError$2(error, stackTrace);
        return future;
      }
    },
    Future_Future$error: function(error, stackTrace, $T) {
      var replacement,
        t1 = $.Zone__current;
      if (t1 !== C.C__RootZone) {
        replacement = t1.errorCallback$2(error, stackTrace);
        if (replacement != null) {
          error = replacement.error;
          if (error == null)
            error = new P.NullThrownError();
          stackTrace = replacement.stackTrace;
        }
      }
      t1 = new P._Future($.Zone__current, $T._eval$1("_Future<0>"));
      t1._asyncCompleteError$2(error, stackTrace);
      return t1;
    },
    Future_wait: function(futures, eagerError, $T) {
      var handleError, future, pos, e, st, t2, t3, _i, t4, exception, _box_0 = {}, cleanUp = null,
        t1 = $T._eval$1("_Future<List<0>>"),
        result = new P._Future($.Zone__current, t1);
      _box_0.values = null;
      _box_0.remaining = 0;
      _box_0.stackTrace = _box_0.error = null;
      handleError = new P.Future_wait_handleError(_box_0, cleanUp, true, result);
      try {
        for (t2 = futures.length, t3 = type$.Null, _i = 0, t4 = 0; _i < futures.length; futures.length === t2 || (0, H.throwConcurrentModificationError)(futures), ++_i) {
          future = futures[_i];
          pos = t4;
          future.then$1$2$onError(new P.Future_wait_closure(_box_0, pos, result, cleanUp, true, $T), handleError, t3);
          t4 = ++_box_0.remaining;
        }
        if (t4 === 0) {
          t1 = new P._Future($.Zone__current, t1);
          t1._asyncComplete$1(C.List_empty1);
          return t1;
        }
        t1 = new Array(t4);
        t1.fixed$length = Array;
        _box_0.values = H.setRuntimeTypeInfo(t1, $T._eval$1("JSArray<0>"));
      } catch (exception) {
        e = H.unwrapException(exception);
        st = H.getTraceFromException(exception);
        t1 = P.Future_Future$error(e, st, $T._eval$1("List<0>"));
        return t1;
      }
      return result;
    },
    Future_forEach: function(elements, action, $T) {
      return P.Future_doWhile(new P.Future_forEach_closure(new J.ArrayIterator(elements, 0, H._arrayInstanceType(elements)._eval$1("ArrayIterator<1>")), action));
    },
    Future__kTrue: function(_) {
      return true;
    },
    Future_doWhile: function(action) {
      var nextIteration, t1 = {},
        t2 = $.Zone__current,
        doneSignal = new P._Future(t2, type$._Future_dynamic);
      t1.nextIteration = null;
      nextIteration = t2.bindUnaryCallbackGuarded$1$1(new P.Future_doWhile_closure(t1, action, doneSignal), type$.bool);
      t1.nextIteration = nextIteration;
      nextIteration.call$1(true);
      return doneSignal;
    },
    _completeWithErrorCallback: function(result, error, stackTrace) {
      var replacement = $.Zone__current.errorCallback$2(error, stackTrace);
      if (replacement != null) {
        error = replacement.error;
        if (error == null)
          error = new P.NullThrownError();
        stackTrace = replacement.stackTrace;
      }
      result._completeError$2(error, stackTrace);
    },
    _Future$zoneValue: function(value, _zone, $T) {
      var t1 = new P._Future(_zone, $T._eval$1("_Future<0>"));
      $T._check(value);
      t1._state = 4;
      t1._resultOrListeners = value;
      return t1;
    },
    _Future__chainForeignFuture: function(source, target) {
      var e, s, exception;
      H.assertHelper(target._state < 4);
      H.assertHelper(!(source instanceof P._Future));
      H.assertHelper(target._state === 0);
      target._state = 1;
      try {
        source.then$1$2$onError(new P._Future__chainForeignFuture_closure(target), new P._Future__chainForeignFuture_closure0(target), type$.Null);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P.scheduleMicrotask(new P._Future__chainForeignFuture_closure1(target, e, s));
      }
    },
    _Future__chainCoreFuture: function(source, target) {
      var t1, t2, t3, listeners;
      H.assertHelper(target._state <= 1);
      for (t1 = type$._Future_dynamic; t2 = source._state, t3 = t2 === 2, t3;) {
        H.assertHelper(t3);
        source = t1._check(source._resultOrListeners);
      }
      if (t2 >= 4) {
        listeners = target._removeListeners$0();
        target._cloneResult$1(source);
        P._Future__propagateToListeners(target, listeners);
      } else {
        listeners = type$._FutureListener_dynamic_dynamic._check(target._resultOrListeners);
        H.assertHelper(target._state <= 1);
        target._state = 2;
        target._resultOrListeners = source;
        source._prependListeners$1(listeners);
      }
    },
    _Future__propagateToListeners: function(source, listeners) {
      var t2, t3, t4, _box_0, hasError, asyncError, listeners0, sourceResult, t5, t6, zone, previous, oldZone, current, result, _box_1 = {},
        t1 = _box_1.source = source;
      for (t2 = type$.AsyncError, t3 = type$._FutureListener_dynamic_dynamic, t4 = type$.Future_dynamic; true;) {
        _box_0 = {};
        H.assertHelper(t1._state >= 4);
        t1 = _box_1.source;
        hasError = t1._state === 8;
        if (listeners == null) {
          if (hasError) {
            asyncError = t2._check(t1._resultOrListeners);
            t1._zone.handleUncaughtError$2(asyncError.error, asyncError.stackTrace);
          }
          return;
        }
        for (; listeners0 = listeners._nextListener, listeners0 != null; listeners = listeners0) {
          listeners._nextListener = null;
          P._Future__propagateToListeners(_box_1.source, listeners);
        }
        t1 = _box_1.source;
        sourceResult = t1._resultOrListeners;
        _box_0.listenerHasError = hasError;
        _box_0.listenerValueOrError = sourceResult;
        t5 = !hasError;
        if (t5) {
          t6 = listeners.state;
          t6 = (t6 & 1) !== 0 || (t6 & 15) === 8;
        } else
          t6 = true;
        if (t6) {
          t6 = listeners.result;
          zone = t6._zone;
          if (hasError) {
            t1 = t1._zone;
            t1 = !(t1 === zone || t1.get$errorZone() === zone.get$errorZone());
          } else
            t1 = false;
          if (t1) {
            t1 = _box_1.source;
            H.assertHelper(t1._state === 8);
            asyncError = t2._check(t1._resultOrListeners);
            _box_1.source._zone.handleUncaughtError$2(asyncError.error, asyncError.stackTrace);
            return;
          }
          t1 = $.Zone__current;
          if (t1 !== zone) {
            H.assertHelper(zone !== t1);
            previous = $.Zone__current;
            $.Zone__current = zone;
            oldZone = previous;
          } else
            oldZone = null;
          t1 = listeners.state;
          if ((t1 & 15) === 8)
            new P._Future__propagateToListeners_handleWhenCompleteCallback(_box_1, _box_0, listeners, hasError).call$0();
          else if (t5) {
            if ((t1 & 1) !== 0)
              new P._Future__propagateToListeners_handleValueCallback(_box_0, listeners, sourceResult).call$0();
          } else if ((t1 & 2) !== 0)
            new P._Future__propagateToListeners_handleError(_box_1, _box_0, listeners).call$0();
          if (oldZone != null)
            $.Zone__current = oldZone;
          t1 = _box_0.listenerValueOrError;
          if (t4._is(t1)) {
            if (t1._state >= 4) {
              H.assertHelper(t6._state < 4);
              current = t3._check(t6._resultOrListeners);
              t6._resultOrListeners = null;
              listeners = t6._reverseListeners$1(current);
              H.assertHelper(t6._state < 4);
              H.assertHelper(t1._state >= 4);
              t6._state = t1._state;
              t6._resultOrListeners = t1._resultOrListeners;
              _box_1.source = t1;
              continue;
            } else
              P._Future__chainCoreFuture(t1, t6);
            return;
          }
        }
        result = listeners.result;
        H.assertHelper(result._state < 4);
        current = t3._check(result._resultOrListeners);
        result._resultOrListeners = null;
        listeners = result._reverseListeners$1(current);
        t1 = _box_0.listenerHasError;
        t5 = _box_0.listenerValueOrError;
        t6 = result._state >= 4;
        if (!t1) {
          result.$ti._precomputed1._check(t5);
          H.assertHelper(!t6);
          result._state = 4;
          result._resultOrListeners = t5;
        } else {
          t2._check(t5);
          H.assertHelper(!t6);
          result._state = 8;
          result._resultOrListeners = t5;
        }
        _box_1.source = result;
        t1 = result;
      }
    },
    _registerErrorHandler: function(errorHandler, zone) {
      if (type$.dynamic_Function_Object_StackTrace._is(errorHandler))
        return zone.registerBinaryCallback$3$1(errorHandler, type$.dynamic, type$.Object, type$.StackTrace);
      if (type$.dynamic_Function_Object._is(errorHandler))
        return zone.registerUnaryCallback$2$1(errorHandler, type$.dynamic, type$.Object);
      throw H.wrapException(P.ArgumentError$value(errorHandler, "onError", "Error handler must accept one Object or one Object and a StackTrace as arguments, and return a a valid result"));
    },
    _microtaskLoop: function() {
      var t1, t2;
      for (; t1 = $._nextCallback, t1 != null;) {
        $._lastPriorityCallback = null;
        t2 = t1.next;
        $._nextCallback = t2;
        if (t2 == null)
          $._lastCallback = null;
        t1.callback.call$0();
      }
    },
    _startMicrotaskLoop: function() {
      $._isInCallbackLoop = true;
      try {
        P._microtaskLoop();
      } finally {
        $._lastPriorityCallback = null;
        $._isInCallbackLoop = false;
        if ($._nextCallback != null)
          $.$get$_AsyncRun__scheduleImmediateClosure().call$1(P.async___startMicrotaskLoop$closure());
      }
    },
    _scheduleAsyncCallback: function(callback) {
      var newEntry = new P._AsyncCallbackEntry(callback);
      if ($._nextCallback == null) {
        $._nextCallback = $._lastCallback = newEntry;
        if (!$._isInCallbackLoop)
          $.$get$_AsyncRun__scheduleImmediateClosure().call$1(P.async___startMicrotaskLoop$closure());
      } else
        $._lastCallback = $._lastCallback.next = newEntry;
    },
    _schedulePriorityAsyncCallback: function(callback) {
      var entry, t2,
        t1 = $._nextCallback;
      if (t1 == null) {
        P._scheduleAsyncCallback(callback);
        $._lastPriorityCallback = $._lastCallback;
        return;
      }
      entry = new P._AsyncCallbackEntry(callback);
      t2 = $._lastPriorityCallback;
      if (t2 == null) {
        entry.next = t1;
        $._nextCallback = $._lastPriorityCallback = entry;
      } else {
        entry.next = t2.next;
        $._lastPriorityCallback = t2.next = entry;
        if (entry.next == null)
          $._lastCallback = entry;
      }
    },
    scheduleMicrotask: function(callback) {
      var t1, _null = null,
        currentZone = $.Zone__current;
      if (C.C__RootZone === currentZone) {
        P._rootScheduleMicrotask(_null, _null, C.C__RootZone, callback);
        return;
      }
      if (C.C__RootZone === currentZone.get$_scheduleMicrotask().zone)
        t1 = C.C__RootZone.get$errorZone() === currentZone.get$errorZone();
      else
        t1 = false;
      if (t1) {
        P._rootScheduleMicrotask(_null, _null, currentZone, currentZone.registerCallback$1$1(callback, type$.void));
        return;
      }
      t1 = $.Zone__current;
      t1.scheduleMicrotask$1(t1.bindCallbackGuarded$1(callback));
    },
    Stream_Stream$fromFuture: function(future, $T) {
      var _null = null,
        t1 = $T._eval$1("_SyncStreamController<0>"),
        controller = new P._SyncStreamController(_null, _null, _null, _null, t1);
      future.then$1$2$onError(new P.Stream_Stream$fromFuture_closure(controller, $T), new P.Stream_Stream$fromFuture_closure0(controller), type$.Null);
      return new P._ControllerStream(controller, t1._eval$1("_ControllerStream<1>"));
    },
    Stream_Stream$fromIterable: function(elements, $T) {
      return new P._GeneratedStreamImpl(new P.Stream_Stream$fromIterable_closure(elements, $T), $T._eval$1("_GeneratedStreamImpl<0>"));
    },
    StreamIterator_StreamIterator: function(stream, $T) {
      if (stream == null)
        H.throwExpression(P.ArgumentError$notNull("stream"));
      return new P._StreamIterator($T._eval$1("_StreamIterator<0>"));
    },
    StreamController_StreamController: function(onCancel, onListen, sync, $T) {
      var _null = null;
      return sync ? new P._SyncStreamController(onListen, _null, _null, onCancel, $T._eval$1("_SyncStreamController<0>")) : new P._AsyncStreamController(onListen, _null, _null, onCancel, $T._eval$1("_AsyncStreamController<0>"));
    },
    _runGuarded: function(notificationHandler) {
      var e, s, exception;
      if (notificationHandler == null)
        return;
      try {
        notificationHandler.call$0();
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        $.Zone__current.handleUncaughtError$2(e, s);
      }
    },
    _AddStreamState_makeErrorHandler: function(controller) {
      return new P._AddStreamState_makeErrorHandler_closure(controller);
    },
    _BufferingStreamSubscription$: function(onData, onError, onDone, cancelOnError, $T) {
      var t1 = $.Zone__current,
        t2 = cancelOnError ? 1 : 0;
      t2 = new P._BufferingStreamSubscription(t1, t2, $T._eval$1("_BufferingStreamSubscription<0>"));
      t2._BufferingStreamSubscription$4(onData, onError, onDone, cancelOnError, $T);
      return t2;
    },
    _nullDataHandler: function(value) {
    },
    _nullErrorHandler: function(error, stackTrace) {
      type$.StackTrace._check(stackTrace);
      $.Zone__current.handleUncaughtError$2(error, stackTrace);
    },
    _nullDoneHandler: function() {
    },
    _runUserCode: function(userCode, onSuccess, onError, $T) {
      var e, s, replacement, error, stackTrace, exception, error0;
      try {
        onSuccess.call$1(userCode.call$0());
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        replacement = $.Zone__current.errorCallback$2(e, s);
        if (replacement == null)
          onError.call$2(e, s);
        else {
          error0 = replacement.error;
          error = error0 == null ? new P.NullThrownError() : error0;
          stackTrace = replacement.stackTrace;
          onError.call$2(error, stackTrace);
        }
      }
    },
    _cancelAndError: function(subscription, future, error, stackTrace) {
      var cancelFuture = subscription.cancel$0();
      if (cancelFuture != null && cancelFuture !== $.$get$Future__nullFuture())
        cancelFuture.whenComplete$1(new P._cancelAndError_closure(future, error, stackTrace));
      else
        future._completeError$2(error, stackTrace);
    },
    _cancelAndErrorClosure: function(subscription, future) {
      return new P._cancelAndErrorClosure_closure(subscription, future);
    },
    _cancelAndValue: function(subscription, future, value) {
      var cancelFuture = subscription.cancel$0();
      if (cancelFuture != null && cancelFuture !== $.$get$Future__nullFuture())
        cancelFuture.whenComplete$1(new P._cancelAndValue_closure(future, value));
      else
        future._complete$1(value);
    },
    Timer_Timer: function(duration, callback) {
      var t1 = $.Zone__current;
      if (t1 === C.C__RootZone)
        return t1.createTimer$2(duration, callback);
      return t1.createTimer$2(duration, t1.bindCallbackGuarded$1(callback));
    },
    _ZoneSpecification$: function(createPeriodicTimer, createTimer, errorCallback, fork, handleUncaughtError, $print, registerBinaryCallback, registerCallback, registerUnaryCallback, run, runBinary, runUnary, scheduleMicrotask) {
      return new P._ZoneSpecification(handleUncaughtError, run, runUnary, runBinary, registerCallback, registerUnaryCallback, registerBinaryCallback, errorCallback, scheduleMicrotask, createTimer, createPeriodicTimer, $print, fork);
    },
    Zone__enter: function(zone) {
      var previous;
      H.assertHelper(zone != null);
      H.assertHelper(zone !== $.Zone__current);
      previous = $.Zone__current;
      $.Zone__current = zone;
      return previous;
    },
    _parentDelegate: function(zone) {
      if (zone.get$parent(zone) == null)
        return null;
      return zone.get$parent(zone).get$_delegate();
    },
    _rootHandleUncaughtError: function($self, $parent, zone, error, stackTrace) {
      var t1 = {};
      t1.error = error;
      P._schedulePriorityAsyncCallback(new P._rootHandleUncaughtError_closure(t1, type$.StackTrace._check(stackTrace)));
    },
    _rootRun: function($self, $parent, zone, f, $R) {
      var old,
        t1 = type$.Zone;
      t1._check($self);
      type$.ZoneDelegate._check($parent);
      t1._check(zone);
      $R._eval$1("0()")._check(f);
      if ($.Zone__current === zone)
        return f.call$0();
      old = P.Zone__enter(zone);
      try {
        t1 = f.call$0();
        return t1;
      } finally {
        t1 = old;
        H.assertHelper(t1 != null);
        $.Zone__current = t1;
      }
    },
    _rootRunUnary: function($self, $parent, zone, f, arg, $R, $T) {
      var old,
        t1 = type$.Zone;
      t1._check($self);
      type$.ZoneDelegate._check($parent);
      t1._check(zone);
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
      $T._check(arg);
      if ($.Zone__current === zone)
        return f.call$1(arg);
      old = P.Zone__enter(zone);
      try {
        t1 = f.call$1(arg);
        return t1;
      } finally {
        t1 = old;
        H.assertHelper(t1 != null);
        $.Zone__current = t1;
      }
    },
    _rootRunBinary: function($self, $parent, zone, f, arg1, arg2, $R, T1, T2) {
      var old,
        t1 = type$.Zone;
      t1._check($self);
      type$.ZoneDelegate._check($parent);
      t1._check(zone);
      $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
      T1._check(arg1);
      T2._check(arg2);
      if ($.Zone__current === zone)
        return f.call$2(arg1, arg2);
      old = P.Zone__enter(zone);
      try {
        t1 = f.call$2(arg1, arg2);
        return t1;
      } finally {
        t1 = old;
        H.assertHelper(t1 != null);
        $.Zone__current = t1;
      }
    },
    _rootRegisterCallback: function($self, $parent, zone, f, $R) {
      return $R._eval$1("0()")._check(f);
    },
    _rootRegisterUnaryCallback: function($self, $parent, zone, f, $R, $T) {
      return $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
    },
    _rootRegisterBinaryCallback: function($self, $parent, zone, f, $R, T1, T2) {
      return $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
    },
    _rootErrorCallback: function($self, $parent, zone, error, stackTrace) {
      type$.StackTrace._check(stackTrace);
      return null;
    },
    _rootScheduleMicrotask: function($self, $parent, zone, f) {
      var t1;
      type$.void_Function._check(f);
      t1 = C.C__RootZone !== zone;
      if (t1)
        f = !(!t1 || C.C__RootZone.get$errorZone() === zone.get$errorZone()) ? zone.bindCallbackGuarded$1(f) : zone.bindCallback$1$1(f, type$.void);
      P._scheduleAsyncCallback(f);
    },
    _rootCreateTimer: function($self, $parent, zone, duration, callback) {
      type$.Duration._check(duration);
      callback = zone.bindCallback$1$1(type$.void_Function._check(callback), type$.void);
      return P.Timer__createTimer(duration, callback);
    },
    _rootCreatePeriodicTimer: function($self, $parent, zone, duration, callback) {
      var milliseconds;
      type$.Duration._check(duration);
      callback = zone.bindUnaryCallback$2$1(type$.void_Function_Timer._check(callback), type$.dynamic, type$.Timer);
      milliseconds = C.JSInt_methods._tdivFast$1(duration._duration, 1000);
      return P._TimerImpl$periodic(milliseconds < 0 ? 0 : milliseconds, callback);
    },
    _rootPrint: function($self, $parent, zone, line) {
      H.printString(H._checkStringNullable(line));
    },
    _printToZone: function(line) {
      $.Zone__current.print$1(0, line);
    },
    _rootFork: function($self, $parent, zone, specification, zoneValues) {
      var valueMap, t1, t2;
      type$.ZoneSpecification._check(specification);
      type$.Map_dynamic_dynamic._check(zoneValues);
      $.printToZone = P.async___printToZone$closure();
      if (specification == null)
        specification = C._ZoneSpecification_ALf;
      if (zoneValues == null)
        valueMap = zone.get$_async$_map();
      else {
        t1 = type$.dynamic;
        valueMap = P.HashMap_HashMap$from(zoneValues, t1, t1);
      }
      t1 = new P._CustomZone(zone, valueMap);
      t2 = zone.get$_run();
      t1.set$_run(t2);
      t2 = zone.get$_runUnary();
      t1.set$_runUnary(t2);
      t2 = zone.get$_runBinary();
      t1.set$_runBinary(t2);
      t2 = specification.registerCallback;
      t1.set$_registerCallback(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_Function) : zone.get$_registerCallback());
      t2 = specification.registerUnaryCallback;
      t1.set$_registerUnaryCallback(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_Function) : zone.get$_registerUnaryCallback());
      t2 = specification.registerBinaryCallback;
      t1.set$_registerBinaryCallback(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_Function) : zone.get$_registerBinaryCallback());
      t2 = specification.errorCallback;
      t1.set$_errorCallback(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_of_AsyncError_Function_Zone_ZoneDelegate_Zone_Object_StackTrace) : zone.get$_errorCallback());
      t2 = zone.get$_scheduleMicrotask();
      t1.set$_scheduleMicrotask(t2);
      t2 = zone.get$_createTimer();
      t1.set$_createTimer(t2);
      t2 = zone.get$_createPeriodicTimer();
      t1.set$_createPeriodicTimer(t2);
      t2 = specification.print;
      t1.set$_print(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_String) : zone.get$_print());
      t2 = zone.get$_fork();
      t1.set$_fork(t2);
      t2 = specification.handleUncaughtError;
      t1.set$_handleUncaughtError(t2 != null ? new P._ZoneFunction(t1, t2, type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_Object_StackTrace) : zone.get$_handleUncaughtError());
      return t1;
    },
    runZoned: function(body, onError, zoneSpecification, zoneValues, $R) {
      var e, stackTrace, errorHandler, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, exception, _null = null, t1 = {};
      if (onError == null)
        return P._runZoned(body, zoneValues, zoneSpecification, $R);
      t1.binaryOnError = t1.unaryOnError = null;
      if (type$.void_Function_Object_StackTrace._is(onError))
        t1.binaryOnError = onError;
      else if (type$.void_Function_Object._is(onError))
        t1.unaryOnError = onError;
      else
        throw H.wrapException(P.ArgumentError$("onError callback must take either an Object (the error), or both an Object (the error) and a StackTrace."));
      errorHandler = new P.runZoned_closure(t1);
      if (zoneSpecification == null)
        zoneSpecification = P._ZoneSpecification$(_null, _null, _null, _null, errorHandler, _null, _null, _null, _null, _null, _null, _null, _null);
      else {
        t2 = zoneSpecification;
        t3 = t2.run;
        t4 = t2.runUnary;
        t5 = t2.runBinary;
        t6 = t2.registerCallback;
        t7 = t2.registerUnaryCallback;
        t8 = t2.registerBinaryCallback;
        t9 = t2.errorCallback;
        t10 = t2.scheduleMicrotask;
        t11 = t2.createTimer;
        t12 = t2.createPeriodicTimer;
        t13 = t2.print;
        zoneSpecification = P._ZoneSpecification$(t12, t11, t9, t2.fork, errorHandler, t13, t8, t6, t7, t3, t5, t4, t10);
      }
      try {
        t2 = P._runZoned(body, zoneValues, zoneSpecification, $R);
        return t2;
      } catch (exception) {
        e = H.unwrapException(exception);
        stackTrace = H.getTraceFromException(exception);
        t2 = t1.binaryOnError;
        if (t2 != null)
          t2.call$2(e, stackTrace);
        else {
          H.assertHelper(t1.unaryOnError != null);
          t1.unaryOnError.call$1(e);
        }
      }
      return _null;
    },
    _runZoned: function(body, zoneValues, specification, $R) {
      return $.Zone__current.fork$2$specification$zoneValues(specification, zoneValues).run$1$1(body, $R);
    },
    _AsyncRun__initializeScheduleImmediate_internalCallback: function _AsyncRun__initializeScheduleImmediate_internalCallback(t0) {
      this._box_0 = t0;
    },
    _AsyncRun__initializeScheduleImmediate_closure: function _AsyncRun__initializeScheduleImmediate_closure(t0, t1, t2) {
      this._box_0 = t0;
      this.div = t1;
      this.span = t2;
    },
    _AsyncRun__scheduleImmediateJsOverride_internalCallback: function _AsyncRun__scheduleImmediateJsOverride_internalCallback(t0) {
      this.callback = t0;
    },
    _AsyncRun__scheduleImmediateWithSetImmediate_internalCallback: function _AsyncRun__scheduleImmediateWithSetImmediate_internalCallback(t0) {
      this.callback = t0;
    },
    _TimerImpl: function _TimerImpl(t0) {
      this._once = t0;
      this._handle = null;
      this._tick = 0;
    },
    _TimerImpl_internalCallback: function _TimerImpl_internalCallback(t0, t1) {
      this.$this = t0;
      this.callback = t1;
    },
    _TimerImpl$periodic_closure: function _TimerImpl$periodic_closure(t0, t1, t2, t3) {
      var _ = this;
      _.$this = t0;
      _.milliseconds = t1;
      _.start = t2;
      _.callback = t3;
    },
    _AsyncAwaitCompleter: function _AsyncAwaitCompleter(t0, t1) {
      this._future = t0;
      this.isSync = false;
      this.$ti = t1;
    },
    _awaitOnObject_closure: function _awaitOnObject_closure(t0) {
      this.bodyFunction = t0;
    },
    _awaitOnObject_closure0: function _awaitOnObject_closure0(t0) {
      this.bodyFunction = t0;
    },
    _wrapJsFunctionForAsync_closure: function _wrapJsFunctionForAsync_closure(t0) {
      this.$protected = t0;
    },
    _BroadcastStream: function _BroadcastStream(t0, t1) {
      this._controller = t0;
      this.$ti = t1;
    },
    _BroadcastSubscription: function _BroadcastSubscription(t0, t1, t2, t3) {
      var _ = this;
      _._eventState = 0;
      _._async$_previous = _._async$_next = null;
      _._controller = t0;
      _._onDone = _._onError = _._onData = null;
      _._zone = t1;
      _._state = t2;
      _._pending = _._cancelFuture = null;
      _.$ti = t3;
    },
    _BroadcastStreamController: function _BroadcastStreamController() {
    },
    _SyncBroadcastStreamController: function _SyncBroadcastStreamController(t0, t1, t2) {
      var _ = this;
      _.onListen = t0;
      _.onCancel = t1;
      _._state = 0;
      _._doneFuture = _._addStreamState = _._lastSubscription = _._firstSubscription = null;
      _.$ti = t2;
    },
    _SyncBroadcastStreamController__sendData_closure: function _SyncBroadcastStreamController__sendData_closure(t0, t1) {
      this.$this = t0;
      this.data = t1;
    },
    _SyncBroadcastStreamController__sendError_closure: function _SyncBroadcastStreamController__sendError_closure(t0, t1, t2) {
      this.$this = t0;
      this.error = t1;
      this.stackTrace = t2;
    },
    _SyncBroadcastStreamController__sendDone_closure: function _SyncBroadcastStreamController__sendDone_closure(t0) {
      this.$this = t0;
    },
    _AsyncBroadcastStreamController: function _AsyncBroadcastStreamController(t0, t1, t2) {
      var _ = this;
      _.onListen = t0;
      _.onCancel = t1;
      _._state = 0;
      _._doneFuture = _._addStreamState = _._lastSubscription = _._firstSubscription = null;
      _.$ti = t2;
    },
    Future: function Future() {
    },
    Future_Future_closure: function Future_Future_closure(t0, t1) {
      this.result = t0;
      this.computation = t1;
    },
    Future_Future$microtask_closure: function Future_Future$microtask_closure(t0, t1) {
      this.result = t0;
      this.computation = t1;
    },
    Future_wait_handleError: function Future_wait_handleError(t0, t1, t2, t3) {
      var _ = this;
      _._box_0 = t0;
      _.cleanUp = t1;
      _.eagerError = t2;
      _.result = t3;
    },
    Future_wait_closure: function Future_wait_closure(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _._box_0 = t0;
      _.pos = t1;
      _.result = t2;
      _.cleanUp = t3;
      _.eagerError = t4;
      _.T = t5;
    },
    Future_forEach_closure: function Future_forEach_closure(t0, t1) {
      this.iterator = t0;
      this.action = t1;
    },
    Future_doWhile_closure: function Future_doWhile_closure(t0, t1, t2) {
      this._box_0 = t0;
      this.action = t1;
      this.doneSignal = t2;
    },
    TimeoutException: function TimeoutException(t0, t1) {
      this.message = t0;
      this.duration = t1;
    },
    Completer: function Completer() {
    },
    _Completer: function _Completer() {
    },
    _AsyncCompleter: function _AsyncCompleter(t0, t1) {
      this.future = t0;
      this.$ti = t1;
    },
    _SyncCompleter: function _SyncCompleter(t0, t1) {
      this.future = t0;
      this.$ti = t1;
    },
    _FutureListener: function _FutureListener(t0, t1, t2, t3, t4) {
      var _ = this;
      _._nextListener = null;
      _.result = t0;
      _.state = t1;
      _.callback = t2;
      _.errorCallback = t3;
      _.$ti = t4;
    },
    _Future: function _Future(t0, t1) {
      var _ = this;
      _._state = 0;
      _._zone = t0;
      _._resultOrListeners = null;
      _.$ti = t1;
    },
    _Future__addListener_closure: function _Future__addListener_closure(t0, t1) {
      this.$this = t0;
      this.listener = t1;
    },
    _Future__prependListeners_closure: function _Future__prependListeners_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    _Future__chainForeignFuture_closure: function _Future__chainForeignFuture_closure(t0) {
      this.target = t0;
    },
    _Future__chainForeignFuture_closure0: function _Future__chainForeignFuture_closure0(t0) {
      this.target = t0;
    },
    _Future__chainForeignFuture_closure1: function _Future__chainForeignFuture_closure1(t0, t1, t2) {
      this.target = t0;
      this.e = t1;
      this.s = t2;
    },
    _Future__asyncComplete_closure: function _Future__asyncComplete_closure(t0, t1) {
      this.$this = t0;
      this.value = t1;
    },
    _Future__chainFuture_closure: function _Future__chainFuture_closure(t0, t1) {
      this.$this = t0;
      this.value = t1;
    },
    _Future__asyncCompleteError_closure: function _Future__asyncCompleteError_closure(t0, t1, t2) {
      this.$this = t0;
      this.error = t1;
      this.stackTrace = t2;
    },
    _Future__propagateToListeners_handleWhenCompleteCallback: function _Future__propagateToListeners_handleWhenCompleteCallback(t0, t1, t2, t3) {
      var _ = this;
      _._box_1 = t0;
      _._box_0 = t1;
      _.listener = t2;
      _.hasError = t3;
    },
    _Future__propagateToListeners_handleWhenCompleteCallback_closure: function _Future__propagateToListeners_handleWhenCompleteCallback_closure(t0) {
      this.originalSource = t0;
    },
    _Future__propagateToListeners_handleValueCallback: function _Future__propagateToListeners_handleValueCallback(t0, t1, t2) {
      this._box_0 = t0;
      this.listener = t1;
      this.sourceResult = t2;
    },
    _Future__propagateToListeners_handleError: function _Future__propagateToListeners_handleError(t0, t1, t2) {
      this._box_1 = t0;
      this._box_0 = t1;
      this.listener = t2;
    },
    _AsyncCallbackEntry: function _AsyncCallbackEntry(t0) {
      this.callback = t0;
      this.next = null;
    },
    Stream: function Stream() {
    },
    Stream_Stream$fromFuture_closure: function Stream_Stream$fromFuture_closure(t0, t1) {
      this.controller = t0;
      this.T = t1;
    },
    Stream_Stream$fromFuture_closure0: function Stream_Stream$fromFuture_closure0(t0) {
      this.controller = t0;
    },
    Stream_Stream$fromIterable_closure: function Stream_Stream$fromIterable_closure(t0, t1) {
      this.elements = t0;
      this.T = t1;
    },
    Stream_pipe_closure: function Stream_pipe_closure(t0) {
      this.streamConsumer = t0;
    },
    Stream_length_closure: function Stream_length_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Stream_length_closure0: function Stream_length_closure0(t0, t1) {
      this._box_0 = t0;
      this.future = t1;
    },
    Stream_first_closure: function Stream_first_closure(t0, t1, t2) {
      this._box_0 = t0;
      this.$this = t1;
      this.future = t2;
    },
    Stream_first_closure0: function Stream_first_closure0(t0) {
      this.future = t0;
    },
    Stream_last_closure: function Stream_last_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Stream_last_closure0: function Stream_last_closure0(t0, t1) {
      this._box_0 = t0;
      this.future = t1;
    },
    Stream_firstWhere_closure: function Stream_firstWhere_closure(t0, t1, t2, t3) {
      var _ = this;
      _._box_0 = t0;
      _.$this = t1;
      _.test = t2;
      _.future = t3;
    },
    Stream_firstWhere__closure: function Stream_firstWhere__closure(t0, t1) {
      this.test = t0;
      this.value = t1;
    },
    Stream_firstWhere__closure0: function Stream_firstWhere__closure0(t0, t1, t2) {
      this._box_0 = t0;
      this.future = t1;
      this.value = t2;
    },
    Stream_firstWhere_closure0: function Stream_firstWhere_closure0(t0, t1, t2) {
      this.$this = t0;
      this.orElse = t1;
      this.future = t2;
    },
    StreamSubscription: function StreamSubscription() {
    },
    StreamTransformerBase: function StreamTransformerBase() {
    },
    _StreamController: function _StreamController() {
    },
    _StreamController__subscribe_closure: function _StreamController__subscribe_closure(t0) {
      this.$this = t0;
    },
    _StreamController__recordCancel_complete: function _StreamController__recordCancel_complete(t0) {
      this.$this = t0;
    },
    _SyncStreamControllerDispatch: function _SyncStreamControllerDispatch() {
    },
    _AsyncStreamControllerDispatch: function _AsyncStreamControllerDispatch() {
    },
    _AsyncStreamController: function _AsyncStreamController(t0, t1, t2, t3, t4) {
      var _ = this;
      _._varData = null;
      _._state = 0;
      _._doneFuture = null;
      _.onListen = t0;
      _.onPause = t1;
      _.onResume = t2;
      _.onCancel = t3;
      _.$ti = t4;
    },
    _SyncStreamController: function _SyncStreamController(t0, t1, t2, t3, t4) {
      var _ = this;
      _._varData = null;
      _._state = 0;
      _._doneFuture = null;
      _.onListen = t0;
      _.onPause = t1;
      _.onResume = t2;
      _.onCancel = t3;
      _.$ti = t4;
    },
    _ControllerStream: function _ControllerStream(t0, t1) {
      this._controller = t0;
      this.$ti = t1;
    },
    _ControllerSubscription: function _ControllerSubscription(t0, t1, t2, t3) {
      var _ = this;
      _._controller = t0;
      _._onDone = _._onError = _._onData = null;
      _._zone = t1;
      _._state = t2;
      _._pending = _._cancelFuture = null;
      _.$ti = t3;
    },
    _StreamSinkWrapper: function _StreamSinkWrapper(t0, t1) {
      this._async$_target = t0;
      this.$ti = t1;
    },
    _AddStreamState: function _AddStreamState() {
    },
    _AddStreamState_makeErrorHandler_closure: function _AddStreamState_makeErrorHandler_closure(t0) {
      this.controller = t0;
    },
    _AddStreamState_cancel_closure: function _AddStreamState_cancel_closure(t0) {
      this.$this = t0;
    },
    _StreamControllerAddStreamState: function _StreamControllerAddStreamState(t0, t1, t2, t3) {
      var _ = this;
      _.varData = t0;
      _.addStreamFuture = t1;
      _.addSubscription = t2;
      _.$ti = t3;
    },
    _BufferingStreamSubscription: function _BufferingStreamSubscription(t0, t1, t2) {
      var _ = this;
      _._onDone = _._onError = _._onData = null;
      _._zone = t0;
      _._state = t1;
      _._pending = _._cancelFuture = null;
      _.$ti = t2;
    },
    _BufferingStreamSubscription__sendError_sendError: function _BufferingStreamSubscription__sendError_sendError(t0, t1, t2) {
      this.$this = t0;
      this.error = t1;
      this.stackTrace = t2;
    },
    _BufferingStreamSubscription__sendDone_sendDone: function _BufferingStreamSubscription__sendDone_sendDone(t0) {
      this.$this = t0;
    },
    _StreamImpl: function _StreamImpl() {
    },
    _GeneratedStreamImpl: function _GeneratedStreamImpl(t0, t1) {
      this._pending = t0;
      this._isUsed = false;
      this.$ti = t1;
    },
    _IterablePendingEvents: function _IterablePendingEvents(t0, t1) {
      this._async$_iterator = t0;
      this._state = 0;
      this.$ti = t1;
    },
    _DelayedEvent: function _DelayedEvent() {
    },
    _DelayedData: function _DelayedData(t0, t1) {
      this.value = t0;
      this.next = null;
      this.$ti = t1;
    },
    _DelayedError: function _DelayedError(t0, t1) {
      this.error = t0;
      this.stackTrace = t1;
      this.next = null;
    },
    _DelayedDone: function _DelayedDone() {
    },
    _PendingEvents: function _PendingEvents() {
    },
    _PendingEvents_schedule_closure: function _PendingEvents_schedule_closure(t0, t1) {
      this.$this = t0;
      this.dispatch = t1;
    },
    _StreamImplEvents: function _StreamImplEvents(t0) {
      var _ = this;
      _.lastPendingEvent = _.firstPendingEvent = null;
      _._state = 0;
      _.$ti = t0;
    },
    _DoneStreamSubscription: function _DoneStreamSubscription(t0, t1, t2) {
      var _ = this;
      _._zone = t0;
      _._state = 0;
      _._onDone = t1;
      _.$ti = t2;
    },
    _StreamIterator: function _StreamIterator(t0) {
      this.$ti = t0;
    },
    _EmptyStream: function _EmptyStream(t0) {
      this.$ti = t0;
    },
    _cancelAndError_closure: function _cancelAndError_closure(t0, t1, t2) {
      this.future = t0;
      this.error = t1;
      this.stackTrace = t2;
    },
    _cancelAndErrorClosure_closure: function _cancelAndErrorClosure_closure(t0, t1) {
      this.subscription = t0;
      this.future = t1;
    },
    _cancelAndValue_closure: function _cancelAndValue_closure(t0, t1) {
      this.future = t0;
      this.value = t1;
    },
    Timer: function Timer() {
    },
    AsyncError: function AsyncError(t0, t1) {
      this.error = t0;
      this.stackTrace = t1;
    },
    _ZoneFunction: function _ZoneFunction(t0, t1, t2) {
      this.zone = t0;
      this.$function = t1;
      this.$ti = t2;
    },
    ZoneSpecification: function ZoneSpecification() {
    },
    _ZoneSpecification: function _ZoneSpecification(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) {
      var _ = this;
      _.handleUncaughtError = t0;
      _.run = t1;
      _.runUnary = t2;
      _.runBinary = t3;
      _.registerCallback = t4;
      _.registerUnaryCallback = t5;
      _.registerBinaryCallback = t6;
      _.errorCallback = t7;
      _.scheduleMicrotask = t8;
      _.createTimer = t9;
      _.createPeriodicTimer = t10;
      _.print = t11;
      _.fork = t12;
    },
    ZoneDelegate: function ZoneDelegate() {
    },
    Zone: function Zone() {
    },
    _ZoneDelegate: function _ZoneDelegate(t0) {
      this._delegationTarget = t0;
    },
    _Zone: function _Zone() {
    },
    _CustomZone: function _CustomZone(t0, t1) {
      var _ = this;
      _._delegateCache = _._handleUncaughtError = _._fork = _._print = _._createPeriodicTimer = _._createTimer = _._scheduleMicrotask = _._errorCallback = _._registerBinaryCallback = _._registerUnaryCallback = _._registerCallback = _._runBinary = _._runUnary = _._run = null;
      _.parent = t0;
      _._async$_map = t1;
    },
    _CustomZone_bindCallback_closure: function _CustomZone_bindCallback_closure(t0, t1, t2) {
      this.$this = t0;
      this.registered = t1;
      this.R = t2;
    },
    _CustomZone_bindUnaryCallback_closure: function _CustomZone_bindUnaryCallback_closure(t0, t1, t2, t3) {
      var _ = this;
      _.$this = t0;
      _.registered = t1;
      _.T = t2;
      _.R = t3;
    },
    _CustomZone_bindCallbackGuarded_closure: function _CustomZone_bindCallbackGuarded_closure(t0, t1) {
      this.$this = t0;
      this.registered = t1;
    },
    _CustomZone_bindUnaryCallbackGuarded_closure: function _CustomZone_bindUnaryCallbackGuarded_closure(t0, t1, t2) {
      this.$this = t0;
      this.registered = t1;
      this.T = t2;
    },
    _rootHandleUncaughtError_closure: function _rootHandleUncaughtError_closure(t0, t1) {
      this._box_0 = t0;
      this.stackTrace = t1;
    },
    _RootZone: function _RootZone() {
    },
    _RootZone_bindCallback_closure: function _RootZone_bindCallback_closure(t0, t1, t2) {
      this.$this = t0;
      this.f = t1;
      this.R = t2;
    },
    _RootZone_bindCallbackGuarded_closure: function _RootZone_bindCallbackGuarded_closure(t0, t1) {
      this.$this = t0;
      this.f = t1;
    },
    _RootZone_bindUnaryCallbackGuarded_closure: function _RootZone_bindUnaryCallbackGuarded_closure(t0, t1, t2) {
      this.$this = t0;
      this.f = t1;
      this.T = t2;
    },
    runZoned_closure: function runZoned_closure(t0) {
      this._box_0 = t0;
    },
    HashMap_HashMap: function($K, $V) {
      return new P._HashMap($K._eval$1("@<0>")._bind$1($V)._eval$1("_HashMap<1,2>"));
    },
    _HashMap__getTableEntry: function(table, key) {
      var entry = table[key];
      return entry === table ? null : entry;
    },
    _HashMap__setTableEntry: function(table, key, value) {
      if (value == null)
        table[key] = table;
      else
        table[key] = value;
    },
    _HashMap__newHashTable: function() {
      var table = Object.create(null);
      P._HashMap__setTableEntry(table, "<non-identifier-key>", table);
      delete table["<non-identifier-key>"];
      return table;
    },
    LinkedHashMap_LinkedHashMap: function($K, $V) {
      return new H.JsLinkedHashMap($K._eval$1("@<0>")._bind$1($V)._eval$1("JsLinkedHashMap<1,2>"));
    },
    LinkedHashMap_LinkedHashMap$_literal: function(keyValuePairs, $K, $V) {
      return $K._eval$1("@<0>")._bind$1($V)._eval$1("LinkedHashMap<1,2>")._check(H.fillLiteralMap(keyValuePairs, new H.JsLinkedHashMap($K._eval$1("@<0>")._bind$1($V)._eval$1("JsLinkedHashMap<1,2>"))));
    },
    LinkedHashMap_LinkedHashMap$_empty: function($K, $V) {
      return new H.JsLinkedHashMap($K._eval$1("@<0>")._bind$1($V)._eval$1("JsLinkedHashMap<1,2>"));
    },
    LinkedHashSet_LinkedHashSet: function($E) {
      return new P._LinkedHashSet($E._eval$1("_LinkedHashSet<0>"));
    },
    LinkedHashSet_LinkedHashSet$_empty: function($E) {
      return new P._LinkedHashSet($E._eval$1("_LinkedHashSet<0>"));
    },
    LinkedHashSet_LinkedHashSet$_literal: function(values, $E) {
      return $E._eval$1("LinkedHashSet<0>")._check(H.fillLiteralSet(values, new P._LinkedHashSet($E._eval$1("_LinkedHashSet<0>"))));
    },
    _LinkedHashSet__newHashTable: function() {
      var table = Object.create(null);
      H.assertHelper(table != null);
      table["<non-identifier-key>"] = table;
      delete table["<non-identifier-key>"];
      return table;
    },
    _LinkedHashSetIterator$: function(_set, _modifications, $E) {
      var t1 = new P._LinkedHashSetIterator(_set, _modifications, $E._eval$1("_LinkedHashSetIterator<0>"));
      t1._collection$_cell = _set._collection$_first;
      return t1;
    },
    HashMap_HashMap$from: function(other, $K, $V) {
      var result = P.HashMap_HashMap($K, $V);
      other.forEach$1(0, new P.HashMap_HashMap$from_closure(result, $K, $V));
      return result;
    },
    IterableBase_iterableToShortString: function(iterable, leftDelimiter, rightDelimiter) {
      var parts, t1;
      if (P._isToStringVisiting(iterable)) {
        if (leftDelimiter === "(" && rightDelimiter === ")")
          return "(...)";
        return leftDelimiter + "..." + rightDelimiter;
      }
      parts = H.setRuntimeTypeInfo([], type$.JSArray_String);
      C.JSArray_methods.add$1($._toStringVisiting, iterable);
      try {
        P._iterablePartsToStrings(iterable, parts);
      } finally {
        H.assertHelper(C.JSArray_methods.get$last($._toStringVisiting) === iterable);
        if (0 >= $._toStringVisiting.length)
          return H.ioore($._toStringVisiting, -1);
        $._toStringVisiting.pop();
      }
      t1 = P.StringBuffer__writeAll(leftDelimiter, type$.Iterable_dynamic._check(parts), ", ") + rightDelimiter;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    IterableBase_iterableToFullString: function(iterable, leftDelimiter, rightDelimiter) {
      var buffer, t1;
      if (P._isToStringVisiting(iterable))
        return leftDelimiter + "..." + rightDelimiter;
      buffer = new P.StringBuffer(leftDelimiter);
      C.JSArray_methods.add$1($._toStringVisiting, iterable);
      try {
        t1 = buffer;
        t1._contents = P.StringBuffer__writeAll(t1._contents, iterable, ", ");
      } finally {
        H.assertHelper(C.JSArray_methods.get$last($._toStringVisiting) === iterable);
        if (0 >= $._toStringVisiting.length)
          return H.ioore($._toStringVisiting, -1);
        $._toStringVisiting.pop();
      }
      buffer._contents += rightDelimiter;
      t1 = buffer._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _isToStringVisiting: function(o) {
      var t1, i;
      for (t1 = $._toStringVisiting.length, i = 0; i < t1; ++i)
        if (o === $._toStringVisiting[i])
          return true;
      return false;
    },
    _iterablePartsToStrings: function(iterable, parts) {
      var next, ultimateString, penultimateString, penultimate, ultimate, ultimate0, elision,
        it = iterable.get$iterator(iterable),
        $length = 0, count = 0;
      while (true) {
        if (!($length < 80 || count < 3))
          break;
        if (!it.moveNext$0())
          return;
        next = H.S(it.get$current());
        C.JSArray_methods.add$1(parts, next);
        $length += next.length + 2;
        ++count;
      }
      if (!it.moveNext$0()) {
        if (count <= 5)
          return;
        if (0 >= parts.length)
          return H.ioore(parts, -1);
        ultimateString = parts.pop();
        if (0 >= parts.length)
          return H.ioore(parts, -1);
        penultimateString = parts.pop();
      } else {
        penultimate = it.get$current();
        ++count;
        if (!it.moveNext$0()) {
          if (count <= 4) {
            C.JSArray_methods.add$1(parts, H.S(penultimate));
            return;
          }
          ultimateString = H.S(penultimate);
          if (0 >= parts.length)
            return H.ioore(parts, -1);
          penultimateString = parts.pop();
          $length += ultimateString.length + 2;
        } else {
          ultimate = it.get$current();
          ++count;
          H.assertHelper(count < 100);
          for (; it.moveNext$0(); penultimate = ultimate, ultimate = ultimate0) {
            ultimate0 = it.get$current();
            ++count;
            if (count > 100) {
              while (true) {
                if (!($length > 75 && count > 3))
                  break;
                if (0 >= parts.length)
                  return H.ioore(parts, -1);
                $length -= parts.pop().length + 2;
                --count;
              }
              C.JSArray_methods.add$1(parts, "...");
              return;
            }
          }
          penultimateString = H.S(penultimate);
          ultimateString = H.S(ultimate);
          $length += ultimateString.length + penultimateString.length + 4;
        }
      }
      if (count > parts.length + 2) {
        $length += 5;
        elision = "...";
      } else
        elision = null;
      while (true) {
        if (!($length > 80 && parts.length > 3))
          break;
        if (0 >= parts.length)
          return H.ioore(parts, -1);
        $length -= parts.pop().length + 2;
        if (elision == null) {
          $length += 5;
          elision = "...";
        }
      }
      if (elision != null)
        C.JSArray_methods.add$1(parts, elision);
      C.JSArray_methods.add$1(parts, penultimateString);
      C.JSArray_methods.add$1(parts, ultimateString);
    },
    LinkedHashMap_LinkedHashMap$from: function(other, $K, $V) {
      var result = P.LinkedHashMap_LinkedHashMap($K, $V);
      other.forEach$1(0, new P.LinkedHashMap_LinkedHashMap$from_closure(result, $K, $V));
      return result;
    },
    LinkedHashSet_LinkedHashSet$from: function(elements, $E) {
      var t1,
        result = P.LinkedHashSet_LinkedHashSet($E);
      for (t1 = J.get$iterator$ax(elements); t1.moveNext$0();)
        result.add$1(0, $E._check(t1.get$current()));
      return result;
    },
    MapBase_mapToString: function(m) {
      var result, t1 = {};
      if (P._isToStringVisiting(m))
        return "{...}";
      result = new P.StringBuffer("");
      try {
        C.JSArray_methods.add$1($._toStringVisiting, m);
        result._contents += "{";
        t1.first = true;
        m.forEach$1(0, new P.MapBase_mapToString_closure(t1, result));
        result._contents += "}";
      } finally {
        H.assertHelper(C.JSArray_methods.get$last($._toStringVisiting) === m);
        if (0 >= $._toStringVisiting.length)
          return H.ioore($._toStringVisiting, -1);
        $._toStringVisiting.pop();
      }
      t1 = result._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    ListQueue$: function($E) {
      var t1 = new P.ListQueue($E._eval$1("ListQueue<0>")),
        t2 = new Array(8);
      t2.fixed$length = Array;
      t1.set$_table(H.setRuntimeTypeInfo(t2, $E._eval$1("JSArray<0>")));
      return t1;
    },
    _ListQueueIterator$: function(queue, $E) {
      return new P._ListQueueIterator(queue, queue._tail, queue._modificationCount, queue._head, $E._eval$1("_ListQueueIterator<0>"));
    },
    _HashMap: function _HashMap(t0) {
      var _ = this;
      _._collection$_length = 0;
      _._keys = _._collection$_rest = _._nums = _._strings = null;
      _.$ti = t0;
    },
    _IdentityHashMap: function _IdentityHashMap(t0) {
      var _ = this;
      _._collection$_length = 0;
      _._keys = _._collection$_rest = _._nums = _._strings = null;
      _.$ti = t0;
    },
    _HashMapKeyIterable: function _HashMapKeyIterable(t0, t1) {
      this._map = t0;
      this.$ti = t1;
    },
    _HashMapKeyIterator: function _HashMapKeyIterator(t0, t1, t2) {
      var _ = this;
      _._map = t0;
      _._keys = t1;
      _._offset = 0;
      _._collection$_current = null;
      _.$ti = t2;
    },
    _LinkedHashSet: function _LinkedHashSet(t0) {
      var _ = this;
      _._collection$_length = 0;
      _._collection$_last = _._collection$_first = _._collection$_rest = _._nums = _._strings = null;
      _._collection$_modifications = 0;
      _.$ti = t0;
    },
    _LinkedHashSetCell: function _LinkedHashSetCell(t0) {
      this._element = t0;
      this._collection$_previous = this._collection$_next = null;
    },
    _LinkedHashSetIterator: function _LinkedHashSetIterator(t0, t1, t2) {
      var _ = this;
      _._set = t0;
      _._collection$_modifications = t1;
      _._collection$_current = _._collection$_cell = null;
      _.$ti = t2;
    },
    UnmodifiableListView: function UnmodifiableListView(t0, t1) {
      this._collection$_source = t0;
      this.$ti = t1;
    },
    HashMap_HashMap$from_closure: function HashMap_HashMap$from_closure(t0, t1, t2) {
      this.result = t0;
      this.K = t1;
      this.V = t2;
    },
    IterableBase: function IterableBase() {
    },
    LinkedHashMap_LinkedHashMap$from_closure: function LinkedHashMap_LinkedHashMap$from_closure(t0, t1, t2) {
      this.result = t0;
      this.K = t1;
      this.V = t2;
    },
    ListBase: function ListBase() {
    },
    ListMixin: function ListMixin() {
    },
    MapBase: function MapBase() {
    },
    MapBase_mapToString_closure: function MapBase_mapToString_closure(t0, t1) {
      this._box_0 = t0;
      this.result = t1;
    },
    MapMixin: function MapMixin() {
    },
    _UnmodifiableMapMixin: function _UnmodifiableMapMixin() {
    },
    MapView: function MapView() {
    },
    UnmodifiableMapView: function UnmodifiableMapView(t0, t1) {
      this._map = t0;
      this.$ti = t1;
    },
    ListQueue: function ListQueue(t0) {
      var _ = this;
      _._table = null;
      _._modificationCount = _._tail = _._head = 0;
      _.$ti = t0;
    },
    _ListQueueIterator: function _ListQueueIterator(t0, t1, t2, t3, t4) {
      var _ = this;
      _._queue = t0;
      _._end = t1;
      _._modificationCount = t2;
      _._position = t3;
      _._collection$_current = null;
      _.$ti = t4;
    },
    SetMixin: function SetMixin() {
    },
    SetBase: function SetBase() {
    },
    _SetBase: function _SetBase() {
    },
    _ListBase_Object_ListMixin: function _ListBase_Object_ListMixin() {
    },
    _SetBase_Object_SetMixin: function _SetBase_Object_SetMixin() {
    },
    _UnmodifiableMapView_MapView__UnmodifiableMapMixin: function _UnmodifiableMapView_MapView__UnmodifiableMapMixin() {
    },
    _parseJson: function(source, reviver) {
      var parsed, e, exception, t1;
      if (typeof source != "string")
        throw H.wrapException(H.argumentErrorValue(source));
      parsed = null;
      try {
        parsed = JSON.parse(source);
      } catch (exception) {
        e = H.unwrapException(exception);
        t1 = P.FormatException$(String(e), null, null);
        throw H.wrapException(t1);
      }
      t1 = P._convertJsonToDartLazy(parsed);
      return t1;
    },
    _convertJsonToDartLazy: function(object) {
      var i;
      if (object == null)
        return null;
      if (typeof object != "object")
        return object;
      if (Object.getPrototypeOf(object) !== Array.prototype)
        return new P._JsonMap(object, Object.create(null));
      for (i = 0; i < object.length; ++i)
        object[i] = P._convertJsonToDartLazy(object[i]);
      return object;
    },
    Utf8Decoder__convertIntercepted: function(allowMalformed, codeUnits, start, end) {
      if (codeUnits instanceof Uint8Array)
        return P.Utf8Decoder__convertInterceptedUint8List(false, codeUnits, start, end);
      return null;
    },
    Utf8Decoder__convertInterceptedUint8List: function(allowMalformed, codeUnits, start, end) {
      var t1, $length,
        decoder = $.$get$Utf8Decoder__decoder();
      if (decoder == null)
        return null;
      t1 = 0 === start;
      if (t1 && true)
        return P.Utf8Decoder__useTextDecoderChecked(decoder, codeUnits);
      $length = codeUnits.length;
      end = P.RangeError_checkValidRange(start, end, $length);
      if (t1 && end === $length)
        return P.Utf8Decoder__useTextDecoderChecked(decoder, codeUnits);
      return P.Utf8Decoder__useTextDecoderChecked(decoder, codeUnits.subarray(start, end));
    },
    Utf8Decoder__useTextDecoderChecked: function(decoder, codeUnits) {
      if (P.Utf8Decoder__unsafe(codeUnits))
        return null;
      return P.Utf8Decoder__useTextDecoderUnchecked(decoder, codeUnits);
    },
    Utf8Decoder__useTextDecoderUnchecked: function(decoder, codeUnits) {
      var t1, exception;
      try {
        t1 = decoder.decode(codeUnits);
        return t1;
      } catch (exception) {
        H.unwrapException(exception);
      }
      return null;
    },
    Utf8Decoder__unsafe: function(codeUnits) {
      var i,
        limit = codeUnits.length - 2;
      for (i = 0; i < limit; ++i)
        if (codeUnits[i] === 237)
          if ((codeUnits[i + 1] & 224) === 160)
            return true;
      return false;
    },
    Utf8Decoder__makeDecoder: function() {
      var t1, exception;
      try {
        t1 = new TextDecoder("utf-8", {fatal: true});
        return t1;
      } catch (exception) {
        H.unwrapException(exception);
      }
      return null;
    },
    _scanOneByteCharacters: function(units, from, endIndex) {
      var t1, i, unit;
      for (t1 = J.getInterceptor$asx(units), i = from; i < endIndex; ++i) {
        unit = t1.$index(units, i);
        if (typeof unit !== "number")
          return unit.$and();
        if ((unit & 127) !== unit)
          return i - from;
      }
      return endIndex - from;
    },
    Base64Codec__checkPadding: function(source, sourceIndex, sourceEnd, firstPadding, paddingCount, $length) {
      if (C.JSInt_methods.$mod($length, 4) !== 0)
        throw H.wrapException(P.FormatException$("Invalid base64 padding, padded length must be multiple of four, is " + $length, source, sourceEnd));
      if (firstPadding + paddingCount !== $length)
        throw H.wrapException(P.FormatException$("Invalid base64 padding, '=' not at the end", source, sourceIndex));
      if (paddingCount > 2)
        throw H.wrapException(P.FormatException$("Invalid base64 padding, more than two '=' characters", source, sourceIndex));
    },
    _JsonMap: function _JsonMap(t0, t1) {
      this._original = t0;
      this._processed = t1;
      this._data = null;
    },
    _JsonMapKeyIterable: function _JsonMapKeyIterable(t0) {
      this._parent = t0;
    },
    AsciiCodec: function AsciiCodec() {
    },
    _UnicodeSubsetEncoder: function _UnicodeSubsetEncoder() {
    },
    AsciiEncoder: function AsciiEncoder(t0) {
      this._subsetMask = t0;
    },
    Base64Codec: function Base64Codec() {
    },
    Base64Encoder: function Base64Encoder() {
    },
    Codec: function Codec() {
    },
    _FusedCodec: function _FusedCodec(t0, t1, t2) {
      this._convert$_first = t0;
      this._second = t1;
      this.$ti = t2;
    },
    Converter: function Converter() {
    },
    Encoding: function Encoding() {
    },
    JsonCodec: function JsonCodec() {
    },
    JsonDecoder: function JsonDecoder(t0) {
      this._reviver = t0;
    },
    Utf8Codec: function Utf8Codec() {
    },
    Utf8Encoder: function Utf8Encoder() {
    },
    _Utf8Encoder: function _Utf8Encoder(t0) {
      this._bufferIndex = this._carry = 0;
      this._buffer = t0;
    },
    Utf8Decoder: function Utf8Decoder(t0) {
      this._allowMalformed = t0;
    },
    _Utf8Decoder: function _Utf8Decoder(t0, t1) {
      var _ = this;
      _._allowMalformed = t0;
      _._stringSink = t1;
      _._isFirstCharacter = true;
      _._extraUnits = _._expectedUnits = _._convert$_value = 0;
    },
    int_parse: function(source, onError, radix) {
      var value = H.Primitives_parseInt(source, radix);
      if (value != null)
        return value;
      if (onError != null)
        return onError.call$1(source);
      throw H.wrapException(P.FormatException$(source, null, null));
    },
    Error__objectToString: function(object) {
      if (object instanceof H.Closure)
        return object.toString$0(0);
      return "Instance of '" + H.S(H.Primitives_objectTypeName(object)) + "'";
    },
    List_List$filled: function($length, fill, $E) {
      var i,
        result = J.JSArray_JSArray$fixed($length, $E);
      if ($length !== 0 && true)
        for (i = 0; i < result.length; ++i)
          C.JSArray_methods.$indexSet(result, i, fill);
      return result;
    },
    List_List$from: function(elements, growable, $E) {
      var t1,
        list = H.setRuntimeTypeInfo([], $E._eval$1("JSArray<0>"));
      for (t1 = J.get$iterator$ax(elements); t1.moveNext$0();)
        C.JSArray_methods.add$1(list, $E._check(t1.get$current()));
      if (growable)
        return list;
      return $E._eval$1("List<0>")._check(J.JSArray_markFixedList(list));
    },
    List_List$unmodifiable: function(elements, $E) {
      var result = P.List_List$from(elements, false, $E);
      result.fixed$length = Array;
      result.immutable$list = Array;
      return $E._eval$1("List<0>")._check(result);
    },
    String_String$fromCharCodes: function(charCodes, start, end) {
      var len;
      if (Array.isArray(charCodes)) {
        type$.JSArray_int._check(charCodes);
        len = charCodes.length;
        end = P.RangeError_checkValidRange(start, end, len);
        return H.Primitives_stringFromCharCodes(start > 0 || end < len ? C.JSArray_methods.sublist$2(charCodes, start, end) : charCodes);
      }
      if (type$.NativeUint8List._is(charCodes))
        return H.Primitives_stringFromNativeUint8List(charCodes, start, P.RangeError_checkValidRange(start, end, charCodes.length));
      return P.String__stringFromIterable(charCodes, start, end);
    },
    String_String$fromCharCode: function(charCode) {
      return H.Primitives_stringFromCharCode(charCode);
    },
    String__stringFromIterable: function(charCodes, start, end) {
      var t1, it, i, list, _null = null;
      if (start < 0)
        throw H.wrapException(P.RangeError$range(start, 0, J.get$length$asx(charCodes), _null, _null));
      t1 = end == null;
      if (!t1 && end < start)
        throw H.wrapException(P.RangeError$range(end, start, J.get$length$asx(charCodes), _null, _null));
      it = J.get$iterator$ax(charCodes);
      for (i = 0; i < start; ++i)
        if (!it.moveNext$0())
          throw H.wrapException(P.RangeError$range(start, 0, i, _null, _null));
      list = [];
      if (t1)
        for (; it.moveNext$0();)
          list.push(it.get$current());
      else
        for (i = start; i < end; ++i) {
          if (!it.moveNext$0())
            throw H.wrapException(P.RangeError$range(end, start, i, _null, _null));
          list.push(it.get$current());
        }
      return H.Primitives_stringFromCharCodes(list);
    },
    RegExp_RegExp: function(source, multiLine) {
      return new H.JSSyntaxRegExp(source, H.JSSyntaxRegExp_makeNative(source, multiLine, true, false, false, false));
    },
    StringBuffer__writeAll: function(string, objects, separator) {
      var iterator = J.get$iterator$ax(objects);
      if (!iterator.moveNext$0())
        return string;
      if (separator.length === 0) {
        do
          string += H.S(iterator.get$current());
        while (iterator.moveNext$0());
      } else {
        string += H.S(iterator.get$current());
        for (; iterator.moveNext$0();)
          string = string + separator + H.S(iterator.get$current());
      }
      return string;
    },
    Uri_base: function() {
      var uri = H.Primitives_currentUri();
      if (uri != null)
        return P.Uri_parse(uri);
      throw H.wrapException(P.UnsupportedError$("'Uri.base' is not supported"));
    },
    _Uri__uriEncode: function(canonicalTable, text, encoding, spaceToPlus) {
      var t1, bytes, i, t2, byte, t3,
        _s16_ = "0123456789ABCDEF";
      if (encoding === C.C_Utf8Codec) {
        t1 = $.$get$_Uri__needsNoEncoding()._nativeRegExp;
        if (typeof text != "string")
          H.throwExpression(H.argumentErrorValue(text));
        t1 = t1.test(text);
      } else
        t1 = false;
      if (t1)
        return text;
      H._instanceType(encoding)._eval$1("Codec.S")._check(text);
      bytes = encoding.get$encoder().convert$1(text);
      for (t1 = bytes.length, i = 0, t2 = ""; i < t1; ++i) {
        byte = bytes[i];
        if (byte < 128) {
          t3 = byte >>> 4;
          if (t3 >= 8)
            return H.ioore(canonicalTable, t3);
          t3 = (canonicalTable[t3] & 1 << (byte & 15)) !== 0;
        } else
          t3 = false;
        if (t3)
          t2 += H.Primitives_stringFromCharCode(byte);
        else
          t2 = spaceToPlus && byte === 32 ? t2 + "+" : t2 + "%" + _s16_[byte >>> 4 & 15] + _s16_[byte & 15];
      }
      return t2.charCodeAt(0) == 0 ? t2 : t2;
    },
    StackTrace_current: function() {
      var stackTrace, exception;
      if (H.boolConversionCheck($.$get$_hasErrorStackProperty()))
        return H.getTraceFromException(new Error());
      try {
        throw H.wrapException("");
      } catch (exception) {
        H.unwrapException(exception);
        stackTrace = H.getTraceFromException(exception);
        return stackTrace;
      }
    },
    DateTime__fourDigits: function(n) {
      var absN = Math.abs(n),
        sign = n < 0 ? "-" : "";
      if (absN >= 1000)
        return "" + n;
      if (absN >= 100)
        return sign + "0" + absN;
      if (absN >= 10)
        return sign + "00" + absN;
      return sign + "000" + absN;
    },
    DateTime__threeDigits: function(n) {
      if (n >= 100)
        return "" + n;
      if (n >= 10)
        return "0" + n;
      return "00" + n;
    },
    DateTime__twoDigits: function(n) {
      if (n >= 10)
        return "" + n;
      return "0" + n;
    },
    Duration$: function(microseconds, minutes) {
      if (typeof microseconds !== "number")
        return H.iae(microseconds);
      return new P.Duration(60000000 * minutes + microseconds);
    },
    Error_safeToString: function(object) {
      if (typeof object == "number" || H._isBool(object) || null == object)
        return J.toString$0$(object);
      if (typeof object == "string")
        return JSON.stringify(object);
      return P.Error__objectToString(object);
    },
    AssertionError$: function(message) {
      return new P.AssertionError(message);
    },
    ArgumentError$: function(message) {
      return new P.ArgumentError(false, null, null, message);
    },
    ArgumentError$value: function(value, $name, message) {
      return new P.ArgumentError(true, value, $name, message);
    },
    ArgumentError$notNull: function($name) {
      return new P.ArgumentError(false, null, $name, "Must not be null");
    },
    RangeError$: function(message) {
      var _null = null;
      return new P.RangeError(_null, _null, false, _null, _null, message);
    },
    RangeError$value: function(value, $name) {
      return new P.RangeError(null, null, true, value, $name, "Value not in range");
    },
    RangeError$range: function(invalidValue, minValue, maxValue, $name, message) {
      return new P.RangeError(minValue, maxValue, true, invalidValue, $name, "Invalid value");
    },
    RangeError_checkValueInInterval: function(value, minValue, maxValue, $name) {
      if (value < minValue || value > maxValue)
        throw H.wrapException(P.RangeError$range(value, minValue, maxValue, $name, null));
    },
    RangeError_checkValidRange: function(start, end, $length) {
      if (0 > start || start > $length)
        throw H.wrapException(P.RangeError$range(start, 0, $length, "start", null));
      if (end != null) {
        if (start > end || end > $length)
          throw H.wrapException(P.RangeError$range(end, start, $length, "end", null));
        return end;
      }
      return $length;
    },
    RangeError_checkNotNegative: function(value, $name) {
      if (typeof value !== "number")
        return value.$lt();
      if (value < 0)
        throw H.wrapException(P.RangeError$range(value, 0, null, $name, null));
    },
    IndexError$: function(invalidValue, indexable, $name, message, $length) {
      var t1 = H._checkIntNullable($length == null ? J.get$length$asx(indexable) : $length);
      return new P.IndexError(t1, true, invalidValue, $name, "Index out of range");
    },
    UnsupportedError$: function(message) {
      return new P.UnsupportedError(message);
    },
    UnimplementedError$: function(message) {
      return new P.UnimplementedError(message);
    },
    StateError$: function(message) {
      return new P.StateError(message);
    },
    ConcurrentModificationError$: function(modifiedObject) {
      return new P.ConcurrentModificationError(modifiedObject);
    },
    FormatException$: function(message, source, offset) {
      return new P.FormatException(message, source, offset);
    },
    List_List$generate: function($length, generator, growable, $E) {
      var i,
        result = H.setRuntimeTypeInfo([], $E._eval$1("JSArray<0>"));
      C.JSArray_methods.set$length(result, $length);
      for (i = 0; i < $length; ++i)
        C.JSArray_methods.$indexSet(result, i, generator.call$1(i));
      return result;
    },
    Map_castFrom: function(source, $K, $V, K2, V2) {
      return new H.CastMap(source, $K._eval$1("@<0>")._bind$1($V)._bind$1(K2)._bind$1(V2)._eval$1("CastMap<1,2,3,4>"));
    },
    print: function(object) {
      var line = H.S(object),
        t1 = $.printToZone;
      if (t1 == null)
        H.printString(line);
      else
        t1.call$1(line);
    },
    _combineSurrogatePair: function(start, end) {
      return 65536 + ((start & 1023) << 10) + (end & 1023);
    },
    Uri_parse: function(uri) {
      var delta, t1, indices, schemeEnd, hostStart, portStart, pathStart, queryStart, fragmentStart, isSimple, scheme, t2, schemeAuth, queryStart0, pathStart0, _null = null,
        end = uri.length;
      if (end >= 5) {
        delta = ((J._codeUnitAt$1$s(uri, 4) ^ 58) * 3 | C.JSString_methods._codeUnitAt$1(uri, 0) ^ 100 | C.JSString_methods._codeUnitAt$1(uri, 1) ^ 97 | C.JSString_methods._codeUnitAt$1(uri, 2) ^ 116 | C.JSString_methods._codeUnitAt$1(uri, 3) ^ 97) >>> 0;
        if (delta === 0)
          return P.UriData__parse(end < end ? C.JSString_methods.substring$2(uri, 0, end) : uri, 5, _null).get$uri();
        else if (delta === 32)
          return P.UriData__parse(C.JSString_methods.substring$2(uri, 5, end), 0, _null).get$uri();
      }
      t1 = new Array(8);
      t1.fixed$length = Array;
      indices = H.setRuntimeTypeInfo(t1, type$.JSArray_int);
      C.JSArray_methods.$indexSet(indices, 0, 0);
      C.JSArray_methods.$indexSet(indices, 1, -1);
      C.JSArray_methods.$indexSet(indices, 2, -1);
      C.JSArray_methods.$indexSet(indices, 7, -1);
      C.JSArray_methods.$indexSet(indices, 3, 0);
      C.JSArray_methods.$indexSet(indices, 4, 0);
      C.JSArray_methods.$indexSet(indices, 5, end);
      C.JSArray_methods.$indexSet(indices, 6, end);
      if (P._scan(uri, 0, end, 0, indices) >= 14)
        C.JSArray_methods.$indexSet(indices, 7, end);
      schemeEnd = indices[1];
      if (typeof schemeEnd !== "number")
        return schemeEnd.$ge();
      if (schemeEnd >= 0)
        if (P._scan(uri, 0, schemeEnd, 20, indices) === 20)
          indices[7] = schemeEnd;
      t1 = indices[2];
      if (typeof t1 !== "number")
        return t1.$add();
      hostStart = t1 + 1;
      portStart = indices[3];
      pathStart = indices[4];
      queryStart = indices[5];
      fragmentStart = indices[6];
      if (typeof fragmentStart !== "number")
        return fragmentStart.$lt();
      if (typeof queryStart !== "number")
        return H.iae(queryStart);
      if (fragmentStart < queryStart)
        queryStart = fragmentStart;
      if (typeof pathStart !== "number")
        return pathStart.$lt();
      if (pathStart < hostStart)
        pathStart = queryStart;
      else if (pathStart <= schemeEnd)
        pathStart = schemeEnd + 1;
      if (typeof portStart !== "number")
        return portStart.$lt();
      if (portStart < hostStart)
        portStart = pathStart;
      H.assertHelper(hostStart === 0 || schemeEnd <= hostStart);
      H.assertHelper(hostStart <= portStart);
      H.assertHelper(schemeEnd <= pathStart);
      H.assertHelper(portStart <= pathStart);
      H.assertHelper(pathStart <= queryStart);
      H.assertHelper(queryStart <= fragmentStart);
      t1 = indices[7];
      if (typeof t1 !== "number")
        return t1.$lt();
      isSimple = t1 < 0;
      if (isSimple)
        if (hostStart > schemeEnd + 3) {
          scheme = _null;
          isSimple = false;
        } else {
          t1 = portStart > 0;
          if (t1 && portStart + 1 === pathStart) {
            scheme = _null;
            isSimple = false;
          } else {
            if (!(queryStart < end && queryStart === pathStart + 2 && J.startsWith$2$s(uri, "..", pathStart)))
              t2 = queryStart > pathStart + 2 && J.startsWith$2$s(uri, "/..", queryStart - 3);
            else
              t2 = true;
            if (t2) {
              scheme = _null;
              isSimple = false;
            } else {
              if (schemeEnd === 4)
                if (J.startsWith$2$s(uri, "file", 0)) {
                  if (hostStart <= 0) {
                    if (!C.JSString_methods.startsWith$2(uri, "/", pathStart)) {
                      schemeAuth = "file:///";
                      delta = 3;
                    } else {
                      schemeAuth = "file://";
                      delta = 2;
                    }
                    uri = schemeAuth + C.JSString_methods.substring$2(uri, pathStart, end);
                    schemeEnd -= 0;
                    t1 = delta - 0;
                    queryStart += t1;
                    fragmentStart += t1;
                    end = uri.length;
                    hostStart = 7;
                    portStart = 7;
                    pathStart = 7;
                  } else if (pathStart === queryStart) {
                    queryStart0 = queryStart + 1;
                    ++fragmentStart;
                    uri = C.JSString_methods.replaceRange$3(uri, pathStart, queryStart, "/");
                    ++end;
                    queryStart = queryStart0;
                  }
                  scheme = "file";
                } else if (C.JSString_methods.startsWith$2(uri, "http", 0)) {
                  if (t1 && portStart + 3 === pathStart && C.JSString_methods.startsWith$2(uri, "80", portStart + 1)) {
                    pathStart0 = pathStart - 3;
                    queryStart -= 3;
                    fragmentStart -= 3;
                    uri = C.JSString_methods.replaceRange$3(uri, portStart, pathStart, "");
                    end -= 3;
                    pathStart = pathStart0;
                  }
                  scheme = "http";
                } else
                  scheme = _null;
              else if (schemeEnd === 5 && J.startsWith$2$s(uri, "https", 0)) {
                if (t1 && portStart + 4 === pathStart && J.startsWith$2$s(uri, "443", portStart + 1)) {
                  pathStart0 = pathStart - 4;
                  queryStart -= 4;
                  fragmentStart -= 4;
                  uri = J.replaceRange$3$asx(uri, portStart, pathStart, "");
                  end -= 3;
                  pathStart = pathStart0;
                }
                scheme = "https";
              } else
                scheme = _null;
              isSimple = true;
            }
          }
        }
      else
        scheme = _null;
      if (isSimple) {
        t1 = uri.length;
        if (end < t1) {
          uri = J.substring$2$s(uri, 0, end);
          schemeEnd -= 0;
          hostStart -= 0;
          portStart -= 0;
          pathStart -= 0;
          queryStart -= 0;
          fragmentStart -= 0;
        }
        return new P._SimpleUri(uri, schemeEnd, hostStart, portStart, pathStart, queryStart, fragmentStart, scheme);
      }
      return P._Uri__Uri$notSimple(uri, 0, end, schemeEnd, hostStart, portStart, pathStart, queryStart, fragmentStart, scheme);
    },
    Uri_decodeComponent: function(encodedComponent) {
      H._checkStringNullable(encodedComponent);
      return P._Uri__uriDecode(encodedComponent, 0, encodedComponent.length, C.C_Utf8Codec, false);
    },
    Uri__parseIPv4Address: function(host, start, end) {
      var t1, i, partStart, partIndex, char, part, partIndex0, _null = null,
        _s43_ = "IPv4 address should contain exactly 4 parts",
        _s37_ = "each part must be in the range 0..255",
        error = new P.Uri__parseIPv4Address_error(host),
        result = new Uint8Array(4);
      for (t1 = result.length, i = start, partStart = i, partIndex = 0; i < end; ++i) {
        char = C.JSString_methods.codeUnitAt$1(host, i);
        if (char !== 46) {
          if ((char ^ 48) > 9)
            error.call$2("invalid character", i);
        } else {
          if (partIndex === 3)
            error.call$2(_s43_, i);
          part = P.int_parse(C.JSString_methods.substring$2(host, partStart, i), _null, _null);
          if (typeof part !== "number")
            return part.$gt();
          if (part > 255)
            error.call$2(_s37_, partStart);
          partIndex0 = partIndex + 1;
          if (partIndex >= t1)
            return H.ioore(result, partIndex);
          result[partIndex] = part;
          partStart = i + 1;
          partIndex = partIndex0;
        }
      }
      if (partIndex !== 3)
        error.call$2(_s43_, end);
      part = P.int_parse(C.JSString_methods.substring$2(host, partStart, end), _null, _null);
      if (typeof part !== "number")
        return part.$gt();
      if (part > 255)
        error.call$2(_s37_, partStart);
      if (partIndex >= t1)
        return H.ioore(result, partIndex);
      result[partIndex] = part;
      return result;
    },
    Uri_parseIPv6Address: function(host, start, end) {
      var parts, i, partStart, wildcardSeen, seenDot, char, atEnd, t1, last, bytes, t2, wildCardLength, index, value, j, t3,
        error = new P.Uri_parseIPv6Address_error(host),
        parseHex = new P.Uri_parseIPv6Address_parseHex(error, host);
      if (host.length < 2)
        error.call$1("address is too short");
      parts = H.setRuntimeTypeInfo([], type$.JSArray_int);
      for (i = start, partStart = i, wildcardSeen = false, seenDot = false; i < end; ++i) {
        char = C.JSString_methods.codeUnitAt$1(host, i);
        if (char === 58) {
          if (i === start) {
            ++i;
            if (C.JSString_methods.codeUnitAt$1(host, i) !== 58)
              error.call$2("invalid start colon.", i);
            partStart = i;
          }
          if (i === partStart) {
            if (wildcardSeen)
              error.call$2("only one wildcard `::` is allowed", i);
            C.JSArray_methods.add$1(parts, -1);
            wildcardSeen = true;
          } else
            C.JSArray_methods.add$1(parts, parseHex.call$2(partStart, i));
          partStart = i + 1;
        } else if (char === 46)
          seenDot = true;
      }
      if (parts.length === 0)
        error.call$1("too few parts");
      atEnd = partStart === end;
      t1 = C.JSArray_methods.get$last(parts);
      if (atEnd && t1 !== -1)
        error.call$2("expected a part after last `:`", end);
      if (!atEnd)
        if (!seenDot)
          C.JSArray_methods.add$1(parts, parseHex.call$2(partStart, end));
        else {
          last = P.Uri__parseIPv4Address(host, partStart, end);
          C.JSArray_methods.add$1(parts, (last[0] << 8 | last[1]) >>> 0);
          C.JSArray_methods.add$1(parts, (last[2] << 8 | last[3]) >>> 0);
        }
      if (wildcardSeen) {
        if (parts.length > 7)
          error.call$1("an address with a wildcard must have less than 7 parts");
      } else if (parts.length !== 8)
        error.call$1("an address without a wildcard must contain exactly 8 parts");
      bytes = new Uint8Array(16);
      for (t1 = parts.length, t2 = bytes.length, wildCardLength = 9 - t1, i = 0, index = 0; i < t1; ++i) {
        value = parts[i];
        if (value === -1)
          for (j = 0; j < wildCardLength; ++j) {
            if (index < 0 || index >= t2)
              return H.ioore(bytes, index);
            bytes[index] = 0;
            t3 = index + 1;
            if (t3 >= t2)
              return H.ioore(bytes, t3);
            bytes[t3] = 0;
            index += 2;
          }
        else {
          t3 = C.JSInt_methods._shrOtherPositive$1(value, 8);
          if (index < 0 || index >= t2)
            return H.ioore(bytes, index);
          bytes[index] = t3;
          t3 = index + 1;
          if (t3 >= t2)
            return H.ioore(bytes, t3);
          bytes[t3] = value & 255;
          index += 2;
        }
      }
      return bytes;
    },
    _Uri__Uri$notSimple: function(uri, start, end, schemeEnd, hostStart, portStart, pathStart, queryStart, fragmentStart, scheme) {
      var userInfoStart, userInfo, host, t1, port, path, query, _null = null;
      if (scheme == null)
        if (schemeEnd > start)
          scheme = P._Uri__makeScheme(uri, start, schemeEnd);
        else {
          if (schemeEnd === start)
            P._Uri__fail(uri, start, "Invalid empty scheme");
          scheme = "";
        }
      if (hostStart > start) {
        userInfoStart = schemeEnd + 3;
        userInfo = userInfoStart < hostStart ? P._Uri__makeUserInfo(uri, userInfoStart, hostStart - 1) : "";
        host = P._Uri__makeHost(uri, hostStart, portStart, false);
        t1 = portStart + 1;
        port = t1 < pathStart ? P._Uri__makePort(P.int_parse(J.substring$2$s(uri, t1, pathStart), new P._Uri__Uri$notSimple_closure(uri, portStart), _null), scheme) : _null;
      } else {
        port = _null;
        host = port;
        userInfo = "";
      }
      path = P._Uri__makePath(uri, pathStart, queryStart, _null, scheme, host != null);
      query = queryStart < fragmentStart ? P._Uri__makeQuery(uri, queryStart + 1, fragmentStart, _null) : _null;
      return new P._Uri(scheme, userInfo, host, port, path, query, fragmentStart < end ? P._Uri__makeFragment(uri, fragmentStart + 1, end) : _null);
    },
    _Uri__Uri: function(host, path, pathSegments, scheme) {
      var userInfo, query, fragment, port, isFile, t1, hasAuthority, t2, _null = null;
      scheme = P._Uri__makeScheme(scheme, 0, scheme == null ? 0 : scheme.length);
      userInfo = P._Uri__makeUserInfo(_null, 0, 0);
      host = P._Uri__makeHost(host, 0, host == null ? 0 : host.length, false);
      query = P._Uri__makeQuery(_null, 0, 0, _null);
      fragment = P._Uri__makeFragment(_null, 0, 0);
      port = P._Uri__makePort(_null, scheme);
      isFile = scheme === "file";
      if (host == null)
        t1 = userInfo.length !== 0 || port != null || isFile;
      else
        t1 = false;
      if (t1)
        host = "";
      t1 = host == null;
      hasAuthority = !t1;
      path = P._Uri__makePath(path, 0, path == null ? 0 : path.length, pathSegments, scheme, hasAuthority);
      t2 = scheme.length === 0;
      if (t2 && t1 && !C.JSString_methods.startsWith$1(path, "/"))
        path = P._Uri__normalizeRelativePath(path, !t2 || hasAuthority);
      else
        path = P._Uri__removeDotSegments(path);
      return new P._Uri(scheme, userInfo, t1 && C.JSString_methods.startsWith$1(path, "//") ? "" : host, port, path, query, fragment);
    },
    _Uri__defaultPort: function(scheme) {
      if (scheme === "http")
        return 80;
      if (scheme === "https")
        return 443;
      return 0;
    },
    _Uri__fail: function(uri, index, message) {
      throw H.wrapException(P.FormatException$(message, uri, index));
    },
    _Uri__Uri$file: function(path, windows) {
      return windows ? P._Uri__makeWindowsFileUrl(path, false) : P._Uri__makeFileUri(path, false);
    },
    _Uri__checkNonWindowsPathReservedCharacters: function(segments, argumentError) {
      C.JSArray_methods.forEach$1(segments, new P._Uri__checkNonWindowsPathReservedCharacters_closure(false));
    },
    _Uri__checkWindowsPathReservedCharacters: function(segments, argumentError, firstSegment) {
      var t1, t2;
      for (t1 = H.SubListIterable$(segments, firstSegment, null, H._arrayInstanceType(segments)._precomputed1), t1 = new H.ListIterator(t1, t1.get$length(t1), t1.$ti._eval$1("ListIterator<ListIterable.E>")); t1.moveNext$0();) {
        t2 = t1.__internal$_current;
        if (J.contains$1$asx(t2, P.RegExp_RegExp('["*/:<>?\\\\|]', false)))
          if (argumentError)
            throw H.wrapException(P.ArgumentError$("Illegal character in path"));
          else
            throw H.wrapException(P.UnsupportedError$("Illegal character in path: " + t2));
      }
    },
    _Uri__checkWindowsDriveLetter: function(charCode, argumentError) {
      var t1,
        _s21_ = "Illegal drive letter ";
      if (!(65 <= charCode && charCode <= 90))
        t1 = 97 <= charCode && charCode <= 122;
      else
        t1 = true;
      if (t1)
        return;
      if (argumentError)
        throw H.wrapException(P.ArgumentError$(_s21_ + P.String_String$fromCharCode(charCode)));
      else
        throw H.wrapException(P.UnsupportedError$(_s21_ + P.String_String$fromCharCode(charCode)));
    },
    _Uri__makeFileUri: function(path, slashTerminated) {
      var _null = null,
        segments = H.setRuntimeTypeInfo(path.split("/"), type$.JSArray_String);
      if (C.JSString_methods.startsWith$1(path, "/"))
        return P._Uri__Uri(_null, _null, segments, "file");
      else
        return P._Uri__Uri(_null, _null, segments, _null);
    },
    _Uri__makeWindowsFileUrl: function(path, slashTerminated) {
      var t1, pathSegments, pathStart, hostPart, _s1_ = "\\", _null = null, _s4_ = "file";
      if (C.JSString_methods.startsWith$1(path, "\\\\?\\"))
        if (C.JSString_methods.startsWith$2(path, "UNC\\", 4))
          path = C.JSString_methods.replaceRange$3(path, 0, 7, _s1_);
        else {
          path = C.JSString_methods.substring$1(path, 4);
          if (path.length < 3 || C.JSString_methods._codeUnitAt$1(path, 1) !== 58 || C.JSString_methods._codeUnitAt$1(path, 2) !== 92)
            throw H.wrapException(P.ArgumentError$("Windows paths with \\\\?\\ prefix must be absolute"));
        }
      else
        path = H.stringReplaceAllUnchecked(path, "/", _s1_);
      t1 = path.length;
      if (t1 > 1 && C.JSString_methods._codeUnitAt$1(path, 1) === 58) {
        P._Uri__checkWindowsDriveLetter(C.JSString_methods._codeUnitAt$1(path, 0), true);
        if (t1 === 2 || C.JSString_methods._codeUnitAt$1(path, 2) !== 92)
          throw H.wrapException(P.ArgumentError$("Windows paths with drive letter must be absolute"));
        pathSegments = H.setRuntimeTypeInfo(path.split(_s1_), type$.JSArray_String);
        P._Uri__checkWindowsPathReservedCharacters(pathSegments, true, 1);
        return P._Uri__Uri(_null, _null, pathSegments, _s4_);
      }
      if (C.JSString_methods.startsWith$1(path, _s1_))
        if (C.JSString_methods.startsWith$2(path, _s1_, 1)) {
          pathStart = C.JSString_methods.indexOf$2(path, _s1_, 2);
          t1 = pathStart < 0;
          hostPart = t1 ? C.JSString_methods.substring$1(path, 2) : C.JSString_methods.substring$2(path, 2, pathStart);
          pathSegments = H.setRuntimeTypeInfo((t1 ? "" : C.JSString_methods.substring$1(path, pathStart + 1)).split(_s1_), type$.JSArray_String);
          P._Uri__checkWindowsPathReservedCharacters(pathSegments, true, 0);
          return P._Uri__Uri(hostPart, _null, pathSegments, _s4_);
        } else {
          pathSegments = H.setRuntimeTypeInfo(path.split(_s1_), type$.JSArray_String);
          P._Uri__checkWindowsPathReservedCharacters(pathSegments, true, 0);
          return P._Uri__Uri(_null, _null, pathSegments, _s4_);
        }
      else {
        pathSegments = H.setRuntimeTypeInfo(path.split(_s1_), type$.JSArray_String);
        P._Uri__checkWindowsPathReservedCharacters(pathSegments, true, 0);
        return P._Uri__Uri(_null, _null, pathSegments, _null);
      }
    },
    _Uri__makePort: function(port, scheme) {
      if (port != null && port === P._Uri__defaultPort(scheme))
        return null;
      return port;
    },
    _Uri__makeHost: function(host, start, end, strictIPv6) {
      var t1, t2, index, zoneIDstart, zoneID, i;
      if (host == null)
        return null;
      if (start === end)
        return "";
      if (C.JSString_methods.codeUnitAt$1(host, start) === 91) {
        t1 = end - 1;
        if (C.JSString_methods.codeUnitAt$1(host, t1) !== 93)
          P._Uri__fail(host, start, "Missing end `]` to match `[` in host");
        t2 = start + 1;
        index = P._Uri__checkZoneID(host, t2, t1);
        if (index < t1) {
          zoneIDstart = index + 1;
          zoneID = P._Uri__normalizeZoneID(host, C.JSString_methods.startsWith$2(host, "25", zoneIDstart) ? index + 3 : zoneIDstart, t1, "%25");
        } else
          zoneID = "";
        P.Uri_parseIPv6Address(host, t2, index);
        return C.JSString_methods.substring$2(host, start, index).toLowerCase() + zoneID + "]";
      }
      for (i = start; i < end; ++i)
        if (C.JSString_methods.codeUnitAt$1(host, i) === 58) {
          index = C.JSString_methods.indexOf$2(host, "%", start);
          index = index >= start && index < end ? index : end;
          if (index < end) {
            zoneIDstart = index + 1;
            zoneID = P._Uri__normalizeZoneID(host, C.JSString_methods.startsWith$2(host, "25", zoneIDstart) ? index + 3 : zoneIDstart, end, "%25");
          } else
            zoneID = "";
          P.Uri_parseIPv6Address(host, start, index);
          return "[" + C.JSString_methods.substring$2(host, start, index) + zoneID + "]";
        }
      return P._Uri__normalizeRegName(host, start, end);
    },
    _Uri__checkZoneID: function(host, start, end) {
      var index = C.JSString_methods.indexOf$2(host, "%", start);
      return index >= start && index < end ? index : end;
    },
    _Uri__normalizeZoneID: function(host, start, end, prefix) {
      var index, sectionStart, isNormalized, char, replacement, t1, t2, tail, sourceLength,
        buffer = prefix !== "" ? new P.StringBuffer(prefix) : null;
      for (index = start, sectionStart = index, isNormalized = true; index < end;) {
        char = C.JSString_methods.codeUnitAt$1(host, index);
        if (char === 37) {
          replacement = P._Uri__normalizeEscape(host, index, true);
          t1 = replacement == null;
          if (t1 && isNormalized) {
            index += 3;
            continue;
          }
          if (buffer == null)
            buffer = new P.StringBuffer("");
          t2 = buffer._contents += C.JSString_methods.substring$2(host, sectionStart, index);
          if (t1)
            replacement = C.JSString_methods.substring$2(host, index, index + 3);
          else if (replacement === "%")
            P._Uri__fail(host, index, "ZoneID should not contain % anymore");
          buffer._contents = t2 + replacement;
          index += 3;
          sectionStart = index;
          isNormalized = true;
        } else {
          if (char < 127) {
            t1 = char >>> 4;
            if (t1 >= 8)
              return H.ioore(C.List_nxB, t1);
            t1 = (C.List_nxB[t1] & 1 << (char & 15)) !== 0;
          } else
            t1 = false;
          if (t1) {
            if (isNormalized && 65 <= char && 90 >= char) {
              if (buffer == null)
                buffer = new P.StringBuffer("");
              if (sectionStart < index) {
                buffer._contents += C.JSString_methods.substring$2(host, sectionStart, index);
                sectionStart = index;
              }
              isNormalized = false;
            }
            ++index;
          } else {
            if ((char & 64512) === 55296 && index + 1 < end) {
              tail = C.JSString_methods.codeUnitAt$1(host, index + 1);
              if ((tail & 64512) === 56320) {
                char = 65536 | (char & 1023) << 10 | tail & 1023;
                sourceLength = 2;
              } else
                sourceLength = 1;
            } else
              sourceLength = 1;
            if (buffer == null)
              buffer = new P.StringBuffer("");
            buffer._contents += C.JSString_methods.substring$2(host, sectionStart, index);
            buffer._contents += P._Uri__escapeChar(char);
            index += sourceLength;
            sectionStart = index;
          }
        }
      }
      if (buffer == null)
        return C.JSString_methods.substring$2(host, start, end);
      if (sectionStart < end)
        buffer._contents += C.JSString_methods.substring$2(host, sectionStart, end);
      t1 = buffer._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _Uri__normalizeRegName: function(host, start, end) {
      var index, sectionStart, buffer, isNormalized, char, replacement, t1, slice, t2, sourceLength, tail;
      for (index = start, sectionStart = index, buffer = null, isNormalized = true; index < end;) {
        char = C.JSString_methods.codeUnitAt$1(host, index);
        if (char === 37) {
          replacement = P._Uri__normalizeEscape(host, index, true);
          t1 = replacement == null;
          if (t1 && isNormalized) {
            index += 3;
            continue;
          }
          if (buffer == null)
            buffer = new P.StringBuffer("");
          slice = C.JSString_methods.substring$2(host, sectionStart, index);
          t2 = buffer._contents += !isNormalized ? slice.toLowerCase() : slice;
          if (t1) {
            replacement = C.JSString_methods.substring$2(host, index, index + 3);
            sourceLength = 3;
          } else if (replacement === "%") {
            replacement = "%25";
            sourceLength = 1;
          } else
            sourceLength = 3;
          buffer._contents = t2 + replacement;
          index += sourceLength;
          sectionStart = index;
          isNormalized = true;
        } else {
          if (char < 127) {
            t1 = char >>> 4;
            if (t1 >= 8)
              return H.ioore(C.List_qNA, t1);
            t1 = (C.List_qNA[t1] & 1 << (char & 15)) !== 0;
          } else
            t1 = false;
          if (t1) {
            if (isNormalized && 65 <= char && 90 >= char) {
              if (buffer == null)
                buffer = new P.StringBuffer("");
              if (sectionStart < index) {
                buffer._contents += C.JSString_methods.substring$2(host, sectionStart, index);
                sectionStart = index;
              }
              isNormalized = false;
            }
            ++index;
          } else {
            if (char <= 93) {
              t1 = char >>> 4;
              if (t1 >= 8)
                return H.ioore(C.List_2Vk, t1);
              t1 = (C.List_2Vk[t1] & 1 << (char & 15)) !== 0;
            } else
              t1 = false;
            if (t1)
              P._Uri__fail(host, index, "Invalid character");
            else {
              if ((char & 64512) === 55296 && index + 1 < end) {
                tail = C.JSString_methods.codeUnitAt$1(host, index + 1);
                if ((tail & 64512) === 56320) {
                  char = 65536 | (char & 1023) << 10 | tail & 1023;
                  sourceLength = 2;
                } else
                  sourceLength = 1;
              } else
                sourceLength = 1;
              if (buffer == null)
                buffer = new P.StringBuffer("");
              slice = C.JSString_methods.substring$2(host, sectionStart, index);
              buffer._contents += !isNormalized ? slice.toLowerCase() : slice;
              buffer._contents += P._Uri__escapeChar(char);
              index += sourceLength;
              sectionStart = index;
            }
          }
        }
      }
      if (buffer == null)
        return C.JSString_methods.substring$2(host, start, end);
      if (sectionStart < end) {
        slice = C.JSString_methods.substring$2(host, sectionStart, end);
        buffer._contents += !isNormalized ? slice.toLowerCase() : slice;
      }
      t1 = buffer._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _Uri__makeScheme: function(scheme, start, end) {
      var i, containsUpperCase, codeUnit, t1;
      if (start === end)
        return "";
      if (!P._Uri__isAlphabeticCharacter(J.getInterceptor$s(scheme)._codeUnitAt$1(scheme, start)))
        P._Uri__fail(scheme, start, "Scheme not starting with alphabetic character");
      for (i = start, containsUpperCase = false; i < end; ++i) {
        codeUnit = C.JSString_methods._codeUnitAt$1(scheme, i);
        if (codeUnit < 128) {
          t1 = codeUnit >>> 4;
          if (t1 >= 8)
            return H.ioore(C.List_JYB, t1);
          t1 = (C.List_JYB[t1] & 1 << (codeUnit & 15)) !== 0;
        } else
          t1 = false;
        if (!t1)
          P._Uri__fail(scheme, i, "Illegal scheme character");
        if (65 <= codeUnit && codeUnit <= 90)
          containsUpperCase = true;
      }
      scheme = C.JSString_methods.substring$2(scheme, start, end);
      return P._Uri__canonicalizeScheme(containsUpperCase ? scheme.toLowerCase() : scheme);
    },
    _Uri__canonicalizeScheme: function(scheme) {
      if (scheme === "http")
        return "http";
      if (scheme === "file")
        return "file";
      if (scheme === "https")
        return "https";
      if (scheme === "package")
        return "package";
      return scheme;
    },
    _Uri__makeUserInfo: function(userInfo, start, end) {
      if (userInfo == null)
        return "";
      return P._Uri__normalizeOrSubstring(userInfo, start, end, C.List_gRj, false);
    },
    _Uri__makePath: function(path, start, end, pathSegments, scheme, hasAuthority) {
      var result,
        isFile = scheme === "file",
        ensureLeadingSlash = isFile || hasAuthority,
        t1 = path == null;
      if (t1 && pathSegments == null)
        return isFile ? "/" : "";
      t1 = !t1;
      if (t1 && pathSegments != null)
        throw H.wrapException(P.ArgumentError$("Both path and pathSegments specified"));
      if (t1)
        result = P._Uri__normalizeOrSubstring(path, start, end, C.List_qg4, true);
      else {
        pathSegments.toString;
        t1 = H._arrayInstanceType(pathSegments);
        result = new H.MappedListIterable(pathSegments, t1._eval$1("String(1)")._check(new P._Uri__makePath_closure()), t1._eval$1("MappedListIterable<1,String>")).join$1(0, "/");
      }
      if (result.length === 0) {
        if (isFile)
          return "/";
      } else if (ensureLeadingSlash && !C.JSString_methods.startsWith$1(result, "/"))
        result = "/" + result;
      return P._Uri__normalizePath(result, scheme, hasAuthority);
    },
    _Uri__normalizePath: function(path, scheme, hasAuthority) {
      var t1 = scheme.length === 0;
      if (t1 && !hasAuthority && !C.JSString_methods.startsWith$1(path, "/"))
        return P._Uri__normalizeRelativePath(path, !t1 || hasAuthority);
      return P._Uri__removeDotSegments(path);
    },
    _Uri__makeQuery: function(query, start, end, queryParameters) {
      if (query != null)
        return P._Uri__normalizeOrSubstring(query, start, end, C.List_CVk, true);
      return null;
    },
    _Uri__makeFragment: function(fragment, start, end) {
      if (fragment == null)
        return null;
      return P._Uri__normalizeOrSubstring(fragment, start, end, C.List_CVk, true);
    },
    _Uri__normalizeEscape: function(source, index, lowerCase) {
      var t1, firstDigit, secondDigit, firstDigitValue, secondDigitValue, value;
      H.assertHelper(C.JSString_methods.codeUnitAt$1(source, index) === 37);
      t1 = index + 2;
      if (t1 >= source.length)
        return "%";
      firstDigit = C.JSString_methods.codeUnitAt$1(source, index + 1);
      secondDigit = C.JSString_methods.codeUnitAt$1(source, t1);
      firstDigitValue = H.hexDigitValue(firstDigit);
      secondDigitValue = H.hexDigitValue(secondDigit);
      if (firstDigitValue < 0 || secondDigitValue < 0)
        return "%";
      value = firstDigitValue * 16 + secondDigitValue;
      if (value < 127) {
        t1 = C.JSInt_methods._shrOtherPositive$1(value, 4);
        if (t1 >= 8)
          return H.ioore(C.List_nxB, t1);
        t1 = (C.List_nxB[t1] & 1 << (value & 15)) !== 0;
      } else
        t1 = false;
      if (t1)
        return H.Primitives_stringFromCharCode(lowerCase && 65 <= value && 90 >= value ? (value | 32) >>> 0 : value);
      if (firstDigit >= 97 || secondDigit >= 97)
        return C.JSString_methods.substring$2(source, index, index + 3).toUpperCase();
      return null;
    },
    _Uri__escapeChar: function(char) {
      var t1, codeUnits, flag, encodedBytes, index, byte,
        _s16_ = "0123456789ABCDEF";
      H.assertHelper(char <= 1114111);
      if (char < 128) {
        t1 = new Array(3);
        t1.fixed$length = Array;
        codeUnits = H.setRuntimeTypeInfo(t1, type$.JSArray_int);
        C.JSArray_methods.$indexSet(codeUnits, 0, 37);
        C.JSArray_methods.$indexSet(codeUnits, 1, C.JSString_methods._codeUnitAt$1(_s16_, char >>> 4));
        C.JSArray_methods.$indexSet(codeUnits, 2, C.JSString_methods._codeUnitAt$1(_s16_, char & 15));
      } else {
        if (char > 2047)
          if (char > 65535) {
            flag = 240;
            encodedBytes = 4;
          } else {
            flag = 224;
            encodedBytes = 3;
          }
        else {
          flag = 192;
          encodedBytes = 2;
        }
        t1 = new Array(3 * encodedBytes);
        t1.fixed$length = Array;
        codeUnits = H.setRuntimeTypeInfo(t1, type$.JSArray_int);
        for (index = 0; --encodedBytes, encodedBytes >= 0; flag = 128) {
          byte = C.JSInt_methods._shrReceiverPositive$1(char, 6 * encodedBytes) & 63 | flag;
          C.JSArray_methods.$indexSet(codeUnits, index, 37);
          C.JSArray_methods.$indexSet(codeUnits, index + 1, C.JSString_methods._codeUnitAt$1(_s16_, byte >>> 4));
          C.JSArray_methods.$indexSet(codeUnits, index + 2, C.JSString_methods._codeUnitAt$1(_s16_, byte & 15));
          index += 3;
        }
      }
      return P.String_String$fromCharCodes(codeUnits, 0, null);
    },
    _Uri__normalizeOrSubstring: function(component, start, end, charTable, escapeDelimiters) {
      var t1 = P._Uri__normalize(component, start, end, charTable, escapeDelimiters);
      return t1 == null ? C.JSString_methods.substring$2(component, start, end) : t1;
    },
    _Uri__normalize: function(component, start, end, charTable, escapeDelimiters) {
      var t1, index, sectionStart, buffer, char, t2, replacement, sourceLength, tail, _null = null;
      for (t1 = !escapeDelimiters, index = start, sectionStart = index, buffer = _null; index < end;) {
        char = C.JSString_methods.codeUnitAt$1(component, index);
        if (char < 127) {
          t2 = char >>> 4;
          if (t2 >= 8)
            return H.ioore(charTable, t2);
          t2 = (charTable[t2] & 1 << (char & 15)) !== 0;
        } else
          t2 = false;
        if (t2)
          ++index;
        else {
          if (char === 37) {
            replacement = P._Uri__normalizeEscape(component, index, false);
            if (replacement == null) {
              index += 3;
              continue;
            }
            if ("%" === replacement) {
              replacement = "%25";
              sourceLength = 1;
            } else
              sourceLength = 3;
          } else {
            if (t1)
              if (char <= 93) {
                t2 = char >>> 4;
                if (t2 >= 8)
                  return H.ioore(C.List_2Vk, t2);
                t2 = (C.List_2Vk[t2] & 1 << (char & 15)) !== 0;
              } else
                t2 = false;
            else
              t2 = false;
            if (t2) {
              P._Uri__fail(component, index, "Invalid character");
              sourceLength = _null;
              replacement = sourceLength;
            } else {
              if ((char & 64512) === 55296) {
                t2 = index + 1;
                if (t2 < end) {
                  tail = C.JSString_methods.codeUnitAt$1(component, t2);
                  if ((tail & 64512) === 56320) {
                    char = 65536 | (char & 1023) << 10 | tail & 1023;
                    sourceLength = 2;
                  } else
                    sourceLength = 1;
                } else
                  sourceLength = 1;
              } else
                sourceLength = 1;
              replacement = P._Uri__escapeChar(char);
            }
          }
          if (buffer == null)
            buffer = new P.StringBuffer("");
          buffer._contents += C.JSString_methods.substring$2(component, sectionStart, index);
          buffer._contents += H.S(replacement);
          if (typeof sourceLength !== "number")
            return H.iae(sourceLength);
          index += sourceLength;
          sectionStart = index;
        }
      }
      if (buffer == null)
        return _null;
      if (sectionStart < end)
        buffer._contents += C.JSString_methods.substring$2(component, sectionStart, end);
      t1 = buffer._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _Uri__mayContainDotSegments: function(path) {
      if (C.JSString_methods.startsWith$1(path, "."))
        return true;
      return C.JSString_methods.indexOf$1(path, "/.") !== -1;
    },
    _Uri__removeDotSegments: function(path) {
      var output, t1, t2, appendSlash, _i, segment, t3;
      if (!P._Uri__mayContainDotSegments(path))
        return path;
      H.assertHelper(path.length !== 0);
      output = H.setRuntimeTypeInfo([], type$.JSArray_String);
      for (t1 = path.split("/"), t2 = t1.length, appendSlash = false, _i = 0; _i < t2; ++_i) {
        segment = t1[_i];
        if (J.$eq$(segment, "..")) {
          t3 = output.length;
          if (t3 !== 0) {
            if (0 >= t3)
              return H.ioore(output, -1);
            output.pop();
            if (output.length === 0)
              C.JSArray_methods.add$1(output, "");
          }
          appendSlash = true;
        } else if ("." === segment)
          appendSlash = true;
        else {
          C.JSArray_methods.add$1(output, segment);
          appendSlash = false;
        }
      }
      if (appendSlash)
        C.JSArray_methods.add$1(output, "");
      return C.JSArray_methods.join$1(output, "/");
    },
    _Uri__normalizeRelativePath: function(path, allowScheme) {
      var output, t1, t2, appendSlash, _i, segment;
      H.assertHelper(!C.JSString_methods.startsWith$1(path, "/"));
      if (!P._Uri__mayContainDotSegments(path))
        return !allowScheme ? P._Uri__escapeScheme(path) : path;
      H.assertHelper(path.length !== 0);
      output = H.setRuntimeTypeInfo([], type$.JSArray_String);
      for (t1 = path.split("/"), t2 = t1.length, appendSlash = false, _i = 0; _i < t2; ++_i) {
        segment = t1[_i];
        if (".." === segment)
          if (output.length !== 0 && C.JSArray_methods.get$last(output) !== "..") {
            if (0 >= output.length)
              return H.ioore(output, -1);
            output.pop();
            appendSlash = true;
          } else {
            C.JSArray_methods.add$1(output, "..");
            appendSlash = false;
          }
        else if ("." === segment)
          appendSlash = true;
        else {
          C.JSArray_methods.add$1(output, segment);
          appendSlash = false;
        }
      }
      t1 = output.length;
      if (t1 !== 0)
        if (t1 === 1) {
          if (0 >= t1)
            return H.ioore(output, 0);
          t1 = output[0].length === 0;
        } else
          t1 = false;
      else
        t1 = true;
      if (t1)
        return "./";
      if (appendSlash || C.JSArray_methods.get$last(output) === "..")
        C.JSArray_methods.add$1(output, "");
      if (!allowScheme) {
        if (0 >= output.length)
          return H.ioore(output, 0);
        C.JSArray_methods.$indexSet(output, 0, P._Uri__escapeScheme(output[0]));
      }
      return C.JSArray_methods.join$1(output, "/");
    },
    _Uri__escapeScheme: function(path) {
      var i, char, t2,
        t1 = path.length;
      if (t1 >= 2 && P._Uri__isAlphabeticCharacter(J._codeUnitAt$1$s(path, 0)))
        for (i = 1; i < t1; ++i) {
          char = C.JSString_methods._codeUnitAt$1(path, i);
          if (char === 58)
            return C.JSString_methods.substring$2(path, 0, i) + "%3A" + C.JSString_methods.substring$1(path, i + 1);
          if (char <= 127) {
            t2 = char >>> 4;
            if (t2 >= 8)
              return H.ioore(C.List_JYB, t2);
            t2 = (C.List_JYB[t2] & 1 << (char & 15)) === 0;
          } else
            t2 = true;
          if (t2)
            break;
        }
      return path;
    },
    _Uri__toWindowsFilePath: function(uri) {
      var hasDriveLetter, t2, host,
        segments = uri.get$pathSegments(),
        t1 = segments.length;
      if (t1 > 0 && J.get$length$asx(segments[0]) === 2 && J.codeUnitAt$1$s(segments[0], 1) === 58) {
        if (0 >= t1)
          return H.ioore(segments, 0);
        P._Uri__checkWindowsDriveLetter(J.codeUnitAt$1$s(segments[0], 0), false);
        P._Uri__checkWindowsPathReservedCharacters(segments, false, 1);
        hasDriveLetter = true;
      } else {
        P._Uri__checkWindowsPathReservedCharacters(segments, false, 0);
        hasDriveLetter = false;
      }
      t2 = uri.get$hasAbsolutePath() && !hasDriveLetter ? "\\" : "";
      if (uri.get$hasAuthority()) {
        host = uri.get$host(uri);
        if (host.length !== 0)
          t2 = t2 + "\\" + host + "\\";
      }
      t2 = P.StringBuffer__writeAll(t2, segments, "\\");
      t1 = hasDriveLetter && t1 === 1 ? t2 + "\\" : t2;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _Uri__hexCharPairToByte: function(s, pos) {
      var byte, i, charCode;
      for (byte = 0, i = 0; i < 2; ++i) {
        charCode = C.JSString_methods._codeUnitAt$1(s, pos + i);
        if (48 <= charCode && charCode <= 57)
          byte = byte * 16 + charCode - 48;
        else {
          charCode |= 32;
          if (97 <= charCode && charCode <= 102)
            byte = byte * 16 + charCode - 87;
          else
            throw H.wrapException(P.ArgumentError$("Invalid URL encoding"));
        }
      }
      return byte;
    },
    _Uri__uriDecode: function(text, start, end, encoding, plusToSpace) {
      var t1, simple, t2, i, codeUnit, t3, bytes;
      H.assertHelper(start <= end);
      t1 = text.length;
      H.assertHelper(end <= t1);
      t2 = J.getInterceptor$s(text);
      i = start;
      while (true) {
        if (!(i < end)) {
          simple = true;
          break;
        }
        codeUnit = t2._codeUnitAt$1(text, i);
        if (codeUnit <= 127)
          if (codeUnit !== 37)
            t3 = false;
          else
            t3 = true;
        else
          t3 = true;
        if (t3) {
          simple = false;
          break;
        }
        ++i;
      }
      if (simple) {
        if (C.C_Utf8Codec !== encoding)
          t1 = false;
        else
          t1 = true;
        if (t1)
          return t2.substring$2(text, start, end);
        else
          bytes = new H.CodeUnits(t2.substring$2(text, start, end));
      } else {
        bytes = H.setRuntimeTypeInfo([], type$.JSArray_int);
        for (i = start; i < end; ++i) {
          codeUnit = t2._codeUnitAt$1(text, i);
          if (codeUnit > 127)
            throw H.wrapException(P.ArgumentError$("Illegal percent encoding in URI"));
          if (codeUnit === 37) {
            if (i + 3 > t1)
              throw H.wrapException(P.ArgumentError$("Truncated URI"));
            C.JSArray_methods.add$1(bytes, P._Uri__hexCharPairToByte(text, i + 1));
            i += 2;
          } else
            C.JSArray_methods.add$1(bytes, codeUnit);
        }
      }
      type$.List_int._check(bytes);
      return new P.Utf8Decoder(false).convert$1(bytes);
    },
    _Uri__isAlphabeticCharacter: function(codeUnit) {
      var lowerCase = codeUnit | 32;
      return 97 <= lowerCase && lowerCase <= 122;
    },
    UriData__writeUri: function(mimeType, charsetName, parameters, buffer, indices) {
      var slashIndex, t1;
      if (true)
        buffer._contents = buffer._contents;
      else {
        slashIndex = P.UriData__validateMimeType("");
        if (slashIndex < 0)
          throw H.wrapException(P.ArgumentError$value("", "mimeType", "Invalid MIME type"));
        t1 = buffer._contents += H.S(P._Uri__uriEncode(C.List_qFt, C.JSString_methods.substring$2("", 0, slashIndex), C.C_Utf8Codec, false));
        buffer._contents = t1 + "/";
        buffer._contents += H.S(P._Uri__uriEncode(C.List_qFt, C.JSString_methods.substring$1("", slashIndex + 1), C.C_Utf8Codec, false));
      }
    },
    UriData__validateMimeType: function(mimeType) {
      var t1, slashIndex, i;
      for (t1 = mimeType.length, slashIndex = -1, i = 0; i < t1; ++i) {
        if (C.JSString_methods._codeUnitAt$1(mimeType, i) !== 47)
          continue;
        if (slashIndex < 0) {
          slashIndex = i;
          continue;
        }
        return -1;
      }
      return slashIndex;
    },
    UriData__parse: function(text, start, sourceUri) {
      var indices, t1, i, slashIndex, char, equalsIndex, lastSeparator, t2, data,
        _s17_ = "Invalid MIME type";
      H.assertHelper(start === 0 || start === 5);
      H.assertHelper(start === 5 === C.JSString_methods.startsWith$1(text, "data:"));
      indices = H.setRuntimeTypeInfo([start - 1], type$.JSArray_int);
      for (t1 = text.length, i = start, slashIndex = -1, char = null; i < t1; ++i) {
        char = C.JSString_methods._codeUnitAt$1(text, i);
        if (char === 44 || char === 59)
          break;
        if (char === 47) {
          if (slashIndex < 0) {
            slashIndex = i;
            continue;
          }
          throw H.wrapException(P.FormatException$(_s17_, text, i));
        }
      }
      if (slashIndex < 0 && i > start)
        throw H.wrapException(P.FormatException$(_s17_, text, i));
      for (; char !== 44;) {
        C.JSArray_methods.add$1(indices, i);
        ++i;
        for (equalsIndex = -1; i < t1; ++i) {
          char = C.JSString_methods._codeUnitAt$1(text, i);
          if (char === 61) {
            if (equalsIndex < 0)
              equalsIndex = i;
          } else if (char === 59 || char === 44)
            break;
        }
        if (equalsIndex >= 0)
          C.JSArray_methods.add$1(indices, equalsIndex);
        else {
          lastSeparator = C.JSArray_methods.get$last(indices);
          if (char !== 44 || i !== lastSeparator + 7 || !C.JSString_methods.startsWith$2(text, "base64", lastSeparator + 1))
            throw H.wrapException(P.FormatException$("Expecting '='", text, i));
          break;
        }
      }
      C.JSArray_methods.add$1(indices, i);
      t2 = i + 1;
      if ((indices.length & 1) === 1)
        text = C.C_Base64Codec.normalize$3(text, t2, t1);
      else {
        data = P._Uri__normalize(text, t2, t1, C.List_CVk, true);
        if (data != null)
          text = C.JSString_methods.replaceRange$3(text, t2, t1, data);
      }
      return new P.UriData(text, indices, sourceUri);
    },
    UriData__uriEncodeBytes: function(canonicalTable, bytes, buffer) {
      var t1, byteOr, i, byte, t2, t3,
        _s16_ = "0123456789ABCDEF";
      for (t1 = J.getInterceptor$asx(bytes), byteOr = 0, i = 0; i < t1.get$length(bytes); ++i) {
        byte = t1.$index(bytes, i);
        if (typeof byte !== "number")
          return H.iae(byte);
        byteOr |= byte;
        if (byte < 128) {
          t2 = C.JSInt_methods._shrOtherPositive$1(byte, 4);
          if (t2 >= 8)
            return H.ioore(canonicalTable, t2);
          t2 = (canonicalTable[t2] & 1 << (byte & 15)) !== 0;
        } else
          t2 = false;
        t3 = buffer._contents;
        if (t2)
          buffer._contents = t3 + H.Primitives_stringFromCharCode(byte);
        else {
          t2 = t3 + H.Primitives_stringFromCharCode(37);
          buffer._contents = t2;
          t2 += H.Primitives_stringFromCharCode(C.JSString_methods._codeUnitAt$1(_s16_, C.JSInt_methods._shrOtherPositive$1(byte, 4)));
          buffer._contents = t2;
          buffer._contents = t2 + H.Primitives_stringFromCharCode(C.JSString_methods._codeUnitAt$1(_s16_, byte & 15));
        }
      }
      if ((byteOr & 4294967040) >>> 0 !== 0)
        for (i = 0; i < t1.get$length(bytes); ++i) {
          byte = t1.$index(bytes, i);
          if (typeof byte !== "number")
            return byte.$lt();
          if (byte < 0 || byte > 255)
            throw H.wrapException(P.ArgumentError$value(byte, "non-byte value", null));
        }
    },
    _createTables: function() {
      var _s77_ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~!$&'()*+,;=",
        _s1_ = ".", _s1_0 = ":", _s1_1 = "/", _s1_2 = "?", _s1_3 = "#",
        t1 = type$.Uint8List,
        tables = P.List_List$generate(22, new P._createTables_closure(), true, t1),
        t2 = new P._createTables_build(tables),
        t3 = new P._createTables_setChars(),
        t4 = new P._createTables_setRange(),
        t5 = t1._check(t2.call$2(0, 225));
      t3.call$3(t5, _s77_, 1);
      t3.call$3(t5, _s1_, 14);
      t3.call$3(t5, _s1_0, 34);
      t3.call$3(t5, _s1_1, 3);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(14, 225));
      t3.call$3(t5, _s77_, 1);
      t3.call$3(t5, _s1_, 15);
      t3.call$3(t5, _s1_0, 34);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(15, 225));
      t3.call$3(t5, _s77_, 1);
      t3.call$3(t5, "%", 225);
      t3.call$3(t5, _s1_0, 34);
      t3.call$3(t5, _s1_1, 9);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(1, 225));
      t3.call$3(t5, _s77_, 1);
      t3.call$3(t5, _s1_0, 34);
      t3.call$3(t5, _s1_1, 10);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(2, 235));
      t3.call$3(t5, _s77_, 139);
      t3.call$3(t5, _s1_1, 131);
      t3.call$3(t5, _s1_, 146);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(3, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_1, 68);
      t3.call$3(t5, _s1_, 18);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(4, 229));
      t3.call$3(t5, _s77_, 5);
      t4.call$3(t5, "AZ", 229);
      t3.call$3(t5, _s1_0, 102);
      t3.call$3(t5, "@", 68);
      t3.call$3(t5, "[", 232);
      t3.call$3(t5, _s1_1, 138);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(5, 229));
      t3.call$3(t5, _s77_, 5);
      t4.call$3(t5, "AZ", 229);
      t3.call$3(t5, _s1_0, 102);
      t3.call$3(t5, "@", 68);
      t3.call$3(t5, _s1_1, 138);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(6, 231));
      t4.call$3(t5, "19", 7);
      t3.call$3(t5, "@", 68);
      t3.call$3(t5, _s1_1, 138);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(7, 231));
      t4.call$3(t5, "09", 7);
      t3.call$3(t5, "@", 68);
      t3.call$3(t5, _s1_1, 138);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t3.call$3(t1._check(t2.call$2(8, 8)), "]", 5);
      t5 = t1._check(t2.call$2(9, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_, 16);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(16, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_, 17);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(17, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_1, 9);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(10, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_, 18);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(18, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_, 19);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(19, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_1, 234);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(11, 235));
      t3.call$3(t5, _s77_, 11);
      t3.call$3(t5, _s1_1, 10);
      t3.call$3(t5, _s1_2, 172);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(12, 236));
      t3.call$3(t5, _s77_, 12);
      t3.call$3(t5, _s1_2, 12);
      t3.call$3(t5, _s1_3, 205);
      t5 = t1._check(t2.call$2(13, 237));
      t3.call$3(t5, _s77_, 13);
      t3.call$3(t5, _s1_2, 13);
      t4.call$3(t1._check(t2.call$2(20, 245)), "az", 21);
      t2 = t1._check(t2.call$2(21, 245));
      t4.call$3(t2, "az", 21);
      t4.call$3(t2, "09", 21);
      t3.call$3(t2, "+-.", 21);
      return tables;
    },
    _scan: function(uri, start, end, state, indices) {
      var t1, i, table, char, transition,
        tables = $.$get$_scannerTables();
      H.assertHelper(end <= uri.length);
      for (t1 = J.getInterceptor$s(uri), i = start; i < end; ++i) {
        if (state < 0 || state >= tables.length)
          return H.ioore(tables, state);
        table = tables[state];
        char = t1._codeUnitAt$1(uri, i) ^ 96;
        if (char > 95)
          char = 31;
        if (char >= table.length)
          return H.ioore(table, char);
        transition = table[char];
        state = transition & 31;
        C.JSArray_methods.$indexSet(indices, transition >>> 5, i);
      }
      return state;
    },
    bool: function bool() {
    },
    DateTime: function DateTime(t0, t1) {
      this._value = t0;
      this.isUtc = t1;
    },
    double: function double() {
    },
    Duration: function Duration(t0) {
      this._duration = t0;
    },
    Duration_toString_sixDigits: function Duration_toString_sixDigits() {
    },
    Duration_toString_twoDigits: function Duration_toString_twoDigits() {
    },
    Error: function Error() {
    },
    AssertionError: function AssertionError(t0) {
      this.message = t0;
    },
    NullThrownError: function NullThrownError() {
    },
    ArgumentError: function ArgumentError(t0, t1, t2, t3) {
      var _ = this;
      _._hasValue = t0;
      _.invalidValue = t1;
      _.name = t2;
      _.message = t3;
    },
    RangeError: function RangeError(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _.start = t0;
      _.end = t1;
      _._hasValue = t2;
      _.invalidValue = t3;
      _.name = t4;
      _.message = t5;
    },
    IndexError: function IndexError(t0, t1, t2, t3, t4) {
      var _ = this;
      _.length = t0;
      _._hasValue = t1;
      _.invalidValue = t2;
      _.name = t3;
      _.message = t4;
    },
    UnsupportedError: function UnsupportedError(t0) {
      this.message = t0;
    },
    UnimplementedError: function UnimplementedError(t0) {
      this.message = t0;
    },
    StateError: function StateError(t0) {
      this.message = t0;
    },
    ConcurrentModificationError: function ConcurrentModificationError(t0) {
      this.modifiedObject = t0;
    },
    OutOfMemoryError: function OutOfMemoryError() {
    },
    StackOverflowError: function StackOverflowError() {
    },
    CyclicInitializationError: function CyclicInitializationError(t0) {
      this.variableName = t0;
    },
    _Exception: function _Exception(t0) {
      this.message = t0;
    },
    FormatException: function FormatException(t0, t1, t2) {
      this.message = t0;
      this.source = t1;
      this.offset = t2;
    },
    Expando: function Expando(t0, t1, t2) {
      this._jsWeakMapOrKey = t0;
      this.name = t1;
      this.$ti = t2;
    },
    Function: function Function() {
    },
    int: function int() {
    },
    Iterable: function Iterable() {
    },
    Iterator: function Iterator() {
    },
    List: function List() {
    },
    Map: function Map() {
    },
    MapEntry: function MapEntry(t0, t1, t2) {
      this.key = t0;
      this.value = t1;
      this.$ti = t2;
    },
    Null: function Null() {
    },
    num: function num() {
    },
    Object: function Object() {
    },
    Pattern: function Pattern() {
    },
    Match: function Match() {
    },
    RegExpMatch: function RegExpMatch() {
    },
    Set: function Set() {
    },
    StackTrace: function StackTrace() {
    },
    _StringStackTrace: function _StringStackTrace(t0) {
      this._stackTrace = t0;
    },
    Stopwatch: function Stopwatch() {
      this._stop = this._core$_start = 0;
    },
    String: function String() {
    },
    Runes: function Runes(t0) {
      this.string = t0;
    },
    RuneIterator: function RuneIterator(t0) {
      var _ = this;
      _.string = t0;
      _._nextPosition = _._core$_position = 0;
      _._currentCodePoint = null;
    },
    StringBuffer: function StringBuffer(t0) {
      this._contents = t0;
    },
    Uri: function Uri() {
    },
    Uri__parseIPv4Address_error: function Uri__parseIPv4Address_error(t0) {
      this.host = t0;
    },
    Uri_parseIPv6Address_error: function Uri_parseIPv6Address_error(t0) {
      this.host = t0;
    },
    Uri_parseIPv6Address_parseHex: function Uri_parseIPv6Address_parseHex(t0, t1) {
      this.error = t0;
      this.host = t1;
    },
    _Uri: function _Uri(t0, t1, t2, t3, t4, t5, t6) {
      var _ = this;
      _.scheme = t0;
      _._userInfo = t1;
      _._host = t2;
      _._port = t3;
      _.path = t4;
      _._query = t5;
      _._fragment = t6;
      _._hashCodeCache = _._text = _._pathSegments = null;
    },
    _Uri__Uri$notSimple_closure: function _Uri__Uri$notSimple_closure(t0, t1) {
      this.uri = t0;
      this.portStart = t1;
    },
    _Uri__checkNonWindowsPathReservedCharacters_closure: function _Uri__checkNonWindowsPathReservedCharacters_closure(t0) {
      this.argumentError = t0;
    },
    _Uri__makePath_closure: function _Uri__makePath_closure() {
    },
    UriData: function UriData(t0, t1, t2) {
      this._text = t0;
      this._separatorIndices = t1;
      this._uriCache = t2;
    },
    _createTables_closure: function _createTables_closure() {
    },
    _createTables_build: function _createTables_build(t0) {
      this.tables = t0;
    },
    _createTables_setChars: function _createTables_setChars() {
    },
    _createTables_setRange: function _createTables_setRange() {
    },
    _SimpleUri: function _SimpleUri(t0, t1, t2, t3, t4, t5, t6, t7) {
      var _ = this;
      _._uri = t0;
      _._schemeEnd = t1;
      _._hostStart = t2;
      _._portStart = t3;
      _._pathStart = t4;
      _._queryStart = t5;
      _._fragmentStart = t6;
      _._schemeCache = t7;
      _._hashCodeCache = null;
    },
    _DataUri: function _DataUri(t0, t1, t2, t3, t4, t5, t6) {
      var _ = this;
      _.scheme = t0;
      _._userInfo = t1;
      _._host = t2;
      _._port = t3;
      _.path = t4;
      _._query = t5;
      _._fragment = t6;
      _._hashCodeCache = _._text = _._pathSegments = null;
    },
    _StructuredClone: function _StructuredClone() {
    },
    _StructuredClone_walk_closure: function _StructuredClone_walk_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    _StructuredClone_walk_closure0: function _StructuredClone_walk_closure0(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    _AcceptStructuredClone: function _AcceptStructuredClone() {
    },
    _AcceptStructuredClone_walk_closure: function _AcceptStructuredClone_walk_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    _StructuredCloneDart2Js: function _StructuredCloneDart2Js(t0, t1) {
      this.values = t0;
      this.copies = t1;
    },
    _AcceptStructuredCloneDart2Js: function _AcceptStructuredCloneDart2Js(t0, t1) {
      this.values = t0;
      this.copies = t1;
      this.mustCopy = false;
    },
    _convertDataTree: function(data) {
      return new P._convertDataTree__convert(new P._IdentityHashMap(type$._IdentityHashMap_dynamic_dynamic)).call$1(data);
    },
    promiseToFuture: function(jsPromise, $T) {
      var t1 = new P._Future($.Zone__current, $T._eval$1("_Future<0>")),
        completer = new P._AsyncCompleter(t1, $T._eval$1("_AsyncCompleter<0>"));
      jsPromise.then(H.convertDartClosureToJS(new P.promiseToFuture_closure(completer, $T), 1), H.convertDartClosureToJS(new P.promiseToFuture_closure0(completer), 1));
      return t1;
    },
    _convertDataTree__convert: function _convertDataTree__convert(t0) {
      this._convertedObjects = t0;
    },
    promiseToFuture_closure: function promiseToFuture_closure(t0, t1) {
      this.completer = t0;
      this.T = t1;
    },
    promiseToFuture_closure0: function promiseToFuture_closure0(t0) {
      this.completer = t0;
    },
    ByteBuffer: function ByteBuffer() {
    },
    ByteData: function ByteData() {
    },
    Int8List: function Int8List() {
    },
    Uint8List: function Uint8List() {
    },
    Uint8ClampedList: function Uint8ClampedList() {
    },
    Int16List: function Int16List() {
    },
    Uint16List: function Uint16List() {
    },
    Int32List: function Int32List() {
    },
    Uint32List: function Uint32List() {
    },
    Float32List: function Float32List() {
    },
    Float64List: function Float64List() {
    },
    SqlError: function SqlError() {
    },
    max: function(a, b, $T) {
      H.checkTypeBound($T, type$.num, "T", "max");
      $T._check(a);
      $T._check(b);
      return Math.max(H.checkNum(a), H.checkNum(b));
    },
    pow: function(x, exponent) {
      return Math.pow(x, exponent);
    }
  },
  W = {
    _EventStreamSubscription$: function(_target, _eventType, onData, _useCapture, $T) {
      var t1 = onData == null ? null : W._wrapZone(new W._EventStreamSubscription_closure(onData), type$.Event);
      t1 = new W._EventStreamSubscription(_target, _eventType, t1, false, $T._eval$1("_EventStreamSubscription<0>"));
      t1._tryResume$0();
      return t1;
    },
    _wrapZone: function(callback, $T) {
      var t1 = $.Zone__current;
      if (t1 === C.C__RootZone)
        return callback;
      return t1.bindUnaryCallbackGuarded$1$1(callback, $T);
    },
    ApplicationCacheErrorEvent: function ApplicationCacheErrorEvent() {
    },
    Blob: function Blob() {
    },
    DomError: function DomError() {
    },
    DomException: function DomException() {
    },
    ErrorEvent: function ErrorEvent() {
    },
    Event: function Event() {
    },
    EventTarget: function EventTarget() {
    },
    File: function File() {
    },
    Location: function Location() {
    },
    MediaError: function MediaError() {
    },
    MediaKeyMessageEvent: function MediaKeyMessageEvent() {
    },
    MessageEvent: function MessageEvent() {
    },
    MessagePort: function MessagePort() {
    },
    NavigatorUserMediaError: function NavigatorUserMediaError() {
    },
    OverconstrainedError: function OverconstrainedError() {
    },
    PositionError: function PositionError() {
    },
    PresentationConnectionCloseEvent: function PresentationConnectionCloseEvent() {
    },
    SpeechRecognitionError: function SpeechRecognitionError() {
    },
    EventStreamProvider: function EventStreamProvider(t0) {
      this.$ti = t0;
    },
    _EventStream: function _EventStream(t0, t1, t2, t3) {
      var _ = this;
      _._html$_target = t0;
      _._eventType = t1;
      _._useCapture = t2;
      _.$ti = t3;
    },
    _EventStreamSubscription: function _EventStreamSubscription(t0, t1, t2, t3, t4) {
      var _ = this;
      _._pauseCount = 0;
      _._html$_target = t0;
      _._eventType = t1;
      _._html$_onData = t2;
      _._useCapture = t3;
      _.$ti = t4;
    },
    _EventStreamSubscription_closure: function _EventStreamSubscription_closure(t0) {
      this.onData = t0;
    }
  },
  S = {AsyncMemoizer: function AsyncMemoizer(t0, t1) {
      this._async_memoizer$_completer = t0;
      this.$ti = t1;
    }, NullStreamSink: function NullStreamSink(t0, t1) {
      var _ = this;
      _.done = t0;
      _._addingStream = _._null_stream_sink$_closed = false;
      _.$ti = t1;
    }, NullStreamSink_addStream_closure: function NullStreamSink_addStream_closure(t0) {
      this.$this = t0;
    }, Validator: function Validator(t0) {
      this._isDefined = t0;
    },
    SpanScanner$: function(string) {
      var t1, t2;
      string.toString;
      t1 = new H.CodeUnits(string);
      t2 = H.setRuntimeTypeInfo([0], type$.JSArray_int);
      t2 = new Y.SourceFile(null, t2, new Uint32Array(H._ensureNativeList(t1.toList$0(t1))));
      t2.SourceFile$decoded$2$url(t1, null);
      return new S.SpanScanner(t2, null, string);
    },
    SpanScanner: function SpanScanner(t0, t1, t2) {
      var _ = this;
      _._sourceFile = t0;
      _._lastSpan = null;
      _.sourceUrl = t1;
      _.string = t2;
      _._string_scanner$_position = 0;
      _._lastMatchPosition = _._lastMatch = null;
    },
    _SpanScannerState: function _SpanScannerState(t0, t1) {
      this._span_scanner$_scanner = t0;
      this.position = t1;
    },
    RemoteListener_start: function(getMain, beforeLoad, hidePrints) {
      var printZone, spec, t3, _null = null, t1 = {},
        controller = B.StreamChannelController$(false, true, type$.Object),
        t2 = type$.dynamic,
        channel = D._MultiChannel$(controller._local, t2);
      t1.verboseChain = true;
      printZone = $.Zone__current;
      spec = P._ZoneSpecification$(_null, _null, _null, _null, _null, new S.RemoteListener_start_closure(printZone, channel), _null, _null, _null, _null, _null, _null, _null);
      P.Stream_Stream$fromIterable([], t2).listen$1(new S.RemoteListener_start_closure0()).cancel$0();
      t3 = type$.String;
      P.runZoned(type$.Null_Function._check(new S.RemoteListener_start_closure1(t1, getMain, channel, controller, beforeLoad, printZone, spec)), _null, _null, P.LinkedHashMap_LinkedHashMap$_literal([$.$get$_currentKey(), new N.SuiteChannelManager(P.LinkedHashMap_LinkedHashMap$_empty(t3, type$.StreamChannel_dynamic), P.LinkedHashMap_LinkedHashMap$_empty(t3, type$.StreamChannelCompleter_dynamic), P.LinkedHashSet_LinkedHashSet$_empty(t3))], t2, t2), type$.Null);
      return controller._foreign;
    },
    RemoteListener__deserializeSet: function(list) {
      if (list == null)
        return null;
      if (J.get$isEmpty$asx(list))
        return null;
      return P.LinkedHashSet_LinkedHashSet$from(list, type$.String);
    },
    RemoteListener__sendLoadException: function(channel, message) {
      var t1 = type$.String;
      channel._mainController._foreign._sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "loadException", "message", message], t1, t1));
    },
    RemoteListener__sendError: function(channel, error, stackTrace, verboseChain) {
      channel._mainController._foreign._sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "error", "error", U.RemoteException_serialize(error, type$.StackTraceFormatter._as($.Zone__current.$index(0, $.$get$_currentKey0())).formatStackTrace$2$verbose(stackTrace, verboseChain))], type$.String, type$.Object));
    },
    RemoteListener: function RemoteListener(t0, t1) {
      this._suite = t0;
      this._printZone = t1;
    },
    RemoteListener_start_closure: function RemoteListener_start_closure(t0, t1) {
      this.printZone = t0;
      this.channel = t1;
    },
    RemoteListener_start_closure0: function RemoteListener_start_closure0() {
    },
    RemoteListener_start_closure1: function RemoteListener_start_closure1(t0, t1, t2, t3, t4, t5, t6) {
      var _ = this;
      _._box_0 = t0;
      _.getMain = t1;
      _.channel = t2;
      _.controller = t3;
      _.beforeLoad = t4;
      _.printZone = t5;
      _.spec = t6;
    },
    RemoteListener_start__closure: function RemoteListener_start__closure(t0, t1, t2, t3, t4, t5, t6) {
      var _ = this;
      _._box_0 = t0;
      _.getMain = t1;
      _.channel = t2;
      _.controller = t3;
      _.beforeLoad = t4;
      _.printZone = t5;
      _.spec = t6;
    },
    RemoteListener_start___closure: function RemoteListener_start___closure(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _._box_0 = t0;
      _.getMain = t1;
      _.channel = t2;
      _.controller = t3;
      _.beforeLoad = t4;
      _.printZone = t5;
    },
    RemoteListener_start____closure: function RemoteListener_start____closure(t0, t1) {
      this.controller = t0;
      this.channel = t1;
    },
    RemoteListener_start____closure0: function RemoteListener_start____closure0(t0, t1, t2) {
      this.suite = t0;
      this.printZone = t1;
      this.channel = t2;
    },
    RemoteListener_start_____closure: function RemoteListener_start_____closure(t0, t1, t2) {
      this.suite = t0;
      this.printZone = t1;
      this.channel = t2;
    },
    RemoteListener_start___closure0: function RemoteListener_start___closure0(t0, t1) {
      this._box_0 = t0;
      this.channel = t1;
    },
    RemoteListener__serializeGroup_closure: function RemoteListener__serializeGroup_closure(t0, t1, t2) {
      this._box_0 = t0;
      this.$this = t1;
      this.channel = t2;
    },
    RemoteListener__serializeTest_closure: function RemoteListener__serializeTest_closure(t0, t1, t2, t3) {
      var _ = this;
      _.$this = t0;
      _.test = t1;
      _.groups = t2;
      _.channel = t3;
    },
    RemoteListener__runLiveTest_closure: function RemoteListener__runLiveTest_closure(t0) {
      this.liveTest = t0;
    },
    RemoteListener__runLiveTest_closure0: function RemoteListener__runLiveTest_closure0(t0) {
      this.channel = t0;
    },
    RemoteListener__runLiveTest_closure1: function RemoteListener__runLiveTest_closure1(t0, t1) {
      this.channel = t0;
      this.liveTest = t1;
    },
    RemoteListener__runLiveTest_closure2: function RemoteListener__runLiveTest_closure2(t0, t1) {
      this.$this = t0;
      this.channel = t1;
    },
    RemoteListener__runLiveTest_closure3: function RemoteListener__runLiveTest_closure3(t0, t1) {
      this.liveTest = t0;
      this.channel = t1;
    },
    RemoteListener__runLiveTest__closure: function RemoteListener__runLiveTest__closure(t0) {
      this.channel = t0;
    }
  },
  O = {DelegatingSink: function DelegatingSink(t0, t1) {
      this._sink$_sink = t0;
      this.$ti = t1;
    }, None: function None() {
    }, Scanner: function Scanner(t0) {
      this._scanner = t0;
      this._scanner$_next = null;
      this._endOfFileEmitted = false;
    }, EmptyUnmodifiableSet: function EmptyUnmodifiableSet(t0) {
      this.$ti = t0;
    },
    Style__getPlatformStyle: function() {
      if (P.Uri_base().get$scheme() !== "file")
        return $.$get$Style_url();
      var t1 = P.Uri_base();
      if (!C.JSString_methods.endsWith$1(t1.get$path(t1), "/"))
        return $.$get$Style_url();
      if (P._Uri__Uri(null, "a/b", null, null).toFilePath$0() === "a\\b")
        return $.$get$Style_windows();
      return $.$get$Style_posix();
    },
    Style: function Style() {
    },
    Pool$: function(_maxAllocatedResources) {
      var t4,
        t1 = type$.Completer_PoolResource,
        t2 = P.ListQueue$(t1),
        t3 = P.ListQueue$(type$.void_Function);
      t1 = P.ListQueue$(t1);
      t4 = $.Zone__current;
      if (_maxAllocatedResources <= 0)
        H.throwExpression(P.ArgumentError$value(_maxAllocatedResources, "maxAllocatedResources", "Must be greater than zero."));
      return new O.Pool(t2, t3, t1, _maxAllocatedResources, new S.AsyncMemoizer(new P._AsyncCompleter(new P._Future(t4, type$._Future_dynamic), type$._AsyncCompleter_dynamic), type$.AsyncMemoizer_dynamic));
    },
    Pool: function Pool(t0, t1, t2, t3, t4) {
      var _ = this;
      _._requestedResources = t0;
      _._onReleaseCallbacks = t1;
      _._onReleaseCompleters = t2;
      _._maxAllocatedResources = t3;
      _._allocatedResources = 0;
      _._closeGroup = _._timer = null;
      _._pool$_closeMemo = t4;
    },
    Pool_close_closure: function Pool_close_closure(t0) {
      this.$this = t0;
    },
    Pool__onResourceReleaseAllowed_closure: function Pool__onResourceReleaseAllowed_closure(t0, t1) {
      this.zone = t0;
      this.registered = t1;
    },
    Pool__runOnRelease_closure: function Pool__runOnRelease_closure(t0) {
      this.$this = t0;
    },
    Pool__runOnRelease_closure0: function Pool__runOnRelease_closure0(t0) {
      this.$this = t0;
    },
    PoolResource: function PoolResource(t0) {
      this._pool = t0;
      this._released = false;
    },
    mapStackTrace: function(sourceMap, stackTrace, minified, packageResolver, sdkRoot) {
      var t2, t3, sdkLib, t4, t1 = {};
      t1.packageResolver = packageResolver;
      if (type$.Chain._is(stackTrace)) {
        t2 = stackTrace.get$traces();
        t3 = H._arrayInstanceType(t2);
        return new U.Chain(P.List_List$unmodifiable(new H.MappedListIterable(t2, t3._eval$1("Trace(1)")._check(new O.mapStackTrace_closure(t1, sourceMap, false, sdkRoot)), t3._eval$1("MappedListIterable<1,Trace>")), type$.Trace));
      }
      t2 = sdkRoot == null;
      !t2;
      sdkLib = t2 ? null : sdkRoot.toString$0(0) + "/lib";
      t2 = Y.Trace_Trace$from(stackTrace).get$frames();
      t3 = H._arrayInstanceType(t2);
      t4 = t3._eval$1("MappedListIterable<1,Frame>");
      return new Y.Trace(P.List_List$unmodifiable(new H.MappedListIterable(t2, t3._eval$1("Frame(1)")._check(new O.mapStackTrace_closure0(t1, sourceMap, sdkRoot, sdkLib, false)), t4).super$Iterable$where(0, t4._eval$1("bool(ListIterable.E)")._check(new O.mapStackTrace_closure1())), type$.Frame), new P._StringStackTrace(null));
    },
    _prettifyMember: function(member) {
      var t2, t3,
        t1 = P.RegExp_RegExp("/?<$", false);
      member.toString;
      t1 = H.stringReplaceAllUnchecked(member, t1, "");
      t2 = P.RegExp_RegExp("\\$\\d+(\\$[a-zA-Z_0-9]+)*$", false);
      t3 = type$.String_Function_Match;
      t2 = C.JSString_methods.splitMapJoin$2$onMatch(H.stringReplaceAllUnchecked(t1, t2, ""), P.RegExp_RegExp("(_+)closure\\d*\\.call$", false), t3._check(new O._prettifyMember_closure()));
      t1 = P.RegExp_RegExp("\\.call$", false);
      t1 = H.stringReplaceAllUnchecked(t2, t1, "");
      t2 = P.RegExp_RegExp("^dart\\.", false);
      t1 = H.stringReplaceAllUnchecked(t1, t2, "");
      t2 = P.RegExp_RegExp("[a-zA-Z_0-9]+\\$", false);
      t1 = H.stringReplaceAllUnchecked(t1, t2, "");
      t2 = P.RegExp_RegExp("^[a-zA-Z_0-9]+.(static|dart).", false);
      return C.JSString_methods.splitMapJoin$2$onMatch(H.stringReplaceAllUnchecked(t1, t2, ""), P.RegExp_RegExp("([a-zA-Z0-9]+)_", false), t3._check(new O._prettifyMember_closure0()));
    },
    mapStackTrace_closure: function mapStackTrace_closure(t0, t1, t2, t3) {
      var _ = this;
      _._box_0 = t0;
      _.sourceMap = t1;
      _.minified = t2;
      _.sdkRoot = t3;
    },
    mapStackTrace_closure0: function mapStackTrace_closure0(t0, t1, t2, t3, t4) {
      var _ = this;
      _._box_0 = t0;
      _.sourceMap = t1;
      _.sdkRoot = t2;
      _.sdkLib = t3;
      _.minified = t4;
    },
    mapStackTrace_closure1: function mapStackTrace_closure1() {
    },
    _prettifyMember_closure: function _prettifyMember_closure() {
    },
    _prettifyMember_closure0: function _prettifyMember_closure0() {
    },
    StackZoneSpecification: function StackZoneSpecification(t0, t1, t2) {
      var _ = this;
      _._chains = t0;
      _._stack_zone_specification$_onError = t1;
      _._currentNode = null;
      _._errorZone = t2;
    },
    StackZoneSpecification_chainFor_closure: function StackZoneSpecification_chainFor_closure(t0) {
      this._box_0 = t0;
    },
    StackZoneSpecification_chainFor_closure0: function StackZoneSpecification_chainFor_closure0(t0, t1) {
      this.$this = t0;
      this.original = t1;
    },
    StackZoneSpecification__registerCallback_closure: function StackZoneSpecification__registerCallback_closure(t0, t1, t2, t3) {
      var _ = this;
      _.$this = t0;
      _.f = t1;
      _.node = t2;
      _.R = t3;
    },
    StackZoneSpecification__registerUnaryCallback_closure: function StackZoneSpecification__registerUnaryCallback_closure(t0, t1, t2, t3, t4) {
      var _ = this;
      _.$this = t0;
      _.f = t1;
      _.node = t2;
      _.T = t3;
      _.R = t4;
    },
    StackZoneSpecification__registerUnaryCallback__closure: function StackZoneSpecification__registerUnaryCallback__closure(t0, t1, t2) {
      this.f = t0;
      this.arg = t1;
      this.R = t2;
    },
    StackZoneSpecification__registerBinaryCallback_closure: function StackZoneSpecification__registerBinaryCallback_closure(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _.$this = t0;
      _.f = t1;
      _.node = t2;
      _.T1 = t3;
      _.T2 = t4;
      _.R = t5;
    },
    StackZoneSpecification__registerBinaryCallback__closure: function StackZoneSpecification__registerBinaryCallback__closure(t0, t1, t2, t3) {
      var _ = this;
      _.f = t0;
      _.arg1 = t1;
      _.arg2 = t2;
      _.R = t3;
    },
    StackZoneSpecification__currentTrace_closure: function StackZoneSpecification__currentTrace_closure(t0, t1, t2) {
      this._box_0 = t0;
      this.$this = t1;
      this.stackTrace = t2;
    },
    _Node: function _Node(t0, t1) {
      this.trace = t0;
      this.previous = t1;
    },
    Group$: function($name, entries, metadata, setUpAll, tearDownAll, trace) {
      var t1 = P.List_List$unmodifiable(entries, type$.GroupEntry);
      return new O.Group($name, metadata, trace, t1, setUpAll, tearDownAll);
    },
    Group: function Group(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _.name = t0;
      _.metadata = t1;
      _.trace = t2;
      _.entries = t3;
      _.setUpAll = t4;
      _.tearDownAll = t5;
    },
    Group_forPlatform_closure: function Group_forPlatform_closure(t0) {
      this.platform = t0;
    },
    Group__map_closure: function Group__map_closure(t0) {
      this.callback = t0;
    },
    Group__map_closure0: function Group__map_closure0() {
    },
    Metadata__parseOnPlatform: function(onPlatform) {
      return P.LinkedHashMap_LinkedHashMap$_empty(type$.PlatformSelector, type$.Metadata);
    },
    Metadata__parseTags: function(tags) {
      return P.LinkedHashSet_LinkedHashSet$_empty(type$.String);
    },
    Metadata_Metadata: function(chainStackTraces, forTag, onPlatform, retry, skip, skipReason, tags, testOn, timeout, verboseTrace) {
      var t2, t3, empty, t4, merged, _null = null, t1 = {};
      t1.tags = tags;
      t1.forTag = forTag;
      t2 = new O.Metadata_Metadata__unresolved(t1, testOn, timeout, skip, verboseTrace, chainStackTraces, retry, skipReason, onPlatform);
      if (forTag == null || tags == null)
        return t2.call$0();
      t1.tags = P.LinkedHashSet_LinkedHashSet$from(tags, type$.String);
      t3 = type$.Metadata;
      t1.forTag = P.LinkedHashMap_LinkedHashMap$from(t1.forTag, type$.BooleanSelector, t3);
      empty = O.Metadata$_(_null, _null, _null, _null, _null, _null, _null, _null, _null, _null);
      t4 = t1.forTag.get$keys();
      merged = C.JSArray_methods.fold$1$2(P.List_List$from(t4, true, H._instanceType(t4)._eval$1("Iterable.E")), empty, new O.Metadata_Metadata_closure(t1), t3);
      if (merged === empty)
        return t2.call$0();
      return merged.merge$1(t2.call$0());
    },
    Metadata$_: function(chainStackTraces, forTag, onPlatform, retry, skip, skipReason, tags, testOn, timeout, verboseTrace) {
      var t1 = testOn == null ? C.PlatformSelector_All : testOn,
        t2 = timeout == null ? C.Timeout_null_1 : timeout,
        t3 = tags == null ? P.LinkedHashSet_LinkedHashSet$_empty(type$.String) : tags.toSet$0(0),
        t4 = onPlatform == null ? C.Map_empty : new P.UnmodifiableMapView(onPlatform, type$.UnmodifiableMapView_PlatformSelector_Metadata),
        t5 = forTag == null ? C.Map_empty0 : new P.UnmodifiableMapView(forTag, type$.UnmodifiableMapView_BooleanSelector_Metadata);
      t5 = new O.Metadata(t1, t2, skip, skipReason, verboseTrace, chainStackTraces, new L.UnmodifiableSetView(t3, type$.UnmodifiableSetView_String), retry, t4, t5);
      if (retry != null)
        P.RangeError_checkNotNegative(retry, "retry");
      t5._validateTags$0();
      return t5;
    },
    Metadata$parse: function(onPlatform, retry, skip, tags, testOn, timeout) {
      var _null = null,
        t1 = timeout == null ? C.Timeout_null_1 : timeout,
        t2 = skip == null,
        t3 = t2 ? _null : skip,
        t4 = O.Metadata__parseOnPlatform(onPlatform);
      t4 = new O.Metadata(C.PlatformSelector_All, t1, t3, _null, _null, _null, O.Metadata__parseTags(tags), retry, t4, C.Map_empty0);
      !t2;
      if (retry != null)
        P.RangeError_checkNotNegative(retry, "retry");
      t4._validateTags$0();
      return t4;
    },
    Metadata$deserialize: function(serialized) {
      var pair, t13,
        t1 = J.getInterceptor$asx(serialized),
        t2 = t1.$index(serialized, "testOn") == null ? C.PlatformSelector_All : E.PlatformSelector$parse(H._asStringNullable(t1.$index(serialized, "testOn"))),
        t3 = O.Metadata__deserializeTimeout(t1.$index(serialized, "timeout")),
        t4 = H._asBoolNullable(t1.$index(serialized, "skip")),
        t5 = H._asStringNullable(t1.$index(serialized, "skipReason")),
        t6 = H._asBoolNullable(t1.$index(serialized, "verboseTrace")),
        t7 = H._asBoolNullable(t1.$index(serialized, "chainStackTraces")),
        t8 = H._asIntNullable(t1.$index(serialized, "retry")),
        t9 = type$.Iterable_dynamic,
        t10 = P.LinkedHashSet_LinkedHashSet$from(t9._as(t1.$index(serialized, "tags")), type$.String),
        t11 = type$.Metadata,
        t12 = P.LinkedHashMap_LinkedHashMap$_empty(type$.PlatformSelector, t11);
      for (t9 = J.get$iterator$ax(t9._check(t1.$index(serialized, "onPlatform"))); t9.moveNext$0();) {
        pair = t9.get$current();
        t13 = J.getInterceptor$ax(pair);
        t12.$indexSet(0, E.PlatformSelector$parse(H._asStringNullable(t13.get$first(pair))), O.Metadata$deserialize(t13.get$last(pair)));
      }
      return new O.Metadata(t2, t3, t4, t5, t6, t7, t10, t8, t12, type$.Map_dynamic_dynamic._as(t1.$index(serialized, "forTag")).map$2$1(0, new O.Metadata$deserialize_closure(), type$.BooleanSelector, t11));
    },
    Metadata__deserializeTimeout: function(serialized) {
      var scaleFactor,
        t1 = J.getInterceptor$(serialized);
      if (t1.$eq(serialized, "none"))
        return C.Timeout_null_null;
      scaleFactor = t1.$index(serialized, "scaleFactor");
      if (scaleFactor != null)
        return new R.Timeout(null, H._asNumNullable(scaleFactor));
      return new R.Timeout(P.Duration$(H._asIntNullable(t1.$index(serialized, "duration")), 0), null);
    },
    Metadata: function Metadata(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {
      var _ = this;
      _.testOn = t0;
      _.timeout = t1;
      _._skip = t2;
      _.skipReason = t3;
      _._verboseTrace = t4;
      _._chainStackTraces = t5;
      _.tags = t6;
      _._retry = t7;
      _.onPlatform = t8;
      _.forTag = t9;
    },
    Metadata_Metadata__unresolved: function Metadata_Metadata__unresolved(t0, t1, t2, t3, t4, t5, t6, t7, t8) {
      var _ = this;
      _._box_0 = t0;
      _.testOn = t1;
      _.timeout = t2;
      _.skip = t3;
      _.verboseTrace = t4;
      _.chainStackTraces = t5;
      _.retry = t6;
      _.skipReason = t7;
      _.onPlatform = t8;
    },
    Metadata_Metadata_closure: function Metadata_Metadata_closure(t0) {
      this._box_0 = t0;
    },
    Metadata$deserialize_closure: function Metadata$deserialize_closure() {
    },
    Metadata__validateTags_closure: function Metadata__validateTags_closure() {
    },
    Metadata__validateTags_closure0: function Metadata__validateTags_closure0() {
    },
    Metadata_validatePlatformSelectors_closure: function Metadata_validatePlatformSelectors_closure(t0) {
      this.validVariables = t0;
    },
    Metadata_merge_closure: function Metadata_merge_closure() {
    },
    Metadata_merge_closure0: function Metadata_merge_closure0() {
    },
    Metadata_forPlatform_closure: function Metadata_forPlatform_closure(t0, t1) {
      this._box_0 = t0;
      this.platform = t1;
    },
    Metadata_serialize_closure: function Metadata_serialize_closure(t0) {
      this.serializedOnPlatform = t0;
    },
    Metadata_serialize_closure0: function Metadata_serialize_closure0() {
    },
    IterableSet: function IterableSet(t0, t1) {
      this._iterable_set$_base = t0;
      this.$ti = t1;
    },
    _IterableSet_SetMixin_UnmodifiableSetMixin: function _IterableSet_SetMixin_UnmodifiableSetMixin() {
    },
    Engine$: function() {
      var t6, t7, t8, t9, t10, t11, _null = null,
        t1 = $.Zone__current,
        t2 = H.setRuntimeTypeInfo([], type$.JSArray_dynamic),
        t3 = type$.RunnerSuite,
        t4 = P.StreamController_StreamController(_null, _null, false, t3),
        t5 = new L.StreamGroup(C._StreamGroupState_dormant, new H.JsLinkedHashMap(type$.JsLinkedHashMap_of_Stream_LiveTest_and_StreamSubscription_LiveTest), type$.StreamGroup_LiveTest);
      t5.set$_stream_group$_controller(new P._SyncBroadcastStreamController(t5.get$_onListen(), t5.get$_onCancelBroadcast(), type$._SyncBroadcastStreamController_LiveTest));
      t6 = type$.LiveTest;
      t7 = Y.UnionSetController$(true, t6);
      t8 = Y.UnionSetController$(true, t6);
      t9 = Y.UnionSetController$(true, t6);
      t10 = Q.QueueList$(t6);
      t11 = O.Pool$(1);
      t1 = new O.Engine(t11, O.Pool$(2), new F.FutureGroup(new P._AsyncCompleter(new P._Future(t1, type$._Future_List_dynamic), type$._AsyncCompleter_List_dynamic), t2, type$.FutureGroup_dynamic), P.LinkedHashSet_LinkedHashSet$_empty(type$.StreamSubscription_dynamic), t4, P.LinkedHashSet_LinkedHashSet$_empty(t3), new P._AsyncBroadcastStreamController(_null, _null, type$._AsyncBroadcastStreamController_RunnerSuite), P.LinkedHashSet_LinkedHashSet$_empty(type$.LiveSuite), new P._AsyncBroadcastStreamController(_null, _null, type$._AsyncBroadcastStreamController_LiveSuite), t5, t7, t8, t9, t10, P.LinkedHashSet_LinkedHashSet$_empty(t6), P.LinkedHashSet_LinkedHashSet$_empty(t6));
      t1.Engine$3$concurrency$coverage$maxSuites(_null, _null, _null);
      return t1;
    },
    Engine: function Engine(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) {
      var _ = this;
      _._engine$_closed = _._engine$_runCalled = false;
      _._closedBeforeDone = null;
      _._runPool = t0;
      _._loadPool = t1;
      _._group = t2;
      _._engine$_subscriptions = t3;
      _._suiteController = t4;
      _._addedSuites = t5;
      _._onSuiteAddedController = t6;
      _._liveSuites = t7;
      _._onSuiteStartedController = t8;
      _._onTestStartedGroup = t9;
      _._passedGroup = t10;
      _._skippedGroup = t11;
      _._failedGroup = t12;
      _._active = t13;
      _._restarted = t14;
      _._activeLoadTests = t15;
    },
    Engine_success_closure: function Engine_success_closure() {
    },
    Engine_closure: function Engine_closure(t0) {
      this.$this = t0;
    },
    Engine_closure0: function Engine_closure0() {
    },
    Engine_run_closure: function Engine_run_closure(t0) {
      this.$this = t0;
    },
    Engine_run__closure: function Engine_run__closure(t0, t1) {
      this.$this = t0;
      this.suite = t1;
    },
    Engine_run___closure: function Engine_run___closure(t0, t1, t2) {
      this._box_0 = t0;
      this.$this = t1;
      this.loadResource = t2;
    },
    Engine_run____closure: function Engine_run____closure(t0) {
      this._box_0 = t0;
    },
    Engine_run_closure0: function Engine_run_closure0(t0, t1) {
      this._box_1 = t0;
      this.$this = t1;
    },
    Engine__runLiveTest_closure: function Engine__runLiveTest_closure(t0, t1) {
      this.$this = t0;
      this.liveTest = t1;
    },
    Engine__runLiveTest_closure0: function Engine__runLiveTest_closure0(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Engine__runLiveTest_closure1: function Engine__runLiveTest_closure1() {
    },
    Engine__runSkippedTest_closure: function Engine__runSkippedTest_closure() {
    },
    Engine__runSkippedTest_closure0: function Engine__runSkippedTest_closure0(t0, t1) {
      this._box_0 = t0;
      this.skipped = t1;
    },
    Engine__runSkippedTest_closure1: function Engine__runSkippedTest_closure1() {
    },
    binarySearch: function(list, matches) {
      var max, min, half;
      if (list.length === 0)
        return -1;
      if (H.boolConversionCheck(matches.call$1(C.JSArray_methods.get$first(list))))
        return 0;
      if (!H.boolConversionCheck(matches.call$1(C.JSArray_methods.get$last(list))))
        return list.length;
      max = list.length - 1;
      for (min = 0; min < max;) {
        half = min + C.JSInt_methods._tdivFast$1(max - min, 2);
        if (half < 0 || half >= list.length)
          return H.ioore(list, half);
        if (H.boolConversionCheck(matches.call$1(list[half])))
          max = half;
        else
          min = half + 1;
      }
      return max;
    }
  },
  Y = {DelegatingStreamSubscription: function DelegatingStreamSubscription() {
    }, StreamCompleter: function StreamCompleter(t0, t1) {
      this._stream = t0;
      this.$ti = t1;
    }, _CompleterStream: function _CompleterStream(t0) {
      this._sourceStream = this._stream_completer$_controller = null;
      this.$ti = t0;
    }, BooleanSelectorImpl: function BooleanSelectorImpl(t0) {
      this._selector = t0;
    },
    mapMap: function(map, value, K1, V1, K2, V2) {
      var key, result, t1 = {};
      t1.key = key;
      t1.value = value;
      t1.key = null;
      t1.key = new Y.mapMap_closure(K2, K1, V1);
      result = P.LinkedHashMap_LinkedHashMap$_empty(K2, V2);
      map.forEach$1(0, new Y.mapMap_closure0(t1, result, K1, V1));
      return result;
    },
    mergeMaps: function(map1, map2, value, $K, $V) {
      var result = P.LinkedHashMap_LinkedHashMap$from(map1, $K, $V);
      map2.forEach$1(0, new Y.mergeMaps_closure(result, value, $K, $V));
      return result;
    },
    mapMap_closure: function mapMap_closure(t0, t1, t2) {
      this.K2 = t0;
      this.K1 = t1;
      this.V1 = t2;
    },
    mapMap_closure0: function mapMap_closure0(t0, t1, t2, t3) {
      var _ = this;
      _._box_0 = t0;
      _.result = t1;
      _.K1 = t2;
      _.V1 = t3;
    },
    mergeMaps_closure: function mergeMaps_closure(t0, t1, t2, t3) {
      var _ = this;
      _.result = t0;
      _.value = t1;
      _.K = t2;
      _.V = t3;
    },
    UnionSetController$: function(disjoint, $E) {
      var t1 = P.LinkedHashSet_LinkedHashSet($E._eval$1("Set<0>")),
        t2 = new Y.UnionSetController(t1, $E._eval$1("UnionSetController<0>"));
      t2.set$_union_set_controller$_set(new M.UnionSet(t1, true, $E._eval$1("UnionSet<0>")));
      return t2;
    },
    UnionSetController: function UnionSetController(t0, t1) {
      this._union_set_controller$_set = null;
      this._union_set_controller$_sets = t0;
      this.$ti = t1;
    },
    _IsTrue: function _IsTrue() {
    },
    _Predicate: function _Predicate(t0, t1, t2) {
      this._matcher = t0;
      this._core_matchers$_description = t1;
      this.$ti = t2;
    },
    FileLocation$_: function(file, offset) {
      if (offset < 0)
        H.throwExpression(P.RangeError$("Offset may not be negative, was " + offset + "."));
      else if (offset > file._decodedChars.length)
        H.throwExpression(P.RangeError$("Offset " + offset + " must not be greater than the number of characters in the file, " + file.get$length(file) + "."));
      return new Y.FileLocation(file, offset);
    },
    _FileSpan$: function(file, _start, _end) {
      if (_end < _start)
        H.throwExpression(P.ArgumentError$("End " + _end + " must come after start " + _start + "."));
      else if (_end > file._decodedChars.length)
        H.throwExpression(P.RangeError$("End " + _end + " must not be greater than the number of characters in the file, " + file.get$length(file) + "."));
      else if (_start < 0)
        H.throwExpression(P.RangeError$("Start may not be negative, was " + _start + "."));
      return new Y._FileSpan(file, _start, _end);
    },
    SourceFile: function SourceFile(t0, t1, t2) {
      var _ = this;
      _.url = t0;
      _._lineStarts = t1;
      _._decodedChars = t2;
      _._cachedLine = null;
    },
    FileLocation: function FileLocation(t0, t1) {
      this.file = t0;
      this.offset = t1;
    },
    _FileSpan: function _FileSpan(t0, t1, t2) {
      this.file = t0;
      this._file$_start = t1;
      this._file$_end = t2;
    },
    SourceSpanMixin: function SourceSpanMixin() {
    },
    Trace_Trace$current: function(level) {
      return new T.LazyTrace(new Y.Trace_Trace$current_closure(Y.Trace_Trace$from(P.StackTrace_current()), level));
    },
    Trace_Trace$from: function(trace) {
      if (trace == null)
        throw H.wrapException(P.ArgumentError$("Cannot create a Trace from null."));
      if (type$.Trace._is(trace))
        return trace;
      if (type$.Chain._is(trace))
        return trace.toTrace$0();
      return new T.LazyTrace(new Y.Trace_Trace$from_closure(trace));
    },
    Trace_Trace$parse: function(trace) {
      var error, t1, exception;
      try {
        if (trace.length === 0) {
          t1 = P.List_List$unmodifiable(H.setRuntimeTypeInfo([], type$.JSArray_Frame), type$.Frame);
          return new Y.Trace(t1, new P._StringStackTrace(null));
        }
        if (C.JSString_methods.contains$1(trace, $.$get$_v8Trace())) {
          t1 = Y.Trace$parseV8(trace);
          return t1;
        }
        if (C.JSString_methods.contains$1(trace, "\tat ")) {
          t1 = Y.Trace$parseJSCore(trace);
          return t1;
        }
        if (C.JSString_methods.contains$1(trace, $.$get$_firefoxSafariTrace())) {
          t1 = Y.Trace$parseFirefox(trace);
          return t1;
        }
        if (C.JSString_methods.contains$1(trace, "===== asynchronous gap ===========================\n")) {
          t1 = U.Chain_Chain$parse(trace).toTrace$0();
          return t1;
        }
        if (C.JSString_methods.contains$1(trace, $.$get$_friendlyTrace())) {
          t1 = Y.Trace$parseFriendly(trace);
          return t1;
        }
        t1 = P.List_List$unmodifiable(Y.Trace__parseVM(trace), type$.Frame);
        return new Y.Trace(t1, new P._StringStackTrace(trace));
      } catch (exception) {
        t1 = H.unwrapException(exception);
        if (type$.FormatException._is(t1)) {
          error = t1;
          throw H.wrapException(P.FormatException$(H.S(J.get$message$x(error)) + "\nStack trace:\n" + H.S(trace), null, null));
        } else
          throw exception;
      }
    },
    Trace__parseVM: function(trace) {
      var t2, $frames,
        t1 = J.trim$0$s(trace),
        lines = H.setRuntimeTypeInfo(H.stringReplaceAllUnchecked(t1, "<asynchronous suspension>\n", "").split("\n"), type$.JSArray_String);
      t1 = H.SubListIterable$(lines, 0, lines.length - 1, type$.String);
      t2 = t1.$ti;
      $frames = new H.MappedListIterable(t1, t2._eval$1("Frame(ListIterable.E)")._check(new Y.Trace__parseVM_closure()), t2._eval$1("MappedListIterable<ListIterable.E,Frame>")).toList$0(0);
      if (!J.endsWith$1$s(C.JSArray_methods.get$last(lines), ".da"))
        C.JSArray_methods.add$1($frames, A.Frame_Frame$parseVM(C.JSArray_methods.get$last(lines)));
      return $frames;
    },
    Trace$parseV8: function(trace) {
      var t2, t3,
        t1 = H.SubListIterable$(H.setRuntimeTypeInfo(trace.split("\n"), type$.JSArray_String), 1, null, type$.String);
      t1 = t1.super$Iterable$skipWhile(0, t1.$ti._eval$1("bool(ListIterable.E)")._check(new Y.Trace$parseV8_closure()));
      t2 = type$.Frame;
      t3 = t1.$ti;
      return new Y.Trace(P.List_List$unmodifiable(H.MappedIterable_MappedIterable(t1, t3._eval$1("Frame(Iterable.E)")._check(new Y.Trace$parseV8_closure0()), t3._eval$1("Iterable.E"), t2), t2), new P._StringStackTrace(trace));
    },
    Trace$parseJSCore: function(trace) {
      return new Y.Trace(P.List_List$unmodifiable(new H.MappedIterable(new H.WhereIterable(H.setRuntimeTypeInfo(trace.split("\n"), type$.JSArray_String), type$.bool_Function_String._check(new Y.Trace$parseJSCore_closure()), type$.WhereIterable_String), type$.Frame_Function_String._check(new Y.Trace$parseJSCore_closure0()), type$.MappedIterable_String_Frame), type$.Frame), new P._StringStackTrace(trace));
    },
    Trace$parseFirefox: function(trace) {
      return new Y.Trace(P.List_List$unmodifiable(new H.MappedIterable(new H.WhereIterable(H.setRuntimeTypeInfo(C.JSString_methods.trim$0(trace).split("\n"), type$.JSArray_String), type$.bool_Function_String._check(new Y.Trace$parseFirefox_closure()), type$.WhereIterable_String), type$.Frame_Function_String._check(new Y.Trace$parseFirefox_closure0()), type$.MappedIterable_String_Frame), type$.Frame), new P._StringStackTrace(trace));
    },
    Trace$parseFriendly: function(trace) {
      var t1 = trace.length === 0 ? H.setRuntimeTypeInfo([], type$.JSArray_Frame) : new H.MappedIterable(new H.WhereIterable(H.setRuntimeTypeInfo(C.JSString_methods.trim$0(trace).split("\n"), type$.JSArray_String), type$.bool_Function_String._check(new Y.Trace$parseFriendly_closure()), type$.WhereIterable_String), type$.Frame_Function_String._check(new Y.Trace$parseFriendly_closure0()), type$.MappedIterable_String_Frame);
      return new Y.Trace(P.List_List$unmodifiable(t1, type$.Frame), new P._StringStackTrace(trace));
    },
    Trace: function Trace(t0, t1) {
      this.frames = t0;
      this.original = t1;
    },
    Trace_Trace$current_closure: function Trace_Trace$current_closure(t0, t1) {
      this.trace = t0;
      this.level = t1;
    },
    Trace_Trace$from_closure: function Trace_Trace$from_closure(t0) {
      this.trace = t0;
    },
    Trace__parseVM_closure: function Trace__parseVM_closure() {
    },
    Trace$parseV8_closure: function Trace$parseV8_closure() {
    },
    Trace$parseV8_closure0: function Trace$parseV8_closure0() {
    },
    Trace$parseJSCore_closure: function Trace$parseJSCore_closure() {
    },
    Trace$parseJSCore_closure0: function Trace$parseJSCore_closure0() {
    },
    Trace$parseFirefox_closure: function Trace$parseFirefox_closure() {
    },
    Trace$parseFirefox_closure0: function Trace$parseFirefox_closure0() {
    },
    Trace$parseFriendly_closure: function Trace$parseFriendly_closure() {
    },
    Trace$parseFriendly_closure0: function Trace$parseFriendly_closure0() {
    },
    Trace_foldFrames_closure: function Trace_foldFrames_closure(t0) {
      this.oldPredicate = t0;
    },
    Trace_foldFrames_closure0: function Trace_foldFrames_closure0(t0) {
      this._box_0 = t0;
    },
    Trace_toString_closure0: function Trace_toString_closure0() {
    },
    Trace_toString_closure: function Trace_toString_closure(t0) {
      this.longest = t0;
    },
    RunnerSuite: function RunnerSuite(t0, t1, t2, t3) {
      var _ = this;
      _._runner_suite$_controller = t0;
      _.platform = t1;
      _.path = t2;
      _.group = t3;
    },
    RunnerSuiteController: function RunnerSuiteController(t0, t1, t2, t3, t4) {
      var _ = this;
      _._config = t0;
      _._runner_suite$_onClose = t1;
      _._onDebuggingController = t2;
      _._channelNames = t3;
      _._closeMemo = t4;
    },
    RunnerSuiteController__close_closure: function RunnerSuiteController__close_closure(t0) {
      this.$this = t0;
    }
  },
  F = {FutureGroup: function FutureGroup(t0, t1, t2) {
      var _ = this;
      _._future_group$_pending = 0;
      _._future_group$_closed = false;
      _._future_group$_completer = t0;
      _._values = t1;
      _.$ti = t2;
    }, FutureGroup_add_closure: function FutureGroup_add_closure(t0, t1) {
      this.$this = t0;
      this.index = t1;
    }, FutureGroup_add_closure0: function FutureGroup_add_closure0(t0) {
      this.$this = t0;
    }, ValueResult: function ValueResult(t0, t1) {
      this.value = t0;
      this.$ti = t1;
    },
    PackageConfigResolver__normalizeMap: function(map) {
      var t1 = type$.String,
        t2 = type$.Uri;
      return new P.UnmodifiableMapView(Y.mapMap(map, new F.PackageConfigResolver__normalizeMap_closure(), t1, t2, t1, t2), type$.UnmodifiableMapView_String_Uri);
    },
    PackageConfigResolver: function PackageConfigResolver(t0) {
      this.packageConfigMap = t0;
    },
    PackageConfigResolver__normalizeMap_closure: function PackageConfigResolver__normalizeMap_closure() {
    },
    UrlStyle: function UrlStyle(t0, t1, t2, t3) {
      var _ = this;
      _.separatorPattern = t0;
      _.needsSeparatorPattern = t1;
      _.rootPattern = t2;
      _.relativeRootPattern = t3;
    }
  },
  V = {ErrorResult: function ErrorResult(t0, t1) {
      this.error = t0;
      this.stackTrace = t1;
    },
    SourceLocation$: function(offset, column, line, sourceUrl) {
      var t2, t3, t4, t5,
        t1 = typeof sourceUrl == "string" ? P.Uri_parse(sourceUrl) : sourceUrl;
      type$.Uri._check(t1);
      t2 = line == null;
      t3 = t2 ? 0 : line;
      t4 = column == null;
      t5 = t4 ? offset : column;
      if (offset < 0)
        H.throwExpression(P.RangeError$("Offset may not be negative, was " + offset + "."));
      else if (!t2 && line < 0)
        H.throwExpression(P.RangeError$("Line may not be negative, was " + H.S(line) + "."));
      else if (!t4 && column < 0)
        H.throwExpression(P.RangeError$("Column may not be negative, was " + H.S(column) + "."));
      return new V.SourceLocation(t1, offset, t3, t5);
    },
    SourceLocation: function SourceLocation(t0, t1, t2, t3) {
      var _ = this;
      _.sourceUrl = t0;
      _.offset = t1;
      _.line = t2;
      _.column = t3;
    },
    SourceSpan: function SourceSpan() {
    },
    SourceSpanBase: function SourceSpanBase() {
    },
    GroupEntry: function GroupEntry() {
    },
    LiveTestController$: function(suite, _test, onRun, onClose, groups) {
      var _null = null,
        t1 = H.setRuntimeTypeInfo([], type$.JSArray_AsyncError),
        t2 = $.Zone__current,
        t3 = P.List_List$unmodifiable(groups, type$.Group);
      t1 = new V.LiveTestController(suite, t3, _test, onRun, onClose, t1, C.State_Status_pending_Result_success, new P._SyncBroadcastStreamController(_null, _null, type$._SyncBroadcastStreamController_State), new P._SyncBroadcastStreamController(_null, _null, type$._SyncBroadcastStreamController_AsyncError), new P._SyncBroadcastStreamController(_null, _null, type$._SyncBroadcastStreamController_Message), new P._AsyncCompleter(new P._Future(t2, type$._Future_void), type$._AsyncCompleter_void));
      t1._liveTest = new V._LiveTest(t1);
      return t1;
    },
    _LiveTest: function _LiveTest(t0) {
      this._live_test_controller$_controller = t0;
    },
    LiveTestController: function LiveTestController(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) {
      var _ = this;
      _._liveTest = null;
      _._live_test_controller$_suite = t0;
      _._groups = t1;
      _._test = t2;
      _._onRun = t3;
      _._onClose = t4;
      _._errors = t5;
      _._live_test_controller$_state = t6;
      _._onStateChangeController = t7;
      _._onErrorController = t8;
      _._onMessageController = t9;
      _.completer = t10;
      _._runCalled = false;
    },
    Test: function Test() {
    },
    errorsDontStopTest: function(body) {
      var t1 = $.Zone__current,
        t2 = new P._Future(t1, type$._Future_dynamic),
        t3 = type$.Invoker;
      t3._as(t1.$index(0, C.Symbol_cQL)).addOutstandingCallback$0();
      t3._as($.Zone__current.$index(0, C.Symbol_cQL)).waitForOutstandingCallbacks$1(new V.errorsDontStopTest_closure(body, new P._AsyncCompleter(t2, type$._AsyncCompleter_dynamic))).then$1$1(new V.errorsDontStopTest_closure0(), type$.void);
      return t2;
    },
    errorsDontStopTest_closure: function errorsDontStopTest_closure(t0, t1) {
      this.body = t0;
      this.completer = t1;
    },
    errorsDontStopTest_closure0: function errorsDontStopTest_closure0() {
    }
  },
  E = {Result: function Result() {
    }, StringDescription: function StringDescription(t0) {
      this._out = t0;
    }, FeatureMatcher: function FeatureMatcher() {
    }, PosixStyle: function PosixStyle(t0, t1, t2) {
      this.separatorPattern = t0;
      this.needsSeparatorPattern = t1;
      this.rootPattern = t2;
    },
    StringScannerException$: function(message, span, source) {
      return new E.StringScannerException(message, span);
    },
    StringScannerException: function StringScannerException(t0, t1) {
      this._span_exception$_message = t0;
      this._span_exception$_span = t1;
    },
    PlatformSelector$parse: function(selector) {
      return new E.PlatformSelector(E.PlatformSelector__wrapFormatException(new E.PlatformSelector$parse_closure(selector), null, type$.BooleanSelector));
    },
    PlatformSelector__wrapFormatException: function(body, span, $T) {
      var t1 = body.call$0();
      return t1;
    },
    PlatformSelector: function PlatformSelector(t0) {
      this._platform_selector$_inner = t0;
    },
    PlatformSelector$parse_closure: function PlatformSelector$parse_closure(t0) {
      this.selector = t0;
    },
    PlatformSelector_validate_closure: function PlatformSelector_validate_closure(t0, t1) {
      this.$this = t0;
      this.validVariables = t1;
    },
    PlatformSelector_validate__closure: function PlatformSelector_validate__closure(t0) {
      this.validVariables = t0;
    },
    PlatformSelector_evaluate_closure: function PlatformSelector_evaluate_closure(t0) {
      this.platform = t0;
    },
    SuitePlatform$: function(runtime, inGoogle, os) {
      var t1 = os == null ? C.OperatingSystem_none_none : os;
      if (H.boolConversionCheck(runtime.isBrowser) && t1 !== C.OperatingSystem_none_none)
        H.throwExpression(P.ArgumentError$('No OS should be passed for runtime "' + runtime.toString$0(0) + '".'));
      return new E.SuitePlatform(runtime, t1, inGoogle);
    },
    SuitePlatform: function SuitePlatform(t0, t1, t2) {
      this.runtime = t0;
      this.os = t1;
      this.inGoogle = t2;
    },
    StackTraceMapper: function StackTraceMapper() {
    },
    LiveSuite: function LiveSuite() {
    },
    JSStackTraceMapper_deserialize: function(serialized) {
      var t1, t2, t3,
        _s11_ = "packageRoot",
        packageRoot = H._asStringNullable(serialized.$index(0, _s11_));
      if (packageRoot == null)
        packageRoot = "";
      t1 = H._asStringNullable(serialized.$index(0, "mapContents"));
      t2 = P.Uri_parse(H._asStringNullable(serialized.$index(0, "sdkRoot")));
      if (packageRoot.length !== 0)
        t3 = new D.PackageRootResolver(B.ensureTrailingSlash(B.asUri(P.Uri_parse(H._asStringNullable(serialized.$index(0, _s11_))), _s11_)));
      else {
        t3 = type$.String;
        t3 = F.PackageConfigResolver__normalizeMap(E.JSStackTraceMapper__deserializePackageConfigMap(type$.Map_dynamic_dynamic._as(serialized.$index(0, "packageConfigMap")).cast$2$0(0, t3, t3)));
        t3 = new F.PackageConfigResolver(t3);
      }
      return new E.JSStackTraceMapper(t3, t2, t1, P.Uri_parse(H._asStringNullable(serialized.$index(0, "mapUrl"))));
    },
    JSStackTraceMapper__deserializePackageConfigMap: function(serialized) {
      return serialized.map$2$1(0, new E.JSStackTraceMapper__deserializePackageConfigMap_closure(), type$.String, type$.Uri);
    },
    JSStackTraceMapper: function JSStackTraceMapper(t0, t1, t2, t3) {
      var _ = this;
      _._mapping = null;
      _._packageResolver = t0;
      _._sdkRoot = t1;
      _._mapContents = t2;
      _._mapUrl = t3;
    },
    JSStackTraceMapper__deserializePackageConfigMap_closure: function JSStackTraceMapper__deserializePackageConfigMap_closure() {
    }
  },
  L = {StreamGroup: function StreamGroup(t0, t1, t2) {
      var _ = this;
      _._stream_group$_controller = null;
      _._stream_group$_closed = false;
      _._stream_group$_state = t0;
      _._stream_group$_subscriptions = t1;
      _.$ti = t2;
    }, StreamGroup_add_closure: function StreamGroup_add_closure() {
    }, StreamGroup_add_closure0: function StreamGroup_add_closure0(t0, t1) {
      this.$this = t0;
      this.stream = t1;
    }, StreamGroup__onListen_closure: function StreamGroup__onListen_closure(t0) {
      this.$this = t0;
    }, StreamGroup__onCancelBroadcast_closure: function StreamGroup__onCancelBroadcast_closure(t0) {
      this.$this = t0;
    }, StreamGroup__listenToStream_closure: function StreamGroup__listenToStream_closure(t0, t1) {
      this.$this = t0;
      this.stream = t1;
    }, _StreamGroupState: function _StreamGroupState(t0) {
      this.name = t0;
    }, Token: function Token(t0, t1) {
      this.type = t0;
      this.span = t1;
    }, IdentifierToken: function IdentifierToken(t0, t1) {
      this.span = t0;
      this.name = t1;
    }, TokenType: function TokenType(t0) {
      this.name = t0;
    },
    UnmodifiableSetView$: function(setBase, $E) {
      return new L.UnmodifiableSetView(setBase, $E._eval$1("UnmodifiableSetView<0>"));
    },
    UnmodifiableSetView: function UnmodifiableSetView(t0, t1) {
      this._base = t0;
      this.$ti = t1;
    },
    UnmodifiableSetMixin: function UnmodifiableSetMixin() {
    },
    _UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin: function _UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin() {
    },
    WindowsStyle: function WindowsStyle(t0, t1, t2, t3) {
      var _ = this;
      _.separatorPattern = t0;
      _.needsSeparatorPattern = t1;
      _.rootPattern = t2;
      _.relativeRootPattern = t3;
    },
    WindowsStyle_absolutePathToUri_closure: function WindowsStyle_absolutePathToUri_closure() {
    },
    decodeVlq: function(chars) {
      var t1, t2, result, $stop, shift, t3, char, digit, result0, _null = null;
      for (t1 = chars._parser$_length, t2 = chars._internal, result = 0, $stop = false, shift = 0; !$stop;) {
        t3 = ++chars.index;
        if (t3 >= t1)
          throw H.wrapException(P.StateError$("incomplete VLQ value"));
        if (t3 >= 0 && true) {
          if (t3 < 0 || t3 >= t2.length)
            return H.ioore(t2, t3);
          char = t2[t3];
        } else
          char = _null;
        t3 = $.$get$_digits();
        if (!t3.containsKey$1(char))
          throw H.wrapException(P.FormatException$("invalid character in VLQ encoding: " + H.S(char), _null, _null));
        digit = t3.$index(0, char);
        if (typeof digit !== "number")
          return digit.$and();
        $stop = (digit & 32) === 0;
        result += C.JSInt_methods._shlPositive$1(digit & 31, shift);
        shift += 5;
      }
      result0 = result >>> 1;
      result = (result & 1) === 1 ? -result0 : result0;
      if (result < $.$get$MIN_INT32() || result > $.$get$MAX_INT32())
        throw H.wrapException(P.FormatException$("expected an encoded 32 bit int, but we got: " + result, _null, _null));
      return result;
    },
    closure: function closure() {
    },
    internalBootstrapBrowserTest: function(getMain) {
      var t2,
        channel = S.RemoteListener_start(getMain, new L.internalBootstrapBrowserTest_closure(), false),
        t1 = N.postMessageChannel();
      t1.$ti._eval$1("StreamChannel<1>")._check(channel);
      t1.get$stream(t1).pipe$1(channel._sink);
      t2 = channel._streamController;
      t2.toString;
      new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).pipe$1(t1.get$sink());
    },
    internalBootstrapBrowserTest_closure: function internalBootstrapBrowserTest_closure() {
    }
  },
  G = {StreamQueue: function StreamQueue(t0, t1, t2, t3) {
      var _ = this;
      _._stream_queue$_source = t0;
      _._stream_queue$_subscription = null;
      _._isClosed = _._isDone = false;
      _._eventsReceived = 0;
      _._eventQueue = t1;
      _._requestQueue = t2;
      _.$ti = t3;
    }, StreamQueue__ensureListening_closure: function StreamQueue__ensureListening_closure(t0) {
      this.$this = t0;
    }, StreamQueue__ensureListening_closure1: function StreamQueue__ensureListening_closure1(t0) {
      this.$this = t0;
    }, StreamQueue__ensureListening_closure0: function StreamQueue__ensureListening_closure0(t0) {
      this.$this = t0;
    }, _EventRequest: function _EventRequest() {
    }, _NextRequest: function _NextRequest(t0, t1) {
      this._completer = t0;
      this.$ti = t1;
    }, _RestRequest: function _RestRequest(t0, t1, t2) {
      this._completer = t0;
      this._streamQueue = t1;
      this.$ti = t2;
    }, Parser: function Parser(t0) {
      this._parser0$_scanner = t0;
    }, Matcher: function Matcher() {
    }, SourceMapSpan: function SourceMapSpan(t0, t1, t2, t3) {
      var _ = this;
      _.isIdentifier = t0;
      _.start = t1;
      _.end = t2;
      _.text = t3;
    },
    SourceSpanFormatException$: function(message, span, _source) {
      return new G.SourceSpanFormatException(message, span);
    },
    SourceSpanException: function SourceSpanException() {
    },
    SourceSpanFormatException: function SourceSpanFormatException(t0, t1) {
      this._span_exception$_message = t0;
      this._span_exception$_span = t1;
    },
    State: function State(t0, t1) {
      this.status = t0;
      this.result = t1;
    },
    Status: function Status(t0) {
      this.name = t0;
    },
    Result0: function Result0(t0) {
      this.name = t0;
    },
    expect: function(actual, matcher, reason) {
      G._expect(true, matcher, null, reason, null, false);
    },
    _expect: function(actual, matcher, formatter, reason, skip, verbose) {
      var matchState, e, trace, exception,
        t1 = type$.Invoker;
      if (t1._as($.Zone__current.$index(0, C.Symbol_cQL)) == null)
        throw H.wrapException(P.StateError$("expect() may only be called within a test."));
      t1 = t1._as($.Zone__current.$index(0, C.Symbol_cQL));
      if (H.boolConversionCheck(H._asBoolNullable($.Zone__current.$index(0, t1._closableKey))) && t1._onCloseCompleter.future._state !== 0)
        throw H.wrapException(K.ClosedException$());
      matcher = M.wrapMatcher(matcher);
      t1 = type$.dynamic;
      matchState = P.LinkedHashMap_LinkedHashMap$_empty(t1, t1);
      try {
        if (matcher.matches$2(0, true, matchState)) {
          t1 = P.Future_Future$sync(new G._expect_closure(), t1);
          return t1;
        }
        t1 = reason;
      } catch (exception) {
        e = H.unwrapException(exception);
        trace = H.getTraceFromException(exception);
        t1 = reason == null ? H.S(e) + " at " + H.S(trace) : reason;
      }
      G.fail(new G._expect_closure0().call$5(true, matcher, t1, matchState, false));
    },
    fail: function(message) {
      return H.throwExpression(new G.TestFailure(message));
    },
    formatFailure: function(expected, actual, which, reason) {
      var t2,
        t1 = new E.StringDescription(new P.StringBuffer("")).addDescriptionOf$1(expected)._out._contents;
      t1 = B.indent(t1.charCodeAt(0) == 0 ? t1 : t1, "Expected: ") + "\n";
      t2 = new E.StringDescription(new P.StringBuffer("")).addDescriptionOf$1(true)._out._contents;
      t2 = t1 + (B.indent(t2.charCodeAt(0) == 0 ? t2 : t2, "  Actual: ") + "\n");
      t1 = which.length !== 0 ? t2 + (B.indent(which, "   Which: ") + "\n") : t2;
      if (reason != null)
        t1 += reason + "\n";
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    TestFailure: function TestFailure(t0) {
      this.message = t0;
    },
    _expect_closure0: function _expect_closure0() {
    },
    _expect_closure: function _expect_closure() {
    },
    method1: function() {
      return $.x = $.x + 1;
    },
    method2: function() {
      return $.x = $.x + 1;
    },
    main0: function() {
      R.group("a group", new G.main_closure0());
    },
    main_closure0: function main_closure0() {
    },
    main__closure: function main__closure() {
    }
  },
  T = {StreamSinkCompleter: function StreamSinkCompleter(t0, t1) {
      this.sink = t0;
      this.$ti = t1;
    }, _CompleterSink: function _CompleterSink(t0) {
      var _ = this;
      _._destinationSink = _._stream_sink_completer$_doneCompleter = _._stream_sink_completer$_controller = null;
      _.$ti = t0;
    }, _CompleterSink__setDestinationSink_closure: function _CompleterSink__setDestinationSink_closure() {
    }, SubscriptionStream: function SubscriptionStream(t0, t1) {
      this._subscription_stream$_source = t0;
      this.$ti = t1;
    }, _CancelOnErrorSubscriptionWrapper: function _CancelOnErrorSubscriptionWrapper(t0, t1) {
      this._stream_subscription$_source = t0;
      this.$ti = t1;
    }, _CancelOnErrorSubscriptionWrapper_onError_closure: function _CancelOnErrorSubscriptionWrapper_onError_closure(t0, t1) {
      this.$this = t0;
      this.handleError = t1;
    }, _CancelOnErrorSubscriptionWrapper_onError__closure: function _CancelOnErrorSubscriptionWrapper_onError__closure(t0, t1, t2) {
      this.handleError = t0;
      this.error = t1;
      this.stackTrace = t2;
    }, Evaluator: function Evaluator(t0) {
      this._semantics = t0;
    },
    parseJsonExtended: function(json, mapUrl, otherMaps) {
      if (type$.List_dynamic._is(json))
        return T.MappingBundle$fromJson(json, H._checkStringNullable(mapUrl));
      return T.parseJson(type$.Map_dynamic_dynamic._as(json), null, null);
    },
    parseJson: function(map, mapUrl, otherMaps) {
      var _s8_ = "sections";
      if (!J.$eq$(map.$index(0, "version"), 3))
        throw H.wrapException(P.ArgumentError$("unexpected source map version: " + H.S(map.$index(0, "version")) + ". Only version 3 is supported."));
      if (map.containsKey$1(_s8_)) {
        if (map.containsKey$1("mappings") || map.containsKey$1("sources") || map.containsKey$1("names"))
          throw H.wrapException(P.FormatException$('map containing "sections" cannot contain "mappings", "sources", or "names".', null, null));
        return T.MultiSectionMapping$fromJson(type$.List_dynamic._check(map.$index(0, _s8_)), otherMaps, mapUrl);
      }
      return T.SingleMapping$fromJson(map, mapUrl);
    },
    MultiSectionMapping$fromJson: function(sections, otherMaps, mapUrl) {
      var t1 = type$.JSArray_int;
      t1 = new T.MultiSectionMapping(H.setRuntimeTypeInfo([], t1), H.setRuntimeTypeInfo([], t1), H.setRuntimeTypeInfo([], type$.JSArray_Mapping));
      t1.MultiSectionMapping$fromJson$3$mapUrl(sections, otherMaps, mapUrl);
      return t1;
    },
    MappingBundle$fromJson: function(json, mapUrl) {
      var t1 = new T.MappingBundle(P.LinkedHashMap_LinkedHashMap$_empty(type$.String, type$.SingleMapping));
      t1.MappingBundle$fromJson$2$mapUrl(json, mapUrl);
      return t1;
    },
    SingleMapping$fromJson: function(map, mapUrl) {
      var t5, t6, t7, t8,
        t1 = H._checkStringNullable(map.$index(0, "file")),
        t2 = type$.Iterable_dynamic,
        t3 = type$.String,
        t4 = P.List_List$from(t2._check(map.$index(0, "sources")), true, t3);
      t2 = P.List_List$from(t2._check(map.$index(0, "names")), true, t3);
      t5 = H._checkIntNullable(J.get$length$asx(map.$index(0, "sources")));
      if (typeof t5 !== "number")
        return H.iae(t5);
      t5 = new Array(t5);
      t5.fixed$length = Array;
      t5 = H.setRuntimeTypeInfo(t5, type$.JSArray_SourceFile);
      t6 = H._checkStringNullable(map.$index(0, "sourceRoot"));
      t7 = H.setRuntimeTypeInfo([], type$.JSArray_TargetLineEntry);
      t8 = typeof mapUrl == "string" ? P.Uri_parse(mapUrl) : mapUrl;
      t3 = new T.SingleMapping(t4, t2, t5, t7, t1, t6, type$.Uri._check(t8), P.LinkedHashMap_LinkedHashMap$_empty(t3, type$.dynamic));
      t3.SingleMapping$fromJson$2$mapUrl(map, mapUrl);
      return t3;
    },
    Mapping: function Mapping() {
    },
    MultiSectionMapping: function MultiSectionMapping(t0, t1, t2) {
      this._lineStart = t0;
      this._columnStart = t1;
      this._maps = t2;
    },
    MappingBundle: function MappingBundle(t0) {
      this._mappings = t0;
    },
    SingleMapping: function SingleMapping(t0, t1, t2, t3, t4, t5, t6, t7) {
      var _ = this;
      _.urls = t0;
      _.names = t1;
      _.files = t2;
      _.lines = t3;
      _.targetUrl = t4;
      _.sourceRoot = t5;
      _._parser$_mapUrl = t6;
      _.extensions = t7;
    },
    SingleMapping$fromJson_closure: function SingleMapping$fromJson_closure(t0) {
      this.$this = t0;
    },
    SingleMapping__findLine_closure: function SingleMapping__findLine_closure(t0) {
      this.line = t0;
    },
    SingleMapping__findColumn_closure: function SingleMapping__findColumn_closure(t0) {
      this.column = t0;
    },
    TargetLineEntry: function TargetLineEntry(t0, t1) {
      this.line = t0;
      this.entries = t1;
    },
    TargetEntry: function TargetEntry(t0, t1, t2, t3, t4) {
      var _ = this;
      _.column = t0;
      _.sourceUrlId = t1;
      _.sourceLine = t2;
      _.sourceColumn = t3;
      _.sourceNameId = t4;
    },
    _MappingTokenizer: function _MappingTokenizer(t0, t1) {
      this._internal = t0;
      this._parser$_length = t1;
      this.index = -1;
    },
    _TokenKind: function _TokenKind(t0, t1, t2) {
      this.isNewLine = t0;
      this.isNewSegment = t1;
      this.isEof = t2;
    },
    LazyTrace: function LazyTrace(t0) {
      this._lazy_trace$_thunk = t0;
      this._lazy_trace$_inner = null;
    },
    LazyTrace_foldFrames_closure: function LazyTrace_foldFrames_closure(t0, t1, t2) {
      this.$this = t0;
      this.predicate = t1;
      this.terse = t2;
    },
    RuntimeSelection: function RuntimeSelection() {
    }
  },
  X = {BooleanSelector: function BooleanSelector() {
    }, All: function All() {
    },
    ParsedPath_ParsedPath$parse: function(path, style) {
      var t1, parts, separators, start, i,
        root = style.getRoot$1(path);
      style.isRootRelative$1(path);
      if (root != null)
        path = J.substring$1$s(path, root.length);
      t1 = type$.JSArray_String;
      parts = H.setRuntimeTypeInfo([], t1);
      separators = H.setRuntimeTypeInfo([], t1);
      t1 = path.length;
      if (t1 !== 0 && style.isSeparator$1(C.JSString_methods._codeUnitAt$1(path, 0))) {
        if (0 >= t1)
          return H.ioore(path, 0);
        C.JSArray_methods.add$1(separators, path[0]);
        start = 1;
      } else {
        C.JSArray_methods.add$1(separators, "");
        start = 0;
      }
      for (i = start; i < t1; ++i)
        if (style.isSeparator$1(C.JSString_methods._codeUnitAt$1(path, i))) {
          C.JSArray_methods.add$1(parts, C.JSString_methods.substring$2(path, start, i));
          C.JSArray_methods.add$1(separators, path[i]);
          start = i + 1;
        }
      if (start < t1) {
        C.JSArray_methods.add$1(parts, C.JSString_methods.substring$1(path, start));
        C.JSArray_methods.add$1(separators, "");
      }
      return new X.ParsedPath(style, root, parts, separators);
    },
    ParsedPath: function ParsedPath(t0, t1, t2, t3) {
      var _ = this;
      _.style = t0;
      _.root = t1;
      _.parts = t2;
      _.separators = t3;
    },
    ParsedPath_normalize_closure: function ParsedPath_normalize_closure(t0) {
      this.$this = t0;
    },
    PathException$: function(message) {
      return new X.PathException(message);
    },
    PathException: function PathException(t0) {
      this.message = t0;
    },
    SourceSpanWithContext$: function(start, end, text, _context) {
      var t1 = new X.SourceSpanWithContext(_context, start, end, text);
      t1.SourceSpanBase$3(start, end, text);
      if (!C.JSString_methods.contains$1(_context, text))
        H.throwExpression(P.ArgumentError$('The context line "' + _context + '" must contain "' + text + '".'));
      if (B.findLineStart(_context, text, start.get$column()) == null)
        H.throwExpression(P.ArgumentError$('The span text "' + text + '" must start at column ' + (start.get$column() + 1) + ' in a line within "' + _context + '".'));
      return t1;
    },
    SourceSpanWithContext: function SourceSpanWithContext(t0, t1, t2, t3) {
      var _ = this;
      _._context = t0;
      _.start = t1;
      _.end = t2;
      _.text = t3;
    },
    LazyChain: function LazyChain(t0) {
      this._thunk = t0;
      this._lazy_chain$_inner = null;
    },
    LazyChain_foldFrames_closure: function LazyChain_foldFrames_closure(t0, t1, t2) {
      this.$this = t0;
      this.predicate = t1;
      this.terse = t2;
    },
    LazyChain_toTrace_closure: function LazyChain_toTrace_closure(t0) {
      this.$this = t0;
    },
    StringScanner: function StringScanner() {
    },
    Declarer$: function(collectTraces, metadata, noRetry, platformVariables) {
      var _null = null,
        t1 = metadata == null ? O.Metadata_Metadata(_null, _null, _null, _null, _null, _null, _null, _null, _null, _null) : metadata,
        t2 = platformVariables == null ? C.C_EmptyUnmodifiableSet : platformVariables,
        t3 = type$.JSArray_of_dynamic_Function,
        t4 = type$.JSArray_GroupEntry;
      return new X.Declarer(_null, _null, t1, t2, _null, collectTraces, noRetry, H.setRuntimeTypeInfo([], t3), H.setRuntimeTypeInfo([], t3), H.setRuntimeTypeInfo([], t3), new R.Timeout(P.Duration$(0, 12), _null), H.setRuntimeTypeInfo([], t3), H.setRuntimeTypeInfo([], t4), H.setRuntimeTypeInfo([], t4));
    },
    Declarer: function Declarer(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) {
      var _ = this;
      _._declarer$_parent = t0;
      _._declarer$_name = t1;
      _._metadata = t2;
      _._platformVariables = t3;
      _._declarer$_trace = t4;
      _._collectTraces = t5;
      _._noRetry = t6;
      _._setUps = t7;
      _._tearDowns = t8;
      _._setUpAlls = t9;
      _._timeout = t10;
      _._tearDownAlls = t11;
      _._entries = t12;
      _._built = false;
      _._soloEntries = t13;
    },
    Declarer_test_closure: function Declarer_test_closure(t0, t1) {
      this.$this = t0;
      this.body = t1;
    },
    Declarer_test__closure: function Declarer_test__closure(t0, t1) {
      this.$this = t0;
      this.body = t1;
    },
    Declarer_test___closure: function Declarer_test___closure(t0, t1) {
      this.$this = t0;
      this.body = t1;
    },
    Declarer_group_closure: function Declarer_group_closure(t0) {
      this.body = t0;
    },
    Declarer_build_closure: function Declarer_build_closure(t0) {
      this.$this = t0;
    },
    Declarer__runSetUps_closure: function Declarer__runSetUps_closure() {
    },
    Declarer__tearDownAll_closure: function Declarer__tearDownAll_closure(t0) {
      this.$this = t0;
    },
    Declarer__tearDownAll__closure: function Declarer__tearDownAll__closure(t0) {
      this.$this = t0;
    },
    Declarer__tearDownAll___closure: function Declarer__tearDownAll___closure(t0) {
      this.$this = t0;
    },
    PrintSink: function PrintSink(t0) {
      this._print_sink$_buffer = t0;
    }
  },
  U = {
    _expandSafe: function(start, end) {
      if (start == null || end == null)
        return null;
      if (start.file !== end.file)
        return null;
      return start.expand$1(0, end);
    },
    VariableNode: function VariableNode(t0, t1) {
      this.span = t0;
      this.name = t1;
    },
    NotNode: function NotNode(t0, t1) {
      this.span = t0;
      this.child = t1;
    },
    OrNode: function OrNode(t0, t1) {
      this.left = t0;
      this.right = t1;
    },
    AndNode: function AndNode(t0, t1) {
      this.left = t0;
      this.right = t1;
    },
    ConditionalNode: function ConditionalNode(t0, t1, t2) {
      this.condition = t0;
      this.whenTrue = t1;
      this.whenFalse = t2;
    },
    Highlighter__normalizeNewlines: function(span) {
      var t1, endOffset, i, t2, t3, t4,
        text = span.get$text();
      if (!C.JSString_methods.contains$1(text, "\r\n"))
        return span;
      t1 = span.get$end();
      endOffset = t1.get$offset(t1);
      for (t1 = text.length - 1, i = 0; i < t1; ++i)
        if (C.JSString_methods._codeUnitAt$1(text, i) === 13 && C.JSString_methods._codeUnitAt$1(text, i + 1) === 10)
          --endOffset;
      t1 = span.get$start();
      t2 = span.get$sourceUrl();
      t3 = span.get$end().get$line();
      t2 = V.SourceLocation$(endOffset, span.get$end().get$column(), t3, t2);
      t3 = H.stringReplaceAllUnchecked(text, "\r\n", "\n");
      t4 = span.get$context();
      return X.SourceSpanWithContext$(t1, t2, t3, H.stringReplaceAllUnchecked(t4, "\r\n", "\n"));
    },
    Highlighter__normalizeTrailingNewline: function(span) {
      var context, text, start, end, t1, t2, t3;
      if (!C.JSString_methods.endsWith$1(span.get$context(), "\n"))
        return span;
      if (C.JSString_methods.endsWith$1(span.get$text(), "\n\n"))
        return span;
      context = C.JSString_methods.substring$2(span.get$context(), 0, span.get$context().length - 1);
      text = span.get$text();
      start = span.get$start();
      end = span.get$end();
      if (C.JSString_methods.endsWith$1(span.get$text(), "\n")) {
        t1 = B.findLineStart(span.get$context(), span.get$text(), span.get$start().get$column());
        t2 = span.get$start().get$column();
        if (typeof t1 !== "number")
          return t1.$add();
        t2 = t1 + t2 + span.get$length(span) === span.get$context().length;
        t1 = t2;
      } else
        t1 = false;
      if (t1) {
        text = C.JSString_methods.substring$2(span.get$text(), 0, span.get$text().length - 1);
        t1 = span.get$end();
        t1 = t1.get$offset(t1);
        t2 = span.get$sourceUrl();
        t3 = span.get$end().get$line();
        if (typeof t3 !== "number")
          return t3.$sub();
        end = V.SourceLocation$(t1 - 1, U.Highlighter__lastLineLength(text), t3 - 1, t2);
        t1 = span.get$start();
        t1 = t1.get$offset(t1);
        t2 = span.get$end();
        start = t1 === t2.get$offset(t2) ? end : span.get$start();
      }
      return X.SourceSpanWithContext$(start, end, text, context);
    },
    Highlighter__normalizeEndOfLine: function(span) {
      var text, t1, t2, t3, t4;
      if (span.get$end().get$column() !== 0)
        return span;
      if (span.get$end().get$line() == span.get$start().get$line())
        return span;
      text = C.JSString_methods.substring$2(span.get$text(), 0, span.get$text().length - 1);
      t1 = span.get$start();
      t2 = span.get$end();
      t2 = t2.get$offset(t2);
      t3 = span.get$sourceUrl();
      t4 = span.get$end().get$line();
      if (typeof t4 !== "number")
        return t4.$sub();
      return X.SourceSpanWithContext$(t1, V.SourceLocation$(t2 - 1, U.Highlighter__lastLineLength(text), t4 - 1, t3), text, span.get$context());
    },
    Highlighter__lastLineLength: function(text) {
      var t1 = text.length;
      if (t1 === 0)
        return 0;
      if (C.JSString_methods.codeUnitAt$1(text, t1 - 1) === 10)
        return t1 === 1 ? 0 : t1 - C.JSString_methods.lastIndexOf$2(text, "\n", t1 - 2) - 1;
      else
        return t1 - C.JSString_methods.lastIndexOf$1(text, "\n") - 1;
    },
    Highlighter: function Highlighter(t0, t1, t2, t3, t4) {
      var _ = this;
      _._span = t0;
      _._color = t1;
      _._multiline = t2;
      _._paddingBeforeSidebar = t3;
      _._highlighter$_buffer = t4;
    },
    Highlighter__writeFirstLine_closure: function Highlighter__writeFirstLine_closure(t0, t1) {
      this.$this = t0;
      this.line = t1;
    },
    Highlighter__writeFirstLine_closure0: function Highlighter__writeFirstLine_closure0(t0, t1) {
      this.$this = t0;
      this.textInside = t1;
    },
    Highlighter__writeFirstLine_closure1: function Highlighter__writeFirstLine_closure1(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Highlighter__writeFirstLine_closure2: function Highlighter__writeFirstLine_closure2(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Highlighter__writeIntermediateLines_closure: function Highlighter__writeIntermediateLines_closure(t0, t1) {
      this.$this = t0;
      this.line = t1;
    },
    Highlighter__writeLastLine_closure: function Highlighter__writeLastLine_closure(t0, t1) {
      this.$this = t0;
      this.line = t1;
    },
    Highlighter__writeLastLine_closure0: function Highlighter__writeLastLine_closure0(t0, t1) {
      this.$this = t0;
      this.textInside = t1;
    },
    Highlighter__writeLastLine_closure1: function Highlighter__writeLastLine_closure1(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Highlighter__writeSidebar_closure: function Highlighter__writeSidebar_closure(t0, t1, t2) {
      this.$this = t0;
      this.line = t1;
      this.end = t2;
    },
    Chain_capture: function(callback, errorZone, when, $T) {
      var t1, spec, _null = null;
      if (!when)
        return P.runZoned(callback, _null, _null, _null, $T);
      if (typeof WeakMap == "function")
        t1 = new WeakMap();
      else {
        t1 = $.Expando__keyCount;
        $.Expando__keyCount = t1 + 1;
        t1 = "expando$key$" + t1;
      }
      spec = new O.StackZoneSpecification(new P.Expando(t1, "stack chains", type$.Expando__Node), _null, false);
      t1 = type$.dynamic;
      return P.runZoned(new U.Chain_capture_closure(callback, $T), _null, P._ZoneSpecification$(_null, _null, spec.get$_stack_zone_specification$_errorCallback(), _null, _null, _null, spec.get$_stack_zone_specification$_registerBinaryCallback(), spec.get$_stack_zone_specification$_registerCallback(), spec.get$_stack_zone_specification$_registerUnaryCallback(), _null, _null, _null, _null), P.LinkedHashMap_LinkedHashMap$_literal([$.$get$_specKey(), spec, $.$get$StackZoneSpecification_disableKey(), false], t1, t1), $T);
    },
    Chain_Chain$current: function() {
      var t1 = $.Zone__current,
        t2 = $.$get$_specKey(),
        t3 = type$.StackZoneSpecification;
      if (t3._check(t1.$index(0, t2)) != null) {
        t1 = t3._check($.Zone__current.$index(0, t2));
        t2 = t1._currentTrace$1(3);
        t1 = t1._currentNode;
        return new O._Node(Y.Trace_Trace$from(t2), t1).toChain$0();
      }
      return new X.LazyChain(new U.Chain_Chain$current_closure(U.Chain_Chain$forTrace(P.StackTrace_current()), 0));
    },
    Chain_Chain$forTrace: function(trace) {
      var t1, t2, t3;
      if (type$.Chain._is(trace))
        return trace;
      t1 = $.Zone__current;
      t2 = $.$get$_specKey();
      t3 = type$.StackZoneSpecification;
      if (t3._check(t1.$index(0, t2)) != null)
        return t3._check($.Zone__current.$index(0, t2)).chainFor$1(trace);
      t1 = type$.Trace;
      if (t1._is(trace))
        return new U.Chain(P.List_List$unmodifiable(H.setRuntimeTypeInfo([trace], type$.JSArray_Trace), t1));
      return new X.LazyChain(new U.Chain_Chain$forTrace_closure(trace));
    },
    Chain_Chain$parse: function(chain) {
      var _s26_ = "<asynchronous suspension>\n",
        _s51_ = "===== asynchronous gap ===========================\n";
      if (chain.length === 0)
        return new U.Chain(P.List_List$unmodifiable(H.setRuntimeTypeInfo([], type$.JSArray_Trace), type$.Trace));
      if (C.JSString_methods.contains$1(chain, _s26_))
        return new U.Chain(P.List_List$unmodifiable(new H.MappedListIterable(H.setRuntimeTypeInfo(chain.split(_s26_), type$.JSArray_String), type$.Trace_Function_String._check(new U.Chain_Chain$parse_closure()), type$.MappedListIterable_String_Trace), type$.Trace));
      if (!C.JSString_methods.contains$1(chain, _s51_))
        return new U.Chain(P.List_List$unmodifiable(H.setRuntimeTypeInfo([Y.Trace_Trace$parse(chain)], type$.JSArray_Trace), type$.Trace));
      return new U.Chain(P.List_List$unmodifiable(new H.MappedListIterable(H.setRuntimeTypeInfo(chain.split(_s51_), type$.JSArray_String), type$.Trace_Function_String._check(new U.Chain_Chain$parse_closure0()), type$.MappedListIterable_String_Trace), type$.Trace));
    },
    Chain: function Chain(t0) {
      this.traces = t0;
    },
    Chain_capture_closure: function Chain_capture_closure(t0, t1) {
      this.callback = t0;
      this.T = t1;
    },
    Chain_Chain$current_closure: function Chain_Chain$current_closure(t0, t1) {
      this.chain = t0;
      this.level = t1;
    },
    Chain_Chain$forTrace_closure: function Chain_Chain$forTrace_closure(t0) {
      this.trace = t0;
    },
    Chain_Chain$parse_closure: function Chain_Chain$parse_closure() {
    },
    Chain_Chain$parse_closure0: function Chain_Chain$parse_closure0() {
    },
    Chain_foldFrames_closure: function Chain_foldFrames_closure(t0, t1) {
      this.predicate = t0;
      this.terse = t1;
    },
    Chain_foldFrames_closure0: function Chain_foldFrames_closure0(t0) {
      this.terse = t0;
    },
    Chain_toTrace_closure: function Chain_toTrace_closure() {
    },
    Chain_toString_closure0: function Chain_toString_closure0() {
    },
    Chain_toString__closure0: function Chain_toString__closure0() {
    },
    Chain_toString_closure: function Chain_toString_closure(t0) {
      this.longest = t0;
    },
    Chain_toString__closure: function Chain_toString__closure(t0) {
      this.longest = t0;
    },
    Invoker_guard: function(callback, $T) {
      var _null = null;
      return P.runZoned(callback, _null, P._ZoneSpecification$(_null, _null, _null, _null, new U.Invoker_guard_closure(), _null, _null, _null, _null, _null, _null, _null, _null), _null, $T);
    },
    LocalTest: function LocalTest(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _.name = t0;
      _.metadata = t1;
      _.trace = t2;
      _.isScaffoldAll = t3;
      _._body = t4;
      _._guarded = t5;
    },
    Invoker: function Invoker(t0, t1, t2, t3, t4, t5, t6) {
      var _ = this;
      _._invoker$_controller = null;
      _._guarded = t0;
      _._closableKey = t1;
      _._onCloseCompleter = t2;
      _._outstandingCallbackZones = t3;
      _._counterKey = t4;
      _._runCount = 0;
      _._timeoutTimer = _._invokerZone = null;
      _._invoker$_tearDowns = t5;
      _._printsOnFailure = t6;
    },
    Invoker_guard_closure: function Invoker_guard_closure() {
    },
    Invoker_guard__closure: function Invoker_guard__closure(t0, t1, t2, t3) {
      var _ = this;
      _.invoker = t0;
      _.zone = t1;
      _.error = t2;
      _.stackTrace = t3;
    },
    Invoker_waitForOutstandingCallbacks_closure: function Invoker_waitForOutstandingCallbacks_closure(t0, t1, t2, t3) {
      var _ = this;
      _._box_0 = t0;
      _.$this = t1;
      _.fn = t2;
      _.counter = t3;
    },
    Invoker_waitForOutstandingCallbacks_closure0: function Invoker_waitForOutstandingCallbacks_closure0(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    Invoker_heartbeat_message: function Invoker_heartbeat_message(t0) {
      this.timeout = t0;
    },
    Invoker_heartbeat_closure: function Invoker_heartbeat_closure(t0, t1, t2) {
      this.$this = t0;
      this.message = t1;
      this.timeout = t2;
    },
    Invoker_heartbeat__closure: function Invoker_heartbeat__closure(t0, t1, t2) {
      this.$this = t0;
      this.message = t1;
      this.timeout = t2;
    },
    Invoker__handleError_closure: function Invoker__handleError_closure(t0) {
      this._box_0 = t0;
    },
    Invoker__handleError_closure0: function Invoker__handleError_closure0(t0) {
      this.$this = t0;
    },
    Invoker__onRun_closure: function Invoker__onRun_closure(t0, t1) {
      this.$this = t0;
      this.outstandingCallbacksForBody = t1;
    },
    Invoker__onRun__closure: function Invoker__onRun__closure(t0, t1) {
      this.$this = t0;
      this.outstandingCallbacksForBody = t1;
    },
    Invoker__onRun___closure: function Invoker__onRun___closure(t0) {
      this.$this = t0;
    },
    Invoker__onRun____closure: function Invoker__onRun____closure(t0) {
      this.$this = t0;
    },
    Invoker__onRun___closure0: function Invoker__onRun___closure0(t0) {
      this.$this = t0;
    },
    _AsyncCounter: function _AsyncCounter(t0) {
      this._count = 1;
      this._invoker$_completer = t0;
    },
    StackTraceFormatter: function StackTraceFormatter(t0, t1) {
      this._mapper = null;
      this._except = t0;
      this._only = t1;
    },
    StackTraceFormatter_formatStackTrace_closure: function StackTraceFormatter_formatStackTrace_closure(t0) {
      this.$this = t0;
    },
    Suite__filterGroup: function(group, platform) {
      var t1, _null = null,
        filtered = group.forPlatform$1(platform);
      if (filtered != null)
        return filtered;
      t1 = P.List_List$unmodifiable(H.setRuntimeTypeInfo([], type$.JSArray_GroupEntry), type$.GroupEntry);
      return new O.Group(_null, group.metadata, _null, t1, _null, _null);
    },
    Suite: function Suite(t0, t1, t2) {
      this.platform = t0;
      this.path = t1;
      this.group = t2;
    },
    SuiteConfiguration__list: function(input, $T) {
      return null;
    },
    SuiteConfiguration__map: function(input, $K, $V) {
      return C.Map_empty1;
    },
    SuiteConfiguration: function SuiteConfiguration() {
    },
    RemoteException_serialize: function(error, stackTrace) {
      var exception, supertype, t1, message = null;
      if (typeof error == "string")
        message = error;
      else
        try {
          message = J.toString$0$(J.get$message$x(error));
        } catch (exception) {
          if (!type$.NoSuchMethodError._is(H.unwrapException(exception)))
            throw exception;
        }
      supertype = error instanceof G.TestFailure ? "TestFailure" : null;
      t1 = J.getInterceptor$(error);
      return P.LinkedHashMap_LinkedHashMap$_literal(["message", message, "type", t1.get$runtimeType(error).toString$0(0), "supertype", supertype, "toString", t1.toString$0(error), "stackChain", J.toString$0$(U.Chain_Chain$forTrace(stackTrace))], type$.String, type$.dynamic);
    }
  },
  R = {IntersectionSelector: function IntersectionSelector(t0, t1) {
      this._selector1 = t0;
      this._selector2 = t1;
    }, StreamChannel: function StreamChannel() {
    }, _StreamChannel: function _StreamChannel(t0, t1, t2) {
      this.stream = t0;
      this.sink = t1;
      this.$ti = t2;
    }, StreamChannelMixin: function StreamChannelMixin() {
    }, Timeout: function Timeout(t0, t1) {
      this.duration = t0;
      this.scaleFactor = t1;
    }, ExpandedReporter: function ExpandedReporter(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) {
      var _ = this;
      _._expanded$_color = t0;
      _._green = t1;
      _._red = t2;
      _._yellow = t3;
      _._gray = t4;
      _._bold = t5;
      _._noColor = t6;
      _._engine = t7;
      _._printPath = t8;
      _._printPlatform = t9;
      _._stopwatch = t10;
      _._lastProgressSuffix = _._lastProgressMessage = _._lastProgressFailed = _._lastProgressSkipped = _._lastProgressPassed = null;
      _._subscriptions = t11;
      _._expanded$_sink = t12;
    }, ExpandedReporter__onTestStarted_closure: function ExpandedReporter__onTestStarted_closure(t0, t1) {
      this.$this = t0;
      this.liveTest = t1;
    }, ExpandedReporter__onTestStarted_closure0: function ExpandedReporter__onTestStarted_closure0(t0, t1) {
      this.$this = t0;
      this.liveTest = t1;
    }, ExpandedReporter__onTestStarted_closure1: function ExpandedReporter__onTestStarted_closure1(t0, t1) {
      this.$this = t0;
      this.liveTest = t1;
    },
    _declarer: function() {
      var t1,
        declarer = type$.Declarer._as($.Zone__current.$index(0, C.Symbol_Drw));
      if (declarer != null)
        return declarer;
      t1 = $._globalDeclarer;
      if (t1 != null)
        return t1;
      $._globalDeclarer = X.Declarer$(false, null, false, null);
      P.scheduleMicrotask(new R._declarer_closure());
      return $._globalDeclarer;
    },
    test: function(description, body) {
      var _null = null;
      R._declarer().test$9$onPlatform$retry$skip$solo$tags$testOn$timeout(description, body, _null, _null, _null, false, _null, _null, _null);
      return;
    },
    group: function(description, body) {
      var _null = null;
      R._declarer().group$9$onPlatform$retry$skip$solo$tags$testOn$timeout(description, body, _null, _null, _null, false, _null, _null, _null);
      return;
    },
    _declarer_closure: function _declarer_closure() {
    },
    _declarer__closure: function _declarer__closure(t0) {
      this.engine = t0;
    },
    main: function() {
      L.internalBootstrapBrowserTest(new R.main_closure());
    },
    main_closure: function main_closure() {
    }
  },
  B = {RecursiveVisitor: function RecursiveVisitor() {
    }, InternalStyle: function InternalStyle() {
    },
    StreamChannelController$: function(allowForeignErrors, sync, $T) {
      var _null = null,
        t1 = new B.StreamChannelController($T._eval$1("StreamChannelController<0>")),
        localToForeignController = P.StreamController_StreamController(_null, _null, true, $T),
        foreignToLocalController = P.StreamController_StreamController(_null, _null, true, $T),
        t2 = H._instanceType(foreignToLocalController),
        t3 = H._instanceType(localToForeignController);
      t1.set$_local(K.GuaranteeChannel$(new P._ControllerStream(foreignToLocalController, t2._eval$1("_ControllerStream<1>")), new P._StreamSinkWrapper(localToForeignController, t3._eval$1("_StreamSinkWrapper<1>")), true, $T));
      t1.set$_foreign(K.GuaranteeChannel$(new P._ControllerStream(localToForeignController, t3._eval$1("_ControllerStream<1>")), new P._StreamSinkWrapper(foreignToLocalController, t2._eval$1("_StreamSinkWrapper<1>")), allowForeignErrors, $T));
      return t1;
    },
    StreamChannelController: function StreamChannelController(t0) {
      this._foreign = this._local = null;
      this.$ti = t0;
    },
    Runtime_Runtime$deserialize: function(serialized) {
      var $parent, t1, t2, t3,
        _s10_ = "identifier";
      if (typeof serialized == "string")
        return C.JSArray_methods.firstWhere$1(C.List_m7e, new B.Runtime_Runtime$deserialize_closure(serialized));
      type$.Map_dynamic_dynamic._as(serialized);
      $parent = serialized.$index(0, "parent");
      if ($parent != null) {
        t1 = H._asStringNullable(serialized.$index(0, "name"));
        t2 = H._asStringNullable(serialized.$index(0, _s10_));
        t3 = B.Runtime_Runtime$deserialize($parent);
        return new B.Runtime(t1, t2, t3, t3.isDartVM, t3.isBrowser, t3.isJS, t3.isBlink, t3.isHeadless);
      }
      return new B.Runtime(H._asStringNullable(serialized.$index(0, "name")), H._asStringNullable(serialized.$index(0, _s10_)), null, H._asBoolNullable(serialized.$index(0, "isDartVM")), H._asBoolNullable(serialized.$index(0, "isBrowser")), H._asBoolNullable(serialized.$index(0, "isJS")), H._asBoolNullable(serialized.$index(0, "isBlink")), H._asBoolNullable(serialized.$index(0, "isHeadless")));
    },
    Runtime: function Runtime(t0, t1, t2, t3, t4, t5, t6, t7) {
      var _ = this;
      _.name = t0;
      _.identifier = t1;
      _.parent = t2;
      _.isDartVM = t3;
      _.isBrowser = t4;
      _.isJS = t5;
      _.isBlink = t6;
      _.isHeadless = t7;
    },
    Runtime_Runtime$deserialize_closure: function Runtime_Runtime$deserialize_closure(t0) {
      this.serialized = t0;
    },
    indent: function(string, first) {
      var size = first == null ? 2 : first.length;
      return B.prefixLines(string, C.JSString_methods.$mul(" ", size), first);
    },
    toSentence: function(iter) {
      var result,
        t1 = iter.length;
      if (t1 === 1)
        return J.toString$0$(C.JSArray_methods.get$first(iter));
      result = H.SubListIterable$(iter, 0, t1 - 1, H._arrayInstanceType(iter)._precomputed1).join$1(0, ", ");
      if (iter.length > 2)
        result += ",";
      return result + " and " + H.S(C.JSArray_methods.get$last(iter));
    },
    pluralize: function($name, number) {
      if (number === 1)
        return $name;
      return $name + "s";
    },
    prefixLines: function(text, prefix, first) {
      var single, lines, t1, t2;
      if (first == null)
        first = prefix;
      single = first;
      lines = H.setRuntimeTypeInfo(text.split("\n"), type$.JSArray_String);
      if (lines.length === 1)
        return single + text;
      t1 = first + H.S(C.JSArray_methods.get$first(lines)) + "\n";
      for (t2 = H.SubListIterable$(lines, 1, null, type$.String).take$1(0, lines.length - 2), t2 = new H.ListIterator(t2, t2.get$length(t2), t2.$ti._eval$1("ListIterator<ListIterable.E>")); t2.moveNext$0();)
        t1 += prefix + H.S(t2.__internal$_current) + "\n";
      t1 += prefix + H.S(C.JSArray_methods.get$last(lines));
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    closure0: function closure0() {
    },
    LiveSuiteController$: function(_suite) {
      var t1 = $.Zone__current,
        t2 = H.setRuntimeTypeInfo([], type$.JSArray_dynamic),
        t3 = $.Zone__current,
        t4 = type$._Future_dynamic,
        t5 = type$._AsyncCompleter_dynamic,
        t6 = type$.LiveTest;
      t5 = new B.LiveSuiteController(_suite, new F.FutureGroup(new P._AsyncCompleter(new P._Future(t1, type$._Future_List_dynamic), type$._AsyncCompleter_List_dynamic), t2, type$.FutureGroup_dynamic), new P._AsyncCompleter(new P._Future(t3, t4), t5), new P._SyncBroadcastStreamController(null, null, type$._SyncBroadcastStreamController_LiveTest), P.LinkedHashSet_LinkedHashSet$_empty(t6), P.LinkedHashSet_LinkedHashSet$_empty(t6), P.LinkedHashSet_LinkedHashSet$_empty(t6), new S.AsyncMemoizer(new P._AsyncCompleter(new P._Future(t3, t4), t5), type$.AsyncMemoizer_dynamic));
      t5.LiveSuiteController$1(_suite);
      return t5;
    },
    _LiveSuite: function _LiveSuite(t0) {
      this._live_suite_controller$_controller = t0;
    },
    LiveSuiteController: function LiveSuiteController(t0, t1, t2, t3, t4, t5, t6, t7) {
      var _ = this;
      _._liveSuite = null;
      _._live_suite_controller$_suite = t0;
      _._onCompleteGroup = t1;
      _._live_suite_controller$_onCloseCompleter = t2;
      _._onTestStartedController = t3;
      _._passed = t4;
      _._skipped = t5;
      _._failed = t6;
      _._live_suite_controller$_active = null;
      _._live_suite_controller$_closeMemo = t7;
    },
    LiveSuiteController_closure: function LiveSuiteController_closure(t0) {
      this.$this = t0;
    },
    LiveSuiteController_closure0: function LiveSuiteController_closure0() {
    },
    LiveSuiteController_reportLiveTest_closure: function LiveSuiteController_reportLiveTest_closure(t0, t1, t2) {
      this.$this = t0;
      this.liveTest = t1;
      this.countSuccess = t2;
    },
    LiveSuiteController_close_closure: function LiveSuiteController_close_closure(t0) {
      this.$this = t0;
    },
    asUri: function(uri, $name) {
      if (type$.Uri._is(uri))
        return uri;
      throw H.wrapException(P.ArgumentError$value(uri, $name, "Must be a String or a Uri."));
    },
    ensureTrailingSlash: function(uri) {
      var t1;
      if (uri.get$pathSegments().length === 0)
        return uri.replace$1$path(0, "/");
      t1 = C.JSArray_methods.get$last(uri.get$pathSegments());
      t1.toString;
      if (J.get$length$asx(t1) === 0)
        return uri;
      t1 = uri.get$pathSegments();
      t1 = H.setRuntimeTypeInfo(t1.slice(0), H._arrayInstanceType(t1)._eval$1("JSArray<1>"));
      C.JSArray_methods.add$1(t1, "");
      return uri.replace$1$pathSegments(0, t1);
    },
    isAlphabetic: function(char) {
      var t1;
      if (!(char >= 65 && char <= 90))
        t1 = char >= 97 && char <= 122;
      else
        t1 = true;
      return t1;
    },
    isDriveLetter: function(path, index) {
      var t1 = path.length,
        t2 = index + 2;
      if (t1 < t2)
        return false;
      if (!B.isAlphabetic(C.JSString_methods.codeUnitAt$1(path, index)))
        return false;
      if (C.JSString_methods.codeUnitAt$1(path, index + 1) !== 58)
        return false;
      if (t1 === t2)
        return true;
      return C.JSString_methods.codeUnitAt$1(path, t2) === 47;
    },
    countCodeUnits: function(string, codeUnit) {
      var t1, count;
      for (t1 = new H.CodeUnits(string), t1 = new H.ListIterator(t1, t1.get$length(t1), type$.CodeUnits._eval$1("ListIterator<ListMixin.E>")), count = 0; t1.moveNext$0();)
        if (t1.__internal$_current === codeUnit)
          ++count;
      return count;
    },
    findLineStart: function(context, text, column) {
      var beginningOfLine, index, lineStart;
      if (text.length === 0)
        for (beginningOfLine = 0; true;) {
          index = C.JSString_methods.indexOf$2(context, "\n", beginningOfLine);
          if (index === -1)
            return context.length - beginningOfLine >= column ? beginningOfLine : null;
          if (index - beginningOfLine >= column)
            return beginningOfLine;
          beginningOfLine = index + 1;
        }
      index = C.JSString_methods.indexOf$1(context, text);
      for (; index !== -1;) {
        lineStart = index === 0 ? 0 : C.JSString_methods.lastIndexOf$2(context, "\n", index - 1) + 1;
        if (column === index - lineStart)
          return lineStart;
        index = C.JSString_methods.indexOf$2(context, text, index + 1);
      }
      return null;
    },
    validateErrorArgs: function(string, match, position, $length) {
      var t1;
      if (position < 0)
        throw H.wrapException(P.RangeError$("position must be greater than or equal to 0."));
      else if (position > string.length)
        throw H.wrapException(P.RangeError$("position must be less than or equal to the string length."));
      t1 = position + $length > string.length;
      if (t1)
        throw H.wrapException(P.RangeError$("position plus length must not go beyond the end of the string."));
    }
  },
  Q = {
    QueueList$: function($E) {
      var t1 = new Q.QueueList($E._eval$1("QueueList<0>")),
        t2 = new Array(8);
      t2.fixed$length = Array;
      t1.set$_queue_list$_table(H.setRuntimeTypeInfo(t2, $E._eval$1("JSArray<0>")));
      return t1;
    },
    QueueList__nextPowerOf2: function(number) {
      var nextNumber;
      H.assertHelper(number > 0);
      number = (number << 1 >>> 0) - 1;
      for (; true; number = nextNumber) {
        nextNumber = (number & number - 1) >>> 0;
        if (nextNumber === 0)
          return number;
      }
    },
    QueueList: function QueueList(t0) {
      var _ = this;
      _._queue_list$_table = null;
      _._queue_list$_tail = _._queue_list$_head = 0;
      _.$ti = t0;
    },
    _QueueList_Object_ListMixin: function _QueueList_Object_ListMixin() {
    }
  },
  M = {UnionSet: function UnionSet(t0, t1, t2) {
      this._sets = t0;
      this._disjoint = t1;
      this.$ti = t2;
    }, UnionSet_length_closure: function UnionSet_length_closure(t0) {
      this.$this = t0;
    }, UnionSet__iterable_closure: function UnionSet__iterable_closure(t0) {
      this.$this = t0;
    }, _UnionSet_SetBase_UnmodifiableSetMixin: function _UnionSet_SetBase_UnmodifiableSetMixin() {
    }, _DelegatingIterableBase: function _DelegatingIterableBase() {
    }, DelegatingIterable: function DelegatingIterable() {
    }, DelegatingSet: function DelegatingSet(t0, t1) {
      this._base = t0;
      this.$ti = t1;
    }, TypeMatcher: function TypeMatcher() {
    },
    wrapMatcher: function(x) {
      var _s18_ = "satisfies function";
      if (x instanceof G.Matcher)
        return x;
      else if (type$.bool_Function_Object._is(x))
        return new Y._Predicate(x, _s18_, type$._Predicate_Object);
      else if (type$.bool_Function_Null._is(x))
        return new Y._Predicate(new M.wrapMatcher_closure(x), _s18_, type$._Predicate_dynamic);
      else
        return typeof x == "string" ? new D._StringEqualsMatcher(x) : new D._DeepMatcher(x, 100);
    },
    escape: function(str) {
      str.toString;
      return C.JSString_methods.splitMapJoin$2$onMatch(H.stringReplaceAllUnchecked(str, "\\", "\\\\"), $.$get$_escapeRegExp(), type$.String_Function_Match._check(new M.escape_closure()));
    },
    _getHexLiteral: function(input) {
      var t1, it, result;
      H._checkStringNullable(input);
      input.toString;
      t1 = new P.Runes(input);
      it = t1.get$iterator(t1);
      if (!it.moveNext$0())
        H.throwExpression(H.IterableElementError_noElement());
      result = it.get$current();
      if (it.moveNext$0())
        H.throwExpression(H.IterableElementError_tooMany());
      return "\\x" + C.JSString_methods.padLeft$2(J.toRadixString$1$n(result, 16).toUpperCase(), 2, "0");
    },
    wrapMatcher_closure: function wrapMatcher_closure(t0) {
      this.x = t0;
    },
    escape_closure: function escape_closure() {
    },
    Context_Context: function(style) {
      var current = style == null ? D.current() : ".";
      if (style == null)
        style = $.$get$Style_platform();
      return new M.Context(style, current);
    },
    _parseUri: function(uri) {
      if (type$.Uri._is(uri))
        return uri;
      throw H.wrapException(P.ArgumentError$value(uri, "uri", "Value must be a String or a Uri"));
    },
    _validateArgList: function(method, args) {
      var numArgs, i, numArgs0, message, t1, t2, t3;
      for (numArgs = args.length, i = 1; i < numArgs; ++i) {
        if (args[i] == null || args[i - 1] != null)
          continue;
        for (; numArgs >= 1; numArgs = numArgs0) {
          numArgs0 = numArgs - 1;
          if (args[numArgs0] != null)
            break;
        }
        message = new P.StringBuffer("");
        t1 = method + "(";
        message._contents = t1;
        t2 = H.SubListIterable$(args, 0, numArgs, H._arrayInstanceType(args)._precomputed1);
        t3 = t2.$ti;
        t3 = t1 + new H.MappedListIterable(t2, t3._eval$1("String(ListIterable.E)")._check(new M._validateArgList_closure()), t3._eval$1("MappedListIterable<ListIterable.E,String>")).join$1(0, ", ");
        message._contents = t3;
        message._contents = t3 + ("): part " + (i - 1) + " was null, but part " + i + " was not.");
        throw H.wrapException(P.ArgumentError$(message.toString$0(0)));
      }
    },
    Context: function Context(t0, t1) {
      this.style = t0;
      this._context$_current = t1;
    },
    Context_join_closure: function Context_join_closure() {
    },
    Context_joinAll_closure: function Context_joinAll_closure() {
    },
    Context_split_closure: function Context_split_closure() {
    },
    _validateArgList_closure: function _validateArgList_closure() {
    },
    _PathDirection: function _PathDirection(t0) {
      this.name = t0;
    },
    _PathRelation: function _PathRelation(t0) {
      this.name = t0;
    }
  },
  D = {
    _StringEqualsMatcher__writeLeading: function(buff, s, start) {
      var t1 = buff._contents;
      if (start > 10) {
        t1 += "... ";
        buff._contents = t1;
        buff._contents = t1 + C.JSString_methods.substring$2(s, start - 10, start);
      } else
        buff._contents = t1 + C.JSString_methods.substring$2(s, 0, start);
    },
    _StringEqualsMatcher__writeTrailing: function(buff, s, start) {
      var t1 = start + 10,
        t2 = buff._contents;
      if (t1 > s.length)
        buff._contents = t2 + C.JSString_methods.substring$1(s, start);
      else {
        t1 = t2 + C.JSString_methods.substring$2(s, start, t1);
        buff._contents = t1;
        buff._contents = t1 + " ...";
      }
    },
    _StringEqualsMatcher: function _StringEqualsMatcher(t0) {
      this._equals_matcher$_value = t0;
    },
    _DeepMatcher: function _DeepMatcher(t0, t1) {
      this._expected = t0;
      this._limit = t1;
    },
    _DeepMatcher__compareSets_closure: function _DeepMatcher__compareSets_closure(t0, t1, t2, t3) {
      var _ = this;
      _.matcher = t0;
      _.expectedElement = t1;
      _.location = t2;
      _.depth = t3;
    },
    PackageRootResolver: function PackageRootResolver(t0) {
      this.packageRoot = t0;
    },
    SourceLocationMixin: function SourceLocationMixin() {
    },
    _MultiChannel$: function(_inner, $T) {
      var t1 = type$.int;
      t1 = new D._MultiChannel(_inner, B.StreamChannelController$(true, true, $T), P.LinkedHashMap_LinkedHashMap$_empty(t1, $T._eval$1("StreamChannelController<0>")), P.LinkedHashSet_LinkedHashSet(t1), P.LinkedHashSet_LinkedHashSet(t1), $T._eval$1("_MultiChannel<0>"));
      t1._MultiChannel$1(_inner, $T);
      return t1;
    },
    _MultiChannel: function _MultiChannel(t0, t1, t2, t3, t4, t5) {
      var _ = this;
      _._multi_channel$_inner = t0;
      _._innerStreamSubscription = null;
      _._mainController = t1;
      _._controllers = t2;
      _._pendingIds = t3;
      _._closedIds = t4;
      _._nextId = 1;
      _.$ti = t5;
    },
    _MultiChannel_closure: function _MultiChannel_closure(t0, t1) {
      this.$this = t0;
      this.T = t1;
    },
    _MultiChannel_closure0: function _MultiChannel_closure0(t0) {
      this.$this = t0;
    },
    _MultiChannel_closure1: function _MultiChannel_closure1(t0, t1) {
      this.$this = t0;
      this.T = t1;
    },
    _MultiChannel__closure: function _MultiChannel__closure(t0, t1, t2) {
      this.$this = t0;
      this.id = t1;
      this.T = t2;
    },
    _MultiChannel_virtualChannel_closure: function _MultiChannel_virtualChannel_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    _MultiChannel_virtualChannel_closure0: function _MultiChannel_virtualChannel_closure0(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    VirtualChannel: function VirtualChannel(t0, t1, t2, t3, t4) {
      var _ = this;
      _._multi_channel$_parent = t0;
      _.id = t1;
      _.stream = t2;
      _.sink = t3;
      _.$ti = t4;
    },
    Message: function Message(t0, t1) {
      this.type = t0;
      this.text = t1;
    },
    MessageType: function MessageType(t0) {
      this.name = t0;
    },
    current: function() {
      var exception, t1, path, lastIndex, uri = null;
      try {
        uri = P.Uri_base();
      } catch (exception) {
        if (type$.Exception._is(H.unwrapException(exception))) {
          t1 = $._current;
          if (t1 != null)
            return t1;
          throw exception;
        } else
          throw exception;
      }
      if (J.$eq$(uri, $._currentUriBase))
        return $._current;
      $._currentUriBase = uri;
      if ($.$get$Style_platform() == $.$get$Style_url())
        return $._current = uri.resolve$1(".").toString$0(0);
      else {
        path = uri.toFilePath$0();
        t1 = path.length;
        lastIndex = t1 - 1;
        if (lastIndex < 0)
          return H.ioore(path, lastIndex);
        t1 = path[lastIndex];
        H.assertHelper(t1 === "/" || t1 === "\\");
        return $._current = lastIndex === 0 ? path : C.JSString_methods.substring$2(path, 0, lastIndex);
      }
    }
  },
  Z = {
    prettyPrint: function(object, maxItems, maxLineLength) {
      return new Z.prettyPrint__prettyPrint(maxItems, maxLineLength).call$4(object, 0, P.LinkedHashSet_LinkedHashSet$_empty(type$.Object), true);
    },
    _typeName: function(x) {
      if (type$.Type._is(x))
        return "Type";
      if (type$.Uri._is(x))
        return "Uri";
      if (type$.Set_dynamic._is(x))
        return "Set";
      return J.get$runtimeType$(x).toString$0(0);
    },
    _escapeString: function(source) {
      var t1 = M.escape(H._checkStringNullable(source));
      return H.stringReplaceAllUnchecked(t1, "'", "\\'");
    },
    prettyPrint__prettyPrint: function prettyPrint__prettyPrint(t0, t1) {
      this.maxItems = t0;
      this.maxLineLength = t1;
    },
    prettyPrint__prettyPrint_pp: function prettyPrint__prettyPrint_pp(t0, t1, t2) {
      this._box_0 = t0;
      this._prettyPrint = t1;
      this.indent = t2;
    },
    prettyPrint__prettyPrint_closure: function prettyPrint__prettyPrint_closure(t0) {
      this.indent = t0;
    },
    prettyPrint__prettyPrint_closure0: function prettyPrint__prettyPrint_closure0(t0, t1) {
      this.pp = t0;
      this.object = t1;
    },
    prettyPrint__prettyPrint_closure1: function prettyPrint__prettyPrint_closure1(t0) {
      this.indent = t0;
    },
    LiveTest: function LiveTest() {
    }
  },
  A = {
    Frame_Frame$parseVM: function(frame) {
      return A.Frame__catchFormatException(frame, new A.Frame_Frame$parseVM_closure(frame));
    },
    Frame_Frame$parseV8: function(frame) {
      return A.Frame__catchFormatException(frame, new A.Frame_Frame$parseV8_closure(frame));
    },
    Frame_Frame$parseFirefox: function(frame) {
      return A.Frame__catchFormatException(frame, new A.Frame_Frame$parseFirefox_closure(frame));
    },
    Frame_Frame$parseFriendly: function(frame) {
      return A.Frame__catchFormatException(frame, new A.Frame_Frame$parseFriendly_closure(frame));
    },
    Frame__uriOrPathToUri: function(uriOrPath) {
      if (J.getInterceptor$asx(uriOrPath).contains$1(uriOrPath, $.$get$Frame__uriRegExp()))
        return P.Uri_parse(uriOrPath);
      else if (C.JSString_methods.contains$1(uriOrPath, $.$get$Frame__windowsRegExp()))
        return P._Uri__Uri$file(uriOrPath, true);
      else if (C.JSString_methods.startsWith$1(uriOrPath, "/"))
        return P._Uri__Uri$file(uriOrPath, false);
      if (C.JSString_methods.contains$1(uriOrPath, "\\"))
        return $.$get$windows().toUri$1(uriOrPath);
      return P.Uri_parse(uriOrPath);
    },
    Frame__catchFormatException: function(text, body) {
      var t1, exception;
      try {
        t1 = body.call$0();
        return t1;
      } catch (exception) {
        if (type$.FormatException._is(H.unwrapException(exception)))
          return new N.UnparsedFrame(P._Uri__Uri(null, "unparsed", null, null), text);
        else
          throw exception;
      }
    },
    Frame: function Frame(t0, t1, t2, t3) {
      var _ = this;
      _.uri = t0;
      _.line = t1;
      _.column = t2;
      _.member = t3;
    },
    Frame_Frame$parseVM_closure: function Frame_Frame$parseVM_closure(t0) {
      this.frame = t0;
    },
    Frame_Frame$parseV8_closure: function Frame_Frame$parseV8_closure(t0) {
      this.frame = t0;
    },
    Frame_Frame$parseV8_closure_parseLocation: function Frame_Frame$parseV8_closure_parseLocation(t0) {
      this.frame = t0;
    },
    Frame_Frame$parseFirefox_closure: function Frame_Frame$parseFirefox_closure(t0) {
      this.frame = t0;
    },
    Frame_Frame$parseFriendly_closure: function Frame_Frame$parseFriendly_closure(t0) {
      this.frame = t0;
    },
    AsciiGlyphSet: function AsciiGlyphSet() {
    }
  },
  N = {UnparsedFrame: function UnparsedFrame(t0, t1) {
      this.uri = t0;
      this.member = t1;
    }, StreamChannelCompleter: function StreamChannelCompleter(t0, t1, t2) {
      var _ = this;
      _._streamCompleter = t0;
      _._sinkCompleter = t1;
      _._stream_channel_completer$_channel = null;
      _._stream_channel_completer$_set = false;
      _.$ti = t2;
    },
    postMessageChannel: function() {
      var t1, t2,
        controller = B.StreamChannelController$(true, true, type$.dynamic);
      new W._EventStream(window, "message", false, type$._EventStream_MessageEvent).firstWhere$1(0, new N.postMessageChannel_closure()).then$1$1(new N.postMessageChannel_closure0(controller), type$.Null);
      t1 = P.LinkedHashMap_LinkedHashMap$_literal(["href", window.location.href, "ready", true], type$.String, type$.Object);
      t1 = P._convertDataTree(t1);
      t2 = window.location;
      self.window.parent.postMessage(t1, (t2 && C.Location_methods).get$origin(t2));
      return controller._foreign;
    },
    postMessageChannel_closure: function postMessageChannel_closure() {
    },
    postMessageChannel_closure0: function postMessageChannel_closure0(t0) {
      this.controller = t0;
    },
    postMessageChannel__closure: function postMessageChannel__closure(t0) {
      this.controller = t0;
    },
    postMessageChannel__closure0: function postMessageChannel__closure0(t0) {
      this.port = t0;
    },
    postMessageChannel__closure1: function postMessageChannel__closure1(t0, t1) {
      this.port = t0;
      this.portSubscription = t1;
    },
    OperatingSystem_find: function(identifier) {
      return C.JSArray_methods.firstWhere$2$orElse(C.List_opx, new N.OperatingSystem_find_closure(identifier), new N.OperatingSystem_find_closure0());
    },
    OperatingSystem: function OperatingSystem(t0, t1) {
      this.name = t0;
      this.identifier = t1;
    },
    OperatingSystem_find_closure: function OperatingSystem_find_closure(t0) {
      this.identifier = t0;
    },
    OperatingSystem_find_closure0: function OperatingSystem_find_closure0() {
    },
    SuiteChannelManager: function SuiteChannelManager(t0, t1, t2) {
      this._incomingConnections = t0;
      this._outgoingConnections = t1;
      this._names = t2;
    }
  },
  K = {
    GuaranteeChannel$: function(innerStream, innerSink, allowSinkErrors, $T) {
      var t2, t1 = {};
      t1.innerStream = innerStream;
      t2 = new K.GuaranteeChannel($T._eval$1("GuaranteeChannel<0>"));
      t2.GuaranteeChannel$3$allowSinkErrors(innerSink, allowSinkErrors, t1, $T);
      return t2;
    },
    GuaranteeChannel: function GuaranteeChannel(t0) {
      var _ = this;
      _._subscription = _._streamController = _._sink = null;
      _._disconnected = false;
      _.$ti = t0;
    },
    GuaranteeChannel_closure: function GuaranteeChannel_closure(t0, t1) {
      this._box_0 = t0;
      this.$this = t1;
    },
    GuaranteeChannel__closure: function GuaranteeChannel__closure(t0) {
      this.$this = t0;
    },
    _GuaranteeSink: function _GuaranteeSink(t0, t1, t2, t3, t4) {
      var _ = this;
      _._inner = t0;
      _._channel = t1;
      _._doneCompleter = t2;
      _._closed = _._disconnected = false;
      _._addStreamCompleter = _._addStreamSubscription = null;
      _._allowErrors = t3;
      _.$ti = t4;
    },
    _GuaranteeSink__addError_closure: function _GuaranteeSink__addError_closure() {
    },
    _GuaranteeSink_addStream_closure: function _GuaranteeSink_addStream_closure(t0) {
      this.$this = t0;
    },
    UnicodeGlyphSet: function UnicodeGlyphSet() {
    },
    ClosedException$: function() {
      return new K.ClosedException();
    },
    ClosedException: function ClosedException() {
    }
  };
  var holders = [C, H, J, P, W, S, O, Y, F, V, E, L, G, T, X, U, R, B, Q, M, D, Z, A, N, K];
  hunkHelpers.setFunctionNamesIfNecessary(holders);
  var $ = {};
  H.JS_CONST.prototype = {};
  J.Interceptor.prototype = {
    $eq: function(receiver, other) {
      return receiver === other;
    },
    get$hashCode: function(receiver) {
      return H.Primitives_objectHashCode(receiver);
    },
    toString$0: function(receiver) {
      return "Instance of '" + H.S(H.Primitives_objectTypeName(receiver)) + "'";
    },
    get$runtimeType: function(receiver) {
      return H.getRuntimeType(receiver);
    }
  };
  J.JSBool.prototype = {
    toString$0: function(receiver) {
      return String(receiver);
    },
    get$hashCode: function(receiver) {
      return receiver ? 519018 : 218159;
    },
    get$runtimeType: function(receiver) {
      return C.Type_bool_lhE;
    },
    $isbool: 1
  };
  J.JSNull.prototype = {
    $eq: function(receiver, other) {
      return null == other;
    },
    toString$0: function(receiver) {
      return "null";
    },
    get$hashCode: function(receiver) {
      return 0;
    },
    get$runtimeType: function(receiver) {
      return C.Type_Null_Yyn;
    },
    $isNull: 1
  };
  J.JSObject.prototype = {};
  J.JavaScriptObject.prototype = {
    get$hashCode: function(receiver) {
      return 0;
    },
    get$runtimeType: function(receiver) {
      return C.Type_JSObject_8k0;
    },
    toString$0: function(receiver) {
      return String(receiver);
    },
    $isJSObject: 1
  };
  J.PlainJavaScriptObject.prototype = {};
  J.UnknownJavaScriptObject.prototype = {};
  J.JavaScriptFunction.prototype = {
    toString$0: function(receiver) {
      var dartClosure = receiver[$.$get$DART_CLOSURE_PROPERTY_NAME()];
      if (dartClosure == null)
        return this.super$JavaScriptObject$toString(receiver);
      return "JavaScript function for " + H.S(J.toString$0$(dartClosure));
    },
    $signature: function() {
      return {func: 1, opt: [,,,,,,,,,,,,,,,,]};
    },
    $isFunction: 1
  };
  J.JSArray.prototype = {
    add$1: function(receiver, value) {
      H._arrayInstanceType(receiver)._precomputed1._check(value);
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("add"));
      receiver.push(value);
    },
    removeAt$1: function(receiver, index) {
      var t1;
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("removeAt"));
      t1 = receiver.length;
      if (index >= t1)
        throw H.wrapException(P.RangeError$value(index, null));
      return receiver.splice(index, 1)[0];
    },
    insert$2: function(receiver, index, value) {
      var t1;
      H._arrayInstanceType(receiver)._precomputed1._check(value);
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("insert"));
      t1 = receiver.length;
      if (index > t1)
        throw H.wrapException(P.RangeError$value(index, null));
      receiver.splice(index, 0, value);
    },
    insertAll$2: function(receiver, index, iterable) {
      var t1, insertionLength, end;
      H._arrayInstanceType(receiver)._eval$1("Iterable<1>")._check(iterable);
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("insertAll"));
      t1 = receiver.length;
      P.RangeError_checkValueInInterval(index, 0, t1, "index");
      insertionLength = iterable.length;
      this.set$length(receiver, t1 + insertionLength);
      end = index + insertionLength;
      this.setRange$4(receiver, end, receiver.length, receiver, index);
      this.setRange$3(receiver, index, end, iterable);
    },
    removeLast$0: function(receiver) {
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("removeLast"));
      if (receiver.length === 0)
        throw H.wrapException(H.diagnoseIndexError(receiver, -1));
      return receiver.pop();
    },
    remove$1: function(receiver, element) {
      var i;
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("remove"));
      for (i = 0; i < receiver.length; ++i)
        if (J.$eq$(receiver[i], element)) {
          receiver.splice(i, 1);
          return true;
        }
      return false;
    },
    addAll$1: function(receiver, collection) {
      var i, t1, e, i0;
      H._arrayInstanceType(receiver)._eval$1("Iterable<1>")._check(collection);
      i = receiver.length;
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("addAll"));
      for (t1 = J.get$iterator$ax(collection); t1.moveNext$0(); i = i0) {
        e = t1.get$current();
        i0 = i + 1;
        H.assertHelper(i === receiver.length || H.throwExpression(P.ConcurrentModificationError$(receiver)));
        receiver.push(e);
      }
    },
    forEach$1: function(receiver, f) {
      var end, i;
      H._arrayInstanceType(receiver)._eval$1("~(1)")._check(f);
      end = receiver.length;
      for (i = 0; i < end; ++i) {
        f.call$1(receiver[i]);
        if (receiver.length !== end)
          throw H.wrapException(P.ConcurrentModificationError$(receiver));
      }
    },
    map$1$1: function(receiver, f, $T) {
      var t1 = H._arrayInstanceType(receiver);
      return new H.MappedListIterable(receiver, t1._bind$1($T)._eval$1("1(2)")._check(f), t1._eval$1("@<1>")._bind$1($T)._eval$1("MappedListIterable<1,2>"));
    },
    join$1: function(receiver, separator) {
      var i,
        list = new Array(receiver.length);
      list.fixed$length = Array;
      for (i = 0; i < receiver.length; ++i)
        this.$indexSet(list, i, H.S(receiver[i]));
      return list.join(separator);
    },
    join$0: function($receiver) {
      return this.join$1($receiver, "");
    },
    fold$1$2: function(receiver, initialValue, combine, $T) {
      var $length, value, i;
      $T._check(initialValue);
      H._arrayInstanceType(receiver)._bind$1($T)._eval$1("1(1,2)")._check(combine);
      $length = receiver.length;
      for (value = initialValue, i = 0; i < $length; ++i) {
        value = combine.call$2(value, receiver[i]);
        if (receiver.length !== $length)
          throw H.wrapException(P.ConcurrentModificationError$(receiver));
      }
      return value;
    },
    firstWhere$2$orElse: function(receiver, test, orElse) {
      var end, i, element,
        t1 = H._arrayInstanceType(receiver);
      t1._eval$1("bool(1)")._check(test);
      t1._eval$1("1()")._check(orElse);
      end = receiver.length;
      for (i = 0; i < end; ++i) {
        element = receiver[i];
        if (H.boolConversionCheck(test.call$1(element)))
          return element;
        if (receiver.length !== end)
          throw H.wrapException(P.ConcurrentModificationError$(receiver));
      }
      if (orElse != null)
        return orElse.call$0();
      throw H.wrapException(H.IterableElementError_noElement());
    },
    firstWhere$1: function($receiver, test) {
      return this.firstWhere$2$orElse($receiver, test, null);
    },
    elementAt$1: function(receiver, index) {
      if (index < 0 || index >= receiver.length)
        return H.ioore(receiver, index);
      return receiver[index];
    },
    sublist$2: function(receiver, start, end) {
      if (start < 0 || start > receiver.length)
        throw H.wrapException(P.RangeError$range(start, 0, receiver.length, "start", null));
      if (end < start || end > receiver.length)
        throw H.wrapException(P.RangeError$range(end, start, receiver.length, "end", null));
      if (start === end)
        return H.setRuntimeTypeInfo([], H._arrayInstanceType(receiver));
      return H.setRuntimeTypeInfo(receiver.slice(start, end), H._arrayInstanceType(receiver));
    },
    get$first: function(receiver) {
      if (receiver.length > 0)
        return receiver[0];
      throw H.wrapException(H.IterableElementError_noElement());
    },
    get$last: function(receiver) {
      var t1 = receiver.length;
      if (t1 > 0)
        return receiver[t1 - 1];
      throw H.wrapException(H.IterableElementError_noElement());
    },
    get$single: function(receiver) {
      var t1 = receiver.length;
      if (t1 === 1) {
        if (0 >= t1)
          return H.ioore(receiver, 0);
        return receiver[0];
      }
      if (t1 === 0)
        throw H.wrapException(H.IterableElementError_noElement());
      throw H.wrapException(H.IterableElementError_tooMany());
    },
    setRange$4: function(receiver, start, end, iterable, skipCount) {
      var $length, i,
        t1 = H._arrayInstanceType(receiver);
      t1._eval$1("Iterable<1>")._check(iterable);
      if (!!receiver.immutable$list)
        H.throwExpression(P.UnsupportedError$("setRange"));
      P.RangeError_checkValidRange(start, end, receiver.length);
      $length = end - start;
      if ($length === 0)
        return;
      P.RangeError_checkNotNegative(skipCount, "skipCount");
      t1._eval$1("List<1>")._check(iterable);
      t1 = J.getInterceptor$asx(iterable);
      if (skipCount + $length > t1.get$length(iterable))
        throw H.wrapException(H.IterableElementError_tooFew());
      if (skipCount < start)
        for (i = $length - 1; i >= 0; --i)
          receiver[start + i] = t1.$index(iterable, skipCount + i);
      else
        for (i = 0; i < $length; ++i)
          receiver[start + i] = t1.$index(iterable, skipCount + i);
    },
    setRange$3: function($receiver, start, end, iterable) {
      return this.setRange$4($receiver, start, end, iterable, 0);
    },
    fillRange$3: function(receiver, start, end, fillValue) {
      var i;
      H._arrayInstanceType(receiver)._precomputed1._check(fillValue);
      if (!!receiver.immutable$list)
        H.throwExpression(P.UnsupportedError$("fill range"));
      P.RangeError_checkValidRange(start, end, receiver.length);
      for (i = start; i < end; ++i)
        receiver[i] = fillValue;
    },
    replaceRange$3: function(receiver, start, end, replacement) {
      var t1, removeLength, insertEnd, delta, newLength, _this = this;
      H._arrayInstanceType(receiver)._eval$1("Iterable<1>")._check(replacement);
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("replaceRange"));
      t1 = receiver.length;
      P.RangeError_checkValidRange(start, end, t1);
      removeLength = end - start;
      insertEnd = start + 1;
      if (removeLength >= 1) {
        delta = removeLength - 1;
        newLength = t1 - delta;
        _this.setRange$3(receiver, start, insertEnd, replacement);
        if (delta !== 0) {
          _this.setRange$4(receiver, insertEnd, newLength, receiver, end);
          _this.set$length(receiver, newLength);
        }
      } else {
        newLength = t1 + (1 - removeLength);
        _this.set$length(receiver, newLength);
        _this.setRange$4(receiver, insertEnd, newLength, receiver, end);
        _this.setRange$3(receiver, start, insertEnd, replacement);
      }
    },
    contains$1: function(receiver, other) {
      var i;
      for (i = 0; i < receiver.length; ++i)
        if (J.$eq$(receiver[i], other))
          return true;
      return false;
    },
    get$isEmpty: function(receiver) {
      return receiver.length === 0;
    },
    toString$0: function(receiver) {
      return P.IterableBase_iterableToFullString(receiver, "[", "]");
    },
    toSet$0: function(receiver) {
      return P.LinkedHashSet_LinkedHashSet$from(receiver, H._arrayInstanceType(receiver)._precomputed1);
    },
    get$iterator: function(receiver) {
      return new J.ArrayIterator(receiver, receiver.length, H._arrayInstanceType(receiver)._eval$1("ArrayIterator<1>"));
    },
    get$hashCode: function(receiver) {
      return H.Primitives_objectHashCode(receiver);
    },
    get$length: function(receiver) {
      return receiver.length;
    },
    set$length: function(receiver, newLength) {
      var _s9_ = "newLength";
      if (!!receiver.fixed$length)
        H.throwExpression(P.UnsupportedError$("set length"));
      if (!H._isInt(newLength))
        throw H.wrapException(P.ArgumentError$value(newLength, _s9_, null));
      if (newLength < 0)
        throw H.wrapException(P.RangeError$range(newLength, 0, null, _s9_, null));
      receiver.length = newLength;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      if (!H._isInt(index))
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      if (index >= receiver.length || index < 0)
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      return receiver[index];
    },
    $indexSet: function(receiver, index, value) {
      H._checkIntNullable(index);
      H._arrayInstanceType(receiver)._precomputed1._check(value);
      if (!!receiver.immutable$list)
        H.throwExpression(P.UnsupportedError$("indexed set"));
      if (!H._isInt(index))
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      if (index >= receiver.length || index < 0)
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      receiver[index] = value;
    },
    $isEfficientLengthIterable: 1,
    $isIterable: 1,
    $isList: 1
  };
  J.JSUnmodifiableArray.prototype = {};
  J.ArrayIterator.prototype = {
    get$current: function() {
      return this._current;
    },
    moveNext$0: function() {
      var t2, _this = this,
        t1 = _this._iterable,
        $length = t1.length;
      if (_this._length !== $length)
        throw H.wrapException(H.throwConcurrentModificationError(t1));
      t2 = _this._index;
      if (t2 >= $length) {
        _this.set$_current(null);
        return false;
      }
      _this.set$_current(t1[t2]);
      ++_this._index;
      return true;
    },
    set$_current: function(_current) {
      this._current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  J.JSNumber.prototype = {
    floor$0: function(receiver) {
      var truncated, d;
      if (receiver >= 0) {
        if (receiver <= 2147483647)
          return receiver | 0;
      } else if (receiver >= -2147483648) {
        truncated = receiver | 0;
        return receiver === truncated ? truncated : truncated - 1;
      }
      d = Math.floor(receiver);
      if (isFinite(d))
        return d;
      throw H.wrapException(P.UnsupportedError$("" + receiver + ".floor()"));
    },
    round$0: function(receiver) {
      if (receiver > 0) {
        if (receiver !== 1 / 0)
          return Math.round(receiver);
      } else if (receiver > -1 / 0)
        return 0 - Math.round(0 - receiver);
      throw H.wrapException(P.UnsupportedError$("" + receiver + ".round()"));
    },
    toRadixString$1: function(receiver, radix) {
      var result, match, t1, exponent;
      if (radix < 2 || radix > 36)
        throw H.wrapException(P.RangeError$range(radix, 2, 36, "radix", null));
      result = receiver.toString(radix);
      if (C.JSString_methods.codeUnitAt$1(result, result.length - 1) !== 41)
        return result;
      match = /^([\da-z]+)(?:\.([\da-z]+))?\(e\+(\d+)\)$/.exec(result);
      if (match == null)
        H.throwExpression(P.UnsupportedError$("Unexpected toString result: " + result));
      t1 = match.length;
      if (1 >= t1)
        return H.ioore(match, 1);
      result = match[1];
      if (3 >= t1)
        return H.ioore(match, 3);
      exponent = +match[3];
      t1 = match[2];
      if (t1 != null) {
        result += t1;
        exponent -= t1.length;
      }
      return result + C.JSString_methods.$mul("0", exponent);
    },
    toString$0: function(receiver) {
      if (receiver === 0 && 1 / receiver < 0)
        return "-0.0";
      else
        return "" + receiver;
    },
    get$hashCode: function(receiver) {
      var absolute, floorLog2, factor, scaled,
        intValue = receiver | 0;
      if (receiver === intValue)
        return 536870911 & intValue;
      absolute = Math.abs(receiver);
      floorLog2 = Math.log(absolute) / 0.6931471805599453 | 0;
      factor = Math.pow(2, floorLog2);
      scaled = absolute < 1 ? absolute / factor : factor / absolute;
      return 536870911 & ((scaled * 9007199254740992 | 0) + (scaled * 3542243181176521 | 0)) * 599197 + floorLog2 * 1259;
    },
    $mod: function(receiver, other) {
      var result = receiver % other;
      if (result === 0)
        return 0;
      if (result > 0)
        return result;
      if (other < 0)
        return result - other;
      else
        return result + other;
    },
    $tdiv: function(receiver, other) {
      if ((receiver | 0) === receiver)
        if (other >= 1 || other < -1)
          return receiver / other | 0;
      return this._tdivSlow$1(receiver, other);
    },
    _tdivFast$1: function(receiver, other) {
      return (receiver | 0) === receiver ? receiver / other | 0 : this._tdivSlow$1(receiver, other);
    },
    _tdivSlow$1: function(receiver, other) {
      var quotient = receiver / other;
      if (quotient >= -2147483648 && quotient <= 2147483647)
        return quotient | 0;
      if (quotient > 0) {
        if (quotient !== 1 / 0)
          return Math.floor(quotient);
      } else if (quotient > -1 / 0)
        return Math.ceil(quotient);
      throw H.wrapException(P.UnsupportedError$("Result of truncating division is " + H.S(quotient) + ": " + H.S(receiver) + " ~/ " + other));
    },
    _shlPositive$1: function(receiver, other) {
      return other > 31 ? 0 : receiver << other >>> 0;
    },
    _shrOtherPositive$1: function(receiver, other) {
      var t1;
      if (receiver > 0)
        t1 = this._shrBothPositive$1(receiver, other);
      else {
        t1 = other > 31 ? 31 : other;
        t1 = receiver >> t1 >>> 0;
      }
      return t1;
    },
    _shrReceiverPositive$1: function(receiver, other) {
      if (other < 0)
        throw H.wrapException(H.argumentErrorValue(other));
      return this._shrBothPositive$1(receiver, other);
    },
    _shrBothPositive$1: function(receiver, other) {
      return other > 31 ? 0 : receiver >>> other;
    },
    get$runtimeType: function(receiver) {
      return C.Type_num_cv7;
    },
    $isdouble: 1,
    $isnum: 1
  };
  J.JSInt.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_int_tHn;
    },
    $isint: 1
  };
  J.JSDouble.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_double_K1J;
    }
  };
  J.JSString.prototype = {
    codeUnitAt$1: function(receiver, index) {
      if (index < 0)
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      if (index >= receiver.length)
        H.throwExpression(H.diagnoseIndexError(receiver, index));
      return receiver.charCodeAt(index);
    },
    _codeUnitAt$1: function(receiver, index) {
      if (index >= receiver.length)
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      return receiver.charCodeAt(index);
    },
    allMatches$2: function(receiver, string, start) {
      var t1;
      if (typeof string != "string")
        H.throwExpression(H.argumentErrorValue(string));
      t1 = string.length;
      if (start > t1)
        throw H.wrapException(P.RangeError$range(start, 0, t1, null, null));
      return new H._StringAllMatchesIterable(string, receiver, start);
    },
    allMatches$1: function($receiver, string) {
      return this.allMatches$2($receiver, string, 0);
    },
    matchAsPrefix$2: function(receiver, string, start) {
      var t1, t2, i, _null = null;
      if (start < 0 || start > string.length)
        throw H.wrapException(P.RangeError$range(start, 0, string.length, _null, _null));
      t1 = receiver.length;
      if (start + t1 > string.length)
        return _null;
      for (t2 = J.getInterceptor$s(string), i = 0; i < t1; ++i)
        if (t2.codeUnitAt$1(string, start + i) !== this._codeUnitAt$1(receiver, i))
          return _null;
      return new H.StringMatch(start, receiver);
    },
    $add: function(receiver, other) {
      if (typeof other != "string")
        throw H.wrapException(P.ArgumentError$value(other, null, null));
      return receiver + other;
    },
    endsWith$1: function(receiver, other) {
      var otherLength = other.length,
        t1 = receiver.length;
      if (otherLength > t1)
        return false;
      return other === this.substring$1(receiver, t1 - otherLength);
    },
    splitMapJoin$2$onMatch: function(receiver, from, onMatch) {
      return H.stringReplaceAllFuncUnchecked(receiver, from, type$.String_Function_Match._check(onMatch), type$.String_Function_String._check(null));
    },
    replaceFirst$2: function(receiver, from, to) {
      P.RangeError_checkValueInInterval(0, 0, receiver.length, "startIndex");
      return H.stringReplaceFirstUnchecked(receiver, from, to, 0);
    },
    replaceRange$3: function(receiver, start, end, replacement) {
      end = P.RangeError_checkValidRange(start, end, receiver.length);
      return H.stringReplaceRangeUnchecked(receiver, start, end, replacement);
    },
    startsWith$2: function(receiver, pattern, index) {
      var endIndex;
      type$.Pattern._check(pattern);
      if (index < 0 || index > receiver.length)
        throw H.wrapException(P.RangeError$range(index, 0, receiver.length, null, null));
      if (typeof pattern == "string") {
        endIndex = index + pattern.length;
        if (endIndex > receiver.length)
          return false;
        return pattern === receiver.substring(index, endIndex);
      }
      return J.matchAsPrefix$2$s(pattern, receiver, index) != null;
    },
    startsWith$1: function($receiver, pattern) {
      return this.startsWith$2($receiver, pattern, 0);
    },
    substring$2: function(receiver, startIndex, endIndex) {
      if (endIndex == null)
        endIndex = receiver.length;
      if (startIndex < 0)
        throw H.wrapException(P.RangeError$value(startIndex, null));
      if (startIndex > endIndex)
        throw H.wrapException(P.RangeError$value(startIndex, null));
      if (endIndex > receiver.length)
        throw H.wrapException(P.RangeError$value(endIndex, null));
      return receiver.substring(startIndex, endIndex);
    },
    substring$1: function($receiver, startIndex) {
      return this.substring$2($receiver, startIndex, null);
    },
    trim$0: function(receiver) {
      var startIndex, t1, endIndex0,
        result = receiver.trim(),
        endIndex = result.length;
      if (endIndex === 0)
        return result;
      if (this._codeUnitAt$1(result, 0) === 133) {
        startIndex = J.JSString__skipLeadingWhitespace(result, 1);
        if (startIndex === endIndex)
          return "";
      } else
        startIndex = 0;
      t1 = endIndex - 1;
      endIndex0 = this.codeUnitAt$1(result, t1) === 133 ? J.JSString__skipTrailingWhitespace(result, t1) : endIndex;
      if (startIndex === 0 && endIndex0 === endIndex)
        return result;
      return result.substring(startIndex, endIndex0);
    },
    $mul: function(receiver, times) {
      var s, result;
      if (0 >= times)
        return "";
      if (times === 1 || receiver.length === 0)
        return receiver;
      if (times !== times >>> 0)
        throw H.wrapException(C.C_OutOfMemoryError);
      for (s = receiver, result = ""; true;) {
        if ((times & 1) === 1)
          result = s + result;
        times = times >>> 1;
        if (times === 0)
          break;
        s += s;
      }
      return result;
    },
    padLeft$2: function(receiver, width, padding) {
      var delta = width - receiver.length;
      if (delta <= 0)
        return receiver;
      return this.$mul(padding, delta) + receiver;
    },
    padRight$1: function(receiver, width) {
      var delta;
      if (typeof width !== "number")
        return width.$sub();
      delta = width - receiver.length;
      if (delta <= 0)
        return receiver;
      return receiver + this.$mul(" ", delta);
    },
    indexOf$2: function(receiver, pattern, start) {
      var t1;
      if (start < 0 || start > receiver.length)
        throw H.wrapException(P.RangeError$range(start, 0, receiver.length, null, null));
      t1 = receiver.indexOf(pattern, start);
      return t1;
    },
    indexOf$1: function($receiver, pattern) {
      return this.indexOf$2($receiver, pattern, 0);
    },
    lastIndexOf$2: function(receiver, pattern, start) {
      var t1, t2;
      if (start == null)
        start = receiver.length;
      else if (start < 0 || start > receiver.length)
        throw H.wrapException(P.RangeError$range(start, 0, receiver.length, null, null));
      t1 = pattern.length;
      t2 = receiver.length;
      if (start + t1 > t2)
        start = t2 - t1;
      return receiver.lastIndexOf(pattern, start);
    },
    lastIndexOf$1: function($receiver, pattern) {
      return this.lastIndexOf$2($receiver, pattern, null);
    },
    contains$1: function(receiver, other) {
      if (other == null)
        H.throwExpression(H.argumentErrorValue(other));
      return H.stringContainsUnchecked(receiver, other, 0);
    },
    toString$0: function(receiver) {
      return receiver;
    },
    get$hashCode: function(receiver) {
      var t1, hash, i;
      for (t1 = receiver.length, hash = 0, i = 0; i < t1; ++i) {
        hash = 536870911 & hash + receiver.charCodeAt(i);
        hash = 536870911 & hash + ((524287 & hash) << 10);
        hash ^= hash >> 6;
      }
      hash = 536870911 & hash + ((67108863 & hash) << 3);
      hash ^= hash >> 11;
      return 536870911 & hash + ((16383 & hash) << 15);
    },
    get$runtimeType: function(receiver) {
      return C.Type_String_k8F;
    },
    get$length: function(receiver) {
      return receiver.length;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      if (index >= receiver.length || index < 0)
        throw H.wrapException(H.diagnoseIndexError(receiver, index));
      return receiver[index];
    },
    $isPattern: 1,
    $isString: 1
  };
  H._CastIterableBase.prototype = {
    get$iterator: function(_) {
      var t1 = this._source,
        t2 = H._instanceType(this);
      return new H.CastIterator(t1.get$iterator(t1), t2._eval$1("@<1>")._bind$1(t2._rest[1])._eval$1("CastIterator<1,2>"));
    },
    get$length: function(_) {
      var t1 = this._source;
      return t1.get$length(t1);
    },
    get$isEmpty: function(_) {
      var t1 = this._source;
      return t1.get$isEmpty(t1);
    },
    get$first: function(_) {
      var t1 = this._source;
      return H._instanceType(this)._rest[1]._as(t1.get$first(t1));
    },
    get$last: function(_) {
      var t1 = this._source;
      return H._instanceType(this)._rest[1]._as(t1.get$last(t1));
    },
    contains$1: function(_, other) {
      return this._source.contains$1(0, other);
    },
    toString$0: function(_) {
      return this._source.toString$0(0);
    }
  };
  H.CastIterator.prototype = {
    moveNext$0: function() {
      return this._source.moveNext$0();
    },
    get$current: function() {
      return this.$ti._rest[1]._as(this._source.get$current());
    },
    $isIterator: 1
  };
  H.CastIterable.prototype = {};
  H._EfficientLengthCastIterable.prototype = {$isEfficientLengthIterable: 1};
  H.CastMap.prototype = {
    cast$2$0: function(_, RK, RV) {
      var t1 = this.$ti;
      return new H.CastMap(this._source, t1._eval$1("@<1>")._bind$1(t1._rest[1])._bind$1(RK)._bind$1(RV)._eval$1("CastMap<1,2,3,4>"));
    },
    containsKey$1: function(key) {
      return this._source.containsKey$1(key);
    },
    $index: function(_, key) {
      return this.$ti._rest[3]._as(this._source.$index(0, key));
    },
    remove$1: function(_, key) {
      return this.$ti._rest[3]._as(this._source.remove$1(0, key));
    },
    forEach$1: function(_, f) {
      this._source.forEach$1(0, new H.CastMap_forEach_closure(this, this.$ti._eval$1("~(3,4)")._check(f)));
    },
    get$keys: function() {
      var t1 = this.$ti;
      return H.CastIterable_CastIterable(this._source.get$keys(), t1._precomputed1, t1._rest[2]);
    },
    get$length: function(_) {
      var t1 = this._source;
      return t1.get$length(t1);
    },
    get$isEmpty: function(_) {
      var t1 = this._source;
      return t1.get$isEmpty(t1);
    }
  };
  H.CastMap_forEach_closure.prototype = {
    call$2: function(key, value) {
      var t1 = this.$this.$ti;
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      this.f.call$2(t1._rest[2]._as(key), t1._rest[3]._as(value));
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(1,2)");
    }
  };
  H.CodeUnits.prototype = {
    get$length: function(_) {
      return this._string.length;
    },
    $index: function(_, i) {
      return C.JSString_methods.codeUnitAt$1(this._string, H._checkIntNullable(i));
    }
  };
  H.EfficientLengthIterable.prototype = {};
  H.ListIterable.prototype = {
    get$iterator: function(_) {
      var _this = this;
      return new H.ListIterator(_this, _this.get$length(_this), H._instanceType(_this)._eval$1("ListIterator<ListIterable.E>"));
    },
    get$isEmpty: function(_) {
      return this.get$length(this) === 0;
    },
    get$first: function(_) {
      if (this.get$length(this) === 0)
        throw H.wrapException(H.IterableElementError_noElement());
      return this.elementAt$1(0, 0);
    },
    get$last: function(_) {
      var _this = this;
      if (_this.get$length(_this) === 0)
        throw H.wrapException(H.IterableElementError_noElement());
      return _this.elementAt$1(0, _this.get$length(_this) - 1);
    },
    contains$1: function(_, element) {
      var i, _this = this,
        $length = _this.get$length(_this);
      for (i = 0; i < $length; ++i) {
        if (J.$eq$(_this.elementAt$1(0, i), element))
          return true;
        if ($length !== _this.get$length(_this))
          throw H.wrapException(P.ConcurrentModificationError$(_this));
      }
      return false;
    },
    join$1: function(_, separator) {
      var first, t1, i, _this = this,
        $length = _this.get$length(_this);
      if (separator.length !== 0) {
        if ($length === 0)
          return "";
        first = H.S(_this.elementAt$1(0, 0));
        if ($length !== _this.get$length(_this))
          throw H.wrapException(P.ConcurrentModificationError$(_this));
        for (t1 = first, i = 1; i < $length; ++i) {
          t1 = t1 + separator + H.S(_this.elementAt$1(0, i));
          if ($length !== _this.get$length(_this))
            throw H.wrapException(P.ConcurrentModificationError$(_this));
        }
        return t1.charCodeAt(0) == 0 ? t1 : t1;
      } else {
        for (i = 0, t1 = ""; i < $length; ++i) {
          t1 += H.S(_this.elementAt$1(0, i));
          if ($length !== _this.get$length(_this))
            throw H.wrapException(P.ConcurrentModificationError$(_this));
        }
        return t1.charCodeAt(0) == 0 ? t1 : t1;
      }
    },
    join$0: function($receiver) {
      return this.join$1($receiver, "");
    },
    map$1$1: function(_, f, $T) {
      var t1 = H._instanceType(this);
      return new H.MappedListIterable(this, t1._bind$1($T)._eval$1("1(ListIterable.E)")._check(f), t1._eval$1("@<ListIterable.E>")._bind$1($T)._eval$1("MappedListIterable<1,2>"));
    },
    fold$1$2: function(_, initialValue, combine, $T) {
      var $length, value, i, _this = this;
      $T._check(initialValue);
      H._instanceType(_this)._bind$1($T)._eval$1("1(1,ListIterable.E)")._check(combine);
      $length = _this.get$length(_this);
      for (value = initialValue, i = 0; i < $length; ++i) {
        value = combine.call$2(value, _this.elementAt$1(0, i));
        if ($length !== _this.get$length(_this))
          throw H.wrapException(P.ConcurrentModificationError$(_this));
      }
      return value;
    },
    toList$1$growable: function(_, growable) {
      var i, _this = this,
        result = H.setRuntimeTypeInfo([], H._instanceType(_this)._eval$1("JSArray<ListIterable.E>"));
      C.JSArray_methods.set$length(result, _this.get$length(_this));
      for (i = 0; i < _this.get$length(_this); ++i)
        C.JSArray_methods.$indexSet(result, i, _this.elementAt$1(0, i));
      return result;
    },
    toList$0: function($receiver) {
      return this.toList$1$growable($receiver, true);
    },
    toSet$0: function(_) {
      var i, _this = this,
        result = P.LinkedHashSet_LinkedHashSet(H._instanceType(_this)._eval$1("ListIterable.E"));
      for (i = 0; i < _this.get$length(_this); ++i)
        result.add$1(0, _this.elementAt$1(0, i));
      return result;
    }
  };
  H.SubListIterable.prototype = {
    get$_endIndex: function() {
      var $length = J.get$length$asx(this.__internal$_iterable),
        t1 = this._endOrLength;
      if (t1 == null || t1 > $length)
        return $length;
      return t1;
    },
    get$_startIndex: function() {
      var $length = J.get$length$asx(this.__internal$_iterable),
        t1 = this.__internal$_start;
      if (t1 > $length)
        return $length;
      return t1;
    },
    get$length: function(_) {
      var t2,
        $length = J.get$length$asx(this.__internal$_iterable),
        t1 = this.__internal$_start;
      if (t1 >= $length)
        return 0;
      t2 = this._endOrLength;
      if (t2 == null || t2 >= $length)
        return $length - t1;
      if (typeof t2 !== "number")
        return t2.$sub();
      return t2 - t1;
    },
    elementAt$1: function(_, index) {
      var t1, _this = this,
        realIndex = _this.get$_startIndex() + index;
      if (index >= 0) {
        t1 = _this.get$_endIndex();
        if (typeof t1 !== "number")
          return H.iae(t1);
        t1 = realIndex >= t1;
      } else
        t1 = true;
      if (t1)
        throw H.wrapException(P.IndexError$(index, _this, "index", null, null));
      return J.elementAt$1$ax(_this.__internal$_iterable, realIndex);
    },
    take$1: function(_, count) {
      var t1, t2, newEnd, _this = this;
      P.RangeError_checkNotNegative(count, "count");
      t1 = _this._endOrLength;
      t2 = _this.__internal$_start;
      newEnd = t2 + count;
      if (t1 == null)
        return H.SubListIterable$(_this.__internal$_iterable, t2, newEnd, _this.$ti._precomputed1);
      else {
        if (t1 < newEnd)
          return _this;
        return H.SubListIterable$(_this.__internal$_iterable, t2, newEnd, _this.$ti._precomputed1);
      }
    }
  };
  H.ListIterator.prototype = {
    get$current: function() {
      return this.__internal$_current;
    },
    moveNext$0: function() {
      var t3, _this = this,
        t1 = _this.__internal$_iterable,
        t2 = J.getInterceptor$asx(t1),
        $length = t2.get$length(t1);
      if (_this.__internal$_length !== $length)
        throw H.wrapException(P.ConcurrentModificationError$(t1));
      t3 = _this.__internal$_index;
      if (t3 >= $length) {
        _this.set$__internal$_current(null);
        return false;
      }
      _this.set$__internal$_current(t2.elementAt$1(t1, t3));
      ++_this.__internal$_index;
      return true;
    },
    set$__internal$_current: function(_current) {
      this.__internal$_current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  H.MappedIterable.prototype = {
    get$iterator: function(_) {
      var t1 = H._instanceType(this);
      return new H.MappedIterator(J.get$iterator$ax(this.__internal$_iterable), this._f, t1._eval$1("@<1>")._bind$1(t1._rest[1])._eval$1("MappedIterator<1,2>"));
    },
    get$length: function(_) {
      return J.get$length$asx(this.__internal$_iterable);
    },
    get$isEmpty: function(_) {
      return J.get$isEmpty$asx(this.__internal$_iterable);
    },
    get$first: function(_) {
      return this._f.call$1(J.get$first$ax(this.__internal$_iterable));
    },
    get$last: function(_) {
      return this._f.call$1(J.get$last$ax(this.__internal$_iterable));
    }
  };
  H.EfficientLengthMappedIterable.prototype = {$isEfficientLengthIterable: 1};
  H.MappedIterator.prototype = {
    moveNext$0: function() {
      var _this = this,
        t1 = _this._iterator;
      if (t1.moveNext$0()) {
        _this.set$__internal$_current(_this._f.call$1(t1.get$current()));
        return true;
      }
      _this.set$__internal$_current(null);
      return false;
    },
    get$current: function() {
      return this.__internal$_current;
    },
    set$__internal$_current: function(_current) {
      this.__internal$_current = this.$ti._rest[1]._check(_current);
    }
  };
  H.MappedListIterable.prototype = {
    get$length: function(_) {
      return J.get$length$asx(this._source);
    },
    elementAt$1: function(_, index) {
      return this._f.call$1(J.elementAt$1$ax(this._source, index));
    }
  };
  H.WhereIterable.prototype = {
    get$iterator: function(_) {
      return new H.WhereIterator(J.get$iterator$ax(this.__internal$_iterable), this._f, this.$ti._eval$1("WhereIterator<1>"));
    },
    map$1$1: function(_, f, $T) {
      var t1 = this.$ti;
      return new H.MappedIterable(this, t1._bind$1($T)._eval$1("1(2)")._check(f), t1._eval$1("@<1>")._bind$1($T)._eval$1("MappedIterable<1,2>"));
    }
  };
  H.WhereIterator.prototype = {
    moveNext$0: function() {
      var t1, t2;
      for (t1 = this._iterator, t2 = this._f; t1.moveNext$0();)
        if (H.boolConversionCheck(t2.call$1(t1.get$current())))
          return true;
      return false;
    },
    get$current: function() {
      return this._iterator.get$current();
    }
  };
  H.ExpandIterable.prototype = {
    get$iterator: function(_) {
      var t1 = this.$ti;
      return new H.ExpandIterator(J.get$iterator$ax(this.__internal$_iterable), this._f, C.C_EmptyIterator, t1._eval$1("@<1>")._bind$1(t1._rest[1])._eval$1("ExpandIterator<1,2>"));
    }
  };
  H.ExpandIterator.prototype = {
    get$current: function() {
      return this.__internal$_current;
    },
    moveNext$0: function() {
      var t1, t2, _this = this;
      if (_this._currentExpansion == null)
        return false;
      for (t1 = _this._iterator, t2 = _this._f; !_this._currentExpansion.moveNext$0();) {
        _this.set$__internal$_current(null);
        if (t1.moveNext$0()) {
          _this.set$_currentExpansion(null);
          _this.set$_currentExpansion(J.get$iterator$ax(t2.call$1(t1.get$current())));
        } else
          return false;
      }
      _this.set$__internal$_current(_this._currentExpansion.get$current());
      return true;
    },
    set$_currentExpansion: function(_currentExpansion) {
      this._currentExpansion = this.$ti._eval$1("Iterator<2>")._check(_currentExpansion);
    },
    set$__internal$_current: function(_current) {
      this.__internal$_current = this.$ti._rest[1]._check(_current);
    },
    $isIterator: 1
  };
  H.SkipWhileIterable.prototype = {
    get$iterator: function(_) {
      return new H.SkipWhileIterator(J.get$iterator$ax(this.__internal$_iterable), this._f, this.$ti._eval$1("SkipWhileIterator<1>"));
    }
  };
  H.SkipWhileIterator.prototype = {
    moveNext$0: function() {
      var t1, t2, _this = this;
      if (!_this._hasSkipped) {
        _this._hasSkipped = true;
        for (t1 = _this._iterator, t2 = _this._f; t1.moveNext$0();)
          if (!H.boolConversionCheck(t2.call$1(t1.get$current())))
            return true;
      }
      return _this._iterator.moveNext$0();
    },
    get$current: function() {
      return this._iterator.get$current();
    }
  };
  H.EmptyIterator.prototype = {
    moveNext$0: function() {
      return false;
    },
    get$current: function() {
      return null;
    },
    $isIterator: 1
  };
  H.FixedLengthListMixin.prototype = {
    set$length: function(receiver, newLength) {
      throw H.wrapException(P.UnsupportedError$("Cannot change the length of a fixed-length list"));
    }
  };
  H.UnmodifiableListMixin.prototype = {
    $indexSet: function(_, index, value) {
      H._checkIntNullable(index);
      H._instanceType(this)._eval$1("UnmodifiableListMixin.E")._check(value);
      throw H.wrapException(P.UnsupportedError$("Cannot modify an unmodifiable list"));
    },
    set$length: function(_, newLength) {
      throw H.wrapException(P.UnsupportedError$("Cannot change the length of an unmodifiable list"));
    }
  };
  H.UnmodifiableListBase.prototype = {};
  H.ReversedListIterable.prototype = {
    get$length: function(_) {
      return J.get$length$asx(this._source);
    },
    elementAt$1: function(_, index) {
      var t1 = this._source,
        t2 = J.getInterceptor$asx(t1);
      return t2.elementAt$1(t1, t2.get$length(t1) - 1 - index);
    }
  };
  H.Symbol.prototype = {
    get$hashCode: function(_) {
      var hash = this._hashCode;
      if (hash != null)
        return hash;
      hash = 536870911 & 664597 * J.get$hashCode$(this.__internal$_name);
      this._hashCode = hash;
      return hash;
    },
    toString$0: function(_) {
      return 'Symbol("' + H.S(this.__internal$_name) + '")';
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof H.Symbol && this.__internal$_name == other.__internal$_name;
    }
  };
  H.ConstantMap.prototype = {
    cast$2$0: function(_, RK, RV) {
      var t1 = H._instanceType(this);
      return P.Map_castFrom(this, t1._precomputed1, t1._rest[1], RK, RV);
    },
    get$isEmpty: function(_) {
      return this.get$length(this) === 0;
    },
    toString$0: function(_) {
      return P.MapBase_mapToString(this);
    },
    remove$1: function(_, key) {
      return H.ConstantMap__throwUnmodifiable();
    },
    map$2$1: function(_, transform, K2, V2) {
      var result = P.LinkedHashMap_LinkedHashMap$_empty(K2, V2);
      this.forEach$1(0, new H.ConstantMap_map_closure(this, H._instanceType(this)._bind$1(K2)._bind$1(V2)._eval$1("MapEntry<1,2>(3,4)")._check(transform), result));
      return result;
    },
    $isMap: 1
  };
  H.ConstantMap_map_closure.prototype = {
    call$2: function(key, value) {
      var t1 = H._instanceType(this.$this),
        entry = this.transform.call$2(t1._precomputed1._check(key), t1._rest[1]._check(value));
      this.result.$indexSet(0, entry.key, entry.value);
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(1,2)");
    }
  };
  H.ConstantStringMap.prototype = {
    get$length: function(_) {
      return this.__js_helper$_length;
    },
    containsKey$1: function(key) {
      if (typeof key != "string")
        return false;
      if ("__proto__" === key)
        return false;
      return this._jsObject.hasOwnProperty(key);
    },
    $index: function(_, key) {
      if (!this.containsKey$1(key))
        return null;
      return this._fetch$1(key);
    },
    _fetch$1: function(key) {
      return this._jsObject[H._checkStringNullable(key)];
    },
    forEach$1: function(_, f) {
      var keys, t2, i, key,
        t1 = H._instanceType(this);
      t1._eval$1("~(1,2)")._check(f);
      keys = this.__js_helper$_keys;
      for (t2 = keys.length, t1 = t1._rest[1], i = 0; i < t2; ++i) {
        key = keys[i];
        f.call$2(key, t1._check(this._fetch$1(key)));
      }
    },
    get$keys: function() {
      return new H._ConstantMapKeyIterable(this, H._instanceType(this)._eval$1("_ConstantMapKeyIterable<1>"));
    }
  };
  H._ConstantMapKeyIterable.prototype = {
    get$iterator: function(_) {
      var t1 = this.__js_helper$_map.__js_helper$_keys;
      return new J.ArrayIterator(t1, t1.length, H._arrayInstanceType(t1)._eval$1("ArrayIterator<1>"));
    },
    get$length: function(_) {
      return this.__js_helper$_map.__js_helper$_keys.length;
    }
  };
  H.Instantiation.prototype = {
    Instantiation$1: function(_genericClosure) {
      if (false)
        H.instantiatedGenericFunctionType(0, 0);
    },
    toString$0: function(_) {
      var types = "<" + C.JSArray_methods.join$1([H.createRuntimeType(this.$ti._precomputed1)], ", ") + ">";
      return H.S(this._genericClosure) + " with " + types;
    }
  };
  H.Instantiation1.prototype = {
    call$2: function(a0, a1) {
      return this._genericClosure.call$1$2(a0, a1, this.$ti._rest[0]);
    },
    call$4: function(a0, a1, a2, a3) {
      return this._genericClosure.call$1$4(a0, a1, a2, a3, this.$ti._rest[0]);
    },
    $signature: function() {
      return H.instantiatedGenericFunctionType(H.closureFunctionType(this._genericClosure), this.$ti);
    }
  };
  H.Primitives_initTicker_closure.prototype = {
    call$0: function() {
      return C.JSNumber_methods.floor$0(1000 * this.performance.now());
    },
    $signature: 36
  };
  H.TypeErrorDecoder.prototype = {
    matchTypeError$1: function(message) {
      var result, t1, _this = this,
        match = new RegExp(_this._pattern).exec(message);
      if (match == null)
        return null;
      result = Object.create(null);
      t1 = _this._arguments;
      if (t1 !== -1)
        result.arguments = match[t1 + 1];
      t1 = _this._argumentsExpr;
      if (t1 !== -1)
        result.argumentsExpr = match[t1 + 1];
      t1 = _this._expr;
      if (t1 !== -1)
        result.expr = match[t1 + 1];
      t1 = _this._method;
      if (t1 !== -1)
        result.method = match[t1 + 1];
      t1 = _this._receiver;
      if (t1 !== -1)
        result.receiver = match[t1 + 1];
      return result;
    }
  };
  H.NullError.prototype = {
    toString$0: function(_) {
      var t1 = this._method;
      if (t1 == null)
        return "NoSuchMethodError: " + H.S(this.__js_helper$_message);
      return "NoSuchMethodError: method not found: '" + t1 + "' on null";
    },
    $isNoSuchMethodError: 1
  };
  H.JsNoSuchMethodError.prototype = {
    toString$0: function(_) {
      var t2, _this = this,
        _s38_ = "NoSuchMethodError: method not found: '",
        t1 = _this._method;
      if (t1 == null)
        return "NoSuchMethodError: " + H.S(_this.__js_helper$_message);
      t2 = _this._receiver;
      if (t2 == null)
        return _s38_ + t1 + "' (" + H.S(_this.__js_helper$_message) + ")";
      return _s38_ + t1 + "' on '" + t2 + "' (" + H.S(_this.__js_helper$_message) + ")";
    },
    $isNoSuchMethodError: 1
  };
  H.UnknownJsTypeError.prototype = {
    toString$0: function(_) {
      var t1 = this.__js_helper$_message;
      return t1.length === 0 ? "Error" : "Error: " + t1;
    }
  };
  H.ExceptionAndStackTrace.prototype = {};
  H.unwrapException_saveStackTrace.prototype = {
    call$1: function(error) {
      if (type$.Error._is(error))
        if (error.$thrownJsError == null)
          error.$thrownJsError = this.ex;
      return error;
    },
    $signature: 18
  };
  H._StackTrace.prototype = {
    toString$0: function(_) {
      var trace,
        t1 = this._trace;
      if (t1 != null)
        return t1;
      t1 = this._exception;
      trace = t1 !== null && typeof t1 === "object" ? t1.stack : null;
      return this._trace = trace == null ? "" : trace;
    },
    $isStackTrace: 1
  };
  H.Closure.prototype = {
    toString$0: function(_) {
      var $constructor = this.constructor,
        $name = $constructor == null ? null : $constructor.name;
      return "Closure '" + H.unminifyOrTag($name == null ? "unknown" : $name) + "'";
    },
    $isFunction: 1,
    get$$call: function() {
      return this;
    },
    "call*": "call$1",
    $requiredArgCount: 1,
    $defaultValues: null
  };
  H.TearOffClosure.prototype = {};
  H.StaticClosure.prototype = {
    toString$0: function(_) {
      var $name = this.$static_name;
      if ($name == null)
        return "Closure of unknown static method";
      return "Closure '" + H.unminifyOrTag($name) + "'";
    }
  };
  H.BoundClosure.prototype = {
    $eq: function(_, other) {
      var _this = this;
      if (other == null)
        return false;
      if (_this === other)
        return true;
      if (!(other instanceof H.BoundClosure))
        return false;
      return _this._self === other._self && _this._target === other._target && _this._receiver === other._receiver;
    },
    get$hashCode: function(_) {
      var receiverHashCode,
        t1 = this._receiver;
      if (t1 == null)
        receiverHashCode = H.Primitives_objectHashCode(this._self);
      else
        receiverHashCode = typeof t1 !== "object" ? J.get$hashCode$(t1) : H.Primitives_objectHashCode(t1);
      return (receiverHashCode ^ H.Primitives_objectHashCode(this._target)) >>> 0;
    },
    toString$0: function(_) {
      var receiver = this._receiver;
      if (receiver == null)
        receiver = this._self;
      return "Closure '" + H.S(this._name) + "' of " + ("Instance of '" + H.S(H.Primitives_objectTypeName(receiver)) + "'");
    }
  };
  H.TypeErrorImplementation.prototype = {
    toString$0: function(_) {
      return this.message;
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  H.RuntimeError.prototype = {
    toString$0: function(_) {
      return "RuntimeError: " + H.S(this.message);
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  H._AssertionError.prototype = {
    toString$0: function(_) {
      return "Assertion failed: " + P.Error_safeToString(this.message);
    }
  };
  H.JsLinkedHashMap.prototype = {
    get$length: function(_) {
      return this.__js_helper$_length;
    },
    get$isEmpty: function(_) {
      return this.__js_helper$_length === 0;
    },
    get$keys: function() {
      return new H.LinkedHashMapKeyIterable(this, H._instanceType(this)._eval$1("LinkedHashMapKeyIterable<1>"));
    },
    get$values: function() {
      var t1 = H._instanceType(this);
      return H.MappedIterable_MappedIterable(this.get$keys(), new H.JsLinkedHashMap_values_closure(this), t1._precomputed1, t1._rest[1]);
    },
    containsKey$1: function(key) {
      var strings, nums, _this = this;
      if (typeof key == "string") {
        strings = _this.__js_helper$_strings;
        if (strings == null)
          return false;
        return _this._containsTableEntry$2(strings, key);
      } else if (typeof key == "number" && (key & 0x3ffffff) === key) {
        nums = _this.__js_helper$_nums;
        if (nums == null)
          return false;
        return _this._containsTableEntry$2(nums, key);
      } else
        return _this.internalContainsKey$1(key);
    },
    internalContainsKey$1: function(key) {
      var _this = this,
        rest = _this.__js_helper$_rest;
      if (rest == null)
        return false;
      return _this.internalFindBucketIndex$2(_this._getTableBucket$2(rest, _this.internalComputeHashCode$1(key)), key) >= 0;
    },
    addAll$1: function(_, other) {
      H._instanceType(this)._eval$1("Map<1,2>")._check(other).forEach$1(0, new H.JsLinkedHashMap_addAll_closure(this));
    },
    $index: function(_, key) {
      var strings, cell, t1, nums, _this = this, _null = null;
      if (typeof key == "string") {
        strings = _this.__js_helper$_strings;
        if (strings == null)
          return _null;
        cell = _this._getTableCell$2(strings, key);
        t1 = cell == null ? _null : cell.hashMapCellValue;
        return t1;
      } else if (typeof key == "number" && (key & 0x3ffffff) === key) {
        nums = _this.__js_helper$_nums;
        if (nums == null)
          return _null;
        cell = _this._getTableCell$2(nums, key);
        t1 = cell == null ? _null : cell.hashMapCellValue;
        return t1;
      } else
        return _this.internalGet$1(key);
    },
    internalGet$1: function(key) {
      var bucket, index, _this = this,
        rest = _this.__js_helper$_rest;
      if (rest == null)
        return null;
      bucket = _this._getTableBucket$2(rest, _this.internalComputeHashCode$1(key));
      index = _this.internalFindBucketIndex$2(bucket, key);
      if (index < 0)
        return null;
      return bucket[index].hashMapCellValue;
    },
    $indexSet: function(_, key, value) {
      var strings, nums, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      if (typeof key == "string") {
        strings = _this.__js_helper$_strings;
        _this.__js_helper$_addHashTableEntry$3(strings == null ? _this.__js_helper$_strings = _this._newHashTable$0() : strings, key, value);
      } else if (typeof key == "number" && (key & 0x3ffffff) === key) {
        nums = _this.__js_helper$_nums;
        _this.__js_helper$_addHashTableEntry$3(nums == null ? _this.__js_helper$_nums = _this._newHashTable$0() : nums, key, value);
      } else
        _this.internalSet$2(key, value);
    },
    internalSet$2: function(key, value) {
      var rest, hash, bucket, index, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      rest = _this.__js_helper$_rest;
      if (rest == null)
        rest = _this.__js_helper$_rest = _this._newHashTable$0();
      hash = _this.internalComputeHashCode$1(key);
      bucket = _this._getTableBucket$2(rest, hash);
      if (bucket == null)
        _this._setTableEntry$3(rest, hash, [_this._newLinkedCell$2(key, value)]);
      else {
        index = _this.internalFindBucketIndex$2(bucket, key);
        if (index >= 0)
          bucket[index].hashMapCellValue = value;
        else
          bucket.push(_this._newLinkedCell$2(key, value));
      }
    },
    putIfAbsent$2: function(key, ifAbsent) {
      var value, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._eval$1("2()")._check(ifAbsent);
      if (_this.containsKey$1(key))
        return _this.$index(0, key);
      value = ifAbsent.call$0();
      _this.$indexSet(0, key, value);
      return value;
    },
    remove$1: function(_, key) {
      var _this = this;
      if (typeof key == "string")
        return _this.__js_helper$_removeHashTableEntry$2(_this.__js_helper$_strings, key);
      else if (typeof key == "number" && (key & 0x3ffffff) === key)
        return _this.__js_helper$_removeHashTableEntry$2(_this.__js_helper$_nums, key);
      else
        return _this.internalRemove$1(key);
    },
    internalRemove$1: function(key) {
      var hash, bucket, index, cell, _this = this,
        rest = _this.__js_helper$_rest;
      if (rest == null)
        return null;
      hash = _this.internalComputeHashCode$1(key);
      bucket = _this._getTableBucket$2(rest, hash);
      index = _this.internalFindBucketIndex$2(bucket, key);
      if (index < 0)
        return null;
      cell = bucket.splice(index, 1)[0];
      _this.__js_helper$_unlinkCell$1(cell);
      if (bucket.length === 0)
        _this._deleteTableEntry$2(rest, hash);
      return cell.hashMapCellValue;
    },
    clear$0: function(_) {
      var _this = this;
      if (_this.__js_helper$_length > 0) {
        _this.__js_helper$_strings = _this.__js_helper$_nums = _this.__js_helper$_rest = _this._first = _this._last = null;
        _this.__js_helper$_length = 0;
        _this._modified$0();
      }
    },
    forEach$1: function(_, action) {
      var cell, modifications, _this = this;
      H._instanceType(_this)._eval$1("~(1,2)")._check(action);
      cell = _this._first;
      modifications = _this._modifications;
      for (; cell != null;) {
        action.call$2(cell.hashMapCellKey, cell.hashMapCellValue);
        if (modifications !== _this._modifications)
          throw H.wrapException(P.ConcurrentModificationError$(_this));
        cell = cell._next;
      }
    },
    __js_helper$_addHashTableEntry$3: function(table, key, value) {
      var cell, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      cell = _this._getTableCell$2(table, key);
      if (cell == null)
        _this._setTableEntry$3(table, key, _this._newLinkedCell$2(key, value));
      else
        cell.hashMapCellValue = value;
    },
    __js_helper$_removeHashTableEntry$2: function(table, key) {
      var cell;
      if (table == null)
        return null;
      cell = this._getTableCell$2(table, key);
      if (cell == null)
        return null;
      this.__js_helper$_unlinkCell$1(cell);
      this._deleteTableEntry$2(table, key);
      return cell.hashMapCellValue;
    },
    _modified$0: function() {
      this._modifications = this._modifications + 1 & 67108863;
    },
    _newLinkedCell$2: function(key, value) {
      var last, _this = this,
        t1 = H._instanceType(_this),
        cell = new H.LinkedHashMapCell(t1._precomputed1._check(key), t1._rest[1]._check(value));
      if (_this._first == null)
        _this._first = _this._last = cell;
      else {
        last = _this._last;
        cell._previous = last;
        _this._last = last._next = cell;
      }
      ++_this.__js_helper$_length;
      _this._modified$0();
      return cell;
    },
    __js_helper$_unlinkCell$1: function(cell) {
      var _this = this,
        previous = cell._previous,
        next = cell._next;
      if (previous == null) {
        H.assertHelper(cell == _this._first);
        _this._first = next;
      } else
        previous._next = next;
      if (next == null) {
        H.assertHelper(cell == _this._last);
        _this._last = previous;
      } else
        next._previous = previous;
      --_this.__js_helper$_length;
      _this._modified$0();
    },
    internalComputeHashCode$1: function(key) {
      return J.get$hashCode$(key) & 0x3ffffff;
    },
    internalFindBucketIndex$2: function(bucket, key) {
      var $length, i;
      if (bucket == null)
        return -1;
      $length = bucket.length;
      for (i = 0; i < $length; ++i)
        if (J.$eq$(bucket[i].hashMapCellKey, key))
          return i;
      return -1;
    },
    toString$0: function(_) {
      return P.MapBase_mapToString(this);
    },
    _getTableCell$2: function(table, key) {
      return table[key];
    },
    _getTableBucket$2: function(table, key) {
      return table[key];
    },
    _setTableEntry$3: function(table, key, value) {
      H.assertHelper(value != null);
      table[key] = value;
    },
    _deleteTableEntry$2: function(table, key) {
      delete table[key];
    },
    _containsTableEntry$2: function(table, key) {
      return this._getTableCell$2(table, key) != null;
    },
    _newHashTable$0: function() {
      var _s20_ = "<non-identifier-key>",
        table = Object.create(null);
      this._setTableEntry$3(table, _s20_, table);
      this._deleteTableEntry$2(table, _s20_);
      return table;
    },
    $isLinkedHashMap: 1
  };
  H.JsLinkedHashMap_values_closure.prototype = {
    call$1: function(each) {
      var t1 = this.$this;
      return t1.$index(0, H._instanceType(t1)._precomputed1._check(each));
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("2(1)");
    }
  };
  H.JsLinkedHashMap_addAll_closure.prototype = {
    call$2: function(key, value) {
      var t1 = this.$this,
        t2 = H._instanceType(t1);
      t1.$indexSet(0, t2._precomputed1._check(key), t2._rest[1]._check(value));
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(1,2)");
    }
  };
  H.LinkedHashMapCell.prototype = {};
  H.LinkedHashMapKeyIterable.prototype = {
    get$length: function(_) {
      return this.__js_helper$_map.__js_helper$_length;
    },
    get$isEmpty: function(_) {
      return this.__js_helper$_map.__js_helper$_length === 0;
    },
    get$iterator: function(_) {
      var t1 = this.__js_helper$_map,
        t2 = new H.LinkedHashMapKeyIterator(t1, t1._modifications, this.$ti._eval$1("LinkedHashMapKeyIterator<1>"));
      t2._cell = t1._first;
      return t2;
    },
    contains$1: function(_, element) {
      return this.__js_helper$_map.containsKey$1(element);
    }
  };
  H.LinkedHashMapKeyIterator.prototype = {
    get$current: function() {
      return this.__js_helper$_current;
    },
    moveNext$0: function() {
      var _this = this,
        t1 = _this.__js_helper$_map;
      if (_this._modifications !== t1._modifications)
        throw H.wrapException(P.ConcurrentModificationError$(t1));
      else {
        t1 = _this._cell;
        if (t1 == null) {
          _this.set$__js_helper$_current(null);
          return false;
        } else {
          _this.set$__js_helper$_current(t1.hashMapCellKey);
          _this._cell = _this._cell._next;
          return true;
        }
      }
    },
    set$__js_helper$_current: function(_current) {
      this.__js_helper$_current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  H.initHooks_closure.prototype = {
    call$1: function(o) {
      return this.getTag(o);
    },
    $signature: 18
  };
  H.initHooks_closure0.prototype = {
    call$2: function(o, tag) {
      return this.getUnknownTag(o, tag);
    },
    $signature: 104
  };
  H.initHooks_closure1.prototype = {
    call$1: function(tag) {
      return this.prototypeForTag(H._checkStringNullable(tag));
    },
    $signature: 94
  };
  H.JSSyntaxRegExp.prototype = {
    toString$0: function(_) {
      return "RegExp/" + this.pattern + "/" + this._nativeRegExp.flags;
    },
    get$_nativeGlobalVersion: function() {
      var _this = this,
        t1 = _this._nativeGlobalRegExp;
      if (t1 != null)
        return t1;
      t1 = _this._nativeRegExp;
      return _this._nativeGlobalRegExp = H.JSSyntaxRegExp_makeNative(_this.pattern, t1.multiline, !t1.ignoreCase, t1.unicode, t1.dotAll, true);
    },
    get$_nativeAnchoredVersion: function() {
      var _this = this,
        t1 = _this._nativeAnchoredRegExp;
      if (t1 != null)
        return t1;
      t1 = _this._nativeRegExp;
      return _this._nativeAnchoredRegExp = H.JSSyntaxRegExp_makeNative(_this.pattern + "|()", t1.multiline, !t1.ignoreCase, t1.unicode, t1.dotAll, true);
    },
    firstMatch$1: function(string) {
      var m;
      if (typeof string != "string")
        H.throwExpression(H.argumentErrorValue(string));
      m = this._nativeRegExp.exec(string);
      if (m == null)
        return null;
      return H._MatchImplementation$(this, m);
    },
    allMatches$2: function(_, string, start) {
      var t1 = string.length;
      if (start > t1)
        throw H.wrapException(P.RangeError$range(start, 0, t1, null, null));
      return new H._AllMatchesIterable(this, string, start);
    },
    allMatches$1: function($receiver, string) {
      return this.allMatches$2($receiver, string, 0);
    },
    _execGlobal$2: function(string, start) {
      var match,
        regexp = this.get$_nativeGlobalVersion();
      regexp.lastIndex = start;
      match = regexp.exec(string);
      if (match == null)
        return null;
      return H._MatchImplementation$(this, match);
    },
    _execAnchored$2: function(string, start) {
      var match,
        regexp = this.get$_nativeAnchoredVersion();
      regexp.lastIndex = start;
      match = regexp.exec(string);
      if (match == null)
        return null;
      if (0 >= match.length)
        return H.ioore(match, -1);
      if (match.pop() != null)
        return null;
      return H._MatchImplementation$(this, match);
    },
    matchAsPrefix$2: function(_, string, start) {
      if (start < 0 || start > string.length)
        throw H.wrapException(P.RangeError$range(start, 0, string.length, null, null));
      return this._execAnchored$2(string, start);
    },
    $isPattern: 1,
    $isRegExp: 1
  };
  H._MatchImplementation.prototype = {
    get$start: function() {
      return this._match.index;
    },
    get$end: function() {
      var t1 = this._match;
      return t1.index + t1[0].length;
    },
    $index: function(_, index) {
      var t1;
      H._checkIntNullable(index);
      t1 = this._match;
      if (index >= t1.length)
        return H.ioore(t1, index);
      return t1[index];
    },
    $isMatch: 1,
    $isRegExpMatch: 1
  };
  H._AllMatchesIterable.prototype = {
    get$iterator: function(_) {
      return new H._AllMatchesIterator(this._re, this.__js_helper$_string, this._start);
    }
  };
  H._AllMatchesIterator.prototype = {
    get$current: function() {
      return this.__js_helper$_current;
    },
    moveNext$0: function() {
      var t2, t3, match, nextIndex, _this = this,
        t1 = _this.__js_helper$_string;
      if (t1 == null)
        return false;
      t2 = _this._nextIndex;
      if (t2 <= t1.length) {
        t3 = _this._regExp;
        match = t3._execGlobal$2(t1, t2);
        if (match != null) {
          _this.__js_helper$_current = match;
          nextIndex = match.get$end();
          if (match._match.index === nextIndex) {
            if (t3._nativeRegExp.unicode) {
              t1 = _this._nextIndex;
              t2 = t1 + 1;
              t3 = _this.__js_helper$_string;
              if (t2 < t3.length) {
                t1 = J.getInterceptor$s(t3).codeUnitAt$1(t3, t1);
                if (t1 >= 55296 && t1 <= 56319) {
                  t1 = C.JSString_methods.codeUnitAt$1(t3, t2);
                  t1 = t1 >= 56320 && t1 <= 57343;
                } else
                  t1 = false;
              } else
                t1 = false;
            } else
              t1 = false;
            nextIndex = (t1 ? nextIndex + 1 : nextIndex) + 1;
          }
          _this._nextIndex = nextIndex;
          return true;
        }
      }
      _this.__js_helper$_string = _this.__js_helper$_current = null;
      return false;
    },
    $isIterator: 1
  };
  H.StringMatch.prototype = {
    get$end: function() {
      return this.start + this.pattern.length;
    },
    $index: function(_, g) {
      H._checkIntNullable(g);
      if (g !== 0)
        H.throwExpression(P.RangeError$value(g, null));
      return this.pattern;
    },
    $isMatch: 1,
    get$start: function() {
      return this.start;
    }
  };
  H._StringAllMatchesIterable.prototype = {
    get$iterator: function(_) {
      return new H._StringAllMatchesIterator(this._input, this._pattern, this.__js_helper$_index);
    },
    get$first: function(_) {
      var t1 = this._pattern,
        index = this._input.indexOf(t1, this.__js_helper$_index);
      if (index >= 0)
        return new H.StringMatch(index, t1);
      throw H.wrapException(H.IterableElementError_noElement());
    }
  };
  H._StringAllMatchesIterator.prototype = {
    moveNext$0: function() {
      var index, end, _this = this,
        t1 = _this.__js_helper$_index,
        t2 = _this._pattern,
        t3 = t2.length,
        t4 = _this._input,
        t5 = t4.length;
      if (t1 + t3 > t5) {
        _this.__js_helper$_current = null;
        return false;
      }
      index = t4.indexOf(t2, t1);
      if (index < 0) {
        _this.__js_helper$_index = t5 + 1;
        _this.__js_helper$_current = null;
        return false;
      }
      end = index + t3;
      _this.__js_helper$_current = new H.StringMatch(index, t2);
      _this.__js_helper$_index = end === _this.__js_helper$_index ? end + 1 : end;
      return true;
    },
    get$current: function() {
      return this.__js_helper$_current;
    },
    $isIterator: 1
  };
  H.NativeByteBuffer.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_ByteBuffer_RkP;
    },
    $isNativeByteBuffer: 1,
    $isByteBuffer: 1
  };
  H.NativeTypedData.prototype = {$isNativeTypedData: 1};
  H.NativeByteData.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_ByteData_zNC;
    }
  };
  H.NativeTypedArray.prototype = {
    get$length: function(receiver) {
      return receiver.length;
    },
    $isJavaScriptIndexingBehavior: 1
  };
  H.NativeTypedArrayOfDouble.prototype = {
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    },
    $indexSet: function(receiver, index, value) {
      H._checkIntNullable(index);
      H._checkDoubleNullable(value);
      H._checkValidIndex(index, receiver, receiver.length);
      receiver[index] = value;
    },
    $isEfficientLengthIterable: 1,
    $isIterable: 1,
    $isList: 1
  };
  H.NativeTypedArrayOfInt.prototype = {
    $indexSet: function(receiver, index, value) {
      H._checkIntNullable(index);
      H._checkIntNullable(value);
      H._checkValidIndex(index, receiver, receiver.length);
      receiver[index] = value;
    },
    $isEfficientLengthIterable: 1,
    $isIterable: 1,
    $isList: 1
  };
  H.NativeFloat32List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Float32List_LB7;
    }
  };
  H.NativeFloat64List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Float64List_LB7;
    }
  };
  H.NativeInt16List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Int16List_uXf;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    }
  };
  H.NativeInt32List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Int32List_O50;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    }
  };
  H.NativeInt8List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Int8List_ekJ;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    }
  };
  H.NativeUint16List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Uint16List_2bx;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    }
  };
  H.NativeUint32List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Uint32List_2bx;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    },
    sublist$2: function(receiver, start, end) {
      return new Uint32Array(receiver.subarray(start, H._checkValidRange(start, end, receiver.length)));
    },
    $isUint32List: 1
  };
  H.NativeUint8ClampedList.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Uint8ClampedList_Jik;
    },
    get$length: function(receiver) {
      return receiver.length;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    }
  };
  H.NativeUint8List.prototype = {
    get$runtimeType: function(receiver) {
      return C.Type_Uint8List_WLA;
    },
    get$length: function(receiver) {
      return receiver.length;
    },
    $index: function(receiver, index) {
      H._checkIntNullable(index);
      H._checkValidIndex(index, receiver, receiver.length);
      return receiver[index];
    },
    sublist$2: function(receiver, start, end) {
      return new Uint8Array(receiver.subarray(start, H._checkValidRange(start, end, receiver.length)));
    },
    $isNativeUint8List: 1,
    $isUint8List: 1
  };
  H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin.prototype = {};
  H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin.prototype = {};
  H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin.prototype = {};
  H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin.prototype = {};
  H.Rti.prototype = {
    _eval$1: function(recipe) {
      return H._Universe_evalInEnvironment(init.typeUniverse, this, recipe);
    },
    _bind$1: function(typeOrTuple) {
      return H._Universe_bind(init.typeUniverse, this, typeOrTuple);
    }
  };
  H._FunctionParameters.prototype = {};
  H._Type.prototype = {
    get$hashCode: function(_) {
      var s,
        t1 = this._hashCode;
      if (t1 == null) {
        s = this._rti._canonicalRecipe;
        if (H.assertTest(typeof s == "string"))
          H.assertThrow("Missing canonical recipe");
        t1 = this._hashCode = C.JSString_methods.get$hashCode(s);
      }
      return t1;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof H._Type && this._rti == other._rti;
    },
    toString$0: function(_) {
      return H._rtiToString(this._rti, null);
    },
    $isType: 1
  };
  H._Error.prototype = {
    toString$0: function(_) {
      return this._message;
    }
  };
  H._CastError.prototype = {};
  H._TypeError.prototype = {
    get$message: function(_) {
      return this._message;
    }
  };
  P._AsyncRun__initializeScheduleImmediate_internalCallback.prototype = {
    call$1: function(_) {
      var t1 = this._box_0,
        f = t1.storedCallback;
      t1.storedCallback = null;
      f.call$0();
    },
    $signature: 3
  };
  P._AsyncRun__initializeScheduleImmediate_closure.prototype = {
    call$1: function(callback) {
      var t1, t2;
      type$.void_Function._check(callback);
      t1 = this._box_0;
      H.assertHelper(t1.storedCallback == null);
      t1.storedCallback = callback;
      t1 = this.div;
      t2 = this.span;
      t1.firstChild ? t1.removeChild(t2) : t1.appendChild(t2);
    },
    $signature: 91
  };
  P._AsyncRun__scheduleImmediateJsOverride_internalCallback.prototype = {
    call$0: function() {
      this.callback.call$0();
    },
    $signature: 0
  };
  P._AsyncRun__scheduleImmediateWithSetImmediate_internalCallback.prototype = {
    call$0: function() {
      this.callback.call$0();
    },
    $signature: 0
  };
  P._TimerImpl.prototype = {
    _TimerImpl$2: function(milliseconds, callback) {
      if (self.setTimeout != null)
        this._handle = self.setTimeout(H.convertDartClosureToJS(new P._TimerImpl_internalCallback(this, callback), 0), milliseconds);
      else
        throw H.wrapException(P.UnsupportedError$("`setTimeout()` not found."));
    },
    _TimerImpl$periodic$2: function(milliseconds, callback) {
      if (self.setTimeout != null)
        this._handle = self.setInterval(H.convertDartClosureToJS(new P._TimerImpl$periodic_closure(this, milliseconds, Date.now(), callback), 0), milliseconds);
      else
        throw H.wrapException(P.UnsupportedError$("Periodic timer."));
    },
    cancel$0: function() {
      if (self.setTimeout != null) {
        var t1 = this._handle;
        if (t1 == null)
          return;
        if (this._once)
          self.clearTimeout(t1);
        else
          self.clearInterval(t1);
        this._handle = null;
      } else
        throw H.wrapException(P.UnsupportedError$("Canceling a timer."));
    },
    $isTimer: 1
  };
  P._TimerImpl_internalCallback.prototype = {
    call$0: function() {
      var t1 = this.$this;
      t1._handle = null;
      t1._tick = 1;
      this.callback.call$0();
    },
    $signature: 1
  };
  P._TimerImpl$periodic_closure.prototype = {
    call$0: function() {
      var duration, _this = this,
        t1 = _this.$this,
        tick = t1._tick + 1,
        t2 = _this.milliseconds;
      if (t2 > 0) {
        duration = Date.now() - _this.start;
        if (duration > (tick + 1) * t2)
          tick = C.JSInt_methods.$tdiv(duration, t2);
      }
      t1._tick = tick;
      _this.callback.call$1(t1);
    },
    $signature: 0
  };
  P._AsyncAwaitCompleter.prototype = {
    complete$1: function(value) {
      var t2, t3,
        t1 = this.$ti;
      t1._eval$1("1/")._check(value);
      t2 = !this.isSync || t1._eval$1("Future<1>")._is(value);
      t3 = this._future;
      if (t2)
        t3._asyncComplete$1(value);
      else
        t3._completeWithValue$1(t1._precomputed1._check(value));
    },
    completeError$2: function(e, st) {
      var t1 = this._future;
      if (this.isSync)
        t1._completeError$2(e, st);
      else
        t1._asyncCompleteError$2(e, st);
    },
    $isCompleter: 1
  };
  P._awaitOnObject_closure.prototype = {
    call$1: function(result) {
      return this.bodyFunction.call$2(0, result);
    },
    $signature: 15
  };
  P._awaitOnObject_closure0.prototype = {
    call$2: function(error, stackTrace) {
      this.bodyFunction.call$2(1, new H.ExceptionAndStackTrace(error, type$.StackTrace._check(stackTrace)));
    },
    $signature: 5
  };
  P._wrapJsFunctionForAsync_closure.prototype = {
    call$2: function(errorCode, result) {
      this.$protected(H._checkIntNullable(errorCode), result);
    },
    $signature: 89
  };
  P._BroadcastStream.prototype = {
    get$isBroadcast: function() {
      return true;
    }
  };
  P._BroadcastSubscription.prototype = {
    _onPause$0: function() {
    },
    _onResume$0: function() {
    },
    set$_async$_next: function(_next) {
      this._async$_next = this.$ti._check(_next);
    },
    set$_async$_previous: function(_previous) {
      this._async$_previous = this.$ti._check(_previous);
    }
  };
  P._BroadcastStreamController.prototype = {
    get$_mayAddEvent: function() {
      return this._state < 4;
    },
    _ensureDoneFuture$0: function() {
      var t1 = this._doneFuture;
      if (t1 != null)
        return t1;
      return this._doneFuture = new P._Future($.Zone__current, type$._Future_dynamic);
    },
    _removeListener$1: function(subscription) {
      var previous, next, _this = this;
      H._instanceType(_this)._eval$1("_BroadcastSubscription<1>")._check(subscription);
      H.assertHelper(subscription._controller === _this);
      H.assertHelper(subscription._async$_next !== subscription);
      previous = subscription._async$_previous;
      next = subscription._async$_next;
      if (previous == null)
        _this.set$_firstSubscription(next);
      else
        previous.set$_async$_next(next);
      if (next == null)
        _this.set$_lastSubscription(previous);
      else
        next.set$_async$_previous(previous);
      subscription.set$_async$_previous(subscription);
      subscription.set$_async$_next(subscription);
    },
    _subscribe$4: function(onData, onError, onDone, cancelOnError) {
      var t2, t3, t4, subscription, oldLast, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      if ((_this._state & 4) !== 0) {
        if (onDone == null)
          onDone = P.async___nullDoneHandler$closure();
        t1 = new P._DoneStreamSubscription($.Zone__current, onDone, t1._eval$1("_DoneStreamSubscription<1>"));
        t1._schedule$0();
        return t1;
      }
      t2 = $.Zone__current;
      t3 = cancelOnError ? 1 : 0;
      t4 = t1._eval$1("_BroadcastSubscription<1>");
      subscription = new P._BroadcastSubscription(_this, t2, t3, t4);
      subscription._BufferingStreamSubscription$4(onData, onError, onDone, cancelOnError, t1._precomputed1);
      subscription.set$_async$_previous(subscription);
      subscription.set$_async$_next(subscription);
      t4._check(subscription);
      H.assertHelper(subscription._async$_next === subscription);
      subscription._eventState = _this._state & 1;
      oldLast = _this._lastSubscription;
      _this.set$_lastSubscription(subscription);
      subscription.set$_async$_next(null);
      subscription.set$_async$_previous(oldLast);
      if (oldLast == null)
        _this.set$_firstSubscription(subscription);
      else
        oldLast.set$_async$_next(subscription);
      if (_this._firstSubscription == _this._lastSubscription)
        P._runGuarded(_this.onListen);
      return subscription;
    },
    _recordCancel$1: function(sub) {
      var _this = this,
        t1 = H._instanceType(_this);
      sub = t1._eval$1("_BroadcastSubscription<1>")._check(t1._eval$1("StreamSubscription<1>")._check(sub));
      if (sub._async$_next === sub)
        return null;
      t1 = (sub._eventState & 2) !== 0;
      if (t1) {
        H.assertHelper(t1);
        sub._eventState |= 4;
      } else {
        _this._removeListener$1(sub);
        if ((_this._state & 2) === 0 && _this._firstSubscription == null)
          _this._callOnCancel$0();
      }
      return null;
    },
    _recordPause$1: function(subscription) {
      H._instanceType(this)._eval$1("StreamSubscription<1>")._check(subscription);
    },
    _recordResume$1: function(subscription) {
      H._instanceType(this)._eval$1("StreamSubscription<1>")._check(subscription);
    },
    _addEventError$0: function() {
      var t1 = this._state;
      if ((t1 & 4) !== 0)
        return new P.StateError("Cannot add new events after calling close");
      H.assertHelper((t1 & 8) !== 0);
      return new P.StateError("Cannot add new events while doing an addStream");
    },
    add$1: function(_, data) {
      var _this = this;
      H._instanceType(_this)._precomputed1._check(data);
      if (!_this.get$_mayAddEvent())
        throw H.wrapException(_this._addEventError$0());
      _this._sendData$1(data);
    },
    addError$2: function(error, stackTrace) {
      var replacement;
      type$.StackTrace._check(stackTrace);
      if (error == null)
        error = new P.NullThrownError();
      if (!this.get$_mayAddEvent())
        throw H.wrapException(this._addEventError$0());
      replacement = $.Zone__current.errorCallback$2(error, stackTrace);
      if (replacement != null) {
        error = replacement.error;
        if (error == null)
          error = new P.NullThrownError();
        stackTrace = replacement.stackTrace;
      }
      this._sendError$2(error, stackTrace);
    },
    addError$1: function(error) {
      return this.addError$2(error, null);
    },
    close$0: function(_) {
      var doneFuture, _this = this;
      if ((_this._state & 4) !== 0) {
        H.assertHelper(_this._doneFuture != null);
        return _this._doneFuture;
      }
      if (!_this.get$_mayAddEvent())
        throw H.wrapException(_this._addEventError$0());
      _this._state |= 4;
      doneFuture = _this._ensureDoneFuture$0();
      _this._sendDone$0();
      return doneFuture;
    },
    _async$_addError$2: function(error, stackTrace) {
      this._sendError$2(error, type$.StackTrace._check(stackTrace));
    },
    _close$0: function() {
      var addState, _this = this;
      H.assertHelper((_this._state & 8) !== 0);
      addState = _this._addStreamState;
      _this.set$_addStreamState(null);
      _this._state &= 4294967287;
      addState.addStreamFuture._asyncComplete$1(null);
    },
    _forEachListener$1: function(action) {
      var t1, subscription, id, next, _this = this;
      H._instanceType(_this)._eval$1("~(_BufferingStreamSubscription<1>)")._check(action);
      t1 = _this._state;
      if ((t1 & 2) !== 0)
        throw H.wrapException(P.StateError$("Cannot fire new event. Controller is already firing an event"));
      subscription = _this._firstSubscription;
      if (subscription == null)
        return;
      id = t1 & 1;
      _this._state = t1 ^ 3;
      for (; subscription != null;) {
        t1 = subscription._eventState;
        if ((t1 & 1) === id) {
          subscription._eventState = t1 | 2;
          action.call$1(subscription);
          t1 = subscription._eventState ^= 1;
          next = subscription._async$_next;
          if ((t1 & 4) !== 0)
            _this._removeListener$1(subscription);
          subscription._eventState &= 4294967293;
          subscription = next;
        } else
          subscription = subscription._async$_next;
      }
      _this._state &= 4294967293;
      if (_this._firstSubscription == null)
        _this._callOnCancel$0();
    },
    _callOnCancel$0: function() {
      var _this = this;
      H.assertHelper(_this._firstSubscription == null);
      if ((_this._state & 4) !== 0 && _this._doneFuture._state === 0)
        _this._doneFuture._asyncComplete$1(null);
      P._runGuarded(_this.onCancel);
    },
    set$_firstSubscription: function(_firstSubscription) {
      this._firstSubscription = H._instanceType(this)._eval$1("_BroadcastSubscription<1>")._check(_firstSubscription);
    },
    set$_lastSubscription: function(_lastSubscription) {
      this._lastSubscription = H._instanceType(this)._eval$1("_BroadcastSubscription<1>")._check(_lastSubscription);
    },
    set$_addStreamState: function(_addStreamState) {
      this._addStreamState = H._instanceType(this)._eval$1("_AddStreamState<1>")._check(_addStreamState);
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isStreamController: 1,
    $is_StreamControllerLifecycle: 1,
    $is_EventDispatch: 1,
    $isSink: 1
  };
  P._SyncBroadcastStreamController.prototype = {
    get$_mayAddEvent: function() {
      return P._BroadcastStreamController.prototype.get$_mayAddEvent.call(this) && (this._state & 2) === 0;
    },
    _addEventError$0: function() {
      if ((this._state & 2) !== 0)
        return new P.StateError("Cannot fire new event. Controller is already firing an event");
      return this.super$_BroadcastStreamController$_addEventError();
    },
    _sendData$1: function(data) {
      var t1, _this = this;
      _this.$ti._precomputed1._check(data);
      if (_this._firstSubscription == null)
        return;
      t1 = _this._firstSubscription;
      if (t1 == _this._lastSubscription) {
        _this._state |= 2;
        t1._add$1(data);
        _this._state &= 4294967293;
        if (_this._firstSubscription == null)
          _this._callOnCancel$0();
        return;
      }
      _this._forEachListener$1(new P._SyncBroadcastStreamController__sendData_closure(_this, data));
    },
    _sendError$2: function(error, stackTrace) {
      if (this._firstSubscription == null)
        return;
      this._forEachListener$1(new P._SyncBroadcastStreamController__sendError_closure(this, error, stackTrace));
    },
    _sendDone$0: function() {
      var _this = this;
      if (_this._firstSubscription != null)
        _this._forEachListener$1(new P._SyncBroadcastStreamController__sendDone_closure(_this));
      else {
        H.assertHelper(_this._doneFuture != null);
        H.assertHelper(_this._doneFuture._state === 0);
        _this._doneFuture._asyncComplete$1(null);
      }
    }
  };
  P._SyncBroadcastStreamController__sendData_closure.prototype = {
    call$1: function(subscription) {
      this.$this.$ti._eval$1("_BufferingStreamSubscription<1>")._check(subscription)._add$1(this.data);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(_BufferingStreamSubscription<1>)");
    }
  };
  P._SyncBroadcastStreamController__sendError_closure.prototype = {
    call$1: function(subscription) {
      this.$this.$ti._eval$1("_BufferingStreamSubscription<1>")._check(subscription)._async$_addError$2(this.error, this.stackTrace);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(_BufferingStreamSubscription<1>)");
    }
  };
  P._SyncBroadcastStreamController__sendDone_closure.prototype = {
    call$1: function(subscription) {
      this.$this.$ti._eval$1("_BufferingStreamSubscription<1>")._check(subscription)._close$0();
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(_BufferingStreamSubscription<1>)");
    }
  };
  P._AsyncBroadcastStreamController.prototype = {
    _sendData$1: function(data) {
      var subscription,
        t1 = this.$ti;
      t1._precomputed1._check(data);
      for (subscription = this._firstSubscription, t1 = t1._eval$1("_DelayedData<1>"); subscription != null; subscription = subscription._async$_next)
        subscription._addPending$1(new P._DelayedData(data, t1));
    },
    _sendError$2: function(error, stackTrace) {
      var subscription;
      for (subscription = this._firstSubscription; subscription != null; subscription = subscription._async$_next)
        subscription._addPending$1(new P._DelayedError(error, stackTrace));
    },
    _sendDone$0: function() {
      var _this = this,
        subscription = _this._firstSubscription;
      if (subscription != null)
        for (; subscription != null; subscription = subscription._async$_next)
          subscription._addPending$1(C.C__DelayedDone);
      else {
        H.assertHelper(_this._doneFuture != null);
        H.assertHelper(_this._doneFuture._state === 0);
        _this._doneFuture._asyncComplete$1(null);
      }
    }
  };
  P.Future.prototype = {};
  P.Future_Future_closure.prototype = {
    call$0: function() {
      var e, s, exception;
      try {
        this.result._complete$1(this.computation.call$0());
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._completeWithErrorCallback(this.result, e, s);
      }
    },
    $signature: 0
  };
  P.Future_Future$microtask_closure.prototype = {
    call$0: function() {
      var e, s, exception;
      try {
        this.result._complete$1(this.computation.call$0());
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._completeWithErrorCallback(this.result, e, s);
      }
    },
    $signature: 0
  };
  P.Future_wait_handleError.prototype = {
    call$2: function(theError, theStackTrace) {
      var t1, t2, _this = this;
      type$.StackTrace._check(theStackTrace);
      t1 = _this._box_0;
      t2 = --t1.remaining;
      if (t1.values != null) {
        t1.values = null;
        if (t1.remaining === 0 || _this.eagerError)
          _this.result._completeError$2(theError, theStackTrace);
        else {
          t1.error = theError;
          t1.stackTrace = theStackTrace;
        }
      } else if (t2 === 0 && !_this.eagerError)
        _this.result._completeError$2(t1.error, t1.stackTrace);
    },
    $signature: 5
  };
  P.Future_wait_closure.prototype = {
    call$1: function(value) {
      var t1, t2, _this = this;
      _this.T._check(value);
      t1 = _this._box_0;
      --t1.remaining;
      t2 = t1.values;
      if (t2 != null) {
        C.JSArray_methods.$indexSet(t2, _this.pos, value);
        if (t1.remaining === 0)
          _this.result._completeWithValue$1(t1.values);
      } else if (t1.remaining === 0 && !_this.eagerError)
        _this.result._completeError$2(t1.error, t1.stackTrace);
    },
    $signature: function() {
      return this.T._eval$1("Null(0)");
    }
  };
  P.Future_forEach_closure.prototype = {
    call$0: function() {
      var result,
        t1 = this.iterator;
      if (!t1.moveNext$0())
        return false;
      result = this.action.call$1(t1._current);
      if (type$.Future_dynamic._is(result))
        return result.then$1$1(P.async_Future__kTrue$closure(), type$.bool);
      return true;
    },
    $signature: 81
  };
  P.Future_doWhile_closure.prototype = {
    call$1: function(keepGoing) {
      var result, error, stackTrace, t1, t2, exception, error0, stackTrace0, replacement, _this = this;
      H._checkBoolNullable(keepGoing);
      for (t1 = type$.Future_bool, t2 = _this.action; H.boolConversionCheck(keepGoing);) {
        result = null;
        try {
          result = t2.call$0();
        } catch (exception) {
          error = H.unwrapException(exception);
          stackTrace = H.getTraceFromException(exception);
          error0 = error;
          stackTrace0 = stackTrace;
          replacement = $.Zone__current.errorCallback$2(error0, stackTrace0);
          if (replacement != null) {
            error = replacement.error;
            if (error == null)
              error = new P.NullThrownError();
            stackTrace = replacement.stackTrace;
          } else {
            stackTrace = stackTrace0;
            error = error0;
          }
          _this.doneSignal._asyncCompleteError$2(error, stackTrace);
          return;
        }
        if (t1._is(result)) {
          result.then$1$2$onError(_this._box_0.nextIteration, _this.doneSignal.get$_completeError(), type$.void);
          return;
        }
        keepGoing = H._checkBoolNullable(result);
      }
      _this.doneSignal._complete$1(null);
    },
    $signature: 43
  };
  P.TimeoutException.prototype = {
    toString$0: function(_) {
      var t1 = this.duration,
        result = (t1 != null ? "TimeoutException after " + t1.toString$0(0) : "TimeoutException") + ": " + this.message;
      return result;
    },
    $isException: 1,
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.Completer.prototype = {};
  P._Completer.prototype = {
    completeError$2: function(error, stackTrace) {
      var replacement;
      if (error == null)
        error = new P.NullThrownError();
      if (this.future._state !== 0)
        throw H.wrapException(P.StateError$("Future already completed"));
      replacement = $.Zone__current.errorCallback$2(error, stackTrace);
      if (replacement != null) {
        error = replacement.error;
        if (error == null)
          error = new P.NullThrownError();
        stackTrace = replacement.stackTrace;
      }
      this._completeError$2(error, stackTrace);
    },
    completeError$1: function(error) {
      return this.completeError$2(error, null);
    },
    $isCompleter: 1
  };
  P._AsyncCompleter.prototype = {
    complete$1: function(value) {
      var t1;
      this.$ti._eval$1("1/")._check(value);
      t1 = this.future;
      if (t1._state !== 0)
        throw H.wrapException(P.StateError$("Future already completed"));
      t1._asyncComplete$1(value);
    },
    complete$0: function() {
      return this.complete$1(null);
    },
    _completeError$2: function(error, stackTrace) {
      this.future._asyncCompleteError$2(error, stackTrace);
    }
  };
  P._SyncCompleter.prototype = {
    complete$1: function(value) {
      var t1;
      this.$ti._eval$1("1/")._check(value);
      t1 = this.future;
      if (t1._state !== 0)
        throw H.wrapException(P.StateError$("Future already completed"));
      t1._complete$1(value);
    },
    complete$0: function() {
      return this.complete$1(null);
    },
    _completeError$2: function(error, stackTrace) {
      this.future._completeError$2(error, stackTrace);
    }
  };
  P._FutureListener.prototype = {
    matchesErrorTest$1: function(asyncError) {
      if ((this.state & 15) !== 6)
        return true;
      return this.result._zone.runUnary$2$2(type$.bool_Function_Object._check(this.callback), asyncError.error, type$.bool, type$.Object);
    },
    handleError$1: function(asyncError) {
      var errorCallback, t2, t3, t4, _this = this,
        t1 = (_this.state & 2) !== 0;
      if (t1) {
        H.assertHelper(t1);
        t1 = _this.errorCallback != null;
      } else
        t1 = false;
      H.assertHelper(t1);
      errorCallback = _this.errorCallback;
      t1 = type$.dynamic;
      t2 = type$.Object;
      t3 = _this.$ti._eval$1("2/");
      t4 = _this.result._zone;
      if (type$.dynamic_Function_Object_StackTrace._is(errorCallback))
        return t3._check(t4.runBinary$3$3(errorCallback, asyncError.error, asyncError.stackTrace, t1, t2, type$.StackTrace));
      else {
        H.assertHelper(type$.dynamic_Function_Object._is(errorCallback));
        return t3._check(t4.runUnary$2$2(errorCallback, asyncError.error, t1, t2));
      }
    }
  };
  P._Future.prototype = {
    then$1$2$onError: function(f, onError, $R) {
      var currentZone, result, t2,
        t1 = this.$ti;
      t1._bind$1($R)._eval$1("1/(2)")._check(f);
      currentZone = $.Zone__current;
      if (currentZone !== C.C__RootZone) {
        f = currentZone.registerUnaryCallback$2$1(f, $R._eval$1("0/"), t1._precomputed1);
        if (onError != null)
          onError = P._registerErrorHandler(onError, currentZone);
      }
      result = new P._Future($.Zone__current, $R._eval$1("_Future<0>"));
      t2 = onError == null ? 1 : 3;
      this._addListener$1(new P._FutureListener(result, t2, f, onError, t1._eval$1("@<1>")._bind$1($R)._eval$1("_FutureListener<1,2>")));
      return result;
    },
    then$1$1: function(f, $R) {
      return this.then$1$2$onError(f, null, $R);
    },
    _thenAwait$1$2: function(f, onError, $E) {
      var result,
        t1 = this.$ti;
      t1._bind$1($E)._eval$1("1/(2)")._check(f);
      result = new P._Future($.Zone__current, $E._eval$1("_Future<0>"));
      this._addListener$1(new P._FutureListener(result, (onError == null ? 1 : 3) | 16, f, onError, t1._eval$1("@<1>")._bind$1($E)._eval$1("_FutureListener<1,2>")));
      return result;
    },
    catchError$1: function(onError) {
      var t1, t2, result;
      type$.bool_Function_dynamic._check(null);
      t1 = this.$ti;
      t2 = $.Zone__current;
      result = new P._Future(t2, t1);
      if (t2 !== C.C__RootZone)
        onError = P._registerErrorHandler(onError, t2);
      this._addListener$1(new P._FutureListener(result, 2, null, onError, t1._eval$1("@<1>")._bind$1(t1._precomputed1)._eval$1("_FutureListener<1,2>")));
      return result;
    },
    whenComplete$1: function(action) {
      var t1, t2, result;
      type$.dynamic_Function._check(action);
      t1 = this.$ti;
      t2 = $.Zone__current;
      result = new P._Future(t2, t1);
      if (t2 !== C.C__RootZone)
        action = t2.registerCallback$1$1(action, type$.dynamic);
      this._addListener$1(new P._FutureListener(result, 8, action, null, t1._eval$1("@<1>")._bind$1(t1._precomputed1)._eval$1("_FutureListener<1,2>")));
      return result;
    },
    _cloneResult$1: function(source) {
      H.assertHelper(this._state < 4);
      H.assertHelper(source._state >= 4);
      this._state = source._state;
      this._resultOrListeners = source._resultOrListeners;
    },
    _addListener$1: function(listener) {
      var t1, source, _this = this;
      H.assertHelper(listener._nextListener == null);
      t1 = _this._state;
      if (t1 <= 1) {
        listener._nextListener = type$._FutureListener_dynamic_dynamic._check(_this._resultOrListeners);
        _this._resultOrListeners = listener;
      } else {
        if (t1 === 2) {
          source = type$._Future_dynamic._check(_this._resultOrListeners);
          if (source._state < 4) {
            source._addListener$1(listener);
            return;
          }
          _this._cloneResult$1(source);
        }
        H.assertHelper(_this._state >= 4);
        _this._zone.scheduleMicrotask$1(new P._Future__addListener_closure(_this, listener));
      }
    },
    _prependListeners$1: function(listeners) {
      var t1, existingListeners, cursor, cursor0, source, _this = this, _box_0 = {};
      _box_0.listeners = listeners;
      if (listeners == null)
        return;
      t1 = _this._state;
      if (t1 <= 1) {
        existingListeners = type$._FutureListener_dynamic_dynamic._check(_this._resultOrListeners);
        cursor = _this._resultOrListeners = listeners;
        if (existingListeners != null) {
          for (; cursor0 = cursor._nextListener, cursor0 != null; cursor = cursor0)
            ;
          cursor._nextListener = existingListeners;
        }
      } else {
        if (t1 === 2) {
          source = type$._Future_dynamic._check(_this._resultOrListeners);
          if (source._state < 4) {
            source._prependListeners$1(listeners);
            return;
          }
          _this._cloneResult$1(source);
        }
        H.assertHelper(_this._state >= 4);
        _box_0.listeners = _this._reverseListeners$1(listeners);
        _this._zone.scheduleMicrotask$1(new P._Future__prependListeners_closure(_box_0, _this));
      }
    },
    _removeListeners$0: function() {
      var current, _this = this;
      H.assertHelper(_this._state < 4);
      current = type$._FutureListener_dynamic_dynamic._check(_this._resultOrListeners);
      _this._resultOrListeners = null;
      return _this._reverseListeners$1(current);
    },
    _reverseListeners$1: function(listeners) {
      var current, prev, next;
      for (current = listeners, prev = null; current != null; prev = current, current = next) {
        next = current._nextListener;
        current._nextListener = prev;
      }
      return prev;
    },
    _complete$1: function(value) {
      var listeners, _this = this,
        t1 = _this.$ti;
      t1._eval$1("1/")._check(value);
      H.assertHelper(_this._state < 4);
      if (t1._eval$1("Future<1>")._is(value))
        if (t1._is(value))
          P._Future__chainCoreFuture(value, _this);
        else
          P._Future__chainForeignFuture(value, _this);
      else {
        listeners = _this._removeListeners$0();
        t1._precomputed1._check(value);
        H.assertHelper(_this._state < 4);
        _this._state = 4;
        _this._resultOrListeners = value;
        P._Future__propagateToListeners(_this, listeners);
      }
    },
    _completeWithValue$1: function(value) {
      var listeners, _this = this,
        t1 = _this.$ti;
      t1._precomputed1._check(value);
      H.assertHelper(_this._state < 4);
      H.assertHelper(!t1._eval$1("Future<1>")._is(value));
      listeners = _this._removeListeners$0();
      H.assertHelper(_this._state < 4);
      _this._state = 4;
      _this._resultOrListeners = value;
      P._Future__propagateToListeners(_this, listeners);
    },
    _completeError$2: function(error, stackTrace) {
      var listeners, _this = this;
      type$.StackTrace._check(stackTrace);
      H.assertHelper(_this._state < 4);
      listeners = _this._removeListeners$0();
      H.assertHelper(_this._state < 4);
      _this._state = 8;
      _this._resultOrListeners = new P.AsyncError(error, stackTrace);
      P._Future__propagateToListeners(_this, listeners);
    },
    _completeError$1: function(error) {
      return this._completeError$2(error, null);
    },
    _asyncComplete$1: function(value) {
      var _this = this,
        t1 = _this.$ti;
      t1._eval$1("1/")._check(value);
      H.assertHelper(_this._state < 4);
      if (t1._eval$1("Future<1>")._is(value)) {
        _this._chainFuture$1(value);
        return;
      }
      H.assertHelper(_this._state === 0);
      _this._state = 1;
      _this._zone.scheduleMicrotask$1(new P._Future__asyncComplete_closure(_this, value));
    },
    _chainFuture$1: function(value) {
      var _this = this,
        t1 = _this.$ti;
      t1._eval$1("Future<1>")._check(value);
      if (t1._is(value)) {
        if (value._state === 8) {
          H.assertHelper(_this._state === 0);
          _this._state = 1;
          _this._zone.scheduleMicrotask$1(new P._Future__chainFuture_closure(_this, value));
        } else
          P._Future__chainCoreFuture(value, _this);
        return;
      }
      P._Future__chainForeignFuture(value, _this);
    },
    _asyncCompleteError$2: function(error, stackTrace) {
      var _this = this;
      type$.StackTrace._check(stackTrace);
      H.assertHelper(_this._state < 4);
      H.assertHelper(_this._state === 0);
      _this._state = 1;
      _this._zone.scheduleMicrotask$1(new P._Future__asyncCompleteError_closure(_this, error, stackTrace));
    },
    $isFuture: 1
  };
  P._Future__addListener_closure.prototype = {
    call$0: function() {
      P._Future__propagateToListeners(this.$this, this.listener);
    },
    $signature: 0
  };
  P._Future__prependListeners_closure.prototype = {
    call$0: function() {
      P._Future__propagateToListeners(this.$this, this._box_0.listeners);
    },
    $signature: 0
  };
  P._Future__chainForeignFuture_closure.prototype = {
    call$1: function(value) {
      var t1 = this.target;
      H.assertHelper(t1._state === 1);
      H.assertHelper(t1._state === 1);
      t1._state = 0;
      t1._complete$1(value);
    },
    $signature: 3
  };
  P._Future__chainForeignFuture_closure0.prototype = {
    call$2: function(error, stackTrace) {
      var t1;
      type$.StackTrace._check(stackTrace);
      t1 = this.target;
      H.assertHelper(t1._state === 1);
      t1._completeError$2(error, stackTrace);
    },
    call$1: function(error) {
      return this.call$2(error, null);
    },
    $signature: 80
  };
  P._Future__chainForeignFuture_closure1.prototype = {
    call$0: function() {
      this.target._completeError$2(this.e, this.s);
    },
    $signature: 0
  };
  P._Future__asyncComplete_closure.prototype = {
    call$0: function() {
      var t1 = this.$this;
      t1._completeWithValue$1(t1.$ti._precomputed1._check(this.value));
    },
    $signature: 0
  };
  P._Future__chainFuture_closure.prototype = {
    call$0: function() {
      P._Future__chainCoreFuture(this.value, this.$this);
    },
    $signature: 0
  };
  P._Future__asyncCompleteError_closure.prototype = {
    call$0: function() {
      this.$this._completeError$2(this.error, this.stackTrace);
    },
    $signature: 0
  };
  P._Future__propagateToListeners_handleWhenCompleteCallback.prototype = {
    call$0: function() {
      var completeResult, e, s, t3, exception, originalSource, _this = this,
        t1 = _this.listener,
        t2 = t1.state;
      H.assertHelper((t2 & 1) === 0);
      t3 = (t2 & 2) === 0;
      H.assertHelper(t3);
      completeResult = null;
      try {
        H.assertHelper(t3);
        H.assertHelper((t2 & 15) === 8);
        completeResult = t1.result._zone.run$1$1(type$.dynamic_Function._check(t1.callback), type$.dynamic);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        if (_this.hasError) {
          t1 = _this._box_1.source;
          H.assertHelper(t1._state === 8);
          t1 = type$.AsyncError._check(t1._resultOrListeners).error;
          t2 = e;
          t2 = t1 == null ? t2 == null : t1 === t2;
          t1 = t2;
        } else
          t1 = false;
        t2 = _this._box_0;
        if (t1) {
          t1 = _this._box_1.source;
          H.assertHelper(t1._state === 8);
          t2.listenerValueOrError = type$.AsyncError._check(t1._resultOrListeners);
        } else
          t2.listenerValueOrError = new P.AsyncError(e, s);
        t2.listenerHasError = true;
        return;
      }
      if (type$.Future_dynamic._is(completeResult)) {
        if (completeResult instanceof P._Future && completeResult._state >= 4) {
          if (completeResult._state === 8) {
            t1 = completeResult;
            H.assertHelper(t1._state === 8);
            t2 = _this._box_0;
            t2.listenerValueOrError = type$.AsyncError._check(t1._resultOrListeners);
            t2.listenerHasError = true;
          }
          return;
        }
        originalSource = _this._box_1.source;
        t1 = _this._box_0;
        t1.listenerValueOrError = completeResult.then$1$1(new P._Future__propagateToListeners_handleWhenCompleteCallback_closure(originalSource), type$.dynamic);
        t1.listenerHasError = false;
      }
    },
    $signature: 1
  };
  P._Future__propagateToListeners_handleWhenCompleteCallback_closure.prototype = {
    call$1: function(_) {
      return this.originalSource;
    },
    $signature: 75
  };
  P._Future__propagateToListeners_handleValueCallback.prototype = {
    call$0: function() {
      var e, s, t1, t2, t3, t4, exception, _this = this;
      try {
        t1 = _this.listener;
        t2 = t1.$ti;
        t3 = t2._precomputed1;
        t4 = t3._check(_this.sourceResult);
        H.assertHelper((t1.state & 1) !== 0);
        _this._box_0.listenerValueOrError = t1.result._zone.runUnary$2$2(t2._eval$1("2/(1)")._check(t1.callback), t4, t2._eval$1("2/"), t3);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        t1 = _this._box_0;
        t1.listenerValueOrError = new P.AsyncError(e, s);
        t1.listenerHasError = true;
      }
    },
    $signature: 1
  };
  P._Future__propagateToListeners_handleError.prototype = {
    call$0: function() {
      var asyncError, e, s, t1, t2, exception, t3, t4, t5, _this = this;
      try {
        t1 = _this._box_1.source;
        H.assertHelper(t1._state === 8);
        asyncError = type$.AsyncError._check(t1._resultOrListeners);
        t1 = _this.listener;
        if (H.boolConversionCheck(t1.matchesErrorTest$1(asyncError))) {
          H.assertHelper((t1.state & 2) !== 0);
          t2 = t1.errorCallback != null;
        } else
          t2 = false;
        if (t2) {
          t2 = _this._box_0;
          t2.listenerValueOrError = t1.handleError$1(asyncError);
          t2.listenerHasError = false;
        }
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        t1 = _this._box_1;
        t2 = t1.source;
        H.assertHelper(t2._state === 8);
        t3 = type$.AsyncError;
        t2 = t3._check(t2._resultOrListeners).error;
        t4 = e;
        t5 = _this._box_0;
        if (t2 == null ? t4 == null : t2 === t4) {
          t1 = t1.source;
          H.assertHelper(t1._state === 8);
          t5.listenerValueOrError = t3._check(t1._resultOrListeners);
        } else
          t5.listenerValueOrError = new P.AsyncError(e, s);
        t5.listenerHasError = true;
      }
    },
    $signature: 1
  };
  P._AsyncCallbackEntry.prototype = {};
  P.Stream.prototype = {
    get$isBroadcast: function() {
      return false;
    },
    pipe$1: function(streamConsumer) {
      H._instanceType(this)._eval$1("StreamConsumer<Stream.T>")._check(streamConsumer);
      return streamConsumer.addStream$1(this).then$1$1(new P.Stream_pipe_closure(streamConsumer), type$.dynamic);
    },
    get$length: function(_) {
      var t1 = {},
        future = new P._Future($.Zone__current, type$._Future_int);
      t1.count = 0;
      this.listen$4$cancelOnError$onDone$onError(new P.Stream_length_closure(t1, this), true, new P.Stream_length_closure0(t1, future), future.get$_completeError());
      return future;
    },
    get$first: function(_) {
      var t1 = {},
        future = new P._Future($.Zone__current, H._instanceType(this)._eval$1("_Future<Stream.T>"));
      t1.subscription = null;
      t1.subscription = this.listen$4$cancelOnError$onDone$onError(new P.Stream_first_closure(t1, this, future), true, new P.Stream_first_closure0(future), future.get$_completeError());
      return future;
    },
    get$last: function(_) {
      var t1 = {},
        future = new P._Future($.Zone__current, H._instanceType(this)._eval$1("_Future<Stream.T>"));
      t1.result = null;
      t1.foundResult = false;
      this.listen$4$cancelOnError$onDone$onError(new P.Stream_last_closure(t1, this), true, new P.Stream_last_closure0(t1, future), future.get$_completeError());
      return future;
    },
    firstWhere$1: function(_, test) {
      var future, _this = this, t1 = {},
        t2 = H._instanceType(_this);
      t2._eval$1("bool(Stream.T)")._check(test);
      t2._eval$1("Stream.T()")._check(null);
      future = new P._Future($.Zone__current, t2._eval$1("_Future<Stream.T>"));
      t1.subscription = null;
      t1.subscription = _this.listen$4$cancelOnError$onDone$onError(new P.Stream_firstWhere_closure(t1, _this, test, future), true, new P.Stream_firstWhere_closure0(_this, null, future), future.get$_completeError());
      return future;
    }
  };
  P.Stream_Stream$fromFuture_closure.prototype = {
    call$1: function(value) {
      var t1 = this.controller;
      t1._add$1(this.T._check(value));
      t1._closeUnchecked$0();
    },
    $signature: function() {
      return this.T._eval$1("Null(0)");
    }
  };
  P.Stream_Stream$fromFuture_closure0.prototype = {
    call$2: function(error, stackTrace) {
      var t1 = this.controller;
      t1._async$_addError$2(error, type$.StackTrace._check(stackTrace));
      t1._closeUnchecked$0();
    },
    $signature: 6
  };
  P.Stream_Stream$fromIterable_closure.prototype = {
    call$0: function() {
      var t1 = this.elements;
      return new P._IterablePendingEvents(new J.ArrayIterator(t1, 0, H._arrayInstanceType(t1)._eval$1("ArrayIterator<1>")), this.T._eval$1("_IterablePendingEvents<0>"));
    },
    $signature: function() {
      return this.T._eval$1("_IterablePendingEvents<0>()");
    }
  };
  P.Stream_pipe_closure.prototype = {
    call$1: function(_) {
      return this.streamConsumer.close$0(0);
    },
    $signature: 73
  };
  P.Stream_length_closure.prototype = {
    call$1: function(_) {
      H._instanceType(this.$this)._eval$1("Stream.T")._check(_);
      ++this._box_0.count;
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(Stream.T)");
    }
  };
  P.Stream_length_closure0.prototype = {
    call$0: function() {
      this.future._complete$1(this._box_0.count);
    },
    $signature: 0
  };
  P.Stream_first_closure.prototype = {
    call$1: function(value) {
      H._instanceType(this.$this)._eval$1("Stream.T")._check(value);
      P._cancelAndValue(this._box_0.subscription, this.future, value);
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(Stream.T)");
    }
  };
  P.Stream_first_closure0.prototype = {
    call$0: function() {
      var e, s, t1, exception;
      try {
        t1 = H.IterableElementError_noElement();
        throw H.wrapException(t1);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._completeWithErrorCallback(this.future, e, s);
      }
    },
    $signature: 0
  };
  P.Stream_last_closure.prototype = {
    call$1: function(value) {
      var t1;
      H._instanceType(this.$this)._eval$1("Stream.T")._check(value);
      t1 = this._box_0;
      t1.foundResult = true;
      t1.result = value;
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(Stream.T)");
    }
  };
  P.Stream_last_closure0.prototype = {
    call$0: function() {
      var e, s, exception,
        t1 = this._box_0;
      if (t1.foundResult) {
        this.future._complete$1(t1.result);
        return;
      }
      try {
        t1 = H.IterableElementError_noElement();
        throw H.wrapException(t1);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._completeWithErrorCallback(this.future, e, s);
      }
    },
    $signature: 0
  };
  P.Stream_firstWhere_closure.prototype = {
    call$1: function(value) {
      var t1, t2, _this = this;
      H._instanceType(_this.$this)._eval$1("Stream.T")._check(value);
      t1 = _this._box_0;
      t2 = _this.future;
      P._runUserCode(new P.Stream_firstWhere__closure(_this.test, value), new P.Stream_firstWhere__closure0(t1, t2, value), P._cancelAndErrorClosure(t1.subscription, t2), type$.bool);
    },
    $signature: function() {
      return H._instanceType(this.$this)._eval$1("Null(Stream.T)");
    }
  };
  P.Stream_firstWhere__closure.prototype = {
    call$0: function() {
      return this.test.call$1(this.value);
    },
    $signature: 49
  };
  P.Stream_firstWhere__closure0.prototype = {
    call$1: function(isMatch) {
      if (H.boolConversionCheck(H._checkBoolNullable(isMatch)))
        P._cancelAndValue(this._box_0.subscription, this.future, this.value);
    },
    $signature: 43
  };
  P.Stream_firstWhere_closure0.prototype = {
    call$0: function() {
      var e, s, t1, exception;
      try {
        t1 = H.IterableElementError_noElement();
        throw H.wrapException(t1);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._completeWithErrorCallback(this.future, e, s);
      }
    },
    $signature: 0
  };
  P.StreamSubscription.prototype = {};
  P.StreamTransformerBase.prototype = {$isStreamTransformer: 1};
  P._StreamController.prototype = {
    get$_pendingEvents: function() {
      var t1, _this = this;
      H.assertHelper((_this._state & 3) === 0);
      if ((_this._state & 8) === 0)
        return H._instanceType(_this)._eval$1("_PendingEvents<1>")._check(_this._varData);
      t1 = H._instanceType(_this);
      return t1._eval$1("_PendingEvents<1>")._check(t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData).varData);
    },
    _ensurePendingEvents$0: function() {
      var t1, state, t2, _this = this;
      H.assertHelper((_this._state & 3) === 0);
      if ((_this._state & 8) === 0) {
        t1 = _this._varData;
        if (t1 == null)
          t1 = _this._varData = new P._StreamImplEvents(H._instanceType(_this)._eval$1("_StreamImplEvents<1>"));
        return H._instanceType(_this)._eval$1("_StreamImplEvents<1>")._check(t1);
      }
      t1 = H._instanceType(_this);
      state = t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData);
      t2 = state.varData;
      if (t2 == null)
        t2 = state.varData = new P._StreamImplEvents(t1._eval$1("_StreamImplEvents<1>"));
      return t1._eval$1("_StreamImplEvents<1>")._check(t2);
    },
    get$_async$_subscription: function() {
      var t1, _this = this;
      H.assertHelper((_this._state & 1) !== 0);
      if ((_this._state & 8) !== 0) {
        t1 = H._instanceType(_this);
        return t1._eval$1("_ControllerSubscription<1>")._check(t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData).varData);
      }
      return H._instanceType(_this)._eval$1("_ControllerSubscription<1>")._check(_this._varData);
    },
    _badEventState$0: function() {
      var t1 = this._state;
      if ((t1 & 4) !== 0)
        return new P.StateError("Cannot add event after closing");
      H.assertHelper((t1 & 8) !== 0);
      return new P.StateError("Cannot add event while adding a stream");
    },
    addStream$2$cancelOnError: function(source, cancelOnError) {
      var t2, t3, t4, t5, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("Stream<1>")._check(source);
      t2 = _this._state;
      if (t2 >= 4)
        throw H.wrapException(_this._badEventState$0());
      if ((t2 & 2) !== 0) {
        t1 = new P._Future($.Zone__current, type$._Future_dynamic);
        t1._asyncComplete$1(null);
        return t1;
      }
      t2 = _this._varData;
      t3 = cancelOnError === true;
      t4 = new P._Future($.Zone__current, type$._Future_dynamic);
      t5 = t3 ? P._AddStreamState_makeErrorHandler(_this) : _this.get$_async$_addError();
      t5 = source.listen$4$cancelOnError$onDone$onError(_this.get$_add(), t3, _this.get$_close(), t5);
      t3 = _this._state;
      if ((t3 & 1) !== 0 ? (_this.get$_async$_subscription()._state & 4) !== 0 : (t3 & 2) === 0)
        t5.pause$0();
      _this._varData = new P._StreamControllerAddStreamState(t2, t4, t5, t1._eval$1("_StreamControllerAddStreamState<1>"));
      _this._state |= 8;
      return t4;
    },
    _ensureDoneFuture$0: function() {
      var t1 = this._doneFuture;
      if (t1 == null)
        t1 = this._doneFuture = (this._state & 2) !== 0 ? $.$get$Future__nullFuture() : new P._Future($.Zone__current, type$._Future_dynamic);
      return t1;
    },
    add$1: function(_, value) {
      var _this = this;
      H._instanceType(_this)._precomputed1._check(value);
      if (_this._state >= 4)
        throw H.wrapException(_this._badEventState$0());
      _this._add$1(value);
    },
    addError$2: function(error, stackTrace) {
      var replacement;
      type$.StackTrace._check(stackTrace);
      if (this._state >= 4)
        throw H.wrapException(this._badEventState$0());
      if (error == null)
        error = new P.NullThrownError();
      replacement = $.Zone__current.errorCallback$2(error, stackTrace);
      if (replacement != null) {
        error = replacement.error;
        if (error == null)
          error = new P.NullThrownError();
        stackTrace = replacement.stackTrace;
      }
      this._async$_addError$2(error, stackTrace);
    },
    addError$1: function(error) {
      return this.addError$2(error, null);
    },
    close$0: function(_) {
      var _this = this,
        t1 = _this._state;
      if ((t1 & 4) !== 0)
        return _this._ensureDoneFuture$0();
      if (t1 >= 4)
        throw H.wrapException(_this._badEventState$0());
      _this._closeUnchecked$0();
      return _this._ensureDoneFuture$0();
    },
    _closeUnchecked$0: function() {
      var t1 = this._state |= 4;
      if ((t1 & 1) !== 0)
        this._sendDone$0();
      else if ((t1 & 3) === 0)
        this._ensurePendingEvents$0().add$1(0, C.C__DelayedDone);
    },
    _add$1: function(value) {
      var t2, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(value);
      t2 = _this._state;
      if ((t2 & 1) !== 0)
        _this._sendData$1(value);
      else if ((t2 & 3) === 0)
        _this._ensurePendingEvents$0().add$1(0, new P._DelayedData(value, t1._eval$1("_DelayedData<1>")));
    },
    _async$_addError$2: function(error, stackTrace) {
      var t1;
      type$.StackTrace._check(stackTrace);
      t1 = this._state;
      if ((t1 & 1) !== 0)
        this._sendError$2(error, stackTrace);
      else if ((t1 & 3) === 0)
        this._ensurePendingEvents$0().add$1(0, new P._DelayedError(error, stackTrace));
    },
    _close$0: function() {
      var addState, _this = this;
      H.assertHelper((_this._state & 8) !== 0);
      addState = H._instanceType(_this)._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData);
      _this._varData = addState.varData;
      _this._state &= 4294967287;
      addState.addStreamFuture._asyncComplete$1(null);
    },
    _subscribe$4: function(onData, onError, onDone, cancelOnError) {
      var t2, t3, subscription, pendingEvents, addState, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      if ((_this._state & 3) !== 0)
        throw H.wrapException(P.StateError$("Stream has already been listened to."));
      t2 = $.Zone__current;
      t3 = cancelOnError ? 1 : 0;
      subscription = new P._ControllerSubscription(_this, t2, t3, t1._eval$1("_ControllerSubscription<1>"));
      subscription._BufferingStreamSubscription$4(onData, onError, onDone, cancelOnError, t1._precomputed1);
      pendingEvents = _this.get$_pendingEvents();
      t3 = _this._state |= 1;
      if ((t3 & 8) !== 0) {
        addState = t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData);
        addState.varData = subscription;
        addState.addSubscription.resume$0();
      } else
        _this._varData = subscription;
      subscription._setPendingEvents$1(pendingEvents);
      subscription._guardCallback$1(new P._StreamController__subscribe_closure(_this));
      return subscription;
    },
    _recordCancel$1: function(subscription) {
      var result, e, s, exception, result0, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("StreamSubscription<1>")._check(subscription);
      result = null;
      if ((_this._state & 8) !== 0)
        result = t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData).cancel$0();
      _this._varData = null;
      _this._state = _this._state & 4294967286 | 2;
      t1 = _this.onCancel;
      if (t1 != null)
        if (result == null)
          try {
            result = type$.Future_dynamic._check(t1.call$0());
          } catch (exception) {
            e = H.unwrapException(exception);
            s = H.getTraceFromException(exception);
            result0 = new P._Future($.Zone__current, type$._Future_dynamic);
            result0._asyncCompleteError$2(e, s);
            result = result0;
          }
        else
          result = result.whenComplete$1(t1);
      t1 = new P._StreamController__recordCancel_complete(_this);
      if (result != null)
        result = result.whenComplete$1(t1);
      else
        t1.call$0();
      return result;
    },
    _recordPause$1: function(subscription) {
      var _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("StreamSubscription<1>")._check(subscription);
      if ((_this._state & 8) !== 0)
        t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData).addSubscription.pause$0();
      P._runGuarded(_this.onPause);
    },
    _recordResume$1: function(subscription) {
      var _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("StreamSubscription<1>")._check(subscription);
      if ((_this._state & 8) !== 0)
        t1._eval$1("_StreamControllerAddStreamState<1>")._check(_this._varData).addSubscription.resume$0();
      P._runGuarded(_this.onResume);
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isStreamController: 1,
    $is_StreamControllerLifecycle: 1,
    $is_EventDispatch: 1,
    $isSink: 1
  };
  P._StreamController__subscribe_closure.prototype = {
    call$0: function() {
      P._runGuarded(this.$this.onListen);
    },
    $signature: 0
  };
  P._StreamController__recordCancel_complete.prototype = {
    call$0: function() {
      var t1 = this.$this._doneFuture;
      if (t1 != null && t1._state === 0)
        t1._asyncComplete$1(null);
    },
    $signature: 1
  };
  P._SyncStreamControllerDispatch.prototype = {
    _sendData$1: function(data) {
      this.$ti._precomputed1._check(data);
      this.get$_async$_subscription()._add$1(data);
    },
    _sendError$2: function(error, stackTrace) {
      this.get$_async$_subscription()._async$_addError$2(error, stackTrace);
    },
    _sendDone$0: function() {
      this.get$_async$_subscription()._close$0();
    }
  };
  P._AsyncStreamControllerDispatch.prototype = {
    _sendData$1: function(data) {
      var t1 = this.$ti;
      t1._precomputed1._check(data);
      this.get$_async$_subscription()._addPending$1(new P._DelayedData(data, t1._eval$1("_DelayedData<1>")));
    },
    _sendError$2: function(error, stackTrace) {
      this.get$_async$_subscription()._addPending$1(new P._DelayedError(error, stackTrace));
    },
    _sendDone$0: function() {
      this.get$_async$_subscription()._addPending$1(C.C__DelayedDone);
    }
  };
  P._AsyncStreamController.prototype = {};
  P._SyncStreamController.prototype = {};
  P._ControllerStream.prototype = {
    _createSubscription$4: function(onData, onError, onDone, cancelOnError) {
      return this._controller._subscribe$4(H._instanceType(this)._eval$1("~(1)")._check(onData), onError, type$.void_Function._check(onDone), cancelOnError);
    },
    get$hashCode: function(_) {
      return (H.Primitives_objectHashCode(this._controller) ^ 892482866) >>> 0;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      if (this === other)
        return true;
      return other instanceof P._ControllerStream && other._controller === this._controller;
    }
  };
  P._ControllerSubscription.prototype = {
    _onCancel$0: function() {
      return this._controller._recordCancel$1(this);
    },
    _onPause$0: function() {
      this._controller._recordPause$1(this);
    },
    _onResume$0: function() {
      this._controller._recordResume$1(this);
    }
  };
  P._StreamSinkWrapper.prototype = {
    add$1: function(_, data) {
      this._async$_target.add$1(0, this.$ti._precomputed1._check(data));
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isSink: 1
  };
  P._AddStreamState.prototype = {
    cancel$0: function() {
      var cancel = this.addSubscription.cancel$0();
      if (cancel == null) {
        this.addStreamFuture._asyncComplete$1(null);
        return null;
      }
      return cancel.whenComplete$1(new P._AddStreamState_cancel_closure(this));
    }
  };
  P._AddStreamState_makeErrorHandler_closure.prototype = {
    call$2: function(e, s) {
      var t1 = this.controller;
      t1._async$_addError$2(e, type$.StackTrace._check(s));
      t1._close$0();
    },
    $signature: 5
  };
  P._AddStreamState_cancel_closure.prototype = {
    call$0: function() {
      this.$this.addStreamFuture._asyncComplete$1(null);
    },
    $signature: 0
  };
  P._StreamControllerAddStreamState.prototype = {};
  P._BufferingStreamSubscription.prototype = {
    _BufferingStreamSubscription$4: function(onData, onError, onDone, cancelOnError, $T) {
      this.onData$1(onData);
      this.onError$1(0, onError);
      this.onDone$1(onDone);
    },
    _setPendingEvents$1: function(pendingEvents) {
      var _this = this;
      H._instanceType(_this)._eval$1("_PendingEvents<_BufferingStreamSubscription.T>")._check(pendingEvents);
      H.assertHelper(_this._pending == null);
      if (pendingEvents == null)
        return;
      _this.set$_pending(pendingEvents);
      if (!pendingEvents.get$isEmpty(pendingEvents)) {
        _this._state = (_this._state | 64) >>> 0;
        _this._pending.schedule$1(_this);
      }
    },
    onData$1: function(handleData) {
      var t1 = H._instanceType(this);
      t1._eval$1("~(_BufferingStreamSubscription.T)")._check(handleData);
      if (handleData == null)
        handleData = P.async___nullDataHandler$closure();
      this.set$_onData(this._zone.registerUnaryCallback$2$1(handleData, type$.dynamic, t1._eval$1("_BufferingStreamSubscription.T")));
    },
    onError$1: function(_, handleError) {
      var _this = this;
      if (handleError == null)
        handleError = P.async___nullErrorHandler$closure();
      if (type$.void_Function_Object_StackTrace._is(handleError))
        _this._onError = _this._zone.registerBinaryCallback$3$1(handleError, type$.dynamic, type$.Object, type$.StackTrace);
      else if (type$.void_Function_Object._is(handleError))
        _this._onError = _this._zone.registerUnaryCallback$2$1(handleError, type$.dynamic, type$.Object);
      else
        throw H.wrapException(P.ArgumentError$("handleError callback must take either an Object (the error), or both an Object (the error) and a StackTrace."));
    },
    onDone$1: function(handleDone) {
      type$.void_Function._check(handleDone);
      if (handleDone == null)
        handleDone = P.async___nullDoneHandler$closure();
      this.set$_onDone(this._zone.registerCallback$1$1(handleDone, type$.void));
    },
    pause$1: function(resumeSignal) {
      var t2, t3, _this = this,
        t1 = _this._state;
      if ((t1 & 8) !== 0)
        return;
      t2 = (t1 + 128 | 4) >>> 0;
      _this._state = t2;
      if (t1 < 128 && _this._pending != null) {
        t3 = _this._pending;
        if (t3._state === 1)
          t3._state = 3;
      }
      if ((t1 & 4) === 0 && (t2 & 32) === 0)
        _this._guardCallback$1(_this.get$_onPause());
    },
    pause$0: function() {
      return this.pause$1(null);
    },
    resume$0: function() {
      var _this = this,
        t1 = _this._state;
      if ((t1 & 8) !== 0)
        return;
      if (t1 >= 128) {
        t1 = _this._state -= 128;
        if (t1 < 128) {
          if ((t1 & 64) !== 0) {
            t1 = _this._pending;
            t1 = !t1.get$isEmpty(t1);
          } else
            t1 = false;
          if (t1)
            _this._pending.schedule$1(_this);
          else {
            H.assertHelper(_this.get$_mayResumeInput());
            t1 = (_this._state & 4294967291) >>> 0;
            _this._state = t1;
            if ((t1 & 32) === 0)
              _this._guardCallback$1(_this.get$_onResume());
          }
        }
      }
    },
    cancel$0: function() {
      var _this = this,
        t1 = (_this._state & 4294967279) >>> 0;
      _this._state = t1;
      if ((t1 & 8) === 0)
        _this._cancel$0();
      t1 = _this._cancelFuture;
      return t1 == null ? $.$get$Future__nullFuture() : t1;
    },
    get$_mayResumeInput: function() {
      if (this._state < 128) {
        var t1 = this._pending;
        t1 = t1 == null || t1.get$isEmpty(t1);
      } else
        t1 = false;
      return t1;
    },
    get$isPaused: function() {
      return this._state >= 128;
    },
    _cancel$0: function() {
      var t2, _this = this,
        t1 = _this._state = (_this._state | 8) >>> 0;
      if ((t1 & 64) !== 0) {
        t2 = _this._pending;
        if (t2._state === 1)
          t2._state = 3;
      }
      if ((t1 & 32) === 0)
        _this.set$_pending(null);
      _this._cancelFuture = _this._onCancel$0();
    },
    _add$1: function(data) {
      var t2, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("_BufferingStreamSubscription.T")._check(data);
      H.assertHelper((_this._state & 2) === 0);
      t2 = _this._state;
      if ((t2 & 8) !== 0)
        return;
      if (t2 < 32)
        _this._sendData$1(data);
      else
        _this._addPending$1(new P._DelayedData(data, t1._eval$1("_DelayedData<_BufferingStreamSubscription.T>")));
    },
    _async$_addError$2: function(error, stackTrace) {
      var t1 = this._state;
      if ((t1 & 8) !== 0)
        return;
      if (t1 < 32)
        this._sendError$2(error, stackTrace);
      else
        this._addPending$1(new P._DelayedError(error, stackTrace));
    },
    _close$0: function() {
      var t1, _this = this;
      H.assertHelper((_this._state & 2) === 0);
      t1 = _this._state;
      if ((t1 & 8) !== 0)
        return;
      t1 = (t1 | 2) >>> 0;
      _this._state = t1;
      if (t1 < 32)
        _this._sendDone$0();
      else
        _this._addPending$1(C.C__DelayedDone);
    },
    _onPause$0: function() {
      H.assertHelper((this._state & 4) !== 0);
    },
    _onResume$0: function() {
      H.assertHelper((this._state & 4) === 0);
    },
    _onCancel$0: function() {
      H.assertHelper((this._state & 8) !== 0);
      return null;
    },
    _addPending$1: function($event) {
      var _this = this,
        t1 = H._instanceType(_this)._eval$1("_StreamImplEvents<_BufferingStreamSubscription.T>"),
        pending = t1._check(_this._pending);
      if (pending == null) {
        pending = new P._StreamImplEvents(t1);
        _this.set$_pending(pending);
      }
      pending.add$1(0, $event);
      t1 = _this._state;
      if ((t1 & 64) === 0) {
        t1 = (t1 | 64) >>> 0;
        _this._state = t1;
        if (t1 < 128)
          _this._pending.schedule$1(_this);
      }
    },
    _sendData$1: function(data) {
      var t2, _this = this,
        t1 = H._instanceType(_this)._eval$1("_BufferingStreamSubscription.T");
      t1._check(data);
      H.assertHelper((_this._state & 8) === 0);
      H.assertHelper(_this._state < 128);
      H.assertHelper((_this._state & 32) === 0);
      t2 = _this._state;
      _this._state = (t2 | 32) >>> 0;
      _this._zone.runUnaryGuarded$1$2(_this._onData, data, t1);
      _this._state = (_this._state & 4294967263) >>> 0;
      _this._checkState$1((t2 & 4) !== 0);
    },
    _sendError$2: function(error, stackTrace) {
      var t1, t2, _this = this;
      type$.StackTrace._check(stackTrace);
      H.assertHelper((_this._state & 8) === 0);
      H.assertHelper(_this._state < 128);
      H.assertHelper((_this._state & 32) === 0);
      t1 = _this._state;
      t2 = new P._BufferingStreamSubscription__sendError_sendError(_this, error, stackTrace);
      if ((t1 & 1) !== 0) {
        _this._state = (t1 | 16) >>> 0;
        _this._cancel$0();
        t1 = _this._cancelFuture;
        if (t1 != null && t1 !== $.$get$Future__nullFuture())
          t1.whenComplete$1(t2);
        else
          t2.call$0();
      } else {
        t2.call$0();
        _this._checkState$1((t1 & 4) !== 0);
      }
    },
    _sendDone$0: function() {
      var t1, t2, _this = this;
      H.assertHelper((_this._state & 8) === 0);
      H.assertHelper(_this._state < 128);
      H.assertHelper((_this._state & 32) === 0);
      t1 = new P._BufferingStreamSubscription__sendDone_sendDone(_this);
      _this._cancel$0();
      _this._state = (_this._state | 16) >>> 0;
      t2 = _this._cancelFuture;
      if (t2 != null && t2 !== $.$get$Future__nullFuture())
        t2.whenComplete$1(t1);
      else
        t1.call$0();
    },
    _guardCallback$1: function(callback) {
      var t1, _this = this;
      type$.void_Function._check(callback);
      H.assertHelper((_this._state & 32) === 0);
      t1 = _this._state;
      _this._state = (t1 | 32) >>> 0;
      callback.call$0();
      _this._state = (_this._state & 4294967263) >>> 0;
      _this._checkState$1((t1 & 4) !== 0);
    },
    _checkState$1: function(wasInputPaused) {
      var t1, isInputPaused, _this = this;
      H.assertHelper((_this._state & 32) === 0);
      if ((_this._state & 64) !== 0) {
        t1 = _this._pending;
        t1 = t1.get$isEmpty(t1);
      } else
        t1 = false;
      if (t1) {
        t1 = (_this._state & 4294967231) >>> 0;
        _this._state = t1;
        if ((t1 & 4) !== 0 && _this.get$_mayResumeInput())
          _this._state = (_this._state & 4294967291) >>> 0;
      }
      for (; true; wasInputPaused = isInputPaused) {
        t1 = _this._state;
        if ((t1 & 8) !== 0) {
          _this.set$_pending(null);
          return;
        }
        isInputPaused = (t1 & 4) !== 0;
        if (wasInputPaused === isInputPaused)
          break;
        _this._state = (t1 ^ 32) >>> 0;
        if (isInputPaused)
          _this._onPause$0();
        else
          _this._onResume$0();
        _this._state = (_this._state & 4294967263) >>> 0;
      }
      t1 = _this._state;
      if ((t1 & 64) !== 0 && t1 < 128)
        _this._pending.schedule$1(_this);
    },
    set$_onData: function(_onData) {
      this._onData = H._instanceType(this)._eval$1("~(_BufferingStreamSubscription.T)")._check(_onData);
    },
    set$_onDone: function(_onDone) {
      this._onDone = type$.void_Function._check(_onDone);
    },
    set$_pending: function(_pending) {
      this._pending = H._instanceType(this)._eval$1("_PendingEvents<_BufferingStreamSubscription.T>")._check(_pending);
    },
    $isStreamSubscription: 1,
    $is_EventDispatch: 1
  };
  P._BufferingStreamSubscription__sendError_sendError.prototype = {
    call$0: function() {
      var onError, t3, t4, t5,
        t1 = this.$this,
        t2 = t1._state;
      if ((t2 & 8) !== 0 && (t2 & 16) === 0)
        return;
      t1._state = (t2 | 32) >>> 0;
      onError = t1._onError;
      t2 = this.error;
      t3 = type$.Object;
      t4 = t1._zone;
      if (type$.void_Function_Object_StackTrace._is(onError))
        t4.runBinaryGuarded$2$3(onError, t2, this.stackTrace, t3, type$.StackTrace);
      else {
        t5 = type$.void_Function_Object;
        H.assertHelper(t5._is(onError));
        t4.runUnaryGuarded$1$2(t5._check(t1._onError), t2, t3);
      }
      t1._state = (t1._state & 4294967263) >>> 0;
    },
    $signature: 1
  };
  P._BufferingStreamSubscription__sendDone_sendDone.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._state;
      if ((t2 & 16) === 0)
        return;
      t1._state = (t2 | 42) >>> 0;
      t1._zone.runGuarded$1(t1._onDone);
      t1._state = (t1._state & 4294967263) >>> 0;
    },
    $signature: 1
  };
  P._StreamImpl.prototype = {
    listen$4$cancelOnError$onDone$onError: function(onData, cancelOnError, onDone, onError) {
      return this._createSubscription$4(H._instanceType(this)._eval$1("~(1)")._check(onData), onError, type$.void_Function._check(onDone), true === H._checkBoolNullable(cancelOnError));
    },
    listen$2$onDone: function(onData, onDone) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, null);
    },
    listen$3$onDone$onError: function(onData, onDone, onError) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, onError);
    },
    listen$1: function(onData) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, null, null);
    },
    _createSubscription$4: function(onData, onError, onDone, cancelOnError) {
      var t1 = H._instanceType(this);
      return P._BufferingStreamSubscription$(t1._eval$1("~(1)")._check(onData), onError, type$.void_Function._check(onDone), cancelOnError, t1._precomputed1);
    }
  };
  P._GeneratedStreamImpl.prototype = {
    _createSubscription$4: function(onData, onError, onDone, cancelOnError) {
      var _this = this,
        t1 = _this.$ti;
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      if (_this._isUsed)
        throw H.wrapException(P.StateError$("Stream has already been listened to."));
      _this._isUsed = true;
      t1 = P._BufferingStreamSubscription$(onData, onError, onDone, cancelOnError, t1._precomputed1);
      t1._setPendingEvents$1(_this._pending.call$0());
      return t1;
    }
  };
  P._IterablePendingEvents.prototype = {
    get$isEmpty: function(_) {
      return this._async$_iterator == null;
    },
    handleNext$1: function(dispatch) {
      var hasMore, e, s, t1, exception, _this = this;
      _this.$ti._eval$1("_EventDispatch<1>")._check(dispatch);
      t1 = _this._async$_iterator;
      if (t1 == null)
        throw H.wrapException(P.StateError$("No events pending."));
      hasMore = null;
      try {
        hasMore = t1.moveNext$0();
        if (H.boolConversionCheck(hasMore))
          dispatch._sendData$1(_this._async$_iterator.get$current());
        else {
          _this.set$_async$_iterator(null);
          dispatch._sendDone$0();
        }
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        if (hasMore == null) {
          _this.set$_async$_iterator(C.C_EmptyIterator);
          dispatch._sendError$2(e, s);
        } else
          dispatch._sendError$2(e, s);
      }
    },
    set$_async$_iterator: function(_iterator) {
      this._async$_iterator = this.$ti._eval$1("Iterator<1>")._check(_iterator);
    }
  };
  P._DelayedEvent.prototype = {
    set$next: function(next) {
      this.next = type$._DelayedEvent_dynamic._check(next);
    },
    get$next: function() {
      return this.next;
    }
  };
  P._DelayedData.prototype = {
    perform$1: function(dispatch) {
      this.$ti._eval$1("_EventDispatch<1>")._check(dispatch)._sendData$1(this.value);
    }
  };
  P._DelayedError.prototype = {
    perform$1: function(dispatch) {
      dispatch._sendError$2(this.error, this.stackTrace);
    }
  };
  P._DelayedDone.prototype = {
    perform$1: function(dispatch) {
      dispatch._sendDone$0();
    },
    get$next: function() {
      return null;
    },
    set$next: function(_) {
      throw H.wrapException(P.StateError$("No events after a done."));
    },
    $is_DelayedEvent: 1
  };
  P._PendingEvents.prototype = {
    schedule$1: function(dispatch) {
      var t1, _this = this;
      H._instanceType(_this)._eval$1("_EventDispatch<1>")._check(dispatch);
      if (_this._state === 1)
        return;
      H.assertHelper(!_this.get$isEmpty(_this));
      t1 = _this._state;
      if (t1 >= 1) {
        H.assertHelper(t1 === 3);
        _this._state = 1;
        return;
      }
      P.scheduleMicrotask(new P._PendingEvents_schedule_closure(_this, dispatch));
      _this._state = 1;
    }
  };
  P._PendingEvents_schedule_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        oldState = t1._state;
      t1._state = 0;
      if (oldState === 3)
        return;
      t1.handleNext$1(this.dispatch);
    },
    $signature: 0
  };
  P._StreamImplEvents.prototype = {
    get$isEmpty: function(_) {
      return this.lastPendingEvent == null;
    },
    add$1: function(_, $event) {
      var _this = this,
        t1 = _this.lastPendingEvent;
      if (t1 == null)
        _this.firstPendingEvent = _this.lastPendingEvent = $event;
      else {
        t1.set$next($event);
        _this.lastPendingEvent = $event;
      }
    },
    handleNext$1: function(dispatch) {
      var $event, t1, _this = this;
      _this.$ti._eval$1("_EventDispatch<1>")._check(dispatch);
      H.assertHelper(_this._state !== 1);
      $event = _this.firstPendingEvent;
      t1 = $event.get$next();
      _this.firstPendingEvent = t1;
      if (t1 == null)
        _this.lastPendingEvent = null;
      $event.perform$1(dispatch);
    }
  };
  P._DoneStreamSubscription.prototype = {
    get$isPaused: function() {
      return this._state >= 4;
    },
    _schedule$0: function() {
      var _this = this;
      if ((_this._state & 2) !== 0)
        return;
      _this._zone.scheduleMicrotask$1(_this.get$_sendDone());
      _this._state = (_this._state | 2) >>> 0;
    },
    onData$1: function(handleData) {
      this.$ti._eval$1("~(1)")._check(handleData);
    },
    onError$1: function(_, handleError) {
    },
    onDone$1: function(handleDone) {
      this.set$_onDone(type$.void_Function._check(handleDone));
    },
    pause$1: function(resumeSignal) {
      this._state += 4;
    },
    pause$0: function() {
      return this.pause$1(null);
    },
    resume$0: function() {
      var t1 = this._state;
      if (t1 >= 4) {
        t1 = this._state = t1 - 4;
        if (t1 < 4 && (t1 & 1) === 0)
          this._schedule$0();
      }
    },
    cancel$0: function() {
      return $.$get$Future__nullFuture();
    },
    _sendDone$0: function() {
      var _this = this,
        t1 = _this._state = (_this._state & 4294967293) >>> 0;
      if (t1 >= 4)
        return;
      _this._state = (t1 | 1) >>> 0;
      t1 = _this._onDone;
      if (t1 != null)
        _this._zone.runGuarded$1(t1);
    },
    set$_onDone: function(_onDone) {
      this._onDone = type$.void_Function._check(_onDone);
    },
    $isStreamSubscription: 1
  };
  P._StreamIterator.prototype = {};
  P._EmptyStream.prototype = {
    get$isBroadcast: function() {
      return true;
    },
    listen$4$cancelOnError$onDone$onError: function(onData, cancelOnError, onDone, onError) {
      var t1 = this.$ti;
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      H._checkBoolNullable(cancelOnError);
      t1 = new P._DoneStreamSubscription($.Zone__current, onDone, t1._eval$1("_DoneStreamSubscription<1>"));
      t1._schedule$0();
      return t1;
    },
    listen$3$onDone$onError: function(onData, onDone, onError) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, onError);
    },
    listen$1: function(onData) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, null, null);
    }
  };
  P._cancelAndError_closure.prototype = {
    call$0: function() {
      return this.future._completeError$2(this.error, this.stackTrace);
    },
    $signature: 1
  };
  P._cancelAndErrorClosure_closure.prototype = {
    call$2: function(error, stackTrace) {
      P._cancelAndError(this.subscription, this.future, error, type$.StackTrace._check(stackTrace));
    },
    $signature: 5
  };
  P._cancelAndValue_closure.prototype = {
    call$0: function() {
      return this.future._complete$1(this.value);
    },
    $signature: 1
  };
  P.Timer.prototype = {};
  P.AsyncError.prototype = {
    toString$0: function(_) {
      return H.S(this.error);
    },
    $isError: 1
  };
  P._ZoneFunction.prototype = {};
  P.ZoneSpecification.prototype = {};
  P._ZoneSpecification.prototype = {$isZoneSpecification: 1};
  P.ZoneDelegate.prototype = {};
  P.Zone.prototype = {};
  P._ZoneDelegate.prototype = {
    handleUncaughtError$3: function(zone, error, stackTrace) {
      var implementation, implZone;
      type$.StackTrace._check(stackTrace);
      implementation = this._delegationTarget.get$_handleUncaughtError();
      implZone = implementation.zone;
      return implementation.$function.call$5(implZone, P._parentDelegate(implZone), zone, error, stackTrace);
    },
    registerCallback$1$2: function(zone, f, $R) {
      var implementation, implZone;
      $R._eval$1("0()")._check(f);
      implementation = this._delegationTarget.get$_registerCallback();
      implZone = implementation.zone;
      return type$.A_Function_Function_A_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function._check(implementation.$function).call$1$4(implZone, P._parentDelegate(implZone), zone, f, $R);
    },
    registerUnaryCallback$2$2: function(zone, f, $R, $T) {
      var implementation, implZone;
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
      implementation = this._delegationTarget.get$_registerUnaryCallback();
      implZone = implementation.zone;
      return type$.A_Function_B_Function_A_and_B_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_B._check(implementation.$function).call$2$4(implZone, P._parentDelegate(implZone), zone, f, $R, $T);
    },
    registerBinaryCallback$3$2: function(zone, f, $R, T1, T2) {
      var implementation, implZone;
      $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
      implementation = this._delegationTarget.get$_registerBinaryCallback();
      implZone = implementation.zone;
      return type$.A_Function_2_B_and_C_Function_A_and_B_and_C_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_2_B_and_C._check(implementation.$function).call$3$4(implZone, P._parentDelegate(implZone), zone, f, $R, T1, T2);
    },
    errorCallback$3: function(zone, error, stackTrace) {
      var implementation = this._delegationTarget.get$_errorCallback(),
        implZone = implementation.zone;
      if (implZone === C.C__RootZone)
        return null;
      return implementation.$function.call$5(implZone, P._parentDelegate(implZone), zone, error, stackTrace);
    },
    $isZoneDelegate: 1
  };
  P._Zone.prototype = {$isZone: 1};
  P._CustomZone.prototype = {
    get$_delegate: function() {
      var t1 = this._delegateCache;
      if (t1 != null)
        return t1;
      return this._delegateCache = new P._ZoneDelegate(this);
    },
    get$errorZone: function() {
      return this._handleUncaughtError.zone;
    },
    runGuarded$1: function(f) {
      var e, s, exception;
      type$.void_Function._check(f);
      try {
        this.run$1$1(f, type$.void);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        this.handleUncaughtError$2(e, s);
      }
    },
    runUnaryGuarded$1$2: function(f, arg, $T) {
      var e, s, exception;
      $T._eval$1("~(0)")._check(f);
      $T._check(arg);
      try {
        this.runUnary$2$2(f, arg, type$.void, $T);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        this.handleUncaughtError$2(e, s);
      }
    },
    runBinaryGuarded$2$3: function(f, arg1, arg2, T1, T2) {
      var e, s, exception;
      T1._eval$1("@<0>")._bind$1(T2)._eval$1("~(1,2)")._check(f);
      T1._check(arg1);
      T2._check(arg2);
      try {
        this.runBinary$3$3(f, arg1, arg2, type$.void, T1, T2);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        this.handleUncaughtError$2(e, s);
      }
    },
    bindCallback$1$1: function(f, $R) {
      return new P._CustomZone_bindCallback_closure(this, this.registerCallback$1$1($R._eval$1("0()")._check(f), $R), $R);
    },
    bindUnaryCallback$2$1: function(f, $R, $T) {
      return new P._CustomZone_bindUnaryCallback_closure(this, this.registerUnaryCallback$2$1($R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f), $R, $T), $T, $R);
    },
    bindCallbackGuarded$1: function(f) {
      return new P._CustomZone_bindCallbackGuarded_closure(this, this.registerCallback$1$1(type$.void_Function._check(f), type$.void));
    },
    bindUnaryCallbackGuarded$1$1: function(f, $T) {
      return new P._CustomZone_bindUnaryCallbackGuarded_closure(this, this.registerUnaryCallback$2$1($T._eval$1("~(0)")._check(f), type$.void, $T), $T);
    },
    $index: function(_, key) {
      var value,
        t1 = this._async$_map,
        result = t1.$index(0, key);
      if (result != null || t1.containsKey$1(key))
        return result;
      value = this.parent.$index(0, key);
      if (value != null)
        t1.$indexSet(0, key, value);
      return value;
    },
    handleUncaughtError$2: function(error, stackTrace) {
      var implementation, t1, parentDelegate;
      type$.StackTrace._check(stackTrace);
      implementation = this._handleUncaughtError;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return implementation.$function.call$5(t1, parentDelegate, this, error, stackTrace);
    },
    fork$2$specification$zoneValues: function(specification, zoneValues) {
      var t1, parentDelegate,
        implementation = this._fork;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return implementation.$function.call$5(t1, parentDelegate, this, specification, zoneValues);
    },
    run$1$1: function(f, $R) {
      var implementation, t1, parentDelegate;
      $R._eval$1("0()")._check(f);
      implementation = this._run;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_A_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function._check(implementation.$function).call$1$4(t1, parentDelegate, this, f, $R);
    },
    runUnary$2$2: function(f, arg, $R, $T) {
      var implementation, t1, parentDelegate;
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
      $T._check(arg);
      implementation = this._runUnary;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_A_and_B_5_Zone_and_ZoneDelegate_and_Zone_and_A_Function_B_and_B._check(implementation.$function).call$2$5(t1, parentDelegate, this, f, arg, $R, $T);
    },
    runBinary$3$3: function(f, arg1, arg2, $R, T1, T2) {
      var implementation, t1, parentDelegate;
      $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
      T1._check(arg1);
      T2._check(arg2);
      implementation = this._runBinary;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_A_and_B_and_C_6_Zone_and_ZoneDelegate_and_Zone_and_A_Function_2_B_and_C_and_B_and_C._check(implementation.$function).call$3$6(t1, parentDelegate, this, f, arg1, arg2, $R, T1, T2);
    },
    registerCallback$1$1: function(callback, $R) {
      var implementation, t1, parentDelegate;
      $R._eval$1("0()")._check(callback);
      implementation = this._registerCallback;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_Function_A_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function._check(implementation.$function).call$1$4(t1, parentDelegate, this, callback, $R);
    },
    registerUnaryCallback$2$1: function(callback, $R, $T) {
      var implementation, t1, parentDelegate;
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(callback);
      implementation = this._registerUnaryCallback;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_B_Function_A_and_B_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_B._check(implementation.$function).call$2$4(t1, parentDelegate, this, callback, $R, $T);
    },
    registerBinaryCallback$3$1: function(callback, $R, T1, T2) {
      var implementation, t1, parentDelegate;
      $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(callback);
      implementation = this._registerBinaryCallback;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return type$.A_Function_2_B_and_C_Function_A_and_B_and_C_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_2_B_and_C._check(implementation.$function).call$3$4(t1, parentDelegate, this, callback, $R, T1, T2);
    },
    errorCallback$2: function(error, stackTrace) {
      var implementation, implementationZone, parentDelegate;
      type$.StackTrace._check(stackTrace);
      implementation = this._errorCallback;
      H.assertHelper(implementation != null);
      implementationZone = implementation.zone;
      if (implementationZone === C.C__RootZone)
        return null;
      parentDelegate = P._parentDelegate(implementationZone);
      return implementation.$function.call$5(implementationZone, parentDelegate, this, error, stackTrace);
    },
    scheduleMicrotask$1: function(f) {
      var implementation, t1, parentDelegate;
      type$.void_Function._check(f);
      implementation = this._scheduleMicrotask;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return implementation.$function.call$4(t1, parentDelegate, this, f);
    },
    createTimer$2: function(duration, f) {
      var implementation, t1, parentDelegate;
      type$.void_Function._check(f);
      implementation = this._createTimer;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return implementation.$function.call$5(t1, parentDelegate, this, duration, f);
    },
    print$1: function(_, line) {
      var t1, parentDelegate,
        implementation = this._print;
      H.assertHelper(implementation != null);
      t1 = implementation.zone;
      parentDelegate = P._parentDelegate(t1);
      return implementation.$function.call$4(t1, parentDelegate, this, line);
    },
    set$_run: function(_run) {
      this._run = type$._ZoneFunction_Function._check(_run);
    },
    set$_runUnary: function(_runUnary) {
      this._runUnary = type$._ZoneFunction_Function._check(_runUnary);
    },
    set$_runBinary: function(_runBinary) {
      this._runBinary = type$._ZoneFunction_Function._check(_runBinary);
    },
    set$_registerCallback: function(_registerCallback) {
      this._registerCallback = type$._ZoneFunction_Function._check(_registerCallback);
    },
    set$_registerUnaryCallback: function(_registerUnaryCallback) {
      this._registerUnaryCallback = type$._ZoneFunction_Function._check(_registerUnaryCallback);
    },
    set$_registerBinaryCallback: function(_registerBinaryCallback) {
      this._registerBinaryCallback = type$._ZoneFunction_Function._check(_registerBinaryCallback);
    },
    set$_errorCallback: function(_errorCallback) {
      this._errorCallback = type$._ZoneFunction_of_AsyncError_Function_Zone_ZoneDelegate_Zone_Object_StackTrace._check(_errorCallback);
    },
    set$_scheduleMicrotask: function(_scheduleMicrotask) {
      this._scheduleMicrotask = type$._ZoneFunction_of_void_Function_4_Zone_and_ZoneDelegate_and_Zone_and_void_Function._check(_scheduleMicrotask);
    },
    set$_createTimer: function(_createTimer) {
      this._createTimer = type$._ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function._check(_createTimer);
    },
    set$_createPeriodicTimer: function(_createPeriodicTimer) {
      this._createPeriodicTimer = type$._ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function_Timer._check(_createPeriodicTimer);
    },
    set$_print: function(_print) {
      this._print = type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_String._check(_print);
    },
    set$_fork: function(_fork) {
      this._fork = type$._ZoneFunction_of_Zone_Function_5_Zone_and_ZoneDelegate_and_Zone_and_ZoneSpecification_and_Map_dynamic_dynamic._check(_fork);
    },
    set$_handleUncaughtError: function(_handleUncaughtError) {
      this._handleUncaughtError = type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_Object_StackTrace._check(_handleUncaughtError);
    },
    get$_run: function() {
      return this._run;
    },
    get$_runUnary: function() {
      return this._runUnary;
    },
    get$_runBinary: function() {
      return this._runBinary;
    },
    get$_registerCallback: function() {
      return this._registerCallback;
    },
    get$_registerUnaryCallback: function() {
      return this._registerUnaryCallback;
    },
    get$_registerBinaryCallback: function() {
      return this._registerBinaryCallback;
    },
    get$_errorCallback: function() {
      return this._errorCallback;
    },
    get$_scheduleMicrotask: function() {
      return this._scheduleMicrotask;
    },
    get$_createTimer: function() {
      return this._createTimer;
    },
    get$_createPeriodicTimer: function() {
      return this._createPeriodicTimer;
    },
    get$_print: function() {
      return this._print;
    },
    get$_fork: function() {
      return this._fork;
    },
    get$_handleUncaughtError: function() {
      return this._handleUncaughtError;
    },
    get$parent: function(receiver) {
      return this.parent;
    },
    get$_async$_map: function() {
      return this._async$_map;
    }
  };
  P._CustomZone_bindCallback_closure.prototype = {
    call$0: function() {
      return this.$this.run$1$1(this.registered, this.R);
    },
    $signature: function() {
      return this.R._eval$1("0()");
    }
  };
  P._CustomZone_bindUnaryCallback_closure.prototype = {
    call$1: function(arg) {
      var _this = this,
        t1 = _this.T;
      return _this.$this.runUnary$2$2(_this.registered, t1._check(arg), _this.R, t1);
    },
    $signature: function() {
      return this.R._eval$1("@<0>")._bind$1(this.T)._eval$1("1(2)");
    }
  };
  P._CustomZone_bindCallbackGuarded_closure.prototype = {
    call$0: function() {
      return this.$this.runGuarded$1(this.registered);
    },
    $signature: 1
  };
  P._CustomZone_bindUnaryCallbackGuarded_closure.prototype = {
    call$1: function(arg) {
      var t1 = this.T;
      return this.$this.runUnaryGuarded$1$2(this.registered, t1._check(arg), t1);
    },
    $signature: function() {
      return this.T._eval$1("~(0)");
    }
  };
  P._rootHandleUncaughtError_closure.prototype = {
    call$0: function() {
      var error,
        t1 = this._box_0,
        t2 = t1.error;
      t1 = t2 == null ? t1.error = new P.NullThrownError() : t2;
      t2 = this.stackTrace;
      if (t2 == null)
        throw H.wrapException(t1);
      error = H.wrapException(t1);
      error.stack = t2.toString$0(0);
      throw error;
    },
    $signature: 0
  };
  P._RootZone.prototype = {
    get$_run: function() {
      return C._ZoneFunction__RootZone__rootRun;
    },
    get$_runUnary: function() {
      return C._ZoneFunction__RootZone__rootRunUnary;
    },
    get$_runBinary: function() {
      return C._ZoneFunction__RootZone__rootRunBinary;
    },
    get$_registerCallback: function() {
      return C._ZoneFunction__RootZone__rootRegisterCallback;
    },
    get$_registerUnaryCallback: function() {
      return C._ZoneFunction_Eeh;
    },
    get$_registerBinaryCallback: function() {
      return C._ZoneFunction_7G2;
    },
    get$_errorCallback: function() {
      return C._ZoneFunction__RootZone__rootErrorCallback;
    },
    get$_scheduleMicrotask: function() {
      return C._ZoneFunction__RootZone__rootScheduleMicrotask;
    },
    get$_createTimer: function() {
      return C._ZoneFunction__RootZone__rootCreateTimer;
    },
    get$_createPeriodicTimer: function() {
      return C._ZoneFunction_3bB;
    },
    get$_print: function() {
      return C._ZoneFunction__RootZone__rootPrint;
    },
    get$_fork: function() {
      return C._ZoneFunction__RootZone__rootFork;
    },
    get$_handleUncaughtError: function() {
      return C._ZoneFunction_NMc;
    },
    get$parent: function(_) {
      return null;
    },
    get$_async$_map: function() {
      return $.$get$_RootZone__rootMap();
    },
    get$_delegate: function() {
      var t1 = $._RootZone__rootDelegate;
      if (t1 != null)
        return t1;
      return $._RootZone__rootDelegate = new P._ZoneDelegate(this);
    },
    get$errorZone: function() {
      return this;
    },
    runGuarded$1: function(f) {
      var e, s, exception, _null = null;
      type$.void_Function._check(f);
      try {
        if (C.C__RootZone === $.Zone__current) {
          f.call$0();
          return;
        }
        P._rootRun(_null, _null, this, f, type$.void);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._rootHandleUncaughtError(_null, _null, this, e, type$.StackTrace._check(s));
      }
    },
    runUnaryGuarded$1$2: function(f, arg, $T) {
      var e, s, exception, _null = null;
      $T._eval$1("~(0)")._check(f);
      $T._check(arg);
      try {
        if (C.C__RootZone === $.Zone__current) {
          f.call$1(arg);
          return;
        }
        P._rootRunUnary(_null, _null, this, f, arg, type$.void, $T);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._rootHandleUncaughtError(_null, _null, this, e, type$.StackTrace._check(s));
      }
    },
    runBinaryGuarded$2$3: function(f, arg1, arg2, T1, T2) {
      var e, s, exception, _null = null;
      T1._eval$1("@<0>")._bind$1(T2)._eval$1("~(1,2)")._check(f);
      T1._check(arg1);
      T2._check(arg2);
      try {
        if (C.C__RootZone === $.Zone__current) {
          f.call$2(arg1, arg2);
          return;
        }
        P._rootRunBinary(_null, _null, this, f, arg1, arg2, type$.void, T1, T2);
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        P._rootHandleUncaughtError(_null, _null, this, e, type$.StackTrace._check(s));
      }
    },
    bindCallback$1$1: function(f, $R) {
      return new P._RootZone_bindCallback_closure(this, $R._eval$1("0()")._check(f), $R);
    },
    bindCallbackGuarded$1: function(f) {
      return new P._RootZone_bindCallbackGuarded_closure(this, type$.void_Function._check(f));
    },
    bindUnaryCallbackGuarded$1$1: function(f, $T) {
      return new P._RootZone_bindUnaryCallbackGuarded_closure(this, $T._eval$1("~(0)")._check(f), $T);
    },
    $index: function(_, key) {
      return null;
    },
    handleUncaughtError$2: function(error, stackTrace) {
      P._rootHandleUncaughtError(null, null, this, error, type$.StackTrace._check(stackTrace));
    },
    fork$2$specification$zoneValues: function(specification, zoneValues) {
      return P._rootFork(null, null, this, specification, zoneValues);
    },
    run$1$1: function(f, $R) {
      $R._eval$1("0()")._check(f);
      if ($.Zone__current === C.C__RootZone)
        return f.call$0();
      return P._rootRun(null, null, this, f, $R);
    },
    runUnary$2$2: function(f, arg, $R, $T) {
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
      $T._check(arg);
      if ($.Zone__current === C.C__RootZone)
        return f.call$1(arg);
      return P._rootRunUnary(null, null, this, f, arg, $R, $T);
    },
    runBinary$3$3: function(f, arg1, arg2, $R, T1, T2) {
      $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
      T1._check(arg1);
      T2._check(arg2);
      if ($.Zone__current === C.C__RootZone)
        return f.call$2(arg1, arg2);
      return P._rootRunBinary(null, null, this, f, arg1, arg2, $R, T1, T2);
    },
    registerCallback$1$1: function(f, $R) {
      return $R._eval$1("0()")._check(f);
    },
    registerUnaryCallback$2$1: function(f, $R, $T) {
      return $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
    },
    registerBinaryCallback$3$1: function(f, $R, T1, T2) {
      return $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f);
    },
    errorCallback$2: function(error, stackTrace) {
      type$.StackTrace._check(stackTrace);
      return null;
    },
    scheduleMicrotask$1: function(f) {
      P._rootScheduleMicrotask(null, null, this, type$.void_Function._check(f));
    },
    createTimer$2: function(duration, f) {
      return P.Timer__createTimer(duration, type$.void_Function._check(f));
    },
    print$1: function(_, line) {
      H.printString(line);
    }
  };
  P._RootZone_bindCallback_closure.prototype = {
    call$0: function() {
      return this.$this.run$1$1(this.f, this.R);
    },
    $signature: function() {
      return this.R._eval$1("0()");
    }
  };
  P._RootZone_bindCallbackGuarded_closure.prototype = {
    call$0: function() {
      return this.$this.runGuarded$1(this.f);
    },
    $signature: 1
  };
  P._RootZone_bindUnaryCallbackGuarded_closure.prototype = {
    call$1: function(arg) {
      var t1 = this.T;
      return this.$this.runUnaryGuarded$1$2(this.f, t1._check(arg), t1);
    },
    $signature: function() {
      return this.T._eval$1("~(0)");
    }
  };
  P.runZoned_closure.prototype = {
    call$5: function($self, $parent, zone, error, stackTrace) {
      var e, s, t2, t3, t4, exception,
        t1 = type$.StackTrace;
      t1._check(stackTrace);
      try {
        t2 = this._box_0;
        t3 = type$.void;
        t4 = type$.Object;
        if (t2.binaryOnError != null)
          $self.get$parent($self).runBinary$3$3(t2.binaryOnError, error, stackTrace, t3, t4, t1);
        else {
          H.assertHelper(t2.unaryOnError != null);
          $self.get$parent($self).runUnary$2$2(t2.unaryOnError, error, t3, t4);
        }
      } catch (exception) {
        e = H.unwrapException(exception);
        s = H.getTraceFromException(exception);
        t1 = e;
        if (t1 == null ? error == null : t1 === error)
          $parent.handleUncaughtError$3(zone, error, stackTrace);
        else
          $parent.handleUncaughtError$3(zone, e, s);
      }
    },
    $signature: 28
  };
  P._HashMap.prototype = {
    get$length: function(_) {
      return this._collection$_length;
    },
    get$isEmpty: function(_) {
      return this._collection$_length === 0;
    },
    get$keys: function() {
      return new P._HashMapKeyIterable(this, H._instanceType(this)._eval$1("_HashMapKeyIterable<1>"));
    },
    containsKey$1: function(key) {
      var strings, nums;
      if (typeof key == "string" && key !== "__proto__") {
        strings = this._strings;
        return strings == null ? false : strings[key] != null;
      } else if (typeof key == "number" && (key & 1073741823) === key) {
        nums = this._nums;
        return nums == null ? false : nums[key] != null;
      } else
        return this._containsKey$1(key);
    },
    _containsKey$1: function(key) {
      var rest = this._collection$_rest;
      if (rest == null)
        return false;
      return this._findBucketIndex$2(this._getBucket$2(rest, key), key) >= 0;
    },
    $index: function(_, key) {
      var strings, t1, nums;
      if (typeof key == "string" && key !== "__proto__") {
        strings = this._strings;
        t1 = strings == null ? null : P._HashMap__getTableEntry(strings, key);
        return t1;
      } else if (typeof key == "number" && (key & 1073741823) === key) {
        nums = this._nums;
        t1 = nums == null ? null : P._HashMap__getTableEntry(nums, key);
        return t1;
      } else
        return this._get$1(key);
    },
    _get$1: function(key) {
      var bucket, index,
        rest = this._collection$_rest;
      if (rest == null)
        return null;
      bucket = this._getBucket$2(rest, key);
      index = this._findBucketIndex$2(bucket, key);
      return index < 0 ? null : bucket[index + 1];
    },
    $indexSet: function(_, key, value) {
      var strings, nums, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      if (typeof key == "string" && key !== "__proto__") {
        strings = _this._strings;
        _this._addHashTableEntry$3(strings == null ? _this._strings = P._HashMap__newHashTable() : strings, key, value);
      } else if (typeof key == "number" && (key & 1073741823) === key) {
        nums = _this._nums;
        _this._addHashTableEntry$3(nums == null ? _this._nums = P._HashMap__newHashTable() : nums, key, value);
      } else
        _this._set$2(key, value);
    },
    _set$2: function(key, value) {
      var rest, hash, bucket, index, _this = this,
        t1 = H._instanceType(_this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      rest = _this._collection$_rest;
      if (rest == null)
        rest = _this._collection$_rest = P._HashMap__newHashTable();
      hash = _this._computeHashCode$1(key);
      bucket = rest[hash];
      if (bucket == null) {
        P._HashMap__setTableEntry(rest, hash, [key, value]);
        ++_this._collection$_length;
        _this._keys = null;
      } else {
        index = _this._findBucketIndex$2(bucket, key);
        if (index >= 0)
          bucket[index + 1] = value;
        else {
          bucket.push(key, value);
          ++_this._collection$_length;
          _this._keys = null;
        }
      }
    },
    remove$1: function(_, key) {
      var t1 = this._remove$1(key);
      return t1;
    },
    _remove$1: function(key) {
      var hash, bucket, index, result, _this = this,
        rest = _this._collection$_rest;
      if (rest == null)
        return null;
      hash = _this._computeHashCode$1(key);
      bucket = rest[hash];
      index = _this._findBucketIndex$2(bucket, key);
      if (index < 0)
        return null;
      --_this._collection$_length;
      _this._keys = null;
      result = bucket.splice(index, 2)[1];
      if (0 === bucket.length)
        delete rest[hash];
      return result;
    },
    forEach$1: function(_, action) {
      var keys, $length, i, key, _this = this,
        t1 = H._instanceType(_this);
      t1._eval$1("~(1,2)")._check(action);
      keys = _this._computeKeys$0();
      for ($length = keys.length, t1 = t1._precomputed1, i = 0; i < $length; ++i) {
        key = keys[i];
        action.call$2(t1._check(key), _this.$index(0, key));
        if (keys !== _this._keys)
          throw H.wrapException(P.ConcurrentModificationError$(_this));
      }
    },
    _computeKeys$0: function() {
      var result, strings, names, entries, index, i, nums, rest, bucket, $length, i0, _this = this,
        t1 = _this._keys;
      if (t1 != null)
        return t1;
      result = new Array(_this._collection$_length);
      result.fixed$length = Array;
      strings = _this._strings;
      if (strings != null) {
        names = Object.getOwnPropertyNames(strings);
        entries = names.length;
        for (index = 0, i = 0; i < entries; ++i) {
          result[index] = names[i];
          ++index;
        }
      } else
        index = 0;
      nums = _this._nums;
      if (nums != null) {
        names = Object.getOwnPropertyNames(nums);
        entries = names.length;
        for (i = 0; i < entries; ++i) {
          result[index] = +names[i];
          ++index;
        }
      }
      rest = _this._collection$_rest;
      if (rest != null) {
        names = Object.getOwnPropertyNames(rest);
        entries = names.length;
        for (i = 0; i < entries; ++i) {
          bucket = rest[names[i]];
          $length = bucket.length;
          for (i0 = 0; i0 < $length; i0 += 2) {
            result[index] = bucket[i0];
            ++index;
          }
        }
      }
      H.assertHelper(index === _this._collection$_length);
      return _this._keys = result;
    },
    _addHashTableEntry$3: function(table, key, value) {
      var t1 = H._instanceType(this);
      t1._precomputed1._check(key);
      t1._rest[1]._check(value);
      if (table[key] == null) {
        ++this._collection$_length;
        this._keys = null;
      }
      P._HashMap__setTableEntry(table, key, value);
    },
    _computeHashCode$1: function(key) {
      return J.get$hashCode$(key) & 1073741823;
    },
    _getBucket$2: function(table, key) {
      return table[this._computeHashCode$1(key)];
    },
    _findBucketIndex$2: function(bucket, key) {
      var $length, i;
      if (bucket == null)
        return -1;
      $length = bucket.length;
      for (i = 0; i < $length; i += 2)
        if (J.$eq$(bucket[i], key))
          return i;
      return -1;
    }
  };
  P._IdentityHashMap.prototype = {
    _computeHashCode$1: function(key) {
      return H.objectHashCode(key) & 1073741823;
    },
    _findBucketIndex$2: function(bucket, key) {
      var $length, i, t1;
      if (bucket == null)
        return -1;
      $length = bucket.length;
      for (i = 0; i < $length; i += 2) {
        t1 = bucket[i];
        if (t1 == null ? key == null : t1 === key)
          return i;
      }
      return -1;
    }
  };
  P._HashMapKeyIterable.prototype = {
    get$length: function(_) {
      return this._map._collection$_length;
    },
    get$isEmpty: function(_) {
      return this._map._collection$_length === 0;
    },
    get$iterator: function(_) {
      var t1 = this._map;
      return new P._HashMapKeyIterator(t1, t1._computeKeys$0(), this.$ti._eval$1("_HashMapKeyIterator<1>"));
    },
    contains$1: function(_, element) {
      return this._map.containsKey$1(element);
    }
  };
  P._HashMapKeyIterator.prototype = {
    get$current: function() {
      return this._collection$_current;
    },
    moveNext$0: function() {
      var _this = this,
        keys = _this._keys,
        offset = _this._offset,
        t1 = _this._map;
      if (keys !== t1._keys)
        throw H.wrapException(P.ConcurrentModificationError$(t1));
      else if (offset >= keys.length) {
        _this.set$_collection$_current(null);
        return false;
      } else {
        _this.set$_collection$_current(keys[offset]);
        _this._offset = offset + 1;
        return true;
      }
    },
    set$_collection$_current: function(_current) {
      this._collection$_current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  P._LinkedHashSet.prototype = {
    _newSet$0: function() {
      return new P._LinkedHashSet(H._instanceType(this)._eval$1("_LinkedHashSet<1>"));
    },
    get$iterator: function(_) {
      var _this = this,
        t1 = new P._LinkedHashSetIterator(_this, _this._collection$_modifications, H._instanceType(_this)._eval$1("_LinkedHashSetIterator<1>"));
      t1._collection$_cell = _this._collection$_first;
      return t1;
    },
    get$length: function(_) {
      return this._collection$_length;
    },
    get$isEmpty: function(_) {
      return this._collection$_length === 0;
    },
    contains$1: function(_, object) {
      var strings, nums;
      if (typeof object == "string" && object !== "__proto__") {
        strings = this._strings;
        if (strings == null)
          return false;
        return type$._LinkedHashSetCell._check(strings[object]) != null;
      } else if (typeof object == "number" && (object & 1073741823) === object) {
        nums = this._nums;
        if (nums == null)
          return false;
        return type$._LinkedHashSetCell._check(nums[object]) != null;
      } else
        return this._contains$1(object);
    },
    _contains$1: function(object) {
      var rest = this._collection$_rest;
      if (rest == null)
        return false;
      return this._findBucketIndex$2(rest[this._computeHashCode$1(object)], object) >= 0;
    },
    get$first: function(_) {
      var t1 = this._collection$_first;
      if (t1 == null)
        throw H.wrapException(P.StateError$("No elements"));
      return H._instanceType(this)._precomputed1._check(t1._element);
    },
    get$last: function(_) {
      var t1 = this._collection$_last;
      if (t1 == null)
        throw H.wrapException(P.StateError$("No elements"));
      return H._instanceType(this)._precomputed1._check(t1._element);
    },
    add$1: function(_, element) {
      var strings, nums, _this = this;
      H._instanceType(_this)._precomputed1._check(element);
      if (typeof element == "string" && element !== "__proto__") {
        strings = _this._strings;
        return _this._addHashTableEntry$2(strings == null ? _this._strings = P._LinkedHashSet__newHashTable() : strings, element);
      } else if (typeof element == "number" && (element & 1073741823) === element) {
        nums = _this._nums;
        return _this._addHashTableEntry$2(nums == null ? _this._nums = P._LinkedHashSet__newHashTable() : nums, element);
      } else
        return _this._collection$_add$1(element);
    },
    _collection$_add$1: function(element) {
      var rest, hash, bucket, t1, _this = this;
      H._instanceType(_this)._precomputed1._check(element);
      rest = _this._collection$_rest;
      if (rest == null)
        rest = _this._collection$_rest = P._LinkedHashSet__newHashTable();
      hash = _this._computeHashCode$1(element);
      bucket = rest[hash];
      if (bucket == null) {
        t1 = [_this._collection$_newLinkedCell$1(element)];
        H.assertHelper(t1 != null);
        rest[hash] = t1;
      } else {
        if (_this._findBucketIndex$2(bucket, element) >= 0)
          return false;
        bucket.push(_this._collection$_newLinkedCell$1(element));
      }
      return true;
    },
    remove$1: function(_, object) {
      var _this = this;
      if (typeof object == "string" && object !== "__proto__")
        return _this._removeHashTableEntry$2(_this._strings, object);
      else if (typeof object == "number" && (object & 1073741823) === object)
        return _this._removeHashTableEntry$2(_this._nums, object);
      else
        return _this._remove$1(object);
    },
    _remove$1: function(object) {
      var hash, bucket, index, cell, _this = this,
        rest = _this._collection$_rest;
      if (rest == null)
        return false;
      hash = _this._computeHashCode$1(object);
      bucket = rest[hash];
      index = _this._findBucketIndex$2(bucket, object);
      if (index < 0)
        return false;
      cell = bucket.splice(index, 1)[0];
      if (0 === bucket.length)
        delete rest[hash];
      _this._unlinkCell$1(cell);
      return true;
    },
    _addHashTableEntry$2: function(table, element) {
      H._instanceType(this)._precomputed1._check(element);
      if (type$._LinkedHashSetCell._check(table[element]) != null)
        return false;
      table[element] = this._collection$_newLinkedCell$1(element);
      return true;
    },
    _removeHashTableEntry$2: function(table, element) {
      var cell;
      if (table == null)
        return false;
      cell = type$._LinkedHashSetCell._check(table[element]);
      if (cell == null)
        return false;
      this._unlinkCell$1(cell);
      delete table[element];
      return true;
    },
    _collection$_modified$0: function() {
      this._collection$_modifications = 1073741823 & this._collection$_modifications + 1;
    },
    _collection$_newLinkedCell$1: function(element) {
      var last, _this = this,
        cell = new P._LinkedHashSetCell(H._instanceType(_this)._precomputed1._check(element));
      if (_this._collection$_first == null)
        _this._collection$_first = _this._collection$_last = cell;
      else {
        last = _this._collection$_last;
        cell._collection$_previous = last;
        _this._collection$_last = last._collection$_next = cell;
      }
      ++_this._collection$_length;
      _this._collection$_modified$0();
      return cell;
    },
    _unlinkCell$1: function(cell) {
      var _this = this,
        previous = cell._collection$_previous,
        next = cell._collection$_next;
      if (previous == null) {
        H.assertHelper(cell == _this._collection$_first);
        _this._collection$_first = next;
      } else
        previous._collection$_next = next;
      if (next == null) {
        H.assertHelper(cell == _this._collection$_last);
        _this._collection$_last = previous;
      } else
        next._collection$_previous = previous;
      --_this._collection$_length;
      _this._collection$_modified$0();
    },
    _computeHashCode$1: function(element) {
      return J.get$hashCode$(element) & 1073741823;
    },
    _findBucketIndex$2: function(bucket, element) {
      var $length, i;
      if (bucket == null)
        return -1;
      $length = bucket.length;
      for (i = 0; i < $length; ++i)
        if (J.$eq$(bucket[i]._element, element))
          return i;
      return -1;
    },
    $isLinkedHashSet: 1
  };
  P._LinkedHashSetCell.prototype = {};
  P._LinkedHashSetIterator.prototype = {
    get$current: function() {
      return this._collection$_current;
    },
    moveNext$0: function() {
      var _this = this,
        t1 = _this._set;
      if (_this._collection$_modifications !== t1._collection$_modifications)
        throw H.wrapException(P.ConcurrentModificationError$(t1));
      else {
        t1 = _this._collection$_cell;
        if (t1 == null) {
          _this.set$_collection$_current(null);
          return false;
        } else {
          _this.set$_collection$_current(_this.$ti._precomputed1._check(t1._element));
          _this._collection$_cell = _this._collection$_cell._collection$_next;
          return true;
        }
      }
    },
    set$_collection$_current: function(_current) {
      this._collection$_current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  P.UnmodifiableListView.prototype = {
    get$length: function(_) {
      var t1 = this._collection$_source;
      return t1.get$length(t1);
    },
    $index: function(_, index) {
      return this._collection$_source.$index(0, H._checkIntNullable(index));
    }
  };
  P.HashMap_HashMap$from_closure.prototype = {
    call$2: function(k, v) {
      this.result.$indexSet(0, this.K._check(k), this.V._check(v));
    },
    $signature: 6
  };
  P.IterableBase.prototype = {};
  P.LinkedHashMap_LinkedHashMap$from_closure.prototype = {
    call$2: function(k, v) {
      this.result.$indexSet(0, this.K._check(k), this.V._check(v));
    },
    $signature: 6
  };
  P.ListBase.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.ListMixin.prototype = {
    get$iterator: function(receiver) {
      return new H.ListIterator(receiver, this.get$length(receiver), H.instanceType(receiver)._eval$1("ListIterator<ListMixin.E>"));
    },
    elementAt$1: function(receiver, index) {
      return this.$index(receiver, index);
    },
    get$isEmpty: function(receiver) {
      return this.get$length(receiver) === 0;
    },
    get$first: function(receiver) {
      if (this.get$length(receiver) === 0)
        throw H.wrapException(H.IterableElementError_noElement());
      return this.$index(receiver, 0);
    },
    get$last: function(receiver) {
      if (this.get$length(receiver) === 0)
        throw H.wrapException(H.IterableElementError_noElement());
      return this.$index(receiver, this.get$length(receiver) - 1);
    },
    map$1$1: function(receiver, f, $T) {
      var t1 = H.instanceType(receiver);
      return new H.MappedListIterable(receiver, t1._bind$1($T)._eval$1("1(ListMixin.E)")._check(f), t1._eval$1("@<ListMixin.E>")._bind$1($T)._eval$1("MappedListIterable<1,2>"));
    },
    toList$1$growable: function(receiver, growable) {
      var i,
        result = H.setRuntimeTypeInfo([], H.instanceType(receiver)._eval$1("JSArray<ListMixin.E>"));
      C.JSArray_methods.set$length(result, this.get$length(receiver));
      for (i = 0; i < this.get$length(receiver); ++i)
        C.JSArray_methods.$indexSet(result, i, this.$index(receiver, i));
      return result;
    },
    toList$0: function($receiver) {
      return this.toList$1$growable($receiver, true);
    },
    toSet$0: function(receiver) {
      var i,
        result = P.LinkedHashSet_LinkedHashSet(H.instanceType(receiver)._eval$1("ListMixin.E"));
      for (i = 0; i < this.get$length(receiver); ++i)
        result.add$1(0, this.$index(receiver, i));
      return result;
    },
    remove$1: function(receiver, element) {
      var i;
      for (i = 0; i < this.get$length(receiver); ++i)
        if (J.$eq$(this.$index(receiver, i), element)) {
          this._closeGap$2(receiver, i, i + 1);
          return true;
        }
      return false;
    },
    _closeGap$2: function(receiver, start, end) {
      var size, i, _this = this,
        $length = _this.get$length(receiver);
      H.assertHelper(start < end);
      H.assertHelper(end <= $length);
      size = end - start;
      for (i = end; i < $length; ++i)
        _this.$indexSet(receiver, i - size, _this.$index(receiver, i));
      _this.set$length(receiver, $length - size);
    },
    fillRange$3: function(receiver, start, end, fill) {
      var i;
      H.instanceType(receiver)._eval$1("ListMixin.E")._check(fill);
      P.RangeError_checkValidRange(start, end, this.get$length(receiver));
      for (i = start; i < end; ++i)
        this.$indexSet(receiver, i, fill);
    },
    toString$0: function(receiver) {
      return P.IterableBase_iterableToFullString(receiver, "[", "]");
    }
  };
  P.MapBase.prototype = {};
  P.MapBase_mapToString_closure.prototype = {
    call$2: function(k, v) {
      var t2,
        t1 = this._box_0;
      if (!t1.first)
        this.result._contents += ", ";
      t1.first = false;
      t1 = this.result;
      t2 = t1._contents += H.S(k);
      t1._contents = t2 + ": ";
      t1._contents += H.S(v);
    },
    $signature: 6
  };
  P.MapMixin.prototype = {
    cast$2$0: function(_, RK, RV) {
      var t1 = H._instanceType(this);
      return P.Map_castFrom(this, t1._eval$1("MapMixin.K"), t1._eval$1("MapMixin.V"), RK, RV);
    },
    forEach$1: function(_, action) {
      var t1, key;
      H._instanceType(this)._eval$1("~(MapMixin.K,MapMixin.V)")._check(action);
      for (t1 = this.get$keys(), t1 = t1.get$iterator(t1); t1.moveNext$0();) {
        key = t1.get$current();
        action.call$2(key, this.$index(0, key));
      }
    },
    map$2$1: function(_, transform, K2, V2) {
      var result, t1, key, entry;
      H._instanceType(this)._bind$1(K2)._bind$1(V2)._eval$1("MapEntry<1,2>(MapMixin.K,MapMixin.V)")._check(transform);
      result = P.LinkedHashMap_LinkedHashMap$_empty(K2, V2);
      for (t1 = this.get$keys(), t1 = t1.get$iterator(t1); t1.moveNext$0();) {
        key = t1.get$current();
        entry = transform.call$2(key, this.$index(0, key));
        result.$indexSet(0, entry.key, entry.value);
      }
      return result;
    },
    containsKey$1: function(key) {
      return this.get$keys().contains$1(0, key);
    },
    get$length: function(_) {
      var t1 = this.get$keys();
      return t1.get$length(t1);
    },
    get$isEmpty: function(_) {
      var t1 = this.get$keys();
      return t1.get$isEmpty(t1);
    },
    toString$0: function(_) {
      return P.MapBase_mapToString(this);
    },
    $isMap: 1
  };
  P._UnmodifiableMapMixin.prototype = {
    remove$1: function(_, key) {
      throw H.wrapException(P.UnsupportedError$("Cannot modify unmodifiable map"));
    }
  };
  P.MapView.prototype = {
    cast$2$0: function(_, RK, RV) {
      return this._map.cast$2$0(0, RK, RV);
    },
    $index: function(_, key) {
      return this._map.$index(0, key);
    },
    containsKey$1: function(key) {
      return this._map.containsKey$1(key);
    },
    forEach$1: function(_, action) {
      this._map.forEach$1(0, H._instanceType(this)._eval$1("~(1,2)")._check(action));
    },
    get$isEmpty: function(_) {
      var t1 = this._map;
      return t1.get$isEmpty(t1);
    },
    get$length: function(_) {
      var t1 = this._map;
      return t1.get$length(t1);
    },
    get$keys: function() {
      return this._map.get$keys();
    },
    remove$1: function(_, key) {
      return this._map.remove$1(0, key);
    },
    toString$0: function(_) {
      return this._map.toString$0(0);
    },
    map$2$1: function(_, transform, K2, V2) {
      return this._map.map$2$1(0, H._instanceType(this)._bind$1(K2)._bind$1(V2)._eval$1("MapEntry<1,2>(3,4)")._check(transform), K2, V2);
    },
    $isMap: 1
  };
  P.UnmodifiableMapView.prototype = {
    cast$2$0: function(_, RK, RV) {
      return new P.UnmodifiableMapView(this._map.cast$2$0(0, RK, RV), RK._eval$1("@<0>")._bind$1(RV)._eval$1("UnmodifiableMapView<1,2>"));
    }
  };
  P.ListQueue.prototype = {
    get$iterator: function(_) {
      var _this = this;
      return new P._ListQueueIterator(_this, _this._tail, _this._modificationCount, _this._head, _this.$ti._eval$1("_ListQueueIterator<1>"));
    },
    get$isEmpty: function(_) {
      return this._head === this._tail;
    },
    get$length: function(_) {
      return (this._tail - this._head & this._table.length - 1) >>> 0;
    },
    get$first: function(_) {
      var t2,
        t1 = this._head;
      if (t1 === this._tail)
        throw H.wrapException(H.IterableElementError_noElement());
      t2 = this._table;
      if (t1 >= t2.length)
        return H.ioore(t2, t1);
      return t2[t1];
    },
    get$last: function(_) {
      var t3,
        t1 = this._head,
        t2 = this._tail;
      if (t1 === t2)
        throw H.wrapException(H.IterableElementError_noElement());
      t1 = this._table;
      t3 = t1.length;
      t2 = (t2 - 1 & t3 - 1) >>> 0;
      if (t2 < 0 || t2 >= t3)
        return H.ioore(t1, t2);
      return t1[t2];
    },
    elementAt$1: function(_, index) {
      var t1, t2, t3, _this = this,
        $length = _this.get$length(_this);
      if (0 > index || index >= $length)
        H.throwExpression(P.IndexError$(index, _this, "index", null, $length));
      t1 = _this._table;
      t2 = t1.length;
      t3 = (_this._head + index & t2 - 1) >>> 0;
      if (t3 < 0 || t3 >= t2)
        return H.ioore(t1, t3);
      return t1[t3];
    },
    clear$0: function(_) {
      var _this = this,
        i = _this._head;
      if (i !== _this._tail) {
        for (; i !== _this._tail; i = (i + 1 & _this._table.length - 1) >>> 0)
          C.JSArray_methods.$indexSet(_this._table, i, null);
        _this._head = _this._tail = 0;
        ++_this._modificationCount;
      }
    },
    toString$0: function(_) {
      return P.IterableBase_iterableToFullString(this, "{", "}");
    },
    removeFirst$0: function() {
      var t2, result, _this = this,
        t1 = _this._head;
      if (t1 === _this._tail)
        throw H.wrapException(H.IterableElementError_noElement());
      ++_this._modificationCount;
      t2 = _this._table;
      if (t1 >= t2.length)
        return H.ioore(t2, t1);
      result = t2[t1];
      C.JSArray_methods.$indexSet(t2, t1, null);
      _this._head = (_this._head + 1 & _this._table.length - 1) >>> 0;
      return result;
    },
    _collection$_add$1: function(element) {
      var t2, t3, newTable, split, _this = this,
        t1 = _this.$ti;
      t1._precomputed1._check(element);
      C.JSArray_methods.$indexSet(_this._table, _this._tail, element);
      t2 = _this._tail;
      t3 = _this._table.length;
      t2 = (t2 + 1 & t3 - 1) >>> 0;
      _this._tail = t2;
      if (_this._head === t2) {
        t2 = new Array(t3 * 2);
        t2.fixed$length = Array;
        newTable = H.setRuntimeTypeInfo(t2, t1._eval$1("JSArray<1>"));
        t1 = _this._table;
        t2 = _this._head;
        split = t1.length - t2;
        C.JSArray_methods.setRange$4(newTable, 0, split, t1, t2);
        C.JSArray_methods.setRange$4(newTable, split, split + _this._head, _this._table, 0);
        _this._head = 0;
        _this._tail = _this._table.length;
        _this.set$_table(newTable);
      }
      ++_this._modificationCount;
    },
    set$_table: function(_table) {
      this._table = this.$ti._eval$1("List<1>")._check(_table);
    },
    $isQueue: 1
  };
  P._ListQueueIterator.prototype = {
    get$current: function() {
      return this._collection$_current;
    },
    moveNext$0: function() {
      var t2, t3, _this = this,
        t1 = _this._queue;
      if (_this._modificationCount !== t1._modificationCount)
        H.throwExpression(P.ConcurrentModificationError$(t1));
      t2 = _this._position;
      if (t2 === _this._end) {
        _this.set$_collection$_current(null);
        return false;
      }
      t3 = t1._table;
      if (t2 >= t3.length)
        return H.ioore(t3, t2);
      _this.set$_collection$_current(t3[t2]);
      _this._position = (_this._position + 1 & t1._table.length - 1) >>> 0;
      return true;
    },
    set$_collection$_current: function(_current) {
      this._collection$_current = this.$ti._precomputed1._check(_current);
    },
    $isIterator: 1
  };
  P.SetMixin.prototype = {
    get$isEmpty: function(_) {
      return this.get$length(this) === 0;
    },
    map$1$1: function(_, f, $T) {
      var t1 = H._instanceType(this);
      return new H.EfficientLengthMappedIterable(this, t1._bind$1($T)._eval$1("1(2)")._check(f), t1._eval$1("@<1>")._bind$1($T)._eval$1("EfficientLengthMappedIterable<1,2>"));
    },
    toString$0: function(_) {
      return P.IterableBase_iterableToFullString(this, "{", "}");
    },
    every$1: function(_, f) {
      var t1;
      H._instanceType(this)._eval$1("bool(1)")._check(f);
      for (t1 = this.get$iterator(this); t1.moveNext$0();)
        if (!H.boolConversionCheck(f.call$1(t1.get$current())))
          return false;
      return true;
    },
    get$first: function(_) {
      var it = this.get$iterator(this);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      return it.get$current();
    },
    get$last: function(_) {
      var result,
        it = this.get$iterator(this);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      do
        result = it.get$current();
      while (it.moveNext$0());
      return result;
    },
    $isEfficientLengthIterable: 1,
    $isIterable: 1,
    $isSet: 1
  };
  P.SetBase.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isSet: 1};
  P._SetBase.prototype = {
    toSet$0: function(_) {
      var t1 = this._newSet$0();
      t1.addAll$1(0, this);
      return t1;
    },
    get$isEmpty: function(_) {
      return this._collection$_length === 0;
    },
    addAll$1: function(_, elements) {
      var t1;
      H._instanceType(this)._eval$1("Iterable<1>")._check(elements);
      for (t1 = elements.get$iterator(elements); t1.moveNext$0();)
        this.add$1(0, t1.get$current());
    },
    union$1: function(other) {
      var t1;
      H._instanceType(this)._eval$1("Set<1>")._check(other);
      t1 = this.toSet$0(0);
      t1.addAll$1(0, other);
      return t1;
    },
    toList$1$growable: function(_, growable) {
      var i, i0, _this = this,
        t1 = H._instanceType(_this),
        result = H.setRuntimeTypeInfo([], t1._eval$1("JSArray<1>"));
      C.JSArray_methods.set$length(result, _this._collection$_length);
      for (t1 = P._LinkedHashSetIterator$(_this, _this._collection$_modifications, t1._precomputed1), i = 0; t1.moveNext$0(); i = i0) {
        i0 = i + 1;
        C.JSArray_methods.$indexSet(result, i, t1._collection$_current);
      }
      return result;
    },
    toList$0: function($receiver) {
      return this.toList$1$growable($receiver, true);
    },
    map$1$1: function(_, f, $T) {
      var t1 = H._instanceType(this);
      return new H.EfficientLengthMappedIterable(this, t1._bind$1($T)._eval$1("1(2)")._check(f), t1._eval$1("@<1>")._bind$1($T)._eval$1("EfficientLengthMappedIterable<1,2>"));
    },
    toString$0: function(_) {
      return P.IterableBase_iterableToFullString(this, "{", "}");
    },
    where$1: function(_, f) {
      var t1 = H._instanceType(this);
      return new H.WhereIterable(this, t1._eval$1("bool(1)")._check(f), t1._eval$1("WhereIterable<1>"));
    },
    fold$1$2: function(_, initialValue, combine, $T) {
      var t1, value;
      $T._check(initialValue);
      t1 = H._instanceType(this);
      t1._bind$1($T)._eval$1("1(1,2)")._check(combine);
      for (t1 = P._LinkedHashSetIterator$(this, this._collection$_modifications, t1._precomputed1), value = initialValue; t1.moveNext$0();)
        value = combine.call$2(value, t1._collection$_current);
      return value;
    },
    every$1: function(_, f) {
      var t1 = H._instanceType(this);
      t1._eval$1("bool(1)")._check(f);
      for (t1 = P._LinkedHashSetIterator$(this, this._collection$_modifications, t1._precomputed1); t1.moveNext$0();)
        if (!H.boolConversionCheck(f.call$1(t1._collection$_current)))
          return false;
      return true;
    },
    any$1: function(_, test) {
      var t1 = H._instanceType(this);
      t1._eval$1("bool(1)")._check(test);
      for (t1 = P._LinkedHashSetIterator$(this, this._collection$_modifications, t1._precomputed1); t1.moveNext$0();)
        if (H.boolConversionCheck(test.call$1(t1._collection$_current)))
          return true;
      return false;
    },
    get$first: function(_) {
      var it = P._LinkedHashSetIterator$(this, this._collection$_modifications, H._instanceType(this)._precomputed1);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      return it._collection$_current;
    },
    get$last: function(_) {
      var result,
        it = P._LinkedHashSetIterator$(this, this._collection$_modifications, H._instanceType(this)._precomputed1);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      do
        result = it._collection$_current;
      while (it.moveNext$0());
      return result;
    },
    $isEfficientLengthIterable: 1,
    $isIterable: 1,
    $isSet: 1
  };
  P._ListBase_Object_ListMixin.prototype = {};
  P._SetBase_Object_SetMixin.prototype = {};
  P._UnmodifiableMapView_MapView__UnmodifiableMapMixin.prototype = {};
  P._JsonMap.prototype = {
    $index: function(_, key) {
      var result,
        t1 = this._processed;
      if (t1 == null)
        return this.get$_upgradedMap().$index(0, key);
      else if (typeof key != "string")
        return null;
      else {
        result = t1[key];
        return typeof result == "undefined" ? this._process$1(key) : result;
      }
    },
    get$length: function(_) {
      var t1;
      if (this._processed == null) {
        t1 = this.get$_upgradedMap();
        t1 = t1.get$length(t1);
      } else
        t1 = this._convert$_computeKeys$0().length;
      return t1;
    },
    get$isEmpty: function(_) {
      return this.get$length(this) === 0;
    },
    get$keys: function() {
      if (this._processed == null)
        return this.get$_upgradedMap().get$keys();
      return new P._JsonMapKeyIterable(this);
    },
    containsKey$1: function(key) {
      if (this._processed == null)
        return this.get$_upgradedMap().containsKey$1(key);
      if (typeof key != "string")
        return false;
      return Object.prototype.hasOwnProperty.call(this._original, key);
    },
    remove$1: function(_, key) {
      if (this._processed != null && !this.containsKey$1(key))
        return null;
      return this._upgrade$0().remove$1(0, key);
    },
    forEach$1: function(_, f) {
      var keys, i, key, value, _this = this;
      type$.void_Function_String_dynamic._check(f);
      if (_this._processed == null)
        return _this.get$_upgradedMap().forEach$1(0, f);
      keys = _this._convert$_computeKeys$0();
      for (i = 0; i < keys.length; ++i) {
        key = keys[i];
        value = _this._processed[key];
        if (typeof value == "undefined") {
          value = P._convertJsonToDartLazy(_this._original[key]);
          _this._processed[key] = value;
        }
        f.call$2(key, value);
        if (keys !== _this._data)
          throw H.wrapException(P.ConcurrentModificationError$(_this));
      }
    },
    get$_upgradedMap: function() {
      H.assertHelper(this._processed == null);
      return this._data;
    },
    _convert$_computeKeys$0: function() {
      var keys, _this = this;
      H.assertHelper(_this._processed != null);
      keys = type$.List_dynamic._check(_this._data);
      if (keys == null)
        keys = _this._data = H.setRuntimeTypeInfo(Object.keys(_this._original), type$.JSArray_String);
      return keys;
    },
    _upgrade$0: function() {
      var result, keys, i, t1, key, _this = this;
      if (_this._processed == null)
        return _this.get$_upgradedMap();
      result = P.LinkedHashMap_LinkedHashMap$_empty(type$.String, type$.dynamic);
      keys = _this._convert$_computeKeys$0();
      for (i = 0; t1 = keys.length, i < t1; ++i) {
        key = keys[i];
        result.$indexSet(0, key, _this.$index(0, key));
      }
      if (t1 === 0)
        C.JSArray_methods.add$1(keys, null);
      else
        C.JSArray_methods.set$length(keys, 0);
      _this._original = _this._processed = null;
      return _this._data = result;
    },
    _process$1: function(key) {
      var result;
      if (!Object.prototype.hasOwnProperty.call(this._original, key))
        return null;
      result = P._convertJsonToDartLazy(this._original[key]);
      return this._processed[key] = result;
    }
  };
  P._JsonMapKeyIterable.prototype = {
    get$length: function(_) {
      var t1 = this._parent;
      return t1.get$length(t1);
    },
    elementAt$1: function(_, index) {
      var t1 = this._parent;
      if (t1._processed == null)
        t1 = t1.get$keys().elementAt$1(0, index);
      else {
        t1 = t1._convert$_computeKeys$0();
        if (index < 0 || index >= t1.length)
          return H.ioore(t1, index);
        t1 = t1[index];
      }
      return t1;
    },
    get$iterator: function(_) {
      var t1 = this._parent;
      if (t1._processed == null) {
        t1 = t1.get$keys();
        t1 = t1.get$iterator(t1);
      } else {
        t1 = t1._convert$_computeKeys$0();
        t1 = new J.ArrayIterator(t1, t1.length, H._arrayInstanceType(t1)._eval$1("ArrayIterator<1>"));
      }
      return t1;
    },
    contains$1: function(_, key) {
      return this._parent.containsKey$1(key);
    }
  };
  P.AsciiCodec.prototype = {
    encode$1: function(source) {
      return C.AsciiEncoder_127.convert$1(source);
    }
  };
  P._UnicodeSubsetEncoder.prototype = {
    convert$1: function(string) {
      var $length, result, t1, t2, t3, i, codeUnit;
      H._checkStringNullable(string);
      $length = P.RangeError_checkValidRange(0, null, string.length) - 0;
      result = new Uint8Array($length);
      for (t1 = result.length, t2 = ~this._subsetMask, t3 = J.getInterceptor$s(string), i = 0; i < $length; ++i) {
        codeUnit = t3._codeUnitAt$1(string, i);
        if ((codeUnit & t2) !== 0)
          throw H.wrapException(P.ArgumentError$value(string, "string", "Contains invalid characters."));
        if (i >= t1)
          return H.ioore(result, i);
        result[i] = codeUnit;
      }
      return result;
    }
  };
  P.AsciiEncoder.prototype = {};
  P.Base64Codec.prototype = {
    normalize$3: function(source, start, end) {
      var inverseAlphabet, i, sliceStart, buffer, firstPadding, firstPaddingSourceIndex, paddingCount, i0, char, i1, digit1, digit2, char0, value, t2, endLength, $length,
        _s31_ = "Invalid base64 encoding length ",
        t1 = source.length;
      end = P.RangeError_checkValidRange(start, end, t1);
      inverseAlphabet = $.$get$_Base64Decoder__inverseAlphabet();
      for (i = start, sliceStart = i, buffer = null, firstPadding = -1, firstPaddingSourceIndex = -1, paddingCount = 0; i < end; i = i0) {
        i0 = i + 1;
        char = C.JSString_methods._codeUnitAt$1(source, i);
        if (char === 37) {
          i1 = i0 + 2;
          if (i1 <= end) {
            H.assertHelper(i1 <= t1);
            digit1 = H.hexDigitValue(C.JSString_methods._codeUnitAt$1(source, i0));
            digit2 = H.hexDigitValue(C.JSString_methods._codeUnitAt$1(source, i0 + 1));
            char0 = digit1 * 16 + digit2 - (digit2 & 256);
            if (char0 === 37)
              char0 = -1;
            i0 = i1;
          } else
            char0 = -1;
        } else
          char0 = char;
        if (0 <= char0 && char0 <= 127) {
          if (char0 < 0 || char0 >= inverseAlphabet.length)
            return H.ioore(inverseAlphabet, char0);
          value = inverseAlphabet[char0];
          if (value >= 0) {
            char0 = C.JSString_methods.codeUnitAt$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", value);
            if (char0 === char)
              continue;
            char = char0;
          } else {
            if (value === -1) {
              if (firstPadding < 0) {
                t2 = buffer == null ? null : buffer._contents.length;
                if (t2 == null)
                  t2 = 0;
                firstPadding = t2 + (i - sliceStart);
                firstPaddingSourceIndex = i;
              }
              ++paddingCount;
              if (char === 61)
                continue;
            }
            char = char0;
          }
          if (value !== -2) {
            if (buffer == null)
              buffer = new P.StringBuffer("");
            t2 = buffer._contents += C.JSString_methods.substring$2(source, sliceStart, i);
            buffer._contents = t2 + H.Primitives_stringFromCharCode(char);
            sliceStart = i0;
            continue;
          }
        }
        throw H.wrapException(P.FormatException$("Invalid base64 data", source, i));
      }
      if (buffer != null) {
        t1 = buffer._contents += C.JSString_methods.substring$2(source, sliceStart, end);
        t2 = t1.length;
        if (firstPadding >= 0)
          P.Base64Codec__checkPadding(source, firstPaddingSourceIndex, end, firstPadding, paddingCount, t2);
        else {
          endLength = C.JSInt_methods.$mod(t2 - 1, 4) + 1;
          if (endLength === 1)
            throw H.wrapException(P.FormatException$(_s31_, source, end));
          for (; endLength < 4;) {
            t1 += "=";
            buffer._contents = t1;
            ++endLength;
          }
        }
        t1 = buffer._contents;
        return C.JSString_methods.replaceRange$3(source, start, end, t1.charCodeAt(0) == 0 ? t1 : t1);
      }
      $length = end - start;
      if (firstPadding >= 0)
        P.Base64Codec__checkPadding(source, firstPaddingSourceIndex, end, firstPadding, paddingCount, $length);
      else {
        endLength = C.JSInt_methods.$mod($length, 4);
        if (endLength === 1)
          throw H.wrapException(P.FormatException$(_s31_, source, end));
        if (endLength > 1)
          source = C.JSString_methods.replaceRange$3(source, end, end, endLength === 2 ? "==" : "=");
      }
      return source;
    }
  };
  P.Base64Encoder.prototype = {};
  P.Codec.prototype = {};
  P._FusedCodec.prototype = {};
  P.Converter.prototype = {};
  P.Encoding.prototype = {};
  P.JsonCodec.prototype = {
    decode$2$reviver: function(source, reviver) {
      var t1;
      type$.dynamic_Function_Object_Object._check(reviver);
      t1 = P._parseJson(source, this.get$decoder()._reviver);
      return t1;
    },
    get$decoder: function() {
      return C.JsonDecoder_null;
    }
  };
  P.JsonDecoder.prototype = {};
  P.Utf8Codec.prototype = {
    get$encoder: function() {
      return C.C_Utf8Encoder;
    }
  };
  P.Utf8Encoder.prototype = {
    convert$1: function(string) {
      var end, $length, t1, encoder, endPosition, t2, lastCodeUnit;
      H._checkStringNullable(string);
      end = P.RangeError_checkValidRange(0, null, string.length);
      $length = end - 0;
      if ($length === 0)
        return new Uint8Array(0);
      t1 = new Uint8Array($length * 3);
      encoder = new P._Utf8Encoder(t1);
      endPosition = encoder._fillBuffer$3(string, 0, end);
      t2 = end - 1;
      H.assertHelper(endPosition >= t2);
      if (endPosition !== end) {
        lastCodeUnit = J.codeUnitAt$1$s(string, t2);
        H.assertHelper((lastCodeUnit & 64512) === 55296);
        H.assertHelper(!encoder._writeSurrogate$2(lastCodeUnit, 0));
      }
      return C.NativeUint8List_methods.sublist$2(t1, 0, encoder._bufferIndex);
    }
  };
  P._Utf8Encoder.prototype = {
    _writeSurrogate$2: function(leadingSurrogate, nextCodeUnit) {
      var rune, t3, t4, _this = this,
        t1 = _this._buffer,
        t2 = t1.length;
      if ((nextCodeUnit & 64512) === 56320) {
        rune = 65536 + ((leadingSurrogate & 1023) << 10) | nextCodeUnit & 1023;
        H.assertHelper(rune > 65535);
        H.assertHelper(rune <= 1114111);
        t3 = _this._bufferIndex;
        t4 = _this._bufferIndex = t3 + 1;
        if (t3 >= t2)
          return H.ioore(t1, t3);
        t1[t3] = 240 | rune >>> 18;
        t3 = _this._bufferIndex = t4 + 1;
        if (t4 >= t2)
          return H.ioore(t1, t4);
        t1[t4] = 128 | rune >>> 12 & 63;
        t4 = _this._bufferIndex = t3 + 1;
        if (t3 >= t2)
          return H.ioore(t1, t3);
        t1[t3] = 128 | rune >>> 6 & 63;
        _this._bufferIndex = t4 + 1;
        if (t4 >= t2)
          return H.ioore(t1, t4);
        t1[t4] = 128 | rune & 63;
        return true;
      } else {
        t3 = _this._bufferIndex;
        t4 = _this._bufferIndex = t3 + 1;
        if (t3 >= t2)
          return H.ioore(t1, t3);
        t1[t3] = 224 | leadingSurrogate >>> 12;
        t3 = _this._bufferIndex = t4 + 1;
        if (t4 >= t2)
          return H.ioore(t1, t4);
        t1[t4] = 128 | leadingSurrogate >>> 6 & 63;
        _this._bufferIndex = t3 + 1;
        if (t3 >= t2)
          return H.ioore(t1, t3);
        t1[t3] = 128 | leadingSurrogate & 63;
        return false;
      }
    },
    _fillBuffer$3: function(str, start, end) {
      var t1, t2, t3, stringIndex, codeUnit, t4, stringIndex0, t5, _this = this;
      if (start !== end && (J.codeUnitAt$1$s(str, end - 1) & 64512) === 55296)
        --end;
      for (t1 = _this._buffer, t2 = t1.length, t3 = J.getInterceptor$s(str), stringIndex = start; stringIndex < end; ++stringIndex) {
        codeUnit = t3._codeUnitAt$1(str, stringIndex);
        if (codeUnit <= 127) {
          t4 = _this._bufferIndex;
          if (t4 >= t2)
            break;
          _this._bufferIndex = t4 + 1;
          t1[t4] = codeUnit;
        } else if ((codeUnit & 64512) === 55296) {
          if (_this._bufferIndex + 3 >= t2)
            break;
          stringIndex0 = stringIndex + 1;
          if (_this._writeSurrogate$2(codeUnit, C.JSString_methods._codeUnitAt$1(str, stringIndex0)))
            stringIndex = stringIndex0;
        } else if (codeUnit <= 2047) {
          t4 = _this._bufferIndex;
          t5 = t4 + 1;
          if (t5 >= t2)
            break;
          _this._bufferIndex = t5;
          if (t4 >= t2)
            return H.ioore(t1, t4);
          t1[t4] = 192 | codeUnit >>> 6;
          _this._bufferIndex = t5 + 1;
          t1[t5] = 128 | codeUnit & 63;
        } else {
          H.assertHelper(codeUnit <= 65535);
          t4 = _this._bufferIndex;
          if (t4 + 2 >= t2)
            break;
          t5 = _this._bufferIndex = t4 + 1;
          if (t4 >= t2)
            return H.ioore(t1, t4);
          t1[t4] = 224 | codeUnit >>> 12;
          t4 = _this._bufferIndex = t5 + 1;
          if (t5 >= t2)
            return H.ioore(t1, t5);
          t1[t5] = 128 | codeUnit >>> 6 & 63;
          _this._bufferIndex = t4 + 1;
          if (t4 >= t2)
            return H.ioore(t1, t4);
          t1[t4] = 128 | codeUnit & 63;
        }
      }
      return stringIndex;
    }
  };
  P.Utf8Decoder.prototype = {
    convert$1: function(codeUnits) {
      var result, end, oneBytes, firstPart, buffer, start, isFirstCharacter, decoder, t1;
      type$.List_int._check(codeUnits);
      result = P.Utf8Decoder__convertIntercepted(false, codeUnits, 0, null);
      if (result != null)
        return result;
      end = P.RangeError_checkValidRange(0, null, J.get$length$asx(codeUnits));
      oneBytes = P._scanOneByteCharacters(codeUnits, 0, end);
      if (oneBytes > 0) {
        firstPart = P.String_String$fromCharCodes(codeUnits, 0, oneBytes);
        if (oneBytes === end)
          return firstPart;
        buffer = new P.StringBuffer(firstPart);
        start = oneBytes;
        isFirstCharacter = false;
      } else {
        start = 0;
        buffer = null;
        isFirstCharacter = true;
      }
      if (buffer == null)
        buffer = new P.StringBuffer("");
      decoder = new P._Utf8Decoder(false, buffer);
      decoder._isFirstCharacter = isFirstCharacter;
      decoder.convert$3(codeUnits, start, end);
      decoder.flush$2(codeUnits, end);
      t1 = buffer._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    }
  };
  P._Utf8Decoder.prototype = {
    flush$2: function(source, offset) {
      var t1;
      type$.List_int._check(source);
      if (this._expectedUnits > 0) {
        t1 = P.FormatException$("Unfinished UTF-8 octet sequence", source, offset);
        throw H.wrapException(t1);
      }
    },
    convert$3: function(codeUnits, startIndex, endIndex) {
      var value, expectedUnits, extraUnits, t1, t2, i, unit, t3, oneBytes, i0, i1, t4, _this = this,
        _s21_ = "Bad UTF-8 encoding 0x";
      type$.List_int._check(codeUnits);
      value = _this._convert$_value;
      expectedUnits = _this._expectedUnits;
      extraUnits = _this._extraUnits;
      _this._extraUnits = _this._expectedUnits = _this._convert$_value = 0;
      $label0$0:
        for (t1 = J.getInterceptor$asx(codeUnits), t2 = _this._stringSink, i = startIndex; true; i = i1) {
          $label1$1:
            if (expectedUnits > 0) {
              do {
                if (i === endIndex)
                  break $label0$0;
                unit = t1.$index(codeUnits, i);
                if (typeof unit !== "number")
                  return unit.$and();
                if ((unit & 192) !== 128) {
                  t3 = P.FormatException$(_s21_ + C.JSInt_methods.toRadixString$1(unit, 16), codeUnits, i);
                  throw H.wrapException(t3);
                } else {
                  value = (value << 6 | unit & 63) >>> 0;
                  --expectedUnits;
                  ++i;
                }
              } while (expectedUnits > 0);
              t3 = extraUnits - 1;
              if (t3 < 0 || t3 >= 4)
                return H.ioore(C.List_127_2047_65535_1114111, t3);
              if (value <= C.List_127_2047_65535_1114111[t3]) {
                t3 = P.FormatException$("Overlong encoding of 0x" + C.JSInt_methods.toRadixString$1(value, 16), codeUnits, i - extraUnits - 1);
                throw H.wrapException(t3);
              }
              if (value > 1114111) {
                t3 = P.FormatException$("Character outside valid Unicode range: 0x" + C.JSInt_methods.toRadixString$1(value, 16), codeUnits, i - extraUnits - 1);
                throw H.wrapException(t3);
              }
              if (!_this._isFirstCharacter || value !== 65279)
                t2._contents += H.Primitives_stringFromCharCode(value);
              _this._isFirstCharacter = false;
            }
          for (t3 = i < endIndex; t3;) {
            oneBytes = P._scanOneByteCharacters(codeUnits, i, endIndex);
            if (oneBytes > 0) {
              _this._isFirstCharacter = false;
              i0 = i + oneBytes;
              H.assertHelper(i0 <= endIndex);
              t2._contents += P.String_String$fromCharCodes(codeUnits, i, i0);
              if (i0 === endIndex)
                break;
            } else
              i0 = i;
            i1 = i0 + 1;
            unit = t1.$index(codeUnits, i0);
            if (typeof unit !== "number")
              return unit.$lt();
            if (unit < 0) {
              t4 = P.FormatException$("Negative UTF-8 code unit: -0x" + C.JSInt_methods.toRadixString$1(-unit, 16), codeUnits, i1 - 1);
              throw H.wrapException(t4);
            } else {
              H.assertHelper(unit > 127);
              if ((unit & 224) === 192) {
                value = unit & 31;
                expectedUnits = 1;
                extraUnits = 1;
                continue $label0$0;
              }
              if ((unit & 240) === 224) {
                value = unit & 15;
                expectedUnits = 2;
                extraUnits = 2;
                continue $label0$0;
              }
              if ((unit & 248) === 240 && unit < 245) {
                value = unit & 7;
                expectedUnits = 3;
                extraUnits = 3;
                continue $label0$0;
              }
              t4 = P.FormatException$(_s21_ + C.JSInt_methods.toRadixString$1(unit, 16), codeUnits, i1 - 1);
              throw H.wrapException(t4);
            }
          }
          break $label0$0;
        }
      if (expectedUnits > 0) {
        _this._convert$_value = value;
        _this._expectedUnits = expectedUnits;
        _this._extraUnits = extraUnits;
      }
    }
  };
  P.bool.prototype = {};
  P.DateTime.prototype = {
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof P.DateTime && this._value === other._value && true;
    },
    get$hashCode: function(_) {
      var t1 = this._value;
      return (t1 ^ C.JSInt_methods._shrOtherPositive$1(t1, 30)) & 1073741823;
    },
    toString$0: function(_) {
      var _this = this,
        y = P.DateTime__fourDigits(H.Primitives_getYear(_this)),
        m = P.DateTime__twoDigits(H.Primitives_getMonth(_this)),
        d = P.DateTime__twoDigits(H.Primitives_getDay(_this)),
        h = P.DateTime__twoDigits(H.Primitives_getHours(_this)),
        min = P.DateTime__twoDigits(H.Primitives_getMinutes(_this)),
        sec = P.DateTime__twoDigits(H.Primitives_getSeconds(_this)),
        ms = P.DateTime__threeDigits(H.Primitives_getMilliseconds(_this)),
        t1 = y + "-" + m + "-" + d + " " + h + ":" + min + ":" + sec + "." + ms + "Z";
      return t1;
    }
  };
  P.double.prototype = {};
  P.Duration.prototype = {
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof P.Duration && this._duration === other._duration;
    },
    get$hashCode: function(_) {
      return C.JSInt_methods.get$hashCode(this._duration);
    },
    toString$0: function(_) {
      var twoDigitMinutes, twoDigitSeconds, sixDigitUs,
        t1 = new P.Duration_toString_twoDigits(),
        t2 = this._duration;
      if (t2 < 0)
        return "-" + new P.Duration(0 - t2).toString$0(0);
      twoDigitMinutes = t1.call$1(C.JSInt_methods._tdivFast$1(t2, 60000000) % 60);
      twoDigitSeconds = t1.call$1(C.JSInt_methods._tdivFast$1(t2, 1000000) % 60);
      sixDigitUs = new P.Duration_toString_sixDigits().call$1(t2 % 1000000);
      return "" + C.JSInt_methods._tdivFast$1(t2, 3600000000) + ":" + H.S(twoDigitMinutes) + ":" + H.S(twoDigitSeconds) + "." + H.S(sixDigitUs);
    }
  };
  P.Duration_toString_sixDigits.prototype = {
    call$1: function(n) {
      if (n >= 100000)
        return "" + n;
      if (n >= 10000)
        return "0" + n;
      if (n >= 1000)
        return "00" + n;
      if (n >= 100)
        return "000" + n;
      if (n >= 10)
        return "0000" + n;
      return "00000" + n;
    },
    $signature: 25
  };
  P.Duration_toString_twoDigits.prototype = {
    call$1: function(n) {
      if (n >= 10)
        return "" + n;
      return "0" + n;
    },
    $signature: 25
  };
  P.Error.prototype = {};
  P.AssertionError.prototype = {
    toString$0: function(_) {
      var t1 = this.message;
      if (t1 != null)
        return "Assertion failed: " + P.Error_safeToString(t1);
      return "Assertion failed";
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.NullThrownError.prototype = {
    toString$0: function(_) {
      return "Throw of null.";
    }
  };
  P.ArgumentError.prototype = {
    get$_errorName: function() {
      return "Invalid argument" + (!this._hasValue ? "(s)" : "");
    },
    get$_errorExplanation: function() {
      return "";
    },
    toString$0: function(_) {
      var message, prefix, explanation, errorValue, _this = this,
        t1 = _this.name,
        nameString = t1 != null ? " (" + t1 + ")" : "";
      t1 = _this.message;
      message = t1 == null ? "" : ": " + H.S(t1);
      prefix = _this.get$_errorName() + nameString + message;
      if (!_this._hasValue)
        return prefix;
      explanation = _this.get$_errorExplanation();
      errorValue = P.Error_safeToString(_this.invalidValue);
      return prefix + explanation + ": " + errorValue;
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.RangeError.prototype = {
    get$_errorName: function() {
      return "RangeError";
    },
    get$_errorExplanation: function() {
      var t1, explanation, t2, _this = this;
      H.assertHelper(_this._hasValue);
      t1 = _this.start;
      if (t1 == null) {
        t1 = _this.end;
        explanation = t1 != null ? ": Not less than or equal to " + H.S(t1) : "";
      } else {
        t2 = _this.end;
        if (t2 == null)
          explanation = ": Not greater than or equal to " + H.S(t1);
        else if (t2 > t1)
          explanation = ": Not in range " + H.S(t1) + ".." + H.S(t2) + ", inclusive";
        else
          explanation = t2 < t1 ? ": Valid value range is empty" : ": Only valid value is " + H.S(t1);
      }
      return explanation;
    }
  };
  P.IndexError.prototype = {
    get$_errorName: function() {
      return "RangeError";
    },
    get$_errorExplanation: function() {
      var invalidValue, t1;
      H.assertHelper(this._hasValue);
      invalidValue = H._checkIntNullable(this.invalidValue);
      if (typeof invalidValue !== "number")
        return invalidValue.$lt();
      if (invalidValue < 0)
        return ": index must not be negative";
      t1 = this.length;
      if (t1 === 0)
        return ": no indices are valid";
      return ": index should be less than " + H.S(t1);
    },
    get$length: function(receiver) {
      return this.length;
    }
  };
  P.UnsupportedError.prototype = {
    toString$0: function(_) {
      return "Unsupported operation: " + this.message;
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.UnimplementedError.prototype = {
    toString$0: function(_) {
      var t1 = this.message;
      return t1 != null ? "UnimplementedError: " + t1 : "UnimplementedError";
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.StateError.prototype = {
    toString$0: function(_) {
      return "Bad state: " + this.message;
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.ConcurrentModificationError.prototype = {
    toString$0: function(_) {
      var t1 = this.modifiedObject;
      if (t1 == null)
        return "Concurrent modification during iteration.";
      return "Concurrent modification during iteration: " + P.Error_safeToString(t1) + ".";
    }
  };
  P.OutOfMemoryError.prototype = {
    toString$0: function(_) {
      return "Out of Memory";
    },
    $isError: 1
  };
  P.StackOverflowError.prototype = {
    toString$0: function(_) {
      return "Stack Overflow";
    },
    $isError: 1
  };
  P.CyclicInitializationError.prototype = {
    toString$0: function(_) {
      var t1 = this.variableName;
      return t1 == null ? "Reading static variable during its initialization" : "Reading static variable '" + t1 + "' during its initialization";
    }
  };
  P._Exception.prototype = {
    toString$0: function(_) {
      return "Exception: " + this.message;
    },
    $isException: 1,
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.FormatException.prototype = {
    toString$0: function(_) {
      var source, lineNum, lineStart, previousCharWasCR, i, char, lineEnd, end, start, prefix, postfix, slice,
        t1 = this.message,
        report = t1 != null && "" !== t1 ? "FormatException: " + H.S(t1) : "FormatException",
        offset = this.offset,
        objectSource = this.source;
      if (typeof objectSource == "string") {
        if (offset != null)
          t1 = offset < 0 || offset > objectSource.length;
        else
          t1 = false;
        if (t1)
          offset = null;
        if (offset == null) {
          source = objectSource.length > 78 ? C.JSString_methods.substring$2(objectSource, 0, 75) + "..." : objectSource;
          return report + "\n" + source;
        }
        for (lineNum = 1, lineStart = 0, previousCharWasCR = false, i = 0; i < offset; ++i) {
          char = C.JSString_methods._codeUnitAt$1(objectSource, i);
          if (char === 10) {
            if (lineStart !== i || !previousCharWasCR)
              ++lineNum;
            lineStart = i + 1;
            previousCharWasCR = false;
          } else if (char === 13) {
            ++lineNum;
            lineStart = i + 1;
            previousCharWasCR = true;
          }
        }
        report = lineNum > 1 ? report + (" (at line " + lineNum + ", character " + (offset - lineStart + 1) + ")\n") : report + (" (at character " + (offset + 1) + ")\n");
        lineEnd = objectSource.length;
        for (i = offset; i < lineEnd; ++i) {
          char = C.JSString_methods.codeUnitAt$1(objectSource, i);
          if (char === 10 || char === 13) {
            lineEnd = i;
            break;
          }
        }
        if (lineEnd - lineStart > 78)
          if (offset - lineStart < 75) {
            end = lineStart + 75;
            start = lineStart;
            prefix = "";
            postfix = "...";
          } else {
            if (lineEnd - offset < 75) {
              start = lineEnd - 75;
              end = lineEnd;
              postfix = "";
            } else {
              start = offset - 36;
              end = offset + 36;
              postfix = "...";
            }
            prefix = "...";
          }
        else {
          end = lineEnd;
          start = lineStart;
          prefix = "";
          postfix = "";
        }
        slice = C.JSString_methods.substring$2(objectSource, start, end);
        return report + prefix + slice + postfix + "\n" + C.JSString_methods.$mul(" ", offset - start + prefix.length) + "^\n";
      } else
        return offset != null ? report + (" (at offset " + H.S(offset) + ")") : report;
    },
    $isException: 1,
    get$message: function(receiver) {
      return this.message;
    }
  };
  P.Expando.prototype = {
    $index: function(_, object) {
      var t2, values,
        t1 = this._jsWeakMapOrKey;
      if (typeof t1 != "string") {
        if (object != null)
          t2 = typeof object == "number" || typeof object == "string";
        else
          t2 = true;
        if (t2)
          H.throwExpression(P.ArgumentError$value(object, "Expandos are not allowed on strings, numbers, booleans or null", null));
        return t1.get(object);
      }
      values = H.Primitives_getProperty(object, "expando$values");
      t1 = values == null ? null : H.Primitives_getProperty(values, t1);
      return this.$ti._precomputed1._check(t1);
    },
    $indexSet: function(_, object, value) {
      var t1, values,
        _s14_ = "expando$values";
      this.$ti._precomputed1._check(value);
      t1 = this._jsWeakMapOrKey;
      if (typeof t1 != "string")
        t1.set(object, value);
      else {
        values = H.Primitives_getProperty(object, _s14_);
        if (values == null) {
          values = new P.Object();
          H.Primitives_setProperty(object, _s14_, values);
        }
        H.Primitives_setProperty(values, t1, value);
      }
    },
    toString$0: function(_) {
      return "Expando:" + this.name;
    }
  };
  P.Function.prototype = {};
  P.int.prototype = {};
  P.Iterable.prototype = {
    map$1$1: function(_, f, $T) {
      var t1 = H._instanceType(this);
      return H.MappedIterable_MappedIterable(this, t1._bind$1($T)._eval$1("1(Iterable.E)")._check(f), t1._eval$1("Iterable.E"), $T);
    },
    where$1: function(_, test) {
      var t1 = H._instanceType(this);
      return new H.WhereIterable(this, t1._eval$1("bool(Iterable.E)")._check(test), t1._eval$1("WhereIterable<Iterable.E>"));
    },
    contains$1: function(_, element) {
      var t1;
      for (t1 = this.get$iterator(this); t1.moveNext$0();)
        if (J.$eq$(t1.get$current(), element))
          return true;
      return false;
    },
    join$1: function(_, separator) {
      var t1,
        iterator = this.get$iterator(this);
      if (!iterator.moveNext$0())
        return "";
      if (separator === "") {
        t1 = "";
        do
          t1 += H.S(iterator.get$current());
        while (iterator.moveNext$0());
      } else {
        t1 = H.S(iterator.get$current());
        for (; iterator.moveNext$0();)
          t1 = t1 + separator + H.S(iterator.get$current());
      }
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    join$0: function($receiver) {
      return this.join$1($receiver, "");
    },
    toList$1$growable: function(_, growable) {
      return P.List_List$from(this, true, H._instanceType(this)._eval$1("Iterable.E"));
    },
    toList$0: function($receiver) {
      return this.toList$1$growable($receiver, true);
    },
    toSet$0: function(_) {
      return P.LinkedHashSet_LinkedHashSet$from(this, H._instanceType(this)._eval$1("Iterable.E"));
    },
    get$length: function(_) {
      var it, count;
      H.assertHelper(!type$.EfficientLengthIterable_dynamic._is(this));
      it = this.get$iterator(this);
      for (count = 0; it.moveNext$0();)
        ++count;
      return count;
    },
    get$isEmpty: function(_) {
      return !this.get$iterator(this).moveNext$0();
    },
    skipWhile$1: function(_, test) {
      var t1 = H._instanceType(this);
      return new H.SkipWhileIterable(this, t1._eval$1("bool(Iterable.E)")._check(test), t1._eval$1("SkipWhileIterable<Iterable.E>"));
    },
    get$first: function(_) {
      var it = this.get$iterator(this);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      return it.get$current();
    },
    get$last: function(_) {
      var result,
        it = this.get$iterator(this);
      if (!it.moveNext$0())
        throw H.wrapException(H.IterableElementError_noElement());
      do
        result = it.get$current();
      while (it.moveNext$0());
      return result;
    },
    elementAt$1: function(_, index) {
      var t1, elementIndex, element;
      P.RangeError_checkNotNegative(index, "index");
      for (t1 = this.get$iterator(this), elementIndex = 0; t1.moveNext$0();) {
        element = t1.get$current();
        if (index === elementIndex)
          return element;
        ++elementIndex;
      }
      throw H.wrapException(P.IndexError$(index, this, "index", null, elementIndex));
    },
    toString$0: function(_) {
      return P.IterableBase_iterableToShortString(this, "(", ")");
    }
  };
  P.Iterator.prototype = {};
  P.List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1};
  P.Map.prototype = {};
  P.MapEntry.prototype = {
    toString$0: function(_) {
      return "MapEntry(" + H.S(this.key) + ": " + H.S(this.value) + ")";
    }
  };
  P.Null.prototype = {
    get$hashCode: function(_) {
      return P.Object.prototype.get$hashCode.call(this, this);
    },
    toString$0: function(_) {
      return "null";
    }
  };
  P.num.prototype = {};
  P.Object.prototype = {constructor: P.Object, $isObject: 1,
    $eq: function(_, other) {
      return this === other;
    },
    get$hashCode: function(_) {
      return H.Primitives_objectHashCode(this);
    },
    toString$0: function(_) {
      return "Instance of '" + H.S(H.Primitives_objectTypeName(this)) + "'";
    },
    get$runtimeType: function(_) {
      return H.getRuntimeType(this);
    },
    toString: function() {
      return this.toString$0(this);
    }
  };
  P.Pattern.prototype = {};
  P.Match.prototype = {};
  P.RegExpMatch.prototype = {$isMatch: 1};
  P.Set.prototype = {};
  P.StackTrace.prototype = {};
  P._StringStackTrace.prototype = {
    toString$0: function(_) {
      return this._stackTrace;
    },
    $isStackTrace: 1
  };
  P.Stopwatch.prototype = {
    get$elapsedMicroseconds: function() {
      var t2, ticks,
        t1 = this._stop;
      if (t1 == null)
        t1 = H._checkIntNullable($.Primitives_timerTicks.call$0());
      t2 = this._core$_start;
      if (typeof t1 !== "number")
        return t1.$sub();
      ticks = t1 - t2;
      t1 = $.Stopwatch__frequency;
      if (t1 === 1000000)
        return ticks;
      H.assertHelper(t1 === 1000);
      return ticks * 1000;
    }
  };
  P.String.prototype = {$isPattern: 1};
  P.Runes.prototype = {
    get$iterator: function(_) {
      return new P.RuneIterator(this.string);
    },
    get$last: function(_) {
      var code, previousCode,
        t1 = this.string,
        t2 = t1.length;
      if (t2 === 0)
        throw H.wrapException(P.StateError$("No elements."));
      code = C.JSString_methods.codeUnitAt$1(t1, t2 - 1);
      if ((code & 64512) === 56320 && t2 > 1) {
        previousCode = C.JSString_methods.codeUnitAt$1(t1, t2 - 2);
        if ((previousCode & 64512) === 55296)
          return P._combineSurrogatePair(previousCode, code);
      }
      return code;
    }
  };
  P.RuneIterator.prototype = {
    get$current: function() {
      return this._currentCodePoint;
    },
    moveNext$0: function() {
      var codeUnit, nextPosition, nextCodeUnit, _this = this,
        t1 = _this._core$_position = _this._nextPosition,
        t2 = _this.string,
        t3 = t2.length;
      if (t1 === t3) {
        _this._currentCodePoint = null;
        return false;
      }
      codeUnit = C.JSString_methods._codeUnitAt$1(t2, t1);
      nextPosition = t1 + 1;
      if ((codeUnit & 64512) === 55296 && nextPosition < t3) {
        nextCodeUnit = C.JSString_methods._codeUnitAt$1(t2, nextPosition);
        if ((nextCodeUnit & 64512) === 56320) {
          _this._nextPosition = nextPosition + 1;
          _this._currentCodePoint = P._combineSurrogatePair(codeUnit, nextCodeUnit);
          return true;
        }
      }
      _this._nextPosition = nextPosition;
      _this._currentCodePoint = codeUnit;
      return true;
    },
    $isIterator: 1
  };
  P.StringBuffer.prototype = {
    get$length: function(_) {
      return this._contents.length;
    },
    toString$0: function(_) {
      var t1 = this._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    $isStringSink: 1
  };
  P.Uri.prototype = {};
  P.Uri__parseIPv4Address_error.prototype = {
    call$2: function(msg, position) {
      throw H.wrapException(P.FormatException$("Illegal IPv4 address, " + msg, this.host, position));
    },
    $signature: 68
  };
  P.Uri_parseIPv6Address_error.prototype = {
    call$2: function(msg, position) {
      throw H.wrapException(P.FormatException$("Illegal IPv6 address, " + msg, this.host, position));
    },
    call$1: function(msg) {
      return this.call$2(msg, null);
    },
    $signature: 67
  };
  P.Uri_parseIPv6Address_parseHex.prototype = {
    call$2: function(start, end) {
      var value;
      if (end - start > 4)
        this.error.call$2("an IPv6 part can only contain a maximum of 4 hex digits", start);
      value = P.int_parse(C.JSString_methods.substring$2(this.host, start, end), null, 16);
      if (typeof value !== "number")
        return value.$lt();
      if (value < 0 || value > 65535)
        this.error.call$2("each part must be in the range of `0x0..0xFFFF`", start);
      return value;
    },
    $signature: 65
  };
  P._Uri.prototype = {
    get$userInfo: function() {
      return this._userInfo;
    },
    get$host: function(_) {
      var t1 = this._host;
      if (t1 == null)
        return "";
      if (C.JSString_methods.startsWith$1(t1, "["))
        return C.JSString_methods.substring$2(t1, 1, t1.length - 1);
      return t1;
    },
    get$port: function(_) {
      var t1 = this._port;
      if (t1 == null)
        return P._Uri__defaultPort(this.scheme);
      return t1;
    },
    get$query: function() {
      var t1 = this._query;
      return t1 == null ? "" : t1;
    },
    get$fragment: function() {
      var t1 = this._fragment;
      return t1 == null ? "" : t1;
    },
    replace$2$path$pathSegments: function(_, path, pathSegments) {
      var scheme, isFile, userInfo, port, host, hasAuthority, t1, _this = this;
      type$.Iterable_String._check(pathSegments);
      type$.Map_String_dynamic._check(null);
      scheme = _this.scheme;
      isFile = scheme === "file";
      userInfo = _this._userInfo;
      port = _this._port;
      host = _this._host;
      if (!(host != null))
        host = userInfo.length !== 0 || port != null || isFile ? "" : null;
      hasAuthority = host != null;
      t1 = path == null;
      if (!t1 || pathSegments != null)
        path = P._Uri__makePath(path, 0, t1 ? 0 : path.length, pathSegments, scheme, hasAuthority);
      else {
        path = _this.path;
        if (!isFile)
          t1 = hasAuthority && path.length !== 0;
        else
          t1 = true;
        if (t1 && !C.JSString_methods.startsWith$1(path, "/"))
          path = "/" + path;
      }
      return new P._Uri(scheme, userInfo, host, port, path, _this._query, _this._fragment);
    },
    replace$1$path: function($receiver, path) {
      return this.replace$2$path$pathSegments($receiver, path, null);
    },
    replace$1$pathSegments: function($receiver, pathSegments) {
      return this.replace$2$path$pathSegments($receiver, null, pathSegments);
    },
    get$pathSegments: function() {
      var pathToSplit,
        result = this._pathSegments;
      if (result != null)
        return result;
      pathToSplit = this.path;
      if (pathToSplit.length !== 0 && C.JSString_methods._codeUnitAt$1(pathToSplit, 0) === 47)
        pathToSplit = C.JSString_methods.substring$1(pathToSplit, 1);
      result = pathToSplit === "" ? C.List_empty : P.List_List$unmodifiable(new H.MappedListIterable(H.setRuntimeTypeInfo(pathToSplit.split("/"), type$.JSArray_String), type$.dynamic_Function_String._check(P.core_Uri_decodeComponent$closure()), type$.MappedListIterable_String_dynamic), type$.String);
      this.set$_pathSegments(result);
      return result;
    },
    _mergePaths$2: function(base, reference) {
      var backCount, refStart, baseEnd, newEnd, delta, t1;
      for (backCount = 0, refStart = 0; C.JSString_methods.startsWith$2(reference, "../", refStart);) {
        refStart += 3;
        ++backCount;
      }
      baseEnd = C.JSString_methods.lastIndexOf$1(base, "/");
      while (true) {
        if (!(baseEnd > 0 && backCount > 0))
          break;
        newEnd = C.JSString_methods.lastIndexOf$2(base, "/", baseEnd - 1);
        if (newEnd < 0)
          break;
        delta = baseEnd - newEnd;
        t1 = delta !== 2;
        if (!t1 || delta === 3)
          if (C.JSString_methods.codeUnitAt$1(base, newEnd + 1) === 46)
            t1 = !t1 || C.JSString_methods.codeUnitAt$1(base, newEnd + 2) === 46;
          else
            t1 = false;
        else
          t1 = false;
        if (t1)
          break;
        --backCount;
        baseEnd = newEnd;
      }
      return C.JSString_methods.replaceRange$3(base, baseEnd + 1, null, C.JSString_methods.substring$1(reference, refStart - 3 * backCount));
    },
    resolve$1: function(reference) {
      return this.resolveUri$1(P.Uri_parse(reference));
    },
    resolveUri$1: function(reference) {
      var targetScheme, targetUserInfo, targetHost, targetPort, targetPath, targetQuery, t1, mergedPath, t2, _this = this, _null = null;
      if (reference.get$scheme().length !== 0) {
        targetScheme = reference.get$scheme();
        if (reference.get$hasAuthority()) {
          targetUserInfo = reference.get$userInfo();
          targetHost = reference.get$host(reference);
          targetPort = reference.get$hasPort() ? reference.get$port(reference) : _null;
        } else {
          targetPort = _null;
          targetHost = targetPort;
          targetUserInfo = "";
        }
        targetPath = P._Uri__removeDotSegments(reference.get$path(reference));
        targetQuery = reference.get$hasQuery() ? reference.get$query() : _null;
      } else {
        targetScheme = _this.scheme;
        if (reference.get$hasAuthority()) {
          targetUserInfo = reference.get$userInfo();
          targetHost = reference.get$host(reference);
          targetPort = P._Uri__makePort(reference.get$hasPort() ? reference.get$port(reference) : _null, targetScheme);
          targetPath = P._Uri__removeDotSegments(reference.get$path(reference));
          targetQuery = reference.get$hasQuery() ? reference.get$query() : _null;
        } else {
          targetUserInfo = _this._userInfo;
          targetHost = _this._host;
          targetPort = _this._port;
          if (reference.get$path(reference) === "") {
            targetPath = _this.path;
            targetQuery = reference.get$hasQuery() ? reference.get$query() : _this._query;
          } else {
            if (reference.get$hasAbsolutePath())
              targetPath = P._Uri__removeDotSegments(reference.get$path(reference));
            else {
              t1 = _this.path;
              if (t1.length === 0)
                if (targetHost == null)
                  targetPath = targetScheme.length === 0 ? reference.get$path(reference) : P._Uri__removeDotSegments(reference.get$path(reference));
                else
                  targetPath = P._Uri__removeDotSegments("/" + reference.get$path(reference));
              else {
                mergedPath = _this._mergePaths$2(t1, reference.get$path(reference));
                t2 = targetScheme.length === 0;
                if (!t2 || targetHost != null || C.JSString_methods.startsWith$1(t1, "/"))
                  targetPath = P._Uri__removeDotSegments(mergedPath);
                else
                  targetPath = P._Uri__normalizeRelativePath(mergedPath, !t2 || targetHost != null);
              }
            }
            targetQuery = reference.get$hasQuery() ? reference.get$query() : _null;
          }
        }
      }
      return new P._Uri(targetScheme, targetUserInfo, targetHost, targetPort, targetPath, targetQuery, reference.get$hasFragment() ? reference.get$fragment() : _null);
    },
    get$hasAuthority: function() {
      return this._host != null;
    },
    get$hasPort: function() {
      return this._port != null;
    },
    get$hasQuery: function() {
      return this._query != null;
    },
    get$hasFragment: function() {
      return this._fragment != null;
    },
    get$hasAbsolutePath: function() {
      return C.JSString_methods.startsWith$1(this.path, "/");
    },
    toFilePath$0: function() {
      var windows, pathSegments, _this = this,
        t1 = _this.scheme;
      if (t1 !== "" && t1 !== "file")
        throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a " + H.S(t1) + " URI"));
      t1 = _this._query;
      if ((t1 == null ? "" : t1) !== "")
        throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a URI with a query component"));
      t1 = _this._fragment;
      if ((t1 == null ? "" : t1) !== "")
        throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a URI with a fragment component"));
      windows = $.$get$_Uri__isWindowsCached();
      if (H.boolConversionCheck(windows))
        t1 = P._Uri__toWindowsFilePath(_this);
      else {
        if (_this._host != null && _this.get$host(_this) !== "")
          H.throwExpression(P.UnsupportedError$("Cannot extract a non-Windows file path from a file URI with an authority"));
        pathSegments = _this.get$pathSegments();
        P._Uri__checkNonWindowsPathReservedCharacters(pathSegments, false);
        t1 = P.StringBuffer__writeAll(C.JSString_methods.startsWith$1(_this.path, "/") ? "/" : "", pathSegments, "/");
        t1 = t1.charCodeAt(0) == 0 ? t1 : t1;
      }
      return t1;
    },
    toString$0: function(_) {
      var t2, t3, t4, _this = this,
        t1 = _this._text;
      if (t1 == null) {
        t1 = _this.scheme;
        t2 = t1.length !== 0 ? t1 + ":" : "";
        t3 = _this._host;
        t4 = t3 == null;
        if (!t4 || t1 === "file") {
          t1 = t2 + "//";
          t2 = _this._userInfo;
          if (t2.length !== 0)
            t1 = t1 + t2 + "@";
          if (!t4)
            t1 += t3;
          t2 = _this._port;
          if (t2 != null)
            t1 = t1 + ":" + H.S(t2);
        } else
          t1 = t2;
        t1 += _this.path;
        t2 = _this._query;
        if (t2 != null)
          t1 = t1 + "?" + t2;
        t2 = _this._fragment;
        if (t2 != null)
          t1 = t1 + "#" + t2;
        t1 = _this._text = t1.charCodeAt(0) == 0 ? t1 : t1;
      }
      return t1;
    },
    $eq: function(_, other) {
      var t1, t2, _this = this;
      if (other == null)
        return false;
      if (_this === other)
        return true;
      if (type$.Uri._is(other))
        if (_this.scheme == other.get$scheme())
          if (_this._host != null === other.get$hasAuthority())
            if (_this._userInfo == other.get$userInfo())
              if (_this.get$host(_this) == other.get$host(other))
                if (_this.get$port(_this) == other.get$port(other))
                  if (_this.path === other.get$path(other)) {
                    t1 = _this._query;
                    t2 = t1 == null;
                    if (!t2 === other.get$hasQuery()) {
                      if (t2)
                        t1 = "";
                      if (t1 === other.get$query()) {
                        t1 = _this._fragment;
                        t2 = t1 == null;
                        if (!t2 === other.get$hasFragment()) {
                          if (t2)
                            t1 = "";
                          t1 = t1 === other.get$fragment();
                        } else
                          t1 = false;
                      } else
                        t1 = false;
                    } else
                      t1 = false;
                  } else
                    t1 = false;
                else
                  t1 = false;
              else
                t1 = false;
            else
              t1 = false;
          else
            t1 = false;
        else
          t1 = false;
      else
        t1 = false;
      return t1;
    },
    get$hashCode: function(_) {
      var t1 = this._hashCodeCache;
      return t1 == null ? this._hashCodeCache = C.JSString_methods.get$hashCode(this.toString$0(0)) : t1;
    },
    set$_pathSegments: function(_pathSegments) {
      this._pathSegments = type$.List_String._check(_pathSegments);
    },
    $isUri: 1,
    get$scheme: function() {
      return this.scheme;
    },
    get$path: function(receiver) {
      return this.path;
    }
  };
  P._Uri__Uri$notSimple_closure.prototype = {
    call$1: function(_) {
      throw H.wrapException(P.FormatException$("Invalid port", this.uri, this.portStart + 1));
    },
    $signature: 30
  };
  P._Uri__checkNonWindowsPathReservedCharacters_closure.prototype = {
    call$1: function(segment) {
      var _s23_ = "Illegal path character ";
      H._checkStringNullable(segment);
      if (J.contains$1$asx(segment, "/"))
        if (this.argumentError)
          throw H.wrapException(P.ArgumentError$(_s23_ + segment));
        else
          throw H.wrapException(P.UnsupportedError$(_s23_ + segment));
    },
    $signature: 30
  };
  P._Uri__makePath_closure.prototype = {
    call$1: function(s) {
      return P._Uri__uriEncode(C.List_qg40, H._checkStringNullable(s), C.C_Utf8Codec, false);
    },
    $signature: 7
  };
  P.UriData.prototype = {
    get$uri: function() {
      var t2, queryIndex, end, query, _this = this, _null = null,
        t1 = _this._uriCache;
      if (t1 != null)
        return t1;
      t1 = _this._separatorIndices;
      if (0 >= t1.length)
        return H.ioore(t1, 0);
      t2 = _this._text;
      t1 = t1[0] + 1;
      queryIndex = C.JSString_methods.indexOf$2(t2, "?", t1);
      end = t2.length;
      if (queryIndex >= 0) {
        query = P._Uri__normalizeOrSubstring(t2, queryIndex + 1, end, C.List_CVk, false);
        end = queryIndex;
      } else
        query = _null;
      return _this._uriCache = new P._DataUri("data", _null, _null, _null, P._Uri__normalizeOrSubstring(t2, t1, end, C.List_qg4, false), query, _null);
    },
    toString$0: function(_) {
      var t2,
        t1 = this._separatorIndices;
      if (0 >= t1.length)
        return H.ioore(t1, 0);
      t2 = this._text;
      return t1[0] === -1 ? "data:" + t2 : t2;
    }
  };
  P._createTables_closure.prototype = {
    call$1: function(_) {
      return new Uint8Array(96);
    },
    $signature: 64
  };
  P._createTables_build.prototype = {
    call$2: function(state, defaultTransition) {
      var t1 = this.tables;
      if (state >= t1.length)
        return H.ioore(t1, state);
      t1 = t1[state];
      J.fillRange$3$ax(t1, 0, 96, defaultTransition);
      return t1;
    },
    $signature: 62
  };
  P._createTables_setChars.prototype = {
    call$3: function(target, chars, transition) {
      var t1, t2, i, t3;
      for (t1 = chars.length, t2 = target.length, i = 0; i < t1; ++i) {
        t3 = C.JSString_methods._codeUnitAt$1(chars, i) ^ 96;
        if (t3 >= t2)
          return H.ioore(target, t3);
        target[t3] = transition;
      }
    },
    $signature: 41
  };
  P._createTables_setRange.prototype = {
    call$3: function(target, range, transition) {
      var i, n, t1, t2;
      for (i = C.JSString_methods._codeUnitAt$1(range, 0), n = C.JSString_methods._codeUnitAt$1(range, 1), t1 = target.length; i <= n; ++i) {
        t2 = (i ^ 96) >>> 0;
        if (t2 >= t1)
          return H.ioore(target, t2);
        target[t2] = transition;
      }
    },
    $signature: 41
  };
  P._SimpleUri.prototype = {
    get$hasAuthority: function() {
      return this._hostStart > 0;
    },
    get$hasPort: function() {
      return this._hostStart > 0 && this._portStart + 1 < this._pathStart;
    },
    get$hasQuery: function() {
      return this._queryStart < this._fragmentStart;
    },
    get$hasFragment: function() {
      return this._fragmentStart < this._uri.length;
    },
    get$_isFile: function() {
      return this._schemeEnd === 4 && C.JSString_methods.startsWith$1(this._uri, "file");
    },
    get$_isHttp: function() {
      return this._schemeEnd === 4 && C.JSString_methods.startsWith$1(this._uri, "http");
    },
    get$_isHttps: function() {
      return this._schemeEnd === 5 && C.JSString_methods.startsWith$1(this._uri, "https");
    },
    get$hasAbsolutePath: function() {
      return C.JSString_methods.startsWith$2(this._uri, "/", this._pathStart);
    },
    get$scheme: function() {
      var t2, _this = this,
        _s7_ = "package",
        t1 = _this._schemeEnd;
      if (t1 <= 0)
        return "";
      t2 = _this._schemeCache;
      if (t2 != null)
        return t2;
      if (_this.get$_isHttp())
        t1 = _this._schemeCache = "http";
      else if (_this.get$_isHttps()) {
        _this._schemeCache = "https";
        t1 = "https";
      } else if (_this.get$_isFile()) {
        _this._schemeCache = "file";
        t1 = "file";
      } else if (t1 === 7 && C.JSString_methods.startsWith$1(_this._uri, _s7_)) {
        _this._schemeCache = _s7_;
        t1 = _s7_;
      } else {
        t1 = C.JSString_methods.substring$2(_this._uri, 0, t1);
        _this._schemeCache = t1;
      }
      return t1;
    },
    get$userInfo: function() {
      var t1 = this._hostStart,
        t2 = this._schemeEnd + 3;
      return t1 > t2 ? C.JSString_methods.substring$2(this._uri, t2, t1 - 1) : "";
    },
    get$host: function(_) {
      var t1 = this._hostStart;
      return t1 > 0 ? C.JSString_methods.substring$2(this._uri, t1, this._portStart) : "";
    },
    get$port: function(_) {
      var _this = this;
      if (_this.get$hasPort())
        return P.int_parse(C.JSString_methods.substring$2(_this._uri, _this._portStart + 1, _this._pathStart), null, null);
      if (_this.get$_isHttp())
        return 80;
      if (_this.get$_isHttps())
        return 443;
      return 0;
    },
    get$path: function(_) {
      return C.JSString_methods.substring$2(this._uri, this._pathStart, this._queryStart);
    },
    get$query: function() {
      var t1 = this._queryStart,
        t2 = this._fragmentStart;
      return t1 < t2 ? C.JSString_methods.substring$2(this._uri, t1 + 1, t2) : "";
    },
    get$fragment: function() {
      var t1 = this._fragmentStart,
        t2 = this._uri;
      return t1 < t2.length ? C.JSString_methods.substring$1(t2, t1 + 1) : "";
    },
    get$pathSegments: function() {
      var parts, i,
        start = this._pathStart,
        end = this._queryStart,
        t1 = this._uri;
      if (C.JSString_methods.startsWith$2(t1, "/", start))
        ++start;
      if (start === end)
        return C.List_empty;
      parts = H.setRuntimeTypeInfo([], type$.JSArray_String);
      for (i = start; i < end; ++i)
        if (C.JSString_methods.codeUnitAt$1(t1, i) === 47) {
          C.JSArray_methods.add$1(parts, C.JSString_methods.substring$2(t1, start, i));
          start = i + 1;
        }
      C.JSArray_methods.add$1(parts, C.JSString_methods.substring$2(t1, start, end));
      return P.List_List$unmodifiable(parts, type$.String);
    },
    _isPort$1: function(port) {
      var portDigitStart = this._portStart + 1;
      return portDigitStart + port.length === this._pathStart && C.JSString_methods.startsWith$2(this._uri, port, portDigitStart);
    },
    removeFragment$0: function() {
      var _this = this,
        t1 = _this._fragmentStart,
        t2 = _this._uri;
      if (t1 >= t2.length)
        return _this;
      return new P._SimpleUri(C.JSString_methods.substring$2(t2, 0, t1), _this._schemeEnd, _this._hostStart, _this._portStart, _this._pathStart, _this._queryStart, t1, _this._schemeCache);
    },
    replace$2$path$pathSegments: function(_, path, pathSegments) {
      var scheme, isFile, t1, userInfo, port, host, hasAuthority, t2, query, fragment, _this = this, _null = null;
      type$.Iterable_String._check(pathSegments);
      type$.Map_String_dynamic._check(null);
      scheme = _this.get$scheme();
      isFile = scheme === "file";
      t1 = _this._hostStart;
      userInfo = t1 > 0 ? C.JSString_methods.substring$2(_this._uri, _this._schemeEnd + 3, t1) : "";
      port = _this.get$hasPort() ? _this.get$port(_this) : _null;
      t1 = _this._hostStart;
      if (t1 > 0)
        host = C.JSString_methods.substring$2(_this._uri, t1, _this._portStart);
      else
        host = userInfo.length !== 0 || port != null || isFile ? "" : _null;
      hasAuthority = host != null;
      t1 = path == null;
      if (!t1 || pathSegments != null)
        path = P._Uri__makePath(path, 0, t1 ? 0 : path.length, pathSegments, scheme, hasAuthority);
      else {
        path = C.JSString_methods.substring$2(_this._uri, _this._pathStart, _this._queryStart);
        if (!isFile)
          t1 = hasAuthority && path.length !== 0;
        else
          t1 = true;
        if (t1 && !C.JSString_methods.startsWith$1(path, "/"))
          path = "/" + path;
      }
      t1 = _this._queryStart;
      t2 = _this._fragmentStart;
      query = t1 < t2 ? C.JSString_methods.substring$2(_this._uri, t1 + 1, t2) : _null;
      t1 = _this._fragmentStart;
      t2 = _this._uri;
      fragment = t1 < t2.length ? C.JSString_methods.substring$1(t2, t1 + 1) : _null;
      return new P._Uri(scheme, userInfo, host, port, path, query, fragment);
    },
    replace$1$path: function($receiver, path) {
      return this.replace$2$path$pathSegments($receiver, path, null);
    },
    replace$1$pathSegments: function($receiver, pathSegments) {
      return this.replace$2$path$pathSegments($receiver, null, pathSegments);
    },
    resolve$1: function(reference) {
      return this.resolveUri$1(P.Uri_parse(reference));
    },
    resolveUri$1: function(reference) {
      if (reference instanceof P._SimpleUri)
        return this._simpleMerge$2(this, reference);
      return this._toNonSimple$0().resolveUri$1(reference);
    },
    _simpleMerge$2: function(base, ref) {
      var t2, t3, isSimple, delta, refStart, baseStart, baseEnd, baseUri, baseStart0, backCount, refStart0, insert,
        t1 = ref._schemeEnd;
      if (t1 > 0)
        return ref;
      t2 = ref._hostStart;
      if (t2 > 0) {
        t3 = base._schemeEnd;
        if (t3 <= 0)
          return ref;
        if (base.get$_isFile())
          isSimple = ref._pathStart !== ref._queryStart;
        else if (base.get$_isHttp())
          isSimple = !ref._isPort$1("80");
        else
          isSimple = !base.get$_isHttps() || !ref._isPort$1("443");
        if (isSimple) {
          delta = t3 + 1;
          return new P._SimpleUri(C.JSString_methods.substring$2(base._uri, 0, delta) + C.JSString_methods.substring$1(ref._uri, t1 + 1), t3, t2 + delta, ref._portStart + delta, ref._pathStart + delta, ref._queryStart + delta, ref._fragmentStart + delta, base._schemeCache);
        } else
          return this._toNonSimple$0().resolveUri$1(ref);
      }
      refStart = ref._pathStart;
      t1 = ref._queryStart;
      if (refStart === t1) {
        t2 = ref._fragmentStart;
        if (t1 < t2) {
          t3 = base._queryStart;
          delta = t3 - t1;
          return new P._SimpleUri(C.JSString_methods.substring$2(base._uri, 0, t3) + C.JSString_methods.substring$1(ref._uri, t1), base._schemeEnd, base._hostStart, base._portStart, base._pathStart, t1 + delta, t2 + delta, base._schemeCache);
        }
        t1 = ref._uri;
        if (t2 < t1.length) {
          t3 = base._fragmentStart;
          return new P._SimpleUri(C.JSString_methods.substring$2(base._uri, 0, t3) + C.JSString_methods.substring$1(t1, t2), base._schemeEnd, base._hostStart, base._portStart, base._pathStart, base._queryStart, t2 + (t3 - t2), base._schemeCache);
        }
        return base.removeFragment$0();
      }
      t2 = ref._uri;
      if (C.JSString_methods.startsWith$2(t2, "/", refStart)) {
        t3 = base._pathStart;
        delta = t3 - refStart;
        return new P._SimpleUri(C.JSString_methods.substring$2(base._uri, 0, t3) + C.JSString_methods.substring$1(t2, refStart), base._schemeEnd, base._hostStart, base._portStart, t3, t1 + delta, ref._fragmentStart + delta, base._schemeCache);
      }
      baseStart = base._pathStart;
      baseEnd = base._queryStart;
      if (baseStart === baseEnd && base._hostStart > 0) {
        for (; C.JSString_methods.startsWith$2(t2, "../", refStart);)
          refStart += 3;
        delta = baseStart - refStart + 1;
        return new P._SimpleUri(C.JSString_methods.substring$2(base._uri, 0, baseStart) + "/" + C.JSString_methods.substring$1(t2, refStart), base._schemeEnd, base._hostStart, base._portStart, baseStart, t1 + delta, ref._fragmentStart + delta, base._schemeCache);
      }
      baseUri = base._uri;
      for (baseStart0 = baseStart; C.JSString_methods.startsWith$2(baseUri, "../", baseStart0);)
        baseStart0 += 3;
      backCount = 0;
      while (true) {
        refStart0 = refStart + 3;
        if (!(refStart0 <= t1 && C.JSString_methods.startsWith$2(t2, "../", refStart)))
          break;
        ++backCount;
        refStart = refStart0;
      }
      for (insert = ""; baseEnd > baseStart0;) {
        --baseEnd;
        if (C.JSString_methods.codeUnitAt$1(baseUri, baseEnd) === 47) {
          if (backCount === 0) {
            insert = "/";
            break;
          }
          --backCount;
          insert = "/";
        }
      }
      if (baseEnd === baseStart0 && base._schemeEnd <= 0 && !C.JSString_methods.startsWith$2(baseUri, "/", baseStart)) {
        refStart -= backCount * 3;
        insert = "";
      }
      delta = baseEnd - refStart + insert.length;
      return new P._SimpleUri(C.JSString_methods.substring$2(baseUri, 0, baseEnd) + insert + C.JSString_methods.substring$1(t2, refStart), base._schemeEnd, base._hostStart, base._portStart, baseStart, t1 + delta, ref._fragmentStart + delta, base._schemeCache);
    },
    toFilePath$0: function() {
      var t1, t2, windows, _this = this;
      if (_this._schemeEnd >= 0 && !_this.get$_isFile())
        throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a " + H.S(_this.get$scheme()) + " URI"));
      t1 = _this._queryStart;
      t2 = _this._uri;
      if (t1 < t2.length) {
        if (t1 < _this._fragmentStart)
          throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a URI with a query component"));
        throw H.wrapException(P.UnsupportedError$("Cannot extract a file path from a URI with a fragment component"));
      }
      windows = $.$get$_Uri__isWindowsCached();
      if (H.boolConversionCheck(windows))
        t1 = P._Uri__toWindowsFilePath(_this);
      else {
        if (_this._hostStart < _this._portStart)
          H.throwExpression(P.UnsupportedError$("Cannot extract a non-Windows file path from a file URI with an authority"));
        t1 = C.JSString_methods.substring$2(t2, _this._pathStart, t1);
      }
      return t1;
    },
    get$hashCode: function(_) {
      var t1 = this._hashCodeCache;
      return t1 == null ? this._hashCodeCache = C.JSString_methods.get$hashCode(this._uri) : t1;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      if (this === other)
        return true;
      return type$.Uri._is(other) && this._uri === other.toString$0(0);
    },
    _toNonSimple$0: function() {
      var _this = this, _null = null,
        t1 = _this.get$scheme(),
        t2 = _this.get$userInfo(),
        t3 = _this._hostStart > 0 ? _this.get$host(_this) : _null,
        t4 = _this.get$hasPort() ? _this.get$port(_this) : _null,
        t5 = _this._uri,
        t6 = _this._queryStart,
        t7 = C.JSString_methods.substring$2(t5, _this._pathStart, t6),
        t8 = _this._fragmentStart;
      t6 = t6 < t8 ? _this.get$query() : _null;
      return new P._Uri(t1, t2, t3, t4, t7, t6, t8 < t5.length ? _this.get$fragment() : _null);
    },
    toString$0: function(_) {
      return this._uri;
    },
    $isUri: 1
  };
  P._DataUri.prototype = {};
  W.ApplicationCacheErrorEvent.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.Blob.prototype = {$isBlob: 1};
  W.DomError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.DomException.prototype = {
    toString$0: function(receiver) {
      return String(receiver);
    },
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.ErrorEvent.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.Event.prototype = {$isEvent: 1};
  W.EventTarget.prototype = {
    addEventListener$3: function(receiver, type, listener, useCapture) {
      type$.dynamic_Function_Event._check(listener);
      if (listener != null)
        this._addEventListener$3(receiver, type, listener, false);
    },
    _addEventListener$3: function(receiver, type, listener, options) {
      return receiver.addEventListener(type, H.convertDartClosureToJS(type$.dynamic_Function_Event._check(listener), 1), false);
    },
    _removeEventListener$3: function(receiver, type, listener, options) {
      return receiver.removeEventListener(type, H.convertDartClosureToJS(type$.dynamic_Function_Event._check(listener), 1), false);
    },
    $isEventTarget: 1
  };
  W.File.prototype = {$isFile: 1};
  W.Location.prototype = {
    get$origin: function(receiver) {
      if ("origin" in receiver)
        return receiver.origin;
      return H.S(receiver.protocol) + "//" + H.S(receiver.host);
    },
    toString$0: function(receiver) {
      return String(receiver);
    }
  };
  W.MediaError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.MediaKeyMessageEvent.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.MessageEvent.prototype = {$isMessageEvent: 1};
  W.MessagePort.prototype = {
    addEventListener$3: function(receiver, type, listener, useCapture) {
      type$.dynamic_Function_Event._check(listener);
      if (type === "message")
        receiver.start();
      this.super$EventTarget$addEventListener(receiver, type, listener, false);
    },
    postMessage$1: function(receiver, message) {
      type$.List_Object._check(null);
      receiver.postMessage(new P._StructuredCloneDart2Js([], []).walk$1(message));
      return;
    },
    $isMessagePort: 1
  };
  W.NavigatorUserMediaError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.OverconstrainedError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.PositionError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.PresentationConnectionCloseEvent.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.SpeechRecognitionError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  W.EventStreamProvider.prototype = {};
  W._EventStream.prototype = {
    get$isBroadcast: function() {
      return true;
    },
    listen$4$cancelOnError$onDone$onError: function(onData, cancelOnError, onDone, onError) {
      var t1 = this.$ti;
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      H._checkBoolNullable(cancelOnError);
      return W._EventStreamSubscription$(this._html$_target, this._eventType, onData, false, t1._precomputed1);
    },
    listen$3$onDone$onError: function(onData, onDone, onError) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, onError);
    },
    listen$1: function(onData) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, null, null);
    }
  };
  W._EventStreamSubscription.prototype = {
    cancel$0: function() {
      var _this = this;
      if (_this._html$_target == null)
        return null;
      _this._unlisten$0();
      _this._html$_target = null;
      _this.set$_html$_onData(null);
      return null;
    },
    pause$1: function(resumeSignal) {
      if (this._html$_target == null)
        return;
      ++this._pauseCount;
      this._unlisten$0();
    },
    pause$0: function() {
      return this.pause$1(null);
    },
    resume$0: function() {
      var _this = this;
      if (_this._html$_target == null || _this._pauseCount <= 0)
        return;
      --_this._pauseCount;
      _this._tryResume$0();
    },
    _tryResume$0: function() {
      var _this = this,
        t1 = _this._html$_onData;
      if (t1 != null && _this._pauseCount <= 0)
        J.addEventListener$3$x(_this._html$_target, _this._eventType, t1, false);
    },
    _unlisten$0: function() {
      var t3,
        t1 = this._html$_onData,
        t2 = t1 != null;
      if (t2) {
        t3 = this._html$_target;
        t3.toString;
        type$.dynamic_Function_Event._check(t1);
        if (t2)
          J._removeEventListener$3$x(t3, this._eventType, t1, false);
      }
    },
    set$_html$_onData: function(_onData) {
      this._html$_onData = type$.dynamic_Function_Event._check(_onData);
    }
  };
  W._EventStreamSubscription_closure.prototype = {
    call$1: function(e) {
      return this.onData.call$1(type$.Event._check(e));
    },
    $signature: 61
  };
  P._StructuredClone.prototype = {
    findSlot$1: function(value) {
      var i,
        t1 = this.values,
        $length = t1.length;
      for (i = 0; i < $length; ++i)
        if (t1[i] === value)
          return i;
      C.JSArray_methods.add$1(t1, value);
      C.JSArray_methods.add$1(this.copies, null);
      return $length;
    },
    walk$1: function(e) {
      var slot, t2, copy, _this = this, t1 = {};
      if (e == null)
        return e;
      if (H._isBool(e))
        return e;
      if (typeof e == "number")
        return e;
      if (typeof e == "string")
        return e;
      if (e instanceof P.DateTime)
        return new Date(e._value);
      if (type$.RegExp._is(e))
        throw H.wrapException(P.UnimplementedError$("structured clone of RegExp"));
      if (type$.File._is(e))
        return e;
      if (type$.Blob._is(e))
        return e;
      if (type$.NativeByteBuffer._is(e) || type$.NativeTypedData._is(e) || type$.MessagePort._is(e))
        return e;
      if (type$.Map_dynamic_dynamic._is(e)) {
        slot = _this.findSlot$1(e);
        t2 = _this.copies;
        if (slot >= t2.length)
          return H.ioore(t2, slot);
        copy = t1.copy = t2[slot];
        if (copy != null)
          return copy;
        copy = {};
        t1.copy = copy;
        C.JSArray_methods.$indexSet(t2, slot, copy);
        e.forEach$1(0, new P._StructuredClone_walk_closure(t1, _this));
        return t1.copy;
      }
      if (type$.List_dynamic._is(e)) {
        slot = _this.findSlot$1(e);
        t1 = _this.copies;
        if (slot >= t1.length)
          return H.ioore(t1, slot);
        copy = t1[slot];
        if (copy != null)
          return copy;
        return _this.copyList$2(e, slot);
      }
      if (type$.JSObject._is(e)) {
        slot = _this.findSlot$1(e);
        t2 = _this.copies;
        if (slot >= t2.length)
          return H.ioore(t2, slot);
        copy = t1.copy = t2[slot];
        if (copy != null)
          return copy;
        copy = {};
        t1.copy = copy;
        C.JSArray_methods.$indexSet(t2, slot, copy);
        _this.forEachObjectKey$2(e, new P._StructuredClone_walk_closure0(t1, _this));
        return t1.copy;
      }
      throw H.wrapException(P.UnimplementedError$("structured clone of other type"));
    },
    copyList$2: function(e, slot) {
      var i,
        t1 = J.getInterceptor$asx(e),
        $length = t1.get$length(e),
        copy = new Array($length);
      C.JSArray_methods.$indexSet(this.copies, slot, copy);
      for (i = 0; i < $length; ++i)
        C.JSArray_methods.$indexSet(copy, i, this.walk$1(t1.$index(e, i)));
      return copy;
    }
  };
  P._StructuredClone_walk_closure.prototype = {
    call$2: function(key, value) {
      this._box_0.copy[key] = this.$this.walk$1(value);
    },
    $signature: 6
  };
  P._StructuredClone_walk_closure0.prototype = {
    call$2: function(key, value) {
      this._box_0.copy[key] = this.$this.walk$1(value);
    },
    $signature: 6
  };
  P._AcceptStructuredClone.prototype = {
    findSlot$1: function(value) {
      var i,
        t1 = this.values,
        $length = t1.length;
      for (i = 0; i < $length; ++i)
        if (t1[i] === value)
          return i;
      C.JSArray_methods.add$1(t1, value);
      C.JSArray_methods.add$1(this.copies, null);
      return $length;
    },
    walk$1: function(e) {
      var millisSinceEpoch, t1, proto, slot, copy, t2, l, $length, i, _this = this, _box_0 = {};
      if (e == null)
        return e;
      if (H._isBool(e))
        return e;
      if (typeof e == "number")
        return e;
      if (typeof e == "string")
        return e;
      if (e instanceof Date) {
        millisSinceEpoch = e.getTime();
        if (Math.abs(millisSinceEpoch) <= 864e13)
          t1 = false;
        else
          t1 = true;
        if (t1)
          H.throwExpression(P.ArgumentError$("DateTime is outside valid range: " + millisSinceEpoch));
        return new P.DateTime(millisSinceEpoch, true);
      }
      if (e instanceof RegExp)
        throw H.wrapException(P.UnimplementedError$("structured clone of RegExp"));
      if (typeof Promise != "undefined" && e instanceof Promise)
        return P.promiseToFuture(e, type$.dynamic);
      proto = Object.getPrototypeOf(e);
      if (proto === Object.prototype || proto === null) {
        slot = _this.findSlot$1(e);
        t1 = _this.copies;
        if (slot >= t1.length)
          return H.ioore(t1, slot);
        copy = _box_0.copy = t1[slot];
        if (copy != null)
          return copy;
        t2 = type$.dynamic;
        copy = P.LinkedHashMap_LinkedHashMap$_empty(t2, t2);
        _box_0.copy = copy;
        C.JSArray_methods.$indexSet(t1, slot, copy);
        _this.forEachJsField$2(e, new P._AcceptStructuredClone_walk_closure(_box_0, _this));
        return _box_0.copy;
      }
      if (e instanceof Array) {
        l = e;
        slot = _this.findSlot$1(l);
        t1 = _this.copies;
        if (slot >= t1.length)
          return H.ioore(t1, slot);
        copy = t1[slot];
        if (copy != null)
          return copy;
        t2 = J.getInterceptor$asx(l);
        $length = t2.get$length(l);
        copy = _this.mustCopy ? new Array($length) : l;
        C.JSArray_methods.$indexSet(t1, slot, copy);
        for (t1 = J.getInterceptor$ax(copy), i = 0; i < $length; ++i)
          t1.$indexSet(copy, i, _this.walk$1(t2.$index(l, i)));
        return copy;
      }
      return e;
    },
    convertNativeToDart_AcceptStructuredClone$2$mustCopy: function(object, mustCopy) {
      this.mustCopy = true;
      return this.walk$1(object);
    }
  };
  P._AcceptStructuredClone_walk_closure.prototype = {
    call$2: function(key, value) {
      var t1 = this._box_0.copy,
        t2 = this.$this.walk$1(value);
      J.$indexSet$ax(t1, key, t2);
      return t2;
    },
    $signature: 60
  };
  P._StructuredCloneDart2Js.prototype = {
    forEachObjectKey$2: function(object, action) {
      var t1, t2, _i, key;
      type$.dynamic_Function_dynamic_dynamic._check(action);
      for (t1 = Object.keys(object), t2 = t1.length, _i = 0; _i < t2; ++_i) {
        key = t1[_i];
        action.call$2(key, object[key]);
      }
    }
  };
  P._AcceptStructuredCloneDart2Js.prototype = {
    forEachJsField$2: function(object, action) {
      var t1, t2, _i, key;
      type$.dynamic_Function_dynamic_dynamic._check(action);
      for (t1 = Object.keys(object), t2 = t1.length, _i = 0; _i < t1.length; t1.length === t2 || (0, H.throwConcurrentModificationError)(t1), ++_i) {
        key = t1[_i];
        action.call$2(key, object[key]);
      }
    }
  };
  P._convertDataTree__convert.prototype = {
    call$1: function(o) {
      var convertedMap, key, convertedList,
        t1 = this._convertedObjects;
      if (t1.containsKey$1(o))
        return t1.$index(0, o);
      if (type$.Map_dynamic_dynamic._is(o)) {
        convertedMap = {};
        t1.$indexSet(0, o, convertedMap);
        for (t1 = o.get$keys(), t1 = t1.get$iterator(t1); t1.moveNext$0();) {
          key = t1.get$current();
          convertedMap[key] = this.call$1(o.$index(0, key));
        }
        return convertedMap;
      } else if (type$.Iterable_dynamic._is(o)) {
        convertedList = [];
        t1.$indexSet(0, o, convertedList);
        C.JSArray_methods.addAll$1(convertedList, J.map$1$1$ax(o, this, type$.dynamic));
        return convertedList;
      } else
        return o;
    },
    $signature: 18
  };
  P.promiseToFuture_closure.prototype = {
    call$1: function(r) {
      return this.completer.complete$1(this.T._eval$1("0/")._check(r));
    },
    $signature: 15
  };
  P.promiseToFuture_closure0.prototype = {
    call$1: function(e) {
      return this.completer.completeError$1(e);
    },
    $signature: 15
  };
  P.ByteBuffer.prototype = {};
  P.ByteData.prototype = {};
  P.Int8List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Uint8List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Uint8ClampedList.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Int16List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Uint16List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Int32List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Uint32List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Float32List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.Float64List.prototype = {$isEfficientLengthIterable: 1, $isIterable: 1, $isList: 1};
  P.SqlError.prototype = {
    get$message: function(receiver) {
      return receiver.message;
    }
  };
  S.AsyncMemoizer.prototype = {
    runOnce$1: function(computation) {
      var t2, t3,
        t1 = this.$ti;
      t1._eval$1("1/()")._check(computation);
      t2 = this._async_memoizer$_completer;
      t3 = t2.future;
      if (t3._state === 0)
        t2.complete$1(P.Future_Future$sync(computation, t1._precomputed1));
      return t3;
    }
  };
  O.DelegatingSink.prototype = {$isSink: 1};
  Y.DelegatingStreamSubscription.prototype = {
    onData$1: function(handleData) {
      this._stream_subscription$_source.onData$1(this.$ti._eval$1("~(1)")._check(handleData));
    },
    onError$1: function(_, handleError) {
      this._stream_subscription$_source.onError$1(0, handleError);
    },
    onDone$1: function(handleDone) {
      this._stream_subscription$_source.onDone$1(type$.void_Function._check(handleDone));
    },
    pause$1: function(resumeFuture) {
      this._stream_subscription$_source.pause$1(resumeFuture);
    },
    pause$0: function() {
      return this.pause$1(null);
    },
    resume$0: function() {
      this._stream_subscription$_source.resume$0();
    },
    cancel$0: function() {
      return this._stream_subscription$_source.cancel$0();
    },
    $isStreamSubscription: 1
  };
  F.FutureGroup.prototype = {
    add$1: function(_, task) {
      var t1, index, _this = this;
      _this.$ti._eval$1("Future<1>")._check(task);
      if (_this._future_group$_closed)
        throw H.wrapException(P.StateError$("The FutureGroup is closed."));
      t1 = _this._values;
      index = t1.length;
      C.JSArray_methods.add$1(t1, null);
      ++_this._future_group$_pending;
      task.then$1$1(new F.FutureGroup_add_closure(_this, index), type$.Null).catchError$1(new F.FutureGroup_add_closure0(_this));
    },
    close$0: function(_) {
      var t1, _this = this;
      _this._future_group$_closed = true;
      if (_this._future_group$_pending !== 0)
        return;
      t1 = _this._future_group$_completer;
      if (t1.future._state !== 0)
        return;
      t1.complete$1(_this._values);
    },
    $isSink: 1
  };
  F.FutureGroup_add_closure.prototype = {
    call$1: function(value) {
      var t2, t3,
        t1 = this.$this;
      t1.$ti._precomputed1._check(value);
      t2 = t1._future_group$_completer;
      if (t2.future._state !== 0)
        return null;
      --t1._future_group$_pending;
      t3 = t1._values;
      C.JSArray_methods.$indexSet(t3, this.index, value);
      if (t1._future_group$_pending !== 0)
        return null;
      if (!t1._future_group$_closed)
        return null;
      t2.complete$1(t3);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(1)");
    }
  };
  F.FutureGroup_add_closure0.prototype = {
    call$2: function(error, stackTrace) {
      var t1 = this.$this._future_group$_completer;
      if (t1.future._state !== 0)
        return null;
      t1.completeError$2(error, type$.StackTrace._check(stackTrace));
    },
    $signature: 6
  };
  S.NullStreamSink.prototype = {
    add$1: function(_, data) {
      this.$ti._precomputed1._check(data);
      this._checkEventAllowed$0();
    },
    addStream$1: function(stream) {
      var future, _this = this;
      _this.$ti._eval$1("Stream<1>")._check(stream);
      _this._checkEventAllowed$0();
      _this._addingStream = true;
      future = stream.listen$1(null).cancel$0();
      if (future == null) {
        future = new P._Future($.Zone__current, type$._Future_dynamic);
        future._asyncComplete$1(null);
      }
      return future.whenComplete$1(new S.NullStreamSink_addStream_closure(_this));
    },
    _checkEventAllowed$0: function() {
      if (this._null_stream_sink$_closed)
        throw H.wrapException(P.StateError$("Cannot add to a closed sink."));
      if (this._addingStream)
        throw H.wrapException(P.StateError$("Cannot add to a sink while adding a stream."));
    },
    close$0: function(_) {
      this._null_stream_sink$_closed = true;
      return this.done;
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isSink: 1,
    get$done: function() {
      return this.done;
    }
  };
  S.NullStreamSink_addStream_closure.prototype = {
    call$0: function() {
      this.$this._addingStream = false;
    },
    $signature: 0
  };
  V.ErrorResult.prototype = {
    complete$1: function(completer) {
      completer.completeError$2(this.error, this.stackTrace);
    },
    addTo$1: function(sink) {
      sink.addError$2(this.error, this.stackTrace);
    },
    get$hashCode: function(_) {
      return (J.get$hashCode$(this.error) ^ J.get$hashCode$(this.stackTrace) ^ 492929599) >>> 0;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof V.ErrorResult && J.$eq$(this.error, other.error) && this.stackTrace == other.stackTrace;
    },
    $isResult: 1
  };
  E.Result.prototype = {};
  F.ValueResult.prototype = {
    complete$1: function(completer) {
      this.$ti._eval$1("Completer<1>")._check(completer).complete$1(this.value);
    },
    addTo$1: function(sink) {
      this.$ti._eval$1("EventSink<1>")._check(sink).add$1(0, this.value);
    },
    get$hashCode: function(_) {
      return (J.get$hashCode$(this.value) ^ 842997089) >>> 0;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof F.ValueResult && J.$eq$(this.value, other.value);
    },
    $isResult: 1
  };
  Y.StreamCompleter.prototype = {
    setSourceStream$1: function(sourceStream) {
      var t1;
      this.$ti._eval$1("Stream<1>")._check(sourceStream);
      t1 = this._stream;
      if (t1._sourceStream != null)
        throw H.wrapException(P.StateError$("Source stream already set"));
      t1.set$_sourceStream(t1.$ti._eval$1("Stream<1>")._check(sourceStream));
      if (t1._stream_completer$_controller != null)
        t1._linkStreamToController$0();
    }
  };
  Y._CompleterStream.prototype = {
    listen$4$cancelOnError$onDone$onError: function(onData, cancelOnError, onDone, onError) {
      var t1, _this = this;
      _this.$ti._eval$1("@(1)")._check(onData);
      type$.void_Function._check(onDone);
      H._checkBoolNullable(cancelOnError);
      if (_this._stream_completer$_controller == null) {
        t1 = _this._sourceStream;
        if (t1 != null && !t1.get$isBroadcast())
          return _this._sourceStream.listen$4$cancelOnError$onDone$onError(onData, cancelOnError, onDone, onError);
        _this._createController$0();
        if (_this._sourceStream != null)
          _this._linkStreamToController$0();
      }
      t1 = _this._stream_completer$_controller;
      t1.toString;
      return new P._ControllerStream(t1, H._instanceType(t1)._eval$1("_ControllerStream<1>")).listen$4$cancelOnError$onDone$onError(onData, cancelOnError, onDone, onError);
    },
    listen$3$onDone$onError: function(onData, onDone, onError) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, onError);
    },
    listen$1: function(onData) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, null, null);
    },
    _linkStreamToController$0: function() {
      var t1, t2, _this = this;
      H.assertHelper(_this._stream_completer$_controller != null);
      H.assertHelper(_this._sourceStream != null);
      t1 = _this._stream_completer$_controller.addStream$2$cancelOnError(_this._sourceStream, false);
      t2 = _this._stream_completer$_controller;
      t1.whenComplete$1(t2.get$close(t2));
    },
    _createController$0: function() {
      H.assertHelper(this._stream_completer$_controller == null);
      this.set$_stream_completer$_controller(P.StreamController_StreamController(null, null, true, this.$ti._precomputed1));
    },
    set$_stream_completer$_controller: function(_controller) {
      this._stream_completer$_controller = this.$ti._eval$1("StreamController<1>")._check(_controller);
    },
    set$_sourceStream: function(_sourceStream) {
      this._sourceStream = this.$ti._eval$1("Stream<1>")._check(_sourceStream);
    }
  };
  L.StreamGroup.prototype = {
    add$1: function(_, stream) {
      var t1, _this = this;
      _this.$ti._eval$1("Stream<1>")._check(stream);
      if (_this._stream_group$_closed)
        throw H.wrapException(P.StateError$("Can't add a Stream to a closed StreamGroup."));
      t1 = _this._stream_group$_state;
      if (t1 === C._StreamGroupState_dormant)
        _this._stream_group$_subscriptions.putIfAbsent$2(stream, new L.StreamGroup_add_closure());
      else if (t1 === C._StreamGroupState_canceled)
        return stream.listen$1(null).cancel$0();
      else
        _this._stream_group$_subscriptions.putIfAbsent$2(stream, new L.StreamGroup_add_closure0(_this, stream));
      return null;
    },
    _onListen$0: function() {
      this._stream_group$_state = C._StreamGroupState_listening;
      this._stream_group$_subscriptions.forEach$1(0, new L.StreamGroup__onListen_closure(this));
    },
    _onCancelBroadcast$0: function() {
      this._stream_group$_state = C._StreamGroupState_dormant;
      this._stream_group$_subscriptions.forEach$1(0, new L.StreamGroup__onCancelBroadcast_closure(this));
    },
    _listenToStream$1: function(stream) {
      var t1, subscription, _this = this;
      _this.$ti._eval$1("Stream<1>")._check(stream);
      t1 = _this._stream_group$_controller;
      subscription = stream.listen$3$onDone$onError(t1.get$add(t1), new L.StreamGroup__listenToStream_closure(_this, stream), t1.get$addError());
      if (_this._stream_group$_state === C._StreamGroupState_paused)
        subscription.pause$0();
      return subscription;
    },
    close$0: function(_) {
      var t1, _this = this;
      if (_this._stream_group$_closed)
        return _this._stream_group$_controller._ensureDoneFuture$0();
      _this._stream_group$_closed = true;
      t1 = _this._stream_group$_subscriptions;
      if (t1.get$isEmpty(t1))
        _this._stream_group$_controller.close$0(0);
      return _this._stream_group$_controller._ensureDoneFuture$0();
    },
    set$_stream_group$_controller: function(_controller) {
      this._stream_group$_controller = this.$ti._eval$1("StreamController<1>")._check(_controller);
    },
    $isSink: 1
  };
  L.StreamGroup_add_closure.prototype = {
    call$0: function() {
      return null;
    },
    $signature: 0
  };
  L.StreamGroup_add_closure0.prototype = {
    call$0: function() {
      return this.$this._listenToStream$1(this.stream);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("StreamSubscription<1>()");
    }
  };
  L.StreamGroup__onListen_closure.prototype = {
    call$2: function(stream, subscription) {
      var t1 = this.$this,
        t2 = t1.$ti;
      t2._eval$1("Stream<1>")._check(stream);
      if (t2._eval$1("StreamSubscription<1>")._check(subscription) != null)
        return;
      t1._stream_group$_subscriptions.$indexSet(0, stream, t1._listenToStream$1(stream));
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(Stream<1>,StreamSubscription<1>)");
    }
  };
  L.StreamGroup__onCancelBroadcast_closure.prototype = {
    call$2: function(stream, subscription) {
      var t1 = this.$this,
        t2 = t1.$ti;
      t2._eval$1("Stream<1>")._check(stream);
      t2._eval$1("StreamSubscription<1>")._check(subscription);
      if (!stream.get$isBroadcast())
        return;
      subscription.cancel$0();
      t1._stream_group$_subscriptions.$indexSet(0, stream, null);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(Stream<1>,StreamSubscription<1>)");
    }
  };
  L.StreamGroup__listenToStream_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._stream_group$_subscriptions,
        subscription = t2.remove$1(0, t1.$ti._eval$1("Stream<1>")._check(this.stream)),
        future = subscription == null ? null : subscription.cancel$0();
      if (t1._stream_group$_closed && t2.get$isEmpty(t2))
        t1._stream_group$_controller.close$0(0);
      return future;
    },
    $signature: 14
  };
  L._StreamGroupState.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  G.StreamQueue.prototype = {
    get$next: function() {
      var t1, t2, _this = this;
      if (!_this._isClosed) {
        t1 = _this.$ti;
        t2 = new P._Future($.Zone__current, t1._eval$1("_Future<1>"));
        _this._addRequest$1(new G._NextRequest(new P._AsyncCompleter(t2, t1._eval$1("_AsyncCompleter<1>")), t1._eval$1("_NextRequest<1>")));
        return t2;
      }
      throw H.wrapException(_this._failClosed$0());
    },
    _updateRequests$0: function() {
      var t1, t2, t3, t4, _this = this;
      for (t1 = _this._requestQueue, t2 = _this._eventQueue; !t1.get$isEmpty(t1);) {
        t3 = t1._head;
        if (t3 === t1._tail)
          H.throwExpression(H.IterableElementError_noElement());
        t4 = t1._table;
        if (t3 >= t4.length)
          return H.ioore(t4, t3);
        if (t4[t3].update$2(t2, _this._isDone))
          t1.removeFirst$0();
        else
          return;
      }
      if (!_this._isDone)
        _this._stream_queue$_subscription.pause$0();
    },
    _extractStream$0: function() {
      var t1, wasPaused, _this = this, _null = null;
      H.assertHelper(_this._isClosed);
      if (_this._isDone)
        return new P._EmptyStream(_this.$ti._eval$1("_EmptyStream<1>"));
      _this._isDone = true;
      t1 = _this._stream_queue$_subscription;
      if (t1 == null)
        return _this._stream_queue$_source;
      _this.set$_stream_queue$_subscription(_null);
      wasPaused = t1.get$isPaused();
      t1.pause$0();
      t1.onData$1(_null);
      t1.onError$1(0, _null);
      t1.onDone$1(_null);
      if (wasPaused)
        t1.resume$0();
      return new T.SubscriptionStream(t1, _this.$ti._eval$1("SubscriptionStream<1>"));
    },
    _ensureListening$0: function() {
      var t1, _this = this;
      if (_this._isDone)
        return;
      t1 = _this._stream_queue$_subscription;
      if (t1 == null)
        _this.set$_stream_queue$_subscription(_this._stream_queue$_source.listen$3$onDone$onError(new G.StreamQueue__ensureListening_closure(_this), new G.StreamQueue__ensureListening_closure0(_this), new G.StreamQueue__ensureListening_closure1(_this)));
      else
        t1.resume$0();
    },
    _addResult$1: function(result) {
      var t1, _this = this;
      _this.$ti._eval$1("Result<1>")._check(result);
      ++_this._eventsReceived;
      t1 = _this._eventQueue;
      t1._queue_list$_add$1(t1.$ti._precomputed1._check(result));
      _this._updateRequests$0();
    },
    _failClosed$0: function() {
      return new P.StateError("Already cancelled");
    },
    _addRequest$1: function(request) {
      var t1, _this = this;
      _this.$ti._eval$1("_EventRequest<1>")._check(request);
      t1 = _this._requestQueue;
      if (t1._head === t1._tail) {
        if (request.update$2(_this._eventQueue, _this._isDone))
          return;
        _this._ensureListening$0();
      }
      t1._collection$_add$1(t1.$ti._precomputed1._check(request));
    },
    set$_stream_queue$_subscription: function(_subscription) {
      this._stream_queue$_subscription = this.$ti._eval$1("StreamSubscription<1>")._check(_subscription);
    }
  };
  G.StreamQueue__ensureListening_closure.prototype = {
    call$1: function(data) {
      var t1 = this.$this,
        t2 = t1.$ti;
      t1._addResult$1(new F.ValueResult(t2._precomputed1._check(data), t2._eval$1("ValueResult<1>")));
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Null(1)");
    }
  };
  G.StreamQueue__ensureListening_closure1.prototype = {
    call$2: function(error, stackTrace) {
      this.$this._addResult$1(new V.ErrorResult(error, type$.StackTrace._check(stackTrace)));
    },
    $signature: 5
  };
  G.StreamQueue__ensureListening_closure0.prototype = {
    call$0: function() {
      var t1 = this.$this;
      t1.set$_stream_queue$_subscription(null);
      t1._isDone = true;
      t1._updateRequests$0();
    },
    $signature: 0
  };
  G._EventRequest.prototype = {};
  G._NextRequest.prototype = {
    update$2: function(events, isDone) {
      this.$ti._eval$1("QueueList<Result<1>>")._check(events);
      if (events.get$length(events) !== 0) {
        events.removeFirst$0().complete$1(this._completer);
        return true;
      }
      if (isDone) {
        this._completer.completeError$2(new P.StateError("No elements"), P.StackTrace_current());
        return true;
      }
      return false;
    },
    $is_EventRequest: 1
  };
  G._RestRequest.prototype = {
    update$2: function(events, isDone) {
      var t2, controller, _this = this,
        t1 = _this.$ti;
      t1._eval$1("QueueList<Result<1>>")._check(events);
      if (events.get$length(events) === 0) {
        t1 = _this._streamQueue;
        t2 = _this._completer;
        if (t1._isDone) {
          t1 = t2._stream;
          t2 = t1._sourceStream == null;
          if (!t2)
            H.throwExpression(P.StateError$("Source stream already set"));
          H.assertHelper(t2);
          if (t1._stream_completer$_controller == null)
            t1._createController$0();
          t2 = t1._stream_completer$_controller;
          t2.toString;
          t1.set$_sourceStream(new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")));
          t1._stream_completer$_controller.close$0(0);
        } else
          t2.setSourceStream$1(t1._extractStream$0());
      } else {
        controller = P.StreamController_StreamController(null, null, false, t1._precomputed1);
        for (t1 = new H.ListIterator(events, events.get$length(events), events.$ti._eval$1("ListIterator<ListMixin.E>")); t1.moveNext$0();)
          t1.__internal$_current.addTo$1(controller);
        controller.addStream$2$cancelOnError(_this._streamQueue._extractStream$0(), false).whenComplete$1(controller.get$close(controller));
        _this._completer.setSourceStream$1(new P._ControllerStream(controller, H._instanceType(controller)._eval$1("_ControllerStream<1>")));
      }
      return true;
    },
    $is_EventRequest: 1
  };
  T.StreamSinkCompleter.prototype = {};
  T._CompleterSink.prototype = {
    get$_canSendDirectly: function() {
      return this._stream_sink_completer$_controller == null && this._destinationSink != null;
    },
    get$done: function() {
      var t1 = this._stream_sink_completer$_doneCompleter;
      if (t1 != null)
        return t1.future;
      t1 = this._destinationSink;
      if (t1 == null) {
        t1 = new P._Future($.Zone__current, type$._Future_dynamic);
        this._stream_sink_completer$_doneCompleter = new P._SyncCompleter(t1, type$._SyncCompleter_dynamic);
        return t1;
      }
      return t1.get$done();
    },
    addStream$1: function(stream) {
      var _this = this;
      _this.$ti._eval$1("Stream<1>")._check(stream);
      if (_this.get$_canSendDirectly())
        return _this._destinationSink.addStream$1(stream);
      _this._ensureController$0();
      return _this._stream_sink_completer$_controller.addStream$2$cancelOnError(stream, false);
    },
    close$0: function(_) {
      var _this = this;
      if (_this.get$_canSendDirectly())
        _this._destinationSink.close$0(0);
      else {
        _this._ensureController$0();
        _this._stream_sink_completer$_controller.close$0(0);
      }
      return _this.get$done();
    },
    _ensureController$0: function() {
      if (this._stream_sink_completer$_controller == null)
        this.set$_stream_sink_completer$_controller(P.StreamController_StreamController(null, null, true, this.$ti._precomputed1));
    },
    _setDestinationSink$1: function(sink) {
      var t1, _this = this;
      _this.$ti._eval$1("StreamSink<1>")._check(sink);
      H.assertHelper(_this._destinationSink == null);
      _this.set$_destinationSink(sink);
      t1 = _this._stream_sink_completer$_controller;
      if (t1 != null)
        sink.addStream$1(new P._ControllerStream(t1, H._instanceType(t1)._eval$1("_ControllerStream<1>"))).whenComplete$1(sink.get$close(sink)).catchError$1(new T._CompleterSink__setDestinationSink_closure());
      t1 = _this._stream_sink_completer$_doneCompleter;
      if (t1 != null)
        t1.complete$1(sink.get$done());
    },
    set$_stream_sink_completer$_controller: function(_controller) {
      this._stream_sink_completer$_controller = this.$ti._eval$1("StreamController<1>")._check(_controller);
    },
    set$_destinationSink: function(_destinationSink) {
      this._destinationSink = this.$ti._eval$1("StreamSink<1>")._check(_destinationSink);
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isSink: 1
  };
  T._CompleterSink__setDestinationSink_closure.prototype = {
    call$1: function(_) {
    },
    $signature: 3
  };
  T.SubscriptionStream.prototype = {
    listen$4$cancelOnError$onDone$onError: function(onData, cancelOnError, onDone, onError) {
      var result, result0,
        t1 = this.$ti;
      t1._eval$1("~(1)")._check(onData);
      type$.void_Function._check(onDone);
      H._checkBoolNullable(cancelOnError);
      result = this._subscription_stream$_source;
      if (result == null)
        throw H.wrapException(P.StateError$("Stream has already been listened to."));
      this.set$_subscription_stream$_source(null);
      result0 = true === cancelOnError ? new T._CancelOnErrorSubscriptionWrapper(result, t1._eval$1("_CancelOnErrorSubscriptionWrapper<1>")) : result;
      result0.onData$1(onData);
      result0.onError$1(0, onError);
      result0.onDone$1(onDone);
      result.resume$0();
      return result0;
    },
    listen$3$onDone$onError: function(onData, onDone, onError) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, onDone, onError);
    },
    listen$1: function(onData) {
      return this.listen$4$cancelOnError$onDone$onError(onData, null, null, null);
    },
    set$_subscription_stream$_source: function(_source) {
      this._subscription_stream$_source = this.$ti._eval$1("StreamSubscription<1>")._check(_source);
    }
  };
  T._CancelOnErrorSubscriptionWrapper.prototype = {
    onError$1: function(_, handleError) {
      this.super$DelegatingStreamSubscription$onError(0, new T._CancelOnErrorSubscriptionWrapper_onError_closure(this, handleError));
    }
  };
  T._CancelOnErrorSubscriptionWrapper_onError_closure.prototype = {
    call$2: function(error, stackTrace) {
      var cancelFuture, t1;
      type$.StackTrace._check(stackTrace);
      cancelFuture = this.$this.super$DelegatingStreamSubscription$cancel();
      if (cancelFuture != null)
        cancelFuture.whenComplete$1(new T._CancelOnErrorSubscriptionWrapper_onError__closure(this.handleError, error, stackTrace));
      else {
        t1 = this.handleError;
        if (type$.dynamic_Function_dynamic_dynamic._is(t1))
          t1.call$2(error, stackTrace);
        else
          t1.call$1(error);
      }
    },
    $signature: 5
  };
  T._CancelOnErrorSubscriptionWrapper_onError__closure.prototype = {
    call$0: function() {
      var t1 = this.handleError,
        t2 = this.error;
      if (type$.dynamic_Function_dynamic_dynamic._is(t1))
        t1.call$2(t2, this.stackTrace);
      else
        t1.call$1(t2);
    },
    $signature: 0
  };
  X.BooleanSelector.prototype = {};
  X.All.prototype = {
    evaluate$1: function(semantics) {
      return true;
    },
    intersection$1: function(other) {
      return other;
    },
    validate$1: function(isDefined) {
      type$.bool_Function_String._check(isDefined);
    },
    toString$0: function(_) {
      return "<all>";
    },
    $isBooleanSelector: 1
  };
  U.VariableNode.prototype = {
    accept$1: function(visitor) {
      return visitor.visitVariable$1(this);
    },
    toString$0: function(_) {
      return this.name;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof U.VariableNode && this.name == other.name;
    },
    get$hashCode: function(_) {
      return J.get$hashCode$(this.name);
    },
    $isNode: 1,
    get$span: function() {
      return this.span;
    }
  };
  U.NotNode.prototype = {
    accept$1: function(visitor) {
      return visitor.visitNot$1(this);
    },
    toString$0: function(_) {
      var t1 = this.child;
      return t1 instanceof U.VariableNode || t1 instanceof U.NotNode ? "!" + t1.toString$0(0) : "!(" + t1.toString$0(0) + ")";
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof U.NotNode && this.child.$eq(0, other.child);
    },
    get$hashCode: function(_) {
      var t1 = this.child;
      return ~t1.get$hashCode(t1) >>> 0;
    },
    $isNode: 1,
    get$span: function() {
      return this.span;
    }
  };
  U.OrNode.prototype = {
    get$span: function() {
      return U._expandSafe(this.left.get$span(), this.right.get$span());
    },
    accept$1: function(visitor) {
      return visitor.visitOr$1(this);
    },
    toString$0: function(_) {
      var string2,
        string1 = this.left;
      if (string1 instanceof U.AndNode || string1 instanceof U.ConditionalNode)
        string1 = "(" + string1.toString$0(0) + ")";
      string2 = this.right;
      if (string2 instanceof U.AndNode || string2 instanceof U.ConditionalNode)
        string2 = "(" + string2.toString$0(0) + ")";
      return H.S(string1) + " || " + H.S(string2);
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof U.OrNode && this.left.$eq(0, other.left) && this.right.$eq(0, other.right);
    },
    get$hashCode: function(_) {
      var t1 = this.left,
        t2 = this.right;
      return (t1.get$hashCode(t1) ^ t2.get$hashCode(t2)) >>> 0;
    },
    $isNode: 1
  };
  U.AndNode.prototype = {
    get$span: function() {
      return U._expandSafe(this.left.get$span(), this.right.get$span());
    },
    accept$1: function(visitor) {
      return visitor.visitAnd$1(this);
    },
    toString$0: function(_) {
      var string2,
        string1 = this.left;
      if (string1 instanceof U.OrNode || string1 instanceof U.ConditionalNode)
        string1 = "(" + string1.toString$0(0) + ")";
      string2 = this.right;
      if (string2 instanceof U.OrNode || string2 instanceof U.ConditionalNode)
        string2 = "(" + string2.toString$0(0) + ")";
      return H.S(string1) + " && " + H.S(string2);
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof U.AndNode && this.left.$eq(0, other.left) && this.right.$eq(0, other.right);
    },
    get$hashCode: function(_) {
      var t1 = this.left,
        t2 = this.right;
      return (t1.get$hashCode(t1) ^ t2.get$hashCode(t2)) >>> 0;
    },
    $isNode: 1
  };
  U.ConditionalNode.prototype = {
    get$span: function() {
      return U._expandSafe(this.condition.get$span(), this.whenFalse.get$span());
    },
    accept$1: function(visitor) {
      return visitor.visitConditional$1(this);
    },
    toString$0: function(_) {
      var trueString,
        conditionString = this.condition;
      if (conditionString instanceof U.ConditionalNode)
        conditionString = "(" + conditionString.toString$0(0) + ")";
      trueString = this.whenTrue;
      if (trueString instanceof U.ConditionalNode)
        trueString = "(" + trueString.toString$0(0) + ")";
      return H.S(conditionString) + " ? " + H.S(trueString) + " : " + this.whenFalse.toString$0(0);
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof U.ConditionalNode && this.condition.$eq(0, other.condition) && this.whenTrue.$eq(0, other.whenTrue) && this.whenFalse.$eq(0, other.whenFalse);
    },
    get$hashCode: function(_) {
      var t1 = this.condition,
        t2 = this.whenTrue,
        t3 = this.whenFalse;
      return (t1.get$hashCode(t1) ^ t2.get$hashCode(t2) ^ t3.get$hashCode(t3)) >>> 0;
    },
    $isNode: 1
  };
  T.Evaluator.prototype = {
    visitVariable$1: function(node) {
      return this._semantics.call$1(node.name);
    },
    visitNot$1: function(node) {
      return !H.boolConversionCheck(node.child.accept$1(this));
    },
    visitOr$1: function(node) {
      return H.boolConversionCheck(node.left.accept$1(this)) || H.boolConversionCheck(node.right.accept$1(this));
    },
    visitAnd$1: function(node) {
      return H.boolConversionCheck(node.left.accept$1(this)) && H.boolConversionCheck(node.right.accept$1(this));
    },
    visitConditional$1: function(node) {
      return H.boolConversionCheck(node.condition.accept$1(this)) ? node.whenTrue.accept$1(this) : node.whenFalse.accept$1(this);
    },
    $isVisitor: 1
  };
  Y.BooleanSelectorImpl.prototype = {
    evaluate$1: function(semantics) {
      var t1;
      if (type$.Iterable_dynamic._is(semantics)) {
        t1 = semantics.toSet$0(0);
        t1 = t1.get$contains(t1);
      } else {
        type$.bool_Function_String._as(semantics);
        t1 = semantics;
      }
      return this._selector.accept$1(new T.Evaluator(t1));
    },
    intersection$1: function(other) {
      var t1 = J.getInterceptor$(other);
      if (t1.$eq(other, C.C_All))
        return this;
      if (t1.$eq(other, C.C_None))
        return other;
      return other instanceof Y.BooleanSelectorImpl ? new Y.BooleanSelectorImpl(new U.AndNode(this._selector, other._selector)) : new R.IntersectionSelector(this, other);
    },
    validate$1: function(isDefined) {
      this._selector.accept$1(new S.Validator(type$.bool_Function_String._check(isDefined)));
    },
    toString$0: function(_) {
      return this._selector.toString$0(0);
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof Y.BooleanSelectorImpl && this._selector.$eq(0, other._selector);
    },
    get$hashCode: function(_) {
      var t1 = this._selector;
      return t1.get$hashCode(t1);
    },
    $isBooleanSelector: 1
  };
  R.IntersectionSelector.prototype = {
    evaluate$1: function(semantics) {
      return H.boolConversionCheck(this._selector1.evaluate$1(semantics)) && H.boolConversionCheck(this._selector2.evaluate$1(semantics));
    },
    intersection$1: function(other) {
      return new R.IntersectionSelector(this, other);
    },
    validate$1: function(isDefined) {
      type$.bool_Function_String._check(isDefined);
      this._selector1.validate$1(isDefined);
      this._selector2.validate$1(isDefined);
    },
    toString$0: function(_) {
      return "(" + this._selector1.toString$0(0) + ") && (" + H.S(this._selector2) + ")";
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof R.IntersectionSelector && this._selector1.$eq(0, other._selector1) && J.$eq$(this._selector2, other._selector2);
    },
    get$hashCode: function(_) {
      var t1 = this._selector1;
      return (t1.get$hashCode(t1) ^ J.get$hashCode$(this._selector2)) >>> 0;
    },
    $isBooleanSelector: 1
  };
  O.None.prototype = {
    evaluate$1: function(semantics) {
      return false;
    },
    intersection$1: function(other) {
      return this;
    },
    validate$1: function(isDefined) {
      type$.bool_Function_String._check(isDefined);
    },
    toString$0: function(_) {
      return "<none>";
    },
    $isBooleanSelector: 1
  };
  G.Parser.prototype = {
    parse$0: function() {
      var selector = this._conditional$0(),
        t1 = this._parser0$_scanner,
        t2 = t1.peek$0();
      if (t2.get$type(t2) !== C.TokenType_wwi)
        throw H.wrapException(G.SourceSpanFormatException$("Expected end of input.", t1.peek$0().get$span(), null));
      return selector;
    },
    _conditional$0: function() {
      var whenTrue, _this = this,
        condition = _this._or$0(),
        t1 = _this._parser0$_scanner;
      if (!t1.scan$1(C.TokenType_69P))
        return condition;
      whenTrue = _this._conditional$0();
      if (!t1.scan$1(C.TokenType_colon))
        throw H.wrapException(G.SourceSpanFormatException$('Expected ":".', t1.peek$0().get$span(), null));
      return new U.ConditionalNode(condition, whenTrue, _this._conditional$0());
    },
    _or$0: function() {
      var left = this._and$0();
      if (!this._parser0$_scanner.scan$1(C.TokenType_or))
        return left;
      return new U.OrNode(left, this._or$0());
    },
    _and$0: function() {
      var left = this._simpleExpression$0();
      if (!this._parser0$_scanner.scan$1(C.TokenType_and))
        return left;
      return new U.AndNode(left, this._and$0());
    },
    _simpleExpression$0: function() {
      var child,
        t1 = this._parser0$_scanner,
        token = t1.next$0();
      switch (token.get$type(token)) {
        case C.TokenType_not:
          child = this._simpleExpression$0();
          return new U.NotNode(token.get$span().expand$1(0, child.get$span()), child);
        case C.TokenType_e7P:
          child = this._conditional$0();
          if (!t1.scan$1(C.TokenType_31K))
            throw H.wrapException(G.SourceSpanFormatException$('Expected ")".', t1.peek$0().get$span(), null));
          return child;
        case C.TokenType_identifier:
          type$.IdentifierToken._as(token);
          return new U.VariableNode(token.span, token.name);
        default:
          throw H.wrapException(G.SourceSpanFormatException$("Expected expression.", token.get$span(), null));
      }
    }
  };
  O.Scanner.prototype = {
    peek$0: function() {
      var t1 = this._scanner$_next;
      return t1 == null ? this._scanner$_next = this._getNext$0() : t1;
    },
    next$0: function() {
      var _this = this,
        token = _this._scanner$_next;
      if (token == null)
        token = _this._getNext$0();
      _this._endOfFileEmitted = token.get$type(token) === C.TokenType_wwi;
      _this._scanner$_next = null;
      return token;
    },
    scan$1: function(type) {
      var t1 = this.peek$0();
      if (t1.get$type(t1) !== type)
        return false;
      this.next$0();
      return true;
    },
    _getNext$0: function() {
      var t1, t2, _this = this;
      if (_this._endOfFileEmitted)
        throw H.wrapException(P.StateError$("No more tokens."));
      _this._consumeWhitespace$0();
      t1 = _this._scanner;
      t2 = t1._string_scanner$_position;
      if (t2 === t1.string.length)
        return new L.Token(C.TokenType_wwi, t1.spanFrom$1(new S._SpanScannerState(t1, t2)));
      switch (t1.peekChar$0()) {
        case 40:
          return _this._scanOperator$1(C.TokenType_e7P);
        case 41:
          return _this._scanOperator$1(C.TokenType_31K);
        case 63:
          return _this._scanOperator$1(C.TokenType_69P);
        case 58:
          return _this._scanOperator$1(C.TokenType_colon);
        case 33:
          return _this._scanOperator$1(C.TokenType_not);
        case 124:
          t2 = t1._string_scanner$_position;
          t1.expect$1("||");
          return new L.Token(C.TokenType_or, t1.spanFrom$1(new S._SpanScannerState(t1, t2)));
        case 38:
          t2 = t1._string_scanner$_position;
          t1.expect$1("&&");
          return new L.Token(C.TokenType_and, t1.spanFrom$1(new S._SpanScannerState(t1, t2)));
        default:
          t1.expect$2$name($.$get$_hyphenatedIdentifier0(), "expression");
          t2 = t1.get$lastMatch().$index(0, 0);
          if (t1.get$lastMatch() == null)
            t1._lastSpan = null;
          return new L.IdentifierToken(t1._lastSpan, t2);
      }
    },
    _scanOperator$1: function(type) {
      var t1 = this._scanner,
        t2 = t1._string_scanner$_position,
        t3 = t1.string;
      if (t2 === t3.length)
        t1.error$3$length$position(0, "expected more input.", 0, t2);
      J.codeUnitAt$1$s(t3, t1._string_scanner$_position++);
      return new L.Token(type, t1.spanFrom$1(new S._SpanScannerState(t1, t2)));
    },
    _consumeWhitespace$0: function() {
      var success,
        t1 = this._scanner;
      while (true) {
        success = t1.matches$1(0, $.$get$_whitespaceAndSingleLineComments());
        if (success)
          t1._lastMatchPosition = t1._string_scanner$_position = t1._lastMatch.get$end();
        if (!(success || this._multiLineComment$0()))
          break;
      }
    },
    _multiLineComment$0: function() {
      var success,
        t1 = this._scanner;
      if (!t1.scan$1("/*"))
        return false;
      while (true) {
        success = t1.matches$1(0, $.$get$_multiLineCommentBody());
        if (success)
          t1._lastMatchPosition = t1._string_scanner$_position = t1._lastMatch.get$end();
        if (!(success || this._multiLineComment$0()))
          break;
      }
      t1.expect$1("*/");
      return true;
    }
  };
  L.Token.prototype = {
    get$type: function(receiver) {
      return this.type;
    },
    get$span: function() {
      return this.span;
    }
  };
  L.IdentifierToken.prototype = {
    toString$0: function(_) {
      return 'identifier "' + H.S(this.name) + '"';
    },
    $isToken: 1,
    get$type: function() {
      return C.TokenType_identifier;
    },
    get$span: function() {
      return this.span;
    }
  };
  L.TokenType.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  S.Validator.prototype = {
    visitVariable$1: function(node) {
      if (H.boolConversionCheck(this._isDefined.call$1(node.name)))
        return;
      throw H.wrapException(G.SourceSpanFormatException$("Undefined variable.", node.span, null));
    }
  };
  B.RecursiveVisitor.prototype = {
    visitNot$1: function(node) {
      node.child.accept$1(this);
    },
    visitOr$1: function(node) {
      node.left.accept$1(this);
      node.right.accept$1(this);
    },
    visitAnd$1: function(node) {
      node.left.accept$1(this);
      node.right.accept$1(this);
    },
    visitConditional$1: function(node) {
      node.condition.accept$1(this);
      node.whenTrue.accept$1(this);
      node.whenFalse.accept$1(this);
    },
    $isVisitor: 1
  };
  O.EmptyUnmodifiableSet.prototype = {
    get$iterator: function(_) {
      return C.C_EmptyIterator;
    },
    get$length: function(_) {
      return 0;
    },
    contains$1: function(_, element) {
      return false;
    },
    toSet$0: function(_) {
      return P.LinkedHashSet_LinkedHashSet(this.$ti._precomputed1);
    },
    $isEfficientLengthIterable: 1,
    $isSet: 1
  };
  Y.mapMap_closure.prototype = {
    call$2: function(mapKey, _) {
      this.K1._check(mapKey);
      this.V1._check(_);
      return this.K2._as(mapKey);
    },
    $signature: function() {
      return this.K2._eval$1("@<0>")._bind$1(this.K1)._bind$1(this.V1)._eval$1("1(2,3)");
    }
  };
  Y.mapMap_closure0.prototype = {
    call$2: function(mapKey, mapValue) {
      var t1, _this = this;
      _this.K1._check(mapKey);
      _this.V1._check(mapValue);
      t1 = _this._box_0;
      _this.result.$indexSet(0, t1.key.call$2(mapKey, mapValue), t1.value.call$2(mapKey, mapValue));
    },
    $signature: function() {
      return this.K1._eval$1("@<0>")._bind$1(this.V1)._eval$1("Null(1,2)");
    }
  };
  Y.mergeMaps_closure.prototype = {
    call$2: function(key, mapValue) {
      var t1, _this = this;
      _this.K._check(key);
      _this.V._check(mapValue);
      t1 = _this.result;
      t1.$indexSet(0, key, t1.containsKey$1(key) ? _this.value.call$2(t1.$index(0, key), mapValue) : mapValue);
    },
    $signature: function() {
      return this.K._eval$1("@<0>")._bind$1(this.V)._eval$1("Null(1,2)");
    }
  };
  Q.QueueList.prototype = {
    toString$0: function(_) {
      return P.IterableBase_iterableToFullString(this, "{", "}");
    },
    removeFirst$0: function() {
      var t2, result, _this = this,
        t1 = _this._queue_list$_head;
      if (t1 === _this._queue_list$_tail)
        throw H.wrapException(P.StateError$("No element"));
      t2 = _this._queue_list$_table;
      if (t1 >= t2.length)
        return H.ioore(t2, t1);
      result = t2[t1];
      C.JSArray_methods.$indexSet(t2, t1, null);
      _this._queue_list$_head = (_this._queue_list$_head + 1 & _this._queue_list$_table.length - 1) >>> 0;
      return result;
    },
    get$length: function(_) {
      return (this._queue_list$_tail - this._queue_list$_head & this._queue_list$_table.length - 1) >>> 0;
    },
    set$length: function(_, value) {
      var delta, t1, newTail, t2, _this = this;
      if (value < 0)
        throw H.wrapException(P.RangeError$("Length " + value + " may not be negative."));
      delta = value - _this.get$length(_this);
      if (delta >= 0) {
        if (_this._queue_list$_table.length <= value)
          _this._preGrow$1(value);
        _this._queue_list$_tail = (_this._queue_list$_tail + delta & _this._queue_list$_table.length - 1) >>> 0;
        return;
      }
      t1 = _this._queue_list$_tail;
      newTail = t1 + delta;
      t2 = _this._queue_list$_table;
      if (newTail >= 0)
        C.JSArray_methods.fillRange$3(t2, newTail, t1, null);
      else {
        newTail += t2.length;
        C.JSArray_methods.fillRange$3(t2, 0, t1, null);
        t1 = _this._queue_list$_table;
        C.JSArray_methods.fillRange$3(t1, newTail, t1.length, null);
      }
      _this._queue_list$_tail = newTail;
    },
    $index: function(_, index) {
      var t1, t2, t3, _this = this;
      H._checkIntNullable(index);
      if (index < 0 || index >= _this.get$length(_this))
        throw H.wrapException(P.RangeError$("Index " + index + " must be in the range [0.." + _this.get$length(_this) + ")."));
      t1 = _this._queue_list$_table;
      t2 = t1.length;
      t3 = (_this._queue_list$_head + index & t2 - 1) >>> 0;
      if (t3 < 0 || t3 >= t2)
        return H.ioore(t1, t3);
      return t1[t3];
    },
    $indexSet: function(_, index, value) {
      var t1, _this = this;
      H._checkIntNullable(index);
      _this.$ti._precomputed1._check(value);
      if (typeof index !== "number")
        return index.$lt();
      if (index < 0 || index >= _this.get$length(_this))
        throw H.wrapException(P.RangeError$("Index " + index + " must be in the range [0.." + _this.get$length(_this) + ")."));
      t1 = _this._queue_list$_table;
      C.JSArray_methods.$indexSet(t1, (_this._queue_list$_head + index & t1.length - 1) >>> 0, value);
    },
    _queue_list$_add$1: function(element) {
      var t2, t3, newTable, split, _this = this,
        t1 = _this.$ti;
      t1._precomputed1._check(element);
      C.JSArray_methods.$indexSet(_this._queue_list$_table, _this._queue_list$_tail, element);
      t2 = _this._queue_list$_tail;
      t3 = _this._queue_list$_table.length;
      t2 = (t2 + 1 & t3 - 1) >>> 0;
      _this._queue_list$_tail = t2;
      if (_this._queue_list$_head === t2) {
        t2 = new Array(t3 * 2);
        t2.fixed$length = Array;
        newTable = H.setRuntimeTypeInfo(t2, t1._eval$1("JSArray<1>"));
        t1 = _this._queue_list$_table;
        t2 = _this._queue_list$_head;
        split = t1.length - t2;
        C.JSArray_methods.setRange$4(newTable, 0, split, t1, t2);
        C.JSArray_methods.setRange$4(newTable, split, split + _this._queue_list$_head, _this._queue_list$_table, 0);
        _this._queue_list$_head = 0;
        _this._queue_list$_tail = _this._queue_list$_table.length;
        _this.set$_queue_list$_table(newTable);
      }
    },
    _writeToList$1: function(target) {
      var t1, t2, t3, $length, firstPartSize, _this = this;
      _this.$ti._eval$1("List<1>")._check(target);
      H.assertHelper(target.length >= _this.get$length(_this));
      t1 = _this._queue_list$_head;
      t2 = _this._queue_list$_tail;
      t3 = _this._queue_list$_table;
      if (t1 <= t2) {
        $length = t2 - t1;
        C.JSArray_methods.setRange$4(target, 0, $length, t3, t1);
        return $length;
      } else {
        firstPartSize = t3.length - t1;
        C.JSArray_methods.setRange$4(target, 0, firstPartSize, t3, t1);
        C.JSArray_methods.setRange$4(target, firstPartSize, firstPartSize + _this._queue_list$_tail, _this._queue_list$_table, 0);
        return _this._queue_list$_tail + firstPartSize;
      }
    },
    _preGrow$1: function(newElementCount) {
      var newCapacity, t1, newTable, _this = this;
      H.assertHelper(newElementCount >= _this.get$length(_this));
      newCapacity = Q.QueueList__nextPowerOf2(newElementCount + C.JSInt_methods._shrOtherPositive$1(newElementCount, 1));
      if (typeof newCapacity !== "number")
        return H.iae(newCapacity);
      t1 = new Array(newCapacity);
      t1.fixed$length = Array;
      newTable = H.setRuntimeTypeInfo(t1, _this.$ti._eval$1("JSArray<1>"));
      _this._queue_list$_tail = _this._writeToList$1(newTable);
      _this.set$_queue_list$_table(newTable);
      _this._queue_list$_head = 0;
    },
    set$_queue_list$_table: function(_table) {
      this._queue_list$_table = this.$ti._eval$1("List<1>")._check(_table);
    },
    $isEfficientLengthIterable: 1,
    $isQueue: 1,
    $isIterable: 1,
    $isList: 1
  };
  Q._QueueList_Object_ListMixin.prototype = {};
  M.UnionSet.prototype = {
    get$length: function(_) {
      var t1 = this._sets.fold$1$2(0, 0, new M.UnionSet_length_closure(this), type$.int);
      return t1;
    },
    get$iterator: function(_) {
      var t1 = this.get$_union_set$_iterable();
      return t1.get$iterator(t1);
    },
    get$_union_set$_iterable: function() {
      var t1 = this._sets,
        t2 = this.$ti._precomputed1,
        t3 = H._instanceType(t1),
        t4 = t3._bind$1(t2)._eval$1("Iterable<1>(2)")._check(new M.UnionSet__iterable_closure(this));
      return new H.ExpandIterable(t1, t4, t3._eval$1("@<1>")._bind$1(t2)._eval$1("ExpandIterable<1,2>"));
    },
    toSet$0: function(_) {
      var t1,
        result = P.LinkedHashSet_LinkedHashSet(this.$ti._precomputed1);
      for (t1 = this._sets, t1 = P._LinkedHashSetIterator$(t1, t1._collection$_modifications, H._instanceType(t1)._precomputed1); t1.moveNext$0();)
        result.addAll$1(0, t1._collection$_current);
      return result;
    }
  };
  M.UnionSet_length_closure.prototype = {
    call$2: function($length, set) {
      var t1;
      H._checkIntNullable($length);
      this.$this.$ti._eval$1("Set<1>")._check(set);
      t1 = set.get$length(set);
      if (typeof $length !== "number")
        return $length.$add();
      if (typeof t1 !== "number")
        return H.iae(t1);
      return $length + t1;
    },
    $signature: function() {
      return this.$this.$ti._eval$1("int(int,Set<1>)");
    }
  };
  M.UnionSet__iterable_closure.prototype = {
    call$1: function(set) {
      return this.$this.$ti._eval$1("Set<1>")._check(set);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("Set<1>(Set<1>)");
    }
  };
  M._UnionSet_SetBase_UnmodifiableSetMixin.prototype = {};
  Y.UnionSetController.prototype = {
    set$_union_set_controller$_set: function(_set) {
      this._union_set_controller$_set = this.$ti._eval$1("UnionSet<1>")._check(_set);
    }
  };
  L.UnmodifiableSetView.prototype = {};
  L.UnmodifiableSetMixin.prototype = {};
  L._UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin.prototype = {};
  M._DelegatingIterableBase.prototype = {
    contains$1: function(_, element) {
      return this._base.contains$1(0, element);
    },
    every$1: function(_, test) {
      return this._base.every$1(0, H._instanceType(this)._eval$1("bool(1)")._check(test));
    },
    get$first: function(_) {
      var t1 = this._base;
      return t1.get$first(t1);
    },
    get$isEmpty: function(_) {
      var t1 = this._base;
      return t1.get$isEmpty(t1);
    },
    get$iterator: function(_) {
      var t1 = this._base;
      return t1.get$iterator(t1);
    },
    get$last: function(_) {
      var t1 = this._base;
      return t1.get$last(t1);
    },
    get$length: function(_) {
      var t1 = this._base;
      return t1.get$length(t1);
    },
    map$1$1: function(_, f, $T) {
      return this._base.map$1$1(0, H._instanceType(this)._bind$1($T)._eval$1("1(2)")._check(f), $T);
    },
    toList$1$growable: function(_, growable) {
      return this._base.toList$1$growable(0, true);
    },
    toList$0: function($receiver) {
      return this.toList$1$growable($receiver, true);
    },
    toSet$0: function(_) {
      return this._base.toSet$0(0);
    },
    where$1: function(_, test) {
      return this._base.where$1(0, H._instanceType(this)._eval$1("bool(1)")._check(test));
    },
    toString$0: function(_) {
      return this._base.toString$0(0);
    },
    $isIterable: 1
  };
  M.DelegatingIterable.prototype = {};
  M.DelegatingSet.prototype = {
    union$1: function(other) {
      var t1 = H._instanceType(this)._eval$1("Set<1>");
      t1._check(other);
      return t1._check(this._base).union$1(other);
    },
    toSet$0: function(_) {
      var t1 = H._instanceType(this);
      return new M.DelegatingSet(t1._eval$1("Set<1>")._check(this._base).toSet$0(0), t1._eval$1("DelegatingSet<1>"));
    },
    $isEfficientLengthIterable: 1,
    $isSet: 1
  };
  Y._IsTrue.prototype = {
    matches$2: function(_, item, matchState) {
      return J.$eq$(item, true);
    },
    describe$1: function(description) {
      description._out._contents += "true";
      return description;
    }
  };
  Y._Predicate.prototype = {
    typedMatches$2: function(item, matchState) {
      return this._matcher.call$1(this.$ti._precomputed1._check(item));
    },
    describe$1: function(description) {
      description._out._contents += this._core_matchers$_description;
      return description;
    }
  };
  E.StringDescription.prototype = {
    get$length: function(_) {
      return this._out._contents.length;
    },
    toString$0: function(_) {
      var t1 = this._out._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    addDescriptionOf$1: function(value) {
      if (value instanceof G.Matcher)
        value.describe$1(this);
      else
        this._out._contents += Z.prettyPrint(value, 25, 80);
      return this;
    },
    $isDescription: 1
  };
  D._StringEqualsMatcher.prototype = {
    typedMatches$2: function(item, matchState) {
      return this._equals_matcher$_value === H._checkStringNullable(item);
    },
    describe$1: function(description) {
      return description.addDescriptionOf$1(this._equals_matcher$_value);
    },
    describeTypedMismatch$4: function(item, mismatchDescription, matchState, verbose) {
      var buff, escapedItem, escapedValue, minLength, minLength0, minLength1, start, t1, i;
      H._checkStringNullable(true);
      buff = new P.StringBuffer("");
      buff._contents = "is different.";
      escapedItem = M.escape(true);
      escapedValue = M.escape(this._equals_matcher$_value);
      minLength = escapedItem.length;
      minLength0 = escapedValue.length;
      minLength1 = minLength < minLength0 ? minLength : minLength0;
      for (start = 0; start < minLength1; ++start)
        if (C.JSString_methods._codeUnitAt$1(escapedValue, start) !== C.JSString_methods._codeUnitAt$1(escapedItem, start))
          break;
      if (start === minLength1) {
        t1 = buff._contents;
        if (minLength0 < minLength) {
          buff._contents = t1 + " Both strings start the same, but the actual value also has the following trailing characters: ";
          D._StringEqualsMatcher__writeTrailing(buff, escapedItem, minLength0);
        } else {
          buff._contents = t1 + " Both strings start the same, but the actual value is missing the following trailing characters: ";
          D._StringEqualsMatcher__writeTrailing(buff, escapedValue, minLength);
        }
      } else {
        buff._contents += "\nExpected: ";
        D._StringEqualsMatcher__writeLeading(buff, escapedValue, start);
        D._StringEqualsMatcher__writeTrailing(buff, escapedValue, start);
        buff._contents += "\n  Actual: ";
        D._StringEqualsMatcher__writeLeading(buff, escapedItem, start);
        D._StringEqualsMatcher__writeTrailing(buff, escapedItem, start);
        t1 = buff._contents += "\n          ";
        i = start > 10 ? 14 : start;
        for (; i > 0; --i) {
          t1 += " ";
          buff._contents = t1;
        }
        buff._contents += "^\n Differ at offset " + start;
      }
      t1 = buff._contents;
      mismatchDescription._out._contents += t1.charCodeAt(0) == 0 ? t1 : t1;
      return mismatchDescription;
    }
  };
  D._DeepMatcher.prototype = {
    _compareIterables$5: function(expected, actual, matcher, depth, $location) {
      var expectedIterator, actualIterator, index, expectedNext, actualNext, t1, newLocation, rp;
      type$.List_String_Function_dynamic_dynamic_String_int._check(matcher);
      if (type$.Iterable_dynamic._is(actual)) {
        expectedIterator = J.get$iterator$ax(expected);
        actualIterator = J.get$iterator$ax(actual);
        for (index = 0; true; ++index) {
          expectedNext = expectedIterator.moveNext$0();
          actualNext = actualIterator.moveNext$0();
          t1 = !expectedNext;
          if (t1 && !actualNext)
            return null;
          newLocation = $location + "[" + index + "]";
          if (t1)
            return H.setRuntimeTypeInfo(["longer than expected", newLocation], type$.JSArray_String);
          if (!actualNext)
            return H.setRuntimeTypeInfo(["shorter than expected", newLocation], type$.JSArray_String);
          rp = matcher.call$4(expectedIterator.get$current(), actualIterator.get$current(), newLocation, depth);
          if (rp != null)
            return rp;
        }
      } else
        return H.setRuntimeTypeInfo(["is not Iterable", $location], type$.JSArray_String);
    },
    _compareSets$5: function(expected, actual, matcher, depth, $location) {
      var other, t1, expectedElement, t2;
      type$.List_String_Function_dynamic_dynamic_String_int._check(matcher);
      if (type$.Iterable_dynamic._is(actual)) {
        other = J.toSet$0$ax(actual);
        for (t1 = expected.get$iterator(expected); t1.moveNext$0();) {
          expectedElement = t1.get$current();
          if (other.every$1(0, new D._DeepMatcher__compareSets_closure(matcher, expectedElement, $location, depth)))
            return H.setRuntimeTypeInfo(["does not contain " + H.S(expectedElement), $location], type$.JSArray_String);
        }
        t1 = other.get$length(other);
        t2 = expected.get$length(expected);
        if (typeof t2 !== "number")
          return H.iae(t2);
        if (t1 > t2)
          return H.setRuntimeTypeInfo(["larger than expected", $location], type$.JSArray_String);
        else {
          t1 = other.get$length(other);
          t2 = expected.get$length(expected);
          if (typeof t2 !== "number")
            return H.iae(t2);
          if (t1 < t2)
            return H.setRuntimeTypeInfo(["smaller than expected", $location], type$.JSArray_String);
          else
            return null;
        }
      } else
        return H.setRuntimeTypeInfo(["is not Iterable", $location], type$.JSArray_String);
    },
    _recursiveMatch$4: function(expected, actual, $location, depth) {
      var e, t1, description, exception, err, key, t2, rp, _this = this;
      if (expected instanceof G.Matcher) {
        t1 = type$.dynamic;
        if (expected.matches$2(0, actual, P.LinkedHashMap_LinkedHashMap$_empty(t1, t1)))
          return null;
        description = new E.StringDescription(new P.StringBuffer(""));
        expected.describe$1(description);
        return H.setRuntimeTypeInfo(["does not match " + description.toString$0(0), $location], type$.JSArray_String);
      } else
        try {
          if (J.$eq$(expected, actual))
            return null;
        } catch (exception) {
          e = H.unwrapException(exception);
          t1 = H.setRuntimeTypeInfo(['== threw "' + H.S(e) + '"', $location], type$.JSArray_String);
          return t1;
        }
      t1 = _this._limit;
      if (depth > t1)
        return H.setRuntimeTypeInfo(["recursion depth limit exceeded", $location], type$.JSArray_String);
      if (depth === 0 || t1 > 1)
        if (type$.Set_dynamic._is(expected))
          return _this._compareSets$5(expected, actual, _this.get$_recursiveMatch(), depth + 1, $location);
        else if (type$.Iterable_dynamic._is(expected))
          return _this._compareIterables$5(expected, actual, _this.get$_recursiveMatch(), depth + 1, $location);
        else {
          t1 = type$.Map_dynamic_dynamic;
          if (t1._is(expected)) {
            if (!t1._is(actual))
              return H.setRuntimeTypeInfo(["expected a map", $location], type$.JSArray_String);
            err = expected.get$length(expected) == actual.get$length(actual) ? "" : "has different length and ";
            for (t1 = expected.get$keys(), t1 = t1.get$iterator(t1); t1.moveNext$0();) {
              key = t1.get$current();
              if (!actual.containsKey$1(key))
                return H.setRuntimeTypeInfo([err + "is missing map key '" + H.S(key) + "'", $location], type$.JSArray_String);
            }
            for (t1 = actual.get$keys(), t1 = t1.get$iterator(t1); t1.moveNext$0();) {
              key = t1.get$current();
              if (!expected.containsKey$1(key))
                return H.setRuntimeTypeInfo([err + "has extra map key '" + H.S(key) + "'", $location], type$.JSArray_String);
            }
            for (t1 = expected.get$keys(), t1 = t1.get$iterator(t1), t2 = depth + 1; t1.moveNext$0();) {
              key = t1.get$current();
              rp = _this._recursiveMatch$4(expected.$index(0, key), actual.$index(0, key), $location + "['" + H.S(key) + "']", t2);
              if (rp != null)
                return rp;
            }
            return null;
          }
        }
      t1 = new P.StringBuffer("");
      if (depth > 0) {
        t1._contents = "was ";
        t2 = new E.StringDescription(t1).addDescriptionOf$1(actual);
        t2._out._contents += " instead of ";
        t2.addDescriptionOf$1(expected);
        t1 = t1._contents;
        return H.setRuntimeTypeInfo([t1.charCodeAt(0) == 0 ? t1 : t1, $location], type$.JSArray_String);
      }
      return H.setRuntimeTypeInfo(["", $location], type$.JSArray_String);
    },
    _equals_matcher$_match$3: function(expected, actual, matchState) {
      var t1, t2, reason, innerState,
        rp = this._recursiveMatch$4(expected, actual, "", 0);
      if (rp == null)
        return null;
      t1 = J.getInterceptor$asx(rp);
      t2 = t1.$index(rp, 0);
      t2.toString;
      if (J.get$length$asx(t2) !== 0) {
        t2 = t1.$index(rp, 1);
        t2.toString;
        reason = J.get$length$asx(t2) !== 0 ? H.S(t1.$index(rp, 0)) + " at location " + H.S(t1.$index(rp, 1)) : t1.$index(rp, 0);
      } else
        reason = "";
      t1 = type$.dynamic;
      t2 = P.LinkedHashMap_LinkedHashMap$_literal(["reason", reason], t1, t1);
      innerState = P.LinkedHashMap_LinkedHashMap$from(matchState, t1, t1);
      matchState.clear$0(0);
      matchState.$indexSet(0, "state", innerState);
      matchState.addAll$1(0, t2);
      return reason;
    },
    matches$2: function(_, item, matchState) {
      return this._equals_matcher$_match$3(this._expected, item, matchState) == null;
    },
    describe$1: function(description) {
      return description.addDescriptionOf$1(this._expected);
    },
    describeMismatch$4: function(item, mismatchDescription, matchState, verbose) {
      var t1, t2, t3,
        reason = H._asStringNullable(matchState.$index(0, "reason"));
      if (reason == null)
        reason = "";
      t1 = reason.length === 0 && mismatchDescription._out._contents.length > 0;
      t2 = mismatchDescription._out;
      t3 = t2._contents;
      if (t1) {
        t2._contents = t3 + "is ";
        mismatchDescription.addDescriptionOf$1(true);
      } else
        t2._contents = t3 + reason;
      return mismatchDescription;
    }
  };
  D._DeepMatcher__compareSets_closure.prototype = {
    call$1: function(actualElement) {
      var _this = this;
      return _this.matcher.call$4(_this.expectedElement, actualElement, _this.location, _this.depth) != null;
    },
    $signature: 9
  };
  E.FeatureMatcher.prototype = {
    matches$2: function(_, item, matchState) {
      return this.super$TypeMatcher$matches(0, item, matchState) && H.boolConversionCheck(this.typedMatches$2(H._instanceType(this)._eval$1("FeatureMatcher.T")._check(item), matchState));
    },
    describeMismatch$4: function(item, mismatchDescription, matchState, verbose) {
      if (H._instanceType(this)._eval$1("FeatureMatcher.T")._is(true))
        return this.describeTypedMismatch$4(true, mismatchDescription, matchState, false);
      mismatchDescription._out._contents += "not an ";
      return this.super$TypeMatcher$describe(mismatchDescription);
    },
    describeTypedMismatch$4: function(item, mismatchDescription, matchState, verbose) {
      H._instanceType(this)._eval$1("FeatureMatcher.T")._check(true);
      return mismatchDescription;
    }
  };
  G.Matcher.prototype = {
    describeMismatch$4: function(item, mismatchDescription, matchState, verbose) {
      return mismatchDescription;
    }
  };
  Z.prettyPrint__prettyPrint.prototype = {
    call$4: function(object, indent, seen, $top) {
      var description, type, t2, strings, t3, singleLine, value, defaultToString, _this = this, t1 = {};
      t1.seen = seen;
      if (object instanceof G.Matcher) {
        description = new E.StringDescription(new P.StringBuffer(""));
        object.describe$1(description);
        return "<" + description.toString$0(0) + ">";
      }
      if (seen.contains$1(0, object))
        return "(recursive)";
      t1.seen = seen.union$1(P.LinkedHashSet_LinkedHashSet$_literal([object], type$.dynamic));
      t1 = new Z.prettyPrint__prettyPrint_pp(t1, _this, indent);
      if (type$.Iterable_dynamic._is(object)) {
        type = type$.List_dynamic._is(object) ? "" : Z._typeName(object) + ":";
        t2 = type$.String;
        strings = J.map$1$1$ax(object, t1, t2).toList$0(0);
        t1 = strings.length;
        t3 = _this.maxItems;
        if (t1 > t3)
          C.JSArray_methods.replaceRange$3(strings, t3 - 1, t1, H.setRuntimeTypeInfo(["..."], type$.JSArray_String));
        singleLine = type + "[" + C.JSArray_methods.join$1(strings, ", ") + "]";
        if (singleLine.length + indent <= _this.maxLineLength && !C.JSString_methods.contains$1(singleLine, "\n"))
          return singleLine;
        t1 = H._arrayInstanceType(strings);
        return type + "[\n" + new H.MappedListIterable(strings, t1._eval$1("String(1)")._check(new Z.prettyPrint__prettyPrint_closure(indent)), t1._eval$1("MappedListIterable<1,String>")).join$1(0, ",\n") + "\n" + C.JSArray_methods.join$1(P.List_List$filled(indent, " ", t2), "") + "]";
      } else if (type$.Map_dynamic_dynamic._is(object)) {
        t2 = type$.String;
        strings = object.get$keys().map$1$1(0, new Z.prettyPrint__prettyPrint_closure0(t1, object), t2).toList$0(0);
        t1 = strings.length;
        t3 = _this.maxItems;
        if (t1 > t3)
          C.JSArray_methods.replaceRange$3(strings, t3 - 1, t1, H.setRuntimeTypeInfo(["..."], type$.JSArray_String));
        singleLine = "{" + C.JSArray_methods.join$1(strings, ", ") + "}";
        if (singleLine.length + indent <= _this.maxLineLength && !C.JSString_methods.contains$1(singleLine, "\n"))
          return singleLine;
        t1 = H._arrayInstanceType(strings);
        return "{\n" + new H.MappedListIterable(strings, t1._eval$1("String(1)")._check(new Z.prettyPrint__prettyPrint_closure1(indent)), t1._eval$1("MappedListIterable<1,String>")).join$1(0, ",\n") + "\n" + C.JSArray_methods.join$1(P.List_List$filled(indent, " ", t2), "") + "}";
      } else {
        t1 = type$.String;
        if (typeof object == "string")
          return "'" + new H.MappedListIterable(H.setRuntimeTypeInfo(object.split("\n"), type$.JSArray_String), type$.String_Function_String._check(Z.pretty_print___escapeString$closure()), type$.MappedListIterable_String_String).join$1(0, "\\n'\n" + C.JSArray_methods.join$1(P.List_List$filled(indent + 2, " ", t1), "") + "'") + "'";
        else {
          t2 = J.toString$0$(object);
          t1 = C.JSArray_methods.join$1(P.List_List$filled(indent, " ", t1), "") + "\n";
          t2.toString;
          value = H.stringReplaceAllUnchecked(t2, "\n", t1);
          defaultToString = C.JSString_methods.startsWith$1(value, "Instance of ");
          if ($top)
            value = "<" + value + ">";
          if (typeof object == "number" || H._isBool(object) || type$.Function._is(object) || type$.RegExp._is(object) || object instanceof P.MapEntry || object instanceof P.Expando || object == null || defaultToString)
            return value;
          else
            return Z._typeName(object) + ":" + value;
        }
      }
    },
    $signature: 55
  };
  Z.prettyPrint__prettyPrint_pp.prototype = {
    call$1: function(child) {
      return this._prettyPrint.call$4(child, this.indent + 2, this._box_0.seen, false);
    },
    $signature: 40
  };
  Z.prettyPrint__prettyPrint_closure.prototype = {
    call$1: function(string) {
      H._checkStringNullable(string);
      return C.JSString_methods.$add(C.JSArray_methods.join$1(P.List_List$filled(this.indent + 2, " ", type$.String), ""), string);
    },
    $signature: 7
  };
  Z.prettyPrint__prettyPrint_closure0.prototype = {
    call$1: function(key) {
      var t1 = this.pp;
      return H.S(t1.call$1(key)) + ": " + H.S(t1.call$1(this.object.$index(0, key)));
    },
    $signature: 40
  };
  Z.prettyPrint__prettyPrint_closure1.prototype = {
    call$1: function(string) {
      H._checkStringNullable(string);
      return C.JSString_methods.$add(C.JSArray_methods.join$1(P.List_List$filled(this.indent + 2, " ", type$.String), ""), string);
    },
    $signature: 7
  };
  M.TypeMatcher.prototype = {
    describe$1: function(description) {
      var $name,
        t1 = H._rtiToString(H.createRuntimeType(H._instanceType(this)._eval$1("TypeMatcher.T"))._rti, null),
        t2 = $.$get$_dart2DynamicArgs();
      t1.toString;
      $name = H.stringReplaceAllUnchecked(t1, t2, "");
      description._out._contents += "<Instance of '" + $name + "'>";
      return description;
    },
    matches$2: function(_, item, matchState) {
      return H._instanceType(this)._eval$1("TypeMatcher.T")._is(item);
    }
  };
  M.wrapMatcher_closure.prototype = {
    call$1: function(a) {
      return H._checkBoolNullable(this.x.call$1(a));
    },
    $signature: 9
  };
  M.escape_closure.prototype = {
    call$1: function(match) {
      var mapped = C.Map_F9GZw.$index(0, match.$index(0, 0));
      if (mapped != null)
        return mapped;
      return M._getHexLiteral(match.$index(0, 0));
    },
    $signature: 24
  };
  F.PackageConfigResolver.prototype = {$isSyncPackageResolver: 1,
    get$packageRoot: function() {
      return null;
    },
    get$packageConfigMap: function() {
      return this.packageConfigMap;
    }
  };
  F.PackageConfigResolver__normalizeMap_closure.prototype = {
    call$2: function(_, uri) {
      return B.ensureTrailingSlash(type$.Uri._check(uri));
    },
    $signature: 51
  };
  D.PackageRootResolver.prototype = {$isSyncPackageResolver: 1,
    get$packageConfigMap: function() {
      return null;
    },
    get$packageRoot: function() {
      return this.packageRoot;
    }
  };
  M.Context.prototype = {
    absolute$7: function(_, part1, part2, part3, part4, part5, part6, part7) {
      var t1;
      M._validateArgList("absolute", H.setRuntimeTypeInfo([part1, part2, part3, part4, part5, part6, part7], type$.JSArray_String));
      t1 = this.style;
      t1 = t1.rootLength$1(part1) > 0 && !t1.isRootRelative$1(part1);
      if (t1)
        return part1;
      t1 = this._context$_current;
      return this.join$8(0, t1 != null ? t1 : D.current(), part1, part2, part3, part4, part5, part6, part7);
    },
    absolute$1: function($receiver, part1) {
      return this.absolute$7($receiver, part1, null, null, null, null, null, null);
    },
    join$8: function(_, part1, part2, part3, part4, part5, part6, part7, part8) {
      var parts = H.setRuntimeTypeInfo([part1, part2, part3, part4, part5, part6, part7, part8], type$.JSArray_String);
      M._validateArgList("join", parts);
      return this.joinAll$1(new H.WhereIterable(parts, type$.bool_Function_String._check(new M.Context_join_closure()), type$.WhereIterable_String));
    },
    join$2: function($receiver, part1, part2) {
      return this.join$8($receiver, part1, part2, null, null, null, null, null, null);
    },
    joinAll$1: function(parts) {
      var t1, t2, t3, needsSeparator, isAbsoluteAndNotRootRelative, t4, t5, parsed, path, t6;
      type$.Iterable_String._check(parts);
      for (t1 = parts.$ti, t2 = t1._eval$1("bool(Iterable.E)")._check(new M.Context_joinAll_closure()), t3 = parts.get$iterator(parts), t1 = new H.WhereIterator(t3, t2, t1._eval$1("WhereIterator<Iterable.E>")), t2 = this.style, needsSeparator = false, isAbsoluteAndNotRootRelative = false, t4 = ""; t1.moveNext$0();) {
        t5 = t3.get$current();
        if (t2.isRootRelative$1(t5) && isAbsoluteAndNotRootRelative) {
          parsed = X.ParsedPath_ParsedPath$parse(t5, t2);
          path = t4.charCodeAt(0) == 0 ? t4 : t4;
          t4 = C.JSString_methods.substring$2(path, 0, t2.rootLength$2$withDrive(path, true));
          parsed.root = t4;
          if (t2.needsSeparator$1(t4))
            C.JSArray_methods.$indexSet(parsed.separators, 0, t2.get$separator());
          t4 = parsed.toString$0(0);
        } else if (t2.rootLength$1(t5) > 0) {
          isAbsoluteAndNotRootRelative = !t2.isRootRelative$1(t5);
          t4 = H.S(t5);
        } else {
          t6 = t5.length;
          if (t6 !== 0) {
            if (0 >= t6)
              return H.ioore(t5, 0);
            t6 = t2.containsSeparator$1(t5[0]);
          } else
            t6 = false;
          if (!t6)
            if (needsSeparator)
              t4 += t2.get$separator();
          t4 += t5;
        }
        needsSeparator = t2.needsSeparator$1(t5);
      }
      return t4.charCodeAt(0) == 0 ? t4 : t4;
    },
    split$1: function(_, path) {
      var parsed = X.ParsedPath_ParsedPath$parse(path, this.style),
        t1 = parsed.parts,
        t2 = H._arrayInstanceType(t1),
        t3 = t2._eval$1("WhereIterable<1>");
      parsed.set$parts(P.List_List$from(new H.WhereIterable(t1, t2._eval$1("bool(1)")._check(new M.Context_split_closure()), t3), true, t3._eval$1("Iterable.E")));
      t1 = parsed.root;
      if (t1 != null)
        C.JSArray_methods.insert$2(parsed.parts, 0, t1);
      return parsed.parts;
    },
    normalize$1: function(path) {
      var parsed;
      if (!this._needsNormalization$1(path))
        return path;
      parsed = X.ParsedPath_ParsedPath$parse(path, this.style);
      parsed.normalize$0();
      return parsed.toString$0(0);
    },
    _needsNormalization$1: function(path) {
      var t1, root, i, start, previous, t2, t3, previousPrevious, codeUnit, t4;
      path.toString;
      t1 = this.style;
      root = t1.rootLength$1(path);
      if (root !== 0) {
        if (t1 === $.$get$Style_windows())
          for (i = 0; i < root; ++i)
            if (C.JSString_methods._codeUnitAt$1(path, i) === 47)
              return true;
        start = root;
        previous = 47;
      } else {
        start = 0;
        previous = null;
      }
      for (t2 = new H.CodeUnits(path)._string, t3 = t2.length, i = start, previousPrevious = null; i < t3; ++i, previousPrevious = previous, previous = codeUnit) {
        codeUnit = C.JSString_methods.codeUnitAt$1(t2, i);
        if (t1.isSeparator$1(codeUnit)) {
          if (t1 === $.$get$Style_windows() && codeUnit === 47)
            return true;
          if (previous != null && t1.isSeparator$1(previous))
            return true;
          if (previous === 46)
            t4 = previousPrevious == null || previousPrevious === 46 || t1.isSeparator$1(previousPrevious);
          else
            t4 = false;
          if (t4)
            return true;
        }
      }
      if (previous == null)
        return true;
      if (t1.isSeparator$1(previous))
        return true;
      if (previous === 46)
        t1 = previousPrevious == null || t1.isSeparator$1(previousPrevious) || previousPrevious === 46;
      else
        t1 = false;
      if (t1)
        return true;
      return false;
    },
    relative$2$from: function(path, from) {
      var fromParsed, pathParsed, t2, t3, t4, t5, _this = this,
        _s26_ = 'Unable to find a path to "',
        t1 = from == null;
      if (t1 && _this.style.rootLength$1(path) <= 0)
        return _this.normalize$1(path);
      if (t1) {
        t1 = _this._context$_current;
        from = t1 != null ? t1 : D.current();
      } else
        from = _this.absolute$1(0, from);
      t1 = _this.style;
      if (t1.rootLength$1(from) <= 0 && t1.rootLength$1(path) > 0)
        return _this.normalize$1(path);
      if (t1.rootLength$1(path) <= 0 || t1.isRootRelative$1(path))
        path = _this.absolute$1(0, path);
      if (t1.rootLength$1(path) <= 0 && t1.rootLength$1(from) > 0)
        throw H.wrapException(X.PathException$(_s26_ + H.S(path) + '" from "' + H.S(from) + '".'));
      fromParsed = X.ParsedPath_ParsedPath$parse(from, t1);
      fromParsed.normalize$0();
      pathParsed = X.ParsedPath_ParsedPath$parse(path, t1);
      pathParsed.normalize$0();
      t2 = fromParsed.parts;
      t3 = t2.length;
      if (t3 !== 0) {
        if (0 >= t3)
          return H.ioore(t2, 0);
        t2 = J.$eq$(t2[0], ".");
      } else
        t2 = false;
      if (t2)
        return pathParsed.toString$0(0);
      t2 = fromParsed.root;
      t3 = pathParsed.root;
      if (t2 != t3)
        t2 = t2 == null || t3 == null || !t1.pathsEqual$2(t2, t3);
      else
        t2 = false;
      if (t2)
        return pathParsed.toString$0(0);
      while (true) {
        t2 = fromParsed.parts;
        t3 = t2.length;
        if (t3 !== 0) {
          t4 = pathParsed.parts;
          t5 = t4.length;
          if (t5 !== 0) {
            if (0 >= t3)
              return H.ioore(t2, 0);
            t2 = t2[0];
            if (0 >= t5)
              return H.ioore(t4, 0);
            t4 = t1.pathsEqual$2(t2, t4[0]);
            t2 = t4;
          } else
            t2 = false;
        } else
          t2 = false;
        if (!t2)
          break;
        C.JSArray_methods.removeAt$1(fromParsed.parts, 0);
        C.JSArray_methods.removeAt$1(fromParsed.separators, 1);
        C.JSArray_methods.removeAt$1(pathParsed.parts, 0);
        C.JSArray_methods.removeAt$1(pathParsed.separators, 1);
      }
      t2 = fromParsed.parts;
      t3 = t2.length;
      if (t3 !== 0) {
        if (0 >= t3)
          return H.ioore(t2, 0);
        t2 = J.$eq$(t2[0], "..");
      } else
        t2 = false;
      if (t2)
        throw H.wrapException(X.PathException$(_s26_ + H.S(path) + '" from "' + H.S(from) + '".'));
      t2 = type$.String;
      C.JSArray_methods.insertAll$2(pathParsed.parts, 0, P.List_List$filled(fromParsed.parts.length, "..", t2));
      C.JSArray_methods.$indexSet(pathParsed.separators, 0, "");
      C.JSArray_methods.insertAll$2(pathParsed.separators, 1, P.List_List$filled(fromParsed.parts.length, t1.get$separator(), t2));
      t1 = pathParsed.parts;
      t2 = t1.length;
      if (t2 === 0)
        return ".";
      if (t2 > 1 && J.$eq$(C.JSArray_methods.get$last(t1), ".")) {
        C.JSArray_methods.removeLast$0(pathParsed.parts);
        t1 = pathParsed.separators;
        C.JSArray_methods.removeLast$0(t1);
        C.JSArray_methods.removeLast$0(t1);
        C.JSArray_methods.add$1(t1, "");
      }
      pathParsed.root = "";
      pathParsed.removeTrailingSeparators$0();
      return pathParsed.toString$0(0);
    },
    relative$1: function(path) {
      return this.relative$2$from(path, null);
    },
    _isWithinOrEquals$2: function($parent, child) {
      var relative, childIsRootRelative, parentIsRootRelative, result, exception, _this = this,
        t1 = _this.style,
        parentIsAbsolute = t1.rootLength$1(H._checkStringNullable($parent)) > 0,
        childIsAbsolute = t1.rootLength$1(H._checkStringNullable(child)) > 0;
      if (parentIsAbsolute && !childIsAbsolute) {
        child = _this.absolute$1(0, child);
        if (t1.isRootRelative$1($parent))
          $parent = _this.absolute$1(0, $parent);
      } else if (childIsAbsolute && !parentIsAbsolute) {
        $parent = _this.absolute$1(0, $parent);
        if (t1.isRootRelative$1(child))
          child = _this.absolute$1(0, child);
      } else if (childIsAbsolute && parentIsAbsolute) {
        childIsRootRelative = t1.isRootRelative$1(child);
        parentIsRootRelative = t1.isRootRelative$1($parent);
        if (childIsRootRelative && !parentIsRootRelative)
          child = _this.absolute$1(0, child);
        else if (parentIsRootRelative && !childIsRootRelative)
          $parent = _this.absolute$1(0, $parent);
      }
      result = _this._isWithinOrEqualsFast$2($parent, child);
      if (result !== C._PathRelation_inconclusive)
        return result;
      relative = null;
      try {
        relative = _this.relative$2$from(child, $parent);
      } catch (exception) {
        if (H.unwrapException(exception) instanceof X.PathException)
          return C._PathRelation_different;
        else
          throw exception;
      }
      if (t1.rootLength$1(H._checkStringNullable(relative)) > 0)
        return C._PathRelation_different;
      if (J.$eq$(relative, "."))
        return C._PathRelation_equal;
      if (J.$eq$(relative, ".."))
        return C._PathRelation_different;
      return J.get$length$asx(relative) >= 3 && J.startsWith$1$s(relative, "..") && t1.isSeparator$1(J.codeUnitAt$1$s(relative, 2)) ? C._PathRelation_different : C._PathRelation_within;
    },
    _isWithinOrEqualsFast$2: function($parent, child) {
      var t1, parentRootLength, childRootLength, t2, t3, i, childIndex, parentIndex, lastCodeUnit, lastParentSeparator, parentCodeUnit, childCodeUnit, parentIndex0, t4, direction, _this = this;
      if ($parent === ".")
        $parent = "";
      t1 = _this.style;
      parentRootLength = t1.rootLength$1($parent);
      childRootLength = t1.rootLength$1(child);
      if (parentRootLength !== childRootLength)
        return C._PathRelation_different;
      for (t2 = J.getInterceptor$s($parent), t3 = J.getInterceptor$s(child), i = 0; i < parentRootLength; ++i)
        if (!t1.codeUnitsEqual$2(t2._codeUnitAt$1($parent, i), t3._codeUnitAt$1(child, i)))
          return C._PathRelation_different;
      t2 = $parent.length;
      childIndex = childRootLength;
      parentIndex = parentRootLength;
      lastCodeUnit = 47;
      lastParentSeparator = null;
      while (true) {
        if (!(parentIndex < t2 && childIndex < child.length))
          break;
        c$0: {
          parentCodeUnit = C.JSString_methods.codeUnitAt$1($parent, parentIndex);
          childCodeUnit = t3.codeUnitAt$1(child, childIndex);
          if (t1.codeUnitsEqual$2(parentCodeUnit, childCodeUnit)) {
            if (t1.isSeparator$1(parentCodeUnit))
              lastParentSeparator = parentIndex;
            ++parentIndex;
            ++childIndex;
            lastCodeUnit = parentCodeUnit;
            break c$0;
          }
          if (t1.isSeparator$1(parentCodeUnit) && t1.isSeparator$1(lastCodeUnit)) {
            parentIndex0 = parentIndex + 1;
            lastParentSeparator = parentIndex;
            parentIndex = parentIndex0;
            break c$0;
          } else if (t1.isSeparator$1(childCodeUnit) && t1.isSeparator$1(lastCodeUnit)) {
            ++childIndex;
            break c$0;
          }
          if (parentCodeUnit === 46 && t1.isSeparator$1(lastCodeUnit)) {
            ++parentIndex;
            if (parentIndex === t2)
              break;
            parentCodeUnit = C.JSString_methods.codeUnitAt$1($parent, parentIndex);
            if (t1.isSeparator$1(parentCodeUnit)) {
              parentIndex0 = parentIndex + 1;
              lastParentSeparator = parentIndex;
              parentIndex = parentIndex0;
              break c$0;
            }
            if (parentCodeUnit === 46) {
              ++parentIndex;
              if (parentIndex === t2 || t1.isSeparator$1(C.JSString_methods.codeUnitAt$1($parent, parentIndex)))
                return C._PathRelation_inconclusive;
            }
          }
          if (childCodeUnit === 46 && t1.isSeparator$1(lastCodeUnit)) {
            ++childIndex;
            t4 = child.length;
            if (childIndex === t4)
              break;
            childCodeUnit = C.JSString_methods.codeUnitAt$1(child, childIndex);
            if (t1.isSeparator$1(childCodeUnit)) {
              ++childIndex;
              break c$0;
            }
            if (childCodeUnit === 46) {
              ++childIndex;
              if (childIndex === t4 || t1.isSeparator$1(C.JSString_methods.codeUnitAt$1(child, childIndex)))
                return C._PathRelation_inconclusive;
            }
          }
          if (_this._pathDirection$2(child, childIndex) !== C._PathDirection_988)
            return C._PathRelation_inconclusive;
          if (_this._pathDirection$2($parent, parentIndex) !== C._PathDirection_988)
            return C._PathRelation_inconclusive;
          return C._PathRelation_different;
        }
      }
      if (childIndex === child.length) {
        if (parentIndex === t2 || t1.isSeparator$1(C.JSString_methods.codeUnitAt$1($parent, parentIndex)))
          lastParentSeparator = parentIndex;
        else if (lastParentSeparator == null)
          lastParentSeparator = Math.max(0, parentRootLength - 1);
        direction = _this._pathDirection$2($parent, lastParentSeparator);
        if (direction === C._PathDirection_8Gl)
          return C._PathRelation_equal;
        return direction === C._PathDirection_ZGD ? C._PathRelation_inconclusive : C._PathRelation_different;
      }
      direction = _this._pathDirection$2(child, childIndex);
      if (direction === C._PathDirection_8Gl)
        return C._PathRelation_equal;
      if (direction === C._PathDirection_ZGD)
        return C._PathRelation_inconclusive;
      return t1.isSeparator$1(C.JSString_methods.codeUnitAt$1(child, childIndex)) || t1.isSeparator$1(lastCodeUnit) ? C._PathRelation_within : C._PathRelation_different;
    },
    _pathDirection$2: function(path, index) {
      var t1, t2, i, depth, reachedRoot, i0, t3;
      for (t1 = path.length, t2 = this.style, i = index, depth = 0, reachedRoot = false; i < t1;) {
        while (true) {
          if (!(i < t1 && t2.isSeparator$1(C.JSString_methods.codeUnitAt$1(path, i))))
            break;
          ++i;
        }
        if (i === t1)
          break;
        i0 = i;
        while (true) {
          if (!(i0 < t1 && !t2.isSeparator$1(C.JSString_methods.codeUnitAt$1(path, i0))))
            break;
          ++i0;
        }
        t3 = i0 - i;
        if (!(t3 === 1 && C.JSString_methods.codeUnitAt$1(path, i) === 46))
          if (t3 === 2 && C.JSString_methods.codeUnitAt$1(path, i) === 46 && C.JSString_methods.codeUnitAt$1(path, i + 1) === 46) {
            --depth;
            if (depth < 0)
              break;
            if (depth === 0)
              reachedRoot = true;
          } else
            ++depth;
        if (i0 === t1)
          break;
        i = i0 + 1;
      }
      if (depth < 0)
        return C._PathDirection_ZGD;
      if (depth === 0)
        return C._PathDirection_8Gl;
      if (reachedRoot)
        return C._PathDirection_FIw;
      return C._PathDirection_988;
    },
    toUri$1: function(path) {
      var t2,
        t1 = this.style;
      if (t1.rootLength$1(path) <= 0)
        return t1.relativePathToUri$1(path);
      else {
        t2 = this._context$_current;
        return t1.absolutePathToUri$1(this.join$2(0, t2 != null ? t2 : D.current(), path));
      }
    },
    prettyUri$1: function(uri) {
      var path, rel, _this = this,
        typedUri = M._parseUri(uri);
      if (typedUri.get$scheme() === "file" && _this.style == $.$get$Style_url())
        return typedUri.toString$0(0);
      else if (typedUri.get$scheme() !== "file" && typedUri.get$scheme() !== "" && _this.style != $.$get$Style_url())
        return typedUri.toString$0(0);
      path = _this.normalize$1(_this.style.pathFromUri$1(M._parseUri(typedUri)));
      rel = _this.relative$1(path);
      return _this.split$1(0, rel).length > _this.split$1(0, path).length ? path : rel;
    }
  };
  M.Context_join_closure.prototype = {
    call$1: function(part) {
      return H._checkStringNullable(part) != null;
    },
    $signature: 4
  };
  M.Context_joinAll_closure.prototype = {
    call$1: function(part) {
      return H._checkStringNullable(part) !== "";
    },
    $signature: 4
  };
  M.Context_split_closure.prototype = {
    call$1: function(part) {
      return H._checkStringNullable(part).length !== 0;
    },
    $signature: 4
  };
  M._validateArgList_closure.prototype = {
    call$1: function(arg) {
      H._checkStringNullable(arg);
      return arg == null ? "null" : '"' + arg + '"';
    },
    $signature: 7
  };
  M._PathDirection.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  M._PathRelation.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  B.InternalStyle.prototype = {
    getRoot$1: function(path) {
      var t1,
        $length = this.rootLength$1(path);
      if ($length > 0)
        return J.substring$2$s(path, 0, $length);
      if (this.isRootRelative$1(path)) {
        if (0 >= path.length)
          return H.ioore(path, 0);
        t1 = path[0];
      } else
        t1 = null;
      return t1;
    },
    relativePathToUri$1: function(path) {
      var segments = M.Context_Context(this).split$1(0, path);
      if (this.isSeparator$1(J.codeUnitAt$1$s(path, path.length - 1)))
        C.JSArray_methods.add$1(segments, "");
      return P._Uri__Uri(null, null, segments, null);
    },
    codeUnitsEqual$2: function(codeUnit1, codeUnit2) {
      return codeUnit1 === codeUnit2;
    },
    pathsEqual$2: function(path1, path2) {
      return path1 == path2;
    }
  };
  X.ParsedPath.prototype = {
    get$hasTrailingSeparator: function() {
      var t1 = this.parts;
      if (t1.length !== 0)
        t1 = J.$eq$(C.JSArray_methods.get$last(t1), "") || !J.$eq$(C.JSArray_methods.get$last(this.separators), "");
      else
        t1 = false;
      return t1;
    },
    removeTrailingSeparators$0: function() {
      var t1, t2, _this = this;
      while (true) {
        t1 = _this.parts;
        if (!(t1.length !== 0 && J.$eq$(C.JSArray_methods.get$last(t1), "")))
          break;
        C.JSArray_methods.removeLast$0(_this.parts);
        C.JSArray_methods.removeLast$0(_this.separators);
      }
      t1 = _this.separators;
      t2 = t1.length;
      if (t2 !== 0)
        C.JSArray_methods.$indexSet(t1, t2 - 1, "");
    },
    normalize$0: function() {
      var t1, t2, leadingDoubles, _i, part, t3, newSeparators, _this = this,
        newParts = H.setRuntimeTypeInfo([], type$.JSArray_String);
      for (t1 = _this.parts, t2 = t1.length, leadingDoubles = 0, _i = 0; _i < t1.length; t1.length === t2 || (0, H.throwConcurrentModificationError)(t1), ++_i) {
        part = t1[_i];
        t3 = J.getInterceptor$(part);
        if (!(t3.$eq(part, ".") || t3.$eq(part, "")))
          if (t3.$eq(part, "..")) {
            t3 = newParts.length;
            if (t3 !== 0) {
              if (0 >= t3)
                return H.ioore(newParts, -1);
              newParts.pop();
            } else
              ++leadingDoubles;
          } else
            C.JSArray_methods.add$1(newParts, part);
      }
      if (_this.root == null)
        C.JSArray_methods.insertAll$2(newParts, 0, P.List_List$filled(leadingDoubles, "..", type$.String));
      if (newParts.length === 0 && _this.root == null)
        C.JSArray_methods.add$1(newParts, ".");
      newSeparators = P.List_List$generate(newParts.length, new X.ParsedPath_normalize_closure(_this), true, type$.String);
      t1 = _this.root;
      C.JSArray_methods.insert$2(newSeparators, 0, t1 != null && newParts.length !== 0 && _this.style.needsSeparator$1(t1) ? _this.style.get$separator() : "");
      _this.set$parts(newParts);
      _this.set$separators(newSeparators);
      t1 = _this.root;
      if (t1 != null && _this.style === $.$get$Style_windows()) {
        t1.toString;
        _this.root = H.stringReplaceAllUnchecked(t1, "/", "\\");
      }
      _this.removeTrailingSeparators$0();
    },
    toString$0: function(_) {
      var i, t2, _this = this,
        t1 = _this.root;
      t1 = t1 != null ? t1 : "";
      for (i = 0; i < _this.parts.length; ++i) {
        t2 = _this.separators;
        if (i >= t2.length)
          return H.ioore(t2, i);
        t2 = t1 + H.S(t2[i]);
        t1 = _this.parts;
        if (i >= t1.length)
          return H.ioore(t1, i);
        t1 = t2 + H.S(t1[i]);
      }
      t1 += H.S(C.JSArray_methods.get$last(_this.separators));
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    set$parts: function(parts) {
      this.parts = type$.List_String._check(parts);
    },
    set$separators: function(separators) {
      this.separators = type$.List_String._check(separators);
    }
  };
  X.ParsedPath_normalize_closure.prototype = {
    call$1: function(_) {
      return this.$this.style.get$separator();
    },
    $signature: 25
  };
  X.PathException.prototype = {
    toString$0: function(_) {
      return "PathException: " + this.message;
    },
    $isException: 1,
    get$message: function(receiver) {
      return this.message;
    }
  };
  O.Style.prototype = {
    toString$0: function(_) {
      return this.get$name(this);
    }
  };
  E.PosixStyle.prototype = {
    containsSeparator$1: function(path) {
      return C.JSString_methods.contains$1(path, "/");
    },
    isSeparator$1: function(codeUnit) {
      return codeUnit === 47;
    },
    needsSeparator$1: function(path) {
      var t1 = path.length;
      return t1 !== 0 && C.JSString_methods.codeUnitAt$1(path, t1 - 1) !== 47;
    },
    rootLength$2$withDrive: function(path, withDrive) {
      if (path.length !== 0 && C.JSString_methods._codeUnitAt$1(path, 0) === 47)
        return 1;
      return 0;
    },
    rootLength$1: function(path) {
      return this.rootLength$2$withDrive(path, false);
    },
    isRootRelative$1: function(path) {
      return false;
    },
    pathFromUri$1: function(uri) {
      var t1;
      if (uri.get$scheme() === "" || uri.get$scheme() === "file") {
        t1 = uri.get$path(uri);
        return P._Uri__uriDecode(t1, 0, t1.length, C.C_Utf8Codec, false);
      }
      throw H.wrapException(P.ArgumentError$("Uri " + uri.toString$0(0) + " must have scheme 'file:'."));
    },
    absolutePathToUri$1: function(path) {
      var parsed = X.ParsedPath_ParsedPath$parse(path, this),
        t1 = parsed.parts;
      if (t1.length === 0)
        C.JSArray_methods.addAll$1(t1, H.setRuntimeTypeInfo(["", ""], type$.JSArray_String));
      else if (parsed.get$hasTrailingSeparator())
        C.JSArray_methods.add$1(parsed.parts, "");
      return P._Uri__Uri(null, null, parsed.parts, "file");
    },
    get$name: function() {
      return "posix";
    },
    get$separator: function() {
      return "/";
    }
  };
  F.UrlStyle.prototype = {
    containsSeparator$1: function(path) {
      return C.JSString_methods.contains$1(path, "/");
    },
    isSeparator$1: function(codeUnit) {
      return codeUnit === 47;
    },
    needsSeparator$1: function(path) {
      var t1 = path.length;
      if (t1 === 0)
        return false;
      if (C.JSString_methods.codeUnitAt$1(path, t1 - 1) !== 47)
        return true;
      return C.JSString_methods.endsWith$1(path, "://") && this.rootLength$1(path) === t1;
    },
    rootLength$2$withDrive: function(path, withDrive) {
      var i, codeUnit, index, t2,
        t1 = path.length;
      if (t1 === 0)
        return 0;
      if (C.JSString_methods._codeUnitAt$1(path, 0) === 47)
        return 1;
      for (i = 0; i < t1; ++i) {
        codeUnit = C.JSString_methods._codeUnitAt$1(path, i);
        if (codeUnit === 47)
          return 0;
        if (codeUnit === 58) {
          if (i === 0)
            return 0;
          index = C.JSString_methods.indexOf$2(path, "/", C.JSString_methods.startsWith$2(path, "//", i + 1) ? i + 3 : i);
          if (index <= 0)
            return t1;
          if (!withDrive || t1 < index + 3)
            return index;
          if (!C.JSString_methods.startsWith$1(path, "file://"))
            return index;
          if (!B.isDriveLetter(path, index + 1))
            return index;
          t2 = index + 3;
          return t1 === t2 ? t2 : index + 4;
        }
      }
      return 0;
    },
    rootLength$1: function(path) {
      return this.rootLength$2$withDrive(path, false);
    },
    isRootRelative$1: function(path) {
      return path.length !== 0 && C.JSString_methods._codeUnitAt$1(path, 0) === 47;
    },
    pathFromUri$1: function(uri) {
      return J.toString$0$(uri);
    },
    relativePathToUri$1: function(path) {
      return P.Uri_parse(path);
    },
    absolutePathToUri$1: function(path) {
      return P.Uri_parse(path);
    },
    get$name: function() {
      return "url";
    },
    get$separator: function() {
      return "/";
    }
  };
  L.WindowsStyle.prototype = {
    containsSeparator$1: function(path) {
      return C.JSString_methods.contains$1(path, "/");
    },
    isSeparator$1: function(codeUnit) {
      return codeUnit === 47 || codeUnit === 92;
    },
    needsSeparator$1: function(path) {
      var t1 = path.length;
      if (t1 === 0)
        return false;
      t1 = C.JSString_methods.codeUnitAt$1(path, t1 - 1);
      return !(t1 === 47 || t1 === 92);
    },
    rootLength$2$withDrive: function(path, withDrive) {
      var t2, index,
        t1 = path.length;
      if (t1 === 0)
        return 0;
      t2 = C.JSString_methods._codeUnitAt$1(path, 0);
      if (t2 === 47)
        return 1;
      if (t2 === 92) {
        if (t1 < 2 || C.JSString_methods._codeUnitAt$1(path, 1) !== 92)
          return 1;
        index = C.JSString_methods.indexOf$2(path, "\\", 2);
        if (index > 0) {
          index = C.JSString_methods.indexOf$2(path, "\\", index + 1);
          if (index > 0)
            return index;
        }
        return t1;
      }
      if (t1 < 3)
        return 0;
      if (!B.isAlphabetic(t2))
        return 0;
      if (C.JSString_methods._codeUnitAt$1(path, 1) !== 58)
        return 0;
      t1 = C.JSString_methods._codeUnitAt$1(path, 2);
      if (!(t1 === 47 || t1 === 92))
        return 0;
      return 3;
    },
    rootLength$1: function(path) {
      return this.rootLength$2$withDrive(path, false);
    },
    isRootRelative$1: function(path) {
      return this.rootLength$1(path) === 1;
    },
    pathFromUri$1: function(uri) {
      var path, t1;
      if (uri.get$scheme() !== "" && uri.get$scheme() !== "file")
        throw H.wrapException(P.ArgumentError$("Uri " + uri.toString$0(0) + " must have scheme 'file:'."));
      path = uri.get$path(uri);
      if (uri.get$host(uri) === "") {
        if (path.length >= 3 && C.JSString_methods.startsWith$1(path, "/") && B.isDriveLetter(path, 1))
          path = C.JSString_methods.replaceFirst$2(path, "/", "");
      } else
        path = "\\\\" + H.S(uri.get$host(uri)) + path;
      t1 = H.stringReplaceAllUnchecked(path, "/", "\\");
      return P._Uri__uriDecode(t1, 0, t1.length, C.C_Utf8Codec, false);
    },
    absolutePathToUri$1: function(path) {
      var rootParts, t2,
        parsed = X.ParsedPath_ParsedPath$parse(path, this),
        t1 = parsed.root;
      if (J.startsWith$1$s(t1, "\\\\")) {
        rootParts = new H.WhereIterable(H.setRuntimeTypeInfo(t1.split("\\"), type$.JSArray_String), type$.bool_Function_String._check(new L.WindowsStyle_absolutePathToUri_closure()), type$.WhereIterable_String);
        C.JSArray_methods.insert$2(parsed.parts, 0, rootParts.get$last(rootParts));
        if (parsed.get$hasTrailingSeparator())
          C.JSArray_methods.add$1(parsed.parts, "");
        return P._Uri__Uri(rootParts.get$first(rootParts), null, parsed.parts, "file");
      } else {
        if (parsed.parts.length === 0 || parsed.get$hasTrailingSeparator())
          C.JSArray_methods.add$1(parsed.parts, "");
        t1 = parsed.parts;
        t2 = parsed.root;
        t2.toString;
        t2 = H.stringReplaceAllUnchecked(t2, "/", "");
        C.JSArray_methods.insert$2(t1, 0, H.stringReplaceAllUnchecked(t2, "\\", ""));
        return P._Uri__Uri(null, null, parsed.parts, "file");
      }
    },
    codeUnitsEqual$2: function(codeUnit1, codeUnit2) {
      var upperCase1;
      if (codeUnit1 === codeUnit2)
        return true;
      if (codeUnit1 === 47)
        return codeUnit2 === 92;
      if (codeUnit1 === 92)
        return codeUnit2 === 47;
      if ((codeUnit1 ^ codeUnit2) !== 32)
        return false;
      upperCase1 = codeUnit1 | 32;
      return upperCase1 >= 97 && upperCase1 <= 122;
    },
    pathsEqual$2: function(path1, path2) {
      var t1, t2, i;
      if (path1 == path2)
        return true;
      t1 = path1.length;
      if (t1 !== path2.length)
        return false;
      for (t2 = J.getInterceptor$s(path2), i = 0; i < t1; ++i)
        if (!this.codeUnitsEqual$2(C.JSString_methods._codeUnitAt$1(path1, i), t2._codeUnitAt$1(path2, i)))
          return false;
      return true;
    },
    get$name: function() {
      return "windows";
    },
    get$separator: function() {
      return "\\";
    }
  };
  L.WindowsStyle_absolutePathToUri_closure.prototype = {
    call$1: function(part) {
      return H._checkStringNullable(part) !== "";
    },
    $signature: 4
  };
  O.Pool.prototype = {
    request$0: function(_) {
      var t1, t2, _this = this;
      if (_this._pool$_closeMemo._async_memoizer$_completer.future._state !== 0)
        throw H.wrapException(P.StateError$("request() may not be called on a closed Pool."));
      t1 = _this._allocatedResources;
      if (t1 < _this._maxAllocatedResources) {
        _this._allocatedResources = t1 + 1;
        t1 = new P._Future($.Zone__current, type$._Future_PoolResource);
        t1._asyncComplete$1(new O.PoolResource(_this));
        return t1;
      } else {
        t1 = _this._onReleaseCallbacks;
        if (!t1.get$isEmpty(t1))
          return _this._runOnRelease$1(t1.removeFirst$0());
        else {
          t1 = new P._Future($.Zone__current, type$._Future_PoolResource);
          t2 = _this._requestedResources;
          t2._collection$_add$1(t2.$ti._precomputed1._check(new P._AsyncCompleter(t1, type$._AsyncCompleter_PoolResource)));
          _this._resetTimer$0();
          return t1;
        }
      }
    },
    withResource$1$1: function(callback, $T) {
      $T._eval$1("0/()")._check(callback);
      return this.withResource$body$Pool(callback, $T, $T);
    },
    withResource$body$Pool: function(callback, $T, $async$type) {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter($async$type),
        $async$returnValue, $async$handler = 2, $async$currentError, $async$next = [], $async$self = this, resource, t1;
      var $async$withResource$1$1 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1) {
          $async$currentError = $async$result;
          $async$goto = $async$handler;
        }
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              if ($async$self._pool$_closeMemo._async_memoizer$_completer.future._state !== 0)
                throw H.wrapException(P.StateError$("withResource() may not be called on a closed Pool."));
              $async$goto = 3;
              return P._asyncAwait($async$self.request$0(0), $async$withResource$1$1);
            case 3:
              // returning from await.
              resource = $async$result;
              $async$handler = 4;
              $async$goto = 7;
              return P._asyncAwait(callback.call$0(), $async$withResource$1$1);
            case 7:
              // returning from await.
              t1 = $async$result;
              $async$returnValue = t1;
              $async$next = [1];
              // goto finally
              $async$goto = 5;
              break;
              $async$next.push(6);
              // goto finally
              $async$goto = 5;
              break;
            case 4:
              // uncaught
              $async$next = [2];
            case 5:
              // finally
              $async$handler = 2;
              resource.release$0();
              // goto the next finally handler
              $async$goto = $async$next.pop();
              break;
            case 6:
              // after finally
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
            case 2:
              // rethrow
              return P._asyncRethrow($async$currentError, $async$completer);
          }
      });
      return P._asyncStartSync($async$withResource$1$1, $async$completer);
    },
    close$0: function(_) {
      return this._pool$_closeMemo.runOnce$1(new O.Pool_close_closure(this));
    },
    _onResourceReleaseAllowed$1: function(onRelease) {
      var t1, zone, t2, _this = this;
      type$.dynamic_Function._check(onRelease);
      _this._resetTimer$0();
      t1 = _this._requestedResources;
      if (!t1.get$isEmpty(t1))
        t1.removeFirst$0().complete$1(_this._runOnRelease$1(onRelease));
      else {
        t1 = type$.dynamic;
        if (_this._pool$_closeMemo._async_memoizer$_completer.future._state !== 0) {
          _this._closeGroup.add$1(0, P.Future_Future$sync(onRelease, t1));
          if (--_this._allocatedResources === 0)
            _this._closeGroup.close$0(0);
        } else {
          zone = $.Zone__current;
          t2 = _this._onReleaseCallbacks;
          t2._collection$_add$1(t2.$ti._precomputed1._check(new O.Pool__onResourceReleaseAllowed_closure(zone, zone.registerCallback$1$1(onRelease, t1))));
        }
      }
    },
    _runOnRelease$1: function(onRelease) {
      var t1, t2;
      P.Future_Future$sync(type$.dynamic_Function._check(onRelease), type$.dynamic).then$1$1(new O.Pool__runOnRelease_closure(this), type$.Null).catchError$1(new O.Pool__runOnRelease_closure0(this));
      t1 = new P._Future($.Zone__current, type$._Future_PoolResource);
      t2 = this._onReleaseCompleters;
      t2._collection$_add$1(t2.$ti._precomputed1._check(new P._SyncCompleter(t1, type$._SyncCompleter_PoolResource)));
      return t1;
    },
    _resetTimer$0: function() {
      var t2,
        t1 = this._timer;
      if (t1 == null)
        return;
      t2 = this._requestedResources;
      if (t2._head === t2._tail)
        t1._restartable_timer$_timer.cancel$0();
      else {
        t1._restartable_timer$_timer.cancel$0();
        t1._restartable_timer$_timer = P.Timer_Timer(t1._restartable_timer$_duration, t1._callback);
      }
    }
  };
  O.Pool_close_closure.prototype = {
    call$0: function() {
      var t3, t4, callback,
        t1 = this.$this,
        t2 = t1._closeGroup;
      if (t2 != null)
        return t2._future_group$_completer.future;
      t1._resetTimer$0();
      t1._closeGroup = new F.FutureGroup(new P._AsyncCompleter(new P._Future($.Zone__current, type$._Future_List_dynamic), type$._AsyncCompleter_List_dynamic), H.setRuntimeTypeInfo([], type$.JSArray_dynamic), type$.FutureGroup_dynamic);
      for (t2 = t1._onReleaseCallbacks, t3 = P._ListQueueIterator$(t2, t2.$ti._precomputed1), t4 = type$.dynamic; t3.moveNext$0();) {
        callback = t3._collection$_current;
        t1._closeGroup.add$1(0, P.Future_Future$sync(callback, t4));
      }
      t1._allocatedResources = t1._allocatedResources - t2.get$length(t2);
      t2.clear$0(0);
      if (t1._allocatedResources === 0)
        t1._closeGroup.close$0(0);
      return t1._closeGroup._future_group$_completer.future;
    },
    $signature: 50
  };
  O.Pool__onResourceReleaseAllowed_closure.prototype = {
    call$0: function() {
      return this.zone.run$1$1(this.registered, type$.void);
    },
    $signature: 1
  };
  O.Pool__runOnRelease_closure.prototype = {
    call$1: function(value) {
      var t1 = this.$this;
      t1._onReleaseCompleters.removeFirst$0().complete$1(new O.PoolResource(t1));
    },
    $signature: 3
  };
  O.Pool__runOnRelease_closure0.prototype = {
    call$2: function(error, stackTrace) {
      type$.StackTrace._check(stackTrace);
      this.$this._onReleaseCompleters.removeFirst$0().completeError$2(error, stackTrace);
    },
    $signature: 5
  };
  O.PoolResource.prototype = {
    release$0: function() {
      var t1, t2;
      if (this._released)
        throw H.wrapException(P.StateError$("A PoolResource may only be released once."));
      this._released = true;
      t1 = this._pool;
      t1._resetTimer$0();
      t2 = t1._requestedResources;
      if (!t2.get$isEmpty(t2))
        t2.removeFirst$0().complete$1(new O.PoolResource(t1));
      else {
        t2 = --t1._allocatedResources;
        if (t1._pool$_closeMemo._async_memoizer$_completer.future._state !== 0 && t2 === 0)
          t1._closeGroup.close$0(0);
      }
    }
  };
  O.mapStackTrace_closure.prototype = {
    call$1: function(trace) {
      var _this = this;
      return Y.Trace_Trace$from(O.mapStackTrace(_this.sourceMap, type$.Trace._check(trace), _this.minified, _this._box_0.packageResolver, _this.sdkRoot));
    },
    $signature: 45
  };
  O.mapStackTrace_closure0.prototype = {
    call$1: function(frame) {
      var column, t1, t2, span, sourceUrl, t3, packageUrl, t4, _this = this;
      type$.Frame._check(frame);
      if (frame.get$line() == null)
        return null;
      column = frame.get$column() == null ? 0 : frame.get$column();
      t1 = frame.get$line();
      if (typeof t1 !== "number")
        return t1.$sub();
      if (typeof column !== "number")
        return column.$sub();
      t2 = frame.get$uri();
      t2 = t2 == null ? null : t2.toString$0(0);
      span = _this.sourceMap.spanFor$3$uri(t1 - 1, column - 1, t2);
      if (span == null)
        return null;
      sourceUrl = J.toString$0$(span.get$sourceUrl());
      if (_this.sdkRoot != null && $.$get$url()._isWithinOrEquals$2(_this.sdkLib, sourceUrl) === C._PathRelation_within)
        sourceUrl = C.JSString_methods.$add("dart:", $.$get$url().relative$2$from(sourceUrl, _this.sdkLib));
      else {
        t1 = _this._box_0;
        t2 = t1.packageResolver;
        if (t2 != null)
          if (t2.get$packageRoot() != null && $.$get$url()._isWithinOrEquals$2(J.toString$0$(t1.packageResolver.get$packageRoot()), sourceUrl) === C._PathRelation_within)
            sourceUrl = C.JSString_methods.$add("package:", $.$get$url().relative$2$from(sourceUrl, J.toString$0$(t1.packageResolver.get$packageRoot())));
          else if (t1.packageResolver.get$packageConfigMap() != null)
            for (t2 = t1.packageResolver.get$packageConfigMap()._map.get$keys(), t2 = t2.get$iterator(t2); t2.moveNext$0();) {
              t3 = t2.get$current();
              packageUrl = J.toString$0$(t1.packageResolver.get$packageConfigMap()._map.$index(0, t3));
              t4 = $.$get$url();
              if (t4._isWithinOrEquals$2(packageUrl, sourceUrl) !== C._PathRelation_within)
                continue;
              sourceUrl = C.JSString_methods.$add("package:" + H.S(t3) + "/", t4.relative$2$from(sourceUrl, packageUrl));
              break;
            }
      }
      t1 = P.Uri_parse(sourceUrl);
      t2 = span.get$start().get$line();
      if (typeof t2 !== "number")
        return t2.$add();
      t3 = span.get$start().get$column();
      if (_this.minified)
        t4 = span.get$isIdentifier() ? span.get$text() : frame.get$member();
      else
        t4 = O._prettifyMember(frame.get$member());
      return new A.Frame(t1, t2 + 1, t3 + 1, t4);
    },
    $signature: 46
  };
  O.mapStackTrace_closure1.prototype = {
    call$1: function(frame) {
      return type$.Frame._check(frame) != null;
    },
    $signature: 21
  };
  O._prettifyMember_closure.prototype = {
    call$1: function(match) {
      return C.JSString_methods.$mul(".<fn>", match.$index(0, 1).length);
    },
    $signature: 24
  };
  O._prettifyMember_closure0.prototype = {
    call$1: function(match) {
      return J.$add$ansx(match.$index(0, 1), ".");
    },
    $signature: 24
  };
  T.Mapping.prototype = {};
  T.MultiSectionMapping.prototype = {
    MultiSectionMapping$fromJson$3$mapUrl: function(sections, otherMaps, mapUrl) {
      var t1, t2, t3, t4, t5, section, t6, line, column, url, map, _s6_ = "offset", _null = null;
      for (t1 = J.get$iterator$ax(sections), t2 = this._maps, t3 = type$.Map_dynamic_dynamic, t4 = this._lineStart, t5 = this._columnStart; t1.moveNext$0();) {
        section = t1.get$current();
        t6 = J.getInterceptor$asx(section);
        if (t6.$index(section, _s6_) == null)
          throw H.wrapException(P.FormatException$("section missing offset", _null, _null));
        line = J.$index$asx(t6.$index(section, _s6_), "line");
        if (line == null)
          throw H.wrapException(P.FormatException$("offset missing line", _null, _null));
        column = J.$index$asx(t6.$index(section, _s6_), "column");
        if (column == null)
          throw H.wrapException(P.FormatException$("offset missing column", _null, _null));
        C.JSArray_methods.add$1(t4, H._checkIntNullable(line));
        C.JSArray_methods.add$1(t5, H._checkIntNullable(column));
        url = t6.$index(section, "url");
        map = t6.$index(section, "map");
        t6 = url != null;
        if (t6 && map != null)
          throw H.wrapException(P.FormatException$("section can't use both url and map entries", _null, _null));
        else if (t6) {
          t6 = P.FormatException$("section contains refers to " + H.S(url) + ', but no map was given for it. Make sure a map is passed in "otherMaps"', _null, _null);
          throw H.wrapException(t6);
        } else if (map != null)
          C.JSArray_methods.add$1(t2, T.parseJson(t3._check(map), mapUrl, otherMaps));
        else
          throw H.wrapException(P.FormatException$("section missing url or map", _null, _null));
      }
      if (t4.length === 0)
        throw H.wrapException(P.FormatException$("expected at least one section", _null, _null));
    },
    _indexFor$2: function(line, column) {
      var t1, t2, t3, t4, i, t5;
      for (t1 = this._lineStart, t2 = t1.length, t3 = this._columnStart, t4 = t3.length, i = 0; i < t2; ++i) {
        t5 = t1[i];
        if (line < t5)
          return i - 1;
        if (line === t5) {
          if (i >= t4)
            return H.ioore(t3, i);
          t5 = column < t3[i];
        } else
          t5 = false;
        if (t5)
          return i - 1;
      }
      return t2 - 1;
    },
    spanFor$4$files$uri: function(line, column, files, uri) {
      var index, t1, t2, t3, _this = this;
      type$.Map_String_SourceFile._check(files);
      index = _this._indexFor$2(line, column);
      t1 = _this._maps;
      if (index < 0 || index >= t1.length)
        return H.ioore(t1, index);
      t1 = t1[index];
      t2 = _this._lineStart;
      if (index >= t2.length)
        return H.ioore(t2, index);
      t2 = t2[index];
      t3 = _this._columnStart;
      if (index >= t3.length)
        return H.ioore(t3, index);
      return t1.spanFor$3$files(line - t2, column - t3[index], files);
    },
    spanFor$3$uri: function(line, column, uri) {
      return this.spanFor$4$files$uri(line, column, null, uri);
    },
    spanFor$3$files: function(line, column, files) {
      return this.spanFor$4$files$uri(line, column, files, null);
    },
    toString$0: function(_) {
      var t2, t3, t4, i, _this = this,
        t1 = H.getRuntimeType(_this).toString$0(0) + " : [";
      for (t2 = _this._lineStart, t3 = _this._columnStart, t4 = _this._maps, i = 0; i < t2.length; ++i) {
        t1 = t1 + "(" + t2[i] + ",";
        if (i >= t3.length)
          return H.ioore(t3, i);
        t1 = t1 + t3[i] + ":";
        if (i >= t4.length)
          return H.ioore(t4, i);
        t1 = t1 + t4[i].toString$0(0) + ")";
      }
      t1 += "]";
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    }
  };
  T.MappingBundle.prototype = {
    MappingBundle$fromJson$2$mapUrl: function(json, mapUrl) {
      var t1, t2, t3, t4, t5;
      for (t1 = J.get$iterator$ax(json), t2 = type$.Map_dynamic_dynamic, t3 = type$.SingleMapping, t4 = this._mappings; t1.moveNext$0();) {
        t5 = t3._as(T.parseJson(t2._check(t1.get$current()), mapUrl, null));
        t4.$indexSet(0, t5.targetUrl, t5);
      }
    },
    toString$0: function(_) {
      var t1, t2;
      for (t1 = this._mappings.get$values(), t1 = t1.get$iterator(t1), t2 = ""; t1.moveNext$0();)
        t2 += J.toString$0$(t1.get$current());
      return t2.charCodeAt(0) == 0 ? t2 : t2;
    },
    spanFor$4$files$uri: function(line, column, files, uri) {
      var separatorCodeUnits, t1, t2, onBoundary, i, candidate, $location;
      type$.Map_String_SourceFile._check(files);
      if (uri == null)
        throw H.wrapException(P.ArgumentError$notNull("uri"));
      separatorCodeUnits = H.setRuntimeTypeInfo([47, 58], type$.JSArray_int);
      for (t1 = uri.length, t2 = this._mappings, onBoundary = true, i = 0; i < t1; ++i) {
        if (onBoundary) {
          candidate = C.JSString_methods.substring$1(uri, i);
          if (t2.containsKey$1(candidate))
            return t2.$index(0, candidate).spanFor$4$files$uri(line, column, files, candidate);
        }
        onBoundary = C.JSArray_methods.contains$1(separatorCodeUnits, C.JSString_methods._codeUnitAt$1(uri, i));
      }
      $location = V.SourceLocation$(line * 1000000 + column, column, line, P.Uri_parse(uri));
      t1 = new G.SourceMapSpan(false, $location, $location, "");
      t1.SourceSpanBase$3($location, $location, "");
      return t1;
    },
    spanFor$3$uri: function(line, column, uri) {
      return this.spanFor$4$files$uri(line, column, null, uri);
    }
  };
  T.SingleMapping.prototype = {
    SingleMapping$fromJson$2$mapUrl: function(map, mapUrl) {
      var t5, source, t6, t7, tokenizer, entries, line, column, srcUrlId, srcLine, srcColumn, srcNameId, _this = this,
        _s14_ = "sourcesContent",
        _null = null,
        sourcesContent = map.$index(0, _s14_) == null ? C.List_empty0 : P.List_List$from(type$.Iterable_dynamic._check(map.$index(0, _s14_)), true, type$.String),
        t1 = type$.Uri,
        t2 = _this.files,
        t3 = _this.urls,
        t4 = type$.JSArray_int,
        i = 0;
      while (true) {
        t5 = t3.length;
        if (!(i < t5 && i < sourcesContent.length))
          break;
        c$0: {
          if (i >= sourcesContent.length)
            return H.ioore(sourcesContent, i);
          source = sourcesContent[i];
          if (source == null)
            break c$0;
          H._checkStringNullable(source);
          if (i >= t5)
            return H.ioore(t3, i);
          t5 = t3[i];
          t6 = new H.CodeUnits(source);
          t7 = H.setRuntimeTypeInfo([0], t4);
          t7 = new Y.SourceFile(t1._check(typeof t5 == "string" ? P.Uri_parse(t5) : t5), t7, new Uint32Array(H._ensureNativeList(t6.toList$0(t6))));
          t7.SourceFile$decoded$2$url(t6, t5);
          C.JSArray_methods.$indexSet(t2, i, t7);
        }
        ++i;
      }
      t1 = H._checkStringNullable(map.$index(0, "mappings"));
      t2 = t1.length;
      tokenizer = new T._MappingTokenizer(t1, t2);
      t1 = type$.JSArray_TargetEntry;
      entries = H.setRuntimeTypeInfo([], t1);
      t4 = _this.names;
      t5 = t2 - 1;
      t2 = t2 > 0;
      t6 = _this.lines;
      line = 0;
      column = 0;
      srcUrlId = 0;
      srcLine = 0;
      srcColumn = 0;
      srcNameId = 0;
      while (true) {
        if (!(tokenizer.index < t5 && t2))
          break;
        c$1: {
          if (tokenizer.get$nextKind().isNewLine) {
            if (entries.length !== 0) {
              C.JSArray_methods.add$1(t6, new T.TargetLineEntry(line, entries));
              entries = H.setRuntimeTypeInfo([], t1);
            }
            ++line;
            ++tokenizer.index;
            column = 0;
            break c$1;
          }
          if (tokenizer.get$nextKind().isNewSegment)
            throw H.wrapException(_this._segmentError$2(0, line));
          column += L.decodeVlq(tokenizer);
          t7 = tokenizer.get$nextKind();
          if (!(!t7.isNewLine && !t7.isNewSegment && !t7.isEof))
            C.JSArray_methods.add$1(entries, new T.TargetEntry(column, _null, _null, _null, _null));
          else {
            srcUrlId += L.decodeVlq(tokenizer);
            if (srcUrlId >= t3.length)
              throw H.wrapException(P.StateError$("Invalid source url id. " + H.S(_this.targetUrl) + ", " + line + ", " + srcUrlId));
            t7 = tokenizer.get$nextKind();
            if (!(!t7.isNewLine && !t7.isNewSegment && !t7.isEof))
              throw H.wrapException(_this._segmentError$2(2, line));
            srcLine += L.decodeVlq(tokenizer);
            t7 = tokenizer.get$nextKind();
            if (!(!t7.isNewLine && !t7.isNewSegment && !t7.isEof))
              throw H.wrapException(_this._segmentError$2(3, line));
            srcColumn += L.decodeVlq(tokenizer);
            t7 = tokenizer.get$nextKind();
            if (!(!t7.isNewLine && !t7.isNewSegment && !t7.isEof))
              C.JSArray_methods.add$1(entries, new T.TargetEntry(column, srcUrlId, srcLine, srcColumn, _null));
            else {
              srcNameId += L.decodeVlq(tokenizer);
              if (srcNameId >= t4.length)
                throw H.wrapException(P.StateError$("Invalid name id: " + H.S(_this.targetUrl) + ", " + line + ", " + srcNameId));
              C.JSArray_methods.add$1(entries, new T.TargetEntry(column, srcUrlId, srcLine, srcColumn, srcNameId));
            }
          }
          if (tokenizer.get$nextKind().isNewSegment)
            ++tokenizer.index;
        }
      }
      if (entries.length !== 0)
        C.JSArray_methods.add$1(t6, new T.TargetLineEntry(line, entries));
      map.forEach$1(0, new T.SingleMapping$fromJson_closure(_this));
    },
    _segmentError$2: function(seen, line) {
      return new P.StateError("Invalid entry in sourcemap, expected 1, 4, or 5 values, but got " + seen + ".\ntargeturl: " + H.S(this.targetUrl) + ", line: " + line);
    },
    _findLine$1: function(line) {
      var t2,
        t1 = this.lines,
        index = O.binarySearch(t1, new T.SingleMapping__findLine_closure(line));
      if (index <= 0)
        t1 = null;
      else {
        t2 = index - 1;
        if (t2 >= t1.length)
          return H.ioore(t1, t2);
        t2 = t1[t2];
        t1 = t2;
      }
      return t1;
    },
    _findColumn$3: function(line, column, lineEntry) {
      var entries, index, t1;
      if (lineEntry == null || lineEntry.entries.length === 0)
        return null;
      if (lineEntry.line !== line)
        return C.JSArray_methods.get$last(lineEntry.entries);
      entries = lineEntry.entries;
      index = O.binarySearch(entries, new T.SingleMapping__findColumn_closure(column));
      if (index <= 0)
        t1 = null;
      else {
        t1 = index - 1;
        if (t1 >= entries.length)
          return H.ioore(entries, t1);
        t1 = entries[t1];
      }
      return t1;
    },
    spanFor$4$files$uri: function(line, column, files, uri) {
      var entry, url, t1, t2, start, t3, _this = this;
      type$.Map_String_SourceFile._check(files);
      entry = _this._findColumn$3(line, column, _this._findLine$1(line));
      if (entry == null || entry.sourceUrlId == null)
        return null;
      url = C.JSArray_methods.$index(_this.urls, entry.sourceUrlId);
      t1 = _this.sourceRoot;
      if (t1 != null)
        url = t1 + H.S(url);
      t1 = _this._parser$_mapUrl;
      t1 = t1 == null ? url : t1.resolve$1(url);
      t2 = entry.sourceLine;
      start = V.SourceLocation$(0, entry.sourceColumn, t2, t1);
      t1 = entry.sourceNameId;
      if (t1 != null) {
        t2 = _this.names;
        if (t1 >>> 0 !== t1 || t1 >= t2.length)
          return H.ioore(t2, t1);
        t1 = t2[t1];
        t2 = t1.length;
        t2 = V.SourceLocation$(start.offset + t2, start.column + t2, start.line, start.sourceUrl);
        t3 = new G.SourceMapSpan(true, start, t2, t1);
        t3.SourceSpanBase$3(start, t2, t1);
        return t3;
      } else {
        t1 = new G.SourceMapSpan(false, start, start, "");
        t1.SourceSpanBase$3(start, start, "");
        return t1;
      }
    },
    spanFor$3$uri: function(line, column, uri) {
      return this.spanFor$4$files$uri(line, column, null, uri);
    },
    spanFor$3$files: function(line, column, files) {
      return this.spanFor$4$files$uri(line, column, files, null);
    },
    toString$0: function(_) {
      var _this = this,
        t1 = H.getRuntimeType(_this).toString$0(0);
      t1 + " : [";
      t1 = t1 + " : [targetUrl: " + H.S(_this.targetUrl) + ", sourceRoot: " + H.S(_this.sourceRoot) + ", urls: " + H.S(_this.urls) + ", names: " + H.S(_this.names) + ", lines: " + H.S(_this.lines) + "]";
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    }
  };
  T.SingleMapping$fromJson_closure.prototype = {
    call$2: function($name, value) {
      if (J.startsWith$1$s($name, "x_"))
        this.$this.extensions.$indexSet(0, H._checkStringNullable($name), value);
    },
    $signature: 6
  };
  T.SingleMapping__findLine_closure.prototype = {
    call$1: function(e) {
      return e.get$line() > this.line;
    },
    $signature: 9
  };
  T.SingleMapping__findColumn_closure.prototype = {
    call$1: function(e) {
      return e.get$column() > this.column;
    },
    $signature: 9
  };
  T.TargetLineEntry.prototype = {
    toString$0: function(_) {
      return H.getRuntimeType(this).toString$0(0) + ": " + this.line + " " + H.S(this.entries);
    },
    get$line: function() {
      return this.line;
    }
  };
  T.TargetEntry.prototype = {
    toString$0: function(_) {
      var _this = this;
      return H.getRuntimeType(_this).toString$0(0) + ": (" + _this.column + ", " + H.S(_this.sourceUrlId) + ", " + H.S(_this.sourceLine) + ", " + H.S(_this.sourceColumn) + ", " + H.S(_this.sourceNameId) + ")";
    },
    get$column: function() {
      return this.column;
    }
  };
  T._MappingTokenizer.prototype = {
    moveNext$0: function() {
      return ++this.index < this._parser$_length;
    },
    get$current: function() {
      var t2,
        t1 = this.index;
      if (t1 >= 0 && t1 < this._parser$_length) {
        t2 = this._internal;
        if (t1 < 0 || t1 >= t2.length)
          return H.ioore(t2, t1);
        t1 = t2[t1];
      } else
        t1 = null;
      return t1;
    },
    get$hasTokens: function() {
      var t1 = this._parser$_length;
      return this.index < t1 - 1 && t1 > 0;
    },
    get$nextKind: function() {
      var t1, t2, next;
      if (!this.get$hasTokens())
        return C._TokenKind_false_false_true;
      t1 = this._internal;
      t2 = this.index + 1;
      if (t2 < 0 || t2 >= t1.length)
        return H.ioore(t1, t2);
      next = t1[t2];
      if (next === ";")
        return C._TokenKind_true_false_false;
      if (next === ",")
        return C._TokenKind_false_true_false;
      return C._TokenKind_false_false_false;
    },
    toString$0: function(_) {
      var t1, i, t2, t3, _this = this;
      for (t1 = _this._internal, i = 0, t2 = ""; i < _this.index; ++i) {
        if (i >= t1.length)
          return H.ioore(t1, i);
        t2 += t1[i];
      }
      t2 += "\x1b[31m";
      t2 = t2 + H.S(_this.get$current() == null ? "" : _this.get$current()) + "\x1b[0m";
      for (i = _this.index + 1, t3 = t1.length; i < t3; ++i) {
        if (i < 0)
          return H.ioore(t1, i);
        t2 += t1[i];
      }
      t1 = t2 + (" (" + _this.index + ")");
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    $isIterator: 1
  };
  T._TokenKind.prototype = {};
  G.SourceMapSpan.prototype = {
    get$isIdentifier: function() {
      return this.isIdentifier;
    }
  };
  L.closure.prototype = {
    call$0: function() {
      var i,
        map = P.LinkedHashMap_LinkedHashMap$_empty(type$.String, type$.int);
      for (i = 0; i < 64; ++i)
        map.$indexSet(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i], i);
      return map;
    },
    $signature: 93
  };
  Y.SourceFile.prototype = {
    get$length: function(_) {
      return this._decodedChars.length;
    },
    get$lines: function() {
      return this._lineStarts.length;
    },
    SourceFile$decoded$2$url: function(decodedChars, url) {
      var t1, t2, t3, i, c, j, t4;
      for (t1 = this._decodedChars, t2 = t1.length, t3 = this._lineStarts, i = 0; i < t2; ++i) {
        c = t1[i];
        if (c === 13) {
          j = i + 1;
          if (j < t2) {
            if (j >= t2)
              return H.ioore(t1, j);
            t4 = t1[j] !== 10;
          } else
            t4 = true;
          if (t4)
            c = 10;
        }
        if (c === 10)
          C.JSArray_methods.add$1(t3, i + 1);
      }
    },
    span$2: function(start, end) {
      return Y._FileSpan$(this, start, end);
    },
    getLine$1: function(offset) {
      var t1, _this = this;
      if (offset < 0)
        throw H.wrapException(P.RangeError$("Offset may not be negative, was " + offset + "."));
      else if (offset > _this._decodedChars.length)
        throw H.wrapException(P.RangeError$("Offset " + offset + " must not be greater than the number of characters in the file, " + _this.get$length(_this) + "."));
      t1 = _this._lineStarts;
      if (offset < C.JSArray_methods.get$first(t1))
        return -1;
      if (offset >= C.JSArray_methods.get$last(t1))
        return t1.length - 1;
      if (_this._isNearCachedLine$1(offset))
        return _this._cachedLine;
      return _this._cachedLine = _this._binarySearch$1(offset) - 1;
    },
    _isNearCachedLine$1: function(offset) {
      var t2, t3, t4, _this = this,
        t1 = _this._cachedLine;
      if (t1 == null)
        return false;
      t2 = _this._lineStarts;
      if (t1 >>> 0 !== t1 || t1 >= t2.length)
        return H.ioore(t2, t1);
      if (offset < t2[t1])
        return false;
      t1 = _this._cachedLine;
      t3 = t2.length;
      if (typeof t1 !== "number")
        return t1.$ge();
      if (t1 < t3 - 1) {
        t4 = t1 + 1;
        if (t4 < 0 || t4 >= t3)
          return H.ioore(t2, t4);
        t4 = offset < t2[t4];
      } else
        t4 = true;
      if (t4)
        return true;
      if (t1 < t3 - 2) {
        t4 = t1 + 2;
        if (t4 < 0 || t4 >= t3)
          return H.ioore(t2, t4);
        t4 = offset < t2[t4];
        t2 = t4;
      } else
        t2 = true;
      if (t2) {
        _this._cachedLine = t1 + 1;
        return true;
      }
      return false;
    },
    _binarySearch$1: function(offset) {
      var min, half,
        t1 = this._lineStarts,
        t2 = t1.length,
        max = t2 - 1;
      for (min = 0; min < max;) {
        half = min + C.JSInt_methods._tdivFast$1(max - min, 2);
        if (half < 0 || half >= t2)
          return H.ioore(t1, half);
        if (t1[half] > offset)
          max = half;
        else
          min = half + 1;
      }
      return max;
    },
    getColumn$1: function(offset) {
      var line, lineStart, _this = this;
      if (offset < 0)
        throw H.wrapException(P.RangeError$("Offset may not be negative, was " + offset + "."));
      else if (offset > _this._decodedChars.length)
        throw H.wrapException(P.RangeError$("Offset " + offset + " must be not be greater than the number of characters in the file, " + _this.get$length(_this) + "."));
      line = _this.getLine$1(offset);
      lineStart = C.JSArray_methods.$index(_this._lineStarts, line);
      if (lineStart > offset)
        throw H.wrapException(P.RangeError$("Line " + H.S(line) + " comes after offset " + offset + "."));
      return offset - lineStart;
    },
    getOffset$2: function(line, column) {
      var t1, t2, result, t3;
      if (typeof line !== "number")
        return line.$lt();
      if (line < 0)
        throw H.wrapException(P.RangeError$("Line may not be negative, was " + line + "."));
      else {
        t1 = this._lineStarts;
        t2 = t1.length;
        if (line >= t2)
          throw H.wrapException(P.RangeError$("Line " + line + " must be less than the number of lines in the file, " + this.get$lines() + "."));
      }
      result = t1[line];
      if (result <= this._decodedChars.length) {
        t3 = line + 1;
        t1 = t3 < t2 && result >= t1[t3];
      } else
        t1 = true;
      if (t1)
        throw H.wrapException(P.RangeError$("Line " + line + " doesn't have 0 columns."));
      return result;
    },
    getOffset$1: function(line) {
      return this.getOffset$2(line, null);
    }
  };
  Y.FileLocation.prototype = {
    get$sourceUrl: function() {
      return this.file.url;
    },
    get$line: function() {
      return this.file.getLine$1(this.offset);
    },
    get$column: function() {
      return this.file.getColumn$1(this.offset);
    },
    get$offset: function(receiver) {
      return this.offset;
    }
  };
  Y._FileSpan.prototype = {
    get$sourceUrl: function() {
      return this.file.url;
    },
    get$length: function(_) {
      return this._file$_end - this._file$_start;
    },
    get$start: function() {
      return Y.FileLocation$_(this.file, this._file$_start);
    },
    get$end: function() {
      return Y.FileLocation$_(this.file, this._file$_end);
    },
    get$text: function() {
      return P.String_String$fromCharCodes(C.NativeUint32List_methods.sublist$2(this.file._decodedChars, this._file$_start, this._file$_end), 0, null);
    },
    get$context: function() {
      var t2, _this = this,
        t1 = _this.file,
        endOffset = _this._file$_end,
        endLine = t1.getLine$1(endOffset);
      if (t1.getColumn$1(endOffset) === 0 && endLine !== 0) {
        if (endOffset - _this._file$_start === 0) {
          if (endLine === t1._lineStarts.length - 1)
            t1 = "";
          else {
            t2 = t1.getOffset$1(endLine);
            if (typeof endLine !== "number")
              return endLine.$add();
            t1 = P.String_String$fromCharCodes(C.NativeUint32List_methods.sublist$2(t1._decodedChars, t2, t1.getOffset$1(endLine + 1)), 0, null);
          }
          return t1;
        }
      } else if (endLine === t1._lineStarts.length - 1)
        endOffset = t1._decodedChars.length;
      else {
        if (typeof endLine !== "number")
          return endLine.$add();
        endOffset = t1.getOffset$1(endLine + 1);
      }
      return P.String_String$fromCharCodes(C.NativeUint32List_methods.sublist$2(t1._decodedChars, t1.getOffset$1(t1.getLine$1(_this._file$_start)), endOffset), 0, null);
    },
    $eq: function(_, other) {
      var _this = this;
      if (other == null)
        return false;
      if (!type$.FileSpan._is(other))
        return _this.super$SourceSpanMixin$$eq(0, other);
      if (!(other instanceof Y._FileSpan))
        return _this.super$SourceSpanMixin$$eq(0, other) && J.$eq$(_this.file.url, other.get$sourceUrl());
      return _this._file$_start === other._file$_start && _this._file$_end === other._file$_end && J.$eq$(_this.file.url, other.file.url);
    },
    get$hashCode: function(_) {
      return Y.SourceSpanMixin.prototype.get$hashCode.call(this, this);
    },
    expand$1: function(_, other) {
      var start, _this = this,
        t1 = _this.file;
      if (!J.$eq$(t1.url, other.file.url))
        throw H.wrapException(P.ArgumentError$('Source URLs "' + H.S(_this.get$sourceUrl()) + '" and  "' + H.S(other.get$sourceUrl()) + "\" don't match."));
      start = Math.min(_this._file$_start, other._file$_start);
      return Y._FileSpan$(t1, start, Math.max(_this._file$_end, other._file$_end));
    },
    $isFileSpan: 1,
    $isSourceSpanWithContext: 1
  };
  U.Highlighter.prototype = {
    highlight$0: function() {
      var t1, t2, lineStart, context, lines, t3, t4, lineNumber, _i, line, lastLineIndex, _this = this;
      _this._writeSidebar$1$end($._glyphs.get$downEnd());
      t1 = _this._highlighter$_buffer;
      t1._contents += "\n";
      t2 = _this._span;
      lineStart = B.findLineStart(t2.get$context(), t2.get$text(), t2.get$start().get$column());
      H.assertHelper(lineStart != null);
      context = t2.get$context();
      if (typeof lineStart !== "number")
        return lineStart.$gt();
      if (lineStart > 0) {
        lines = C.JSString_methods.substring$2(context, 0, lineStart - 1).split("\n");
        t3 = t2.get$start().get$line();
        t4 = lines.length;
        if (typeof t3 !== "number")
          return t3.$sub();
        lineNumber = t3 - t4;
        for (t3 = _this._multiline, _i = 0; _i < t4; ++_i) {
          line = lines[_i];
          _this._writeSidebar$1$line(lineNumber);
          t1._contents += C.JSString_methods.$mul(" ", t3 ? 3 : 1);
          _this._writeText$1(line);
          t1._contents += "\n";
          ++lineNumber;
        }
        context = C.JSString_methods.substring$1(context, lineStart);
      }
      lines = H.setRuntimeTypeInfo(context.split("\n"), type$.JSArray_String);
      t3 = t2.get$end().get$line();
      t2 = t2.get$start().get$line();
      if (typeof t3 !== "number")
        return t3.$sub();
      if (typeof t2 !== "number")
        return H.iae(t2);
      lastLineIndex = t3 - t2;
      t2 = C.JSArray_methods.get$last(lines);
      t2.toString;
      if (J.get$length$asx(t2) === 0 && lines.length > lastLineIndex + 1) {
        if (0 >= lines.length)
          return H.ioore(lines, -1);
        lines.pop();
      }
      _this._writeFirstLine$1(C.JSArray_methods.get$first(lines));
      if (_this._multiline) {
        _this._writeIntermediateLines$1(H.SubListIterable$(lines, 1, null, type$.String).take$1(0, lastLineIndex - 1));
        if (lastLineIndex < 0 || lastLineIndex >= lines.length)
          return H.ioore(lines, lastLineIndex);
        _this._writeLastLine$1(lines[lastLineIndex]);
      }
      _this._writeTrailingLines$1(H.SubListIterable$(lines, lastLineIndex + 1, null, type$.String));
      _this._writeSidebar$1$end($._glyphs.get$upEnd());
      t1 = t1._contents;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    _writeFirstLine$1: function(line) {
      var t3, t4, startColumn, endColumn, textBefore, textInside, tabsBefore, tabsInside, _this = this, t1 = {},
        t2 = _this._span;
      _this._writeSidebar$1$line(t2.get$start().get$line());
      t3 = t2.get$start().get$column();
      t4 = line.length;
      startColumn = t1.startColumn = Math.min(t3, t4);
      t3 = t2.get$end();
      t3 = t3.get$offset(t3);
      t2 = t2.get$start();
      endColumn = t1.endColumn = Math.min(startColumn + t3 - t2.get$offset(t2), t4);
      textBefore = J.substring$2$s(line, 0, startColumn);
      t2 = _this._multiline;
      if (t2 && _this._isOnlyWhitespace$1(textBefore)) {
        t1 = _this._highlighter$_buffer;
        t1._contents += " ";
        _this._colorize$1(new U.Highlighter__writeFirstLine_closure(_this, line));
        t1._contents += "\n";
        return;
      }
      t3 = _this._highlighter$_buffer;
      t3._contents += C.JSString_methods.$mul(" ", t2 ? 3 : 1);
      _this._writeText$1(textBefore);
      textInside = C.JSString_methods.substring$2(line, startColumn, endColumn);
      _this._colorize$1(new U.Highlighter__writeFirstLine_closure0(_this, textInside));
      _this._writeText$1(C.JSString_methods.substring$1(line, endColumn));
      t3._contents += "\n";
      tabsBefore = _this._countTabs$1(textBefore);
      tabsInside = _this._countTabs$1(textInside);
      startColumn += tabsBefore * 3;
      t1.startColumn = startColumn;
      t1.endColumn = endColumn + (tabsBefore + tabsInside) * 3;
      _this._writeSidebar$0();
      if (t2) {
        t3._contents += " ";
        _this._colorize$1(new U.Highlighter__writeFirstLine_closure1(t1, _this));
      } else {
        t3._contents += C.JSString_methods.$mul(" ", startColumn + 1);
        _this._colorize$1(new U.Highlighter__writeFirstLine_closure2(t1, _this));
      }
      t3._contents += "\n";
    },
    _writeIntermediateLines$1: function(lines) {
      var t1, lineNumber, t2, t3, _this = this;
      type$.Iterable_String._check(lines);
      H.assertHelper(_this._multiline);
      t1 = _this._span.get$start().get$line();
      if (typeof t1 !== "number")
        return t1.$add();
      lineNumber = t1 + 1;
      for (t1 = new H.ListIterator(lines, lines.get$length(lines), lines.$ti._eval$1("ListIterator<ListIterable.E>")), t2 = _this._highlighter$_buffer; t1.moveNext$0();) {
        t3 = t1.__internal$_current;
        _this._writeSidebar$1$line(lineNumber);
        t2._contents += " ";
        _this._colorize$1(new U.Highlighter__writeIntermediateLines_closure(_this, t3));
        t2._contents += "\n";
        ++lineNumber;
      }
    },
    _writeLastLine$1: function(line) {
      var t3, t4, endColumn, textInside, _this = this, t1 = {},
        t2 = _this._multiline;
      H.assertHelper(t2);
      t3 = _this._span;
      _this._writeSidebar$1$line(t3.get$end().get$line());
      t3 = t3.get$end().get$column();
      t4 = line.length;
      endColumn = t1.endColumn = Math.min(t3, t4);
      if (t2 && endColumn === t4) {
        t1 = _this._highlighter$_buffer;
        t1._contents += " ";
        _this._colorize$1(new U.Highlighter__writeLastLine_closure(_this, line));
        t1._contents += "\n";
        return;
      }
      t2 = _this._highlighter$_buffer;
      t2._contents += " ";
      textInside = J.substring$2$s(line, 0, endColumn);
      _this._colorize$1(new U.Highlighter__writeLastLine_closure0(_this, textInside));
      _this._writeText$1(C.JSString_methods.substring$1(line, endColumn));
      t2._contents += "\n";
      t1.endColumn = endColumn + _this._countTabs$1(textInside) * 3;
      _this._writeSidebar$0();
      t2._contents += " ";
      _this._colorize$1(new U.Highlighter__writeLastLine_closure1(t1, _this));
      t2._contents += "\n";
    },
    _writeTrailingLines$1: function(lines) {
      var t1, lineNumber, t2, t3, t4, _this = this;
      type$.Iterable_String._check(lines);
      t1 = _this._span.get$end().get$line();
      if (typeof t1 !== "number")
        return t1.$add();
      lineNumber = t1 + 1;
      for (t1 = new H.ListIterator(lines, lines.get$length(lines), lines.$ti._eval$1("ListIterator<ListIterable.E>")), t2 = _this._highlighter$_buffer, t3 = _this._multiline; t1.moveNext$0();) {
        t4 = t1.__internal$_current;
        _this._writeSidebar$1$line(lineNumber);
        t2._contents += C.JSString_methods.$mul(" ", t3 ? 3 : 1);
        _this._writeText$1(t4);
        t2._contents += "\n";
        ++lineNumber;
      }
    },
    _writeText$1: function(text) {
      var t1, t2, t3;
      text.toString;
      t1 = new H.CodeUnits(text);
      t1 = new H.ListIterator(t1, t1.get$length(t1), type$.CodeUnits._eval$1("ListIterator<ListMixin.E>"));
      t2 = this._highlighter$_buffer;
      for (; t1.moveNext$0();) {
        t3 = t1.__internal$_current;
        if (t3 === 9)
          t2._contents += C.JSString_methods.$mul(" ", 4);
        else
          t2._contents += H.Primitives_stringFromCharCode(t3);
      }
    },
    _writeSidebar$2$end$line: function(end, line) {
      this._colorize$2$color(new U.Highlighter__writeSidebar_closure(this, line, end), "\x1b[34m");
    },
    _writeSidebar$1$end: function(end) {
      return this._writeSidebar$2$end$line(end, null);
    },
    _writeSidebar$1$line: function(line) {
      return this._writeSidebar$2$end$line(null, line);
    },
    _writeSidebar$0: function() {
      return this._writeSidebar$2$end$line(null, null);
    },
    _countTabs$1: function(text) {
      var t1, count;
      for (t1 = new H.CodeUnits(text), t1 = new H.ListIterator(t1, t1.get$length(t1), type$.CodeUnits._eval$1("ListIterator<ListMixin.E>")), count = 0; t1.moveNext$0();)
        if (t1.__internal$_current === 9)
          ++count;
      return count;
    },
    _isOnlyWhitespace$1: function(text) {
      var t1, t2;
      for (t1 = new H.CodeUnits(text), t1 = new H.ListIterator(t1, t1.get$length(t1), type$.CodeUnits._eval$1("ListIterator<ListMixin.E>")); t1.moveNext$0();) {
        t2 = t1.__internal$_current;
        if (t2 !== 32 && t2 !== 9)
          return false;
      }
      return true;
    },
    _colorize$2$color: function(callback, color) {
      var t1, t2;
      type$.void_Function._check(callback);
      t1 = this._color;
      t2 = t1 != null;
      if (t2) {
        t1 = color == null ? t1 : color;
        this._highlighter$_buffer._contents += t1;
      }
      callback.call$0();
      if (t2)
        this._highlighter$_buffer._contents += "\x1b[0m";
    },
    _colorize$1: function(callback) {
      return this._colorize$2$color(callback, null);
    }
  };
  U.Highlighter__writeFirstLine_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._highlighter$_buffer,
        t3 = t2._contents += $._glyphs.glyphOrAscii$2("\u250c", "/");
      t2._contents = t3 + " ";
      t1._writeText$1(this.line);
    },
    $signature: 0
  };
  U.Highlighter__writeFirstLine_closure0.prototype = {
    call$0: function() {
      return this.$this._writeText$1(this.textInside);
    },
    $signature: 1
  };
  U.Highlighter__writeFirstLine_closure1.prototype = {
    call$0: function() {
      var t2,
        t1 = this.$this._highlighter$_buffer;
      t1._contents += $._glyphs.get$topLeftCorner();
      t2 = t1._contents += C.JSString_methods.$mul($._glyphs.get$horizontalLine(), this._box_0.startColumn + 1);
      t1._contents = t2 + "^";
    },
    $signature: 0
  };
  U.Highlighter__writeFirstLine_closure2.prototype = {
    call$0: function() {
      var t1 = this._box_0;
      this.$this._highlighter$_buffer._contents += C.JSString_methods.$mul("^", Math.max(t1.endColumn - t1.startColumn, 1));
      return null;
    },
    $signature: 1
  };
  U.Highlighter__writeIntermediateLines_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._highlighter$_buffer,
        t3 = t2._contents += $._glyphs.get$verticalLine();
      t2._contents = t3 + " ";
      t1._writeText$1(this.line);
    },
    $signature: 0
  };
  U.Highlighter__writeLastLine_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._highlighter$_buffer,
        t3 = t2._contents += $._glyphs.glyphOrAscii$2("\u2514", "\\");
      t2._contents = t3 + " ";
      t1._writeText$1(this.line);
    },
    $signature: 0
  };
  U.Highlighter__writeLastLine_closure0.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = t1._highlighter$_buffer,
        t3 = t2._contents += $._glyphs.get$verticalLine();
      t2._contents = t3 + " ";
      t1._writeText$1(this.textInside);
    },
    $signature: 0
  };
  U.Highlighter__writeLastLine_closure1.prototype = {
    call$0: function() {
      var t2,
        t1 = this.$this._highlighter$_buffer;
      t1._contents += $._glyphs.get$bottomLeftCorner();
      t2 = t1._contents += C.JSString_methods.$mul($._glyphs.get$horizontalLine(), this._box_0.endColumn);
      t1._contents = t2 + "^";
    },
    $signature: 0
  };
  U.Highlighter__writeSidebar_closure.prototype = {
    call$0: function() {
      var t1 = this.line,
        t2 = this.$this,
        t3 = t2._highlighter$_buffer;
      t2 = t2._paddingBeforeSidebar;
      if (t1 != null)
        t3._contents += C.JSString_methods.padRight$1(C.JSInt_methods.toString$0(t1 + 1), t2);
      else
        t3._contents += C.JSString_methods.$mul(" ", t2);
      t1 = this.end;
      t3._contents += t1 == null ? $._glyphs.get$verticalLine() : t1;
    },
    $signature: 0
  };
  V.SourceLocation.prototype = {
    distance$1: function(other) {
      var t1 = this.sourceUrl;
      if (!J.$eq$(t1, other.get$sourceUrl()))
        throw H.wrapException(P.ArgumentError$('Source URLs "' + H.S(t1) + '" and "' + H.S(other.get$sourceUrl()) + "\" don't match."));
      return Math.abs(this.offset - other.get$offset(other));
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return type$.SourceLocation._is(other) && J.$eq$(this.sourceUrl, other.get$sourceUrl()) && this.offset === other.get$offset(other);
    },
    get$hashCode: function(_) {
      return J.get$hashCode$(this.sourceUrl) + this.offset;
    },
    toString$0: function(_) {
      var _this = this,
        t1 = "<" + H.getRuntimeType(_this).toString$0(0) + ": " + _this.offset + " ",
        source = _this.sourceUrl;
      return t1 + (H.S(source == null ? "unknown source" : source) + ":" + (_this.line + 1) + ":" + (_this.column + 1)) + ">";
    },
    get$sourceUrl: function() {
      return this.sourceUrl;
    },
    get$offset: function(receiver) {
      return this.offset;
    },
    get$line: function() {
      return this.line;
    },
    get$column: function() {
      return this.column;
    }
  };
  D.SourceLocationMixin.prototype = {
    distance$1: function(other) {
      if (!J.$eq$(this.file.url, other.get$sourceUrl()))
        throw H.wrapException(P.ArgumentError$('Source URLs "' + H.S(this.get$sourceUrl()) + '" and "' + H.S(other.get$sourceUrl()) + "\" don't match."));
      return Math.abs(this.offset - other.get$offset(other));
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return type$.SourceLocation._is(other) && J.$eq$(this.file.url, other.get$sourceUrl()) && this.offset === other.get$offset(other);
    },
    get$hashCode: function(_) {
      return J.get$hashCode$(this.file.url) + this.offset;
    },
    toString$0: function(_) {
      var t1 = this.offset,
        t2 = "<" + H.getRuntimeType(this).toString$0(0) + ": " + t1 + " ",
        t3 = this.file,
        source = t3.url,
        t4 = H.S(source == null ? "unknown source" : source) + ":",
        t5 = t3.getLine$1(t1);
      if (typeof t5 !== "number")
        return t5.$add();
      return t2 + (t4 + (t5 + 1) + ":" + (t3.getColumn$1(t1) + 1)) + ">";
    },
    $isSourceLocation: 1
  };
  V.SourceSpan.prototype = {};
  V.SourceSpanBase.prototype = {
    SourceSpanBase$3: function(start, end, text) {
      var t3,
        t1 = this.end,
        t2 = this.start;
      if (!J.$eq$(t1.get$sourceUrl(), t2.get$sourceUrl()))
        throw H.wrapException(P.ArgumentError$('Source URLs "' + H.S(t2.get$sourceUrl()) + '" and  "' + H.S(t1.get$sourceUrl()) + "\" don't match."));
      else if (t1.get$offset(t1) < t2.get$offset(t2))
        throw H.wrapException(P.ArgumentError$("End " + t1.toString$0(0) + " must come after start " + t2.toString$0(0) + "."));
      else {
        t3 = this.text;
        if (t3.length !== t2.distance$1(t1))
          throw H.wrapException(P.ArgumentError$('Text "' + t3 + '" must be ' + t2.distance$1(t1) + " characters long."));
      }
    },
    get$start: function() {
      return this.start;
    },
    get$end: function() {
      return this.end;
    },
    get$text: function() {
      return this.text;
    }
  };
  G.SourceSpanException.prototype = {
    get$message: function(_) {
      return this._span_exception$_message;
    },
    toString$1$color: function(_, color) {
      var t1 = this._span_exception$_span;
      if (t1 == null)
        return this._span_exception$_message;
      return "Error on " + t1.message$2$color(0, this._span_exception$_message, color);
    },
    toString$0: function($receiver) {
      return this.toString$1$color($receiver, null);
    },
    $isException: 1
  };
  G.SourceSpanFormatException.prototype = {$isFormatException: 1};
  Y.SourceSpanMixin.prototype = {
    get$sourceUrl: function() {
      return this.get$start().get$sourceUrl();
    },
    get$length: function(_) {
      var t2,
        t1 = this.get$end();
      t1 = t1.get$offset(t1);
      t2 = this.get$start();
      return t1 - t2.get$offset(t2);
    },
    message$2$color: function(_, message, color) {
      var t2, highlight, _this = this,
        t1 = _this.get$start().get$line();
      if (typeof t1 !== "number")
        return t1.$add();
      t1 = "line " + (t1 + 1) + ", column " + (_this.get$start().get$column() + 1);
      if (_this.get$sourceUrl() != null) {
        t2 = _this.get$sourceUrl();
        t2 = t1 + (" of " + H.S($.$get$context().prettyUri$1(t2)));
        t1 = t2;
      }
      t1 += ": " + H.S(message);
      highlight = _this.highlight$1$color(color);
      if (highlight.length !== 0)
        t1 = t1 + "\n" + highlight;
      return t1.charCodeAt(0) == 0 ? t1 : t1;
    },
    message$1: function($receiver, message) {
      return this.message$2$color($receiver, message, null);
    },
    highlight$1$color: function(color) {
      var t2, t3, t4, newSpan, _this = this,
        t1 = type$.SourceSpanWithContext._is(_this);
      if (!t1 && _this.get$length(_this) === 0)
        return "";
      if (t1 && B.findLineStart(_this.get$context(), _this.get$text(), _this.get$start().get$column()) != null)
        t1 = _this;
      else {
        t1 = _this.get$start();
        t1 = V.SourceLocation$(t1.get$offset(t1), 0, 0, _this.get$sourceUrl());
        t2 = _this.get$end();
        t2 = t2.get$offset(t2);
        t3 = _this.get$sourceUrl();
        t4 = B.countCodeUnits(_this.get$text(), 10);
        t3 = X.SourceSpanWithContext$(t1, V.SourceLocation$(t2, U.Highlighter__lastLineLength(_this.get$text()), t4, t3), _this.get$text(), _this.get$text());
        t1 = t3;
      }
      newSpan = U.Highlighter__normalizeEndOfLine(U.Highlighter__normalizeTrailingNewline(U.Highlighter__normalizeNewlines(t1)));
      return new U.Highlighter(newSpan, color, newSpan.get$start().get$line() != newSpan.get$end().get$line(), J.toString$0$(newSpan.get$end().get$line()).length + 1, new P.StringBuffer("")).highlight$0();
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return type$.SourceSpan._is(other) && this.get$start().$eq(0, other.get$start()) && this.get$end().$eq(0, other.get$end());
    },
    get$hashCode: function(_) {
      var t2,
        t1 = this.get$start();
      t1 = t1.get$hashCode(t1);
      t2 = this.get$end();
      return t1 + 31 * t2.get$hashCode(t2);
    },
    toString$0: function(_) {
      var _this = this;
      return "<" + H.getRuntimeType(_this).toString$0(0) + ": from " + _this.get$start().toString$0(0) + " to " + _this.get$end().toString$0(0) + ' "' + _this.get$text() + '">';
    },
    $isSourceSpan: 1
  };
  X.SourceSpanWithContext.prototype = {
    get$context: function() {
      return this._context;
    }
  };
  U.Chain.prototype = {
    foldFrames$2$terse: function(predicate, terse) {
      var t1 = this.traces,
        t2 = H._arrayInstanceType(t1),
        t3 = t2._eval$1("MappedListIterable<1,Trace>"),
        foldedTraces = new H.MappedListIterable(t1, t2._eval$1("Trace(1)")._check(new U.Chain_foldFrames_closure(type$.bool_Function_Frame._check(predicate), true)), t3),
        nonEmptyTraces = foldedTraces.super$Iterable$where(0, t3._eval$1("bool(ListIterable.E)")._check(new U.Chain_foldFrames_closure0(true)));
      if (!nonEmptyTraces.get$iterator(nonEmptyTraces).moveNext$0() && !foldedTraces.get$isEmpty(foldedTraces))
        return new U.Chain(P.List_List$unmodifiable(H.setRuntimeTypeInfo([foldedTraces.get$last(foldedTraces)], type$.JSArray_Trace), type$.Trace));
      return new U.Chain(P.List_List$unmodifiable(nonEmptyTraces, type$.Trace));
    },
    toTrace$0: function() {
      var t1 = this.traces,
        t2 = H._arrayInstanceType(t1);
      return new Y.Trace(P.List_List$unmodifiable(new H.ExpandIterable(t1, t2._eval$1("Iterable<Frame>(1)")._check(new U.Chain_toTrace_closure()), t2._eval$1("ExpandIterable<1,Frame>")), type$.Frame), new P._StringStackTrace(null));
    },
    toString$0: function(_) {
      var t1 = this.traces,
        t2 = H._arrayInstanceType(t1),
        t3 = type$.int;
      return new H.MappedListIterable(t1, t2._eval$1("String(1)")._check(new U.Chain_toString_closure(new H.MappedListIterable(t1, t2._eval$1("int(1)")._check(new U.Chain_toString_closure0()), t2._eval$1("MappedListIterable<1,int>")).fold$1$2(0, 0, H.instantiate1(P.math__max$closure(), t3), t3))), t2._eval$1("MappedListIterable<1,String>")).join$1(0, "===== asynchronous gap ===========================\n");
    },
    $isStackTrace: 1,
    get$traces: function() {
      return this.traces;
    }
  };
  U.Chain_capture_closure.prototype = {
    call$0: function() {
      var error, stackTrace, t1, exception;
      try {
        t1 = this.callback.call$0();
        return t1;
      } catch (exception) {
        error = H.unwrapException(exception);
        stackTrace = H.getTraceFromException(exception);
        $.Zone__current.handleUncaughtError$2(error, stackTrace);
        return null;
      }
    },
    $signature: function() {
      return this.T._eval$1("0()");
    }
  };
  U.Chain_Chain$current_closure.prototype = {
    call$0: function() {
      var t3,
        t1 = this.chain,
        t2 = C.JSArray_methods.get$first(t1.get$traces()).get$frames();
      t2 = H.SubListIterable$(t2, this.level + 2, null, H._arrayInstanceType(t2)._precomputed1);
      t3 = C.JSArray_methods.get$first(t1.get$traces()).get$original();
      t3 = H.setRuntimeTypeInfo([new Y.Trace(P.List_List$unmodifiable(t2, type$.Frame), new P._StringStackTrace(t3._stackTrace))], type$.JSArray_Trace);
      t1 = t1.get$traces();
      C.JSArray_methods.addAll$1(t3, H.SubListIterable$(t1, 1, null, H._arrayInstanceType(t1)._precomputed1));
      return new U.Chain(P.List_List$unmodifiable(t3, type$.Trace));
    },
    $signature: 16
  };
  U.Chain_Chain$forTrace_closure.prototype = {
    call$0: function() {
      return U.Chain_Chain$parse(J.toString$0$(this.trace));
    },
    $signature: 16
  };
  U.Chain_Chain$parse_closure.prototype = {
    call$1: function(trace) {
      H._checkStringNullable(trace);
      return new Y.Trace(P.List_List$unmodifiable(Y.Trace__parseVM(trace), type$.Frame), new P._StringStackTrace(trace));
    },
    $signature: 42
  };
  U.Chain_Chain$parse_closure0.prototype = {
    call$1: function(trace) {
      return Y.Trace$parseFriendly(H._checkStringNullable(trace));
    },
    $signature: 42
  };
  U.Chain_foldFrames_closure.prototype = {
    call$1: function(trace) {
      return type$.Trace._check(trace).foldFrames$2$terse(this.predicate, this.terse);
    },
    $signature: 45
  };
  U.Chain_foldFrames_closure0.prototype = {
    call$1: function(trace) {
      type$.Trace._check(trace);
      if (trace.get$frames().length > 1)
        return true;
      if (trace.get$frames().length === 0)
        return false;
      if (!this.terse)
        return false;
      return C.JSArray_methods.get$single(trace.get$frames()).get$line() != null;
    },
    $signature: 52
  };
  U.Chain_toTrace_closure.prototype = {
    call$1: function(trace) {
      return type$.Trace._check(trace).get$frames();
    },
    $signature: 53
  };
  U.Chain_toString_closure0.prototype = {
    call$1: function(trace) {
      var t1 = type$.Trace._check(trace).get$frames(),
        t2 = H._arrayInstanceType(t1),
        t3 = type$.int;
      return new H.MappedListIterable(t1, t2._eval$1("int(1)")._check(new U.Chain_toString__closure0()), t2._eval$1("MappedListIterable<1,int>")).fold$1$2(0, 0, H.instantiate1(P.math__max$closure(), t3), t3);
    },
    $signature: 54
  };
  U.Chain_toString__closure0.prototype = {
    call$1: function(frame) {
      type$.Frame._check(frame);
      return frame.get$location(frame).length;
    },
    $signature: 39
  };
  U.Chain_toString_closure.prototype = {
    call$1: function(trace) {
      var t1 = type$.Trace._check(trace).get$frames(),
        t2 = H._arrayInstanceType(t1);
      return new H.MappedListIterable(t1, t2._eval$1("String(1)")._check(new U.Chain_toString__closure(this.longest)), t2._eval$1("MappedListIterable<1,String>")).join$0(0);
    },
    $signature: 56
  };
  U.Chain_toString__closure.prototype = {
    call$1: function(frame) {
      type$.Frame._check(frame);
      return J.padRight$1$s(frame.get$location(frame), this.longest) + "  " + H.S(frame.get$member()) + "\n";
    },
    $signature: 38
  };
  A.Frame.prototype = {
    get$isCore: function() {
      return this.uri.get$scheme() === "dart";
    },
    get$library: function() {
      var t1 = this.uri;
      if (t1.get$scheme() === "data")
        return "data:...";
      return $.$get$context().prettyUri$1(t1);
    },
    get$$package: function() {
      var t1 = this.uri;
      if (t1.get$scheme() !== "package")
        return null;
      return C.JSArray_methods.get$first(t1.get$path(t1).split("/"));
    },
    get$location: function(_) {
      var t2, _this = this,
        t1 = _this.line;
      if (t1 == null)
        return _this.get$library();
      t2 = _this.column;
      if (t2 == null)
        return H.S(_this.get$library()) + " " + H.S(t1);
      return H.S(_this.get$library()) + " " + H.S(t1) + ":" + H.S(t2);
    },
    toString$0: function(_) {
      return H.S(this.get$location(this)) + " in " + H.S(this.member);
    },
    get$uri: function() {
      return this.uri;
    },
    get$line: function() {
      return this.line;
    },
    get$column: function() {
      return this.column;
    },
    get$member: function() {
      return this.member;
    }
  };
  A.Frame_Frame$parseVM_closure.prototype = {
    call$0: function() {
      var match, t2, t3, member, uri, lineAndColumn, line, _null = null,
        t1 = this.frame;
      if (t1 === "...")
        return new A.Frame(P._Uri__Uri(_null, _null, _null, _null), _null, _null, "...");
      match = $.$get$_vmFrame().firstMatch$1(t1);
      if (match == null)
        return new N.UnparsedFrame(P._Uri__Uri(_null, "unparsed", _null, _null), t1);
      t1 = match._match;
      if (1 >= t1.length)
        return H.ioore(t1, 1);
      t2 = t1[1];
      t3 = $.$get$_asyncBody();
      t2.toString;
      t2 = H.stringReplaceAllUnchecked(t2, t3, "<async>");
      member = H.stringReplaceAllUnchecked(t2, "<anonymous closure>", "<fn>");
      if (2 >= t1.length)
        return H.ioore(t1, 2);
      uri = P.Uri_parse(t1[2]);
      if (3 >= t1.length)
        return H.ioore(t1, 3);
      lineAndColumn = t1[3].split(":");
      t1 = lineAndColumn.length;
      line = t1 > 1 ? P.int_parse(lineAndColumn[1], _null, _null) : _null;
      return new A.Frame(uri, line, t1 > 2 ? P.int_parse(lineAndColumn[2], _null, _null) : _null, member);
    },
    $signature: 17
  };
  A.Frame_Frame$parseV8_closure.prototype = {
    call$0: function() {
      var t2, t3, t4, _s4_ = "<fn>",
        t1 = this.frame,
        match = $.$get$_v8Frame().firstMatch$1(t1);
      if (match == null)
        return new N.UnparsedFrame(P._Uri__Uri(null, "unparsed", null, null), t1);
      t1 = new A.Frame_Frame$parseV8_closure_parseLocation(t1);
      t2 = match._match;
      t3 = t2.length;
      if (2 >= t3)
        return H.ioore(t2, 2);
      t4 = t2[2];
      if (t4 != null) {
        t2 = t2[1];
        t2.toString;
        t2 = H.stringReplaceAllUnchecked(t2, "<anonymous>", _s4_);
        t2 = H.stringReplaceAllUnchecked(t2, "Anonymous function", _s4_);
        return t1.call$2(t4, H.stringReplaceAllUnchecked(t2, "(anonymous function)", _s4_));
      } else {
        if (3 >= t3)
          return H.ioore(t2, 3);
        return t1.call$2(t2[3], _s4_);
      }
    },
    $signature: 17
  };
  A.Frame_Frame$parseV8_closure_parseLocation.prototype = {
    call$2: function($location, member) {
      var t2, urlMatch, t3, _null = null,
        t1 = $.$get$_v8EvalLocation(),
        evalMatch = t1.firstMatch$1($location);
      for (; evalMatch != null;) {
        t2 = evalMatch._match;
        if (1 >= t2.length)
          return H.ioore(t2, 1);
        $location = t2[1];
        evalMatch = t1.firstMatch$1($location);
      }
      if ($location === "native")
        return new A.Frame(P.Uri_parse("native"), _null, _null, member);
      urlMatch = $.$get$_v8UrlLocation().firstMatch$1($location);
      if (urlMatch == null)
        return new N.UnparsedFrame(P._Uri__Uri(_null, "unparsed", _null, _null), this.frame);
      t1 = urlMatch._match;
      if (1 >= t1.length)
        return H.ioore(t1, 1);
      t2 = A.Frame__uriOrPathToUri(t1[1]);
      if (2 >= t1.length)
        return H.ioore(t1, 2);
      t3 = P.int_parse(t1[2], _null, _null);
      if (3 >= t1.length)
        return H.ioore(t1, 3);
      return new A.Frame(t2, t3, P.int_parse(t1[3], _null, _null), member);
    },
    $signature: 59
  };
  A.Frame_Frame$parseFirefox_closure.prototype = {
    call$0: function() {
      var uri, t2, t3, member, line, _null = null,
        t1 = this.frame,
        match = $.$get$_firefoxSafariFrame().firstMatch$1(t1);
      if (match == null)
        return new N.UnparsedFrame(P._Uri__Uri(_null, "unparsed", _null, _null), t1);
      t1 = match._match;
      if (3 >= t1.length)
        return H.ioore(t1, 3);
      uri = A.Frame__uriOrPathToUri(t1[3]);
      t2 = t1.length;
      if (1 >= t2)
        return H.ioore(t1, 1);
      t3 = t1[1];
      if (t3 != null) {
        if (2 >= t2)
          return H.ioore(t1, 2);
        t2 = C.JSString_methods.allMatches$1("/", t1[2]);
        member = J.$add$ansx(t3, C.JSArray_methods.join$0(P.List_List$filled(t2.get$length(t2), ".<fn>", type$.String)));
        if (member === "")
          member = "<fn>";
        member = C.JSString_methods.replaceFirst$2(member, $.$get$_initialDot(), "");
      } else
        member = "<fn>";
      if (4 >= t1.length)
        return H.ioore(t1, 4);
      t2 = t1[4];
      line = t2 === "" ? _null : P.int_parse(t2, _null, _null);
      if (5 >= t1.length)
        return H.ioore(t1, 5);
      t1 = t1[5];
      return new A.Frame(uri, line, t1 == null || t1 === "" ? _null : P.int_parse(t1, _null, _null), member);
    },
    $signature: 17
  };
  A.Frame_Frame$parseFriendly_closure.prototype = {
    call$0: function() {
      var t2, buffer, indices, uri, line, column, _null = null,
        t1 = this.frame,
        match = $.$get$_friendlyFrame().firstMatch$1(t1);
      if (match == null)
        throw H.wrapException(P.FormatException$("Couldn't parse package:stack_trace stack trace line '" + H.S(t1) + "'.", _null, _null));
      t1 = match._match;
      if (1 >= t1.length)
        return H.ioore(t1, 1);
      t2 = t1[1];
      if (t2 === "data:...") {
        buffer = new P.StringBuffer("");
        indices = H.setRuntimeTypeInfo([-1], type$.JSArray_int);
        P.UriData__writeUri(_null, _null, _null, buffer, indices);
        C.JSArray_methods.add$1(indices, buffer._contents.length);
        buffer._contents += ",";
        P.UriData__uriEncodeBytes(C.List_CVk, C.C_AsciiCodec.encode$1(""), buffer);
        t2 = buffer._contents;
        uri = new P.UriData(t2.charCodeAt(0) == 0 ? t2 : t2, indices, _null).get$uri();
      } else
        uri = P.Uri_parse(t2);
      if (uri.get$scheme() === "") {
        t2 = $.$get$context();
        uri = t2.toUri$1(t2.absolute$7(0, t2.style.pathFromUri$1(M._parseUri(uri)), _null, _null, _null, _null, _null, _null));
      }
      if (2 >= t1.length)
        return H.ioore(t1, 2);
      t2 = t1[2];
      line = t2 == null ? _null : P.int_parse(t2, _null, _null);
      if (3 >= t1.length)
        return H.ioore(t1, 3);
      t2 = t1[3];
      column = t2 == null ? _null : P.int_parse(t2, _null, _null);
      if (4 >= t1.length)
        return H.ioore(t1, 4);
      return new A.Frame(uri, line, column, t1[4]);
    },
    $signature: 17
  };
  X.LazyChain.prototype = {
    get$_chain: function() {
      var _this = this;
      if (_this._lazy_chain$_inner == null)
        _this.set$_lazy_chain$_inner(_this._thunk.call$0());
      return _this._lazy_chain$_inner;
    },
    get$traces: function() {
      return this.get$_chain().get$traces();
    },
    foldFrames$2$terse: function(predicate, terse) {
      return new X.LazyChain(new X.LazyChain_foldFrames_closure(this, type$.bool_Function_Frame._check(predicate), true));
    },
    toTrace$0: function() {
      return new T.LazyTrace(new X.LazyChain_toTrace_closure(this));
    },
    toString$0: function(_) {
      return J.toString$0$(this.get$_chain());
    },
    set$_lazy_chain$_inner: function(_inner) {
      this._lazy_chain$_inner = type$.Chain._check(_inner);
    },
    $isStackTrace: 1,
    $isChain: 1
  };
  X.LazyChain_foldFrames_closure.prototype = {
    call$0: function() {
      return this.$this.get$_chain().foldFrames$2$terse(this.predicate, this.terse);
    },
    $signature: 16
  };
  X.LazyChain_toTrace_closure.prototype = {
    call$0: function() {
      return this.$this.get$_chain().toTrace$0();
    },
    $signature: 8
  };
  T.LazyTrace.prototype = {
    get$_lazy_trace$_trace: function() {
      var _this = this;
      if (_this._lazy_trace$_inner == null)
        _this.set$_lazy_trace$_inner(_this._lazy_trace$_thunk.call$0());
      return _this._lazy_trace$_inner;
    },
    get$frames: function() {
      return this.get$_lazy_trace$_trace().get$frames();
    },
    get$original: function() {
      return this.get$_lazy_trace$_trace().get$original();
    },
    foldFrames$2$terse: function(predicate, terse) {
      return new T.LazyTrace(new T.LazyTrace_foldFrames_closure(this, type$.bool_Function_Frame._check(predicate), true));
    },
    toString$0: function(_) {
      return J.toString$0$(this.get$_lazy_trace$_trace());
    },
    set$_lazy_trace$_inner: function(_inner) {
      this._lazy_trace$_inner = type$.Trace._check(_inner);
    },
    $isStackTrace: 1,
    $isTrace: 1
  };
  T.LazyTrace_foldFrames_closure.prototype = {
    call$0: function() {
      return this.$this.get$_lazy_trace$_trace().foldFrames$2$terse(this.predicate, this.terse);
    },
    $signature: 8
  };
  O.StackZoneSpecification.prototype = {
    chainFor$1: function(trace) {
      var t2, previous, t3, t1 = {};
      t1.trace = trace;
      if (type$.Chain._is(trace))
        return trace;
      if (trace == null) {
        trace = P.StackTrace_current();
        t1.trace = trace;
        t2 = trace;
      } else
        t2 = trace;
      previous = this._chains.$index(0, t2);
      if (previous == null)
        previous = this._currentNode;
      if (previous == null) {
        t3 = type$.Trace;
        if (t3._is(t2))
          return new U.Chain(P.List_List$unmodifiable(H.setRuntimeTypeInfo([t2], type$.JSArray_Trace), t3));
        return new X.LazyChain(new O.StackZoneSpecification_chainFor_closure(t1));
      } else
        return new O._Node(Y.Trace_Trace$from(!type$.Trace._is(t2) ? t1.trace = new T.LazyTrace(new O.StackZoneSpecification_chainFor_closure0(this, t2)) : t2), previous).toChain$0();
    },
    _stack_zone_specification$_registerCallback$1$4: function($self, $parent, zone, f, $R) {
      var t1, t2;
      $R._eval$1("0()")._check(f);
      if (f == null || J.$eq$($.Zone__current.$index(0, $.$get$StackZoneSpecification_disableKey()), true))
        return $parent.registerCallback$1$2(zone, f, $R);
      t1 = this._currentTrace$1(2);
      t2 = this._currentNode;
      return $parent.registerCallback$1$2(zone, new O.StackZoneSpecification__registerCallback_closure(this, f, new O._Node(Y.Trace_Trace$from(t1), t2), $R), $R);
    },
    _stack_zone_specification$_registerCallback$4: function($self, $parent, zone, f) {
      return this._stack_zone_specification$_registerCallback$1$4($self, $parent, zone, f, type$.dynamic);
    },
    _stack_zone_specification$_registerUnaryCallback$2$4: function($self, $parent, zone, f, $R, $T) {
      var t1, t2;
      $R._eval$1("@<0>")._bind$1($T)._eval$1("1(2)")._check(f);
      if (f == null || J.$eq$($.Zone__current.$index(0, $.$get$StackZoneSpecification_disableKey()), true))
        return $parent.registerUnaryCallback$2$2(zone, f, $R, $T);
      t1 = this._currentTrace$1(2);
      t2 = this._currentNode;
      return $parent.registerUnaryCallback$2$2(zone, new O.StackZoneSpecification__registerUnaryCallback_closure(this, f, new O._Node(Y.Trace_Trace$from(t1), t2), $T, $R), $R, $T);
    },
    _stack_zone_specification$_registerUnaryCallback$4: function($self, $parent, zone, f) {
      return this._stack_zone_specification$_registerUnaryCallback$2$4($self, $parent, zone, f, type$.dynamic, type$.dynamic);
    },
    _stack_zone_specification$_registerBinaryCallback$3$4: function($self, $parent, zone, f, $R, T1, T2) {
      var t1, t2;
      type$.Function._check(f);
      if (f == null || J.$eq$($.Zone__current.$index(0, $.$get$StackZoneSpecification_disableKey()), true))
        return $parent.registerBinaryCallback$3$2(zone, $R._eval$1("@<0>")._bind$1(T1)._bind$1(T2)._eval$1("1(2,3)")._check(f), $R, T1, T2);
      t1 = this._currentTrace$1(2);
      t2 = this._currentNode;
      return $parent.registerBinaryCallback$3$2(zone, new O.StackZoneSpecification__registerBinaryCallback_closure(this, f, new O._Node(Y.Trace_Trace$from(t1), t2), T1, T2, $R), $R, T1, T2);
    },
    _stack_zone_specification$_registerBinaryCallback$4: function($self, $parent, zone, f) {
      return this._stack_zone_specification$_registerBinaryCallback$3$4($self, $parent, zone, f, type$.dynamic, type$.dynamic, type$.dynamic);
    },
    _stack_zone_specification$_errorCallback$5: function($self, $parent, zone, error, stackTrace) {
      var t1, t2, t3, asyncError, _this = this;
      type$.StackTrace._check(stackTrace);
      if (J.$eq$($.Zone__current.$index(0, $.$get$StackZoneSpecification_disableKey()), true))
        return $parent.errorCallback$3(zone, error, stackTrace);
      if (stackTrace == null) {
        t1 = _this._currentTrace$1(3);
        t2 = _this._currentNode;
        stackTrace = new O._Node(Y.Trace_Trace$from(t1), t2).toChain$0();
      } else {
        t1 = _this._chains;
        if (t1.$index(0, stackTrace) == null) {
          t2 = _this._currentTrace$1(3);
          t3 = _this._currentNode;
          t1.$indexSet(0, stackTrace, new O._Node(Y.Trace_Trace$from(t2), t3));
        }
      }
      asyncError = $parent.errorCallback$3(zone, error, stackTrace);
      return asyncError == null ? new P.AsyncError(error, stackTrace) : asyncError;
    },
    _stack_zone_specification$_run$1$2: function(f, node, $T) {
      var previousNode, stackTrace, t1, exception, t2, _this = this;
      $T._eval$1("0()")._check(f);
      previousNode = _this._currentNode;
      _this._currentNode = node;
      try {
        t1 = f.call$0();
        return t1;
      } catch (exception) {
        H.unwrapException(exception);
        stackTrace = H.getTraceFromException(exception);
        t1 = _this._chains;
        t2 = stackTrace;
        if (t1.$index(0, t2) == null)
          t1.$indexSet(0, t2, node);
        throw exception;
      } finally {
        _this.set$_currentNode(previousNode);
      }
    },
    _currentTrace$1: function(level) {
      var t1 = {};
      t1.level = level;
      return new T.LazyTrace(new O.StackZoneSpecification__currentTrace_closure(t1, this, P.StackTrace_current()));
    },
    _trimVMChain$1: function(trace) {
      var text = J.toString$0$(trace),
        index = J.getInterceptor$s(text).indexOf$1(text, "<asynchronous suspension>\n");
      return index === -1 ? text : C.JSString_methods.substring$2(text, 0, index);
    },
    set$_currentNode: function(_currentNode) {
      this._currentNode = type$._Node._check(_currentNode);
    }
  };
  O.StackZoneSpecification_chainFor_closure.prototype = {
    call$0: function() {
      return U.Chain_Chain$parse(J.toString$0$(this._box_0.trace));
    },
    $signature: 16
  };
  O.StackZoneSpecification_chainFor_closure0.prototype = {
    call$0: function() {
      return Y.Trace_Trace$parse(this.$this._trimVMChain$1(this.original));
    },
    $signature: 8
  };
  O.StackZoneSpecification__registerCallback_closure.prototype = {
    call$0: function() {
      var _this = this;
      return _this.$this._stack_zone_specification$_run$1$2(_this.f, _this.node, _this.R);
    },
    $signature: function() {
      return this.R._eval$1("0()");
    }
  };
  O.StackZoneSpecification__registerUnaryCallback_closure.prototype = {
    call$1: function(arg) {
      var _this = this,
        t1 = _this.R;
      return _this.$this._stack_zone_specification$_run$1$2(new O.StackZoneSpecification__registerUnaryCallback__closure(_this.f, _this.T._check(arg), t1), _this.node, t1);
    },
    $signature: function() {
      return this.R._eval$1("@<0>")._bind$1(this.T)._eval$1("1(2)");
    }
  };
  O.StackZoneSpecification__registerUnaryCallback__closure.prototype = {
    call$0: function() {
      return this.f.call$1(this.arg);
    },
    $signature: function() {
      return this.R._eval$1("0()");
    }
  };
  O.StackZoneSpecification__registerBinaryCallback_closure.prototype = {
    call$2: function(arg1, arg2) {
      var _this = this,
        t1 = _this.R;
      return _this.$this._stack_zone_specification$_run$1$2(new O.StackZoneSpecification__registerBinaryCallback__closure(_this.f, _this.T1._check(arg1), _this.T2._check(arg2), t1), _this.node, t1);
    },
    $signature: function() {
      return this.R._eval$1("@<0>")._bind$1(this.T1)._bind$1(this.T2)._eval$1("1(2,3)");
    }
  };
  O.StackZoneSpecification__registerBinaryCallback__closure.prototype = {
    call$0: function() {
      var _this = this;
      return _this.R._check(_this.f.call$2(_this.arg1, _this.arg2));
    },
    $signature: function() {
      return this.R._eval$1("0()");
    }
  };
  O.StackZoneSpecification__currentTrace_closure.prototype = {
    call$0: function() {
      var text = this.$this._trimVMChain$1(this.stackTrace),
        t1 = Y.Trace_Trace$parse(text).frames,
        t2 = this._box_0.level;
      if (typeof t2 !== "number")
        return t2.$add();
      return new Y.Trace(P.List_List$unmodifiable(H.SubListIterable$(t1, t2 + 2, null, H._arrayInstanceType(t1)._precomputed1), type$.Frame), new P._StringStackTrace(text));
    },
    $signature: 8
  };
  O._Node.prototype = {
    toChain$0: function() {
      var node,
        nodes = H.setRuntimeTypeInfo([], type$.JSArray_Trace);
      for (node = this; node != null;) {
        C.JSArray_methods.add$1(nodes, node.trace);
        node = node.previous;
      }
      return new U.Chain(P.List_List$unmodifiable(nodes, type$.Trace));
    }
  };
  Y.Trace.prototype = {
    foldFrames$2$terse: function(predicate, terse) {
      var newFrames, t1, t2, _box_0 = {};
      _box_0.predicate = predicate;
      _box_0.predicate = new Y.Trace_foldFrames_closure(type$.bool_Function_Frame._check(predicate));
      newFrames = H.setRuntimeTypeInfo([], type$.JSArray_Frame);
      for (t1 = this.frames, t2 = H._arrayInstanceType(t1)._eval$1("ReversedListIterable<1>"), t1 = new H.ReversedListIterable(t1, t2), t2 = new H.ListIterator(t1, t1.get$length(t1), t2._eval$1("ListIterator<ListIterable.E>")); t2.moveNext$0();) {
        t1 = t2.__internal$_current;
        if (t1 instanceof N.UnparsedFrame || !H.boolConversionCheck(_box_0.predicate.call$1(t1)))
          C.JSArray_methods.add$1(newFrames, t1);
        else if (newFrames.length === 0 || !H.boolConversionCheck(_box_0.predicate.call$1(C.JSArray_methods.get$last(newFrames))))
          C.JSArray_methods.add$1(newFrames, new A.Frame(t1.get$uri(), t1.get$line(), t1.get$column(), t1.get$member()));
      }
      newFrames = new H.MappedListIterable(newFrames, type$.Frame_Function_Frame._check(new Y.Trace_foldFrames_closure0(_box_0)), type$.MappedListIterable_Frame_Frame).toList$0(0);
      if (newFrames.length > 1 && H.boolConversionCheck(_box_0.predicate.call$1(C.JSArray_methods.get$first(newFrames))))
        C.JSArray_methods.removeAt$1(newFrames, 0);
      return new Y.Trace(P.List_List$unmodifiable(new H.ReversedListIterable(newFrames, H._arrayInstanceType(newFrames)._eval$1("ReversedListIterable<1>")), type$.Frame), new P._StringStackTrace(this.original._stackTrace));
    },
    toString$0: function(_) {
      var t1 = this.frames,
        t2 = H._arrayInstanceType(t1),
        t3 = type$.int;
      return new H.MappedListIterable(t1, t2._eval$1("String(1)")._check(new Y.Trace_toString_closure(new H.MappedListIterable(t1, t2._eval$1("int(1)")._check(new Y.Trace_toString_closure0()), t2._eval$1("MappedListIterable<1,int>")).fold$1$2(0, 0, H.instantiate1(P.math__max$closure(), t3), t3))), t2._eval$1("MappedListIterable<1,String>")).join$0(0);
    },
    $isStackTrace: 1,
    get$frames: function() {
      return this.frames;
    },
    get$original: function() {
      return this.original;
    }
  };
  Y.Trace_Trace$current_closure.prototype = {
    call$0: function() {
      var t1 = this.trace,
        t2 = t1.get$frames();
      t2 = H.SubListIterable$(t2, this.level + 2, null, H._arrayInstanceType(t2)._precomputed1);
      t1 = t1.get$original();
      return new Y.Trace(P.List_List$unmodifiable(t2, type$.Frame), new P._StringStackTrace(t1._stackTrace));
    },
    $signature: 8
  };
  Y.Trace_Trace$from_closure.prototype = {
    call$0: function() {
      return Y.Trace_Trace$parse(this.trace.toString$0(0));
    },
    $signature: 8
  };
  Y.Trace__parseVM_closure.prototype = {
    call$1: function(line) {
      return A.Frame_Frame$parseVM(H._checkStringNullable(line));
    },
    $signature: 10
  };
  Y.Trace$parseV8_closure.prototype = {
    call$1: function(line) {
      return !J.startsWith$1$s(H._checkStringNullable(line), $.$get$_v8TraceLine());
    },
    $signature: 4
  };
  Y.Trace$parseV8_closure0.prototype = {
    call$1: function(line) {
      return A.Frame_Frame$parseV8(H._checkStringNullable(line));
    },
    $signature: 10
  };
  Y.Trace$parseJSCore_closure.prototype = {
    call$1: function(line) {
      return H._checkStringNullable(line) !== "\tat ";
    },
    $signature: 4
  };
  Y.Trace$parseJSCore_closure0.prototype = {
    call$1: function(line) {
      return A.Frame_Frame$parseV8(H._checkStringNullable(line));
    },
    $signature: 10
  };
  Y.Trace$parseFirefox_closure.prototype = {
    call$1: function(line) {
      H._checkStringNullable(line);
      return line.length !== 0 && line !== "[native code]";
    },
    $signature: 4
  };
  Y.Trace$parseFirefox_closure0.prototype = {
    call$1: function(line) {
      return A.Frame_Frame$parseFirefox(H._checkStringNullable(line));
    },
    $signature: 10
  };
  Y.Trace$parseFriendly_closure.prototype = {
    call$1: function(line) {
      return !J.startsWith$1$s(H._checkStringNullable(line), "=====");
    },
    $signature: 4
  };
  Y.Trace$parseFriendly_closure0.prototype = {
    call$1: function(line) {
      return A.Frame_Frame$parseFriendly(H._checkStringNullable(line));
    },
    $signature: 10
  };
  Y.Trace_foldFrames_closure.prototype = {
    call$1: function(frame) {
      if (H.boolConversionCheck(this.oldPredicate.call$1(frame)))
        return true;
      if (frame.get$isCore())
        return true;
      if (frame.get$$package() === "stack_trace")
        return true;
      if (!J.contains$1$asx(frame.get$member(), "<async>"))
        return false;
      return frame.get$line() == null;
    },
    $signature: 21
  };
  Y.Trace_foldFrames_closure0.prototype = {
    call$1: function(frame) {
      var t1, t2;
      type$.Frame._check(frame);
      if (frame instanceof N.UnparsedFrame || !H.boolConversionCheck(this._box_0.predicate.call$1(frame)))
        return frame;
      t1 = frame.get$library();
      t2 = $.$get$_terseRegExp();
      t1.toString;
      return new A.Frame(P.Uri_parse(H.stringReplaceAllUnchecked(t1, t2, "")), null, null, frame.get$member());
    },
    $signature: 46
  };
  Y.Trace_toString_closure0.prototype = {
    call$1: function(frame) {
      type$.Frame._check(frame);
      return frame.get$location(frame).length;
    },
    $signature: 39
  };
  Y.Trace_toString_closure.prototype = {
    call$1: function(frame) {
      type$.Frame._check(frame);
      if (frame instanceof N.UnparsedFrame)
        return frame.toString$0(0) + "\n";
      return J.padRight$1$s(frame.get$location(frame), this.longest) + "  " + H.S(frame.get$member()) + "\n";
    },
    $signature: 38
  };
  N.UnparsedFrame.prototype = {
    toString$0: function(_) {
      return this.member;
    },
    $isFrame: 1,
    get$uri: function() {
      return this.uri;
    },
    get$line: function() {
      return null;
    },
    get$column: function() {
      return null;
    },
    get$isCore: function() {
      return false;
    },
    get$library: function() {
      return "unparsed";
    },
    get$$package: function() {
      return null;
    },
    get$location: function() {
      return "unparsed";
    },
    get$member: function() {
      return this.member;
    }
  };
  K.GuaranteeChannel.prototype = {
    get$stream: function(_) {
      var t1 = this._streamController;
      t1.toString;
      return new P._ControllerStream(t1, H._instanceType(t1)._eval$1("_ControllerStream<1>"));
    },
    get$sink: function() {
      return this._sink;
    },
    GuaranteeChannel$3$allowSinkErrors: function(innerSink, allowSinkErrors, _box_0, $T) {
      var _this = this;
      _this.set$_sink(new K._GuaranteeSink(innerSink, _this, new P._AsyncCompleter(new P._Future($.Zone__current, type$._Future_dynamic), type$._AsyncCompleter_dynamic), allowSinkErrors, $T._eval$1("_GuaranteeSink<0>")));
      _this.set$_streamController(P.StreamController_StreamController(null, new K.GuaranteeChannel_closure(_box_0, _this), true, $T));
    },
    _onSinkDisconnected$0: function() {
      this._disconnected = true;
      var t1 = this._subscription;
      if (t1 != null)
        t1.cancel$0();
      this._streamController.close$0(0);
    },
    set$_sink: function(_sink) {
      this._sink = this.$ti._eval$1("_GuaranteeSink<1>")._check(_sink);
    },
    set$_streamController: function(_streamController) {
      this._streamController = this.$ti._eval$1("StreamController<1>")._check(_streamController);
    },
    set$_subscription: function(_subscription) {
      this._subscription = this.$ti._eval$1("StreamSubscription<1>")._check(_subscription);
    }
  };
  K.GuaranteeChannel_closure.prototype = {
    call$0: function() {
      var t2, t3,
        t1 = this.$this;
      if (t1._disconnected)
        return;
      t2 = this._box_0.innerStream;
      t3 = t1._streamController;
      t1.set$_subscription(t2.listen$3$onDone$onError(t3.get$add(t3), new K.GuaranteeChannel__closure(t1), t3.get$addError()));
    },
    $signature: 0
  };
  K.GuaranteeChannel__closure.prototype = {
    call$0: function() {
      var t1 = this.$this;
      t1._sink._onStreamDisconnected$0();
      t1._streamController.close$0(0);
    },
    $signature: 0
  };
  K._GuaranteeSink.prototype = {
    get$done: function() {
      return this._doneCompleter.future;
    },
    add$1: function(_, data) {
      var t1, _this = this;
      _this.$ti._precomputed1._check(data);
      if (_this._closed)
        throw H.wrapException(P.StateError$("Cannot add event after closing."));
      if (_this._addStreamSubscription != null)
        throw H.wrapException(P.StateError$("Cannot add event while adding stream."));
      if (_this._disconnected)
        return;
      t1 = _this._inner;
      t1._async$_target.add$1(0, t1.$ti._precomputed1._check(data));
    },
    addError$2: function(error, stackTrace) {
      var _this = this;
      type$.StackTrace._check(stackTrace);
      if (_this._closed)
        throw H.wrapException(P.StateError$("Cannot add event after closing."));
      if (_this._addStreamSubscription != null)
        throw H.wrapException(P.StateError$("Cannot add event while adding stream."));
      if (_this._disconnected)
        return;
      _this._addError$2(error, stackTrace);
    },
    addError$1: function(error) {
      return this.addError$2(error, null);
    },
    _addError$2: function(error, stackTrace) {
      var _this = this;
      type$.StackTrace._check(stackTrace);
      if (_this._allowErrors) {
        _this._inner._async$_target.addError$2(error, stackTrace);
        return;
      }
      _this._doneCompleter.completeError$2(error, stackTrace);
      _this._onStreamDisconnected$0();
      _this._channel._onSinkDisconnected$0();
      _this._inner._async$_target.close$0(0).catchError$1(new K._GuaranteeSink__addError_closure());
    },
    _addError$1: function(error) {
      return this._addError$2(error, null);
    },
    addStream$1: function(stream) {
      var t1, t2, _this = this;
      _this.$ti._eval$1("Stream<1>")._check(stream);
      if (_this._closed)
        throw H.wrapException(P.StateError$("Cannot add stream after closing."));
      if (_this._addStreamSubscription != null)
        throw H.wrapException(P.StateError$("Cannot add stream while adding stream."));
      if (_this._disconnected) {
        t1 = new P._Future($.Zone__current, type$._Future_void);
        t1._asyncComplete$1(null);
        return t1;
      }
      t1 = new P._SyncCompleter(new P._Future($.Zone__current, type$._Future_dynamic), type$._SyncCompleter_dynamic);
      _this._addStreamCompleter = t1;
      t2 = _this._inner;
      _this.set$_addStreamSubscription(stream.listen$3$onDone$onError(t2.get$add(t2), t1.get$complete(), _this.get$_addError()));
      return _this._addStreamCompleter.future.then$1$1(new K._GuaranteeSink_addStream_closure(_this), type$.void);
    },
    close$0: function(_) {
      var _this = this;
      if (_this._addStreamSubscription != null)
        throw H.wrapException(P.StateError$("Cannot close sink while adding stream."));
      if (_this._closed)
        return _this._doneCompleter.future;
      _this._closed = true;
      if (!_this._disconnected) {
        _this._channel._onSinkDisconnected$0();
        _this._doneCompleter.complete$1(_this._inner._async$_target.close$0(0));
      }
      return _this._doneCompleter.future;
    },
    _onStreamDisconnected$0: function() {
      var t1, _this = this;
      _this._disconnected = true;
      t1 = _this._doneCompleter;
      if (t1.future._state === 0)
        t1.complete$0();
      t1 = _this._addStreamSubscription;
      if (t1 == null)
        return;
      _this._addStreamCompleter.complete$1(t1.cancel$0());
      _this._addStreamCompleter = null;
      _this.set$_addStreamSubscription(null);
    },
    set$_addStreamSubscription: function(_addStreamSubscription) {
      this._addStreamSubscription = this.$ti._eval$1("StreamSubscription<1>")._check(_addStreamSubscription);
    },
    $isEventSink: 1,
    $isStreamConsumer: 1,
    $isStreamSink: 1,
    $isSink: 1
  };
  K._GuaranteeSink__addError_closure.prototype = {
    call$1: function(_) {
    },
    $signature: 3
  };
  K._GuaranteeSink_addStream_closure.prototype = {
    call$1: function(_) {
      var t1 = this.$this;
      t1._addStreamCompleter = null;
      t1.set$_addStreamSubscription(null);
    },
    $signature: 3
  };
  D._MultiChannel.prototype = {
    _MultiChannel$1: function(_inner, $T) {
      var t2, _this = this,
        t1 = _this._mainController;
      _this._controllers.$indexSet(0, 0, t1);
      t2 = t1._local._streamController;
      t2.toString;
      new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).listen$2$onDone(new D._MultiChannel_closure(_this, $T), new D._MultiChannel_closure0(_this));
      t2 = _this._multi_channel$_inner._streamController;
      t2.toString;
      _this._innerStreamSubscription = new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).listen$3$onDone$onError(new D._MultiChannel_closure1(_this, $T), _this.get$_closeInnerChannel(), t1._local._sink.get$addError());
    },
    virtualChannel$1: function(id) {
      var t2, t3, controller, _this = this, t1 = {};
      t1.outputId = t1.inputId = null;
      if (id != null) {
        t1.inputId = id;
        t1.outputId = id + 1;
        t2 = id;
      } else {
        t2 = _this._nextId;
        t3 = t1.inputId = t2 + 1;
        t1.outputId = t2;
        _this._nextId = t2 + 2;
        t2 = t3;
      }
      if (_this._multi_channel$_inner == null) {
        t1 = _this.$ti;
        t3 = new P._Future($.Zone__current, type$._Future_dynamic);
        t3._asyncComplete$1(null);
        return new D.VirtualChannel(_this, t2, new P._EmptyStream(t1._eval$1("_EmptyStream<1>")), new S.NullStreamSink(t3, t1._eval$1("NullStreamSink<1>")), t1._eval$1("VirtualChannel<1>"));
      }
      if (_this._pendingIds.remove$1(0, t2))
        controller = _this._controllers.$index(0, t2);
      else {
        t3 = _this._controllers;
        if (t3.containsKey$1(t2) || _this._closedIds.contains$1(0, t2))
          throw H.wrapException(P.ArgumentError$("A virtual channel with id " + H.S(id) + " already exists."));
        else {
          controller = B.StreamChannelController$(true, true, _this.$ti._precomputed1);
          t3.$indexSet(0, t2, controller);
        }
      }
      t2 = controller._local._streamController;
      t2.toString;
      new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).listen$2$onDone(new D._MultiChannel_virtualChannel_closure(t1, _this), new D._MultiChannel_virtualChannel_closure0(t1, _this));
      t1 = t1.outputId;
      t2 = controller._foreign;
      t3 = t2._streamController;
      t3.toString;
      return new D.VirtualChannel(_this, t1, new P._ControllerStream(t3, H._instanceType(t3)._eval$1("_ControllerStream<1>")), t2._sink, _this.$ti._eval$1("VirtualChannel<1>"));
    },
    virtualChannel$0: function() {
      return this.virtualChannel$1(null);
    },
    _closeChannel$2: function(inputId, outputId) {
      var t1, t2, _this = this;
      _this._closedIds.add$1(0, inputId);
      t1 = _this._controllers;
      t1.remove$1(0, inputId)._local._sink.close$0(0);
      t2 = _this._multi_channel$_inner;
      if (t2 == null)
        return;
      t2._sink.add$1(0, H.setRuntimeTypeInfo([outputId], type$.JSArray_int));
      if (t1.get$isEmpty(t1))
        _this._closeInnerChannel$0();
    },
    _closeInnerChannel$0: function() {
      var t1, t2, t3, _i, _this = this;
      _this._multi_channel$_inner._sink.close$0(0);
      _this._innerStreamSubscription.cancel$0();
      _this._multi_channel$_inner = null;
      for (t1 = _this._controllers, t2 = P.List_List$from(t1.get$values(), true, type$.dynamic), t3 = t2.length, _i = 0; _i < t2.length; t2.length === t3 || (0, H.throwConcurrentModificationError)(t2), ++_i)
        t2[_i].get$local()._sink.close$0(0);
      t1.clear$0(0);
    },
    $isMultiChannel: 1
  };
  D._MultiChannel_closure.prototype = {
    call$1: function(message) {
      this.T._check(message);
      return this.$this._multi_channel$_inner._sink.add$1(0, [0, message]);
    },
    $signature: function() {
      return this.T._eval$1("~(0)");
    }
  };
  D._MultiChannel_closure0.prototype = {
    call$0: function() {
      return this.$this._closeChannel$2(0, 0);
    },
    $signature: 1
  };
  D._MultiChannel_closure1.prototype = {
    call$1: function(message) {
      var t3, controller,
        t1 = J.getInterceptor$asx(message),
        id = t1.$index(message, 0),
        t2 = this.$this;
      if (t2._closedIds.contains$1(0, id))
        return;
      H._checkIntNullable(id);
      t3 = this.T;
      controller = t2._controllers.putIfAbsent$2(id, new D._MultiChannel__closure(t2, id, t3));
      t2 = t1.get$length(message);
      if (typeof t2 !== "number")
        return t2.$gt();
      if (t2 > 1)
        controller._local._sink.add$1(0, t3._check(t1.$index(message, 1)));
      else
        controller._local._sink.close$0(0);
    },
    $signature: 3
  };
  D._MultiChannel__closure.prototype = {
    call$0: function() {
      this.$this._pendingIds.add$1(0, H._checkIntNullable(this.id));
      return B.StreamChannelController$(true, true, this.T);
    },
    $signature: function() {
      return this.T._eval$1("StreamChannelController<0>()");
    }
  };
  D._MultiChannel_virtualChannel_closure.prototype = {
    call$1: function(message) {
      var t1 = this.$this;
      t1.$ti._precomputed1._check(message);
      return t1._multi_channel$_inner._sink.add$1(0, [this._box_0.outputId, message]);
    },
    $signature: function() {
      return this.$this.$ti._eval$1("~(1)");
    }
  };
  D._MultiChannel_virtualChannel_closure0.prototype = {
    call$0: function() {
      var t1 = this._box_0;
      return this.$this._closeChannel$2(t1.inputId, t1.outputId);
    },
    $signature: 1
  };
  D.VirtualChannel.prototype = {$isMultiChannel: 1,
    get$stream: function(receiver) {
      return this.stream;
    }
  };
  N.StreamChannelCompleter.prototype = {
    set$_stream_channel_completer$_channel: function(_channel) {
      this._stream_channel_completer$_channel = this.$ti._eval$1("StreamChannel<1>")._check(_channel);
    }
  };
  B.StreamChannelController.prototype = {
    get$local: function() {
      return this._local;
    },
    set$_local: function(_local) {
      this._local = this.$ti._eval$1("StreamChannel<1>")._check(_local);
    },
    set$_foreign: function(_foreign) {
      this._foreign = this.$ti._eval$1("StreamChannel<1>")._check(_foreign);
    }
  };
  R.StreamChannel.prototype = {};
  R._StreamChannel.prototype = {
    get$stream: function(receiver) {
      return this.stream;
    }
  };
  R.StreamChannelMixin.prototype = {$isStreamChannel: 1};
  E.StringScannerException.prototype = {};
  S.SpanScanner.prototype = {
    spanFrom$1: function(startState) {
      var endPosition = this._string_scanner$_position;
      return this._sourceFile.span$2(startState.position, endPosition);
    },
    matches$1: function(_, pattern) {
      var _this = this;
      if (!_this.super$StringScanner$matches(0, pattern)) {
        _this._lastSpan = null;
        return false;
      }
      _this._lastSpan = _this._sourceFile.span$2(_this._string_scanner$_position, _this.get$lastMatch().get$end());
      return true;
    },
    error$3$length$position: function(_, message, $length, position) {
      var t1 = this.string;
      B.validateErrorArgs(t1, null, position, $length);
      throw H.wrapException(E.StringScannerException$(message, this._sourceFile.span$2(position, position + $length), t1));
    }
  };
  S._SpanScannerState.prototype = {$isLineScannerState: 1};
  X.StringScanner.prototype = {
    get$lastMatch: function() {
      var _this = this;
      if (_this._string_scanner$_position !== _this._lastMatchPosition)
        _this._lastMatch = null;
      return _this._lastMatch;
    },
    peekChar$0: function() {
      var index = this._string_scanner$_position;
      if (index < 0 || index >= this.string.length)
        return null;
      return J.codeUnitAt$1$s(this.string, index);
    },
    scan$1: function(pattern) {
      var _this = this,
        success = _this.matches$1(0, pattern);
      if (success)
        _this._lastMatchPosition = _this._string_scanner$_position = _this._lastMatch.get$end();
      return success;
    },
    expect$2$name: function(pattern, $name) {
      var t1;
      if (this.scan$1(pattern))
        return;
      if ($name == null)
        if (type$.RegExp._is(pattern))
          $name = "/" + pattern.pattern + "/";
        else {
          t1 = J.toString$0$(pattern);
          t1 = H.stringReplaceAllUnchecked(t1, "\\", "\\\\");
          $name = '"' + H.stringReplaceAllUnchecked(t1, '"', '\\"') + '"';
        }
      this.error$3$length$position(0, "expected " + $name + ".", 0, this._string_scanner$_position);
    },
    expect$1: function(pattern) {
      return this.expect$2$name(pattern, null);
    },
    matches$1: function(_, pattern) {
      var _this = this,
        t1 = J.matchAsPrefix$2$s(pattern, _this.string, _this._string_scanner$_position);
      _this._lastMatch = t1;
      _this._lastMatchPosition = _this._string_scanner$_position;
      return t1 != null;
    }
  };
  A.AsciiGlyphSet.prototype = {
    glyphOrAscii$2: function(glyph, alternative) {
      return alternative;
    },
    get$horizontalLine: function() {
      return "-";
    },
    get$verticalLine: function() {
      return "|";
    },
    get$topLeftCorner: function() {
      return ",";
    },
    get$bottomLeftCorner: function() {
      return "'";
    },
    get$upEnd: function() {
      return "'";
    },
    get$downEnd: function() {
      return ",";
    }
  };
  K.UnicodeGlyphSet.prototype = {
    glyphOrAscii$2: function(glyph, alternative) {
      return glyph;
    },
    get$horizontalLine: function() {
      return "\u2500";
    },
    get$verticalLine: function() {
      return "\u2502";
    },
    get$topLeftCorner: function() {
      return "\u250c";
    },
    get$bottomLeftCorner: function() {
      return "\u2514";
    },
    get$upEnd: function() {
      return "\u2575";
    },
    get$downEnd: function() {
      return "\u2577";
    }
  };
  L.internalBootstrapBrowserTest_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, t1, serialized, formatter, manager, $async$temp1;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              manager = type$.SuiteChannelManager._as($.Zone__current.$index(0, $.$get$_currentKey()));
              if (manager == null)
                H.throwExpression(P.StateError$("suiteChannel() may only be called within a test worker."));
              t1 = manager.connectOut$1("test.browser.mapper");
              t1 = t1.get$stream(t1);
              $async$temp1 = type$.Map_dynamic_dynamic;
              $async$goto = 3;
              return P._asyncAwait(t1.get$first(t1), $async$call$0);
            case 3:
              // returning from await.
              serialized = $async$temp1._as($async$result);
              if (serialized == null) {
                // goto return
                $async$goto = 1;
                break;
              }
              t1 = E.JSStackTraceMapper_deserialize(serialized);
              formatter = type$.StackTraceFormatter._as($.Zone__current.$index(0, $.$get$_currentKey0()));
              if (formatter == null)
                H.throwExpression(P.StateError$("setStackTraceMapper() may only be called within a test worker."));
              formatter.configure$1$mapper(t1);
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  N.postMessageChannel_closure.prototype = {
    call$1: function(message) {
      var t1, t2;
      type$.MessageEvent._check(message);
      t1 = message.origin;
      t2 = window.location;
      return t1 === (t2 && C.Location_methods).get$origin(t2) && J.$eq$(new P._AcceptStructuredCloneDart2Js([], []).convertNativeToDart_AcceptStructuredClone$2$mustCopy(message.data, true), "port");
    },
    $signature: 69
  };
  N.postMessageChannel_closure0.prototype = {
    call$1: function(message) {
      var t2, t3, portSubscription,
        t1 = type$.MessageEvent,
        port = J.get$first$ax(t1._check(message).ports);
      port.toString;
      t2 = this.controller;
      t3 = type$.void_Function_MessageEvent._check(new N.postMessageChannel__closure(t2));
      type$.void_Function._check(null);
      portSubscription = W._EventStreamSubscription$(port, "message", t3, false, t1);
      t2 = t2._local._streamController;
      t2.toString;
      new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).listen$2$onDone(new N.postMessageChannel__closure0(port), new N.postMessageChannel__closure1(port, portSubscription));
    },
    $signature: 29
  };
  N.postMessageChannel__closure.prototype = {
    call$1: function(message) {
      type$.MessageEvent._check(message);
      this.controller._local._sink.add$1(0, new P._AcceptStructuredCloneDart2Js([], []).convertNativeToDart_AcceptStructuredClone$2$mustCopy(message.data, true));
    },
    $signature: 29
  };
  N.postMessageChannel__closure0.prototype = {
    call$1: function(data) {
      C.MessagePort_methods.postMessage$1(this.port, P.LinkedHashMap_LinkedHashMap$_literal(["data", data], type$.String, type$.dynamic));
    },
    $signature: 3
  };
  N.postMessageChannel__closure1.prototype = {
    call$0: function() {
      var t1 = type$.String;
      C.MessagePort_methods.postMessage$1(this.port, P.LinkedHashMap_LinkedHashMap$_literal(["event", "done"], t1, t1));
      this.portSubscription.cancel$0();
    },
    $signature: 0
  };
  K.ClosedException.prototype = {
    toString$0: function(_) {
      return "This test has been closed.";
    },
    $isException: 1
  };
  X.Declarer.prototype = {
    test$9$onPlatform$retry$skip$solo$tags$testOn$timeout: function($name, body, onPlatform, retry, skip, solo, tags, testOn, timeout) {
      var newMetadata, metadata, t1, t2, _this = this;
      type$.dynamic_Function._check(body);
      type$.Map_String_dynamic._check(onPlatform);
      _this._checkNotBuilt$1("test");
      newMetadata = O.Metadata$parse(onPlatform, H.boolConversionCheck(_this._noRetry) ? 0 : retry, skip, tags, testOn, timeout);
      newMetadata.validatePlatformSelectors$1(_this._platformVariables);
      metadata = _this._metadata.merge$1(newMetadata);
      t1 = _this._declarer$_name;
      t1 = t1 == null ? $name : t1 + " " + $name;
      t2 = H.boolConversionCheck(_this._collectTraces) ? Y.Trace_Trace$current(2) : null;
      C.JSArray_methods.add$1(_this._entries, new U.LocalTest(t1, metadata, t2, false, new X.Declarer_test_closure(_this, body), false));
    },
    group$9$onPlatform$retry$skip$solo$tags$testOn$timeout: function($name, body, onPlatform, retry, skip, solo, tags, testOn, timeout) {
      var t2, newMetadata, t3, metadata, t4, trace, t5, t6, t7, t8, t9, t10, t11, t12, declarer, _this = this, _null = null,
        t1 = type$.void_Function;
      t1._check(body);
      type$.Map_String_dynamic._check(onPlatform);
      _this._checkNotBuilt$1("group");
      t2 = H.boolConversionCheck(_this._noRetry);
      newMetadata = O.Metadata$parse(onPlatform, t2 ? 0 : retry, skip, tags, testOn, timeout);
      t3 = _this._platformVariables;
      newMetadata.validatePlatformSelectors$1(t3);
      metadata = _this._metadata.merge$1(newMetadata);
      t4 = H.boolConversionCheck(_this._collectTraces);
      trace = t4 ? Y.Trace_Trace$current(2) : _null;
      t5 = _this._declarer$_name;
      t5 = t5 == null ? $name : t5 + " " + $name;
      t6 = type$.JSArray_of_dynamic_Function;
      t7 = H.setRuntimeTypeInfo([], t6);
      t8 = H.setRuntimeTypeInfo([], t6);
      t9 = H.setRuntimeTypeInfo([], t6);
      t10 = P.Duration$(0, 12);
      t6 = H.setRuntimeTypeInfo([], t6);
      t11 = type$.JSArray_GroupEntry;
      t12 = H.setRuntimeTypeInfo([], t11);
      t11 = H.setRuntimeTypeInfo([], t11);
      declarer = new X.Declarer(_this, t5, metadata, t3, trace, t4, t2, t7, t8, t9, new R.Timeout(t10, _null), t6, t12, t11);
      t12 = type$.dynamic;
      P.runZoned(t1._check(new X.Declarer_group_closure(body)), _null, _null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, declarer], t12, t12), type$.void);
      t12 = _this._entries;
      C.JSArray_methods.add$1(t12, declarer.build$0());
      t1 = t11.length;
      if (t1 !== 0)
        C.JSArray_methods.add$1(_this._soloEntries, C.JSArray_methods.get$last(t12));
    },
    build$0: function() {
      var t1, t2, _this = this;
      _this._checkNotBuilt$1("build");
      _this._built = true;
      t1 = _this._entries;
      t2 = H._arrayInstanceType(t1);
      return O.Group$(_this._declarer$_name, new H.MappedListIterable(t1, t2._eval$1("GroupEntry(1)")._check(new X.Declarer_build_closure(_this)), t2._eval$1("MappedListIterable<1,GroupEntry>")).toList$0(0), _this._metadata, _this.get$_setUpAll(), _this.get$_tearDownAll(), _this._declarer$_trace);
    },
    _checkNotBuilt$1: function($name) {
      if (!this._built)
        return;
      throw H.wrapException(P.StateError$("Can't call " + $name + "() once tests have begun running."));
    },
    _runSetUps$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic),
        $async$self = this, t1;
      var $async$_runSetUps$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self._declarer$_parent;
              $async$goto = t1 != null ? 2 : 3;
              break;
            case 2:
              // then
              $async$goto = 4;
              return P._asyncAwait(t1._runSetUps$0(), $async$_runSetUps$0);
            case 4:
              // returning from await.
            case 3:
              // join
              $async$goto = 5;
              return P._asyncAwait(P.Future_forEach($async$self._setUps, new X.Declarer__runSetUps_closure(), type$.dynamic_Function), $async$_runSetUps$0);
            case 5:
              // returning from await.
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$_runSetUps$0, $async$completer);
    },
    get$_setUpAll: function() {
      return null;
    },
    get$_tearDownAll: function() {
      var _this = this,
        t1 = _this._tearDownAlls.length;
      if (t1 === 0)
        return null;
      t1 = _this._declarer$_name;
      t1 = t1 == null ? "(tearDownAll)" : t1 + " (tearDownAll)";
      return new U.LocalTest(t1, _this._metadata.change$1$timeout(_this._timeout), null, true, new X.Declarer__tearDownAll_closure(_this), false);
    }
  };
  X.Declarer_test_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, $async$self = this, declarer, declarer0, t1, t2, t3, t4, t5, _i, tearDown, t6, parents;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          $async$outer:
            switch ($async$goto) {
              case 0:
                // Function start
                parents = H.setRuntimeTypeInfo([], type$.JSArray_Declarer);
                for (declarer = $async$self.$this, declarer0 = declarer; declarer0 != null; declarer0 = declarer0._declarer$_parent)
                  C.JSArray_methods.add$1(parents, declarer0);
                for (t1 = type$.ReversedListIterable_Declarer, t2 = new H.ReversedListIterable(parents, t1), t1 = new H.ListIterator(t2, t2.get$length(t2), t1._eval$1("ListIterator<ListIterable.E>")), t2 = type$.Invoker, t3 = type$.dynamic_Function, t4 = type$.Declarer; t1.moveNext$0();)
                  for (t5 = t1.__internal$_current._tearDowns, _i = 0; false; ++_i) {
                    if (_i >= 0) {
                      $async$returnValue = H.ioore(t5, _i);
                      // goto return
                      $async$goto = 1;
                      break $async$outer;
                    }
                    tearDown = t5[_i];
                    t6 = t2._as($.Zone__current.$index(0, C.Symbol_cQL));
                    t6.toString;
                    t3._check(tearDown);
                    if (H.boolConversionCheck(H._asBoolNullable($.Zone__current.$index(0, t6._closableKey))) && t6._onCloseCompleter.future._state !== 0)
                      H.throwExpression(K.ClosedException$());
                    if (t6._invoker$_controller._liveTest._live_test_controller$_controller._test.isScaffoldAll)
                      C.JSArray_methods.add$1(t4._as($.Zone__current.$index(0, C.Symbol_Drw))._tearDownAlls, tearDown);
                    else
                      C.JSArray_methods.add$1(t6._invoker$_tearDowns, tearDown);
                  }
                t1 = type$.dynamic;
                $async$goto = 3;
                return P._asyncAwait(P.runZoned(new X.Declarer_test__closure(declarer, $async$self.body), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, declarer], t1, t1), type$.Future_void), $async$call$0);
              case 3:
                // returning from await.
              case 1:
                // return
                return P._asyncReturn($async$returnValue, $async$completer);
            }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  X.Declarer_test__closure.prototype = {
    call$0: function() {
      return type$.Invoker._as($.Zone__current.$index(0, C.Symbol_cQL)).waitForOutstandingCallbacks$1(new X.Declarer_test___closure(this.$this, this.body));
    },
    $signature: 13
  };
  X.Declarer_test___closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$self = this;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              $async$goto = 2;
              return P._asyncAwait($async$self.$this._runSetUps$0(), $async$call$0);
            case 2:
              // returning from await.
              $async$goto = 3;
              return P._asyncAwait($async$self.body.call$0(), $async$call$0);
            case 3:
              // returning from await.
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  X.Declarer_group_closure.prototype = {
    call$0: function() {
      if (!type$.Future_dynamic._is(this.body.call$0()))
        return;
      throw H.wrapException(P.ArgumentError$("Groups may not be async."));
    },
    $signature: 0
  };
  X.Declarer_build_closure.prototype = {
    call$1: function(entry) {
      var t1;
      type$.GroupEntry._check(entry);
      t1 = this.$this._soloEntries;
      return t1.length !== 0 && !C.JSArray_methods.contains$1(t1, entry) ? new U.LocalTest(entry.get$name(entry), entry.get$metadata().change$2$skip$skipReason(true, 'does not have "solo"'), null, false, null, true) : entry;
    },
    $signature: 22
  };
  X.Declarer__runSetUps_closure.prototype = {
    call$1: function(setUp) {
      return setUp.call$0();
    },
    $signature: 18
  };
  X.Declarer__tearDownAll_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = type$.dynamic;
      return P.runZoned(new X.Declarer__tearDownAll__closure(t1), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, t1], t2, t2), type$.Future_Null);
    },
    $signature: 2
  };
  X.Declarer__tearDownAll__closure.prototype = {
    call$0: function() {
      return type$.Invoker._as($.Zone__current.$index(0, C.Symbol_cQL)).unclosable$1$1(new X.Declarer__tearDownAll___closure(this.$this), type$.Future_Null);
    },
    $signature: 2
  };
  X.Declarer__tearDownAll___closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, $async$self = this, t1, t2;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self.$this._tearDownAlls;
            case 3:
              // for condition
              if (!(t2 = t1.length, t2 !== 0)) {
                // goto after for
                $async$goto = 4;
                break;
              }
              if (0 >= t2) {
                $async$returnValue = H.ioore(t1, -1);
                // goto return
                $async$goto = 1;
                break;
              }
              $async$goto = 5;
              return P._asyncAwait(V.errorsDontStopTest(t1.pop()), $async$call$0);
            case 5:
              // returning from await.
              // goto for condition
              $async$goto = 3;
              break;
            case 4:
              // after for
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  O.Group.prototype = {
    forPlatform$1: function(platform) {
      var newMetadata, filtered, _this = this,
        t1 = _this.metadata;
      if (!H.boolConversionCheck(t1.testOn.evaluate$1(platform)))
        return null;
      newMetadata = t1.forPlatform$1(platform);
      filtered = _this._group$_map$1(new O.Group_forPlatform_closure(platform));
      if (filtered.length === 0 && _this.entries.length !== 0)
        return null;
      return O.Group$(_this.name, filtered, newMetadata, _this.setUpAll, _this.tearDownAll, _this.trace);
    },
    _group$_map$1: function(callback) {
      var t1 = this.entries,
        t2 = H._arrayInstanceType(t1),
        t3 = t2._eval$1("MappedListIterable<1,GroupEntry>");
      t3 = new H.MappedListIterable(t1, t2._eval$1("GroupEntry(1)")._check(new O.Group__map_closure(type$.GroupEntry_Function_GroupEntry._check(callback))), t3).super$Iterable$where(0, t3._eval$1("bool(ListIterable.E)")._check(new O.Group__map_closure0()));
      return P.List_List$from(t3, true, t3.$ti._eval$1("Iterable.E"));
    },
    $isGroupEntry: 1,
    get$name: function(receiver) {
      return this.name;
    },
    get$metadata: function() {
      return this.metadata;
    }
  };
  O.Group_forPlatform_closure.prototype = {
    call$1: function(entry) {
      return entry.forPlatform$1(this.platform);
    },
    $signature: 22
  };
  O.Group__map_closure.prototype = {
    call$1: function(entry) {
      return this.callback.call$1(type$.GroupEntry._check(entry));
    },
    $signature: 22
  };
  O.Group__map_closure0.prototype = {
    call$1: function(entry) {
      return type$.GroupEntry._check(entry) != null;
    },
    $signature: 72
  };
  V.GroupEntry.prototype = {};
  U.LocalTest.prototype = {
    load$2$groups: function(suite, groups) {
      var t1, invoker;
      type$.Iterable_Group._check(groups);
      t1 = new P._AsyncCompleter(new P._Future($.Zone__current, type$._Future_void), type$._AsyncCompleter_void);
      invoker = new U.Invoker(this._guarded, new P.Object(), t1, H.setRuntimeTypeInfo([], type$.JSArray_Zone), new P.Object(), H.setRuntimeTypeInfo([], type$.JSArray_of_dynamic_Function), H.setRuntimeTypeInfo([], type$.JSArray_String));
      t1 = V.LiveTestController$(suite, this, invoker.get$_invoker$_onRun(), t1.get$complete(), groups);
      invoker._invoker$_controller = t1;
      return t1._liveTest;
    },
    forPlatform$1: function(platform) {
      var _this = this,
        t1 = _this.metadata;
      if (!H.boolConversionCheck(t1.testOn.evaluate$1(platform)))
        return null;
      return new U.LocalTest(_this.name, t1.forPlatform$1(platform), _this.trace, _this.isScaffoldAll, _this._body, _this._guarded);
    },
    get$name: function(receiver) {
      return this.name;
    },
    get$metadata: function() {
      return this.metadata;
    }
  };
  U.Invoker.prototype = {
    get$_outstandingCallbacks: function() {
      var counter = type$._AsyncCounter._as($.Zone__current.$index(0, this._counterKey));
      if (counter != null)
        return counter;
      throw H.wrapException(P.StateError$("Can't add or remove outstanding callbacks outside of a test body."));
    },
    addOutstandingCallback$0: function() {
      if (H.boolConversionCheck(H._asBoolNullable($.Zone__current.$index(0, this._closableKey))) && this._onCloseCompleter.future._state !== 0)
        throw H.wrapException(K.ClosedException$());
      ++this.get$_outstandingCallbacks()._count;
    },
    waitForOutstandingCallbacks$1: function(fn) {
      var t2, counter, t3, _this = this, t1 = {};
      type$.FutureOr_void_Function._check(fn);
      _this.heartbeat$0();
      t1.zone = null;
      t2 = new P._Future($.Zone__current, type$._Future_void);
      counter = new U._AsyncCounter(new P._AsyncCompleter(t2, type$._AsyncCompleter_void));
      t3 = type$.dynamic;
      P.runZoned(new U.Invoker_waitForOutstandingCallbacks_closure(t1, _this, fn, counter), null, null, P.LinkedHashMap_LinkedHashMap$_literal([_this._counterKey, counter], t3, t3), type$.Future_Null);
      return t2.whenComplete$1(new U.Invoker_waitForOutstandingCallbacks_closure0(t1, _this));
    },
    unclosable$1$1: function(fn, $T) {
      var t1;
      $T._eval$1("0()")._check(fn);
      this.heartbeat$0();
      t1 = type$.dynamic;
      return P.runZoned(fn, null, null, P.LinkedHashMap_LinkedHashMap$_literal([this._closableKey, false], t1, t1), $T);
    },
    heartbeat$0: function() {
      var t1, timeout, _this = this;
      if (_this._invoker$_controller._liveTest._live_test_controller$_controller._live_test_controller$_state.status === C.Status_complete)
        return;
      t1 = _this._timeoutTimer;
      if (t1 != null)
        t1.cancel$0();
      timeout = _this._invoker$_controller._liveTest._live_test_controller$_controller._test.metadata.timeout.apply$1(C.Duration_30000000);
      if (timeout == null)
        return;
      _this._timeoutTimer = _this._invokerZone.createTimer$2(timeout, new U.Invoker_heartbeat_closure(_this, new U.Invoker_heartbeat_message(timeout), timeout));
    },
    _handleError$3: function(zone, error, stackTrace) {
      var t2, t3, t4, shouldBeDone, _this = this, t1 = {};
      t1.stackTrace = stackTrace;
      if (_this._runCount !== zone.$index(0, C.Symbol_runCount))
        return;
      zone.run$1$1(new U.Invoker__handleError_closure(t1), type$.Null);
      t2 = _this._invoker$_controller;
      t3 = t2._liveTest._live_test_controller$_controller._live_test_controller$_state;
      if (t3.status === C.Status_complete) {
        t4 = t3.result;
        shouldBeDone = t4 === C.Result_success || t4 === C.Result_skipped;
      } else
        shouldBeDone = false;
      if (!(error instanceof G.TestFailure))
        t2.setState$1(C.State_Status_complete_Result_error);
      else if (t3.result !== C.Result_error)
        t2.setState$1(C.State_Status_complete_Result_failure);
      _this._invoker$_controller.addError$2(error, t1.stackTrace);
      zone.run$1$1(new U.Invoker__handleError_closure0(_this), type$.void);
      t2 = _this._invoker$_controller._liveTest._live_test_controller$_controller;
      if (t2._test.metadata._chainStackTraces === false)
        C.JSArray_methods.add$1(_this._printsOnFailure, "Consider enabling the flag chain-stack-traces to receive more detailed exceptions.\nFor example, 'pub run test --chain-stack-traces'.");
      t2 = _this._printsOnFailure;
      if (t2.length !== 0) {
        P.print(C.JSArray_methods.join$1(t2, "\n\n"));
        C.JSArray_methods.set$length(t2, 0);
      }
      if (!shouldBeDone)
        return;
      _this._invoker$_controller._liveTest._live_test_controller$_controller._live_test_controller$_suite.toString;
      _this._handleError$3(zone, "This test failed after it had already completed. Make sure to use [expectAsync]\nor the [completes] matcher when testing async code.", t1.stackTrace);
    },
    _handleError$2: function(zone, error) {
      return this._handleError$3(zone, error, null);
    },
    _invoker$_onRun$0: function() {
      var t1, t2, _this = this;
      _this._invoker$_controller.setState$1(C.State_Status_running_Result_success);
      t1 = $.Zone__current;
      ++_this._runCount;
      t2 = _this._invoker$_controller._liveTest._live_test_controller$_controller;
      U.Chain_capture(new U.Invoker__onRun_closure(_this, new U._AsyncCounter(new P._AsyncCompleter(new P._Future(t1, type$._Future_void), type$._AsyncCompleter_void))), false, t2._test.metadata._chainStackTraces !== false, type$.Null);
    },
    _runTearDowns$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.void),
        $async$returnValue, $async$self = this, t1, t2;
      var $async$_runTearDowns$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self._invoker$_tearDowns;
            case 3:
              // for condition
              if (!(t2 = t1.length, t2 !== 0)) {
                // goto after for
                $async$goto = 4;
                break;
              }
              if (0 >= t2) {
                $async$returnValue = H.ioore(t1, -1);
                // goto return
                $async$goto = 1;
                break;
              }
              $async$goto = 5;
              return P._asyncAwait(V.errorsDontStopTest(t1.pop()), $async$_runTearDowns$0);
            case 5:
              // returning from await.
              // goto for condition
              $async$goto = 3;
              break;
            case 4:
              // after for
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$_runTearDowns$0, $async$completer);
    }
  };
  U.Invoker_guard_closure.prototype = {
    call$5: function($self, _, zone, error, stackTrace) {
      var invoker;
      type$.StackTrace._check(stackTrace);
      invoker = zone.$index(0, C.Symbol_cQL);
      if (invoker != null)
        $self.get$parent($self).run$1$1(new U.Invoker_guard__closure(invoker, zone, error, stackTrace), type$.dynamic);
      else
        $self.get$parent($self).handleUncaughtError$2(error, stackTrace);
    },
    $signature: 28
  };
  U.Invoker_guard__closure.prototype = {
    call$0: function() {
      var _this = this;
      return _this.invoker._handleError$3(_this.zone, _this.error, _this.stackTrace);
    },
    $signature: 34
  };
  U.Invoker_waitForOutstandingCallbacks_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$self = this, zone;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              zone = $.Zone__current;
              $async$self._box_0.zone = zone;
              C.JSArray_methods.add$1($async$self.$this._outstandingCallbackZones, zone);
              $async$goto = 2;
              return P._asyncAwait($async$self.fn.call$0(), $async$call$0);
            case 2:
              // returning from await.
              $async$self.counter.decrement$0();
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  U.Invoker_waitForOutstandingCallbacks_closure0.prototype = {
    call$0: function() {
      C.JSArray_methods.remove$1(this.$this._outstandingCallbackZones, this._box_0.zone);
    },
    $signature: 0
  };
  U.Invoker_heartbeat_message.prototype = {
    call$0: function() {
      var message,
        t1 = this.timeout._duration,
        minutes = C.JSInt_methods._tdivFast$1(t1, 60000000),
        seconds = C.JSInt_methods.$mod(C.JSInt_methods._tdivFast$1(t1, 1000000), 60),
        decaseconds = C.JSInt_methods._tdivFast$1(C.JSInt_methods.$mod(C.JSInt_methods._tdivFast$1(t1, 1000), 1000), 100),
        t2 = minutes !== 0,
        t3 = t2 ? "" + minutes + " minutes" : "";
      if (!t2 || seconds !== 0) {
        t2 = t2 ? t3 + ", " : t3;
        t2 += seconds;
        t2 = (decaseconds !== 0 ? t2 + ("." + decaseconds) : t2) + " seconds";
      } else
        t2 = t3;
      message = "Test timed out after " + (t2.charCodeAt(0) == 0 ? t2 : t2) + ".";
      return t1 === 30000000 ? message + " See https://pub.dev/packages/test#timeouts" : message;
    },
    $signature: 74
  };
  U.Invoker_heartbeat_closure.prototype = {
    call$0: function() {
      var t1 = this.$this;
      C.JSArray_methods.get$last(t1._outstandingCallbackZones).run$1$1(new U.Invoker_heartbeat__closure(t1, this.message, this.timeout), type$.Null);
    },
    $signature: 0
  };
  U.Invoker_heartbeat__closure.prototype = {
    call$0: function() {
      var t1 = this.$this;
      if (t1._invoker$_controller._liveTest._live_test_controller$_controller._live_test_controller$_state.status === C.Status_complete)
        return;
      t1._handleError$2($.Zone__current, new P.TimeoutException(this.message.call$0(), this.timeout));
    },
    $signature: 0
  };
  U.Invoker__handleError_closure.prototype = {
    call$0: function() {
      var t1 = this._box_0,
        t2 = t1.stackTrace;
      if (t2 == null)
        t1.stackTrace = U.Chain_Chain$current();
      else
        t1.stackTrace = U.Chain_Chain$forTrace(t2);
    },
    $signature: 0
  };
  U.Invoker__handleError_closure0.prototype = {
    call$0: function() {
      var t1 = this.$this.get$_outstandingCallbacks()._invoker$_completer;
      if (t1.future._state === 0)
        t1.complete$0();
      return null;
    },
    $signature: 1
  };
  U.Invoker__onRun_closure.prototype = {
    call$0: function() {
      var t1 = this.$this,
        t2 = type$.void_Function._check(new U.Invoker__onRun__closure(t1, this.outstandingCallbacksForBody));
      if (t1._guarded)
        U.Invoker_guard(t2, type$.void);
      else
        t2.call$0();
    },
    $signature: 0
  };
  U.Invoker__onRun__closure.prototype = {
    call$0: function() {
      var _null = null,
        t1 = this.$this,
        t2 = type$.dynamic;
      t2 = P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_cQL, t1, t1._counterKey, this.outstandingCallbacksForBody, t1._closableKey, true, C.Symbol_runCount, t1._runCount], t2, t2);
      P.runZoned(new U.Invoker__onRun___closure(t1), _null, P._ZoneSpecification$(_null, _null, _null, _null, _null, new U.Invoker__onRun___closure0(t1), _null, _null, _null, _null, _null, _null, _null), t2, type$.Future_Null);
    },
    $signature: 0
  };
  U.Invoker__onRun___closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, $async$self = this, t3, t4, t5, t6, t1, t2;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self.$this;
              t2 = $.Zone__current;
              t1._invokerZone = t2;
              C.JSArray_methods.add$1(t1._outstandingCallbackZones, t2);
              P.Future_Future(new U.Invoker__onRun____closure(t1), type$.void);
              $async$goto = 3;
              return P._asyncAwait(t1.get$_outstandingCallbacks()._invoker$_completer.future, $async$call$0);
            case 3:
              // returning from await.
              t2 = t1._timeoutTimer;
              if (t2 != null)
                t2.cancel$0();
              t2 = t1._invoker$_controller;
              t3 = t2._liveTest._live_test_controller$_controller;
              t4 = t3._live_test_controller$_state.result;
              if (t4 !== C.Result_success) {
                t5 = t1._runCount;
                t6 = t3._test.metadata._retry;
                t5 = t5 < (t6 == null ? 0 : t6) + 1;
              } else
                t5 = false;
              if (t5) {
                t2.message$1(0, new D.Message(C.MessageType_print, "Retry: " + H.S(t3._test.name)));
                t1._invoker$_onRun$0();
                // goto return
                $async$goto = 1;
                break;
              }
              t2.setState$1(new G.State(C.Status_complete, t4));
              t1._invoker$_controller.completer.complete$0();
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  U.Invoker__onRun____closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$self = this, t1;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self.$this;
              $async$goto = 2;
              return P._asyncAwait(t1._invoker$_controller._liveTest._live_test_controller$_controller._test._body.call$0(), $async$call$0);
            case 2:
              // returning from await.
              $async$goto = 3;
              return P._asyncAwait(t1.unclosable$1$1(t1.get$_runTearDowns(), type$.Future_void), $async$call$0);
            case 3:
              // returning from await.
              t1.heartbeat$0();
              t1.get$_outstandingCallbacks().decrement$0();
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  U.Invoker__onRun___closure0.prototype = {
    call$4: function(_, __, ___, line) {
      H._checkStringNullable(line);
      return this.$this._invoker$_controller.message$1(0, new D.Message(C.MessageType_print, line));
    },
    $signature: 37
  };
  U._AsyncCounter.prototype = {
    decrement$0: function() {
      if (--this._count !== 0)
        return;
      var t1 = this._invoker$_completer;
      if (t1.future._state !== 0)
        return;
      t1.complete$0();
    }
  };
  Z.LiveTest.prototype = {};
  V._LiveTest.prototype = {
    run$0: function() {
      var t1 = this._live_test_controller$_controller;
      if (t1._runCalled)
        H.throwExpression(P.StateError$("LiveTest.run() may not be called more than once."));
      else if ((t1._onErrorController._state & 4) !== 0)
        H.throwExpression(P.StateError$("LiveTest.run() may not be called for a closed test."));
      t1._runCalled = true;
      t1._onRun.call$0();
      return t1._liveTest._live_test_controller$_controller.completer.future;
    }
  };
  V.LiveTestController.prototype = {
    addError$2: function(error, stackTrace) {
      var asyncError,
        t1 = this._onErrorController;
      if ((t1._state & 4) !== 0)
        return;
      asyncError = new P.AsyncError(error, U.Chain_Chain$forTrace(stackTrace));
      C.JSArray_methods.add$1(this._errors, asyncError);
      t1.add$1(0, asyncError);
    },
    setState$1: function(newState) {
      var _this = this;
      if ((_this._onErrorController._state & 4) !== 0)
        return;
      if (_this._live_test_controller$_state.$eq(0, newState))
        return;
      _this._live_test_controller$_state = newState;
      _this._onStateChangeController.add$1(0, newState);
    },
    message$1: function(_, message) {
      var t1 = this._onMessageController;
      if (t1._firstSubscription != null)
        t1.add$1(0, message);
      else
        H.printString(message.text);
    },
    _live_test_controller$_run$0: function() {
      var _this = this;
      if (_this._runCalled)
        throw H.wrapException(P.StateError$("LiveTest.run() may not be called more than once."));
      else if ((_this._onErrorController._state & 4) !== 0)
        throw H.wrapException(P.StateError$("LiveTest.run() may not be called for a closed test."));
      _this._runCalled = true;
      _this._onRun.call$0();
      return _this._liveTest._live_test_controller$_controller.completer.future;
    },
    _live_test_controller$_close$0: function() {
      var _this = this,
        t1 = _this._onErrorController;
      if ((t1._state & 4) !== 0)
        return _this.completer.future;
      _this._onStateChangeController.close$0(0);
      t1.close$0(0);
      if (_this._runCalled)
        _this._onClose.call$0();
      else
        _this.completer.complete$0();
      return _this.completer.future;
    }
  };
  D.Message.prototype = {};
  D.MessageType.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  O.Metadata.prototype = {
    _validateTags$0: function() {
      var t1 = this.tags.where$1(0, new O.Metadata__validateTags_closure()),
        t2 = t1.$ti,
        t3 = t2._eval$1("MappedIterable<1,String>"),
        invalidTags = P.List_List$from(new H.MappedIterable(t1, t2._eval$1("String(1)")._check(new O.Metadata__validateTags_closure0()), t3), true, t3._eval$1("Iterable.E"));
      t1 = invalidTags.length;
      if (t1 === 0)
        return;
      throw H.wrapException(P.ArgumentError$("Invalid " + B.pluralize("tag", t1) + " " + H.S(B.toSentence(invalidTags)) + ". Tags must be (optionally hyphenated) Dart identifiers."));
    },
    validatePlatformSelectors$1: function(validVariables) {
      type$.Set_String._check(validVariables);
      this.testOn.validate$1(validVariables);
      this.onPlatform.forEach$1(0, new O.Metadata_validatePlatformSelectors_closure(validVariables));
    },
    merge$1: function(other) {
      var t4, t5, t6, t7, t8, t9, t10, _this = this,
        t1 = _this.testOn.intersection$1(other.testOn),
        t2 = _this.timeout.merge$1(other.timeout),
        t3 = other._skip;
      if (t3 == null)
        t3 = _this._skip;
      t4 = other.skipReason;
      if (t4 == null)
        t4 = _this.skipReason;
      t5 = other._verboseTrace;
      if (t5 == null)
        t5 = _this._verboseTrace;
      t6 = other._chainStackTraces;
      if (t6 == null)
        t6 = _this._chainStackTraces;
      t7 = other._retry;
      if (t7 == null)
        t7 = _this._retry;
      t8 = _this.tags.union$1(other.tags);
      t9 = type$.Metadata;
      t10 = Y.mergeMaps(_this.onPlatform, other.onPlatform, new O.Metadata_merge_closure(), type$.PlatformSelector, t9);
      return O.Metadata_Metadata(t6, Y.mergeMaps(_this.forTag, other.forTag, new O.Metadata_merge_closure0(), type$.BooleanSelector, t9), t10, t7, t3, t4, t8, t1, t2, t5);
    },
    change$4$onPlatform$skip$skipReason$timeout: function(onPlatform, skip, skipReason, timeout) {
      var _this = this;
      type$.Map_PlatformSelector_Metadata._check(onPlatform);
      type$.Set_String._check(null);
      type$.Map_BooleanSelector_Metadata._check(null);
      if (timeout == null)
        timeout = _this.timeout;
      if (skip == null)
        skip = _this._skip;
      if (skipReason == null)
        skipReason = _this.skipReason;
      if (onPlatform == null)
        onPlatform = _this.onPlatform;
      return O.Metadata_Metadata(_this._chainStackTraces, _this.forTag, onPlatform, _this._retry, skip, skipReason, _this.tags, _this.testOn, timeout, _this._verboseTrace);
    },
    change$1$onPlatform: function(onPlatform) {
      return this.change$4$onPlatform$skip$skipReason$timeout(onPlatform, null, null, null);
    },
    change$1$timeout: function(timeout) {
      return this.change$4$onPlatform$skip$skipReason$timeout(null, null, null, timeout);
    },
    change$2$skip$skipReason: function(skip, skipReason) {
      return this.change$4$onPlatform$skip$skipReason$timeout(null, skip, skipReason, null);
    },
    forPlatform$1: function(platform) {
      var t1 = {},
        t2 = this.onPlatform;
      if (t2.get$isEmpty(t2))
        return this;
      t1.metadata = this;
      t2.forEach$1(0, new O.Metadata_forPlatform_closure(t1, platform));
      return t1.metadata.change$1$onPlatform(P.LinkedHashMap_LinkedHashMap$_empty(type$.PlatformSelector, type$.Metadata));
    },
    serialize$0: function() {
      var t1, t2, t3, _this = this, serializedOnPlatform = [];
      _this.onPlatform.forEach$1(0, new O.Metadata_serialize_closure(serializedOnPlatform));
      t1 = _this.testOn._platform_selector$_inner;
      t2 = J.getInterceptor$(t1);
      t3 = t2.$eq(t1, C.C_All);
      t1 = t3 ? null : t2.toString$0(t1);
      t2 = type$.String;
      return P.LinkedHashMap_LinkedHashMap$_literal(["testOn", t1, "timeout", _this._serializeTimeout$1(_this.timeout), "skip", _this._skip, "skipReason", _this.skipReason, "verboseTrace", _this._verboseTrace, "chainStackTraces", _this._chainStackTraces, "retry", _this._retry, "tags", _this.tags.toList$0(0), "onPlatform", serializedOnPlatform, "forTag", _this.forTag.map$2$1(0, new O.Metadata_serialize_closure0(), t2, type$.Map_String_dynamic)], t2, type$.dynamic);
    },
    _serializeTimeout$1: function(timeout) {
      var t1;
      if (timeout.$eq(0, C.Timeout_null_null))
        return "none";
      t1 = timeout.duration;
      t1 = t1 == null ? null : t1._duration;
      return P.LinkedHashMap_LinkedHashMap$_literal(["duration", t1, "scaleFactor", timeout.scaleFactor], type$.String, type$.num);
    }
  };
  O.Metadata_Metadata__unresolved.prototype = {
    call$0: function() {
      var _this = this,
        t1 = _this._box_0,
        t2 = t1.tags;
      return O.Metadata$_(_this.chainStackTraces, t1.forTag, _this.onPlatform, _this.retry, _this.skip, _this.skipReason, t2, _this.testOn, _this.timeout, _this.verboseTrace);
    },
    $signature: 77
  };
  O.Metadata_Metadata_closure.prototype = {
    call$2: function(merged, selector) {
      var t1, t2;
      type$.Metadata._check(merged);
      type$.BooleanSelector._check(selector);
      t1 = this._box_0;
      t2 = t1.tags;
      if (!H.boolConversionCheck(selector.evaluate$1(t2.get$contains(t2))))
        return merged;
      return merged.merge$1(t1.forTag.remove$1(0, selector));
    },
    $signature: 78
  };
  O.Metadata$deserialize_closure.prototype = {
    call$2: function(key, nested) {
      return new P.MapEntry(new Y.BooleanSelectorImpl(new G.Parser(new O.Scanner(S.SpanScanner$(H._asStringNullable(key)))).parse$0()), O.Metadata$deserialize(nested), type$.MapEntry_BooleanSelector_Metadata);
    },
    $signature: 79
  };
  O.Metadata__validateTags_closure.prototype = {
    call$1: function(tag) {
      return !J.contains$1$asx(H._checkStringNullable(tag), $.$get$anchoredHyphenatedIdentifier());
    },
    $signature: 4
  };
  O.Metadata__validateTags_closure0.prototype = {
    call$1: function(tag) {
      return '"' + H.S(H._checkStringNullable(tag)) + '"';
    },
    $signature: 7
  };
  O.Metadata_validatePlatformSelectors_closure.prototype = {
    call$2: function(selector, metadata) {
      var t1;
      type$.PlatformSelector._check(selector);
      type$.Metadata._check(metadata);
      t1 = this.validVariables;
      selector.validate$1(t1);
      metadata.validatePlatformSelectors$1(t1);
    },
    $signature: 19
  };
  O.Metadata_merge_closure.prototype = {
    call$2: function(metadata1, metadata2) {
      var t1 = type$.Metadata;
      return t1._check(metadata1).merge$1(t1._check(metadata2));
    },
    $signature: 44
  };
  O.Metadata_merge_closure0.prototype = {
    call$2: function(metadata1, metadata2) {
      var t1 = type$.Metadata;
      return t1._check(metadata1).merge$1(t1._check(metadata2));
    },
    $signature: 44
  };
  O.Metadata_forPlatform_closure.prototype = {
    call$2: function(platformSelector, platformMetadata) {
      var t1;
      type$.PlatformSelector._check(platformSelector);
      type$.Metadata._check(platformMetadata);
      if (!H.boolConversionCheck(platformSelector.evaluate$1(this.platform)))
        return;
      t1 = this._box_0;
      t1.metadata = t1.metadata.merge$1(platformMetadata);
    },
    $signature: 19
  };
  O.Metadata_serialize_closure.prototype = {
    call$2: function(key, value) {
      type$.PlatformSelector._check(key);
      type$.Metadata._check(value);
      C.JSArray_methods.add$1(this.serializedOnPlatform, [J.toString$0$(key), value.serialize$0()]);
    },
    $signature: 19
  };
  O.Metadata_serialize_closure0.prototype = {
    call$2: function(selector, metadata) {
      type$.BooleanSelector._check(selector);
      type$.Metadata._check(metadata);
      return new P.MapEntry(J.toString$0$(selector), metadata.serialize$0(), type$.MapEntry_of_String_and_Map_String_dynamic);
    },
    $signature: 82
  };
  N.OperatingSystem.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  N.OperatingSystem_find_closure.prototype = {
    call$1: function(platform) {
      return type$.OperatingSystem._check(platform).identifier === this.identifier;
    },
    $signature: 83
  };
  N.OperatingSystem_find_closure0.prototype = {
    call$0: function() {
      return null;
    },
    $signature: 0
  };
  E.PlatformSelector.prototype = {
    validate$1: function(validVariables) {
      type$.Set_String._check(validVariables);
      if (this === C.PlatformSelector_All)
        return;
      E.PlatformSelector__wrapFormatException(new E.PlatformSelector_validate_closure(this, validVariables), null, type$.void);
    },
    evaluate$1: function(platform) {
      return this._platform_selector$_inner.evaluate$1(new E.PlatformSelector_evaluate_closure(platform));
    },
    intersection$1: function(other) {
      var t1 = other._platform_selector$_inner,
        t2 = J.$eq$(t1, C.C_All);
      if (t2)
        return this;
      return new E.PlatformSelector(this._platform_selector$_inner.intersection$1(t1));
    },
    toString$0: function(_) {
      return J.toString$0$(this._platform_selector$_inner);
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof E.PlatformSelector && J.$eq$(this._platform_selector$_inner, other._platform_selector$_inner);
    },
    get$hashCode: function(_) {
      return J.get$hashCode$(this._platform_selector$_inner);
    }
  };
  E.PlatformSelector$parse_closure.prototype = {
    call$0: function() {
      return new Y.BooleanSelectorImpl(new G.Parser(new O.Scanner(S.SpanScanner$(this.selector))).parse$0());
    },
    $signature: 84
  };
  E.PlatformSelector_validate_closure.prototype = {
    call$0: function() {
      return this.$this._platform_selector$_inner.validate$1(new E.PlatformSelector_validate__closure(this.validVariables));
    },
    $signature: 1
  };
  E.PlatformSelector_validate__closure.prototype = {
    call$1: function($name) {
      return $.$get$_universalValidVariables().contains$1(0, $name) || this.validVariables.contains$1(0, $name);
    },
    $signature: 4
  };
  E.PlatformSelector_evaluate_closure.prototype = {
    call$1: function(variable) {
      var t1, t2, t3;
      H._checkStringNullable(variable);
      t1 = this.platform;
      t2 = t1.runtime;
      if (variable == t2.identifier)
        return true;
      t3 = t2.parent;
      if (variable == (t3 == null ? null : t3.identifier))
        return true;
      t3 = t1.os;
      if (variable === t3.identifier)
        return true;
      switch (variable) {
        case "dart-vm":
          return t2.isDartVM;
        case "browser":
          return t2.isBrowser;
        case "js":
          return t2.isJS;
        case "blink":
          return t2.isBlink;
        case "posix":
          return t3 !== C.OperatingSystem_Windows_windows && t3 !== C.OperatingSystem_none_none;
        case "google":
          return t1.inGoogle;
        default:
          return false;
      }
    },
    $signature: 4
  };
  B.Runtime.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  B.Runtime_Runtime$deserialize_closure.prototype = {
    call$1: function(platform) {
      return type$.Runtime._check(platform).identifier === this.serialized;
    },
    $signature: 85
  };
  U.StackTraceFormatter.prototype = {
    configure$3$except$mapper$only: function(except, mapper, only) {
      var t1 = type$.Set_String;
      t1._check(except);
      t1._check(only);
      if (mapper != null)
        this._mapper = mapper;
      if (except != null)
        this.set$_except(except);
      if (only != null)
        this.set$_only(only);
    },
    configure$2$except$only: function(except, only) {
      return this.configure$3$except$mapper$only(except, null, only);
    },
    configure$1$mapper: function(mapper) {
      return this.configure$3$except$mapper$only(null, mapper, null);
    },
    formatStackTrace$2$verbose: function(stackTrace, verbose) {
      var t2, t3, chain,
        t1 = this._mapper;
      if (t1 == null)
        t1 = null;
      else {
        t2 = t1._mapping;
        if (t2 == null) {
          t2 = t1._mapContents;
          t3 = t1._mapUrl;
          t3 = t1._mapping = T.parseJsonExtended(C.C_JsonCodec.decode$2$reviver(t2, null), t3, null);
          t2 = t3;
        }
        t1 = O.mapStackTrace(t2, stackTrace, false, t1._packageResolver, t1._sdkRoot);
      }
      chain = U.Chain_Chain$forTrace(t1 == null ? stackTrace : t1);
      if (verbose)
        return chain;
      return chain.foldFrames$2$terse(new U.StackTraceFormatter_formatStackTrace_closure(this), true);
    },
    set$_except: function(_except) {
      this._except = type$.Set_String._check(_except);
    },
    set$_only: function(_only) {
      this._only = type$.Set_String._check(_only);
    }
  };
  U.StackTraceFormatter_formatStackTrace_closure.prototype = {
    call$1: function(frame) {
      var t1 = this.$this,
        t2 = t1._only;
      if (t2._collection$_length !== 0)
        return !t2.contains$1(0, frame.get$$package());
      return t1._except.contains$1(0, frame.get$$package());
    },
    $signature: 21
  };
  G.State.prototype = {
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof G.State && this.status === other.status && this.result === other.result;
    },
    get$hashCode: function(_) {
      return (H.Primitives_objectHashCode(this.status) ^ 7 * H.Primitives_objectHashCode(this.result)) >>> 0;
    },
    toString$0: function(_) {
      var t1 = this.status;
      if (t1 === C.Status_pending)
        return "pending";
      if (t1 === C.Status_complete)
        return this.result.name;
      t1 = this.result;
      if (t1 === C.Result_success)
        return "running";
      return "running with " + t1.toString$0(0);
    }
  };
  G.Status.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  G.Result0.prototype = {
    toString$0: function(_) {
      return this.name;
    }
  };
  U.Suite.prototype = {};
  E.SuitePlatform.prototype = {};
  V.Test.prototype = {$isGroupEntry: 1};
  G.TestFailure.prototype = {
    toString$0: function(_) {
      return this.message;
    },
    get$message: function(receiver) {
      return this.message;
    }
  };
  G._expect_closure0.prototype = {
    call$5: function(actual, matcher, reason, matchState, verbose) {
      var t1 = new P.StringBuffer("");
      matcher.describeMismatch$4(true, new E.StringDescription(t1), matchState, false);
      t1 = t1._contents;
      return G.formatFailure(matcher, true, t1.charCodeAt(0) == 0 ? t1 : t1, reason);
    },
    $signature: 86
  };
  G._expect_closure.prototype = {
    call$0: function() {
    },
    $signature: 0
  };
  R.Timeout.prototype = {
    merge$1: function(other) {
      var t1, t2;
      if (this.$eq(0, C.Timeout_null_null) || other.$eq(0, C.Timeout_null_null))
        return C.Timeout_null_null;
      t1 = other.duration;
      if (t1 != null)
        return new R.Timeout(t1, null);
      t1 = this.duration;
      if (t1 != null) {
        t2 = other.scaleFactor;
        t1 = t1._duration;
        if (typeof t2 !== "number")
          return H.iae(t2);
        return new R.Timeout(new P.Duration(C.JSNumber_methods.round$0(t1 * t2)), null);
      }
      t1 = this.scaleFactor;
      t2 = other.scaleFactor;
      if (typeof t1 !== "number")
        return t1.$mul();
      if (typeof t2 !== "number")
        return H.iae(t2);
      return new R.Timeout(null, t1 * t2);
    },
    apply$1: function(base) {
      var t1;
      if (this.$eq(0, C.Timeout_null_null))
        return null;
      t1 = this.duration;
      if (t1 == null) {
        t1 = this.scaleFactor;
        if (typeof t1 !== "number")
          return H.iae(t1);
        t1 = new P.Duration(C.JSNumber_methods.round$0(base._duration * t1));
      }
      return t1;
    },
    get$hashCode: function(_) {
      return (J.get$hashCode$(this.duration) ^ 5 * J.get$hashCode$(this.scaleFactor)) >>> 0;
    },
    $eq: function(_, other) {
      if (other == null)
        return false;
      return other instanceof R.Timeout && J.$eq$(other.duration, this.duration) && other.scaleFactor == this.scaleFactor;
    },
    toString$0: function(_) {
      var t1 = this.duration;
      if (t1 != null)
        return t1.toString$0(0);
      t1 = this.scaleFactor;
      if (t1 != null)
        return H.S(t1) + "x";
      return "none";
    }
  };
  S.RemoteListener.prototype = {
    _serializeGroup$3: function(channel, group, parents) {
      var t2, t3, t4, t5, t6, t1 = {};
      t1.parents = parents;
      type$.Iterable_Group._check(parents);
      parents = H.setRuntimeTypeInfo(parents.slice(0), H._arrayInstanceType(parents));
      C.JSArray_methods.add$1(parents, group);
      t1.parents = parents;
      t2 = group.metadata.serialize$0();
      t3 = group.trace;
      t3 = t3 == null ? null : J.toString$0$(t3.get$_lazy_trace$_trace());
      t4 = group.entries;
      t5 = H._arrayInstanceType(t4);
      t6 = type$.dynamic;
      return P.LinkedHashMap_LinkedHashMap$_literal(["type", "group", "name", group.name, "metadata", t2, "trace", t3, "setUpAll", this._serializeTest$3(channel, group.setUpAll, parents), "tearDownAll", this._serializeTest$3(channel, group.tearDownAll, parents), "entries", new H.MappedListIterable(t4, t5._eval$1("Map<@,@>(1)")._check(new S.RemoteListener__serializeGroup_closure(t1, this, channel)), t5._eval$1("MappedListIterable<1,Map<@,@>>")).toList$0(0)], t6, t6);
    },
    _serializeTest$3: function(channel, test, groups) {
      var testChannel, t1, t2, t3, t4;
      type$.Iterable_Group._check(groups);
      if (test == null)
        return null;
      testChannel = channel.virtualChannel$0();
      testChannel.stream.listen$1(new S.RemoteListener__serializeTest_closure(this, test, groups, channel));
      t1 = test.name;
      t2 = test.metadata.serialize$0();
      t3 = test.trace;
      t3 = t3 == null ? null : J.toString$0$(t3.get$_lazy_trace$_trace());
      t4 = type$.dynamic;
      return P.LinkedHashMap_LinkedHashMap$_literal(["type", "test", "name", t1, "metadata", t2, "trace", t3, "channel", testChannel.id], t4, t4);
    },
    _runLiveTest$2: function(liveTest, channel) {
      var t1, t2;
      channel.stream.listen$1(new S.RemoteListener__runLiveTest_closure(liveTest));
      t1 = liveTest._live_test_controller$_controller;
      t2 = t1._onStateChangeController;
      new P._BroadcastStream(t2, H._instanceType(t2)._eval$1("_BroadcastStream<1>")).listen$1(new S.RemoteListener__runLiveTest_closure0(channel));
      t2 = t1._onErrorController;
      new P._BroadcastStream(t2, H._instanceType(t2)._eval$1("_BroadcastStream<1>")).listen$1(new S.RemoteListener__runLiveTest_closure1(channel, liveTest));
      t1 = t1._onMessageController;
      new P._BroadcastStream(t1, H._instanceType(t1)._eval$1("_BroadcastStream<1>")).listen$1(new S.RemoteListener__runLiveTest_closure2(this, channel));
      t1 = type$.dynamic;
      P.runZoned(new S.RemoteListener__runLiveTest_closure3(liveTest, channel), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_MAi, channel], t1, t1), type$.Null);
    }
  };
  S.RemoteListener_start_closure.prototype = {
    call$4: function(_, __, ___, line) {
      var t1;
      H._checkStringNullable(line);
      t1 = this.printZone;
      if (t1 != null)
        t1.print$1(0, line);
      t1 = type$.String;
      this.channel._mainController._foreign._sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "print", "line", line], t1, t1));
    },
    $signature: 87
  };
  S.RemoteListener_start_closure0.prototype = {
    call$1: function(_) {
    },
    $signature: 3
  };
  S.RemoteListener_start_closure1.prototype = {
    call$0: function() {
      var _this = this,
        t1 = type$.String,
        t2 = P.LinkedHashSet_LinkedHashSet$_literal(["test", "stream_channel", "test_api"], t1),
        t3 = type$.dynamic;
      P.runZoned(type$.Null_Function._check(new S.RemoteListener_start__closure(_this._box_0, _this.getMain, _this.channel, _this.controller, _this.beforeLoad, _this.printZone, _this.spec)), null, null, P.LinkedHashMap_LinkedHashMap$_literal([$.$get$_currentKey0(), new U.StackTraceFormatter(t2, P.LinkedHashSet_LinkedHashSet$_empty(t1))], t3, t3), type$.Null);
    },
    $signature: 0
  };
  S.RemoteListener_start__closure.prototype = {
    call$0: function() {
      var _this = this,
        t1 = _this._box_0,
        t2 = _this.channel;
      P.runZoned(new S.RemoteListener_start___closure(t1, _this.getMain, t2, _this.controller, _this.beforeLoad, _this.printZone), new S.RemoteListener_start___closure0(t1, t2), _this.spec, null, type$.Future_Null);
    },
    $signature: 0
  };
  S.RemoteListener_start___closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, $async$next = [], $async$self = this, error, stackTrace, exception, t1, t2, queue, message, t3, metadata, declarer, t4, map, t5, t6, main;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              main = null;
              try {
                main = $async$self.getMain.call$0();
              } catch (exception) {
                t1 = H.unwrapException(exception);
                if (type$.NoSuchMethodError._is(t1)) {
                  S.RemoteListener__sendLoadException($async$self.channel, "No top-level main() function defined.");
                  // goto return
                  $async$goto = 1;
                  break;
                } else {
                  error = t1;
                  stackTrace = H.getTraceFromException(exception);
                  S.RemoteListener__sendError($async$self.channel, error, stackTrace, $async$self._box_0.verboseChain);
                  // goto return
                  $async$goto = 1;
                  break;
                }
              }
              if (!type$.Function._is(main)) {
                S.RemoteListener__sendLoadException($async$self.channel, "Top-level main getter is not a function.");
                // goto return
                $async$goto = 1;
                break;
              } else if (!type$.dynamic_Function._is(main)) {
                S.RemoteListener__sendLoadException($async$self.channel, "Top-level main() function takes arguments.");
                // goto return
                $async$goto = 1;
                break;
              }
              t1 = $async$self.channel;
              t2 = t1._mainController._foreign._streamController;
              t2.toString;
              queue = new G.StreamQueue(new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")), Q.QueueList$(type$.Result_dynamic), P.ListQueue$(type$._EventRequest_dynamic), type$.StreamQueue_dynamic);
              $async$goto = 3;
              return P._asyncAwait(queue.get$next(), $async$call$0);
            case 3:
              // returning from await.
              message = $async$result;
              t2 = J.getInterceptor$asx(message);
              H.assertHelper(J.$eq$(t2.$index(message, "type"), "initial"));
              if (queue._isClosed)
                H.throwExpression(queue._failClosed$0());
              t3 = new Y._CompleterStream(type$._CompleterStream_dynamic);
              queue._isClosed = true;
              queue._addRequest$1(new G._RestRequest(new Y.StreamCompleter(t3, type$.StreamCompleter_dynamic), queue, type$._RestRequest_dynamic));
              t3.listen$1(new S.RemoteListener_start____closure($async$self.controller, t1));
              t3 = H._asBoolNullable(t2.$index(message, "asciiGlyphs"));
              if (t3 === true)
                $._glyphs = C.C_AsciiGlyphSet;
              metadata = O.Metadata$deserialize(t2.$index(message, "metadata"));
              $async$self._box_0.verboseChain = metadata._verboseTrace === true;
              t3 = P.LinkedHashSet_LinkedHashSet$from(type$.Iterable_dynamic._as(t2.$index(message, "platformVariables")), type$.String);
              declarer = X.Declarer$(H._asBoolNullable(t2.$index(message, "collectTraces")), metadata, H._asBoolNullable(t2.$index(message, "noRetry")), t3);
              t3 = type$.List_dynamic;
              type$.StackTraceFormatter._as($.Zone__current.$index(0, $.$get$_currentKey0())).configure$2$except$only(S.RemoteListener__deserializeSet(t3._as(t2.$index(message, "foldTraceExcept"))), S.RemoteListener__deserializeSet(t3._as(t2.$index(message, "foldTraceOnly"))));
              $async$goto = 4;
              return P._asyncAwait($async$self.beforeLoad.call$0(), $async$call$0);
            case 4:
              // returning from await.
              t3 = type$.dynamic;
              $async$goto = 5;
              return P._asyncAwait(P.runZoned(type$.void_Function._check(main), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, declarer], t3, t3), type$.void), $async$call$0);
            case 5:
              // returning from await.
              t4 = declarer.build$0();
              map = type$.Map_dynamic_dynamic._as(t2.$index(message, "platform"));
              t5 = B.Runtime_Runtime$deserialize(map.$index(0, "runtime"));
              t6 = N.OperatingSystem_find(H._asStringNullable(map.$index(0, "os")));
              t6 = E.SuitePlatform$(t5, H._asBoolNullable(map.$index(0, "inGoogle")), t6);
              P.runZoned(new S.RemoteListener_start____closure0(new U.Suite(t6, H._asStringNullable(t2.$index(message, "path")), U.Suite__filterGroup(t4, t6)), $async$self.printZone, t1), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, declarer], t3, t3), type$.Null);
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  S.RemoteListener_start____closure.prototype = {
    call$1: function(message) {
      var t2, t3, t4,
        t1 = J.getInterceptor$asx(message);
      if (J.$eq$(t1.$index(message, "type"), "close")) {
        this.controller._local._sink.close$0(0);
        return;
      }
      H.assertHelper(J.$eq$(t1.$index(message, "type"), "suiteChannel"));
      t2 = type$.SuiteChannelManager._as($.Zone__current.$index(0, $.$get$_currentKey()));
      t3 = H._asStringNullable(t1.$index(message, "name"));
      t1 = this.channel.virtualChannel$1(H._asIntNullable(t1.$index(message, "id")));
      t4 = t2._outgoingConnections;
      if (t4.containsKey$1(t3)) {
        t2 = t4.remove$1(0, t3);
        t2.toString;
        H.instanceType(t2)._eval$1("StreamChannel<1>")._check(t1);
        if (t2._stream_channel_completer$_set)
          H.throwExpression(P.StateError$("The channel has already been set."));
        t2._stream_channel_completer$_set = true;
        t2._streamCompleter.setSourceStream$1(t1.stream);
        t2 = t2._sinkCompleter;
        t3 = t2.$ti;
        t1 = t3._eval$1("StreamSink<1>")._check(t1.sink);
        t2 = t3._eval$1("_CompleterSink<1>")._check(t2.sink);
        if (t2._destinationSink != null)
          H.throwExpression(P.StateError$("Destination sink already set"));
        t2._setDestinationSink$1(t1);
      } else {
        t2 = t2._incomingConnections;
        if (t2.containsKey$1(t3))
          H.throwExpression(P.StateError$('Duplicate RunnerSuite.channel() connection "' + H.S(t3) + '".'));
        else
          t2.$indexSet(0, t3, t1);
      }
    },
    $signature: 3
  };
  S.RemoteListener_start____closure0.prototype = {
    call$0: function() {
      U.Invoker_guard(new S.RemoteListener_start_____closure(this.suite, this.printZone, this.channel), type$.void);
    },
    $signature: 0
  };
  S.RemoteListener_start_____closure.prototype = {
    call$0: function() {
      var t1 = this.suite,
        t2 = this.channel;
      t2._mainController._foreign._sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "success", "root", new S.RemoteListener(t1, this.printZone)._serializeGroup$3(t2, t1.group, H.setRuntimeTypeInfo([], type$.JSArray_Group))], type$.String, type$.Object));
      return null;
    },
    $signature: 1
  };
  S.RemoteListener_start___closure0.prototype = {
    call$2: function(error, stackTrace) {
      S.RemoteListener__sendError(this.channel, error, type$.StackTrace._check(stackTrace), this._box_0.verboseChain);
    },
    $signature: 5
  };
  S.RemoteListener__serializeGroup_closure.prototype = {
    call$1: function(entry) {
      var t1, t2, t3;
      type$.GroupEntry._check(entry);
      t1 = this.$this;
      t2 = this.channel;
      t3 = this._box_0.parents;
      return entry instanceof O.Group ? t1._serializeGroup$3(t2, entry, t3) : t1._serializeTest$3(t2, type$.Test._as(entry), t3);
    },
    $signature: 88
  };
  S.RemoteListener__serializeTest_closure.prototype = {
    call$1: function(message) {
      var t2, _this = this,
        t1 = J.getInterceptor$asx(message);
      H.assertHelper(J.$eq$(t1.$index(message, "command"), "run"));
      t2 = _this.$this;
      t2._runLiveTest$2(_this.test.load$2$groups(t2._suite, _this.groups), _this.channel.virtualChannel$1(H._asIntNullable(t1.$index(message, "channel"))));
    },
    $signature: 3
  };
  S.RemoteListener__runLiveTest_closure.prototype = {
    call$1: function(message) {
      H.assertHelper(J.$eq$(J.$index$asx(message, "command"), "close"));
      this.liveTest._live_test_controller$_controller._live_test_controller$_close$0();
    },
    $signature: 3
  };
  S.RemoteListener__runLiveTest_closure0.prototype = {
    call$1: function(state) {
      var t1;
      type$.State._check(state);
      t1 = type$.String;
      this.channel.sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "state-change", "status", state.status.name, "result", state.result.name], t1, t1));
    },
    $signature: 23
  };
  S.RemoteListener__runLiveTest_closure1.prototype = {
    call$1: function(asyncError) {
      var t1, t2, t3, t4;
      type$.AsyncError._check(asyncError);
      t1 = asyncError.error;
      t2 = type$.StackTraceFormatter._as($.Zone__current.$index(0, $.$get$_currentKey0()));
      t3 = asyncError.stackTrace;
      t4 = this.liveTest._live_test_controller$_controller;
      this.channel.sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "error", "error", U.RemoteException_serialize(t1, t2.formatStackTrace$2$verbose(t3, t4._test.metadata._verboseTrace === true))], type$.String, type$.Object));
    },
    $signature: 90
  };
  S.RemoteListener__runLiveTest_closure2.prototype = {
    call$1: function(message) {
      var t1;
      type$.Message._check(message);
      t1 = this.$this._printZone;
      if (t1 != null)
        t1.print$1(0, message.text);
      t1 = type$.String;
      this.channel.sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "message", "message-type", message.type.name, "text", message.text], t1, t1));
    },
    $signature: 27
  };
  S.RemoteListener__runLiveTest_closure3.prototype = {
    call$0: function() {
      this.liveTest._live_test_controller$_controller._live_test_controller$_run$0().then$1$1(new S.RemoteListener__runLiveTest__closure(this.channel), type$.void);
    },
    $signature: 0
  };
  S.RemoteListener__runLiveTest__closure.prototype = {
    call$1: function(_) {
      var t1 = type$.String;
      return this.channel.sink.add$1(0, P.LinkedHashMap_LinkedHashMap$_literal(["type", "complete"], t1, t1));
    },
    $signature: 15
  };
  N.SuiteChannelManager.prototype = {
    connectOut$1: function($name) {
      var t2, completer,
        t1 = this._incomingConnections;
      if (t1.containsKey$1($name))
        return t1.$index(0, $name);
      else {
        t1 = this._names;
        if (t1.contains$1(0, $name))
          throw H.wrapException(P.StateError$('Duplicate suiteChannel() connection "' + $name + '".'));
        else {
          t1.add$1(0, $name);
          t1 = new Y._CompleterStream(type$._CompleterStream_dynamic);
          t2 = new T._CompleterSink(type$._CompleterSink_dynamic);
          completer = new N.StreamChannelCompleter(new Y.StreamCompleter(t1, type$.StreamCompleter_dynamic), new T.StreamSinkCompleter(t2, type$.StreamSinkCompleter_dynamic), type$.StreamChannelCompleter_dynamic);
          completer.set$_stream_channel_completer$_channel(new R._StreamChannel(t1, t2, type$._StreamChannel_dynamic));
          this._outgoingConnections.$indexSet(0, $name, completer);
          return completer._stream_channel_completer$_channel;
        }
      }
    }
  };
  O.IterableSet.prototype = {
    get$length: function(_) {
      var t1 = this._iterable_set$_base._collection$_source;
      return t1.get$length(t1);
    },
    get$iterator: function(_) {
      var t1 = this._iterable_set$_base;
      return new H.ListIterator(t1, t1.get$length(t1), t1.$ti._eval$1("ListIterator<ListMixin.E>"));
    },
    toSet$0: function(_) {
      var t1 = this._iterable_set$_base;
      return t1.toSet$0(t1);
    }
  };
  O._IterableSet_SetMixin_UnmodifiableSetMixin.prototype = {};
  E.StackTraceMapper.prototype = {};
  V.errorsDontStopTest_closure.prototype = {
    call$0: function() {
      P.Future_Future$sync(this.body, type$.dynamic).whenComplete$1(this.completer.get$complete());
    },
    $signature: 0
  };
  V.errorsDontStopTest_closure0.prototype = {
    call$1: function(_) {
      var t1 = type$.Invoker._as($.Zone__current.$index(0, C.Symbol_cQL));
      t1.heartbeat$0();
      t1.get$_outstandingCallbacks().decrement$0();
      return null;
    },
    $signature: 92
  };
  B.closure0.prototype = {
    call$0: function() {
      var t1 = $.$get$context().style;
      if (t1 == $.$get$Style_url())
        return C.OperatingSystem_none_none;
      if (t1 == $.$get$Style_windows())
        return C.OperatingSystem_Windows_windows;
      if ($._macOSDirectories.any$1(0, J.get$startsWith$s(D.current())))
        return C.OperatingSystem_RkP;
      return C.OperatingSystem_Linux_linux;
    },
    $signature: 115
  };
  O.Engine.prototype = {
    get$_onUnpaused: function() {
      var t1 = new P._Future($.Zone__current, type$._Future_dynamic);
      t1._asyncComplete$1(null);
      return t1;
    },
    get$success: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.bool),
        $async$returnValue, $async$self = this;
      var $async$get$success = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              $async$goto = 3;
              return P._asyncAwait(P.Future_wait(H.setRuntimeTypeInfo([$async$self._group._future_group$_completer.future, $async$self._loadPool._pool$_closeMemo._async_memoizer$_completer.future], type$.JSArray_Future_dynamic), true, type$.dynamic), $async$get$success);
            case 3:
              // returning from await.
              if (H.boolConversionCheck($async$self._closedBeforeDone)) {
                $async$returnValue = null;
                // goto return
                $async$goto = 1;
                break;
              }
              $async$returnValue = $async$self.get$liveTests().every$1(0, new O.Engine_success_closure());
              // goto return
              $async$goto = 1;
              break;
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$get$success, $async$completer);
    },
    get$liveTests: function() {
      var _this = this;
      return new M.UnionSet(P.LinkedHashSet_LinkedHashSet$from(H.setRuntimeTypeInfo([_this._passedGroup._union_set_controller$_set, _this._skippedGroup._union_set_controller$_set, _this._failedGroup._union_set_controller$_set, new O.IterableSet(new P.UnmodifiableListView(_this._active, type$.UnmodifiableListView_LiveTest), type$.IterableSet_LiveTest)], type$.JSArray_Set_LiveTest), type$.Set_LiveTest), true, type$.UnionSet_LiveTest);
    },
    Engine$3$concurrency$coverage$maxSuites: function(concurrency, coverage, maxSuites) {
      this._group._future_group$_completer.future.then$1$1(new O.Engine_closure(this), type$.Null).catchError$1(new O.Engine_closure0());
    },
    run$0: function() {
      var t2, subscription, _this = this, t1 = {};
      if (_this._engine$_runCalled)
        throw H.wrapException(P.StateError$("Engine.run() may not be called more than once."));
      _this._engine$_runCalled = true;
      t1.subscription = null;
      t2 = _this._suiteController;
      subscription = new P._ControllerStream(t2, H._instanceType(t2)._eval$1("_ControllerStream<1>")).listen$2$onDone(new O.Engine_run_closure(_this), new O.Engine_run_closure0(t1, _this));
      t1.subscription = subscription;
      _this._engine$_subscriptions.add$1(0, subscription);
      return _this.get$success();
    },
    _runGroup$3: function(suiteController, group, parents) {
      type$.List_Group._check(parents);
      return this._runGroup$body$Engine(suiteController, group, parents);
    },
    _runGroup$body$Engine: function(suiteController, group, parents) {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic),
        $async$returnValue, $async$handler = 2, $async$currentError, $async$next = [], $async$self = this, suiteConfig, skipGroup, setUpAllSucceeded, liveTest, entries, entry, test, liveTest0, t1, skipGroup0, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, _i, t16, t17, t18, invoker, t19, t20, result, t21;
      var $async$_runGroup$3 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1) {
          $async$currentError = $async$result;
          $async$goto = $async$handler;
        }
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              C.JSArray_methods.add$1(parents, group);
              $async$handler = 3;
              t1 = suiteController._liveSuite._live_suite_controller$_controller._live_suite_controller$_suite;
              suiteConfig = t1._runner_suite$_controller._config;
              suiteConfig.toString;
              skipGroup0 = group.metadata._skip === true;
              skipGroup = skipGroup0;
              setUpAllSucceeded = true;
              $async$goto = !H.boolConversionCheck(skipGroup) && group.setUpAll != null ? 6 : 7;
              break;
            case 6:
              // then
              liveTest = group.setUpAll.load$2$groups(t1, parents);
              $async$goto = 8;
              return P._asyncAwait($async$self._engine$_runLiveTest$3$countSuccess(suiteController, liveTest, false), $async$_runGroup$3);
            case 8:
              // returning from await.
              t1 = liveTest._live_test_controller$_controller._live_test_controller$_state.result;
              setUpAllSucceeded = t1 === C.Result_success || t1 === C.Result_skipped;
            case 7:
              // join
              $async$goto = !$async$self._engine$_closed && H.boolConversionCheck(setUpAllSucceeded) ? 9 : 10;
              break;
            case 9:
              // then
              t1 = group.entries;
              t1 = H.setRuntimeTypeInfo(t1.slice(0), H._arrayInstanceType(t1)._eval$1("JSArray<1>"));
              entries = t1;
              suiteConfig.toString;
              t1 = entries, t2 = t1.length, t3 = type$.Group, t4 = type$.List_Group, t5 = type$._Future_void, t6 = type$._AsyncCompleter_void, t7 = type$._SyncBroadcastStreamController_Message, t8 = type$._SyncBroadcastStreamController_AsyncError, t9 = type$._SyncBroadcastStreamController_State, t10 = type$.Test, t11 = type$.Iterable_Group, t12 = type$.JSArray_Zone, t13 = type$.JSArray_of_dynamic_Function, t14 = type$.JSArray_String, t15 = type$.JSArray_AsyncError, _i = 0;
            case 11:
              // for condition
              if (!(_i < t1.length)) {
                // goto after for
                $async$goto = 13;
                break;
              }
              entry = t1[_i];
              if ($async$self._engine$_closed) {
                $async$next = [1];
                // goto finally
                $async$goto = 4;
                break;
              }
              $async$goto = entry instanceof O.Group ? 14 : 16;
              break;
            case 14:
              // then
              $async$goto = 17;
              return P._asyncAwait($async$self._runGroup$3(suiteController, entry, parents), $async$_runGroup$3);
            case 17:
              // returning from await.
              // goto join
              $async$goto = 15;
              break;
            case 16:
              // else
              suiteConfig.toString;
              t16 = entry.get$metadata();
              t16 = t16._skip === true;
              $async$goto = t16 ? 18 : 20;
              break;
            case 18:
              // then
              $async$goto = 21;
              return P._asyncAwait($async$self._runSkippedTest$3(suiteController, t10._as(entry), parents), $async$_runGroup$3);
            case 21:
              // returning from await.
              // goto join
              $async$goto = 19;
              break;
            case 20:
              // else
              test = t10._as(entry);
              t16 = test;
              t17 = suiteController._liveSuite._live_suite_controller$_controller;
              t16.toString;
              t11._check(parents);
              t18 = new P._AsyncCompleter(new P._Future($.Zone__current, t5), t6);
              invoker = new U.Invoker(t16._guarded, new P.Object(), t18, H.setRuntimeTypeInfo([], t12), new P.Object(), H.setRuntimeTypeInfo([], t13), H.setRuntimeTypeInfo([], t14));
              t19 = H.setRuntimeTypeInfo([], t15);
              t20 = $.Zone__current;
              result = P.List_List$from(parents, false, t3);
              result.fixed$length = Array;
              result.immutable$list = Array;
              t21 = t4._check(result);
              t16 = new V.LiveTestController(t17._live_suite_controller$_suite, t21, t16, invoker.get$_invoker$_onRun(), t18.get$complete(), t19, C.State_Status_pending_Result_success, new P._SyncBroadcastStreamController(null, null, t9), new P._SyncBroadcastStreamController(null, null, t8), new P._SyncBroadcastStreamController(null, null, t7), new P._AsyncCompleter(new P._Future(t20, t5), t6));
              t17 = new V._LiveTest(t16);
              t16._liveTest = t17;
              invoker._invoker$_controller = t16;
              $async$goto = 22;
              return P._asyncAwait($async$self._engine$_runLiveTest$2(suiteController, t17), $async$_runGroup$3);
            case 22:
              // returning from await.
            case 19:
              // join
            case 15:
              // join
            case 12:
              // for update
              t1.length === t2 || (0, H.throwConcurrentModificationError)(t1), ++_i;
              // goto for condition
              $async$goto = 11;
              break;
            case 13:
              // after for
            case 10:
              // join
              $async$goto = !H.boolConversionCheck(skipGroup) && group.tearDownAll != null ? 23 : 24;
              break;
            case 23:
              // then
              liveTest0 = group.tearDownAll.load$2$groups(suiteController._liveSuite._live_suite_controller$_controller._live_suite_controller$_suite, parents);
              $async$goto = 25;
              return P._asyncAwait($async$self._engine$_runLiveTest$3$countSuccess(suiteController, liveTest0, false), $async$_runGroup$3);
            case 25:
              // returning from await.
              $async$goto = $async$self._engine$_closed ? 26 : 27;
              break;
            case 26:
              // then
              $async$goto = 28;
              return P._asyncAwait(liveTest0._live_test_controller$_controller._live_test_controller$_close$0(), $async$_runGroup$3);
            case 28:
              // returning from await.
            case 27:
              // join
            case 24:
              // join
              $async$next.push(5);
              // goto finally
              $async$goto = 4;
              break;
            case 3:
              // uncaught
              $async$next = [2];
            case 4:
              // finally
              $async$handler = 2;
              C.JSArray_methods.remove$1(parents, group);
              // goto the next finally handler
              $async$goto = $async$next.pop();
              break;
            case 5:
              // after finally
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
            case 2:
              // rethrow
              return P._asyncRethrow($async$currentError, $async$completer);
          }
      });
      return P._asyncStartSync($async$_runGroup$3, $async$completer);
    },
    _engine$_runLiveTest$3$countSuccess: function(suiteController, liveTest, countSuccess) {
      return this._runLiveTest$body$Engine(suiteController, liveTest, countSuccess);
    },
    _engine$_runLiveTest$2: function(suiteController, liveTest) {
      return this._engine$_runLiveTest$3$countSuccess(suiteController, liveTest, true);
    },
    _runLiveTest$body$Engine: function(suiteController, liveTest, countSuccess) {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic),
        $async$returnValue, $async$self = this, t2, t3, subscription, t1;
      var $async$_engine$_runLiveTest$3$countSuccess = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = {};
              $async$goto = 3;
              return P._asyncAwait($async$self.get$_onUnpaused(), $async$_engine$_runLiveTest$3$countSuccess);
            case 3:
              // returning from await.
              t2 = $async$self._active;
              t2._queue_list$_add$1(t2.$ti._precomputed1._check(liveTest));
              t2.get$first(t2).toString;
              t1.subscription = null;
              t2 = liveTest._live_test_controller$_controller;
              t3 = t2._onStateChangeController;
              subscription = new P._BroadcastStream(t3, H._instanceType(t3)._eval$1("_BroadcastStream<1>")).listen$2$onDone(new O.Engine__runLiveTest_closure($async$self, liveTest), new O.Engine__runLiveTest_closure0(t1, $async$self));
              t1.subscription = subscription;
              $async$self._engine$_subscriptions.add$1(0, subscription);
              suiteController.reportLiveTest$2$countSuccess(liveTest, countSuccess);
              $async$goto = 4;
              return P._asyncAwait(P.Future_Future$microtask(liveTest.get$run(), type$.dynamic), $async$_engine$_runLiveTest$3$countSuccess);
            case 4:
              // returning from await.
              $async$goto = 5;
              return P._asyncAwait(P.Future_Future(new O.Engine__runLiveTest_closure1(), type$.Null), $async$_engine$_runLiveTest$3$countSuccess);
            case 5:
              // returning from await.
              t1 = $async$self._restarted;
              if (!t1.contains$1(0, liveTest)) {
                // goto return
                $async$goto = 1;
                break;
              }
              $async$goto = 6;
              return P._asyncAwait($async$self._engine$_runLiveTest$3$countSuccess(suiteController, t2._test.load$2$groups(t2._live_test_controller$_suite, t2._groups), countSuccess), $async$_engine$_runLiveTest$3$countSuccess);
            case 6:
              // returning from await.
              t1.remove$1(0, liveTest);
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$_engine$_runLiveTest$3$countSuccess, $async$completer);
    },
    _runSkippedTest$3: function(suiteController, test, parents) {
      return this._runSkippedTest$body$Engine(suiteController, test, type$.List_Group._check(parents));
    },
    _runSkippedTest$body$Engine: function(suiteController, test, parents) {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic),
        $async$returnValue, $async$self = this, skipped, controller, t1;
      var $async$_runSkippedTest$3 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = {};
              $async$goto = 3;
              return P._asyncAwait($async$self.get$_onUnpaused(), $async$_runSkippedTest$3);
            case 3:
              // returning from await.
              skipped = new U.LocalTest(test.name, test.metadata, test.trace, false, new O.Engine__runSkippedTest_closure(), true);
              t1.controller = null;
              controller = V.LiveTestController$(suiteController._liveSuite._live_suite_controller$_controller._live_suite_controller$_suite, skipped, new O.Engine__runSkippedTest_closure0(t1, skipped), new O.Engine__runSkippedTest_closure1(), parents);
              t1.controller = controller;
              $async$goto = 4;
              return P._asyncAwait($async$self._engine$_runLiveTest$2(suiteController, controller._liveTest), $async$_runSkippedTest$3);
            case 4:
              // returning from await.
              $async$returnValue = $async$result;
              // goto return
              $async$goto = 1;
              break;
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$_runSkippedTest$3, $async$completer);
    },
    _addLiveSuite$1: function(liveSuite) {
      var t1, t2, t3, _this = this;
      _this._liveSuites.add$1(0, liveSuite);
      _this._onSuiteStartedController.add$1(0, liveSuite);
      t1 = liveSuite._live_suite_controller$_controller;
      t2 = t1._onTestStartedController;
      _this._onTestStartedGroup.add$1(0, new P._BroadcastStream(t2, H._instanceType(t2)._eval$1("_BroadcastStream<1>")));
      t2 = _this._passedGroup;
      t3 = type$.UnmodifiableSetView_LiveTest;
      t2._union_set_controller$_sets.add$1(0, t2.$ti._eval$1("Set<1>")._check(new L.UnmodifiableSetView(t1._passed, t3)));
      t2 = _this._skippedGroup;
      t2._union_set_controller$_sets.add$1(0, t2.$ti._eval$1("Set<1>")._check(new L.UnmodifiableSetView(t1._skipped, t3)));
      t2 = _this._failedGroup;
      t2._union_set_controller$_sets.add$1(0, t2.$ti._eval$1("Set<1>")._check(new L.UnmodifiableSetView(t1._failed, t3)));
    }
  };
  O.Engine_success_closure.prototype = {
    call$1: function(liveTest) {
      var t1 = type$.LiveTest._check(liveTest)._live_test_controller$_controller._live_test_controller$_state,
        t2 = t1.result;
      return (t2 === C.Result_success || t2 === C.Result_skipped) && t1.status === C.Status_complete;
    },
    $signature: 95
  };
  O.Engine_closure.prototype = {
    call$1: function(_) {
      var t1;
      type$.List_dynamic._check(_);
      t1 = this.$this;
      t1._onTestStartedGroup.close$0(0);
      t1._onSuiteStartedController.close$0(0);
      if (t1._closedBeforeDone == null)
        t1._closedBeforeDone = false;
    },
    $signature: 48
  };
  O.Engine_closure0.prototype = {
    call$1: function(_) {
    },
    $signature: 3
  };
  O.Engine_run_closure.prototype = {
    call$1: function(suite) {
      var t1;
      type$.RunnerSuite._check(suite);
      t1 = this.$this;
      t1._addedSuites.add$1(0, suite);
      t1._onSuiteAddedController.add$1(0, suite);
      t1._group.add$1(0, new O.Engine_run__closure(t1, suite).call$0());
    },
    $signature: 97
  };
  O.Engine_run__closure.prototype = {
    call$0: function() {
      return this.$call$body$Engine_run__closure();
    },
    $call$body$Engine_run__closure: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$self = this, controller, t1, t2, loadResource;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = {};
              t2 = $async$self.$this;
              $async$goto = 2;
              return P._asyncAwait(t2._loadPool.request$0(0), $async$call$0);
            case 2:
              // returning from await.
              loadResource = $async$result;
              t1.controller = null;
              controller = B.LiveSuiteController$($async$self.suite);
              t1.controller = controller;
              t2._addLiveSuite$1(controller._liveSuite);
              $async$goto = 3;
              return P._asyncAwait(t2._runPool.withResource$1$1(new O.Engine_run___closure(t1, t2, loadResource), type$.Null), $async$call$0);
            case 3:
              // returning from await.
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  O.Engine_run___closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, $async$self = this, t2, t3, t1;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $async$self.$this;
              if (t1._engine$_closed) {
                // goto return
                $async$goto = 1;
                break;
              }
              t2 = $async$self._box_0;
              t3 = t2.controller;
              $async$goto = 3;
              return P._asyncAwait(t1._runGroup$3(t3, t3._liveSuite._live_suite_controller$_controller._live_suite_controller$_suite.group, H.setRuntimeTypeInfo([], type$.JSArray_Group)), $async$call$0);
            case 3:
              // returning from await.
              t3 = t2.controller;
              t3._onTestStartedController.close$0(0);
              t3._onCompleteGroup.close$0(0);
              t1 = $async$self.loadResource;
              t1.toString;
              t2 = type$.dynamic_Function._check(new O.Engine_run____closure(t2));
              if (t1._released)
                H.throwExpression(P.StateError$("A PoolResource may only be released once."));
              t1._released = true;
              t1._pool._onResourceReleaseAllowed$1(t2);
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  O.Engine_run____closure.prototype = {
    call$0: function() {
      return this._box_0.controller.close$0(0);
    },
    $signature: 14
  };
  O.Engine_run_closure0.prototype = {
    call$0: function() {
      var t1 = this.$this;
      t1._engine$_subscriptions.remove$1(0, this._box_1.subscription);
      t1._onSuiteAddedController.close$0(0);
      t1._group.close$0(0);
      t1._loadPool.close$0(0);
    },
    $signature: 0
  };
  O.Engine__runLiveTest_closure.prototype = {
    call$1: function(state) {
      var t1, t2;
      if (type$.State._check(state).status !== C.Status_complete)
        return;
      t1 = this.$this;
      t2 = t1._active;
      t2.remove$1(t2, this.liveTest);
      if (t2.get$length(t2) === 0 && t1._activeLoadTests._collection$_length !== 0) {
        t1 = t1._activeLoadTests;
        t2._queue_list$_add$1(t2.$ti._precomputed1._check(t1.get$first(t1)));
      }
    },
    $signature: 23
  };
  O.Engine__runLiveTest_closure0.prototype = {
    call$0: function() {
      this.$this._engine$_subscriptions.remove$1(0, this._box_0.subscription);
    },
    $signature: 0
  };
  O.Engine__runLiveTest_closure1.prototype = {
    call$0: function() {
    },
    $signature: 0
  };
  O.Engine__runSkippedTest_closure.prototype = {
    call$0: function() {
    },
    $signature: 0
  };
  O.Engine__runSkippedTest_closure0.prototype = {
    call$0: function() {
      var t2,
        t1 = this._box_0;
      t1.controller.setState$1(C.State_Status_running_Result_success);
      t1.controller.setState$1(C.State_Status_running_Result_skipped);
      t2 = this.skipped.metadata.skipReason;
      if (t2 != null)
        t1.controller.message$1(0, new D.Message(C.MessageType_skip, "Skip: " + t2));
      t1.controller.setState$1(C.State_Status_complete_Result_skipped);
      t1.controller.completer.complete$0();
    },
    $signature: 0
  };
  O.Engine__runSkippedTest_closure1.prototype = {
    call$0: function() {
    },
    $signature: 0
  };
  E.LiveSuite.prototype = {};
  B._LiveSuite.prototype = {};
  B.LiveSuiteController.prototype = {
    LiveSuiteController$1: function(_suite) {
      var _this = this;
      _this._liveSuite = new B._LiveSuite(_this);
      _this._onCompleteGroup._future_group$_completer.future.then$1$2$onError(new B.LiveSuiteController_closure(_this), new B.LiveSuiteController_closure0(), type$.Null);
    },
    reportLiveTest$2$countSuccess: function(liveTest, countSuccess) {
      var t2, t3, _this = this,
        t1 = _this._onTestStartedController;
      if ((t1._state & 4) !== 0)
        throw H.wrapException(P.StateError$("Can't call reportLiveTest() after noMoreTests()."));
      t2 = liveTest._live_test_controller$_controller;
      H.assertHelper(t2._live_test_controller$_suite == _this._live_suite_controller$_suite);
      H.assertHelper(_this._live_suite_controller$_active == null);
      _this._live_suite_controller$_active = liveTest;
      t3 = t2._onStateChangeController;
      new P._BroadcastStream(t3, H._instanceType(t3)._eval$1("_BroadcastStream<1>")).listen$1(new B.LiveSuiteController_reportLiveTest_closure(_this, liveTest, countSuccess));
      t1.add$1(0, liveTest);
      _this._onCompleteGroup.add$1(0, t2.completer.future);
    },
    close$0: function(_) {
      return this._live_suite_controller$_closeMemo.runOnce$1(new B.LiveSuiteController_close_closure(this));
    }
  };
  B.LiveSuiteController_closure.prototype = {
    call$1: function(_) {
      type$.List_dynamic._check(_);
    },
    $signature: 48
  };
  B.LiveSuiteController_closure0.prototype = {
    call$1: function(_) {
    },
    $signature: 3
  };
  B.LiveSuiteController_reportLiveTest_closure.prototype = {
    call$1: function(state) {
      var t1, t2, _this = this;
      type$.State._check(state);
      if (state.status !== C.Status_complete)
        return;
      t1 = _this.$this;
      t1._live_suite_controller$_active = null;
      t2 = state.result;
      if (t2 === C.Result_skipped)
        t1._skipped.add$1(0, _this.liveTest);
      else if (t2 !== C.Result_success) {
        t2 = _this.liveTest;
        t1._passed.remove$1(0, t2);
        t1._failed.add$1(0, t2);
      } else if (_this.countSuccess) {
        t2 = _this.liveTest;
        t1._passed.add$1(0, t2);
        t1._failed.remove$1(0, t2);
      }
    },
    $signature: 23
  };
  B.LiveSuiteController_close_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$handler = 1, $async$currentError, $async$next = [], $async$self = this;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1) {
          $async$currentError = $async$result;
          $async$goto = $async$handler;
        }
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              $async$handler = 2;
              $async$goto = 5;
              return P._asyncAwait($async$self.$this._live_suite_controller$_suite._runner_suite$_controller._runner_suite$_close$0(), $async$call$0);
            case 5:
              // returning from await.
              $async$next.push(4);
              // goto finally
              $async$goto = 3;
              break;
            case 2:
              // uncaught
              $async$next = [1];
            case 3:
              // finally
              $async$handler = 1;
              $async$self.$this._live_suite_controller$_onCloseCompleter.complete$0();
              // goto the next finally handler
              $async$goto = $async$next.pop();
              break;
            case 4:
              // after finally
              // implicit return
              return P._asyncReturn(null, $async$completer);
            case 1:
              // rethrow
              return P._asyncRethrow($async$currentError, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  R.ExpandedReporter.prototype = {
    _onTestStarted$1: function(liveTest) {
      var t1, t2, t3, t4, _this = this;
      type$.LiveTest._check(liveTest);
      liveTest.toString;
      t1 = _this._stopwatch;
      t2 = t1._stop != null;
      if (t2)
        if (t2) {
          t2 = t1._core$_start;
          t3 = H._checkIntNullable($.Primitives_timerTicks.call$0());
          t4 = t1._stop;
          if (typeof t3 !== "number")
            return t3.$sub();
          if (typeof t4 !== "number")
            return H.iae(t4);
          t1._core$_start = t2 + (t3 - t4);
          t1._stop = null;
        }
      t1 = _this._engine._active;
      if (t1.get$length(t1) === 1)
        _this._progressLine$1(_this._description$1(liveTest));
      t1 = liveTest._live_test_controller$_controller._onStateChangeController;
      _this._subscriptions.add$1(0, new P._BroadcastStream(t1, H._instanceType(t1)._eval$1("_BroadcastStream<1>")).listen$1(new R.ExpandedReporter__onTestStarted_closure(_this, liveTest)));
      t1 = _this._subscriptions;
      t2 = liveTest._live_test_controller$_controller;
      t3 = t2._onErrorController;
      t1.add$1(0, new P._BroadcastStream(t3, H._instanceType(t3)._eval$1("_BroadcastStream<1>")).listen$1(new R.ExpandedReporter__onTestStarted_closure0(_this, liveTest)));
      t2 = t2._onMessageController;
      t1.add$1(0, new P._BroadcastStream(t2, H._instanceType(t2)._eval$1("_BroadcastStream<1>")).listen$1(new R.ExpandedReporter__onTestStarted_closure1(_this, liveTest)));
    },
    _onStateChange$2: function(liveTest, state) {
      var t1, t2, t3;
      if (state.status !== C.Status_complete)
        return;
      t1 = this._engine._active;
      t2 = type$.UnmodifiableListView_LiveTest;
      t3 = new P.UnmodifiableListView(t1, t2);
      if (t3.get$length(t3) !== 0) {
        t1 = new P.UnmodifiableListView(t1, t2);
        this._progressLine$1(this._description$1(t1.get$first(t1)));
      }
    },
    _expanded$_onError$3: function(liveTest, error, stackTrace) {
      var t1, _this = this;
      if (liveTest._live_test_controller$_controller._live_test_controller$_state.status !== C.Status_complete)
        return;
      _this._progressLine$2$suffix(_this._description$1(liveTest), " " + _this._bold + _this._red + "[E]" + _this._noColor);
      t1 = _this._expanded$_sink;
      t1.writeln$1(B.indent(H.S(error), null));
      t1.writeln$1(B.indent(H.S(stackTrace), null));
      return;
    },
    _expanded$_onDone$1: function(success) {
      var t1, t2, t3, t4, _this = this;
      H._checkBoolNullable(success);
      if (success == null)
        return;
      t1 = _this._engine;
      t2 = t1.get$liveTests();
      if (t2.get$length(t2) === 0)
        _this._expanded$_sink.writeln$1("No tests ran.");
      else if (!success) {
        for (t2 = type$.UnmodifiableListView_LiveTest, t1 = new P.UnmodifiableListView(t1._active, t2), t2 = new H.ListIterator(t1, t1.get$length(t1), t2._eval$1("ListIterator<ListMixin.E>")), t1 = _this._bold, t3 = _this._red, t4 = _this._noColor; t2.moveNext$0();)
          _this._progressLine$2$suffix(_this._description$1(t2.__internal$_current), " - did not complete " + t1 + t3 + "[E]" + t4);
        _this._progressLine$2$color("Some tests failed.", t3);
      } else {
        t1 = t1._passedGroup._union_set_controller$_set;
        if (t1.get$length(t1) === 0)
          _this._progressLine$1("All tests skipped.");
        else
          _this._progressLine$1("All tests passed!");
      }
    },
    _progressLine$3$color$suffix: function(message, color, suffix) {
      var t4, t5, _this = this,
        t1 = _this._engine,
        t2 = t1._passedGroup,
        t3 = t2._union_set_controller$_set;
      if (t3.get$length(t3) == _this._lastProgressPassed) {
        t3 = t1._skippedGroup._union_set_controller$_set;
        if (t3.get$length(t3) == _this._lastProgressSkipped) {
          t3 = t1._failedGroup._union_set_controller$_set;
          if (t3.get$length(t3) == _this._lastProgressFailed)
            if (message == _this._lastProgressMessage)
              t3 = suffix == null || suffix === _this._lastProgressSuffix;
            else
              t3 = false;
          else
            t3 = false;
        } else
          t3 = false;
      } else
        t3 = false;
      if (t3)
        return;
      t3 = t2._union_set_controller$_set;
      _this._lastProgressPassed = t3.get$length(t3);
      t3 = t1._skippedGroup;
      t4 = t3._union_set_controller$_set;
      _this._lastProgressSkipped = t4.get$length(t4);
      t1 = t1._failedGroup;
      t4 = t1._union_set_controller$_set;
      _this._lastProgressFailed = t4.get$length(t4);
      _this._lastProgressMessage = message;
      _this._lastProgressSuffix = suffix;
      if (suffix != null)
        message = J.$add$ansx(message, suffix);
      if (color == null)
        color = "";
      t4 = P.Duration$(_this._stopwatch.get$elapsedMicroseconds(), 0)._duration;
      t4 = C.JSString_methods.padLeft$2(C.JSInt_methods.toString$0(C.JSInt_methods._tdivFast$1(t4, 60000000)), 2, "0") + ":" + C.JSString_methods.padLeft$2(C.JSInt_methods.toString$0(C.JSInt_methods.$mod(C.JSInt_methods._tdivFast$1(t4, 1000000), 60)), 2, "0") + " " + _this._green + "+";
      t2 = t2._union_set_controller$_set;
      t5 = _this._noColor;
      t2 = t4 + H.S(t2.get$length(t2)) + t5;
      t4 = t3._union_set_controller$_set;
      if (t4.get$length(t4) !== 0) {
        t2 = t2 + _this._yellow + " ~";
        t3 = t3._union_set_controller$_set;
        t3 = t2 + H.S(t3.get$length(t3)) + t5;
        t2 = t3;
      }
      t3 = t1._union_set_controller$_set;
      if (t3.get$length(t3) !== 0) {
        t2 = t2 + _this._red + " -";
        t1 = t1._union_set_controller$_set;
        t1 = t2 + H.S(t1.get$length(t1)) + t5;
      } else
        t1 = t2;
      t5 = t1 + ": " + color + H.S(message) + t5;
      _this._expanded$_sink.writeln$1(t5.charCodeAt(0) == 0 ? t5 : t5);
    },
    _progressLine$2$suffix: function(message, suffix) {
      return this._progressLine$3$color$suffix(message, null, suffix);
    },
    _progressLine$2$color: function(message, color) {
      return this._progressLine$3$color$suffix(message, color, null);
    },
    _progressLine$1: function(message) {
      return this._progressLine$3$color$suffix(message, null, null);
    },
    _description$1: function(liveTest) {
      var t1 = liveTest._live_test_controller$_controller;
      return t1._test.name;
    }
  };
  R.ExpandedReporter__onTestStarted_closure.prototype = {
    call$1: function(state) {
      return this.$this._onStateChange$2(this.liveTest, type$.State._check(state));
    },
    $signature: 100
  };
  R.ExpandedReporter__onTestStarted_closure0.prototype = {
    call$1: function(error) {
      type$.AsyncError._check(error);
      return this.$this._expanded$_onError$3(this.liveTest, error.error, error.stackTrace);
    },
    $signature: 101
  };
  R.ExpandedReporter__onTestStarted_closure1.prototype = {
    call$1: function(message) {
      var t1, text;
      type$.Message._check(message);
      t1 = this.$this;
      t1._progressLine$1(t1._description$1(this.liveTest));
      text = message.text;
      if (message.type === C.MessageType_skip)
        text = "  " + t1._yellow + text + t1._noColor;
      t1._expanded$_sink.writeln$1(text);
    },
    $signature: 27
  };
  Y.RunnerSuite.prototype = {};
  Y.RunnerSuiteController.prototype = {
    _runner_suite$_close$0: function() {
      return this._closeMemo.runOnce$1(new Y.RunnerSuiteController__close_closure(this));
    },
    set$_runner_suite$_suite: function(_suite) {
      type$.Future_RunnerSuite._check(_suite);
    }
  };
  Y.RunnerSuiteController__close_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$self = this;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              $async$goto = 2;
              return P._asyncAwait($async$self.$this._onDebuggingController.close$0(0), $async$call$0);
            case 2:
              // returning from await.
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  T.RuntimeSelection.prototype = {};
  U.SuiteConfiguration.prototype = {};
  X.PrintSink.prototype = {
    writeln$1: function(obj) {
      this._print_sink$_buffer._contents += obj + "\n";
      this._flush$0();
    },
    _flush$0: function() {
      var t1 = this._print_sink$_buffer;
      if (C.JSString_methods.endsWith$1(t1.toString$0(0), "\n")) {
        P.print(t1);
        t1._contents = "";
      }
    },
    $isStringSink: 1
  };
  E.JSStackTraceMapper.prototype = {};
  E.JSStackTraceMapper__deserializePackageConfigMap_closure.prototype = {
    call$2: function(key, value) {
      return new P.MapEntry(H._checkStringNullable(key), P.Uri_parse(H._checkStringNullable(value)), type$.MapEntry_String_Uri);
    },
    $signature: 102
  };
  R._declarer_closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        $async$returnValue, controller, suite, engine, t1, t2, t3, t4, $async$temp1;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              t1 = $.$get$SuiteConfiguration_empty();
              t2 = $._globalDeclarer.build$0();
              t3 = E.SuitePlatform$(C.Runtime_ql0, false, $.$get$currentOSGuess());
              t4 = P.Uri_base();
              t4 = $.$get$context().prettyUri$1(t4);
              controller = new Y.RunnerSuiteController(t1, null, new P._AsyncBroadcastStreamController(null, null, type$._AsyncBroadcastStreamController_bool), P.LinkedHashSet_LinkedHashSet$_empty(type$.String), new S.AsyncMemoizer(new P._AsyncCompleter(new P._Future($.Zone__current, type$._Future_dynamic), type$._AsyncCompleter_dynamic), type$.AsyncMemoizer_dynamic));
              suite = new Y.RunnerSuite(controller, t3, t4, U.Suite__filterGroup(t2, t3));
              t1 = new P._Future($.Zone__current, type$._Future_RunnerSuite);
              t1._asyncComplete$1(suite);
              controller.set$_runner_suite$_suite(t1);
              engine = O.Engine$();
              t1 = engine._suiteController;
              t1.add$1(0, H._instanceType(t1)._precomputed1._check(type$.RunnerSuite._check(suite)));
              t1.close$0(0);
              if ($.Stopwatch__frequency == null) {
                H.Primitives_initTicker();
                $.Stopwatch__frequency = $.Primitives_timerFrequency;
              }
              t1 = P.LinkedHashSet_LinkedHashSet$_empty(type$.StreamSubscription_dynamic);
              t2 = new R.ExpandedReporter(true, "\x1b[32m", "\x1b[31m", "\x1b[33m", "\x1b[1;30m", "\x1b[1m", "\x1b[0m", engine, false, false, new P.Stopwatch(), t1, new X.PrintSink(new P.StringBuffer("")));
              t3 = engine._onTestStartedGroup._stream_group$_controller;
              t3.toString;
              t1.add$1(0, new P._BroadcastStream(t3, H._instanceType(t3)._eval$1("_BroadcastStream<1>")).listen$1(t2.get$_onTestStarted()));
              t3 = engine.get$success();
              t3.toString;
              t1.add$1(0, P.Stream_Stream$fromFuture(t3, t3.$ti._precomputed1).listen$1(t2.get$_expanded$_onDone()));
              t2 = type$.dynamic;
              $async$temp1 = H;
              $async$goto = 3;
              return P._asyncAwait(P.runZoned(new R._declarer__closure(engine), null, null, P.LinkedHashMap_LinkedHashMap$_literal([C.Symbol_Drw, $._globalDeclarer], t2, t2), type$.Future_bool), $async$call$0);
            case 3:
              // returning from await.
              if ($async$temp1.boolConversionCheck($async$result)) {
                $async$returnValue = null;
                // goto return
                $async$goto = 1;
                break;
              }
              P.print("");
              P.Future_Future$error("Dummy exception to set exit code.", null, type$.void);
            case 1:
              // return
              return P._asyncReturn($async$returnValue, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  R._declarer__closure.prototype = {
    call$0: function() {
      return U.Invoker_guard(this.engine.get$run(), type$.Future_bool);
    },
    $signature: 31
  };
  G.main_closure0.prototype = {
    call$0: function() {
      R.test("sample test", new G.main__closure());
    },
    $signature: 0
  };
  G.main__closure.prototype = {
    call$0: function() {
      var $async$goto = 0,
        $async$completer = P._makeAsyncAwaitCompleter(type$.Null),
        res;
      var $async$call$0 = P._wrapJsFunctionForAsync(function($async$errorCode, $async$result) {
        if ($async$errorCode === 1)
          return P._asyncRethrow($async$result, $async$completer);
        while (true)
          switch ($async$goto) {
            case 0:
              // Function start
              res = G.method1();
              if (res === 0)
                G.method2();
              G.expect(true, C.C__IsTrue, null);
              // implicit return
              return P._asyncReturn(null, $async$completer);
          }
      });
      return P._asyncStartSync($async$call$0, $async$completer);
    },
    $signature: 2
  };
  R.main_closure.prototype = {
    call$0: function() {
      return G.main_test__main$closure();
    },
    $signature: 103
  };
  (function aliases() {
    var _ = J.JavaScriptObject.prototype;
    _.super$JavaScriptObject$toString = _.toString$0;
    _ = P._BroadcastStreamController.prototype;
    _.super$_BroadcastStreamController$_addEventError = _._addEventError$0;
    _ = P.Iterable.prototype;
    _.super$Iterable$where = _.where$1;
    _.super$Iterable$skipWhile = _.skipWhile$1;
    _ = W.EventTarget.prototype;
    _.super$EventTarget$addEventListener = _.addEventListener$3;
    _ = Y.DelegatingStreamSubscription.prototype;
    _.super$DelegatingStreamSubscription$onError = _.onError$1;
    _.super$DelegatingStreamSubscription$cancel = _.cancel$0;
    _ = M.TypeMatcher.prototype;
    _.super$TypeMatcher$describe = _.describe$1;
    _.super$TypeMatcher$matches = _.matches$2;
    _ = Y.SourceSpanMixin.prototype;
    _.super$SourceSpanMixin$$eq = _.$eq;
    _ = X.StringScanner.prototype;
    _.super$StringScanner$matches = _.matches$1;
  })();
  (function installTearOffs() {
    var _instance = hunkHelpers.installInstanceTearOff,
      _static_0 = hunkHelpers._static_0,
      _static_1 = hunkHelpers._static_1,
      _static = hunkHelpers.installStaticTearOff,
      _instance_0_u = hunkHelpers._instance_0u,
      _instance_1_i = hunkHelpers._instance_1i,
      _instance_0_i = hunkHelpers._instance_0i,
      _instance_1_u = hunkHelpers._instance_1u,
      _instance_2_u = hunkHelpers._instance_2u;
    _instance(J.JSString.prototype, "get$startsWith", 1, 1, null, ["call$2", "call$1"], ["startsWith$2", "startsWith$1"], 57, 0);
    _static_0(H, "_js_helper_Primitives_dateNow$closure", "Primitives_dateNow", 36);
    _static_1(P, "async__AsyncRun__scheduleImmediateJsOverride$closure", "_AsyncRun__scheduleImmediateJsOverride", 20);
    _static_1(P, "async__AsyncRun__scheduleImmediateWithSetImmediate$closure", "_AsyncRun__scheduleImmediateWithSetImmediate", 20);
    _static_1(P, "async__AsyncRun__scheduleImmediateWithTimer$closure", "_AsyncRun__scheduleImmediateWithTimer", 20);
    _static_1(P, "async_Future__kTrue$closure", "Future__kTrue", 9);
    _static_0(P, "async___startMicrotaskLoop$closure", "_startMicrotaskLoop", 1);
    _static_1(P, "async___nullDataHandler$closure", "_nullDataHandler", 11);
    _static(P, "async___nullErrorHandler$closure", 1, null, ["call$2", "call$1"], ["_nullErrorHandler", function(error) {
      return P._nullErrorHandler(error, null);
    }], 12, 0);
    _static_0(P, "async___nullDoneHandler$closure", "_nullDoneHandler", 1);
    _static(P, "async___rootHandleUncaughtError$closure", 5, null, ["call$5"], ["_rootHandleUncaughtError"], 105, 0);
    _static(P, "async___rootRun$closure", 4, null, ["call$1$4", "call$4"], ["_rootRun", function($self, $parent, zone, f) {
      return P._rootRun($self, $parent, zone, f, type$.dynamic);
    }], 106, 0);
    _static(P, "async___rootRunUnary$closure", 5, null, ["call$2$5", "call$5"], ["_rootRunUnary", function($self, $parent, zone, f, arg) {
      return P._rootRunUnary($self, $parent, zone, f, arg, type$.dynamic, type$.dynamic);
    }], 107, 0);
    _static(P, "async___rootRunBinary$closure", 6, null, ["call$3$6"], ["_rootRunBinary"], 108, 0);
    _static(P, "async___rootRegisterCallback$closure", 4, null, ["call$1$4", "call$4"], ["_rootRegisterCallback", function($self, $parent, zone, f) {
      return P._rootRegisterCallback($self, $parent, zone, f, type$.dynamic);
    }], 35, 0);
    _static(P, "async___rootRegisterUnaryCallback$closure", 4, null, ["call$2$4", "call$4"], ["_rootRegisterUnaryCallback", function($self, $parent, zone, f) {
      return P._rootRegisterUnaryCallback($self, $parent, zone, f, type$.dynamic, type$.dynamic);
    }], 33, 0);
    _static(P, "async___rootRegisterBinaryCallback$closure", 4, null, ["call$3$4", "call$4"], ["_rootRegisterBinaryCallback", function($self, $parent, zone, f) {
      return P._rootRegisterBinaryCallback($self, $parent, zone, f, type$.dynamic, type$.dynamic, type$.dynamic);
    }], 109, 0);
    _static(P, "async___rootErrorCallback$closure", 5, null, ["call$5"], ["_rootErrorCallback"], 32, 0);
    _static(P, "async___rootScheduleMicrotask$closure", 4, null, ["call$4"], ["_rootScheduleMicrotask"], 110, 0);
    _static(P, "async___rootCreateTimer$closure", 5, null, ["call$5"], ["_rootCreateTimer"], 111, 0);
    _static(P, "async___rootCreatePeriodicTimer$closure", 5, null, ["call$5"], ["_rootCreatePeriodicTimer"], 112, 0);
    _static(P, "async___rootPrint$closure", 4, null, ["call$4"], ["_rootPrint"], 37, 0);
    _static_1(P, "async___printToZone$closure", "_printToZone", 113);
    _static(P, "async___rootFork$closure", 5, null, ["call$5"], ["_rootFork"], 114, 0);
    var _;
    _instance_0_u(_ = P._BroadcastSubscription.prototype, "get$_onPause", "_onPause$0", 1);
    _instance_0_u(_, "get$_onResume", "_onResume$0", 1);
    _instance_1_i(_ = P._BroadcastStreamController.prototype, "get$add", "add$1", 11);
    _instance(_, "get$addError", 0, 1, null, ["call$2", "call$1"], ["addError$2", "addError$1"], 12, 0);
    _instance(P._AsyncCompleter.prototype, "get$complete", 0, 0, null, ["call$1", "call$0"], ["complete$1", "complete$0"], 47, 0);
    _instance(P._SyncCompleter.prototype, "get$complete", 0, 0, null, ["call$1", "call$0"], ["complete$1", "complete$0"], 47, 0);
    _instance(P._Future.prototype, "get$_completeError", 0, 1, null, ["call$2", "call$1"], ["_completeError$2", "_completeError$1"], 12, 0);
    _instance_1_i(_ = P._StreamController.prototype, "get$add", "add$1", 11);
    _instance(_, "get$addError", 0, 1, null, ["call$2", "call$1"], ["addError$2", "addError$1"], 12, 0);
    _instance_0_i(_, "get$close", "close$0", 14);
    _instance_1_u(_, "get$_add", "_add$1", 11);
    _instance_2_u(_, "get$_async$_addError", "_async$_addError$2", 70);
    _instance_0_u(_, "get$_close", "_close$0", 1);
    _instance_0_u(_ = P._ControllerSubscription.prototype, "get$_onPause", "_onPause$0", 1);
    _instance_0_u(_, "get$_onResume", "_onResume$0", 1);
    _instance_1_i(P._StreamSinkWrapper.prototype, "get$add", "add$1", 11);
    _instance_0_u(_ = P._BufferingStreamSubscription.prototype, "get$_onPause", "_onPause$0", 1);
    _instance_0_u(_, "get$_onResume", "_onResume$0", 1);
    _instance_0_u(P._DoneStreamSubscription.prototype, "get$_sendDone", "_sendDone$0", 1);
    _instance_1_i(P._LinkedHashSet.prototype, "get$contains", "contains$1", 26);
    _static_1(P, "core_Uri_decodeComponent$closure", "Uri_decodeComponent", 7);
    _instance_0_i(S.NullStreamSink.prototype, "get$close", "close$0", 14);
    _instance_0_u(_ = L.StreamGroup.prototype, "get$_onListen", "_onListen$0", 1);
    _instance_0_u(_, "get$_onCancelBroadcast", "_onCancelBroadcast$0", 1);
    _instance_1_i(M._DelegatingIterableBase.prototype, "get$contains", "contains$1", 26);
    _instance(D._DeepMatcher.prototype, "get$_recursiveMatch", 0, 4, null, ["call$4"], ["_recursiveMatch$4"], 58, 0);
    _static_1(Z, "pretty_print___escapeString$closure", "_escapeString", 7);
    _static_1(M, "util___getHexLiteral$closure", "_getHexLiteral", 7);
    _instance(Y.SourceSpanMixin.prototype, "get$message", 1, 1, null, ["call$2$color", "call$1"], ["message$2$color", "message$1"], 71, 0);
    _instance(_ = O.StackZoneSpecification.prototype, "get$_stack_zone_specification$_registerCallback", 0, 4, null, ["call$1$4", "call$4"], ["_stack_zone_specification$_registerCallback$1$4", "_stack_zone_specification$_registerCallback$4"], 35, 0);
    _instance(_, "get$_stack_zone_specification$_registerUnaryCallback", 0, 4, null, ["call$2$4", "call$4"], ["_stack_zone_specification$_registerUnaryCallback$2$4", "_stack_zone_specification$_registerUnaryCallback$4"], 33, 0);
    _instance(_, "get$_stack_zone_specification$_registerBinaryCallback", 0, 4, null, ["call$3$4", "call$4"], ["_stack_zone_specification$_registerBinaryCallback$3$4", "_stack_zone_specification$_registerBinaryCallback$4"], 63, 0);
    _instance(_, "get$_stack_zone_specification$_errorCallback", 0, 5, null, ["call$5"], ["_stack_zone_specification$_errorCallback$5"], 32, 0);
    _instance(_ = K._GuaranteeSink.prototype, "get$addError", 0, 1, null, ["call$2", "call$1"], ["addError$2", "addError$1"], 12, 0);
    _instance(_, "get$_addError", 0, 1, null, ["call$2", "call$1"], ["_addError$2", "_addError$1"], 66, 0);
    _instance_0_i(_, "get$close", "close$0", 13);
    _instance_0_u(D._MultiChannel.prototype, "get$_closeInnerChannel", "_closeInnerChannel$0", 1);
    _instance_0_u(_ = U.Invoker.prototype, "get$_invoker$_onRun", "_invoker$_onRun$0", 1);
    _instance_0_u(_, "get$_runTearDowns", "_runTearDowns$0", 13);
    _instance_0_u(V._LiveTest.prototype, "get$run", "run$0", 13);
    _instance_1_i(V.LiveTestController.prototype, "get$message", "message$1", 96);
    _instance_0_u(O.Engine.prototype, "get$run", "run$0", 31);
    _instance_1_u(_ = R.ExpandedReporter.prototype, "get$_onTestStarted", "_onTestStarted$1", 98);
    _instance_1_u(_, "get$_expanded$_onDone", "_expanded$_onDone$1", 99);
    _static_0(G, "main_test__main$closure", "main0", 34);
    _static(P, "math__max$closure", 2, null, ["call$1$2", "call$2"], ["max", function(a, b) {
      return P.max(a, b, type$.num);
    }], 76, 0);
  })();
  (function inheritance() {
    var _mixin = hunkHelpers.mixin,
      _inherit = hunkHelpers.inherit,
      _inheritMany = hunkHelpers.inheritMany;
    _inherit(P.Object, null);
    _inheritMany(P.Object, [H.JS_CONST, J.Interceptor, J.JSObject, J.ArrayIterator, P.Iterable, H.CastIterator, P.MapMixin, H.Closure, P._ListBase_Object_ListMixin, H.ListIterator, P.Iterator, H.ExpandIterator, H.EmptyIterator, H.FixedLengthListMixin, H.UnmodifiableListMixin, H.Symbol, H.ConstantMap, H.TypeErrorDecoder, P.Error, H.ExceptionAndStackTrace, H._StackTrace, H.LinkedHashMapCell, H.LinkedHashMapKeyIterator, H.JSSyntaxRegExp, H._MatchImplementation, H._AllMatchesIterator, H.StringMatch, H._StringAllMatchesIterator, H.Rti, H._FunctionParameters, H._Type, P._TimerImpl, P._AsyncAwaitCompleter, P.Stream, P._BufferingStreamSubscription, P._BroadcastStreamController, P.Future, P.TimeoutException, P.Completer, P._Completer, P._FutureListener, P._Future, P._AsyncCallbackEntry, P.StreamSubscription, P.StreamTransformerBase, P._StreamController, P._SyncStreamControllerDispatch, P._AsyncStreamControllerDispatch, P._StreamSinkWrapper, P._AddStreamState, P._PendingEvents, P._DelayedEvent, P._DelayedDone, P._DoneStreamSubscription, P._StreamIterator, P.Timer, P.AsyncError, P._ZoneFunction, P.ZoneSpecification, P._ZoneSpecification, P.ZoneDelegate, P.Zone, P._ZoneDelegate, P._Zone, P._HashMapKeyIterator, P._SetBase, P._LinkedHashSetCell, P._LinkedHashSetIterator, P.ListMixin, P._UnmodifiableMapMixin, P.MapView, P._ListQueueIterator, P.SetMixin, P._SetBase_Object_SetMixin, P.Codec, P._Utf8Encoder, P._Utf8Decoder, P.bool, P.DateTime, P.num, P.Duration, P.OutOfMemoryError, P.StackOverflowError, P._Exception, P.FormatException, P.Expando, P.Function, P.List, P.Map, P.MapEntry, P.Null, P.Pattern, P.Match, P.RegExpMatch, P.StackTrace, P._StringStackTrace, P.Stopwatch, P.String, P.RuneIterator, P.StringBuffer, P.Uri, P._Uri, P.UriData, P._SimpleUri, W.EventStreamProvider, P._StructuredClone, P._AcceptStructuredClone, P.ByteBuffer, P.ByteData, P.Int8List, P.Uint8List, P.Uint8ClampedList, P.Int16List, P.Uint16List, P.Int32List, P.Uint32List, P.Float32List, P.Float64List, S.AsyncMemoizer, O.DelegatingSink, Y.DelegatingStreamSubscription, F.FutureGroup, S.NullStreamSink, V.ErrorResult, E.Result, F.ValueResult, Y.StreamCompleter, L.StreamGroup, L._StreamGroupState, G.StreamQueue, G._EventRequest, G._NextRequest, G._RestRequest, T.StreamSinkCompleter, T._CompleterSink, X.BooleanSelector, X.All, U.VariableNode, U.NotNode, U.OrNode, U.AndNode, U.ConditionalNode, T.Evaluator, Y.BooleanSelectorImpl, R.IntersectionSelector, O.None, G.Parser, O.Scanner, L.Token, L.IdentifierToken, L.TokenType, B.RecursiveVisitor, Q._QueueList_Object_ListMixin, Y.UnionSetController, M._DelegatingIterableBase, L.UnmodifiableSetMixin, G.Matcher, E.StringDescription, F.PackageConfigResolver, D.PackageRootResolver, M.Context, M._PathDirection, M._PathRelation, O.Style, X.ParsedPath, X.PathException, O.Pool, O.PoolResource, T.Mapping, T.TargetLineEntry, T.TargetEntry, T._MappingTokenizer, T._TokenKind, Y.SourceSpanMixin, Y.SourceFile, D.SourceLocationMixin, U.Highlighter, V.SourceLocation, V.SourceSpan, G.SourceSpanException, U.Chain, A.Frame, X.LazyChain, T.LazyTrace, O.StackZoneSpecification, O._Node, Y.Trace, N.UnparsedFrame, R.StreamChannelMixin, K._GuaranteeSink, N.StreamChannelCompleter, B.StreamChannelController, R.StreamChannel, X.StringScanner, S._SpanScannerState, A.AsciiGlyphSet, K.UnicodeGlyphSet, K.ClosedException, X.Declarer, O.Group, V.GroupEntry, V.Test, U.Invoker, U._AsyncCounter, Z.LiveTest, V.LiveTestController, D.Message, D.MessageType, O.Metadata, N.OperatingSystem, E.PlatformSelector, B.Runtime, U.StackTraceFormatter, G.State, G.Status, G.Result0, U.Suite, E.SuitePlatform, G.TestFailure, R.Timeout, S.RemoteListener, N.SuiteChannelManager, E.StackTraceMapper, O.Engine, E.LiveSuite, B.LiveSuiteController, R.ExpandedReporter, Y.RunnerSuiteController, T.RuntimeSelection, U.SuiteConfiguration, X.PrintSink]);
    _inheritMany(J.Interceptor, [J.JSBool, J.JSNull, J.JavaScriptObject, J.JSArray, J.JSNumber, J.JSString, H.NativeByteBuffer, H.NativeTypedData, W.Event, W.Blob, W.DomError, W.DomException, W.EventTarget, W.Location, W.MediaError, W.NavigatorUserMediaError, W.OverconstrainedError, W.PositionError, P.SqlError]);
    _inheritMany(J.JavaScriptObject, [J.PlainJavaScriptObject, J.UnknownJavaScriptObject, J.JavaScriptFunction]);
    _inherit(J.JSUnmodifiableArray, J.JSArray);
    _inheritMany(J.JSNumber, [J.JSInt, J.JSDouble]);
    _inheritMany(P.Iterable, [H._CastIterableBase, H.EfficientLengthIterable, H.MappedIterable, H.WhereIterable, H.ExpandIterable, H.SkipWhileIterable, H._ConstantMapKeyIterable, P.IterableBase, H._StringAllMatchesIterable, P.Runes]);
    _inherit(H.CastIterable, H._CastIterableBase);
    _inherit(H._EfficientLengthCastIterable, H.CastIterable);
    _inherit(P.MapBase, P.MapMixin);
    _inheritMany(P.MapBase, [H.CastMap, H.JsLinkedHashMap, P._HashMap, P._JsonMap]);
    _inheritMany(H.Closure, [H.CastMap_forEach_closure, H.ConstantMap_map_closure, H.Instantiation, H.Primitives_initTicker_closure, H.unwrapException_saveStackTrace, H.TearOffClosure, H.JsLinkedHashMap_values_closure, H.JsLinkedHashMap_addAll_closure, H.initHooks_closure, H.initHooks_closure0, H.initHooks_closure1, P._AsyncRun__initializeScheduleImmediate_internalCallback, P._AsyncRun__initializeScheduleImmediate_closure, P._AsyncRun__scheduleImmediateJsOverride_internalCallback, P._AsyncRun__scheduleImmediateWithSetImmediate_internalCallback, P._TimerImpl_internalCallback, P._TimerImpl$periodic_closure, P._awaitOnObject_closure, P._awaitOnObject_closure0, P._wrapJsFunctionForAsync_closure, P._SyncBroadcastStreamController__sendData_closure, P._SyncBroadcastStreamController__sendError_closure, P._SyncBroadcastStreamController__sendDone_closure, P.Future_Future_closure, P.Future_Future$microtask_closure, P.Future_wait_handleError, P.Future_wait_closure, P.Future_forEach_closure, P.Future_doWhile_closure, P._Future__addListener_closure, P._Future__prependListeners_closure, P._Future__chainForeignFuture_closure, P._Future__chainForeignFuture_closure0, P._Future__chainForeignFuture_closure1, P._Future__asyncComplete_closure, P._Future__chainFuture_closure, P._Future__asyncCompleteError_closure, P._Future__propagateToListeners_handleWhenCompleteCallback, P._Future__propagateToListeners_handleWhenCompleteCallback_closure, P._Future__propagateToListeners_handleValueCallback, P._Future__propagateToListeners_handleError, P.Stream_Stream$fromFuture_closure, P.Stream_Stream$fromFuture_closure0, P.Stream_Stream$fromIterable_closure, P.Stream_pipe_closure, P.Stream_length_closure, P.Stream_length_closure0, P.Stream_first_closure, P.Stream_first_closure0, P.Stream_last_closure, P.Stream_last_closure0, P.Stream_firstWhere_closure, P.Stream_firstWhere__closure, P.Stream_firstWhere__closure0, P.Stream_firstWhere_closure0, P._StreamController__subscribe_closure, P._StreamController__recordCancel_complete, P._AddStreamState_makeErrorHandler_closure, P._AddStreamState_cancel_closure, P._BufferingStreamSubscription__sendError_sendError, P._BufferingStreamSubscription__sendDone_sendDone, P._PendingEvents_schedule_closure, P._cancelAndError_closure, P._cancelAndErrorClosure_closure, P._cancelAndValue_closure, P._CustomZone_bindCallback_closure, P._CustomZone_bindUnaryCallback_closure, P._CustomZone_bindCallbackGuarded_closure, P._CustomZone_bindUnaryCallbackGuarded_closure, P._rootHandleUncaughtError_closure, P._RootZone_bindCallback_closure, P._RootZone_bindCallbackGuarded_closure, P._RootZone_bindUnaryCallbackGuarded_closure, P.runZoned_closure, P.HashMap_HashMap$from_closure, P.LinkedHashMap_LinkedHashMap$from_closure, P.MapBase_mapToString_closure, P.Duration_toString_sixDigits, P.Duration_toString_twoDigits, P.Uri__parseIPv4Address_error, P.Uri_parseIPv6Address_error, P.Uri_parseIPv6Address_parseHex, P._Uri__Uri$notSimple_closure, P._Uri__checkNonWindowsPathReservedCharacters_closure, P._Uri__makePath_closure, P._createTables_closure, P._createTables_build, P._createTables_setChars, P._createTables_setRange, W._EventStreamSubscription_closure, P._StructuredClone_walk_closure, P._StructuredClone_walk_closure0, P._AcceptStructuredClone_walk_closure, P._convertDataTree__convert, P.promiseToFuture_closure, P.promiseToFuture_closure0, F.FutureGroup_add_closure, F.FutureGroup_add_closure0, S.NullStreamSink_addStream_closure, L.StreamGroup_add_closure, L.StreamGroup_add_closure0, L.StreamGroup__onListen_closure, L.StreamGroup__onCancelBroadcast_closure, L.StreamGroup__listenToStream_closure, G.StreamQueue__ensureListening_closure, G.StreamQueue__ensureListening_closure1, G.StreamQueue__ensureListening_closure0, T._CompleterSink__setDestinationSink_closure, T._CancelOnErrorSubscriptionWrapper_onError_closure, T._CancelOnErrorSubscriptionWrapper_onError__closure, Y.mapMap_closure, Y.mapMap_closure0, Y.mergeMaps_closure, M.UnionSet_length_closure, M.UnionSet__iterable_closure, D._DeepMatcher__compareSets_closure, Z.prettyPrint__prettyPrint, Z.prettyPrint__prettyPrint_pp, Z.prettyPrint__prettyPrint_closure, Z.prettyPrint__prettyPrint_closure0, Z.prettyPrint__prettyPrint_closure1, M.wrapMatcher_closure, M.escape_closure, F.PackageConfigResolver__normalizeMap_closure, M.Context_join_closure, M.Context_joinAll_closure, M.Context_split_closure, M._validateArgList_closure, X.ParsedPath_normalize_closure, L.WindowsStyle_absolutePathToUri_closure, O.Pool_close_closure, O.Pool__onResourceReleaseAllowed_closure, O.Pool__runOnRelease_closure, O.Pool__runOnRelease_closure0, O.mapStackTrace_closure, O.mapStackTrace_closure0, O.mapStackTrace_closure1, O._prettifyMember_closure, O._prettifyMember_closure0, T.SingleMapping$fromJson_closure, T.SingleMapping__findLine_closure, T.SingleMapping__findColumn_closure, L.closure, U.Highlighter__writeFirstLine_closure, U.Highlighter__writeFirstLine_closure0, U.Highlighter__writeFirstLine_closure1, U.Highlighter__writeFirstLine_closure2, U.Highlighter__writeIntermediateLines_closure, U.Highlighter__writeLastLine_closure, U.Highlighter__writeLastLine_closure0, U.Highlighter__writeLastLine_closure1, U.Highlighter__writeSidebar_closure, U.Chain_capture_closure, U.Chain_Chain$current_closure, U.Chain_Chain$forTrace_closure, U.Chain_Chain$parse_closure, U.Chain_Chain$parse_closure0, U.Chain_foldFrames_closure, U.Chain_foldFrames_closure0, U.Chain_toTrace_closure, U.Chain_toString_closure0, U.Chain_toString__closure0, U.Chain_toString_closure, U.Chain_toString__closure, A.Frame_Frame$parseVM_closure, A.Frame_Frame$parseV8_closure, A.Frame_Frame$parseV8_closure_parseLocation, A.Frame_Frame$parseFirefox_closure, A.Frame_Frame$parseFriendly_closure, X.LazyChain_foldFrames_closure, X.LazyChain_toTrace_closure, T.LazyTrace_foldFrames_closure, O.StackZoneSpecification_chainFor_closure, O.StackZoneSpecification_chainFor_closure0, O.StackZoneSpecification__registerCallback_closure, O.StackZoneSpecification__registerUnaryCallback_closure, O.StackZoneSpecification__registerUnaryCallback__closure, O.StackZoneSpecification__registerBinaryCallback_closure, O.StackZoneSpecification__registerBinaryCallback__closure, O.StackZoneSpecification__currentTrace_closure, Y.Trace_Trace$current_closure, Y.Trace_Trace$from_closure, Y.Trace__parseVM_closure, Y.Trace$parseV8_closure, Y.Trace$parseV8_closure0, Y.Trace$parseJSCore_closure, Y.Trace$parseJSCore_closure0, Y.Trace$parseFirefox_closure, Y.Trace$parseFirefox_closure0, Y.Trace$parseFriendly_closure, Y.Trace$parseFriendly_closure0, Y.Trace_foldFrames_closure, Y.Trace_foldFrames_closure0, Y.Trace_toString_closure0, Y.Trace_toString_closure, K.GuaranteeChannel_closure, K.GuaranteeChannel__closure, K._GuaranteeSink__addError_closure, K._GuaranteeSink_addStream_closure, D._MultiChannel_closure, D._MultiChannel_closure0, D._MultiChannel_closure1, D._MultiChannel__closure, D._MultiChannel_virtualChannel_closure, D._MultiChannel_virtualChannel_closure0, L.internalBootstrapBrowserTest_closure, N.postMessageChannel_closure, N.postMessageChannel_closure0, N.postMessageChannel__closure, N.postMessageChannel__closure0, N.postMessageChannel__closure1, X.Declarer_test_closure, X.Declarer_test__closure, X.Declarer_test___closure, X.Declarer_group_closure, X.Declarer_build_closure, X.Declarer__runSetUps_closure, X.Declarer__tearDownAll_closure, X.Declarer__tearDownAll__closure, X.Declarer__tearDownAll___closure, O.Group_forPlatform_closure, O.Group__map_closure, O.Group__map_closure0, U.Invoker_guard_closure, U.Invoker_guard__closure, U.Invoker_waitForOutstandingCallbacks_closure, U.Invoker_waitForOutstandingCallbacks_closure0, U.Invoker_heartbeat_message, U.Invoker_heartbeat_closure, U.Invoker_heartbeat__closure, U.Invoker__handleError_closure, U.Invoker__handleError_closure0, U.Invoker__onRun_closure, U.Invoker__onRun__closure, U.Invoker__onRun___closure, U.Invoker__onRun____closure, U.Invoker__onRun___closure0, O.Metadata_Metadata__unresolved, O.Metadata_Metadata_closure, O.Metadata$deserialize_closure, O.Metadata__validateTags_closure, O.Metadata__validateTags_closure0, O.Metadata_validatePlatformSelectors_closure, O.Metadata_merge_closure, O.Metadata_merge_closure0, O.Metadata_forPlatform_closure, O.Metadata_serialize_closure, O.Metadata_serialize_closure0, N.OperatingSystem_find_closure, N.OperatingSystem_find_closure0, E.PlatformSelector$parse_closure, E.PlatformSelector_validate_closure, E.PlatformSelector_validate__closure, E.PlatformSelector_evaluate_closure, B.Runtime_Runtime$deserialize_closure, U.StackTraceFormatter_formatStackTrace_closure, G._expect_closure0, G._expect_closure, S.RemoteListener_start_closure, S.RemoteListener_start_closure0, S.RemoteListener_start_closure1, S.RemoteListener_start__closure, S.RemoteListener_start___closure, S.RemoteListener_start____closure, S.RemoteListener_start____closure0, S.RemoteListener_start_____closure, S.RemoteListener_start___closure0, S.RemoteListener__serializeGroup_closure, S.RemoteListener__serializeTest_closure, S.RemoteListener__runLiveTest_closure, S.RemoteListener__runLiveTest_closure0, S.RemoteListener__runLiveTest_closure1, S.RemoteListener__runLiveTest_closure2, S.RemoteListener__runLiveTest_closure3, S.RemoteListener__runLiveTest__closure, V.errorsDontStopTest_closure, V.errorsDontStopTest_closure0, B.closure0, O.Engine_success_closure, O.Engine_closure, O.Engine_closure0, O.Engine_run_closure, O.Engine_run__closure, O.Engine_run___closure, O.Engine_run____closure, O.Engine_run_closure0, O.Engine__runLiveTest_closure, O.Engine__runLiveTest_closure0, O.Engine__runLiveTest_closure1, O.Engine__runSkippedTest_closure, O.Engine__runSkippedTest_closure0, O.Engine__runSkippedTest_closure1, B.LiveSuiteController_closure, B.LiveSuiteController_closure0, B.LiveSuiteController_reportLiveTest_closure, B.LiveSuiteController_close_closure, R.ExpandedReporter__onTestStarted_closure, R.ExpandedReporter__onTestStarted_closure0, R.ExpandedReporter__onTestStarted_closure1, Y.RunnerSuiteController__close_closure, E.JSStackTraceMapper__deserializePackageConfigMap_closure, R._declarer_closure, R._declarer__closure, G.main_closure0, G.main__closure, R.main_closure]);
    _inherit(P.ListBase, P._ListBase_Object_ListMixin);
    _inherit(H.UnmodifiableListBase, P.ListBase);
    _inheritMany(H.UnmodifiableListBase, [H.CodeUnits, P.UnmodifiableListView]);
    _inheritMany(H.EfficientLengthIterable, [H.ListIterable, H.LinkedHashMapKeyIterable, P._HashMapKeyIterable, P.Set]);
    _inheritMany(H.ListIterable, [H.SubListIterable, H.MappedListIterable, H.ReversedListIterable, P.ListQueue, P._JsonMapKeyIterable]);
    _inherit(H.EfficientLengthMappedIterable, H.MappedIterable);
    _inheritMany(P.Iterator, [H.MappedIterator, H.WhereIterator, H.SkipWhileIterator]);
    _inherit(H.ConstantStringMap, H.ConstantMap);
    _inherit(H.Instantiation1, H.Instantiation);
    _inheritMany(P.Error, [H.NullError, H.JsNoSuchMethodError, H.UnknownJsTypeError, H.TypeErrorImplementation, H.RuntimeError, P.AssertionError, H._Error, P.NullThrownError, P.ArgumentError, P.UnsupportedError, P.UnimplementedError, P.StateError, P.ConcurrentModificationError, P.CyclicInitializationError]);
    _inheritMany(H.TearOffClosure, [H.StaticClosure, H.BoundClosure]);
    _inherit(H._AssertionError, P.AssertionError);
    _inheritMany(P.IterableBase, [H._AllMatchesIterable, O.EmptyUnmodifiableSet]);
    _inheritMany(H.NativeTypedData, [H.NativeByteData, H.NativeTypedArray]);
    _inheritMany(H.NativeTypedArray, [H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin, H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin]);
    _inherit(H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin, H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin);
    _inherit(H.NativeTypedArrayOfDouble, H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin);
    _inherit(H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin, H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin);
    _inherit(H.NativeTypedArrayOfInt, H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin);
    _inheritMany(H.NativeTypedArrayOfDouble, [H.NativeFloat32List, H.NativeFloat64List]);
    _inheritMany(H.NativeTypedArrayOfInt, [H.NativeInt16List, H.NativeInt32List, H.NativeInt8List, H.NativeUint16List, H.NativeUint32List, H.NativeUint8ClampedList, H.NativeUint8List]);
    _inheritMany(H._Error, [H._CastError, H._TypeError]);
    _inheritMany(P.Stream, [P._StreamImpl, P._EmptyStream, W._EventStream, Y._CompleterStream, T.SubscriptionStream]);
    _inheritMany(P._StreamImpl, [P._ControllerStream, P._GeneratedStreamImpl]);
    _inherit(P._BroadcastStream, P._ControllerStream);
    _inherit(P._ControllerSubscription, P._BufferingStreamSubscription);
    _inherit(P._BroadcastSubscription, P._ControllerSubscription);
    _inheritMany(P._BroadcastStreamController, [P._SyncBroadcastStreamController, P._AsyncBroadcastStreamController]);
    _inheritMany(P._Completer, [P._AsyncCompleter, P._SyncCompleter]);
    _inheritMany(P._StreamController, [P._AsyncStreamController, P._SyncStreamController]);
    _inherit(P._StreamControllerAddStreamState, P._AddStreamState);
    _inheritMany(P._PendingEvents, [P._IterablePendingEvents, P._StreamImplEvents]);
    _inheritMany(P._DelayedEvent, [P._DelayedData, P._DelayedError]);
    _inheritMany(P._Zone, [P._CustomZone, P._RootZone]);
    _inherit(P._IdentityHashMap, P._HashMap);
    _inherit(P._LinkedHashSet, P._SetBase);
    _inherit(P._UnmodifiableMapView_MapView__UnmodifiableMapMixin, P.MapView);
    _inherit(P.UnmodifiableMapView, P._UnmodifiableMapView_MapView__UnmodifiableMapMixin);
    _inherit(P.SetBase, P._SetBase_Object_SetMixin);
    _inheritMany(P.Codec, [P.Encoding, P.Base64Codec, P._FusedCodec, P.JsonCodec]);
    _inheritMany(P.Encoding, [P.AsciiCodec, P.Utf8Codec]);
    _inherit(P.Converter, P.StreamTransformerBase);
    _inheritMany(P.Converter, [P._UnicodeSubsetEncoder, P.Base64Encoder, P.JsonDecoder, P.Utf8Encoder, P.Utf8Decoder]);
    _inherit(P.AsciiEncoder, P._UnicodeSubsetEncoder);
    _inheritMany(P.num, [P.double, P.int]);
    _inheritMany(P.ArgumentError, [P.RangeError, P.IndexError]);
    _inherit(P._DataUri, P._Uri);
    _inheritMany(W.Event, [W.ApplicationCacheErrorEvent, W.ErrorEvent, W.MediaKeyMessageEvent, W.MessageEvent, W.PresentationConnectionCloseEvent, W.SpeechRecognitionError]);
    _inherit(W.File, W.Blob);
    _inherit(W.MessagePort, W.EventTarget);
    _inherit(W._EventStreamSubscription, P.StreamSubscription);
    _inherit(P._StructuredCloneDart2Js, P._StructuredClone);
    _inherit(P._AcceptStructuredCloneDart2Js, P._AcceptStructuredClone);
    _inherit(T._CancelOnErrorSubscriptionWrapper, Y.DelegatingStreamSubscription);
    _inherit(S.Validator, B.RecursiveVisitor);
    _inherit(Q.QueueList, Q._QueueList_Object_ListMixin);
    _inherit(M._UnionSet_SetBase_UnmodifiableSetMixin, P.SetBase);
    _inherit(M.UnionSet, M._UnionSet_SetBase_UnmodifiableSetMixin);
    _inherit(M.DelegatingIterable, M._DelegatingIterableBase);
    _inherit(M.DelegatingSet, M.DelegatingIterable);
    _inherit(L._UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin, M.DelegatingSet);
    _inherit(L.UnmodifiableSetView, L._UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin);
    _inheritMany(G.Matcher, [Y._IsTrue, M.TypeMatcher, D._DeepMatcher]);
    _inherit(E.FeatureMatcher, M.TypeMatcher);
    _inheritMany(E.FeatureMatcher, [Y._Predicate, D._StringEqualsMatcher]);
    _inherit(B.InternalStyle, O.Style);
    _inheritMany(B.InternalStyle, [E.PosixStyle, F.UrlStyle, L.WindowsStyle]);
    _inheritMany(T.Mapping, [T.MultiSectionMapping, T.MappingBundle, T.SingleMapping]);
    _inheritMany(Y.SourceSpanMixin, [V.SourceSpanBase, Y._FileSpan]);
    _inheritMany(V.SourceSpanBase, [G.SourceMapSpan, X.SourceSpanWithContext]);
    _inherit(Y.FileLocation, D.SourceLocationMixin);
    _inherit(G.SourceSpanFormatException, G.SourceSpanException);
    _inheritMany(R.StreamChannelMixin, [K.GuaranteeChannel, D._MultiChannel, D.VirtualChannel, R._StreamChannel]);
    _inherit(E.StringScannerException, G.SourceSpanFormatException);
    _inherit(S.SpanScanner, X.StringScanner);
    _inherit(U.LocalTest, V.Test);
    _inherit(V._LiveTest, Z.LiveTest);
    _inherit(O._IterableSet_SetMixin_UnmodifiableSetMixin, P.SetMixin);
    _inherit(O.IterableSet, O._IterableSet_SetMixin_UnmodifiableSetMixin);
    _inherit(B._LiveSuite, E.LiveSuite);
    _inherit(Y.RunnerSuite, U.Suite);
    _inherit(E.JSStackTraceMapper, E.StackTraceMapper);
    _mixin(H.UnmodifiableListBase, H.UnmodifiableListMixin);
    _mixin(H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin, P.ListMixin);
    _mixin(H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin, H.FixedLengthListMixin);
    _mixin(H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin, P.ListMixin);
    _mixin(H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin, H.FixedLengthListMixin);
    _mixin(P._AsyncStreamController, P._AsyncStreamControllerDispatch);
    _mixin(P._SyncStreamController, P._SyncStreamControllerDispatch);
    _mixin(P._ListBase_Object_ListMixin, P.ListMixin);
    _mixin(P._SetBase_Object_SetMixin, P.SetMixin);
    _mixin(P._UnmodifiableMapView_MapView__UnmodifiableMapMixin, P._UnmodifiableMapMixin);
    _mixin(Q._QueueList_Object_ListMixin, P.ListMixin);
    _mixin(M._UnionSet_SetBase_UnmodifiableSetMixin, L.UnmodifiableSetMixin);
    _mixin(L._UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin, L.UnmodifiableSetMixin);
    _mixin(O._IterableSet_SetMixin_UnmodifiableSetMixin, L.UnmodifiableSetMixin);
  })();
  var init = {typeUniverse: {eC: new Map(), tR: {}, eT: {}, tPV: {}, sEA: []}, mangledGlobalNames: {int: "int", double: "double", num: "num", String: "String", bool: "bool", Null: "Null", List: "List"}, mangledNames: {}, getTypeFromName: getGlobalFromName, metadata: [], types: ["Null()", "~()", "Future<Null>()", "Null(@)", "bool(String)", "Null(@,StackTrace)", "Null(@,@)", "String(String)", "Trace()", "bool(@)", "Frame(String)", "~(Object)", "~(Object[StackTrace])", "Future<~>()", "Future<@>()", "~(@)", "Chain()", "Frame()", "@(@)", "Null(PlatformSelector,Metadata)", "~(~())", "bool(Frame)", "GroupEntry(GroupEntry)", "Null(State)", "String(Match)", "String(int)", "bool(Object)", "Null(Message)", "Null(Zone,ZoneDelegate,Zone,Object,StackTrace)", "Null(MessageEvent)", "Null(String)", "Future<bool>()", "AsyncError(Zone,ZoneDelegate,Zone,Object,StackTrace)", "0^(1^)(Zone,ZoneDelegate,Zone,0^(1^))<Object,Object>", "@()", "0^()(Zone,ZoneDelegate,Zone,0^())<Object>", "int()", "~(Zone,ZoneDelegate,Zone,String)", "String(Frame)", "int(Frame)", "String(@)", "~(Uint8List,String,int)", "Trace(String)", "Null(bool)", "Metadata(Metadata,Metadata)", "Trace(Trace)", "Frame(Frame)", "~([Object])", "Null(List<@>)", "bool()", "Future<List<@>>()", "Uri(@,@)", "bool(Trace)", "List<Frame>(Trace)", "int(Trace)", "String(@,int,Set<@>,bool)", "String(Trace)", "bool(Pattern[int])", "List<String>(Object,Object,String,int)", "Frame(@,@)", "@(@,@)", "@(Event)", "Uint8List(@,@)", "0^(1^,2^)(Zone,ZoneDelegate,Zone,Function)<Object,Object,Object>", "Uint8List(int)", "int(int,int)", "~(@[StackTrace])", "~(String[@])", "~(String,int)", "bool(MessageEvent)", "~(Object,StackTrace)", "String(String{color:@})", "bool(GroupEntry)", "Future<@>(@)", "String()", "_Future<@>(@)", "0^(0^,0^)<num>", "Metadata()", "Metadata(Metadata,BooleanSelector)", "MapEntry<BooleanSelector,Metadata>(@,@)", "Null(@[StackTrace])", "bool/()", "MapEntry<String,Map<String,@>>(BooleanSelector,Metadata)", "bool(OperatingSystem)", "BooleanSelector()", "bool(Runtime)", "String(@,Matcher,String,Map<@,@>,bool)", "Null(Zone,ZoneDelegate,Zone,String)", "Map<@,@>(GroupEntry)", "Null(int,@)", "Null(AsyncError)", "Null(~())", "~(~)", "Map<String,int>()", "@(String)", "bool(LiveTest)", "~(Message)", "Null(RunnerSuite)", "~(LiveTest)", "~(bool)", "~(State)", "~(AsyncError)", "MapEntry<String,Uri>(String,String)", "@()()", "@(@,String)", "~(Zone,ZoneDelegate,Zone,@,StackTrace)", "0^(Zone,ZoneDelegate,Zone,0^())<Object>", "0^(Zone,ZoneDelegate,Zone,0^(1^),1^)<Object,Object>", "0^(Zone,ZoneDelegate,Zone,0^(1^,2^),1^,2^)<Object,Object,Object>", "0^(1^,2^)(Zone,ZoneDelegate,Zone,0^(1^,2^))<Object,Object,Object>", "~(Zone,ZoneDelegate,Zone,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~(Timer))", "~(String)", "Zone(Zone,ZoneDelegate,Zone,ZoneSpecification,Map<@,@>)", "OperatingSystem()"], interceptorsByTag: null, leafTags: null};
  H._Universe_addRules(init.typeUniverse, JSON.parse('{"JavaScriptFunction":"JavaScriptObject","PlainJavaScriptObject":"JavaScriptObject","UnknownJavaScriptObject":"JavaScriptObject","AbortPaymentEvent":"Event","ExtendableEvent":"Event","Window":"EventTarget","JSBool":{"bool":[]},"JSNull":{"Null":[]},"JavaScriptObject":{"JSObject":[],"Function":[]},"JSArray":{"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"JSUnmodifiableArray":{"JSArray":["1"],"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"ArrayIterator":{"Iterator":["1"]},"JSNumber":{"double":[],"num":[]},"JSInt":{"int":[],"double":[],"num":[]},"JSDouble":{"double":[],"num":[]},"JSString":{"String":[],"Pattern":[]},"_CastIterableBase":{"Iterable":["2"]},"CastIterator":{"Iterator":["2"]},"CastIterable":{"_CastIterableBase":["1","2"],"Iterable":["2"],"Iterable.E":"2"},"_EfficientLengthCastIterable":{"CastIterable":["1","2"],"EfficientLengthIterable":["2"],"_CastIterableBase":["1","2"],"Iterable":["2"],"Iterable.E":"2"},"CastMap":{"MapMixin":["3","4"],"Map":["3","4"],"MapMixin.K":"3","MapMixin.V":"4"},"CodeUnits":{"UnmodifiableListMixin":["int"],"ListMixin":["int"],"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"],"ListMixin.E":"int","UnmodifiableListMixin.E":"int"},"EfficientLengthIterable":{"Iterable":["1"]},"ListIterable":{"EfficientLengthIterable":["1"],"Iterable":["1"]},"SubListIterable":{"ListIterable":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1","ListIterable.E":"1"},"ListIterator":{"Iterator":["1"]},"MappedIterable":{"Iterable":["2"],"Iterable.E":"2"},"EfficientLengthMappedIterable":{"MappedIterable":["1","2"],"EfficientLengthIterable":["2"],"Iterable":["2"],"Iterable.E":"2"},"MappedIterator":{"Iterator":["2"]},"MappedListIterable":{"ListIterable":["2"],"EfficientLengthIterable":["2"],"Iterable":["2"],"Iterable.E":"2","ListIterable.E":"2"},"WhereIterable":{"Iterable":["1"],"Iterable.E":"1"},"WhereIterator":{"Iterator":["1"]},"ExpandIterable":{"Iterable":["2"],"Iterable.E":"2"},"ExpandIterator":{"Iterator":["2"]},"SkipWhileIterable":{"Iterable":["1"],"Iterable.E":"1"},"SkipWhileIterator":{"Iterator":["1"]},"EmptyIterator":{"Iterator":["1"]},"UnmodifiableListBase":{"UnmodifiableListMixin":["1"],"ListMixin":["1"],"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"ReversedListIterable":{"ListIterable":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1","ListIterable.E":"1"},"ConstantMap":{"Map":["1","2"]},"ConstantStringMap":{"ConstantMap":["1","2"],"Map":["1","2"]},"_ConstantMapKeyIterable":{"Iterable":["1"],"Iterable.E":"1"},"Instantiation":{"Closure":[],"Function":[]},"Instantiation1":{"Closure":[],"Function":[]},"NullError":{"NoSuchMethodError":[],"Error":[]},"JsNoSuchMethodError":{"NoSuchMethodError":[],"Error":[]},"UnknownJsTypeError":{"Error":[]},"_StackTrace":{"StackTrace":[]},"Closure":{"Function":[]},"TearOffClosure":{"Closure":[],"Function":[]},"StaticClosure":{"Closure":[],"Function":[]},"BoundClosure":{"Closure":[],"Function":[]},"TypeErrorImplementation":{"Error":[]},"RuntimeError":{"Error":[]},"_AssertionError":{"Error":[]},"JsLinkedHashMap":{"LinkedHashMap":["1","2"],"MapMixin":["1","2"],"Map":["1","2"],"MapMixin.K":"1","MapMixin.V":"2"},"LinkedHashMapKeyIterable":{"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1"},"LinkedHashMapKeyIterator":{"Iterator":["1"]},"JSSyntaxRegExp":{"RegExp":[],"Pattern":[]},"_MatchImplementation":{"RegExpMatch":[],"Match":[]},"_AllMatchesIterable":{"Iterable":["RegExpMatch"],"Iterable.E":"RegExpMatch"},"_AllMatchesIterator":{"Iterator":["RegExpMatch"]},"StringMatch":{"Match":[]},"_StringAllMatchesIterable":{"Iterable":["Match"],"Iterable.E":"Match"},"_StringAllMatchesIterator":{"Iterator":["Match"]},"NativeByteBuffer":{"ByteBuffer":[]},"NativeByteData":{"NativeTypedData":[]},"NativeTypedArray":{"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[]},"NativeTypedArrayOfDouble":{"ListMixin":["double"],"JavaScriptIndexingBehavior":["@"],"List":["double"],"NativeTypedData":[],"EfficientLengthIterable":["double"],"FixedLengthListMixin":["double"],"Iterable":["double"]},"NativeTypedArrayOfInt":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"]},"NativeFloat32List":{"ListMixin":["double"],"JavaScriptIndexingBehavior":["@"],"List":["double"],"NativeTypedData":[],"EfficientLengthIterable":["double"],"FixedLengthListMixin":["double"],"Iterable":["double"],"ListMixin.E":"double"},"NativeFloat64List":{"ListMixin":["double"],"JavaScriptIndexingBehavior":["@"],"List":["double"],"NativeTypedData":[],"EfficientLengthIterable":["double"],"FixedLengthListMixin":["double"],"Iterable":["double"],"ListMixin.E":"double"},"NativeInt16List":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeInt32List":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeInt8List":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeUint16List":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeUint32List":{"Uint32List":[],"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeUint8ClampedList":{"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"NativeUint8List":{"Uint8List":[],"ListMixin":["int"],"List":["int"],"JavaScriptIndexingBehavior":["@"],"NativeTypedData":[],"EfficientLengthIterable":["int"],"FixedLengthListMixin":["int"],"Iterable":["int"],"ListMixin.E":"int"},"_Type":{"Type":[]},"_Error":{"Error":[]},"_CastError":{"Error":[]},"_TypeError":{"Error":[]},"_TimerImpl":{"Timer":[]},"_AsyncAwaitCompleter":{"Completer":["1"]},"_BroadcastStream":{"_ControllerStream":["1"],"_StreamImpl":["1"],"Stream":["1"],"Stream.T":"1"},"_BroadcastSubscription":{"_ControllerSubscription":["1"],"_BufferingStreamSubscription":["1"],"_EventDispatch":["1"],"StreamSubscription":["1"],"_BufferingStreamSubscription.T":"1"},"_BroadcastStreamController":{"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_SyncBroadcastStreamController":{"_BroadcastStreamController":["1"],"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_AsyncBroadcastStreamController":{"_BroadcastStreamController":["1"],"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"TimeoutException":{"Exception":[]},"_Completer":{"Completer":["1"]},"_AsyncCompleter":{"_Completer":["1"],"Completer":["1"]},"_SyncCompleter":{"_Completer":["1"],"Completer":["1"]},"_Future":{"Future":["1"]},"StreamTransformerBase":{"StreamTransformer":["1","2"]},"_StreamController":{"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_AsyncStreamController":{"_AsyncStreamControllerDispatch":["1"],"_StreamController":["1"],"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_SyncStreamController":{"_SyncStreamControllerDispatch":["1"],"_StreamController":["1"],"StreamController":["1"],"StreamSink":["1"],"EventSink":["1"],"_EventDispatch":["1"],"_StreamControllerLifecycle":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_ControllerStream":{"_StreamImpl":["1"],"Stream":["1"],"Stream.T":"1"},"_ControllerSubscription":{"_BufferingStreamSubscription":["1"],"_EventDispatch":["1"],"StreamSubscription":["1"],"_BufferingStreamSubscription.T":"1"},"_StreamSinkWrapper":{"StreamSink":["1"],"EventSink":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_StreamControllerAddStreamState":{"_AddStreamState":["1"]},"_BufferingStreamSubscription":{"_EventDispatch":["1"],"StreamSubscription":["1"],"_BufferingStreamSubscription.T":"1"},"_StreamImpl":{"Stream":["1"]},"_GeneratedStreamImpl":{"_StreamImpl":["1"],"Stream":["1"],"Stream.T":"1"},"_IterablePendingEvents":{"_PendingEvents":["1"]},"_DelayedData":{"_DelayedEvent":["1"]},"_DelayedError":{"_DelayedEvent":["@"]},"_DelayedDone":{"_DelayedEvent":["@"]},"_StreamImplEvents":{"_PendingEvents":["1"]},"_DoneStreamSubscription":{"StreamSubscription":["1"]},"_EmptyStream":{"Stream":["1"],"Stream.T":"1"},"AsyncError":{"Error":[]},"_ZoneSpecification":{"ZoneSpecification":[]},"_ZoneDelegate":{"ZoneDelegate":[]},"_Zone":{"Zone":[]},"_CustomZone":{"_Zone":[],"Zone":[]},"_RootZone":{"_Zone":[],"Zone":[]},"_HashMap":{"MapMixin":["1","2"],"Map":["1","2"],"MapMixin.K":"1","MapMixin.V":"2"},"_IdentityHashMap":{"_HashMap":["1","2"],"MapMixin":["1","2"],"Map":["1","2"],"MapMixin.K":"1","MapMixin.V":"2"},"_HashMapKeyIterable":{"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1"},"_HashMapKeyIterator":{"Iterator":["1"]},"_LinkedHashSet":{"_SetBase":["1"],"LinkedHashSet":["1"],"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_LinkedHashSetIterator":{"Iterator":["1"]},"UnmodifiableListView":{"UnmodifiableListMixin":["1"],"ListMixin":["1"],"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"ListMixin.E":"1","UnmodifiableListMixin.E":"1"},"IterableBase":{"Iterable":["1"]},"ListBase":{"ListMixin":["1"],"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"MapBase":{"MapMixin":["1","2"],"Map":["1","2"]},"MapMixin":{"Map":["1","2"]},"MapView":{"Map":["1","2"]},"UnmodifiableMapView":{"_UnmodifiableMapView_MapView__UnmodifiableMapMixin":["1","2"],"MapView":["1","2"],"_UnmodifiableMapMixin":["1","2"],"Map":["1","2"]},"ListQueue":{"ListIterable":["1"],"Queue":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1","ListIterable.E":"1"},"_ListQueueIterator":{"Iterator":["1"]},"SetMixin":{"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"SetBase":{"SetMixin":["1"],"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_SetBase":{"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_JsonMap":{"MapMixin":["String","@"],"Map":["String","@"],"MapMixin.K":"String","MapMixin.V":"@"},"_JsonMapKeyIterable":{"ListIterable":["String"],"EfficientLengthIterable":["String"],"Iterable":["String"],"Iterable.E":"String","ListIterable.E":"String"},"AsciiCodec":{"Codec":["String","List<int>"],"Codec.S":"String"},"_UnicodeSubsetEncoder":{"Converter":["String","List<int>"],"StreamTransformer":["String","List<int>"]},"AsciiEncoder":{"Converter":["String","List<int>"],"StreamTransformer":["String","List<int>"]},"Base64Codec":{"Codec":["List<int>","String"],"Codec.S":"List<int>"},"Base64Encoder":{"Converter":["List<int>","String"],"StreamTransformer":["List<int>","String"]},"_FusedCodec":{"Codec":["1","3"],"Codec.S":"1"},"Converter":{"StreamTransformer":["1","2"]},"Encoding":{"Codec":["String","List<int>"]},"JsonCodec":{"Codec":["Object","String"],"Codec.S":"Object"},"JsonDecoder":{"Converter":["String","Object"],"StreamTransformer":["String","Object"]},"Utf8Codec":{"Codec":["String","List<int>"],"Codec.S":"String"},"Utf8Encoder":{"Converter":["String","List<int>"],"StreamTransformer":["String","List<int>"]},"Utf8Decoder":{"Converter":["List<int>","String"],"StreamTransformer":["List<int>","String"]},"double":{"num":[]},"AssertionError":{"Error":[]},"NullThrownError":{"Error":[]},"ArgumentError":{"Error":[]},"RangeError":{"Error":[]},"IndexError":{"Error":[]},"UnsupportedError":{"Error":[]},"UnimplementedError":{"Error":[]},"StateError":{"Error":[]},"ConcurrentModificationError":{"Error":[]},"OutOfMemoryError":{"Error":[]},"StackOverflowError":{"Error":[]},"CyclicInitializationError":{"Error":[]},"_Exception":{"Exception":[]},"FormatException":{"Exception":[]},"int":{"num":[]},"List":{"EfficientLengthIterable":["1"],"Iterable":["1"]},"RegExpMatch":{"Match":[]},"Set":{"EfficientLengthIterable":["1"],"Iterable":["1"]},"_StringStackTrace":{"StackTrace":[]},"String":{"Pattern":[]},"Runes":{"Iterable":["int"],"Iterable.E":"int"},"RuneIterator":{"Iterator":["int"]},"StringBuffer":{"StringSink":[]},"_Uri":{"Uri":[]},"_SimpleUri":{"Uri":[]},"_DataUri":{"Uri":[]},"ApplicationCacheErrorEvent":{"Event":[]},"ErrorEvent":{"Event":[]},"File":{"Blob":[]},"MediaKeyMessageEvent":{"Event":[]},"MessageEvent":{"Event":[]},"MessagePort":{"EventTarget":[]},"PresentationConnectionCloseEvent":{"Event":[]},"SpeechRecognitionError":{"Event":[]},"_EventStream":{"Stream":["1"],"Stream.T":"1"},"_EventStreamSubscription":{"StreamSubscription":["1"]},"Int8List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Uint8List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Uint8ClampedList":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Int16List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Uint16List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Int32List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Uint32List":{"List":["int"],"EfficientLengthIterable":["int"],"Iterable":["int"]},"Float32List":{"List":["double"],"EfficientLengthIterable":["double"],"Iterable":["double"]},"Float64List":{"List":["double"],"EfficientLengthIterable":["double"],"Iterable":["double"]},"DelegatingSink":{"Sink":["1"]},"DelegatingStreamSubscription":{"StreamSubscription":["1"]},"FutureGroup":{"Sink":["Future<1>"]},"NullStreamSink":{"StreamSink":["1"],"EventSink":["1"],"StreamConsumer":["1"],"Sink":["1"]},"ErrorResult":{"Result":["Null"]},"ValueResult":{"Result":["1"]},"_CompleterStream":{"Stream":["1"],"Stream.T":"1"},"StreamGroup":{"Sink":["Stream<1>"]},"_NextRequest":{"_EventRequest":["1"]},"_RestRequest":{"_EventRequest":["1"]},"_CompleterSink":{"StreamSink":["1"],"EventSink":["1"],"StreamConsumer":["1"],"Sink":["1"]},"SubscriptionStream":{"Stream":["1"],"Stream.T":"1"},"_CancelOnErrorSubscriptionWrapper":{"DelegatingStreamSubscription":["1"],"StreamSubscription":["1"]},"All":{"BooleanSelector":[]},"VariableNode":{"Node":[]},"NotNode":{"Node":[]},"OrNode":{"Node":[]},"AndNode":{"Node":[]},"ConditionalNode":{"Node":[]},"Evaluator":{"Visitor":["bool"]},"BooleanSelectorImpl":{"BooleanSelector":[]},"IntersectionSelector":{"BooleanSelector":[]},"None":{"BooleanSelector":[]},"IdentifierToken":{"Token":[]},"Validator":{"Visitor":["@"]},"RecursiveVisitor":{"Visitor":["@"]},"EmptyUnmodifiableSet":{"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"Iterable.E":"1"},"QueueList":{"ListMixin":["1"],"Queue":["1"],"List":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"],"ListMixin.E":"1"},"UnionSet":{"UnmodifiableSetMixin":["1"],"SetMixin":["1"],"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"UnmodifiableSetView":{"_UnmodifiableSetView_DelegatingSet_UnmodifiableSetMixin":["1"],"DelegatingSet":["1"],"UnmodifiableSetMixin":["1"],"DelegatingIterable":["1"],"Set":["1"],"_DelegatingIterableBase":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_DelegatingIterableBase":{"Iterable":["1"]},"DelegatingIterable":{"_DelegatingIterableBase":["1"],"Iterable":["1"]},"DelegatingSet":{"DelegatingIterable":["1"],"Set":["1"],"_DelegatingIterableBase":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_IsTrue":{"Matcher":[]},"_Predicate":{"FeatureMatcher":["1"],"TypeMatcher":["1"],"Matcher":[],"TypeMatcher.T":"1","FeatureMatcher.T":"1"},"StringDescription":{"Description":[]},"_StringEqualsMatcher":{"FeatureMatcher":["String"],"TypeMatcher":["String"],"Matcher":[],"TypeMatcher.T":"String","FeatureMatcher.T":"String"},"_DeepMatcher":{"Matcher":[]},"FeatureMatcher":{"TypeMatcher":["1"],"Matcher":[]},"TypeMatcher":{"Matcher":[],"TypeMatcher.T":"1"},"PackageConfigResolver":{"SyncPackageResolver":[]},"PackageRootResolver":{"SyncPackageResolver":[]},"PathException":{"Exception":[]},"PosixStyle":{"InternalStyle":[]},"UrlStyle":{"InternalStyle":[]},"WindowsStyle":{"InternalStyle":[]},"MultiSectionMapping":{"Mapping":[]},"MappingBundle":{"Mapping":[]},"SingleMapping":{"Mapping":[]},"_MappingTokenizer":{"Iterator":["String"]},"SourceMapSpan":{"SourceSpan":[]},"FileLocation":{"SourceLocation":[]},"_FileSpan":{"FileSpan":[],"SourceSpanWithContext":[],"SourceSpan":[]},"SourceLocationMixin":{"SourceLocation":[]},"SourceSpanBase":{"SourceSpan":[]},"SourceSpanException":{"Exception":[]},"SourceSpanFormatException":{"FormatException":[],"Exception":[]},"SourceSpanMixin":{"SourceSpan":[]},"SourceSpanWithContext":{"SourceSpan":[]},"Chain":{"StackTrace":[]},"LazyChain":{"Chain":[],"StackTrace":[]},"LazyTrace":{"Trace":[],"StackTrace":[]},"Trace":{"StackTrace":[]},"UnparsedFrame":{"Frame":[]},"GuaranteeChannel":{"StreamChannelMixin":["1"],"StreamChannel":["1"]},"_GuaranteeSink":{"StreamSink":["1"],"EventSink":["1"],"StreamConsumer":["1"],"Sink":["1"]},"_MultiChannel":{"StreamChannelMixin":["1"],"MultiChannel":["1"],"StreamChannel":["1"]},"VirtualChannel":{"StreamChannelMixin":["1"],"MultiChannel":["1"],"StreamChannel":["1"]},"_StreamChannel":{"StreamChannelMixin":["1"],"StreamChannel":["1"]},"StreamChannelMixin":{"StreamChannel":["1"]},"StringScannerException":{"FormatException":[],"Exception":[]},"_SpanScannerState":{"LineScannerState":[]},"ClosedException":{"Exception":[]},"Group":{"GroupEntry":[]},"LocalTest":{"Test":[],"GroupEntry":[]},"_LiveTest":{"LiveTest":[]},"Test":{"GroupEntry":[]},"IterableSet":{"SetMixin":["1"],"UnmodifiableSetMixin":["1"],"Set":["1"],"EfficientLengthIterable":["1"],"Iterable":["1"]},"_LiveSuite":{"LiveSuite":[]},"RunnerSuite":{"Suite":[]},"PrintSink":{"StringSink":[]},"JSStackTraceMapper":{"StackTraceMapper":[]}}'));
  H._Universe_addErasedTypes(init.typeUniverse, JSON.parse('{"UnmodifiableListBase":1,"StreamTransformerBase":2,"IterableBase":1,"ListBase":1,"MapBase":2,"SetBase":1,"_ListBase_Object_ListMixin":1,"_SetBase_Object_SetMixin":1,"_QueueList_Object_ListMixin":1,"_UnionSet_SetBase_UnmodifiableSetMixin":1,"_IterableSet_SetMixin_UnmodifiableSetMixin":1}'));
  var type$ = (function rtii() {
    var findType = H.findType;
    return {
      A_Function_2_B_and_C_Function_A_and_B_and_C_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_2_B_and_C: findType("0^(1^,2^)(Zone,ZoneDelegate,Zone,0^(1^,2^))<Object,Object,Object>"),
      A_Function_A_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function: findType("0^(Zone,ZoneDelegate,Zone,0^())<Object>"),
      A_Function_A_and_B_5_Zone_and_ZoneDelegate_and_Zone_and_A_Function_B_and_B: findType("0^(Zone,ZoneDelegate,Zone,0^(1^),1^)<Object,Object>"),
      A_Function_A_and_B_and_C_6_Zone_and_ZoneDelegate_and_Zone_and_A_Function_2_B_and_C_and_B_and_C: findType("0^(Zone,ZoneDelegate,Zone,0^(1^,2^),1^,2^)<Object,Object,Object>"),
      A_Function_B_Function_A_and_B_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function_B: findType("0^(1^)(Zone,ZoneDelegate,Zone,0^(1^))<Object,Object>"),
      A_Function_Function_A_4_Zone_and_ZoneDelegate_and_Zone_and_A_Function: findType("0^()(Zone,ZoneDelegate,Zone,0^())<Object>"),
      AsyncError: findType("AsyncError"),
      AsyncMemoizer_dynamic: findType("AsyncMemoizer<@>"),
      Blob: findType("Blob"),
      BooleanSelector: findType("BooleanSelector"),
      Chain: findType("Chain"),
      CodeUnits: findType("CodeUnits"),
      Completer_PoolResource: findType("Completer<PoolResource>"),
      Declarer: findType("Declarer"),
      Duration: findType("Duration"),
      EfficientLengthIterable_dynamic: findType("EfficientLengthIterable<@>"),
      Error: findType("Error"),
      Event: findType("Event"),
      Exception: findType("Exception"),
      Expando__Node: findType("Expando<_Node>"),
      File: findType("File"),
      FileSpan: findType("FileSpan"),
      FormatException: findType("FormatException"),
      Frame: findType("Frame"),
      Frame_Function_Frame: findType("Frame(Frame)"),
      Frame_Function_String: findType("Frame(String)"),
      Function: findType("Function"),
      FutureGroup_dynamic: findType("FutureGroup<@>"),
      FutureOr_void_Function: findType("~/()"),
      Future_Null: findType("Future<Null>"),
      Future_RunnerSuite: findType("Future<RunnerSuite>"),
      Future_bool: findType("Future<bool>"),
      Future_dynamic: findType("Future<@>"),
      Future_void: findType("Future<~>"),
      Group: findType("Group"),
      GroupEntry: findType("GroupEntry"),
      GroupEntry_Function_GroupEntry: findType("GroupEntry(GroupEntry)"),
      IdentifierToken: findType("IdentifierToken"),
      Invoker: findType("Invoker"),
      IterableSet_LiveTest: findType("IterableSet<LiveTest>"),
      Iterable_Group: findType("Iterable<Group>"),
      Iterable_String: findType("Iterable<String>"),
      Iterable_dynamic: findType("Iterable<@>"),
      Iterator_Match: findType("Iterator<Match>"),
      JSArray_AsyncError: findType("JSArray<AsyncError>"),
      JSArray_Declarer: findType("JSArray<Declarer>"),
      JSArray_Frame: findType("JSArray<Frame>"),
      JSArray_Future_dynamic: findType("JSArray<Future<@>>"),
      JSArray_Group: findType("JSArray<Group>"),
      JSArray_GroupEntry: findType("JSArray<GroupEntry>"),
      JSArray_Mapping: findType("JSArray<Mapping>"),
      JSArray_Set_LiveTest: findType("JSArray<Set<LiveTest>>"),
      JSArray_SourceFile: findType("JSArray<SourceFile>"),
      JSArray_String: findType("JSArray<String>"),
      JSArray_TargetEntry: findType("JSArray<TargetEntry>"),
      JSArray_TargetLineEntry: findType("JSArray<TargetLineEntry>"),
      JSArray_Trace: findType("JSArray<Trace>"),
      JSArray_Zone: findType("JSArray<Zone>"),
      JSArray_dynamic: findType("JSArray<@>"),
      JSArray_int: findType("JSArray<int>"),
      JSArray_of_dynamic_Function: findType("JSArray<@()>"),
      JSObject: findType("JSObject"),
      JavaScriptFunction: findType("JavaScriptFunction"),
      JavaScriptIndexingBehavior_dynamic: findType("JavaScriptIndexingBehavior<@>"),
      JsLinkedHashMap_of_Stream_LiveTest_and_StreamSubscription_LiveTest: findType("JsLinkedHashMap<Stream<LiveTest>,StreamSubscription<LiveTest>>"),
      List_Group: findType("List<Group>"),
      List_Object: findType("List<Object>"),
      List_String: findType("List<String>"),
      List_String_Function_dynamic_dynamic_String_int: findType("List<String>(@,@,String,int)"),
      List_dynamic: findType("List<@>"),
      List_int: findType("List<int>"),
      LiveSuite: findType("LiveSuite"),
      LiveTest: findType("LiveTest"),
      MapEntry_BooleanSelector_Metadata: findType("MapEntry<BooleanSelector,Metadata>"),
      MapEntry_String_Uri: findType("MapEntry<String,Uri>"),
      MapEntry_of_String_and_Map_String_dynamic: findType("MapEntry<String,Map<String,@>>"),
      Map_BooleanSelector_Metadata: findType("Map<BooleanSelector,Metadata>"),
      Map_PlatformSelector_Metadata: findType("Map<PlatformSelector,Metadata>"),
      Map_String_SourceFile: findType("Map<String,SourceFile>"),
      Map_String_dynamic: findType("Map<String,@>"),
      Map_dynamic_dynamic: findType("Map<@,@>"),
      MappedIterable_String_Frame: findType("MappedIterable<String,Frame>"),
      MappedListIterable_Frame_Frame: findType("MappedListIterable<Frame,Frame>"),
      MappedListIterable_String_String: findType("MappedListIterable<String,String>"),
      MappedListIterable_String_Trace: findType("MappedListIterable<String,Trace>"),
      MappedListIterable_String_dynamic: findType("MappedListIterable<String,@>"),
      Message: findType("Message"),
      MessageEvent: findType("MessageEvent"),
      MessagePort: findType("MessagePort"),
      Metadata: findType("Metadata"),
      NativeByteBuffer: findType("NativeByteBuffer"),
      NativeTypedData: findType("NativeTypedData"),
      NativeUint8List: findType("NativeUint8List"),
      NoSuchMethodError: findType("NoSuchMethodError"),
      Null: findType("Null"),
      Null_Function: findType("Null()"),
      Object: findType("Object"),
      OperatingSystem: findType("OperatingSystem"),
      Pattern: findType("Pattern"),
      PlatformSelector: findType("PlatformSelector"),
      RegExp: findType("RegExp"),
      Result_dynamic: findType("Result<@>"),
      ReversedListIterable_Declarer: findType("ReversedListIterable<Declarer>"),
      RunnerSuite: findType("RunnerSuite"),
      Runtime: findType("Runtime"),
      Set_LiveTest: findType("Set<LiveTest>"),
      Set_String: findType("Set<String>"),
      Set_dynamic: findType("Set<@>"),
      SingleMapping: findType("SingleMapping"),
      SourceLocation: findType("SourceLocation"),
      SourceSpan: findType("SourceSpan"),
      SourceSpanWithContext: findType("SourceSpanWithContext"),
      StackTrace: findType("StackTrace"),
      StackTraceFormatter: findType("StackTraceFormatter"),
      StackZoneSpecification: findType("StackZoneSpecification"),
      State: findType("State"),
      StreamChannelCompleter_dynamic: findType("StreamChannelCompleter<@>"),
      StreamChannel_dynamic: findType("StreamChannel<@>"),
      StreamCompleter_dynamic: findType("StreamCompleter<@>"),
      StreamGroup_LiveTest: findType("StreamGroup<LiveTest>"),
      StreamQueue_dynamic: findType("StreamQueue<@>"),
      StreamSinkCompleter_dynamic: findType("StreamSinkCompleter<@>"),
      StreamSubscription_dynamic: findType("StreamSubscription<@>"),
      String: findType("String"),
      String_Function_Match: findType("String(Match)"),
      String_Function_String: findType("String(String)"),
      SuiteChannelManager: findType("SuiteChannelManager"),
      Test: findType("Test"),
      Timer: findType("Timer"),
      Trace: findType("Trace"),
      Trace_Function_String: findType("Trace(String)"),
      Type: findType("Type"),
      Uint8List: findType("Uint8List"),
      UnionSet_LiveTest: findType("UnionSet<LiveTest>"),
      UnknownJavaScriptObject: findType("UnknownJavaScriptObject"),
      UnmodifiableListView_LiveTest: findType("UnmodifiableListView<LiveTest>"),
      UnmodifiableMapView_BooleanSelector_Metadata: findType("UnmodifiableMapView<BooleanSelector,Metadata>"),
      UnmodifiableMapView_PlatformSelector_Metadata: findType("UnmodifiableMapView<PlatformSelector,Metadata>"),
      UnmodifiableMapView_String_Uri: findType("UnmodifiableMapView<String,Uri>"),
      UnmodifiableSetView_LiveTest: findType("UnmodifiableSetView<LiveTest>"),
      UnmodifiableSetView_String: findType("UnmodifiableSetView<String>"),
      Uri: findType("Uri"),
      WhereIterable_String: findType("WhereIterable<String>"),
      Zone: findType("Zone"),
      ZoneDelegate: findType("ZoneDelegate"),
      ZoneSpecification: findType("ZoneSpecification"),
      _AsyncBroadcastStreamController_LiveSuite: findType("_AsyncBroadcastStreamController<LiveSuite>"),
      _AsyncBroadcastStreamController_RunnerSuite: findType("_AsyncBroadcastStreamController<RunnerSuite>"),
      _AsyncBroadcastStreamController_bool: findType("_AsyncBroadcastStreamController<bool>"),
      _AsyncCompleter_List_dynamic: findType("_AsyncCompleter<List<@>>"),
      _AsyncCompleter_PoolResource: findType("_AsyncCompleter<PoolResource>"),
      _AsyncCompleter_dynamic: findType("_AsyncCompleter<@>"),
      _AsyncCompleter_void: findType("_AsyncCompleter<~>"),
      _AsyncCounter: findType("_AsyncCounter"),
      _CompleterSink_dynamic: findType("_CompleterSink<@>"),
      _CompleterStream_dynamic: findType("_CompleterStream<@>"),
      _DelayedEvent_dynamic: findType("_DelayedEvent<@>"),
      _EventRequest_dynamic: findType("_EventRequest<@>"),
      _EventStream_MessageEvent: findType("_EventStream<MessageEvent>"),
      _FutureListener_dynamic_dynamic: findType("_FutureListener<@,@>"),
      _Future_List_dynamic: findType("_Future<List<@>>"),
      _Future_PoolResource: findType("_Future<PoolResource>"),
      _Future_RunnerSuite: findType("_Future<RunnerSuite>"),
      _Future_dynamic: findType("_Future<@>"),
      _Future_int: findType("_Future<int>"),
      _Future_void: findType("_Future<~>"),
      _IdentityHashMap_dynamic_dynamic: findType("_IdentityHashMap<@,@>"),
      _LinkedHashSetCell: findType("_LinkedHashSetCell"),
      _Node: findType("_Node"),
      _Predicate_Object: findType("_Predicate<Object>"),
      _Predicate_dynamic: findType("_Predicate<@>"),
      _RestRequest_dynamic: findType("_RestRequest<@>"),
      _StreamChannel_dynamic: findType("_StreamChannel<@>"),
      _SyncBroadcastStreamController_AsyncError: findType("_SyncBroadcastStreamController<AsyncError>"),
      _SyncBroadcastStreamController_LiveTest: findType("_SyncBroadcastStreamController<LiveTest>"),
      _SyncBroadcastStreamController_Message: findType("_SyncBroadcastStreamController<Message>"),
      _SyncBroadcastStreamController_State: findType("_SyncBroadcastStreamController<State>"),
      _SyncCompleter_PoolResource: findType("_SyncCompleter<PoolResource>"),
      _SyncCompleter_dynamic: findType("_SyncCompleter<@>"),
      _ZoneFunction_Function: findType("_ZoneFunction<Function>"),
      _ZoneFunction_of_AsyncError_Function_Zone_ZoneDelegate_Zone_Object_StackTrace: findType("_ZoneFunction<AsyncError(Zone,ZoneDelegate,Zone,Object,StackTrace)>"),
      _ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function: findType("_ZoneFunction<Timer(Zone,ZoneDelegate,Zone,Duration,~())>"),
      _ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function_Timer: findType("_ZoneFunction<Timer(Zone,ZoneDelegate,Zone,Duration,~(Timer))>"),
      _ZoneFunction_of_Zone_Function_5_Zone_and_ZoneDelegate_and_Zone_and_ZoneSpecification_and_Map_dynamic_dynamic: findType("_ZoneFunction<Zone(Zone,ZoneDelegate,Zone,ZoneSpecification,Map<@,@>)>"),
      _ZoneFunction_of_void_Function_4_Zone_and_ZoneDelegate_and_Zone_and_void_Function: findType("_ZoneFunction<~(Zone,ZoneDelegate,Zone,~())>"),
      _ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_Object_StackTrace: findType("_ZoneFunction<~(Zone,ZoneDelegate,Zone,Object,StackTrace)>"),
      _ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_String: findType("_ZoneFunction<~(Zone,ZoneDelegate,Zone,String)>"),
      bool: findType("bool"),
      bool_Function_Frame: findType("bool(Frame)"),
      bool_Function_Null: findType("bool(Null)"),
      bool_Function_Object: findType("bool(Object)"),
      bool_Function_String: findType("bool(String)"),
      bool_Function_dynamic: findType("bool(@)"),
      dynamic: findType("@"),
      dynamic_Function: findType("@()"),
      dynamic_Function_Event: findType("@(Event)"),
      dynamic_Function_Object: findType("@(Object)"),
      dynamic_Function_Object_Object: findType("@(Object,Object)"),
      dynamic_Function_Object_StackTrace: findType("@(Object,StackTrace)"),
      dynamic_Function_String: findType("@(String)"),
      dynamic_Function_dynamic_dynamic: findType("@(@,@)"),
      int: findType("int"),
      num: findType("num"),
      void: findType("~"),
      void_Function: findType("~()"),
      void_Function_MessageEvent: findType("~(MessageEvent)"),
      void_Function_Object: findType("~(Object)"),
      void_Function_Object_StackTrace: findType("~(Object,StackTrace)"),
      void_Function_String_dynamic: findType("~(String,@)"),
      void_Function_Timer: findType("~(Timer)")
    };
  })();
  (function constants() {
    var makeConstList = hunkHelpers.makeConstList;
    C.Interceptor_methods = J.Interceptor.prototype;
    C.JSArray_methods = J.JSArray.prototype;
    C.JSInt_methods = J.JSInt.prototype;
    C.JSNumber_methods = J.JSNumber.prototype;
    C.JSString_methods = J.JSString.prototype;
    C.JavaScriptFunction_methods = J.JavaScriptFunction.prototype;
    C.Location_methods = W.Location.prototype;
    C.MessagePort_methods = W.MessagePort.prototype;
    C.NativeUint32List_methods = H.NativeUint32List.prototype;
    C.NativeUint8List_methods = H.NativeUint8List.prototype;
    C.PlainJavaScriptObject_methods = J.PlainJavaScriptObject.prototype;
    C.UnknownJavaScriptObject_methods = J.UnknownJavaScriptObject.prototype;
    C.AsciiEncoder_127 = new P.AsciiEncoder(127);
    C.List_empty = H.setRuntimeTypeInfo(makeConstList([]), type$.JSArray_String);
    C.C_All = new X.All();
    C.C_AsciiCodec = new P.AsciiCodec();
    C.C_AsciiGlyphSet = new A.AsciiGlyphSet();
    C.C_Base64Encoder = new P.Base64Encoder();
    C.C_Base64Codec = new P.Base64Codec();
    C.C_EmptyIterator = new H.EmptyIterator(H.findType("EmptyIterator<Null>"));
    C.C_EmptyUnmodifiableSet = new O.EmptyUnmodifiableSet(H.findType("EmptyUnmodifiableSet<String>"));
    C.C_JS_CONST = function getTagFallback(o) {
  var s = Object.prototype.toString.call(o);
  return s.substring(8, s.length - 1);
};
    C.C_JS_CONST0 = function() {
  var toStringFunction = Object.prototype.toString;
  function getTag(o) {
    var s = toStringFunction.call(o);
    return s.substring(8, s.length - 1);
  }
  function getUnknownTag(object, tag) {
    if (/^HTML[A-Z].*Element$/.test(tag)) {
      var name = toStringFunction.call(object);
      if (name == "[object Object]") return null;
      return "HTMLElement";
    }
  }
  function getUnknownTagGenericBrowser(object, tag) {
    if (self.HTMLElement && object instanceof HTMLElement) return "HTMLElement";
    return getUnknownTag(object, tag);
  }
  function prototypeForTag(tag) {
    if (typeof window == "undefined") return null;
    if (typeof window[tag] == "undefined") return null;
    var constructor = window[tag];
    if (typeof constructor != "function") return null;
    return constructor.prototype;
  }
  function discriminator(tag) { return null; }
  var isBrowser = typeof navigator == "object";
  return {
    getTag: getTag,
    getUnknownTag: isBrowser ? getUnknownTagGenericBrowser : getUnknownTag,
    prototypeForTag: prototypeForTag,
    discriminator: discriminator };
};
    C.C_JS_CONST6 = function(getTagFallback) {
  return function(hooks) {
    if (typeof navigator != "object") return hooks;
    var ua = navigator.userAgent;
    if (ua.indexOf("DumpRenderTree") >= 0) return hooks;
    if (ua.indexOf("Chrome") >= 0) {
      function confirm(p) {
        return typeof window == "object" && window[p] && window[p].name == p;
      }
      if (confirm("Window") && confirm("HTMLElement")) return hooks;
    }
    hooks.getTag = getTagFallback;
  };
};
    C.C_JS_CONST1 = function(hooks) {
  if (typeof dartExperimentalFixupGetTag != "function") return hooks;
  hooks.getTag = dartExperimentalFixupGetTag(hooks.getTag);
};
    C.C_JS_CONST2 = function(hooks) {
  var getTag = hooks.getTag;
  var prototypeForTag = hooks.prototypeForTag;
  function getTagFixed(o) {
    var tag = getTag(o);
    if (tag == "Document") {
      if (!!o.xmlVersion) return "!Document";
      return "!HTMLDocument";
    }
    return tag;
  }
  function prototypeForTagFixed(tag) {
    if (tag == "Document") return null;
    return prototypeForTag(tag);
  }
  hooks.getTag = getTagFixed;
  hooks.prototypeForTag = prototypeForTagFixed;
};
    C.C_JS_CONST5 = function(hooks) {
  var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
  if (userAgent.indexOf("Firefox") == -1) return hooks;
  var getTag = hooks.getTag;
  var quickMap = {
    "BeforeUnloadEvent": "Event",
    "DataTransfer": "Clipboard",
    "GeoGeolocation": "Geolocation",
    "Location": "!Location",
    "WorkerMessageEvent": "MessageEvent",
    "XMLDocument": "!Document"};
  function getTagFirefox(o) {
    var tag = getTag(o);
    return quickMap[tag] || tag;
  }
  hooks.getTag = getTagFirefox;
};
    C.C_JS_CONST4 = function(hooks) {
  var userAgent = typeof navigator == "object" ? navigator.userAgent : "";
  if (userAgent.indexOf("Trident/") == -1) return hooks;
  var getTag = hooks.getTag;
  var quickMap = {
    "BeforeUnloadEvent": "Event",
    "DataTransfer": "Clipboard",
    "HTMLDDElement": "HTMLElement",
    "HTMLDTElement": "HTMLElement",
    "HTMLPhraseElement": "HTMLElement",
    "Position": "Geoposition"
  };
  function getTagIE(o) {
    var tag = getTag(o);
    var newTag = quickMap[tag];
    if (newTag) return newTag;
    if (tag == "Object") {
      if (window.DataView && (o instanceof window.DataView)) return "DataView";
    }
    return tag;
  }
  function prototypeForTagIE(tag) {
    var constructor = window[tag];
    if (constructor == null) return null;
    return constructor.prototype;
  }
  hooks.getTag = getTagIE;
  hooks.prototypeForTag = prototypeForTagIE;
};
    C.C_JS_CONST3 = function(hooks) { return hooks; }
;
    C.C_JsonCodec = new P.JsonCodec();
    C.C_None = new O.None();
    C.C_OutOfMemoryError = new P.OutOfMemoryError();
    C.C_UnicodeGlyphSet = new K.UnicodeGlyphSet();
    C.C_Utf8Codec = new P.Utf8Codec();
    C.C_Utf8Encoder = new P.Utf8Encoder();
    C.C__DelayedDone = new P._DelayedDone();
    C.C__IsTrue = new Y._IsTrue();
    C.C__RootZone = new P._RootZone();
    C.Duration_0 = new P.Duration(0);
    C.Duration_30000000 = new P.Duration(30000000);
    C.JsonDecoder_null = new P.JsonDecoder(null);
    C.List_127_2047_65535_1114111 = H.setRuntimeTypeInfo(makeConstList([127, 2047, 65535, 1114111]), type$.JSArray_int);
    C.List_2Vk = H.setRuntimeTypeInfo(makeConstList([0, 0, 32776, 33792, 1, 10240, 0, 0]), type$.JSArray_int);
    C.List_CVk = H.setRuntimeTypeInfo(makeConstList([0, 0, 65490, 45055, 65535, 34815, 65534, 18431]), type$.JSArray_int);
    C.List_JYB = H.setRuntimeTypeInfo(makeConstList([0, 0, 26624, 1023, 65534, 2047, 65534, 2047]), type$.JSArray_int);
    C.List_empty1 = H.setRuntimeTypeInfo(makeConstList([]), H.findType("JSArray<Null>"));
    C.List_empty0 = H.setRuntimeTypeInfo(makeConstList([]), type$.JSArray_dynamic);
    C.List_gRj = H.setRuntimeTypeInfo(makeConstList([0, 0, 32722, 12287, 65534, 34815, 65534, 18431]), type$.JSArray_int);
    C.Runtime_ql0 = new B.Runtime("VM", "vm", null, true, false, false, false, false);
    C.Runtime_4e8 = new B.Runtime("Chrome", "chrome", null, false, true, true, true, false);
    C.Runtime_IBZ = new B.Runtime("PhantomJS", "phantomjs", null, false, true, true, true, true);
    C.Runtime_8Rg = new B.Runtime("Firefox", "firefox", null, false, true, true, false, false);
    C.Runtime_ivT = new B.Runtime("Safari", "safari", null, false, true, true, false, false);
    C.Runtime_Mzn = new B.Runtime("Internet Explorer", "ie", null, false, true, true, false, false);
    C.Runtime_R5O = new B.Runtime("Node.js", "node", null, false, false, true, false, false);
    C.List_m7e = H.setRuntimeTypeInfo(makeConstList([C.Runtime_ql0, C.Runtime_4e8, C.Runtime_IBZ, C.Runtime_8Rg, C.Runtime_ivT, C.Runtime_Mzn, C.Runtime_R5O]), H.findType("JSArray<Runtime>"));
    C.List_nxB = H.setRuntimeTypeInfo(makeConstList([0, 0, 24576, 1023, 65534, 34815, 65534, 18431]), type$.JSArray_int);
    C.OperatingSystem_Windows_windows = new N.OperatingSystem("Windows", "windows");
    C.OperatingSystem_RkP = new N.OperatingSystem("OS X", "mac-os");
    C.OperatingSystem_Linux_linux = new N.OperatingSystem("Linux", "linux");
    C.OperatingSystem_Android_android = new N.OperatingSystem("Android", "android");
    C.OperatingSystem_iOS_ios = new N.OperatingSystem("iOS", "ios");
    C.List_opx = H.setRuntimeTypeInfo(makeConstList([C.OperatingSystem_Windows_windows, C.OperatingSystem_RkP, C.OperatingSystem_Linux_linux, C.OperatingSystem_Android_android, C.OperatingSystem_iOS_ios]), H.findType("JSArray<OperatingSystem>"));
    C.List_qFt = H.setRuntimeTypeInfo(makeConstList([0, 0, 27858, 1023, 65534, 51199, 65535, 32767]), type$.JSArray_int);
    C.List_qNA = H.setRuntimeTypeInfo(makeConstList([0, 0, 32754, 11263, 65534, 34815, 65534, 18431]), type$.JSArray_int);
    C.List_qg40 = H.setRuntimeTypeInfo(makeConstList([0, 0, 32722, 12287, 65535, 34815, 65534, 18431]), type$.JSArray_int);
    C.List_qg4 = H.setRuntimeTypeInfo(makeConstList([0, 0, 65490, 12287, 65535, 34815, 65534, 18431]), type$.JSArray_int);
    C.List_F9h = H.setRuntimeTypeInfo(makeConstList(["\n", "\r", "\f", "\b", "\t", "\v", "\x7f"]), type$.JSArray_String);
    C.Map_F9GZw = new H.ConstantStringMap(7, {"\n": "\\n", "\r": "\\r", "\f": "\\f", "\b": "\\b", "\t": "\\t", "\v": "\\v", "\x7f": "\\x7F"}, C.List_F9h, H.findType("ConstantStringMap<String,String>"));
    C.List_empty2 = H.setRuntimeTypeInfo(makeConstList([]), H.findType("JSArray<BooleanSelector>"));
    C.Map_empty0 = new H.ConstantStringMap(0, {}, C.List_empty2, H.findType("ConstantStringMap<BooleanSelector,Metadata>"));
    C.Map_empty1 = new H.ConstantStringMap(0, {}, C.List_empty1, H.findType("ConstantStringMap<Null,Null>"));
    C.List_empty3 = H.setRuntimeTypeInfo(makeConstList([]), H.findType("JSArray<PlatformSelector>"));
    C.Map_empty = new H.ConstantStringMap(0, {}, C.List_empty3, H.findType("ConstantStringMap<PlatformSelector,Metadata>"));
    C.MessageType_print = new D.MessageType("print");
    C.MessageType_skip = new D.MessageType("skip");
    C.OperatingSystem_none_none = new N.OperatingSystem("none", "none");
    C.PlatformSelector_All = new E.PlatformSelector(C.C_All);
    C.Result_error = new G.Result0("error");
    C.Result_skipped = new G.Result0("skipped");
    C.Result_success = new G.Result0("success");
    C.Status_complete = new G.Status("complete");
    C.State_Status_complete_Result_error = new G.State(C.Status_complete, C.Result_error);
    C.Result_failure = new G.Result0("failure");
    C.State_Status_complete_Result_failure = new G.State(C.Status_complete, C.Result_failure);
    C.State_Status_complete_Result_skipped = new G.State(C.Status_complete, C.Result_skipped);
    C.Status_pending = new G.Status("pending");
    C.State_Status_pending_Result_success = new G.State(C.Status_pending, C.Result_success);
    C.Status_running = new G.Status("running");
    C.State_Status_running_Result_skipped = new G.State(C.Status_running, C.Result_skipped);
    C.State_Status_running_Result_success = new G.State(C.Status_running, C.Result_success);
    C.Symbol_Drw = new H.Symbol("test.declarer");
    C.Symbol_MAi = new H.Symbol("test.runner.test_channel");
    C.Symbol_cQL = new H.Symbol("test.invoker");
    C.Symbol_runCount = new H.Symbol("runCount");
    C.Timeout_null_1 = new R.Timeout(null, 1);
    C.Timeout_null_null = new R.Timeout(null, null);
    C.TokenType_31K = new L.TokenType("right paren");
    C.TokenType_69P = new L.TokenType("question mark");
    C.TokenType_and = new L.TokenType("and");
    C.TokenType_colon = new L.TokenType("colon");
    C.TokenType_e7P = new L.TokenType("left paren");
    C.TokenType_identifier = new L.TokenType("identifier");
    C.TokenType_not = new L.TokenType("not");
    C.TokenType_or = new L.TokenType("or");
    C.TokenType_wwi = new L.TokenType("end of file");
    C.Type_ByteBuffer_RkP = H.typeLiteral("ByteBuffer");
    C.Type_ByteData_zNC = H.typeLiteral("ByteData");
    C.Type_Float32List_LB7 = H.typeLiteral("Float32List");
    C.Type_Float64List_LB7 = H.typeLiteral("Float64List");
    C.Type_Int16List_uXf = H.typeLiteral("Int16List");
    C.Type_Int32List_O50 = H.typeLiteral("Int32List");
    C.Type_Int8List_ekJ = H.typeLiteral("Int8List");
    C.Type_JSObject_8k0 = H.typeLiteral("JSObject");
    C.Type_Null_Yyn = H.typeLiteral("Null");
    C.Type_String_k8F = H.typeLiteral("String");
    C.Type_Uint16List_2bx = H.typeLiteral("Uint16List");
    C.Type_Uint32List_2bx = H.typeLiteral("Uint32List");
    C.Type_Uint8ClampedList_Jik = H.typeLiteral("Uint8ClampedList");
    C.Type_Uint8List_WLA = H.typeLiteral("Uint8List");
    C.Type_bool_lhE = H.typeLiteral("bool");
    C.Type_double_K1J = H.typeLiteral("double");
    C.Type_int_tHn = H.typeLiteral("int");
    C.Type_num_cv7 = H.typeLiteral("num");
    C._PathDirection_8Gl = new M._PathDirection("at root");
    C._PathDirection_988 = new M._PathDirection("below root");
    C._PathDirection_FIw = new M._PathDirection("reaches root");
    C._PathDirection_ZGD = new M._PathDirection("above root");
    C._PathRelation_different = new M._PathRelation("different");
    C._PathRelation_equal = new M._PathRelation("equal");
    C._PathRelation_inconclusive = new M._PathRelation("inconclusive");
    C._PathRelation_within = new M._PathRelation("within");
    C._StreamGroupState_canceled = new L._StreamGroupState("canceled");
    C._StreamGroupState_dormant = new L._StreamGroupState("dormant");
    C._StreamGroupState_listening = new L._StreamGroupState("listening");
    C._StreamGroupState_paused = new L._StreamGroupState("paused");
    C._TokenKind_false_false_false = new T._TokenKind(false, false, false);
    C._TokenKind_false_false_true = new T._TokenKind(false, false, true);
    C._TokenKind_false_true_false = new T._TokenKind(false, true, false);
    C._TokenKind_true_false_false = new T._TokenKind(true, false, false);
    C._ZoneFunction_3bB = new P._ZoneFunction(C.C__RootZone, P.async___rootCreatePeriodicTimer$closure(), type$._ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function_Timer);
    C._ZoneFunction_7G2 = new P._ZoneFunction(C.C__RootZone, P.async___rootRegisterBinaryCallback$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction_Eeh = new P._ZoneFunction(C.C__RootZone, P.async___rootRegisterUnaryCallback$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction_NMc = new P._ZoneFunction(C.C__RootZone, P.async___rootHandleUncaughtError$closure(), type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_Object_StackTrace);
    C._ZoneFunction__RootZone__rootCreateTimer = new P._ZoneFunction(C.C__RootZone, P.async___rootCreateTimer$closure(), type$._ZoneFunction_of_Timer_Function_5_Zone_and_ZoneDelegate_and_Zone_and_Duration_and_void_Function);
    C._ZoneFunction__RootZone__rootErrorCallback = new P._ZoneFunction(C.C__RootZone, P.async___rootErrorCallback$closure(), type$._ZoneFunction_of_AsyncError_Function_Zone_ZoneDelegate_Zone_Object_StackTrace);
    C._ZoneFunction__RootZone__rootFork = new P._ZoneFunction(C.C__RootZone, P.async___rootFork$closure(), type$._ZoneFunction_of_Zone_Function_5_Zone_and_ZoneDelegate_and_Zone_and_ZoneSpecification_and_Map_dynamic_dynamic);
    C._ZoneFunction__RootZone__rootPrint = new P._ZoneFunction(C.C__RootZone, P.async___rootPrint$closure(), type$._ZoneFunction_of_void_Function_Zone_ZoneDelegate_Zone_String);
    C._ZoneFunction__RootZone__rootRegisterCallback = new P._ZoneFunction(C.C__RootZone, P.async___rootRegisterCallback$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction__RootZone__rootRun = new P._ZoneFunction(C.C__RootZone, P.async___rootRun$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction__RootZone__rootRunBinary = new P._ZoneFunction(C.C__RootZone, P.async___rootRunBinary$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction__RootZone__rootRunUnary = new P._ZoneFunction(C.C__RootZone, P.async___rootRunUnary$closure(), type$._ZoneFunction_Function);
    C._ZoneFunction__RootZone__rootScheduleMicrotask = new P._ZoneFunction(C.C__RootZone, P.async___rootScheduleMicrotask$closure(), type$._ZoneFunction_of_void_Function_4_Zone_and_ZoneDelegate_and_Zone_and_void_Function);
    C._ZoneSpecification_ALf = new P._ZoneSpecification(null, null, null, null, null, null, null, null, null, null, null, null, null);
  })();
  (function staticFields() {
    $.printToZone = null;
    $.Primitives_timerFrequency = null;
    $.Primitives_timerTicks = null;
    $.Closure_functionCounter = 0;
    $.BoundClosure_selfFieldNameCache = null;
    $.BoundClosure_receiverFieldNameCache = null;
    $.getTagFunction = null;
    $.alternateTagFunction = null;
    $.prototypeForTagFunction = null;
    $.dispatchRecordsForInstanceTags = null;
    $.interceptorsForUncacheableTags = null;
    $.initNativeDispatchFlag = null;
    $._nextCallback = null;
    $._lastCallback = null;
    $._lastPriorityCallback = null;
    $._isInCallbackLoop = false;
    $.Zone__current = C.C__RootZone;
    $._RootZone__rootDelegate = null;
    $._toStringVisiting = [];
    $.Expando__keyCount = 0;
    $.Stopwatch__frequency = null;
    $._currentUriBase = null;
    $._current = null;
    $._glyphs = C.C_UnicodeGlyphSet;
    $._macOSDirectories = P.LinkedHashSet_LinkedHashSet$_literal(["/Applications", "/Library", "/Network", "/System", "/Users"], type$.String);
    $._globalDeclarer = null;
    $.x = 0;
  })();
  (function lazyInitializers() {
    var _lazy = hunkHelpers.lazy;
    _lazy($, "DART_CLOSURE_PROPERTY_NAME", "$get$DART_CLOSURE_PROPERTY_NAME", function() {
      return H.getIsolateAffinityTag("_$dart_dartClosure");
    });
    _lazy($, "JS_INTEROP_INTERCEPTOR_TAG", "$get$JS_INTEROP_INTERCEPTOR_TAG", function() {
      return H.getIsolateAffinityTag("_$dart_js");
    });
    _lazy($, "TypeErrorDecoder_noSuchMethodPattern", "$get$TypeErrorDecoder_noSuchMethodPattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokeCallErrorOn({
        toString: function() {
          return "$receiver$";
        }
      }));
    });
    _lazy($, "TypeErrorDecoder_notClosurePattern", "$get$TypeErrorDecoder_notClosurePattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokeCallErrorOn({$method$: null,
        toString: function() {
          return "$receiver$";
        }
      }));
    });
    _lazy($, "TypeErrorDecoder_nullCallPattern", "$get$TypeErrorDecoder_nullCallPattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokeCallErrorOn(null));
    });
    _lazy($, "TypeErrorDecoder_nullLiteralCallPattern", "$get$TypeErrorDecoder_nullLiteralCallPattern", function() {
      return H.TypeErrorDecoder_extractPattern(function() {
        var $argumentsExpr$ = '$arguments$';
        try {
          null.$method$($argumentsExpr$);
        } catch (e) {
          return e.message;
        }
      }());
    });
    _lazy($, "TypeErrorDecoder_undefinedCallPattern", "$get$TypeErrorDecoder_undefinedCallPattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokeCallErrorOn(void 0));
    });
    _lazy($, "TypeErrorDecoder_undefinedLiteralCallPattern", "$get$TypeErrorDecoder_undefinedLiteralCallPattern", function() {
      return H.TypeErrorDecoder_extractPattern(function() {
        var $argumentsExpr$ = '$arguments$';
        try {
          (void 0).$method$($argumentsExpr$);
        } catch (e) {
          return e.message;
        }
      }());
    });
    _lazy($, "TypeErrorDecoder_nullPropertyPattern", "$get$TypeErrorDecoder_nullPropertyPattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokePropertyErrorOn(null));
    });
    _lazy($, "TypeErrorDecoder_nullLiteralPropertyPattern", "$get$TypeErrorDecoder_nullLiteralPropertyPattern", function() {
      return H.TypeErrorDecoder_extractPattern(function() {
        try {
          null.$method$;
        } catch (e) {
          return e.message;
        }
      }());
    });
    _lazy($, "TypeErrorDecoder_undefinedPropertyPattern", "$get$TypeErrorDecoder_undefinedPropertyPattern", function() {
      return H.TypeErrorDecoder_extractPattern(H.TypeErrorDecoder_provokePropertyErrorOn(void 0));
    });
    _lazy($, "TypeErrorDecoder_undefinedLiteralPropertyPattern", "$get$TypeErrorDecoder_undefinedLiteralPropertyPattern", function() {
      return H.TypeErrorDecoder_extractPattern(function() {
        try {
          (void 0).$method$;
        } catch (e) {
          return e.message;
        }
      }());
    });
    _lazy($, "_AsyncRun__scheduleImmediateClosure", "$get$_AsyncRun__scheduleImmediateClosure", function() {
      return P._AsyncRun__initializeScheduleImmediate();
    });
    _lazy($, "Future__nullFuture", "$get$Future__nullFuture", function() {
      return P._Future$zoneValue(null, C.C__RootZone, type$.Null);
    });
    _lazy($, "_RootZone__rootMap", "$get$_RootZone__rootMap", function() {
      var t1 = type$.dynamic;
      return P.HashMap_HashMap(t1, t1);
    });
    _lazy($, "Utf8Decoder__decoder", "$get$Utf8Decoder__decoder", function() {
      return P.Utf8Decoder__makeDecoder();
    });
    _lazy($, "_Base64Decoder__inverseAlphabet", "$get$_Base64Decoder__inverseAlphabet", function() {
      return H.NativeInt8List__create1(H._ensureNativeList(H.setRuntimeTypeInfo([-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -1, -2, -2, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2], type$.JSArray_int)));
    });
    _lazy($, "_Uri__isWindowsCached", "$get$_Uri__isWindowsCached", function() {
      return typeof process != "undefined" && Object.prototype.toString.call(process) == "[object process]" && process.platform == "win32";
    });
    _lazy($, "_Uri__needsNoEncoding", "$get$_Uri__needsNoEncoding", function() {
      return P.RegExp_RegExp("^[\\-\\.0-9A-Z_a-z~]*$", false);
    });
    _lazy($, "_hasErrorStackProperty", "$get$_hasErrorStackProperty", function() {
      return new Error().stack != void 0;
    });
    _lazy($, "_scannerTables", "$get$_scannerTables", function() {
      return P._createTables();
    });
    _lazy($, "_whitespaceAndSingleLineComments", "$get$_whitespaceAndSingleLineComments", function() {
      return P.RegExp_RegExp("([ \\t\\n]+|//[^\\n]*(\\n|$))+", false);
    });
    _lazy($, "_multiLineCommentBody", "$get$_multiLineCommentBody", function() {
      return P.RegExp_RegExp("([^/*]|/[^*]|\\*[^/])+", false);
    });
    _lazy($, "_hyphenatedIdentifier", "$get$_hyphenatedIdentifier0", function() {
      return P.RegExp_RegExp("[a-zA-Z_-][a-zA-Z0-9_-]*", false);
    });
    _lazy($, "_dart2DynamicArgs", "$get$_dart2DynamicArgs", function() {
      return P.RegExp_RegExp("<dynamic(, dynamic)*>", false);
    });
    _lazy($, "_escapeRegExp", "$get$_escapeRegExp", function() {
      return P.RegExp_RegExp("[\\x00-\\x07\\x0E-\\x1F" + C.Map_F9GZw.get$keys().map$1$1(0, M.util___getHexLiteral$closure(), type$.String).join$0(0) + "]", false);
    });
    _lazy($, "windows", "$get$windows", function() {
      return M.Context_Context($.$get$Style_windows());
    });
    _lazy($, "url", "$get$url", function() {
      return M.Context_Context($.$get$Style_url());
    });
    _lazy($, "context", "$get$context", function() {
      return new M.Context($.$get$Style_platform(), null);
    });
    _lazy($, "Style_posix", "$get$Style_posix", function() {
      return new E.PosixStyle(P.RegExp_RegExp("/", false), P.RegExp_RegExp("[^/]$", false), P.RegExp_RegExp("^/", false));
    });
    _lazy($, "Style_windows", "$get$Style_windows", function() {
      return new L.WindowsStyle(P.RegExp_RegExp("[/\\\\]", false), P.RegExp_RegExp("[^/\\\\]$", false), P.RegExp_RegExp("^(\\\\\\\\[^\\\\]+\\\\[^\\\\/]+|[a-zA-Z]:[/\\\\])", false), P.RegExp_RegExp("^[/\\\\](?![/\\\\])", false));
    });
    _lazy($, "Style_url", "$get$Style_url", function() {
      return new F.UrlStyle(P.RegExp_RegExp("/", false), P.RegExp_RegExp("(^[a-zA-Z][-+.a-zA-Z\\d]*://|[^/])$", false), P.RegExp_RegExp("[a-zA-Z][-+.a-zA-Z\\d]*://[^/]*", false), P.RegExp_RegExp("^/", false));
    });
    _lazy($, "Style_platform", "$get$Style_platform", function() {
      return O.Style__getPlatformStyle();
    });
    _lazy($, "_digits", "$get$_digits", function() {
      return new L.closure().call$0();
    });
    _lazy($, "MAX_INT32", "$get$MAX_INT32", function() {
      return H._checkIntNullable(P.pow(2, 31) - 1);
    });
    _lazy($, "MIN_INT32", "$get$MIN_INT32", function() {
      return H._checkIntNullable(-P.pow(2, 31));
    });
    _lazy($, "_specKey", "$get$_specKey", function() {
      return new P.Object();
    });
    _lazy($, "_vmFrame", "$get$_vmFrame", function() {
      return P.RegExp_RegExp("^#\\d+\\s+(\\S.*) \\((.+?)((?::\\d+){0,2})\\)$", false);
    });
    _lazy($, "_v8Frame", "$get$_v8Frame", function() {
      return P.RegExp_RegExp("^\\s*at (?:(\\S.*?)(?: \\[as [^\\]]+\\])? \\((.*)\\)|(.*))$", false);
    });
    _lazy($, "_v8UrlLocation", "$get$_v8UrlLocation", function() {
      return P.RegExp_RegExp("^(.*):(\\d+):(\\d+)|native$", false);
    });
    _lazy($, "_v8EvalLocation", "$get$_v8EvalLocation", function() {
      return P.RegExp_RegExp("^eval at (?:\\S.*?) \\((.*)\\)(?:, .*?:\\d+:\\d+)?$", false);
    });
    _lazy($, "_firefoxSafariFrame", "$get$_firefoxSafariFrame", function() {
      return P.RegExp_RegExp("^(?:([^@(/]*)(?:\\(.*\\))?((?:/[^/]*)*)(?:\\(.*\\))?@)?(.*?):(\\d*)(?::(\\d*))?$", false);
    });
    _lazy($, "_friendlyFrame", "$get$_friendlyFrame", function() {
      return P.RegExp_RegExp("^(\\S+)(?: (\\d+)(?::(\\d+))?)?\\s+([^\\d].*)$", false);
    });
    _lazy($, "_asyncBody", "$get$_asyncBody", function() {
      return P.RegExp_RegExp("<(<anonymous closure>|[^>]+)_async_body>", false);
    });
    _lazy($, "_initialDot", "$get$_initialDot", function() {
      return P.RegExp_RegExp("^\\.", false);
    });
    _lazy($, "Frame__uriRegExp", "$get$Frame__uriRegExp", function() {
      return P.RegExp_RegExp("^[a-zA-Z][-+.a-zA-Z\\d]*://", false);
    });
    _lazy($, "Frame__windowsRegExp", "$get$Frame__windowsRegExp", function() {
      return P.RegExp_RegExp("^([a-zA-Z]:[\\\\/]|\\\\\\\\)", false);
    });
    _lazy($, "StackZoneSpecification_disableKey", "$get$StackZoneSpecification_disableKey", function() {
      return new P.Object();
    });
    _lazy($, "_terseRegExp", "$get$_terseRegExp", function() {
      return P.RegExp_RegExp("(-patch)?([/\\\\].*)?$", false);
    });
    _lazy($, "_v8Trace", "$get$_v8Trace", function() {
      return P.RegExp_RegExp("\\n    ?at ", false);
    });
    _lazy($, "_v8TraceLine", "$get$_v8TraceLine", function() {
      return P.RegExp_RegExp("    ?at ", false);
    });
    _lazy($, "_firefoxSafariTrace", "$get$_firefoxSafariTrace", function() {
      return P.RegExp_RegExp("^(([.0-9A-Za-z_$/<]|\\(.*\\))*@)?[^\\s]*:\\d*$", true);
    });
    _lazy($, "_friendlyTrace", "$get$_friendlyTrace", function() {
      return P.RegExp_RegExp("^[^\\s<][^\\s]*( \\d+(:\\d+)?)?[ \\t]+[^\\s]+$", true);
    });
    _lazy($, "Metadata_empty", "$get$Metadata_empty", function() {
      var _null = null;
      return O.Metadata$_(_null, _null, _null, _null, _null, _null, _null, _null, _null, _null);
    });
    _lazy($, "_universalValidVariables", "$get$_universalValidVariables", function() {
      var _i,
        t1 = P.LinkedHashSet_LinkedHashSet(type$.String);
      t1.add$1(0, "posix");
      t1.add$1(0, "dart-vm");
      t1.add$1(0, "browser");
      t1.add$1(0, "js");
      t1.add$1(0, "blink");
      t1.add$1(0, "google");
      for (_i = 0; _i < 7; ++_i)
        t1.add$1(0, C.List_m7e[_i].identifier);
      for (_i = 0; _i < 5; ++_i)
        t1.add$1(0, C.List_opx[_i].identifier);
      return t1;
    });
    _lazy($, "_currentKey", "$get$_currentKey0", function() {
      return new P.Object();
    });
    _lazy($, "_currentKey0", "$get$_currentKey", function() {
      return new P.Object();
    });
    _lazy($, "currentOSGuess", "$get$currentOSGuess", function() {
      return new B.closure0().call$0();
    });
    _lazy($, "_hyphenatedIdentifier0", "$get$_hyphenatedIdentifier", function() {
      return P.RegExp_RegExp("[a-zA-Z_-][a-zA-Z0-9_-]*", false);
    });
    _lazy($, "anchoredHyphenatedIdentifier", "$get$anchoredHyphenatedIdentifier", function() {
      return P.RegExp_RegExp("^" + $.$get$_hyphenatedIdentifier().pattern + "$", false);
    });
    _lazy($, "SuiteConfiguration_empty", "$get$SuiteConfiguration_empty", function() {
      var t1, _null = null;
      U.SuiteConfiguration__list(_null, type$.String);
      t1 = type$.Pattern;
      L.UnmodifiableSetView$(P.LinkedHashSet_LinkedHashSet$_empty(t1), t1);
      U.SuiteConfiguration__list(_null, H.findType("RuntimeSelection"));
      t1 = H.findType("SuiteConfiguration");
      U.SuiteConfiguration__map(_null, type$.BooleanSelector, t1);
      U.SuiteConfiguration__map(_null, type$.PlatformSelector, t1);
      $.$get$Metadata_empty();
      return new U.SuiteConfiguration();
    });
  })();
  (function nativeSupport() {
    !function() {
      var intern = function(s) {
        var o = {};
        o[s] = 1;
        return Object.keys(hunkHelpers.convertToFastObject(o))[0];
      };
      init.getIsolateTag = function(name) {
        return intern("___dart_" + name + init.isolateTag);
      };
      var tableProperty = "___dart_isolate_tags_";
      var usedProperties = Object[tableProperty] || (Object[tableProperty] = Object.create(null));
      var rootProperty = "_ZxYxX";
      for (var i = 0;; i++) {
        var property = intern(rootProperty + "_" + i + "_");
        if (!(property in usedProperties)) {
          usedProperties[property] = 1;
          init.isolateTag = property;
          break;
        }
      }
      init.dispatchPropertyName = init.getIsolateTag("dispatch_record");
    }();
    hunkHelpers.setOrUpdateInterceptorsByTag({ArrayBuffer: H.NativeByteBuffer, ArrayBufferView: H.NativeTypedData, DataView: H.NativeByteData, Float32Array: H.NativeFloat32List, Float64Array: H.NativeFloat64List, Int16Array: H.NativeInt16List, Int32Array: H.NativeInt32List, Int8Array: H.NativeInt8List, Uint16Array: H.NativeUint16List, Uint32Array: H.NativeUint32List, Uint8ClampedArray: H.NativeUint8ClampedList, CanvasPixelArray: H.NativeUint8ClampedList, Uint8Array: H.NativeUint8List, ApplicationCacheErrorEvent: W.ApplicationCacheErrorEvent, Blob: W.Blob, DOMError: W.DomError, DOMException: W.DomException, ErrorEvent: W.ErrorEvent, AbortPaymentEvent: W.Event, AnimationEvent: W.Event, AnimationPlaybackEvent: W.Event, BackgroundFetchClickEvent: W.Event, BackgroundFetchEvent: W.Event, BackgroundFetchFailEvent: W.Event, BackgroundFetchedEvent: W.Event, BeforeInstallPromptEvent: W.Event, BeforeUnloadEvent: W.Event, BlobEvent: W.Event, CanMakePaymentEvent: W.Event, ClipboardEvent: W.Event, CloseEvent: W.Event, CompositionEvent: W.Event, CustomEvent: W.Event, DeviceMotionEvent: W.Event, DeviceOrientationEvent: W.Event, ExtendableEvent: W.Event, ExtendableMessageEvent: W.Event, FetchEvent: W.Event, FocusEvent: W.Event, FontFaceSetLoadEvent: W.Event, ForeignFetchEvent: W.Event, GamepadEvent: W.Event, HashChangeEvent: W.Event, InstallEvent: W.Event, KeyboardEvent: W.Event, MediaEncryptedEvent: W.Event, MediaQueryListEvent: W.Event, MediaStreamEvent: W.Event, MediaStreamTrackEvent: W.Event, MIDIConnectionEvent: W.Event, MIDIMessageEvent: W.Event, MouseEvent: W.Event, DragEvent: W.Event, MutationEvent: W.Event, NotificationEvent: W.Event, PageTransitionEvent: W.Event, PaymentRequestEvent: W.Event, PaymentRequestUpdateEvent: W.Event, PointerEvent: W.Event, PopStateEvent: W.Event, PresentationConnectionAvailableEvent: W.Event, ProgressEvent: W.Event, PromiseRejectionEvent: W.Event, PushEvent: W.Event, RTCDataChannelEvent: W.Event, RTCDTMFToneChangeEvent: W.Event, RTCPeerConnectionIceEvent: W.Event, RTCTrackEvent: W.Event, SecurityPolicyViolationEvent: W.Event, SensorErrorEvent: W.Event, SpeechRecognitionEvent: W.Event, SpeechSynthesisEvent: W.Event, StorageEvent: W.Event, SyncEvent: W.Event, TextEvent: W.Event, TouchEvent: W.Event, TrackEvent: W.Event, TransitionEvent: W.Event, WebKitTransitionEvent: W.Event, UIEvent: W.Event, VRDeviceEvent: W.Event, VRDisplayEvent: W.Event, VRSessionEvent: W.Event, WheelEvent: W.Event, MojoInterfaceRequestEvent: W.Event, ResourceProgressEvent: W.Event, USBConnectionEvent: W.Event, IDBVersionChangeEvent: W.Event, AudioProcessingEvent: W.Event, OfflineAudioCompletionEvent: W.Event, WebGLContextEvent: W.Event, Event: W.Event, InputEvent: W.Event, Window: W.EventTarget, DOMWindow: W.EventTarget, EventTarget: W.EventTarget, File: W.File, Location: W.Location, MediaError: W.MediaError, MediaKeyMessageEvent: W.MediaKeyMessageEvent, MessageEvent: W.MessageEvent, MessagePort: W.MessagePort, NavigatorUserMediaError: W.NavigatorUserMediaError, OverconstrainedError: W.OverconstrainedError, PositionError: W.PositionError, PresentationConnectionCloseEvent: W.PresentationConnectionCloseEvent, SpeechRecognitionError: W.SpeechRecognitionError, SQLError: P.SqlError});
    hunkHelpers.setOrUpdateLeafTags({ArrayBuffer: true, ArrayBufferView: false, DataView: true, Float32Array: true, Float64Array: true, Int16Array: true, Int32Array: true, Int8Array: true, Uint16Array: true, Uint32Array: true, Uint8ClampedArray: true, CanvasPixelArray: true, Uint8Array: false, ApplicationCacheErrorEvent: true, Blob: false, DOMError: true, DOMException: true, ErrorEvent: true, AbortPaymentEvent: true, AnimationEvent: true, AnimationPlaybackEvent: true, BackgroundFetchClickEvent: true, BackgroundFetchEvent: true, BackgroundFetchFailEvent: true, BackgroundFetchedEvent: true, BeforeInstallPromptEvent: true, BeforeUnloadEvent: true, BlobEvent: true, CanMakePaymentEvent: true, ClipboardEvent: true, CloseEvent: true, CompositionEvent: true, CustomEvent: true, DeviceMotionEvent: true, DeviceOrientationEvent: true, ExtendableEvent: true, ExtendableMessageEvent: true, FetchEvent: true, FocusEvent: true, FontFaceSetLoadEvent: true, ForeignFetchEvent: true, GamepadEvent: true, HashChangeEvent: true, InstallEvent: true, KeyboardEvent: true, MediaEncryptedEvent: true, MediaQueryListEvent: true, MediaStreamEvent: true, MediaStreamTrackEvent: true, MIDIConnectionEvent: true, MIDIMessageEvent: true, MouseEvent: true, DragEvent: true, MutationEvent: true, NotificationEvent: true, PageTransitionEvent: true, PaymentRequestEvent: true, PaymentRequestUpdateEvent: true, PointerEvent: true, PopStateEvent: true, PresentationConnectionAvailableEvent: true, ProgressEvent: true, PromiseRejectionEvent: true, PushEvent: true, RTCDataChannelEvent: true, RTCDTMFToneChangeEvent: true, RTCPeerConnectionIceEvent: true, RTCTrackEvent: true, SecurityPolicyViolationEvent: true, SensorErrorEvent: true, SpeechRecognitionEvent: true, SpeechSynthesisEvent: true, StorageEvent: true, SyncEvent: true, TextEvent: true, TouchEvent: true, TrackEvent: true, TransitionEvent: true, WebKitTransitionEvent: true, UIEvent: true, VRDeviceEvent: true, VRDisplayEvent: true, VRSessionEvent: true, WheelEvent: true, MojoInterfaceRequestEvent: true, ResourceProgressEvent: true, USBConnectionEvent: true, IDBVersionChangeEvent: true, AudioProcessingEvent: true, OfflineAudioCompletionEvent: true, WebGLContextEvent: true, Event: false, InputEvent: false, Window: true, DOMWindow: true, EventTarget: false, File: true, Location: true, MediaError: true, MediaKeyMessageEvent: true, MessageEvent: true, MessagePort: true, NavigatorUserMediaError: true, OverconstrainedError: true, PositionError: true, PresentationConnectionCloseEvent: true, SpeechRecognitionError: true, SQLError: true});
    H.NativeTypedArray.$nativeSuperclassTag = "ArrayBufferView";
    H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin.$nativeSuperclassTag = "ArrayBufferView";
    H._NativeTypedArrayOfDouble_NativeTypedArray_ListMixin_FixedLengthListMixin.$nativeSuperclassTag = "ArrayBufferView";
    H.NativeTypedArrayOfDouble.$nativeSuperclassTag = "ArrayBufferView";
    H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin.$nativeSuperclassTag = "ArrayBufferView";
    H._NativeTypedArrayOfInt_NativeTypedArray_ListMixin_FixedLengthListMixin.$nativeSuperclassTag = "ArrayBufferView";
    H.NativeTypedArrayOfInt.$nativeSuperclassTag = "ArrayBufferView";
  })();
  Function.prototype.call$0 = function() {
    return this();
  };
  Function.prototype.call$1 = function(a) {
    return this(a);
  };
  Function.prototype.call$2 = function(a, b) {
    return this(a, b);
  };
  Function.prototype.call$3$3 = function(a, b, c) {
    return this(a, b, c);
  };
  Function.prototype.call$2$2 = function(a, b) {
    return this(a, b);
  };
  Function.prototype.call$1$1 = function(a) {
    return this(a);
  };
  Function.prototype.call$2$1 = function(a) {
    return this(a);
  };
  Function.prototype.call$3 = function(a, b, c) {
    return this(a, b, c);
  };
  Function.prototype.call$4 = function(a, b, c, d) {
    return this(a, b, c, d);
  };
  Function.prototype.call$3$1 = function(a) {
    return this(a);
  };
  Function.prototype.call$2$3 = function(a, b, c) {
    return this(a, b, c);
  };
  Function.prototype.call$1$2 = function(a, b) {
    return this(a, b);
  };
  Function.prototype.call$5 = function(a, b, c, d, e) {
    return this(a, b, c, d, e);
  };
  Function.prototype.call$3$4 = function(a, b, c, d) {
    return this(a, b, c, d);
  };
  Function.prototype.call$2$4 = function(a, b, c, d) {
    return this(a, b, c, d);
  };
  Function.prototype.call$1$4 = function(a, b, c, d) {
    return this(a, b, c, d);
  };
  Function.prototype.call$3$6 = function(a, b, c, d, e, f) {
    return this(a, b, c, d, e, f);
  };
  Function.prototype.call$2$5 = function(a, b, c, d, e) {
    return this(a, b, c, d, e);
  };
  Function.prototype.call$2$0 = function() {
    return this();
  };
  convertAllToFastObject(holders);
  convertToFastObject($);
  (function(callback) {
    if (typeof document === "undefined") {
      callback(null);
      return;
    }
    if (typeof document.currentScript != 'undefined') {
      callback(document.currentScript);
      return;
    }
    var scripts = document.scripts;
    function onLoad(event) {
      for (var i = 0; i < scripts.length; ++i)
        scripts[i].removeEventListener("load", onLoad, false);
      callback(event.target);
    }
    for (var i = 0; i < scripts.length; ++i)
      scripts[i].addEventListener("load", onLoad, false);
  })(function(currentScript) {
    init.currentScript = currentScript;
    if (typeof dartMainRunner === "function")
      dartMainRunner(R.main, []);
    else
      R.main([]);
  });
})();

//# sourceMappingURL=main_test.dart.browser_test.dart.js.map
