X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/43c09d8062fc4aef4f1e0e5d3598e526a02bb288..783b5e3729228908d7404ae7404af1023501a906:/vendor/assets/polyfill/es6.js diff --git a/vendor/assets/polyfill/es6.js b/vendor/assets/polyfill/es6.js index ae2436e1a..70dae2d9a 100644 --- a/vendor/assets/polyfill/es6.js +++ b/vendor/assets/polyfill/es6.js @@ -1,87 +1,60 @@ -/* Polyfill service v3.27.1 +/* Polyfill service v3.38.0 * For detailed credits and licence information see https://github.com/financial-times/polyfill-service. * * Features requested: es6 * + * - _ESAbstract.ArrayCreate, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - _ESAbstract.Call, License: CC0 (required by "Array.from", "es6", "Array.prototype.find", "Array.prototype.findIndex", "WeakMap", "WeakSet", "_ESAbstract.GetIterator", "Map", "Set", "_ESAbstract.IteratorClose", "_ESAbstract.IteratorNext", "_ESAbstract.IteratorStep", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.of", "Array.prototype.fill", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.OrdinaryToPrimitive") + * - _ESAbstract.Get, License: CC0 (required by "Array.from", "es6", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Object.assign", "RegExp.prototype.flags", "WeakMap", "WeakSet", "_ESAbstract.IteratorValue", "Map", "Set", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_Iterator", "_StringIterator", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.codePointAt", "String.prototype.repeat") + * - _ESAbstract.HasProperty, License: CC0 (required by "Array.prototype.copyWithin", "es6", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") + * - _ESAbstract.IsArray, License: CC0 (required by "String.fromCodePoint", "es6", "WeakMap", "WeakSet", "Array.isArray", "Map", "Array.from", "Set", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") * - _ESAbstract.IsCallable, License: CC0 (required by "Array.from", "es6", "Array.prototype.find", "Array.prototype.findIndex", "Map", "Set", "WeakMap", "WeakSet", "_ESAbstract.GetMethod", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map", "Function.prototype.bind", "_ESAbstract.Construct", "Array.of", "Object.getOwnPropertyDescriptor", "Object.assign", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.fill", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") - * - Object.defineProperty, License: CC0 (required by "Function.name", "es6", "Map", "Array.from", "Number.Epsilon", "Number.MAX_SAFE_INTEGER", "Number.MIN_SAFE_INTEGER", "Object.setPrototypeOf", "RegExp.prototype.flags", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Symbol", "WeakMap", "WeakSet", "_ESAbstract.CreateMethodProperty", "Array.of", "Array.prototype.copyWithin", "Array.prototype.entries", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.keys", "Array.prototype.values", "Math.acosh", "Math.asinh", "Math.atanh", "Math.cbrt", "Math.clz32", "Math.cosh", "Math.expm1", "Math.fround", "Math.hypot", "Math.imul", "Math.log10", "Math.log1p", "Math.log2", "Math.sign", "Math.sinh", "Math.tanh", "Math.trunc", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "Number.parseFloat", "Number.parseInt", "Object.assign", "Object.is", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ArrayIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_StringIterator", "_ESAbstract.CreateDataProperty", "_ESAbstract.CreateDataPropertyOrThrow", "_ESAbstract.CreateIterResultObject", "_Iterator", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator") - * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.@@iterator", "Array.prototype.copyWithin", "Array.prototype.entries", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.keys", "Array.prototype.values", "Map", "Math.acosh", "Math.asinh", "Math.atanh", "Math.cbrt", "Math.clz32", "Math.cosh", "Math.expm1", "Math.fround", "Math.hypot", "Math.imul", "Math.log10", "Math.log1p", "Math.log2", "Math.sign", "Math.sinh", "Math.tanh", "Math.trunc", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "Number.parseFloat", "Number.parseInt", "Object.assign", "Object.is", "Object.setPrototypeOf", "Set", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "WeakMap", "WeakSet", "Array.isArray", "Object.create", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "_ArrayIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Object.getOwnPropertyDescriptor", "Array.prototype.forEach", "Object.getPrototypeOf", "Object.getOwnPropertyNames", "Array.prototype.filter", "Array.prototype.map", "Object.freeze", "Function.prototype.bind", "Object.defineProperties", "_Iterator", "_StringIterator") + * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.@@iterator", "es6", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") + * - _ESAbstract.SameValueNonNumber, License: CC0 (required by "_ESAbstract.SameValueZero", "Map", "es6", "Array.from", "Set", "WeakSet", "_ESAbstract.SameValue", "Object.is", "String.fromCodePoint", "WeakMap") + * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.find", "es6", "Array.prototype.findIndex", "RegExp.prototype.flags", "_ESAbstract.IteratorComplete", "Map", "Array.from", "Set", "_ESAbstract.IteratorStep", "WeakMap", "WeakSet", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Array.prototype.filter", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.copyWithin", "es6", "Array.prototype.fill", "Number.isInteger", "Number.isSafeInteger", "String.fromCodePoint", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.ToLength", "Array.from", "Array.prototype.find", "Array.prototype.findIndex") + * - _ESAbstract.ToLength, License: CC0 (required by "Array.from", "es6", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") + * - _ESAbstract.ToNumber, License: CC0 (required by "String.fromCodePoint", "es6") * - _ESAbstract.ToObject, License: CC0 (required by "Array.from", "es6", "Array.prototype.entries", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "Object.assign", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.GetV", "_ESAbstract.GetMethod", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "Object.defineProperties", "Object.create", "_ArrayIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") * - _ESAbstract.GetV, License: CC0 (required by "_ESAbstract.GetMethod", "Array.from", "es6", "Map", "Set", "_ESAbstract.GetIterator", "WeakMap", "WeakSet") * - _ESAbstract.GetMethod, License: CC0 (required by "Array.from", "es6", "Map", "Set", "_ESAbstract.IsConstructor", "Array.of", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ESAbstract.IteratorClose", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") - * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.copyWithin", "es6", "Array.prototype.fill", "Number.isInteger", "Number.isSafeInteger", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.ToLength", "Array.from", "Array.prototype.find", "Array.prototype.findIndex") - * - _ESAbstract.ToLength, License: CC0 (required by "Array.from", "es6", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") - * - _ESAbstract.Get, License: CC0 (required by "Array.from", "es6", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Object.assign", "RegExp.prototype.flags", "WeakMap", "WeakSet", "_ESAbstract.IteratorValue", "Map", "Set", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_Iterator", "_StringIterator", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.codePointAt", "String.prototype.repeat") - * - _ESAbstract.HasProperty, License: CC0 (required by "Array.prototype.copyWithin", "es6", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") - * - _ESAbstract.Call, License: CC0 (required by "Array.from", "es6", "Array.prototype.find", "Array.prototype.findIndex", "WeakMap", "WeakSet", "_ESAbstract.GetIterator", "Map", "Set", "_ESAbstract.IteratorClose", "_ESAbstract.IteratorNext", "_ESAbstract.IteratorStep", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.of", "Array.prototype.fill", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.OrdinaryToPrimitive") - * - _ESAbstract.Type, License: CC0 (required by "Map", "es6", "Array.from", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "RegExp.prototype.flags", "WeakMap", "WeakSet", "_ESAbstract.IsConstructor", "Array.of", "_ESAbstract.GetIterator", "Set", "_ESAbstract.IteratorClose", "_ESAbstract.ToString", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.IteratorValue", "_ESAbstract.CreateIterResultObject", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "_ESAbstract.IteratorNext", "_ESAbstract.SameValueZero", "Object.create", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.SameValue", "Object.is", "_ESAbstract.IsRegExp", "_ESAbstract.ToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "Object.defineProperties", "_Iterator", "_StringIterator", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.OrdinaryToPrimitive") - * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") - * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") - * - _ESAbstract.ToString, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") - * - Array.prototype.forEach, License: CC0 (required by "Object.setPrototypeOf", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - _ESAbstract.IsArray, License: CC0 (required by "WeakMap", "es6", "WeakSet", "Array.isArray", "Map", "Array.from", "Set", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") - * - _ESAbstract.ArrayCreate, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") - * - _ESAbstract.IsConstructor, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - _ESAbstract.ToUint32, License: CC0 (required by "Math.clz32", "es6", "Math.imul") + * - _ESAbstract.Type, License: CC0 (required by "Map", "es6", "Array.from", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "Object.seal", "RegExp.prototype.flags", "WeakMap", "WeakSet", "_ESAbstract.IsConstructor", "Array.of", "_ESAbstract.GetIterator", "Set", "_ESAbstract.IteratorClose", "_ESAbstract.ToString", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ESAbstract.IteratorValue", "_ESAbstract.CreateIterResultObject", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "_ESAbstract.IteratorNext", "_ESAbstract.SameValueZero", "Object.create", "Object.setPrototypeOf", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.SameValue", "Object.is", "String.fromCodePoint", "_ESAbstract.IsRegExp", "_ESAbstract.ToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "Object.defineProperties", "_Iterator", "_StringIterator", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.OrdinaryToPrimitive") * - _ESAbstract.GetPrototypeFromConstructor, License: CC0 (required by "_ESAbstract.OrdinaryCreateFromConstructor", "Map", "es6", "Array.from", "Set", "WeakMap", "WeakSet", "_ESAbstract.Construct", "Array.of") - * - Object.keys, License: MIT (required by "Object.assign", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Object.defineProperties", "Object.create", "Object.setPrototypeOf", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") - * - Function.prototype.bind, License: MIT (required by "_ESAbstract.Construct", "Array.from", "es6", "Array.of", "Object.getOwnPropertyDescriptor", "Object.assign", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") - * - Object.getOwnPropertyDescriptor, License: CC0 (required by "Object.assign", "es6", "Object.setPrototypeOf", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") - * - Object.defineProperties, License: CC0 (required by "Object.create", "Map", "es6", "Array.from", "Object.setPrototypeOf", "Set", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") - * - Object.create, License: CC0 (required by "Map", "es6", "Array.from", "Object.setPrototypeOf", "Set", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_StringIterator") - * - Object.getPrototypeOf, License: CC0 (required by "Object.setPrototypeOf", "es6", "_ESAbstract.OrdinaryCreateFromConstructor", "Map", "Array.from", "Set", "WeakMap", "WeakSet", "_ESAbstract.Construct", "Array.of") - * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "Map", "es6", "Array.from", "Set", "WeakMap", "WeakSet", "_ESAbstract.Construct", "Array.of") - * - _ESAbstract.Construct, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") - * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.filter", "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") - * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.find", "es6", "Array.prototype.findIndex", "RegExp.prototype.flags", "_ESAbstract.IteratorComplete", "Map", "Array.from", "Set", "_ESAbstract.IteratorStep", "WeakMap", "WeakSet", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Array.prototype.filter", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.from", "es6", "Array.of", "_ESAbstract.CreateIterResultObject", "Map", "Set") - * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") - * - Array.prototype.filter, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - Array.prototype.map, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - Object.getOwnPropertyNames, License: CC0 (required by "Object.setPrototypeOf", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - Object.freeze, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") - * - Symbol, License: MIT (required by "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "WeakMap", "WeakSet", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") - * - Symbol.iterator, License: MIT (required by "es6", "Array.from", "Array.prototype.@@iterator", "Map", "Set", "String.prototype.@@iterator", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") - * - _ESAbstract.GetIterator, License: CC0 (required by "Array.from", "es6", "Map", "Set", "WeakMap", "WeakSet") + * - _ESAbstract.IsConstructor, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - _ESAbstract.IsRegExp, License: CC0 (required by "String.prototype.endsWith", "es6", "String.prototype.includes", "String.prototype.startsWith") * - _ESAbstract.IteratorClose, License: CC0 (required by "Array.from", "es6", "Map", "Set", "WeakMap", "WeakSet") - * - _ESAbstract.IteratorNext, License: CC0 (required by "Map", "es6", "Array.from", "Set", "_ESAbstract.IteratorStep", "WeakMap", "WeakSet") * - _ESAbstract.IteratorComplete, License: CC0 (required by "Map", "es6", "Array.from", "Set", "_ESAbstract.IteratorStep", "WeakMap", "WeakSet") + * - _ESAbstract.IteratorNext, License: CC0 (required by "Map", "es6", "Array.from", "Set", "_ESAbstract.IteratorStep", "WeakMap", "WeakSet") * - _ESAbstract.IteratorStep, License: CC0 (required by "Array.from", "es6", "Map", "Set", "WeakMap", "WeakSet") * - _ESAbstract.IteratorValue, License: CC0 (required by "Array.from", "es6", "Map", "Set", "WeakMap", "WeakSet") - * - _ESAbstract.CreateIterResultObject, License: CC0 (required by "Map", "es6", "Array.from", "Set") - * - _ESAbstract.SameValueNonNumber, License: CC0 (required by "_ESAbstract.SameValueZero", "Map", "es6", "Array.from", "Set", "WeakSet", "_ESAbstract.SameValue", "Object.is", "WeakMap") + * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") + * - _ESAbstract.SameValue, License: CC0 (required by "Object.is", "es6", "String.fromCodePoint", "WeakMap") * - _ESAbstract.SameValueZero, License: CC0 (required by "Map", "es6", "Array.from", "Set", "WeakSet") + * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") + * - _ESAbstract.ToString, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "Array.prototype.forEach", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.filter", "Array.prototype.map") + * - _ESAbstract.UTF16Decode, License: CC0 (required by "String.prototype.codePointAt", "es6") + * - _ESAbstract.UTF16Encoding, License: CC0 (required by "String.fromCodePoint", "es6") + * - _TypedArray, License: MIT (required by "Math.fround", "es6") + * - Object.defineProperty, License: CC0 (required by "Function.prototype.name", "es6", "Map", "Array.from", "Number.Epsilon", "Number.MAX_SAFE_INTEGER", "Number.MIN_SAFE_INTEGER", "Object.setPrototypeOf", "RegExp.prototype.flags", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Symbol", "WeakMap", "WeakSet", "_ESAbstract.CreateMethodProperty", "Array.of", "Array.prototype.copyWithin", "Array.prototype.entries", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.keys", "Array.prototype.values", "Math.acosh", "Math.asinh", "Math.atanh", "Math.cbrt", "Math.clz32", "Math.cosh", "Math.expm1", "Math.fround", "Math.hypot", "Math.imul", "Math.log10", "Math.log1p", "Math.log2", "Math.sign", "Math.sinh", "Math.tanh", "Math.trunc", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "Number.parseFloat", "Number.parseInt", "Object.assign", "Object.is", "Object.seal", "String.fromCodePoint", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "_ArrayIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_StringIterator", "_ESAbstract.CreateDataProperty", "_ESAbstract.CreateDataPropertyOrThrow", "_ESAbstract.CreateIterResultObject", "_Iterator", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator") + * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.from", "es6", "Array.of", "_ESAbstract.CreateIterResultObject", "Map", "Set") + * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - _ESAbstract.CreateIterResultObject, License: CC0 (required by "Map", "es6", "Array.from", "Set") + * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.from", "es6", "Array.of", "Array.prototype.@@iterator", "Array.prototype.copyWithin", "Array.prototype.entries", "Array.prototype.fill", "Array.prototype.find", "Array.prototype.findIndex", "Array.prototype.keys", "Array.prototype.values", "Map", "Math.acosh", "Math.asinh", "Math.atanh", "Math.cbrt", "Math.clz32", "Math.cosh", "Math.expm1", "Math.fround", "Math.hypot", "Math.imul", "Math.log10", "Math.log1p", "Math.log2", "Math.sign", "Math.sinh", "Math.tanh", "Math.trunc", "Number.isFinite", "Number.isInteger", "Number.isNaN", "Number.isSafeInteger", "Number.parseFloat", "Number.parseInt", "Object.assign", "Object.is", "Object.seal", "Object.setPrototypeOf", "Set", "String.fromCodePoint", "String.prototype.@@iterator", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith", "WeakMap", "WeakSet", "Array.isArray", "Object.create", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "_ArrayIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Object.getOwnPropertyDescriptor", "Object.keys", "Array.prototype.forEach", "Object.getPrototypeOf", "Object.getOwnPropertyNames", "Array.prototype.filter", "Array.prototype.map", "Object.freeze", "Function.prototype.bind", "Object.defineProperties", "_Iterator", "_StringIterator") * - Array.isArray, License: CC0 (required by "Map", "es6", "Array.from", "Set", "WeakMap") - * - Symbol.species, License: MIT (required by "es6", "Map", "Array.from", "Set") - * - Map, License: CC0 (required by "es6", "Array.from") - * - Set, License: CC0 (required by "es6", "Array.from") - * - Array.from, License: CC0 (required by "es6") - * - Array.of, License: CC0 (required by "es6") - * - Object.assign, License: CC0 (required by "es6", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") - * - Symbol.toStringTag, License: MIT (required by "es6", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") - * - _Iterator, License: MIT (required by "_ArrayIterator", "Array.prototype.entries", "es6", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") - * - Object.setPrototypeOf, License: MIT (required by "es6", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") - * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.@@iterator", "es6", "String.prototype.codePointAt", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.repeat", "String.prototype.startsWith") - * - _ESAbstract.IsRegExp, License: CC0 (required by "String.prototype.endsWith", "es6", "String.prototype.includes", "String.prototype.startsWith") - * - String.prototype.includes, License: CC0 (required by "es6", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator") - * - _ArrayIterator, License: MIT (required by "Array.prototype.entries", "es6", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator") - * - Array.prototype.values, License: MIT (required by "es6", "Array.prototype.@@iterator") - * - Array.prototype.@@iterator, License: CC0 (required by "es6") * - Array.prototype.copyWithin, License: MIT (required by "es6") - * - Array.prototype.entries, License: CC0 (required by "es6") * - Array.prototype.fill, License: CC0 (required by "es6") * - Array.prototype.find, License: CC0 (required by "es6") * - Array.prototype.findIndex, License: CC0 (required by "es6") - * - Array.prototype.keys, License: CC0 (required by "es6") - * - Function.name, License: MIT (required by "es6") + * - Array.prototype.forEach, License: CC0 (required by "Object.setPrototypeOf", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - Function.prototype.bind, License: MIT (required by "_ESAbstract.Construct", "Array.from", "es6", "Array.of", "Object.getOwnPropertyDescriptor", "Object.assign", "Object.setPrototypeOf", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") * - Math.acosh, License: CC0 (required by "es6") * - Math.asinh, License: CC0 (required by "es6") * - Math.atanh, License: CC0 (required by "es6") * - Math.cbrt, License: CC0 (required by "es6") - * - _ESAbstract.ToUint32, License: CC0 (required by "Math.clz32", "es6", "Math.imul") * - Math.clz32, License: CC0 (required by "es6") * - Math.cosh, License: CC0 (required by "es6") * - Math.expm1, License: CC0 (required by "es6") - * - _TypedArray, License: Copyright 2010, Linden Research, Inc. Copyright 2014, Joshua Bell. (required by "Math.fround", "es6") * - Math.fround, License: CC0 (required by "es6") * - Math.hypot, License: CC0 (required by "es6") * - Math.imul, License: CC0 (required by "es6") @@ -92,39 +65,142 @@ * - Math.sinh, License: CC0 (required by "es6") * - Math.tanh, License: CC0 (required by "es6") * - Math.trunc, License: CC0 (required by "es6") - * - Number.Epsilon, License: MIT (required by "es6") - * - Number.MAX_SAFE_INTEGER, License: MIT (required by "es6") - * - Number.MIN_SAFE_INTEGER, License: MIT (required by "es6") * - Number.isFinite, License: MIT (required by "es6") * - Number.isInteger, License: MIT (required by "es6") * - Number.isNaN, License: MIT (required by "es6") * - Number.isSafeInteger, License: MIT (required by "es6") * - Number.parseFloat, License: MIT (required by "es6") * - Number.parseInt, License: MIT (required by "es6") - * - _ESAbstract.SameValue, License: CC0 (required by "Object.is", "es6", "WeakMap") + * - Function.prototype.name, License: MIT (required by "es6") + * - Number.Epsilon, License: MIT (required by "es6") + * - Number.MAX_SAFE_INTEGER, License: MIT (required by "es6") + * - Number.MIN_SAFE_INTEGER, License: MIT (required by "es6") + * - Object.freeze, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - Object.getOwnPropertyDescriptor, License: CC0 (required by "Object.assign", "es6", "Object.setPrototypeOf", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") + * - Object.getOwnPropertyNames, License: CC0 (required by "Object.setPrototypeOf", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - Object.getPrototypeOf, License: CC0 (required by "Object.setPrototypeOf", "es6", "_ESAbstract.OrdinaryCreateFromConstructor", "Map", "Array.from", "Set", "WeakMap", "WeakSet", "_ESAbstract.Construct", "Array.of") * - Object.is, License: CC0 (required by "es6") + * - Object.keys, License: MIT (required by "Object.assign", "es6", "Symbol", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Object.defineProperties", "Object.create", "Object.setPrototypeOf", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") + * - Object.assign, License: CC0 (required by "es6", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") + * - Object.defineProperties, License: CC0 (required by "Object.create", "Map", "es6", "Array.from", "Object.setPrototypeOf", "Set", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_Iterator", "_StringIterator") + * - Object.create, License: CC0 (required by "Map", "es6", "Array.from", "Object.setPrototypeOf", "Set", "Symbol", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_StringIterator") + * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "Map", "es6", "Array.from", "Set", "WeakMap", "WeakSet", "_ESAbstract.Construct", "Array.of") + * - _ESAbstract.Construct, License: CC0 (required by "Array.from", "es6", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.filter", "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "Array.prototype.map") + * - Array.prototype.filter, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - Array.prototype.map, License: CC0 (required by "Symbol", "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables") + * - Array.of, License: CC0 (required by "es6") + * - Object.seal, License: MIT (required by "es6") + * - Object.setPrototypeOf, License: MIT (required by "es6", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") * - Promise, License: MIT (required by "es6") * - RegExp.prototype.flags, License: MIT (required by "es6") - * - _StringIterator, License: MIT (required by "String.prototype.@@iterator", "es6") - * - String.prototype.@@iterator, License: CC0 (required by "es6") - * - _ESAbstract.UTF16Decode, License: CC0 (required by "String.prototype.codePointAt", "es6") + * - String.fromCodePoint, License: MIT (required by "es6") * - String.prototype.codePointAt, License: MIT (required by "es6") * - String.prototype.endsWith, License: CC0 (required by "es6") + * - String.prototype.includes, License: CC0 (required by "es6", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator") * - String.prototype.repeat, License: CC0 (required by "es6") * - String.prototype.startsWith, License: CC0 (required by "es6") + * - Symbol, License: MIT (required by "es6", "Map", "Array.from", "Set", "Symbol.hasInstance", "Symbol.isConcatSpreadable", "Symbol.iterator", "Array.prototype.@@iterator", "String.prototype.@@iterator", "Symbol.match", "Symbol.replace", "Symbol.search", "Symbol.species", "Symbol.split", "Symbol.toPrimitive", "Symbol.toStringTag", "Symbol.unscopables", "WeakMap", "WeakSet", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") * - Symbol.hasInstance, License: MIT (required by "es6") * - Symbol.isConcatSpreadable, License: MIT (required by "es6") + * - Symbol.iterator, License: MIT (required by "es6", "Array.from", "Array.prototype.@@iterator", "Map", "Set", "String.prototype.@@iterator", "_ESAbstract.GetIterator", "WeakMap", "WeakSet", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "_StringIterator") + * - _ESAbstract.GetIterator, License: CC0 (required by "Array.from", "es6", "Map", "Set", "WeakMap", "WeakSet") * - Symbol.match, License: MIT (required by "es6") * - Symbol.replace, License: MIT (required by "es6") * - Symbol.search, License: MIT (required by "es6") + * - Symbol.species, License: MIT (required by "es6", "Map", "Array.from", "Set") + * - Map, License: CC0 (required by "es6", "Array.from") + * - Set, License: CC0 (required by "es6", "Array.from") + * - Array.from, License: CC0 (required by "es6") * - Symbol.split, License: MIT (required by "es6") * - Symbol.toPrimitive, License: MIT (required by "es6") + * - Symbol.toStringTag, License: MIT (required by "es6", "_Iterator", "_ArrayIterator", "Array.prototype.entries", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") + * - _Iterator, License: MIT (required by "_ArrayIterator", "Array.prototype.entries", "es6", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator", "_StringIterator", "String.prototype.@@iterator") + * - _ArrayIterator, License: MIT (required by "Array.prototype.entries", "es6", "Array.prototype.keys", "Array.prototype.values", "Array.prototype.@@iterator") + * - Array.prototype.entries, License: CC0 (required by "es6") + * - Array.prototype.keys, License: CC0 (required by "es6") + * - Array.prototype.values, License: MIT (required by "es6", "Array.prototype.@@iterator") + * - Array.prototype.@@iterator, License: CC0 (required by "es6") + * - _StringIterator, License: MIT (required by "String.prototype.@@iterator", "es6") + * - String.prototype.@@iterator, License: CC0 (required by "es6") * - Symbol.unscopables, License: MIT (required by "es6") - * - WeakMap, License: CC0 (required by "es6") - * - WeakSet, License: CC0 (required by "es6") */ + * - WeakMap, License: MIT (required by "es6") + * - WeakSet, License: MIT (required by "es6") */ (function(undefined) { +// _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.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.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.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.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.IsCallable // 7.2.3. IsCallable ( argument ) function IsCallable(argument) { // eslint-disable-line no-unused-vars @@ -135,102 +211,105 @@ function IsCallable(argument) { // eslint-disable-line no-unused-vars // 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'; } -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) { +// _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; +} - 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'; +// _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 - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty. - Object['defineProperty'] = function defineProperty(object, property, descriptor) { + // Polyfill.io - We can skip all above steps because the === operator does it all for us. + return x === y; +} - // 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.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.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.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.ToNumber +// 7.1.3. ToNumber ( argument ) +function ToNumber(argument) { // eslint-disable-line no-unused-vars + return Number(argument); } // _ESAbstract.ToObject @@ -287,67 +366,21 @@ function GetMethod(V, P) { // eslint-disable-line no-unused-vars return func; } -// _ESAbstract.ToInteger -// 7.1.4. ToInteger ( argument ) -function ToInteger(argument) { // eslint-disable-line no-unused-vars +// _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, 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) { + // 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. 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.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.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); + // 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; } // _ESAbstract.Type @@ -373,5476 +406,5808 @@ function Type(x) { // eslint-disable-line no-unused-vars } } -// _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; - } - } +// _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; } - // 6. Throw a TypeError exception. - throw new TypeError('Cannot convert to primitive.'); + // 5. Return proto. + return proto; } -// _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); +// _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; } - // 3. Return input - return input; -} + // 2. If argument has a [[Construct]] internal method, return true. + // 3. Return false. -// _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); - } + // 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; } -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'); +// _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; } - // 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; + // 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); } - // 7. Return undefined. - return undefined; -}); - + // 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; } +// _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. -// _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. + // 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; +} - // 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.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.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; +// _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 length>2^32-1, throw a RangeError exception. - if (length > (Math.pow(2, 32) - 1)) { - throw new RangeError('Invalid array length'); + // 3. If Type(result) is not Object, throw a TypeError exception. + if (Type(result) !== 'object') { + throw new TypeError('bad iterator'); } - // 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; + // 4. Return result. + return result; } -// _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') { +// _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; } - // 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; + // 4. Return result. + return result; } -// _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; +// _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.'); } - // 5. Return proto. - return proto; + // Return ? Get(iterResult, "value"). + return Get(iterResult, "value"); } -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; +// _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.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; - }()); - var equalsConstructorPrototypeIfNotBuggy = function (o) { - /* global window */ - if (typeof window === 'undefined' || !hasAutomationEqualityBug) { - return equalsConstructorPrototype(o); + } + // 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; } - try { - return equalsConstructorPrototype(o); - } catch (e) { + // 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; } - }; - - 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]'; + // d. If x is the same Number value as y, return true. + if (x === y) { + return true; } - return isArgs; + // e. Return false. + return false; } + // 3. Return SameValueNonNumber(x, y). + return SameValueNonNumber(x, y); +} - 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'); +// _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; } - - 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)); - } + // b. If x is +0 and y is -0, return true. + if (1/x === Infinity && 1/y === -Infinity) { + return true; } - - 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)); - } - } + // 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 (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]); - } +// _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.'); } - return theKeys; - }; -}()); - + // 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; } -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); +// _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); } - // 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)) - ); +// _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; +} - } +// _ESAbstract.UTF16Encoding +// 10.1.1. Static Semantics: UTF16Encoding ( cp ) +function UTF16Encoding(cp) { // eslint-disable-line no-unused-vars + // 1. Assert: 0 ≤ cp ≤ 0x10FFFF. + // 2. If cp ≤ 0xFFFF, return cp. + if (cp <= 0xFFFF) { + return cp; + } else { + // 3. Let cu1 be floor((cp - 0x10000) / 0x400) + 0xD800. + var cu1 = Math.floor((cp - 0x10000) / 0x400) + 0xD800; + // 4. Let cu2 be ((cp - 0x10000) modulo 0x400) + 0xDC00. + var cu2 = ((cp - 0x10000) % 0x400) + 0xDC00; + // 5. Return the code unit sequence consisting of cu1 followed by cu2. + return [cu1, cu2]; + } +} - }; +// _TypedArray +/* + Copyright (c) 2010, Linden Research, Inc. + Copyright (c) 2014, Joshua Bell - // 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. + 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: - var boundLength = max(0, target.length - args.length); + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. - // 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); - } + 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$ + */ - // 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); +// Original can be found at: +// https://bitbucket.org/lindenlab/llsd +// Modifications by Joshua Bell inexorabletash@gmail.com +// https://github.com/inexorabletash/polyfill - if (target.prototype) { - Empty.prototype = target.prototype; - bound.prototype = new Empty(); - // Clean up dangling references. - Empty.prototype = null; - } +// 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 - // TODO - // 18. Set the [[Extensible]] internal property of F to true. + // 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; - // 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. + // 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'; + } + } - // 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. + // 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; } - // 22. Return F. - return bound; -}); + // 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) -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 - } -}()))) { + (function() { + var orig = Object.defineProperty; + var dom_only = !(function(){try{return Object.defineProperty({},'x',{});}catch(_){return false;}}()); -// Object.getOwnPropertyDescriptor -/* global CreateMethodProperty */ -(function () { - var call = Function.prototype.call; - var prototypeOfObject = Object.prototype; - var owns = call.bind(prototypeOfObject.hasOwnProperty); + 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; + }; + } + }()); - 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; - } - } + // 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 (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) { - var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: "; + if (obj.length > MAX_ARRAY_LENGTH) throw RangeError('Array too large for polyfill'); - CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(object, property) { - if ((typeof object != "object" && typeof object != "function") || object === null) { - throw new TypeError(ERR_NON_OBJECT + object); - } + function makeArrayAccessor(index) { + Object.defineProperty(obj, index, { + 'get': function() { return obj._getter(index); }, + 'set': function(v) { obj._setter(index, v); }, + enumerable: true, + configurable: false + }); + } - // 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 - } - } + var i; + for (i = 0; i < obj.length; i += 1) { + makeArrayAccessor(i); + } + } - // If object does not owns property return undefined immediately. - if (!owns(object, property)) { - return; - } + // Internal conversion functions: + // pack() - take a number (interpreted as Type), output a byte array + // unpack() - take a byte array, output a Type-like number - // If object has a property then it's for sure both `enumerable` and - // `configurable`. - var descriptor = { enumerable: true, configurable: true }; + 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; } - // 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; + function packI8(n) { return [n & 0xff]; } + function unpackI8(bytes) { return as_signed(bytes[0], 8); } - var getter = lookupGetter(object, property); - var setter = lookupSetter(object, property); + function packU8(n) { return [n & 0xff]; } + function unpackU8(bytes) { return as_unsigned(bytes[0], 8); } - // Once we have getter and setter we can put values back. - object.__proto__ = prototype; + function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; } - 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; - } - } + function packI16(n) { return [n & 0xff, (n >> 8) & 0xff]; } + function unpackI16(bytes) { return as_signed(bytes[1] << 8 | bytes[0], 16); } - // 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; - }); - } -}()); + 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); } -if (!('defineProperties' in Object)) { + 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); } -// 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; -}); + function packIEEE754(v, ebits, fbits) { -} + var bias = (1 << (ebits - 1)) - 1; -if (!('create' in Object)) { + 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; + } -// 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); + // 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); - obj.constructor.prototype = O; + 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)); + } + } - // 3. If Properties is not undefined, then - if (1 in arguments) { - // a. Return ? ObjectDefineProperties(obj, Properties). - return Object.defineProperties(obj, properties); - } + // 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(''); - return obj; -}); + // 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; -if (!('getPrototypeOf' in Object)) { + 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(''); -// Object.getPrototypeOf -/* global CreateMethodProperty */ -// Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js + // 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); -// 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; - } -}); + // 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 + // -// _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. + (function() { - // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). - var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto); + 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)}); - // 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; -} + for (var i = 0; i < length; i += 1) + this._bytes[i] = 0; + } -// _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; + global.ArrayBuffer = global.ArrayBuffer || ArrayBuffer; - // 2. If argumentsList is not present, set argumentsList to a new empty List. - var argumentsList = arguments.length > 1 ? arguments[1] : []; + // + // 5 The Typed Array View Types + // - // 3. Assert: IsConstructor(F) is true. - if (!IsConstructor(F)) { - throw new TypeError('F must be a constructor.'); - } + function $TypedArray$() { - // 4. Assert: IsConstructor(newTarget) is true. - if (!IsConstructor(newTarget)) { - throw new TypeError('newTarget must be a constructor.'); - } + // %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}); - // 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); - } -} + }).apply(this, arguments); + } -// _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; - } + // %TypedArray% ( typedArray ) + if (arguments.length >= 1 && + Type(arguments[0]) === 'object' && + arguments[0] instanceof $TypedArray$) { + return (function(typedArray){ + if (this.constructor !== typedArray.constructor) throw TypeError(); - // 3. Let isArray be ? IsArray(originalArray). - var isArray = IsArray(originalArray); + 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}); - // 4. If isArray is false, return ? ArrayCreate(length). - if (isArray === false) { - return ArrayCreate(length); - } + for (var i = 0; i < this.length; i += 1) + this._setter(i, typedArray._getter(i)); - // 5. Let C be ? Get(originalArray, "constructor"). - var C = Get(originalArray, 'constructor'); + }).apply(this, arguments); + } - // 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]); -} + // %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) { -// _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); -} + 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}); -// _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)) { + for (var i = 0; i < this.length; i += 1) { + var s = array[i]; + this._setter(i, Number(s)); + } + }).apply(this, arguments); + } -// 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; - } + // %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) { - } - // d. Increase k by 1. - k = k + 1; - } - // 9. Return A. - return A; -}); + 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 (!('map' in Array.prototype)) { + 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; -// 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; -}); + } 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'); -if (!('getOwnPropertyNames' in Object)) { + Object.defineProperty(this, 'buffer', {value: buffer}); + Object.defineProperty(this, 'byteLength', {value: byteLength}); + Object.defineProperty(this, 'byteOffset', {value: byteOffset}); + Object.defineProperty(this, 'length', {value: length}); -// Object.getOwnPropertyNames -/* global CreateMethodProperty */ + }).apply(this, arguments); + } -var toString = ({}).toString; -var split = ''.split; + // %TypedArray% ( all other argument combinations ) + throw TypeError(); + } -CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) { - var buffer = []; - var key; + // Properties of the %TypedArray Instrinsic Object - // 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"]; + // %TypedArray%.from ( source , mapfn=undefined, thisArg=undefined ) + Object.defineProperty($TypedArray$, 'from', {value: function(iterable) { + return new this(iterable); + }}); - if (typeof object === 'undefined' || object === null) { - throw new TypeError('Cannot convert undefined or null to object'); - } + // %TypedArray%.of ( ...items ) + Object.defineProperty($TypedArray$, 'of', {value: function(/*...items*/) { + return new this(arguments); + }}); - // 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); + // %TypedArray%.prototype + var $TypedArrayPrototype$ = {}; + $TypedArray$.prototype = $TypedArrayPrototype$; - // Enumerable properties only - for (key in object) { - if (Object.prototype.hasOwnProperty.call(object, key)) { - buffer.push(key); - } - } + // WebIDL: getter type (unsigned long index); + Object.defineProperty($TypedArray$.prototype, '_getter', {value: function(index) { + if (arguments.length < 1) throw SyntaxError('Not enough arguments'); - // Check for and add the common non-enumerable properties - for (var i=0, s=commonProps.length; i= this.length) + return undefined; - return buffer; -}); + 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}); -if (!('freeze' in Object)) { + // 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'); -// 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; -}); + 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]; + } + }}); -if (!('Symbol' in this && this.Symbol.length === 0)) { + // get %TypedArray%.prototype.buffer + // get %TypedArray%.prototype.byteLength + // get %TypedArray%.prototype.byteOffset + // -- applied directly to the object in the constructor -// Symbol -// A modification of https://github.com/WebReflection/get-own-property-symbols -// (C) Andrea Giammarchi - MIT Licensed + // %TypedArray%.prototype.constructor + Object.defineProperty($TypedArray$.prototype, 'constructor', {value: $TypedArray$}); -(function (Object, GOPS, global) { + // %TypedArray%.prototype.copyWithin (target, start, end = this.length ) + Object.defineProperty($TypedArray$.prototype, 'copyWithin', {value: function(target, start) { + var end = arguments[2]; - var setDescriptor; - var id = 0; - var random = '' + Math.random(); - var prefix = '__\x01symbol:'; - var prefixLength = prefix.length; - var internalSymbol = '__\x01symbol@@' + random; - var DP = 'defineProperty'; - var DPies = 'defineProperties'; - var GOPN = 'getOwnPropertyNames'; - var GOPD = 'getOwnPropertyDescriptor'; - var PIE = 'propertyIsEnumerable'; - var ObjectProto = Object.prototype; - var hOP = ObjectProto.hasOwnProperty; - var pIE = ObjectProto[PIE]; - var toString = ObjectProto.toString; - var concat = Array.prototype.concat; - var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : []; - var nGOPN = Object[GOPN]; - var gOPN = function getOwnPropertyNames (obj) { - if (toString.call(obj) === '[object Window]') { - try { - return nGOPN(obj); - } catch (e) { - // IE bug where layout engine calls userland gOPN for cross-domain `window` objects - return concat.call([], cachedWindowNames); - } - } - return nGOPN(obj); - }; - var gOPD = Object[GOPD]; - var create = Object.create; - var keys = Object.keys; - var freeze = Object.freeze || Object; - var defineProperty = Object[DP]; - var $defineProperties = Object[DPies]; - var descriptor = gOPD(Object, GOPN); - var addInternalIfNeeded = function (o, uid, enumerable) { - if (!hOP.call(o, internalSymbol)) { - try { - defineProperty(o, internalSymbol, { - enumerable: false, - configurable: false, - writable: false, - value: {} - }); - } catch (e) { - o[internalSymbol] = {}; - } - } - o[internalSymbol]['@@' + uid] = enumerable; - }; - var createWithSymbols = function (proto, descriptors) { - var self = create(proto); - gOPN(descriptors).forEach(function (key) { - if (propertyIsEnumerable.call(descriptors, key)) { - $defineProperty(self, key, descriptors[key]); - } - }); - return self; - }; - var copyAsNonEnumerable = function (descriptor) { - var newDescriptor = create(descriptor); - newDescriptor.enumerable = false; - return newDescriptor; - }; - var get = function get(){}; - var onlyNonSymbols = function (name) { - return name != internalSymbol && - !hOP.call(source, name); - }; - var onlySymbols = function (name) { - return name != internalSymbol && - hOP.call(source, name); - }; - var propertyIsEnumerable = function propertyIsEnumerable(key) { - var uid = '' + key; - return onlySymbols(uid) ? ( - hOP.call(this, uid) && - this[internalSymbol]['@@' + uid] - ) : pIE.call(this, key); - }; - var setAndGetSymbol = function (uid) { - var descriptor = { - enumerable: false, - configurable: true, - get: get, - set: function (value) { - setDescriptor(this, uid, { - enumerable: false, - configurable: true, - writable: true, - value: value - }); - addInternalIfNeeded(this, uid, true); - } - }; - try { - defineProperty(ObjectProto, uid, descriptor); - } catch (e) { - ObjectProto[uid] = descriptor.value; - } - return freeze(source[uid] = defineProperty( - Object(uid), - 'constructor', - sourceConstructor - )); - }; - var Symbol = function Symbol() { - var description = arguments[0]; - if (this instanceof Symbol) { - throw new TypeError('Symbol is not a constructor'); - } - return setAndGetSymbol( - prefix.concat(description || '', random, ++id) - ); - }; - var source = create(null); - var sourceConstructor = {value: Symbol}; - var sourceMap = function (uid) { - return source[uid]; - }; - var $defineProperty = function defineProp(o, key, descriptor) { - var uid = '' + key; - if (onlySymbols(uid)) { - setDescriptor(o, uid, descriptor.enumerable ? - copyAsNonEnumerable(descriptor) : descriptor); - addInternalIfNeeded(o, uid, !!descriptor.enumerable); - } else { - defineProperty(o, key, descriptor); - } - return o; - }; + 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; + }}); - var onlyInternalSymbols = function (obj) { - return function (name) { - return hOP.call(obj, internalSymbol) && hOP.call(obj[internalSymbol], '@@' + name); - }; - }; - var $getOwnPropertySymbols = function getOwnPropertySymbols(o) { - return gOPN(o).filter(o === ObjectProto ? onlyInternalSymbols(o) : onlySymbols).map(sourceMap); - } - ; + // %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; } - descriptor.value = $defineProperty; - defineProperty(Object, DP, descriptor); + start = ToInt32(start); + end = ToInt32(end); - descriptor.value = $getOwnPropertySymbols; - defineProperty(Object, GOPS, descriptor); + if (arguments.length < 1) { start = 0; } + if (arguments.length < 2) { end = this.length; } - descriptor.value = function getOwnPropertyNames(o) { - return gOPN(o).filter(onlyNonSymbols); - }; - defineProperty(Object, GOPN, descriptor); + if (start < 0) { start = this.length + start; } + if (end < 0) { end = this.length + end; } - descriptor.value = function defineProperties(o, descriptors) { - var symbols = $getOwnPropertySymbols(descriptors); - if (symbols.length) { - keys(descriptors).concat(symbols).forEach(function (uid) { - if (propertyIsEnumerable.call(descriptors, uid)) { - $defineProperty(o, uid, descriptors[uid]); - } - }); - } else { - $defineProperties(o, descriptors); - } - return o; - }; - defineProperty(Object, DPies, descriptor); + start = clamp(start, 0, this.length); + end = clamp(end, 0, this.length); - descriptor.value = propertyIsEnumerable; - defineProperty(ObjectProto, PIE, descriptor); + var len = end - start; + if (len < 0) { + len = 0; + } - descriptor.value = Symbol; - defineProperty(global, 'Symbol', descriptor); + return new this.constructor( + this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len); + }}); - // defining `Symbol.for(key)` - descriptor.value = function (key) { - var uid = prefix.concat(prefix, key, random); - return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid); - }; - defineProperty(Symbol, 'for', descriptor); + // %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 - // defining `Symbol.keyFor(symbol)` - descriptor.value = function (symbol) { - if (onlyNonSymbols(symbol)) - throw new TypeError(symbol + ' is not a symbol'); - return hOP.call(source, symbol) ? - symbol.slice(prefixLength * 2, -random.length) : - void 0 - ; - }; - defineProperty(Symbol, 'keyFor', descriptor); + 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; + } - descriptor.value = function getOwnPropertyDescriptor(o, key) { - var descriptor = gOPD(o, key); - if (descriptor && onlySymbols(key)) { - descriptor.enumerable = propertyIsEnumerable.call(o, key); - } - return descriptor; - }; - defineProperty(Object, GOPD, descriptor); + TypedArray.BYTES_PER_ELEMENT = elementSize; - descriptor.value = function (proto, descriptors) { - return arguments.length === 1 || typeof descriptors === "undefined" ? - create(proto) : - createWithSymbols(proto, descriptors); - }; - defineProperty(Object, 'create', descriptor); + var TypedArrayPrototype = function() {}; + TypedArrayPrototype.prototype = $TypedArrayPrototype$; - descriptor.value = function () { - var str = toString.call(this); - return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str; - }; - defineProperty(ObjectProto, 'toString', descriptor); + 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}); - setDescriptor = function (o, key, descriptor) { - var protoDescriptor = gOPD(ObjectProto, key); - delete ObjectProto[key]; - defineProperty(o, key, descriptor); - if (o !== ObjectProto) { - defineProperty(ObjectProto, key, protoDescriptor); - } - }; + return TypedArray; + } -}(Object, 'getOwnPropertySymbols', this)); + 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; + }()); -if (!('Symbol' in this && 'iterator' in this.Symbol)) { + // + // 6 The DataView View Type + // -// Symbol.iterator -/* global Symbol */ -Object.defineProperty(Symbol, 'iterator', { value: Symbol('iterator') }); + (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(); -// _ESAbstract.GetIterator -/* global GetMethod, Symbol, Call, Type, GetV */ -// 7.4.1. GetIterator ( obj [ , method ] ) -// The abstract operation GetIterator with argument obj and optional argument method performs the following steps: -function GetIterator(obj /*, method */) { // eslint-disable-line no-unused-vars - // 1. If method is not present, then - // a. Set method to ? GetMethod(obj, @@iterator). - var method = arguments.length > 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; -} + byteOffset = ToUint32(byteOffset); + if (byteOffset > buffer.byteLength) + throw RangeError('byteOffset out of range'); -// _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. + if (byteLength === undefined) + byteLength = buffer.byteLength - byteOffset; + else + byteLength = ToUint32(byteLength); - // 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; -} + 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 -// _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; -} + function makeGetter(arrayType) { + return function GetViewValue(byteOffset, littleEndian) { + byteOffset = ToUint32(byteOffset); -// _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")); -} + if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) + throw RangeError('Array index out of range'); -// _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; -} + byteOffset += this.byteOffset; -// _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"); -} + 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)); -// _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; -} + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) + bytes.reverse(); -// _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. + return r(new arrayType(new Uint8Array(bytes).buffer), 0); + }; + } - // Polyfill.io - We can skip all above steps because the === operator does it all for us. - return x === y; -} + 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)}); -// _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)) { + 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'); -// 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); -}); + // 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)); -if (!('Symbol' in this && 'species' in this.Symbol)) { + // Flip if necessary + if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) + bytes.reverse(); -// Symbol.species -/* global Symbol */ -Object.defineProperty(Symbol, 'species', { value: Symbol('species') }); + // 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)}); -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; - } -}()))) { + global.DataView = global.DataView || DataView; -// 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 - }); +}(self)); +if (!("defineProperty"in Object&&function(){try{var e={} +return Object.defineProperty(e,"test",{value:42}),!0}catch(t){return!1}}() +)) { - // 3. Set map.[[MapData]] to a new empty List. - // Polyfill.io - This step was done as part of step two. +// Object.defineProperty +(function (nativeDefineProperty) { - // 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 - }); + 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'); } - // 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; + if (!(descriptor instanceof Object)) { + throw new TypeError('Property description must be an object'); } - // 6. Let adder be ? Get(map, "set"). - var adder = map.set; + 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; - // 7. If IsCallable(adder) is false, throw a TypeError exception. - if (!IsCallable(adder)) { - throw new TypeError("Map.prototype.set is not a function"); + // 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; } - // 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); - } + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter must be a function'); } - } 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]); - } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); } + Object.__defineSetter__.call(object, propertyString, descriptor.set); } - return map; + + // 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)); - // 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); + +// _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; } +} - // 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; - } - ); +// _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; +} - // 23.1.3.2. Map.prototype.constructor - CreateMethodProperty(Map.prototype, 'constructor', Map); +// _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; +} - // 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; - } - ); +// _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); +} +if (!("isArray"in Array +)) { - // 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'); - } - ); +// 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); +}); - // 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; - }); +if (!("copyWithin"in Array.prototype&&function(){try{var t=function n(){} +t.prototype[0]="foo" +var o=new t +o[1]=1,o[2]=2,o.length=3 +var r=Array.prototype.copyWithin.call(o,1,0) +return!(!r[0]||Object.prototype.hasOwnProperty.call(r,"0")||!Object.prototype.hasOwnProperty.call(r,"1")||"foo"!==r[0]||"foo"!==r[1]||1!==r[2]||3!==r.length)}catch(e){return!1}}() +)) { - // 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; - }); +// 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]; - // 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"); - }); + // 22.1.3.3.1 Let O be ? ToObject(this value). + if (this === null || this === undefined) { + throw new TypeError('Cannot call method on ' + this); + } - // 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; - }); + var o = Object(this); - // 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 - }); + // 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); - // 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'); - } - ); + // 22.1.3.3.3 Let relativeTarget be ? ToInteger(target). + var relativeTarget = ToInteger(target); - // 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); + // 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); + } - // 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 }. + // 22.1.3.3.5 Let relativeStart be ? ToInteger(start). + var relativeStart = ToInteger(start); - // 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' - }); + // 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); } - // 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; - } + // 22.1.3.3.9 Let count be min(final-from, len-to). + var count = Math.min(final - from, len - to); - // 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 - }); + // 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]; } - ); - - // 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; + // 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; } -}(this)); + // 22.1.3.3.13 Return O. + return o; +}); } -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; +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; +}); -// 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; +} + +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; +}); - // 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. +if (!("findIndex"in Array.prototype +)) { - // 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 - }); +// 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; +}); - // 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"); - } +if (!("forEach"in Array.prototype +)) { - 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]); - } - } +// 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]); } - 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); + // d. Increase k by 1. + k = k + 1; } + // 7. Return undefined. + return undefined; +}); - // 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; - }); +if (!("bind"in Function.prototype +)) { - // 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; - }); +// 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 - // 23.2.3.3. Set.prototype.constructor - CreateMethodProperty(Set.prototype, 'constructor', Set); + // 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 () { - // 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; + 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. - this._size = --this._size; - if (!supportsGetters) { - this.size = this._size; - } - // ii. Return true. - return true; - } + var result = target.apply( + this, + array_concat.call(args, array_slice.call(arguments)) + ); + if ($Object(result) === result) { + return result; } - // 6. Return false. - return false; - } - ); + return this; - // 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'); - } - ); + } 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. - // 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; - } - ); + // equiv: target.call(this, ...boundArgs, ...args) + return target.apply( + that, + array_concat.call(args, array_slice.call(arguments)) + ); - // 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); + // 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. - // 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 - }); + 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; } - // 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); + // 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; +}); - // 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' - }); +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)); +}); - // 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; +} + +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)); +}); - // 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); - }); +if (!("atanh"in Math +)) { - // 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 }. +// 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; +}); - 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; +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; +}); -}(this)); +} + +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 (!('from' in Array && (function () { - try { - Array.from({ length: -Infinity }); +if (!("cosh"in Math +)) { - return true; - } catch (e) { - return false; +// 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; } -}()))) { - -// 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]'; + // If x is +0, the result is 1. + if (x === 0 && 1/x === Infinity) { + return 1; } - - // 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 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 (!('of' in Array)) { +if (!("expm1"in Math +)) { -// 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, +// 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 { - // a. Let A be ? ArrayCreate(len). - var A = ArrayCreate(len); + return Math.exp(x) - 1; } - // 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; +}); + +} + +if (!("fround"in Math +)) { +// Math.fround +/* global Float32Array, CreateMethodProperty */ +// 20.2.2.17 Math.fround ( x ) +CreateMethodProperty(Math, 'fround', function (x) { + // 1. If x is NaN, return NaN. + if (isNaN(x)) { + return NaN; } - // 8. Perform ? Set(A, "length", len, true) - A["length"] = len; - // 9. Return A. - return A; + // 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 (!('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); +if (!("hypot"in Math +)) { - // 2. If only one argument was passed, return to. - if (arguments.length === 1) { - return to; +// 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; + } - // 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); + // If any argument is -∞, the result is +∞. + if (arguments[i] === -Infinity) { + return Infinity; } - // 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; - } + // 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); } } - // 5. Return to. - return to; + + return max * Math.sqrt(y); }); } -if (!('Symbol' in this && 'toStringTag' in this.Symbol)) { +if (!("imul"in Math +)) { -// Symbol.toStringTag -/* global Symbol */ -Object.defineProperty(Symbol, 'toStringTag', { - value: Symbol('toStringTag') +// 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); + var UINT16 = 0xffff; + var aHigh = a >>> 16 & UINT16; + var aLow = UINT16 & a; + var bHigh = b >>> 16 & UINT16; + var bLow = UINT16 & b; + // the shift by 0 fixes the sign on the high part + // the final |0 converts the unsigned value into a signed value + return aLow * bLow + (aHigh * bLow + aLow * bHigh << 16 >>> 0) | 0; }); - } +if (!("log10"in Math +)) { -// _Iterator -/* global Symbol */ -// A modification of https://github.com/medikoo/es6-iterator -// Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com) +// Math.log10 +/* global CreateMethodProperty */ +// 20.2.2.22. Math.log10 ( x ) +CreateMethodProperty(Math, 'log10', function log10(x) { + return Math.log(x) / Math.LN10; +}); -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); +if (!("log1p"in Math +)) { + +// Math.log1p +/* global CreateMethodProperty */ +// 20.2.2.21. Math.log1p ( x ) +CreateMethodProperty(Math, 'log1p', function log1p(x) { + x = Number(x); + if (-1 < x && x < 1) { + // Polyfill.io - For numbers in the range −1 < x < 1 + // Because we are using log, the precision of the result will be identical to log(1). + // To fix this we avoid using log and use the Taylor Series expansion of log. + // This series converges when |x| < 1. As we can not sum to infinity, + // we instead sum the first 300 parts of the series to give a close approximation. + // |x|<1, log(1+x) = x - x^2/2 + x^3/3 - ... + (-1)^(n-1)*x^n/n + ... + var y = x; + for (var i = 2; i <= 300; i++) { + y += Math.pow((-1), (i - 1)) * Math.pow(x, i) / i; } - 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)); - }; + return y; + } - 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 + 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; } - }, { - _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 + 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; +}); - 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; -}()); +if (!("tanh"in Math +)) { -// Object.setPrototypeOf +// Math.tanh /* 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/ +// 20.2.2.34. Math.tanh ( x ) +CreateMethodProperty(Math, 'tanh', function tanh(x) { + var y; - // 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. + 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 (!("isFinite"in Number +)) { + +// Number.isFinite +/* global CreateMethodProperty, Type */ (function () { - if (Object.setPrototypeOf) { return; } + 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); + }); +}()); - /*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; +if (!("isInteger"in Number +)) { - 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); - } - }; - } +// 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; } - } - CreateMethodProperty(Object, 'setPrototypeOf', sPOf); + // 2. If number is NaN, return true. + if (that.isNaN(number)) { + return true; + } + // 3. Otherwise, return false. + return false; + }); }()); -// _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') { +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. 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); + // 2. If number is NaN, +∞, or -∞, return false. + if (isNaN(number) || number === Infinity || number === -Infinity) { + return false; } - // 4. If argument has a [[RegExpMatcher]] internal slot, return true. - try { - var lastIndex = argument.lastIndex; - argument.lastIndex = 0; - RegExp.prototype.exec.call(argument); + // 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; - } catch (e) {} finally { - argument.lastIndex = lastIndex; } - // 5. Return false. + // 6. Otherwise, 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; -}); +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 +)) { -// _ArrayIterator -/* global Iterator */ -// A modification of https://github.com/medikoo/es6-iterator -// Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com) +// 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); -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 (!("name"in Function.prototype&&"x"===function x(){}.name +)) { + +// Function.prototype.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 || ''; }; - 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 + + 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; }, - toString: { - value: function() { - return '[object Array Iterator]'; - }, - configurable: true, - enumerable: false, - writable: true - } + configurable: 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 (!("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 (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype[Symbol.iterator])) { +if (!("freeze"in Object +)) { -// 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); +// 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 (!('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); - } +if (!("getOwnPropertyDescriptor"in Object&&"function"==typeof Object.getOwnPropertyDescriptor&&function(){try{var t={} +return t.test=0,0===Object.getOwnPropertyDescriptor(t,"test").value}catch(e){return!1}}() +)) { - // 22.1.3.3.5 Let relativeStart be ? ToInteger(start). - var relativeStart = ToInteger(start); +// Object.getOwnPropertyDescriptor +/* global CreateMethodProperty */ +(function () { + var call = Function.prototype.call; + var prototypeOfObject = Object.prototype; + var owns = call.bind(prototypeOfObject.hasOwnProperty); - // 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); + var lookupGetter; + var lookupSetter; + var supportsAccessors; + if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { + lookupGetter = call.bind(prototypeOfObject.__lookupGetter__); + lookupSetter = call.bind(prototypeOfObject.__lookupSetter__); } - - // 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); + function doesGetOwnPropertyDescriptorWork(object) { + try { + object.sentinel = 0; + return Object.getOwnPropertyDescriptor( + object, + "sentinel" + ).value === 0; + } catch (exception) { + // returns falsy + } } - - // 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); + // 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; + } } - // 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 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 (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype.entries)) { + // 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; -// 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'); -}); + 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 (!('fill' in Array.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; + } + } -// 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; + // 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; + }); } - // 8. Return O. - return O; -}); +}()); } -if (!('find' in Array.prototype)) { +if (!("getOwnPropertyNames"in Object +)) { -// 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'); +// 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'); } - // 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; + + // 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); } - // e. Increase k by 1. - var k = k + 1; } - // 7. Return undefined. - return undefined; + + // Check for and add the common non-enumerable properties + for (var i=0, s=commonProps.length; i 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; + 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; } - // 7. Return -1. - return -1; }); } -if (!('Symbol' in this && 'iterator' in this.Symbol && !!Array.prototype.keys)) { +if (!("is"in Object +)) { -// 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'); +// 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 (!('name' in Function.prototype && (function x() {}).name === 'x')) { - -// Function.name -(function () { +if (!("keys"in Object&&function(){return 2===Object.keys(arguments).length}(1,2)&&function(){try{return Object.keys(""),!0}catch(t){return!1}}() +)) { - var - accessorName = 'name', - fnNameMatchRegex = /^\s*function\s+([^\(\s]*)\s*/, - $Function = Function, - FunctionName = 'Function', - FunctionProto = $Function.prototype, - FunctionProtoCtor = FunctionProto.constructor, +// Object.keys +/* global CreateMethodProperty */ +CreateMethodProperty(Object, "keys", (function() { + 'use strict'; - getFunctionName = function(fn) { - var match, name; + // modified from https://github.com/es-shims/object-keys - if (fn === $Function || fn === FunctionProtoCtor) { - name = FunctionName; + 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; + } } - else if (fn !== FunctionProto) { - match = ('' + fn).match(fnNameMatchRegex); - name = match && match[1]; + return false; + }()); + var equalsConstructorPrototypeIfNotBuggy = function (o) { + /* global window */ + if (typeof window === 'undefined' || !hasAutomationEqualityBug) { + return equalsConstructorPrototype(o); + } + try { + return equalsConstructorPrototype(o); + } catch (e) { + return false; } - return name || ''; }; + 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; + } - 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 - }); - -}()); - -} + 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 (!('acosh' in Math)) { + if (object === undefined || object === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } -// 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)); -}); + 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 (!('asinh' in Math)) { + if (hasDontEnumBug) { + var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); -// 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)); -}); + 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 (!('atanh' in Math)) { +if (!("assign"in Object +)) { -// 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; +// 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; } - return Math.log((1 + x) / (1 - x)) / 2; -}); -} + // 3. Let sources be the List of argument values starting with the second argument + var sources = Array.prototype.slice.call(arguments, 1); -if (!('cbrt' in Math)) { + // 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); + } -// 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; + // c. For each element nextKey of keys in List order, do + for (index2 = 0; index2 < keys.length; index2++) { + var nextKey = keys[index2]; + var enumerable; + try { + // 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 + enumerable = desc !== undefined && desc.enumerable === true; + } catch (e) { + // Polyfill.io - We use Object.prototype.propertyIsEnumerable as a fallback + // because `Object.getOwnPropertyDescriptor(window.location, 'hash')` causes Internet Explorer 11 to crash. + enumerable = Object.prototype.propertyIsEnumerable.call(from, nextKey); + } + if (enumerable) { + // 1. Let propValue be ? Get(from, nextKey). + var propValue = Get(from, nextKey); + // 2. Perform ? Set(to, nextKey, propValue, true). + to[nextKey] = propValue; + } + } } - var y = Math.pow(Math.abs(x), 1 / 3); - return x < 0 ? -y : y; + // 5. Return to. + return to; }); } +if (!("defineProperties"in Object +)) { -// _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; +// 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'); } - // 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; + // 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 (!('cosh' in Math)) { +if (!("create"in Object +)) { -// 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; +// 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'); } - x = Math.abs(x); - if (x > 709) { - var y = Math.exp(0.5 * x); - return y / 2 * y; + // 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); } - var y = Math.exp(x); - return (y + 1 / y) / 2; + + return obj; }); } -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; - } +// _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. - if (x > -1e-6 && x < 1e-6) { - return x + x * x / 2; - } else { - return Math.exp(x) - 1; - } -}); + // 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; -// _TypedArray -/* - Copyright (c) 2010, Linden Research, Inc. - Copyright (c) 2014, Joshua Bell + // 2. If argumentsList is not present, set argumentsList to a new empty List. + var argumentsList = arguments.length > 1 ? arguments[1] : []; - 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: + // 3. Assert: IsConstructor(F) is true. + if (!IsConstructor(F)) { + throw new TypeError('F must be a constructor.'); + } - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. + // 4. Assert: IsConstructor(newTarget) is true. + if (!IsConstructor(newTarget)) { + throw new TypeError('newTarget must be a constructor.'); + } - 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$ - */ + // 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); + } +} -// Original can be found at: -// https://bitbucket.org/lindenlab/llsd -// Modifications by Joshua Bell inexorabletash@gmail.com -// https://github.com/inexorabletash/polyfill +// _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; + } -// 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 + // 3. Let isArray be ? IsArray(originalArray). + var isArray = IsArray(originalArray); - // 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; + // 4. If isArray is false, return ? ArrayCreate(length). + if (isArray === false) { + return ArrayCreate(length); + } - // 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'; - } - } + // 5. Let C be ? Get(originalArray, "constructor"). + var C = Get(originalArray, 'constructor'); - // 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; } + // 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]); +} +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; + } - // 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; + } + // d. Increase k by 1. + k = k + 1; + } + // 9. Return A. + return A; +}); - // 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 (!("map"in Array.prototype +)) { - 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; - }; - } - }()); +// 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; +}); - // 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'); +if (!("of"in Array +)) { - function makeArrayAccessor(index) { - Object.defineProperty(obj, index, { - 'get': function() { return obj._getter(index); }, - 'set': function(v) { obj._setter(index, v); }, - enumerable: true, - configurable: false - }); - } +// 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; - var i; - for (i = 0; i < obj.length; i += 1) { - makeArrayAccessor(i); - } - } + } + // 8. Perform ? Set(A, "length", len, true) + A["length"] = len; + // 9. Return A. + return A; +}); - // 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; } +if (!("seal"in Object&&function(){try{return Object.seal("1"),!0}catch(t){return!1}} +)) { - function packI8(n) { return [n & 0xff]; } - function unpackI8(bytes) { return as_signed(bytes[0], 8); } +// Object.seal +/* global CreateMethodProperty, Type */ +// 19.1.2.19 Object.seal ( O ) +(function(originalObjectSeal) { + CreateMethodProperty(Object, 'seal', function seal(O) { + // 1. If Type(O) is not Object, return O. + if (Type(O) === 'object') { + return O; + } + // 2. Let status be ? SetIntegrityLevel(O, "sealed"). + // 3. If status is false, throw a TypeError exception. + // 4. Return O. + return originalObjectSeal ? originalObjectSeal(O) : O; + }); +}(Object.seal)); - 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); } +// 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/ - 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); } + // 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; } - 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); } + /*jshint proto: true */ + // @author Andrea Giammarchi - @WebReflection - function packIEEE754(v, ebits, fbits) { + 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 bias = (1 << (ebits - 1)) - 1; + 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); +}()); +if (!("Promise"in this +)) { - 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; - } +// 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= 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)); - } - } +// RegExp.prototype.flags +/* global Get, ToBoolean, Type */ +Object.defineProperty(RegExp.prototype, 'flags', { + configurable: true, + enumerable: false, + get: function () { + // 21.2.5.3.1 Let R be the this value. + var R = this; - // 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(''); + // 21.2.5.3.2 If Type(R) is not Object, throw a TypeError exception. + if (Type(R) !== 'object') { + throw new TypeError('Method called on incompatible type: must be an object.'); + } + // 21.2.5.3.3 Let result be the empty String. + var result = ''; - // Bits to bytes - var bytes = []; - while (str.length) { - bytes.unshift(parseInt(str.substring(0, 8), 2)); - str = str.substring(8); - } - return bytes; - } + // 21.2.5.3.4 Let global be ToBoolean(? Get(R, "global")). + var global = ToBoolean(Get(R, 'global')); - function unpackIEEE754(bytes, ebits, fbits) { - // Bytes to bits - var bits = [], i, j, b, str, - bias, s, e, f; + // 21.2.5.3.5 If global is true, append the code unit 0x0067 (LATIN SMALL LETTER G) as the last code unit of result. + if (global) { + result += 'g'; + } - 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(''); + // 21.2.5.3.6 Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + var ignoreCase = ToBoolean(Get(R, 'ignoreCase')); - // 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); + // 21.2.5.3.7 If ignoreCase is true, append the code unit 0x0069 (LATIN SMALL LETTER I) as the last code unit of result. + if (ignoreCase) { + result += 'i'; + } - // 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; - } - } + // 21.2.5.3.8 Let multiline be ToBoolean(? Get(R, "multiline")). + var multiline = ToBoolean(Get(R, 'multiline')); - 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); } + // 21.2.5.3.9 If multiline is true, append the code unit 0x006D (LATIN SMALL LETTER M) as the last code unit of result. + if (multiline) { + result += 'm'; + } - // - // 3 The ArrayBuffer Type - // + // 21.2.5.3.10 Let unicode be ToBoolean(? Get(R, "unicode")). + var unicode = ToBoolean(Get(R, 'unicode')); - (function() { + // 21.2.5.3.11 If unicode is true, append the code unit 0x0075 (LATIN SMALL LETTER U) as the last code unit of result. + if (unicode) { + result += 'u'; + } - 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)}); + // 21.2.5.3.12 Let sticky be ToBoolean(? Get(R, "sticky")). + var sticky = ToBoolean(Get(R, 'sticky')); - for (var i = 0; i < length; i += 1) - this._bytes[i] = 0; - } + // 21.2.5.3.13 If sticky is true, append the code unit 0x0079 (LATIN SMALL LETTER Y) as the last code unit of result. + if (sticky) { + result += 'y'; + } - global.ArrayBuffer = global.ArrayBuffer || ArrayBuffer; + // 21.2.5.3.14 Return result. + return result; + } +}); - // - // 5 The Typed Array View Types - // +} - function $TypedArray$() { +if (!("fromCodePoint"in String&&1===String.fromCodePoint.length +)) { + +// String.fromCodePoint +/* global CreateMethodProperty, IsArray, SameValue, ToInteger, ToNumber, UTF16Encoding */ + +// 21.1.2.2. String.fromCodePoint ( ...codePoints ) +CreateMethodProperty(String, 'fromCodePoint', function fromCodePoint(_) { // eslint-disable-line no-unused-vars + // Polyfill.io - List to store the characters whilst iterating over the code points. + var result = []; + // 1. Let codePoints be a List containing the arguments passed to this function. + var codePoints = arguments; + // 2. Let length be the number of elements in codePoints. + var length = arguments.length; + // 3. Let elements be a new empty List. + var elements = []; + // 4. Let nextIndex be 0. + var nextIndex = 0; + // 5. Repeat, while nextIndex < length + while (nextIndex < length) { + // Polyfill.io - We reset the elements List as we store the partial results in the result List. + var elements = []; + // a. Let next be codePoints[nextIndex]. + var next = codePoints[nextIndex]; + // b. Let nextCP be ? ToNumber(next). + var nextCP = ToNumber(next); + // c. If SameValue(nextCP, ToInteger(nextCP)) is false, throw a RangeError exception. + if (SameValue(nextCP, ToInteger(nextCP)) === false) { + throw new RangeError('Invalid code point ' + Object.prototype.toString.call(nextCP)); + } + // d. If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception. + if (nextCP < 0 || nextCP > 0x10FFFF) { + throw new RangeError('Invalid code point ' + Object.prototype.toString.call(nextCP)); + } + // e. Append the elements of the UTF16Encoding of nextCP to the end of elements. + // Polyfill.io - UTF16Encoding can return a single codepoint or a list of multiple codepoints. + var cp = UTF16Encoding(nextCP); + if (IsArray(cp)) { + elements = elements.concat(cp); + } else { + elements.push(cp); + } + // f. Let nextIndex be nextIndex + 1. + nextIndex = nextIndex + 1; - // %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}); + // Polyfill.io - Retrieving the characters whilst iterating enables the function to work in a memory efficient and performant way. + result.push(String.fromCharCode.apply(null, elements)); + } + // 6. Return the String value whose elements are, in order, the elements in the List elements. If length is 0, the empty string is returned. + return length === 0 ? '' : result.join(''); +}); - }).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(); +if (!("codePointAt"in String.prototype +)) { - 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}); +// 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); +}); - for (var i = 0; i < this.length; i += 1) - this._setter(i, typedArray._getter(i)); +} - }).apply(this, arguments); - } +if (!("endsWith"in String.prototype +)) { - // %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) { +// 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; +}); - 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); - } +if (!("includes"in String.prototype +)) { - // %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) { +// 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; +}); - 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 (!("repeat"in String.prototype +)) { - 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; +// 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; +}); - } 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'); +if (!("startsWith"in String.prototype +)) { - Object.defineProperty(this, 'buffer', {value: buffer}); - Object.defineProperty(this, 'byteLength', {value: byteLength}); - Object.defineProperty(this, 'byteOffset', {value: byteOffset}); - Object.defineProperty(this, 'length', {value: length}); +// 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; +}); - }).apply(this, arguments); - } +} - // %TypedArray% ( all other argument combinations ) - throw TypeError(); - } +if (!("Symbol"in this&&0===this.Symbol.length +)) { - // Properties of the %TypedArray Instrinsic Object +// Symbol +// A modification of https://github.com/WebReflection/get-own-property-symbols +// (C) Andrea Giammarchi - MIT Licensed - // %TypedArray%.from ( source , mapfn=undefined, thisArg=undefined ) - Object.defineProperty($TypedArray$, 'from', {value: function(iterable) { - return new this(iterable); - }}); +(function (Object, GOPS, global) { + 'use strict'; //so that ({}).toString.call(null) returns the correct [object Null] rather than [object Window] - // %TypedArray%.of ( ...items ) - Object.defineProperty($TypedArray$, 'of', {value: function(/*...items*/) { - return new this(arguments); - }}); + var setDescriptor; + var id = 0; + var random = '' + Math.random(); + var prefix = '__\x01symbol:'; + var prefixLength = prefix.length; + var internalSymbol = '__\x01symbol@@' + random; + var DP = 'defineProperty'; + var DPies = 'defineProperties'; + var GOPN = 'getOwnPropertyNames'; + var GOPD = 'getOwnPropertyDescriptor'; + var PIE = 'propertyIsEnumerable'; + var ObjectProto = Object.prototype; + var hOP = ObjectProto.hasOwnProperty; + var pIE = ObjectProto[PIE]; + var toString = ObjectProto.toString; + var concat = Array.prototype.concat; + var cachedWindowNames = Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : []; + var nGOPN = Object[GOPN]; + var gOPN = function getOwnPropertyNames (obj) { + if (toString.call(obj) === '[object Window]') { + try { + return nGOPN(obj); + } catch (e) { + // IE bug where layout engine calls userland gOPN for cross-domain `window` objects + return concat.call([], cachedWindowNames); + } + } + return nGOPN(obj); + }; + var gOPD = Object[GOPD]; + var create = Object.create; + var keys = Object.keys; + var freeze = Object.freeze || Object; + var defineProperty = Object[DP]; + var $defineProperties = Object[DPies]; + var descriptor = gOPD(Object, GOPN); + var addInternalIfNeeded = function (o, uid, enumerable) { + if (!hOP.call(o, internalSymbol)) { + try { + defineProperty(o, internalSymbol, { + enumerable: false, + configurable: false, + writable: false, + value: {} + }); + } catch (e) { + o[internalSymbol] = {}; + } + } + o[internalSymbol]['@@' + uid] = enumerable; + }; + var createWithSymbols = function (proto, descriptors) { + var self = create(proto); + gOPN(descriptors).forEach(function (key) { + if (propertyIsEnumerable.call(descriptors, key)) { + $defineProperty(self, key, descriptors[key]); + } + }); + return self; + }; + var copyAsNonEnumerable = function (descriptor) { + var newDescriptor = create(descriptor); + newDescriptor.enumerable = false; + return newDescriptor; + }; + var get = function get(){}; + var onlyNonSymbols = function (name) { + return name != internalSymbol && + !hOP.call(source, name); + }; + var onlySymbols = function (name) { + return name != internalSymbol && + hOP.call(source, name); + }; + var propertyIsEnumerable = function propertyIsEnumerable(key) { + var uid = '' + key; + return onlySymbols(uid) ? ( + hOP.call(this, uid) && + this[internalSymbol]['@@' + uid] + ) : pIE.call(this, key); + }; + var setAndGetSymbol = function (uid) { + var descriptor = { + enumerable: false, + configurable: true, + get: get, + set: function (value) { + setDescriptor(this, uid, { + enumerable: false, + configurable: true, + writable: true, + value: value + }); + addInternalIfNeeded(this, uid, true); + } + }; + try { + defineProperty(ObjectProto, uid, descriptor); + } catch (e) { + ObjectProto[uid] = descriptor.value; + } + return freeze(source[uid] = defineProperty( + Object(uid), + 'constructor', + sourceConstructor + )); + }; + var Symbol = function Symbol() { + var description = arguments[0]; + if (this instanceof Symbol) { + throw new TypeError('Symbol is not a constructor'); + } + return setAndGetSymbol( + prefix.concat(description || '', random, ++id) + ); + }; + var source = create(null); + var sourceConstructor = {value: Symbol}; + var sourceMap = function (uid) { + return source[uid]; + }; + var $defineProperty = function defineProp(o, key, descriptor) { + var uid = '' + key; + if (onlySymbols(uid)) { + setDescriptor(o, uid, descriptor.enumerable ? + copyAsNonEnumerable(descriptor) : descriptor); + addInternalIfNeeded(o, uid, !!descriptor.enumerable); + } else { + defineProperty(o, key, descriptor); + } + return o; + }; - // %TypedArray%.prototype - var $TypedArrayPrototype$ = {}; - $TypedArray$.prototype = $TypedArrayPrototype$; + var onlyInternalSymbols = function (obj) { + return function (name) { + return hOP.call(obj, internalSymbol) && hOP.call(obj[internalSymbol], '@@' + name); + }; + }; + var $getOwnPropertySymbols = function getOwnPropertySymbols(o) { + return gOPN(o).filter(o === ObjectProto ? onlyInternalSymbols(o) : onlySymbols).map(sourceMap); + } + ; - // WebIDL: getter type (unsigned long index); - Object.defineProperty($TypedArray$.prototype, '_getter', {value: function(index) { - if (arguments.length < 1) throw SyntaxError('Not enough arguments'); + descriptor.value = $defineProperty; + defineProperty(Object, DP, descriptor); - index = ToUint32(index); - if (index >= this.length) - return undefined; + descriptor.value = $getOwnPropertySymbols; + defineProperty(Object, GOPS, descriptor); - 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); - }}); + descriptor.value = function getOwnPropertyNames(o) { + return gOPN(o).filter(onlyNonSymbols); + }; + defineProperty(Object, GOPN, descriptor); - // NONSTANDARD: convenience alias for getter: type get(unsigned long index); - Object.defineProperty($TypedArray$.prototype, 'get', {value: $TypedArray$.prototype._getter}); + descriptor.value = function defineProperties(o, descriptors) { + var symbols = $getOwnPropertySymbols(descriptors); + if (symbols.length) { + keys(descriptors).concat(symbols).forEach(function (uid) { + if (propertyIsEnumerable.call(descriptors, uid)) { + $defineProperty(o, uid, descriptors[uid]); + } + }); + } else { + $defineProperties(o, descriptors); + } + return o; + }; + defineProperty(Object, DPies, descriptor); - // 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'); + descriptor.value = propertyIsEnumerable; + defineProperty(ObjectProto, PIE, descriptor); - index = ToUint32(index); - if (index >= this.length) - return; + descriptor.value = Symbol; + defineProperty(global, 'Symbol', descriptor); - 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]; - } - }}); + // defining `Symbol.for(key)` + descriptor.value = function (key) { + var uid = prefix.concat(prefix, key, random); + return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid); + }; + defineProperty(Symbol, 'for', descriptor); - // get %TypedArray%.prototype.buffer - // get %TypedArray%.prototype.byteLength - // get %TypedArray%.prototype.byteOffset - // -- applied directly to the object in the constructor + // defining `Symbol.keyFor(symbol)` + descriptor.value = function (symbol) { + if (onlyNonSymbols(symbol)) + throw new TypeError(symbol + ' is not a symbol'); + return hOP.call(source, symbol) ? + symbol.slice(prefixLength * 2, -random.length) : + void 0 + ; + }; + defineProperty(Symbol, 'keyFor', descriptor); - // %TypedArray%.prototype.constructor - Object.defineProperty($TypedArray$.prototype, 'constructor', {value: $TypedArray$}); + descriptor.value = function getOwnPropertyDescriptor(o, key) { + var descriptor = gOPD(o, key); + if (descriptor && onlySymbols(key)) { + descriptor.enumerable = propertyIsEnumerable.call(o, key); + } + return descriptor; + }; + defineProperty(Object, GOPD, descriptor); - // %TypedArray%.prototype.copyWithin (target, start, end = this.length ) - Object.defineProperty($TypedArray$.prototype, 'copyWithin', {value: function(target, start) { - var end = arguments[2]; + descriptor.value = function (proto, descriptors) { + return arguments.length === 1 || typeof descriptors === "undefined" ? + create(proto) : + createWithSymbols(proto, descriptors); + }; + defineProperty(Object, 'create', descriptor); - 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; - }}); + var strictModeSupported = (function(){ 'use strict'; return this; }).call(null) === null; + if (strictModeSupported) { + descriptor.value = function () { + var str = toString.call(this); + return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str; + }; + } else { + descriptor.value = function () { + // https://github.com/Financial-Times/polyfill-library/issues/164#issuecomment-486965300 + // Polyfill.io this code is here for the situation where a browser does not + // support strict mode and is executing `Object.prototype.toString.call(null)`. + // This code ensures that we return the correct result in that situation however, + // this code also introduces a bug where it will return the incorrect result for + // `Object.prototype.toString.call(window)`. We can't have the correct result for + // both `window` and `null`, so we have opted for `null` as we believe this is the more + // common situation. + if (this === window) { + return '[object Null]'; + } - // %TypedArray%.prototype.entries ( ) - // -- defined in es6.js to shim browsers w/ native TypedArrays + var str = toString.call(this); + return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str; + }; + } + defineProperty(ObjectProto, 'toString', descriptor); - // %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; - }}); + setDescriptor = function (o, key, descriptor) { + var protoDescriptor = gOPD(ObjectProto, key); + delete ObjectProto[key]; + defineProperty(o, key, descriptor); + if (o !== ObjectProto) { + defineProperty(ObjectProto, key, protoDescriptor); + } + }; - // %TypedArray%.prototype.fill (value, start = 0, end = this.length ) - Object.defineProperty($TypedArray$.prototype, 'fill', {value: function(value) { - var start = arguments[1], - end = arguments[2]; +}(Object, 'getOwnPropertySymbols', this)); - 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); - }}); +if (!("Symbol"in this&&"hasInstance"in this.Symbol +)) { - // %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; - }}); +// Symbol.hasInstance +/* global Symbol */ +Object.defineProperty(Symbol, 'hasInstance', { value: Symbol('hasInstance') }); - // %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); - }}); +if (!("Symbol"in this&&"isConcatSpreadable"in this.Symbol +)) { - // %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; - }}); +// Symbol.isConcatSpreadable +/* global Symbol */ +Object.defineProperty(Symbol, 'isConcatSpreadable', { value: Symbol('isConcatSpreadable') }); - // %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 +if (!("Symbol"in this&&"iterator"in this.Symbol +)) { - // %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; - }}); +// Symbol.iterator +/* global Symbol */ +Object.defineProperty(Symbol, 'iterator', { value: Symbol('iterator') }); - // 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; - }}); +// _ESAbstract.GetIterator +/* global GetMethod, Symbol, Call, Type, GetV */ +// 7.4.1. GetIterator ( obj [ , method ] ) +// The abstract operation GetIterator with argument obj and optional argument method performs the following steps: +function GetIterator(obj /*, method */) { // eslint-disable-line no-unused-vars + // 1. If method is not present, then + // a. Set method to ? GetMethod(obj, @@iterator). + var method = arguments.length > 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; +} +if (!("Symbol"in this&&"match"in this.Symbol +)) { - // %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; - }}); +// 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') }); - // %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 (!("Symbol"in this&&"search"in this.Symbol +)) { - 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]); +// Symbol.search +/* global Symbol */ +Object.defineProperty(Symbol, 'search', { value: Symbol('search') }); - 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 (!("Symbol"in this&&"species"in this.Symbol +)) { - 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]); +// Symbol.species +/* global Symbol */ +Object.defineProperty(Symbol, 'species', { value: Symbol('species') }); - 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)'); - } - }}); +if (!("Map"in this&&function(t){try{var n=new Map([[1,1],[2,2]]) +return 0===Map.length&&2===n.size&&"Symbol"in t&&"iterator"in Symbol&&"function"==typeof n[Symbol.iterator]}catch(i){return!1}}(this) +)) { - // %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; - }}); +// 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; + } + }()); - // %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; - }}); + // 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 + }); - // %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; - }}); + // 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: {} + }); - // %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; } + // 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); + } - start = ToInt32(start); - end = ToInt32(end); + // 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; + } + ); - if (arguments.length < 1) { start = 0; } - if (arguments.length < 2) { end = this.length; } + // 23.1.3.2. Map.prototype.constructor + CreateMethodProperty(Map.prototype, 'constructor', Map); - if (start < 0) { start = this.length + start; } - if (end < 0) { end = this.length + end; } + // 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; + } + ); - start = clamp(start, 0, this.length); - end = clamp(end, 0, this.length); + // 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'); + } + ); - var len = end - start; - if (len < 0) { - len = 0; - } + // 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; + } + ); - return new this.constructor( - this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len); - }}); + // 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; + }); - // %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 + // 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; + }); - 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; - } + // 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 (key === -0) { + 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; + }); - TypedArray.BYTES_PER_ELEMENT = elementSize; + // 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 + }); + } - var TypedArrayPrototype = function() {}; - TypedArrayPrototype.prototype = $TypedArrayPrototype$; + // 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'); + } + ); - TypedArray.prototype = new TypedArrayPrototype(); + // 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); - Object.defineProperty(TypedArray.prototype, 'BYTES_PER_ELEMENT', {value: elementSize}); - Object.defineProperty(TypedArray.prototype, '_pack', {value: pack}); - Object.defineProperty(TypedArray.prototype, '_unpack', {value: unpack}); + // 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 }. - return TypedArray; - } + // 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' + }); + } - 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); + // 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; + } - 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; - }()); + // 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 + }); - // - // 6 The DataView View Type - // + // 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); + } + ); - (function() { - function r(array, index) { - return IsCallable(array.get) ? array.get(index) : array[index]; - } + // 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 }. - var IS_BIG_ENDIAN = (function() { - var u16array = new Uint16Array([0x1234]), - u8array = new Uint8Array(u16array.buffer); - return r(u8array, 0) === 0x12; - }()); + CreateMethodProperty(MapIteratorPrototype, Symbol.iterator, function iterator() { + return this; + } + ); - // 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(); + // 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)); - 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 (!("Set"in this&&function(){try{var t=new Set([1,2]) +return 0===Set.length&&2===t.size&&"Symbol"in this&&"iterator"in Symbol&&"function"==typeof t[Symbol.iterator]}catch(e){return!1}}() +)) { + +// 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; + } + }()); - if ((byteOffset + byteLength) > buffer.byteLength) - throw RangeError('byteOffset and length reference an area beyond the end of the buffer'); + // 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 + }); - Object.defineProperty(this, 'buffer', {value: buffer}); - Object.defineProperty(this, 'byteLength', {value: byteLength}); - Object.defineProperty(this, 'byteOffset', {value: byteOffset}); - }; + // 3. Set set.[[SetData]] to a new empty List. + // Polyfill.io - This step was done as part of step two. - // get DataView.prototype.buffer - // get DataView.prototype.byteLength - // get DataView.prototype.byteOffset - // -- applied directly to instances by the constructor + // 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 + }); + } - function makeGetter(arrayType) { - return function GetViewValue(byteOffset, littleEndian) { - byteOffset = ToUint32(byteOffset); + // 4. If iterable is not present, let iterable be undefined. + var iterable = arguments.length > 0 ? arguments[0] : undefined; - if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) - throw RangeError('Array index out of range'); + // 5. If iterable is either undefined or null, return set. + if (iterable === null || iterable === undefined) { + return set; + } - byteOffset += this.byteOffset; + // 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"); + } - 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)); + 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]); + } + } else { + throw (e); + } + } + return set; + }; - if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) - bytes.reverse(); + // 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: {} + }); - return r(new arrayType(new Uint8Array(bytes).buffer), 0); - }; - } + // 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); + } - 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)}); + // 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); - 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'); + this._size = ++this._size; + if (!supportsGetters) { + this.size = this._size; + } + // 8. Return S. + return S; + }); - // Get bytes - var typeArray = new arrayType([value]), - byteArray = new Uint8Array(typeArray.buffer), - bytes = [], i, byteView; + // 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; + }); - for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) - bytes.push(r(byteArray, i)); + // 23.2.3.3. Set.prototype.constructor + CreateMethodProperty(Set.prototype, 'constructor', Set); - // Flip if necessary - if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) - bytes.reverse(); + // 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; - // Write them - byteView = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT); - byteView.set(bytes); - }; - } + this._size = --this._size; + if (!supportsGetters) { + this.size = this._size; + } + // ii. Return true. + return true; + } + } + // 6. Return false. + return false; + } + ); - 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)}); + // 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'); + } + ); - global.DataView = global.DataView || DataView; + // 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; + } + ); -}(self)); -if (!('fround' in Math)) { + // 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); -// 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; + // 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 + }); } - // 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]; -}); -} + // 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); -if (!('hypot' in Math)) { + // 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 }. -// 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; + // 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' + }); } - 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; + + // 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; + } - // If any argument is -∞, the result is +∞. - if (arguments[i] === -Infinity) { - return Infinity; + // 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); + }); - // 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. + // 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 }. - 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); + CreateMethodProperty(SetIteratorPrototype, Symbol.iterator, function iterator() { + return this; } - } - - 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)) { + // 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; + } -// Math.log2 -/* global CreateMethodProperty */ -// 20.2.2.23. Math.log2 ( x ) -CreateMethodProperty(Math, 'log2', function log2(x) { - return Math.log(x) / Math.LN2; -}); +}(this)); } -if (!('sign' in Math)) { +if (!("from"in Array&&function(){try{return Array.from({length:-Infinity}),!0}catch(r){return!1}}() +)) { -// 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; +// 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; -if (!('sinh' in Math)) { + } + // 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); + } -// 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; + // 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; + } } - var t = Math.exp(absx) - 1; - if (absx < 1) { - return (s * (2 * t - t * t / (t + 1)))/2; + // 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; } - 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)); -}); + // 13. Perform ? Set(A, "length", len, true). + A["length"] = len; + // 14. Return A. + return A; + }); +}()); } -if (!('trunc' in Math)) { +if (!("Symbol"in this&&"split"in this.Symbol +)) { -// Math.trunc -/* global CreateMethodProperty */ -CreateMethodProperty(Math, 'trunc', function trunc(x) { - return x < 0 ? Math.ceil(x) : Math.floor(x); -}); +// Symbol.split +/* global Symbol */ +Object.defineProperty(Symbol, 'split', { value: Symbol('split') }); } -if (!('EPSILON' in Number)) { +if (!("Symbol"in this&&"toPrimitive"in this.Symbol +)) { -// 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) -}); +// Symbol.toPrimitive +/* global Symbol */ +Object.defineProperty(Symbol, 'toPrimitive', { value: Symbol('toPrimitive') }); } -if (!('MAX_SAFE_INTEGER' in Number)) { +if (!("Symbol"in this&&"toStringTag"in this.Symbol +)) { -// 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 +// Symbol.toStringTag +/* global Symbol */ +Object.defineProperty(Symbol, 'toStringTag', { + value: Symbol('toStringTag') }); } -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) -}); +// _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; + }; -if (!('isFinite' in Number)) { + 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)); + }; -// 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; + 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 } - // 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); - }); -}()); + }, { + _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 + }); -if (!('isInteger' in Number)) { + return Iterator; +}()); -// 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; -}); +// _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 -if (!('isNaN' in Number)) { + 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); -// 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; + 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 } - // 3. Otherwise, return false. - return false; }); -}()); -} - -if (!('isSafeInteger' in Number)) { + return ArrayIterator; +}()); +if (!("Symbol"in this&&"iterator"in this.Symbol&&!!Array.prototype.entries +)) { -// 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; +// 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 (!('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)) { +if (!("Symbol"in this&&"iterator"in this.Symbol&&!!Array.prototype.keys +)) { -// 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); +// 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 (!('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= 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)) { +if (!("Symbol"in this&&"unscopables"in this.Symbol +)) { // Symbol.unscopables /* global Symbol */ @@ -6152,19 +6301,9 @@ 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)))) { +if (!((function(e){try{if("WeakMap"in e&&0===WeakMap.length){var t={},a=new WeakMap([[t,"test"]]) +return"test"===a.get(t)&&!1===a["delete"](0)}return!1}catch(n){return!1}})(this) +)) { // WeakMap /* globals Symbol, OrdinaryCreateFromConstructor, IsCallable, GetIterator, IteratorStep, IteratorValue, IteratorClose, Get, Call, CreateMethodProperty, Type, SameValue */ @@ -6433,19 +6572,9 @@ if (!((function(global) { } -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)))) { +if (!((function(e){try{if("WeakSet"in e&&0===WeakSet.length){var t={},n=new WeakSet([t]) +return n.has(t)&&!1===n["delete"](0)}return!1}catch(r){return!1}})(this) +)) { // WeakSet /* global Call, CreateMethodProperty, Get, GetIterator, IsArray, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Type, Symbol */