From: Tom Hughes Date: Wed, 30 Jan 2019 12:02:06 +0000 (+0000) Subject: Replace augment.js with conditional polyfills for ES5 and ES6 X-Git-Tag: live~3282^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/fa0a933c24f9866db17694dbef667e3c4d7ed08f Replace augment.js with conditional polyfills for ES5 and ES6 --- diff --git a/Vendorfile b/Vendorfile index c41282623..22a6ae422 100644 --- a/Vendorfile +++ b/Vendorfile @@ -67,6 +67,11 @@ folder 'vendor/assets' do end end + folder 'polyfill' do + file 'es5.js', 'https://polyfill.io/v3/polyfill.js?features=es5&flags=gated,always' + file 'es6.js', 'https://polyfill.io/v3/polyfill.js?features=es6&flags=gated,always' + end + folder 'javascripts' do file 'html5shiv.js', 'https://raw.githubusercontent.com/aFarkas/html5shiv/master/src/html5shiv.js' file 'bowser.js', 'https://github.com/lancedikson/bowser/releases/download/1.9.4/bowser.js' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 654b01680..ebb0ff580 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -5,7 +5,6 @@ //= require jquery.throttle-debounce //= require bootstrap.tooltip //= require bootstrap.dropdown -//= require augment //= require osm //= require leaflet //= require leaflet.osm diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index c06b01ed1..8c6b246d8 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -2,6 +2,8 @@ <%= javascript_include_tag "html5shiv" unless browser.html5? %> + <%= javascript_include_tag "es5" unless browser.es5? %> + <%= javascript_include_tag "es6" unless browser.es6? %> <%= javascript_include_tag "application" %> <%= javascript_include_tag "i18n/" + I18n.locale.to_s %> <%= stylesheet_link_tag "screen-#{dir}", :media => "screen" %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 7bd35daf6..4193fe482 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -20,7 +20,7 @@ Rails.application.config.assets.precompile += %w[leaflet-all.css leaflet.ie.css] Rails.application.config.assets.precompile += %w[id.js id.css] Rails.application.config.assets.precompile += %w[embed.js embed.css] Rails.application.config.assets.precompile += %w[errors.css] -Rails.application.config.assets.precompile += %w[html5shiv.js] +Rails.application.config.assets.precompile += %w[html5shiv.js es5.js es6.js] Rails.application.config.assets.precompile += %w[images/marker-*.png img/*-handle.png] Rails.application.config.assets.precompile += %w[swfobject.js expressInstall.swf] Rails.application.config.assets.precompile += %w[potlatch2.swf] diff --git a/vendor/assets/augment.js/augment.js b/vendor/assets/augment.js/augment.js deleted file mode 100644 index 33f03908f..000000000 --- a/vendor/assets/augment.js/augment.js +++ /dev/null @@ -1,444 +0,0 @@ -// augment.js JavaScript 1.8.5 methods for all, version: 0.4.2 -// using snippets from Mozilla - https://developer.mozilla.org/en/JavaScript -// (c) 2011 Oliver Nightingale -// -// Released under MIT license. -// -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every -if (!Array.prototype.every) { - Array.prototype.every = function(fun /*, thisp */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - var thisp = arguments[1]; - for (var i = 0; i < len; i++) { - if (i in t && !fun.call(thisp, t[i], i, t)) - return false; - } - - return true; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter -if (!Array.prototype.filter) { - Array.prototype.filter = function(fun /*, thisp */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - var res = []; - var thisp = arguments[1]; - for (var i = 0; i < len; i++) { - if (i in t) { - var val = t[i]; // in case fun mutates this - if (fun.call(thisp, val, i, t)) - res.push(val); - } - } - - return res; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach -if (!Array.prototype.forEach) { - Array.prototype.forEach = function(fun /*, thisp */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - var thisp = arguments[1]; - for (var i = 0; i < len; i++) { - if (i in t) - fun.call(thisp, t[i], i, t); - } - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function(searchElement /*, fromIndex */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (len === 0) - return -1; - - var n = 0; - if (arguments.length > 0) { - n = Number(arguments[1]); - if (n !== n) // shortcut for verifying if it's NaN - n = 0; - else if (n !== 0 && n !== (Infinity) && n !== -(Infinity)) - n = (n > 0 || -1) * Math.floor(Math.abs(n)); - } - - if (n >= len) - return -1; - - var k = n >= 0 - ? n - : Math.max(len - Math.abs(n), 0); - - for (; k < len; k++) { - if (k in t && t[k] === searchElement) - return k; - } - return -1; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray -Array.isArray = Array.isArray || function(o) { return Object.prototype.toString.call(o) === '[object Array]'; }; -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf -if (!Array.prototype.lastIndexOf) { - Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (len === 0) - return -1; - - var n = len; - if (arguments.length > 1) { - n = Number(arguments[1]); - if (n !== n) - n = 0; - else if (n !== 0 && n !== (Infinity) && n !== -(Infinity)) - n = (n > 0 || -1) * Math.floor(Math.abs(n)); - } - - var k = n >= 0 - ? Math.min(n, len - 1) - : len - Math.abs(n); - - for (; k >= 0; k--) { - if (k in t && t[k] === searchElement) - return k; - } - return -1; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map -if (!Array.prototype.map) { - Array.prototype.map = function(fun /*, thisp */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - var res = new Array(len); - var thisp = arguments[1]; - for (var i = 0; i < len; i++) { - if (i in t) - res[i] = fun.call(thisp, t[i], i, t); - } - - return res; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce -if (!Array.prototype.reduce) { - Array.prototype.reduce = function(fun /*, initialValue */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - // no value to return if no initial value and an empty array - if (len == 0 && arguments.length == 1) - throw new TypeError(); - - var k = 0; - var accumulator; - if (arguments.length >= 2) { - accumulator = arguments[1]; - } else { - do { - if (k in t) { - accumulator = t[k++]; - break; - } - - // if array contains no values, no initial value to return - if (++k >= len) - throw new TypeError(); - } - while (true); - } - - while (k < len) { - if (k in t) - accumulator = fun.call(undefined, accumulator, t[k], k, t); - k++; - } - - return accumulator; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight -if (!Array.prototype.reduceRight) { - Array.prototype.reduceRight = function(callbackfn /*, initialValue */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof callbackfn !== "function") - throw new TypeError(); - - // no value to return if no initial value, empty array - if (len === 0 && arguments.length === 1) - throw new TypeError(); - - var k = len - 1; - var accumulator; - if (arguments.length >= 2) { - accumulator = arguments[1]; - } else { - do { - if (k in this) { - accumulator = this[k--]; - break; - } - - // if array contains no values, no initial value to return - if (--k < 0) - throw new TypeError(); - } - while (true); - } - - while (k >= 0) { - if (k in t) - accumulator = callbackfn.call(undefined, accumulator, t[k], k, t); - k--; - } - - return accumulator; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some -if (!Array.prototype.some) { - Array.prototype.some = function(fun /*, thisp */) { - "use strict"; - - if (this === void 0 || this === null) - throw new TypeError(); - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== "function") - throw new TypeError(); - - var thisp = arguments[1]; - for (var i = 0; i < len; i++) { - if (i in t && fun.call(thisp, t[i], i, t)) - return true; - } - - return false; - }; -} -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/now -if (!Date.now) { - Date.now = function now () { - return +new Date(); - }; -} -if (!Date.prototype.toISOString) { - Date.prototype.toISOString = (function () { - - var pad = function (n, length) { - length = length || 2 - return (n = n + "", n.length === length) ? n : pad("0" + n, length); - } - - return function () { - var year = this.getUTCFullYear() - year = (year < 0 ? '-' : (year > 9999 ? '+' : '')) + ('00000' + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6); - - var date = [year, pad(this.getUTCMonth() + 1), pad(this.getUTCDate())].join("-") - var time = [pad(this.getUTCHours()), pad(this.getUTCMinutes()), pad(this.getUTCSeconds())].join(":") + "." + pad(this.getUTCMilliseconds(), 3) - return [date, time].join("T") + "Z" - } - })() -}; -if (!Date.prototype.toJSON) { - Date.prototype.toJSON = Date.prototype.toJSON -}; -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind -if (!Function.prototype.bind ) { - - Function.prototype.bind = function(obj) { - - if (typeof this !== 'function') throw new TypeError ("Function.prototype.bind - what is trying to be bound is not callable") - - var slice = Array.prototype.slice, - args = slice.call(arguments, 1), - self = this, - nop = function () {}, - bound = function () { - - if (nop.prototype && this instanceof nop) { - var result = self.apply(new nop, args.concat(slice.call(arguments))) - return (Object(result) === result) ? result : self - } else { - return self.apply(obj, args.concat(slice.call(arguments))) - }; - }; - - nop.prototype = self.prototype; - - bound.prototype = new nop(); - - return bound; - }; -} -;(function () { "use strict" - - var ensureIsObject = function (param) { - if (param !== Object(param)) throw new TypeError('Object.getPrototypeOf called on non-object'); - } - - if (!Object.getPrototypeOf) { - if (typeof "test".__proto__ === "object") { - Object.getPrototypeOf = function (obj) { - ensureIsObject(obj) - return obj.__proto__ - } - } else { - Object.getPrototypeOf = function (obj) { - ensureIsObject(obj) - return obj.constructor.prototype - } - }; - }; -})(); -// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation -if (!Object.keys) { - Object.keys = (function () { - var hasOwnProperty = Object.prototype.hasOwnProperty, - hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), - dontEnums = [ - 'toString', - 'toLocaleString', - 'valueOf', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'constructor' - ], - dontEnumsLength = dontEnums.length - - return function (obj) { - if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object') - - var result = [] - - for (var prop in obj) { - if (hasOwnProperty.call(obj, prop)) result.push(prop) - } - - if (hasDontEnumBug) { - for (var i=0; i < dontEnumsLength; i++) { - if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]) - } - } - return result - } - })() -};if (!String.prototype.trim) { - String.prototype.trim = (function () { - - var trimLeft = /^\s+/, - trimRight = /\s+$/ - - return function () { - return this.replace(trimLeft, "").replace(trimRight, "") - } - })() -}; -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex -// https://tc39.github.io/ecma262/#sec-array.prototype.findindex -if (!Array.prototype.findIndex) { - Object.defineProperty(Array.prototype, 'findIndex', { - value: function(predicate) { - // 1. Let O be ? ToObject(this value). - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If IsCallable(predicate) is false, throw a TypeError exception. - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); - } - - // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. - var thisArg = arguments[1]; - - // 5. Let k be 0. - var k = 0; - - // 6. Repeat, while k < len - while (k < len) { - // a. Let Pk be ! ToString(k). - // b. Let kValue be ? Get(O, Pk). - // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). - // d. If testResult is true, return k. - var kValue = o[k]; - if (predicate.call(thisArg, kValue, k, o)) { - return k; - } - // e. Increase k by 1. - k++; - } - - // 7. Return -1. - return -1; - }, - configurable: true, - writable: true - }); -} diff --git a/vendor/assets/polyfill/es5.js b/vendor/assets/polyfill/es5.js new file mode 100644 index 000000000..f16f7cc16 --- /dev/null +++ b/vendor/assets/polyfill/es5.js @@ -0,0 +1,1821 @@ +/* Polyfill service v3.27.1 + * For detailed credits and licence information see https://github.com/financial-times/polyfill-service. + * + * Features requested: es5 + * + * - Object.defineProperty, License: CC0 (required by "es5", "Object.defineProperties", "Object.create", "_ESAbstract.CreateMethodProperty", "Array.isArray", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "String.prototype.trim", "_ESAbstract.CreateDataProperty", "_ESAbstract.CreateDataPropertyOrThrow", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate") + * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.isArray", "es5", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.create", "Object.defineProperties", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "String.prototype.trim") + * - _ESAbstract.IsArray, License: CC0 (required by "Array.isArray", "es5", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map") + * - Array.isArray, License: CC0 (required by "es5") + * - _ESAbstract.ToObject, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.GetV", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate") + * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.indexOf", "es5", "Array.prototype.lastIndexOf", "_ESAbstract.ToLength", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some") + * - _ESAbstract.ToLength, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some") + * - _ESAbstract.Get, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct") + * - _ESAbstract.IsCallable, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive") + * - _ESAbstract.Call, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.OrdinaryToPrimitive") + * - _ESAbstract.GetV, License: CC0 (required by "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate") + * - _ESAbstract.GetMethod, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate") + * - _ESAbstract.Type, License: CC0 (required by "Object.create", "es5", "Object.defineProperties", "_ESAbstract.ToString", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.ToPrimitive", "_ESAbstract.IsConstructor", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct") + * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim") + * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim") + * - _ESAbstract.ToString, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim") + * - _ESAbstract.HasProperty, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some") + * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.some") + * - Array.prototype.every, License: CC0 (required by "es5") + * - _ESAbstract.ArrayCreate, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map") + * - _ESAbstract.IsConstructor, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map", "_ESAbstract.Construct") + * - _ESAbstract.GetPrototypeFromConstructor, License: CC0 (required by "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map") + * - Object.keys, License: MIT (required by "es5", "Object.defineProperties", "Object.create") + * - Function.prototype.bind, License: MIT (required by "es5", "Object.getOwnPropertyDescriptor", "Object.defineProperties", "Object.create", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map") + * - Object.getOwnPropertyDescriptor, License: CC0 (required by "es5", "Object.defineProperties", "Object.create") + * - Object.defineProperties, License: CC0 (required by "es5", "Object.create") + * - Object.create, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map") + * - Object.getPrototypeOf, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map") + * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map") + * - _ESAbstract.Construct, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map") + * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map") + * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.prototype.filter", "es5", "Array.prototype.map") + * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map") + * - Array.prototype.filter, License: CC0 (required by "es5") + * - Array.prototype.forEach, License: CC0 (required by "es5") + * - Array.prototype.indexOf, License: CC0 (required by "es5") + * - Array.prototype.lastIndexOf, License: CC0 (required by "es5") + * - Array.prototype.map, License: CC0 (required by "es5") + * - Array.prototype.reduce, License: CC0 (required by "es5") + * - Array.prototype.reduceRight, License: CC0 (required by "es5") + * - Array.prototype.some, License: CC0 (required by "es5") + * - Date.now, License: CC0 (required by "es5") + * - Date.prototype.toISOString, License: CC0 (required by "es5") + * - Object.freeze, License: CC0 (required by "es5") + * - Object.getOwnPropertyNames, License: CC0 (required by "es5") + * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.trim", "es5") + * - String.prototype.trim, License: CC0 (required by "es5") */ + +(function(undefined) { +if (!(// In IE8, defineProperty could only act on DOM elements, so full support +// for the feature requires the ability to set a property on an arbitrary object +'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } +}()))) { + +// Object.defineProperty +(function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + // Polyfill.io - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty. + Object['defineProperty'] = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object.defineProperty called on non-object'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineGetter__.call(object, propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + Object.__defineSetter__.call(object, propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; +}(Object.defineProperty)); + +} + + +// _ESAbstract.CreateMethodProperty +// 7.3.5. CreateMethodProperty ( O, P, V ) +function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}. + var newDesc = { + value: V, + writable: true, + enumerable: false, + configurable: true + }; + // 4. Return ? O.[[DefineOwnProperty]](P, newDesc). + Object.defineProperty(O, P, newDesc); +} + +// _ESAbstract.IsArray +// 7.2.2. IsArray ( argument ) +function IsArray(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + // 2. If argument is an Array exotic object, return true. + // 3. If argument is a Proxy exotic object, then + // a. If argument.[[ProxyHandler]] is null, throw a TypeError exception. + // b. Let target be argument.[[ProxyTarget]]. + // c. Return ? IsArray(target). + // 4. Return false. + + // Polyfill.io - We can skip all the above steps and check the string returned from Object.prototype.toString(). + return Object.prototype.toString.call(argument) === '[object Array]'; +} +if (!('isArray' in Array)) { + +// Array.isArray +/* global CreateMethodProperty, IsArray */ +// 22.1.2.2. Array.isArray ( arg ) +CreateMethodProperty(Array, 'isArray', function isArray(arg) { + // 1. Return ? IsArray(arg). + return IsArray(arg); +}); + +} + + +// _ESAbstract.ToObject +// 7.1.13 ToObject ( argument ) +// The abstract operation ToObject converts argument to a value of type Object according to Table 12: +// Table 12: ToObject Conversions +/* +|----------------------------------------------------------------------------------------------------------------------------------------------------| +| Argument Type | Result | +|----------------------------------------------------------------------------------------------------------------------------------------------------| +| Undefined | Throw a TypeError exception. | +| Null | Throw a TypeError exception. | +| Boolean | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. | +| Number | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects. | +| String | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects. | +| Symbol | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects. | +| Object | Return argument. | +|----------------------------------------------------------------------------------------------------------------------------------------------------| +*/ +function ToObject(argument) { // eslint-disable-line no-unused-vars + if (argument === null || argument === undefined) { + throw TypeError(); + } + return Object(argument); +} + +// _ESAbstract.ToInteger +// 7.1.4. ToInteger ( argument ) +function ToInteger(argument) { // eslint-disable-line no-unused-vars + // 1. Let number be ? ToNumber(argument). + var number = Number(argument); + // 2. If number is NaN, return +0. + if (isNaN(number)) { + return 0; + } + // 3. If number is +0, -0, +∞, or -∞, return number. + if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) { + return number; + } + // 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)). + return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number)); +} + +// _ESAbstract.ToLength +/* global ToInteger */ +// 7.1.15. ToLength ( argument ) +function ToLength(argument) { // eslint-disable-line no-unused-vars + // 1. Let len be ? ToInteger(argument). + var len = ToInteger(argument); + // 2. If len ≤ +0, return +0. + if (len <= 0) { + return 0; + } + // 3. Return min(len, 253-1). + return Math.min(len, Math.pow(2, 53) -1); +} + +// _ESAbstract.Get +// 7.3.1. Get ( O, P ) +function Get(O, P) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Return ? O.[[Get]](P, O). + return O[P]; +} + +// _ESAbstract.IsCallable +// 7.2.3. IsCallable ( argument ) +function IsCallable(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + // 2. If argument has a [[Call]] internal method, return true. + // 3. Return false. + + // Polyfill.io - Only function objects have a [[Call]] internal method. This means we can simplify this function to check that the argument has a type of function. + return typeof argument === 'function'; +} + +// _ESAbstract.Call +/* global IsCallable */ +// 7.3.12. Call ( F, V [ , argumentsList ] ) +function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars + // 1. If argumentsList is not present, set argumentsList to a new empty List. + var argumentsList = arguments.length > 2 ? arguments[2] : []; + // 2. If IsCallable(F) is false, throw a TypeError exception. + if (IsCallable(F) === false) { + throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.'); + } + // 3. Return ? F.[[Call]](V, argumentsList). + return F.apply(V, argumentsList); +} + +// _ESAbstract.GetV +/* global ToObject */ +// 7.3.2 GetV (V, P) +function GetV(v, p) { // eslint-disable-line no-unused-vars + // 1. Assert: IsPropertyKey(P) is true. + // 2. Let O be ? ToObject(V). + var o = ToObject(v); + // 3. Return ? O.[[Get]](P, V). + return o[p]; +} + +// _ESAbstract.GetMethod +/* global GetV, IsCallable */ +// 7.3.9. GetMethod ( V, P ) +function GetMethod(V, P) { // eslint-disable-line no-unused-vars + // 1. Assert: IsPropertyKey(P) is true. + // 2. Let func be ? GetV(V, P). + var func = GetV(V, P); + // 3. If func is either undefined or null, return undefined. + if (func === null || func === undefined) { + return undefined; + } + // 4. If IsCallable(func) is false, throw a TypeError exception. + if (IsCallable(func) === false) { + throw new TypeError('Method not callable: ' + P); + } + // 5. Return func. + return func; +} + +// _ESAbstract.Type +// "Type(x)" is used as shorthand for "the type of x"... +function Type(x) { // eslint-disable-line no-unused-vars + switch (typeof x) { + case 'undefined': + return 'undefined'; + case 'boolean': + return 'boolean'; + case 'number': + return 'number'; + case 'string': + return 'string'; + case 'symbol': + return 'symbol'; + default: + // typeof null is 'object' + if (x === null) return 'null'; + // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`. + if ('Symbol' in this && x instanceof this.Symbol) return 'symbol'; + return 'object'; + } +} + +// _ESAbstract.OrdinaryToPrimitive +/* global Get, IsCallable, Call, Type */ +// 7.1.1.1. OrdinaryToPrimitive ( O, hint ) +function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: Type(hint) is String and its value is either "string" or "number". + // 3. If hint is "string", then + if (hint === 'string') { + // a. Let methodNames be « "toString", "valueOf" ». + var methodNames = ['toString', 'valueOf']; + // 4. Else, + } else { + // a. Let methodNames be « "valueOf", "toString" ». + methodNames = ['valueOf', 'toString']; + } + // 5. For each name in methodNames in List order, do + for (var i = 0; i < methodNames.length; ++i) { + var name = methodNames[i]; + // a. Let method be ? Get(O, name). + var method = Get(O, name); + // b. If IsCallable(method) is true, then + if (IsCallable(method)) { + // i. Let result be ? Call(method, O). + var result = Call(method, O); + // ii. If Type(result) is not Object, return result. + if (Type(result) !== 'object') { + return result; + } + } + } + // 6. Throw a TypeError exception. + throw new TypeError('Cannot convert to primitive.'); +} + +// _ESAbstract.ToPrimitive +/* global Type, GetMethod, Call, OrdinaryToPrimitive */ +// 7.1.1. ToPrimitive ( input [ , PreferredType ] ) +function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars + var PreferredType = arguments.length > 1 ? arguments[1] : undefined; + // 1. Assert: input is an ECMAScript language value. + // 2. If Type(input) is Object, then + if (Type(input) === 'object') { + // a. If PreferredType is not present, let hint be "default". + if (arguments.length < 2) { + var hint = 'default'; + // b. Else if PreferredType is hint String, let hint be "string". + } else if (PreferredType === String) { + hint = 'string'; + // c. Else PreferredType is hint Number, let hint be "number". + } else if (PreferredType === Number) { + hint = 'number'; + } + // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + var exoticToPrim = typeof this.Symbol === 'function' && typeof this.Symbol.toPrimitive === 'symbol' ? GetMethod(input, this.Symbol.toPrimitive) : undefined; + // e. If exoticToPrim is not undefined, then + if (exoticToPrim !== undefined) { + // i. Let result be ? Call(exoticToPrim, input, « hint »). + var result = Call(exoticToPrim, input, [hint]); + // ii. If Type(result) is not Object, return result. + if (Type(result) !== 'object') { + return result; + } + // iii. Throw a TypeError exception. + throw new TypeError('Cannot convert exotic object to primitive.'); + } + // f. If hint is "default", set hint to "number". + if (hint === 'default') { + hint = 'number'; + } + // g. Return ? OrdinaryToPrimitive(input, hint). + return OrdinaryToPrimitive(input, hint); + } + // 3. Return input + return input; +} + +// _ESAbstract.ToString +/* global Type, ToPrimitive */ +// 7.1.12. ToString ( argument ) +// The abstract operation ToString converts argument to a value of type String according to Table 11: +// Table 11: ToString Conversions +/* +|---------------|--------------------------------------------------------| +| Argument Type | Result | +|---------------|--------------------------------------------------------| +| Undefined | Return "undefined". | +|---------------|--------------------------------------------------------| +| Null | Return "null". | +|---------------|--------------------------------------------------------| +| Boolean | If argument is true, return "true". | +| | If argument is false, return "false". | +|---------------|--------------------------------------------------------| +| Number | Return NumberToString(argument). | +|---------------|--------------------------------------------------------| +| String | Return argument. | +|---------------|--------------------------------------------------------| +| Symbol | Throw a TypeError exception. | +|---------------|--------------------------------------------------------| +| Object | Apply the following steps: | +| | Let primValue be ? ToPrimitive(argument, hint String). | +| | Return ? ToString(primValue). | +|---------------|--------------------------------------------------------| +*/ +function ToString(argument) { // eslint-disable-line no-unused-vars + switch(Type(argument)) { + case 'symbol': + throw new TypeError('Cannot convert a Symbol value to a string'); + break; + case 'object': + var primValue = ToPrimitive(argument, 'string'); + return ToString(primValue); + default: + return String(argument); + } +} + +// _ESAbstract.HasProperty +// 7.3.10. HasProperty ( O, P ) +function HasProperty(O, P) { // eslint-disable-line no-unused-vars + // Assert: Type(O) is Object. + // Assert: IsPropertyKey(P) is true. + // Return ? O.[[HasProperty]](P). + return P in O; +} + +// _ESAbstract.ToBoolean +// 7.1.2. ToBoolean ( argument ) +// The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9: +/* +-------------------------------------------------------------------------------------------------------------- +| Argument Type | Result | +-------------------------------------------------------------------------------------------------------------- +| Undefined | Return false. | +| Null | Return false. | +| Boolean | Return argument. | +| Number | If argument is +0, -0, or NaN, return false; otherwise return true. | +| String | If argument is the empty String (its length is zero), return false; otherwise return true. | +| Symbol | Return true. | +| Object | Return true. | +-------------------------------------------------------------------------------------------------------------- +*/ +function ToBoolean(argument) { // eslint-disable-line no-unused-vars + return Boolean(argument); +} +if (!('every' in Array.prototype)) { + +// Array.prototype.every +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */ +// 22.1.3.5. Array.prototype.every ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'every', function every(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O])); + // iii. If testResult is false, return false. + if (testResult === false) { + return false; + } + } + // d. Increase k by 1. + var k = k + 1; + } + // 7. Return true. + return true; +}); + +} + + +// _ESAbstract.ArrayCreate +// 9.4.2.2. ArrayCreate ( length [ , proto ] ) +function ArrayCreate(length /* [, proto] */) { // eslint-disable-line no-unused-vars + // 1. Assert: length is an integer Number ≥ 0. + // 2. If length is -0, set length to +0. + if (1 / length === -Infinity) { + length = 0; + } + // 3. If length>2^32-1, throw a RangeError exception. + if (length > (Math.pow(2, 32) - 1)) { + throw new RangeError('Invalid array length'); + } + // 4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%. + // 5. Let A be a newly created Array exotic object. + var A = []; + // 6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1. + // 7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1. + // 8. Set A.[[Prototype]] to proto. + // 9. Set A.[[Extensible]] to true. + // 10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}). + A.length = length; + // 11. Return A. + return A; +} + +// _ESAbstract.IsConstructor +/* global Type */ +// 7.2.4. IsConstructor ( argument ) +function IsConstructor(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + if (Type(argument) !== 'object') { + return false; + } + // 2. If argument has a [[Construct]] internal method, return true. + // 3. Return false. + + // Polyfill.io - `new argument` is the only way to truly test if a function is a constructor. + // We choose to not use`new argument` because the argument could have side effects when called. + // Instead we check to see if the argument is a function and if it has a prototype. + // Arrow functions do not have a [[Construct]] internal method, nor do they have a prototype. + return typeof argument === 'function' && !!argument.prototype; +} + +// _ESAbstract.GetPrototypeFromConstructor +/* global Get, Type */ +// 9.1.14. GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) +function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars + // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object. + // 2. Assert: IsCallable(constructor) is true. + // 3. Let proto be ? Get(constructor, "prototype"). + var proto = Get(constructor, "prototype"); + // 4. If Type(proto) is not Object, then + if (Type(proto) !== 'object') { + // a. Let realm be ? GetFunctionRealm(constructor). + // b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + proto = intrinsicDefaultProto; + } + // 5. Return proto. + return proto; +} +if (!('keys' in Object && (function () { + // Safari 5.0 bug where Object.keys doesn't work with arguments + return (Object.keys(arguments)).length === 2; +}(1, 2)) && (function () { + try { + // In ES6 Object.keys works on all object except `null` and `undefined`. + Object.keys(''); + return true; + } catch (e) { + return false; + } +}()))) { + +// Object.keys +Object.keys = (function() { + 'use strict'; + + // modified from https://github.com/es-shims/object-keys + + var has = Object.prototype.hasOwnProperty; + var toStr = Object.prototype.toString; + var isEnumerable = Object.prototype.propertyIsEnumerable; + var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString'); + var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype'); + var dontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor' + ]; + var equalsConstructorPrototype = function (o) { + var ctor = o.constructor; + return ctor && ctor.prototype === o; + }; + var excludedKeys = { + $console: true, + $external: true, + $frame: true, + $frameElement: true, + $frames: true, + $innerHeight: true, + $innerWidth: true, + $outerHeight: true, + $outerWidth: true, + $pageXOffset: true, + $pageYOffset: true, + $parent: true, + $scrollLeft: true, + $scrollTop: true, + $scrollX: true, + $scrollY: true, + $self: true, + $webkitIndexedDB: true, + $webkitStorageInfo: true, + $window: true + }; + var hasAutomationEqualityBug = (function () { + /* global window */ + if (typeof window === 'undefined') { return false; } + for (var k in window) { + try { + if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { + try { + equalsConstructorPrototype(window[k]); + } catch (e) { + return true; + } + } + } catch (e) { + return true; + } + } + return false; + }()); + var equalsConstructorPrototypeIfNotBuggy = function (o) { + /* global window */ + if (typeof window === 'undefined' || !hasAutomationEqualityBug) { + return equalsConstructorPrototype(o); + } + try { + return equalsConstructorPrototype(o); + } catch (e) { + return false; + } + }; + + function isArgumentsObject(value) { + var str = toStr.call(value); + var isArgs = str === '[object Arguments]'; + if (!isArgs) { + isArgs = str !== '[object Array]' && + value !== null && + typeof value === 'object' && + typeof value.length === 'number' && + value.length >= 0 && + toStr.call(value.callee) === '[object Function]'; + } + return isArgs; + } + + return function keys(object) { + var isFunction = toStr.call(object) === '[object Function]'; + var isArguments = isArgumentsObject(object); + var isString = toStr.call(object) === '[object String]'; + var theKeys = []; + + if (object === undefined || object === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + + var skipProto = hasProtoEnumBug && isFunction; + if (isString && object.length > 0 && !has.call(object, 0)) { + for (var i = 0; i < object.length; ++i) { + theKeys.push(String(i)); + } + } + + if (isArguments && object.length > 0) { + for (var j = 0; j < object.length; ++j) { + theKeys.push(String(j)); + } + } else { + for (var name in object) { + if (!(skipProto && name === 'prototype') && has.call(object, name)) { + theKeys.push(String(name)); + } + } + } + + if (hasDontEnumBug) { + var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); + + for (var k = 0; k < dontEnums.length; ++k) { + if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { + theKeys.push(dontEnums[k]); + } + } + } + return theKeys; + }; +}()); + +} + +if (!('bind' in Function.prototype)) { + +// Function.prototype.bind +/* global CreateMethodProperty, IsCallable */ +// 19.2.3.2. Function.prototype.bind ( thisArg, ...args ) +// https://github.com/es-shims/es5-shim/blob/d6d7ff1b131c7ba14c798cafc598bb6780d37d3b/es5-shim.js#L182 +CreateMethodProperty(Function.prototype, 'bind', function bind(that) { // .length is 1 + // add necessary es5-shim utilities + var $Array = Array; + var $Object = Object; + var ArrayPrototype = $Array.prototype; + var Empty = function Empty() { }; + var array_slice = ArrayPrototype.slice; + var array_concat = ArrayPrototype.concat; + var array_push = ArrayPrototype.push; + var max = Math.max; + // /add necessary es5-shim utilities + + // 1. Let Target be the this value. + var target = this; + // 2. If IsCallable(Target) is false, throw a TypeError exception. + if (!IsCallable(target)) { + throw new TypeError('Function.prototype.bind called on incompatible ' + target); + } + // 3. Let A be a new (possibly empty) internal list of all of the + // argument values provided after thisArg (arg1, arg2 etc), in order. + // XXX slicedArgs will stand in for "A" if used + var args = array_slice.call(arguments, 1); // for normal call + // 4. Let F be a new native ECMAScript object. + // 11. Set the [[Prototype]] internal property of F to the standard + // built-in Function prototype object as specified in 15.3.3.1. + // 12. Set the [[Call]] internal property of F as described in + // 15.3.4.5.1. + // 13. Set the [[Construct]] internal property of F as described in + // 15.3.4.5.2. + // 14. Set the [[HasInstance]] internal property of F as described in + // 15.3.4.5.3. + var bound; + var binder = function () { + + if (this instanceof bound) { + // 15.3.4.5.2 [[Construct]] + // When the [[Construct]] internal method of a function object, + // F that was created using the bind function is called with a + // list of arguments ExtraArgs, the following steps are taken: + // 1. Let target be the value of F's [[TargetFunction]] + // internal property. + // 2. If target has no [[Construct]] internal method, a + // TypeError exception is thrown. + // 3. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Construct]] internal + // method of target providing args as the arguments. + + var result = target.apply( + this, + array_concat.call(args, array_slice.call(arguments)) + ); + if ($Object(result) === result) { + return result; + } + return this; + + } else { + // 15.3.4.5.1 [[Call]] + // When the [[Call]] internal method of a function object, F, + // which was created using the bind function is called with a + // this value and a list of arguments ExtraArgs, the following + // steps are taken: + // 1. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 2. Let boundThis be the value of F's [[BoundThis]] internal + // property. + // 3. Let target be the value of F's [[TargetFunction]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Call]] internal method + // of target providing boundThis as the this value and + // providing args as the arguments. + + // equiv: target.call(this, ...boundArgs, ...args) + return target.apply( + that, + array_concat.call(args, array_slice.call(arguments)) + ); + + } + + }; + + // 15. If the [[Class]] internal property of Target is "Function", then + // a. Let L be the length property of Target minus the length of A. + // b. Set the length own property of F to either 0 or L, whichever is + // larger. + // 16. Else set the length own property of F to 0. + + var boundLength = max(0, target.length - args.length); + + // 17. Set the attributes of the length own property of F to the values + // specified in 15.3.5.1. + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + array_push.call(boundArgs, '$' + i); + } + + // XXX Build a dynamic function with desired amount of arguments is the only + // way to set the length property of a function. + // In environments where Content Security Policies enabled (Chrome extensions, + // for ex.) all use of eval or Function costructor throws an exception. + // However in all of these environments Function.prototype.bind exists + // and so this code will never be executed. + bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder); + + if (target.prototype) { + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + // Clean up dangling references. + Empty.prototype = null; + } + + // TODO + // 18. Set the [[Extensible]] internal property of F to true. + + // TODO + // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3). + // 20. Call the [[DefineOwnProperty]] internal method of F with + // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]: + // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and + // false. + // 21. Call the [[DefineOwnProperty]] internal method of F with + // arguments "arguments", PropertyDescriptor {[[Get]]: thrower, + // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false}, + // and false. + + // TODO + // NOTE Function objects created using Function.prototype.bind do not + // have a prototype property or the [[Code]], [[FormalParameters]], and + // [[Scope]] internal properties. + // XXX can't delete prototype in pure-js. + + // 22. Return F. + return bound; +}); + +} + +if (!('getOwnPropertyDescriptor' in Object && typeof Object.getOwnPropertyDescriptor === 'function' && (function() { + try { + var object = {}; + object.test = 0; + return Object.getOwnPropertyDescriptor( + object, + "test" + ).value === 0; + } catch (exception) { + return false + } +}()))) { + +// Object.getOwnPropertyDescriptor +/* global CreateMethodProperty */ +(function () { + var call = Function.prototype.call; + var prototypeOfObject = Object.prototype; + var owns = call.bind(prototypeOfObject.hasOwnProperty); + + var lookupGetter; + var lookupSetter; + var supportsAccessors; + if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { + lookupGetter = call.bind(prototypeOfObject.__lookupGetter__); + lookupSetter = call.bind(prototypeOfObject.__lookupSetter__); + } + function doesGetOwnPropertyDescriptorWork(object) { + try { + object.sentinel = 0; + return Object.getOwnPropertyDescriptor( + object, + "sentinel" + ).value === 0; + } catch (exception) { + // returns falsy + } + } + // check whether getOwnPropertyDescriptor works if it's given. Otherwise, + // shim partially. + if (Object.defineProperty) { + var getOwnPropertyDescriptorWorksOnObject = + doesGetOwnPropertyDescriptorWork({}); + var getOwnPropertyDescriptorWorksOnDom = typeof document == "undefined" || + doesGetOwnPropertyDescriptorWork(document.createElement("div")); + if (!getOwnPropertyDescriptorWorksOnDom || + !getOwnPropertyDescriptorWorksOnObject + ) { + var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor; + } + } + + if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) { + var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: "; + + CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(object, property) { + if ((typeof object != "object" && typeof object != "function") || object === null) { + throw new TypeError(ERR_NON_OBJECT + object); + } + + // make a valiant attempt to use the real getOwnPropertyDescriptor + // for I8's DOM elements. + if (getOwnPropertyDescriptorFallback) { + try { + return getOwnPropertyDescriptorFallback.call(Object, object, property); + } catch (exception) { + // try the shim if the real one doesn't work + } + } + + // If object does not owns property return undefined immediately. + if (!owns(object, property)) { + return; + } + + // If object has a property then it's for sure both `enumerable` and + // `configurable`. + var descriptor = { enumerable: true, configurable: true }; + + // If JS engine supports accessor properties then property may be a + // getter or setter. + if (supportsAccessors) { + // Unfortunately `__lookupGetter__` will return a getter even + // if object has own non getter property along with a same named + // inherited getter. To avoid misbehavior we temporary remove + // `__proto__` so that `__lookupGetter__` will return getter only + // if it's owned by an object. + var prototype = object.__proto__; + object.__proto__ = prototypeOfObject; + + var getter = lookupGetter(object, property); + var setter = lookupSetter(object, property); + + // Once we have getter and setter we can put values back. + object.__proto__ = prototype; + + if (getter || setter) { + if (getter) { + descriptor.get = getter; + } + if (setter) { + descriptor.set = setter; + } + // If it was accessor property we're done and return here + // in order to avoid adding `value` to the descriptor. + return descriptor; + } + } + + // If we got this far we know that object has an own property that is + // not an accessor so we set it as a value and return descriptor. + descriptor.value = object[property]; + descriptor.writable = true; + return descriptor; + }); + } +}()); + +} + +if (!('defineProperties' in Object)) { + +// Object.defineProperties +/* global CreateMethodProperty, Get, ToObject, Type */ +// 19.1.2.3. Object.defineProperties ( O, Properties ) +CreateMethodProperty(Object, 'defineProperties', function defineProperties(O, Properties) { + // 1. If Type(O) is not Object, throw a TypeError exception. + if (Type(O) !== 'object') { + throw new TypeError('Object.defineProperties called on non-object'); + } + // 2. Let props be ? ToObject(Properties). + var props = ToObject(Properties); + // 3. Let keys be ? props.[[OwnPropertyKeys]](). + /* + Polyfill.io - This step in our polyfill is not complying with the specification. + [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols. + TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]]. + */ + var keys = Object.keys(props); + // 4. Let descriptors be a new empty List. + var descriptors = []; + // 5. For each element nextKey of keys in List order, do + for (var i = 0; i < keys.length; i++) { + var nextKey = keys[i]; + // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey). + var propDesc = Object.getOwnPropertyDescriptor(props, nextKey); + // b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then + if (propDesc !== undefined && propDesc.enumerable) { + // i. Let descObj be ? Get(props, nextKey). + var descObj = Get(props, nextKey); + // ii. Let desc be ? ToPropertyDescriptor(descObj). + // Polyfill.io - We skip this step because Object.defineProperty deals with it. + // TODO: Implement this step? + var desc = descObj; + // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. + descriptors.push([nextKey, desc]); + } + } + // 6. For each pair from descriptors in list order, do + for (var i = 0; i < descriptors.length; i++){ + // a. Let P be the first element of pair. + var P = descriptors[i][0]; + // b. Let desc be the second element of pair. + var desc = descriptors[i][1]; + // c. Perform ? DefinePropertyOrThrow(O, P, desc). + Object.defineProperty(O, P, desc); + } + // 7. Return O. + return O; +}); + +} + +if (!('create' in Object)) { + +// Object.create +/* global CreateMethodProperty, Type */ +CreateMethodProperty(Object, 'create', function create(O, properties) { + // 1. If Type(O) is neither Object nor Null, throw a TypeError exception. + if (Type(O) !== 'object' && Type(O) !== 'null') { + throw new TypeError('Object prototype may only be an Object or null'); + } + // 2. Let obj be ObjectCreate(O). + var obj = new Function('e', 'function Object() {}Object.prototype=e;return new Object')(O); + + obj.constructor.prototype = O; + + // 3. If Properties is not undefined, then + if (1 in arguments) { + // a. Return ? ObjectDefineProperties(obj, Properties). + return Object.defineProperties(obj, properties); + } + + return obj; +}); + +} + +if (!('getPrototypeOf' in Object)) { + +// Object.getPrototypeOf +/* global CreateMethodProperty */ +// Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js + +// https://github.com/es-shims/es5-shim/issues#issue/2 +// http://ejohn.org/blog/objectgetprototypeof/ +// recommended by fschaefer on github +// +// sure, and webreflection says ^_^ +// ... this will nerever possibly return null +// ... Opera Mini breaks here with infinite loops +CreateMethodProperty(Object, 'getPrototypeOf', function getPrototypeOf(object) { + if (object !== Object(object)) { + throw new TypeError('Object.getPrototypeOf called on non-object'); + } + var proto = object.__proto__; + if (proto || proto === null) { + return proto; + } else if (typeof object.constructor == 'function' && object instanceof object.constructor) { + return object.constructor.prototype; + } else if (object instanceof Object) { + return Object.prototype; + } else { + // Correctly return null for Objects created with `Object.create(null)` + // (shammed or native) or `{ __proto__: null}`. Also returns null for + // cross-realm objects on browsers that lack `__proto__` support (like + // IE <11), but that's the best we can do. + return null; + } +}); + +} + + +// _ESAbstract.OrdinaryCreateFromConstructor +/* global GetPrototypeFromConstructor */ +// 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) +function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars + var internalSlotsList = arguments[2] || {}; + // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. + // The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object. + + // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto); + + // 3. Return ObjectCreate(proto, internalSlotsList). + // Polyfill.io - We do not pass internalSlotsList to Object.create because Object.create does not use the default ordinary object definitions specified in 9.1. + var obj = Object.create(proto); + for (var name in internalSlotsList) { + if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) { + Object.defineProperty(obj, name, { + configurable: true, + enumerable: false, + writable: true, + value: internalSlotsList[name] + }); + } + } + return obj; +} + +// _ESAbstract.Construct +/* global IsConstructor, OrdinaryCreateFromConstructor, Call */ +// 7.3.13. Construct ( F [ , argumentsList [ , newTarget ]] ) +function Construct(F /* [ , argumentsList [ , newTarget ]] */) { // eslint-disable-line no-unused-vars + // 1. If newTarget is not present, set newTarget to F. + var newTarget = arguments.length > 2 ? arguments[2] : F; + + // 2. If argumentsList is not present, set argumentsList to a new empty List. + var argumentsList = arguments.length > 1 ? arguments[1] : []; + + // 3. Assert: IsConstructor(F) is true. + if (!IsConstructor(F)) { + throw new TypeError('F must be a constructor.'); + } + + // 4. Assert: IsConstructor(newTarget) is true. + if (!IsConstructor(newTarget)) { + throw new TypeError('newTarget must be a constructor.'); + } + + // 5. Return ? F.[[Construct]](argumentsList, newTarget). + // Polyfill.io - If newTarget is the same as F, it is equivalent to new F(...argumentsList). + if (newTarget === F) { + return new (Function.prototype.bind.apply(F, [null].concat(argumentsList)))(); + } else { + // Polyfill.io - This is mimicking section 9.2.2 step 5.a. + var obj = OrdinaryCreateFromConstructor(newTarget, Object.prototype); + return Call(F, obj, argumentsList); + } +} + +// _ESAbstract.ArraySpeciesCreate +/* global IsArray, ArrayCreate, Get, Type, IsConstructor, Construct */ +// 9.4.2.3. ArraySpeciesCreate ( originalArray, length ) +function ArraySpeciesCreate(originalArray, length) { // eslint-disable-line no-unused-vars + // 1. Assert: length is an integer Number ≥ 0. + // 2. If length is -0, set length to +0. + if (1/length === -Infinity) { + length = 0; + } + + // 3. Let isArray be ? IsArray(originalArray). + var isArray = IsArray(originalArray); + + // 4. If isArray is false, return ? ArrayCreate(length). + if (isArray === false) { + return ArrayCreate(length); + } + + // 5. Let C be ? Get(originalArray, "constructor"). + var C = Get(originalArray, 'constructor'); + + // Polyfill.io - We skip this section as not sure how to make a cross-realm normal Array, a same-realm Array. + // 6. If IsConstructor(C) is true, then + // if (IsConstructor(C)) { + // a. Let thisRealm be the current Realm Record. + // b. Let realmC be ? GetFunctionRealm(C). + // c. If thisRealm and realmC are not the same Realm Record, then + // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. + // } + // 7. If Type(C) is Object, then + if (Type(C) === 'object') { + // a. Set C to ? Get(C, @@species). + C = 'Symbol' in this && 'species' in this.Symbol ? Get(C, this.Symbol.species) : undefined; + // b. If C is null, set C to undefined. + if (C === null) { + C = undefined; + } + } + // 8. If C is undefined, return ? ArrayCreate(length). + if (C === undefined) { + return ArrayCreate(length); + } + // 9. If IsConstructor(C) is false, throw a TypeError exception. + if (!IsConstructor(C)) { + throw new TypeError('C must be a constructor'); + } + // 10. Return ? Construct(C, « length »). + return Construct(C, [length]); +} + +// _ESAbstract.CreateDataProperty +// 7.3.4. CreateDataProperty ( O, P, V ) +// NOTE +// This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. +// Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false. +function CreateDataProperty(O, P, V) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Let newDesc be the PropertyDescriptor{ [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }. + var newDesc = { + value: V, + writable: true, + enumerable: true, + configurable: true + }; + // 4. Return ? O.[[DefineOwnProperty]](P, newDesc). + try { + Object.defineProperty(O, P, newDesc); + return true; + } catch (e) { + return false; + } +} + +// _ESAbstract.CreateDataPropertyOrThrow +/* global CreateDataProperty */ +// 7.3.6. CreateDataPropertyOrThrow ( O, P, V ) +function CreateDataPropertyOrThrow(O, P, V) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Let success be ? CreateDataProperty(O, P, V). + var success = CreateDataProperty(O, P, V); + // 4. If success is false, throw a TypeError exception. + if (!success) { + throw new TypeError('Cannot assign value `' + Object.prototype.toString.call(V) + '` to property `' + Object.prototype.toString.call(P) + '` on object `' + Object.prototype.toString.call(O) + '`'); + } + // 5. Return success. + return success; +} +if (!('filter' in Array.prototype)) { + +// Array.prototype.filter +/* global CreateMethodProperty, ToObject, ToLength, Get, IsCallable, ArraySpeciesCreate, ToString, HasProperty, ToBoolean, Call, CreateDataPropertyOrThrow */ +// 22.1.3.7. Array.prototype.filter ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'filter', function filter(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let A be ? ArraySpeciesCreate(O, 0). + var A = ArraySpeciesCreate(O, 0); + // 6. Let k be 0. + var k = 0; + // 7. Let to be 0. + var to = 0; + // 8. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + var selected = ToBoolean(Call(callbackfn, T, [kValue, k, O])); + // iii. If selected is true, then + if (selected) { + // 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue) + CreateDataPropertyOrThrow(A, ToString(to), kValue); + // 2. Increase to by 1. + to = to + 1; + } + + } + // d. Increase k by 1. + k = k + 1; + } + // 9. Return A. + return A; +}); + +} + +if (!('forEach' in Array.prototype)) { + +// Array.prototype.forEach +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +// 22.1.3.10. Array.prototype.forEach ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'forEach', function forEach(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly. + // We will use arrayLike in place of O when we are iterating through the list. + var arraylike = O instanceof String ? O.split('') : O; + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(arraylike, Pk); + // ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + Call(callbackfn, T, [kValue, k, O]); + } + // d. Increase k by 1. + k = k + 1; + } + // 7. Return undefined. + return undefined; +}); + +} + +if (!('indexOf' in Array.prototype)) { + +// Array.prototype.indexOf +/* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */ +// 22.1.3.12. Array.prototype.indexOf ( searchElement [ , fromIndex ] ) +CreateMethodProperty(Array.prototype, 'indexOf', function indexOf(searchElement /* [ , fromIndex ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If len is 0, return -1. + if (len === 0) { + return -1; + } + // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.) + var n = ToInteger(arguments[1]); + // 5. If n ≥ len, return -1. + if (n >= len) { + return -1; + } + // 6. If n ≥ 0, then + if (n >= 0) { + // a. If n is -0, let k be +0; else let k be n. + var k = n === -0 ? 0 : n; + // 7. Else n < 0, + } else { + // a. Let k be len + n. + var k = len + n; + // b. If k < 0, let k be 0. + if (k < 0) { + k = 0; + } + } + // 8. Repeat, while k < len + while (k < len) { + // a. Let kPresent be ? HasProperty(O, ! ToString(k)). + var kPresent = HasProperty(O, ToString(k)); + // b. If kPresent is true, then + if (kPresent) { + // i. Let elementK be ? Get(O, ! ToString(k)). + var elementK = Get(O, ToString(k)); + // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK. + var same = searchElement === elementK; + // iii. If same is true, return k. + if (same) { + return k; + } + } + // c. Increase k by 1. + k = k + 1; + } + // 9. Return -1. + return -1; +}); + +} + +if (!('lastIndexOf' in Array.prototype)) { + +// Array.prototype.lastIndexOf +/* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */ +// 22.1.3.15. Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) +CreateMethodProperty(Array.prototype, 'lastIndexOf', function lastIndexOf(searchElement /* [ , fromIndex ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If len is 0, return -1. + if (len === 0) { + return -1; + } + // 4. If fromIndex is present, let n be ? ToInteger(fromIndex); else let n be len-1. + var n = arguments.length > 1 ? ToInteger(arguments[1]) : len - 1; + // 5. If n ≥ 0, then + if (n >= 0) { + // a. If n is -0, let k be +0; else let k be min(n, len - 1). + var k = n === -0 ? 0 : Math.min(n, len - 1); + // 6. Else n < 0, + } else { + // a. Let k be len + n. + k = len + n; + } + // 7. Repeat, while k ≥ 0 + while (k >= 0) { + // a. Let kPresent be ? HasProperty(O, ! ToString(k)). + var kPresent = HasProperty(O, ToString(k)); + // b. If kPresent is true, then + if (kPresent) { + // i. Let elementK be ? Get(O, ! ToString(k)). + var elementK = Get(O, ToString(k)); + // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK. + var same = searchElement === elementK; + // iii. If same is true, return k. + if (same) { + return k; + } + } + // c. Decrease k by 1. + k = k - 1; + } + // 9. Return -1. + return -1; +}); + +} + +if (!('map' in Array.prototype)) { + +// Array.prototype.map +/* global ArraySpeciesCreate, Call, CreateDataPropertyOrThrow, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +/* global CreateMethodProperty, ToObject, ToLength, Get, ArraySpeciesCreate, ToString, HasProperty, Call, CreateDataPropertyOrThrow */ +// 22.1.3.16. Array.prototype.map ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'map', function map(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let A be ? ArraySpeciesCreate(O, len). + var A = ArraySpeciesCreate(O, len); + // 6. Let k be 0. + var k = 0; + // 7. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + var mappedValue = Call(callbackfn, T, [kValue, k, O]); + // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + } + // d. Increase k by 1. + k = k + 1; + } + // 8. Return A. + return A; +}); + +} + +if (!('reduce' in Array.prototype)) { + +// Array.prototype.reduce +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +// 22.1.3.19. Array.prototype.reduce ( callbackfn [ , initialValue ] ) +CreateMethodProperty(Array.prototype, 'reduce', function reduce(callbackfn /* [ , initialValue ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly. + // We will use arrayLike in place of O when we are iterating through the list. + var arraylike = O instanceof String ? O.split('') : O; + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(arraylike, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If len is 0 and initialValue is not present, throw a TypeError exception. + var initialValue = arguments.length > 1 ? arguments[1] : undefined; + if (len === 0 && arguments.length < 2) { + throw new TypeError('Reduce of empty array with no initial value'); + } + // 5. Let k be 0. + var k = 0; + // 6. Let accumulator be undefined. + var accumulator = undefined; + // 7. If initialValue is present, then + if (arguments.length > 1) { + // a. Set accumulator to initialValue. + accumulator = initialValue; + // 8. Else initialValue is not present, + } else { + // a. Let kPresent be false. + var kPresent = false; + // b. Repeat, while kPresent is false and k < len + while (kPresent === false && k < len) { + // i. Let Pk be ! ToString(k). + var Pk = ToString(k); + // ii. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // iii. If kPresent is true, then + if (kPresent) { + // 1. Set accumulator to ? Get(O, Pk). + var accumulator = Get(arraylike, Pk); + } + // iv. Increase k by 1. + k = k + 1; + } + // c. If kPresent is false, throw a TypeError exception. + if (kPresent === false) { + throw new TypeError('Reduce of empty array with no initial value'); + } + } + // 9. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(arraylike, Pk); + // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »). + accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]); + } + // d. Increase k by 1. + k = k + 1; + } + // 10. Return accumulator. + return accumulator; +}); + +} + +if (!('reduceRight' in Array.prototype)) { + +// Array.prototype.reduceRight +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +// 22.1.3.20. Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) +CreateMethodProperty(Array.prototype, 'reduceRight', function reduceRight(callbackfn /* [ , initialValue ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly. + // We will use arrayLike in place of O when we are iterating through the list. + var arraylike = O instanceof String ? O.split('') : O; + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(arraylike, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If len is 0 and initialValue is not present, throw a TypeError exception. + var initialValue = arguments.length > 1 ? arguments[1] : undefined; + if (len === 0 && arguments.length < 2) { + throw new TypeError('Reduce of empty array with no initial value'); + } + // 5. Let k be len-1. + var k = len - 1; + // 6. Let accumulator be undefined. + var accumulator = undefined; + // 7. If initialValue is present, then + if (arguments.length > 1) { + // a. Set accumulator to initialValue. + accumulator = initialValue; + // 8.Else initialValue is not present, + } else { + // a. Let kPresent be false. + var kPresent = false; + // b. Repeat, while kPresent is false and k ≥ 0 + while (kPresent === false && k >= 0) { + // i. Let Pk be ! ToString(k). + var Pk = ToString(k); + // ii. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // iii. If kPresent is true, then + if (kPresent) { + // 1. Set accumulator to ? Get(O, Pk). + accumulator = Get(arraylike, Pk); + } + // iv. Decrease k by 1. + k = k - 1; + } + // c. If kPresent is false, throw a TypeError exception. + if (kPresent === false) { + throw new TypeError('Reduce of empty array with no initial value'); + } + } + // 9. Repeat, while k ≥ 0 + while (k >= 0) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(arraylike, Pk); + // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »). + accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]); + } + // d. Decrease k by 1. + k = k - 1; + } + // 10 Return accumulator. + return accumulator; +}); + +} + +if (!('some' in Array.prototype)) { + +// Array.prototype.some +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */ +// 22.1.3.24. Array.prototype.some ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'some', function some(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O])); + // iii. If testResult is true, return true. + if (testResult) { + return true; + } + } + // d. Increase k by 1. + k = k + 1; + } + // 7. Return false. + return false; +}); + +} + +if (!('Date' in this && 'now' in this.Date && 'getTime' in this.Date.prototype)) { + +// Date.now +Date.now = function now() { + return new Date().getTime(); +}; + +} + +if (!('Date' in this && 'toISOString' in Date.prototype)) { + +// Date.prototype.toISOString +Date.prototype.toISOString = function toISOString() { + var date = this; + + function pad(str, len) { + var pad = "0000"; + str = '' + str; + return pad.substr(0, len - str.length) + str; + } + + var y = date.getUTCFullYear(), + m = pad(date.getUTCMonth() + 1, 2), + d = pad(date.getUTCDate(), 2), + h = pad(date.getUTCHours(), 2), + i = pad(date.getUTCMinutes(), 2), + s = pad(date.getUTCSeconds(), 2), + ms = pad(date.getUTCMilliseconds(), 3); + + return y +'-'+ m +'-'+ d + 'T' + h +':'+ i +':'+ s +'.'+ ms +'Z'; +}; + +} + +if (!('freeze' in Object)) { + +// Object.freeze +/* global CreateMethodProperty */ +// 19.1.2.6. Object.freeze ( O ) +CreateMethodProperty(Object, 'freeze', function freeze(O) { + // This feature cannot be implemented fully as a polyfill. + // We choose to silently fail which allows "securable" code + // to "gracefully" degrade to working but insecure code. + return O; +}); + +} + +if (!('getOwnPropertyNames' in Object)) { + +// Object.getOwnPropertyNames +/* global CreateMethodProperty */ + +var toString = ({}).toString; +var split = ''.split; + +CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) { + var buffer = []; + var key; + + // Non-enumerable properties cannot be discovered but can be checked for by name. + // Define those used internally by JS to allow an incomplete solution + var commonProps = ['length', "name", "arguments", "caller", "prototype", "observe", "unobserve"]; + + if (typeof object === 'undefined' || object === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + + // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8) + object = toString.call(object) == '[object String]' ? split.call(object, '') : Object(object); + + // Enumerable properties only + for (key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + buffer.push(key); + } + } + + // Check for and add the common non-enumerable properties + for (var i=0, s=commonProps.length; i 2 ? arguments[2] : []; + // 2. If IsCallable(F) is false, throw a TypeError exception. + if (IsCallable(F) === false) { + throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.'); + } + // 3. Return ? F.[[Call]](V, argumentsList). + return F.apply(V, argumentsList); +} + +// _ESAbstract.Type +// "Type(x)" is used as shorthand for "the type of x"... +function Type(x) { // eslint-disable-line no-unused-vars + switch (typeof x) { + case 'undefined': + return 'undefined'; + case 'boolean': + return 'boolean'; + case 'number': + return 'number'; + case 'string': + return 'string'; + case 'symbol': + return 'symbol'; + default: + // typeof null is 'object' + if (x === null) return 'null'; + // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`. + if ('Symbol' in this && x instanceof this.Symbol) return 'symbol'; + return 'object'; + } +} + +// _ESAbstract.OrdinaryToPrimitive +/* global Get, IsCallable, Call, Type */ +// 7.1.1.1. OrdinaryToPrimitive ( O, hint ) +function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: Type(hint) is String and its value is either "string" or "number". + // 3. If hint is "string", then + if (hint === 'string') { + // a. Let methodNames be « "toString", "valueOf" ». + var methodNames = ['toString', 'valueOf']; + // 4. Else, + } else { + // a. Let methodNames be « "valueOf", "toString" ». + methodNames = ['valueOf', 'toString']; + } + // 5. For each name in methodNames in List order, do + for (var i = 0; i < methodNames.length; ++i) { + var name = methodNames[i]; + // a. Let method be ? Get(O, name). + var method = Get(O, name); + // b. If IsCallable(method) is true, then + if (IsCallable(method)) { + // i. Let result be ? Call(method, O). + var result = Call(method, O); + // ii. If Type(result) is not Object, return result. + if (Type(result) !== 'object') { + return result; + } + } + } + // 6. Throw a TypeError exception. + throw new TypeError('Cannot convert to primitive.'); +} + +// _ESAbstract.ToPrimitive +/* global Type, GetMethod, Call, OrdinaryToPrimitive */ +// 7.1.1. ToPrimitive ( input [ , PreferredType ] ) +function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars + var PreferredType = arguments.length > 1 ? arguments[1] : undefined; + // 1. Assert: input is an ECMAScript language value. + // 2. If Type(input) is Object, then + if (Type(input) === 'object') { + // a. If PreferredType is not present, let hint be "default". + if (arguments.length < 2) { + var hint = 'default'; + // b. Else if PreferredType is hint String, let hint be "string". + } else if (PreferredType === String) { + hint = 'string'; + // c. Else PreferredType is hint Number, let hint be "number". + } else if (PreferredType === Number) { + hint = 'number'; + } + // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + var exoticToPrim = typeof this.Symbol === 'function' && typeof this.Symbol.toPrimitive === 'symbol' ? GetMethod(input, this.Symbol.toPrimitive) : undefined; + // e. If exoticToPrim is not undefined, then + if (exoticToPrim !== undefined) { + // i. Let result be ? Call(exoticToPrim, input, « hint »). + var result = Call(exoticToPrim, input, [hint]); + // ii. If Type(result) is not Object, return result. + if (Type(result) !== 'object') { + return result; + } + // iii. Throw a TypeError exception. + throw new TypeError('Cannot convert exotic object to primitive.'); + } + // f. If hint is "default", set hint to "number". + if (hint === 'default') { + hint = 'number'; + } + // g. Return ? OrdinaryToPrimitive(input, hint). + return OrdinaryToPrimitive(input, hint); + } + // 3. Return input + return input; +} + +// _ESAbstract.ToString +/* global Type, ToPrimitive */ +// 7.1.12. ToString ( argument ) +// The abstract operation ToString converts argument to a value of type String according to Table 11: +// Table 11: ToString Conversions +/* +|---------------|--------------------------------------------------------| +| Argument Type | Result | +|---------------|--------------------------------------------------------| +| Undefined | Return "undefined". | +|---------------|--------------------------------------------------------| +| Null | Return "null". | +|---------------|--------------------------------------------------------| +| Boolean | If argument is true, return "true". | +| | If argument is false, return "false". | +|---------------|--------------------------------------------------------| +| Number | Return NumberToString(argument). | +|---------------|--------------------------------------------------------| +| String | Return argument. | +|---------------|--------------------------------------------------------| +| Symbol | Throw a TypeError exception. | +|---------------|--------------------------------------------------------| +| Object | Apply the following steps: | +| | Let primValue be ? ToPrimitive(argument, hint String). | +| | Return ? ToString(primValue). | +|---------------|--------------------------------------------------------| +*/ +function ToString(argument) { // eslint-disable-line no-unused-vars + switch(Type(argument)) { + case 'symbol': + throw new TypeError('Cannot convert a Symbol value to a string'); + break; + case 'object': + var primValue = ToPrimitive(argument, 'string'); + return ToString(primValue); + default: + return String(argument); + } +} +if (!('forEach' in Array.prototype)) { + +// Array.prototype.forEach +/* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +// 22.1.3.10. Array.prototype.forEach ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'forEach', function forEach(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly. + // We will use arrayLike in place of O when we are iterating through the list. + var arraylike = O instanceof String ? O.split('') : O; + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(arraylike, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(arraylike, Pk); + // ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + Call(callbackfn, T, [kValue, k, O]); + } + // d. Increase k by 1. + k = k + 1; + } + // 7. Return undefined. + return undefined; +}); + +} + + +// _ESAbstract.IsArray +// 7.2.2. IsArray ( argument ) +function IsArray(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + // 2. If argument is an Array exotic object, return true. + // 3. If argument is a Proxy exotic object, then + // a. If argument.[[ProxyHandler]] is null, throw a TypeError exception. + // b. Let target be argument.[[ProxyTarget]]. + // c. Return ? IsArray(target). + // 4. Return false. + + // Polyfill.io - We can skip all the above steps and check the string returned from Object.prototype.toString(). + return Object.prototype.toString.call(argument) === '[object Array]'; +} + +// _ESAbstract.ArrayCreate +// 9.4.2.2. ArrayCreate ( length [ , proto ] ) +function ArrayCreate(length /* [, proto] */) { // eslint-disable-line no-unused-vars + // 1. Assert: length is an integer Number ≥ 0. + // 2. If length is -0, set length to +0. + if (1 / length === -Infinity) { + length = 0; + } + // 3. If length>2^32-1, throw a RangeError exception. + if (length > (Math.pow(2, 32) - 1)) { + throw new RangeError('Invalid array length'); + } + // 4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%. + // 5. Let A be a newly created Array exotic object. + var A = []; + // 6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1. + // 7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1. + // 8. Set A.[[Prototype]] to proto. + // 9. Set A.[[Extensible]] to true. + // 10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}). + A.length = length; + // 11. Return A. + return A; +} + +// _ESAbstract.IsConstructor +/* global Type */ +// 7.2.4. IsConstructor ( argument ) +function IsConstructor(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + if (Type(argument) !== 'object') { + return false; + } + // 2. If argument has a [[Construct]] internal method, return true. + // 3. Return false. + + // Polyfill.io - `new argument` is the only way to truly test if a function is a constructor. + // We choose to not use`new argument` because the argument could have side effects when called. + // Instead we check to see if the argument is a function and if it has a prototype. + // Arrow functions do not have a [[Construct]] internal method, nor do they have a prototype. + return typeof argument === 'function' && !!argument.prototype; +} + +// _ESAbstract.GetPrototypeFromConstructor +/* global Get, Type */ +// 9.1.14. GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) +function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars + // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object. + // 2. Assert: IsCallable(constructor) is true. + // 3. Let proto be ? Get(constructor, "prototype"). + var proto = Get(constructor, "prototype"); + // 4. If Type(proto) is not Object, then + if (Type(proto) !== 'object') { + // a. Let realm be ? GetFunctionRealm(constructor). + // b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + proto = intrinsicDefaultProto; + } + // 5. Return proto. + return proto; +} +if (!('keys' in Object && (function () { + // Safari 5.0 bug where Object.keys doesn't work with arguments + return (Object.keys(arguments)).length === 2; +}(1, 2)) && (function () { + try { + // In ES6 Object.keys works on all object except `null` and `undefined`. + Object.keys(''); + return true; + } catch (e) { + return false; + } +}()))) { + +// Object.keys +Object.keys = (function() { + 'use strict'; + + // modified from https://github.com/es-shims/object-keys + + var has = Object.prototype.hasOwnProperty; + var toStr = Object.prototype.toString; + var isEnumerable = Object.prototype.propertyIsEnumerable; + var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString'); + var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype'); + var dontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor' + ]; + var equalsConstructorPrototype = function (o) { + var ctor = o.constructor; + return ctor && ctor.prototype === o; + }; + var excludedKeys = { + $console: true, + $external: true, + $frame: true, + $frameElement: true, + $frames: true, + $innerHeight: true, + $innerWidth: true, + $outerHeight: true, + $outerWidth: true, + $pageXOffset: true, + $pageYOffset: true, + $parent: true, + $scrollLeft: true, + $scrollTop: true, + $scrollX: true, + $scrollY: true, + $self: true, + $webkitIndexedDB: true, + $webkitStorageInfo: true, + $window: true + }; + var hasAutomationEqualityBug = (function () { + /* global window */ + if (typeof window === 'undefined') { return false; } + for (var k in window) { + try { + if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { + try { + equalsConstructorPrototype(window[k]); + } catch (e) { + return true; + } + } + } catch (e) { + return true; + } + } + return false; + }()); + var equalsConstructorPrototypeIfNotBuggy = function (o) { + /* global window */ + if (typeof window === 'undefined' || !hasAutomationEqualityBug) { + return equalsConstructorPrototype(o); + } + try { + return equalsConstructorPrototype(o); + } catch (e) { + return false; + } + }; + + function isArgumentsObject(value) { + var str = toStr.call(value); + var isArgs = str === '[object Arguments]'; + if (!isArgs) { + isArgs = str !== '[object Array]' && + value !== null && + typeof value === 'object' && + typeof value.length === 'number' && + value.length >= 0 && + toStr.call(value.callee) === '[object Function]'; + } + return isArgs; + } + + return function keys(object) { + var isFunction = toStr.call(object) === '[object Function]'; + var isArguments = isArgumentsObject(object); + var isString = toStr.call(object) === '[object String]'; + var theKeys = []; + + if (object === undefined || object === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + + var skipProto = hasProtoEnumBug && isFunction; + if (isString && object.length > 0 && !has.call(object, 0)) { + for (var i = 0; i < object.length; ++i) { + theKeys.push(String(i)); + } + } + + if (isArguments && object.length > 0) { + for (var j = 0; j < object.length; ++j) { + theKeys.push(String(j)); + } + } else { + for (var name in object) { + if (!(skipProto && name === 'prototype') && has.call(object, name)) { + theKeys.push(String(name)); + } + } + } + + if (hasDontEnumBug) { + var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); + + for (var k = 0; k < dontEnums.length; ++k) { + if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { + theKeys.push(dontEnums[k]); + } + } + } + return theKeys; + }; +}()); + +} + +if (!('bind' in Function.prototype)) { + +// Function.prototype.bind +/* global CreateMethodProperty, IsCallable */ +// 19.2.3.2. Function.prototype.bind ( thisArg, ...args ) +// https://github.com/es-shims/es5-shim/blob/d6d7ff1b131c7ba14c798cafc598bb6780d37d3b/es5-shim.js#L182 +CreateMethodProperty(Function.prototype, 'bind', function bind(that) { // .length is 1 + // add necessary es5-shim utilities + var $Array = Array; + var $Object = Object; + var ArrayPrototype = $Array.prototype; + var Empty = function Empty() { }; + var array_slice = ArrayPrototype.slice; + var array_concat = ArrayPrototype.concat; + var array_push = ArrayPrototype.push; + var max = Math.max; + // /add necessary es5-shim utilities + + // 1. Let Target be the this value. + var target = this; + // 2. If IsCallable(Target) is false, throw a TypeError exception. + if (!IsCallable(target)) { + throw new TypeError('Function.prototype.bind called on incompatible ' + target); + } + // 3. Let A be a new (possibly empty) internal list of all of the + // argument values provided after thisArg (arg1, arg2 etc), in order. + // XXX slicedArgs will stand in for "A" if used + var args = array_slice.call(arguments, 1); // for normal call + // 4. Let F be a new native ECMAScript object. + // 11. Set the [[Prototype]] internal property of F to the standard + // built-in Function prototype object as specified in 15.3.3.1. + // 12. Set the [[Call]] internal property of F as described in + // 15.3.4.5.1. + // 13. Set the [[Construct]] internal property of F as described in + // 15.3.4.5.2. + // 14. Set the [[HasInstance]] internal property of F as described in + // 15.3.4.5.3. + var bound; + var binder = function () { + + if (this instanceof bound) { + // 15.3.4.5.2 [[Construct]] + // When the [[Construct]] internal method of a function object, + // F that was created using the bind function is called with a + // list of arguments ExtraArgs, the following steps are taken: + // 1. Let target be the value of F's [[TargetFunction]] + // internal property. + // 2. If target has no [[Construct]] internal method, a + // TypeError exception is thrown. + // 3. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Construct]] internal + // method of target providing args as the arguments. + + var result = target.apply( + this, + array_concat.call(args, array_slice.call(arguments)) + ); + if ($Object(result) === result) { + return result; + } + return this; + + } else { + // 15.3.4.5.1 [[Call]] + // When the [[Call]] internal method of a function object, F, + // which was created using the bind function is called with a + // this value and a list of arguments ExtraArgs, the following + // steps are taken: + // 1. Let boundArgs be the value of F's [[BoundArgs]] internal + // property. + // 2. Let boundThis be the value of F's [[BoundThis]] internal + // property. + // 3. Let target be the value of F's [[TargetFunction]] internal + // property. + // 4. Let args be a new list containing the same values as the + // list boundArgs in the same order followed by the same + // values as the list ExtraArgs in the same order. + // 5. Return the result of calling the [[Call]] internal method + // of target providing boundThis as the this value and + // providing args as the arguments. + + // equiv: target.call(this, ...boundArgs, ...args) + return target.apply( + that, + array_concat.call(args, array_slice.call(arguments)) + ); + + } + + }; + + // 15. If the [[Class]] internal property of Target is "Function", then + // a. Let L be the length property of Target minus the length of A. + // b. Set the length own property of F to either 0 or L, whichever is + // larger. + // 16. Else set the length own property of F to 0. + + var boundLength = max(0, target.length - args.length); + + // 17. Set the attributes of the length own property of F to the values + // specified in 15.3.5.1. + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + array_push.call(boundArgs, '$' + i); + } + + // XXX Build a dynamic function with desired amount of arguments is the only + // way to set the length property of a function. + // In environments where Content Security Policies enabled (Chrome extensions, + // for ex.) all use of eval or Function costructor throws an exception. + // However in all of these environments Function.prototype.bind exists + // and so this code will never be executed. + bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder); + + if (target.prototype) { + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + // Clean up dangling references. + Empty.prototype = null; + } + + // TODO + // 18. Set the [[Extensible]] internal property of F to true. + + // TODO + // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3). + // 20. Call the [[DefineOwnProperty]] internal method of F with + // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]: + // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and + // false. + // 21. Call the [[DefineOwnProperty]] internal method of F with + // arguments "arguments", PropertyDescriptor {[[Get]]: thrower, + // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false}, + // and false. + + // TODO + // NOTE Function objects created using Function.prototype.bind do not + // have a prototype property or the [[Code]], [[FormalParameters]], and + // [[Scope]] internal properties. + // XXX can't delete prototype in pure-js. + + // 22. Return F. + return bound; +}); + +} + +if (!('getOwnPropertyDescriptor' in Object && typeof Object.getOwnPropertyDescriptor === 'function' && (function() { + try { + var object = {}; + object.test = 0; + return Object.getOwnPropertyDescriptor( + object, + "test" + ).value === 0; + } catch (exception) { + return false + } +}()))) { + +// Object.getOwnPropertyDescriptor +/* global CreateMethodProperty */ +(function () { + var call = Function.prototype.call; + var prototypeOfObject = Object.prototype; + var owns = call.bind(prototypeOfObject.hasOwnProperty); + + var lookupGetter; + var lookupSetter; + var supportsAccessors; + if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { + lookupGetter = call.bind(prototypeOfObject.__lookupGetter__); + lookupSetter = call.bind(prototypeOfObject.__lookupSetter__); + } + function doesGetOwnPropertyDescriptorWork(object) { + try { + object.sentinel = 0; + return Object.getOwnPropertyDescriptor( + object, + "sentinel" + ).value === 0; + } catch (exception) { + // returns falsy + } + } + // check whether getOwnPropertyDescriptor works if it's given. Otherwise, + // shim partially. + if (Object.defineProperty) { + var getOwnPropertyDescriptorWorksOnObject = + doesGetOwnPropertyDescriptorWork({}); + var getOwnPropertyDescriptorWorksOnDom = typeof document == "undefined" || + doesGetOwnPropertyDescriptorWork(document.createElement("div")); + if (!getOwnPropertyDescriptorWorksOnDom || + !getOwnPropertyDescriptorWorksOnObject + ) { + var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor; + } + } + + if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) { + var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: "; + + CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(object, property) { + if ((typeof object != "object" && typeof object != "function") || object === null) { + throw new TypeError(ERR_NON_OBJECT + object); + } + + // make a valiant attempt to use the real getOwnPropertyDescriptor + // for I8's DOM elements. + if (getOwnPropertyDescriptorFallback) { + try { + return getOwnPropertyDescriptorFallback.call(Object, object, property); + } catch (exception) { + // try the shim if the real one doesn't work + } + } + + // If object does not owns property return undefined immediately. + if (!owns(object, property)) { + return; + } + + // If object has a property then it's for sure both `enumerable` and + // `configurable`. + var descriptor = { enumerable: true, configurable: true }; + + // If JS engine supports accessor properties then property may be a + // getter or setter. + if (supportsAccessors) { + // Unfortunately `__lookupGetter__` will return a getter even + // if object has own non getter property along with a same named + // inherited getter. To avoid misbehavior we temporary remove + // `__proto__` so that `__lookupGetter__` will return getter only + // if it's owned by an object. + var prototype = object.__proto__; + object.__proto__ = prototypeOfObject; + + var getter = lookupGetter(object, property); + var setter = lookupSetter(object, property); + + // Once we have getter and setter we can put values back. + object.__proto__ = prototype; + + if (getter || setter) { + if (getter) { + descriptor.get = getter; + } + if (setter) { + descriptor.set = setter; + } + // If it was accessor property we're done and return here + // in order to avoid adding `value` to the descriptor. + return descriptor; + } + } + + // If we got this far we know that object has an own property that is + // not an accessor so we set it as a value and return descriptor. + descriptor.value = object[property]; + descriptor.writable = true; + return descriptor; + }); + } +}()); + +} + +if (!('defineProperties' in Object)) { + +// Object.defineProperties +/* global CreateMethodProperty, Get, ToObject, Type */ +// 19.1.2.3. Object.defineProperties ( O, Properties ) +CreateMethodProperty(Object, 'defineProperties', function defineProperties(O, Properties) { + // 1. If Type(O) is not Object, throw a TypeError exception. + if (Type(O) !== 'object') { + throw new TypeError('Object.defineProperties called on non-object'); + } + // 2. Let props be ? ToObject(Properties). + var props = ToObject(Properties); + // 3. Let keys be ? props.[[OwnPropertyKeys]](). + /* + Polyfill.io - This step in our polyfill is not complying with the specification. + [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols. + TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]]. + */ + var keys = Object.keys(props); + // 4. Let descriptors be a new empty List. + var descriptors = []; + // 5. For each element nextKey of keys in List order, do + for (var i = 0; i < keys.length; i++) { + var nextKey = keys[i]; + // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey). + var propDesc = Object.getOwnPropertyDescriptor(props, nextKey); + // b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then + if (propDesc !== undefined && propDesc.enumerable) { + // i. Let descObj be ? Get(props, nextKey). + var descObj = Get(props, nextKey); + // ii. Let desc be ? ToPropertyDescriptor(descObj). + // Polyfill.io - We skip this step because Object.defineProperty deals with it. + // TODO: Implement this step? + var desc = descObj; + // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. + descriptors.push([nextKey, desc]); + } + } + // 6. For each pair from descriptors in list order, do + for (var i = 0; i < descriptors.length; i++){ + // a. Let P be the first element of pair. + var P = descriptors[i][0]; + // b. Let desc be the second element of pair. + var desc = descriptors[i][1]; + // c. Perform ? DefinePropertyOrThrow(O, P, desc). + Object.defineProperty(O, P, desc); + } + // 7. Return O. + return O; +}); + +} + +if (!('create' in Object)) { + +// Object.create +/* global CreateMethodProperty, Type */ +CreateMethodProperty(Object, 'create', function create(O, properties) { + // 1. If Type(O) is neither Object nor Null, throw a TypeError exception. + if (Type(O) !== 'object' && Type(O) !== 'null') { + throw new TypeError('Object prototype may only be an Object or null'); + } + // 2. Let obj be ObjectCreate(O). + var obj = new Function('e', 'function Object() {}Object.prototype=e;return new Object')(O); + + obj.constructor.prototype = O; + + // 3. If Properties is not undefined, then + if (1 in arguments) { + // a. Return ? ObjectDefineProperties(obj, Properties). + return Object.defineProperties(obj, properties); + } + + return obj; +}); + +} + +if (!('getPrototypeOf' in Object)) { + +// Object.getPrototypeOf +/* global CreateMethodProperty */ +// Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js + +// https://github.com/es-shims/es5-shim/issues#issue/2 +// http://ejohn.org/blog/objectgetprototypeof/ +// recommended by fschaefer on github +// +// sure, and webreflection says ^_^ +// ... this will nerever possibly return null +// ... Opera Mini breaks here with infinite loops +CreateMethodProperty(Object, 'getPrototypeOf', function getPrototypeOf(object) { + if (object !== Object(object)) { + throw new TypeError('Object.getPrototypeOf called on non-object'); + } + var proto = object.__proto__; + if (proto || proto === null) { + return proto; + } else if (typeof object.constructor == 'function' && object instanceof object.constructor) { + return object.constructor.prototype; + } else if (object instanceof Object) { + return Object.prototype; + } else { + // Correctly return null for Objects created with `Object.create(null)` + // (shammed or native) or `{ __proto__: null}`. Also returns null for + // cross-realm objects on browsers that lack `__proto__` support (like + // IE <11), but that's the best we can do. + return null; + } +}); + +} + + +// _ESAbstract.OrdinaryCreateFromConstructor +/* global GetPrototypeFromConstructor */ +// 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) +function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars + var internalSlotsList = arguments[2] || {}; + // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. + // The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object. + + // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto); + + // 3. Return ObjectCreate(proto, internalSlotsList). + // Polyfill.io - We do not pass internalSlotsList to Object.create because Object.create does not use the default ordinary object definitions specified in 9.1. + var obj = Object.create(proto); + for (var name in internalSlotsList) { + if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) { + Object.defineProperty(obj, name, { + configurable: true, + enumerable: false, + writable: true, + value: internalSlotsList[name] + }); + } + } + return obj; +} + +// _ESAbstract.Construct +/* global IsConstructor, OrdinaryCreateFromConstructor, Call */ +// 7.3.13. Construct ( F [ , argumentsList [ , newTarget ]] ) +function Construct(F /* [ , argumentsList [ , newTarget ]] */) { // eslint-disable-line no-unused-vars + // 1. If newTarget is not present, set newTarget to F. + var newTarget = arguments.length > 2 ? arguments[2] : F; + + // 2. If argumentsList is not present, set argumentsList to a new empty List. + var argumentsList = arguments.length > 1 ? arguments[1] : []; + + // 3. Assert: IsConstructor(F) is true. + if (!IsConstructor(F)) { + throw new TypeError('F must be a constructor.'); + } + + // 4. Assert: IsConstructor(newTarget) is true. + if (!IsConstructor(newTarget)) { + throw new TypeError('newTarget must be a constructor.'); + } + + // 5. Return ? F.[[Construct]](argumentsList, newTarget). + // Polyfill.io - If newTarget is the same as F, it is equivalent to new F(...argumentsList). + if (newTarget === F) { + return new (Function.prototype.bind.apply(F, [null].concat(argumentsList)))(); + } else { + // Polyfill.io - This is mimicking section 9.2.2 step 5.a. + var obj = OrdinaryCreateFromConstructor(newTarget, Object.prototype); + return Call(F, obj, argumentsList); + } +} + +// _ESAbstract.ArraySpeciesCreate +/* global IsArray, ArrayCreate, Get, Type, IsConstructor, Construct */ +// 9.4.2.3. ArraySpeciesCreate ( originalArray, length ) +function ArraySpeciesCreate(originalArray, length) { // eslint-disable-line no-unused-vars + // 1. Assert: length is an integer Number ≥ 0. + // 2. If length is -0, set length to +0. + if (1/length === -Infinity) { + length = 0; + } + + // 3. Let isArray be ? IsArray(originalArray). + var isArray = IsArray(originalArray); + + // 4. If isArray is false, return ? ArrayCreate(length). + if (isArray === false) { + return ArrayCreate(length); + } + + // 5. Let C be ? Get(originalArray, "constructor"). + var C = Get(originalArray, 'constructor'); + + // Polyfill.io - We skip this section as not sure how to make a cross-realm normal Array, a same-realm Array. + // 6. If IsConstructor(C) is true, then + // if (IsConstructor(C)) { + // a. Let thisRealm be the current Realm Record. + // b. Let realmC be ? GetFunctionRealm(C). + // c. If thisRealm and realmC are not the same Realm Record, then + // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. + // } + // 7. If Type(C) is Object, then + if (Type(C) === 'object') { + // a. Set C to ? Get(C, @@species). + C = 'Symbol' in this && 'species' in this.Symbol ? Get(C, this.Symbol.species) : undefined; + // b. If C is null, set C to undefined. + if (C === null) { + C = undefined; + } + } + // 8. If C is undefined, return ? ArrayCreate(length). + if (C === undefined) { + return ArrayCreate(length); + } + // 9. If IsConstructor(C) is false, throw a TypeError exception. + if (!IsConstructor(C)) { + throw new TypeError('C must be a constructor'); + } + // 10. Return ? Construct(C, « length »). + return Construct(C, [length]); +} + +// _ESAbstract.ToBoolean +// 7.1.2. ToBoolean ( argument ) +// The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9: +/* +-------------------------------------------------------------------------------------------------------------- +| Argument Type | Result | +-------------------------------------------------------------------------------------------------------------- +| Undefined | Return false. | +| Null | Return false. | +| Boolean | Return argument. | +| Number | If argument is +0, -0, or NaN, return false; otherwise return true. | +| String | If argument is the empty String (its length is zero), return false; otherwise return true. | +| Symbol | Return true. | +| Object | Return true. | +-------------------------------------------------------------------------------------------------------------- +*/ +function ToBoolean(argument) { // eslint-disable-line no-unused-vars + return Boolean(argument); +} + +// _ESAbstract.CreateDataProperty +// 7.3.4. CreateDataProperty ( O, P, V ) +// NOTE +// This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. +// Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false. +function CreateDataProperty(O, P, V) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Let newDesc be the PropertyDescriptor{ [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }. + var newDesc = { + value: V, + writable: true, + enumerable: true, + configurable: true + }; + // 4. Return ? O.[[DefineOwnProperty]](P, newDesc). + try { + Object.defineProperty(O, P, newDesc); + return true; + } catch (e) { + return false; + } +} + +// _ESAbstract.CreateDataPropertyOrThrow +/* global CreateDataProperty */ +// 7.3.6. CreateDataPropertyOrThrow ( O, P, V ) +function CreateDataPropertyOrThrow(O, P, V) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(O) is Object. + // 2. Assert: IsPropertyKey(P) is true. + // 3. Let success be ? CreateDataProperty(O, P, V). + var success = CreateDataProperty(O, P, V); + // 4. If success is false, throw a TypeError exception. + if (!success) { + throw new TypeError('Cannot assign value `' + Object.prototype.toString.call(V) + '` to property `' + Object.prototype.toString.call(P) + '` on object `' + Object.prototype.toString.call(O) + '`'); + } + // 5. Return success. + return success; +} +if (!('filter' in Array.prototype)) { + +// Array.prototype.filter +/* global CreateMethodProperty, ToObject, ToLength, Get, IsCallable, ArraySpeciesCreate, ToString, HasProperty, ToBoolean, Call, CreateDataPropertyOrThrow */ +// 22.1.3.7. Array.prototype.filter ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'filter', function filter(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let A be ? ArraySpeciesCreate(O, 0). + var A = ArraySpeciesCreate(O, 0); + // 6. Let k be 0. + var k = 0; + // 7. Let to be 0. + var to = 0; + // 8. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + var selected = ToBoolean(Call(callbackfn, T, [kValue, k, O])); + // iii. If selected is true, then + if (selected) { + // 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue) + CreateDataPropertyOrThrow(A, ToString(to), kValue); + // 2. Increase to by 1. + to = to + 1; + } + + } + // d. Increase k by 1. + k = k + 1; + } + // 9. Return A. + return A; +}); + +} + +if (!('map' in Array.prototype)) { + +// Array.prototype.map +/* global ArraySpeciesCreate, Call, CreateDataPropertyOrThrow, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */ +/* global CreateMethodProperty, ToObject, ToLength, Get, ArraySpeciesCreate, ToString, HasProperty, Call, CreateDataPropertyOrThrow */ +// 22.1.3.16. Array.prototype.map ( callbackfn [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'map', function map(callbackfn /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (IsCallable(callbackfn) === false) { + throw new TypeError(callbackfn + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let A be ? ArraySpeciesCreate(O, len). + var A = ArraySpeciesCreate(O, len); + // 6. Let k be 0. + var k = 0; + // 7. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kPresent be ? HasProperty(O, Pk). + var kPresent = HasProperty(O, Pk); + // c. If kPresent is true, then + if (kPresent) { + // i. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // ii. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + var mappedValue = Call(callbackfn, T, [kValue, k, O]); + // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + } + // d. Increase k by 1. + k = k + 1; + } + // 8. Return A. + return A; +}); + +} + +if (!('getOwnPropertyNames' in Object)) { + +// Object.getOwnPropertyNames +/* global CreateMethodProperty */ + +var toString = ({}).toString; +var split = ''.split; + +CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) { + var buffer = []; + var key; + + // Non-enumerable properties cannot be discovered but can be checked for by name. + // Define those used internally by JS to allow an incomplete solution + var commonProps = ['length', "name", "arguments", "caller", "prototype", "observe", "unobserve"]; + + if (typeof object === 'undefined' || object === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + + // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8) + object = toString.call(object) == '[object String]' ? split.call(object, '') : Object(object); + + // Enumerable properties only + for (key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + buffer.push(key); + } + } + + // Check for and add the common non-enumerable properties + for (var i=0, s=commonProps.length; i 1 ? arguments[1] : GetMethod(obj, Symbol.iterator); + // 2. Let iterator be ? Call(method, obj). + var iterator = Call(method, obj); + // 3. If Type(iterator) is not Object, throw a TypeError exception. + if (Type(iterator) !== 'object') { + throw new TypeError('bad iterator'); + } + // 4. Let nextMethod be ? GetV(iterator, "next"). + var nextMethod = GetV(iterator, "next"); + // 5. Let iteratorRecord be Record {[[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false}. + var iteratorRecord = Object.create(null); + iteratorRecord['[[Iterator]]'] = iterator; + iteratorRecord['[[NextMethod]]'] = nextMethod; + iteratorRecord['[[Done]]'] = false; + // 6. Return iteratorRecord. + return iteratorRecord; +} + +// _ESAbstract.IteratorClose +/* global GetMethod, Type, Call */ +// 7.4.6. IteratorClose ( iteratorRecord, completion ) +function IteratorClose(iteratorRecord, completion) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(iteratorRecord.[[Iterator]]) is Object. + if (Type(iteratorRecord['[[Iterator]]']) !== 'object') { + throw new Error(Object.prototype.toString.call(iteratorRecord['[[Iterator]]']) + 'is not an Object.'); + } + // 2. Assert: completion is a Completion Record. + // Polyfill.io - Ignoring this step as there is no way to check if something is a Completion Record in userland JavaScript. + + // 3. Let iterator be iteratorRecord.[[Iterator]]. + var iterator = iteratorRecord['[[Iterator]]']; + // 4. Let return be ? GetMethod(iterator, "return"). + // Polyfill.io - We name it returnMethod because return is a keyword and can not be used as an identifier (E.G. variable name, function name etc). + var returnMethod = GetMethod(iterator, "return"); + // 5. If return is undefined, return Completion(completion). + if (returnMethod === undefined) { + return completion; + } + // 6. Let innerResult be Call(return, iterator, « »). + try { + var innerResult = Call(returnMethod, iterator); + } catch (error) { + var innerException = error; + } + // 7. If completion.[[Type]] is throw, return Completion(completion). + if (completion) { + return completion; + } + // 8. If innerResult.[[Type]] is throw, return Completion(innerResult). + if (innerException) { + throw innerException; + } + // 9. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception. + if (Type(innerResult) !== 'object') { + throw new TypeError("Iterator's return method returned a non-object."); + } + // 10. Return Completion(completion). + return completion; +} + +// _ESAbstract.IteratorNext +/* global Call, Type */ +// 7.4.2. IteratorNext ( iteratorRecord [ , value ] ) +function IteratorNext(iteratorRecord /* [, value] */) { // eslint-disable-line no-unused-vars + // 1. If value is not present, then + if (arguments.length < 2) { + // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « »). + var result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]']); + // 2. Else, + } else { + // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »). + result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]'], [arguments[1]]); + } + // 3. If Type(result) is not Object, throw a TypeError exception. + if (Type(result) !== 'object') { + throw new TypeError('bad iterator'); + } + // 4. Return result. + return result; +} + +// _ESAbstract.IteratorComplete +/* global Type, ToBoolean, Get */ +// 7.4.3 IteratorComplete ( iterResult ) +function IteratorComplete(iterResult) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(iterResult) is Object. + if (Type(iterResult) !== 'object') { + throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.'); + } + // 2. Return ToBoolean(? Get(iterResult, "done")). + return ToBoolean(Get(iterResult, "done")); +} + +// _ESAbstract.IteratorStep +/* global IteratorNext, IteratorComplete */ +// 7.4.5. IteratorStep ( iteratorRecord ) +function IteratorStep(iteratorRecord) { // eslint-disable-line no-unused-vars + // 1. Let result be ? IteratorNext(iteratorRecord). + var result = IteratorNext(iteratorRecord); + // 2. Let done be ? IteratorComplete(result). + var done = IteratorComplete(result); + // 3. If done is true, return false. + if (done === true) { + return false; + } + // 4. Return result. + return result; +} + +// _ESAbstract.IteratorValue +/* global Type, Get */ +// 7.4.4 IteratorValue ( iterResult ) +function IteratorValue(iterResult) { // eslint-disable-line no-unused-vars + // Assert: Type(iterResult) is Object. + if (Type(iterResult) !== 'object') { + throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.'); + } + // Return ? Get(iterResult, "value"). + return Get(iterResult, "value"); +} + +// _ESAbstract.CreateIterResultObject +/* global Type, CreateDataProperty */ +// 7.4.7. CreateIterResultObject ( value, done ) +function CreateIterResultObject(value, done) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(done) is Boolean. + if (Type(done) !== 'boolean') { + throw new Error(); + } + // 2. Let obj be ObjectCreate(%ObjectPrototype%). + var obj = {}; + // 3. Perform CreateDataProperty(obj, "value", value). + CreateDataProperty(obj, "value", value); + // 4. Perform CreateDataProperty(obj, "done", done). + CreateDataProperty(obj, "done", done); + // 5. Return obj. + return obj; +} + +// _ESAbstract.SameValueNonNumber +// 7.2.12. SameValueNonNumber ( x, y ) +function SameValueNonNumber(x, y) { // eslint-disable-line no-unused-vars + // 1. Assert: Type(x) is not Number. + // 2. Assert: Type(x) is the same as Type(y). + // 3. If Type(x) is Undefined, return true. + // 4. If Type(x) is Null, return true. + // 5. If Type(x) is String, then + // a. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false. + // 6. If Type(x) is Boolean, then + // a. If x and y are both true or both false, return true; otherwise, return false. + // 7. If Type(x) is Symbol, then + // a. If x and y are both the same Symbol value, return true; otherwise, return false. + // 8. If x and y are the same Object value, return true. Otherwise, return false. + + // Polyfill.io - We can skip all above steps because the === operator does it all for us. + return x === y; +} + +// _ESAbstract.SameValueZero +/* global Type, SameValueNonNumber */ +// 7.2.11. SameValueZero ( x, y ) +function SameValueZero (x, y) { // eslint-disable-line no-unused-vars + // 1. If Type(x) is different from Type(y), return false. + if (Type(x) !== Type(y)) { + return false; + } + // 2. If Type(x) is Number, then + if (Type(x) === 'number') { + // a. If x is NaN and y is NaN, return true. + if (isNaN(x) && isNaN(y)) { + return true; + } + // b. If x is +0 and y is -0, return true. + if (1/x === Infinity && 1/y === -Infinity) { + return true; + } + // c. If x is -0 and y is +0, return true. + if (1/x === -Infinity && 1/y === Infinity) { + return true; + } + // d. If x is the same Number value as y, return true. + if (x === y) { + return true; + } + // e. Return false. + return false; + } + // 3. Return SameValueNonNumber(x, y). + return SameValueNonNumber(x, y); +} +if (!('isArray' in Array)) { + +// Array.isArray +/* global CreateMethodProperty, IsArray */ +// 22.1.2.2. Array.isArray ( arg ) +CreateMethodProperty(Array, 'isArray', function isArray(arg) { + // 1. Return ? IsArray(arg). + return IsArray(arg); +}); + +} + +if (!('Symbol' in this && 'species' in this.Symbol)) { + +// Symbol.species +/* global Symbol */ +Object.defineProperty(Symbol, 'species', { value: Symbol('species') }); + +} + +if (!('Map' in this && (function() { + try { + var m = new Map([[1, 1], [2, 2]]); + if (Map.length === 0) { + if (m.size === 2) { + if ('Symbol' in this && 'iterator' in Symbol && typeof m[Symbol.iterator] === 'function') { + return true; + } + } + } + return false; + } catch (e) { + return false; + } +}()))) { + +// Map +/* global CreateIterResultObject, CreateMethodProperty, GetIterator, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Type, Symbol */ +(function (global) { + var supportsGetters = (function () { + try { + var a = {}; + Object.defineProperty(a, 't', { + configurable: true, + enumerable: false, + get: function () { + return true; + }, + set: undefined + }); + return !!a.t; + } catch (e) { + return false; + } + }()); + + // Deleted map items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol. + var undefMarker = Symbol('undef'); + // 23.1.1.1 Map ( [ iterable ] ) + var Map = function Map(/* iterable */) { + // 1. If NewTarget is undefined, throw a TypeError exception. + if (!(this instanceof Map)) { + throw new TypeError('Constructor Map requires "new"'); + } + // 2. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", « [[MapData]] »). + var map = OrdinaryCreateFromConstructor(this, Map.prototype, { + _keys: [], + _values: [], + _size: 0, + _es6Map: true + }); + + // 3. Set map.[[MapData]] to a new empty List. + // Polyfill.io - This step was done as part of step two. + + // Some old engines do not support ES5 getters/setters. Since Map only requires these for the size property, we can fall back to setting the size property statically each time the size of the map changes. + if (!supportsGetters) { + Object.defineProperty(map, 'size', { + configurable: true, + enumerable: false, + writable: true, + value: 0 + }); + } + + // 4. If iterable is not present, let iterable be undefined. + var iterable = arguments.length > 0 ? arguments[0] : undefined; + + // 5. If iterable is either undefined or null, return map. + if (iterable === null || iterable === undefined) { + return map; + } + + // 6. Let adder be ? Get(map, "set"). + var adder = map.set; + + // 7. If IsCallable(adder) is false, throw a TypeError exception. + if (!IsCallable(adder)) { + throw new TypeError("Map.prototype.set is not a function"); + } + + // 8. Let iteratorRecord be ? GetIterator(iterable). + try { + var iteratorRecord = GetIterator(iterable); + // 9. Repeat, + while (true) { + // a. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // b. If next is false, return map. + if (next === false) { + return map; + } + // c. Let nextItem be ? IteratorValue(next). + var nextItem = IteratorValue(next); + // d. If Type(nextItem) is not Object, then + if (Type(nextItem) !== 'object') { + // i. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}. + try { + throw new TypeError('Iterator value ' + nextItem + ' is not an entry object'); + } catch (error) { + // ii. Return ? IteratorClose(iteratorRecord, error). + return IteratorClose(iteratorRecord, error); + } + } + try { + // Polyfill.io - The try catch accounts for steps: f, h, and j. + + // e. Let k be Get(nextItem, "0"). + var k = nextItem[0]; + // f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k). + // g. Let v be Get(nextItem, "1"). + var v = nextItem[1]; + // h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v). + // i. Let status be Call(adder, map, « k.[[Value]], v.[[Value]] »). + adder.call(map, k, v); + } catch (e) { + // j. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status). + return IteratorClose(iteratorRecord, e); + } + } + } catch (e) { + // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those. + if (Array.isArray(iterable) || + Object.prototype.toString.call(iterable) === '[object Arguments]' || + // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property + (!!iterable.callee)) { + var index; + var length = iterable.length; + for (index = 0; index < length; index++) { + adder.call(map, iterable[index][0], iterable[index][1]); + } + } + } + return map; + }; + + // 23.1.2.1. Map.prototype + // The initial value of Map.prototype is the intrinsic object %MapPrototype%. + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. + Object.defineProperty(Map, 'prototype', { + configurable: false, + enumerable: false, + writable: false, + value: {} + }); + + // 23.1.2.2 get Map [ @@species ] + if (supportsGetters) { + Object.defineProperty(Map, Symbol.species, { + configurable: true, + enumerable: false, + get: function () { + // 1. Return the this value. + return this; + }, + set: undefined + }); + } else { + CreateMethodProperty(Map, Symbol.species, Map); + } + + // 23.1.3.1 Map.prototype.clear ( ) + CreateMethodProperty(Map.prototype, 'clear', function clear() { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // 5.a. Set p.[[Key]] to empty. + M._keys[i] = undefMarker; + // 5.b. Set p.[[Value]] to empty. + M._values[i] = undefMarker; + } + this._size = 0; + if (!supportsGetters) { + this.size = this._size; + } + // 6. Return undefined. + return undefined; + } + ); + + // 23.1.3.2. Map.prototype.constructor + CreateMethodProperty(Map.prototype, 'constructor', Map); + + // 23.1.3.3. Map.prototype.delete ( key ) + CreateMethodProperty(Map.prototype, 'delete', function (key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then + if (M._keys[i] !== undefMarker && SameValueZero(M._keys[i], key)) { + // i. Set p.[[Key]] to empty. + this._keys[i] = undefMarker; + // ii. Set p.[[Value]] to empty. + this._values[i] = undefMarker; + this._size = --this._size; + if (!supportsGetters) { + this.size = this._size; + } + // iii. Return true. + return true; + } + } + // 6. Return false. + return false; + } + ); + + // 23.1.3.4. Map.prototype.entries ( ) + CreateMethodProperty(Map.prototype, 'entries', function entries () { + // 1. Let M be the this value. + var M = this; + // 2. Return ? CreateMapIterator(M, "key+value"). + return CreateMapIterator(M, 'key+value'); + } + ); + + // 23.1.3.5. Map.prototype.forEach ( callbackfn [ , thisArg ] ) + CreateMethodProperty(Map.prototype, 'forEach', function (callbackFn) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (!IsCallable(callbackFn)) { + throw new TypeError(Object.prototype.toString.call(callbackFn) + ' is not a function.'); + } + // 5. If thisArg is present, let T be thisArg; else let T be undefined. + if (arguments[1]) { + var T = arguments[1]; + } + // 6. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 7. For each Record {[[Key]], [[Value]]} e that is an element of entries, in original key insertion order, do + for (var i = 0; i < entries.length; i++) { + // a. If e.[[Key]] is not empty, then + if (M._keys[i] !== undefMarker && M._values[i] !== undefMarker ) { + // i. Perform ? Call(callbackfn, T, « e.[[Value]], e.[[Key]], M »). + callbackFn.call(T, M._values[i], M._keys[i], M); + } + } + // 8. Return undefined. + return undefined; + } + ); + + // 23.1.3.6. Map.prototype.get ( key ) + CreateMethodProperty(Map.prototype, 'get', function get(key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]]. + if (M._keys[i] !== undefMarker && SameValueZero(M._keys[i], key)) { + return M._values[i]; + } + } + // 6. Return undefined. + return undefined; + }); + + // 23.1.3.7. Map.prototype.has ( key ) + CreateMethodProperty(Map.prototype, 'has', function has (key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (typeof M !== 'object') { + throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return true. + if (M._keys[i] !== undefMarker && SameValueZero(M._keys[i], key)) { + return true; + } + } + // 6. Return false. + return false; + }); + + // 23.1.3.8. Map.prototype.keys ( ) + CreateMethodProperty(Map.prototype, 'keys', function keys () { + // 1. Let M be the this value. + var M = this; + // 2. Return ? CreateMapIterator(M, "key"). + return CreateMapIterator(M, "key"); + }); + + // 23.1.3.9. Map.prototype.set ( key, value ) + CreateMethodProperty(Map.prototype, 'set', function set(key, value) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then + if (M._keys[i] !== undefMarker && SameValueZero(M._keys[i], key)) { + // i. Set p.[[Value]] to value. + M._values[i] = value; + // Return M. + return M; + } + } + // 6. If key is -0, let key be +0. + if (1/key === -Infinity) { + key = 0; + } + // 7. Let p be the Record {[[Key]]: key, [[Value]]: value}. + var p = {}; + p['[[Key]]'] = key; + p['[[Value]]'] = value; + // 8. Append p as the last element of entries. + M._keys.push(p['[[Key]]']); + M._values.push(p['[[Value]]']); + ++M._size; + if (!supportsGetters) { + M.size = M._size; + } + // 9. Return M. + return M; + }); + + // 23.1.3.10. get Map.prototype.size + if (supportsGetters) { + Object.defineProperty(Map.prototype, 'size', { + configurable: true, + enumerable: false, + get: function () { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception. + if (M._es6Map !== true) { + throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[MapData]]. + var entries = M._keys; + // 5. Let count be 0. + var count = 0; + // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty, set count to count+1. + if (M._keys[i] !== undefMarker) { + count = count + 1; + } + } + // 7. Return count. + return count; + }, + set: undefined + }); + } + + // 23.1.3.11. Map.prototype.values ( ) + CreateMethodProperty(Map.prototype, 'values', function values () { + // 1. Let M be the this value. + var M = this; + // 2. Return ? CreateMapIterator(M, "value"). + return CreateMapIterator(M, 'value'); + } + ); + + // 23.1.3.12. Map.prototype [ @@iterator ] ( ) + // The initial value of the @@iterator property is the same function object as the initial value of the entries property. + CreateMethodProperty(Map.prototype, Symbol.iterator, Map.prototype.entries); + + // 23.1.3.13. Map.prototype [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "Map". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + // Polyfill.io - Safari 8 implements Map.name but as a non-configurable property, which means it would throw an error if we try and configure it here. + if (!('name' in Map)) { + // 19.2.4.2 name + Object.defineProperty(Map, 'name', { + configurable: true, + enumerable: false, + writable: false, + value: 'Map' + }); + } + + // 23.1.5.1. CreateMapIterator ( map, kind ) + function CreateMapIterator(map, kind) { + // 1. If Type(map) is not Object, throw a TypeError exception. + if (Type(map) !== 'object') { + throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map)); + } + // 2. If map does not have a [[MapData]] internal slot, throw a TypeError exception. + if (map._es6Map !== true) { + throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map)); + } + // 3. Let iterator be ObjectCreate(%MapIteratorPrototype%, « [[Map]], [[MapNextIndex]], [[MapIterationKind]] »). + var iterator = Object.create(MapIteratorPrototype); + // 4. Set iterator.[[Map]] to map. + Object.defineProperty(iterator, '[[Map]]', { + configurable: true, + enumerable: false, + writable: true, + value: map + }); + // 5. Set iterator.[[MapNextIndex]] to 0. + Object.defineProperty(iterator, '[[MapNextIndex]]', { + configurable: true, + enumerable: false, + writable: true, + value: 0 + }); + // 6. Set iterator.[[MapIterationKind]] to kind. + Object.defineProperty(iterator, '[[MapIterationKind]]', { + configurable: true, + enumerable: false, + writable: true, + value: kind + }); + // 7. Return iterator. + return iterator; + } + + // 23.1.5.2. The %MapIteratorPrototype% Object + var MapIteratorPrototype = {}; + // Polyfill.io - We use this as a quick way to check if an object is a Map Iterator instance. + Object.defineProperty(MapIteratorPrototype, 'isMapIterator', { + configurable: false, + enumerable: false, + writable: false, + value: true + }); + + // 23.1.5.2.1. %MapIteratorPrototype%.next ( ) + CreateMethodProperty(MapIteratorPrototype, 'next', function next() { + // 1. Let O be the this value. + var O = this; + // 2. If Type(O) is not Object, throw a TypeError exception. + if (Type(O) !== 'object') { + throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O)); + } + // 3. If O does not have all of the internal slots of a Map Iterator Instance (23.1.5.3), throw a TypeError exception. + if (!O.isMapIterator) { + throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O)); + } + // 4. Let m be O.[[Map]]. + var m = O['[[Map]]']; + // 5. Let index be O.[[MapNextIndex]]. + var index = O['[[MapNextIndex]]']; + // 6. Let itemKind be O.[[MapIterationKind]]. + var itemKind = O['[[MapIterationKind]]']; + // 7. If m is undefined, return CreateIterResultObject(undefined, true). + if (m === undefined) { + return CreateIterResultObject(undefined, true); + } + // 8. Assert: m has a [[MapData]] internal slot. + if (!m._es6Map) { + throw new Error(Object.prototype.toString.call(m) + ' has a [[MapData]] internal slot.'); + } + // 9. Let entries be the List that is m.[[MapData]]. + var entries = m._keys; + // 10. Let numEntries be the number of elements of entries. + var numEntries = entries.length; + // 11. NOTE: numEntries must be redetermined each time this method is evaluated. + // 12. Repeat, while index is less than numEntries, + while (index < numEntries) { + // a. Let e be the Record {[[Key]], [[Value]]} that is the value of entries[index]. + var e = Object.create(null); + e['[[Key]]'] = m._keys[index]; + e['[[Value]]'] = m._values[index]; + // b. Set index to index+1. + index = index + 1; + // c. Set O.[[MapNextIndex]] to index. + O['[[MapNextIndex]]'] = index; + // d. If e.[[Key]] is not empty, then + if (e['[[Key]]'] !== undefMarker) { + // i. If itemKind is "key", let result be e.[[Key]]. + if (itemKind === 'key') { + var result = e['[[Key]]']; + // ii. Else if itemKind is "value", let result be e.[[Value]]. + } else if (itemKind === 'value') { + result = e['[[Value]]']; + // iii. Else, + } else { + // 1. Assert: itemKind is "key+value". + if (itemKind !== 'key+value') { + throw new Error(); + } + // 2. Let result be CreateArrayFromList(« e.[[Key]], e.[[Value]] »). + result = [ + e['[[Key]]'], + e['[[Value]]'] + ]; + } + // iv. Return CreateIterResultObject(result, false). + return CreateIterResultObject(result, false); + } + } + // 13. Set O.[[Map]] to undefined. + O['[[Map]]'] = undefined; + // 14. Return CreateIterResultObject(undefined, true). + return CreateIterResultObject(undefined, true); + } + ); + + // 23.1.5.2.2 %MapIteratorPrototype% [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "Map Iterator". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + CreateMethodProperty(MapIteratorPrototype, Symbol.iterator, function iterator() { + return this; + } + ); + + // Export the object + try { + CreateMethodProperty(global, 'Map', Map); + } catch (e) { + // IE8 throws an error here if we set enumerable to false. + // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx + global['Map'] = Map; + } +}(this)); + +} + +if (!('Set' in this && (function() { + try { + var s = new Set([1, 2]); + if (Set.length === 0) { + if (s.size === 2) { + if ('Symbol' in this && 'iterator' in Symbol && typeof s[Symbol.iterator] === 'function') { + return true; + } + } + } + return false; + } catch (e) { + return false; + } +}()))) { + +// Set +/* global CreateIterResultObject, CreateMethodProperty, GetIterator, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Symbol */ +(function (global) { + var supportsGetters = (function () { + try { + var a = {}; + Object.defineProperty(a, 't', { + configurable: true, + enumerable: false, + get: function () { + return true; + }, + set: undefined + }); + return !!a.t; + } catch (e) { + return false; + } + }()); + + // Deleted set items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol. + var undefMarker = Symbol('undef'); + // 23.2.1.1. Set ( [ iterable ] ) + var Set = function Set(/* iterable */) { + // 1. If NewTarget is undefined, throw a TypeError exception. + if (!(this instanceof Set)) { + throw new TypeError('Constructor Set requires "new"'); + } + // 2. Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] »). + var set = OrdinaryCreateFromConstructor(this, Set.prototype, { + _values: [], + _size: 0, + _es6Set: true + }); + + // 3. Set set.[[SetData]] to a new empty List. + // Polyfill.io - This step was done as part of step two. + + // Some old engines do not support ES5 getters/setters. Since Set only requires these for the size property, we can fall back to setting the size property statically each time the size of the set changes. + if (!supportsGetters) { + Object.defineProperty(set, 'size', { + configurable: true, + enumerable: false, + writable: true, + value: 0 + }); + } + + // 4. If iterable is not present, let iterable be undefined. + var iterable = arguments.length > 0 ? arguments[0] : undefined; + + // 5. If iterable is either undefined or null, return set. + if (iterable === null || iterable === undefined) { + return set; + } + + // 6. Let adder be ? Get(set, "add"). + var adder = set.add; + // 7. If IsCallable(adder) is false, throw a TypeError exception. + if (!IsCallable(adder)) { + throw new TypeError("Set.prototype.add is not a function"); + } + + try { + // 8. Let iteratorRecord be ? GetIterator(iterable). + var iteratorRecord = GetIterator(iterable); + // 9. Repeat, + while (true) { + // a. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // b. If next is false, return set. + if (next === false) { + return set; + } + // c. Let nextValue be ? IteratorValue(next). + var nextValue = IteratorValue(next); + // d. Let status be Call(adder, set, « nextValue.[[Value]] »). + try { + adder.call(set, nextValue); + } catch (e) { + // e. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status). + return IteratorClose(iteratorRecord, e); + } + } + } catch (e) { + // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those. + if (Array.isArray(iterable) || + Object.prototype.toString.call(iterable) === '[object Arguments]' || + // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property + (!!iterable.callee)) { + var index; + var length = iterable.length; + for (index = 0; index < length; index++) { + adder.call(set, iterable[index]); + } + } + } + return set; + }; + + // 23.2.2.1. Set.prototype + // The initial value of Set.prototype is the intrinsic %SetPrototype% object. + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. + Object.defineProperty(Set, 'prototype', { + configurable: false, + enumerable: false, + writable: false, + value: {} + }); + + // 23.2.2.2 get Set [ @@species ] + if (supportsGetters) { + Object.defineProperty(Set, Symbol.species, { + configurable: true, + enumerable: false, + get: function () { + // 1. Return the this value. + return this; + }, + set: undefined + }); + } else { + CreateMethodProperty(Set, Symbol.species, Set); + } + + // 23.2.3.1. Set.prototype.add ( value ) + CreateMethodProperty(Set.prototype, 'add', function add(value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 5. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValueZero(e, value) is true, then + if (e !== undefMarker && SameValueZero(e, value)) { + // i. Return S. + return S; + } + } + // 6. If value is -0, let value be +0. + if (1/value === -Infinity) { + value = 0; + } + // 7. Append value as the last element of entries. + S._values.push(value); + + this._size = ++this._size; + if (!supportsGetters) { + this.size = this._size; + } + // 8. Return S. + return S; + }); + + // 23.2.3.2. Set.prototype.clear ( ) + CreateMethodProperty(Set.prototype, 'clear', function clear() { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 5. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. Replace the element of entries whose value is e with an element whose value is empty. + entries[i] = undefMarker; + } + this._size = 0; + if (!supportsGetters) { + this.size = this._size; + } + // 6. Return undefined. + return undefined; + }); + + // 23.2.3.3. Set.prototype.constructor + CreateMethodProperty(Set.prototype, 'constructor', Set); + + // 23.2.3.4. Set.prototype.delete ( value ) + CreateMethodProperty(Set.prototype, 'delete', function (value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 5. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValueZero(e, value) is true, then + if (e !== undefMarker && SameValueZero(e, value)) { + // i. Replace the element of entries whose value is e with an element whose value is empty. + entries[i] = undefMarker; + + this._size = --this._size; + if (!supportsGetters) { + this.size = this._size; + } + // ii. Return true. + return true; + } + } + // 6. Return false. + return false; + } + ); + + // 23.2.3.5. Set.prototype.entries ( ) + CreateMethodProperty(Set.prototype, 'entries', function entries() { + // 1. Let S be the this value. + var S = this; + // 2. Return ? CreateSetIterator(S, "key+value"). + return CreateSetIterator(S, 'key+value'); + } + ); + + // 23.2.3.6. Set.prototype.forEach ( callbackfn [ , thisArg ] ) + CreateMethodProperty(Set.prototype, 'forEach', function forEach(callbackFn /*[ , thisArg ]*/) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + if (!IsCallable(callbackFn)) { + throw new TypeError(Object.prototype.toString.call(callbackFn) + ' is not a function.'); + } + // 5. If thisArg is present, let T be thisArg; else let T be undefined. + if (arguments[1]) { + var T = arguments[1]; + } + // 6. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 7. For each e that is an element of entries, in original insertion order, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty, then + if (e !== undefMarker) { + // i. Perform ? Call(callbackfn, T, « e, e, S »). + callbackFn.call(T, e, e, S); + } + } + // 8. Return undefined. + return undefined; + } + ); + + // 23.2.3.7. Set.prototype.has ( value ) + CreateMethodProperty(Set.prototype, 'has', function has(value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 5. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValueZero(e, value) is true, return true. + if (e !== undefMarker && SameValueZero(e, value)) { + return true; + } + } + // 6. Return false. + return false; + } + ); + + // Polyfill.io - We need to define Set.prototype.values before Set.prototype.keys because keys is a reference to values. + // 23.2.3.10. Set.prototype.values() + var values = function values() { + // 1. Let S be the this value. + var S = this; + // 2. Return ? CreateSetIterator(S, "value"). + return CreateSetIterator(S, "value"); + }; + CreateMethodProperty(Set.prototype, 'values', values); + + // 23.2.3.8 Set.prototype.keys ( ) + // The initial value of the keys property is the same function object as the initial value of the values property. + CreateMethodProperty(Set.prototype, 'keys', values); + + // 23.2.3.9. get Set.prototype.size + if (supportsGetters) { + Object.defineProperty(Set.prototype, 'size', { + configurable: true, + enumerable: false, + get: function () { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (typeof S !== 'object') { + throw new TypeError('Method Set.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception. + if (S._es6Set !== true) { + throw new TypeError('Method Set.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[SetData]]. + var entries = S._values; + // 5. Let count be 0. + var count = 0; + // 6. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty, set count to count+1. + if (e !== undefMarker) { + count = count + 1; + } + } + // 7. Return count. + return count; + }, + set: undefined + }); + } + + // 23.2.3.11. Set.prototype [ @@iterator ] ( ) + // The initial value of the @@iterator property is the same function object as the initial value of the values property. + CreateMethodProperty(Set.prototype, Symbol.iterator, values); + + // 23.2.3.12. Set.prototype [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "Set". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + // Polyfill.io - Safari 8 implements Set.name but as a non-configurable property, which means it would throw an error if we try and configure it here. + if (!('name' in Set)) { + // 19.2.4.2 name + Object.defineProperty(Set, 'name', { + configurable: true, + enumerable: false, + writable: false, + value: 'Set' + }); + } + + // 23.2.5.1. CreateSetIterator ( set, kind ) + function CreateSetIterator(set, kind) { + // 1. If Type(set) is not Object, throw a TypeError exception. + if (typeof set !== 'object') { + throw new TypeError('createSetIterator called on incompatible receiver ' + Object.prototype.toString.call(set)); + } + // 2. If set does not have a [[SetData]] internal slot, throw a TypeError exception. + if (set._es6Set !== true) { + throw new TypeError('createSetIterator called on incompatible receiver ' + Object.prototype.toString.call(set)); + } + // 3. Let iterator be ObjectCreate(%SetIteratorPrototype%, « [[IteratedSet]], [[SetNextIndex]], [[SetIterationKind]] »). + var iterator = Object.create(SetIteratorPrototype); + // 4. Set iterator.[[IteratedSet]] to set. + Object.defineProperty(iterator, '[[IteratedSet]]', { + configurable: true, + enumerable: false, + writable: true, + value: set + }); + // 5. Set iterator.[[SetNextIndex]] to 0. + Object.defineProperty(iterator, '[[SetNextIndex]]', { + configurable: true, + enumerable: false, + writable: true, + value: 0 + }); + // 6. Set iterator.[[SetIterationKind]] to kind. + Object.defineProperty(iterator, '[[SetIterationKind]]', { + configurable: true, + enumerable: false, + writable: true, + value: kind + }); + // 7. Return iterator. + return iterator; + } + + // 23.2.5.2. The %SetIteratorPrototype% Object + var SetIteratorPrototype = {}; + //Polyfill.io - We add this property to help us identify what is a set iterator. + Object.defineProperty(SetIteratorPrototype, 'isSetIterator', { + configurable: false, + enumerable: false, + writable: false, + value: true + }); + + // 23.2.5.2.1. %SetIteratorPrototype%.next ( ) + CreateMethodProperty(SetIteratorPrototype, 'next', function next() { + // 1. Let O be the this value. + var O = this; + // 2. If Type(O) is not Object, throw a TypeError exception. + if (typeof O !== 'object') { + throw new TypeError('Method %SetIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O)); + } + // 3. If O does not have all of the internal slots of a Set Iterator Instance (23.2.5.3), throw a TypeError exception. + if (!O.isSetIterator) { + throw new TypeError('Method %SetIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O)); + } + // 4. Let s be O.[[IteratedSet]]. + var s = O['[[IteratedSet]]']; + // 5. Let index be O.[[SetNextIndex]]. + var index = O['[[SetNextIndex]]']; + // 6. Let itemKind be O.[[SetIterationKind]]. + var itemKind = O['[[SetIterationKind]]']; + // 7. If s is undefined, return CreateIterResultObject(undefined, true). + if (s === undefined) { + return CreateIterResultObject(undefined, true); + } + // 8. Assert: s has a [[SetData]] internal slot. + if (!s._es6Set) { + throw new Error(Object.prototype.toString.call(s) + ' does not have [[SetData]] internal slot.'); + } + // 9. Let entries be the List that is s.[[SetData]]. + var entries = s._values; + // 10. Let numEntries be the number of elements of entries. + var numEntries = entries.length; + // 11. NOTE: numEntries must be redetermined each time this method is evaluated. + // 12. Repeat, while index is less than numEntries, + while (index < numEntries) { + // a. Let e be entries[index]. + var e = entries[index]; + // b. Set index to index+1. + index = index + 1; + // c. Set O.[[SetNextIndex]] to index. + O['[[SetNextIndex]]'] = index; + // d. If e is not empty, then + if (e !== undefMarker) { + // i. If itemKind is "key+value", then + if (itemKind === 'key+value') { + // 1. Return CreateIterResultObject(CreateArrayFromList(« e, e »), false). + return CreateIterResultObject([e, e], false); + } + // ii. Return CreateIterResultObject(e, false). + return CreateIterResultObject(e, false); + } + } + // 13. Set O.[[IteratedSet]] to undefined. + O['[[IteratedSet]]'] = undefined; + // 14. Return CreateIterResultObject(undefined, true). + return CreateIterResultObject(undefined, true); + }); + + // 23.2.5.2.2. %SetIteratorPrototype% [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "Set Iterator". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + CreateMethodProperty(SetIteratorPrototype, Symbol.iterator, function iterator() { + return this; + } + ); + + // Export the object + try { + CreateMethodProperty(global, 'Set', Set); + } catch (e) { + // IE8 throws an error here if we set enumerable to false. + // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx + global['Set'] = Set; + } + +}(this)); + +} + +if (!('from' in Array && (function () { + try { + Array.from({ length: -Infinity }); + + return true; + } catch (e) { + return false; + } +}()))) { + +// Array.from +/* globals + IsCallable, GetMethod, Symbol, IsConstructor, Construct, ArrayCreate, GetIterator, IteratorClose, + ToString, IteratorStep, IteratorValue, Call, CreateDataPropertyOrThrow, ToObject, ToLength, Get, CreateMethodProperty +*/ +(function () { + var toString = Object.prototype.toString; + var stringMatch = String.prototype.match; + // A cross-realm friendly way to detect if a value is a String object or literal. + function isString(value) { + if (typeof value === 'string') { return true; } + if (typeof value !== 'object') { return false; } + return toString.call(value) === '[object String]'; + } + + // 22.1.2.1. Array.from ( items [ , mapfn [ , thisArg ] ] ) + CreateMethodProperty(Array, 'from', function from(items /* [ , mapfn [ , thisArg ] ] */) { // eslint-disable-line no-undef + // 1. Let C be the this value. + var C = this; + // 2. If mapfn is undefined, let mapping be false. + var mapfn = arguments.length > 1 ? arguments[1] : undefined; + if (mapfn === undefined) { + var mapping = false; + // 3. Else, + } else { + // a. If IsCallable(mapfn) is false, throw a TypeError exception. + if (IsCallable(mapfn) === false) { + throw new TypeError(Object.prototype.toString.call(mapfn) + ' is not a function.'); + } + // b. If thisArg is present, let T be thisArg; else let T be undefined. + var thisArg = arguments.length > 2 ? arguments[2] : undefined; + if (thisArg !== undefined) { + var T = thisArg; + } else { + T = undefined; + } + // c. Let mapping be true. + mapping = true; + + } + // 4. Let usingIterator be ? GetMethod(items, @@iterator). + var usingIterator = GetMethod(items, Symbol.iterator); + // 5. If usingIterator is not undefined, then + if (usingIterator !== undefined) { + // a. If IsConstructor(C) is true, then + if (IsConstructor(C)) { + // i. Let A be ? Construct(C). + var A = Construct(C); + // b. Else, + } else { + // i. Let A be ! ArrayCreate(0). + A = ArrayCreate(0); + } + // c. Let iteratorRecord be ? GetIterator(items, usingIterator). + var iteratorRecord = GetIterator(items, usingIterator); + // d. Let k be 0. + var k = 0; + // e. Repeat, + while (true) { + // i. If k ≥ 2^53-1, then + if (k >= (Math.pow(2, 53) - 1)) { + // 1. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}. + var error = new TypeError('Iteration count can not be greater than or equal 9007199254740991.'); + // 2. Return ? IteratorClose(iteratorRecord, error). + return IteratorClose(iteratorRecord, error); + } + // ii. Let Pk be ! ToString(k). + var Pk = ToString(k); + // iii. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // iv. If next is false, then + if (next === false) { + // 1. Perform ? Set(A, "length", k, true). + A["length"] = k; + // 2. Return A. + return A; + } + // v. Let nextValue be ? IteratorValue(next). + var nextValue = IteratorValue(next); + // vi. If mapping is true, then + if (mapping) { + try { + // Polyfill.io - The try catch accounts for step 2. + // 1. Let mappedValue be Call(mapfn, T, « nextValue, k »). + var mappedValue = Call(mapfn, T, [nextValue, k]); + // 2. If mappedValue is an abrupt completion, return ? IteratorClose(iteratorRecord, mappedValue). + // 3. Let mappedValue be mappedValue.[[Value]]. + } catch (e) { + return IteratorClose(iteratorRecord, e); + } + + // vii. Else, let mappedValue be nextValue. + } else { + mappedValue = nextValue; + } + try { + // Polyfill.io - The try catch accounts for step ix. + // viii. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + // ix. If defineStatus is an abrupt completion, return ? IteratorClose(iteratorRecord, defineStatus). + } catch (e) { + return IteratorClose(iteratorRecord, e); + } + // x. Increase k by 1. + k = k + 1; + } + } + // 6. NOTE: items is not an Iterable so assume it is an array-like object. + // 7. Let arrayLike be ! ToObject(items). + // Polyfill.io - For Strings we need to split astral symbols into surrogate pairs. + if (isString(items)) { + var arrayLike = stringMatch.call(items, /[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || []; + } else { + arrayLike = ToObject(items); + } + // 8. Let len be ? ToLength(? Get(arrayLike, "length")). + var len = ToLength(Get(arrayLike, "length")); + // 9. If IsConstructor(C) is true, then + if (IsConstructor(C)) { + // a. Let A be ? Construct(C, « len »). + A = Construct(C, [len]); + // 10. Else, + } else { + // a. Let A be ? ArrayCreate(len). + A = ArrayCreate(len); + } + // 11. Let k be 0. + k = 0; + // 12. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + Pk = ToString(k); + // b. Let kValue be ? Get(arrayLike, Pk). + var kValue = Get(arrayLike, Pk); + // c. If mapping is true, then + if (mapping === true) { + // i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + mappedValue = Call(mapfn, T, [kValue, k]); + // d. Else, let mappedValue be kValue. + } else { + mappedValue = kValue; + } + // e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + // f. Increase k by 1. + k = k + 1; + } + // 13. Perform ? Set(A, "length", len, true). + A["length"] = len; + // 14. Return A. + return A; + }); +}()); + +} + +if (!('of' in Array)) { + +// Array.of +/* global ArrayCreate, Construct, CreateDataPropertyOrThrow, CreateMethodProperty, IsConstructor, ToString */ +// 22.1.2.3. Array.of ( ...items ) +CreateMethodProperty(Array, 'of', function of() { + // 1. Let len be the actual number of arguments passed to this function. + var len = arguments.length; + // 2. Let items be the List of arguments passed to this function. + var items = arguments; + // 3. Let C be the this value. + var C = this; + // 4. If IsConstructor(C) is true, then + if (IsConstructor(C)) { + // a. Let A be ? Construct(C, « len »). + var A = Construct(C, [len]); + // 5. Else, + } else { + // a. Let A be ? ArrayCreate(len). + var A = ArrayCreate(len); + } + // 6. Let k be 0. + var k = 0; + // 7. Repeat, while k < len + while (k < len) { + // a. Let kValue be items[k]. + var kValue = items[k]; + // b. Let Pk be ! ToString(k). + var Pk = ToString(k); + // c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). + CreateDataPropertyOrThrow(A, Pk, kValue); + // d. Increase k by 1. + var k = k + 1; + + } + // 8. Perform ? Set(A, "length", len, true) + A["length"] = len; + // 9. Return A. + return A; +}); + +} + +if (!('assign' in Object)) { + +// Object.assign +/* global CreateMethodProperty, Get, ToObject */ +// 19.1.2.1 Object.assign ( target, ...sources ) +CreateMethodProperty(Object, 'assign', function assign(target, source) { // eslint-disable-line no-unused-vars + // 1. Let to be ? ToObject(target). + var to = ToObject(target); + + // 2. If only one argument was passed, return to. + if (arguments.length === 1) { + return to; + } + + // 3. Let sources be the List of argument values starting with the second argument + var sources = Array.prototype.slice.call(arguments, 1); + + // 4. For each element nextSource of sources, in ascending index order, do + var index1; + var index2; + var keys; + var from; + for (index1 = 0; index1 < sources.length; index1++) { + var nextSource = sources[index1]; + // a. If nextSource is undefined or null, let keys be a new empty List. + if (nextSource === undefined || nextSource === null) { + keys = []; + // b. Else, + } else { + // i. Let from be ! ToObject(nextSource). + from = ToObject(nextSource); + // ii. Let keys be ? from.[[OwnPropertyKeys]](). + /* + This step in our polyfill is not complying with the specification. + [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols. + TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]]. + */ + keys = Object.keys(from); + } + + // c. For each element nextKey of keys in List order, do + for (index2 = 0; index2 < keys.length; index2++) { + var nextKey = keys[index2]; + // i. Let desc be ? from.[[GetOwnProperty]](nextKey). + var desc = Object.getOwnPropertyDescriptor(from, nextKey); + // ii. If desc is not undefined and desc.[[Enumerable]] is true, then + if (desc !== undefined && desc.enumerable) { + // 1. Let propValue be ? Get(from, nextKey). + var propValue = Get(from, nextKey); + // 2. Perform ? Set(to, nextKey, propValue, true). + to[nextKey] = propValue; + } + } + } + // 5. Return to. + return to; +}); + +} + +if (!('Symbol' in this && 'toStringTag' in this.Symbol)) { + +// Symbol.toStringTag +/* global Symbol */ +Object.defineProperty(Symbol, 'toStringTag', { + value: Symbol('toStringTag') +}); + +} + + +// _Iterator +/* global Symbol */ +// A modification of https://github.com/medikoo/es6-iterator +// Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com) + +var Iterator = (function () { // eslint-disable-line no-unused-vars + var clear = function () { + this.length = 0; + return this; + }; + var callable = function (fn) { + if (typeof fn !== 'function') throw new TypeError(fn + " is not a function"); + return fn; + }; + + var Iterator = function (list, context) { + if (!(this instanceof Iterator)) { + return new Iterator(list, context); + } + Object.defineProperties(this, { + __list__: { + writable: true, + value: list + }, + __context__: { + writable: true, + value: context + }, + __nextIndex__: { + writable: true, + value: 0 + } + }); + if (!context) return; + callable(context.on); + context.on('_add', this._onAdd.bind(this)); + context.on('_delete', this._onDelete.bind(this)); + context.on('_clear', this._onClear.bind(this)); + }; + + Object.defineProperties(Iterator.prototype, Object.assign({ + constructor: { + value: Iterator, + configurable: true, + enumerable: false, + writable: true + }, + _next: { + value: function () { + var i; + if (!this.__list__) return; + if (this.__redo__) { + i = this.__redo__.shift(); + if (i !== undefined) return i; + } + if (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++; + this._unBind(); + }, + configurable: true, + enumerable: false, + writable: true + }, + next: { + value: function () { + return this._createResult(this._next()); + }, + configurable: true, + enumerable: false, + writable: true + }, + _createResult: { + value: function (i) { + if (i === undefined) return { + done: true, + value: undefined + }; + return { + done: false, + value: this._resolve(i) + }; + }, + configurable: true, + enumerable: false, + writable: true + }, + _resolve: { + value: function (i) { + return this.__list__[i]; + }, + configurable: true, + enumerable: false, + writable: true + }, + _unBind: { + value: function () { + this.__list__ = null; + delete this.__redo__; + if (!this.__context__) return; + this.__context__.off('_add', this._onAdd.bind(this)); + this.__context__.off('_delete', this._onDelete.bind(this)); + this.__context__.off('_clear', this._onClear.bind(this)); + this.__context__ = null; + }, + configurable: true, + enumerable: false, + writable: true + }, + toString: { + value: function () { + return '[object Iterator]'; + }, + configurable: true, + enumerable: false, + writable: true + } + }, { + _onAdd: { + value: function (index) { + if (index >= this.__nextIndex__) return; + ++this.__nextIndex__; + if (!this.__redo__) { + Object.defineProperty(this, '__redo__', { + value: [index], + configurable: true, + enumerable: false, + writable: false + }); + return; + } + this.__redo__.forEach(function (redo, i) { + if (redo >= index) this.__redo__[i] = ++redo; + }, this); + this.__redo__.push(index); + }, + configurable: true, + enumerable: false, + writable: true + }, + _onDelete: { + value: function (index) { + var i; + if (index >= this.__nextIndex__) return; + --this.__nextIndex__; + if (!this.__redo__) return; + i = this.__redo__.indexOf(index); + if (i !== -1) this.__redo__.splice(i, 1); + this.__redo__.forEach(function (redo, i) { + if (redo > index) this.__redo__[i] = --redo; + }, this); + }, + configurable: true, + enumerable: false, + writable: true + }, + _onClear: { + value: function () { + if (this.__redo__) clear.call(this.__redo__); + this.__nextIndex__ = 0; + }, + configurable: true, + enumerable: false, + writable: true + } + })); + + Object.defineProperty(Iterator.prototype, Symbol.iterator, { + value: function () { + return this; + }, + configurable: true, + enumerable: false, + writable: true + }); + Object.defineProperty(Iterator.prototype, Symbol.toStringTag, { + value: 'Iterator', + configurable: false, + enumerable: false, + writable: true + }); + + return Iterator; +}()); + +// Object.setPrototypeOf +/* global CreateMethodProperty */ +// ES6-shim 0.16.0 (c) 2013-2014 Paul Miller (http://paulmillr.com) +// ES6-shim may be freely distributed under the MIT license. +// For more details and documentation: +// https://github.com/paulmillr/es6-shim/ + + // NOTE: This versions needs object ownership + // because every promoted object needs to be reassigned + // otherwise uncompatible browsers cannot work as expected + // + // NOTE: This might need es5-shim or polyfills upfront + // because it's based on ES5 API. + // (probably just an IE <= 8 problem) + // + // NOTE: nodejs is fine in version 0.8, 0.10, and future versions. +(function () { + if (Object.setPrototypeOf) { return; } + + /*jshint proto: true */ + // @author Andrea Giammarchi - @WebReflection + + var getOwnPropertyNames = Object.getOwnPropertyNames; + var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var create = Object.create; + var defineProperty = Object.defineProperty; + var getPrototypeOf = Object.getPrototypeOf; + var objProto = Object.prototype; + + var copyDescriptors = function (target, source) { + // define into target descriptors from source + getOwnPropertyNames(source).forEach(function (key) { + defineProperty( + target, + key, + getOwnPropertyDescriptor(source, key) + ); + }); + return target; + }; + // used as fallback when no promotion is possible + var createAndCopy = function setPrototypeOf(origin, proto) { + return copyDescriptors(create(proto), origin); + }; + var set, sPOf; + try { + // this might fail for various reasons + // ignore if Chrome cought it at runtime + set = getOwnPropertyDescriptor(objProto, '__proto__').set; + set.call({}, null); + // setter not poisoned, it can promote + // Firefox, Chrome + sPOf = function setPrototypeOf(origin, proto) { + set.call(origin, proto); + return origin; + }; + } catch (e) { + // do one or more feature detections + set = { __proto__: null }; + // if proto does not work, needs to fallback + // some Opera, Rhino, ducktape + if (set instanceof Object) { + sPOf = createAndCopy; + } else { + // verify if null objects are buggy + /* eslint-disable no-proto */ + set.__proto__ = objProto; + /* eslint-enable no-proto */ + // if null objects are buggy + // nodejs 0.8 to 0.10 + if (set instanceof Object) { + sPOf = function setPrototypeOf(origin, proto) { + // use such bug to promote + /* eslint-disable no-proto */ + origin.__proto__ = proto; + /* eslint-enable no-proto */ + return origin; + }; + } else { + // try to use proto or fallback + // Safari, old Firefox, many others + sPOf = function setPrototypeOf(origin, proto) { + // if proto is not null + if (getPrototypeOf(origin)) { + // use __proto__ to promote + /* eslint-disable no-proto */ + origin.__proto__ = proto; + /* eslint-enable no-proto */ + return origin; + } else { + // otherwise unable to promote: fallback + return createAndCopy(origin, proto); + } + }; + } + } + } + CreateMethodProperty(Object, 'setPrototypeOf', sPOf); +}()); + +// _ESAbstract.RequireObjectCoercible +// 7.2.1. RequireObjectCoercible ( argument ) +// The abstract operation ToObject converts argument to a value of type Object according to Table 12: +// Table 12: ToObject Conversions +/* +|----------------------------------------------------------------------------------------------------------------------------------------------------| +| Argument Type | Result | +|----------------------------------------------------------------------------------------------------------------------------------------------------| +| Undefined | Throw a TypeError exception. | +| Null | Throw a TypeError exception. | +| Boolean | Return argument. | +| Number | Return argument. | +| String | Return argument. | +| Symbol | Return argument. | +| Object | Return argument. | +|----------------------------------------------------------------------------------------------------------------------------------------------------| +*/ +function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars + if (argument === null || argument === undefined) { + throw TypeError(); + } + return argument; +} + +// _ESAbstract.IsRegExp +/* global Type, Get, ToBoolean */ +// 7.2.8. IsRegExp ( argument ) +function IsRegExp(argument) { // eslint-disable-line no-unused-vars + // 1. If Type(argument) is not Object, return false. + if (Type(argument) !== 'object') { + return false; + } + // 2. Let matcher be ? Get(argument, @@match). + var matcher = 'Symbol' in this && 'match' in this.Symbol ? Get(argument, this.Symbol.match) : undefined; + // 3. If matcher is not undefined, return ToBoolean(matcher). + if (matcher !== undefined) { + return ToBoolean(matcher); + } + // 4. If argument has a [[RegExpMatcher]] internal slot, return true. + try { + var lastIndex = argument.lastIndex; + argument.lastIndex = 0; + RegExp.prototype.exec.call(argument); + return true; + } catch (e) {} finally { + argument.lastIndex = lastIndex; + } + // 5. Return false. + return false; +} +if (!('includes' in String.prototype)) { + +// String.prototype.includes +/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */ +// 21.1.3.7. String.prototype.includes ( searchString [ , position ] ) +CreateMethodProperty(String.prototype, 'includes', function includes(searchString /* [ , position ] */) { + 'use strict'; + var position = arguments.length > 1 ? arguments[1] : undefined; + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Let isRegExp be ? IsRegExp(searchString). + var isRegExp = IsRegExp(searchString); + // 4. If isRegExp is true, throw a TypeError exception. + if (isRegExp) { + throw new TypeError('First argument to String.prototype.includes must not be a regular expression'); + } + // 5. Let searchStr be ? ToString(searchString). + var searchStr = ToString(searchString); + // 6. Let pos be ? ToInteger(position). (If position is undefined, this step produces the value 0.) + var pos = ToInteger(position); + // 7. Let len be the length of S. + var len = S.length; + // 8. Let start be min(max(pos, 0), len). + var start = Math.min(Math.max(pos, 0), len); + // 9. Let searchLen be the length of searchStr. + // var searchLength = searchStr.length; + // 10. If there exists any integer k not smaller than start such that k + searchLen is not greater than len, and for all nonnegative integers j less than searchLen, the code unit at index k+j within S is the same as the code unit at index j within searchStr, return true; but if there is no such integer k, return false. + return String.prototype.indexOf.call(S, searchStr, start) !== -1; +}); + +} + + +// _ArrayIterator +/* global Iterator */ +// A modification of https://github.com/medikoo/es6-iterator +// Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com) + +var ArrayIterator = (function() { // eslint-disable-line no-unused-vars + + var ArrayIterator = function(arr, kind) { + if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind); + Iterator.call(this, arr); + if (!kind) kind = 'value'; + else if (String.prototype.includes.call(kind, 'key+value')) kind = 'key+value'; + else if (String.prototype.includes.call(kind, 'key')) kind = 'key'; + else kind = 'value'; + Object.defineProperty(this, '__kind__', { + value: kind, + configurable: false, + enumerable: false, + writable: false + }); + }; + if (Object.setPrototypeOf) Object.setPrototypeOf(ArrayIterator, Iterator.prototype); + + ArrayIterator.prototype = Object.create(Iterator.prototype, { + constructor: { + value: ArrayIterator, + configurable: true, + enumerable: false, + writable: true + }, + _resolve: { + value: function(i) { + if (this.__kind__ === 'value') return this.__list__[i]; + if (this.__kind__ === 'key+value') return [i, this.__list__[i]]; + return i; + }, + configurable: true, + enumerable: false, + writable: true + }, + toString: { + value: function() { + return '[object Array Iterator]'; + }, + configurable: true, + enumerable: false, + writable: true + } + }); + + return ArrayIterator; +}()); +if (!('values' in Array.prototype)) { + +// Array.prototype.values +/* global CreateMethodProperty, Symbol, ToObject */ +// 22.1.3.30/ Array.prototype.values ( ) +// Polyfill.io - Firefox, Chrome and Opera have Array.prototype[Symbol.iterator], which is the exact same function as Array.prototype.values. +if ('Symbol' in this && 'iterator' in Symbol && typeof Array.prototype[Symbol.iterator] === 'function') { + CreateMethodProperty(Array.prototype, 'values', Array.prototype[Symbol.iterator]); +} else { + CreateMethodProperty(Array.prototype, 'values', function values () { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Return CreateArrayIterator(O, "value"). + // TODO: Add CreateArrayIterator + return new ArrayIterator(O, 'value'); + }); +} + +} + +if (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype[Symbol.iterator])) { + +// Array.prototype.@@iterator +/* global Symbol, CreateMethodProperty */ +// 22.1.3.31. Array.prototype [ @@iterator ] ( ) +// The initial value of the @@iterator property is the same function object as the initial value of the Array.prototype.values property. +CreateMethodProperty(Array.prototype, Symbol.iterator, Array.prototype.values); + +} + +if (!('copyWithin' in Array.prototype && (function () { + try { + var Parent = function Parent() {}; + Parent.prototype[0] = 'foo'; + var sparse = new Parent(); + sparse[1] = 1; + sparse[2] = 2; + sparse.length = 3; + var result = Array.prototype.copyWithin.call(sparse, 1, 0); + if (result['0'] && !Object.prototype.hasOwnProperty.call(result, '0') && Object.prototype.hasOwnProperty.call(result, '1') && result[0] === 'foo' && result[1] === 'foo' && result[2] === 1 && result.length === 3) { + return true; + } else { + return false; + } + } catch (err) { + return false; + } +}()))) { + +// Array.prototype.copyWithin +/* global CreateMethodProperty, HasProperty, ToInteger */ +// 22.1.3.3 Array.prototype.copyWithin ( target, start [ , end ] ) +CreateMethodProperty(Array.prototype, 'copyWithin', function copyWithin(target, start /* [ , end ] */ ) { + 'use strict'; + var end = arguments[2]; + + // 22.1.3.3.1 Let O be ? ToObject(this value). + if (this === null || this === undefined) { + throw new TypeError('Cannot call method on ' + this); + } + + var o = Object(this); + + // 22.1.3.3.2 Let len be ? ToLength(? Get(O, "length")). + var len = ToInteger(o.length); + if (len <= 0) { + len = 0; + } + if (len === Infinity) { + len = Math.pow(2, 53) - 1; + } else { + len = Math.min(len, Math.pow(2, 53) - 1); + } + len = Math.max(len, 0); + + // 22.1.3.3.3 Let relativeTarget be ? ToInteger(target). + var relativeTarget = ToInteger(target); + + // 22.1.3.3.4 If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let to be min(relativeTarget, len). + var to; + if (relativeTarget < 0) { + to = Math.max(len + relativeTarget, 0); + } else { + to = Math.min(relativeTarget, len); + } + + // 22.1.3.3.5 Let relativeStart be ? ToInteger(start). + var relativeStart = ToInteger(start); + + // 22.1.3.3.6 If relativeStart < 0, let from be max((len + relativeStart), 0); else let from be min(relativeStart, len). + var from; + if (relativeStart < 0) { + from = Math.max(len + relativeStart, 0); + } else { + from = Math.min(relativeStart, len); + } + + // 22.1.3.3.7 If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + var relativeEnd; + if (end === undefined) { + relativeEnd = len; + } else { + relativeEnd = ToInteger(end); + } + + // 22.1.3.3.8 If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let final be min(relativeEnd, len). + var final; + if (relativeEnd < 0) { + final = Math.max(len + relativeEnd, 0); + } else { + final = Math.min(relativeEnd, len); + } + + // 22.1.3.3.9 Let count be min(final-from, len-to). + var count = Math.min(final - from, len - to); + + // 22.1.3.3.10 If from 0 + while (count > 0) { + // 22.1.3.3.12.a Let fromKey be ! ToString(from). + var fromKey = String(from); + // 22.1.3.3.12.b Let toKey be ! ToString(to). + var toKey = String(to); + // 22.1.3.3.12.c Let fromPresent be ? HasProperty(O, fromKey). + var fromPresent = HasProperty(o, fromKey); + // 22.1.3.3.12.d If fromPresent is true, then + if (fromPresent) { + // 22.1.3.3.12.d.i Let fromVal be ? Get(O, fromKey). + var fromVal = o[fromKey]; + // 22.1.3.3.12.d.ii Perform ? Set(O, toKey, fromVal, true). + o[toKey] = fromVal; + } else { + // 22.1.3.3.12.e Else fromPresent is false, + // 22.1.3.3.12.e.i Perform ? DeletePropertyOrThrow(O, toKey). + delete o[toKey]; + } + // 22.1.3.3.12.f Let from be from + direction. + from = from + direction; + // 22.1.3.3.12.g Let to be to + direction. + to = to + direction; + // 22.1.3.3.12.h Let count be count - 1. + count = count - 1; + } + // 22.1.3.3.13 Return O. + return o; +}); + +} + +if (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype.entries)) { + +// Array.prototype.entries +/* global CreateMethodProperty, ToObject */ +// 22.1.3.4. Array.prototype.entries ( ) +CreateMethodProperty(Array.prototype, 'entries', function entries() { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Return CreateArrayIterator(O, "key+value"). + // TODO: Add CreateArrayIterator + return new ArrayIterator(O, 'key+value'); +}); + +} + +if (!('fill' in Array.prototype)) { + +// Array.prototype.fill +/* global CreateMethodProperty, Get, ToInteger, ToLength, ToObject, ToString */ +// 22.1.3.6. Array.prototype.fill ( value [ , start [ , end ] ] ) +CreateMethodProperty(Array.prototype, 'fill', function fill(value /* [ , start [ , end ] ] */) { + var start = arguments[1]; + var end = arguments[2]; + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. Let relativeStart be ? ToInteger(start). + var relativeStart = ToInteger(start); + // 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be min(relativeStart, len) + var k = relativeStart < 0 ? Math.max((len + relativeStart), 0) : Math.min(relativeStart, len); + // 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + var relativeEnd = end === undefined ? len : ToInteger(end); + // 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let final be min(relativeEnd, len). + var final = relativeEnd < 0 ? Math.max((len + relativeEnd), 0) : Math.min(relativeEnd, len); + // 7. Repeat, while k < final + while (k < final) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Perform ? Set(O, Pk, value, true). + O[Pk] = value; + // c. Increase k by 1. + k = k + 1; + } + // 8. Return O. + return O; +}); + +} + +if (!('find' in Array.prototype)) { + +// Array.prototype.find +/* global Call, CreateMethodProperty, Get, IsCallable, ToBoolean, ToLength, ToObject, ToString */ +// 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'find', function find( predicate /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(predicate) is false, throw a TypeError exception. + if (IsCallable(predicate) === false) { + throw new TypeError(predicate + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + var testResult = ToBoolean(Call(predicate, T, [kValue, k, O ])); + // d. If testResult is true, return kValue. + if (testResult) { + return kValue; + } + // e. Increase k by 1. + var k = k + 1; + } + // 7. Return undefined. + return undefined; +}); + +} + +if (!('findIndex' in Array.prototype)) { + +// Array.prototype.findIndex +/* global Call, CreateMethodProperty, Get, IsCallable, ToBoolean, ToLength, ToObject, ToString */ +// 22.1.3.9. Array.prototype.findIndex ( predicate [ , thisArg ] ) +CreateMethodProperty(Array.prototype, 'findIndex', function findIndex(predicate /* [ , thisArg ] */) { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = ToLength(Get(O, "length")); + // 3. If IsCallable(predicate) is false, throw a TypeError exception. + if (IsCallable(predicate) === false) { + throw new TypeError(predicate + ' is not a function'); + } + // 4. If thisArg is present, let T be thisArg; else let T be undefined. + var T = arguments.length > 1 ? arguments[1] : undefined; + // 5. Let k be 0. + var k = 0; + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + var Pk = ToString(k); + // b. Let kValue be ? Get(O, Pk). + var kValue = Get(O, Pk); + // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + var testResult = ToBoolean(Call(predicate, T, [kValue, k, O])); + // d. If testResult is true, return k. + if (testResult) { + return k; + } + // e. Increase k by 1. + k = k + 1; + } + // 7. Return -1. + return -1; +}); + +} + +if (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype.keys)) { + +// Array.prototype.keys +/* global CreateMethodProperty, ToObject */ +// 22.1.3.14. Array.prototype.keys ( ) +CreateMethodProperty(Array.prototype, 'keys', function keys() { + // 1. Let O be ? ToObject(this value). + var O = ToObject(this); + // 2. Return CreateArrayIterator(O, "key"). + // TODO: Add CreateArrayIterator. + return new ArrayIterator(O, 'key'); +}); + +} + +if (!('name' in Function.prototype && (function x() {}).name === 'x')) { + +// Function.name +(function () { + + var + accessorName = 'name', + fnNameMatchRegex = /^\s*function\s+([^\(\s]*)\s*/, + $Function = Function, + FunctionName = 'Function', + FunctionProto = $Function.prototype, + FunctionProtoCtor = FunctionProto.constructor, + + getFunctionName = function(fn) { + var match, name; + + if (fn === $Function || fn === FunctionProtoCtor) { + name = FunctionName; + } + else if (fn !== FunctionProto) { + match = ('' + fn).match(fnNameMatchRegex); + name = match && match[1]; + } + return name || ''; + }; + + + Object.defineProperty(FunctionProto, accessorName, { + get: function Function$name() { + var + fn = this, + fnName = getFunctionName(fn); + + // Since named function definitions have immutable names, also memoize the + // output by defining the `name` property directly on this Function + // instance so the accessor function will not need to be invoked again. + if (fn !== FunctionProto) { + Object.defineProperty(fn, accessorName, { + value: fnName, + configurable: true + }); + } + + return fnName; + }, + configurable: true + }); + +}()); + +} + +if (!('acosh' in Math)) { + +// Math.acosh +/* global CreateMethodProperty */ +// 20.2.2.3. Math.acosh ( x ) +CreateMethodProperty(Math, 'acosh', function acosh(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is less than 1, the result is NaN. + if (x < 1) { + return NaN; + } + // If x is 1, the result is +0. + if (x === 1) { + return 0; + } + // If x is +∞, the result is +∞. + if (x === Infinity) { + return Infinity; + } + return Math.log(x + Math.sqrt(x * x - 1)); +}); + +} + +if (!('asinh' in Math)) { + +// Math.asinh +/* global CreateMethodProperty */ +// 20.2.2.5. Math.asinh ( x ) +CreateMethodProperty(Math, 'asinh', function asinh(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is +0, the result is +0. + if (x === 0 && 1/x === Infinity) { + return 0; + } + // If x is -0, the result is -0. + if (x === 0 && 1/x === -Infinity) { + return -0; + } + // If x is +∞, the result is +∞. + if (x === Infinity) { + return Infinity; + } + // If x is -∞, the result is -∞. + if (x === -Infinity) { + return -Infinity; + } + return Math.log(x + Math.sqrt(x * x + 1)); +}); + +} + +if (!('atanh' in Math)) { + +// Math.atanh +/* global CreateMethodProperty */ +// 20.2.2.7. Math.atanh ( x ) +CreateMethodProperty(Math, 'atanh', function atanh(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is less than -1, the result is NaN. + if (x < -1) { + return NaN; + } + // If x is greater than 1, the result is NaN. + if (x > 1) { + return NaN; + } + // If x is -1, the result is -∞. + if (x === -1) { + return -Infinity; + } + // If x is +1, the result is +∞. + if (x === 1) { + return Infinity; + } + // If x is +0, the result is +0. + if (x === 0 && 1/x === Infinity) { + return 0; + } + // If x is -0, the result is -0. + if (x === 0 && 1/x === -Infinity) { + return -0; + } + return Math.log((1 + x) / (1 - x)) / 2; +}); + +} + +if (!('cbrt' in Math)) { + +// Math.cbrt +/* global CreateMethodProperty */ +// 20.2.2.9. Math.cbrt ( x ) +CreateMethodProperty(Math, 'cbrt', function cbrt(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is +0, the result is +0. + if (x === 0 && 1/x === Infinity) { + return 0; + } + // If x is -0, the result is -0. + if (x === 0 && 1/x === -Infinity) { + return -0; + } + // If x is +∞, the result is +∞. + if (x === Infinity) { + return Infinity; + } + // If x is -∞, the result is -∞. + if (x === -Infinity) { + return -Infinity; + } + var y = Math.pow(Math.abs(x), 1 / 3); + return x < 0 ? -y : y; +}); + +} + + +// _ESAbstract.ToUint32 +// 7.1.6. ToUint32 ( argument ) +function ToUint32(argument) { // eslint-disable-line no-unused-vars + // 1. Let number be ? ToNumber(argument). + var number = Number(argument); + // 2. If number is NaN, +0, -0, +∞, or -∞, return +0. + if (isNaN(number) || 1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) { + return 0; + } + // 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)). + var int = ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number)); + // 4. Let int32bit be int modulo 2^32. + var int32bit = int >>> 0; + // 5. Return int32bit. + return int32bit; +} +if (!('clz32' in Math)) { + +// Math.clz32 +/* global CreateMethodProperty, ToUint32 */ +// 20.2.2.11. Math.clz32 ( x ) +CreateMethodProperty(Math, 'clz32', function clz32(x) { + // 1. Let n be ToUint32(x). + var n = ToUint32(x); + // 2. Let p be the number of leading zero bits in the 32-bit binary representation of n. + var p = n ? 32 - n.toString(2).length : 32; + // 3. Return p. + return p; +}); + +} + +if (!('cosh' in Math)) { + +// Math.cosh +/* global CreateMethodProperty */ +// 20.2.2.1. 3Math.cosh ( x ) +CreateMethodProperty(Math, 'cosh', function cosh(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is +0, the result is 1. + if (x === 0 && 1/x === Infinity) { + return 1; + } + // If x is -0, the result is 1. + if (x === 0 && 1/x === -Infinity) { + return 1; + } + // If x is +∞, the result is +∞. + if (x === Infinity) { + return Infinity; + } + // If x is -∞, the result is +∞. + if (x === -Infinity) { + return Infinity; + } + x = Math.abs(x); + if (x > 709) { + var y = Math.exp(0.5 * x); + return y / 2 * y; + } + var y = Math.exp(x); + return (y + 1 / y) / 2; +}); + +} + +if (!('expm1' in Math)) { + +// Math.expm1 +/* global CreateMethodProperty */ +// 20.2.2.15. Math.expm1 ( x ) +CreateMethodProperty(Math, 'expm1', function expm1(x) { + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is +0, the result is +0. + if (x === 0 && 1/x === Infinity) { + return 0; + } + // If x is -0, the result is -0. + if (x === 0 && 1/x === -Infinity) { + return -0; + } + // If x is +∞, the result is +∞. + if (x === Infinity) { + return Infinity; + } + // If x is -∞, the result is -1. + if (x === -Infinity) { + return -1; + } + + if (x > -1e-6 && x < 1e-6) { + return x + x * x / 2; + } else { + return Math.exp(x) - 1; + } +}); + +} + + +// _TypedArray +/* + Copyright (c) 2010, Linden Research, Inc. + Copyright (c) 2014, Joshua Bell + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + $/LicenseInfo$ + */ + +// Original can be found at: +// https://bitbucket.org/lindenlab/llsd +// Modifications by Joshua Bell inexorabletash@gmail.com +// https://github.com/inexorabletash/polyfill + +// ES3/ES5 implementation of the Krhonos Typed Array Specification +// Ref: http://www.khronos.org/registry/typedarray/specs/latest/ +// Date: 2011-02-01 +// +// Variations: +// * Allows typed_array.get/set() as alias for subscripts (typed_array[]) +// * Gradually migrating structure from Khronos spec to ES2015 spec +// +// Caveats: +// * Beyond 10000 or so entries, polyfilled array accessors (ta[0], +// etc) become memory-prohibitive, so array creation will fail. Set +// self.TYPED_ARRAY_POLYFILL_NO_ARRAY_ACCESSORS=true to disable +// creation of accessors. Your code will need to use the +// non-standard get()/set() instead, and will need to add those to +// native arrays for interop. +(function(global) { + 'use strict'; + var undefined = (void 0); // Paranoia + + // Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to + // create, and consume so much memory, that the browser appears frozen. + var MAX_ARRAY_LENGTH = 1e5; + + // Approximations of internal ECMAScript conversion functions + function Type(v) { + switch(typeof v) { + case 'undefined': return 'undefined'; + case 'boolean': return 'boolean'; + case 'number': return 'number'; + case 'string': return 'string'; + default: return v === null ? 'null' : 'object'; + } + } + + // Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues: + function Class(v) { return Object.prototype.toString.call(v).replace(/^\[object *|\]$/g, ''); } + function IsCallable(o) { return typeof o === 'function'; } + function ToObject(v) { + if (v === null || v === undefined) throw TypeError(); + return Object(v); + } + function ToInt32(v) { return v >> 0; } + function ToUint32(v) { return v >>> 0; } + + // Snapshot intrinsics + var LN2 = Math.LN2, + abs = Math.abs, + floor = Math.floor, + log = Math.log, + max = Math.max, + min = Math.min, + pow = Math.pow, + round = Math.round; + + // emulate ES5 getter/setter API using legacy APIs + // http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx + // (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but + // note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless) + + (function() { + var orig = Object.defineProperty; + var dom_only = !(function(){try{return Object.defineProperty({},'x',{});}catch(_){return false;}}()); + + if (!orig || dom_only) { + Object.defineProperty = function (o, prop, desc) { + // In IE8 try built-in implementation for defining properties on DOM prototypes. + if (orig) + try { return orig(o, prop, desc); } catch (_) {} + if (o !== Object(o)) + throw TypeError('Object.defineProperty called on non-object'); + if (Object.prototype.__defineGetter__ && ('get' in desc)) + Object.prototype.__defineGetter__.call(o, prop, desc.get); + if (Object.prototype.__defineSetter__ && ('set' in desc)) + Object.prototype.__defineSetter__.call(o, prop, desc.set); + if ('value' in desc) + o[prop] = desc.value; + return o; + }; + } + }()); + + // ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value) + // for index in 0 ... obj.length + function makeArrayAccessors(obj) { + if ('TYPED_ARRAY_POLYFILL_NO_ARRAY_ACCESSORS' in global) + return; + + if (obj.length > MAX_ARRAY_LENGTH) throw RangeError('Array too large for polyfill'); + + function makeArrayAccessor(index) { + Object.defineProperty(obj, index, { + 'get': function() { return obj._getter(index); }, + 'set': function(v) { obj._setter(index, v); }, + enumerable: true, + configurable: false + }); + } + + var i; + for (i = 0; i < obj.length; i += 1) { + makeArrayAccessor(i); + } + } + + // Internal conversion functions: + // pack() - take a number (interpreted as Type), output a byte array + // unpack() - take a byte array, output a Type-like number + + function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; } + function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; } + + function packI8(n) { return [n & 0xff]; } + function unpackI8(bytes) { return as_signed(bytes[0], 8); } + + function packU8(n) { return [n & 0xff]; } + function unpackU8(bytes) { return as_unsigned(bytes[0], 8); } + + function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; } + + function packI16(n) { return [n & 0xff, (n >> 8) & 0xff]; } + function unpackI16(bytes) { return as_signed(bytes[1] << 8 | bytes[0], 16); } + + function packU16(n) { return [n & 0xff, (n >> 8) & 0xff]; } + function unpackU16(bytes) { return as_unsigned(bytes[1] << 8 | bytes[0], 16); } + + function packI32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; } + function unpackI32(bytes) { return as_signed(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); } + + function packU32(n) { return [n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff]; } + function unpackU32(bytes) { return as_unsigned(bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0], 32); } + + function packIEEE754(v, ebits, fbits) { + + var bias = (1 << (ebits - 1)) - 1; + + function roundToEven(n) { + var w = floor(n), f = n - w; + if (f < 0.5) + return w; + if (f > 0.5) + return w + 1; + return w % 2 ? w + 1 : w; + } + + // Compute sign, exponent, fraction + var s, e, f; + if (v !== v) { + // NaN + // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping + e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0; + } else if (v === Infinity || v === -Infinity) { + e = (1 << ebits) - 1; f = 0; s = (v < 0) ? 1 : 0; + } else if (v === 0) { + e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0; + } else { + s = v < 0; + v = abs(v); + + if (v >= pow(2, 1 - bias)) { + // Normalized + e = min(floor(log(v) / LN2), 1023); + var significand = v / pow(2, e); + if (significand < 1) { + e -= 1; + significand *= 2; + } + if (significand >= 2) { + e += 1; + significand /= 2; + } + var d = pow(2, fbits); + f = roundToEven(significand * d) - d; + e += bias; + if (f / d >= 1) { + e += 1; + f = 0; + } + if (e > 2 * bias) { + // Overflow + e = (1 << ebits) - 1; + f = 0; + } + } else { + // Denormalized + e = 0; + f = roundToEven(v / pow(2, 1 - bias - fbits)); + } + } + + // Pack sign, exponent, fraction + var bits = [], i; + for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); } + for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); } + bits.push(s ? 1 : 0); + bits.reverse(); + var str = bits.join(''); + + // Bits to bytes + var bytes = []; + while (str.length) { + bytes.unshift(parseInt(str.substring(0, 8), 2)); + str = str.substring(8); + } + return bytes; + } + + function unpackIEEE754(bytes, ebits, fbits) { + // Bytes to bits + var bits = [], i, j, b, str, + bias, s, e, f; + + for (i = 0; i < bytes.length; ++i) { + b = bytes[i]; + for (j = 8; j; j -= 1) { + bits.push(b % 2 ? 1 : 0); b = b >> 1; + } + } + bits.reverse(); + str = bits.join(''); + + // Unpack sign, exponent, fraction + bias = (1 << (ebits - 1)) - 1; + s = parseInt(str.substring(0, 1), 2) ? -1 : 1; + e = parseInt(str.substring(1, 1 + ebits), 2); + f = parseInt(str.substring(1 + ebits), 2); + + // Produce number + if (e === (1 << ebits) - 1) { + return f !== 0 ? NaN : s * Infinity; + } else if (e > 0) { + // Normalized + return s * pow(2, e - bias) * (1 + f / pow(2, fbits)); + } else if (f !== 0) { + // Denormalized + return s * pow(2, -(bias - 1)) * (f / pow(2, fbits)); + } else { + return s < 0 ? -0 : 0; + } + } + + function unpackF64(b) { return unpackIEEE754(b, 11, 52); } + function packF64(v) { return packIEEE754(v, 11, 52); } + function unpackF32(b) { return unpackIEEE754(b, 8, 23); } + function packF32(v) { return packIEEE754(v, 8, 23); } + + // + // 3 The ArrayBuffer Type + // + + (function() { + + function ArrayBuffer(length) { + length = ToInt32(length); + if (length < 0) throw RangeError('ArrayBuffer size is not a small enough positive integer.'); + Object.defineProperty(this, 'byteLength', {value: length}); + Object.defineProperty(this, '_bytes', {value: Array(length)}); + + for (var i = 0; i < length; i += 1) + this._bytes[i] = 0; + } + + global.ArrayBuffer = global.ArrayBuffer || ArrayBuffer; + + // + // 5 The Typed Array View Types + // + + function $TypedArray$() { + + // %TypedArray% ( length ) + if (!arguments.length || typeof arguments[0] !== 'object') { + return (function(length) { + length = ToInt32(length); + if (length < 0) throw RangeError('length is not a small enough positive integer.'); + Object.defineProperty(this, 'length', {value: length}); + Object.defineProperty(this, 'byteLength', {value: length * this.BYTES_PER_ELEMENT}); + Object.defineProperty(this, 'buffer', {value: new ArrayBuffer(this.byteLength)}); + Object.defineProperty(this, 'byteOffset', {value: 0}); + + }).apply(this, arguments); + } + + // %TypedArray% ( typedArray ) + if (arguments.length >= 1 && + Type(arguments[0]) === 'object' && + arguments[0] instanceof $TypedArray$) { + return (function(typedArray){ + if (this.constructor !== typedArray.constructor) throw TypeError(); + + var byteLength = typedArray.length * this.BYTES_PER_ELEMENT; + Object.defineProperty(this, 'buffer', {value: new ArrayBuffer(byteLength)}); + Object.defineProperty(this, 'byteLength', {value: byteLength}); + Object.defineProperty(this, 'byteOffset', {value: 0}); + Object.defineProperty(this, 'length', {value: typedArray.length}); + + for (var i = 0; i < this.length; i += 1) + this._setter(i, typedArray._getter(i)); + + }).apply(this, arguments); + } + + // %TypedArray% ( array ) + if (arguments.length >= 1 && + Type(arguments[0]) === 'object' && + !(arguments[0] instanceof $TypedArray$) && + !(arguments[0] instanceof ArrayBuffer || Class(arguments[0]) === 'ArrayBuffer')) { + return (function(array) { + + var byteLength = array.length * this.BYTES_PER_ELEMENT; + Object.defineProperty(this, 'buffer', {value: new ArrayBuffer(byteLength)}); + Object.defineProperty(this, 'byteLength', {value: byteLength}); + Object.defineProperty(this, 'byteOffset', {value: 0}); + Object.defineProperty(this, 'length', {value: array.length}); + + for (var i = 0; i < this.length; i += 1) { + var s = array[i]; + this._setter(i, Number(s)); + } + }).apply(this, arguments); + } + + // %TypedArray% ( buffer, byteOffset=0, length=undefined ) + if (arguments.length >= 1 && + Type(arguments[0]) === 'object' && + (arguments[0] instanceof ArrayBuffer || Class(arguments[0]) === 'ArrayBuffer')) { + return (function(buffer, byteOffset, length) { + + byteOffset = ToUint32(byteOffset); + if (byteOffset > buffer.byteLength) + throw RangeError('byteOffset out of range'); + + // The given byteOffset must be a multiple of the element + // size of the specific type, otherwise an exception is raised. + if (byteOffset % this.BYTES_PER_ELEMENT) + throw RangeError('buffer length minus the byteOffset is not a multiple of the element size.'); + + if (length === undefined) { + var byteLength = buffer.byteLength - byteOffset; + if (byteLength % this.BYTES_PER_ELEMENT) + throw RangeError('length of buffer minus byteOffset not a multiple of the element size'); + length = byteLength / this.BYTES_PER_ELEMENT; + + } else { + length = ToUint32(length); + byteLength = length * this.BYTES_PER_ELEMENT; + } + + if ((byteOffset + byteLength) > buffer.byteLength) + throw RangeError('byteOffset and length reference an area beyond the end of the buffer'); + + Object.defineProperty(this, 'buffer', {value: buffer}); + Object.defineProperty(this, 'byteLength', {value: byteLength}); + Object.defineProperty(this, 'byteOffset', {value: byteOffset}); + Object.defineProperty(this, 'length', {value: length}); + + }).apply(this, arguments); + } + + // %TypedArray% ( all other argument combinations ) + throw TypeError(); + } + + // Properties of the %TypedArray Instrinsic Object + + // %TypedArray%.from ( source , mapfn=undefined, thisArg=undefined ) + Object.defineProperty($TypedArray$, 'from', {value: function(iterable) { + return new this(iterable); + }}); + + // %TypedArray%.of ( ...items ) + Object.defineProperty($TypedArray$, 'of', {value: function(/*...items*/) { + return new this(arguments); + }}); + + // %TypedArray%.prototype + var $TypedArrayPrototype$ = {}; + $TypedArray$.prototype = $TypedArrayPrototype$; + + // WebIDL: getter type (unsigned long index); + Object.defineProperty($TypedArray$.prototype, '_getter', {value: function(index) { + if (arguments.length < 1) throw SyntaxError('Not enough arguments'); + + index = ToUint32(index); + if (index >= this.length) + return undefined; + + var bytes = [], i, o; + for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; + i < this.BYTES_PER_ELEMENT; + i += 1, o += 1) { + bytes.push(this.buffer._bytes[o]); + } + return this._unpack(bytes); + }}); + + // NONSTANDARD: convenience alias for getter: type get(unsigned long index); + Object.defineProperty($TypedArray$.prototype, 'get', {value: $TypedArray$.prototype._getter}); + + // WebIDL: setter void (unsigned long index, type value); + Object.defineProperty($TypedArray$.prototype, '_setter', {value: function(index, value) { + if (arguments.length < 2) throw SyntaxError('Not enough arguments'); + + index = ToUint32(index); + if (index >= this.length) + return; + + var bytes = this._pack(value), i, o; + for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; + i < this.BYTES_PER_ELEMENT; + i += 1, o += 1) { + this.buffer._bytes[o] = bytes[i]; + } + }}); + + // get %TypedArray%.prototype.buffer + // get %TypedArray%.prototype.byteLength + // get %TypedArray%.prototype.byteOffset + // -- applied directly to the object in the constructor + + // %TypedArray%.prototype.constructor + Object.defineProperty($TypedArray$.prototype, 'constructor', {value: $TypedArray$}); + + // %TypedArray%.prototype.copyWithin (target, start, end = this.length ) + Object.defineProperty($TypedArray$.prototype, 'copyWithin', {value: function(target, start) { + var end = arguments[2]; + + var o = ToObject(this); + var lenVal = o.length; + var len = ToUint32(lenVal); + len = max(len, 0); + var relativeTarget = ToInt32(target); + var to; + if (relativeTarget < 0) + to = max(len + relativeTarget, 0); + else + to = min(relativeTarget, len); + var relativeStart = ToInt32(start); + var from; + if (relativeStart < 0) + from = max(len + relativeStart, 0); + else + from = min(relativeStart, len); + var relativeEnd; + if (end === undefined) + relativeEnd = len; + else + relativeEnd = ToInt32(end); + var final; + if (relativeEnd < 0) + final = max(len + relativeEnd, 0); + else + final = min(relativeEnd, len); + var count = min(final - from, len - to); + var direction; + if (from < to && to < from + count) { + direction = -1; + from = from + count - 1; + to = to + count - 1; + } else { + direction = 1; + } + while (count > 0) { + o._setter(to, o._getter(from)); + from = from + direction; + to = to + direction; + count = count - 1; + } + return o; + }}); + + // %TypedArray%.prototype.entries ( ) + // -- defined in es6.js to shim browsers w/ native TypedArrays + + // %TypedArray%.prototype.every ( callbackfn, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'every', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + var thisArg = arguments[1]; + for (var i = 0; i < len; i++) { + if (!callbackfn.call(thisArg, t._getter(i), i, t)) + return false; + } + return true; + }}); + + // %TypedArray%.prototype.fill (value, start = 0, end = this.length ) + Object.defineProperty($TypedArray$.prototype, 'fill', {value: function(value) { + var start = arguments[1], + end = arguments[2]; + + var o = ToObject(this); + var lenVal = o.length; + var len = ToUint32(lenVal); + len = max(len, 0); + var relativeStart = ToInt32(start); + var k; + if (relativeStart < 0) + k = max((len + relativeStart), 0); + else + k = min(relativeStart, len); + var relativeEnd; + if (end === undefined) + relativeEnd = len; + else + relativeEnd = ToInt32(end); + var final; + if (relativeEnd < 0) + final = max((len + relativeEnd), 0); + else + final = min(relativeEnd, len); + while (k < final) { + o._setter(k, value); + k += 1; + } + return o; + }}); + + // %TypedArray%.prototype.filter ( callbackfn, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'filter', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + var res = []; + var thisp = arguments[1]; + for (var i = 0; i < len; i++) { + var val = t._getter(i); // in case fun mutates this + if (callbackfn.call(thisp, val, i, t)) + res.push(val); + } + return new this.constructor(res); + }}); + + // %TypedArray%.prototype.find (predicate, thisArg = undefined) + Object.defineProperty($TypedArray$.prototype, 'find', {value: function(predicate) { + var o = ToObject(this); + var lenValue = o.length; + var len = ToUint32(lenValue); + if (!IsCallable(predicate)) throw TypeError(); + var t = arguments.length > 1 ? arguments[1] : undefined; + var k = 0; + while (k < len) { + var kValue = o._getter(k); + var testResult = predicate.call(t, kValue, k, o); + if (Boolean(testResult)) + return kValue; + ++k; + } + return undefined; + }}); + + // %TypedArray%.prototype.findIndex ( predicate, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'findIndex', {value: function(predicate) { + var o = ToObject(this); + var lenValue = o.length; + var len = ToUint32(lenValue); + if (!IsCallable(predicate)) throw TypeError(); + var t = arguments.length > 1 ? arguments[1] : undefined; + var k = 0; + while (k < len) { + var kValue = o._getter(k); + var testResult = predicate.call(t, kValue, k, o); + if (Boolean(testResult)) + return k; + ++k; + } + return -1; + }}); + + // %TypedArray%.prototype.forEach ( callbackfn, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'forEach', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + var thisp = arguments[1]; + for (var i = 0; i < len; i++) + callbackfn.call(thisp, t._getter(i), i, t); + }}); + + // %TypedArray%.prototype.indexOf (searchElement, fromIndex = 0 ) + Object.defineProperty($TypedArray$.prototype, 'indexOf', {value: function(searchElement) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (len === 0) return -1; + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n !== n) { + n = 0; + } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { + n = (n > 0 || -1) * floor(abs(n)); + } + } + if (n >= len) return -1; + var k = n >= 0 ? n : max(len - abs(n), 0); + for (; k < len; k++) { + if (t._getter(k) === searchElement) { + return k; + } + } + return -1; + }}); + + // %TypedArray%.prototype.join ( separator ) + Object.defineProperty($TypedArray$.prototype, 'join', {value: function(separator) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + var tmp = Array(len); + for (var i = 0; i < len; ++i) + tmp[i] = t._getter(i); + return tmp.join(separator === undefined ? ',' : separator); // Hack for IE7 + }}); + + // %TypedArray%.prototype.keys ( ) + // -- defined in es6.js to shim browsers w/ native TypedArrays + + // %TypedArray%.prototype.lastIndexOf ( searchElement, fromIndex = this.length-1 ) + Object.defineProperty($TypedArray$.prototype, 'lastIndexOf', {value: function(searchElement) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (len === 0) return -1; + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n !== n) { + n = 0; + } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { + n = (n > 0 || -1) * floor(abs(n)); + } + } + var k = n >= 0 ? min(n, len - 1) : len - abs(n); + for (; k >= 0; k--) { + if (t._getter(k) === searchElement) + return k; + } + return -1; + }}); + + // get %TypedArray%.prototype.length + // -- applied directly to the object in the constructor + + // %TypedArray%.prototype.map ( callbackfn, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'map', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + var res = []; res.length = len; + var thisp = arguments[1]; + for (var i = 0; i < len; i++) + res[i] = callbackfn.call(thisp, t._getter(i), i, t); + return new this.constructor(res); + }}); + + // %TypedArray%.prototype.reduce ( callbackfn [, initialValue] ) + Object.defineProperty($TypedArray$.prototype, 'reduce', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + // no value to return if no initial value and an empty array + if (len === 0 && arguments.length === 1) throw TypeError(); + var k = 0; + var accumulator; + if (arguments.length >= 2) { + accumulator = arguments[1]; + } else { + accumulator = t._getter(k++); + } + while (k < len) { + accumulator = callbackfn.call(undefined, accumulator, t._getter(k), k, t); + k++; + } + return accumulator; + }}); + + // %TypedArray%.prototype.reduceRight ( callbackfn [, initialValue] ) + Object.defineProperty($TypedArray$.prototype, 'reduceRight', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + // no value to return if no initial value, empty array + if (len === 0 && arguments.length === 1) throw TypeError(); + var k = len - 1; + var accumulator; + if (arguments.length >= 2) { + accumulator = arguments[1]; + } else { + accumulator = t._getter(k--); + } + while (k >= 0) { + accumulator = callbackfn.call(undefined, accumulator, t._getter(k), k, t); + k--; + } + return accumulator; + }}); + + // %TypedArray%.prototype.reverse ( ) + Object.defineProperty($TypedArray$.prototype, 'reverse', {value: function() { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + var half = floor(len / 2); + for (var i = 0, j = len - 1; i < half; ++i, --j) { + var tmp = t._getter(i); + t._setter(i, t._getter(j)); + t._setter(j, tmp); + } + return t; + }}); + + // %TypedArray%.prototype.set(array, offset = 0 ) + // %TypedArray%.prototype.set(typedArray, offset = 0 ) + // WebIDL: void set(TypedArray array, optional unsigned long offset); + // WebIDL: void set(sequence array, optional unsigned long offset); + Object.defineProperty($TypedArray$.prototype, 'set', {value: function(index, value) { + if (arguments.length < 1) throw SyntaxError('Not enough arguments'); + var array, sequence, offset, len, + i, s, d, + byteOffset, byteLength, tmp; + + if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) { + // void set(TypedArray array, optional unsigned long offset); + array = arguments[0]; + offset = ToUint32(arguments[1]); + + if (offset + array.length > this.length) { + throw RangeError('Offset plus length of array is out of range'); + } + + byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT; + byteLength = array.length * this.BYTES_PER_ELEMENT; + + if (array.buffer === this.buffer) { + tmp = []; + for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) { + tmp[i] = array.buffer._bytes[s]; + } + for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) { + this.buffer._bytes[d] = tmp[i]; + } + } else { + for (i = 0, s = array.byteOffset, d = byteOffset; + i < byteLength; i += 1, s += 1, d += 1) { + this.buffer._bytes[d] = array.buffer._bytes[s]; + } + } + } else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') { + // void set(sequence array, optional unsigned long offset); + sequence = arguments[0]; + len = ToUint32(sequence.length); + offset = ToUint32(arguments[1]); + + if (offset + len > this.length) { + throw RangeError('Offset plus length of array is out of range'); + } + + for (i = 0; i < len; i += 1) { + s = sequence[i]; + this._setter(offset + i, Number(s)); + } + } else { + throw TypeError('Unexpected argument type(s)'); + } + }}); + + // %TypedArray%.prototype.slice ( start, end ) + Object.defineProperty($TypedArray$.prototype, 'slice', {value: function(start, end) { + var o = ToObject(this); + var lenVal = o.length; + var len = ToUint32(lenVal); + var relativeStart = ToInt32(start); + var k = (relativeStart < 0) ? max(len + relativeStart, 0) : min(relativeStart, len); + var relativeEnd = (end === undefined) ? len : ToInt32(end); + var final = (relativeEnd < 0) ? max(len + relativeEnd, 0) : min(relativeEnd, len); + var count = final - k; + var c = o.constructor; + var a = new c(count); + var n = 0; + while (k < final) { + var kValue = o._getter(k); + a._setter(n, kValue); + ++k; + ++n; + } + return a; + }}); + + // %TypedArray%.prototype.some ( callbackfn, thisArg = undefined ) + Object.defineProperty($TypedArray$.prototype, 'some', {value: function(callbackfn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + if (!IsCallable(callbackfn)) throw TypeError(); + var thisp = arguments[1]; + for (var i = 0; i < len; i++) { + if (callbackfn.call(thisp, t._getter(i), i, t)) { + return true; + } + } + return false; + }}); + + // %TypedArray%.prototype.sort ( comparefn ) + Object.defineProperty($TypedArray$.prototype, 'sort', {value: function(comparefn) { + if (this === undefined || this === null) throw TypeError(); + var t = Object(this); + var len = ToUint32(t.length); + var tmp = Array(len); + for (var i = 0; i < len; ++i) + tmp[i] = t._getter(i); + function sortCompare(x, y) { + if (x !== x && y !== y) return +0; + if (x !== x) return 1; + if (y !== y) return -1; + if (comparefn !== undefined) { + return comparefn(x, y); + } + if (x < y) return -1; + if (x > y) return 1; + return +0; + } + tmp.sort(sortCompare); + for (i = 0; i < len; ++i) + t._setter(i, tmp[i]); + return t; + }}); + + // %TypedArray%.prototype.subarray(begin = 0, end = this.length ) + // WebIDL: TypedArray subarray(long begin, optional long end); + Object.defineProperty($TypedArray$.prototype, 'subarray', {value: function(start, end) { + function clamp(v, min, max) { return v < min ? min : v > max ? max : v; } + + start = ToInt32(start); + end = ToInt32(end); + + if (arguments.length < 1) { start = 0; } + if (arguments.length < 2) { end = this.length; } + + if (start < 0) { start = this.length + start; } + if (end < 0) { end = this.length + end; } + + start = clamp(start, 0, this.length); + end = clamp(end, 0, this.length); + + var len = end - start; + if (len < 0) { + len = 0; + } + + return new this.constructor( + this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len); + }}); + + // %TypedArray%.prototype.toLocaleString ( ) + // %TypedArray%.prototype.toString ( ) + // %TypedArray%.prototype.values ( ) + // %TypedArray%.prototype [ @@iterator ] ( ) + // get %TypedArray%.prototype [ @@toStringTag ] + // -- defined in es6.js to shim browsers w/ native TypedArrays + + function makeTypedArray(elementSize, pack, unpack) { + // Each TypedArray type requires a distinct constructor instance with + // identical logic, which this produces. + var TypedArray = function() { + Object.defineProperty(this, 'constructor', {value: TypedArray}); + $TypedArray$.apply(this, arguments); + makeArrayAccessors(this); + }; + if ('__proto__' in TypedArray) { + TypedArray.__proto__ = $TypedArray$; + } else { + TypedArray.from = $TypedArray$.from; + TypedArray.of = $TypedArray$.of; + } + + TypedArray.BYTES_PER_ELEMENT = elementSize; + + var TypedArrayPrototype = function() {}; + TypedArrayPrototype.prototype = $TypedArrayPrototype$; + + TypedArray.prototype = new TypedArrayPrototype(); + + Object.defineProperty(TypedArray.prototype, 'BYTES_PER_ELEMENT', {value: elementSize}); + Object.defineProperty(TypedArray.prototype, '_pack', {value: pack}); + Object.defineProperty(TypedArray.prototype, '_unpack', {value: unpack}); + + return TypedArray; + } + + var Int8Array = makeTypedArray(1, packI8, unpackI8); + var Uint8Array = makeTypedArray(1, packU8, unpackU8); + var Uint8ClampedArray = makeTypedArray(1, packU8Clamped, unpackU8); + var Int16Array = makeTypedArray(2, packI16, unpackI16); + var Uint16Array = makeTypedArray(2, packU16, unpackU16); + var Int32Array = makeTypedArray(4, packI32, unpackI32); + var Uint32Array = makeTypedArray(4, packU32, unpackU32); + var Float32Array = makeTypedArray(4, packF32, unpackF32); + var Float64Array = makeTypedArray(8, packF64, unpackF64); + + global.Int8Array = global.Int8Array || Int8Array; + global.Uint8Array = global.Uint8Array || Uint8Array; + global.Uint8ClampedArray = global.Uint8ClampedArray || Uint8ClampedArray; + global.Int16Array = global.Int16Array || Int16Array; + global.Uint16Array = global.Uint16Array || Uint16Array; + global.Int32Array = global.Int32Array || Int32Array; + global.Uint32Array = global.Uint32Array || Uint32Array; + global.Float32Array = global.Float32Array || Float32Array; + global.Float64Array = global.Float64Array || Float64Array; + }()); + + // + // 6 The DataView View Type + // + + (function() { + function r(array, index) { + return IsCallable(array.get) ? array.get(index) : array[index]; + } + + var IS_BIG_ENDIAN = (function() { + var u16array = new Uint16Array([0x1234]), + u8array = new Uint8Array(u16array.buffer); + return r(u8array, 0) === 0x12; + }()); + + // DataView(buffer, byteOffset=0, byteLength=undefined) + // WebIDL: Constructor(ArrayBuffer buffer, + // optional unsigned long byteOffset, + // optional unsigned long byteLength) + function DataView(buffer, byteOffset, byteLength) { + if (!(buffer instanceof ArrayBuffer || Class(buffer) === 'ArrayBuffer')) throw TypeError(); + + byteOffset = ToUint32(byteOffset); + if (byteOffset > buffer.byteLength) + throw RangeError('byteOffset out of range'); + + if (byteLength === undefined) + byteLength = buffer.byteLength - byteOffset; + else + byteLength = ToUint32(byteLength); + + if ((byteOffset + byteLength) > buffer.byteLength) + throw RangeError('byteOffset and length reference an area beyond the end of the buffer'); + + Object.defineProperty(this, 'buffer', {value: buffer}); + Object.defineProperty(this, 'byteLength', {value: byteLength}); + Object.defineProperty(this, 'byteOffset', {value: byteOffset}); + }; + + // get DataView.prototype.buffer + // get DataView.prototype.byteLength + // get DataView.prototype.byteOffset + // -- applied directly to instances by the constructor + + function makeGetter(arrayType) { + return function GetViewValue(byteOffset, littleEndian) { + byteOffset = ToUint32(byteOffset); + + if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) + throw RangeError('Array index out of range'); + + byteOffset += this.byteOffset; + + var uint8Array = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT), + bytes = []; + for (var i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) + bytes.push(r(uint8Array, i)); + + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) + bytes.reverse(); + + return r(new arrayType(new Uint8Array(bytes).buffer), 0); + }; + } + + Object.defineProperty(DataView.prototype, 'getUint8', {value: makeGetter(Uint8Array)}); + Object.defineProperty(DataView.prototype, 'getInt8', {value: makeGetter(Int8Array)}); + Object.defineProperty(DataView.prototype, 'getUint16', {value: makeGetter(Uint16Array)}); + Object.defineProperty(DataView.prototype, 'getInt16', {value: makeGetter(Int16Array)}); + Object.defineProperty(DataView.prototype, 'getUint32', {value: makeGetter(Uint32Array)}); + Object.defineProperty(DataView.prototype, 'getInt32', {value: makeGetter(Int32Array)}); + Object.defineProperty(DataView.prototype, 'getFloat32', {value: makeGetter(Float32Array)}); + Object.defineProperty(DataView.prototype, 'getFloat64', {value: makeGetter(Float64Array)}); + + function makeSetter(arrayType) { + return function SetViewValue(byteOffset, value, littleEndian) { + byteOffset = ToUint32(byteOffset); + if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) + throw RangeError('Array index out of range'); + + // Get bytes + var typeArray = new arrayType([value]), + byteArray = new Uint8Array(typeArray.buffer), + bytes = [], i, byteView; + + for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) + bytes.push(r(byteArray, i)); + + // Flip if necessary + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) + bytes.reverse(); + + // Write them + byteView = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT); + byteView.set(bytes); + }; + } + + Object.defineProperty(DataView.prototype, 'setUint8', {value: makeSetter(Uint8Array)}); + Object.defineProperty(DataView.prototype, 'setInt8', {value: makeSetter(Int8Array)}); + Object.defineProperty(DataView.prototype, 'setUint16', {value: makeSetter(Uint16Array)}); + Object.defineProperty(DataView.prototype, 'setInt16', {value: makeSetter(Int16Array)}); + Object.defineProperty(DataView.prototype, 'setUint32', {value: makeSetter(Uint32Array)}); + Object.defineProperty(DataView.prototype, 'setInt32', {value: makeSetter(Int32Array)}); + Object.defineProperty(DataView.prototype, 'setFloat32', {value: makeSetter(Float32Array)}); + Object.defineProperty(DataView.prototype, 'setFloat64', {value: makeSetter(Float64Array)}); + + global.DataView = global.DataView || DataView; + + }()); + +}(self)); +if (!('fround' in Math)) { + +// Math.fround +/* global Float32Array */ +// 20.2.2.17 Math.fround ( x ) +CreateMethodProperty(Math, 'fround', function (x) { + // 1. If x is NaN, return NaN. + if (isNaN(x)) { + return NaN; + } + // 2. If x is one of +0, -0, +∞, -∞, return x. + if (1 / x === +Infinity || 1 / x === -Infinity || x === +Infinity || x === -Infinity) { + return x; + } + // 3. Let x32 be the result of converting x to a value in IEEE 754-2008 binary32 format using roundTiesToEven. + // 4. Let x64 be the result of converting x32 to a value in IEEE 754-2008 binary64 format. + // 5. Return the ECMAScript Number value corresponding to x64. + return (new Float32Array([x]))[0]; +}); + +} + +if (!('hypot' in Math)) { + +// Math.hypot +/* global CreateMethodProperty */ +// 20.2.2.18. Math.hypot ( value1, value2, ...values ) +CreateMethodProperty(Math, 'hypot', function hypot(value1, value2) { // eslint-disable-line no-unused-vars + // If no arguments are passed, the result is +0. + if (arguments.length === 0) { + return 0; + } + var y = 0; + var max = 0; + for (var i = 0; i < arguments.length; ++i) { + // If any argument is +∞, the result is +∞. + if (arguments[i] === Infinity) { + return Infinity; + } + + // If any argument is -∞, the result is +∞. + if (arguments[i] === -Infinity) { + return Infinity; + } + + // If no argument is +∞ or -∞, and any argument is NaN, the result is NaN. + // If all arguments are either +0 or -0, the result is +0. + // Polyfill.io - The two conditions above are handled in the math. + + var arg = Math.abs(Number(arguments[i])); + if (arg > max) { + y = y * Math.pow(max / arg, 2); + max = arg; + } + if (arg !== 0 || max !== 0) { + y = y + Math.pow(arg / max, 2); + } + } + + return max * Math.sqrt(y); +}); + +} + +if (!('imul' in Math)) { + +// Math.imul +/* global CreateMethodProperty, ToUint32 */ +// 20.2.2.19. Math.imul ( x, y ) +CreateMethodProperty(Math, 'imul', function imul(x, y) { + // 1. Let a be ToUint32(x). + var a = ToUint32(x); + // 2. Let b be ToUint32(y). + var b = ToUint32(y); + // 3. Let product be (a × b) modulo 2^32. + var product = (a * b) % Math.pow(2, 32); + // 4. If product ≥ 2^31, return product - 2^32; otherwise return product. + return (product >= Math.pow(2, 31)) ? product - Math.pow(2, 32) : product; +}); + +} + +if (!('log10' in Math)) { + +// Math.log10 +/* global CreateMethodProperty */ +// 20.2.2.22. Math.log10 ( x ) +CreateMethodProperty(Math, 'log10', function log10(x) { + return Math.log(x) / Math.LN10; +}); + +} + +if (!('log1p' in Math)) { + +// Math.log1p +/* global CreateMethodProperty */ +// 20.2.2.21. Math.log1p ( x ) +CreateMethodProperty(Math, 'log1p', function log1p(x) { + return Math.log(1 + x); +}); + +} + +if (!('log2' in Math)) { + +// Math.log2 +/* global CreateMethodProperty */ +// 20.2.2.23. Math.log2 ( x ) +CreateMethodProperty(Math, 'log2', function log2(x) { + return Math.log(x) / Math.LN2; +}); + +} + +if (!('sign' in Math)) { + +// Math.sign +/* global CreateMethodProperty */ +// 20.2.2.29. Math.sign ( x ) +CreateMethodProperty(Math, 'sign', function sign(x) { + var x = Number(x); + // If x is NaN, the result is NaN. + if (isNaN(x)) { + return NaN; + } + // If x is -0, the result is -0. + if (1 / x === -Infinity) { + return -0; + } + // If x is +0, the result is +0. + if (1 / x === Infinity) { + return 0; + } + // If x is negative and not -0, the result is -1. + if (x < 0) { + return -1; + } + // If x is positive and not +0, the result is +1. + if (x > 0) { + return 1; + } +}); + +} + +if (!('sinh' in Math)) { + +// Math.sinh +/* global CreateMethodProperty */ +// 20.2.2.31. Math.sinh ( x ) +CreateMethodProperty(Math, 'sinh', function sinh(x) { + var s = (x < 0) ? -1 : 1; + var absx = Math.abs(x); + if (absx < 22) { + if (absx < Math.pow(2, -28)) { + return x; + } + var t = Math.exp(absx) - 1; + if (absx < 1) { + return (s * (2 * t - t * t / (t + 1)))/2; + } + return (s * (t + t / (t + 1)))/2; + } + if (absx < 709.7822265625) { + return (s * Math.exp(absx))/2; + } + var w = Math.exp(0.5 * absx); + var t = (s * w)/2; + return t * w; +}); + +} + +if (!('tanh' in Math)) { + +// Math.tanh +/* global CreateMethodProperty */ +// 20.2.2.34. Math.tanh ( x ) +CreateMethodProperty(Math, 'tanh', function tanh(x) { + var y; + + return x === Infinity ? 1 : x === -Infinity ? -1 : (y = Math.exp(2 * x), (y - 1) / (y + 1)); +}); + +} + +if (!('trunc' in Math)) { + +// Math.trunc +/* global CreateMethodProperty */ +CreateMethodProperty(Math, 'trunc', function trunc(x) { + return x < 0 ? Math.ceil(x) : Math.floor(x); +}); + +} + +if (!('EPSILON' in Number)) { + +// Number.Epsilon +// 20.1.2.1. Number.EPSILON +// The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1 that is representable as a Number value, which is approximately 2.2204460492503130808472633361816 x 10-16. +// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +Object.defineProperty(Number, 'EPSILON', { + enumerable: false, + configurable: false, + writable: false, + value: Math.pow(2, -52) +}); + +} + +if (!('MAX_SAFE_INTEGER' in Number)) { + +// Number.MAX_SAFE_INTEGER +// 20.1.2.6. Number.MAX_SAFE_INTEGER +// The value of Number.MAX_SAFE_INTEGER is 9007199254740991 (2^53-1). +// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +Object.defineProperty(Number, 'MAX_SAFE_INTEGER', { + enumerable: false, + configurable: false, + writable: false, + value: Math.pow(2, 53) - 1 +}); + +} + +if (!('MIN_SAFE_INTEGER' in Number)) { + +// Number.MIN_SAFE_INTEGER +// 20.1.2.8. Number.MIN_SAFE_INTEGER +// The value of Number.MIN_SAFE_INTEGER is -9007199254740991 (-(253-1)). +// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +Object.defineProperty(Number, 'MIN_SAFE_INTEGER', { + enumerable: false, + configurable: false, + writable: false, + value: -(Math.pow(2, 53) - 1) +}); + +} + +if (!('isFinite' in Number)) { + +// Number.isFinite +/* global CreateMethodProperty, Type */ +(function () { + var that = this; + // 20.1.2.2. Number.isFinite ( number ) + CreateMethodProperty(Number, 'isFinite', function isFinite(number) { + // 1. If Type(number) is not Number, return false. + if (Type(number) !== 'number') { + return false; + } + // 2. If number is NaN, +∞, or -∞, return false. + // 3. Otherwise, return true. + // Polyfill.io - We use isFinite as it implements steps 2 and 3. + return that.isFinite(number); + }); +}()); + +} + +if (!('isInteger' in Number)) { + +// Number.isInteger +/* global CreateMethodProperty, ToInteger, Type */ +// 20.1.2.3. Number.isInteger ( number ) +CreateMethodProperty(Number, 'isInteger', function isInteger(number) { + // 1. If Type(number) is not Number, return false. + if (Type(number) !== 'number') { + return false; + } + // 2. If number is NaN, +∞, or -∞, return false. + if (isNaN(number) || number === Infinity || number === -Infinity) { + return false; + } + // 3. Let integer be ToInteger(number). + var integer = ToInteger(number); + // 4. If integer is not equal to number, return false. + if (integer !== number) { + return false; + } + // 5. Otherwise, return true. + return true; +}); + +} + +if (!('isNaN' in Number)) { + +// Number.isNaN +/* global CreateMethodProperty, Type */ +(function () { + var that = this; + // 20.1.2.4. Number.isNaN ( number ) + CreateMethodProperty(Number, 'isNaN', function isNaN(number) { + // 1. If Type(number) is not Number, return false. + if (Type(number) !== 'number') { + return false; + } + // 2. If number is NaN, return true. + if (that.isNaN(number)) { + return true; + } + // 3. Otherwise, return false. + return false; + }); +}()); + +} + +if (!('isSafeInteger' in Number)) { + +// Number.isSafeInteger +/* global CreateMethodProperty, Type, ToInteger */ +// 20.1.2.5. Number.isSafeInteger ( number ) +CreateMethodProperty(Number, 'isSafeInteger', function isSafeInteger(number) { + // 1. If Type(number) is not Number, return false. + if (Type(number) !== 'number') { + return false; + } + // 2. If number is NaN, +∞, or -∞, return false. + if (isNaN(number) || number === Infinity || number === -Infinity) { + return false; + } + // 3. Let integer be ToInteger(number). + var integer = ToInteger(number); + // 4. If integer is not equal to number, return false. + if (integer !== number) { + return false; + } + // 5. If abs(integer) ≤ 2^53-1, return true. + if (Math.abs(integer) <= (Math.pow(2, 53) - 1)) { + return true; + } + // 6. Otherwise, return false. + return false; +}); + +} + +if (!('parseFloat' in Number)) { + +// Number.parseFloat +/* global CreateMethodProperty */ +// 20.1.2.12. Number.parseFloat ( string ) +// The value of the Number.parseFloat data property is the same built-in function object that is the value of the parseFloat property of the global object defined in 18.2.4. +CreateMethodProperty(Number, 'parseFloat', parseFloat); + +} + +if (!('parseInt' in Number)) { + +// Number.parseInt +/* global CreateMethodProperty */ +// 20.1.2.13. Number.parseInt ( string, radix ) +// The value of the Number.parseInt data property is the same built-in function object that is the value of the parseInt property of the global object defined in 18.2.5. +CreateMethodProperty(Number, 'parseInt', parseInt); + +} + + +// _ESAbstract.SameValue +/* global Type, SameValueNonNumber */ +// 7.2.10. SameValue ( x, y ) +function SameValue(x, y) { // eslint-disable-line no-unused-vars + // 1. If Type(x) is different from Type(y), return false. + if (Type(x) !== Type(y)) { + return false; + } + // 2. If Type(x) is Number, then + if (Type(x) === 'number') { + // a. If x is NaN and y is NaN, return true. + if (isNaN(x) && isNaN(y)) { + return true; + } + // Polyfill.io - 0 === -0 is true, but they are not the same value. + // b. If x is +0 and y is -0, return false. + // c. If x is -0 and y is +0, return false. + if (x === 0 && y === 0 && 1/x !== 1/y) { + return false; + } + // d. If x is the same Number value as y, return true. + if (x === y) { + return true; + } + // e. Return false. + return false; + } + // 3. Return SameValueNonNumber(x, y). + return SameValueNonNumber(x, y); +} +if (!('is' in Object)) { + +// Object.is +/* global CreateMethodProperty, SameValue */ +// 19.1.2.12. Object.is ( value1, value2 ) +CreateMethodProperty(Object, 'is', function is(value1, value2) { + // 1. Return SameValue(value1, value2). + return SameValue(value1, value2); +}); + +} + +if (!('Promise' in this)) { + +// Promise +!function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var e={};t.m=n,t.c=e,t.i=function(n){return n},t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:r})},t.n=function(n){var e=n&&n.__esModule?function(){return n["default"]}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=100)}({100:/*!***********************!*\ + !*** ./src/global.js ***! + \***********************/ +function(n,t,e){(function(n){var t=e(/*! ./yaku */5);try{n.Promise=t,window.Promise=t}catch(r){}}).call(t,e(/*! ./../~/webpack/buildin/global.js */2))},2:/*!***********************************!*\ + !*** (webpack)/buildin/global.js ***! + \***********************************/ +function(n,t){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(r){"object"==typeof window&&(e=window)}n.exports=e},5:/*!*********************!*\ + !*** ./src/yaku.js ***! + \*********************/ +function(n,t,e){(function(t){!function(){"use strict";function e(){return rn[q][B]||D}function r(n){return n&&"object"==typeof n}function o(n){return"function"==typeof n}function i(n,t){return n instanceof t}function u(n){return i(n,M)}function c(n,t,e){if(!t(n))throw h(e)}function f(){try{return R.apply(S,arguments)}catch(n){return nn.e=n,nn}}function s(n,t){return R=n,S=t,f}function a(n,t){function e(){for(var e=0;en&&(r.length=n)}var r=A(n),o=0;return function(n,t){r[o++]=n,r[o++]=t,2===o&&rn.nextTick(e)}}function l(n,t){var e,r,u,c,f=0;if(!n)throw h(Q);var a=n[rn[q][z]];if(o(a))r=a.call(n);else{if(!o(n.next)){if(i(n,A)){for(e=n.length;f= 0xD800) && (code <= 0xDBFF)) return char + this.__list__[this.__nextIndex__++]; + return char; + }, + configurable: true, + enumerable: false, + writable: true + }, + toString: { + value: function() { + return '[object String Iterator]'; + }, + configurable: true, + enumerable: false, + writable: true + } + }); + + return StringIterator; +}()); +if (!('Symbol' in this && 'iterator' in this.Symbol && !!String.prototype[Symbol.iterator])) { + +// String.prototype.@@iterator +/* global CreateMethodProperty, RequireObjectCoercible, ToString, StringIterator, Symbol */ +// 21.1.3.29. String.prototype [ @@iterator ] ( ) +CreateMethodProperty(String.prototype, Symbol.iterator, function () { + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Return CreateStringIterator(S). + // TODO: Add CreateStringIterator. + return new StringIterator(S); +}); + +} + + +// _ESAbstract.UTF16Decode +// 10.1.2. Static Semantics: UTF16Decode( lead, trail ) +function UTF16Decode(lead, trail) { // eslint-disable-line no-unused-vars + // 1. Assert: 0xD800 ≤ lead ≤ 0xDBFF and 0xDC00 ≤ trail ≤ 0xDFFF. + // 2. Let cp be (lead - 0xD800) × 0x400 + (trail - 0xDC00) + 0x10000. + var cp = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000; + // 3. Return the code point cp. + return cp; +} +if (!('codePointAt' in String.prototype)) { + +// String.prototype.codePointAt +/* global CreateMethodProperty, RequireObjectCoercible, ToInteger, ToString, UTF16Decode */ +// 21.1.3.3. String.prototype.codePointAt ( pos ) +CreateMethodProperty(String.prototype, 'codePointAt', function codePointAt(pos) { + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Let position be ? ToInteger(pos). + var position = ToInteger(pos); + // 4. Let size be the length of S. + var size = S.length; + // 5. If position < 0 or position ≥ size, return undefined. + if (position < 0 || position >= size) { + return undefined; + } + // 6. Let first be the numeric value of the code unit at index position within the String S. + var first = String.prototype.charCodeAt.call(S, position); + // 7. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first. + if (first < 0xD800 || first > 0xDBFF || position + 1 === size) { + return first; + } + // 8. Let second be the numeric value of the code unit at index position+1 within the String S. + var second = String.prototype.charCodeAt.call(S, position + 1); + // 9. If second < 0xDC00 or second > 0xDFFF, return first. + if (second < 0xDC00 || second > 0xDFFF) { + return first; + } + // 10. Return UTF16Decode(first, second). + // 21.1.3.3.10 Return UTF16Decode(first, second). + return UTF16Decode(first, second); +}); + +} + +if (!('endsWith' in String.prototype)) { + +// String.prototype.endsWith +/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */ +// 21.1.3.6. String.prototype.endsWith ( searchString [ , endPosition ] ) +CreateMethodProperty(String.prototype, 'endsWith', function endsWith(searchString /* [ , endPosition ] */) { + 'use strict'; + var endPosition = arguments.length > 1 ? arguments[1] : undefined; + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Let isRegExp be ? IsRegExp(searchString). + var isRegExp = IsRegExp(searchString); + // 4. If isRegExp is true, throw a TypeError exception. + if (isRegExp) { + throw new TypeError('First argument to String.prototype.endsWith must not be a regular expression'); + } + // 5. Let searchStr be ? ToString(searchString). + var searchStr = ToString(searchString); + // 6. Let len be the length of S. + var len = S.length; + // 7. If endPosition is undefined, let pos be len, else let pos be ? ToInteger(endPosition). + var pos = endPosition === undefined ? len : ToInteger(endPosition); + // 8. Let end be min(max(pos, 0), len). + var end = Math.min(Math.max(pos, 0), len); + // 9. Let searchLength be the length of searchStr. + var searchLength = searchStr.length; + // 10. Let start be end - searchLength. + var start = end - searchLength; + // 11. If start is less than 0, return false. + if (start < 0) { + return false; + } + // 12. If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr, return true. + if (S.substr(start, searchLength) === searchStr) { + return true; + } + // 13. Otherwise, return false. + return false; +}); + +} + +if (!('repeat' in String.prototype)) { + +// String.prototype.repeat +/* global CreateMethodProperty, RequireObjectCoercible, ToInteger, ToString */ +// 21.1.3.15String.prototype.repeat ( count ) +CreateMethodProperty(String.prototype, 'repeat', function repeat(count) { + 'use strict'; + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Let n be ? ToInteger(count). + var n = ToInteger(count); + // 4. If n < 0, throw a RangeError exception. + if (n < 0) { + throw new RangeError('Invalid count value'); + } + // 5. If n is +∞, throw a RangeError exception. + if (n === Infinity) { + throw new RangeError('Invalid count value'); + } + // 6. Let T be the String value that is made from n copies of S appended together. If n is 0, T is the empty String. + var T = n === 0 ? '' : new Array(n + 1).join(S); + // 7. Return T. + return T; +}); + +} + +if (!('startsWith' in String.prototype)) { + +// String.prototype.startsWith +/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */ +// 21.1.3.20. String.prototype.startsWith ( searchString [ , position ] ) +CreateMethodProperty(String.prototype, 'startsWith', function startsWith(searchString /* [ , position ] */) { + 'use strict'; + var position = arguments.length > 1 ? arguments[1] : undefined; + // 1. Let O be ? RequireObjectCoercible(this value). + var O = RequireObjectCoercible(this); + // 2. Let S be ? ToString(O). + var S = ToString(O); + // 3. Let isRegExp be ? IsRegExp(searchString). + var isRegExp = IsRegExp(searchString); + // 4. If isRegExp is true, throw a TypeError exception. + if (isRegExp) { + throw new TypeError('First argument to String.prototype.startsWith must not be a regular expression'); + } + // 5. Let searchStr be ? ToString(searchString). + var searchStr = ToString(searchString); + // 6. Let pos be ? ToInteger(position). (If position is undefined, this step produces the value 0.) + var pos = ToInteger(position); + // 7. Let len be the length of S. + var len = S.length; + // 8. Let start be min(max(pos, 0), len). + var start = Math.min(Math.max(pos, 0), len); + // 9. Let searchLength be the length of searchStr. + var searchLength = searchStr.length; + // 10. If searchLength+start is greater than len, return false. + if (searchLength + start > len) { + return false; + } + // 11. If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr, return true. + if (S.substr(start).indexOf(searchString) === 0) { + return true; + } + // 12. Otherwise, return false. + return false; +}); + +} + +if (!('Symbol' in this && 'hasInstance' in this.Symbol)) { + +// Symbol.hasInstance +/* global Symbol */ +Object.defineProperty(Symbol, 'hasInstance', { value: Symbol('hasInstance') }); + +} + +if (!('Symbol' in this && 'isConcatSpreadable' in this.Symbol)) { + +// Symbol.isConcatSpreadable +/* global Symbol */ +Object.defineProperty(Symbol, 'isConcatSpreadable', { value: Symbol('isConcatSpreadable') }); + +} + +if (!('Symbol' in this && 'match' in this.Symbol)) { + +// Symbol.match +/* global Symbol */ +Object.defineProperty(Symbol, 'match', { value: Symbol('match') }); + +} + +if (!('Symbol' in this && 'replace' in this.Symbol)) { + +// Symbol.replace +/* global Symbol */ +Object.defineProperty(Symbol, 'replace', { value: Symbol('replace') }); + +} + +if (!('Symbol' in this && 'search' in this.Symbol)) { + +// Symbol.search +/* global Symbol */ +Object.defineProperty(Symbol, 'search', { value: Symbol('search') }); + +} + +if (!('Symbol' in this && 'split' in this.Symbol)) { + +// Symbol.split +/* global Symbol */ +Object.defineProperty(Symbol, 'split', { value: Symbol('split') }); + +} + +if (!('Symbol' in this && 'toPrimitive' in this.Symbol)) { + +// Symbol.toPrimitive +/* global Symbol */ +Object.defineProperty(Symbol, 'toPrimitive', { value: Symbol('toPrimitive') }); + +} + +if (!('Symbol' in this && 'unscopables' in this.Symbol)) { + +// Symbol.unscopables +/* global Symbol */ +Object.defineProperty(Symbol, 'unscopables', { value: Symbol('unscopables') }); + +} + +if (!((function(global) { + try { + if ("WeakMap" in global && WeakMap.length === 0) { + var o = {}; + var wm = new WeakMap([[o, 'test']]); + return (wm.get(o) === 'test' && wm["delete"](0) === false); + } else { + return false; + } + } catch (err) { + return false; + } +}(this)))) { + +// WeakMap +/* globals Symbol, OrdinaryCreateFromConstructor, IsCallable, GetIterator, IteratorStep, IteratorValue, IteratorClose, Get, Call, CreateMethodProperty, Type, SameValue */ +(function (global) { + // Deleted map items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol. + var undefMarker = Symbol('undef'); + // 23.3.1.1 WeakMap ( [ iterable ] ) + var WeakMap = function WeakMap(/* iterable */) { + // 1. If NewTarget is undefined, throw a TypeError exception. + if (!(this instanceof WeakMap)) { + throw new TypeError('Constructor WeakMap requires "new"'); + } + // 2. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakMapPrototype%", « [[WeakMapData]] »). + var map = OrdinaryCreateFromConstructor(this, WeakMap.prototype, { + _keys: [], + _values: [], + _es6WeakMap: true + }); + + // 3. Set map.[[WeakMapData]] to a new empty List. + // Polyfill.io - This step was done as part of step two. + + // 4. If iterable is not present, let iterable be undefined. + var iterable = arguments.length > 0 ? arguments[0] : undefined; + + // 5. If iterable is either undefined or null, return map. + if (iterable === null || iterable === undefined) { + return map; + } + + // 6. Let adder be ? Get(map, "set"). + var adder = Get(map, "set"); + + // 7. If IsCallable(adder) is false, throw a TypeError exception. + if (!IsCallable(adder)) { + throw new TypeError("WeakMap.prototype.set is not a function"); + } + + // 8. Let iteratorRecord be ? GetIterator(iterable). + try { + var iteratorRecord = GetIterator(iterable); + // 9. Repeat, + while (true) { + // a. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // b. If next is false, return map. + if (next === false) { + return map; + } + // c. Let nextItem be ? IteratorValue(next). + var nextItem = IteratorValue(next); + // d. If Type(nextItem) is not Object, then + if (Type(nextItem) !== 'object') { + // i. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}. + try { + throw new TypeError('Iterator value ' + nextItem + ' is not an entry object'); + } catch (error) { + // ii. Return ? IteratorClose(iteratorRecord, error). + return IteratorClose(iteratorRecord, error); + } + } + try { + // Polyfill.io - The try catch accounts for steps: f, h, and j. + + // e. Let k be Get(nextItem, "0"). + var k = Get(nextItem, "0"); + // f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k). + // g. Let v be Get(nextItem, "1"). + var v = Get(nextItem, "1"); + // h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v). + // i. Let status be Call(adder, map, « k.[[Value]], v.[[Value]] »). + Call(adder, map, [k, v]); + } catch (e) { + // j. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status). + return IteratorClose(iteratorRecord, e); + } + } + } catch (e) { + // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those. + if (Array.isArray(iterable) || + Object.prototype.toString.call(iterable) === '[object Arguments]' || + // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property + (!!iterable.callee)) { + var index; + var length = iterable.length; + for (index = 0; index < length; index++) { + var k = iterable[index][0]; + var v = iterable[index][1]; + Call(adder, map, [k, v]); + } + } + } + return map; + }; + + // 23.3.2.1 WeakMap.prototype + // The initial value of WeakMap.prototype is the intrinsic object %WeakMapPrototype%. + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. + Object.defineProperty(WeakMap, 'prototype', { + configurable: false, + enumerable: false, + writable: false, + value: {} + }); + + // 23.3.3.1 WeakMap.prototype.constructor + CreateMethodProperty(WeakMap.prototype, 'constructor', WeakMap); + + // 23.3.3.2 WeakMap.prototype.delete ( key ) + CreateMethodProperty(WeakMap.prototype, 'delete', function (key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method WeakMap.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError exception. + if (M._es6WeakMap !== true) { + throw new TypeError('Method WeakMap.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[WeakMapData]]. + var entries = M._keys; + // 5. If Type(key) is not Object, return false. + if (Type(key) !== 'object') { + return false; + } + // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, then + if (M._keys[i] !== undefMarker && SameValue(M._keys[i], key)) { + // i. Set p.[[Key]] to empty. + this._keys[i] = undefMarker; + // ii. Set p.[[Value]] to empty. + this._values[i] = undefMarker; + this._size = --this._size; + // iii. Return true. + return true; + } + } + // 7. Return false. + return false; + }); + + // 23.3.3.3 WeakMap.prototype.get ( key ) + CreateMethodProperty(WeakMap.prototype, 'get', function get(key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method WeakMap.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError exception. + if (M._es6WeakMap !== true) { + throw new TypeError('Method WeakMap.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[WeakMapData]]. + var entries = M._keys; + // 5. If Type(key) is not Object, return undefined. + if (Type(key) !== 'object') { + return undefined; + } + // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]]. + if (M._keys[i] !== undefMarker && SameValue(M._keys[i], key)) { + return M._values[i]; + } + } + // 7. Return undefined. + return undefined; + }); + + // 23.3.3.4 WeakMap.prototype.has ( key ) + CreateMethodProperty(WeakMap.prototype, 'has', function has(key) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (typeof M !== 'object') { + throw new TypeError('Method WeakMap.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError exception. + if (M._es6WeakMap !== true) { + throw new TypeError('Method WeakMap.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[WeakMapData]]. + var entries = M._keys; + // 5. If Type(key) is not Object, return false. + if (Type(key) !== 'object') { + return false; + } + // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return true. + if (M._keys[i] !== undefMarker && SameValue(M._keys[i], key)) { + return true; + } + } + // 7. Return false. + return false; + }); + + // 23.3.3.5 WeakMap.prototype.set ( key, value ) + CreateMethodProperty(WeakMap.prototype, 'set', function set(key, value) { + // 1. Let M be the this value. + var M = this; + // 2. If Type(M) is not Object, throw a TypeError exception. + if (Type(M) !== 'object') { + throw new TypeError('Method WeakMap.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError exception. + if (M._es6WeakMap !== true) { + throw new TypeError('Method WeakMap.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M)); + } + // 4. Let entries be the List that is M.[[WeakMapData]]. + var entries = M._keys; + // 5. If Type(key) is not Object, throw a TypeError exception. + if (Type(key) !== 'object') { + throw new TypeError("Invalid value used as weak map key"); + } + // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + // a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, then + if (M._keys[i] !== undefMarker && SameValue(M._keys[i], key)) { + // i. Set p.[[Value]] to value. + M._values[i] = value; + // ii. Return M. + return M; + } + } + // 7. Let p be the Record {[[Key]]: key, [[Value]]: value}. + var p = { + '[[Key]]': key, + '[[Value]]': value + }; + // 8. Append p as the last element of entries. + M._keys.push(p['[[Key]]']); + M._values.push(p['[[Value]]']); + // 9. Return M. + return M; + }); + + // 23.3.3.6 WeakMap.prototype [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "WeakMap". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + // Polyfill.io - Safari 8 implements WeakMap.name but as a non-writable property, which means it would throw an error if we try and write to it here. + if (!('name' in WeakMap)) { + // 19.2.4.2 name + Object.defineProperty(WeakMap, 'name', { + configurable: true, + enumerable: false, + writable: false, + value: 'WeakMap' + }); + } + + // Export the object + try { + CreateMethodProperty(global, 'WeakMap', WeakMap); + } catch (e) { + // IE8 throws an error here if we set enumerable to false. + // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx + global['WeakMap'] = WeakMap; + } +}(this)); + +} + +if (!((function(global) { + try { + if ("WeakSet" in global && WeakSet.length === 0) { + var o = {}; + var ws = new WeakSet([o]); + return (ws.has(o) && ws["delete"](0) === false); + } else { + return false; + } + } catch (err) { + return false; + } +}(this)))) { + +// WeakSet +/* global Call, CreateMethodProperty, Get, GetIterator, IsArray, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Type, Symbol */ +(function (global) { + // Deleted set items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol. + var undefMarker = Symbol('undef'); + // 23.4.1.1. WeakSet ( [ iterable ] ) + var WeakSet = function WeakSet() { + // 1. If NewTarget is undefined, throw a TypeError exception. + if (!(this instanceof WeakSet)) { + throw new TypeError('Constructor WeakSet requires "new"'); + } + // 2. Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakSetPrototype%", « [[WeakSetData]] »). + var set = OrdinaryCreateFromConstructor(this, WeakSet.prototype, { + _values: [], + _size: 0, + _es6WeakSet: true + }); + + // 3. Set set.[[WeakSetData]] to a new empty List. + // Polyfill.io - This step was done as part of step two. + + // 4. If iterable is not present, let iterable be undefined. + var iterable = arguments.length > 0 ? arguments[0] : undefined; + // 5. If iterable is either undefined or null, return set. + if (iterable === null || iterable === undefined) { + return set; + } + // 6. Let adder be ? Get(set, "add"). + var adder = Get(set, 'add'); + // 7. If IsCallable(adder) is false, throw a TypeError exception. + if (!IsCallable(adder)) { + throw new TypeError("WeakSet.prototype.add is not a function"); + } + try { + // 8. Let iteratorRecord be ? GetIterator(iterable). + var iteratorRecord = GetIterator(iterable); + // 9. Repeat, + while (true) { + // a. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // b. If next is false, return set. + if (next === false) { + return set; + } + // c. Let nextValue be ? IteratorValue(next). + var nextValue = IteratorValue(next); + // d. Let status be Call(adder, set, « nextValue »). + try { + Call(adder, set, [nextValue]); + } catch (e) { + // e. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status). + return IteratorClose(iteratorRecord, e); + } + } + } catch (e) { + // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those. + if (IsArray(iterable) || + Object.prototype.toString.call(iterable) === '[object Arguments]' || + // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property + (!!iterable.callee)) { + var index; + var length = iterable.length; + for (index = 0; index < length; index++) { + Call(adder, set, [iterable[index]]); + } + } + } + return set; + }; + + // 23.4.2.1. WeakSet.prototype + // The initial value of WeakSet.prototype is the intrinsic %WeakSetPrototype% object. + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. + Object.defineProperty(WeakSet, 'prototype', { + configurable: false, + enumerable: false, + writable: false, + value: {} + }); + + // 23.4.3.1. WeakSet.prototype.add ( value ) + CreateMethodProperty(WeakSet.prototype, 'add', function add(value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (Type(S) !== 'object') { + throw new TypeError('Method WeakSet.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. + if (S._es6WeakSet !== true) { + throw new TypeError('Method WeakSet.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. If Type(value) is not Object, throw a TypeError exception. + if (Type(value) !== 'object') { + throw new TypeError('Invalid value used in weak set'); + } + // 5. Let entries be the List that is S.[[WeakSetData]]. + var entries = S._values; + // 6. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValue(e, value) is true, then + if (e !== undefMarker && SameValueZero(e, value)) { + // i. Return S. + return S; + } + } + // 7. Append value as the last element of entries. + S._values.push(value); + // 8. Return S. + return S; + }); + + // 23.4.3.2. WeakSet.prototype.constructor + CreateMethodProperty(WeakSet.prototype, 'constructor', WeakSet); + + // 23.4.3.3. WeakSet.prototype.delete ( value ) + CreateMethodProperty(WeakSet.prototype, 'delete', function (value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (Type(S) !== 'object') { + throw new TypeError('Method WeakSet.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. + if (S._es6WeakSet !== true) { + throw new TypeError('Method WeakSet.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. If Type(value) is not Object, return false. + if (Type(value) !== 'object') { + return false; + } + // 5. Let entries be the List that is S.[[WeakSetData]]. + var entries = S._values; + // 6. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValue(e, value) is true, then + if (e !== undefMarker && SameValueZero(e, value)) { + // i. Replace the element of entries whose value is e with an element whose value is empty. + entries[i] = undefMarker; + // ii. Return true. + return true; + } + } + // 7. Return false. + return false; + }); + + // 23.4.3.4. WeakSet.prototype.has ( value ) + CreateMethodProperty(WeakSet.prototype, 'has', function has(value) { + // 1. Let S be the this value. + var S = this; + // 2. If Type(S) is not Object, throw a TypeError exception. + if (Type(S) !== 'object') { + throw new TypeError('Method WeakSet.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 3. If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. + if (S._es6WeakSet !== true) { + throw new TypeError('Method WeakSet.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(S)); + } + // 4. Let entries be the List that is S.[[WeakSetData]]. + var entries = S._values; + // 5. If Type(value) is not Object, return false. + if (Type(value) !== 'object') { + return false; + } + // 6. For each e that is an element of entries, do + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + // a. If e is not empty and SameValue(e, value) is true, return true. + if (e !== undefMarker && SameValueZero(e, value)) { + return true; + } + } + // 7. Return false. + return false; + }); + + // 23.4.3.5. WeakSet.prototype [ @@toStringTag ] + // The initial value of the @@toStringTag property is the String value "WeakSet". + // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. + + // Polyfill.io - Safari 8 implements Set.name but as a non-configurable property, which means it would throw an error if we try and configure it here. + if (!('name' in WeakSet)) { + // 19.2.4.2 name + Object.defineProperty(WeakSet, 'name', { + configurable: true, + enumerable: false, + writable: false, + value: 'WeakSet' + }); + } + + // Export the object + try { + CreateMethodProperty(global, 'WeakSet', WeakSet); + } catch (e) { + // IE8 throws an error here if we set enumerable to false. + // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx + global['WeakSet'] = WeakSet; + } + +}(this)); + +} + +}) +.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});