es6-shim.js 136 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895
  1. /*!
  2. * https://github.com/paulmillr/es6-shim
  3. * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
  4. * and contributors, MIT License
  5. * es6-shim: v0.35.4
  6. * see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE
  7. * Details and documentation:
  8. * https://github.com/paulmillr/es6-shim/
  9. */
  10. // UMD (Universal Module Definition)
  11. // see https://github.com/umdjs/umd/blob/master/returnExports.js
  12. (function (root, factory) {
  13. /*global define */
  14. if (typeof define === 'function' && define.amd) {
  15. // AMD. Register as an anonymous module.
  16. define(factory);
  17. } else if (typeof exports === 'object') {
  18. // Node. Does not work with strict CommonJS, but
  19. // only CommonJS-like environments that support module.exports,
  20. // like Node.
  21. module.exports = factory();
  22. } else {
  23. // Browser globals (root is window)
  24. root.returnExports = factory();
  25. }
  26. }(this, function () {
  27. 'use strict';
  28. var _apply = Function.call.bind(Function.apply);
  29. var _call = Function.call.bind(Function.call);
  30. var isArray = Array.isArray;
  31. var keys = Object.keys;
  32. var not = function notThunker(func) {
  33. return function notThunk() {
  34. return !_apply(func, this, arguments);
  35. };
  36. };
  37. var throwsError = function (func) {
  38. try {
  39. func();
  40. return false;
  41. } catch (e) {
  42. return true;
  43. }
  44. };
  45. var valueOrFalseIfThrows = function valueOrFalseIfThrows(func) {
  46. try {
  47. return func();
  48. } catch (e) {
  49. return false;
  50. }
  51. };
  52. var isCallableWithoutNew = not(throwsError);
  53. var arePropertyDescriptorsSupported = function () {
  54. // if Object.defineProperty exists but throws, it's IE 8
  55. return !throwsError(function () {
  56. return Object.defineProperty({}, 'x', { get: function () { } }); // eslint-disable-line getter-return
  57. });
  58. };
  59. var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
  60. var functionsHaveNames = (function foo() {}).name === 'foo';
  61. var _forEach = Function.call.bind(Array.prototype.forEach);
  62. var _reduce = Function.call.bind(Array.prototype.reduce);
  63. var _filter = Function.call.bind(Array.prototype.filter);
  64. var _some = Function.call.bind(Array.prototype.some);
  65. var defineProperty = function (object, name, value, force) {
  66. if (!force && name in object) { return; }
  67. if (supportsDescriptors) {
  68. Object.defineProperty(object, name, {
  69. configurable: true,
  70. enumerable: false,
  71. writable: true,
  72. value: value
  73. });
  74. } else {
  75. object[name] = value;
  76. }
  77. };
  78. // Define configurable, writable and non-enumerable props
  79. // if they don’t exist.
  80. var defineProperties = function (object, map, forceOverride) {
  81. _forEach(keys(map), function (name) {
  82. var method = map[name];
  83. defineProperty(object, name, method, !!forceOverride);
  84. });
  85. };
  86. var _toString = Function.call.bind(Object.prototype.toString);
  87. var isCallable = typeof /abc/ === 'function' ? function IsCallableSlow(x) {
  88. // Some old browsers (IE, FF) say that typeof /abc/ === 'function'
  89. return typeof x === 'function' && _toString(x) === '[object Function]';
  90. } : function IsCallableFast(x) { return typeof x === 'function'; };
  91. var Value = {
  92. getter: function (object, name, getter) {
  93. if (!supportsDescriptors) {
  94. throw new TypeError('getters require true ES5 support');
  95. }
  96. Object.defineProperty(object, name, {
  97. configurable: true,
  98. enumerable: false,
  99. get: getter
  100. });
  101. },
  102. proxy: function (originalObject, key, targetObject) {
  103. if (!supportsDescriptors) {
  104. throw new TypeError('getters require true ES5 support');
  105. }
  106. var originalDescriptor = Object.getOwnPropertyDescriptor(originalObject, key);
  107. Object.defineProperty(targetObject, key, {
  108. configurable: originalDescriptor.configurable,
  109. enumerable: originalDescriptor.enumerable,
  110. get: function getKey() { return originalObject[key]; },
  111. set: function setKey(value) { originalObject[key] = value; }
  112. });
  113. },
  114. redefine: function (object, property, newValue) {
  115. if (supportsDescriptors) {
  116. var descriptor = Object.getOwnPropertyDescriptor(object, property);
  117. descriptor.value = newValue;
  118. Object.defineProperty(object, property, descriptor);
  119. } else {
  120. object[property] = newValue;
  121. }
  122. },
  123. defineByDescriptor: function (object, property, descriptor) {
  124. if (supportsDescriptors) {
  125. Object.defineProperty(object, property, descriptor);
  126. } else if ('value' in descriptor) {
  127. object[property] = descriptor.value;
  128. }
  129. },
  130. preserveToString: function (target, source) {
  131. if (source && isCallable(source.toString)) {
  132. defineProperty(target, 'toString', source.toString.bind(source), true);
  133. }
  134. }
  135. };
  136. // Simple shim for Object.create on ES3 browsers
  137. // (unlike real shim, no attempt to support `prototype === null`)
  138. var create = Object.create || function (prototype, properties) {
  139. var Prototype = function Prototype() {};
  140. Prototype.prototype = prototype;
  141. var object = new Prototype();
  142. if (typeof properties !== 'undefined') {
  143. keys(properties).forEach(function (key) {
  144. Value.defineByDescriptor(object, key, properties[key]);
  145. });
  146. }
  147. return object;
  148. };
  149. var supportsSubclassing = function (C, f) {
  150. if (!Object.setPrototypeOf) { return false; /* skip test on IE < 11 */ }
  151. return valueOrFalseIfThrows(function () {
  152. var Sub = function Subclass(arg) {
  153. var o = new C(arg);
  154. Object.setPrototypeOf(o, Subclass.prototype);
  155. return o;
  156. };
  157. Object.setPrototypeOf(Sub, C);
  158. Sub.prototype = create(C.prototype, {
  159. constructor: { value: Sub }
  160. });
  161. return f(Sub);
  162. });
  163. };
  164. var getGlobal = function () {
  165. /* global self, window */
  166. // the only reliable means to get the global object is
  167. // `Function('return this')()`
  168. // However, this causes CSP violations in Chrome apps.
  169. if (typeof self !== 'undefined') { return self; }
  170. if (typeof window !== 'undefined') { return window; }
  171. if (typeof global !== 'undefined') { return global; }
  172. throw new Error('unable to locate global object');
  173. };
  174. var globals = getGlobal();
  175. var globalIsFinite = globals.isFinite;
  176. var _indexOf = Function.call.bind(String.prototype.indexOf);
  177. var _arrayIndexOfApply = Function.apply.bind(Array.prototype.indexOf);
  178. var _concat = Function.call.bind(Array.prototype.concat);
  179. // var _sort = Function.call.bind(Array.prototype.sort);
  180. var _strSlice = Function.call.bind(String.prototype.slice);
  181. var _push = Function.call.bind(Array.prototype.push);
  182. var _pushApply = Function.apply.bind(Array.prototype.push);
  183. var _join = Function.call.bind(Array.prototype.join);
  184. var _shift = Function.call.bind(Array.prototype.shift);
  185. var _max = Math.max;
  186. var _min = Math.min;
  187. var _floor = Math.floor;
  188. var _abs = Math.abs;
  189. var _exp = Math.exp;
  190. var _log = Math.log;
  191. var _sqrt = Math.sqrt;
  192. var _hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
  193. var ArrayIterator; // make our implementation private
  194. var noop = function () {};
  195. var OrigMap = globals.Map;
  196. var origMapDelete = OrigMap && OrigMap.prototype['delete'];
  197. var origMapGet = OrigMap && OrigMap.prototype.get;
  198. var origMapHas = OrigMap && OrigMap.prototype.has;
  199. var origMapSet = OrigMap && OrigMap.prototype.set;
  200. var Symbol = globals.Symbol || {};
  201. var symbolSpecies = Symbol.species || '@@species';
  202. var numberIsNaN = Number.isNaN || function isNaN(value) {
  203. // NaN !== NaN, but they are identical.
  204. // NaNs are the only non-reflexive value, i.e., if x !== x,
  205. // then x is NaN.
  206. // isNaN is broken: it converts its argument to number, so
  207. // isNaN('foo') => true
  208. return value !== value;
  209. };
  210. var numberIsFinite = Number.isFinite || function isFinite(value) {
  211. return typeof value === 'number' && globalIsFinite(value);
  212. };
  213. var _sign = isCallable(Math.sign) ? Math.sign : function sign(value) {
  214. var number = Number(value);
  215. if (number === 0) { return number; }
  216. if (numberIsNaN(number)) { return number; }
  217. return number < 0 ? -1 : 1;
  218. };
  219. var _log1p = function log1p(value) {
  220. var x = Number(value);
  221. if (x < -1 || numberIsNaN(x)) { return NaN; }
  222. if (x === 0 || x === Infinity) { return x; }
  223. if (x === -1) { return -Infinity; }
  224. return (1 + x) - 1 === 0 ? x : x * (_log(1 + x) / ((1 + x) - 1));
  225. };
  226. // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
  227. // can be replaced with require('is-arguments') if we ever use a build process instead
  228. var isStandardArguments = function isArguments(value) {
  229. return _toString(value) === '[object Arguments]';
  230. };
  231. var isLegacyArguments = function isArguments(value) {
  232. return value !== null
  233. && typeof value === 'object'
  234. && typeof value.length === 'number'
  235. && value.length >= 0
  236. && _toString(value) !== '[object Array]'
  237. && _toString(value.callee) === '[object Function]';
  238. };
  239. var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
  240. var Type = {
  241. primitive: function (x) { return x === null || (typeof x !== 'function' && typeof x !== 'object'); },
  242. string: function (x) { return _toString(x) === '[object String]'; },
  243. regex: function (x) { return _toString(x) === '[object RegExp]'; },
  244. symbol: function (x) {
  245. return typeof globals.Symbol === 'function' && typeof x === 'symbol';
  246. }
  247. };
  248. var overrideNative = function overrideNative(object, property, replacement) {
  249. var original = object[property];
  250. defineProperty(object, property, replacement, true);
  251. Value.preserveToString(object[property], original);
  252. };
  253. // eslint-disable-next-line no-restricted-properties
  254. var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && Type.symbol(Symbol());
  255. // This is a private name in the es6 spec, equal to '[Symbol.iterator]'
  256. // we're going to use an arbitrary _-prefixed name to make our shims
  257. // work properly with each other, even though we don't have full Iterator
  258. // support. That is, `Array.from(map.keys())` will work, but we don't
  259. // pretend to export a "real" Iterator interface.
  260. var $iterator$ = Type.symbol(Symbol.iterator) ? Symbol.iterator : '_es6-shim iterator_';
  261. // Firefox ships a partial implementation using the name @@iterator.
  262. // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
  263. // So use that name if we detect it.
  264. if (globals.Set && typeof new globals.Set()['@@iterator'] === 'function') {
  265. $iterator$ = '@@iterator';
  266. }
  267. // Reflect
  268. if (!globals.Reflect) {
  269. defineProperty(globals, 'Reflect', {}, true);
  270. }
  271. var Reflect = globals.Reflect;
  272. var $String = String;
  273. /* global document */
  274. var domAll = (typeof document === 'undefined' || !document) ? null : document.all;
  275. var isNullOrUndefined = domAll == null ? function isNullOrUndefined(x) {
  276. return x == null;
  277. } : function isNullOrUndefinedAndNotDocumentAll(x) {
  278. return x == null && x !== domAll;
  279. };
  280. var ES = {
  281. // http://www.ecma-international.org/ecma-262/6.0/#sec-call
  282. Call: function Call(F, V) {
  283. var args = arguments.length > 2 ? arguments[2] : [];
  284. if (!ES.IsCallable(F)) {
  285. throw new TypeError(F + ' is not a function');
  286. }
  287. return _apply(F, V, args);
  288. },
  289. RequireObjectCoercible: function (x, optMessage) {
  290. if (isNullOrUndefined(x)) {
  291. throw new TypeError(optMessage || 'Cannot call method on ' + x);
  292. }
  293. return x;
  294. },
  295. // This might miss the "(non-standard exotic and does not implement
  296. // [[Call]])" case from
  297. // http://www.ecma-international.org/ecma-262/6.0/#sec-typeof-operator-runtime-semantics-evaluation
  298. // but we can't find any evidence these objects exist in practice.
  299. // If we find some in the future, you could test `Object(x) === x`,
  300. // which is reliable according to
  301. // http://www.ecma-international.org/ecma-262/6.0/#sec-toobject
  302. // but is not well optimized by runtimes and creates an object
  303. // whenever it returns false, and thus is very slow.
  304. TypeIsObject: function (x) {
  305. if (x === void 0 || x === null || x === true || x === false) {
  306. return false;
  307. }
  308. return typeof x === 'function' || typeof x === 'object' || x === domAll;
  309. },
  310. ToObject: function (o, optMessage) {
  311. return Object(ES.RequireObjectCoercible(o, optMessage));
  312. },
  313. IsCallable: isCallable,
  314. IsConstructor: function (x) {
  315. // We can't tell callables from constructors in ES5
  316. return ES.IsCallable(x);
  317. },
  318. ToInt32: function (x) {
  319. return ES.ToNumber(x) >> 0;
  320. },
  321. ToUint32: function (x) {
  322. return ES.ToNumber(x) >>> 0;
  323. },
  324. ToNumber: function (value) {
  325. if (hasSymbols && _toString(value) === '[object Symbol]') {
  326. throw new TypeError('Cannot convert a Symbol value to a number');
  327. }
  328. return +value;
  329. },
  330. ToInteger: function (value) {
  331. var number = ES.ToNumber(value);
  332. if (numberIsNaN(number)) { return 0; }
  333. if (number === 0 || !numberIsFinite(number)) { return number; }
  334. return (number > 0 ? 1 : -1) * _floor(_abs(number));
  335. },
  336. ToLength: function (value) {
  337. var len = ES.ToInteger(value);
  338. if (len <= 0) { return 0; } // includes converting -0 to +0
  339. if (len > Number.MAX_SAFE_INTEGER) { return Number.MAX_SAFE_INTEGER; }
  340. return len;
  341. },
  342. SameValue: function (a, b) {
  343. if (a === b) {
  344. // 0 === -0, but they are not identical.
  345. if (a === 0) { return 1 / a === 1 / b; }
  346. return true;
  347. }
  348. return numberIsNaN(a) && numberIsNaN(b);
  349. },
  350. SameValueZero: function (a, b) {
  351. // same as SameValue except for SameValueZero(+0, -0) == true
  352. return (a === b) || (numberIsNaN(a) && numberIsNaN(b));
  353. },
  354. GetIterator: function (o) {
  355. if (isArguments(o)) {
  356. // special case support for `arguments`
  357. return new ArrayIterator(o, 'value');
  358. }
  359. var itFn = ES.GetMethod(o, $iterator$);
  360. if (!ES.IsCallable(itFn)) {
  361. // Better diagnostics if itFn is null or undefined
  362. throw new TypeError('value is not an iterable');
  363. }
  364. var it = ES.Call(itFn, o);
  365. if (!ES.TypeIsObject(it)) {
  366. throw new TypeError('bad iterator');
  367. }
  368. return it;
  369. },
  370. GetMethod: function (o, p) {
  371. var func = ES.ToObject(o)[p];
  372. if (isNullOrUndefined(func)) {
  373. return void 0;
  374. }
  375. if (!ES.IsCallable(func)) {
  376. throw new TypeError('Method not callable: ' + p);
  377. }
  378. return func;
  379. },
  380. IteratorComplete: function (iterResult) {
  381. return !!iterResult.done;
  382. },
  383. IteratorClose: function (iterator, completionIsThrow) {
  384. var returnMethod = ES.GetMethod(iterator, 'return');
  385. if (returnMethod === void 0) {
  386. return;
  387. }
  388. var innerResult, innerException;
  389. try {
  390. innerResult = ES.Call(returnMethod, iterator);
  391. } catch (e) {
  392. innerException = e;
  393. }
  394. if (completionIsThrow) {
  395. return;
  396. }
  397. if (innerException) {
  398. throw innerException;
  399. }
  400. if (!ES.TypeIsObject(innerResult)) {
  401. throw new TypeError("Iterator's return method returned a non-object.");
  402. }
  403. },
  404. IteratorNext: function (it) {
  405. var result = arguments.length > 1 ? it.next(arguments[1]) : it.next();
  406. if (!ES.TypeIsObject(result)) {
  407. throw new TypeError('bad iterator');
  408. }
  409. return result;
  410. },
  411. IteratorStep: function (it) {
  412. var result = ES.IteratorNext(it);
  413. var done = ES.IteratorComplete(result);
  414. return done ? false : result;
  415. },
  416. Construct: function (C, args, newTarget, isES6internal) {
  417. var target = typeof newTarget === 'undefined' ? C : newTarget;
  418. if (!isES6internal && Reflect.construct) {
  419. // Try to use Reflect.construct if available
  420. return Reflect.construct(C, args, target);
  421. }
  422. // OK, we have to fake it. This will only work if the
  423. // C.[[ConstructorKind]] == "base" -- but that's the only
  424. // kind we can make in ES5 code anyway.
  425. // OrdinaryCreateFromConstructor(target, "%ObjectPrototype%")
  426. var proto = target.prototype;
  427. if (!ES.TypeIsObject(proto)) {
  428. proto = Object.prototype;
  429. }
  430. var obj = create(proto);
  431. // Call the constructor.
  432. var result = ES.Call(C, obj, args);
  433. return ES.TypeIsObject(result) ? result : obj;
  434. },
  435. SpeciesConstructor: function (O, defaultConstructor) {
  436. var C = O.constructor;
  437. if (C === void 0) {
  438. return defaultConstructor;
  439. }
  440. if (!ES.TypeIsObject(C)) {
  441. throw new TypeError('Bad constructor');
  442. }
  443. var S = C[symbolSpecies];
  444. if (isNullOrUndefined(S)) {
  445. return defaultConstructor;
  446. }
  447. if (!ES.IsConstructor(S)) {
  448. throw new TypeError('Bad @@species');
  449. }
  450. return S;
  451. },
  452. CreateHTML: function (string, tag, attribute, value) {
  453. var S = ES.ToString(string);
  454. var p1 = '<' + tag;
  455. if (attribute !== '') {
  456. var V = ES.ToString(value);
  457. var escapedV = V.replace(/"/g, '&quot;');
  458. p1 += ' ' + attribute + '="' + escapedV + '"';
  459. }
  460. var p2 = p1 + '>';
  461. var p3 = p2 + S;
  462. return p3 + '</' + tag + '>';
  463. },
  464. IsRegExp: function IsRegExp(argument) {
  465. if (!ES.TypeIsObject(argument)) {
  466. return false;
  467. }
  468. var isRegExp = argument[Symbol.match];
  469. if (typeof isRegExp !== 'undefined') {
  470. return !!isRegExp;
  471. }
  472. return Type.regex(argument);
  473. },
  474. ToString: function ToString(string) {
  475. if (hasSymbols && _toString(string) === '[object Symbol]') {
  476. throw new TypeError('Cannot convert a Symbol value to a number');
  477. }
  478. return $String(string);
  479. }
  480. };
  481. // Well-known Symbol shims
  482. if (supportsDescriptors && hasSymbols) {
  483. var defineWellKnownSymbol = function defineWellKnownSymbol(name) {
  484. if (Type.symbol(Symbol[name])) {
  485. return Symbol[name];
  486. }
  487. // eslint-disable-next-line no-restricted-properties
  488. var sym = Symbol['for']('Symbol.' + name);
  489. Object.defineProperty(Symbol, name, {
  490. configurable: false,
  491. enumerable: false,
  492. writable: false,
  493. value: sym
  494. });
  495. return sym;
  496. };
  497. if (!Type.symbol(Symbol.search)) {
  498. var symbolSearch = defineWellKnownSymbol('search');
  499. var originalSearch = String.prototype.search;
  500. defineProperty(RegExp.prototype, symbolSearch, function search(string) {
  501. return ES.Call(originalSearch, string, [this]);
  502. });
  503. var searchShim = function search(regexp) {
  504. var O = ES.RequireObjectCoercible(this);
  505. if (!isNullOrUndefined(regexp)) {
  506. var searcher = ES.GetMethod(regexp, symbolSearch);
  507. if (typeof searcher !== 'undefined') {
  508. return ES.Call(searcher, regexp, [O]);
  509. }
  510. }
  511. return ES.Call(originalSearch, O, [ES.ToString(regexp)]);
  512. };
  513. overrideNative(String.prototype, 'search', searchShim);
  514. }
  515. if (!Type.symbol(Symbol.replace)) {
  516. var symbolReplace = defineWellKnownSymbol('replace');
  517. var originalReplace = String.prototype.replace;
  518. defineProperty(RegExp.prototype, symbolReplace, function replace(string, replaceValue) {
  519. return ES.Call(originalReplace, string, [this, replaceValue]);
  520. });
  521. var replaceShim = function replace(searchValue, replaceValue) {
  522. var O = ES.RequireObjectCoercible(this);
  523. if (!isNullOrUndefined(searchValue)) {
  524. var replacer = ES.GetMethod(searchValue, symbolReplace);
  525. if (typeof replacer !== 'undefined') {
  526. return ES.Call(replacer, searchValue, [O, replaceValue]);
  527. }
  528. }
  529. return ES.Call(originalReplace, O, [ES.ToString(searchValue), replaceValue]);
  530. };
  531. overrideNative(String.prototype, 'replace', replaceShim);
  532. }
  533. if (!Type.symbol(Symbol.split)) {
  534. var symbolSplit = defineWellKnownSymbol('split');
  535. var originalSplit = String.prototype.split;
  536. defineProperty(RegExp.prototype, symbolSplit, function split(string, limit) {
  537. return ES.Call(originalSplit, string, [this, limit]);
  538. });
  539. var splitShim = function split(separator, limit) {
  540. var O = ES.RequireObjectCoercible(this);
  541. if (!isNullOrUndefined(separator)) {
  542. var splitter = ES.GetMethod(separator, symbolSplit);
  543. if (typeof splitter !== 'undefined') {
  544. return ES.Call(splitter, separator, [O, limit]);
  545. }
  546. }
  547. return ES.Call(originalSplit, O, [ES.ToString(separator), limit]);
  548. };
  549. overrideNative(String.prototype, 'split', splitShim);
  550. }
  551. var symbolMatchExists = Type.symbol(Symbol.match);
  552. var stringMatchIgnoresSymbolMatch = symbolMatchExists && (function () {
  553. // Firefox 41, through Nightly 45 has Symbol.match, but String#match ignores it.
  554. // Firefox 40 and below have Symbol.match but String#match works fine.
  555. var o = {};
  556. o[Symbol.match] = function () { return 42; };
  557. return 'a'.match(o) !== 42;
  558. }());
  559. if (!symbolMatchExists || stringMatchIgnoresSymbolMatch) {
  560. var symbolMatch = defineWellKnownSymbol('match');
  561. var originalMatch = String.prototype.match;
  562. defineProperty(RegExp.prototype, symbolMatch, function match(string) {
  563. return ES.Call(originalMatch, string, [this]);
  564. });
  565. var matchShim = function match(regexp) {
  566. var O = ES.RequireObjectCoercible(this);
  567. if (!isNullOrUndefined(regexp)) {
  568. var matcher = ES.GetMethod(regexp, symbolMatch);
  569. if (typeof matcher !== 'undefined') {
  570. return ES.Call(matcher, regexp, [O]);
  571. }
  572. }
  573. return ES.Call(originalMatch, O, [ES.ToString(regexp)]);
  574. };
  575. overrideNative(String.prototype, 'match', matchShim);
  576. }
  577. }
  578. var wrapConstructor = function wrapConstructor(original, replacement, keysToSkip) {
  579. Value.preserveToString(replacement, original);
  580. if (Object.setPrototypeOf) {
  581. // sets up proper prototype chain where possible
  582. Object.setPrototypeOf(original, replacement);
  583. }
  584. if (supportsDescriptors) {
  585. _forEach(Object.getOwnPropertyNames(original), function (key) {
  586. if (key in noop || keysToSkip[key]) { return; }
  587. Value.proxy(original, key, replacement);
  588. });
  589. } else {
  590. _forEach(Object.keys(original), function (key) {
  591. if (key in noop || keysToSkip[key]) { return; }
  592. replacement[key] = original[key];
  593. });
  594. }
  595. replacement.prototype = original.prototype;
  596. Value.redefine(original.prototype, 'constructor', replacement);
  597. };
  598. var defaultSpeciesGetter = function () { return this; };
  599. var addDefaultSpecies = function (C) {
  600. if (supportsDescriptors && !_hasOwnProperty(C, symbolSpecies)) {
  601. Value.getter(C, symbolSpecies, defaultSpeciesGetter);
  602. }
  603. };
  604. var addIterator = function (prototype, impl) {
  605. var implementation = impl || function iterator() { return this; };
  606. defineProperty(prototype, $iterator$, implementation);
  607. if (!prototype[$iterator$] && Type.symbol($iterator$)) {
  608. // implementations are buggy when $iterator$ is a Symbol
  609. prototype[$iterator$] = implementation;
  610. }
  611. };
  612. var createDataProperty = function createDataProperty(object, name, value) {
  613. if (supportsDescriptors) {
  614. Object.defineProperty(object, name, {
  615. configurable: true,
  616. enumerable: true,
  617. writable: true,
  618. value: value
  619. });
  620. } else {
  621. object[name] = value;
  622. }
  623. };
  624. var createDataPropertyOrThrow = function createDataPropertyOrThrow(object, name, value) {
  625. createDataProperty(object, name, value);
  626. if (!ES.SameValue(object[name], value)) {
  627. throw new TypeError('property is nonconfigurable');
  628. }
  629. };
  630. var emulateES6construct = function (o, defaultNewTarget, defaultProto, slots) {
  631. // This is an es5 approximation to es6 construct semantics. in es6,
  632. // 'new Foo' invokes Foo.[[Construct]] which (for almost all objects)
  633. // just sets the internal variable NewTarget (in es6 syntax `new.target`)
  634. // to Foo and then returns Foo().
  635. // Many ES6 object then have constructors of the form:
  636. // 1. If NewTarget is undefined, throw a TypeError exception
  637. // 2. Let xxx by OrdinaryCreateFromConstructor(NewTarget, yyy, zzz)
  638. // So we're going to emulate those first two steps.
  639. if (!ES.TypeIsObject(o)) {
  640. throw new TypeError('Constructor requires `new`: ' + defaultNewTarget.name);
  641. }
  642. var proto = defaultNewTarget.prototype;
  643. if (!ES.TypeIsObject(proto)) {
  644. proto = defaultProto;
  645. }
  646. var obj = create(proto);
  647. for (var name in slots) {
  648. if (_hasOwnProperty(slots, name)) {
  649. var value = slots[name];
  650. defineProperty(obj, name, value, true);
  651. }
  652. }
  653. return obj;
  654. };
  655. // Firefox 31 reports this function's length as 0
  656. // https://bugzilla.mozilla.org/show_bug.cgi?id=1062484
  657. if (String.fromCodePoint && String.fromCodePoint.length !== 1) {
  658. var originalFromCodePoint = String.fromCodePoint;
  659. overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) {
  660. return ES.Call(originalFromCodePoint, this, arguments);
  661. });
  662. }
  663. var StringShims = {
  664. fromCodePoint: function fromCodePoint(codePoints) {
  665. var result = [];
  666. var next;
  667. for (var i = 0, length = arguments.length; i < length; i++) {
  668. next = Number(arguments[i]);
  669. if (!ES.SameValue(next, ES.ToInteger(next)) || next < 0 || next > 0x10FFFF) {
  670. throw new RangeError('Invalid code point ' + next);
  671. }
  672. if (next < 0x10000) {
  673. _push(result, String.fromCharCode(next));
  674. } else {
  675. next -= 0x10000;
  676. _push(result, String.fromCharCode((next >> 10) + 0xD800));
  677. _push(result, String.fromCharCode((next % 0x400) + 0xDC00));
  678. }
  679. }
  680. return _join(result, '');
  681. },
  682. raw: function raw(template) {
  683. var numberOfSubstitutions = arguments.length - 1;
  684. var cooked = ES.ToObject(template, 'bad template');
  685. var raw = ES.ToObject(cooked.raw, 'bad raw value');
  686. var len = raw.length;
  687. var literalSegments = ES.ToLength(len);
  688. if (literalSegments <= 0) {
  689. return '';
  690. }
  691. var stringElements = [];
  692. var nextIndex = 0;
  693. var nextKey, next, nextSeg, nextSub;
  694. while (nextIndex < literalSegments) {
  695. nextKey = ES.ToString(nextIndex);
  696. nextSeg = ES.ToString(raw[nextKey]);
  697. _push(stringElements, nextSeg);
  698. if (nextIndex + 1 >= literalSegments) {
  699. break;
  700. }
  701. next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : '';
  702. nextSub = ES.ToString(next);
  703. _push(stringElements, nextSub);
  704. nextIndex += 1;
  705. }
  706. return _join(stringElements, '');
  707. }
  708. };
  709. if (String.raw && String.raw({ raw: { 0: 'x', 1: 'y', length: 2 } }) !== 'xy') {
  710. // IE 11 TP has a broken String.raw implementation
  711. overrideNative(String, 'raw', StringShims.raw);
  712. }
  713. defineProperties(String, StringShims);
  714. // Fast repeat, uses the `Exponentiation by squaring` algorithm.
  715. // Perf: http://jsperf.com/string-repeat2/2
  716. var stringRepeat = function repeat(s, times) {
  717. if (times < 1) { return ''; }
  718. if (times % 2) { return repeat(s, times - 1) + s; }
  719. var half = repeat(s, times / 2);
  720. return half + half;
  721. };
  722. var stringMaxLength = Infinity;
  723. var StringPrototypeShims = {
  724. repeat: function repeat(times) {
  725. var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
  726. var numTimes = ES.ToInteger(times);
  727. if (numTimes < 0 || numTimes >= stringMaxLength) {
  728. throw new RangeError('repeat count must be less than infinity and not overflow maximum string size');
  729. }
  730. return stringRepeat(thisStr, numTimes);
  731. },
  732. startsWith: function startsWith(searchString) {
  733. var S = ES.ToString(ES.RequireObjectCoercible(this));
  734. if (ES.IsRegExp(searchString)) {
  735. throw new TypeError('Cannot call method "startsWith" with a regex');
  736. }
  737. var searchStr = ES.ToString(searchString);
  738. var position;
  739. if (arguments.length > 1) {
  740. position = arguments[1];
  741. }
  742. var start = _max(ES.ToInteger(position), 0);
  743. return _strSlice(S, start, start + searchStr.length) === searchStr;
  744. },
  745. endsWith: function endsWith(searchString) {
  746. var S = ES.ToString(ES.RequireObjectCoercible(this));
  747. if (ES.IsRegExp(searchString)) {
  748. throw new TypeError('Cannot call method "endsWith" with a regex');
  749. }
  750. var searchStr = ES.ToString(searchString);
  751. var len = S.length;
  752. var endPosition;
  753. if (arguments.length > 1) {
  754. endPosition = arguments[1];
  755. }
  756. var pos = typeof endPosition === 'undefined' ? len : ES.ToInteger(endPosition);
  757. var end = _min(_max(pos, 0), len);
  758. return _strSlice(S, end - searchStr.length, end) === searchStr;
  759. },
  760. includes: function includes(searchString) {
  761. if (ES.IsRegExp(searchString)) {
  762. throw new TypeError('"includes" does not accept a RegExp');
  763. }
  764. var searchStr = ES.ToString(searchString);
  765. var position;
  766. if (arguments.length > 1) {
  767. position = arguments[1];
  768. }
  769. // Somehow this trick makes method 100% compat with the spec.
  770. return _indexOf(this, searchStr, position) !== -1;
  771. },
  772. codePointAt: function codePointAt(pos) {
  773. var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
  774. var position = ES.ToInteger(pos);
  775. var length = thisStr.length;
  776. if (position >= 0 && position < length) {
  777. var first = thisStr.charCodeAt(position);
  778. var isEnd = position + 1 === length;
  779. if (first < 0xD800 || first > 0xDBFF || isEnd) { return first; }
  780. var second = thisStr.charCodeAt(position + 1);
  781. if (second < 0xDC00 || second > 0xDFFF) { return first; }
  782. return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000;
  783. }
  784. }
  785. };
  786. if (String.prototype.includes && 'a'.includes('a', Infinity) !== false) {
  787. overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
  788. }
  789. if (String.prototype.startsWith && String.prototype.endsWith) {
  790. var startsWithRejectsRegex = throwsError(function () {
  791. /* throws if spec-compliant */
  792. return '/a/'.startsWith(/a/);
  793. });
  794. var startsWithHandlesInfinity = valueOrFalseIfThrows(function () {
  795. return 'abc'.startsWith('a', Infinity) === false;
  796. });
  797. if (!startsWithRejectsRegex || !startsWithHandlesInfinity) {
  798. // Firefox (< 37?) and IE 11 TP have a noncompliant startsWith implementation
  799. overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
  800. overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
  801. }
  802. }
  803. if (hasSymbols) {
  804. var startsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
  805. var re = /a/;
  806. re[Symbol.match] = false;
  807. return '/a/'.startsWith(re);
  808. });
  809. if (!startsWithSupportsSymbolMatch) {
  810. overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
  811. }
  812. var endsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
  813. var re = /a/;
  814. re[Symbol.match] = false;
  815. return '/a/'.endsWith(re);
  816. });
  817. if (!endsWithSupportsSymbolMatch) {
  818. overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
  819. }
  820. var includesSupportsSymbolMatch = valueOrFalseIfThrows(function () {
  821. var re = /a/;
  822. re[Symbol.match] = false;
  823. return '/a/'.includes(re);
  824. });
  825. if (!includesSupportsSymbolMatch) {
  826. overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
  827. }
  828. }
  829. defineProperties(String.prototype, StringPrototypeShims);
  830. // whitespace from: http://es5.github.io/#x15.5.4.20
  831. // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324
  832. var ws = [
  833. '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
  834. '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
  835. '\u2029\uFEFF'
  836. ].join('');
  837. var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
  838. var trimShim = function trim() {
  839. return ES.ToString(ES.RequireObjectCoercible(this)).replace(trimRegexp, '');
  840. };
  841. var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
  842. var nonWSregex = new RegExp('[' + nonWS + ']', 'g');
  843. var isBadHexRegex = /^[-+]0x[0-9a-f]+$/i;
  844. var hasStringTrimBug = nonWS.trim().length !== nonWS.length;
  845. defineProperty(String.prototype, 'trim', trimShim, hasStringTrimBug);
  846. // Given an argument x, it will return an IteratorResult object,
  847. // with value set to x and done to false.
  848. // Given no arguments, it will return an iterator completion object.
  849. var iteratorResult = function (x) {
  850. return { value: x, done: arguments.length === 0 };
  851. };
  852. // see http://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype-@@iterator
  853. var StringIterator = function (s) {
  854. ES.RequireObjectCoercible(s);
  855. defineProperty(this, '_s', ES.ToString(s));
  856. defineProperty(this, '_i', 0);
  857. };
  858. StringIterator.prototype.next = function () {
  859. var s = this._s;
  860. var i = this._i;
  861. if (typeof s === 'undefined' || i >= s.length) {
  862. this._s = void 0;
  863. return iteratorResult();
  864. }
  865. var first = s.charCodeAt(i);
  866. var second, len;
  867. if (first < 0xD800 || first > 0xDBFF || (i + 1) === s.length) {
  868. len = 1;
  869. } else {
  870. second = s.charCodeAt(i + 1);
  871. len = (second < 0xDC00 || second > 0xDFFF) ? 1 : 2;
  872. }
  873. this._i = i + len;
  874. return iteratorResult(s.substr(i, len));
  875. };
  876. addIterator(StringIterator.prototype);
  877. addIterator(String.prototype, function () {
  878. return new StringIterator(this);
  879. });
  880. var ArrayShims = {
  881. from: function from(items) {
  882. var C = this;
  883. var mapFn;
  884. if (arguments.length > 1) {
  885. mapFn = arguments[1];
  886. }
  887. var mapping, T;
  888. if (typeof mapFn === 'undefined') {
  889. mapping = false;
  890. } else {
  891. if (!ES.IsCallable(mapFn)) {
  892. throw new TypeError('Array.from: when provided, the second argument must be a function');
  893. }
  894. if (arguments.length > 2) {
  895. T = arguments[2];
  896. }
  897. mapping = true;
  898. }
  899. // Note that that Arrays will use ArrayIterator:
  900. // https://bugs.ecmascript.org/show_bug.cgi?id=2416
  901. var usingIterator = typeof (isArguments(items) || ES.GetMethod(items, $iterator$)) !== 'undefined';
  902. var length, result, i;
  903. if (usingIterator) {
  904. result = ES.IsConstructor(C) ? Object(new C()) : [];
  905. var iterator = ES.GetIterator(items);
  906. var next, nextValue;
  907. i = 0;
  908. while (true) {
  909. next = ES.IteratorStep(iterator);
  910. if (next === false) {
  911. break;
  912. }
  913. nextValue = next.value;
  914. try {
  915. if (mapping) {
  916. nextValue = typeof T === 'undefined' ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i);
  917. }
  918. result[i] = nextValue;
  919. } catch (e) {
  920. ES.IteratorClose(iterator, true);
  921. throw e;
  922. }
  923. i += 1;
  924. }
  925. length = i;
  926. } else {
  927. var arrayLike = ES.ToObject(items);
  928. length = ES.ToLength(arrayLike.length);
  929. result = ES.IsConstructor(C) ? Object(new C(length)) : new Array(length);
  930. var value;
  931. for (i = 0; i < length; ++i) {
  932. value = arrayLike[i];
  933. if (mapping) {
  934. value = typeof T === 'undefined' ? mapFn(value, i) : _call(mapFn, T, value, i);
  935. }
  936. createDataPropertyOrThrow(result, i, value);
  937. }
  938. }
  939. result.length = length;
  940. return result;
  941. },
  942. of: function of() {
  943. var len = arguments.length;
  944. var C = this;
  945. var A = isArray(C) || !ES.IsCallable(C) ? new Array(len) : ES.Construct(C, [len]);
  946. for (var k = 0; k < len; ++k) {
  947. createDataPropertyOrThrow(A, k, arguments[k]);
  948. }
  949. A.length = len;
  950. return A;
  951. }
  952. };
  953. defineProperties(Array, ArrayShims);
  954. addDefaultSpecies(Array);
  955. // Our ArrayIterator is private; see
  956. // https://github.com/paulmillr/es6-shim/issues/252
  957. ArrayIterator = function (array, kind) {
  958. defineProperty(this, 'i', 0);
  959. defineProperty(this, 'array', array);
  960. defineProperty(this, 'kind', kind);
  961. };
  962. defineProperties(ArrayIterator.prototype, {
  963. next: function () {
  964. var i = this.i;
  965. var array = this.array;
  966. if (!(this instanceof ArrayIterator)) {
  967. throw new TypeError('Not an ArrayIterator');
  968. }
  969. if (typeof array !== 'undefined') {
  970. var len = ES.ToLength(array.length);
  971. if (i < len) {
  972. //for (; i < len; i++) {
  973. var kind = this.kind;
  974. var retval;
  975. if (kind === 'key') {
  976. retval = i;
  977. } else if (kind === 'value') {
  978. retval = array[i];
  979. } else if (kind === 'entry') {
  980. retval = [i, array[i]];
  981. }
  982. this.i = i + 1;
  983. return iteratorResult(retval);
  984. }
  985. }
  986. this.array = void 0;
  987. return iteratorResult();
  988. }
  989. });
  990. addIterator(ArrayIterator.prototype);
  991. /*
  992. var orderKeys = function orderKeys(a, b) {
  993. var aNumeric = String(ES.ToInteger(a)) === a;
  994. var bNumeric = String(ES.ToInteger(b)) === b;
  995. if (aNumeric && bNumeric) {
  996. return b - a;
  997. } else if (aNumeric && !bNumeric) {
  998. return -1;
  999. } else if (!aNumeric && bNumeric) {
  1000. return 1;
  1001. } else {
  1002. return a.localeCompare(b);
  1003. }
  1004. };
  1005. var getAllKeys = function getAllKeys(object) {
  1006. var ownKeys = [];
  1007. var keys = [];
  1008. for (var key in object) {
  1009. _push(_hasOwnProperty(object, key) ? ownKeys : keys, key);
  1010. }
  1011. _sort(ownKeys, orderKeys);
  1012. _sort(keys, orderKeys);
  1013. return _concat(ownKeys, keys);
  1014. };
  1015. */
  1016. // note: this is positioned here because it depends on ArrayIterator
  1017. var arrayOfSupportsSubclassing = Array.of === ArrayShims.of || (function () {
  1018. // Detects a bug in Webkit nightly r181886
  1019. var Foo = function Foo(len) { this.length = len; };
  1020. Foo.prototype = [];
  1021. var fooArr = Array.of.apply(Foo, [1, 2]);
  1022. return fooArr instanceof Foo && fooArr.length === 2;
  1023. }());
  1024. if (!arrayOfSupportsSubclassing) {
  1025. overrideNative(Array, 'of', ArrayShims.of);
  1026. }
  1027. var ArrayPrototypeShims = {
  1028. copyWithin: function copyWithin(target, start) {
  1029. var o = ES.ToObject(this);
  1030. var len = ES.ToLength(o.length);
  1031. var relativeTarget = ES.ToInteger(target);
  1032. var relativeStart = ES.ToInteger(start);
  1033. var to = relativeTarget < 0 ? _max(len + relativeTarget, 0) : _min(relativeTarget, len);
  1034. var from = relativeStart < 0 ? _max(len + relativeStart, 0) : _min(relativeStart, len);
  1035. var end;
  1036. if (arguments.length > 2) {
  1037. end = arguments[2];
  1038. }
  1039. var relativeEnd = typeof end === 'undefined' ? len : ES.ToInteger(end);
  1040. var finalItem = relativeEnd < 0 ? _max(len + relativeEnd, 0) : _min(relativeEnd, len);
  1041. var count = _min(finalItem - from, len - to);
  1042. var direction = 1;
  1043. if (from < to && to < (from + count)) {
  1044. direction = -1;
  1045. from += count - 1;
  1046. to += count - 1;
  1047. }
  1048. while (count > 0) {
  1049. if (from in o) {
  1050. o[to] = o[from];
  1051. } else {
  1052. delete o[to];
  1053. }
  1054. from += direction;
  1055. to += direction;
  1056. count -= 1;
  1057. }
  1058. return o;
  1059. },
  1060. fill: function fill(value) {
  1061. var start;
  1062. if (arguments.length > 1) {
  1063. start = arguments[1];
  1064. }
  1065. var end;
  1066. if (arguments.length > 2) {
  1067. end = arguments[2];
  1068. }
  1069. var O = ES.ToObject(this);
  1070. var len = ES.ToLength(O.length);
  1071. start = ES.ToInteger(typeof start === 'undefined' ? 0 : start);
  1072. end = ES.ToInteger(typeof end === 'undefined' ? len : end);
  1073. var relativeStart = start < 0 ? _max(len + start, 0) : _min(start, len);
  1074. var relativeEnd = end < 0 ? len + end : end;
  1075. for (var i = relativeStart; i < len && i < relativeEnd; ++i) {
  1076. O[i] = value;
  1077. }
  1078. return O;
  1079. },
  1080. find: function find(predicate) {
  1081. var list = ES.ToObject(this);
  1082. var length = ES.ToLength(list.length);
  1083. if (!ES.IsCallable(predicate)) {
  1084. throw new TypeError('Array#find: predicate must be a function');
  1085. }
  1086. var thisArg = arguments.length > 1 ? arguments[1] : null;
  1087. for (var i = 0, value; i < length; i++) {
  1088. value = list[i];
  1089. if (thisArg) {
  1090. if (_call(predicate, thisArg, value, i, list)) {
  1091. return value;
  1092. }
  1093. } else if (predicate(value, i, list)) {
  1094. return value;
  1095. }
  1096. }
  1097. },
  1098. findIndex: function findIndex(predicate) {
  1099. var list = ES.ToObject(this);
  1100. var length = ES.ToLength(list.length);
  1101. if (!ES.IsCallable(predicate)) {
  1102. throw new TypeError('Array#findIndex: predicate must be a function');
  1103. }
  1104. var thisArg = arguments.length > 1 ? arguments[1] : null;
  1105. for (var i = 0; i < length; i++) {
  1106. if (thisArg) {
  1107. if (_call(predicate, thisArg, list[i], i, list)) {
  1108. return i;
  1109. }
  1110. } else if (predicate(list[i], i, list)) {
  1111. return i;
  1112. }
  1113. }
  1114. return -1;
  1115. },
  1116. keys: function keys() {
  1117. return new ArrayIterator(this, 'key');
  1118. },
  1119. values: function values() {
  1120. return new ArrayIterator(this, 'value');
  1121. },
  1122. entries: function entries() {
  1123. return new ArrayIterator(this, 'entry');
  1124. }
  1125. };
  1126. // Safari 7.1 defines Array#keys and Array#entries natively,
  1127. // but the resulting ArrayIterator objects don't have a "next" method.
  1128. if (Array.prototype.keys && !ES.IsCallable([1].keys().next)) {
  1129. delete Array.prototype.keys;
  1130. }
  1131. if (Array.prototype.entries && !ES.IsCallable([1].entries().next)) {
  1132. delete Array.prototype.entries;
  1133. }
  1134. // Chrome 38 defines Array#keys and Array#entries, and Array#@@iterator, but not Array#values
  1135. if (Array.prototype.keys && Array.prototype.entries && !Array.prototype.values && Array.prototype[$iterator$]) {
  1136. defineProperties(Array.prototype, {
  1137. values: Array.prototype[$iterator$]
  1138. });
  1139. if (Type.symbol(Symbol.unscopables)) {
  1140. Array.prototype[Symbol.unscopables].values = true;
  1141. }
  1142. }
  1143. // Chrome 40 defines Array#values with the incorrect name, although Array#{keys,entries} have the correct name
  1144. if (functionsHaveNames && Array.prototype.values && Array.prototype.values.name !== 'values') {
  1145. var originalArrayPrototypeValues = Array.prototype.values;
  1146. overrideNative(Array.prototype, 'values', function values() { return ES.Call(originalArrayPrototypeValues, this, arguments); });
  1147. defineProperty(Array.prototype, $iterator$, Array.prototype.values, true);
  1148. }
  1149. defineProperties(Array.prototype, ArrayPrototypeShims);
  1150. if (1 / [true].indexOf(true, -0) < 0) {
  1151. // indexOf when given a position arg of -0 should return +0.
  1152. // https://github.com/tc39/ecma262/pull/316
  1153. defineProperty(Array.prototype, 'indexOf', function indexOf(searchElement) {
  1154. var value = _arrayIndexOfApply(this, arguments);
  1155. if (value === 0 && (1 / value) < 0) {
  1156. return 0;
  1157. }
  1158. return value;
  1159. }, true);
  1160. }
  1161. addIterator(Array.prototype, function () { return this.values(); });
  1162. // Chrome defines keys/values/entries on Array, but doesn't give us
  1163. // any way to identify its iterator. So add our own shimmed field.
  1164. if (Object.getPrototypeOf) {
  1165. var ChromeArrayIterator = Object.getPrototypeOf([].values());
  1166. if (ChromeArrayIterator) { // in WSH, this is `undefined`
  1167. addIterator(ChromeArrayIterator);
  1168. }
  1169. }
  1170. // note: this is positioned here because it relies on Array#entries
  1171. var arrayFromSwallowsNegativeLengths = (function () {
  1172. // Detects a Firefox bug in v32
  1173. // https://bugzilla.mozilla.org/show_bug.cgi?id=1063993
  1174. return valueOrFalseIfThrows(function () {
  1175. return Array.from({ length: -1 }).length === 0;
  1176. });
  1177. }());
  1178. var arrayFromHandlesIterables = (function () {
  1179. // Detects a bug in Webkit nightly r181886
  1180. var arr = Array.from([0].entries());
  1181. return arr.length === 1 && isArray(arr[0]) && arr[0][0] === 0 && arr[0][1] === 0;
  1182. }());
  1183. if (!arrayFromSwallowsNegativeLengths || !arrayFromHandlesIterables) {
  1184. overrideNative(Array, 'from', ArrayShims.from);
  1185. }
  1186. var arrayFromHandlesUndefinedMapFunction = (function () {
  1187. // Microsoft Edge v0.11 throws if the mapFn argument is *provided* but undefined,
  1188. // but the spec doesn't care if it's provided or not - undefined doesn't throw.
  1189. return valueOrFalseIfThrows(function () {
  1190. return Array.from([0], void 0);
  1191. });
  1192. }());
  1193. if (!arrayFromHandlesUndefinedMapFunction) {
  1194. var origArrayFrom = Array.from;
  1195. overrideNative(Array, 'from', function from(items) {
  1196. if (arguments.length > 1 && typeof arguments[1] !== 'undefined') {
  1197. return ES.Call(origArrayFrom, this, arguments);
  1198. }
  1199. return _call(origArrayFrom, this, items);
  1200. });
  1201. }
  1202. var int32sAsOne = -(Math.pow(2, 32) - 1);
  1203. var toLengthsCorrectly = function (method, reversed) {
  1204. var obj = { length: int32sAsOne };
  1205. obj[reversed ? (obj.length >>> 0) - 1 : 0] = true;
  1206. return valueOrFalseIfThrows(function () {
  1207. _call(method, obj, function () {
  1208. // note: in nonconforming browsers, this will be called
  1209. // -1 >>> 0 times, which is 4294967295, so the throw matters.
  1210. throw new RangeError('should not reach here');
  1211. }, []);
  1212. return true;
  1213. });
  1214. };
  1215. if (!toLengthsCorrectly(Array.prototype.forEach)) {
  1216. var originalForEach = Array.prototype.forEach;
  1217. overrideNative(Array.prototype, 'forEach', function forEach(callbackFn) {
  1218. return ES.Call(originalForEach, this.length >= 0 ? this : [], arguments);
  1219. });
  1220. }
  1221. if (!toLengthsCorrectly(Array.prototype.map)) {
  1222. var originalMap = Array.prototype.map;
  1223. overrideNative(Array.prototype, 'map', function map(callbackFn) {
  1224. return ES.Call(originalMap, this.length >= 0 ? this : [], arguments);
  1225. });
  1226. }
  1227. if (!toLengthsCorrectly(Array.prototype.filter)) {
  1228. var originalFilter = Array.prototype.filter;
  1229. overrideNative(Array.prototype, 'filter', function filter(callbackFn) {
  1230. return ES.Call(originalFilter, this.length >= 0 ? this : [], arguments);
  1231. });
  1232. }
  1233. if (!toLengthsCorrectly(Array.prototype.some)) {
  1234. var originalSome = Array.prototype.some;
  1235. overrideNative(Array.prototype, 'some', function some(callbackFn) {
  1236. return ES.Call(originalSome, this.length >= 0 ? this : [], arguments);
  1237. });
  1238. }
  1239. if (!toLengthsCorrectly(Array.prototype.every)) {
  1240. var originalEvery = Array.prototype.every;
  1241. overrideNative(Array.prototype, 'every', function every(callbackFn) {
  1242. return ES.Call(originalEvery, this.length >= 0 ? this : [], arguments);
  1243. });
  1244. }
  1245. if (!toLengthsCorrectly(Array.prototype.reduce)) {
  1246. var originalReduce = Array.prototype.reduce;
  1247. overrideNative(Array.prototype, 'reduce', function reduce(callbackFn) {
  1248. return ES.Call(originalReduce, this.length >= 0 ? this : [], arguments);
  1249. });
  1250. }
  1251. if (!toLengthsCorrectly(Array.prototype.reduceRight, true)) {
  1252. var originalReduceRight = Array.prototype.reduceRight;
  1253. overrideNative(Array.prototype, 'reduceRight', function reduceRight(callbackFn) {
  1254. return ES.Call(originalReduceRight, this.length >= 0 ? this : [], arguments);
  1255. });
  1256. }
  1257. var lacksOctalSupport = Number('0o10') !== 8;
  1258. var lacksBinarySupport = Number('0b10') !== 2;
  1259. var trimsNonWhitespace = _some(nonWS, function (c) {
  1260. return Number(c + 0 + c) === 0;
  1261. });
  1262. if (lacksOctalSupport || lacksBinarySupport || trimsNonWhitespace) {
  1263. var OrigNumber = Number;
  1264. var binaryRegex = /^0b[01]+$/i;
  1265. var octalRegex = /^0o[0-7]+$/i;
  1266. // Note that in IE 8, RegExp.prototype.test doesn't seem to exist: ie, "test" is an own property of regexes. wtf.
  1267. var isBinary = binaryRegex.test.bind(binaryRegex);
  1268. var isOctal = octalRegex.test.bind(octalRegex);
  1269. var toPrimitive = function (O, hint) { // need to replace this with `es-to-primitive/es6`
  1270. var result;
  1271. if (typeof O.valueOf === 'function') {
  1272. result = O.valueOf();
  1273. if (Type.primitive(result)) {
  1274. return result;
  1275. }
  1276. }
  1277. if (typeof O.toString === 'function') {
  1278. result = O.toString();
  1279. if (Type.primitive(result)) {
  1280. return result;
  1281. }
  1282. }
  1283. throw new TypeError('No default value');
  1284. };
  1285. var hasNonWS = nonWSregex.test.bind(nonWSregex);
  1286. var isBadHex = isBadHexRegex.test.bind(isBadHexRegex);
  1287. var NumberShim = (function () {
  1288. // this is wrapped in an IIFE because of IE 6-8's wacky scoping issues with named function expressions.
  1289. var NumberShim = function Number(value) {
  1290. var primValue;
  1291. if (arguments.length > 0) {
  1292. primValue = Type.primitive(value) ? value : toPrimitive(value, 'number');
  1293. } else {
  1294. primValue = 0;
  1295. }
  1296. if (typeof primValue === 'string') {
  1297. primValue = ES.Call(trimShim, primValue);
  1298. if (isBinary(primValue)) {
  1299. primValue = parseInt(_strSlice(primValue, 2), 2);
  1300. } else if (isOctal(primValue)) {
  1301. primValue = parseInt(_strSlice(primValue, 2), 8);
  1302. } else if (hasNonWS(primValue) || isBadHex(primValue)) {
  1303. primValue = NaN;
  1304. }
  1305. }
  1306. var receiver = this;
  1307. var valueOfSucceeds = valueOrFalseIfThrows(function () {
  1308. OrigNumber.prototype.valueOf.call(receiver);
  1309. return true;
  1310. });
  1311. if (receiver instanceof NumberShim && !valueOfSucceeds) {
  1312. return new OrigNumber(primValue);
  1313. }
  1314. return OrigNumber(primValue);
  1315. };
  1316. return NumberShim;
  1317. }());
  1318. wrapConstructor(OrigNumber, NumberShim, {});
  1319. // this is necessary for ES3 browsers, where these properties are non-enumerable.
  1320. defineProperties(NumberShim, {
  1321. NaN: OrigNumber.NaN,
  1322. MAX_VALUE: OrigNumber.MAX_VALUE,
  1323. MIN_VALUE: OrigNumber.MIN_VALUE,
  1324. NEGATIVE_INFINITY: OrigNumber.NEGATIVE_INFINITY,
  1325. POSITIVE_INFINITY: OrigNumber.POSITIVE_INFINITY
  1326. });
  1327. Number = NumberShim; // eslint-disable-line no-global-assign
  1328. Value.redefine(globals, 'Number', NumberShim);
  1329. }
  1330. var maxSafeInteger = Math.pow(2, 53) - 1;
  1331. defineProperties(Number, {
  1332. MAX_SAFE_INTEGER: maxSafeInteger,
  1333. MIN_SAFE_INTEGER: -maxSafeInteger,
  1334. EPSILON: 2.220446049250313e-16,
  1335. parseInt: globals.parseInt,
  1336. parseFloat: globals.parseFloat,
  1337. isFinite: numberIsFinite,
  1338. isInteger: function isInteger(value) {
  1339. return numberIsFinite(value) && ES.ToInteger(value) === value;
  1340. },
  1341. isSafeInteger: function isSafeInteger(value) {
  1342. return Number.isInteger(value) && _abs(value) <= Number.MAX_SAFE_INTEGER;
  1343. },
  1344. isNaN: numberIsNaN
  1345. });
  1346. // Firefox 37 has a conforming Number.parseInt, but it's not === to the global parseInt (fixed in v40)
  1347. defineProperty(Number, 'parseInt', globals.parseInt, Number.parseInt !== globals.parseInt);
  1348. // Work around bugs in Array#find and Array#findIndex -- early
  1349. // implementations skipped holes in sparse arrays. (Note that the
  1350. // implementations of find/findIndex indirectly use shimmed
  1351. // methods of Number, so this test has to happen down here.)
  1352. /* eslint-disable no-sparse-arrays */
  1353. if ([, 1].find(function () { return true; }) === 1) {
  1354. overrideNative(Array.prototype, 'find', ArrayPrototypeShims.find);
  1355. }
  1356. if ([, 1].findIndex(function () { return true; }) !== 0) {
  1357. overrideNative(Array.prototype, 'findIndex', ArrayPrototypeShims.findIndex);
  1358. }
  1359. /* eslint-enable no-sparse-arrays */
  1360. var isEnumerableOn = Function.bind.call(Function.bind, Object.prototype.propertyIsEnumerable);
  1361. var ensureEnumerable = function ensureEnumerable(obj, prop) {
  1362. if (supportsDescriptors && isEnumerableOn(obj, prop)) {
  1363. Object.defineProperty(obj, prop, { enumerable: false });
  1364. }
  1365. };
  1366. var sliceArgs = function sliceArgs() {
  1367. // per https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments
  1368. // and https://gist.github.com/WebReflection/4327762cb87a8c634a29
  1369. var initial = Number(this);
  1370. var len = arguments.length;
  1371. var desiredArgCount = len - initial;
  1372. var args = new Array(desiredArgCount < 0 ? 0 : desiredArgCount);
  1373. for (var i = initial; i < len; ++i) {
  1374. args[i - initial] = arguments[i];
  1375. }
  1376. return args;
  1377. };
  1378. var assignTo = function assignTo(source) {
  1379. return function assignToSource(target, key) {
  1380. target[key] = source[key];
  1381. return target;
  1382. };
  1383. };
  1384. var assignReducer = function (target, source) {
  1385. var sourceKeys = keys(Object(source));
  1386. var symbols;
  1387. if (ES.IsCallable(Object.getOwnPropertySymbols)) {
  1388. symbols = _filter(Object.getOwnPropertySymbols(Object(source)), isEnumerableOn(source));
  1389. }
  1390. return _reduce(_concat(sourceKeys, symbols || []), assignTo(source), target);
  1391. };
  1392. var ObjectShims = {
  1393. // 19.1.3.1
  1394. assign: function (target, source) {
  1395. var to = ES.ToObject(target, 'Cannot convert undefined or null to object');
  1396. return _reduce(ES.Call(sliceArgs, 1, arguments), assignReducer, to);
  1397. },
  1398. // Added in WebKit in https://bugs.webkit.org/show_bug.cgi?id=143865
  1399. is: function is(a, b) {
  1400. return ES.SameValue(a, b);
  1401. }
  1402. };
  1403. var assignHasPendingExceptions = Object.assign && Object.preventExtensions && (function () {
  1404. // Firefox 37 still has "pending exception" logic in its Object.assign implementation,
  1405. // which is 72% slower than our shim, and Firefox 40's native implementation.
  1406. var thrower = Object.preventExtensions({ 1: 2 });
  1407. try {
  1408. Object.assign(thrower, 'xy');
  1409. } catch (e) {
  1410. return thrower[1] === 'y';
  1411. }
  1412. }());
  1413. if (assignHasPendingExceptions) {
  1414. overrideNative(Object, 'assign', ObjectShims.assign);
  1415. }
  1416. defineProperties(Object, ObjectShims);
  1417. if (supportsDescriptors) {
  1418. var ES5ObjectShims = {
  1419. // 19.1.3.9
  1420. // shim from https://gist.github.com/WebReflection/5593554
  1421. setPrototypeOf: (function (Object) {
  1422. var set;
  1423. var checkArgs = function (O, proto) {
  1424. if (!ES.TypeIsObject(O)) {
  1425. throw new TypeError('cannot set prototype on a non-object');
  1426. }
  1427. if (!(proto === null || ES.TypeIsObject(proto))) {
  1428. throw new TypeError('can only set prototype to an object or null' + proto);
  1429. }
  1430. };
  1431. var setPrototypeOf = function (O, proto) {
  1432. checkArgs(O, proto);
  1433. _call(set, O, proto);
  1434. return O;
  1435. };
  1436. try {
  1437. // this works already in Firefox and Safari
  1438. set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
  1439. _call(set, {}, null);
  1440. } catch (e) {
  1441. if (Object.prototype !== ({}).__proto__) { // eslint-disable-line no-proto
  1442. // IE < 11 cannot be shimmed
  1443. return;
  1444. }
  1445. // probably Chrome or some old Mobile stock browser
  1446. set = function (proto) {
  1447. this.__proto__ = proto; // eslint-disable-line no-proto
  1448. };
  1449. // please note that this will **not** work
  1450. // in those browsers that do not inherit
  1451. // __proto__ by mistake from Object.prototype
  1452. // in these cases we should probably throw an error
  1453. // or at least be informed about the issue
  1454. setPrototypeOf.polyfill = setPrototypeOf(
  1455. setPrototypeOf({}, null),
  1456. Object.prototype
  1457. ) instanceof Object;
  1458. // setPrototypeOf.polyfill === true means it works as meant
  1459. // setPrototypeOf.polyfill === false means it's not 100% reliable
  1460. // setPrototypeOf.polyfill === undefined
  1461. // or
  1462. // setPrototypeOf.polyfill == null means it's not a polyfill
  1463. // which means it works as expected
  1464. // we can even delete Object.prototype.__proto__;
  1465. }
  1466. return setPrototypeOf;
  1467. }(Object))
  1468. };
  1469. defineProperties(Object, ES5ObjectShims);
  1470. }
  1471. // Workaround bug in Opera 12 where setPrototypeOf(x, null) doesn't work,
  1472. // but Object.create(null) does.
  1473. if (
  1474. Object.setPrototypeOf
  1475. && Object.getPrototypeOf
  1476. && Object.getPrototypeOf(Object.setPrototypeOf({}, null)) !== null
  1477. && Object.getPrototypeOf(Object.create(null)) === null
  1478. ) {
  1479. (function () {
  1480. var FAKENULL = Object.create(null);
  1481. var gpo = Object.getPrototypeOf;
  1482. var spo = Object.setPrototypeOf;
  1483. Object.getPrototypeOf = function (o) {
  1484. var result = gpo(o);
  1485. return result === FAKENULL ? null : result;
  1486. };
  1487. Object.setPrototypeOf = function (o, p) {
  1488. var proto = p === null ? FAKENULL : p;
  1489. return spo(o, proto);
  1490. };
  1491. Object.setPrototypeOf.polyfill = false;
  1492. }());
  1493. }
  1494. var objectKeysAcceptsPrimitives = !throwsError(function () { return Object.keys('foo'); });
  1495. if (!objectKeysAcceptsPrimitives) {
  1496. var originalObjectKeys = Object.keys;
  1497. overrideNative(Object, 'keys', function keys(value) {
  1498. return originalObjectKeys(ES.ToObject(value));
  1499. });
  1500. keys = Object.keys;
  1501. }
  1502. var objectKeysRejectsRegex = throwsError(function () { return Object.keys(/a/g); });
  1503. if (objectKeysRejectsRegex) {
  1504. var regexRejectingObjectKeys = Object.keys;
  1505. overrideNative(Object, 'keys', function keys(value) {
  1506. if (Type.regex(value)) {
  1507. var regexKeys = [];
  1508. for (var k in value) {
  1509. if (_hasOwnProperty(value, k)) {
  1510. _push(regexKeys, k);
  1511. }
  1512. }
  1513. return regexKeys;
  1514. }
  1515. return regexRejectingObjectKeys(value);
  1516. });
  1517. keys = Object.keys;
  1518. }
  1519. if (Object.getOwnPropertyNames) {
  1520. var objectGOPNAcceptsPrimitives = !throwsError(function () { return Object.getOwnPropertyNames('foo'); });
  1521. if (!objectGOPNAcceptsPrimitives) {
  1522. var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [];
  1523. var originalObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
  1524. overrideNative(Object, 'getOwnPropertyNames', function getOwnPropertyNames(value) {
  1525. var val = ES.ToObject(value);
  1526. if (_toString(val) === '[object Window]') {
  1527. try {
  1528. return originalObjectGetOwnPropertyNames(val);
  1529. } catch (e) {
  1530. // IE bug where layout engine calls userland gOPN for cross-domain `window` objects
  1531. return _concat([], cachedWindowNames);
  1532. }
  1533. }
  1534. return originalObjectGetOwnPropertyNames(val);
  1535. });
  1536. }
  1537. }
  1538. if (Object.getOwnPropertyDescriptor) {
  1539. var objectGOPDAcceptsPrimitives = !throwsError(function () { return Object.getOwnPropertyDescriptor('foo', 'bar'); });
  1540. if (!objectGOPDAcceptsPrimitives) {
  1541. var originalObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1542. overrideNative(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(value, property) {
  1543. return originalObjectGetOwnPropertyDescriptor(ES.ToObject(value), property);
  1544. });
  1545. }
  1546. }
  1547. if (Object.seal) {
  1548. var objectSealAcceptsPrimitives = !throwsError(function () { return Object.seal('foo'); });
  1549. if (!objectSealAcceptsPrimitives) {
  1550. var originalObjectSeal = Object.seal;
  1551. overrideNative(Object, 'seal', function seal(value) {
  1552. if (!ES.TypeIsObject(value)) { return value; }
  1553. return originalObjectSeal(value);
  1554. });
  1555. }
  1556. }
  1557. if (Object.isSealed) {
  1558. var objectIsSealedAcceptsPrimitives = !throwsError(function () { return Object.isSealed('foo'); });
  1559. if (!objectIsSealedAcceptsPrimitives) {
  1560. var originalObjectIsSealed = Object.isSealed;
  1561. overrideNative(Object, 'isSealed', function isSealed(value) {
  1562. if (!ES.TypeIsObject(value)) { return true; }
  1563. return originalObjectIsSealed(value);
  1564. });
  1565. }
  1566. }
  1567. if (Object.freeze) {
  1568. var objectFreezeAcceptsPrimitives = !throwsError(function () { return Object.freeze('foo'); });
  1569. if (!objectFreezeAcceptsPrimitives) {
  1570. var originalObjectFreeze = Object.freeze;
  1571. overrideNative(Object, 'freeze', function freeze(value) {
  1572. if (!ES.TypeIsObject(value)) { return value; }
  1573. return originalObjectFreeze(value);
  1574. });
  1575. }
  1576. }
  1577. if (Object.isFrozen) {
  1578. var objectIsFrozenAcceptsPrimitives = !throwsError(function () { return Object.isFrozen('foo'); });
  1579. if (!objectIsFrozenAcceptsPrimitives) {
  1580. var originalObjectIsFrozen = Object.isFrozen;
  1581. overrideNative(Object, 'isFrozen', function isFrozen(value) {
  1582. if (!ES.TypeIsObject(value)) { return true; }
  1583. return originalObjectIsFrozen(value);
  1584. });
  1585. }
  1586. }
  1587. if (Object.preventExtensions) {
  1588. var objectPreventExtensionsAcceptsPrimitives = !throwsError(function () { return Object.preventExtensions('foo'); });
  1589. if (!objectPreventExtensionsAcceptsPrimitives) {
  1590. var originalObjectPreventExtensions = Object.preventExtensions;
  1591. overrideNative(Object, 'preventExtensions', function preventExtensions(value) {
  1592. if (!ES.TypeIsObject(value)) { return value; }
  1593. return originalObjectPreventExtensions(value);
  1594. });
  1595. }
  1596. }
  1597. if (Object.isExtensible) {
  1598. var objectIsExtensibleAcceptsPrimitives = !throwsError(function () { return Object.isExtensible('foo'); });
  1599. if (!objectIsExtensibleAcceptsPrimitives) {
  1600. var originalObjectIsExtensible = Object.isExtensible;
  1601. overrideNative(Object, 'isExtensible', function isExtensible(value) {
  1602. if (!ES.TypeIsObject(value)) { return false; }
  1603. return originalObjectIsExtensible(value);
  1604. });
  1605. }
  1606. }
  1607. if (Object.getPrototypeOf) {
  1608. var objectGetProtoAcceptsPrimitives = !throwsError(function () { return Object.getPrototypeOf('foo'); });
  1609. if (!objectGetProtoAcceptsPrimitives) {
  1610. var originalGetProto = Object.getPrototypeOf;
  1611. overrideNative(Object, 'getPrototypeOf', function getPrototypeOf(value) {
  1612. return originalGetProto(ES.ToObject(value));
  1613. });
  1614. }
  1615. }
  1616. var hasFlags = supportsDescriptors && (function () {
  1617. var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
  1618. return desc && ES.IsCallable(desc.get);
  1619. }());
  1620. if (supportsDescriptors && !hasFlags) {
  1621. var regExpFlagsGetter = function flags() {
  1622. if (!ES.TypeIsObject(this)) {
  1623. throw new TypeError('Method called on incompatible type: must be an object.');
  1624. }
  1625. var result = '';
  1626. if (this.global) {
  1627. result += 'g';
  1628. }
  1629. if (this.ignoreCase) {
  1630. result += 'i';
  1631. }
  1632. if (this.multiline) {
  1633. result += 'm';
  1634. }
  1635. if (this.unicode) {
  1636. result += 'u';
  1637. }
  1638. if (this.sticky) {
  1639. result += 'y';
  1640. }
  1641. return result;
  1642. };
  1643. Value.getter(RegExp.prototype, 'flags', regExpFlagsGetter);
  1644. }
  1645. var regExpSupportsFlagsWithRegex = supportsDescriptors && valueOrFalseIfThrows(function () {
  1646. return String(new RegExp(/a/g, 'i')) === '/a/i';
  1647. });
  1648. var regExpNeedsToSupportSymbolMatch = hasSymbols && supportsDescriptors && (function () {
  1649. // Edge 0.12 supports flags fully, but does not support Symbol.match
  1650. var regex = /./;
  1651. regex[Symbol.match] = false;
  1652. return RegExp(regex) === regex;
  1653. }());
  1654. var regexToStringIsGeneric = valueOrFalseIfThrows(function () {
  1655. return RegExp.prototype.toString.call({ source: 'abc' }) === '/abc/';
  1656. });
  1657. var regexToStringSupportsGenericFlags = regexToStringIsGeneric && valueOrFalseIfThrows(function () {
  1658. return RegExp.prototype.toString.call({ source: 'a', flags: 'b' }) === '/a/b';
  1659. });
  1660. if (!regexToStringIsGeneric || !regexToStringSupportsGenericFlags) {
  1661. var origRegExpToString = RegExp.prototype.toString;
  1662. defineProperty(RegExp.prototype, 'toString', function toString() {
  1663. var R = ES.RequireObjectCoercible(this);
  1664. if (Type.regex(R)) {
  1665. return _call(origRegExpToString, R);
  1666. }
  1667. var pattern = $String(R.source);
  1668. var flags = $String(R.flags);
  1669. return '/' + pattern + '/' + flags;
  1670. }, true);
  1671. Value.preserveToString(RegExp.prototype.toString, origRegExpToString);
  1672. RegExp.prototype.toString.prototype = void 0;
  1673. }
  1674. if (supportsDescriptors && (!regExpSupportsFlagsWithRegex || regExpNeedsToSupportSymbolMatch)) {
  1675. var flagsGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
  1676. var sourceDesc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source') || {};
  1677. var legacySourceGetter = function () {
  1678. // prior to it being a getter, it's own + nonconfigurable
  1679. return this.source;
  1680. };
  1681. var sourceGetter = ES.IsCallable(sourceDesc.get) ? sourceDesc.get : legacySourceGetter;
  1682. var OrigRegExp = RegExp;
  1683. var RegExpShim = (function () {
  1684. return function RegExp(pattern, flags) {
  1685. var patternIsRegExp = ES.IsRegExp(pattern);
  1686. var calledWithNew = this instanceof RegExp;
  1687. if (!calledWithNew && patternIsRegExp && typeof flags === 'undefined' && pattern.constructor === RegExp) {
  1688. return pattern;
  1689. }
  1690. var P = pattern;
  1691. var F = flags;
  1692. if (Type.regex(pattern)) {
  1693. P = ES.Call(sourceGetter, pattern);
  1694. F = typeof flags === 'undefined' ? ES.Call(flagsGetter, pattern) : flags;
  1695. return new RegExp(P, F);
  1696. } else if (patternIsRegExp) {
  1697. P = pattern.source;
  1698. F = typeof flags === 'undefined' ? pattern.flags : flags;
  1699. }
  1700. return new OrigRegExp(pattern, flags);
  1701. };
  1702. }());
  1703. wrapConstructor(OrigRegExp, RegExpShim, {
  1704. $input: true // Chrome < v39 & Opera < 26 have a nonstandard "$input" property
  1705. });
  1706. RegExp = RegExpShim; // eslint-disable-line no-global-assign
  1707. Value.redefine(globals, 'RegExp', RegExpShim);
  1708. }
  1709. if (supportsDescriptors) {
  1710. var regexGlobals = {
  1711. input: '$_',
  1712. lastMatch: '$&',
  1713. lastParen: '$+',
  1714. leftContext: '$`',
  1715. rightContext: '$\''
  1716. };
  1717. _forEach(keys(regexGlobals), function (prop) {
  1718. if (prop in RegExp && !(regexGlobals[prop] in RegExp)) {
  1719. Value.getter(RegExp, regexGlobals[prop], function get() {
  1720. return RegExp[prop];
  1721. });
  1722. }
  1723. });
  1724. }
  1725. addDefaultSpecies(RegExp);
  1726. var inverseEpsilon = 1 / Number.EPSILON;
  1727. var roundTiesToEven = function roundTiesToEven(n) {
  1728. // Even though this reduces down to `return n`, it takes advantage of built-in rounding.
  1729. return (n + inverseEpsilon) - inverseEpsilon;
  1730. };
  1731. var BINARY_32_EPSILON = Math.pow(2, -23);
  1732. var BINARY_32_MAX_VALUE = Math.pow(2, 127) * (2 - BINARY_32_EPSILON);
  1733. var BINARY_32_MIN_VALUE = Math.pow(2, -126);
  1734. var E = Math.E;
  1735. var LOG2E = Math.LOG2E;
  1736. var LOG10E = Math.LOG10E;
  1737. var numberCLZ = Number.prototype.clz;
  1738. delete Number.prototype.clz; // Safari 8 has Number#clz
  1739. var MathShims = {
  1740. acosh: function acosh(value) {
  1741. var x = Number(value);
  1742. if (numberIsNaN(x) || value < 1) { return NaN; }
  1743. if (x === 1) { return 0; }
  1744. if (x === Infinity) { return x; }
  1745. var xInvSquared = 1 / (x * x);
  1746. if (x < 2) {
  1747. return _log1p(x - 1 + (_sqrt(1 - xInvSquared) * x));
  1748. }
  1749. var halfX = x / 2;
  1750. return _log1p(halfX + (_sqrt(1 - xInvSquared) * halfX) - 1) + (1 / LOG2E);
  1751. },
  1752. asinh: function asinh(value) {
  1753. var x = Number(value);
  1754. if (x === 0 || !globalIsFinite(x)) {
  1755. return x;
  1756. }
  1757. var a = _abs(x);
  1758. var aSquared = a * a;
  1759. var s = _sign(x);
  1760. if (a < 1) {
  1761. return s * _log1p(a + (aSquared / (_sqrt(aSquared + 1) + 1)));
  1762. }
  1763. return s * (_log1p((a / 2) + (_sqrt(1 + (1 / aSquared)) * a / 2) - 1) + (1 / LOG2E));
  1764. },
  1765. atanh: function atanh(value) {
  1766. var x = Number(value);
  1767. if (x === 0) { return x; }
  1768. if (x === -1) { return -Infinity; }
  1769. if (x === 1) { return Infinity; }
  1770. if (numberIsNaN(x) || x < -1 || x > 1) {
  1771. return NaN;
  1772. }
  1773. var a = _abs(x);
  1774. return _sign(x) * _log1p(2 * a / (1 - a)) / 2;
  1775. },
  1776. cbrt: function cbrt(value) {
  1777. var x = Number(value);
  1778. if (x === 0) { return x; }
  1779. var negate = x < 0;
  1780. var result;
  1781. if (negate) { x = -x; }
  1782. if (x === Infinity) {
  1783. result = Infinity;
  1784. } else {
  1785. result = _exp(_log(x) / 3);
  1786. // from http://en.wikipedia.org/wiki/Cube_root#Numerical_methods
  1787. result = ((x / (result * result)) + (2 * result)) / 3;
  1788. }
  1789. return negate ? -result : result;
  1790. },
  1791. clz32: function clz32(value) {
  1792. // See https://bugs.ecmascript.org/show_bug.cgi?id=2465
  1793. var x = Number(value);
  1794. var number = ES.ToUint32(x);
  1795. if (number === 0) {
  1796. return 32;
  1797. }
  1798. return numberCLZ ? ES.Call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * LOG2E);
  1799. },
  1800. cosh: function cosh(value) {
  1801. var x = Number(value);
  1802. if (x === 0) { return 1; } // +0 or -0
  1803. if (numberIsNaN(x)) { return NaN; }
  1804. if (!globalIsFinite(x)) { return Infinity; }
  1805. var t = _exp(_abs(x) - 1);
  1806. return (t + (1 / (t * E * E))) * (E / 2);
  1807. },
  1808. expm1: function expm1(value) {
  1809. var x = Number(value);
  1810. if (x === -Infinity) { return -1; }
  1811. if (!globalIsFinite(x) || x === 0) { return x; }
  1812. if (_abs(x) > 0.5) {
  1813. return _exp(x) - 1;
  1814. }
  1815. // A more precise approximation using Taylor series expansion
  1816. // from https://github.com/paulmillr/es6-shim/issues/314#issuecomment-70293986
  1817. var t = x;
  1818. var sum = 0;
  1819. var n = 1;
  1820. while (sum + t !== sum) {
  1821. sum += t;
  1822. n += 1;
  1823. t *= x / n;
  1824. }
  1825. return sum;
  1826. },
  1827. hypot: function hypot(x, y) {
  1828. var result = 0;
  1829. var largest = 0;
  1830. for (var i = 0; i < arguments.length; ++i) {
  1831. var value = _abs(Number(arguments[i]));
  1832. if (largest < value) {
  1833. result *= (largest / value) * (largest / value);
  1834. result += 1;
  1835. largest = value;
  1836. } else {
  1837. result += value > 0 ? (value / largest) * (value / largest) : value;
  1838. }
  1839. }
  1840. return largest === Infinity ? Infinity : largest * _sqrt(result);
  1841. },
  1842. log2: function log2(value) {
  1843. return _log(value) * LOG2E;
  1844. },
  1845. log10: function log10(value) {
  1846. return _log(value) * LOG10E;
  1847. },
  1848. log1p: _log1p,
  1849. sign: _sign,
  1850. sinh: function sinh(value) {
  1851. var x = Number(value);
  1852. if (!globalIsFinite(x) || x === 0) { return x; }
  1853. var a = _abs(x);
  1854. if (a < 1) {
  1855. var u = Math.expm1(a);
  1856. return _sign(x) * u * (1 + (1 / (u + 1))) / 2;
  1857. }
  1858. var t = _exp(a - 1);
  1859. return _sign(x) * (t - (1 / (t * E * E))) * (E / 2);
  1860. },
  1861. tanh: function tanh(value) {
  1862. var x = Number(value);
  1863. if (numberIsNaN(x) || x === 0) { return x; }
  1864. // can exit early at +-20 as JS loses precision for true value at this integer
  1865. if (x >= 20) { return 1; }
  1866. if (x <= -20) { return -1; }
  1867. return (Math.expm1(x) - Math.expm1(-x)) / (_exp(x) + _exp(-x));
  1868. },
  1869. trunc: function trunc(value) {
  1870. var x = Number(value);
  1871. return x < 0 ? -_floor(-x) : _floor(x);
  1872. },
  1873. imul: function imul(x, y) {
  1874. // taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
  1875. var a = ES.ToUint32(x);
  1876. var b = ES.ToUint32(y);
  1877. var ah = (a >>> 16) & 0xffff;
  1878. var al = a & 0xffff;
  1879. var bh = (b >>> 16) & 0xffff;
  1880. var bl = b & 0xffff;
  1881. // the shift by 0 fixes the sign on the high part
  1882. // the final |0 converts the unsigned value into a signed value
  1883. return (al * bl) + ((((ah * bl) + (al * bh)) << 16) >>> 0) | 0;
  1884. },
  1885. fround: function fround(x) {
  1886. var v = Number(x);
  1887. if (v === 0 || v === Infinity || v === -Infinity || numberIsNaN(v)) {
  1888. return v;
  1889. }
  1890. var sign = _sign(v);
  1891. var abs = _abs(v);
  1892. if (abs < BINARY_32_MIN_VALUE) {
  1893. return sign * roundTiesToEven(abs / BINARY_32_MIN_VALUE / BINARY_32_EPSILON) * BINARY_32_MIN_VALUE * BINARY_32_EPSILON;
  1894. }
  1895. // Veltkamp's splitting (?)
  1896. var a = (1 + (BINARY_32_EPSILON / Number.EPSILON)) * abs;
  1897. var result = a - (a - abs);
  1898. if (result > BINARY_32_MAX_VALUE || numberIsNaN(result)) {
  1899. return sign * Infinity;
  1900. }
  1901. return sign * result;
  1902. }
  1903. };
  1904. var withinULPDistance = function withinULPDistance(result, expected, distance) {
  1905. return _abs(1 - (result / expected)) / Number.EPSILON < (distance || 8);
  1906. };
  1907. defineProperties(Math, MathShims);
  1908. // Chrome < 40 sinh returns ∞ for large numbers
  1909. defineProperty(Math, 'sinh', MathShims.sinh, Math.sinh(710) === Infinity);
  1910. // Chrome < 40 cosh returns ∞ for large numbers
  1911. defineProperty(Math, 'cosh', MathShims.cosh, Math.cosh(710) === Infinity);
  1912. // IE 11 TP has an imprecise log1p: reports Math.log1p(-1e-17) as 0
  1913. defineProperty(Math, 'log1p', MathShims.log1p, Math.log1p(-1e-17) !== -1e-17);
  1914. // IE 11 TP has an imprecise asinh: reports Math.asinh(-1e7) as not exactly equal to -Math.asinh(1e7)
  1915. defineProperty(Math, 'asinh', MathShims.asinh, Math.asinh(-1e7) !== -Math.asinh(1e7));
  1916. // Chrome < 54 asinh returns ∞ for large numbers and should not
  1917. defineProperty(Math, 'asinh', MathShims.asinh, Math.asinh(1e+300) === Infinity);
  1918. // Chrome < 54 atanh incorrectly returns 0 for large numbers
  1919. defineProperty(Math, 'atanh', MathShims.atanh, Math.atanh(1e-300) === 0);
  1920. // Chrome 40 has an imprecise Math.tanh with very small numbers
  1921. defineProperty(Math, 'tanh', MathShims.tanh, Math.tanh(-2e-17) !== -2e-17);
  1922. // Chrome 40 loses Math.acosh precision with high numbers
  1923. defineProperty(Math, 'acosh', MathShims.acosh, Math.acosh(Number.MAX_VALUE) === Infinity);
  1924. // Chrome < 54 has an inaccurate acosh for EPSILON deltas
  1925. defineProperty(Math, 'acosh', MathShims.acosh, !withinULPDistance(Math.acosh(1 + Number.EPSILON), Math.sqrt(2 * Number.EPSILON)));
  1926. // Firefox 38 on Windows
  1927. defineProperty(Math, 'cbrt', MathShims.cbrt, !withinULPDistance(Math.cbrt(1e-300), 1e-100));
  1928. // node 0.11 has an imprecise Math.sinh with very small numbers
  1929. defineProperty(Math, 'sinh', MathShims.sinh, Math.sinh(-2e-17) !== -2e-17);
  1930. // FF 35 on Linux reports 22025.465794806725 for Math.expm1(10)
  1931. var expm1OfTen = Math.expm1(10);
  1932. defineProperty(Math, 'expm1', MathShims.expm1, expm1OfTen > 22025.465794806719 || expm1OfTen < 22025.4657948067165168);
  1933. // node v12.11 - v12.15 report NaN
  1934. defineProperty(Math, 'hypot', MathShims.hypot, Math.hypot(Infinity, NaN) !== Infinity);
  1935. var origMathRound = Math.round;
  1936. // breaks in e.g. Safari 8, Internet Explorer 11, Opera 12
  1937. var roundHandlesBoundaryConditions = Math.round(0.5 - (Number.EPSILON / 4)) === 0
  1938. && Math.round(-0.5 + (Number.EPSILON / 3.99)) === 1;
  1939. // When engines use Math.floor(x + 0.5) internally, Math.round can be buggy for large integers.
  1940. // This behavior should be governed by "round to nearest, ties to even mode"
  1941. // see http://www.ecma-international.org/ecma-262/6.0/#sec-terms-and-definitions-number-type
  1942. // These are the boundary cases where it breaks.
  1943. var smallestPositiveNumberWhereRoundBreaks = inverseEpsilon + 1;
  1944. var largestPositiveNumberWhereRoundBreaks = (2 * inverseEpsilon) - 1;
  1945. var roundDoesNotIncreaseIntegers = [
  1946. smallestPositiveNumberWhereRoundBreaks,
  1947. largestPositiveNumberWhereRoundBreaks
  1948. ].every(function (num) {
  1949. return Math.round(num) === num;
  1950. });
  1951. defineProperty(Math, 'round', function round(x) {
  1952. var floor = _floor(x);
  1953. var ceil = floor === -1 ? -0 : floor + 1;
  1954. return x - floor < 0.5 ? floor : ceil;
  1955. }, !roundHandlesBoundaryConditions || !roundDoesNotIncreaseIntegers);
  1956. Value.preserveToString(Math.round, origMathRound);
  1957. var origImul = Math.imul;
  1958. if (Math.imul(0xffffffff, 5) !== -5) {
  1959. // Safari 6.1, at least, reports "0" for this value
  1960. Math.imul = MathShims.imul;
  1961. Value.preserveToString(Math.imul, origImul);
  1962. }
  1963. if (Math.imul.length !== 2) {
  1964. // Safari 8.0.4 has a length of 1
  1965. // fixed in https://bugs.webkit.org/show_bug.cgi?id=143658
  1966. overrideNative(Math, 'imul', function imul(x, y) {
  1967. return ES.Call(origImul, Math, arguments);
  1968. });
  1969. }
  1970. // Promises
  1971. // Simplest possible implementation; use a 3rd-party library if you
  1972. // want the best possible speed and/or long stack traces.
  1973. var PromiseShim = (function () {
  1974. var setTimeout = globals.setTimeout;
  1975. // some environments don't have setTimeout - no way to shim here.
  1976. if (typeof setTimeout !== 'function' && typeof setTimeout !== 'object') { return; }
  1977. ES.IsPromise = function (promise) {
  1978. if (!ES.TypeIsObject(promise)) {
  1979. return false;
  1980. }
  1981. if (typeof promise._promise === 'undefined') {
  1982. return false; // uninitialized, or missing our hidden field.
  1983. }
  1984. return true;
  1985. };
  1986. // "PromiseCapability" in the spec is what most promise implementations
  1987. // call a "deferred".
  1988. var PromiseCapability = function (C) {
  1989. if (!ES.IsConstructor(C)) {
  1990. throw new TypeError('Bad promise constructor');
  1991. }
  1992. var capability = this;
  1993. var resolver = function (resolve, reject) {
  1994. if (capability.resolve !== void 0 || capability.reject !== void 0) {
  1995. throw new TypeError('Bad Promise implementation!');
  1996. }
  1997. capability.resolve = resolve;
  1998. capability.reject = reject;
  1999. };
  2000. // Initialize fields to inform optimizers about the object shape.
  2001. capability.resolve = void 0;
  2002. capability.reject = void 0;
  2003. capability.promise = new C(resolver);
  2004. if (!(ES.IsCallable(capability.resolve) && ES.IsCallable(capability.reject))) {
  2005. throw new TypeError('Bad promise constructor');
  2006. }
  2007. };
  2008. // find an appropriate setImmediate-alike
  2009. var makeZeroTimeout;
  2010. if (typeof window !== 'undefined' && ES.IsCallable(window.postMessage)) {
  2011. makeZeroTimeout = function () {
  2012. // from http://dbaron.org/log/20100309-faster-timeouts
  2013. var timeouts = [];
  2014. var messageName = 'zero-timeout-message';
  2015. var setZeroTimeout = function (fn) {
  2016. _push(timeouts, fn);
  2017. window.postMessage(messageName, '*');
  2018. };
  2019. var handleMessage = function (event) {
  2020. if (event.source === window && event.data === messageName) {
  2021. event.stopPropagation();
  2022. if (timeouts.length === 0) { return; }
  2023. var fn = _shift(timeouts);
  2024. fn();
  2025. }
  2026. };
  2027. window.addEventListener('message', handleMessage, true);
  2028. return setZeroTimeout;
  2029. };
  2030. }
  2031. var makePromiseAsap = function () {
  2032. // An efficient task-scheduler based on a pre-existing Promise
  2033. // implementation, which we can use even if we override the
  2034. // global Promise below (in order to workaround bugs)
  2035. // https://github.com/Raynos/observ-hash/issues/2#issuecomment-35857671
  2036. var P = globals.Promise;
  2037. var pr = P && P.resolve && P.resolve();
  2038. return pr && function (task) {
  2039. return pr.then(task);
  2040. };
  2041. };
  2042. var enqueue = ES.IsCallable(globals.setImmediate)
  2043. ? globals.setImmediate
  2044. : (
  2045. typeof process === 'object' && process.nextTick
  2046. ? process.nextTick
  2047. : makePromiseAsap() || (ES.IsCallable(makeZeroTimeout) ? makeZeroTimeout() : function (task) { setTimeout(task, 0); })
  2048. ); // fallback
  2049. // Constants for Promise implementation
  2050. var PROMISE_IDENTITY = function (x) { return x; };
  2051. var PROMISE_THROWER = function (e) { throw e; };
  2052. var PROMISE_PENDING = 0;
  2053. var PROMISE_FULFILLED = 1;
  2054. var PROMISE_REJECTED = 2;
  2055. // We store fulfill/reject handlers and capabilities in a single array.
  2056. var PROMISE_FULFILL_OFFSET = 0;
  2057. var PROMISE_REJECT_OFFSET = 1;
  2058. var PROMISE_CAPABILITY_OFFSET = 2;
  2059. // This is used in an optimization for chaining promises via then.
  2060. var PROMISE_FAKE_CAPABILITY = {};
  2061. var enqueuePromiseReactionJob = function (handler, capability, argument) {
  2062. enqueue(function () {
  2063. promiseReactionJob(handler, capability, argument);
  2064. });
  2065. };
  2066. var promiseReactionJob = function (handler, promiseCapability, argument) {
  2067. var handlerResult, f;
  2068. if (promiseCapability === PROMISE_FAKE_CAPABILITY) {
  2069. // Fast case, when we don't actually need to chain through to a
  2070. // (real) promiseCapability.
  2071. return handler(argument);
  2072. }
  2073. try {
  2074. handlerResult = handler(argument);
  2075. f = promiseCapability.resolve;
  2076. } catch (e) {
  2077. handlerResult = e;
  2078. f = promiseCapability.reject;
  2079. }
  2080. f(handlerResult);
  2081. };
  2082. var fulfillPromise = function (promise, value) {
  2083. var _promise = promise._promise;
  2084. var length = _promise.reactionLength;
  2085. if (length > 0) {
  2086. enqueuePromiseReactionJob(
  2087. _promise.fulfillReactionHandler0,
  2088. _promise.reactionCapability0,
  2089. value
  2090. );
  2091. _promise.fulfillReactionHandler0 = void 0;
  2092. _promise.rejectReactions0 = void 0;
  2093. _promise.reactionCapability0 = void 0;
  2094. if (length > 1) {
  2095. for (var i = 1, idx = 0; i < length; i++, idx += 3) {
  2096. enqueuePromiseReactionJob(
  2097. _promise[idx + PROMISE_FULFILL_OFFSET],
  2098. _promise[idx + PROMISE_CAPABILITY_OFFSET],
  2099. value
  2100. );
  2101. promise[idx + PROMISE_FULFILL_OFFSET] = void 0;
  2102. promise[idx + PROMISE_REJECT_OFFSET] = void 0;
  2103. promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0;
  2104. }
  2105. }
  2106. }
  2107. _promise.result = value;
  2108. _promise.state = PROMISE_FULFILLED;
  2109. _promise.reactionLength = 0;
  2110. };
  2111. var rejectPromise = function (promise, reason) {
  2112. var _promise = promise._promise;
  2113. var length = _promise.reactionLength;
  2114. if (length > 0) {
  2115. enqueuePromiseReactionJob(
  2116. _promise.rejectReactionHandler0,
  2117. _promise.reactionCapability0,
  2118. reason
  2119. );
  2120. _promise.fulfillReactionHandler0 = void 0;
  2121. _promise.rejectReactions0 = void 0;
  2122. _promise.reactionCapability0 = void 0;
  2123. if (length > 1) {
  2124. for (var i = 1, idx = 0; i < length; i++, idx += 3) {
  2125. enqueuePromiseReactionJob(
  2126. _promise[idx + PROMISE_REJECT_OFFSET],
  2127. _promise[idx + PROMISE_CAPABILITY_OFFSET],
  2128. reason
  2129. );
  2130. promise[idx + PROMISE_FULFILL_OFFSET] = void 0;
  2131. promise[idx + PROMISE_REJECT_OFFSET] = void 0;
  2132. promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0;
  2133. }
  2134. }
  2135. }
  2136. _promise.result = reason;
  2137. _promise.state = PROMISE_REJECTED;
  2138. _promise.reactionLength = 0;
  2139. };
  2140. var createResolvingFunctions = function (promise) {
  2141. var alreadyResolved = false;
  2142. var resolve = function (resolution) {
  2143. var then;
  2144. if (alreadyResolved) { return; }
  2145. alreadyResolved = true;
  2146. if (resolution === promise) {
  2147. return rejectPromise(promise, new TypeError('Self resolution'));
  2148. }
  2149. if (!ES.TypeIsObject(resolution)) {
  2150. return fulfillPromise(promise, resolution);
  2151. }
  2152. try {
  2153. then = resolution.then;
  2154. } catch (e) {
  2155. return rejectPromise(promise, e);
  2156. }
  2157. if (!ES.IsCallable(then)) {
  2158. return fulfillPromise(promise, resolution);
  2159. }
  2160. enqueue(function () {
  2161. promiseResolveThenableJob(promise, resolution, then);
  2162. });
  2163. };
  2164. var reject = function (reason) {
  2165. if (alreadyResolved) { return; }
  2166. alreadyResolved = true;
  2167. return rejectPromise(promise, reason);
  2168. };
  2169. return { resolve: resolve, reject: reject };
  2170. };
  2171. var optimizedThen = function (then, thenable, resolve, reject) {
  2172. // Optimization: since we discard the result, we can pass our
  2173. // own then implementation a special hint to let it know it
  2174. // doesn't have to create it. (The PROMISE_FAKE_CAPABILITY
  2175. // object is local to this implementation and unforgeable outside.)
  2176. if (then === Promise$prototype$then) {
  2177. _call(then, thenable, resolve, reject, PROMISE_FAKE_CAPABILITY);
  2178. } else {
  2179. _call(then, thenable, resolve, reject);
  2180. }
  2181. };
  2182. var promiseResolveThenableJob = function (promise, thenable, then) {
  2183. var resolvingFunctions = createResolvingFunctions(promise);
  2184. var resolve = resolvingFunctions.resolve;
  2185. var reject = resolvingFunctions.reject;
  2186. try {
  2187. optimizedThen(then, thenable, resolve, reject);
  2188. } catch (e) {
  2189. reject(e);
  2190. }
  2191. };
  2192. var Promise$prototype, Promise$prototype$then;
  2193. var Promise = (function () {
  2194. var PromiseShim = function Promise(resolver) {
  2195. if (!(this instanceof PromiseShim)) {
  2196. throw new TypeError('Constructor Promise requires "new"');
  2197. }
  2198. if (this && this._promise) {
  2199. throw new TypeError('Bad construction');
  2200. }
  2201. // see https://bugs.ecmascript.org/show_bug.cgi?id=2482
  2202. if (!ES.IsCallable(resolver)) {
  2203. throw new TypeError('not a valid resolver');
  2204. }
  2205. var promise = emulateES6construct(this, PromiseShim, Promise$prototype, {
  2206. _promise: {
  2207. result: void 0,
  2208. state: PROMISE_PENDING,
  2209. // The first member of the "reactions" array is inlined here,
  2210. // since most promises only have one reaction.
  2211. // We've also exploded the 'reaction' object to inline the
  2212. // "handler" and "capability" fields, since both fulfill and
  2213. // reject reactions share the same capability.
  2214. reactionLength: 0,
  2215. fulfillReactionHandler0: void 0,
  2216. rejectReactionHandler0: void 0,
  2217. reactionCapability0: void 0
  2218. }
  2219. });
  2220. var resolvingFunctions = createResolvingFunctions(promise);
  2221. var reject = resolvingFunctions.reject;
  2222. try {
  2223. resolver(resolvingFunctions.resolve, reject);
  2224. } catch (e) {
  2225. reject(e);
  2226. }
  2227. return promise;
  2228. };
  2229. return PromiseShim;
  2230. }());
  2231. Promise$prototype = Promise.prototype;
  2232. var _promiseAllResolver = function (index, values, capability, remaining) {
  2233. var alreadyCalled = false;
  2234. return function (x) {
  2235. if (alreadyCalled) { return; }
  2236. alreadyCalled = true;
  2237. values[index] = x;
  2238. if ((--remaining.count) === 0) {
  2239. var resolve = capability.resolve;
  2240. resolve(values); // call w/ this===undefined
  2241. }
  2242. };
  2243. };
  2244. var performPromiseAll = function (iteratorRecord, C, resultCapability) {
  2245. var it = iteratorRecord.iterator;
  2246. var values = [];
  2247. var remaining = { count: 1 };
  2248. var next, nextValue;
  2249. var index = 0;
  2250. while (true) {
  2251. try {
  2252. next = ES.IteratorStep(it);
  2253. if (next === false) {
  2254. iteratorRecord.done = true;
  2255. break;
  2256. }
  2257. nextValue = next.value;
  2258. } catch (e) {
  2259. iteratorRecord.done = true;
  2260. throw e;
  2261. }
  2262. values[index] = void 0;
  2263. var nextPromise = C.resolve(nextValue);
  2264. var resolveElement = _promiseAllResolver(
  2265. index,
  2266. values,
  2267. resultCapability,
  2268. remaining
  2269. );
  2270. remaining.count += 1;
  2271. optimizedThen(nextPromise.then, nextPromise, resolveElement, resultCapability.reject);
  2272. index += 1;
  2273. }
  2274. if ((--remaining.count) === 0) {
  2275. var resolve = resultCapability.resolve;
  2276. resolve(values); // call w/ this===undefined
  2277. }
  2278. return resultCapability.promise;
  2279. };
  2280. var performPromiseRace = function (iteratorRecord, C, resultCapability) {
  2281. var it = iteratorRecord.iterator;
  2282. var next, nextValue, nextPromise;
  2283. while (true) {
  2284. try {
  2285. next = ES.IteratorStep(it);
  2286. if (next === false) {
  2287. // NOTE: If iterable has no items, resulting promise will never
  2288. // resolve; see:
  2289. // https://github.com/domenic/promises-unwrapping/issues/75
  2290. // https://bugs.ecmascript.org/show_bug.cgi?id=2515
  2291. iteratorRecord.done = true;
  2292. break;
  2293. }
  2294. nextValue = next.value;
  2295. } catch (e) {
  2296. iteratorRecord.done = true;
  2297. throw e;
  2298. }
  2299. nextPromise = C.resolve(nextValue);
  2300. optimizedThen(nextPromise.then, nextPromise, resultCapability.resolve, resultCapability.reject);
  2301. }
  2302. return resultCapability.promise;
  2303. };
  2304. defineProperties(Promise, {
  2305. all: function all(iterable) {
  2306. var C = this;
  2307. if (!ES.TypeIsObject(C)) {
  2308. throw new TypeError('Promise is not object');
  2309. }
  2310. var capability = new PromiseCapability(C);
  2311. var iterator, iteratorRecord;
  2312. try {
  2313. iterator = ES.GetIterator(iterable);
  2314. iteratorRecord = { iterator: iterator, done: false };
  2315. return performPromiseAll(iteratorRecord, C, capability);
  2316. } catch (e) {
  2317. var exception = e;
  2318. if (iteratorRecord && !iteratorRecord.done) {
  2319. try {
  2320. ES.IteratorClose(iterator, true);
  2321. } catch (ee) {
  2322. exception = ee;
  2323. }
  2324. }
  2325. var reject = capability.reject;
  2326. reject(exception);
  2327. return capability.promise;
  2328. }
  2329. },
  2330. race: function race(iterable) {
  2331. var C = this;
  2332. if (!ES.TypeIsObject(C)) {
  2333. throw new TypeError('Promise is not object');
  2334. }
  2335. var capability = new PromiseCapability(C);
  2336. var iterator, iteratorRecord;
  2337. try {
  2338. iterator = ES.GetIterator(iterable);
  2339. iteratorRecord = { iterator: iterator, done: false };
  2340. return performPromiseRace(iteratorRecord, C, capability);
  2341. } catch (e) {
  2342. var exception = e;
  2343. if (iteratorRecord && !iteratorRecord.done) {
  2344. try {
  2345. ES.IteratorClose(iterator, true);
  2346. } catch (ee) {
  2347. exception = ee;
  2348. }
  2349. }
  2350. var reject = capability.reject;
  2351. reject(exception);
  2352. return capability.promise;
  2353. }
  2354. },
  2355. reject: function reject(reason) {
  2356. var C = this;
  2357. if (!ES.TypeIsObject(C)) {
  2358. throw new TypeError('Bad promise constructor');
  2359. }
  2360. var capability = new PromiseCapability(C);
  2361. var rejectFunc = capability.reject;
  2362. rejectFunc(reason); // call with this===undefined
  2363. return capability.promise;
  2364. },
  2365. resolve: function resolve(v) {
  2366. // See https://esdiscuss.org/topic/fixing-promise-resolve for spec
  2367. var C = this;
  2368. if (!ES.TypeIsObject(C)) {
  2369. throw new TypeError('Bad promise constructor');
  2370. }
  2371. if (ES.IsPromise(v)) {
  2372. var constructor = v.constructor;
  2373. if (constructor === C) {
  2374. return v;
  2375. }
  2376. }
  2377. var capability = new PromiseCapability(C);
  2378. var resolveFunc = capability.resolve;
  2379. resolveFunc(v); // call with this===undefined
  2380. return capability.promise;
  2381. }
  2382. });
  2383. defineProperties(Promise$prototype, {
  2384. 'catch': function (onRejected) {
  2385. return this.then(null, onRejected);
  2386. },
  2387. then: function then(onFulfilled, onRejected) {
  2388. var promise = this;
  2389. if (!ES.IsPromise(promise)) { throw new TypeError('not a promise'); }
  2390. var C = ES.SpeciesConstructor(promise, Promise);
  2391. var resultCapability;
  2392. var returnValueIsIgnored = arguments.length > 2 && arguments[2] === PROMISE_FAKE_CAPABILITY;
  2393. if (returnValueIsIgnored && C === Promise) {
  2394. resultCapability = PROMISE_FAKE_CAPABILITY;
  2395. } else {
  2396. resultCapability = new PromiseCapability(C);
  2397. }
  2398. // PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability)
  2399. // Note that we've split the 'reaction' object into its two
  2400. // components, "capabilities" and "handler"
  2401. // "capabilities" is always equal to `resultCapability`
  2402. var fulfillReactionHandler = ES.IsCallable(onFulfilled) ? onFulfilled : PROMISE_IDENTITY;
  2403. var rejectReactionHandler = ES.IsCallable(onRejected) ? onRejected : PROMISE_THROWER;
  2404. var _promise = promise._promise;
  2405. var value;
  2406. if (_promise.state === PROMISE_PENDING) {
  2407. if (_promise.reactionLength === 0) {
  2408. _promise.fulfillReactionHandler0 = fulfillReactionHandler;
  2409. _promise.rejectReactionHandler0 = rejectReactionHandler;
  2410. _promise.reactionCapability0 = resultCapability;
  2411. } else {
  2412. var idx = 3 * (_promise.reactionLength - 1);
  2413. _promise[idx + PROMISE_FULFILL_OFFSET] = fulfillReactionHandler;
  2414. _promise[idx + PROMISE_REJECT_OFFSET] = rejectReactionHandler;
  2415. _promise[idx + PROMISE_CAPABILITY_OFFSET] = resultCapability;
  2416. }
  2417. _promise.reactionLength += 1;
  2418. } else if (_promise.state === PROMISE_FULFILLED) {
  2419. value = _promise.result;
  2420. enqueuePromiseReactionJob(
  2421. fulfillReactionHandler,
  2422. resultCapability,
  2423. value
  2424. );
  2425. } else if (_promise.state === PROMISE_REJECTED) {
  2426. value = _promise.result;
  2427. enqueuePromiseReactionJob(
  2428. rejectReactionHandler,
  2429. resultCapability,
  2430. value
  2431. );
  2432. } else {
  2433. throw new TypeError('unexpected Promise state');
  2434. }
  2435. return resultCapability.promise;
  2436. }
  2437. });
  2438. // This helps the optimizer by ensuring that methods which take
  2439. // capabilities aren't polymorphic.
  2440. PROMISE_FAKE_CAPABILITY = new PromiseCapability(Promise);
  2441. Promise$prototype$then = Promise$prototype.then;
  2442. return Promise;
  2443. }());
  2444. // Chrome's native Promise has extra methods that it shouldn't have. Let's remove them.
  2445. if (globals.Promise) {
  2446. delete globals.Promise.accept;
  2447. delete globals.Promise.defer;
  2448. delete globals.Promise.prototype.chain;
  2449. }
  2450. if (typeof PromiseShim === 'function') {
  2451. // export the Promise constructor.
  2452. defineProperties(globals, { Promise: PromiseShim });
  2453. // In Chrome 33 (and thereabouts) Promise is defined, but the
  2454. // implementation is buggy in a number of ways. Let's check subclassing
  2455. // support to see if we have a buggy implementation.
  2456. var promiseSupportsSubclassing = supportsSubclassing(globals.Promise, function (S) {
  2457. return S.resolve(42).then(function () {}) instanceof S;
  2458. });
  2459. var promiseIgnoresNonFunctionThenCallbacks = !throwsError(function () {
  2460. return globals.Promise.reject(42).then(null, 5).then(null, noop);
  2461. });
  2462. var promiseRequiresObjectContext = throwsError(function () { return globals.Promise.call(3, noop); });
  2463. // Promise.resolve() was errata'ed late in the ES6 process.
  2464. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1170742
  2465. // https://code.google.com/p/v8/issues/detail?id=4161
  2466. // It serves as a proxy for a number of other bugs in early Promise
  2467. // implementations.
  2468. var promiseResolveBroken = (function (Promise) {
  2469. var p = Promise.resolve(5);
  2470. p.constructor = {};
  2471. var p2 = Promise.resolve(p);
  2472. try {
  2473. p2.then(null, noop).then(null, noop); // avoid "uncaught rejection" warnings in console
  2474. } catch (e) {
  2475. return true; // v8 native Promises break here https://code.google.com/p/chromium/issues/detail?id=575314
  2476. }
  2477. return p === p2; // This *should* be false!
  2478. }(globals.Promise));
  2479. // Chrome 46 (probably older too) does not retrieve a thenable's .then synchronously
  2480. var getsThenSynchronously = supportsDescriptors && (function () {
  2481. var count = 0;
  2482. // eslint-disable-next-line getter-return
  2483. var thenable = Object.defineProperty({}, 'then', { get: function () { count += 1; } });
  2484. Promise.resolve(thenable);
  2485. return count === 1;
  2486. }());
  2487. var BadResolverPromise = function BadResolverPromise(executor) {
  2488. var p = new Promise(executor);
  2489. executor(3, function () {});
  2490. this.then = p.then;
  2491. this.constructor = BadResolverPromise;
  2492. };
  2493. BadResolverPromise.prototype = Promise.prototype;
  2494. BadResolverPromise.all = Promise.all;
  2495. // Chrome Canary 49 (probably older too) has some implementation bugs
  2496. var hasBadResolverPromise = valueOrFalseIfThrows(function () {
  2497. return !!BadResolverPromise.all([1, 2]);
  2498. });
  2499. if (
  2500. !promiseSupportsSubclassing
  2501. || !promiseIgnoresNonFunctionThenCallbacks
  2502. || !promiseRequiresObjectContext
  2503. || promiseResolveBroken
  2504. || !getsThenSynchronously
  2505. || hasBadResolverPromise
  2506. ) {
  2507. Promise = PromiseShim; // eslint-disable-line no-global-assign
  2508. overrideNative(globals, 'Promise', PromiseShim);
  2509. }
  2510. if (Promise.all.length !== 1) {
  2511. var origAll = Promise.all;
  2512. overrideNative(Promise, 'all', function all(iterable) {
  2513. return ES.Call(origAll, this, arguments);
  2514. });
  2515. }
  2516. if (Promise.race.length !== 1) {
  2517. var origRace = Promise.race;
  2518. overrideNative(Promise, 'race', function race(iterable) {
  2519. return ES.Call(origRace, this, arguments);
  2520. });
  2521. }
  2522. if (Promise.resolve.length !== 1) {
  2523. var origResolve = Promise.resolve;
  2524. overrideNative(Promise, 'resolve', function resolve(x) {
  2525. return ES.Call(origResolve, this, arguments);
  2526. });
  2527. }
  2528. if (Promise.reject.length !== 1) {
  2529. var origReject = Promise.reject;
  2530. overrideNative(Promise, 'reject', function reject(r) {
  2531. return ES.Call(origReject, this, arguments);
  2532. });
  2533. }
  2534. ensureEnumerable(Promise, 'all');
  2535. ensureEnumerable(Promise, 'race');
  2536. ensureEnumerable(Promise, 'resolve');
  2537. ensureEnumerable(Promise, 'reject');
  2538. addDefaultSpecies(Promise);
  2539. }
  2540. // Map and Set require a true ES5 environment
  2541. // Their fast path also requires that the environment preserve
  2542. // property insertion order, which is not guaranteed by the spec.
  2543. var testOrder = function (a) {
  2544. var b = keys(_reduce(a, function (o, k) {
  2545. o[k] = true;
  2546. return o;
  2547. }, {}));
  2548. return a.join(':') === b.join(':');
  2549. };
  2550. var preservesInsertionOrder = testOrder(['z', 'a', 'bb']);
  2551. // some engines (eg, Chrome) only preserve insertion order for string keys
  2552. var preservesNumericInsertionOrder = testOrder(['z', 1, 'a', '3', 2]);
  2553. if (supportsDescriptors) {
  2554. var fastkey = function fastkey(key, skipInsertionOrderCheck) {
  2555. if (!skipInsertionOrderCheck && !preservesInsertionOrder) {
  2556. return null;
  2557. }
  2558. if (isNullOrUndefined(key)) {
  2559. return '^' + ES.ToString(key);
  2560. } else if (typeof key === 'string') {
  2561. return '$' + key;
  2562. } else if (typeof key === 'number') {
  2563. // note that -0 will get coerced to "0" when used as a property key
  2564. if (!preservesNumericInsertionOrder) {
  2565. return 'n' + key;
  2566. }
  2567. return key;
  2568. } else if (typeof key === 'boolean') {
  2569. return 'b' + key;
  2570. }
  2571. return null;
  2572. };
  2573. var emptyObject = function emptyObject() {
  2574. // accomodate some older not-quite-ES5 browsers
  2575. return Object.create ? Object.create(null) : {};
  2576. };
  2577. var addIterableToMap = function addIterableToMap(MapConstructor, map, iterable) {
  2578. if (isArray(iterable) || Type.string(iterable)) {
  2579. _forEach(iterable, function (entry) {
  2580. if (!ES.TypeIsObject(entry)) {
  2581. throw new TypeError('Iterator value ' + entry + ' is not an entry object');
  2582. }
  2583. map.set(entry[0], entry[1]);
  2584. });
  2585. } else if (iterable instanceof MapConstructor) {
  2586. _call(MapConstructor.prototype.forEach, iterable, function (value, key) {
  2587. map.set(key, value);
  2588. });
  2589. } else {
  2590. var iter, adder;
  2591. if (!isNullOrUndefined(iterable)) {
  2592. adder = map.set;
  2593. if (!ES.IsCallable(adder)) { throw new TypeError('bad map'); }
  2594. iter = ES.GetIterator(iterable);
  2595. }
  2596. if (typeof iter !== 'undefined') {
  2597. while (true) {
  2598. var next = ES.IteratorStep(iter);
  2599. if (next === false) { break; }
  2600. var nextItem = next.value;
  2601. try {
  2602. if (!ES.TypeIsObject(nextItem)) {
  2603. throw new TypeError('Iterator value ' + nextItem + ' is not an entry object');
  2604. }
  2605. _call(adder, map, nextItem[0], nextItem[1]);
  2606. } catch (e) {
  2607. ES.IteratorClose(iter, true);
  2608. throw e;
  2609. }
  2610. }
  2611. }
  2612. }
  2613. };
  2614. var addIterableToSet = function addIterableToSet(SetConstructor, set, iterable) {
  2615. if (isArray(iterable) || Type.string(iterable)) {
  2616. _forEach(iterable, function (value) {
  2617. set.add(value);
  2618. });
  2619. } else if (iterable instanceof SetConstructor) {
  2620. _call(SetConstructor.prototype.forEach, iterable, function (value) {
  2621. set.add(value);
  2622. });
  2623. } else {
  2624. var iter, adder;
  2625. if (!isNullOrUndefined(iterable)) {
  2626. adder = set.add;
  2627. if (!ES.IsCallable(adder)) { throw new TypeError('bad set'); }
  2628. iter = ES.GetIterator(iterable);
  2629. }
  2630. if (typeof iter !== 'undefined') {
  2631. while (true) {
  2632. var next = ES.IteratorStep(iter);
  2633. if (next === false) { break; }
  2634. var nextValue = next.value;
  2635. try {
  2636. _call(adder, set, nextValue);
  2637. } catch (e) {
  2638. ES.IteratorClose(iter, true);
  2639. throw e;
  2640. }
  2641. }
  2642. }
  2643. }
  2644. };
  2645. var collectionShims = {
  2646. Map: (function () {
  2647. var empty = {};
  2648. var MapEntry = function MapEntry(key, value) {
  2649. this.key = key;
  2650. this.value = value;
  2651. this.next = null;
  2652. this.prev = null;
  2653. };
  2654. MapEntry.prototype.isRemoved = function isRemoved() {
  2655. return this.key === empty;
  2656. };
  2657. var isMap = function isMap(map) {
  2658. return !!map._es6map;
  2659. };
  2660. var requireMapSlot = function requireMapSlot(map, method) {
  2661. if (!ES.TypeIsObject(map) || !isMap(map)) {
  2662. throw new TypeError('Method Map.prototype.' + method + ' called on incompatible receiver ' + ES.ToString(map));
  2663. }
  2664. };
  2665. var MapIterator = function MapIterator(map, kind) {
  2666. requireMapSlot(map, '[[MapIterator]]');
  2667. defineProperty(this, 'head', map._head);
  2668. defineProperty(this, 'i', this.head);
  2669. defineProperty(this, 'kind', kind);
  2670. };
  2671. MapIterator.prototype = {
  2672. isMapIterator: true,
  2673. next: function next() {
  2674. if (!this.isMapIterator) {
  2675. throw new TypeError('Not a MapIterator');
  2676. }
  2677. var i = this.i;
  2678. var kind = this.kind;
  2679. var head = this.head;
  2680. if (typeof this.i === 'undefined') {
  2681. return iteratorResult();
  2682. }
  2683. while (i.isRemoved() && i !== head) {
  2684. // back up off of removed entries
  2685. i = i.prev;
  2686. }
  2687. // advance to next unreturned element.
  2688. var result;
  2689. while (i.next !== head) {
  2690. i = i.next;
  2691. if (!i.isRemoved()) {
  2692. if (kind === 'key') {
  2693. result = i.key;
  2694. } else if (kind === 'value') {
  2695. result = i.value;
  2696. } else {
  2697. result = [i.key, i.value];
  2698. }
  2699. this.i = i;
  2700. return iteratorResult(result);
  2701. }
  2702. }
  2703. // once the iterator is done, it is done forever.
  2704. this.i = void 0;
  2705. return iteratorResult();
  2706. }
  2707. };
  2708. addIterator(MapIterator.prototype);
  2709. var Map$prototype;
  2710. var MapShim = function Map() {
  2711. if (!(this instanceof Map)) {
  2712. throw new TypeError('Constructor Map requires "new"');
  2713. }
  2714. if (this && this._es6map) {
  2715. throw new TypeError('Bad construction');
  2716. }
  2717. var map = emulateES6construct(this, Map, Map$prototype, {
  2718. _es6map: true,
  2719. _head: null,
  2720. _map: OrigMap ? new OrigMap() : null,
  2721. _size: 0,
  2722. _storage: emptyObject()
  2723. });
  2724. var head = new MapEntry(null, null);
  2725. // circular doubly-linked list.
  2726. /* eslint no-multi-assign: 1 */
  2727. head.next = head.prev = head;
  2728. map._head = head;
  2729. // Optionally initialize map from iterable
  2730. if (arguments.length > 0) {
  2731. addIterableToMap(Map, map, arguments[0]);
  2732. }
  2733. return map;
  2734. };
  2735. Map$prototype = MapShim.prototype;
  2736. Value.getter(Map$prototype, 'size', function () {
  2737. if (typeof this._size === 'undefined') {
  2738. throw new TypeError('size method called on incompatible Map');
  2739. }
  2740. return this._size;
  2741. });
  2742. defineProperties(Map$prototype, {
  2743. get: function get(key) {
  2744. requireMapSlot(this, 'get');
  2745. var entry;
  2746. var fkey = fastkey(key, true);
  2747. if (fkey !== null) {
  2748. // fast O(1) path
  2749. entry = this._storage[fkey];
  2750. if (entry) {
  2751. return entry.value;
  2752. }
  2753. return;
  2754. }
  2755. if (this._map) {
  2756. // fast object key path
  2757. entry = origMapGet.call(this._map, key);
  2758. if (entry) {
  2759. return entry.value;
  2760. }
  2761. return;
  2762. }
  2763. var head = this._head;
  2764. var i = head;
  2765. while ((i = i.next) !== head) {
  2766. if (ES.SameValueZero(i.key, key)) {
  2767. return i.value;
  2768. }
  2769. }
  2770. },
  2771. has: function has(key) {
  2772. requireMapSlot(this, 'has');
  2773. var fkey = fastkey(key, true);
  2774. if (fkey !== null) {
  2775. // fast O(1) path
  2776. return typeof this._storage[fkey] !== 'undefined';
  2777. }
  2778. if (this._map) {
  2779. // fast object key path
  2780. return origMapHas.call(this._map, key);
  2781. }
  2782. var head = this._head;
  2783. var i = head;
  2784. while ((i = i.next) !== head) {
  2785. if (ES.SameValueZero(i.key, key)) {
  2786. return true;
  2787. }
  2788. }
  2789. return false;
  2790. },
  2791. set: function set(key, value) {
  2792. requireMapSlot(this, 'set');
  2793. var head = this._head;
  2794. var i = head;
  2795. var entry;
  2796. var fkey = fastkey(key, true);
  2797. if (fkey !== null) {
  2798. // fast O(1) path
  2799. if (typeof this._storage[fkey] !== 'undefined') {
  2800. this._storage[fkey].value = value;
  2801. return this;
  2802. }
  2803. entry = this._storage[fkey] = new MapEntry(key, value); /* eslint no-multi-assign: 1 */
  2804. i = head.prev;
  2805. // fall through
  2806. } else if (this._map) {
  2807. // fast object key path
  2808. if (origMapHas.call(this._map, key)) {
  2809. origMapGet.call(this._map, key).value = value;
  2810. } else {
  2811. entry = new MapEntry(key, value);
  2812. origMapSet.call(this._map, key, entry);
  2813. i = head.prev;
  2814. // fall through
  2815. }
  2816. }
  2817. while ((i = i.next) !== head) {
  2818. if (ES.SameValueZero(i.key, key)) {
  2819. i.value = value;
  2820. return this;
  2821. }
  2822. }
  2823. entry = entry || new MapEntry(key, value);
  2824. if (ES.SameValue(-0, key)) {
  2825. entry.key = +0; // coerce -0 to +0 in entry
  2826. }
  2827. entry.next = this._head;
  2828. entry.prev = this._head.prev;
  2829. entry.prev.next = entry;
  2830. entry.next.prev = entry;
  2831. this._size += 1;
  2832. return this;
  2833. },
  2834. 'delete': function (key) {
  2835. requireMapSlot(this, 'delete');
  2836. var head = this._head;
  2837. var i = head;
  2838. var fkey = fastkey(key, true);
  2839. if (fkey !== null) {
  2840. // fast O(1) path
  2841. if (typeof this._storage[fkey] === 'undefined') {
  2842. return false;
  2843. }
  2844. i = this._storage[fkey].prev;
  2845. delete this._storage[fkey];
  2846. // fall through
  2847. } else if (this._map) {
  2848. // fast object key path
  2849. if (!origMapHas.call(this._map, key)) {
  2850. return false;
  2851. }
  2852. i = origMapGet.call(this._map, key).prev;
  2853. origMapDelete.call(this._map, key);
  2854. // fall through
  2855. }
  2856. while ((i = i.next) !== head) {
  2857. if (ES.SameValueZero(i.key, key)) {
  2858. i.key = empty;
  2859. i.value = empty;
  2860. i.prev.next = i.next;
  2861. i.next.prev = i.prev;
  2862. this._size -= 1;
  2863. return true;
  2864. }
  2865. }
  2866. return false;
  2867. },
  2868. clear: function clear() {
  2869. /* eslint no-multi-assign: 1 */
  2870. requireMapSlot(this, 'clear');
  2871. this._map = OrigMap ? new OrigMap() : null;
  2872. this._size = 0;
  2873. this._storage = emptyObject();
  2874. var head = this._head;
  2875. var i = head;
  2876. var p = i.next;
  2877. while ((i = p) !== head) {
  2878. i.key = empty;
  2879. i.value = empty;
  2880. p = i.next;
  2881. i.next = i.prev = head;
  2882. }
  2883. head.next = head.prev = head;
  2884. },
  2885. keys: function keys() {
  2886. requireMapSlot(this, 'keys');
  2887. return new MapIterator(this, 'key');
  2888. },
  2889. values: function values() {
  2890. requireMapSlot(this, 'values');
  2891. return new MapIterator(this, 'value');
  2892. },
  2893. entries: function entries() {
  2894. requireMapSlot(this, 'entries');
  2895. return new MapIterator(this, 'key+value');
  2896. },
  2897. forEach: function forEach(callback) {
  2898. requireMapSlot(this, 'forEach');
  2899. var context = arguments.length > 1 ? arguments[1] : null;
  2900. var it = this.entries();
  2901. for (var entry = it.next(); !entry.done; entry = it.next()) {
  2902. if (context) {
  2903. _call(callback, context, entry.value[1], entry.value[0], this);
  2904. } else {
  2905. callback(entry.value[1], entry.value[0], this);
  2906. }
  2907. }
  2908. }
  2909. });
  2910. addIterator(Map$prototype, Map$prototype.entries);
  2911. return MapShim;
  2912. }()),
  2913. Set: (function () {
  2914. var isSet = function isSet(set) {
  2915. return set._es6set && typeof set._storage !== 'undefined';
  2916. };
  2917. var requireSetSlot = function requireSetSlot(set, method) {
  2918. if (!ES.TypeIsObject(set) || !isSet(set)) {
  2919. // https://github.com/paulmillr/es6-shim/issues/176
  2920. throw new TypeError('Set.prototype.' + method + ' called on incompatible receiver ' + ES.ToString(set));
  2921. }
  2922. };
  2923. // Creating a Map is expensive. To speed up the common case of
  2924. // Sets containing only string or numeric keys, we use an object
  2925. // as backing storage and lazily create a full Map only when
  2926. // required.
  2927. var Set$prototype;
  2928. var SetShim = function Set() {
  2929. if (!(this instanceof Set)) {
  2930. throw new TypeError('Constructor Set requires "new"');
  2931. }
  2932. if (this && this._es6set) {
  2933. throw new TypeError('Bad construction');
  2934. }
  2935. var set = emulateES6construct(this, Set, Set$prototype, {
  2936. _es6set: true,
  2937. '[[SetData]]': null,
  2938. _storage: emptyObject()
  2939. });
  2940. if (!set._es6set) {
  2941. throw new TypeError('bad set');
  2942. }
  2943. // Optionally initialize Set from iterable
  2944. if (arguments.length > 0) {
  2945. addIterableToSet(Set, set, arguments[0]);
  2946. }
  2947. return set;
  2948. };
  2949. Set$prototype = SetShim.prototype;
  2950. var decodeKey = function (key) {
  2951. var k = key;
  2952. if (k === '^null') {
  2953. return null;
  2954. } else if (k === '^undefined') {
  2955. return void 0;
  2956. }
  2957. var first = k.charAt(0);
  2958. if (first === '$') {
  2959. return _strSlice(k, 1);
  2960. } else if (first === 'n') {
  2961. return +_strSlice(k, 1);
  2962. } else if (first === 'b') {
  2963. return k === 'btrue';
  2964. }
  2965. return +k;
  2966. };
  2967. // Switch from the object backing storage to a full Map.
  2968. var ensureMap = function ensureMap(set) {
  2969. if (!set['[[SetData]]']) {
  2970. var m = new collectionShims.Map();
  2971. set['[[SetData]]'] = m;
  2972. _forEach(keys(set._storage), function (key) {
  2973. var k = decodeKey(key);
  2974. m.set(k, k);
  2975. });
  2976. set['[[SetData]]'] = m;
  2977. }
  2978. set._storage = null; // free old backing storage
  2979. };
  2980. Value.getter(SetShim.prototype, 'size', function () {
  2981. requireSetSlot(this, 'size');
  2982. if (this._storage) {
  2983. return keys(this._storage).length;
  2984. }
  2985. ensureMap(this);
  2986. return this['[[SetData]]'].size;
  2987. });
  2988. defineProperties(SetShim.prototype, {
  2989. has: function has(key) {
  2990. requireSetSlot(this, 'has');
  2991. var fkey;
  2992. if (this._storage && (fkey = fastkey(key)) !== null) {
  2993. return !!this._storage[fkey];
  2994. }
  2995. ensureMap(this);
  2996. return this['[[SetData]]'].has(key);
  2997. },
  2998. add: function add(key) {
  2999. requireSetSlot(this, 'add');
  3000. var fkey;
  3001. if (this._storage && (fkey = fastkey(key)) !== null) {
  3002. this._storage[fkey] = true;
  3003. return this;
  3004. }
  3005. ensureMap(this);
  3006. this['[[SetData]]'].set(key, key);
  3007. return this;
  3008. },
  3009. 'delete': function (key) {
  3010. requireSetSlot(this, 'delete');
  3011. var fkey;
  3012. if (this._storage && (fkey = fastkey(key)) !== null) {
  3013. var hasFKey = _hasOwnProperty(this._storage, fkey);
  3014. return (delete this._storage[fkey]) && hasFKey;
  3015. }
  3016. ensureMap(this);
  3017. return this['[[SetData]]']['delete'](key);
  3018. },
  3019. clear: function clear() {
  3020. requireSetSlot(this, 'clear');
  3021. if (this._storage) {
  3022. this._storage = emptyObject();
  3023. }
  3024. if (this['[[SetData]]']) {
  3025. this['[[SetData]]'].clear();
  3026. }
  3027. },
  3028. values: function values() {
  3029. requireSetSlot(this, 'values');
  3030. ensureMap(this);
  3031. return new SetIterator(this['[[SetData]]'].values());
  3032. },
  3033. entries: function entries() {
  3034. requireSetSlot(this, 'entries');
  3035. ensureMap(this);
  3036. return new SetIterator(this['[[SetData]]'].entries());
  3037. },
  3038. forEach: function forEach(callback) {
  3039. requireSetSlot(this, 'forEach');
  3040. var context = arguments.length > 1 ? arguments[1] : null;
  3041. var entireSet = this;
  3042. ensureMap(entireSet);
  3043. this['[[SetData]]'].forEach(function (value, key) {
  3044. if (context) {
  3045. _call(callback, context, key, key, entireSet);
  3046. } else {
  3047. callback(key, key, entireSet);
  3048. }
  3049. });
  3050. }
  3051. });
  3052. defineProperty(SetShim.prototype, 'keys', SetShim.prototype.values, true);
  3053. addIterator(SetShim.prototype, SetShim.prototype.values);
  3054. var SetIterator = function SetIterator(it) {
  3055. defineProperty(this, 'it', it);
  3056. };
  3057. SetIterator.prototype = {
  3058. isSetIterator: true,
  3059. next: function next() {
  3060. if (!this.isSetIterator) {
  3061. throw new TypeError('Not a SetIterator');
  3062. }
  3063. return this.it.next();
  3064. }
  3065. };
  3066. addIterator(SetIterator.prototype);
  3067. return SetShim;
  3068. }())
  3069. };
  3070. var isGoogleTranslate = globals.Set && !Set.prototype['delete'] && Set.prototype.remove && Set.prototype.items && Set.prototype.map && Array.isArray(new Set().keys);
  3071. if (isGoogleTranslate) {
  3072. // special-case force removal of wildly invalid Set implementation in Google Translate iframes
  3073. // see https://github.com/paulmillr/es6-shim/issues/438 / https://twitter.com/ljharb/status/849335573114363904
  3074. globals.Set = collectionShims.Set;
  3075. }
  3076. if (globals.Map || globals.Set) {
  3077. // Safari 8, for example, doesn't accept an iterable.
  3078. var mapAcceptsArguments = valueOrFalseIfThrows(function () { return new Map([[1, 2]]).get(1) === 2; });
  3079. if (!mapAcceptsArguments) {
  3080. globals.Map = function Map() {
  3081. if (!(this instanceof Map)) {
  3082. throw new TypeError('Constructor Map requires "new"');
  3083. }
  3084. var m = new OrigMap();
  3085. if (arguments.length > 0) {
  3086. addIterableToMap(Map, m, arguments[0]);
  3087. }
  3088. delete m.constructor;
  3089. Object.setPrototypeOf(m, globals.Map.prototype);
  3090. return m;
  3091. };
  3092. globals.Map.prototype = create(OrigMap.prototype);
  3093. defineProperty(globals.Map.prototype, 'constructor', globals.Map, true);
  3094. Value.preserveToString(globals.Map, OrigMap);
  3095. }
  3096. var testMap = new Map();
  3097. var mapUsesSameValueZero = (function () {
  3098. // Chrome 38-42, node 0.11/0.12, iojs 1/2 also have a bug when the Map has a size > 4
  3099. var m = new Map([[1, 0], [2, 0], [3, 0], [4, 0]]);
  3100. m.set(-0, m);
  3101. return m.get(0) === m && m.get(-0) === m && m.has(0) && m.has(-0);
  3102. }());
  3103. var mapSupportsChaining = testMap.set(1, 2) === testMap;
  3104. if (!mapUsesSameValueZero || !mapSupportsChaining) {
  3105. overrideNative(Map.prototype, 'set', function set(k, v) {
  3106. _call(origMapSet, this, k === 0 ? 0 : k, v);
  3107. return this;
  3108. });
  3109. }
  3110. if (!mapUsesSameValueZero) {
  3111. defineProperties(Map.prototype, {
  3112. get: function get(k) {
  3113. return _call(origMapGet, this, k === 0 ? 0 : k);
  3114. },
  3115. has: function has(k) {
  3116. return _call(origMapHas, this, k === 0 ? 0 : k);
  3117. }
  3118. }, true);
  3119. Value.preserveToString(Map.prototype.get, origMapGet);
  3120. Value.preserveToString(Map.prototype.has, origMapHas);
  3121. }
  3122. var testSet = new Set();
  3123. var setUsesSameValueZero = Set.prototype['delete'] && Set.prototype.add && Set.prototype.has && (function (s) {
  3124. s['delete'](0);
  3125. s.add(-0);
  3126. return !s.has(0);
  3127. }(testSet));
  3128. var setSupportsChaining = testSet.add(1) === testSet;
  3129. if (!setUsesSameValueZero || !setSupportsChaining) {
  3130. var origSetAdd = Set.prototype.add;
  3131. Set.prototype.add = function add(v) {
  3132. _call(origSetAdd, this, v === 0 ? 0 : v);
  3133. return this;
  3134. };
  3135. Value.preserveToString(Set.prototype.add, origSetAdd);
  3136. }
  3137. if (!setUsesSameValueZero) {
  3138. var origSetHas = Set.prototype.has;
  3139. Set.prototype.has = function has(v) {
  3140. return _call(origSetHas, this, v === 0 ? 0 : v);
  3141. };
  3142. Value.preserveToString(Set.prototype.has, origSetHas);
  3143. var origSetDel = Set.prototype['delete'];
  3144. Set.prototype['delete'] = function SetDelete(v) {
  3145. return _call(origSetDel, this, v === 0 ? 0 : v);
  3146. };
  3147. Value.preserveToString(Set.prototype['delete'], origSetDel);
  3148. }
  3149. var mapSupportsSubclassing = supportsSubclassing(globals.Map, function (M) {
  3150. var m = new M([]);
  3151. // Firefox 32 is ok with the instantiating the subclass but will
  3152. // throw when the map is used.
  3153. m.set(42, 42);
  3154. return m instanceof M;
  3155. });
  3156. // without Object.setPrototypeOf, subclassing is not possible
  3157. var mapFailsToSupportSubclassing = Object.setPrototypeOf && !mapSupportsSubclassing;
  3158. var mapRequiresNew = (function () {
  3159. try {
  3160. return !(globals.Map() instanceof globals.Map);
  3161. } catch (e) {
  3162. return e instanceof TypeError;
  3163. }
  3164. }());
  3165. if (globals.Map.length !== 0 || mapFailsToSupportSubclassing || !mapRequiresNew) {
  3166. globals.Map = function Map() {
  3167. if (!(this instanceof Map)) {
  3168. throw new TypeError('Constructor Map requires "new"');
  3169. }
  3170. var m = new OrigMap();
  3171. if (arguments.length > 0) {
  3172. addIterableToMap(Map, m, arguments[0]);
  3173. }
  3174. delete m.constructor;
  3175. Object.setPrototypeOf(m, Map.prototype);
  3176. return m;
  3177. };
  3178. globals.Map.prototype = OrigMap.prototype;
  3179. defineProperty(globals.Map.prototype, 'constructor', globals.Map, true);
  3180. Value.preserveToString(globals.Map, OrigMap);
  3181. }
  3182. var setSupportsSubclassing = supportsSubclassing(globals.Set, function (S) {
  3183. var s = new S([]);
  3184. s.add(42, 42);
  3185. return s instanceof S;
  3186. });
  3187. // without Object.setPrototypeOf, subclassing is not possible
  3188. var setFailsToSupportSubclassing = Object.setPrototypeOf && !setSupportsSubclassing;
  3189. var setRequiresNew = (function () {
  3190. try {
  3191. return !(globals.Set() instanceof globals.Set);
  3192. } catch (e) {
  3193. return e instanceof TypeError;
  3194. }
  3195. }());
  3196. if (globals.Set.length !== 0 || setFailsToSupportSubclassing || !setRequiresNew) {
  3197. var OrigSet = globals.Set;
  3198. globals.Set = function Set() {
  3199. if (!(this instanceof Set)) {
  3200. throw new TypeError('Constructor Set requires "new"');
  3201. }
  3202. var s = new OrigSet();
  3203. if (arguments.length > 0) {
  3204. addIterableToSet(Set, s, arguments[0]);
  3205. }
  3206. delete s.constructor;
  3207. Object.setPrototypeOf(s, Set.prototype);
  3208. return s;
  3209. };
  3210. globals.Set.prototype = OrigSet.prototype;
  3211. defineProperty(globals.Set.prototype, 'constructor', globals.Set, true);
  3212. Value.preserveToString(globals.Set, OrigSet);
  3213. }
  3214. var newMap = new globals.Map();
  3215. var mapIterationThrowsStopIterator = !valueOrFalseIfThrows(function () {
  3216. return newMap.keys().next().done;
  3217. });
  3218. /*
  3219. - In Firefox < 23, Map#size is a function.
  3220. - In all current Firefox, Set#entries/keys/values & Map#clear do not exist
  3221. - https://bugzilla.mozilla.org/show_bug.cgi?id=869996
  3222. - In Firefox 24, Map and Set do not implement forEach
  3223. - In Firefox 25 at least, Map and Set are callable without "new"
  3224. */
  3225. if (
  3226. typeof globals.Map.prototype.clear !== 'function'
  3227. || new globals.Set().size !== 0
  3228. || newMap.size !== 0
  3229. || typeof globals.Map.prototype.keys !== 'function'
  3230. || typeof globals.Set.prototype.keys !== 'function'
  3231. || typeof globals.Map.prototype.forEach !== 'function'
  3232. || typeof globals.Set.prototype.forEach !== 'function'
  3233. || isCallableWithoutNew(globals.Map)
  3234. || isCallableWithoutNew(globals.Set)
  3235. || typeof newMap.keys().next !== 'function' // Safari 8
  3236. || mapIterationThrowsStopIterator // Firefox 25
  3237. || !mapSupportsSubclassing
  3238. ) {
  3239. defineProperties(globals, {
  3240. Map: collectionShims.Map,
  3241. Set: collectionShims.Set
  3242. }, true);
  3243. }
  3244. if (globals.Set.prototype.keys !== globals.Set.prototype.values) {
  3245. // Fixed in WebKit with https://bugs.webkit.org/show_bug.cgi?id=144190
  3246. defineProperty(globals.Set.prototype, 'keys', globals.Set.prototype.values, true);
  3247. }
  3248. // Shim incomplete iterator implementations.
  3249. addIterator(Object.getPrototypeOf((new globals.Map()).keys()));
  3250. addIterator(Object.getPrototypeOf((new globals.Set()).keys()));
  3251. if (functionsHaveNames && globals.Set.prototype.has.name !== 'has') {
  3252. // Microsoft Edge v0.11.10074.0 is missing a name on Set#has
  3253. var anonymousSetHas = globals.Set.prototype.has;
  3254. overrideNative(globals.Set.prototype, 'has', function has(key) {
  3255. return _call(anonymousSetHas, this, key);
  3256. });
  3257. }
  3258. }
  3259. defineProperties(globals, collectionShims);
  3260. addDefaultSpecies(globals.Map);
  3261. addDefaultSpecies(globals.Set);
  3262. }
  3263. var throwUnlessTargetIsObject = function throwUnlessTargetIsObject(target) {
  3264. if (!ES.TypeIsObject(target)) {
  3265. throw new TypeError('target must be an object');
  3266. }
  3267. };
  3268. // Some Reflect methods are basically the same as
  3269. // those on the Object global, except that a TypeError is thrown if
  3270. // target isn't an object. As well as returning a boolean indicating
  3271. // the success of the operation.
  3272. var ReflectShims = {
  3273. // Apply method in a functional form.
  3274. apply: function apply() {
  3275. return ES.Call(ES.Call, null, arguments);
  3276. },
  3277. // New operator in a functional form.
  3278. construct: function construct(constructor, args) {
  3279. if (!ES.IsConstructor(constructor)) {
  3280. throw new TypeError('First argument must be a constructor.');
  3281. }
  3282. var newTarget = arguments.length > 2 ? arguments[2] : constructor;
  3283. if (!ES.IsConstructor(newTarget)) {
  3284. throw new TypeError('new.target must be a constructor.');
  3285. }
  3286. return ES.Construct(constructor, args, newTarget, 'internal');
  3287. },
  3288. // When deleting a non-existent or configurable property,
  3289. // true is returned.
  3290. // When attempting to delete a non-configurable property,
  3291. // it will return false.
  3292. deleteProperty: function deleteProperty(target, key) {
  3293. throwUnlessTargetIsObject(target);
  3294. if (supportsDescriptors) {
  3295. var desc = Object.getOwnPropertyDescriptor(target, key);
  3296. if (desc && !desc.configurable) {
  3297. return false;
  3298. }
  3299. }
  3300. // Will return true.
  3301. return delete target[key];
  3302. },
  3303. has: function has(target, key) {
  3304. throwUnlessTargetIsObject(target);
  3305. return key in target;
  3306. }
  3307. };
  3308. if (Object.getOwnPropertyNames) {
  3309. Object.assign(ReflectShims, {
  3310. // Basically the result of calling the internal [[OwnPropertyKeys]].
  3311. // Concatenating propertyNames and propertySymbols should do the trick.
  3312. // This should continue to work together with a Symbol shim
  3313. // which overrides Object.getOwnPropertyNames and implements
  3314. // Object.getOwnPropertySymbols.
  3315. ownKeys: function ownKeys(target) {
  3316. throwUnlessTargetIsObject(target);
  3317. var keys = Object.getOwnPropertyNames(target);
  3318. if (ES.IsCallable(Object.getOwnPropertySymbols)) {
  3319. _pushApply(keys, Object.getOwnPropertySymbols(target));
  3320. }
  3321. return keys;
  3322. }
  3323. });
  3324. }
  3325. var callAndCatchException = function ConvertExceptionToBoolean(func) {
  3326. return !throwsError(func);
  3327. };
  3328. if (Object.preventExtensions) {
  3329. Object.assign(ReflectShims, {
  3330. isExtensible: function isExtensible(target) {
  3331. throwUnlessTargetIsObject(target);
  3332. return Object.isExtensible(target);
  3333. },
  3334. preventExtensions: function preventExtensions(target) {
  3335. throwUnlessTargetIsObject(target);
  3336. return callAndCatchException(function () {
  3337. return Object.preventExtensions(target);
  3338. });
  3339. }
  3340. });
  3341. }
  3342. if (supportsDescriptors) {
  3343. var internalGet = function get(target, key, receiver) {
  3344. var desc = Object.getOwnPropertyDescriptor(target, key);
  3345. if (!desc) {
  3346. var parent = Object.getPrototypeOf(target);
  3347. if (parent === null) {
  3348. return void 0;
  3349. }
  3350. return internalGet(parent, key, receiver);
  3351. }
  3352. if ('value' in desc) {
  3353. return desc.value;
  3354. }
  3355. if (desc.get) {
  3356. return ES.Call(desc.get, receiver);
  3357. }
  3358. return void 0;
  3359. };
  3360. var internalSet = function set(target, key, value, receiver) {
  3361. var desc = Object.getOwnPropertyDescriptor(target, key);
  3362. if (!desc) {
  3363. var parent = Object.getPrototypeOf(target);
  3364. if (parent !== null) {
  3365. return internalSet(parent, key, value, receiver);
  3366. }
  3367. desc = {
  3368. value: void 0,
  3369. writable: true,
  3370. enumerable: true,
  3371. configurable: true
  3372. };
  3373. }
  3374. if ('value' in desc) {
  3375. if (!desc.writable) {
  3376. return false;
  3377. }
  3378. if (!ES.TypeIsObject(receiver)) {
  3379. return false;
  3380. }
  3381. var existingDesc = Object.getOwnPropertyDescriptor(receiver, key);
  3382. if (existingDesc) {
  3383. return Reflect.defineProperty(receiver, key, {
  3384. value: value
  3385. });
  3386. }
  3387. return Reflect.defineProperty(receiver, key, {
  3388. value: value,
  3389. writable: true,
  3390. enumerable: true,
  3391. configurable: true
  3392. });
  3393. }
  3394. if (desc.set) {
  3395. _call(desc.set, receiver, value);
  3396. return true;
  3397. }
  3398. return false;
  3399. };
  3400. Object.assign(ReflectShims, {
  3401. defineProperty: function defineProperty(target, propertyKey, attributes) {
  3402. throwUnlessTargetIsObject(target);
  3403. return callAndCatchException(function () {
  3404. return Object.defineProperty(target, propertyKey, attributes);
  3405. });
  3406. },
  3407. getOwnPropertyDescriptor: function getOwnPropertyDescriptor(target, propertyKey) {
  3408. throwUnlessTargetIsObject(target);
  3409. return Object.getOwnPropertyDescriptor(target, propertyKey);
  3410. },
  3411. // Syntax in a functional form.
  3412. get: function get(target, key) {
  3413. throwUnlessTargetIsObject(target);
  3414. var receiver = arguments.length > 2 ? arguments[2] : target;
  3415. return internalGet(target, key, receiver);
  3416. },
  3417. set: function set(target, key, value) {
  3418. throwUnlessTargetIsObject(target);
  3419. var receiver = arguments.length > 3 ? arguments[3] : target;
  3420. return internalSet(target, key, value, receiver);
  3421. }
  3422. });
  3423. }
  3424. if (Object.getPrototypeOf) {
  3425. var objectDotGetPrototypeOf = Object.getPrototypeOf;
  3426. ReflectShims.getPrototypeOf = function getPrototypeOf(target) {
  3427. throwUnlessTargetIsObject(target);
  3428. return objectDotGetPrototypeOf(target);
  3429. };
  3430. }
  3431. if (Object.setPrototypeOf && ReflectShims.getPrototypeOf) {
  3432. var willCreateCircularPrototype = function (object, lastProto) {
  3433. var proto = lastProto;
  3434. while (proto) {
  3435. if (object === proto) {
  3436. return true;
  3437. }
  3438. proto = ReflectShims.getPrototypeOf(proto);
  3439. }
  3440. return false;
  3441. };
  3442. Object.assign(ReflectShims, {
  3443. // Sets the prototype of the given object.
  3444. // Returns true on success, otherwise false.
  3445. setPrototypeOf: function setPrototypeOf(object, proto) {
  3446. throwUnlessTargetIsObject(object);
  3447. if (proto !== null && !ES.TypeIsObject(proto)) {
  3448. throw new TypeError('proto must be an object or null');
  3449. }
  3450. // If they already are the same, we're done.
  3451. if (proto === Reflect.getPrototypeOf(object)) {
  3452. return true;
  3453. }
  3454. // Cannot alter prototype if object not extensible.
  3455. if (Reflect.isExtensible && !Reflect.isExtensible(object)) {
  3456. return false;
  3457. }
  3458. // Ensure that we do not create a circular prototype chain.
  3459. if (willCreateCircularPrototype(object, proto)) {
  3460. return false;
  3461. }
  3462. Object.setPrototypeOf(object, proto);
  3463. return true;
  3464. }
  3465. });
  3466. }
  3467. var defineOrOverrideReflectProperty = function (key, shim) {
  3468. if (!ES.IsCallable(globals.Reflect[key])) {
  3469. defineProperty(globals.Reflect, key, shim);
  3470. } else {
  3471. var acceptsPrimitives = valueOrFalseIfThrows(function () {
  3472. globals.Reflect[key](1);
  3473. globals.Reflect[key](NaN);
  3474. globals.Reflect[key](true);
  3475. return true;
  3476. });
  3477. if (acceptsPrimitives) {
  3478. overrideNative(globals.Reflect, key, shim);
  3479. }
  3480. }
  3481. };
  3482. Object.keys(ReflectShims).forEach(function (key) {
  3483. defineOrOverrideReflectProperty(key, ReflectShims[key]);
  3484. });
  3485. var originalReflectGetProto = globals.Reflect.getPrototypeOf;
  3486. if (functionsHaveNames && originalReflectGetProto && originalReflectGetProto.name !== 'getPrototypeOf') {
  3487. overrideNative(globals.Reflect, 'getPrototypeOf', function getPrototypeOf(target) {
  3488. return _call(originalReflectGetProto, globals.Reflect, target);
  3489. });
  3490. }
  3491. if (globals.Reflect.setPrototypeOf) {
  3492. if (valueOrFalseIfThrows(function () {
  3493. globals.Reflect.setPrototypeOf(1, {});
  3494. return true;
  3495. })) {
  3496. overrideNative(globals.Reflect, 'setPrototypeOf', ReflectShims.setPrototypeOf);
  3497. }
  3498. }
  3499. if (globals.Reflect.defineProperty) {
  3500. if (!valueOrFalseIfThrows(function () {
  3501. var basic = !globals.Reflect.defineProperty(1, 'test', { value: 1 });
  3502. // "extensible" fails on Edge 0.12
  3503. var extensible = typeof Object.preventExtensions !== 'function' || !globals.Reflect.defineProperty(Object.preventExtensions({}), 'test', {});
  3504. return basic && extensible;
  3505. })) {
  3506. overrideNative(globals.Reflect, 'defineProperty', ReflectShims.defineProperty);
  3507. }
  3508. }
  3509. if (globals.Reflect.construct) {
  3510. if (!valueOrFalseIfThrows(function () {
  3511. var F = function F() {};
  3512. return globals.Reflect.construct(function () {}, [], F) instanceof F;
  3513. })) {
  3514. overrideNative(globals.Reflect, 'construct', ReflectShims.construct);
  3515. }
  3516. }
  3517. if (String(new Date(NaN)) !== 'Invalid Date') {
  3518. var dateToString = Date.prototype.toString;
  3519. var shimmedDateToString = function toString() {
  3520. var valueOf = +this;
  3521. if (valueOf !== valueOf) {
  3522. return 'Invalid Date';
  3523. }
  3524. return ES.Call(dateToString, this);
  3525. };
  3526. overrideNative(Date.prototype, 'toString', shimmedDateToString);
  3527. }
  3528. // Annex B HTML methods
  3529. // http://www.ecma-international.org/ecma-262/6.0/#sec-additional-properties-of-the-string.prototype-object
  3530. var stringHTMLshims = {
  3531. anchor: function anchor(name) { return ES.CreateHTML(this, 'a', 'name', name); },
  3532. big: function big() { return ES.CreateHTML(this, 'big', '', ''); },
  3533. blink: function blink() { return ES.CreateHTML(this, 'blink', '', ''); },
  3534. bold: function bold() { return ES.CreateHTML(this, 'b', '', ''); },
  3535. fixed: function fixed() { return ES.CreateHTML(this, 'tt', '', ''); },
  3536. fontcolor: function fontcolor(color) { return ES.CreateHTML(this, 'font', 'color', color); },
  3537. fontsize: function fontsize(size) { return ES.CreateHTML(this, 'font', 'size', size); },
  3538. italics: function italics() { return ES.CreateHTML(this, 'i', '', ''); },
  3539. link: function link(url) { return ES.CreateHTML(this, 'a', 'href', url); },
  3540. small: function small() { return ES.CreateHTML(this, 'small', '', ''); },
  3541. strike: function strike() { return ES.CreateHTML(this, 'strike', '', ''); },
  3542. sub: function sub() { return ES.CreateHTML(this, 'sub', '', ''); },
  3543. sup: function sub() { return ES.CreateHTML(this, 'sup', '', ''); }
  3544. };
  3545. _forEach(Object.keys(stringHTMLshims), function (key) {
  3546. var method = String.prototype[key];
  3547. var shouldOverwrite = false;
  3548. if (ES.IsCallable(method)) {
  3549. var output = _call(method, '', ' " ');
  3550. var quotesCount = _concat([], output.match(/"/g)).length;
  3551. shouldOverwrite = output !== output.toLowerCase() || quotesCount > 2;
  3552. } else {
  3553. shouldOverwrite = true;
  3554. }
  3555. if (shouldOverwrite) {
  3556. overrideNative(String.prototype, key, stringHTMLshims[key]);
  3557. }
  3558. });
  3559. var JSONstringifiesSymbols = (function () {
  3560. // Microsoft Edge v0.12 stringifies Symbols incorrectly
  3561. if (!hasSymbols) { return false; } // Symbols are not supported
  3562. var stringify = typeof JSON === 'object' && typeof JSON.stringify === 'function' ? JSON.stringify : null;
  3563. if (!stringify) { return false; } // JSON.stringify is not supported
  3564. if (typeof stringify(Symbol()) !== 'undefined') { return true; } // Symbols should become `undefined`
  3565. if (stringify([Symbol()]) !== '[null]') { return true; } // Symbols in arrays should become `null`
  3566. var obj = { a: Symbol() };
  3567. obj[Symbol()] = true;
  3568. if (stringify(obj) !== '{}') { return true; } // Symbol-valued keys *and* Symbol-valued properties should be omitted
  3569. return false;
  3570. }());
  3571. var JSONstringifyAcceptsObjectSymbol = valueOrFalseIfThrows(function () {
  3572. // Chrome 45 throws on stringifying object symbols
  3573. if (!hasSymbols) { return true; } // Symbols are not supported
  3574. return JSON.stringify(Object(Symbol())) === '{}' && JSON.stringify([Object(Symbol())]) === '[{}]';
  3575. });
  3576. if (JSONstringifiesSymbols || !JSONstringifyAcceptsObjectSymbol) {
  3577. var origStringify = JSON.stringify;
  3578. overrideNative(JSON, 'stringify', function stringify(value) {
  3579. if (typeof value === 'symbol') { return; }
  3580. var replacer;
  3581. if (arguments.length > 1) {
  3582. replacer = arguments[1];
  3583. }
  3584. var args = [value];
  3585. if (!isArray(replacer)) {
  3586. var replaceFn = ES.IsCallable(replacer) ? replacer : null;
  3587. var wrappedReplacer = function (key, val) {
  3588. var parsedValue = replaceFn ? _call(replaceFn, this, key, val) : val;
  3589. if (typeof parsedValue !== 'symbol') {
  3590. if (Type.symbol(parsedValue)) {
  3591. return assignTo({})(parsedValue);
  3592. }
  3593. return parsedValue;
  3594. }
  3595. };
  3596. args.push(wrappedReplacer);
  3597. } else {
  3598. // create wrapped replacer that handles an array replacer?
  3599. args.push(replacer);
  3600. }
  3601. if (arguments.length > 2) {
  3602. args.push(arguments[2]);
  3603. }
  3604. return origStringify.apply(this, args);
  3605. });
  3606. }
  3607. return globals;
  3608. }));