abortcontroller-polyfill
Advanced tools
Comparing version 1.7.7 to 1.7.8
@@ -6,180 +6,47 @@ (function (factory) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -189,27 +56,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -219,17 +82,90 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
(function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -257,10 +193,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -273,4 +208,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -287,3 +222,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -295,3 +229,2 @@ } | ||
_classCallCheck(this, Emitter); | ||
Object.defineProperty(this, 'listeners', { | ||
@@ -303,4 +236,3 @@ value: {}, | ||
} | ||
_createClass(Emitter, [{ | ||
return _createClass(Emitter, [{ | ||
key: "addEventListener", | ||
@@ -311,3 +243,2 @@ value: function addEventListener(type, callback, options) { | ||
} | ||
this.listeners[type].push({ | ||
@@ -324,5 +255,3 @@ callback: callback, | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
@@ -338,14 +267,12 @@ if (stack[i].callback === callback) { | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[event.type]; | ||
var stackToCall = stack.slice(); | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
var _loop = function _loop() { | ||
var listener = stackToCall[i]; | ||
try { | ||
listener.callback.call(this, event); | ||
listener.callback.call(_this, event); | ||
} catch (e) { | ||
@@ -356,26 +283,19 @@ Promise.resolve().then(function () { | ||
} | ||
if (listener.options && listener.options.once) { | ||
this.removeEventListener(event.type, listener.callback); | ||
_this.removeEventListener(event.type, listener.callback); | ||
} | ||
}; | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
_loop(); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = /*#__PURE__*/function (_Emitter) { | ||
_inherits(AbortSignal, _Emitter); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
var _this; | ||
var _this2; | ||
_classCallCheck(this, AbortSignal); | ||
_this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
_this2 = _callSuper(this, AbortSignal); | ||
// Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
// constructor has failed to run, then "this.listeners" will still be undefined and then we call | ||
@@ -386,10 +306,9 @@ // the parent constructor directly instead as a workaround. For general details, see babel bug: | ||
// https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 | ||
if (!_this2.listeners) { | ||
Emitter.call(_this2); | ||
} | ||
if (!_this.listeners) { | ||
Emitter.call(_assertThisInitialized(_this)); | ||
} // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// we want Object.keys(new AbortController().signal) to be [] for compat with the native impl | ||
Object.defineProperty(_assertThisInitialized(_this), 'aborted', { | ||
Object.defineProperty(_this2, 'aborted', { | ||
value: false, | ||
@@ -399,3 +318,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'onabort', { | ||
Object.defineProperty(_this2, 'onabort', { | ||
value: null, | ||
@@ -405,3 +324,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'reason', { | ||
Object.defineProperty(_this2, 'reason', { | ||
value: undefined, | ||
@@ -411,6 +330,6 @@ writable: true, | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
_createClass(AbortSignal, [{ | ||
_inherits(AbortSignal, _Emitter); | ||
return _createClass(AbortSignal, [{ | ||
key: "toString", | ||
@@ -425,3 +344,2 @@ value: function toString() { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
@@ -431,9 +349,8 @@ this.onabort.call(this, event); | ||
} | ||
_superPropGet(AbortSignal, "dispatchEvent", this, 3)([event]); | ||
} | ||
_get(_getPrototypeOf(AbortSignal.prototype), "dispatchEvent", this).call(this, event); | ||
} | ||
/** | ||
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/throwIfAborted} | ||
*/ | ||
}, { | ||
@@ -443,7 +360,8 @@ key: "throwIfAborted", | ||
var aborted = this.aborted, | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
if (!aborted) return; | ||
throw reason; | ||
} | ||
/** | ||
@@ -456,3 +374,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}], [{ | ||
@@ -467,2 +384,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -476,3 +394,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -485,3 +402,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -491,7 +407,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -508,10 +422,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -527,8 +438,5 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
@@ -538,3 +446,2 @@ var AbortController = /*#__PURE__*/function () { | ||
_classCallCheck(this, AbortController); | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
@@ -548,4 +455,3 @@ // we want Object.keys(new AbortController()) to be [] for compat with the native impl | ||
} | ||
_createClass(AbortController, [{ | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
@@ -564,6 +470,3 @@ value: function abort(reason) { | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -580,3 +483,5 @@ // These are necessary to make sure that we get correct output for: | ||
return true; | ||
} // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -588,4 +493,2 @@ // so the below feature detection needs the !self.AbortController part. | ||
// https://bugs.webkit.org/show_bug.cgi?id=174980#c2 | ||
return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController; | ||
@@ -599,3 +502,2 @@ } | ||
} | ||
self.AbortController = AbortController; | ||
@@ -602,0 +504,0 @@ self.AbortSignal = AbortSignal; |
@@ -5,180 +5,47 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -188,27 +55,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -218,17 +81,90 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
(function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -256,10 +192,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -272,4 +207,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -286,3 +221,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -294,3 +228,2 @@ } | ||
_classCallCheck(this, Emitter); | ||
Object.defineProperty(this, 'listeners', { | ||
@@ -302,4 +235,3 @@ value: {}, | ||
} | ||
_createClass(Emitter, [{ | ||
return _createClass(Emitter, [{ | ||
key: "addEventListener", | ||
@@ -310,3 +242,2 @@ value: function addEventListener(type, callback, options) { | ||
} | ||
this.listeners[type].push({ | ||
@@ -323,5 +254,3 @@ callback: callback, | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
@@ -337,14 +266,12 @@ if (stack[i].callback === callback) { | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[event.type]; | ||
var stackToCall = stack.slice(); | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
var _loop = function _loop() { | ||
var listener = stackToCall[i]; | ||
try { | ||
listener.callback.call(this, event); | ||
listener.callback.call(_this, event); | ||
} catch (e) { | ||
@@ -355,26 +282,19 @@ Promise.resolve().then(function () { | ||
} | ||
if (listener.options && listener.options.once) { | ||
this.removeEventListener(event.type, listener.callback); | ||
_this.removeEventListener(event.type, listener.callback); | ||
} | ||
}; | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
_loop(); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = /*#__PURE__*/function (_Emitter) { | ||
_inherits(AbortSignal, _Emitter); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
var _this; | ||
var _this2; | ||
_classCallCheck(this, AbortSignal); | ||
_this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
_this2 = _callSuper(this, AbortSignal); | ||
// Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
// constructor has failed to run, then "this.listeners" will still be undefined and then we call | ||
@@ -385,10 +305,9 @@ // the parent constructor directly instead as a workaround. For general details, see babel bug: | ||
// https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 | ||
if (!_this2.listeners) { | ||
Emitter.call(_this2); | ||
} | ||
if (!_this.listeners) { | ||
Emitter.call(_assertThisInitialized(_this)); | ||
} // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// we want Object.keys(new AbortController().signal) to be [] for compat with the native impl | ||
Object.defineProperty(_assertThisInitialized(_this), 'aborted', { | ||
Object.defineProperty(_this2, 'aborted', { | ||
value: false, | ||
@@ -398,3 +317,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'onabort', { | ||
Object.defineProperty(_this2, 'onabort', { | ||
value: null, | ||
@@ -404,3 +323,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'reason', { | ||
Object.defineProperty(_this2, 'reason', { | ||
value: undefined, | ||
@@ -410,6 +329,6 @@ writable: true, | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
_createClass(AbortSignal, [{ | ||
_inherits(AbortSignal, _Emitter); | ||
return _createClass(AbortSignal, [{ | ||
key: "toString", | ||
@@ -424,3 +343,2 @@ value: function toString() { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
@@ -430,9 +348,8 @@ this.onabort.call(this, event); | ||
} | ||
_superPropGet(AbortSignal, "dispatchEvent", this, 3)([event]); | ||
} | ||
_get(_getPrototypeOf(AbortSignal.prototype), "dispatchEvent", this).call(this, event); | ||
} | ||
/** | ||
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/throwIfAborted} | ||
*/ | ||
}, { | ||
@@ -442,7 +359,8 @@ key: "throwIfAborted", | ||
var aborted = this.aborted, | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
if (!aborted) return; | ||
throw reason; | ||
} | ||
/** | ||
@@ -455,3 +373,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}], [{ | ||
@@ -466,2 +383,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -475,3 +393,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -484,3 +401,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -490,7 +406,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -507,10 +421,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -526,8 +437,5 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
@@ -537,3 +445,2 @@ var AbortController = /*#__PURE__*/function () { | ||
_classCallCheck(this, AbortController); | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
@@ -547,4 +454,3 @@ // we want Object.keys(new AbortController()) to be [] for compat with the native impl | ||
} | ||
_createClass(AbortController, [{ | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
@@ -563,6 +469,3 @@ value: function abort(reason) { | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -569,0 +472,0 @@ // These are necessary to make sure that we get correct output for: |
@@ -6,180 +6,47 @@ (function (factory) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -189,27 +56,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -219,28 +82,97 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
var _ref = function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
}(typeof self !== 'undefined' ? self : global), | ||
NativeAbortSignal = _ref.NativeAbortSignal, | ||
NativeAbortController = _ref.NativeAbortController; | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
}(typeof self !== 'undefined' ? self : global), | ||
NativeAbortSignal = _ref.NativeAbortSignal, | ||
NativeAbortController = _ref.NativeAbortController; | ||
var AbortSignal = /*#__PURE__*/function (_NativeAbortSignal) { | ||
_inherits(AbortSignal, _NativeAbortSignal); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
_classCallCheck(this, AbortSignal); | ||
return _callSuper(this, AbortSignal); | ||
} | ||
return _super.call(this); | ||
} | ||
/** | ||
* polyfill flag | ||
*/ | ||
_createClass(AbortSignal, null, [{ | ||
_inherits(AbortSignal, _NativeAbortSignal); | ||
return _createClass(AbortSignal, null, [{ | ||
key: "__polyfill__", | ||
@@ -250,2 +182,3 @@ get: function get() { | ||
} | ||
/** | ||
@@ -258,3 +191,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/abort_static} | ||
*/ | ||
}, { | ||
@@ -267,2 +199,3 @@ key: "abort", | ||
} | ||
/** | ||
@@ -275,3 +208,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}, { | ||
@@ -286,2 +218,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -297,3 +230,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -306,3 +238,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -312,7 +243,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -329,10 +258,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -348,34 +274,24 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(NativeAbortSignal); | ||
var AbortController = /*#__PURE__*/function (_NativeAbortControlle) { | ||
_inherits(AbortController, _NativeAbortControlle); | ||
var _super2 = _createSuper(AbortController); | ||
function AbortController() { | ||
var _this; | ||
_classCallCheck(this, AbortController); | ||
_this = _super2.call(this); | ||
_this = _callSuper(this, AbortController); | ||
patchAbortSignal(_this.signal); | ||
return _this; | ||
} | ||
/** | ||
* polyfill flag | ||
*/ | ||
_createClass(AbortController, [{ | ||
_inherits(AbortController, _NativeAbortControlle); | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
value: function abort(reason) { | ||
if (!this.signal.aborted) { | ||
_get(_getPrototypeOf(AbortController.prototype), "abort", this).call(this, reason); | ||
_superPropGet(AbortController, "abort", this, 3)([reason]); | ||
if (this.signal.__polyfill__) { | ||
@@ -395,5 +311,4 @@ var signalReason = normalizeAbortReason(reason); | ||
}]); | ||
}(NativeAbortController); | ||
return AbortController; | ||
}(NativeAbortController); | ||
/** | ||
@@ -404,3 +319,2 @@ * Make the native {@link AbortSignal} instances support the reason property and the throwIfAborted method. | ||
*/ | ||
function patchAbortSignal(signal) { | ||
@@ -425,7 +339,5 @@ if (!('reason' in signal)) { | ||
var existing = this._onabort; | ||
if (existing) { | ||
this.removeEventListener('abort', existing); | ||
} | ||
this._onabort = callback; | ||
@@ -437,5 +349,4 @@ this.addEventListener('abort', callback); | ||
var dispatchEvent = signal.dispatchEvent, | ||
addEventListener = signal.addEventListener, | ||
removeEventListener = signal.removeEventListener; | ||
addEventListener = signal.addEventListener, | ||
removeEventListener = signal.removeEventListener; | ||
signal.addEventListener = function (type, callback, options) { | ||
@@ -453,9 +364,6 @@ if (type === 'abort' && callback && this.__polyfill__) { | ||
} | ||
callback = callback.__polyfill__; | ||
} | ||
return addEventListener.call(this, type, callback, options); | ||
}; | ||
signal.removeEventListener = function (type, callback, options) { | ||
@@ -465,6 +373,4 @@ if (type === 'abort' && callback && this.__polyfill__ && callback.__polyfill__) { | ||
} | ||
return removeEventListener.call(this, type, callback, options); | ||
}; | ||
signal.dispatchEvent = function (event) { | ||
@@ -476,7 +382,5 @@ if (event.type === 'abort') { | ||
} | ||
return dispatchEvent.call(this, event); | ||
}; | ||
} | ||
if (!('throwIfAborted' in signal)) { | ||
@@ -489,13 +393,10 @@ signal.throwIfAborted = function throwIfAborted() { | ||
} | ||
return signal; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -523,10 +424,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -539,4 +439,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -553,3 +453,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -563,3 +462,2 @@ } | ||
} | ||
return !!self.AbortController && typeof self.AbortSignal === 'function' && !self.AbortSignal.prototype.hasOwnProperty('reason'); | ||
@@ -573,7 +471,5 @@ } | ||
} | ||
if (!self.AbortSignal.__polyfill__) { | ||
self.AbortSignal = AbortSignal; | ||
} | ||
if (!self.AbortController.__polyfill__) { | ||
@@ -580,0 +476,0 @@ self.AbortController = AbortController; |
@@ -5,180 +5,47 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -188,27 +55,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -218,28 +81,97 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
var _ref = function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
}(typeof self !== 'undefined' ? self : global), | ||
NativeAbortSignal = _ref.NativeAbortSignal, | ||
NativeAbortController = _ref.NativeAbortController; | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
}(typeof self !== 'undefined' ? self : global), | ||
NativeAbortSignal = _ref.NativeAbortSignal, | ||
NativeAbortController = _ref.NativeAbortController; | ||
var AbortSignal = /*#__PURE__*/function (_NativeAbortSignal) { | ||
_inherits(AbortSignal, _NativeAbortSignal); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
_classCallCheck(this, AbortSignal); | ||
return _callSuper(this, AbortSignal); | ||
} | ||
return _super.call(this); | ||
} | ||
/** | ||
* polyfill flag | ||
*/ | ||
_createClass(AbortSignal, null, [{ | ||
_inherits(AbortSignal, _NativeAbortSignal); | ||
return _createClass(AbortSignal, null, [{ | ||
key: "__polyfill__", | ||
@@ -249,2 +181,3 @@ get: function get() { | ||
} | ||
/** | ||
@@ -257,3 +190,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/abort_static} | ||
*/ | ||
}, { | ||
@@ -266,2 +198,3 @@ key: "abort", | ||
} | ||
/** | ||
@@ -274,3 +207,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}, { | ||
@@ -285,2 +217,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -296,3 +229,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -305,3 +237,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -311,7 +242,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -328,10 +257,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -347,34 +273,24 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(NativeAbortSignal); | ||
var AbortController = /*#__PURE__*/function (_NativeAbortControlle) { | ||
_inherits(AbortController, _NativeAbortControlle); | ||
var _super2 = _createSuper(AbortController); | ||
function AbortController() { | ||
var _this; | ||
_classCallCheck(this, AbortController); | ||
_this = _super2.call(this); | ||
_this = _callSuper(this, AbortController); | ||
patchAbortSignal(_this.signal); | ||
return _this; | ||
} | ||
/** | ||
* polyfill flag | ||
*/ | ||
_createClass(AbortController, [{ | ||
_inherits(AbortController, _NativeAbortControlle); | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
value: function abort(reason) { | ||
if (!this.signal.aborted) { | ||
_get(_getPrototypeOf(AbortController.prototype), "abort", this).call(this, reason); | ||
_superPropGet(AbortController, "abort", this, 3)([reason]); | ||
if (this.signal.__polyfill__) { | ||
@@ -394,5 +310,4 @@ var signalReason = normalizeAbortReason(reason); | ||
}]); | ||
}(NativeAbortController); | ||
return AbortController; | ||
}(NativeAbortController); | ||
/** | ||
@@ -403,3 +318,2 @@ * Make the native {@link AbortSignal} instances support the reason property and the throwIfAborted method. | ||
*/ | ||
function patchAbortSignal(signal) { | ||
@@ -424,7 +338,5 @@ if (!('reason' in signal)) { | ||
var existing = this._onabort; | ||
if (existing) { | ||
this.removeEventListener('abort', existing); | ||
} | ||
this._onabort = callback; | ||
@@ -436,5 +348,4 @@ this.addEventListener('abort', callback); | ||
var dispatchEvent = signal.dispatchEvent, | ||
addEventListener = signal.addEventListener, | ||
removeEventListener = signal.removeEventListener; | ||
addEventListener = signal.addEventListener, | ||
removeEventListener = signal.removeEventListener; | ||
signal.addEventListener = function (type, callback, options) { | ||
@@ -452,9 +363,6 @@ if (type === 'abort' && callback && this.__polyfill__) { | ||
} | ||
callback = callback.__polyfill__; | ||
} | ||
return addEventListener.call(this, type, callback, options); | ||
}; | ||
signal.removeEventListener = function (type, callback, options) { | ||
@@ -464,6 +372,4 @@ if (type === 'abort' && callback && this.__polyfill__ && callback.__polyfill__) { | ||
} | ||
return removeEventListener.call(this, type, callback, options); | ||
}; | ||
signal.dispatchEvent = function (event) { | ||
@@ -475,7 +381,5 @@ if (event.type === 'abort') { | ||
} | ||
return dispatchEvent.call(this, event); | ||
}; | ||
} | ||
if (!('throwIfAborted' in signal)) { | ||
@@ -488,13 +392,10 @@ signal.throwIfAborted = function throwIfAborted() { | ||
} | ||
return signal; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -522,10 +423,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -538,4 +438,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -552,3 +452,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -555,0 +454,0 @@ } |
@@ -5,180 +5,47 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -188,27 +55,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -218,17 +81,90 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
(function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -256,10 +192,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -272,4 +207,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -286,3 +221,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -294,3 +228,2 @@ } | ||
_classCallCheck(this, Emitter); | ||
Object.defineProperty(this, 'listeners', { | ||
@@ -302,4 +235,3 @@ value: {}, | ||
} | ||
_createClass(Emitter, [{ | ||
return _createClass(Emitter, [{ | ||
key: "addEventListener", | ||
@@ -310,3 +242,2 @@ value: function addEventListener(type, callback, options) { | ||
} | ||
this.listeners[type].push({ | ||
@@ -323,5 +254,3 @@ callback: callback, | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
@@ -337,14 +266,12 @@ if (stack[i].callback === callback) { | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[event.type]; | ||
var stackToCall = stack.slice(); | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
var _loop = function _loop() { | ||
var listener = stackToCall[i]; | ||
try { | ||
listener.callback.call(this, event); | ||
listener.callback.call(_this, event); | ||
} catch (e) { | ||
@@ -355,26 +282,19 @@ Promise.resolve().then(function () { | ||
} | ||
if (listener.options && listener.options.once) { | ||
this.removeEventListener(event.type, listener.callback); | ||
_this.removeEventListener(event.type, listener.callback); | ||
} | ||
}; | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
_loop(); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = /*#__PURE__*/function (_Emitter) { | ||
_inherits(AbortSignal, _Emitter); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
var _this; | ||
var _this2; | ||
_classCallCheck(this, AbortSignal); | ||
_this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
_this2 = _callSuper(this, AbortSignal); | ||
// Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
// constructor has failed to run, then "this.listeners" will still be undefined and then we call | ||
@@ -385,10 +305,9 @@ // the parent constructor directly instead as a workaround. For general details, see babel bug: | ||
// https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 | ||
if (!_this2.listeners) { | ||
Emitter.call(_this2); | ||
} | ||
if (!_this.listeners) { | ||
Emitter.call(_assertThisInitialized(_this)); | ||
} // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// we want Object.keys(new AbortController().signal) to be [] for compat with the native impl | ||
Object.defineProperty(_assertThisInitialized(_this), 'aborted', { | ||
Object.defineProperty(_this2, 'aborted', { | ||
value: false, | ||
@@ -398,3 +317,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'onabort', { | ||
Object.defineProperty(_this2, 'onabort', { | ||
value: null, | ||
@@ -404,3 +323,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'reason', { | ||
Object.defineProperty(_this2, 'reason', { | ||
value: undefined, | ||
@@ -410,6 +329,6 @@ writable: true, | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
_createClass(AbortSignal, [{ | ||
_inherits(AbortSignal, _Emitter); | ||
return _createClass(AbortSignal, [{ | ||
key: "toString", | ||
@@ -424,3 +343,2 @@ value: function toString() { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
@@ -430,9 +348,8 @@ this.onabort.call(this, event); | ||
} | ||
_superPropGet(AbortSignal, "dispatchEvent", this, 3)([event]); | ||
} | ||
_get(_getPrototypeOf(AbortSignal.prototype), "dispatchEvent", this).call(this, event); | ||
} | ||
/** | ||
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/throwIfAborted} | ||
*/ | ||
}, { | ||
@@ -442,7 +359,8 @@ key: "throwIfAborted", | ||
var aborted = this.aborted, | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
if (!aborted) return; | ||
throw reason; | ||
} | ||
/** | ||
@@ -455,3 +373,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}], [{ | ||
@@ -466,2 +383,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -475,3 +393,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -484,3 +401,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -490,7 +406,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -507,10 +421,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -526,8 +437,5 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
@@ -537,3 +445,2 @@ var AbortController = /*#__PURE__*/function () { | ||
_classCallCheck(this, AbortController); | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
@@ -547,4 +454,3 @@ // we want Object.keys(new AbortController()) to be [] for compat with the native impl | ||
} | ||
_createClass(AbortController, [{ | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
@@ -563,6 +469,3 @@ value: function abort(reason) { | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -579,3 +482,5 @@ // These are necessary to make sure that we get correct output for: | ||
return true; | ||
} // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -587,4 +492,2 @@ // so the below feature detection needs the !self.AbortController part. | ||
// https://bugs.webkit.org/show_bug.cgi?id=174980#c2 | ||
return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController; | ||
@@ -606,3 +509,2 @@ } | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
@@ -614,11 +516,9 @@ if ('function' === typeof patchTargets) { | ||
} | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ | ||
@@ -635,4 +535,4 @@ fetch: fetch, | ||
} | ||
var Request = NativeRequest; // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -648,9 +548,8 @@ // hence we only patch it if it's available. Also we don't patch it if signal | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var signal; | ||
if (init && init.signal) { | ||
signal = init.signal; // Never pass init.signal to the native Request implementation when the polyfill has | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
@@ -661,8 +560,5 @@ // working native AbortController (i.e. the polyfill was installed due to | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
@@ -676,17 +572,11 @@ Object.defineProperty(request, 'signal', { | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
if (signal) { | ||
var abortError; | ||
try { | ||
@@ -699,10 +589,10 @@ abortError = new DOMException('Aborted', 'AbortError'); | ||
abortError.name = 'AbortError'; | ||
} // Return early if already aborted, thus avoiding making an HTTP request | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
} // Turn an event into a promise, reject it once `abort` is dispatched | ||
} | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
@@ -715,3 +605,2 @@ signal.addEventListener('abort', function () { | ||
}); | ||
if (init && init.signal) { | ||
@@ -725,11 +614,8 @@ // Never pass .signal to the native implementation when the polyfill has | ||
delete init.signal; | ||
} // Return the fastest promise (don't need to wait for request to finish) | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
return realFetch(input, init); | ||
}; | ||
return { | ||
@@ -736,0 +622,0 @@ fetch: abortableFetch, |
@@ -6,180 +6,47 @@ (function (factory) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -189,27 +56,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -219,17 +82,90 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
(function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -257,10 +193,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -273,4 +208,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -287,3 +222,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -295,3 +229,2 @@ } | ||
_classCallCheck(this, Emitter); | ||
Object.defineProperty(this, 'listeners', { | ||
@@ -303,4 +236,3 @@ value: {}, | ||
} | ||
_createClass(Emitter, [{ | ||
return _createClass(Emitter, [{ | ||
key: "addEventListener", | ||
@@ -311,3 +243,2 @@ value: function addEventListener(type, callback, options) { | ||
} | ||
this.listeners[type].push({ | ||
@@ -324,5 +255,3 @@ callback: callback, | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
@@ -338,14 +267,12 @@ if (stack[i].callback === callback) { | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[event.type]; | ||
var stackToCall = stack.slice(); | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
var _loop = function _loop() { | ||
var listener = stackToCall[i]; | ||
try { | ||
listener.callback.call(this, event); | ||
listener.callback.call(_this, event); | ||
} catch (e) { | ||
@@ -356,26 +283,19 @@ Promise.resolve().then(function () { | ||
} | ||
if (listener.options && listener.options.once) { | ||
this.removeEventListener(event.type, listener.callback); | ||
_this.removeEventListener(event.type, listener.callback); | ||
} | ||
}; | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
_loop(); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = /*#__PURE__*/function (_Emitter) { | ||
_inherits(AbortSignal, _Emitter); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
var _this; | ||
var _this2; | ||
_classCallCheck(this, AbortSignal); | ||
_this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
_this2 = _callSuper(this, AbortSignal); | ||
// Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
// constructor has failed to run, then "this.listeners" will still be undefined and then we call | ||
@@ -386,10 +306,9 @@ // the parent constructor directly instead as a workaround. For general details, see babel bug: | ||
// https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 | ||
if (!_this2.listeners) { | ||
Emitter.call(_this2); | ||
} | ||
if (!_this.listeners) { | ||
Emitter.call(_assertThisInitialized(_this)); | ||
} // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// we want Object.keys(new AbortController().signal) to be [] for compat with the native impl | ||
Object.defineProperty(_assertThisInitialized(_this), 'aborted', { | ||
Object.defineProperty(_this2, 'aborted', { | ||
value: false, | ||
@@ -399,3 +318,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'onabort', { | ||
Object.defineProperty(_this2, 'onabort', { | ||
value: null, | ||
@@ -405,3 +324,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'reason', { | ||
Object.defineProperty(_this2, 'reason', { | ||
value: undefined, | ||
@@ -411,6 +330,6 @@ writable: true, | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
_createClass(AbortSignal, [{ | ||
_inherits(AbortSignal, _Emitter); | ||
return _createClass(AbortSignal, [{ | ||
key: "toString", | ||
@@ -425,3 +344,2 @@ value: function toString() { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
@@ -431,9 +349,8 @@ this.onabort.call(this, event); | ||
} | ||
_superPropGet(AbortSignal, "dispatchEvent", this, 3)([event]); | ||
} | ||
_get(_getPrototypeOf(AbortSignal.prototype), "dispatchEvent", this).call(this, event); | ||
} | ||
/** | ||
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/throwIfAborted} | ||
*/ | ||
}, { | ||
@@ -443,7 +360,8 @@ key: "throwIfAborted", | ||
var aborted = this.aborted, | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
if (!aborted) return; | ||
throw reason; | ||
} | ||
/** | ||
@@ -456,3 +374,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}], [{ | ||
@@ -467,2 +384,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -476,3 +394,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -485,3 +402,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -491,7 +407,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -508,10 +422,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -527,8 +438,5 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
@@ -538,3 +446,2 @@ var AbortController = /*#__PURE__*/function () { | ||
_classCallCheck(this, AbortController); | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
@@ -548,4 +455,3 @@ // we want Object.keys(new AbortController()) to be [] for compat with the native impl | ||
} | ||
_createClass(AbortController, [{ | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
@@ -564,6 +470,3 @@ value: function abort(reason) { | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -580,3 +483,5 @@ // These are necessary to make sure that we get correct output for: | ||
return true; | ||
} // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -588,4 +493,2 @@ // so the below feature detection needs the !self.AbortController part. | ||
// https://bugs.webkit.org/show_bug.cgi?id=174980#c2 | ||
return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController; | ||
@@ -607,3 +510,2 @@ } | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
@@ -615,11 +517,9 @@ if ('function' === typeof patchTargets) { | ||
} | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ | ||
@@ -636,4 +536,4 @@ fetch: fetch, | ||
} | ||
var Request = NativeRequest; // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -649,9 +549,8 @@ // hence we only patch it if it's available. Also we don't patch it if signal | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var signal; | ||
if (init && init.signal) { | ||
signal = init.signal; // Never pass init.signal to the native Request implementation when the polyfill has | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
@@ -662,8 +561,5 @@ // working native AbortController (i.e. the polyfill was installed due to | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
@@ -677,17 +573,11 @@ Object.defineProperty(request, 'signal', { | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
if (signal) { | ||
var abortError; | ||
try { | ||
@@ -700,10 +590,10 @@ abortError = new DOMException('Aborted', 'AbortError'); | ||
abortError.name = 'AbortError'; | ||
} // Return early if already aborted, thus avoiding making an HTTP request | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
} // Turn an event into a promise, reject it once `abort` is dispatched | ||
} | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
@@ -716,3 +606,2 @@ signal.addEventListener('abort', function () { | ||
}); | ||
if (init && init.signal) { | ||
@@ -726,11 +615,8 @@ // Never pass .signal to the native implementation when the polyfill has | ||
delete init.signal; | ||
} // Return the fastest promise (don't need to wait for request to finish) | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
return realFetch(input, init); | ||
}; | ||
return { | ||
@@ -747,3 +633,2 @@ fetch: abortableFetch, | ||
} | ||
if (!self.fetch) { | ||
@@ -753,7 +638,5 @@ console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
} | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
self.fetch = fetch; | ||
@@ -760,0 +643,0 @@ self.Request = Request; |
@@ -6,180 +6,47 @@ (function (factory) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _arrayLikeToArray(r, a) { | ||
(null == a || a > r.length) && (a = r.length); | ||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; | ||
return n; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
function _assertThisInitialized(e) { | ||
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
return e; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
function _callSuper(t, o, e) { | ||
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _classCallCheck(a, n) { | ||
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
function _defineProperties(e, r) { | ||
for (var t = 0; t < r.length; t++) { | ||
var o = r[t]; | ||
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
function _createClass(e, r, t) { | ||
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { | ||
writable: !1 | ||
}), e; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function () {}; | ||
function _createForOfIteratorHelper(r, e) { | ||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; | ||
if (!t) { | ||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { | ||
t && (r = t); | ||
var n = 0, | ||
F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
return n >= r.length ? { | ||
done: !0 | ||
} : { | ||
done: !1, | ||
value: r[n++] | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
e: function (r) { | ||
throw r; | ||
}, | ||
@@ -189,27 +56,23 @@ f: F | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
var o, | ||
a = !0, | ||
u = !1; | ||
return { | ||
s: function () { | ||
it = it.call(o); | ||
t = t.call(r); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
var r = t.next(); | ||
return a = r.done, r; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
e: function (r) { | ||
u = !0, o = r; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
a || null == t.return || t.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
if (u) throw o; | ||
} | ||
@@ -219,17 +82,90 @@ } | ||
} | ||
function _get() { | ||
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { | ||
var p = _superPropBase(e, t); | ||
if (p) { | ||
var n = Object.getOwnPropertyDescriptor(p, t); | ||
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; | ||
} | ||
}, _get.apply(null, arguments); | ||
} | ||
function _getPrototypeOf(t) { | ||
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { | ||
return t.__proto__ || Object.getPrototypeOf(t); | ||
}, _getPrototypeOf(t); | ||
} | ||
function _inherits(t, e) { | ||
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); | ||
t.prototype = Object.create(e && e.prototype, { | ||
constructor: { | ||
value: t, | ||
writable: !0, | ||
configurable: !0 | ||
} | ||
}), Object.defineProperty(t, "prototype", { | ||
writable: !1 | ||
}), e && _setPrototypeOf(t, e); | ||
} | ||
function _isNativeReflectConstruct() { | ||
try { | ||
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} catch (t) {} | ||
return (_isNativeReflectConstruct = function () { | ||
return !!t; | ||
})(); | ||
} | ||
function _possibleConstructorReturn(t, e) { | ||
if (e && ("object" == typeof e || "function" == typeof e)) return e; | ||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); | ||
return _assertThisInitialized(t); | ||
} | ||
function _setPrototypeOf(t, e) { | ||
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { | ||
return t.__proto__ = e, t; | ||
}, _setPrototypeOf(t, e); | ||
} | ||
function _superPropBase(t, o) { | ||
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); | ||
return t; | ||
} | ||
function _superPropGet(t, o, e, r) { | ||
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); | ||
return 2 & r && "function" == typeof p ? function (t) { | ||
return p.apply(e, t); | ||
} : p; | ||
} | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _unsupportedIterableToArray(r, a) { | ||
if (r) { | ||
if ("string" == typeof r) return _arrayLikeToArray(r, a); | ||
var t = {}.toString.call(r).slice(8, -1); | ||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; | ||
} | ||
} | ||
(function (self) { | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
return { | ||
NativeAbortSignal: self.AbortSignal, | ||
NativeAbortController: self.AbortController | ||
}; | ||
})(typeof self !== 'undefined' ? self : global); | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function createAbortEvent(reason) { | ||
var event; | ||
try { | ||
@@ -257,10 +193,9 @@ event = new Event('abort'); | ||
} | ||
event.reason = reason; | ||
return event; | ||
} | ||
/** | ||
* @param {any} reason abort reason | ||
*/ | ||
function normalizeAbortReason(reason) { | ||
@@ -273,4 +208,4 @@ if (reason === undefined) { | ||
try { | ||
reason = new DOMException('signal is aborted without reason'); // The DOMException does not support setting the name property directly. | ||
reason = new DOMException('signal is aborted without reason'); | ||
// The DOMException does not support setting the name property directly. | ||
Object.defineProperty(reason, 'name', { | ||
@@ -287,3 +222,2 @@ value: 'AbortError' | ||
} | ||
return reason; | ||
@@ -295,3 +229,2 @@ } | ||
_classCallCheck(this, Emitter); | ||
Object.defineProperty(this, 'listeners', { | ||
@@ -303,4 +236,3 @@ value: {}, | ||
} | ||
_createClass(Emitter, [{ | ||
return _createClass(Emitter, [{ | ||
key: "addEventListener", | ||
@@ -311,3 +243,2 @@ value: function addEventListener(type, callback, options) { | ||
} | ||
this.listeners[type].push({ | ||
@@ -324,5 +255,3 @@ callback: callback, | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
@@ -338,14 +267,12 @@ if (stack[i].callback === callback) { | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[event.type]; | ||
var stackToCall = stack.slice(); | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
var _loop = function _loop() { | ||
var listener = stackToCall[i]; | ||
try { | ||
listener.callback.call(this, event); | ||
listener.callback.call(_this, event); | ||
} catch (e) { | ||
@@ -356,26 +283,19 @@ Promise.resolve().then(function () { | ||
} | ||
if (listener.options && listener.options.once) { | ||
this.removeEventListener(event.type, listener.callback); | ||
_this.removeEventListener(event.type, listener.callback); | ||
} | ||
}; | ||
for (var i = 0, l = stackToCall.length; i < l; i++) { | ||
_loop(); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = /*#__PURE__*/function (_Emitter) { | ||
_inherits(AbortSignal, _Emitter); | ||
var _super = _createSuper(AbortSignal); | ||
function AbortSignal() { | ||
var _this; | ||
var _this2; | ||
_classCallCheck(this, AbortSignal); | ||
_this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
_this2 = _callSuper(this, AbortSignal); | ||
// Some versions of babel does not transpile super() correctly for IE <= 10, if the parent | ||
// constructor has failed to run, then "this.listeners" will still be undefined and then we call | ||
@@ -386,10 +306,9 @@ // the parent constructor directly instead as a workaround. For general details, see babel bug: | ||
// https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 | ||
if (!_this2.listeners) { | ||
Emitter.call(_this2); | ||
} | ||
if (!_this.listeners) { | ||
Emitter.call(_assertThisInitialized(_this)); | ||
} // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
// we want Object.keys(new AbortController().signal) to be [] for compat with the native impl | ||
Object.defineProperty(_assertThisInitialized(_this), 'aborted', { | ||
Object.defineProperty(_this2, 'aborted', { | ||
value: false, | ||
@@ -399,3 +318,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'onabort', { | ||
Object.defineProperty(_this2, 'onabort', { | ||
value: null, | ||
@@ -405,3 +324,3 @@ writable: true, | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), 'reason', { | ||
Object.defineProperty(_this2, 'reason', { | ||
value: undefined, | ||
@@ -411,6 +330,6 @@ writable: true, | ||
}); | ||
return _this; | ||
return _this2; | ||
} | ||
_createClass(AbortSignal, [{ | ||
_inherits(AbortSignal, _Emitter); | ||
return _createClass(AbortSignal, [{ | ||
key: "toString", | ||
@@ -425,3 +344,2 @@ value: function toString() { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
@@ -431,9 +349,8 @@ this.onabort.call(this, event); | ||
} | ||
_superPropGet(AbortSignal, "dispatchEvent", this, 3)([event]); | ||
} | ||
_get(_getPrototypeOf(AbortSignal.prototype), "dispatchEvent", this).call(this, event); | ||
} | ||
/** | ||
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/throwIfAborted} | ||
*/ | ||
}, { | ||
@@ -443,7 +360,8 @@ key: "throwIfAborted", | ||
var aborted = this.aborted, | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
_this$reason = this.reason, | ||
reason = _this$reason === void 0 ? 'Aborted' : _this$reason; | ||
if (!aborted) return; | ||
throw reason; | ||
} | ||
/** | ||
@@ -456,3 +374,2 @@ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal/timeout_static} | ||
*/ | ||
}], [{ | ||
@@ -467,2 +384,3 @@ key: "timeout", | ||
} | ||
/** | ||
@@ -476,3 +394,2 @@ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static} | ||
*/ | ||
}, { | ||
@@ -485,3 +402,2 @@ key: "any", | ||
*/ | ||
function abort() { | ||
@@ -491,7 +407,5 @@ controller.abort(this.reason); | ||
} | ||
function clean() { | ||
var _iterator = _createForOfIteratorHelper(iterable), | ||
_step; | ||
_step; | ||
try { | ||
@@ -508,10 +422,7 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(iterable), | ||
_step2; | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var signal = _step2.value; | ||
if (signal.aborted) { | ||
@@ -527,8 +438,5 @@ controller.abort(signal.reason); | ||
} | ||
return controller.signal; | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
@@ -538,3 +446,2 @@ var AbortController = /*#__PURE__*/function () { | ||
_classCallCheck(this, AbortController); | ||
// Compared to assignment, Object.defineProperty makes properties non-enumerable by default and | ||
@@ -548,4 +455,3 @@ // we want Object.keys(new AbortController()) to be [] for compat with the native impl | ||
} | ||
_createClass(AbortController, [{ | ||
return _createClass(AbortController, [{ | ||
key: "abort", | ||
@@ -564,6 +470,3 @@ value: function abort(reason) { | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
@@ -580,3 +483,5 @@ // These are necessary to make sure that we get correct output for: | ||
return true; | ||
} // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -588,4 +493,2 @@ // so the below feature detection needs the !self.AbortController part. | ||
// https://bugs.webkit.org/show_bug.cgi?id=174980#c2 | ||
return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController; | ||
@@ -607,3 +510,2 @@ } | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
@@ -615,11 +517,9 @@ if ('function' === typeof patchTargets) { | ||
} | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ | ||
@@ -636,4 +536,4 @@ fetch: fetch, | ||
} | ||
var Request = NativeRequest; // Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
@@ -649,9 +549,8 @@ // hence we only patch it if it's available. Also we don't patch it if signal | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var signal; | ||
if (init && init.signal) { | ||
signal = init.signal; // Never pass init.signal to the native Request implementation when the polyfill has | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
@@ -662,8 +561,5 @@ // working native AbortController (i.e. the polyfill was installed due to | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
@@ -677,17 +573,11 @@ Object.defineProperty(request, 'signal', { | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
if (signal) { | ||
var abortError; | ||
try { | ||
@@ -700,10 +590,10 @@ abortError = new DOMException('Aborted', 'AbortError'); | ||
abortError.name = 'AbortError'; | ||
} // Return early if already aborted, thus avoiding making an HTTP request | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
} // Turn an event into a promise, reject it once `abort` is dispatched | ||
} | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
@@ -716,3 +606,2 @@ signal.addEventListener('abort', function () { | ||
}); | ||
if (init && init.signal) { | ||
@@ -726,11 +615,8 @@ // Never pass .signal to the native implementation when the polyfill has | ||
delete init.signal; | ||
} // Return the fastest promise (don't need to wait for request to finish) | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
return realFetch(input, init); | ||
}; | ||
return { | ||
@@ -747,3 +633,2 @@ fetch: abortableFetch, | ||
} | ||
if (!self.fetch) { | ||
@@ -753,7 +638,5 @@ console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
} | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
self.fetch = fetch; | ||
@@ -760,0 +643,0 @@ self.Request = Request; |
{ | ||
"name": "abortcontroller-polyfill", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"description": "Polyfill/ponyfill for the AbortController DOM API + optional patching of fetch (stub that calls catch, doesn't actually abort request).", | ||
@@ -13,3 +13,3 @@ "main": "dist/umd-polyfill.js", | ||
"prepare": "npm run build", | ||
"test": "npm run build && npm-run-all test-headless eslint", | ||
"test": "npm run build && npm run eslint && npm run test-headless", | ||
"test-headless": "cross-env EE_BROWSER=chrome EE_HEADLESS=1 ./scripts/wdio-suppress-exitcode", | ||
@@ -28,19 +28,19 @@ "test-chrome": "cross-env EE_BROWSER=chrome ./scripts/wdio-suppress-exitcode", | ||
"devDependencies": { | ||
"@babel/cli": "^7.19.3", | ||
"@babel/core": "^7.19.3", | ||
"@babel/plugin-transform-member-expression-literals": "^7.18.6", | ||
"@babel/preset-env": "^7.19.3", | ||
"@wdio/cli": "^9.2.10", | ||
"@wdio/jasmine-framework": "^9.2.8", | ||
"@wdio/local-runner": "^9.2.8", | ||
"@wdio/spec-reporter": "^9.2.8", | ||
"@babel/cli": "^7.26.4", | ||
"@babel/core": "^7.26.0", | ||
"@babel/plugin-transform-member-expression-literals": "^7.25.9", | ||
"@babel/preset-env": "^7.26.0", | ||
"@wdio/cli": "^9.4.1", | ||
"@wdio/jasmine-framework": "^9.4.1", | ||
"@wdio/local-runner": "^9.4.1", | ||
"@wdio/spec-reporter": "^9.2.14", | ||
"chalk": "^5.3.0", | ||
"cross-env": "^7.0.3", | ||
"detect-browser": "^5.3.0", | ||
"eslint": "^8.25.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.7.1", | ||
"prettier": "^3.4.2", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"webdriverio": "^9.2.8" | ||
"webdriverio": "^9.4.1" | ||
} | ||
} |
158064
4092