diff options
Diffstat (limited to 'js/vendor/es6-shim/es6-shim.js')
-rw-r--r-- | js/vendor/es6-shim/es6-shim.js | 3438 |
1 files changed, 1823 insertions, 1615 deletions
diff --git a/js/vendor/es6-shim/es6-shim.js b/js/vendor/es6-shim/es6-shim.js index 5ac65e8c7..888bec378 100644 --- a/js/vendor/es6-shim/es6-shim.js +++ b/js/vendor/es6-shim/es6-shim.js @@ -1,21 +1,45 @@ -// ES6-shim 0.18.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(undefined) { + /*! + * https://github.com/paulmillr/es6-shim + * @license es6-shim Copyright 2013-2014 by Paul Miller (http://paulmillr.com) + * and contributors, MIT License + * es6-shim: v0.23.0 + * see https://github.com/paulmillr/es6-shim/blob/0.22.2/LICENSE + * Details and documentation: + * https://github.com/paulmillr/es6-shim/ + */ + +// UMD (Universal Module Definition) +// see https://github.com/umdjs/umd/blob/master/returnExports.js +(function (root, factory) { + /*global define, module, exports */ + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(factory); + } else if (typeof exports === 'object') { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like enviroments that support module.exports, + // like Node. + module.exports = factory(); + } else { + // Browser globals (root is window) + root.returnExports = factory(); + } +}(this, function () { 'use strict'; - var isCallableWithoutNew = function(func) { - try { func(); } - catch (e) { return false; } + var isCallableWithoutNew = function (func) { + try { + func(); + } catch (e) { + return false; + } return true; }; - var supportsSubclassing = function(C, f) { + var supportsSubclassing = function (C, f) { /* jshint proto:true */ try { - var Sub = function() { C.apply(this, arguments); }; + var Sub = function () { C.apply(this, arguments); }; if (!Sub.__proto__) { return false; /* skip test on IE < 11 */ } Object.setPrototypeOf(Sub, C); Sub.prototype = Object.create(C.prototype, { @@ -27,7 +51,7 @@ } }; - var arePropertyDescriptorsSupported = function() { + var arePropertyDescriptorsSupported = function () { try { Object.defineProperty({}, 'x', {}); return true; @@ -36,7 +60,7 @@ } }; - var startsWithRejectsRegex = function() { + var startsWithRejectsRegex = function () { var rejectsRegex = false; if (String.prototype.startsWith) { try { @@ -52,1306 +76,1449 @@ var getGlobal = new Function('return this;'); /*jshint evil: false */ - var main = function() { - var globals = getGlobal(); - var global_isFinite = globals.isFinite; - var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported(); - var startsWithIsCompliant = startsWithRejectsRegex(); - var _slice = Array.prototype.slice; - var _indexOf = String.prototype.indexOf; - var _toString = Object.prototype.toString; - var _hasOwnProperty = Object.prototype.hasOwnProperty; - var ArrayIterator; // make our implementation private - - var defineProperty = function(object, name, value, force) { - if (!force && name in object) return; - if (supportsDescriptors) { - Object.defineProperty(object, name, { - configurable: true, - enumerable: false, - writable: true, - value: value - }); - } else { - object[name] = value; - } - }; + var globals = getGlobal(); + var global_isFinite = globals.isFinite; + var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported(); + var startsWithIsCompliant = startsWithRejectsRegex(); + var _indexOf = Function.call.bind(String.prototype.indexOf); + var _toString = Function.call.bind(Object.prototype.toString); + var _hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty); + var ArrayIterator; // make our implementation private + var noop = function () {}; + + var Symbol = globals.Symbol || {}; + var symbolSpecies = Symbol.species || '@@species'; + var Type = { + string: function (x) { return _toString(x) === '[object String]'; }, + regex: function (x) { return _toString(x) === '[object RegExp]'; }, + symbol: function (x) { + /*jshint notypeof: true */ + return typeof globals.Symbol === 'function' && typeof x === 'symbol'; + /*jshint notypeof: false */ + } + }; - // Define configurable, writable and non-enumerable props - // if they don’t exist. - var defineProperties = function(object, map) { - Object.keys(map).forEach(function(name) { - var method = map[name]; - defineProperty(object, name, method, false); + var defineProperty = function (object, name, value, force) { + if (!force && name in object) { return; } + if (supportsDescriptors) { + Object.defineProperty(object, name, { + configurable: true, + enumerable: false, + writable: true, + value: value }); - }; - - // Simple shim for Object.create on ES3 browsers - // (unlike real shim, no attempt to support `prototype === null`) - var create = Object.create || function(prototype, properties) { - function Type() {} - Type.prototype = prototype; - var object = new Type(); - if (typeof properties !== "undefined") { - defineProperties(object, properties); - } - return object; - }; - - // This is a private name in the es6 spec, equal to '[Symbol.iterator]' - // we're going to use an arbitrary _-prefixed name to make our shims - // work properly with each other, even though we don't have full Iterator - // support. That is, `Array.from(map.keys())` will work, but we don't - // pretend to export a "real" Iterator interface. - var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) || - '_es6shim_iterator_'; - // Firefox ships a partial implementation using the name @@iterator. - // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14 - // So use that name if we detect it. - if (globals.Set && typeof new globals.Set()['@@iterator'] === 'function') { - $iterator$ = '@@iterator'; + } else { + object[name] = value; } - var addIterator = function(prototype, impl) { - if (!impl) { impl = function iterator() { return this; }; } - var o = {}; - o[$iterator$] = impl; - defineProperties(prototype, o); - /* jshint notypeof: true */ - if (!prototype[$iterator$] && typeof $iterator$ === 'symbol') { - // implementations are buggy when $iterator$ is a Symbol - prototype[$iterator$] = impl; - } - }; + }; - // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js - // can be replaced with require('is-arguments') if we ever use a build process instead - var isArguments = function isArguments(value) { - var str = _toString.call(value); - var result = str === '[object Arguments]'; - if (!result) { - result = str !== '[object Array]' && - value !== null && - typeof value === 'object' && - typeof value.length === 'number' && - value.length >= 0 && - _toString.call(value.callee) === '[object Function]'; + var Value = { + getter: function (object, name, getter) { + if (!supportsDescriptors) { + throw new TypeError('getters require true ES5 support'); } - return result; - }; - - var emulateES6construct = function(o) { - if (!ES.TypeIsObject(o)) throw new TypeError('bad object'); - // es5 approximation to es6 subclass semantics: in es6, 'new Foo' - // would invoke Foo.@@create to allocation/initialize the new object. - // In es5 we just get the plain object. So if we detect an - // uninitialized object, invoke o.constructor.@@create - if (!o._es6construct) { - if (o.constructor && ES.IsCallable(o.constructor['@@create'])) { - o = o.constructor['@@create'](o); - } - defineProperties(o, { _es6construct: true }); + Object.defineProperty(object, name, { + configurable: true, + enumerable: false, + get: getter + }); + }, + proxy: function (originalObject, key, targetObject) { + if (!supportsDescriptors) { + throw new TypeError('getters require true ES5 support'); } - return o; - }; - - var ES = { - CheckObjectCoercible: function(x, optMessage) { - /* jshint eqnull:true */ - if (x == null) - throw new TypeError(optMessage || ('Cannot call method on ' + x)); - return x; - }, - - TypeIsObject: function(x) { - /* jshint eqnull:true */ - // this is expensive when it returns false; use this function - // when you expect it to return true in the common case. - return x != null && Object(x) === x; - }, - - ToObject: function(o, optMessage) { - return Object(ES.CheckObjectCoercible(o, optMessage)); - }, + var originalDescriptor = Object.getOwnPropertyDescriptor(originalObject, key); + Object.defineProperty(targetObject, key, { + configurable: originalDescriptor.configurable, + enumerable: originalDescriptor.enumerable, + get: function getKey() { return originalObject[key]; }, + set: function setKey(value) { originalObject[key] = value; } + }); + }, + redefine: function (object, property, newValue) { + if (supportsDescriptors) { + var descriptor = Object.getOwnPropertyDescriptor(object, property); + descriptor.value = newValue; + Object.defineProperty(object, property, descriptor); + } else { + object[property] = newValue; + } + } + }; - IsCallable: function(x) { - return typeof x === 'function' && - // some versions of IE say that typeof /abc/ === 'function' - _toString.call(x) === '[object Function]'; - }, + // Define configurable, writable and non-enumerable props + // if they don’t exist. + var defineProperties = function (object, map) { + Object.keys(map).forEach(function (name) { + var method = map[name]; + defineProperty(object, name, method, false); + }); + }; - ToInt32: function(x) { - return x >> 0; - }, + // Simple shim for Object.create on ES3 browsers + // (unlike real shim, no attempt to support `prototype === null`) + var create = Object.create || function (prototype, properties) { + function Prototype() {} + Prototype.prototype = prototype; + var object = new Prototype(); + if (typeof properties !== 'undefined') { + defineProperties(object, properties); + } + return object; + }; - ToUint32: function(x) { - return x >>> 0; - }, + // This is a private name in the es6 spec, equal to '[Symbol.iterator]' + // we're going to use an arbitrary _-prefixed name to make our shims + // work properly with each other, even though we don't have full Iterator + // support. That is, `Array.from(map.keys())` will work, but we don't + // pretend to export a "real" Iterator interface. + var $iterator$ = Type.symbol(Symbol.iterator) ? Symbol.iterator : '_es6-shim iterator_'; + // Firefox ships a partial implementation using the name @@iterator. + // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14 + // So use that name if we detect it. + if (globals.Set && typeof new globals.Set()['@@iterator'] === 'function') { + $iterator$ = '@@iterator'; + } + var addIterator = function (prototype, impl) { + if (!impl) { impl = function iterator() { return this; }; } + var o = {}; + o[$iterator$] = impl; + defineProperties(prototype, o); + if (!prototype[$iterator$] && Type.symbol($iterator$)) { + // implementations are buggy when $iterator$ is a Symbol + prototype[$iterator$] = impl; + } + }; - ToInteger: function(value) { - var number = +value; - if (Number.isNaN(number)) return 0; - if (number === 0 || !Number.isFinite(number)) return number; - return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); - }, + // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js + // can be replaced with require('is-arguments') if we ever use a build process instead + var isArguments = function isArguments(value) { + var str = _toString(value); + var result = str === '[object Arguments]'; + if (!result) { + result = str !== '[object Array]' && + value !== null && + typeof value === 'object' && + typeof value.length === 'number' && + value.length >= 0 && + _toString(value.callee) === '[object Function]'; + } + return result; + }; - ToLength: function(value) { - var len = ES.ToInteger(value); - if (len <= 0) return 0; // includes converting -0 to +0 - if (len > Number.MAX_SAFE_INTEGER) return Number.MAX_SAFE_INTEGER; - return len; - }, + var ES = { + RequireObjectCoercible: function (x, optMessage) { + /* jshint eqnull:true */ + if (x == null) { + throw new TypeError(optMessage || 'Cannot call method on ' + x); + } + }, + + TypeIsObject: function (x) { + /* jshint eqnull:true */ + // this is expensive when it returns false; use this function + // when you expect it to return true in the common case. + return x != null && Object(x) === x; + }, + + ToObject: function (o, optMessage) { + ES.RequireObjectCoercible(o, optMessage); + return Object(o); + }, + + IsCallable: function (x) { + // some versions of IE say that typeof /abc/ === 'function' + return typeof x === 'function' && _toString(x) === '[object Function]'; + }, + + ToInt32: function (x) { + return ES.ToNumber(x) >> 0; + }, + + ToUint32: function (x) { + return ES.ToNumber(x) >>> 0; + }, + + ToNumber: function (value) { + if (_toString(value) === '[object Symbol]') { + throw new TypeError('Cannot convert a Symbol value to a number'); + } + return +value; + }, + + ToInteger: function (value) { + var number = ES.ToNumber(value); + if (Number.isNaN(number)) { return 0; } + if (number === 0 || !Number.isFinite(number)) { return number; } + return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); + }, + + ToLength: function (value) { + var len = ES.ToInteger(value); + if (len <= 0) { return 0; } // includes converting -0 to +0 + if (len > Number.MAX_SAFE_INTEGER) { return Number.MAX_SAFE_INTEGER; } + return len; + }, + + SameValue: function (a, b) { + if (a === b) { + // 0 === -0, but they are not identical. + if (a === 0) { return 1 / a === 1 / b; } + return true; + } + return Number.isNaN(a) && Number.isNaN(b); + }, + + SameValueZero: function (a, b) { + // same as SameValue except for SameValueZero(+0, -0) == true + return (a === b) || (Number.isNaN(a) && Number.isNaN(b)); + }, + + IsIterable: function (o) { + return ES.TypeIsObject(o) && (typeof o[$iterator$] !== 'undefined' || isArguments(o)); + }, + + GetIterator: function (o) { + if (isArguments(o)) { + // special case support for `arguments` + return new ArrayIterator(o, 'value'); + } + var itFn = o[$iterator$]; + if (!ES.IsCallable(itFn)) { + throw new TypeError('value is not an iterable'); + } + var it = itFn.call(o); + if (!ES.TypeIsObject(it)) { + throw new TypeError('bad iterator'); + } + return it; + }, - SameValue: function(a, b) { - if (a === b) { - // 0 === -0, but they are not identical. - if (a === 0) return 1 / a === 1 / b; - return true; - } - return Number.isNaN(a) && Number.isNaN(b); - }, + IteratorNext: function (it) { + var result = arguments.length > 1 ? it.next(arguments[1]) : it.next(); + if (!ES.TypeIsObject(result)) { + throw new TypeError('bad iterator'); + } + return result; + }, - SameValueZero: function(a, b) { - // same as SameValue except for SameValueZero(+0, -0) == true - return (a === b) || (Number.isNaN(a) && Number.isNaN(b)); - }, + Construct: function (C, args) { + // CreateFromConstructor + var obj; + if (ES.IsCallable(C[symbolSpecies])) { + obj = C[symbolSpecies](); + } else { + // OrdinaryCreateFromConstructor + obj = create(C.prototype || null); + } + // Mark that we've used the es6 construct path + // (see emulateES6construct) + defineProperties(obj, { _es6construct: true }); + // Call the constructor. + var result = C.apply(obj, args); + return ES.TypeIsObject(result) ? result : obj; + } + }; - IsIterable: function(o) { - return ES.TypeIsObject(o) && - (o[$iterator$] !== undefined || isArguments(o)); - }, + var emulateES6construct = function (o) { + if (!ES.TypeIsObject(o)) { throw new TypeError('bad object'); } + // es5 approximation to es6 subclass semantics: in es6, 'new Foo' + // would invoke Foo.@@species to allocation/initialize the new object. + // In es5 we just get the plain object. So if we detect an + // uninitialized object, invoke o.constructor.@@species + if (!o._es6construct) { + if (o.constructor && ES.IsCallable(o.constructor[symbolSpecies])) { + o = o.constructor[symbolSpecies](o); + } + defineProperties(o, { _es6construct: true }); + } + return o; + }; - GetIterator: function(o) { - if (isArguments(o)) { - // special case support for `arguments` - return new ArrayIterator(o, "value"); - } - var it = o[$iterator$](); - if (!ES.TypeIsObject(it)) { - throw new TypeError('bad iterator'); - } - return it; - }, - IteratorNext: function (it) { - var result = arguments.length > 1 ? it.next(arguments[1]) : it.next(); - if (!ES.TypeIsObject(result)) { - throw new TypeError('bad iterator'); - } - return result; - }, + var numberConversion = (function () { + // from https://github.com/inexorabletash/polyfill/blob/master/typedarray.js#L176-L266 + // with permission and license, per https://twitter.com/inexorabletash/status/372206509540659200 - Construct: function(C, args) { - // CreateFromConstructor - var obj; - if (ES.IsCallable(C['@@create'])) { - obj = C['@@create'](); - } else { - // OrdinaryCreateFromConstructor - obj = create(C.prototype || null); - } - // Mark that we've used the es6 construct path - // (see emulateES6construct) - defineProperties(obj, { _es6construct: true }); - // Call the constructor. - var result = C.apply(obj, args); - return ES.TypeIsObject(result) ? result : obj; + function roundToEven(n) { + var w = Math.floor(n), f = n - w; + if (f < 0.5) { + return w; } - }; - - var numberConversion = (function () { - // from https://github.com/inexorabletash/polyfill/blob/master/typedarray.js#L176-L266 - // with permission and license, per https://twitter.com/inexorabletash/status/372206509540659200 + if (f > 0.5) { + return w + 1; + } + return w % 2 ? w + 1 : w; + } - function roundToEven(n) { - var w = Math.floor(n), f = n - w; - if (f < 0.5) { - return w; - } - if (f > 0.5) { - return w + 1; - } - return w % 2 ? w + 1 : w; - } - - function packIEEE754(v, ebits, fbits) { - var bias = (1 << (ebits - 1)) - 1, - s, e, f, ln, - i, bits, str, bytes; - - // Compute sign, exponent, fraction - if (v !== v) { - // NaN - // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping - e = (1 << ebits) - 1; - f = Math.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 = Math.abs(v); - - if (v >= Math.pow(2, 1 - bias)) { - e = Math.min(Math.floor(Math.log(v) / Math.LN2), 1023); - f = roundToEven(v / Math.pow(2, e) * Math.pow(2, fbits)); - if (f / Math.pow(2, fbits) >= 2) { - e = e + 1; - f = 1; - } - if (e > bias) { - // Overflow - e = (1 << ebits) - 1; - f = 0; - } else { - // Normal - e = e + bias; - f = f - Math.pow(2, fbits); - } + function packIEEE754(v, ebits, fbits) { + var bias = (1 << (ebits - 1)) - 1, + s, e, f, + i, bits, str, bytes; + + // Compute sign, exponent, fraction + if (v !== v) { + // NaN + // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping + e = (1 << ebits) - 1; + f = Math.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 = Math.abs(v); + + if (v >= Math.pow(2, 1 - bias)) { + e = Math.min(Math.floor(Math.log(v) / Math.LN2), 1023); + f = roundToEven(v / Math.pow(2, e) * Math.pow(2, fbits)); + if (f / Math.pow(2, fbits) >= 2) { + e = e + 1; + f = 1; + } + if (e > bias) { + // Overflow + e = (1 << ebits) - 1; + f = 0; } else { - // Subnormal - e = 0; - f = roundToEven(v / Math.pow(2, 1 - bias - fbits)); + // Normal + e = e + bias; + f = f - Math.pow(2, fbits); } + } else { + // Subnormal + e = 0; + f = roundToEven(v / Math.pow(2, 1 - bias - fbits)); } + } - // Pack sign, exponent, fraction - bits = []; - for (i = fbits; i; i -= 1) { - bits.push(f % 2 ? 1 : 0); - f = Math.floor(f / 2); - } - for (i = ebits; i; i -= 1) { - bits.push(e % 2 ? 1 : 0); - e = Math.floor(e / 2); - } - bits.push(s ? 1 : 0); - bits.reverse(); - str = bits.join(''); - - // Bits to bytes - bytes = []; - while (str.length) { - bytes.push(parseInt(str.slice(0, 8), 2)); - str = str.slice(8); - } - return bytes; + // Pack sign, exponent, fraction + bits = []; + for (i = fbits; i; i -= 1) { + bits.push(f % 2 ? 1 : 0); + f = Math.floor(f / 2); + } + for (i = ebits; i; i -= 1) { + bits.push(e % 2 ? 1 : 0); + e = Math.floor(e / 2); } + bits.push(s ? 1 : 0); + bits.reverse(); + str = bits.join(''); + + // Bits to bytes + bytes = []; + while (str.length) { + bytes.push(parseInt(str.slice(0, 8), 2)); + str = str.slice(8); + } + return bytes; + } - function unpackIEEE754(bytes, ebits, fbits) { - // Bytes to bits - var bits = [], i, j, b, str, - bias, s, e, f; + function unpackIEEE754(bytes, ebits, fbits) { + // Bytes to bits + var bits = [], i, j, b, str, + bias, s, e, f; - for (i = bytes.length; i; i -= 1) { - b = bytes[i - 1]; - for (j = 8; j; j -= 1) { - bits.push(b % 2 ? 1 : 0); - b = b >> 1; - } - } - bits.reverse(); - str = bits.join(''); - - // Unpack sign, exponent, fraction - bias = (1 << (ebits - 1)) - 1; - s = parseInt(str.slice(0, 1), 2) ? -1 : 1; - e = parseInt(str.slice(1, 1 + ebits), 2); - f = parseInt(str.slice(1 + ebits), 2); - - // Produce number - if (e === (1 << ebits) - 1) { - return f !== 0 ? NaN : s * Infinity; - } else if (e > 0) { - // Normalized - return s * Math.pow(2, e - bias) * (1 + f / Math.pow(2, fbits)); - } else if (f !== 0) { - // Denormalized - return s * Math.pow(2, -(bias - 1)) * (f / Math.pow(2, fbits)); - } else { - return s < 0 ? -0 : 0; + for (i = bytes.length; i; i -= 1) { + b = bytes[i - 1]; + for (j = 8; j; j -= 1) { + bits.push(b % 2 ? 1 : 0); + b = b >> 1; } } - - function unpackFloat64(b) { return unpackIEEE754(b, 11, 52); } - function packFloat64(v) { return packIEEE754(v, 11, 52); } - function unpackFloat32(b) { return unpackIEEE754(b, 8, 23); } - function packFloat32(v) { return packIEEE754(v, 8, 23); } - - var conversions = { - toFloat32: function (num) { return unpackFloat32(packFloat32(num)); } - }; - if (typeof Float32Array !== 'undefined') { - var float32array = new Float32Array(1); - conversions.toFloat32 = function (num) { - float32array[0] = num; - return float32array[0]; - }; + bits.reverse(); + str = bits.join(''); + + // Unpack sign, exponent, fraction + bias = (1 << (ebits - 1)) - 1; + s = parseInt(str.slice(0, 1), 2) ? -1 : 1; + e = parseInt(str.slice(1, 1 + ebits), 2); + f = parseInt(str.slice(1 + ebits), 2); + + // Produce number + if (e === (1 << ebits) - 1) { + return f !== 0 ? NaN : s * Infinity; + } else if (e > 0) { + // Normalized + return s * Math.pow(2, e - bias) * (1 + f / Math.pow(2, fbits)); + } else if (f !== 0) { + // Denormalized + return s * Math.pow(2, -(bias - 1)) * (f / Math.pow(2, fbits)); + } else { + return s < 0 ? -0 : 0; } - return conversions; - }()); + } - defineProperties(String, { - fromCodePoint: function(_) { // length = 1 - var points = _slice.call(arguments, 0, arguments.length); - var result = []; - var next; - for (var i = 0, length = points.length; i < length; i++) { - next = Number(points[i]); - if (!ES.SameValue(next, ES.ToInteger(next)) || - next < 0 || next > 0x10FFFF) { - throw new RangeError('Invalid code point ' + next); - } + function unpackFloat64(b) { return unpackIEEE754(b, 11, 52); } + function packFloat64(v) { return packIEEE754(v, 11, 52); } + function unpackFloat32(b) { return unpackIEEE754(b, 8, 23); } + function packFloat32(v) { return packIEEE754(v, 8, 23); } - if (next < 0x10000) { - result.push(String.fromCharCode(next)); - } else { - next -= 0x10000; - result.push(String.fromCharCode((next >> 10) + 0xD800)); - result.push(String.fromCharCode((next % 0x400) + 0xDC00)); - } + var conversions = { + toFloat32: function (num) { return unpackFloat32(packFloat32(num)); } + }; + if (typeof Float32Array !== 'undefined') { + var float32array = new Float32Array(1); + conversions.toFloat32 = function (num) { + float32array[0] = num; + return float32array[0]; + }; + } + return conversions; + }()); + + defineProperties(String, { + fromCodePoint: function fromCodePoint(codePoints) { + var result = []; + var next; + for (var i = 0, length = arguments.length; i < length; i++) { + next = Number(arguments[i]); + if (!ES.SameValue(next, ES.ToInteger(next)) || next < 0 || next > 0x10FFFF) { + throw new RangeError('Invalid code point ' + next); } - return result.join(''); - }, - raw: function(callSite) { // raw.length===1 - var substitutions = _slice.call(arguments, 1, arguments.length); - var cooked = ES.ToObject(callSite, 'bad callSite'); - var rawValue = cooked.raw; - var raw = ES.ToObject(rawValue, 'bad raw value'); - var len = Object.keys(raw).length; - var literalsegments = ES.ToLength(len); - if (literalsegments === 0) { - return ''; + if (next < 0x10000) { + result.push(String.fromCharCode(next)); + } else { + next -= 0x10000; + result.push(String.fromCharCode((next >> 10) + 0xD800)); + result.push(String.fromCharCode((next % 0x400) + 0xDC00)); } + } + return result.join(''); + }, + + raw: function raw(callSite) { + var cooked = ES.ToObject(callSite, 'bad callSite'); + var rawValue = cooked.raw; + var rawString = ES.ToObject(rawValue, 'bad raw value'); + var len = rawString.length; + var literalsegments = ES.ToLength(len); + if (literalsegments <= 0) { + return ''; + } - var stringElements = []; - var nextIndex = 0; - var nextKey, next, nextSeg, nextSub; - while (nextIndex < literalsegments) { - nextKey = String(nextIndex); - next = raw[nextKey]; - nextSeg = String(next); - stringElements.push(nextSeg); - if (nextIndex + 1 >= literalsegments) { - break; - } - next = substitutions[nextKey]; - if (next === undefined) { - break; - } - nextSub = String(next); - stringElements.push(nextSub); - nextIndex++; + var stringElements = []; + var nextIndex = 0; + var nextKey, next, nextSeg, nextSub; + while (nextIndex < literalsegments) { + nextKey = String(nextIndex); + next = rawString[nextKey]; + nextSeg = String(next); + stringElements.push(nextSeg); + if (nextIndex + 1 >= literalsegments) { + break; } - return stringElements.join(''); + next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : ''; + nextSub = String(next); + stringElements.push(nextSub); + nextIndex++; } - }); - - // Firefox 31 reports this function's length as 0 - // https://bugzilla.mozilla.org/show_bug.cgi?id=1062484 - if (String.fromCodePoint.length !== 1) { - var originalFromCodePoint = String.fromCodePoint; - defineProperty(String, 'fromCodePoint', function (_) { return originalFromCodePoint.apply(this, arguments); }, true); + return stringElements.join(''); } + }); - var StringShims = { - // Fast repeat, uses the `Exponentiation by squaring` algorithm. - // Perf: http://jsperf.com/string-repeat2/2 - repeat: (function() { - var repeat = function(s, times) { - if (times < 1) return ''; - if (times % 2) return repeat(s, times - 1) + s; - var half = repeat(s, times / 2); - return half + half; - }; - - return function(times) { - var thisStr = String(ES.CheckObjectCoercible(this)); |