es5-shim.js 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338
  1. /*!
  2. * https://github.com/es-shims/es5-shim
  3. * @license es5-shim Copyright 2009-2020 by contributors, MIT License
  4. * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
  5. */
  6. // vim: ts=4 sts=4 sw=4 expandtab
  7. // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
  8. ; // eslint-disable-line no-extra-semi
  9. // UMD (Universal Module Definition)
  10. // see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
  11. (function (root, factory) {
  12. 'use strict';
  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 enviroments that support module.exports,
  20. // like Node.
  21. module.exports = factory();
  22. } else {
  23. // Browser globals (root is window)
  24. root.returnExports = factory(); // eslint-disable-line no-param-reassign
  25. }
  26. }(this, function () {
  27. /**
  28. * Brings an environment as close to ECMAScript 5 compliance
  29. * as is possible with the facilities of erstwhile engines.
  30. *
  31. * Annotated ES5: https://es5.github.io/ (specific links below)
  32. * ES5 Spec: https://www.ecma-international.org/wp-content/uploads/ECMA-262_5.1_edition_june_2011.pdf
  33. * Required reading: https://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
  34. */
  35. // Shortcut to an often accessed properties, in order to avoid multiple
  36. // dereference that costs universally. This also holds a reference to known-good
  37. // functions.
  38. var $Array = Array;
  39. var ArrayPrototype = $Array.prototype;
  40. var $Object = Object;
  41. var ObjectPrototype = $Object.prototype;
  42. var $Function = Function;
  43. var FunctionPrototype = $Function.prototype;
  44. var $String = String;
  45. var StringPrototype = $String.prototype;
  46. var $Number = Number;
  47. var NumberPrototype = $Number.prototype;
  48. var array_slice = ArrayPrototype.slice;
  49. var array_splice = ArrayPrototype.splice;
  50. var array_push = ArrayPrototype.push;
  51. var array_unshift = ArrayPrototype.unshift;
  52. var array_concat = ArrayPrototype.concat;
  53. var array_join = ArrayPrototype.join;
  54. var call = FunctionPrototype.call;
  55. var apply = FunctionPrototype.apply;
  56. var max = Math.max;
  57. var min = Math.min;
  58. var floor = Math.floor;
  59. var abs = Math.abs;
  60. var pow = Math.pow;
  61. var round = Math.round;
  62. var log = Math.log;
  63. var LOG10E = Math.LOG10E;
  64. var log10 = Math.log10 || function log10(value) {
  65. return log(value) * LOG10E;
  66. };
  67. // Having a toString local variable name breaks in Opera so use to_string.
  68. var to_string = ObjectPrototype.toString;
  69. /* eslint-disable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
  70. var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
  71. var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, constructorRegex = /^\s*class /, isES6ClassFn = function isES6ClassFn(value) { try { var fnStr = fnToStr.call(value); var singleStripped = fnStr.replace(/\/\/.*\n/g, ''); var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, ''); var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' '); return constructorRegex.test(spaceStripped); } catch (e) { return false; /* not a function */ } }, tryFunctionObject = function tryFunctionObject(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]', isCallable = function isCallable(value) { if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
  72. var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
  73. var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };
  74. /* eslint-enable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
  75. /* inlined from https://npmjs.com/define-properties */
  76. var supportsDescriptors = $Object.defineProperty && (function () {
  77. try {
  78. var obj = {};
  79. $Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
  80. // eslint-disable-next-line no-unreachable-loop, max-statements-per-line
  81. for (var _ in obj) { return false; } // jscs:ignore disallowUnusedVariables
  82. return obj.x === obj;
  83. } catch (e) { /* this is ES3 */
  84. return false;
  85. }
  86. }());
  87. var defineProperties = (function (has) {
  88. // Define configurable, writable, and non-enumerable props
  89. // if they don't exist.
  90. var defineProperty;
  91. if (supportsDescriptors) {
  92. defineProperty = function (object, name, method, forceAssign) {
  93. if (!forceAssign && (name in object)) {
  94. return;
  95. }
  96. $Object.defineProperty(object, name, {
  97. configurable: true,
  98. enumerable: false,
  99. writable: true,
  100. value: method
  101. });
  102. };
  103. } else {
  104. defineProperty = function (object, name, method, forceAssign) {
  105. if (!forceAssign && (name in object)) {
  106. return;
  107. }
  108. object[name] = method; // eslint-disable-line no-param-reassign
  109. };
  110. }
  111. return function defineProperties(object, map, forceAssign) {
  112. for (var name in map) {
  113. if (has.call(map, name)) {
  114. defineProperty(object, name, map[name], forceAssign);
  115. }
  116. }
  117. };
  118. }(ObjectPrototype.hasOwnProperty));
  119. // this is needed in Chrome 15 (probably earlier) - 36
  120. // https://bugs.chromium.org/p/v8/issues/detail?id=3334
  121. if ($Object.defineProperty && supportsDescriptors) {
  122. var F = function () {};
  123. var toStringSentinel = {};
  124. var sentinel = { toString: toStringSentinel };
  125. $Object.defineProperty(F, 'prototype', { value: sentinel, writable: false });
  126. if ((new F()).toString !== toStringSentinel) {
  127. var $dP = $Object.defineProperty;
  128. var $gOPD = $Object.getOwnPropertyDescriptor;
  129. defineProperties($Object, {
  130. defineProperty: function defineProperty(o, k, d) {
  131. var key = $String(k);
  132. if (typeof o === 'function' && key === 'prototype') {
  133. var desc = $gOPD(o, key);
  134. if (desc.writable && !d.writable && 'value' in d) {
  135. try {
  136. o[key] = d.value; // eslint-disable-line no-param-reassign
  137. } catch (e) { /**/ }
  138. }
  139. return $dP(o, key, {
  140. configurable: 'configurable' in d ? d.configurable : desc.configurable,
  141. enumerable: 'enumerable' in d ? d.enumerable : desc.enumerable,
  142. writable: d.writable
  143. });
  144. }
  145. return $dP(o, key, d);
  146. }
  147. }, true);
  148. }
  149. }
  150. //
  151. // Util
  152. // ======
  153. //
  154. /* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
  155. var isPrimitive = function isPrimitive(input) {
  156. var type = typeof input;
  157. return input === null || (type !== 'object' && type !== 'function');
  158. };
  159. var isActualNaN = $Number.isNaN || function isActualNaN(x) {
  160. return x !== x;
  161. };
  162. var ES = {
  163. // ES5 9.4
  164. // https://es5.github.io/#x9.4
  165. // http://jsperf.com/to-integer
  166. /* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
  167. ToInteger: function ToInteger(num) {
  168. var n = +num;
  169. if (isActualNaN(n)) {
  170. n = 0;
  171. } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
  172. n = (n > 0 || -1) * floor(abs(n));
  173. }
  174. return n;
  175. },
  176. /* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
  177. ToPrimitive: function ToPrimitive(input) {
  178. var val, valueOf, toStr;
  179. if (isPrimitive(input)) {
  180. return input;
  181. }
  182. valueOf = input.valueOf;
  183. if (isCallable(valueOf)) {
  184. val = valueOf.call(input);
  185. if (isPrimitive(val)) {
  186. return val;
  187. }
  188. }
  189. toStr = input.toString;
  190. if (isCallable(toStr)) {
  191. val = toStr.call(input);
  192. if (isPrimitive(val)) {
  193. return val;
  194. }
  195. }
  196. throw new TypeError();
  197. },
  198. // ES5 9.9
  199. // https://es5.github.io/#x9.9
  200. /* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
  201. ToObject: function (o) {
  202. if (o == null) { // this matches both null and undefined
  203. throw new TypeError("can't convert " + o + ' to object');
  204. }
  205. return $Object(o);
  206. },
  207. /* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
  208. ToUint32: function ToUint32(x) {
  209. return x >>> 0;
  210. }
  211. };
  212. //
  213. // Function
  214. // ========
  215. //
  216. // ES-5 15.3.4.5
  217. // https://es5.github.io/#x15.3.4.5
  218. var Empty = function Empty() {};
  219. defineProperties(FunctionPrototype, {
  220. bind: function bind(that) { // .length is 1
  221. // 1. Let Target be the this value.
  222. var target = this;
  223. // 2. If IsCallable(Target) is false, throw a TypeError exception.
  224. if (!isCallable(target)) {
  225. throw new TypeError('Function.prototype.bind called on incompatible ' + target);
  226. }
  227. // 3. Let A be a new (possibly empty) internal list of all of the
  228. // argument values provided after thisArg (arg1, arg2 etc), in order.
  229. // XXX slicedArgs will stand in for "A" if used
  230. var args = array_slice.call(arguments, 1); // for normal call
  231. // 4. Let F be a new native ECMAScript object.
  232. // 11. Set the [[Prototype]] internal property of F to the standard
  233. // built-in Function prototype object as specified in 15.3.3.1.
  234. // 12. Set the [[Call]] internal property of F as described in
  235. // 15.3.4.5.1.
  236. // 13. Set the [[Construct]] internal property of F as described in
  237. // 15.3.4.5.2.
  238. // 14. Set the [[HasInstance]] internal property of F as described in
  239. // 15.3.4.5.3.
  240. var bound;
  241. var binder = function () {
  242. if (this instanceof bound) {
  243. // 15.3.4.5.2 [[Construct]]
  244. // When the [[Construct]] internal method of a function object,
  245. // F that was created using the bind function is called with a
  246. // list of arguments ExtraArgs, the following steps are taken:
  247. // 1. Let target be the value of F's [[TargetFunction]]
  248. // internal property.
  249. // 2. If target has no [[Construct]] internal method, a
  250. // TypeError exception is thrown.
  251. // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
  252. // property.
  253. // 4. Let args be a new list containing the same values as the
  254. // list boundArgs in the same order followed by the same
  255. // values as the list ExtraArgs in the same order.
  256. // 5. Return the result of calling the [[Construct]] internal
  257. // method of target providing args as the arguments.
  258. var result = apply.call(
  259. target,
  260. this,
  261. array_concat.call(args, array_slice.call(arguments))
  262. );
  263. if ($Object(result) === result) {
  264. return result;
  265. }
  266. return this;
  267. }
  268. // 15.3.4.5.1 [[Call]]
  269. // When the [[Call]] internal method of a function object, F,
  270. // which was created using the bind function is called with a
  271. // this value and a list of arguments ExtraArgs, the following
  272. // steps are taken:
  273. // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
  274. // property.
  275. // 2. Let boundThis be the value of F's [[BoundThis]] internal
  276. // property.
  277. // 3. Let target be the value of F's [[TargetFunction]] internal
  278. // property.
  279. // 4. Let args be a new list containing the same values as the
  280. // list boundArgs in the same order followed by the same
  281. // values as the list ExtraArgs in the same order.
  282. // 5. Return the result of calling the [[Call]] internal method
  283. // of target providing boundThis as the this value and
  284. // providing args as the arguments.
  285. // equiv: target.call(this, ...boundArgs, ...args)
  286. return apply.call(
  287. target,
  288. that,
  289. array_concat.call(args, array_slice.call(arguments))
  290. );
  291. };
  292. // 15. If the [[Class]] internal property of Target is "Function", then
  293. // a. Let L be the length property of Target minus the length of A.
  294. // b. Set the length own property of F to either 0 or L, whichever is
  295. // larger.
  296. // 16. Else set the length own property of F to 0.
  297. var boundLength = max(0, target.length - args.length);
  298. // 17. Set the attributes of the length own property of F to the values
  299. // specified in 15.3.5.1.
  300. var boundArgs = [];
  301. for (var i = 0; i < boundLength; i++) {
  302. array_push.call(boundArgs, '$' + i);
  303. }
  304. // XXX Build a dynamic function with desired amount of arguments is the only
  305. // way to set the length property of a function.
  306. // In environments where Content Security Policies enabled (Chrome extensions,
  307. // for ex.) all use of eval or Function costructor throws an exception.
  308. // However in all of these environments Function.prototype.bind exists
  309. // and so this code will never be executed.
  310. bound = $Function('binder', 'return function (' + array_join.call(boundArgs, ',') + '){ return binder.apply(this, arguments); }')(binder);
  311. if (target.prototype) {
  312. Empty.prototype = target.prototype;
  313. bound.prototype = new Empty();
  314. // Clean up dangling references.
  315. Empty.prototype = null;
  316. }
  317. // TODO
  318. // 18. Set the [[Extensible]] internal property of F to true.
  319. // TODO
  320. // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
  321. // 20. Call the [[DefineOwnProperty]] internal method of F with
  322. // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
  323. // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
  324. // false.
  325. // 21. Call the [[DefineOwnProperty]] internal method of F with
  326. // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
  327. // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
  328. // and false.
  329. // TODO
  330. // NOTE Function objects created using Function.prototype.bind do not
  331. // have a prototype property or the [[Code]], [[FormalParameters]], and
  332. // [[Scope]] internal properties.
  333. // XXX can't delete prototype in pure-js.
  334. // 22. Return F.
  335. return bound;
  336. }
  337. });
  338. // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
  339. // use it in defining shortcuts.
  340. var owns = call.bind(ObjectPrototype.hasOwnProperty);
  341. var toStr = call.bind(ObjectPrototype.toString);
  342. var arraySlice = call.bind(array_slice);
  343. var arraySliceApply = apply.bind(array_slice);
  344. /* globals document */
  345. if (typeof document === 'object' && document && document.documentElement) {
  346. try {
  347. arraySlice(document.documentElement.childNodes);
  348. } catch (e) {
  349. var origArraySlice = arraySlice;
  350. var origArraySliceApply = arraySliceApply;
  351. arraySlice = function arraySliceIE(arr) {
  352. var r = [];
  353. var i = arr.length;
  354. while (i-- > 0) {
  355. r[i] = arr[i];
  356. }
  357. return origArraySliceApply(r, origArraySlice(arguments, 1));
  358. };
  359. arraySliceApply = function arraySliceApplyIE(arr, args) {
  360. return origArraySliceApply(arraySlice(arr), args);
  361. };
  362. }
  363. }
  364. var strSlice = call.bind(StringPrototype.slice);
  365. var strSplit = call.bind(StringPrototype.split);
  366. var strIndexOf = call.bind(StringPrototype.indexOf);
  367. var pushCall = call.bind(array_push);
  368. var isEnum = call.bind(ObjectPrototype.propertyIsEnumerable);
  369. var arraySort = call.bind(ArrayPrototype.sort);
  370. //
  371. // Array
  372. // =====
  373. //
  374. var isArray = $Array.isArray || function isArray(obj) {
  375. return toStr(obj) === '[object Array]';
  376. };
  377. // ES5 15.4.4.12
  378. // https://es5.github.io/#x15.4.4.13
  379. // Return len+argCount.
  380. // [bugfix, ielt8]
  381. // IE < 8 bug: [].unshift(0) === undefined but should be "1"
  382. var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
  383. defineProperties(ArrayPrototype, {
  384. unshift: function () {
  385. array_unshift.apply(this, arguments);
  386. return this.length;
  387. }
  388. }, hasUnshiftReturnValueBug);
  389. // ES5 15.4.3.2
  390. // https://es5.github.io/#x15.4.3.2
  391. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
  392. defineProperties($Array, { isArray: isArray });
  393. // The IsCallable() check in the Array functions
  394. // has been replaced with a strict check on the
  395. // internal class of the object to trap cases where
  396. // the provided function was actually a regular
  397. // expression literal, which in V8 and
  398. // JavaScriptCore is a typeof "function". Only in
  399. // V8 are regular expression literals permitted as
  400. // reduce parameters, so it is desirable in the
  401. // general case for the shim to match the more
  402. // strict and common behavior of rejecting regular
  403. // expressions.
  404. // ES5 15.4.4.18
  405. // https://es5.github.io/#x15.4.4.18
  406. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
  407. // Check failure of by-index access of string characters (IE < 9)
  408. // and failure of `0 in boxedString` (Rhino)
  409. var boxedString = $Object('a');
  410. var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
  411. var properlyBoxesContext = function properlyBoxed(method) {
  412. // Check node 0.6.21 bug where third parameter is not boxed
  413. var properlyBoxesNonStrict = true;
  414. var properlyBoxesStrict = true;
  415. var threwException = false;
  416. if (method) {
  417. try {
  418. method.call('foo', function (_, __, context) {
  419. if (typeof context !== 'object') {
  420. properlyBoxesNonStrict = false;
  421. }
  422. });
  423. method.call([1], function () {
  424. 'use strict';
  425. properlyBoxesStrict = typeof this === 'string';
  426. }, 'x');
  427. } catch (e) {
  428. threwException = true;
  429. }
  430. }
  431. return !!method && !threwException && properlyBoxesNonStrict && properlyBoxesStrict;
  432. };
  433. defineProperties(ArrayPrototype, {
  434. forEach: function forEach(callbackfn/*, thisArg*/) {
  435. var object = ES.ToObject(this);
  436. var self = splitString && isString(this) ? strSplit(this, '') : object;
  437. var i = -1;
  438. var length = ES.ToUint32(self.length);
  439. var T;
  440. if (arguments.length > 1) {
  441. T = arguments[1];
  442. }
  443. // If no callback function or if callback is not a callable function
  444. if (!isCallable(callbackfn)) {
  445. throw new TypeError('Array.prototype.forEach callback must be a function');
  446. }
  447. while (++i < length) {
  448. if (i in self) {
  449. // Invoke the callback function with call, passing arguments:
  450. // context, property value, property key, thisArg object
  451. if (typeof T === 'undefined') {
  452. callbackfn(self[i], i, object);
  453. } else {
  454. callbackfn.call(T, self[i], i, object);
  455. }
  456. }
  457. }
  458. }
  459. }, !properlyBoxesContext(ArrayPrototype.forEach));
  460. // ES5 15.4.4.19
  461. // https://es5.github.io/#x15.4.4.19
  462. // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
  463. defineProperties(ArrayPrototype, {
  464. map: function map(callbackfn/*, thisArg*/) {
  465. var object = ES.ToObject(this);
  466. var self = splitString && isString(this) ? strSplit(this, '') : object;
  467. var length = ES.ToUint32(self.length);
  468. var result = $Array(length);
  469. var T;
  470. if (arguments.length > 1) {
  471. T = arguments[1];
  472. }
  473. // If no callback function or if callback is not a callable function
  474. if (!isCallable(callbackfn)) {
  475. throw new TypeError('Array.prototype.map callback must be a function');
  476. }
  477. for (var i = 0; i < length; i++) {
  478. if (i in self) {
  479. if (typeof T === 'undefined') {
  480. result[i] = callbackfn(self[i], i, object);
  481. } else {
  482. result[i] = callbackfn.call(T, self[i], i, object);
  483. }
  484. }
  485. }
  486. return result;
  487. }
  488. }, !properlyBoxesContext(ArrayPrototype.map));
  489. // ES5 15.4.4.20
  490. // https://es5.github.io/#x15.4.4.20
  491. // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
  492. defineProperties(ArrayPrototype, {
  493. filter: function filter(callbackfn/*, thisArg*/) {
  494. var object = ES.ToObject(this);
  495. var self = splitString && isString(this) ? strSplit(this, '') : object;
  496. var length = ES.ToUint32(self.length);
  497. var result = [];
  498. var value;
  499. var T;
  500. if (arguments.length > 1) {
  501. T = arguments[1];
  502. }
  503. // If no callback function or if callback is not a callable function
  504. if (!isCallable(callbackfn)) {
  505. throw new TypeError('Array.prototype.filter callback must be a function');
  506. }
  507. for (var i = 0; i < length; i++) {
  508. if (i in self) {
  509. value = self[i];
  510. if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
  511. pushCall(result, value);
  512. }
  513. }
  514. }
  515. return result;
  516. }
  517. }, !properlyBoxesContext(ArrayPrototype.filter));
  518. // ES5 15.4.4.16
  519. // https://es5.github.io/#x15.4.4.16
  520. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
  521. defineProperties(ArrayPrototype, {
  522. every: function every(callbackfn/*, thisArg*/) {
  523. var object = ES.ToObject(this);
  524. var self = splitString && isString(this) ? strSplit(this, '') : object;
  525. var length = ES.ToUint32(self.length);
  526. var T;
  527. if (arguments.length > 1) {
  528. T = arguments[1];
  529. }
  530. // If no callback function or if callback is not a callable function
  531. if (!isCallable(callbackfn)) {
  532. throw new TypeError('Array.prototype.every callback must be a function');
  533. }
  534. for (var i = 0; i < length; i++) {
  535. if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
  536. return false;
  537. }
  538. }
  539. return true;
  540. }
  541. }, !properlyBoxesContext(ArrayPrototype.every));
  542. // ES5 15.4.4.17
  543. // https://es5.github.io/#x15.4.4.17
  544. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
  545. defineProperties(ArrayPrototype, {
  546. some: function some(callbackfn/*, thisArg */) {
  547. var object = ES.ToObject(this);
  548. var self = splitString && isString(this) ? strSplit(this, '') : object;
  549. var length = ES.ToUint32(self.length);
  550. var T;
  551. if (arguments.length > 1) {
  552. T = arguments[1];
  553. }
  554. // If no callback function or if callback is not a callable function
  555. if (!isCallable(callbackfn)) {
  556. throw new TypeError('Array.prototype.some callback must be a function');
  557. }
  558. for (var i = 0; i < length; i++) {
  559. if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
  560. return true;
  561. }
  562. }
  563. return false;
  564. }
  565. }, !properlyBoxesContext(ArrayPrototype.some));
  566. // ES5 15.4.4.21
  567. // https://es5.github.io/#x15.4.4.21
  568. // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
  569. var reduceCoercesToObject = false;
  570. if (ArrayPrototype.reduce) {
  571. reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) {
  572. return list;
  573. }) === 'object';
  574. }
  575. defineProperties(ArrayPrototype, {
  576. reduce: function reduce(callbackfn/*, initialValue*/) {
  577. var object = ES.ToObject(this);
  578. var self = splitString && isString(this) ? strSplit(this, '') : object;
  579. var length = ES.ToUint32(self.length);
  580. // If no callback function or if callback is not a callable function
  581. if (!isCallable(callbackfn)) {
  582. throw new TypeError('Array.prototype.reduce callback must be a function');
  583. }
  584. // no value to return if no initial value and an empty array
  585. if (length === 0 && arguments.length === 1) {
  586. throw new TypeError('reduce of empty array with no initial value');
  587. }
  588. var i = 0;
  589. var result;
  590. if (arguments.length >= 2) {
  591. result = arguments[1];
  592. } else {
  593. do {
  594. if (i in self) {
  595. result = self[i++];
  596. break;
  597. }
  598. // if array contains no values, no initial value to return
  599. if (++i >= length) {
  600. throw new TypeError('reduce of empty array with no initial value');
  601. }
  602. } while (true);
  603. }
  604. for (; i < length; i++) {
  605. if (i in self) {
  606. result = callbackfn(result, self[i], i, object);
  607. }
  608. }
  609. return result;
  610. }
  611. }, !reduceCoercesToObject);
  612. // ES5 15.4.4.22
  613. // https://es5.github.io/#x15.4.4.22
  614. // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
  615. var reduceRightCoercesToObject = false;
  616. if (ArrayPrototype.reduceRight) {
  617. reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) {
  618. return list;
  619. }) === 'object';
  620. }
  621. defineProperties(ArrayPrototype, {
  622. reduceRight: function reduceRight(callbackfn/*, initial*/) {
  623. var object = ES.ToObject(this);
  624. var self = splitString && isString(this) ? strSplit(this, '') : object;
  625. var length = ES.ToUint32(self.length);
  626. // If no callback function or if callback is not a callable function
  627. if (!isCallable(callbackfn)) {
  628. throw new TypeError('Array.prototype.reduceRight callback must be a function');
  629. }
  630. // no value to return if no initial value, empty array
  631. if (length === 0 && arguments.length === 1) {
  632. throw new TypeError('reduceRight of empty array with no initial value');
  633. }
  634. var result;
  635. var i = length - 1;
  636. if (arguments.length >= 2) {
  637. result = arguments[1];
  638. } else {
  639. do {
  640. if (i in self) {
  641. result = self[i--];
  642. break;
  643. }
  644. // if array contains no values, no initial value to return
  645. if (--i < 0) {
  646. throw new TypeError('reduceRight of empty array with no initial value');
  647. }
  648. } while (true);
  649. }
  650. if (i < 0) {
  651. return result;
  652. }
  653. do {
  654. if (i in self) {
  655. result = callbackfn(result, self[i], i, object);
  656. }
  657. } while (i--);
  658. return result;
  659. }
  660. }, !reduceRightCoercesToObject);
  661. // ES5 15.4.4.14
  662. // https://es5.github.io/#x15.4.4.14
  663. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
  664. var hasFirefox2IndexOfBug = ArrayPrototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
  665. defineProperties(ArrayPrototype, {
  666. indexOf: function indexOf(searchElement/*, fromIndex */) {
  667. var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
  668. var length = ES.ToUint32(self.length);
  669. if (length === 0) {
  670. return -1;
  671. }
  672. var i = 0;
  673. if (arguments.length > 1) {
  674. i = ES.ToInteger(arguments[1]);
  675. }
  676. // handle negative indices
  677. i = i >= 0 ? i : max(0, length + i);
  678. for (; i < length; i++) {
  679. if (i in self && self[i] === searchElement) {
  680. return i;
  681. }
  682. }
  683. return -1;
  684. }
  685. }, hasFirefox2IndexOfBug);
  686. // ES5 15.4.4.15
  687. // https://es5.github.io/#x15.4.4.15
  688. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
  689. var hasFirefox2LastIndexOfBug = ArrayPrototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
  690. defineProperties(ArrayPrototype, {
  691. lastIndexOf: function lastIndexOf(searchElement/*, fromIndex */) {
  692. var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
  693. var length = ES.ToUint32(self.length);
  694. if (length === 0) {
  695. return -1;
  696. }
  697. var i = length - 1;
  698. if (arguments.length > 1) {
  699. i = min(i, ES.ToInteger(arguments[1]));
  700. }
  701. // handle negative indices
  702. i = i >= 0 ? i : length - abs(i);
  703. for (; i >= 0; i--) {
  704. if (i in self && searchElement === self[i]) {
  705. return i;
  706. }
  707. }
  708. return -1;
  709. }
  710. }, hasFirefox2LastIndexOfBug);
  711. // ES5 15.4.4.12
  712. // https://es5.github.io/#x15.4.4.12
  713. var spliceNoopReturnsEmptyArray = (function () {
  714. var a = [1, 2];
  715. var result = a.splice();
  716. return a.length === 2 && isArray(result) && result.length === 0;
  717. }());
  718. defineProperties(ArrayPrototype, {
  719. // Safari 5.0 bug where .splice() returns undefined
  720. splice: function splice(start, deleteCount) {
  721. if (arguments.length === 0) {
  722. return [];
  723. }
  724. return array_splice.apply(this, arguments);
  725. }
  726. }, !spliceNoopReturnsEmptyArray);
  727. var spliceWorksWithEmptyObject = (function () {
  728. var obj = {};
  729. ArrayPrototype.splice.call(obj, 0, 0, 1);
  730. return obj.length === 1;
  731. }());
  732. var hasES6Defaults = [0, 1, 2].splice(0).length === 3;
  733. defineProperties(ArrayPrototype, {
  734. splice: function splice(start, deleteCount) {
  735. if (arguments.length === 0) {
  736. return [];
  737. }
  738. var args = arguments;
  739. this.length = max(ES.ToInteger(this.length), 0);
  740. if (arguments.length > 0 && typeof deleteCount !== 'number') {
  741. args = arraySlice(arguments);
  742. if (args.length < 2) {
  743. pushCall(args, this.length - start);
  744. } else {
  745. args[1] = ES.ToInteger(deleteCount);
  746. }
  747. }
  748. return array_splice.apply(this, args);
  749. }
  750. }, !spliceWorksWithEmptyObject || !hasES6Defaults);
  751. var spliceWorksWithLargeSparseArrays = (function () {
  752. // Per https://github.com/es-shims/es5-shim/issues/295
  753. // Safari 7/8 breaks with sparse arrays of size 1e5 or greater
  754. var arr = new $Array(1e5);
  755. // note: the index MUST be 8 or larger or the test will false pass
  756. arr[8] = 'x';
  757. arr.splice(1, 1);
  758. // note: this test must be defined *after* the indexOf shim
  759. // per https://github.com/es-shims/es5-shim/issues/313
  760. return arr.indexOf('x') === 7;
  761. }());
  762. var spliceWorksWithSmallSparseArrays = (function () {
  763. // Per https://github.com/es-shims/es5-shim/issues/295
  764. // Opera 12.15 breaks on this, no idea why.
  765. var n = 256;
  766. var arr = [];
  767. arr[n] = 'a';
  768. arr.splice(n + 1, 0, 'b');
  769. return arr[n] === 'a';
  770. }());
  771. defineProperties(ArrayPrototype, {
  772. splice: function splice(start, deleteCount) {
  773. var O = ES.ToObject(this);
  774. var A = [];
  775. var len = ES.ToUint32(O.length);
  776. var relativeStart = ES.ToInteger(start);
  777. var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
  778. var actualDeleteCount = arguments.length === 0
  779. ? 0
  780. : arguments.length === 1
  781. ? len - actualStart
  782. : min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
  783. var k = 0;
  784. var from;
  785. while (k < actualDeleteCount) {
  786. from = $String(actualStart + k);
  787. if (owns(O, from)) {
  788. A[k] = O[from];
  789. }
  790. k += 1;
  791. }
  792. var items = arraySlice(arguments, 2);
  793. var itemCount = items.length;
  794. var to;
  795. if (itemCount < actualDeleteCount) {
  796. k = actualStart;
  797. var maxK = len - actualDeleteCount;
  798. while (k < maxK) {
  799. from = $String(k + actualDeleteCount);
  800. to = $String(k + itemCount);
  801. if (owns(O, from)) {
  802. O[to] = O[from];
  803. } else {
  804. delete O[to];
  805. }
  806. k += 1;
  807. }
  808. k = len;
  809. var minK = len - actualDeleteCount + itemCount;
  810. while (k > minK) {
  811. delete O[k - 1];
  812. k -= 1;
  813. }
  814. } else if (itemCount > actualDeleteCount) {
  815. k = len - actualDeleteCount;
  816. while (k > actualStart) {
  817. from = $String(k + actualDeleteCount - 1);
  818. to = $String(k + itemCount - 1);
  819. if (owns(O, from)) {
  820. O[to] = O[from];
  821. } else {
  822. delete O[to];
  823. }
  824. k -= 1;
  825. }
  826. }
  827. k = actualStart;
  828. for (var i = 0; i < items.length; ++i) {
  829. O[k] = items[i];
  830. k += 1;
  831. }
  832. O.length = len - actualDeleteCount + itemCount;
  833. return A;
  834. }
  835. }, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);
  836. var originalJoin = ArrayPrototype.join;
  837. var hasStringJoinBug;
  838. try {
  839. hasStringJoinBug = Array.prototype.join.call('123', ',') !== '1,2,3';
  840. } catch (e) {
  841. hasStringJoinBug = true;
  842. }
  843. if (hasStringJoinBug) {
  844. defineProperties(ArrayPrototype, {
  845. join: function join(separator) {
  846. var sep = typeof separator === 'undefined' ? ',' : separator;
  847. return originalJoin.call(isString(this) ? strSplit(this, '') : this, sep);
  848. }
  849. }, hasStringJoinBug);
  850. }
  851. var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
  852. if (hasJoinUndefinedBug) {
  853. defineProperties(ArrayPrototype, {
  854. join: function join(separator) {
  855. var sep = typeof separator === 'undefined' ? ',' : separator;
  856. return originalJoin.call(this, sep);
  857. }
  858. }, hasJoinUndefinedBug);
  859. }
  860. var pushShim = function push(item) {
  861. var O = ES.ToObject(this);
  862. var n = ES.ToUint32(O.length);
  863. var i = 0;
  864. while (i < arguments.length) {
  865. O[n + i] = arguments[i];
  866. i += 1;
  867. }
  868. O.length = n + i;
  869. return n + i;
  870. };
  871. var pushIsNotGeneric = (function () {
  872. var obj = {};
  873. var result = Array.prototype.push.call(obj, undefined);
  874. return result !== 1 || obj.length !== 1 || typeof obj[0] !== 'undefined' || !owns(obj, 0);
  875. }());
  876. defineProperties(ArrayPrototype, {
  877. push: function push(item) {
  878. if (isArray(this)) {
  879. return array_push.apply(this, arguments);
  880. }
  881. return pushShim.apply(this, arguments);
  882. }
  883. }, pushIsNotGeneric);
  884. // This fixes a very weird bug in Opera 10.6 when pushing `undefined
  885. var pushUndefinedIsWeird = (function () {
  886. var arr = [];
  887. var result = arr.push(undefined);
  888. return result !== 1 || arr.length !== 1 || typeof arr[0] !== 'undefined' || !owns(arr, 0);
  889. }());
  890. defineProperties(ArrayPrototype, { push: pushShim }, pushUndefinedIsWeird);
  891. // ES5 15.2.3.14
  892. // https://es5.github.io/#x15.4.4.10
  893. // Fix boxed string bug
  894. defineProperties(ArrayPrototype, {
  895. slice: function (start, end) {
  896. var arr = isString(this) ? strSplit(this, '') : this;
  897. return arraySliceApply(arr, arguments);
  898. }
  899. }, splitString);
  900. var sortIgnoresNonFunctions = (function () {
  901. try {
  902. [1, 2].sort(null);
  903. } catch (e) {
  904. try {
  905. [1, 2].sort({});
  906. } catch (e2) {
  907. return false;
  908. }
  909. }
  910. return true;
  911. }());
  912. var sortThrowsOnRegex = (function () {
  913. // this is a problem in Firefox 4, in which `typeof /a/ === 'function'`
  914. try {
  915. [1, 2].sort(/a/);
  916. return false;
  917. } catch (e) {}
  918. return true;
  919. }());
  920. var sortIgnoresUndefined = (function () {
  921. // applies in IE 8, for one.
  922. try {
  923. [1, 2].sort(undefined);
  924. return true;
  925. } catch (e) {}
  926. return false;
  927. }());
  928. defineProperties(ArrayPrototype, {
  929. sort: function sort(compareFn) {
  930. if (typeof compareFn === 'undefined') {
  931. return arraySort(this);
  932. }
  933. if (!isCallable(compareFn)) {
  934. throw new TypeError('Array.prototype.sort callback must be a function');
  935. }
  936. return arraySort(this, compareFn);
  937. }
  938. }, sortIgnoresNonFunctions || !sortIgnoresUndefined || !sortThrowsOnRegex);
  939. //
  940. // Object
  941. // ======
  942. //
  943. // ES5 15.2.3.14
  944. // https://es5.github.io/#x15.2.3.14
  945. // https://web.archive.org/web/20140727042234/http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
  946. // eslint-disable-next-line quote-props
  947. var hasDontEnumBug = !isEnum({ 'toString': null }, 'toString'); // jscs:ignore disallowQuotedKeysInObjects
  948. var hasProtoEnumBug = isEnum(function () {}, 'prototype');
  949. var hasStringEnumBug = !owns('x', '0');
  950. var equalsConstructorPrototype = function (o) {
  951. var ctor = o.constructor;
  952. return ctor && ctor.prototype === o;
  953. };
  954. var excludedKeys = {
  955. $applicationCache: true,
  956. $console: true,
  957. $external: true,
  958. $frame: true,
  959. $frameElement: true,
  960. $frames: true,
  961. $innerHeight: true,
  962. $innerWidth: true,
  963. $onmozfullscreenchange: true,
  964. $onmozfullscreenerror: true,
  965. $outerHeight: true,
  966. $outerWidth: true,
  967. $pageXOffset: true,
  968. $pageYOffset: true,
  969. $parent: true,
  970. $scrollLeft: true,
  971. $scrollTop: true,
  972. $scrollX: true,
  973. $scrollY: true,
  974. $self: true,
  975. $webkitIndexedDB: true,
  976. $webkitStorageInfo: true,
  977. $window: true,
  978. $width: true,
  979. $height: true,
  980. $top: true,
  981. $localStorage: true
  982. };
  983. var hasAutomationEqualityBug = (function () {
  984. /* globals window */
  985. if (typeof window === 'undefined') {
  986. return false;
  987. }
  988. for (var k in window) {
  989. try {
  990. if (!excludedKeys['$' + k] && owns(window, k) && window[k] !== null && typeof window[k] === 'object') {
  991. equalsConstructorPrototype(window[k]);
  992. }
  993. } catch (e) {
  994. return true;
  995. }
  996. }
  997. return false;
  998. }());
  999. var equalsConstructorPrototypeIfNotBuggy = function (object) {
  1000. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  1001. return equalsConstructorPrototype(object);
  1002. }
  1003. try {
  1004. return equalsConstructorPrototype(object);
  1005. } catch (e) {
  1006. return false;
  1007. }
  1008. };
  1009. var dontEnums = [
  1010. 'toString',
  1011. 'toLocaleString',
  1012. 'valueOf',
  1013. 'hasOwnProperty',
  1014. 'isPrototypeOf',
  1015. 'propertyIsEnumerable',
  1016. 'constructor'
  1017. ];
  1018. var dontEnumsLength = dontEnums.length;
  1019. // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
  1020. // can be replaced with require('is-arguments') if we ever use a build process instead
  1021. var isStandardArguments = function isArguments(value) {
  1022. return toStr(value) === '[object Arguments]';
  1023. };
  1024. var isLegacyArguments = function isArguments(value) {
  1025. return value !== null
  1026. && typeof value === 'object'
  1027. && typeof value.length === 'number'
  1028. && value.length >= 0
  1029. && !isArray(value)
  1030. && isCallable(value.callee);
  1031. };
  1032. var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
  1033. defineProperties($Object, {
  1034. keys: function keys(object) {
  1035. var isFn = isCallable(object);
  1036. var isArgs = isArguments(object);
  1037. var isObject = object !== null && typeof object === 'object';
  1038. var isStr = isObject && isString(object);
  1039. if (!isObject && !isFn && !isArgs) {
  1040. throw new TypeError('Object.keys called on a non-object');
  1041. }
  1042. var theKeys = [];
  1043. var skipProto = hasProtoEnumBug && isFn;
  1044. if ((isStr && hasStringEnumBug) || isArgs) {
  1045. for (var i = 0; i < object.length; ++i) {
  1046. pushCall(theKeys, $String(i));
  1047. }
  1048. }
  1049. if (!isArgs) {
  1050. for (var name in object) {
  1051. if (!(skipProto && name === 'prototype') && owns(object, name)) {
  1052. pushCall(theKeys, $String(name));
  1053. }
  1054. }
  1055. }
  1056. if (hasDontEnumBug) {
  1057. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  1058. for (var j = 0; j < dontEnumsLength; j++) {
  1059. var dontEnum = dontEnums[j];
  1060. if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
  1061. pushCall(theKeys, dontEnum);
  1062. }
  1063. }
  1064. }
  1065. return theKeys;
  1066. }
  1067. });
  1068. var keysWorksWithArguments = $Object.keys && (function () {
  1069. // Safari 5.0 bug
  1070. return $Object.keys(arguments).length === 2;
  1071. }(1, 2));
  1072. var keysHasArgumentsLengthBug = $Object.keys && (function () {
  1073. var argKeys = $Object.keys(arguments);
  1074. return arguments.length !== 1 || argKeys.length !== 1 || argKeys[0] !== 1;
  1075. }(1));
  1076. var originalKeys = $Object.keys;
  1077. defineProperties($Object, {
  1078. keys: function keys(object) {
  1079. if (isArguments(object)) {
  1080. return originalKeys(arraySlice(object));
  1081. }
  1082. return originalKeys(object);
  1083. }
  1084. }, !keysWorksWithArguments || keysHasArgumentsLengthBug);
  1085. //
  1086. // Date
  1087. // ====
  1088. //
  1089. var hasNegativeMonthYearBug = new Date(-3509827329600292).getUTCMonth() !== 0;
  1090. var aNegativeTestDate = new Date(-1509842289600292);
  1091. var aPositiveTestDate = new Date(1449662400000);
  1092. var hasToUTCStringFormatBug = aNegativeTestDate.toUTCString() !== 'Mon, 01 Jan -45875 11:59:59 GMT';
  1093. var hasToDateStringFormatBug;
  1094. var hasToStringFormatBug;
  1095. var timeZoneOffset = aNegativeTestDate.getTimezoneOffset();
  1096. if (timeZoneOffset < -720) {
  1097. hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Tue Jan 02 -45875';
  1098. hasToStringFormatBug = !(/^Thu Dec 10 2015 \d\d:\d\d:\d\d GMT[-+]\d\d\d\d(?: |$)/).test(String(aPositiveTestDate));
  1099. } else {
  1100. hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Mon Jan 01 -45875';
  1101. hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-+]\d\d\d\d(?: |$)/).test(String(aPositiveTestDate));
  1102. }
  1103. var originalGetFullYear = call.bind(Date.prototype.getFullYear);
  1104. var originalGetMonth = call.bind(Date.prototype.getMonth);
  1105. var originalGetDate = call.bind(Date.prototype.getDate);
  1106. var originalGetUTCFullYear = call.bind(Date.prototype.getUTCFullYear);
  1107. var originalGetUTCMonth = call.bind(Date.prototype.getUTCMonth);
  1108. var originalGetUTCDate = call.bind(Date.prototype.getUTCDate);
  1109. var originalGetUTCDay = call.bind(Date.prototype.getUTCDay);
  1110. var originalGetUTCHours = call.bind(Date.prototype.getUTCHours);
  1111. var originalGetUTCMinutes = call.bind(Date.prototype.getUTCMinutes);
  1112. var originalGetUTCSeconds = call.bind(Date.prototype.getUTCSeconds);
  1113. var originalGetUTCMilliseconds = call.bind(Date.prototype.getUTCMilliseconds);
  1114. var dayName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  1115. var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  1116. var daysInMonth = function daysInMonth(month, year) {
  1117. return originalGetDate(new Date(year, month, 0));
  1118. };
  1119. defineProperties(Date.prototype, {
  1120. getFullYear: function getFullYear() {
  1121. if (!this || !(this instanceof Date)) {
  1122. throw new TypeError('this is not a Date object.');
  1123. }
  1124. var year = originalGetFullYear(this);
  1125. if (year < 0 && originalGetMonth(this) > 11) {
  1126. return year + 1;
  1127. }
  1128. return year;
  1129. },
  1130. getMonth: function getMonth() {
  1131. if (!this || !(this instanceof Date)) {
  1132. throw new TypeError('this is not a Date object.');
  1133. }
  1134. var year = originalGetFullYear(this);
  1135. var month = originalGetMonth(this);
  1136. if (year < 0 && month > 11) {
  1137. return 0;
  1138. }
  1139. return month;
  1140. },
  1141. getDate: function getDate() {
  1142. if (!this || !(this instanceof Date)) {
  1143. throw new TypeError('this is not a Date object.');
  1144. }
  1145. var year = originalGetFullYear(this);
  1146. var month = originalGetMonth(this);
  1147. var date = originalGetDate(this);
  1148. if (year < 0 && month > 11) {
  1149. if (month === 12) {
  1150. return date;
  1151. }
  1152. var days = daysInMonth(0, year + 1);
  1153. return (days - date) + 1;
  1154. }
  1155. return date;
  1156. },
  1157. getUTCFullYear: function getUTCFullYear() {
  1158. if (!this || !(this instanceof Date)) {
  1159. throw new TypeError('this is not a Date object.');
  1160. }
  1161. var year = originalGetUTCFullYear(this);
  1162. if (year < 0 && originalGetUTCMonth(this) > 11) {
  1163. return year + 1;
  1164. }
  1165. return year;
  1166. },
  1167. getUTCMonth: function getUTCMonth() {
  1168. if (!this || !(this instanceof Date)) {
  1169. throw new TypeError('this is not a Date object.');
  1170. }
  1171. var year = originalGetUTCFullYear(this);
  1172. var month = originalGetUTCMonth(this);
  1173. if (year < 0 && month > 11) {
  1174. return 0;
  1175. }
  1176. return month;
  1177. },
  1178. getUTCDate: function getUTCDate() {
  1179. if (!this || !(this instanceof Date)) {
  1180. throw new TypeError('this is not a Date object.');
  1181. }
  1182. var year = originalGetUTCFullYear(this);
  1183. var month = originalGetUTCMonth(this);
  1184. var date = originalGetUTCDate(this);
  1185. if (year < 0 && month > 11) {
  1186. if (month === 12) {
  1187. return date;
  1188. }
  1189. var days = daysInMonth(0, year + 1);
  1190. return (days - date) + 1;
  1191. }
  1192. return date;
  1193. }
  1194. }, hasNegativeMonthYearBug);
  1195. defineProperties(Date.prototype, {
  1196. toUTCString: function toUTCString() {
  1197. if (!this || !(this instanceof Date)) {
  1198. throw new TypeError('this is not a Date object.');
  1199. }
  1200. var day = originalGetUTCDay(this);
  1201. var date = originalGetUTCDate(this);
  1202. var month = originalGetUTCMonth(this);
  1203. var year = originalGetUTCFullYear(this);
  1204. var hour = originalGetUTCHours(this);
  1205. var minute = originalGetUTCMinutes(this);
  1206. var second = originalGetUTCSeconds(this);
  1207. return dayName[day] + ', '
  1208. + (date < 10 ? '0' + date : date) + ' '
  1209. + monthName[month] + ' '
  1210. + year + ' '
  1211. + (hour < 10 ? '0' + hour : hour) + ':'
  1212. + (minute < 10 ? '0' + minute : minute) + ':'
  1213. + (second < 10 ? '0' + second : second) + ' GMT';
  1214. }
  1215. }, hasNegativeMonthYearBug || hasToUTCStringFormatBug);
  1216. // Opera 12 has `,`
  1217. defineProperties(Date.prototype, {
  1218. toDateString: function toDateString() {
  1219. if (!this || !(this instanceof Date)) {
  1220. throw new TypeError('this is not a Date object.');
  1221. }
  1222. var day = this.getDay();
  1223. var date = this.getDate();
  1224. var month = this.getMonth();
  1225. var year = this.getFullYear();
  1226. return dayName[day] + ' '
  1227. + monthName[month] + ' '
  1228. + (date < 10 ? '0' + date : date) + ' '
  1229. + year;
  1230. }
  1231. }, hasNegativeMonthYearBug || hasToDateStringFormatBug);
  1232. // can't use defineProperties here because of toString enumeration issue in IE <= 8
  1233. if (hasNegativeMonthYearBug || hasToStringFormatBug) {
  1234. Date.prototype.toString = function toString() {
  1235. if (!this || !(this instanceof Date)) {
  1236. throw new TypeError('this is not a Date object.');
  1237. }
  1238. var day = this.getDay();
  1239. var date = this.getDate();
  1240. var month = this.getMonth();
  1241. var year = this.getFullYear();
  1242. var hour = this.getHours();
  1243. var minute = this.getMinutes();
  1244. var second = this.getSeconds();
  1245. var timezoneOffset = this.getTimezoneOffset();
  1246. var hoursOffset = floor(abs(timezoneOffset) / 60);
  1247. var minutesOffset = floor(abs(timezoneOffset) % 60);
  1248. return dayName[day] + ' '
  1249. + monthName[month] + ' '
  1250. + (date < 10 ? '0' + date : date) + ' '
  1251. + year + ' '
  1252. + (hour < 10 ? '0' + hour : hour) + ':'
  1253. + (minute < 10 ? '0' + minute : minute) + ':'
  1254. + (second < 10 ? '0' + second : second) + ' GMT'
  1255. + (timezoneOffset > 0 ? '-' : '+')
  1256. + (hoursOffset < 10 ? '0' + hoursOffset : hoursOffset)
  1257. + (minutesOffset < 10 ? '0' + minutesOffset : minutesOffset);
  1258. };
  1259. if (supportsDescriptors) {
  1260. $Object.defineProperty(Date.prototype, 'toString', {
  1261. configurable: true,
  1262. enumerable: false,
  1263. writable: true
  1264. });
  1265. }
  1266. }
  1267. // ES5 15.9.5.43
  1268. // https://es5.github.io/#x15.9.5.43
  1269. // This function returns a String value represent the instance in time
  1270. // represented by this Date object. The format of the String is the Date Time
  1271. // string format defined in 15.9.1.15. All fields are present in the String.
  1272. // The time zone is always UTC, denoted by the suffix Z. If the time value of
  1273. // this object is not a finite Number a RangeError exception is thrown.
  1274. var negativeDate = -62198755200000;
  1275. var negativeYearString = '-000001';
  1276. var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1; // eslint-disable-line max-len
  1277. var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
  1278. var getTime = call.bind(Date.prototype.getTime);
  1279. defineProperties(Date.prototype, {
  1280. toISOString: function toISOString() {
  1281. if (!isFinite(this) || !isFinite(getTime(this))) {
  1282. // Adope Photoshop requires the second check.
  1283. throw new RangeError('Date.prototype.toISOString called on non-finite value.');
  1284. }
  1285. var year = originalGetUTCFullYear(this);
  1286. var month = originalGetUTCMonth(this);
  1287. // see https://github.com/es-shims/es5-shim/issues/111
  1288. year += floor(month / 12);
  1289. month = ((month % 12) + 12) % 12;
  1290. // the date time string format is specified in 15.9.1.15.
  1291. var result = [
  1292. month + 1,
  1293. originalGetUTCDate(this),
  1294. originalGetUTCHours(this),
  1295. originalGetUTCMinutes(this),
  1296. originalGetUTCSeconds(this)
  1297. ];
  1298. year = (
  1299. (year < 0 ? '-' : (year > 9999 ? '+' : ''))
  1300. + strSlice('00000' + abs(year), (0 <= year && year <= 9999) ? -4 : -6)
  1301. );
  1302. for (var i = 0; i < result.length; ++i) {
  1303. // pad months, days, hours, minutes, and seconds to have two digits.
  1304. result[i] = strSlice('00' + result[i], -2);
  1305. }
  1306. // pad milliseconds to have three digits.
  1307. return (
  1308. year + '-' + arraySlice(result, 0, 2).join('-')
  1309. + 'T' + arraySlice(result, 2).join(':') + '.'
  1310. + strSlice('000' + originalGetUTCMilliseconds(this), -3) + 'Z'
  1311. );
  1312. }
  1313. }, hasNegativeDateBug || hasSafari51DateBug);
  1314. // ES5 15.9.5.44
  1315. // https://es5.github.io/#x15.9.5.44
  1316. // This function provides a String representation of a Date object for use by
  1317. // JSON.stringify (15.12.3).
  1318. var dateToJSONIsSupported = (function () {
  1319. try {
  1320. return Date.prototype.toJSON
  1321. && new Date(NaN).toJSON() === null
  1322. && new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1
  1323. && Date.prototype.toJSON.call({ // generic
  1324. toISOString: function () { return true; }
  1325. });
  1326. } catch (e) {
  1327. return false;
  1328. }
  1329. }());
  1330. if (!dateToJSONIsSupported) {
  1331. Date.prototype.toJSON = function toJSON(key) {
  1332. // When the toJSON method is called with argument key, the following
  1333. // steps are taken:
  1334. // 1. Let O be the result of calling ToObject, giving it the this
  1335. // value as its argument.
  1336. // 2. Let tv be ES.ToPrimitive(O, hint Number).
  1337. var O = $Object(this);
  1338. var tv = ES.ToPrimitive(O);
  1339. // 3. If tv is a Number and is not finite, return null.
  1340. if (typeof tv === 'number' && !isFinite(tv)) {
  1341. return null;
  1342. }
  1343. // 4. Let toISO be the result of calling the [[Get]] internal method of
  1344. // O with argument "toISOString".
  1345. var toISO = O.toISOString;
  1346. // 5. If IsCallable(toISO) is false, throw a TypeError exception.
  1347. if (!isCallable(toISO)) {
  1348. throw new TypeError('toISOString property is not callable');
  1349. }
  1350. // 6. Return the result of calling the [[Call]] internal method of
  1351. // toISO with O as the this value and an empty argument list.
  1352. return toISO.call(O);
  1353. // NOTE 1 The argument is ignored.
  1354. // NOTE 2 The toJSON function is intentionally generic; it does not
  1355. // require that its this value be a Date object. Therefore, it can be
  1356. // transferred to other kinds of objects for use as a method. However,
  1357. // it does require that any such object have a toISOString method. An
  1358. // object is free to use the argument key to filter its
  1359. // stringification.
  1360. };
  1361. }
  1362. // ES5 15.9.4.2
  1363. // https://es5.github.io/#x15.9.4.2
  1364. // based on work shared by Daniel Friesen (dantman)
  1365. // https://gist.github.com/303249
  1366. var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
  1367. var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
  1368. var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
  1369. if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
  1370. // XXX global assignment won't work in embeddings that use
  1371. // an alternate object for the context.
  1372. var maxSafeUnsigned32Bit = pow(2, 31) - 1;
  1373. var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
  1374. // eslint-disable-next-line no-implicit-globals, no-global-assign
  1375. Date = (function (NativeDate) {
  1376. // Date.length === 7
  1377. var DateShim = function Date(Y, M, D, h, m, s, ms) {
  1378. var length = arguments.length;
  1379. var date;
  1380. if (this instanceof NativeDate) {
  1381. var seconds = s;
  1382. var millis = ms;
  1383. if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
  1384. // work around a Safari 8/9 bug where it treats the seconds as signed
  1385. var msToShift = floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
  1386. var sToShift = floor(msToShift / 1e3);
  1387. seconds += sToShift;
  1388. millis -= sToShift * 1e3;
  1389. }
  1390. var parsed = DateShim.parse(Y);
  1391. var hasNegTimestampParseBug = isNaN(parsed);
  1392. date = length === 1 && $String(Y) === Y && !hasNegTimestampParseBug // isString(Y)
  1393. // We explicitly pass it through parse:
  1394. ? new NativeDate(parsed)
  1395. // We have to manually make calls depending on argument
  1396. // length here
  1397. : length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis)
  1398. : length >= 6 ? new NativeDate(Y, M, D, h, m, seconds)
  1399. : length >= 5 ? new NativeDate(Y, M, D, h, m)
  1400. : length >= 4 ? new NativeDate(Y, M, D, h)
  1401. : length >= 3 ? new NativeDate(Y, M, D)
  1402. : length >= 2 ? new NativeDate(Y, M)
  1403. : length >= 1 ? new NativeDate(Y instanceof NativeDate ? +Y : Y)
  1404. : new NativeDate();
  1405. } else {
  1406. date = NativeDate.apply(this, arguments);
  1407. }
  1408. if (!isPrimitive(date)) {
  1409. // Prevent mixups with unfixed Date object
  1410. defineProperties(date, { constructor: DateShim }, true);
  1411. }
  1412. return date;
  1413. };
  1414. // 15.9.1.15 Date Time String Format.
  1415. var isoDateExpression = new RegExp('^'
  1416. + '(\\d{4}|[+-]\\d{6})' // four-digit year capture or sign + 6-digit extended year
  1417. + '(?:-(\\d{2})' // optional month capture
  1418. + '(?:-(\\d{2})' // optional day capture
  1419. + '(?:' // capture hours:minutes:seconds.milliseconds
  1420. + 'T(\\d{2})' // hours capture
  1421. + ':(\\d{2})' // minutes capture
  1422. + '(?:' // optional :seconds.milliseconds
  1423. + ':(\\d{2})' // seconds capture
  1424. + '(?:(\\.\\d{1,}))?' // milliseconds capture
  1425. + ')?'
  1426. + '(' // capture UTC offset component
  1427. + 'Z|' // UTC capture
  1428. + '(?:' // offset specifier +/-hours:minutes
  1429. + '([-+])' // sign capture
  1430. + '(\\d{2})' // hours offset capture
  1431. + ':(\\d{2})' // minutes offset capture
  1432. + ')'
  1433. + ')?)?)?)?'
  1434. + '$');
  1435. var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
  1436. var dayFromMonth = function dayFromMonth(year, month) {
  1437. var t = month > 1 ? 1 : 0;
  1438. return (
  1439. months[month]
  1440. + floor((year - 1969 + t) / 4)
  1441. - floor((year - 1901 + t) / 100)
  1442. + floor((year - 1601 + t) / 400)
  1443. + (365 * (year - 1970))
  1444. );
  1445. };
  1446. var toUTC = function toUTC(t) {
  1447. var s = 0;
  1448. var ms = t;
  1449. if (hasSafariSignedIntBug && ms > maxSafeUnsigned32Bit) {
  1450. // work around a Safari 8/9 bug where it treats the seconds as signed
  1451. var msToShift = floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
  1452. var sToShift = floor(msToShift / 1e3);
  1453. s += sToShift;
  1454. ms -= sToShift * 1e3;
  1455. }
  1456. return $Number(new NativeDate(1970, 0, 1, 0, 0, s, ms));
  1457. };
  1458. // Copy any custom methods a 3rd party library may have added
  1459. for (var key in NativeDate) {
  1460. if (owns(NativeDate, key)) {
  1461. DateShim[key] = NativeDate[key];
  1462. }
  1463. }
  1464. // Copy "native" methods explicitly; they may be non-enumerable
  1465. defineProperties(DateShim, {
  1466. now: NativeDate.now,
  1467. UTC: NativeDate.UTC
  1468. }, true);
  1469. DateShim.prototype = NativeDate.prototype;
  1470. defineProperties(DateShim.prototype, { constructor: DateShim }, true);
  1471. // Upgrade Date.parse to handle simplified ISO 8601 strings
  1472. var parseShim = function parse(string) {
  1473. var match = isoDateExpression.exec(string);
  1474. if (match) {
  1475. // parse months, days, hours, minutes, seconds, and milliseconds
  1476. // provide default values if necessary
  1477. // parse the UTC offset component
  1478. var year = $Number(match[1]),
  1479. month = $Number(match[2] || 1) - 1,
  1480. day = $Number(match[3] || 1) - 1,
  1481. hour = $Number(match[4] || 0),
  1482. minute = $Number(match[5] || 0),
  1483. second = $Number(match[6] || 0),
  1484. millisecond = floor($Number(match[7] || 0) * 1000),
  1485. // When time zone is missed, local offset should be used
  1486. // (ES 5.1 bug)
  1487. // see https://bugs.ecmascript.org/show_bug.cgi?id=112
  1488. isLocalTime = Boolean(match[4] && !match[8]),
  1489. signOffset = match[9] === '-' ? 1 : -1,
  1490. hourOffset = $Number(match[10] || 0),
  1491. minuteOffset = $Number(match[11] || 0),
  1492. result;
  1493. var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
  1494. if (
  1495. hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25)
  1496. && minute < 60 && second < 60 && millisecond < 1000
  1497. && month > -1 && month < 12 && hourOffset < 24
  1498. && minuteOffset < 60 // detect invalid offsets
  1499. && day > -1
  1500. && day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
  1501. ) {
  1502. result = (
  1503. ((dayFromMonth(year, month) + day) * 24)
  1504. + hour
  1505. + (hourOffset * signOffset)
  1506. ) * 60;
  1507. result = ((
  1508. ((result + minute + (minuteOffset * signOffset)) * 60)
  1509. + second
  1510. ) * 1000) + millisecond;
  1511. if (isLocalTime) {
  1512. result = toUTC(result);
  1513. }
  1514. if (-8.64e15 <= result && result <= 8.64e15) {
  1515. return result;
  1516. }
  1517. }
  1518. return NaN;
  1519. }
  1520. return NativeDate.parse.apply(this, arguments);
  1521. };
  1522. defineProperties(DateShim, { parse: parseShim });
  1523. return DateShim;
  1524. }(Date));
  1525. }
  1526. // ES5 15.9.4.4
  1527. // https://es5.github.io/#x15.9.4.4
  1528. if (!Date.now) {
  1529. Date.now = function now() {
  1530. return new Date().getTime();
  1531. };
  1532. }
  1533. //
  1534. // Number
  1535. // ======
  1536. //
  1537. // ES5.1 15.7.4.5
  1538. // https://es5.github.io/#x15.7.4.5
  1539. var hasToFixedBugs = NumberPrototype.toFixed && (
  1540. (0.00008).toFixed(3) !== '0.000'
  1541. || (0.9).toFixed(0) !== '1'
  1542. || (1.255).toFixed(2) !== '1.25'
  1543. || (1000000000000000128).toFixed(0) !== '1000000000000000128'
  1544. );
  1545. var toFixedHelpers = {
  1546. base: 1e7,
  1547. size: 6,
  1548. data: [0, 0, 0, 0, 0, 0],
  1549. multiply: function multiply(n, c) {
  1550. var i = -1;
  1551. var c2 = c;
  1552. while (++i < toFixedHelpers.size) {
  1553. c2 += n * toFixedHelpers.data[i];
  1554. toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
  1555. c2 = floor(c2 / toFixedHelpers.base);
  1556. }
  1557. },
  1558. divide: function divide(n) {
  1559. var i = toFixedHelpers.size;
  1560. var c = 0;
  1561. while (--i >= 0) {
  1562. c += toFixedHelpers.data[i];
  1563. toFixedHelpers.data[i] = floor(c / n);
  1564. c = (c % n) * toFixedHelpers.base;
  1565. }
  1566. },
  1567. numToString: function numToString() {
  1568. var i = toFixedHelpers.size;
  1569. var s = '';
  1570. while (--i >= 0) {
  1571. if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
  1572. var t = $String(toFixedHelpers.data[i]);
  1573. if (s === '') {
  1574. s = t;
  1575. } else {
  1576. s += strSlice('0000000', 0, 7 - t.length) + t;
  1577. }
  1578. }
  1579. }
  1580. return s;
  1581. },
  1582. pow: function pow(x, n, acc) {
  1583. return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
  1584. },
  1585. log: function log(x) {
  1586. var n = 0;
  1587. var x2 = x;
  1588. while (x2 >= 4096) {
  1589. n += 12;
  1590. x2 /= 4096;
  1591. }
  1592. while (x2 >= 2) {
  1593. n += 1;
  1594. x2 /= 2;
  1595. }
  1596. return n;
  1597. }
  1598. };
  1599. var toFixedShim = function toFixed(fractionDigits) {
  1600. var f, x, s, m, e, z, j, k;
  1601. // Test for NaN and round fractionDigits down
  1602. f = $Number(fractionDigits);
  1603. f = isActualNaN(f) ? 0 : floor(f);
  1604. if (f < 0 || f > 20) {
  1605. throw new RangeError('Number.toFixed called with invalid number of decimals');
  1606. }
  1607. x = $Number(this);
  1608. if (isActualNaN(x)) {
  1609. return 'NaN';
  1610. }
  1611. // If it is too big or small, return the string value of the number
  1612. if (x <= -1e21 || x >= 1e21) {
  1613. return $String(x);
  1614. }
  1615. s = '';
  1616. if (x < 0) {
  1617. s = '-';
  1618. x = -x;
  1619. }
  1620. m = '0';
  1621. if (x > 1e-21) {
  1622. // 1e-21 < x < 1e21
  1623. // -70 < log2(x) < 70
  1624. e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
  1625. z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
  1626. z *= 0x10000000000000; // pow(2, 52);
  1627. e = 52 - e;
  1628. // -18 < e < 122
  1629. // x = z / 2 ^ e
  1630. if (e > 0) {
  1631. toFixedHelpers.multiply(0, z);
  1632. j = f;
  1633. while (j >= 7) {
  1634. toFixedHelpers.multiply(1e7, 0);
  1635. j -= 7;
  1636. }
  1637. toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
  1638. j = e - 1;
  1639. while (j >= 23) {
  1640. toFixedHelpers.divide(1 << 23);
  1641. j -= 23;
  1642. }
  1643. toFixedHelpers.divide(1 << j);
  1644. toFixedHelpers.multiply(1, 1);
  1645. toFixedHelpers.divide(2);
  1646. m = toFixedHelpers.numToString();
  1647. } else {
  1648. toFixedHelpers.multiply(0, z);
  1649. toFixedHelpers.multiply(1 << (-e), 0);
  1650. m = toFixedHelpers.numToString() + strSlice('0.00000000000000000000', 2, 2 + f);
  1651. }
  1652. }
  1653. if (f > 0) {
  1654. k = m.length;
  1655. if (k <= f) {
  1656. m = s + strSlice('0.0000000000000000000', 0, f - k + 2) + m;
  1657. } else {
  1658. m = s + strSlice(m, 0, k - f) + '.' + strSlice(m, k - f);
  1659. }
  1660. } else {
  1661. m = s + m;
  1662. }
  1663. return m;
  1664. };
  1665. defineProperties(NumberPrototype, { toFixed: toFixedShim }, hasToFixedBugs);
  1666. var hasToExponentialRoundingBug = (function () {
  1667. try {
  1668. return (-6.9e-11).toExponential(4) !== '-6.9000e-11';
  1669. } catch (e) {
  1670. return false;
  1671. }
  1672. }());
  1673. var toExponentialAllowsInfiniteDigits = (function () {
  1674. try {
  1675. (1).toExponential(Infinity);
  1676. (1).toExponential(-Infinity);
  1677. return true;
  1678. } catch (e) {
  1679. return false;
  1680. }
  1681. }());
  1682. var originalToExponential = call.bind(NumberPrototype.toExponential);
  1683. var numberToString = call.bind(NumberPrototype.toString);
  1684. var numberValueOf = call.bind(NumberPrototype.valueOf);
  1685. defineProperties(NumberPrototype, {
  1686. toExponential: function toExponential(fractionDigits) {
  1687. // 1: Let x be this Number value.
  1688. var x = numberValueOf(this);
  1689. if (typeof fractionDigits === 'undefined') {
  1690. return originalToExponential(x);
  1691. }
  1692. var f = ES.ToInteger(fractionDigits);
  1693. if (isActualNaN(x)) {
  1694. return 'NaN';
  1695. }
  1696. if (f < 0 || f > 20) {
  1697. if (!isFinite(f)) {
  1698. // IE 6 doesn't throw in the native one
  1699. throw new RangeError('toExponential() argument must be between 0 and 20');
  1700. }
  1701. // this will probably have thrown already
  1702. return originalToExponential(x, f);
  1703. }
  1704. // only cases left are a finite receiver + in-range fractionDigits
  1705. // implementation adapted from https://gist.github.com/SheetJSDev/1100ad56b9f856c95299ed0e068eea08
  1706. // 4: Let s be the empty string
  1707. var s = '';
  1708. // 5: If x < 0
  1709. if (x < 0) {
  1710. s = '-';
  1711. x = -x;
  1712. }
  1713. // 6: If x = +Infinity
  1714. if (x === Infinity) {
  1715. return s + 'Infinity';
  1716. }
  1717. // 7: If fractionDigits is not undefined and (f < 0 or f > 20), throw a RangeError exception.
  1718. if (typeof fractionDigits !== 'undefined' && (f < 0 || f > 20)) {
  1719. throw new RangeError('Fraction digits ' + fractionDigits + ' out of range');
  1720. }
  1721. var m = '';
  1722. var e = 0;
  1723. var c = '';
  1724. var d = '';
  1725. // 8: If x = 0 then
  1726. if (x === 0) {
  1727. e = 0;
  1728. f = 0;
  1729. m = '0';
  1730. } else { // 9: Else, x != 0
  1731. var L = log10(x);
  1732. e = floor(L); // 10 ** e <= x and x < 10 ** (e+1)
  1733. var n = 0;
  1734. if (typeof fractionDigits !== 'undefined') { // eslint-disable-line no-negated-condition
  1735. var w = pow(10, e - f); // x / 10 ** (f+1) < w and w <= x / 10 ** f
  1736. n = round(x / w); // 10 ** f <= n and n < 10 ** (f+1)
  1737. if (2 * x >= (((2 * n) + 1) * w)) {
  1738. n += 1; // pick larger value
  1739. }
  1740. if (n >= pow(10, f + 1)) { // 10e-1 = 1e0
  1741. n /= 10;
  1742. e += 1;
  1743. }
  1744. } else {
  1745. f = 16; // start from Math.ceil(Math.log10(Number.MAX_SAFE_INTEGER)) and loop down
  1746. var guess_n = round(pow(10, L - e + f));
  1747. var target_f = f;
  1748. while (f-- > 0) {
  1749. guess_n = round(pow(10, L - e + f));
  1750. if (
  1751. abs((guess_n * pow(10, e - f)) - x)
  1752. <= abs((n * pow(10, e - target_f)) - x)
  1753. ) {
  1754. target_f = f;
  1755. n = guess_n;
  1756. }
  1757. }
  1758. }
  1759. m = numberToString(n, 10);
  1760. if (typeof fractionDigits === 'undefined') {
  1761. while (strSlice(m, -1) === '0') {
  1762. m = strSlice(m, 0, -1);
  1763. d += 1;
  1764. }
  1765. }
  1766. }
  1767. // 10: If f != 0, then
  1768. if (f !== 0) {
  1769. m = strSlice(m, 0, 1) + '.' + strSlice(m, 1);
  1770. }
  1771. // 11: If e = 0, then
  1772. if (e === 0) {
  1773. c = '+';
  1774. d = '0';
  1775. } else { // 12: Else
  1776. c = e > 0 ? '+' : '-';
  1777. d = numberToString(abs(e), 10);
  1778. }
  1779. // 13: Let m be the concatenation of the four Strings m, "e", c, and d.
  1780. m += 'e' + c + d;
  1781. // 14: Return the concatenation of the Strings s and m.
  1782. return s + m;
  1783. }
  1784. }, hasToExponentialRoundingBug || toExponentialAllowsInfiniteDigits);
  1785. var hasToPrecisionUndefinedBug = (function () {
  1786. try {
  1787. return 1.0.toPrecision(undefined) === '1';
  1788. } catch (e) {
  1789. return true;
  1790. }
  1791. }());
  1792. var originalToPrecision = call.bind(NumberPrototype.toPrecision);
  1793. defineProperties(NumberPrototype, {
  1794. toPrecision: function toPrecision(precision) {
  1795. return typeof precision === 'undefined' ? originalToPrecision(this) : originalToPrecision(this, precision);
  1796. }
  1797. }, hasToPrecisionUndefinedBug);
  1798. //
  1799. // String
  1800. // ======
  1801. //
  1802. // ES5 15.5.4.14
  1803. // https://es5.github.io/#x15.5.4.14
  1804. // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
  1805. // Many browsers do not split properly with regular expressions or they
  1806. // do not perform the split correctly under obscure conditions.
  1807. // See https://blog.stevenlevithan.com/archives/cross-browser-split
  1808. // I've tested in many browsers and this seems to cover the deviant ones:
  1809. // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
  1810. // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
  1811. // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
  1812. // [undefined, "t", undefined, "e", ...]
  1813. // ''.split(/.?/) should be [], not [""]
  1814. // '.'.split(/()()/) should be ["."], not ["", "", "."]
  1815. if (
  1816. 'ab'.split(/(?:ab)*/).length !== 2
  1817. || '.'.split(/(.?)(.?)/).length !== 4
  1818. || 'tesst'.split(/(s)*/)[1] === 't'
  1819. || 'test'.split(/(?:)/, -1).length !== 4
  1820. || ''.split(/.?/).length
  1821. || '.'.split(/()()/).length > 1
  1822. ) {
  1823. (function () {
  1824. var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
  1825. var maxSafe32BitInt = pow(2, 32) - 1;
  1826. StringPrototype.split = function split(separator, limit) {
  1827. var string = String(this);
  1828. if (typeof separator === 'undefined' && limit === 0) {
  1829. return [];
  1830. }
  1831. // If `separator` is not a regex, use native split
  1832. if (!isRegex(separator)) {
  1833. return strSplit(this, separator, limit);
  1834. }
  1835. var output = [];
  1836. var flags = (separator.ignoreCase ? 'i' : '')
  1837. + (separator.multiline ? 'm' : '')
  1838. + (separator.unicode ? 'u' : '') // in ES6
  1839. + (separator.sticky ? 'y' : ''), // Firefox 3+ and ES6
  1840. lastLastIndex = 0,
  1841. // Make `global` and avoid `lastIndex` issues by working with a copy
  1842. separator2, match, lastIndex, lastLength;
  1843. var separatorCopy = new RegExp(separator.source, flags + 'g');
  1844. if (!compliantExecNpcg) {
  1845. // Doesn't need flags gy, but they don't hurt
  1846. separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
  1847. }
  1848. /* Values for `limit`, per the spec:
  1849. * If undefined: 4294967295 // maxSafe32BitInt
  1850. * If 0, Infinity, or NaN: 0
  1851. * If positive number: limit = floor(limit); if (limit > 4294967295) limit -= 4294967296;
  1852. * If negative number: 4294967296 - floor(abs(limit))
  1853. * If other: Type-convert, then use the above rules
  1854. */
  1855. var splitLimit = typeof limit === 'undefined' ? maxSafe32BitInt : ES.ToUint32(limit);
  1856. match = separatorCopy.exec(string);
  1857. while (match) {
  1858. // `separatorCopy.lastIndex` is not reliable cross-browser
  1859. lastIndex = match.index + match[0].length;
  1860. if (lastIndex > lastLastIndex) {
  1861. pushCall(output, strSlice(string, lastLastIndex, match.index));
  1862. // Fix browsers whose `exec` methods don't consistently return `undefined` for
  1863. // nonparticipating capturing groups
  1864. if (!compliantExecNpcg && match.length > 1) {
  1865. /* eslint-disable no-loop-func */
  1866. match[0].replace(separator2, function () {
  1867. for (var i = 1; i < arguments.length - 2; i++) {
  1868. if (typeof arguments[i] === 'undefined') {
  1869. match[i] = void 0;
  1870. }
  1871. }
  1872. });
  1873. /* eslint-enable no-loop-func */
  1874. }
  1875. if (match.length > 1 && match.index < string.length) {
  1876. array_push.apply(output, arraySlice(match, 1));
  1877. }
  1878. lastLength = match[0].length;
  1879. lastLastIndex = lastIndex;
  1880. if (output.length >= splitLimit) {
  1881. break;
  1882. }
  1883. }
  1884. if (separatorCopy.lastIndex === match.index) {
  1885. separatorCopy.lastIndex++; // Avoid an infinite loop
  1886. }
  1887. match = separatorCopy.exec(string);
  1888. }
  1889. if (lastLastIndex === string.length) {
  1890. if (lastLength || !separatorCopy.test('')) {
  1891. pushCall(output, '');
  1892. }
  1893. } else {
  1894. pushCall(output, strSlice(string, lastLastIndex));
  1895. }
  1896. return output.length > splitLimit ? arraySlice(output, 0, splitLimit) : output;
  1897. };
  1898. }());
  1899. // [bugfix, chrome]
  1900. // If separator is undefined, then the result array contains just one String,
  1901. // which is the this value (converted to a String). If limit is not undefined,
  1902. // then the output array is truncated so that it contains no more than limit
  1903. // elements.
  1904. // "0".split(undefined, 0) -> []
  1905. } else if ('0'.split(void 0, 0).length) {
  1906. StringPrototype.split = function split(separator, limit) {
  1907. if (typeof separator === 'undefined' && limit === 0) {
  1908. return [];
  1909. }
  1910. return strSplit(this, separator, limit);
  1911. };
  1912. }
  1913. var str_replace = StringPrototype.replace;
  1914. var replaceReportsGroupsCorrectly = (function () {
  1915. var groups = [];
  1916. 'x'.replace(/x(.)?/g, function (match, group) {
  1917. pushCall(groups, group);
  1918. });
  1919. return groups.length === 1 && typeof groups[0] === 'undefined';
  1920. }());
  1921. if (!replaceReportsGroupsCorrectly) {
  1922. StringPrototype.replace = function replace(searchValue, replaceValue) {
  1923. var isFn = isCallable(replaceValue);
  1924. var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
  1925. if (!isFn || !hasCapturingGroups) {
  1926. return str_replace.call(this, searchValue, replaceValue);
  1927. }
  1928. var wrappedReplaceValue = function (match) {
  1929. var length = arguments.length;
  1930. var originalLastIndex = searchValue.lastIndex;
  1931. searchValue.lastIndex = 0; // eslint-disable-line no-param-reassign
  1932. var args = searchValue.exec(match) || [];
  1933. searchValue.lastIndex = originalLastIndex; // eslint-disable-line no-param-reassign
  1934. pushCall(args, arguments[length - 2], arguments[length - 1]);
  1935. return replaceValue.apply(this, args);
  1936. };
  1937. return str_replace.call(this, searchValue, wrappedReplaceValue);
  1938. };
  1939. }
  1940. // ECMA-262, 3rd B.2.3
  1941. // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
  1942. // non-normative section suggesting uniform semantics and it should be
  1943. // normalized across all browsers
  1944. // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
  1945. var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
  1946. var string_substr = hasNegativeSubstrBug && call.bind(StringPrototype.substr);
  1947. defineProperties(StringPrototype, {
  1948. substr: function substr(start, length) {
  1949. var normalizedStart = start;
  1950. if (start < 0) {
  1951. normalizedStart = max(this.length + start, 0);
  1952. }
  1953. return string_substr(this, normalizedStart, length);
  1954. }
  1955. }, hasNegativeSubstrBug);
  1956. // ES5 15.5.4.20
  1957. // whitespace from: https://es5.github.io/#x15.5.4.20
  1958. var mvs = '\u180E';
  1959. var mvsIsWS = (/\s/).test(mvs);
  1960. var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'
  1961. .replace(/\S/g, ''); // remove the mongolian vowel separator (\u180E) in modern engines
  1962. var zeroWidth = '\u200b';
  1963. var wsRegexChars = '[' + ws + ']';
  1964. var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
  1965. var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
  1966. var hasTrimWhitespaceBug = StringPrototype.trim && (
  1967. ws.trim() !== '' // if ws is not considered whitespace
  1968. || zeroWidth.trim() === '' // if zero-width IS considered whitespace
  1969. || mvs.trim() !== (mvsIsWS ? '' : mvs) // if MVS is either wrongly considered whitespace, or, wrongly considered NOT whitespace
  1970. );
  1971. defineProperties(StringPrototype, {
  1972. // https://blog.stevenlevithan.com/archives/faster-trim-javascript
  1973. // http://perfectionkills.com/whitespace-deviations/
  1974. trim: function trim() {
  1975. 'use strict';
  1976. if (typeof this === 'undefined' || this === null) {
  1977. throw new TypeError("can't convert " + this + ' to object');
  1978. }
  1979. return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
  1980. }
  1981. }, hasTrimWhitespaceBug);
  1982. var trim = call.bind(String.prototype.trim);
  1983. var hasLastIndexBug = StringPrototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
  1984. defineProperties(StringPrototype, {
  1985. lastIndexOf: function lastIndexOf(searchString) {
  1986. if (typeof this === 'undefined' || this === null) {
  1987. throw new TypeError("can't convert " + this + ' to object');
  1988. }
  1989. var S = $String(this);
  1990. var searchStr = $String(searchString);
  1991. var numPos = arguments.length > 1 ? $Number(arguments[1]) : NaN;
  1992. var pos = isActualNaN(numPos) ? Infinity : ES.ToInteger(numPos);
  1993. var start = min(max(pos, 0), S.length);
  1994. var searchLen = searchStr.length;
  1995. var k = start + searchLen;
  1996. while (k > 0) {
  1997. k = max(0, k - searchLen);
  1998. var index = strIndexOf(strSlice(S, k, start + searchLen), searchStr);
  1999. if (index !== -1) {
  2000. return k + index;
  2001. }
  2002. }
  2003. return -1;
  2004. }
  2005. }, hasLastIndexBug);
  2006. var originalLastIndexOf = StringPrototype.lastIndexOf;
  2007. defineProperties(StringPrototype, {
  2008. lastIndexOf: function lastIndexOf(searchString) {
  2009. return originalLastIndexOf.apply(this, arguments);
  2010. }
  2011. }, StringPrototype.lastIndexOf.length !== 1);
  2012. var hexRegex = /^[-+]?0[xX]/;
  2013. // ES-5 15.1.2.2
  2014. if (
  2015. parseInt(ws + '08') !== 8 // eslint-disable-line radix
  2016. || parseInt(ws + '0x16') !== 22 // eslint-disable-line radix
  2017. || (mvsIsWS ? parseInt(mvs + 1) !== 1 : !isNaN(parseInt(mvs + 1))) // eslint-disable-line radix
  2018. ) {
  2019. // eslint-disable-next-line no-global-assign, no-implicit-globals
  2020. parseInt = (function (origParseInt) {
  2021. return function parseInt(str, radix) {
  2022. if (this instanceof parseInt) { new origParseInt(); } // eslint-disable-line new-cap, no-new, max-statements-per-line
  2023. var string = trim(String(str));
  2024. var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
  2025. return origParseInt(string, defaultedRadix);
  2026. };
  2027. }(parseInt));
  2028. }
  2029. // Edge 15-18
  2030. var parseIntFailsToThrowOnBoxedSymbols = (function () {
  2031. if (typeof Symbol !== 'function') {
  2032. return false;
  2033. }
  2034. try {
  2035. // eslint-disable-next-line radix
  2036. parseInt(Object(Symbol.iterator));
  2037. return true;
  2038. } catch (e) { /**/ }
  2039. try {
  2040. // eslint-disable-next-line radix
  2041. parseInt(Symbol.iterator);
  2042. return true;
  2043. } catch (e) { /**/ }
  2044. return false;
  2045. }());
  2046. if (parseIntFailsToThrowOnBoxedSymbols) {
  2047. var symbolValueOf = Symbol.prototype.valueOf;
  2048. // eslint-disable-next-line no-global-assign, no-implicit-globals
  2049. parseInt = (function (origParseInt) {
  2050. return function parseInt(str, radix) {
  2051. if (this instanceof parseInt) { new origParseInt(); } // eslint-disable-line new-cap, no-new, max-statements-per-line
  2052. var isSym = typeof str === 'symbol';
  2053. if (!isSym && str && typeof str === 'object') {
  2054. try {
  2055. symbolValueOf.call(str);
  2056. isSym = true;
  2057. } catch (e) { /**/ }
  2058. }
  2059. if (isSym) {
  2060. // handle Symbols in node 8.3/8.4
  2061. // eslint-disable-next-line no-implicit-coercion, no-unused-expressions
  2062. '' + str; // jscs:ignore disallowImplicitTypeConversion
  2063. }
  2064. var string = trim(String(str));
  2065. var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
  2066. return origParseInt(string, defaultedRadix);
  2067. };
  2068. }(parseInt));
  2069. }
  2070. // https://es5.github.io/#x15.1.2.3
  2071. if (1 / parseFloat('-0') !== -Infinity) {
  2072. // eslint-disable-next-line no-global-assign, no-implicit-globals, no-native-reassign
  2073. parseFloat = (function (origParseFloat) {
  2074. return function parseFloat(string) {
  2075. var inputString = trim(String(string));
  2076. var result = origParseFloat(inputString);
  2077. return result === 0 && strSlice(inputString, 0, 1) === '-' ? -0 : result;
  2078. };
  2079. }(parseFloat));
  2080. }
  2081. if (String(new RangeError('test')) !== 'RangeError: test') {
  2082. var errorToStringShim = function toString() {
  2083. if (typeof this === 'undefined' || this === null) {
  2084. throw new TypeError("can't convert " + this + ' to object');
  2085. }
  2086. var name = this.name;
  2087. if (typeof name === 'undefined') {
  2088. name = 'Error';
  2089. } else if (typeof name !== 'string') {
  2090. name = $String(name);
  2091. }
  2092. var msg = this.message;
  2093. if (typeof msg === 'undefined') {
  2094. msg = '';
  2095. } else if (typeof msg !== 'string') {
  2096. msg = $String(msg);
  2097. }
  2098. if (!name) {
  2099. return msg;
  2100. }
  2101. if (!msg) {
  2102. return name;
  2103. }
  2104. return name + ': ' + msg;
  2105. };
  2106. // can't use defineProperties here because of toString enumeration issue in IE <= 8
  2107. Error.prototype.toString = errorToStringShim;
  2108. }
  2109. if (supportsDescriptors) {
  2110. var ensureNonEnumerable = function (obj, prop) {
  2111. if (isEnum(obj, prop)) {
  2112. var desc = Object.getOwnPropertyDescriptor(obj, prop);
  2113. if (desc.configurable) {
  2114. desc.enumerable = false;
  2115. Object.defineProperty(obj, prop, desc);
  2116. }
  2117. }
  2118. };
  2119. ensureNonEnumerable(Error.prototype, 'message');
  2120. if (Error.prototype.message !== '') {
  2121. Error.prototype.message = '';
  2122. }
  2123. ensureNonEnumerable(Error.prototype, 'name');
  2124. }
  2125. if (String(/a/mig) !== '/a/gim') {
  2126. var regexToString = function toString() {
  2127. var str = '/' + this.source + '/';
  2128. if (this.global) {
  2129. str += 'g';
  2130. }
  2131. if (this.ignoreCase) {
  2132. str += 'i';
  2133. }
  2134. if (this.multiline) {
  2135. str += 'm';
  2136. }
  2137. return str;
  2138. };
  2139. // can't use defineProperties here because of toString enumeration issue in IE <= 8
  2140. RegExp.prototype.toString = regexToString;
  2141. }
  2142. }));