Guest User

Untitled

a guest
Sep 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 108.41 KB | None | 0 0
  1. /* Polyfill service v3.25.1
  2. * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
  3. *
  4. * UA detected: ie/11.0.0
  5. * Features requested: default
  6. *
  7. * - Object.assign, License: CC0 (required by "default", "_Iterator", "_ArrayIterator", "Array.from")
  8. * - Symbol, License: MIT (required by "Map", "default", "Set", "Symbol.iterator", "Symbol.species", "_Iterator", "_ArrayIterator", "Array.from", "Symbol.toStringTag")
  9. * - Symbol.iterator, License: MIT (required by "Map", "default", "Set", "_Iterator", "_ArrayIterator", "Array.from")
  10. * - Symbol.toStringTag, License: MIT (required by "_Iterator", "_ArrayIterator", "Array.from", "default")
  11. * - _Iterator, License: MIT (required by "_ArrayIterator", "Array.from", "default")
  12. * - Object.setPrototypeOf, License: MIT (required by "_ArrayIterator", "Array.from", "default")
  13. * - String.prototype.includes, License: CC0 (required by "default", "String.prototype.contains", "_ArrayIterator", "Array.from")
  14. * - String.prototype.contains, License: CC0 (required by "_ArrayIterator", "Array.from", "default")
  15. * - _ArrayIterator, License: MIT (required by "Array.from", "default")
  16. * - Number.isFinite, License: MIT (required by "Array.from", "default")
  17. * - Number.isNaN, License: MIT (required by "default", "Array.from", "Map", "Set")
  18. * - Array.from, License: CC0 (required by "default")
  19. * - Array.of, License: MIT (required by "default")
  20. * - Array.prototype.fill, License: CC0 (required by "default")
  21. * - Event, License: CC0 (required by "default", "CustomEvent")
  22. * - CustomEvent, License: CC0 (required by "default")
  23. * - _DOMTokenList, License: ISC (required by "DOMTokenList", "default")
  24. * - DOMTokenList, License: CC0 (required by "default", "Element.prototype.classList")
  25. * - _mutation, License: CC0 (required by "DocumentFragment.prototype.append", "default", "DocumentFragment.prototype.prepend", "Element.prototype.after", "Element.prototype.append", "Element.prototype.before", "Element.prototype.prepend", "Element.prototype.remove", "Element.prototype.replaceWith")
  26. * - DocumentFragment.prototype.append, License: CC0 (required by "default")
  27. * - DocumentFragment.prototype.prepend, License: CC0 (required by "default")
  28. * - Element.prototype.after, License: CC0 (required by "default")
  29. * - Element.prototype.append, License: CC0 (required by "default")
  30. * - Element.prototype.before, License: CC0 (required by "default")
  31. * - Element.prototype.classList, License: ISC (required by "default")
  32. * - Element.prototype.matches, License: CC0 (required by "default", "Element.prototype.closest")
  33. * - Element.prototype.closest, License: CC0 (required by "default")
  34. * - Element.prototype.prepend, License: CC0 (required by "default")
  35. * - Element.prototype.remove, License: CC0 (required by "default")
  36. * - Element.prototype.replaceWith, License: CC0 (required by "default")
  37. * - Symbol.species, License: MIT (required by "Map", "default", "Set")
  38. * - Map, License: CC0 (required by "default")
  39. * - Node.prototype.contains, License: CC0 (required by "default")
  40. * - Promise, License: MIT (required by "default")
  41. * - Set, License: CC0 (required by "default")
  42. * - String.prototype.endsWith, License: CC0 (required by "default")
  43. * - String.prototype.startsWith, License: CC0 (required by "default")
  44. * - URL, License: CC0 (required by "default") */
  45.  
  46. (function(undefined) {
  47.  
  48. // Object.assign
  49. (function() {
  50.  
  51. // 7.1.13 ToObject ( argument )
  52. function toObject(argument) {
  53. if (argument === null || argument === undefined) {
  54. throw new TypeError('Cannot call method on ' + argument);
  55. }
  56. return Object(argument);
  57. }
  58.  
  59. Object.defineProperty(Object, 'assign', {
  60. enumerable: false,
  61. configurable: true,
  62. writable: true,
  63. // 19.1.2.1 Object.assign ( target, ...sources )
  64. value: function assign(target, source) { // eslint-disable-line no-unused-vars
  65.  
  66. // 1. Let to be ? ToObject(target).
  67. var to = toObject(target);
  68.  
  69. // 2. If only one argument was passed, return to.
  70. if (arguments.length === 1) {
  71. return to;
  72. }
  73.  
  74. // 3. Let sources be the List of argument values starting with the second argument
  75. var sources = Array.prototype.slice.call(arguments, 1);
  76.  
  77. // 4. For each element nextSource of sources, in ascending index order, do
  78. var index1;
  79. var index2;
  80. var keys;
  81. var key;
  82. var from;
  83. for (index1 = 0; index1 < sources.length; index1++) {
  84. var nextSource = sources[index1];
  85. // 4a. If nextSource is undefined or null, let keys be a new empty List.
  86. if (nextSource === undefined || nextSource === null) {
  87. keys = [];
  88. // 4b. Else,
  89. } else {
  90. // 4bi. Let from be ! ToObject(nextSource).
  91. from = toObject(nextSource);
  92. // 4bii. Let keys be ? from.[[OwnPropertyKeys]]().
  93. /*
  94. This step in our polyfill is not complying with the specification.
  95. [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols.
  96. TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]].
  97. */
  98. keys = Object.keys(from);
  99. }
  100.  
  101. // 4c. For each element nextKey of keys in List order, do
  102. for (index2 = 0; index2 < keys.length; index2++) {
  103. var nextKey = keys[index2];
  104. // 4ci. Let desc be ? from.[[GetOwnProperty]](nextKey).
  105. var desc = Object.getOwnPropertyDescriptor(from, nextKey);
  106. // 4cii. If desc is not undefined and desc.[[Enumerable]] is true, then
  107. if (desc !== undefined && desc.enumerable) {
  108. // 4cii1. Let propValue be ? Get(from, nextKey).
  109. var propValue = from[nextKey];
  110. // 4cii2. Perform ? Set(to, nextKey, propValue, true).
  111. to[nextKey] = propValue;
  112. }
  113. }
  114. }
  115. // 5. Return to.
  116. return to;
  117. }
  118. });
  119. }());
  120.  
  121. // Symbol
  122. // A modification of https://github.com/WebReflection/get-own-property-symbols
  123. // (C) Andrea Giammarchi - MIT Licensed
  124.  
  125. (function (Object, GOPS, global) {
  126.  
  127. var setDescriptor;
  128. var id = 0;
  129. var random = '' + Math.random();
  130. var prefix = '__\x01symbol:';
  131. var prefixLength = prefix.length;
  132. var internalSymbol = '__\x01symbol@@' + random;
  133. var DP = 'defineProperty';
  134. var DPies = 'defineProperties';
  135. var GOPN = 'getOwnPropertyNames';
  136. var GOPD = 'getOwnPropertyDescriptor';
  137. var PIE = 'propertyIsEnumerable';
  138. var ObjectProto = Object.prototype;
  139. var hOP = ObjectProto.hasOwnProperty;
  140. var pIE = ObjectProto[PIE];
  141. var toString = ObjectProto.toString;
  142. var concat = Array.prototype.concat;
  143. var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [];
  144. var nGOPN = Object[GOPN];
  145. var gOPN = function getOwnPropertyNames (obj) {
  146. if (toString.call(obj) === '[object Window]') {
  147. try {
  148. return nGOPN(obj);
  149. } catch (e) {
  150. // IE bug where layout engine calls userland gOPN for cross-domain `window` objects
  151. return concat.call([], cachedWindowNames);
  152. }
  153. }
  154. return nGOPN(obj);
  155. };
  156. var gOPD = Object[GOPD];
  157. var create = Object.create;
  158. var keys = Object.keys;
  159. var freeze = Object.freeze || Object;
  160. var defineProperty = Object[DP];
  161. var $defineProperties = Object[DPies];
  162. var descriptor = gOPD(Object, GOPN);
  163. var addInternalIfNeeded = function (o, uid, enumerable) {
  164. if (!hOP.call(o, internalSymbol)) {
  165. try {
  166. defineProperty(o, internalSymbol, {
  167. enumerable: false,
  168. configurable: false,
  169. writable: false,
  170. value: {}
  171. });
  172. } catch (e) {
  173. o[internalSymbol] = {};
  174. }
  175. }
  176. o[internalSymbol]['@@' + uid] = enumerable;
  177. };
  178. var createWithSymbols = function (proto, descriptors) {
  179. var self = create(proto);
  180. gOPN(descriptors).forEach(function (key) {
  181. if (propertyIsEnumerable.call(descriptors, key)) {
  182. $defineProperty(self, key, descriptors[key]);
  183. }
  184. });
  185. return self;
  186. };
  187. var copyAsNonEnumerable = function (descriptor) {
  188. var newDescriptor = create(descriptor);
  189. newDescriptor.enumerable = false;
  190. return newDescriptor;
  191. };
  192. var get = function get(){};
  193. var onlyNonSymbols = function (name) {
  194. return name != internalSymbol &&
  195. !hOP.call(source, name);
  196. };
  197. var onlySymbols = function (name) {
  198. return name != internalSymbol &&
  199. hOP.call(source, name);
  200. };
  201. var propertyIsEnumerable = function propertyIsEnumerable(key) {
  202. var uid = '' + key;
  203. return onlySymbols(uid) ? (
  204. hOP.call(this, uid) &&
  205. this[internalSymbol]['@@' + uid]
  206. ) : pIE.call(this, key);
  207. };
  208. var setAndGetSymbol = function (uid) {
  209. var descriptor = {
  210. enumerable: false,
  211. configurable: true,
  212. get: get,
  213. set: function (value) {
  214. setDescriptor(this, uid, {
  215. enumerable: false,
  216. configurable: true,
  217. writable: true,
  218. value: value
  219. });
  220. addInternalIfNeeded(this, uid, true);
  221. }
  222. };
  223. try {
  224. defineProperty(ObjectProto, uid, descriptor);
  225. } catch (e) {
  226. ObjectProto[uid] = descriptor.value;
  227. }
  228. return freeze(source[uid] = defineProperty(
  229. Object(uid),
  230. 'constructor',
  231. sourceConstructor
  232. ));
  233. };
  234. var Symbol = function Symbol(description) {
  235. if (this instanceof Symbol) {
  236. throw new TypeError('Symbol is not a constructor');
  237. }
  238. return setAndGetSymbol(
  239. prefix.concat(description || '', random, ++id)
  240. );
  241. };
  242. var source = create(null);
  243. var sourceConstructor = {value: Symbol};
  244. var sourceMap = function (uid) {
  245. return source[uid];
  246. };
  247. var $defineProperty = function defineProp(o, key, descriptor) {
  248. var uid = '' + key;
  249. if (onlySymbols(uid)) {
  250. setDescriptor(o, uid, descriptor.enumerable ?
  251. copyAsNonEnumerable(descriptor) : descriptor);
  252. addInternalIfNeeded(o, uid, !!descriptor.enumerable);
  253. } else {
  254. defineProperty(o, key, descriptor);
  255. }
  256. return o;
  257. };
  258.  
  259. var onlyInternalSymbols = function (obj) {
  260. return function (name) {
  261. return hOP.call(obj, internalSymbol) && hOP.call(obj[internalSymbol], '@@' + name);
  262. };
  263. };
  264. var $getOwnPropertySymbols = function getOwnPropertySymbols(o) {
  265. return gOPN(o).filter(o === ObjectProto ? onlyInternalSymbols(o) : onlySymbols).map(sourceMap);
  266. }
  267. ;
  268.  
  269. descriptor.value = $defineProperty;
  270. defineProperty(Object, DP, descriptor);
  271.  
  272. descriptor.value = $getOwnPropertySymbols;
  273. defineProperty(Object, GOPS, descriptor);
  274.  
  275. descriptor.value = function getOwnPropertyNames(o) {
  276. return gOPN(o).filter(onlyNonSymbols);
  277. };
  278. defineProperty(Object, GOPN, descriptor);
  279.  
  280. descriptor.value = function defineProperties(o, descriptors) {
  281. var symbols = $getOwnPropertySymbols(descriptors);
  282. if (symbols.length) {
  283. keys(descriptors).concat(symbols).forEach(function (uid) {
  284. if (propertyIsEnumerable.call(descriptors, uid)) {
  285. $defineProperty(o, uid, descriptors[uid]);
  286. }
  287. });
  288. } else {
  289. $defineProperties(o, descriptors);
  290. }
  291. return o;
  292. };
  293. defineProperty(Object, DPies, descriptor);
  294.  
  295. descriptor.value = propertyIsEnumerable;
  296. defineProperty(ObjectProto, PIE, descriptor);
  297.  
  298. descriptor.value = Symbol;
  299. defineProperty(global, 'Symbol', descriptor);
  300.  
  301. // defining `Symbol.for(key)`
  302. descriptor.value = function (key) {
  303. var uid = prefix.concat(prefix, key, random);
  304. return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid);
  305. };
  306. defineProperty(Symbol, 'for', descriptor);
  307.  
  308. // defining `Symbol.keyFor(symbol)`
  309. descriptor.value = function (symbol) {
  310. if (onlyNonSymbols(symbol))
  311. throw new TypeError(symbol + ' is not a symbol');
  312. return hOP.call(source, symbol) ?
  313. symbol.slice(prefixLength * 2, -random.length) :
  314. void 0
  315. ;
  316. };
  317. defineProperty(Symbol, 'keyFor', descriptor);
  318.  
  319. descriptor.value = function getOwnPropertyDescriptor(o, key) {
  320. var descriptor = gOPD(o, key);
  321. if (descriptor && onlySymbols(key)) {
  322. descriptor.enumerable = propertyIsEnumerable.call(o, key);
  323. }
  324. return descriptor;
  325. };
  326. defineProperty(Object, GOPD, descriptor);
  327.  
  328. descriptor.value = function (proto, descriptors) {
  329. return arguments.length === 1 || typeof descriptors === "undefined" ?
  330. create(proto) :
  331. createWithSymbols(proto, descriptors);
  332. };
  333. defineProperty(Object, 'create', descriptor);
  334.  
  335. descriptor.value = function () {
  336. var str = toString.call(this);
  337. return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str;
  338. };
  339. defineProperty(ObjectProto, 'toString', descriptor);
  340.  
  341.  
  342. setDescriptor = function (o, key, descriptor) {
  343. var protoDescriptor = gOPD(ObjectProto, key);
  344. delete ObjectProto[key];
  345. defineProperty(o, key, descriptor);
  346. if (o !== ObjectProto) {
  347. defineProperty(ObjectProto, key, protoDescriptor);
  348. }
  349. };
  350.  
  351. }(Object, 'getOwnPropertySymbols', this));
  352.  
  353. // Symbol.iterator
  354. Object.defineProperty(Symbol, 'iterator', {value: Symbol('iterator')});
  355.  
  356. // Symbol.toStringTag
  357. Object.defineProperty(Symbol, 'toStringTag', {
  358. value: Symbol('toStringTag')
  359. });
  360.  
  361. // _Iterator
  362. // A modification of https://github.com/medikoo/es6-iterator
  363. // Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com)
  364.  
  365. var Iterator = (function () { // eslint-disable-line no-unused-vars
  366. var clear = function () {
  367. this.length = 0;
  368. return this;
  369. };
  370. var callable = function (fn) {
  371. if (typeof fn !== 'function') throw new TypeError(fn + " is not a function");
  372. return fn;
  373. };
  374.  
  375. var Iterator = function (list, context) {
  376. if (!(this instanceof Iterator)) {
  377. return new Iterator(list, context);
  378. }
  379. Object.defineProperties(this, {
  380. __list__: {
  381. writable: true,
  382. value: list
  383. },
  384. __context__: {
  385. writable: true,
  386. value: context
  387. },
  388. __nextIndex__: {
  389. writable: true,
  390. value: 0
  391. }
  392. });
  393. if (!context) return;
  394. callable(context.on);
  395. context.on('_add', this._onAdd.bind(this));
  396. context.on('_delete', this._onDelete.bind(this));
  397. context.on('_clear', this._onClear.bind(this));
  398. };
  399.  
  400. Object.defineProperties(Iterator.prototype, Object.assign({
  401. constructor: {
  402. value: Iterator,
  403. configurable: true,
  404. enumerable: false,
  405. writable: true
  406. },
  407. _next: {
  408. value: function () {
  409. var i;
  410. if (!this.__list__) return;
  411. if (this.__redo__) {
  412. i = this.__redo__.shift();
  413. if (i !== undefined) return i;
  414. }
  415. if (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++;
  416. this._unBind();
  417. },
  418. configurable: true,
  419. enumerable: false,
  420. writable: true
  421. },
  422. next: {
  423. value: function () {
  424. return this._createResult(this._next());
  425. },
  426. configurable: true,
  427. enumerable: false,
  428. writable: true
  429. },
  430. _createResult: {
  431. value: function (i) {
  432. if (i === undefined) return {
  433. done: true,
  434. value: undefined
  435. };
  436. return {
  437. done: false,
  438. value: this._resolve(i)
  439. };
  440. },
  441. configurable: true,
  442. enumerable: false,
  443. writable: true
  444. },
  445. _resolve: {
  446. value: function (i) {
  447. return this.__list__[i];
  448. },
  449. configurable: true,
  450. enumerable: false,
  451. writable: true
  452. },
  453. _unBind: {
  454. value: function () {
  455. this.__list__ = null;
  456. delete this.__redo__;
  457. if (!this.__context__) return;
  458. this.__context__.off('_add', this._onAdd.bind(this));
  459. this.__context__.off('_delete', this._onDelete.bind(this));
  460. this.__context__.off('_clear', this._onClear.bind(this));
  461. this.__context__ = null;
  462. },
  463. configurable: true,
  464. enumerable: false,
  465. writable: true
  466. },
  467. toString: {
  468. value: function () {
  469. return '[object Iterator]';
  470. },
  471. configurable: true,
  472. enumerable: false,
  473. writable: true
  474. }
  475. }, {
  476. _onAdd: {
  477. value: function (index) {
  478. if (index >= this.__nextIndex__) return;
  479. ++this.__nextIndex__;
  480. if (!this.__redo__) {
  481. Object.defineProperty(this, '__redo__', {
  482. value: [index],
  483. configurable: true,
  484. enumerable: false,
  485. writable: false
  486. });
  487. return;
  488. }
  489. this.__redo__.forEach(function (redo, i) {
  490. if (redo >= index) this.__redo__[i] = ++redo;
  491. }, this);
  492. this.__redo__.push(index);
  493. },
  494. configurable: true,
  495. enumerable: false,
  496. writable: true
  497. },
  498. _onDelete: {
  499. value: function (index) {
  500. var i;
  501. if (index >= this.__nextIndex__) return;
  502. --this.__nextIndex__;
  503. if (!this.__redo__) return;
  504. i = this.__redo__.indexOf(index);
  505. if (i !== -1) this.__redo__.splice(i, 1);
  506. this.__redo__.forEach(function (redo, i) {
  507. if (redo > index) this.__redo__[i] = --redo;
  508. }, this);
  509. },
  510. configurable: true,
  511. enumerable: false,
  512. writable: true
  513. },
  514. _onClear: {
  515. value: function () {
  516. if (this.__redo__) clear.call(this.__redo__);
  517. this.__nextIndex__ = 0;
  518. },
  519. configurable: true,
  520. enumerable: false,
  521. writable: true
  522. }
  523. }));
  524.  
  525. Object.defineProperty(Iterator.prototype, Symbol.iterator, {
  526. value: function () {
  527. return this;
  528. },
  529. configurable: true,
  530. enumerable: false,
  531. writable: true
  532. });
  533. Object.defineProperty(Iterator.prototype, Symbol.toStringTag, {
  534. value: 'Iterator',
  535. configurable: false,
  536. enumerable: false,
  537. writable: true
  538. });
  539.  
  540. return Iterator;
  541. }());
  542.  
  543. // Object.setPrototypeOf
  544. // ES6-shim 0.16.0 (c) 2013-2014 Paul Miller (http://paulmillr.com)
  545. // ES6-shim may be freely distributed under the MIT license.
  546. // For more details and documentation:
  547. // https://github.com/paulmillr/es6-shim/
  548.  
  549. // NOTE: This versions needs object ownership
  550. // because every promoted object needs to be reassigned
  551. // otherwise uncompatible browsers cannot work as expected
  552. //
  553. // NOTE: This might need es5-shim or polyfills upfront
  554. // because it's based on ES5 API.
  555. // (probably just an IE <= 8 problem)
  556. //
  557. // NOTE: nodejs is fine in version 0.8, 0.10, and future versions.
  558. (function () {
  559. if (Object.setPrototypeOf) { return; }
  560.  
  561. /*jshint proto: true */
  562. // @author Andrea Giammarchi - @WebReflection
  563.  
  564. var getOwnPropertyNames = Object.getOwnPropertyNames;
  565. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  566. var create = Object.create;
  567. var defineProperty = Object.defineProperty;
  568. var getPrototypeOf = Object.getPrototypeOf;
  569. var objProto = Object.prototype;
  570.  
  571. var copyDescriptors = function (target, source) {
  572. // define into target descriptors from source
  573. getOwnPropertyNames(source).forEach(function (key) {
  574. defineProperty(
  575. target,
  576. key,
  577. getOwnPropertyDescriptor(source, key)
  578. );
  579. });
  580. return target;
  581. };
  582. // used as fallback when no promotion is possible
  583. var createAndCopy = function (origin, proto) {
  584. return copyDescriptors(create(proto), origin);
  585. };
  586. var set, setPrototypeOf;
  587. try {
  588. // this might fail for various reasons
  589. // ignore if Chrome cought it at runtime
  590. set = getOwnPropertyDescriptor(objProto, '__proto__').set;
  591. set.call({}, null);
  592. // setter not poisoned, it can promote
  593. // Firefox, Chrome
  594. setPrototypeOf = function (origin, proto) {
  595. set.call(origin, proto);
  596. return origin;
  597. };
  598. } catch (e) {
  599. // do one or more feature detections
  600. set = { __proto__: null };
  601. // if proto does not work, needs to fallback
  602. // some Opera, Rhino, ducktape
  603. if (set instanceof Object) {
  604. setPrototypeOf = createAndCopy;
  605. } else {
  606. // verify if null objects are buggy
  607. /* eslint-disable no-proto */
  608. set.__proto__ = objProto;
  609. /* eslint-enable no-proto */
  610. // if null objects are buggy
  611. // nodejs 0.8 to 0.10
  612. if (set instanceof Object) {
  613. setPrototypeOf = function (origin, proto) {
  614. // use such bug to promote
  615. /* eslint-disable no-proto */
  616. origin.__proto__ = proto;
  617. /* eslint-enable no-proto */
  618. return origin;
  619. };
  620. } else {
  621. // try to use proto or fallback
  622. // Safari, old Firefox, many others
  623. setPrototypeOf = function (origin, proto) {
  624. // if proto is not null
  625. if (getPrototypeOf(origin)) {
  626. // use __proto__ to promote
  627. /* eslint-disable no-proto */
  628. origin.__proto__ = proto;
  629. /* eslint-enable no-proto */
  630. return origin;
  631. } else {
  632. // otherwise unable to promote: fallback
  633. return createAndCopy(origin, proto);
  634. }
  635. };
  636. }
  637. }
  638. }
  639. Object.setPrototypeOf = setPrototypeOf;
  640. }());
  641.  
  642. // String.prototype.includes
  643. String.prototype.includes = function (string, index) {
  644. if (typeof string === 'object' && string instanceof RegExp) throw new TypeError("First argument to String.prototype.includes must not be a regular expression");
  645. return this.indexOf(string, index) !== -1;
  646. };
  647.  
  648. // String.prototype.contains
  649. String.prototype.contains = String.prototype.includes;
  650.  
  651. // _ArrayIterator
  652. // A modification of https://github.com/medikoo/es6-iterator
  653. // Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com)
  654.  
  655. var ArrayIterator = (function() { // eslint-disable-line no-unused-vars
  656.  
  657. var ArrayIterator = function(arr, kind) {
  658. if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind);
  659. Iterator.call(this, arr);
  660. if (!kind) kind = 'value';
  661. else if (String.prototype.contains.call(kind, 'key+value')) kind = 'key+value';
  662. else if (String.prototype.contains.call(kind, 'key')) kind = 'key';
  663. else kind = 'value';
  664. Object.defineProperty(this, '__kind__', {
  665. value: kind,
  666. configurable: false,
  667. enumerable: false,
  668. writable: false
  669. });
  670. };
  671. if (Object.setPrototypeOf) Object.setPrototypeOf(ArrayIterator, Iterator.prototype);
  672.  
  673. ArrayIterator.prototype = Object.create(Iterator.prototype, {
  674. constructor: {
  675. value: ArrayIterator,
  676. configurable: true,
  677. enumerable: false,
  678. writable: true
  679. },
  680. _resolve: {
  681. value: function(i) {
  682. if (this.__kind__ === 'value') return this.__list__[i];
  683. if (this.__kind__ === 'key+value') return [i, this.__list__[i]];
  684. return i;
  685. },
  686. configurable: true,
  687. enumerable: false,
  688. writable: true
  689. },
  690. toString: {
  691. value: function() {
  692. return '[object Array Iterator]';
  693. },
  694. configurable: true,
  695. enumerable: false,
  696. writable: true
  697. }
  698. });
  699.  
  700. return ArrayIterator;
  701. }());
  702.  
  703. // Number.isFinite
  704. Number.isFinite = Number.isFinite || function(value) {
  705. return typeof value === "number" && isFinite(value);
  706. };
  707.  
  708. // Number.isNaN
  709. Number.isNaN = Number.isNaN || function(value) {
  710. return typeof value === "number" && isNaN(value);
  711. };
  712.  
  713. // Array.from
  714. // Wrapped in IIFE to prevent leaking to global scope.
  715. (function () {
  716. 'use strict';
  717.  
  718. function toInteger(value) {
  719. var number = Number(value);
  720. return sign(number) * Math.floor(Math.abs(Math.min(Math.max(number || 0, 0), 9007199254740991)));
  721. }
  722.  
  723. var has = Object.prototype.hasOwnProperty;
  724. var strValue = String.prototype.valueOf;
  725.  
  726. var tryStringObject = function tryStringObject(value) {
  727. try {
  728. strValue.call(value);
  729. return true;
  730. } catch (e) {
  731. return false;
  732. }
  733. };
  734.  
  735. function sign(number) {
  736. return number >= 0 ? 1 : -1;
  737. }
  738.  
  739. var toStr = Object.prototype.toString;
  740. var strClass = '[object String]';
  741. var hasSymbols = typeof Symbol === 'function';
  742. var hasToStringTag = hasSymbols && 'toStringTag' in Symbol;
  743.  
  744. function isString(value) {
  745. if (typeof value === 'string') {
  746. return true;
  747. }
  748. if (typeof value !== 'object') {
  749. return false;
  750. }
  751. return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass;
  752. }
  753.  
  754. var fnToStr = Function.prototype.toString;
  755.  
  756. var constructorRegex = /^\s*class /;
  757. var isES6ClassFn = function isES6ClassFn(value) {
  758. try {
  759. var fnStr = fnToStr.call(value);
  760. var singleStripped = fnStr.replace(/\/\/.*\n/g, '');
  761. var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, '');
  762. var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' ');
  763. return constructorRegex.test(spaceStripped);
  764. } catch (e) {
  765. return false; // not a function
  766. }
  767. };
  768.  
  769. var tryFunctionObject = function tryFunctionObject(value) {
  770. try {
  771. if (isES6ClassFn(value)) {
  772. return false;
  773. }
  774. fnToStr.call(value);
  775. return true;
  776. } catch (e) {
  777. return false;
  778. }
  779. };
  780. var fnClass = '[object Function]';
  781. var genClass = '[object GeneratorFunction]';
  782.  
  783. function isCallable(value) {
  784. if (!value) {
  785. return false;
  786. }
  787. if (typeof value !== 'function' && typeof value !== 'object') {
  788. return false;
  789. }
  790. if (hasToStringTag) {
  791. return tryFunctionObject(value);
  792. }
  793. if (isES6ClassFn(value)) {
  794. return false;
  795. }
  796. var strClass = toStr.call(value);
  797. return strClass === fnClass || strClass === genClass;
  798. };
  799. var isArray = Array.isArray;
  800.  
  801. var parseIterable = function (iterator) {
  802. var done = false;
  803. var iterableResponse;
  804. var tempArray = [];
  805.  
  806. if (iterator && typeof iterator.next === 'function') {
  807. while (!done) {
  808. iterableResponse = iterator.next();
  809. if (
  810. has.call(iterableResponse, 'value') &&
  811. has.call(iterableResponse, 'done')
  812. ) {
  813. if (iterableResponse.done === true) {
  814. done = true;
  815. break; // eslint-disable-line no-restricted-syntax
  816.  
  817. } else if (iterableResponse.done !== false) {
  818. break; // eslint-disable-line no-restricted-syntax
  819. }
  820.  
  821. tempArray.push(iterableResponse.value);
  822. } else if (iterableResponse.done === true) {
  823. done = true;
  824. break; // eslint-disable-line no-restricted-syntax
  825. } else {
  826. break; // eslint-disable-line no-restricted-syntax
  827. }
  828. }
  829. }
  830.  
  831. return done ? tempArray : false;
  832. };
  833.  
  834. var iteratorSymbol;
  835. var forOf;
  836. var hasSet = typeof Set === 'function';
  837. var hasMap = typeof Map === 'function';
  838.  
  839. if (hasSymbols) {
  840. iteratorSymbol = Symbol.iterator;
  841. } else {
  842. var iterate;
  843. try {
  844. iterate = Function('iterable', 'var arr = []; for (var value of iterable) arr.push(value); return arr;'); // eslint-disable-line no-new-func
  845. } catch (e) {}
  846. var supportsStrIterator = (function () {
  847. try {
  848. var supported = false;
  849. var obj = { // eslint-disable-line no-unused-vars
  850. '@@iterator': function () {
  851. return {
  852. 'next': function () {
  853. supported = true;
  854. return {
  855. 'done': true,
  856. 'value': undefined
  857. };
  858. }
  859. };
  860. }
  861. };
  862.  
  863. iterate(obj);
  864. return supported;
  865. } catch (e) {
  866. return false;
  867. }
  868. }());
  869.  
  870. if (supportsStrIterator) {
  871. iteratorSymbol = '@@iterator';
  872. } else if (typeof Set === 'function') {
  873. var s = new Set();
  874. s.add(0);
  875. try {
  876. if (iterate(s).length === 1) {
  877. forOf = iterate;
  878. }
  879. } catch (e) {}
  880. }
  881. }
  882.  
  883. var isSet;
  884. if (hasSet) {
  885. var setSize = Object.getOwnPropertyDescriptor(Set.prototype, 'size').get;
  886. isSet = function (set) {
  887. try {
  888. setSize.call(set);
  889. return true;
  890. } catch (e) {
  891. return false;
  892. }
  893. };
  894. }
  895.  
  896. var isMap;
  897. if (hasMap) {
  898. var mapSize = Object.getOwnPropertyDescriptor(Map.prototype, 'size').get;
  899. isMap = function (m) {
  900. try {
  901. mapSize.call(m);
  902. return true;
  903. } catch (e) {
  904. return false;
  905. }
  906. };
  907. }
  908.  
  909. var setForEach = hasSet && Set.prototype.forEach;
  910. var mapForEach = hasMap && Map.prototype.forEach;
  911. var usingIterator = function (items) {
  912. var tempArray = [];
  913. if (has.call(items, iteratorSymbol)) {
  914. return items[iteratorSymbol]();
  915. } else if (setForEach && isSet(items)) {
  916. setForEach.call(items, function (val) {
  917. tempArray.push(val);
  918. });
  919. return {
  920. next: function () {
  921. return tempArray.length === 0
  922. ? {
  923. done: true
  924. }
  925. : {
  926. value: tempArray.splice(0, 1)[0],
  927. done: false
  928. };
  929. }
  930. };
  931. } else if (mapForEach && isMap(items)) {
  932. mapForEach.call(items, function (val, key) {
  933. tempArray.push([key, val]);
  934. });
  935. return {
  936. next: function () {
  937. return tempArray.length === 0
  938. ? {
  939. done: true
  940. }
  941. : {
  942. value: tempArray.splice(0, 1)[0],
  943. done: false
  944. };
  945. }
  946. };
  947. }
  948. return items;
  949. };
  950.  
  951. var strMatch = String.prototype.match;
  952.  
  953. var parseIterableLike = function (items) {
  954. var arr = parseIterable(usingIterator(items));
  955.  
  956. if (!arr) {
  957. if (isString(items)) {
  958. arr = strMatch.call(items, /[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || [];
  959. } else if (forOf && !isArray(items)) {
  960. // Safari 8's native Map or Set can't be iterated except with for..of
  961. try {
  962. arr = forOf(items);
  963. } catch (e) {}
  964. }
  965. }
  966. return arr || items;
  967. };
  968.  
  969. /*! https://mths.be/array-from v0.2.0 by @mathias */
  970. Object.defineProperty(Array, 'from', {
  971. configurable: true,
  972. value: function from(items) {
  973. var C = this;
  974. if (items === null || typeof items === 'undefined') {
  975. throw new TypeError('`Array.from` requires an array-like object, not `null` or `undefined`');
  976. }
  977. var mapFn, T;
  978. if (typeof arguments[1] !== 'undefined') {
  979. mapFn = arguments[1];
  980. if (!isCallable(mapFn)) {
  981. throw new TypeError('When provided, the second argument to `Array.from` must be a function');
  982. }
  983. if (arguments.length > 2) {
  984. T = arguments[2];
  985. }
  986. }
  987.  
  988. var arrayLike = Object(parseIterableLike(items));
  989. var len = toInteger(arrayLike.length);
  990. var A = isCallable(C) ? Object(new C(len)) : new Array(len);
  991. var k = 0;
  992. var kValue, mappedValue;
  993.  
  994. while (k < len) {
  995. kValue = arrayLike[k];
  996. if (mapFn) {
  997. mappedValue = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.apply(T, [kValue, k]);
  998. } else {
  999. mappedValue = kValue;
  1000. }
  1001. Object.defineProperty(A, k, {
  1002. 'configurable': true,
  1003. 'enumerable': true,
  1004. 'value': mappedValue,
  1005. 'writable': true
  1006. });
  1007. k += 1;
  1008. }
  1009. A.length = len;
  1010. return A;
  1011. },
  1012. writable: true
  1013. });
  1014. }());
  1015.  
  1016. // Array.of
  1017. /*! https://mths.be/array-of v0.1.0 by @mathias */
  1018. (function () {
  1019. 'use strict';
  1020. var defineProperty = (function () {
  1021. // IE 8 only supports `Object.defineProperty` on DOM elements
  1022. try {
  1023. var object = {};
  1024. var $defineProperty = Object.defineProperty;
  1025. var result = $defineProperty(object, object, object) && $defineProperty;
  1026. } catch (error) { /**/ }
  1027. return result;
  1028. }());
  1029. var isConstructor = function isConstructor(Constructor) {
  1030. try {
  1031. return !!new Constructor();
  1032. } catch (_) {
  1033. return false;
  1034. }
  1035. };
  1036. var of = function of() {
  1037. var items = arguments;
  1038. var length = items.length;
  1039. var Me = this;
  1040. var result = isConstructor(Me) ? new Me(length) : new Array(length);
  1041. var index = 0;
  1042. var value;
  1043. while (index < length) {
  1044. value = items[index];
  1045. if (defineProperty) {
  1046. defineProperty(result, index, {
  1047. 'value': value,
  1048. 'writable': true,
  1049. 'enumerable': true,
  1050. 'configurable': true
  1051. });
  1052. } else {
  1053. result[index] = value;
  1054. }
  1055. index += 1;
  1056. }
  1057. result.length = length;
  1058. return result;
  1059. };
  1060. if (defineProperty) {
  1061. defineProperty(Array, 'of', {
  1062. 'value': of,
  1063. 'configurable': true,
  1064. 'writable': true
  1065. });
  1066. } else {
  1067. Array.of = of;
  1068. }
  1069. }());
  1070.  
  1071. // Array.prototype.fill
  1072. Object.defineProperty(Array.prototype, 'fill', {
  1073. configurable: true,
  1074. value: function fill(value) {
  1075. if (this === undefined || this === null) {
  1076. throw new TypeError(this + ' is not an object');
  1077. }
  1078.  
  1079. var arrayLike = Object(this);
  1080.  
  1081. var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;
  1082.  
  1083. var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;
  1084.  
  1085. relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);
  1086.  
  1087. var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;
  1088.  
  1089. relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);
  1090.  
  1091. while (relativeStart < relativeEnd) {
  1092. arrayLike[relativeStart] = value;
  1093.  
  1094. ++relativeStart;
  1095. }
  1096.  
  1097. return arrayLike;
  1098. },
  1099. writable: true
  1100. });
  1101.  
  1102. // Event
  1103. (function () {
  1104. var unlistenableWindowEvents = {
  1105. click: 1,
  1106. dblclick: 1,
  1107. keyup: 1,
  1108. keypress: 1,
  1109. keydown: 1,
  1110. mousedown: 1,
  1111. mouseup: 1,
  1112. mousemove: 1,
  1113. mouseover: 1,
  1114. mouseenter: 1,
  1115. mouseleave: 1,
  1116. mouseout: 1,
  1117. storage: 1,
  1118. storagecommit: 1,
  1119. textinput: 1
  1120. };
  1121.  
  1122. // This polyfill depends on availability of `document` so will not run in a worker
  1123. // However, we asssume there are no browsers with worker support that lack proper
  1124. // support for `Event` within the worker
  1125. if (typeof document === 'undefined' || typeof window === 'undefined') return;
  1126.  
  1127. function indexOf(array, element) {
  1128. var
  1129. index = -1,
  1130. length = array.length;
  1131.  
  1132. while (++index < length) {
  1133. if (index in array && array[index] === element) {
  1134. return index;
  1135. }
  1136. }
  1137.  
  1138. return -1;
  1139. }
  1140.  
  1141. var existingProto = (window.Event && window.Event.prototype) || null;
  1142. window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
  1143. if (!type) {
  1144. throw new Error('Not enough arguments');
  1145. }
  1146.  
  1147. var event;
  1148. // Shortcut if browser supports createEvent
  1149. if ('createEvent' in document) {
  1150. event = document.createEvent('Event');
  1151. var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  1152. var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  1153.  
  1154. event.initEvent(type, bubbles, cancelable);
  1155.  
  1156. return event;
  1157. }
  1158.  
  1159. event = document.createEventObject();
  1160.  
  1161. event.type = type;
  1162. event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  1163. event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  1164.  
  1165. return event;
  1166. };
  1167. if (existingProto) {
  1168. Object.defineProperty(window.Event, 'prototype', {
  1169. configurable: false,
  1170. enumerable: false,
  1171. writable: true,
  1172. value: existingProto
  1173. });
  1174. }
  1175.  
  1176. if (!('createEvent' in document)) {
  1177. window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
  1178. var
  1179. element = this,
  1180. type = arguments[0],
  1181. listener = arguments[1];
  1182.  
  1183. if (element === window && type in unlistenableWindowEvents) {
  1184. throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
  1185. }
  1186.  
  1187. if (!element._events) {
  1188. element._events = {};
  1189. }
  1190.  
  1191. if (!element._events[type]) {
  1192. element._events[type] = function (event) {
  1193. var
  1194. list = element._events[event.type].list,
  1195. events = list.slice(),
  1196. index = -1,
  1197. length = events.length,
  1198. eventElement;
  1199.  
  1200. event.preventDefault = function preventDefault() {
  1201. if (event.cancelable !== false) {
  1202. event.returnValue = false;
  1203. }
  1204. };
  1205.  
  1206. event.stopPropagation = function stopPropagation() {
  1207. event.cancelBubble = true;
  1208. };
  1209.  
  1210. event.stopImmediatePropagation = function stopImmediatePropagation() {
  1211. event.cancelBubble = true;
  1212. event.cancelImmediate = true;
  1213. };
  1214.  
  1215. event.currentTarget = element;
  1216. event.relatedTarget = event.fromElement || null;
  1217. event.target = event.target || event.srcElement || element;
  1218. event.timeStamp = new Date().getTime();
  1219.  
  1220. if (event.clientX) {
  1221. event.pageX = event.clientX + document.documentElement.scrollLeft;
  1222. event.pageY = event.clientY + document.documentElement.scrollTop;
  1223. }
  1224.  
  1225. while (++index < length && !event.cancelImmediate) {
  1226. if (index in events) {
  1227. eventElement = events[index];
  1228.  
  1229. if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
  1230. eventElement.call(element, event);
  1231. }
  1232. }
  1233. }
  1234. };
  1235.  
  1236. element._events[type].list = [];
  1237.  
  1238. if (element.attachEvent) {
  1239. element.attachEvent('on' + type, element._events[type]);
  1240. }
  1241. }
  1242.  
  1243. element._events[type].list.push(listener);
  1244. };
  1245.  
  1246. window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
  1247. var
  1248. element = this,
  1249. type = arguments[0],
  1250. listener = arguments[1],
  1251. index;
  1252.  
  1253. if (element._events && element._events[type] && element._events[type].list) {
  1254. index = indexOf(element._events[type].list, listener);
  1255.  
  1256. if (index !== -1) {
  1257. element._events[type].list.splice(index, 1);
  1258.  
  1259. if (!element._events[type].list.length) {
  1260. if (element.detachEvent) {
  1261. element.detachEvent('on' + type, element._events[type]);
  1262. }
  1263. delete element._events[type];
  1264. }
  1265. }
  1266. }
  1267. };
  1268.  
  1269. window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
  1270. if (!arguments.length) {
  1271. throw new Error('Not enough arguments');
  1272. }
  1273.  
  1274. if (!event || typeof event.type !== 'string') {
  1275. throw new Error('DOM Events Exception 0');
  1276. }
  1277.  
  1278. var element = this, type = event.type;
  1279.  
  1280. try {
  1281. if (!event.bubbles) {
  1282. event.cancelBubble = true;
  1283.  
  1284. var cancelBubbleEvent = function (event) {
  1285. event.cancelBubble = true;
  1286.  
  1287. (element || window).detachEvent('on' + type, cancelBubbleEvent);
  1288. };
  1289.  
  1290. this.attachEvent('on' + type, cancelBubbleEvent);
  1291. }
  1292.  
  1293. this.fireEvent('on' + type, event);
  1294. } catch (error) {
  1295. event.target = element;
  1296.  
  1297. do {
  1298. event.currentTarget = element;
  1299.  
  1300. if ('_events' in element && typeof element._events[type] === 'function') {
  1301. element._events[type].call(element, event);
  1302. }
  1303.  
  1304. if (typeof element['on' + type] === 'function') {
  1305. element['on' + type].call(element, event);
  1306. }
  1307.  
  1308. element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
  1309. } while (element && !event.cancelBubble);
  1310. }
  1311.  
  1312. return true;
  1313. };
  1314.  
  1315. // Add the DOMContentLoaded Event
  1316. document.attachEvent('onreadystatechange', function() {
  1317. if (document.readyState === 'complete') {
  1318. document.dispatchEvent(new Event('DOMContentLoaded', {
  1319. bubbles: true
  1320. }));
  1321. }
  1322. });
  1323. }
  1324. }());
  1325.  
  1326. // CustomEvent
  1327. this.CustomEvent = function CustomEvent(type, eventInitDict) {
  1328. if (!type) {
  1329. throw Error('TypeError: Failed to construct "CustomEvent": An event name must be provided.');
  1330. }
  1331.  
  1332. var event;
  1333. eventInitDict = eventInitDict || {bubbles: false, cancelable: false, detail: null};
  1334.  
  1335. if ('createEvent' in document) {
  1336. try {
  1337. event = document.createEvent('CustomEvent');
  1338. event.initCustomEvent(type, eventInitDict.bubbles, eventInitDict.cancelable, eventInitDict.detail);
  1339. } catch (error) {
  1340. // for browsers which don't support CustomEvent at all, we use a regular event instead
  1341. event = document.createEvent('Event');
  1342. event.initEvent(type, eventInitDict.bubbles, eventInitDict.cancelable);
  1343. event.detail = eventInitDict.detail;
  1344. }
  1345. } else {
  1346.  
  1347. // IE8
  1348. event = new Event(type, eventInitDict);
  1349. event.detail = eventInitDict && eventInitDict.detail || null;
  1350. }
  1351. return event;
  1352. };
  1353.  
  1354. CustomEvent.prototype = Event.prototype;
  1355.  
  1356. // _DOMTokenList
  1357. /*
  1358. Copyright (c) 2016, John Gardner
  1359.  
  1360. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
  1361.  
  1362. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1363. */
  1364. var _DOMTokenList = (function() { // eslint-disable-line no-unused-vars
  1365. var dpSupport = true;
  1366. var defineGetter = function (object, name, fn, configurable) {
  1367. if (Object.defineProperty)
  1368. Object.defineProperty(object, name, {
  1369. configurable: false === dpSupport ? true : !!configurable,
  1370. get: fn
  1371. });
  1372.  
  1373. else object.__defineGetter__(name, fn);
  1374. };
  1375.  
  1376. /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
  1377. try {
  1378. defineGetter({}, "support");
  1379. }
  1380. catch (e) {
  1381. dpSupport = false;
  1382. }
  1383.  
  1384.  
  1385. var _DOMTokenList = function (el, prop) {
  1386. var that = this;
  1387. var tokens = [];
  1388. var tokenMap = {};
  1389. var length = 0;
  1390. var maxLength = 0;
  1391. var addIndexGetter = function (i) {
  1392. defineGetter(that, i, function () {
  1393. preop();
  1394. return tokens[i];
  1395. }, false);
  1396.  
  1397. };
  1398. var reindex = function () {
  1399.  
  1400. /** Define getter functions for array-like access to the tokenList's contents. */
  1401. if (length >= maxLength)
  1402. for (; maxLength < length; ++maxLength) {
  1403. addIndexGetter(maxLength);
  1404. }
  1405. };
  1406.  
  1407. /** Helper function called at the start of each class method. Internal use only. */
  1408. var preop = function () {
  1409. var error;
  1410. var i;
  1411. var args = arguments;
  1412. var rSpace = /\s+/;
  1413.  
  1414. /** Validate the token/s passed to an instance method, if any. */
  1415. if (args.length)
  1416. for (i = 0; i < args.length; ++i)
  1417. if (rSpace.test(args[i])) {
  1418. error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
  1419. error.code = 5;
  1420. error.name = "InvalidCharacterError";
  1421. throw error;
  1422. }
  1423.  
  1424.  
  1425. /** Split the new value apart by whitespace*/
  1426. if (typeof el[prop] === "object") {
  1427. tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
  1428. } else {
  1429. tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
  1430. }
  1431.  
  1432. /** Avoid treating blank strings as single-item token lists */
  1433. if ("" === tokens[0]) tokens = [];
  1434.  
  1435. /** Repopulate the internal token lists */
  1436. tokenMap = {};
  1437. for (i = 0; i < tokens.length; ++i)
  1438. tokenMap[tokens[i]] = true;
  1439. length = tokens.length;
  1440. reindex();
  1441. };
  1442.  
  1443. /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
  1444. preop();
  1445.  
  1446. /** Return the number of tokens in the underlying string. Read-only. */
  1447. defineGetter(that, "length", function () {
  1448. preop();
  1449. return length;
  1450. });
  1451.  
  1452. /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
  1453. that.toLocaleString =
  1454. that.toString = function () {
  1455. preop();
  1456. return tokens.join(" ");
  1457. };
  1458.  
  1459. that.item = function (idx) {
  1460. preop();
  1461. return tokens[idx];
  1462. };
  1463.  
  1464. that.contains = function (token) {
  1465. preop();
  1466. return !!tokenMap[token];
  1467. };
  1468.  
  1469. that.add = function () {
  1470. preop.apply(that, args = arguments);
  1471.  
  1472. for (var args, token, i = 0, l = args.length; i < l; ++i) {
  1473. token = args[i];
  1474. if (!tokenMap[token]) {
  1475. tokens.push(token);
  1476. tokenMap[token] = true;
  1477. }
  1478. }
  1479.  
  1480. /** Update the targeted attribute of the attached element if the token list's changed. */
  1481. if (length !== tokens.length) {
  1482. length = tokens.length >>> 0;
  1483. if (typeof el[prop] === "object") {
  1484. el[prop].baseVal = tokens.join(" ");
  1485. } else {
  1486. el[prop] = tokens.join(" ");
  1487. }
  1488. reindex();
  1489. }
  1490. };
  1491.  
  1492. that.remove = function () {
  1493. preop.apply(that, args = arguments);
  1494.  
  1495. /** Build a hash of token names to compare against when recollecting our token list. */
  1496. for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
  1497. ignore[args[i]] = true;
  1498. delete tokenMap[args[i]];
  1499. }
  1500.  
  1501. /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
  1502. for (i = 0; i < tokens.length; ++i)
  1503. if (!ignore[tokens[i]]) t.push(tokens[i]);
  1504.  
  1505. tokens = t;
  1506. length = t.length >>> 0;
  1507.  
  1508. /** Update the targeted attribute of the attached element. */
  1509. if (typeof el[prop] === "object") {
  1510. el[prop].baseVal = tokens.join(" ");
  1511. } else {
  1512. el[prop] = tokens.join(" ");
  1513. }
  1514. reindex();
  1515. };
  1516.  
  1517. that.toggle = function (token, force) {
  1518. preop.apply(that, [token]);
  1519.  
  1520. /** Token state's being forced. */
  1521. if (undefined !== force) {
  1522. if (force) {
  1523. that.add(token);
  1524. return true;
  1525. } else {
  1526. that.remove(token);
  1527. return false;
  1528. }
  1529. }
  1530.  
  1531. /** Token already exists in tokenList. Remove it, and return FALSE. */
  1532. if (tokenMap[token]) {
  1533. that.remove(token);
  1534. return false;
  1535. }
  1536.  
  1537. /** Otherwise, add the token and return TRUE. */
  1538. that.add(token);
  1539. return true;
  1540. };
  1541.  
  1542. return that;
  1543. };
  1544.  
  1545. return _DOMTokenList;
  1546. }());
  1547.  
  1548. // DOMTokenList
  1549. (function (global) {
  1550. var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
  1551.  
  1552. if (
  1553. !nativeImpl ||
  1554. (
  1555. !!document.createElementNS &&
  1556. !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
  1557. !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
  1558. )
  1559. ) {
  1560. global.DOMTokenList = _DOMTokenList;
  1561. }
  1562.  
  1563. // Add second argument to native DOMTokenList.toggle() if necessary
  1564. (function () {
  1565. var e = document.createElement('span');
  1566. if (!('classList' in e)) return;
  1567. e.classList.toggle('x', false);
  1568. if (!e.classList.contains('x')) return;
  1569. e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
  1570. var force = arguments[1];
  1571. if (force === undefined) {
  1572. var add = !this.contains(token);
  1573. this[add ? 'add' : 'remove'](token);
  1574. return add;
  1575. }
  1576. force = !!force;
  1577. this[force ? 'add' : 'remove'](token);
  1578. return force;
  1579. };
  1580. }());
  1581.  
  1582. // Add multiple arguments to native DOMTokenList.add() if necessary
  1583. (function () {
  1584. var e = document.createElement('span');
  1585. if (!('classList' in e)) return;
  1586. e.classList.add('a', 'b');
  1587. if (e.classList.contains('b')) return;
  1588. var native = e.classList.constructor.prototype.add;
  1589. e.classList.constructor.prototype.add = function () {
  1590. var args = arguments;
  1591. var l = arguments.length;
  1592. for (var i = 0; i < l; i++) {
  1593. native.call(this, args[i]);
  1594. }
  1595. };
  1596. }());
  1597.  
  1598. // Add multiple arguments to native DOMTokenList.remove() if necessary
  1599. (function () {
  1600. var e = document.createElement('span');
  1601. if (!('classList' in e)) return;
  1602. e.classList.add('a');
  1603. e.classList.add('b');
  1604. e.classList.remove('a', 'b');
  1605. if (!e.classList.contains('b')) return;
  1606. var native = e.classList.constructor.prototype.remove;
  1607. e.classList.constructor.prototype.remove = function () {
  1608. var args = arguments;
  1609. var l = arguments.length;
  1610. for (var i = 0; i < l; i++) {
  1611. native.call(this, args[i]);
  1612. }
  1613. };
  1614. }());
  1615.  
  1616. }(this));
  1617.  
  1618. // _mutation
  1619. var _mutation = (function () { // eslint-disable-line no-unused-vars
  1620.  
  1621. function isNode(object) {
  1622. // DOM, Level2
  1623. if (typeof Node === 'function') {
  1624. return object instanceof Node;
  1625. }
  1626. // Older browsers, check if it looks like a Node instance)
  1627. return object &&
  1628. typeof object === "object" &&
  1629. object.nodeName &&
  1630. object.nodeType >= 1 &&
  1631. object.nodeType <= 12;
  1632. }
  1633.  
  1634. // http://dom.spec.whatwg.org/#mutation-method-macro
  1635. return function mutation(nodes) {
  1636. if (nodes.length === 1) {
  1637. return isNode(nodes[0]) ? nodes[0] : document.createTextNode(nodes[0] + '');
  1638. }
  1639.  
  1640. var fragment = document.createDocumentFragment();
  1641. for (var i = 0; i < nodes.length; i++) {
  1642. fragment.appendChild(isNode(nodes[i]) ? nodes[i] : document.createTextNode(nodes[i] + ''));
  1643.  
  1644. }
  1645. return fragment;
  1646. };
  1647. }());
  1648.  
  1649. // DocumentFragment.prototype.append
  1650. DocumentFragment.prototype.append = function append() {
  1651. this.appendChild(_mutation(arguments));
  1652. };
  1653.  
  1654. // DocumentFragment.prototype.prepend
  1655. DocumentFragment.prototype.prepend = function prepend() {
  1656. this.insertBefore(_mutation(arguments), this.firstChild);
  1657. };
  1658.  
  1659. // Element.prototype.after
  1660. Document.prototype.after = Element.prototype.after = function after() {
  1661. if (this.parentNode) {
  1662. var args = Array.prototype.slice.call(arguments),
  1663. viableNextSibling = this.nextSibling,
  1664. idx = viableNextSibling ? args.indexOf(viableNextSibling) : -1;
  1665.  
  1666. while (idx !== -1) {
  1667. viableNextSibling = viableNextSibling.nextSibling;
  1668. if (!viableNextSibling) {
  1669. break;
  1670. }
  1671. idx = args.indexOf(viableNextSibling);
  1672. }
  1673.  
  1674. this.parentNode.insertBefore(_mutation(arguments), viableNextSibling);
  1675. }
  1676. };
  1677.  
  1678. // Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
  1679. // TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
  1680. if ("Text" in this) {
  1681. Text.prototype.after = Element.prototype.after;
  1682. }
  1683.  
  1684. // Element.prototype.append
  1685. Document.prototype.append = Element.prototype.append = function append() {
  1686. this.appendChild(_mutation(arguments));
  1687. };
  1688.  
  1689. // Element.prototype.before
  1690. Document.prototype.before = Element.prototype.before = function before() {
  1691. if (this.parentNode) {
  1692. var args = Array.prototype.slice.call(arguments),
  1693. viablePreviousSibling = this.previousSibling,
  1694. idx = viablePreviousSibling ? args.indexOf(viablePreviousSibling) : -1;
  1695.  
  1696. while (idx !== -1) {
  1697. viablePreviousSibling = viablePreviousSibling.previousSibling;
  1698. if (!viablePreviousSibling) {
  1699. break;
  1700. }
  1701. idx = args.indexOf(viablePreviousSibling);
  1702. }
  1703.  
  1704. this.parentNode.insertBefore(
  1705. _mutation(arguments),
  1706. viablePreviousSibling ? viablePreviousSibling.nextSibling : this.parentNode.firstChild
  1707. );
  1708. }
  1709. };
  1710.  
  1711. // Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
  1712. // TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
  1713. if ("Text" in this) {
  1714. Text.prototype.before = Element.prototype.before;
  1715. }
  1716.  
  1717. // Element.prototype.classList
  1718. /*
  1719. Copyright (c) 2016, John Gardner
  1720.  
  1721. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
  1722.  
  1723. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1724. */
  1725. (function (global) {
  1726. var dpSupport = true;
  1727. var defineGetter = function (object, name, fn, configurable) {
  1728. if (Object.defineProperty)
  1729. Object.defineProperty(object, name, {
  1730. configurable: false === dpSupport ? true : !!configurable,
  1731. get: fn
  1732. });
  1733.  
  1734. else object.__defineGetter__(name, fn);
  1735. };
  1736. /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
  1737. try {
  1738. defineGetter({}, "support");
  1739. }
  1740. catch (e) {
  1741. dpSupport = false;
  1742. }
  1743. /** Polyfills a property with a DOMTokenList */
  1744. var addProp = function (o, name, attr) {
  1745.  
  1746. defineGetter(o.prototype, name, function () {
  1747. var tokenList;
  1748.  
  1749. var THIS = this,
  1750.  
  1751. /** Prevent this from firing twice for some reason. What the hell, IE. */
  1752. gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
  1753. if(THIS[gibberishProperty]) return tokenList;
  1754. THIS[gibberishProperty] = true;
  1755.  
  1756. /**
  1757. * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
  1758. *
  1759. * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
  1760. * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
  1761. * element instead, this would conflict with element types which use indexed properties (such as forms and
  1762. * select lists).
  1763. */
  1764. if (false === dpSupport) {
  1765.  
  1766. var visage;
  1767. var mirror = addProp.mirror || document.createElement("div");
  1768. var reflections = mirror.childNodes;
  1769. var l = reflections.length;
  1770.  
  1771. for (var i = 0; i < l; ++i)
  1772. if (reflections[i]._R === THIS) {
  1773. visage = reflections[i];
  1774. break;
  1775. }
  1776.  
  1777. /** Couldn't find an element's reflection inside the mirror. Materialise one. */
  1778. visage || (visage = mirror.appendChild(document.createElement("div")));
  1779.  
  1780. tokenList = DOMTokenList.call(visage, THIS, attr);
  1781. } else tokenList = new DOMTokenList(THIS, attr);
  1782.  
  1783. defineGetter(THIS, name, function () {
  1784. return tokenList;
  1785. });
  1786. delete THIS[gibberishProperty];
  1787.  
  1788. return tokenList;
  1789. }, true);
  1790. };
  1791.  
  1792. addProp(global.Element, "classList", "className");
  1793. addProp(global.HTMLElement, "classList", "className");
  1794. addProp(global.HTMLLinkElement, "relList", "rel");
  1795. addProp(global.HTMLAnchorElement, "relList", "rel");
  1796. addProp(global.HTMLAreaElement, "relList", "rel");
  1797. }(this));
  1798.  
  1799. // Element.prototype.matches
  1800. Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
  1801.  
  1802. var element = this;
  1803. var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
  1804. var index = 0;
  1805.  
  1806. while (elements[index] && elements[index] !== element) {
  1807. ++index;
  1808. }
  1809.  
  1810. return !!elements[index];
  1811. };
  1812.  
  1813. // Element.prototype.closest
  1814. Element.prototype.closest = function closest(selector) {
  1815. var node = this;
  1816.  
  1817. while (node) {
  1818. if (node.matches(selector)) return node;
  1819. else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
  1820. }
  1821.  
  1822. return null;
  1823. };
  1824.  
  1825. // Element.prototype.prepend
  1826. Document.prototype.prepend = Element.prototype.prepend = function prepend() {
  1827. this.insertBefore(_mutation(arguments), this.firstChild);
  1828. };
  1829.  
  1830. // Element.prototype.remove
  1831. Document.prototype.remove = Element.prototype.remove = function remove() {
  1832. if (this.parentNode) {
  1833. this.parentNode.removeChild(this);
  1834. }
  1835. };
  1836.  
  1837. // Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
  1838. // TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
  1839. if ("Text" in this) {
  1840. Text.prototype.remove = Element.prototype.remove;
  1841. }
  1842.  
  1843. // Element.prototype.replaceWith
  1844. Document.prototype.replaceWith = Element.prototype.replaceWith = function replaceWith() {
  1845. if (this.parentNode) {
  1846. this.parentNode.replaceChild(_mutation(arguments), this);
  1847. }
  1848. };
  1849.  
  1850. // Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
  1851. // TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
  1852. if ('Text' in this) {
  1853. Text.prototype.replaceWith = Element.prototype.replaceWith;
  1854. }
  1855.  
  1856. // Symbol.species
  1857. Object.defineProperty(Symbol, 'species', {value: Symbol('species')});
  1858.  
  1859. // Map
  1860. (function (global) {
  1861. // 7.2.11. SameValueZero ( x, y )
  1862. var sameValueZero = function (x, y) {
  1863. // 1. If Type(x) is different from Type(y), return false.
  1864. if (typeof x !== typeof y) {
  1865. return false;
  1866. }
  1867. // 2. If Type(x) is Number, then
  1868. if (typeof x === 'number') {
  1869. // a. If x is NaN and y is NaN, return true.
  1870. if (isNaN(x) && isNaN(y)) {
  1871. return true;
  1872. }
  1873. // b. If x is +0 and y is -0, return true.
  1874. if (x === +0 && y === -0) {
  1875. return true;
  1876. }
  1877. // c. If x is -0 and y is +0, return true.
  1878. if (x === -0 && y === +0) {
  1879. return true;
  1880. }
  1881. // d. If x is the same Number value as y, return true.
  1882. if (x === y) {
  1883. return true;
  1884. }
  1885. // e. Return false.
  1886. return false;
  1887. }
  1888. // 3. Return SameValueNonNumber(x, y).
  1889. return x === y;
  1890. };
  1891.  
  1892. // 7.3.9. GetMethod ( V, P )
  1893. function getMethod(V, P) {
  1894. // 1. Assert: IsPropertyKey(P) is true.
  1895. // 2. Let func be ? GetV(V, P).
  1896. var func = V[P];
  1897. // 3. If func is either undefined or null, return undefined.
  1898. if (func === null || func === undefined) {
  1899. return undefined;
  1900. }
  1901. // 4. If IsCallable(func) is false, throw a TypeError exception.
  1902. if (typeof func !== 'function') {
  1903. throw new TypeError('Method not callable: ' + P);
  1904. }
  1905. // 5. Return func.
  1906. return func;
  1907. }
  1908.  
  1909. // 7.4.1. GetIterator ( obj [ , method ] )
  1910. // The abstract operation GetIterator with argument obj and optional argument method performs the following steps:
  1911. function getIterator(obj /*, method */) {
  1912. // 1. If method is not present, then
  1913. if (!(1 in arguments)) {
  1914. // a. Set method to ? GetMethod(obj, @@iterator).
  1915. var method = getMethod(obj, Symbol.iterator);
  1916. }
  1917. // 2. Let iterator be ? Call(method, obj).
  1918. var iterator = method.call(obj);
  1919. // 3. If Type(iterator) is not Object, throw a TypeError exception.
  1920. if (typeof iterator !== 'object') {
  1921. throw new TypeError('bad iterator');
  1922. }
  1923. // 4. Let nextMethod be ? GetV(iterator, "next").
  1924. var nextMethod = iterator.next;
  1925. // 5. Let iteratorRecord be Record {[[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false}.
  1926. var iteratorRecord = Object.create(null);
  1927. iteratorRecord['[[Iterator]]'] = iterator;
  1928. iteratorRecord['[[NextMethod]]'] = nextMethod;
  1929. iteratorRecord['[[Done]]'] = false;
  1930. // 6. Return iteratorRecord.
  1931. return iteratorRecord;
  1932. }
  1933.  
  1934. // 7.4.2. IteratorNext ( iteratorRecord [ , value ] )
  1935. function iteratorNext(iteratorRecord /* [, value] */) {
  1936. // 1. If value is not present, then
  1937. if (!(1 in arguments)) {
  1938. // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « »).
  1939. var result = iteratorRecord['[[NextMethod]]'].call(iteratorRecord['[[Iterator]]']);
  1940. // 2. Else,
  1941. } else {
  1942. // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
  1943. var result = iteratorRecord['[[NextMethod]]'].call(iteratorRecord['[[Iterator]]'], arguments[1]);
  1944. }
  1945. // 3. If Type(result) is not Object, throw a TypeError exception.
  1946. if (typeof result !== 'object') {
  1947. throw new TypeError('bad iterator');
  1948. }
  1949. // 4. Return result.
  1950. return result;
  1951. }
  1952.  
  1953. // 7.4.3 IteratorComplete ( iterResult )
  1954. function iteratorComplete(iterResult) {
  1955. // 1. Assert: Type(iterResult) is Object.
  1956. if (typeof iterResult !== 'object') {
  1957. throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.');
  1958. }
  1959. // 2. Return ToBoolean(? Get(iterResult, "done")).
  1960. return Boolean(iterResult['done']);
  1961. }
  1962.  
  1963. // 7.4.4 IteratorValue ( iterResult )
  1964. function iteratorValue(iterResult) {
  1965. // Assert: Type(iterResult) is Object.
  1966. if (typeof iterResult !== 'object') {
  1967. throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.');
  1968. }
  1969. // Return ? Get(iterResult, "value").
  1970. return iterResult.value;
  1971. }
  1972.  
  1973. // 7.4.5. IteratorStep ( iteratorRecord )
  1974. function iteratorStep(iteratorRecord) {
  1975. // 1. Let result be ? IteratorNext(iteratorRecord).
  1976. var result = iteratorNext(iteratorRecord);
  1977. // 2. Let done be ? IteratorComplete(result).
  1978. var done = iteratorComplete(result);
  1979. // 3. If done is true, return false.
  1980. if (done === true) {
  1981. return false;
  1982. }
  1983. // 4. Return result.
  1984. return result;
  1985. }
  1986.  
  1987. // 7.4.6. IteratorClose ( iteratorRecord, completion )
  1988. function iteratorClose(iteratorRecord, completion) {
  1989. // 1. Assert: Type(iteratorRecord.[[Iterator]]) is Object.
  1990. if (typeof iteratorRecord['[[Iterator]]'] !== 'object') {
  1991. throw new Error(Object.prototype.toString.call(iteratorRecord['[[Iterator]]']) + 'is not an Object.');
  1992. }
  1993. // 2. Assert: completion is a Completion Record.
  1994. // Polyfill.io - Ignoring this step as there is no way to check if something is a Completion Record in userland JavaScript.
  1995.  
  1996. // 3. Let iterator be iteratorRecord.[[Iterator]].
  1997. var iterator = iteratorRecord['[[Iterator]]'];
  1998. // 4. Let return be ? GetMethod(iterator, "return").
  1999. // Polyfill.io - We name it returnMethod because return is a keyword and can not be used as an identifier (E.G. variable name, function name etc).
  2000. var returnMethod = getMethod(iterator, "return");
  2001. // 5. If return is undefined, return Completion(completion).
  2002. if (returnMethod === undefined) {
  2003. return completion;
  2004. }
  2005. // 6. Let innerResult be Call(return, iterator, « »).
  2006. try {
  2007. var innerResult = returnMethod.call(iterator);
  2008. } catch (error) {
  2009. var innerException = error;
  2010. }
  2011. // 7. If completion.[[Type]] is throw, return Completion(completion).
  2012. if (completion) {
  2013. return completion;
  2014. }
  2015. // 8. If innerResult.[[Type]] is throw, return Completion(innerResult).
  2016. if (innerException) {
  2017. throw innerException;
  2018. }
  2019. // 9. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
  2020. if (!(typeof innerResult !== 'object')) {
  2021. throw new TypeError("Iterator's return method returned a non-object.");
  2022. }
  2023. // 10. Return Completion(completion).
  2024. return completion;
  2025. }
  2026.  
  2027. // 7.4.7. CreateIterResultObject ( value, done )
  2028. function createIterResultObject(value, done) {
  2029. // 1. Assert: Type(done) is Boolean.
  2030. if (typeof done !== 'boolean') {
  2031. throw new Error();
  2032. }
  2033. // 2. Let obj be ObjectCreate(%ObjectPrototype%).
  2034. var obj = {};
  2035. // 3. Perform CreateDataProperty(obj, "value", value).
  2036. obj.value = value;
  2037. // 4. Perform CreateDataProperty(obj, "done", done).
  2038. obj.done = done;
  2039. // 5. Return obj.
  2040. return obj;
  2041. }
  2042. // 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
  2043. var ordinaryCreateFromConstructor = function (constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
  2044. var internalSlotsList = arguments[2] || {};
  2045. /*
  2046. 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object.
  2047. The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object.
  2048. */
  2049. // Polyfill.io - We ignore the above step and instead pass the intrinsic directly.
  2050.  
  2051. // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
  2052. // Polyfill.io - We ignore the above step and always use the prototype of the constructor.
  2053. var proto = Object.getPrototypeOf(constructor);
  2054.  
  2055. // 3. Return ObjectCreate(proto, internalSlotsList).
  2056. // Polyfill.io - We do not pass internalSlotsList to Object.create because Object.create does use the default ordinary object definitions specified in 9.1.
  2057. var obj = Object.create(proto);
  2058. for (var name in internalSlotsList) {
  2059. if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) {
  2060. Object.defineProperty(obj, name, {
  2061. configurable: true,
  2062. enumerable: false,
  2063. writable: true,
  2064. value: internalSlotsList[name]
  2065. });
  2066. }
  2067. }
  2068. return obj;
  2069. };
  2070.  
  2071. // Deleted map items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol.
  2072. var undefMarker = Symbol('undef');
  2073.  
  2074. var supportsGetters = (function () {
  2075. try {
  2076. var a = {};
  2077. Object.defineProperty(a, 't', {
  2078. configurable: true,
  2079. enumerable: false,
  2080. get: function () {
  2081. return true;
  2082. },
  2083. set: undefined
  2084. });
  2085. return !!a.t;
  2086. } catch (e) {
  2087. return false;
  2088. }
  2089. }());
  2090.  
  2091. var isCallable = function (fn) {
  2092. return typeof fn === 'function';
  2093. };
  2094.  
  2095. // 23.1.1.1 Map ( [ iterable ] )
  2096. var Map = function Map(/* iterable */) {
  2097. // 1. If NewTarget is undefined, throw a TypeError exception.
  2098. if (!(this instanceof Map)) {
  2099. throw new TypeError('Constructor Map requires "new"');
  2100. }
  2101. // 2. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", « [[MapData]] »).
  2102. var map = ordinaryCreateFromConstructor(this, "%MapPrototype%", {
  2103. _keys: [],
  2104. _values: [],
  2105. _size: 0,
  2106. _es6Map: true
  2107. });
  2108.  
  2109. // 3. Set map.[[MapData]] to a new empty List.
  2110. // Polyfill.io - This step was done as part of step two.
  2111.  
  2112. // Some old engines do not support ES5 getters/setters. Since Map only requires these for the size property, we can fall back to setting the size property statically each time the size of the map changes.
  2113. if (!supportsGetters) {
  2114. Object.defineProperty(map, 'size', {
  2115. configurable: true,
  2116. enumerable: false,
  2117. writable: true,
  2118. value: 0
  2119. });
  2120. }
  2121.  
  2122. // 4. If iterable is not present, let iterable be undefined.
  2123. var iterable = arguments[0] || undefined;
  2124.  
  2125. // 5. If iterable is either undefined or null, return map.
  2126. if (iterable === null || iterable === undefined) {
  2127. return map;
  2128. }
  2129.  
  2130. // 6. Let adder be ? Get(map, "set").
  2131. var adder = map.set;
  2132.  
  2133. // 7. If IsCallable(adder) is false, throw a TypeError exception.
  2134. if (!isCallable(adder)) {
  2135. throw new TypeError("Map.prototype.set is not a function");
  2136. }
  2137.  
  2138. // 8. Let iteratorRecord be ? GetIterator(iterable).
  2139. try {
  2140. var iteratorRecord = getIterator(iterable);
  2141. // 9. Repeat,
  2142. while (true) {
  2143. // a. Let next be ? IteratorStep(iteratorRecord).
  2144. var next = iteratorStep(iteratorRecord);
  2145. // b. If next is false, return map.
  2146. if (next === false) {
  2147. return map;
  2148. }
  2149. // c. Let nextItem be ? IteratorValue(next).
  2150. var nextItem = iteratorValue(next);
  2151. // d. If Type(nextItem) is not Object, then
  2152. if (typeof nextItem !== 'object') {
  2153. // i. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}.
  2154. try {
  2155. throw new TypeError('Iterator value ' + nextItem + ' is not an entry object');
  2156. } catch (error) {
  2157. // ii. Return ? IteratorClose(iteratorRecord, error).
  2158. return iteratorClose(iteratorRecord, error);
  2159. }
  2160. }
  2161. try {
  2162. // Polyfill.io - The try catch accounts for steps: f, h, and j.
  2163.  
  2164. // e. Let k be Get(nextItem, "0").
  2165. var k = nextItem[0];
  2166. // f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k).
  2167. // g. Let v be Get(nextItem, "1").
  2168. var v = nextItem[1];
  2169. // h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v).
  2170. // i. Let status be Call(adder, map, « k.[[Value]], v.[[Value]] »).
  2171. adder.call(map, k, v);
  2172. } catch (e) {
  2173. // j. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status).
  2174. return iteratorClose(iteratorRecord, e);
  2175. }
  2176. }
  2177. } catch (e) {
  2178. // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those.
  2179. if (Array.isArray(iterable) ||
  2180. Object.prototype.toString.call(iterable) === '[object Arguments]' ||
  2181. // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property
  2182. (!!iterable.callee)) {
  2183. var index;
  2184. var length = iterable.length;
  2185. for (index = 0; index < length; index++) {
  2186. adder.call(map, iterable[index][0], iterable[index][1]);
  2187. }
  2188. }
  2189. }
  2190. return map;
  2191. };
  2192.  
  2193. // 23.1.2.1. Map.prototype
  2194. // The initial value of Map.prototype is the intrinsic object %MapPrototype%.
  2195. // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
  2196. Object.defineProperty(Map, 'prototype', {
  2197. configurable: false,
  2198. enumerable: false,
  2199. writable: false,
  2200. value: {}
  2201. });
  2202.  
  2203. // 23.1.2.2 get Map [ @@species ]
  2204. if (supportsGetters) {
  2205. Object.defineProperty(Map, Symbol.species, {
  2206. configurable: true,
  2207. enumerable: false,
  2208. get: function () {
  2209. // 1. Return the this value.
  2210. return this;
  2211. },
  2212. set: undefined
  2213. });
  2214. } else {
  2215. Object.defineProperty(Map, Symbol.species, {
  2216. configurable: true,
  2217. enumerable: false,
  2218. writable: true,
  2219. value: Map
  2220. });
  2221. }
  2222.  
  2223. // 23.1.3.1 Map.prototype.clear ( )
  2224. Object.defineProperty(Map.prototype, 'clear', {
  2225. configurable: true,
  2226. enumerable: false,
  2227. writable: true,
  2228. value: function clear() {
  2229. // 1. Let M be the this value.
  2230. var M = this;
  2231. // 2. If Type(M) is not Object, throw a TypeError exception.
  2232. if (typeof M !== 'object') {
  2233. throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
  2234. }
  2235. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2236. if (M._es6Map !== true) {
  2237. throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
  2238. }
  2239. // 4. Let entries be the List that is M.[[MapData]].
  2240. var entries = M._keys;
  2241. // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2242. for (var i = 0; i < entries.length; i++) {
  2243. // 5.a. Set p.[[Key]] to empty.
  2244. M._keys[i] = undefMarker;
  2245. // 5.b. Set p.[[Value]] to empty.
  2246. M._values[i] = undefMarker;
  2247. }
  2248. this._size = 0;
  2249. if (!supportsGetters) {
  2250. this.size = this._size;
  2251. }
  2252. // 6. Return undefined.
  2253. return undefined;
  2254. }
  2255. });
  2256.  
  2257. // 23.1.3.2. Map.prototype.constructor
  2258. Object.defineProperty(Map.prototype, 'constructor', {
  2259. configurable: true,
  2260. enumerable: false,
  2261. writable: true,
  2262. value: Map
  2263. });
  2264.  
  2265. // 23.1.3.3. Map.prototype.delete ( key )
  2266. Object.defineProperty(Map.prototype, 'delete', {
  2267. configurable: true,
  2268. enumerable: false,
  2269. writable: true,
  2270. value: function (key) {
  2271. // 1. Let M be the this value.
  2272. var M = this;
  2273. // 2. If Type(M) is not Object, throw a TypeError exception.
  2274. if (typeof M !== 'object') {
  2275. throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
  2276. }
  2277. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2278. if (M._es6Map !== true) {
  2279. throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
  2280. }
  2281. // 4. Let entries be the List that is M.[[MapData]].
  2282. var entries = M._keys;
  2283. // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2284. for (var i = 0; i < entries.length; i++) {
  2285. // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then
  2286. if (M._keys[i] !== undefMarker && sameValueZero(M._keys[i], key)) {
  2287. // i. Set p.[[Key]] to empty.
  2288. this._keys[i] = undefMarker;
  2289. // ii. Set p.[[Value]] to empty.
  2290. this._values[i] = undefMarker;
  2291. --this._size;
  2292. if (!supportsGetters) {
  2293. this.size = this._size;
  2294. }
  2295. // iii. Return true.
  2296. return true;
  2297. }
  2298. }
  2299. // 6. Return false.
  2300. return false;
  2301. }
  2302. });
  2303.  
  2304. // 23.1.3.4. Map.prototype.entries ( )
  2305. Object.defineProperty(Map.prototype, 'entries', {
  2306. configurable: true,
  2307. enumerable: false,
  2308. writable: true,
  2309. value: function entries () {
  2310. // 1. Let M be the this value.
  2311. var M = this;
  2312. // 2. Return ? CreateMapIterator(M, "key+value").
  2313. return createMapIterator(M, 'key+value');
  2314. }
  2315. });
  2316.  
  2317. // 23.1.3.5. Map.prototype.forEach ( callbackfn [ , thisArg ] )
  2318. Object.defineProperty(Map.prototype, 'forEach', {
  2319. configurable: true,
  2320. enumerable: false,
  2321. writable: true,
  2322. value: function (callbackFn) {
  2323. // 1. Let M be the this value.
  2324. var M = this;
  2325. // 2. If Type(M) is not Object, throw a TypeError exception.
  2326. if (typeof M !== 'object') {
  2327. throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M));
  2328. }
  2329. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2330. if (M._es6Map !== true) {
  2331. throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M));
  2332. }
  2333. // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
  2334. if (!isCallable(callbackFn)) {
  2335. throw new TypeError(Object.prototype.toString.call(callbackFn) + ' is not a function.');
  2336. }
  2337. // 5. If thisArg is present, let T be thisArg; else let T be undefined.
  2338. if (arguments[1]) {
  2339. var T = arguments[1];
  2340. }
  2341. // 6. Let entries be the List that is M.[[MapData]].
  2342. var entries = M._keys;
  2343. // 7. For each Record {[[Key]], [[Value]]} e that is an element of entries, in original key insertion order, do
  2344. for (var i = 0; i < entries.length; i++) {
  2345. // a. If e.[[Key]] is not empty, then
  2346. if (M._keys[i] !== undefMarker && M._values[i] !== undefMarker ) {
  2347. // i. Perform ? Call(callbackfn, T, « e.[[Value]], e.[[Key]], M »).
  2348. callbackFn.call(T, M._values[i], M._keys[i], M);
  2349. }
  2350. }
  2351. // 8. Return undefined.
  2352. return undefined;
  2353. }
  2354. });
  2355.  
  2356. // 23.1.3.6. Map.prototype.get ( key )
  2357. Object.defineProperty(Map.prototype, 'get', {
  2358. configurable: true,
  2359. enumerable: false,
  2360. writable: true,
  2361. value: function get(key) {
  2362. // 1. Let M be the this value.
  2363. var M = this;
  2364. // 2. If Type(M) is not Object, throw a TypeError exception.
  2365. if (typeof M !== 'object') {
  2366. throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M));
  2367. }
  2368. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2369. if (M._es6Map !== true) {
  2370. throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M));
  2371. }
  2372. // 4. Let entries be the List that is M.[[MapData]].
  2373. var entries = M._keys;
  2374. // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2375. for (var i = 0; i < entries.length; i++) {
  2376. // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]].
  2377. if (M._keys[i] !== undefMarker && sameValueZero(M._keys[i], key)) {
  2378. return M._values[i];
  2379. }
  2380. }
  2381. // 6. Return undefined.
  2382. return undefined;
  2383. }
  2384. });
  2385.  
  2386. // 23.1.3.7. Map.prototype.has ( key )
  2387. Object.defineProperty(Map.prototype, 'has', {
  2388. configurable: true,
  2389. enumerable: false,
  2390. writable: true,
  2391. value: function has (key) {
  2392. // 1. Let M be the this value.
  2393. var M = this;
  2394. // 2. If Type(M) is not Object, throw a TypeError exception.
  2395. if (typeof M !== 'object') {
  2396. throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M));
  2397. }
  2398. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2399. if (M._es6Map !== true) {
  2400. throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M));
  2401. }
  2402. // 4. Let entries be the List that is M.[[MapData]].
  2403. var entries = M._keys;
  2404. // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2405. for (var i = 0; i < entries.length; i++) {
  2406. // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return true.
  2407. if (M._keys[i] !== undefMarker && sameValueZero(M._keys[i], key)) {
  2408. return true;
  2409. }
  2410. }
  2411. // 6. Return false.
  2412. return false;
  2413. }
  2414. });
  2415.  
  2416. // 23.1.3.8. Map.prototype.keys ( )
  2417. Object.defineProperty(Map.prototype, 'keys', {
  2418. configurable: true,
  2419. enumerable: false,
  2420. writable: true,
  2421. value: function keys () {
  2422. // 1. Let M be the this value.
  2423. var M = this;
  2424. // 2. Return ? CreateMapIterator(M, "key").
  2425. return createMapIterator(M, "key");
  2426. }
  2427. });
  2428.  
  2429. // 23.1.3.9. Map.prototype.set ( key, value )
  2430. Object.defineProperty(Map.prototype, 'set', {
  2431. configurable: true,
  2432. enumerable: false,
  2433. writable: true,
  2434. value: function set(key, value) {
  2435. // 1. Let M be the this value.
  2436. var M = this;
  2437. // 2. If Type(M) is not Object, throw a TypeError exception.
  2438. if (typeof M !== 'object') {
  2439. throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M));
  2440. }
  2441. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2442. if (M._es6Map !== true) {
  2443. throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M));
  2444. }
  2445. // 4. Let entries be the List that is M.[[MapData]].
  2446. var entries = M._keys;
  2447. // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2448. for (var i = 0; i < entries.length; i++) {
  2449. // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then
  2450. if (M._keys[i] !== undefMarker && sameValueZero(M._keys[i], key)) {
  2451. // i. Set p.[[Value]] to value.
  2452. M._values[i] = value;
  2453. // Return M.
  2454. return M;
  2455. }
  2456. }
  2457. // 6. If key is -0, let key be +0.
  2458. if (key === -0) {
  2459. key = 0;
  2460. }
  2461. // 7. Let p be the Record {[[Key]]: key, [[Value]]: value}.
  2462. var p = {};
  2463. p['[[Key]]'] = key;
  2464. p['[[Value]]'] = value;
  2465. // 8. Append p as the last element of entries.
  2466. M._keys.push(p['[[Key]]']);
  2467. M._values.push(p['[[Value]]']);
  2468. ++M._size;
  2469. if (!supportsGetters) {
  2470. M.size = M._size;
  2471. }
  2472. // 9. Return M.
  2473. return M;
  2474. }
  2475. });
  2476.  
  2477. // 23.1.3.10. get Map.prototype.size
  2478. if (supportsGetters) {
  2479. Object.defineProperty(Map.prototype, 'size', {
  2480. configurable: true,
  2481. enumerable: false,
  2482. get: function () {
  2483. // 1. Let M be the this value.
  2484. var M = this;
  2485. // 2. If Type(M) is not Object, throw a TypeError exception.
  2486. if (typeof M !== 'object') {
  2487. throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M));
  2488. }
  2489. // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
  2490. if (M._es6Map !== true) {
  2491. throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M));
  2492. }
  2493. // 4. Let entries be the List that is M.[[MapData]].
  2494. var entries = M._keys;
  2495. // 5. Let count be 0.
  2496. var count = 0;
  2497. // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
  2498. for (var i = 0; i < entries.length; i++) {
  2499. // a. If p.[[Key]] is not empty, set count to count+1.
  2500. if (M._keys[i] !== undefMarker) {
  2501. count = count + 1;
  2502. }
  2503. }
  2504. // 7. Return count.
  2505. return count;
  2506. },
  2507. set: undefined
  2508. });
  2509. }
  2510.  
  2511. // 23.1.3.11. Map.prototype.values ( )
  2512. Object.defineProperty(Map.prototype, 'values', {
  2513. configurable: true,
  2514. enumerable: false,
  2515. writable: true,
  2516. value: function values () {
  2517. // 1. Let M be the this value.
  2518. var M = this;
  2519. // 2. Return ? CreateMapIterator(M, "value").
  2520. return createMapIterator(M, 'value');
  2521. }
  2522. });
  2523.  
  2524. // 23.1.3.12. Map.prototype [ @@iterator ] ( )
  2525. // The initial value of the @@iterator property is the same function object as the initial value of the entries property.
  2526. Object.defineProperty(Map.prototype, Symbol.iterator, {
  2527. configurable: true,
  2528. enumerable: false,
  2529. writable: true,
  2530. value: Map.prototype.entries
  2531. });
  2532.  
  2533. // 23.1.3.13. Map.prototype [ @@toStringTag ]
  2534. // The initial value of the @@toStringTag property is the String value "Map".
  2535. // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
  2536.  
  2537. // Polyfill.io - Safari 8 implements Map.name but as a non-configurable property, which means it would throw an error if we try and configure it here.
  2538. if (!('name' in Map)) {
  2539. // 19.2.4.2 name
  2540. Object.defineProperty(Map, 'name', {
  2541. configurable: true,
  2542. enumerable: false,
  2543. writable: false,
  2544. value: 'Map'
  2545. });
  2546. }
  2547.  
  2548. // 23.1.5.1. CreateMapIterator ( map, kind )
  2549. function createMapIterator(map, kind) {
  2550. // 1. If Type(map) is not Object, throw a TypeError exception.
  2551. if (typeof map !== 'object') {
  2552. throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map));
  2553. }
  2554. // 2. If map does not have a [[MapData]] internal slot, throw a TypeError exception.
  2555. if (map._es6Map !== true) {
  2556. throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map));
  2557. }
  2558. // 3. Let iterator be ObjectCreate(%MapIteratorPrototype%, « [[Map]], [[MapNextIndex]], [[MapIterationKind]] »).
  2559. var iterator = Object.create(MapIteratorPrototype);
  2560. // 4. Set iterator.[[Map]] to map.
  2561. Object.defineProperty(iterator, '[[Map]]', {
  2562. configurable: true,
  2563. enumerable: false,
  2564. writable: true,
  2565. value: map
  2566. });
  2567. // 5. Set iterator.[[MapNextIndex]] to 0.
  2568. Object.defineProperty(iterator, '[[MapNextIndex]]', {
  2569. configurable: true,
  2570. enumerable: false,
  2571. writable: true,
  2572. value: 0
  2573. });
  2574. // 6. Set iterator.[[MapIterationKind]] to kind.
  2575. Object.defineProperty(iterator, '[[MapIterationKind]]', {
  2576. configurable: true,
  2577. enumerable: false,
  2578. writable: true,
  2579. value: kind
  2580. });
  2581. // 7. Return iterator.
  2582. return iterator;
  2583. }
  2584.  
  2585. // 23.1.5.2. The %MapIteratorPrototype% Object
  2586. var MapIteratorPrototype = {
  2587. // Polyfill.io - We use this as a quick way to check if an object is a Map Iterator instance.
  2588. isMapIterator: true,
  2589. // 23.1.5.2.1. %MapIteratorPrototype%.next ( )
  2590. next: function next () {
  2591. // 1. Let O be the this value.
  2592. var O = this;
  2593. // 2. If Type(O) is not Object, throw a TypeError exception.
  2594. if (typeof O !== 'object') {
  2595. throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
  2596. }
  2597. // 3. If O does not have all of the internal slots of a Map Iterator Instance (23.1.5.3), throw a TypeError exception.
  2598. if (!O.isMapIterator) {
  2599. throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
  2600. }
  2601. // 4. Let m be O.[[Map]].
  2602. var m = O['[[Map]]'];
  2603. // 5. Let index be O.[[MapNextIndex]].
  2604. var index = O['[[MapNextIndex]]'];
  2605. // 6. Let itemKind be O.[[MapIterationKind]].
  2606. var itemKind = O['[[MapIterationKind]]'];
  2607. // 7. If m is undefined, return CreateIterResultObject(undefined, true).
  2608. if (m === undefined) {
  2609. return createIterResultObject(undefined, true);
  2610. }
  2611. // 8. Assert: m has a [[MapData]] internal slot.
  2612. if (!m._es6Map) {
  2613. throw new Error();
  2614. }
  2615. // 9. Let entries be the List that is m.[[MapData]].
  2616. var entries = m._keys;
  2617. // 10. Let numEntries be the number of elements of entries.
  2618. var numEntries = entries.length;
  2619. // 11. NOTE: numEntries must be redetermined each time this method is evaluated.
  2620. // 12. Repeat, while index is less than numEntries,
  2621. while (index < numEntries) {
  2622. // a. Let e be the Record {[[Key]], [[Value]]} that is the value of entries[index].
  2623. var e = Object.create(null);
  2624. e['[[Key]]'] = m._keys[index];
  2625. e['[[Value]]'] = m._values[index];
  2626. // b. Set index to index+1.
  2627. index = index + 1;
  2628. // c. Set O.[[MapNextIndex]] to index.
  2629. O['[[MapNextIndex]]'] = index;
  2630. // d. If e.[[Key]] is not empty, then
  2631. if (e['[[Key]]'] !== undefMarker) {
  2632. // i. If itemKind is "key", let result be e.[[Key]].
  2633. if (itemKind === 'key') {
  2634. var result = e['[[Key]]'];
  2635. // ii. Else if itemKind is "value", let result be e.[[Value]].
  2636. } else if (itemKind === 'value') {
  2637. var result = e['[[Value]]'];
  2638. // iii. Else,
  2639. } else {
  2640. // 1. Assert: itemKind is "key+value".
  2641. if (itemKind !== 'key+value') {
  2642. throw new Error();
  2643. }
  2644. // 2. Let result be CreateArrayFromList(« e.[[Key]], e.[[Value]] »).
  2645. var result = [
  2646. e['[[Key]]'],
  2647. e['[[Value]]']
  2648. ];
  2649. }
  2650. // iv. Return CreateIterResultObject(result, false).
  2651. return createIterResultObject(result, false);
  2652. }
  2653. }
  2654. // 13. Set O.[[Map]] to undefined.
  2655. O['[[Map]]'] = undefined;
  2656. // 14. Return CreateIterResultObject(undefined, true).
  2657. return createIterResultObject(undefined, true);
  2658. }
  2659.  
  2660. // 23.1.5.2.2 %MapIteratorPrototype% [ @@toStringTag ]
  2661. // The initial value of the @@toStringTag property is the String value "Map Iterator".
  2662. // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
  2663. };
  2664. Object.defineProperty(MapIteratorPrototype, Symbol.iterator, {
  2665. configurable: true,
  2666. enumerable: false,
  2667. writable: true,
  2668. value: function iterator() {
  2669. return this;
  2670. }
  2671. });
  2672.  
  2673. // Export the object
  2674. try {
  2675. Object.defineProperty(global, 'Map', {
  2676. configurable: true,
  2677. enumerable: false,
  2678. writable: true,
  2679. value: Map
  2680. });
  2681. } catch (e) {
  2682. // IE8 throws an error here if we set enumerable to false.
  2683. // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx
  2684. global['Map'] = Map;
  2685. }
  2686. }(this));
  2687.  
  2688. // Node.prototype.contains
  2689. (function() {
  2690.  
  2691. function contains(node) {
  2692. if (!(0 in arguments)) {
  2693. throw new TypeError('1 argument is required');
  2694. }
  2695.  
  2696. do {
  2697. if (this === node) {
  2698. return true;
  2699. }
  2700. } while (node = node && node.parentNode);
  2701.  
  2702. return false;
  2703. }
  2704.  
  2705. // IE
  2706. if ('HTMLElement' in this && 'contains' in HTMLElement.prototype) {
  2707. try {
  2708. delete HTMLElement.prototype.contains;
  2709. } catch (e) {}
  2710. }
  2711.  
  2712. if ('Node' in this) {
  2713. Node.prototype.contains = contains;
  2714. } else {
  2715. document.contains = Element.prototype.contains = contains;
  2716. }
  2717.  
  2718. }());
  2719.  
  2720. // Promise
  2721. !function(n){function t(e){if(r[e])return r[e].exports;var o=r[e]={exports:{},id:e,loaded:!1};return n[e].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=n,t.c=r,t.p="",t(0)}({0:/*!***********************!*\
  2722. !*** ./src/global.js ***!
  2723. \***********************/
  2724. function(n,t,r){(function(n){var t=r(/*! ./yaku */80);try{(n||{}).Promise=t,window.Promise=t}catch(err){}}).call(t,function(){return this}())},80:/*!*********************!*\
  2725. !*** ./src/yaku.js ***!
  2726. \*********************/
  2727. function(n,t){(function(t){!function(){"use strict";function r(){return un[B][G]||J}function e(n,t){for(var r in t)n[r]=t[r]}function o(n){return n&&"object"==typeof n}function i(n){return"function"==typeof n}function u(n,t){return n instanceof t}function c(n){return u(n,U)}function f(n,t,r){if(!t(n))throw v(r)}function s(){try{return C.apply(F,arguments)}catch(e){return rn.e=e,rn}}function a(n,t){return C=n,F=t,s}function l(n,t){function r(){for(var r=0;r<o;)t(e[r],e[r+1]),e[r++]=S,e[r++]=S;o=0,e.length>n&&(e.length=n)}var e=O(n),o=0;return function(n,t){e[o++]=n,e[o++]=t,2===o&&un.nextTick(r)}}function h(n,t){var r,e,o,c,f=0;if(!n)throw v(W);var s=n[un[B][D]];if(i(s))e=s.call(n);else{if(!i(n.next)){if(u(n,O)){for(r=n.length;f<r;)t(n[f],f++);return f}throw v(W)}e=n}for(;!(o=e.next()).done;)if(c=a(t)(o.value,f++),c===rn)throw i(e[K])&&e[K](),c.e;return f}function v(n){return new TypeError(n)}function _(n){return(n?"":X)+(new U).stack}function d(n,t){var r="on"+n.toLowerCase(),e=H[r];I&&I.listeners(n).length?n===tn?I.emit(n,t._v,t):I.emit(n,t):e?e({reason:t._v,promise:t}):un[n](t._v,t)}function p(n){return n&&n._s}function w(n){if(p(n))return new n(en);var t,r,e;return t=new n(function(n,o){if(t)throw v();r=n,e=o}),f(r,i),f(e,i),t}function m(n,t){return function(r){A&&(n[Q]=_(!0)),t===q?T(n,r):k(n,t,r)}}function y(n,t,r,e){return i(r)&&(t._onFulfilled=r),i(e)&&(n[M]&&d(nn,n),t._onRejected=e),A&&(t._p=n),n[n._c++]=t,n._s!==z&&cn(n,t),t}function j(n){if(n._umark)return!0;n._umark=!0;for(var t,r=0,e=n._c;r<e;)if(t=n[r++],t._onRejected||j(t))return!0}function x(n,t){function r(n){return e.push(n.replace(/^\s+|\s+$/g,""))}var e=[];return A&&(t[Q]&&r(t[Q]),function o(n){n&&N in n&&(o(n._next),r(n[N]+""),o(n._p))}(t)),(n&&n.stack?n.stack:n)+("\n"+e.join("\n")).replace(on,"")}function g(n,t){return n(t)}function k(n,t,r){var e=0,o=n._c;if(n._s===z)for(n._s=t,n._v=r,t===$&&(A&&c(r)&&(r.longStack=x(r,n)),fn(n));e<o;)cn(n,n[e++]);return n}function T(n,t){if(t===n&&t)return k(n,$,v(Y)),n;if(t!==P&&(i(t)||o(t))){var r=a(b)(t);if(r===rn)return k(n,$,r.e),n;i(r)?(A&&p(t)&&(n._next=t),p(t)?R(n,t,r):un.nextTick(function(){R(n,t,r)})):k(n,q,t)}else k(n,q,t);return n}function b(n){return n.then}function R(n,t,r){var e=a(r,t)(function(r){t&&(t=P,T(n,r))},function(r){t&&(t=P,k(n,$,r))});e===rn&&t&&(k(n,$,e.e),t=P)}var S,C,F,P=null,E="object"==typeof window,H=E?window:t,I=H.process,L=H.console,A=!1,O=Array,U=Error,$=1,q=2,z=3,B="Symbol",D="iterator",G="species",J=B+"("+G+")",K="return",M="_uh",N="_pt",Q="_st",V="Invalid this",W="Invalid argument",X="\nFrom previous ",Y="Chaining cycle detected for promise",Z="Uncaught (in promise)",nn="rejectionHandled",tn="unhandledRejection",rn={e:P},en=function(){},on=/^.+\/node_modules\/yaku\/.+\n?/gm,un=n.exports=function(n){var t,r=this;if(!o(r)||r._s!==S)throw v(V);if(r._s=z,A&&(r[N]=_()),n!==en){if(!i(n))throw v(W);t=a(n)(m(r,q),m(r,$)),t===rn&&k(r,$,t.e)}};un["default"]=un,e(un.prototype,{then:function(n,t){if(void 0===this._s)throw v();return y(this,w(un.speciesConstructor(this,un)),n,t)},"catch":function(n){return this.then(S,n)},"finally":function(n){function t(t){return un.resolve(n()).then(function(){return t})}return this.then(t,t)},_c:0,_p:P}),un.resolve=function(n){return p(n)?n:T(w(this),n)},un.reject=function(n){return k(w(this),$,n)},un.race=function(n){var t=this,r=w(t),e=function(n){k(r,q,n)},o=function(n){k(r,$,n)},i=a(h)(n,function(n){t.resolve(n).then(e,o)});return i===rn?t.reject(i.e):r},un.all=function(n){function t(n){k(o,$,n)}var r,e=this,o=w(e),i=[];return r=a(h)(n,function(n,u){e.resolve(n).then(function(n){i[u]=n,--r||k(o,q,i)},t)}),r===rn?e.reject(r.e):(r||k(o,q,[]),o)},un.Symbol=H[B]||{},a(function(){Object.defineProperty(un,r(),{get:function(){return this}})})(),un.speciesConstructor=function(n,t){var e=n.constructor;return e?e[r()]||t:t},un.unhandledRejection=function(n,t){L&&L.error(Z,A?t.longStack:x(n,t))},un.rejectionHandled=en,un.enableLongStackTrace=function(){A=!0},un.nextTick=E?function(n){setTimeout(n)}:I.nextTick,un._s=1;var cn=l(999,function(n,t){var r,e;return e=n._s!==$?t._onFulfilled:t._onRejected,e===S?void k(t,n._s,n._v):(r=a(g)(e,n._v),r===rn?void k(t,$,r.e):void T(t,r))}),fn=l(9,function(n){j(n)||(n[M]=1,d(tn,n))})}()}).call(t,function(){return this}())}});
  2728. // Set
  2729. (function(global) {
  2730.  
  2731.  
  2732. // Deleted map items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol.
  2733. var undefMarker = Symbol('undef');
  2734.  
  2735. // NaN cannot be found in an array using indexOf, so we encode NaNs using a private symbol.
  2736. var NaNMarker = Symbol('NaN');
  2737.  
  2738. function encodeVal(data) {
  2739. return Number.isNaN(data) ? NaNMarker : data;
  2740. }
  2741. function decodeVal(encodedData) {
  2742. return (encodedData === NaNMarker) ? NaN : encodedData;
  2743. }
  2744.  
  2745. function makeIterator(setInst, getter) {
  2746. var nextIdx = 0;
  2747. return {
  2748. next: function() {
  2749. while (setInst._values[nextIdx] === undefMarker) nextIdx++;
  2750. if (nextIdx === setInst._values.length) {
  2751. return {value: void 0, done: true};
  2752. }
  2753. else {
  2754. return {value: getter.call(setInst, nextIdx++), done: false};
  2755. }
  2756. }
  2757. };
  2758. }
  2759.  
  2760. var Set = function Set() {
  2761. var data = arguments[0];
  2762. this._values = [];
  2763. this.size = this._size = 0;
  2764.  
  2765. // If `data` is iterable (indicated by presence of a forEach method), pre-populate the set
  2766. data && (typeof data.forEach === 'function') && data.forEach(function (item) {
  2767. this.add.call(this, item);
  2768. }, this);
  2769. };
  2770.  
  2771. // Some old engines do not support ES5 getters/setters. Since Set only requires these for the size property, we can fall back to setting the size property statically each time the size of the set changes.
  2772. try {
  2773. Object.defineProperty(Set.prototype, 'size', {
  2774. get: function() {
  2775. return this._size;
  2776. }
  2777. });
  2778. } catch(e) {
  2779. }
  2780.  
  2781. Set.prototype['add'] = function(value) {
  2782. value = encodeVal(value);
  2783. if (this._values.indexOf(value) === -1) {
  2784. this._values.push(value);
  2785. this.size = ++this._size;
  2786. }
  2787. return this;
  2788. };
  2789. Set.prototype['has'] = function(value) {
  2790. return (this._values.indexOf(encodeVal(value)) !== -1);
  2791. };
  2792. Set.prototype['delete'] = function(value) {
  2793. var idx = this._values.indexOf(encodeVal(value));
  2794. if (idx === -1) return false;
  2795. this._values[idx] = undefMarker;
  2796. this.size = --this._size;
  2797. return true;
  2798. };
  2799. Set.prototype['clear'] = function() {
  2800. this._values = [];
  2801. this.size = this._size = 0;
  2802. };
  2803. Set.prototype[Symbol.iterator] =
  2804. Set.prototype['values'] =
  2805. Set.prototype['keys'] = function() {
  2806. var iterator = makeIterator(this, function(i) { return decodeVal(this._values[i]); });
  2807. iterator[Symbol.iterator] = this.keys.bind(this);
  2808. return iterator;
  2809. };
  2810. Set.prototype['entries'] = function() {
  2811. var iterator = makeIterator(this, function(i) { return [decodeVal(this._values[i]), decodeVal(this._values[i])]; });
  2812. iterator[Symbol.iterator] = this.entries.bind(this);
  2813. return iterator;
  2814. };
  2815. Set.prototype['forEach'] = function(callbackFn, thisArg) {
  2816. thisArg = thisArg || global;
  2817. var iterator = this.entries();
  2818. var result = iterator.next();
  2819. while (result.done === false) {
  2820. callbackFn.call(thisArg, result.value[1], result.value[0], this);
  2821. result = iterator.next();
  2822. }
  2823. };
  2824. Set.prototype['constructor'] =
  2825. Set.prototype[Symbol.species] = Set;
  2826.  
  2827. Set.prototype.constructor = Set;
  2828. Set.name = "Set";
  2829.  
  2830. // Export the object
  2831. global.Set = Set;
  2832.  
  2833. }(this));
  2834.  
  2835. // String.prototype.endsWith
  2836. String.prototype.endsWith = function (string) {
  2837. var index = arguments.length < 2 ? this.length : arguments[1];
  2838. var foundIndex = this.lastIndexOf(string);
  2839. return foundIndex !== -1 && foundIndex === index - string.length;
  2840. };
  2841.  
  2842. // String.prototype.startsWith
  2843. String.prototype.startsWith = function (string) {
  2844. var index = arguments.length < 2 ? 0 : arguments[1];
  2845.  
  2846. return this.slice(index).indexOf(string) === 0;
  2847. };
  2848.  
  2849. // URL
  2850. // URL Polyfill
  2851. // Draft specification: https://url.spec.whatwg.org
  2852.  
  2853. // Notes:
  2854. // - Primarily useful for parsing URLs and modifying query parameters
  2855. // - Should work in IE8+ and everything more modern, with es5.js polyfills
  2856.  
  2857. (function (global) {
  2858. 'use strict';
  2859.  
  2860. function isSequence(o) {
  2861. if (!o) return false;
  2862. if ('Symbol' in global && 'iterator' in global.Symbol &&
  2863. typeof o[Symbol.iterator] === 'function') return true;
  2864. if (Array.isArray(o)) return true;
  2865. return false;
  2866. }
  2867.  
  2868. function toArray(iter) {
  2869. return ('from' in Array) ? Array.from(iter) : Array.prototype.slice.call(iter);
  2870. }
  2871.  
  2872. (function() {
  2873.  
  2874. // Browsers may have:
  2875. // * No global URL object
  2876. // * URL with static methods only - may have a dummy constructor
  2877. // * URL with members except searchParams
  2878. // * Full URL API support
  2879. var origURL = global.URL;
  2880. var nativeURL;
  2881. try {
  2882. if (origURL) {
  2883. nativeURL = new global.URL('http://example.com');
  2884. if ('searchParams' in nativeURL)
  2885. return;
  2886. if (!('href' in nativeURL))
  2887. nativeURL = undefined;
  2888. }
  2889. } catch (_) {}
  2890.  
  2891. // NOTE: Doesn't do the encoding/decoding dance
  2892. function urlencoded_serialize(pairs) {
  2893. var output = '', first = true;
  2894. pairs.forEach(function (pair) {
  2895. var name = encodeURIComponent(pair.name);
  2896. var value = encodeURIComponent(pair.value);
  2897. if (!first) output += '&';
  2898. output += name + '=' + value;
  2899. first = false;
  2900. });
  2901. return output.replace(/%20/g, '+');
  2902. }
  2903.  
  2904. // NOTE: Doesn't do the encoding/decoding dance
  2905. function urlencoded_parse(input, isindex) {
  2906. var sequences = input.split('&');
  2907. if (isindex && sequences[0].indexOf('=') === -1)
  2908. sequences[0] = '=' + sequences[0];
  2909. var pairs = [];
  2910. sequences.forEach(function (bytes) {
  2911. if (bytes.length === 0) return;
  2912. var index = bytes.indexOf('=');
  2913. if (index !== -1) {
  2914. var name = bytes.substring(0, index);
  2915. var value = bytes.substring(index + 1);
  2916. } else {
  2917. name = bytes;
  2918. value = '';
  2919. }
  2920. name = name.replace(/\+/g, ' ');
  2921. value = value.replace(/\+/g, ' ');
  2922. pairs.push({ name: name, value: value });
  2923. });
  2924. var output = [];
  2925. pairs.forEach(function (pair) {
  2926. output.push({
  2927. name: decodeURIComponent(pair.name),
  2928. value: decodeURIComponent(pair.value)
  2929. });
  2930. });
  2931. return output;
  2932. }
  2933.  
  2934. function URLUtils(url) {
  2935. if (nativeURL)
  2936. return new origURL(url);
  2937. var anchor = document.createElement('a');
  2938. anchor.href = url;
  2939. return anchor;
  2940. }
  2941.  
  2942. function URLSearchParams(init) {
  2943. var $this = this;
  2944. this._list = [];
  2945.  
  2946. if (init === undefined || init === null) {
  2947. // no-op
  2948. } else if (init instanceof URLSearchParams) {
  2949. // In ES6 init would be a sequence, but special case for ES5.
  2950. this._list = urlencoded_parse(String(init));
  2951. } else if (typeof init === 'object' && isSequence(init)) {
  2952. toArray(init).forEach(function(e) {
  2953. if (!isSequence(e)) throw TypeError();
  2954. var nv = toArray(e);
  2955. if (nv.length !== 2) throw TypeError();
  2956. $this._list.push({name: String(nv[0]), value: String(nv[1])});
  2957. });
  2958. } else if (typeof init === 'object' && init) {
  2959. Object.keys(init).forEach(function(key) {
  2960. $this._list.push({name: String(key), value: String(init[key])});
  2961. });
  2962. } else {
  2963. init = String(init);
  2964. if (init.substring(0, 1) === '?')
  2965. init = init.substring(1);
  2966. this._list = urlencoded_parse(init);
  2967. }
  2968.  
  2969. this._url_object = null;
  2970. this._setList = function (list) { if (!updating) $this._list = list; };
  2971.  
  2972. var updating = false;
  2973. this._update_steps = function() {
  2974. if (updating) return;
  2975. updating = true;
  2976.  
  2977. if (!$this._url_object) return;
  2978.  
  2979. // Partial workaround for IE issue with 'about:'
  2980. if ($this._url_object.protocol === 'about:' &&
  2981. $this._url_object.pathname.indexOf('?') !== -1) {
  2982. $this._url_object.pathname = $this._url_object.pathname.split('?')[0];
  2983. }
  2984.  
  2985. $this._url_object.search = urlencoded_serialize($this._list);
  2986.  
  2987. updating = false;
  2988. };
  2989. }
  2990.  
  2991.  
  2992. Object.defineProperties(URLSearchParams.prototype, {
  2993. append: {
  2994. value: function (name, value) {
  2995. this._list.push({ name: name, value: value });
  2996. this._update_steps();
  2997. }, writable: true, enumerable: true, configurable: true
  2998. },
  2999.  
  3000. 'delete': {
  3001. value: function (name) {
  3002. for (var i = 0; i < this._list.length;) {
  3003. if (this._list[i].name === name)
  3004. this._list.splice(i, 1);
  3005. else
  3006. ++i;
  3007. }
  3008. this._update_steps();
  3009. }, writable: true, enumerable: true, configurable: true
  3010. },
  3011.  
  3012. get: {
  3013. value: function (name) {
  3014. for (var i = 0; i < this._list.length; ++i) {
  3015. if (this._list[i].name === name)
  3016. return this._list[i].value;
  3017. }
  3018. return null;
  3019. }, writable: true, enumerable: true, configurable: true
  3020. },
  3021.  
  3022. getAll: {
  3023. value: function (name) {
  3024. var result = [];
  3025. for (var i = 0; i < this._list.length; ++i) {
  3026. if (this._list[i].name === name)
  3027. result.push(this._list[i].value);
  3028. }
  3029. return result;
  3030. }, writable: true, enumerable: true, configurable: true
  3031. },
  3032.  
  3033. has: {
  3034. value: function (name) {
  3035. for (var i = 0; i < this._list.length; ++i) {
  3036. if (this._list[i].name === name)
  3037. return true;
  3038. }
  3039. return false;
  3040. }, writable: true, enumerable: true, configurable: true
  3041. },
  3042.  
  3043. set: {
  3044. value: function (name, value) {
  3045. var found = false;
  3046. for (var i = 0; i < this._list.length;) {
  3047. if (this._list[i].name === name) {
  3048. if (!found) {
  3049. this._list[i].value = value;
  3050. found = true;
  3051. ++i;
  3052. } else {
  3053. this._list.splice(i, 1);
  3054. }
  3055. } else {
  3056. ++i;
  3057. }
  3058. }
  3059.  
  3060. if (!found)
  3061. this._list.push({ name: name, value: value });
  3062.  
  3063. this._update_steps();
  3064. }, writable: true, enumerable: true, configurable: true
  3065. },
  3066.  
  3067. entries: {
  3068. value: function() { return new Iterator(this._list, 'key+value'); },
  3069. writable: true, enumerable: true, configurable: true
  3070. },
  3071.  
  3072. keys: {
  3073. value: function() { return new Iterator(this._list, 'key'); },
  3074. writable: true, enumerable: true, configurable: true
  3075. },
  3076.  
  3077. values: {
  3078. value: function() { return new Iterator(this._list, 'value'); },
  3079. writable: true, enumerable: true, configurable: true
  3080. },
  3081.  
  3082. forEach: {
  3083. value: function(callback) {
  3084. var thisArg = (arguments.length > 1) ? arguments[1] : undefined;
  3085. this._list.forEach(function(pair, index) {
  3086. callback.call(thisArg, pair.value, pair.name);
  3087. });
  3088.  
  3089. }, writable: true, enumerable: true, configurable: true
  3090. },
  3091.  
  3092. toString: {
  3093. value: function () {
  3094. return urlencoded_serialize(this._list);
  3095. }, writable: true, enumerable: false, configurable: true
  3096. }
  3097. });
  3098.  
  3099. function Iterator(source, kind) {
  3100. var index = 0;
  3101. this['next'] = function() {
  3102. if (index >= source.length)
  3103. return {done: true, value: undefined};
  3104. var pair = source[index++];
  3105. return {done: false, value:
  3106. kind === 'key' ? pair.name :
  3107. kind === 'value' ? pair.value :
  3108. [pair.name, pair.value]};
  3109. };
  3110. }
  3111.  
  3112. if ('Symbol' in global && 'iterator' in global.Symbol) {
  3113. Object.defineProperty(URLSearchParams.prototype, global.Symbol.iterator, {
  3114. value: URLSearchParams.prototype.entries,
  3115. writable: true, enumerable: true, configurable: true});
  3116. Object.defineProperty(Iterator.prototype, global.Symbol.iterator, {
  3117. value: function() { return this; },
  3118. writable: true, enumerable: true, configurable: true});
  3119. }
  3120.  
  3121. function URL(url, base) {
  3122. if (!(this instanceof global.URL))
  3123. throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");
  3124.  
  3125. if (base) {
  3126. url = (function () {
  3127. if (nativeURL) return new origURL(url, base).href;
  3128. var iframe;
  3129. try {
  3130. var doc;
  3131. // Use another document/base tag/anchor for relative URL resolution, if possible
  3132. if (Object.prototype.toString.call(window.operamini) === "[object OperaMini]") {
  3133. iframe = document.createElement('iframe');
  3134. iframe.style.display = 'none';
  3135. document.documentElement.appendChild(iframe);
  3136. doc = iframe.contentWindow.document;
  3137. } else if (document.implementation && document.implementation.createHTMLDocument) {
  3138. doc = document.implementation.createHTMLDocument('');
  3139. } else if (document.implementation && document.implementation.createDocument) {
  3140. doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
  3141. doc.documentElement.appendChild(doc.createElement('head'));
  3142. doc.documentElement.appendChild(doc.createElement('body'));
  3143. } else if (window.ActiveXObject) {
  3144. doc = new window.ActiveXObject('htmlfile');
  3145. doc.write('<head><\/head><body><\/body>');
  3146. doc.close();
  3147. }
  3148.  
  3149. if (!doc) throw Error('base not supported');
  3150.  
  3151. var baseTag = doc.createElement('base');
  3152. baseTag.href = base;
  3153. doc.getElementsByTagName('head')[0].appendChild(baseTag);
  3154. var anchor = doc.createElement('a');
  3155. anchor.href = url;
  3156. return anchor.href;
  3157. } finally {
  3158. if (iframe)
  3159. iframe.parentNode.removeChild(iframe);
  3160. }
  3161. }());
  3162. }
  3163.  
  3164. // An inner object implementing URLUtils (either a native URL
  3165. // object or an HTMLAnchorElement instance) is used to perform the
  3166. // URL algorithms. With full ES5 getter/setter support, return a
  3167. // regular object For IE8's limited getter/setter support, a
  3168. // different HTMLAnchorElement is returned with properties
  3169. // overridden
  3170.  
  3171. var instance = URLUtils(url || '');
  3172.  
  3173. // Detect for ES5 getter/setter support
  3174. // (an Object.defineProperties polyfill that doesn't support getters/setters may throw)
  3175. var ES5_GET_SET = (function() {
  3176. if (!('defineProperties' in Object)) return false;
  3177. try {
  3178. var obj = {};
  3179. Object.defineProperties(obj, { prop: { 'get': function () { return true; } } });
  3180. return obj.prop;
  3181. } catch (_) {
  3182. return false;
  3183. }
  3184. })();
  3185.  
  3186. var self = ES5_GET_SET ? this : document.createElement('a');
  3187.  
  3188.  
  3189.  
  3190. var query_object = new URLSearchParams(
  3191. instance.search ? instance.search.substring(1) : null);
  3192. query_object._url_object = self;
  3193.  
  3194. Object.defineProperties(self, {
  3195. href: {
  3196. get: function () { return instance.href; },
  3197. set: function (v) { instance.href = v; tidy_instance(); update_steps(); },
  3198. enumerable: true, configurable: true
  3199. },
  3200. origin: {
  3201. get: function () {
  3202. if ('origin' in instance) return instance.origin;
  3203. return this.protocol + '//' + this.host;
  3204. },
  3205. enumerable: true, configurable: true
  3206. },
  3207. protocol: {
  3208. get: function () { return instance.protocol; },
  3209. set: function (v) { instance.protocol = v; },
  3210. enumerable: true, configurable: true
  3211. },
  3212. username: {
  3213. get: function () { return instance.username; },
  3214. set: function (v) { instance.username = v; },
  3215. enumerable: true, configurable: true
  3216. },
  3217. password: {
  3218. get: function () { return instance.password; },
  3219. set: function (v) { instance.password = v; },
  3220. enumerable: true, configurable: true
  3221. },
  3222. host: {
  3223. get: function () {
  3224. // IE returns default port in |host|
  3225. var re = {'http:': /:80$/, 'https:': /:443$/, 'ftp:': /:21$/}[instance.protocol];
  3226. return re ? instance.host.replace(re, '') : instance.host;
  3227. },
  3228. set: function (v) { instance.host = v; },
  3229. enumerable: true, configurable: true
  3230. },
  3231. hostname: {
  3232. get: function () { return instance.hostname; },
  3233. set: function (v) { instance.hostname = v; },
  3234. enumerable: true, configurable: true
  3235. },
  3236. port: {
  3237. get: function () { return instance.port; },
  3238. set: function (v) { instance.port = v; },
  3239. enumerable: true, configurable: true
  3240. },
  3241. pathname: {
  3242. get: function () {
  3243. // IE does not include leading '/' in |pathname|
  3244. if (instance.pathname.charAt(0) !== '/') return '/' + instance.pathname;
  3245. return instance.pathname;
  3246. },
  3247. set: function (v) { instance.pathname = v; },
  3248. enumerable: true, configurable: true
  3249. },
  3250. search: {
  3251. get: function () { return instance.search; },
  3252. set: function (v) {
  3253. if (instance.search === v) return;
  3254. instance.search = v; tidy_instance(); update_steps();
  3255. },
  3256. enumerable: true, configurable: true
  3257. },
  3258. searchParams: {
  3259. get: function () { return query_object; },
  3260. enumerable: true, configurable: true
  3261. },
  3262. hash: {
  3263. get: function () { return instance.hash; },
  3264. set: function (v) { instance.hash = v; tidy_instance(); },
  3265. enumerable: true, configurable: true
  3266. },
  3267. toString: {
  3268. value: function() { return instance.toString(); },
  3269. enumerable: false, configurable: true
  3270. },
  3271. valueOf: {
  3272. value: function() { return instance.valueOf(); },
  3273. enumerable: false, configurable: true
  3274. }
  3275. });
  3276.  
  3277. function tidy_instance() {
  3278. var href = instance.href.replace(/#$|\?$|\?(?=#)/g, '');
  3279. if (instance.href !== href)
  3280. instance.href = href;
  3281. }
  3282.  
  3283. function update_steps() {
  3284. query_object._setList(instance.search ? urlencoded_parse(instance.search.substring(1)) : []);
  3285. query_object._update_steps();
  3286. };
  3287.  
  3288. return self;
  3289. }
  3290.  
  3291. if (origURL) {
  3292. for (var i in origURL) {
  3293. if (origURL.hasOwnProperty(i) && typeof origURL[i] === 'function')
  3294. URL[i] = origURL[i];
  3295. }
  3296. }
  3297.  
  3298. global.URL = URL;
  3299. global.URLSearchParams = URLSearchParams;
  3300. }());
  3301.  
  3302. // Patch native URLSearchParams constructor to handle sequences/records
  3303. // if necessary.
  3304. (function() {
  3305. if (new global.URLSearchParams([['a', 1]]).get('a') === '1' &&
  3306. new global.URLSearchParams({a: 1}).get('a') === '1')
  3307. return;
  3308. var orig = global.URLSearchParams;
  3309. global.URLSearchParams = function(init) {
  3310. if (init && typeof init === 'object' && isSequence(init)) {
  3311. var o = new orig();
  3312. toArray(init).forEach(function(e) {
  3313. if (!isSequence(e)) throw TypeError();
  3314. var nv = toArray(e);
  3315. if (nv.length !== 2) throw TypeError();
  3316. o.append(nv[0], nv[1]);
  3317. });
  3318. return o;
  3319. } else if (init && typeof init === 'object') {
  3320. o = new orig();
  3321. Object.keys(init).forEach(function(key) {
  3322. o.set(key, init[key]);
  3323. });
  3324. return o;
  3325. } else {
  3326. return new orig(init);
  3327. }
  3328. };
  3329. }());
  3330.  
  3331. }(self));
  3332. })
  3333. .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
Add Comment
Please, Sign In to add comment