From c39799d24b7610f3dd0f5c718ac4fce77f25db25 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 16 Jan 2016 18:31:17 +0100 Subject: udpate js client deps --- js/vendor/es6-shim/.bower.json | 8 +- js/vendor/es6-shim/CHANGELOG.md | 52 + js/vendor/es6-shim/README.md | 25 +- js/vendor/es6-shim/component.json | 2 +- js/vendor/es6-shim/es6-sham.js | 8 +- js/vendor/es6-shim/es6-sham.min.js | 4 +- js/vendor/es6-shim/es6-shim.js | 890 ++-- js/vendor/es6-shim/es6-shim.map | 2 +- js/vendor/es6-shim/es6-shim.min.js | 8 +- js/vendor/es6-shim/package.json | 54 +- js/vendor/es6-shim/testling.html | 3 +- js/vendor/jquery/.bower.json | 27 +- js/vendor/jquery/AUTHORS.txt | 275 ++ js/vendor/jquery/LICENSE.txt | 36 + js/vendor/jquery/MIT-LICENSE.txt | 21 - js/vendor/jquery/README.md | 5 + js/vendor/jquery/bower.json | 18 +- js/vendor/jquery/dist/jquery.js | 4551 +++++++++++--------- js/vendor/jquery/dist/jquery.min.js | 9 +- js/vendor/jquery/dist/jquery.min.map | 2 +- js/vendor/jquery/src/.jshintrc | 29 + js/vendor/jquery/src/ajax.js | 173 +- js/vendor/jquery/src/ajax/jsonp.js | 39 +- js/vendor/jquery/src/ajax/load.js | 32 +- js/vendor/jquery/src/ajax/parseJSON.js | 4 +- js/vendor/jquery/src/ajax/parseXML.js | 9 +- js/vendor/jquery/src/ajax/script.js | 28 +- js/vendor/jquery/src/ajax/var/location.js | 3 + js/vendor/jquery/src/ajax/var/nonce.js | 4 +- js/vendor/jquery/src/ajax/var/rquery.js | 6 +- js/vendor/jquery/src/ajax/xhr.js | 115 +- js/vendor/jquery/src/attributes.js | 4 +- js/vendor/jquery/src/attributes/attr.js | 97 +- js/vendor/jquery/src/attributes/classes.js | 153 +- js/vendor/jquery/src/attributes/prop.js | 79 +- js/vendor/jquery/src/attributes/support.js | 11 +- js/vendor/jquery/src/attributes/val.js | 65 +- js/vendor/jquery/src/callbacks.js | 201 +- js/vendor/jquery/src/core.js | 149 +- js/vendor/jquery/src/core/access.js | 17 +- js/vendor/jquery/src/core/init.js | 43 +- js/vendor/jquery/src/core/parseHTML.js | 28 +- js/vendor/jquery/src/core/ready.js | 34 +- js/vendor/jquery/src/core/support.js | 18 + js/vendor/jquery/src/core/var/rsingleTag.js | 7 +- js/vendor/jquery/src/css.js | 175 +- js/vendor/jquery/src/css/addGetHookIf.js | 8 +- js/vendor/jquery/src/css/adjustCSS.js | 65 + js/vendor/jquery/src/css/curCSS.js | 24 +- js/vendor/jquery/src/css/defaultDisplay.js | 30 +- js/vendor/jquery/src/css/hiddenVisibleSelectors.js | 15 +- js/vendor/jquery/src/css/showHide.js | 48 + js/vendor/jquery/src/css/support.js | 147 +- js/vendor/jquery/src/css/swap.js | 28 - js/vendor/jquery/src/css/var/cssExpand.js | 4 +- js/vendor/jquery/src/css/var/getStyles.js | 13 +- js/vendor/jquery/src/css/var/isHidden.js | 9 +- js/vendor/jquery/src/css/var/rmargin.js | 6 +- js/vendor/jquery/src/css/var/rnumnonpx.js | 4 +- js/vendor/jquery/src/css/var/swap.js | 24 + js/vendor/jquery/src/data.js | 89 +- js/vendor/jquery/src/data/Data.js | 167 +- js/vendor/jquery/src/data/support.js | 23 + js/vendor/jquery/src/data/var/acceptData.js | 18 + js/vendor/jquery/src/data/var/dataPriv.js | 5 + js/vendor/jquery/src/data/var/dataUser.js | 5 + js/vendor/jquery/src/data/var/data_priv.js | 5 - js/vendor/jquery/src/data/var/data_user.js | 5 - js/vendor/jquery/src/deferred.js | 59 +- js/vendor/jquery/src/deprecated.js | 35 +- js/vendor/jquery/src/dimensions.js | 14 +- js/vendor/jquery/src/effects.js | 211 +- js/vendor/jquery/src/effects/Tween.js | 21 +- js/vendor/jquery/src/effects/animatedSelector.js | 8 +- js/vendor/jquery/src/effects/support.js | 58 + js/vendor/jquery/src/event.js | 492 +-- js/vendor/jquery/src/event/ajax.js | 15 +- js/vendor/jquery/src/event/alias.js | 34 +- js/vendor/jquery/src/event/focusin.js | 53 + js/vendor/jquery/src/event/support.js | 6 +- js/vendor/jquery/src/event/trigger.js | 199 + js/vendor/jquery/src/exports/amd.js | 6 +- js/vendor/jquery/src/exports/global.js | 10 +- js/vendor/jquery/src/intro.js | 2 +- js/vendor/jquery/src/jquery.js | 10 +- js/vendor/jquery/src/manipulation.js | 519 +-- js/vendor/jquery/src/manipulation/_evalUrl.js | 10 +- js/vendor/jquery/src/manipulation/buildFragment.js | 102 + .../jquery/src/manipulation/createSafeFragment.js | 20 + js/vendor/jquery/src/manipulation/getAll.js | 21 + js/vendor/jquery/src/manipulation/setGlobalEval.js | 20 + js/vendor/jquery/src/manipulation/support.js | 13 +- js/vendor/jquery/src/manipulation/var/nodeNames.js | 5 + .../jquery/src/manipulation/var/rcheckableType.js | 6 +- .../src/manipulation/var/rleadingWhitespace.js | 3 + .../jquery/src/manipulation/var/rscriptType.js | 3 + js/vendor/jquery/src/manipulation/var/rtagName.js | 3 + js/vendor/jquery/src/manipulation/wrapMap.js | 27 + js/vendor/jquery/src/offset.js | 76 +- js/vendor/jquery/src/outro.js | 1 + js/vendor/jquery/src/queue.js | 45 +- js/vendor/jquery/src/queue/delay.js | 12 +- js/vendor/jquery/src/selector-native.js | 175 +- js/vendor/jquery/src/selector-sizzle.js | 8 +- js/vendor/jquery/src/selector.js | 2 +- js/vendor/jquery/src/serialize.js | 42 +- js/vendor/jquery/src/sizzle/dist/sizzle.js | 2067 --------- js/vendor/jquery/src/sizzle/dist/sizzle.min.js | 3 - js/vendor/jquery/src/sizzle/dist/sizzle.min.map | 1 - js/vendor/jquery/src/support.js | 63 + js/vendor/jquery/src/traversing.js | 88 +- js/vendor/jquery/src/traversing/findFilter.js | 26 +- js/vendor/jquery/src/traversing/var/dir.js | 20 + .../jquery/src/traversing/var/rneedsContext.js | 4 +- js/vendor/jquery/src/traversing/var/siblings.js | 15 + js/vendor/jquery/src/var/arr.js | 4 +- js/vendor/jquery/src/var/class2type.js | 5 +- js/vendor/jquery/src/var/concat.js | 4 +- js/vendor/jquery/src/var/deletedIds.js | 3 + js/vendor/jquery/src/var/document.js | 3 + js/vendor/jquery/src/var/documentElement.js | 5 + js/vendor/jquery/src/var/hasOwn.js | 4 +- js/vendor/jquery/src/var/indexOf.js | 4 +- js/vendor/jquery/src/var/pnum.js | 6 +- js/vendor/jquery/src/var/push.js | 4 +- js/vendor/jquery/src/var/rcssNum.js | 7 + js/vendor/jquery/src/var/rnotwhite.js | 6 +- js/vendor/jquery/src/var/slice.js | 4 +- js/vendor/jquery/src/var/strundefined.js | 3 - js/vendor/jquery/src/var/support.js | 5 +- js/vendor/jquery/src/var/toString.js | 4 +- js/vendor/jquery/src/wrap.js | 38 +- 132 files changed, 6607 insertions(+), 6400 deletions(-) create mode 100644 js/vendor/jquery/AUTHORS.txt create mode 100644 js/vendor/jquery/LICENSE.txt delete mode 100644 js/vendor/jquery/MIT-LICENSE.txt create mode 100644 js/vendor/jquery/README.md create mode 100644 js/vendor/jquery/src/.jshintrc create mode 100644 js/vendor/jquery/src/ajax/var/location.js create mode 100644 js/vendor/jquery/src/core/support.js create mode 100644 js/vendor/jquery/src/css/adjustCSS.js create mode 100644 js/vendor/jquery/src/css/showHide.js delete mode 100644 js/vendor/jquery/src/css/swap.js create mode 100644 js/vendor/jquery/src/css/var/swap.js create mode 100644 js/vendor/jquery/src/data/support.js create mode 100644 js/vendor/jquery/src/data/var/acceptData.js create mode 100644 js/vendor/jquery/src/data/var/dataPriv.js create mode 100644 js/vendor/jquery/src/data/var/dataUser.js delete mode 100644 js/vendor/jquery/src/data/var/data_priv.js delete mode 100644 js/vendor/jquery/src/data/var/data_user.js create mode 100644 js/vendor/jquery/src/effects/support.js create mode 100644 js/vendor/jquery/src/event/focusin.js create mode 100644 js/vendor/jquery/src/event/trigger.js create mode 100644 js/vendor/jquery/src/manipulation/buildFragment.js create mode 100644 js/vendor/jquery/src/manipulation/createSafeFragment.js create mode 100644 js/vendor/jquery/src/manipulation/getAll.js create mode 100644 js/vendor/jquery/src/manipulation/setGlobalEval.js create mode 100644 js/vendor/jquery/src/manipulation/var/nodeNames.js create mode 100644 js/vendor/jquery/src/manipulation/var/rleadingWhitespace.js create mode 100644 js/vendor/jquery/src/manipulation/var/rscriptType.js create mode 100644 js/vendor/jquery/src/manipulation/var/rtagName.js create mode 100644 js/vendor/jquery/src/manipulation/wrapMap.js delete mode 100644 js/vendor/jquery/src/sizzle/dist/sizzle.js delete mode 100644 js/vendor/jquery/src/sizzle/dist/sizzle.min.js delete mode 100644 js/vendor/jquery/src/sizzle/dist/sizzle.min.map create mode 100644 js/vendor/jquery/src/support.js create mode 100644 js/vendor/jquery/src/traversing/var/dir.js create mode 100644 js/vendor/jquery/src/traversing/var/siblings.js create mode 100644 js/vendor/jquery/src/var/deletedIds.js create mode 100644 js/vendor/jquery/src/var/document.js create mode 100644 js/vendor/jquery/src/var/documentElement.js create mode 100644 js/vendor/jquery/src/var/rcssNum.js delete mode 100644 js/vendor/jquery/src/var/strundefined.js diff --git a/js/vendor/es6-shim/.bower.json b/js/vendor/es6-shim/.bower.json index 00499dbf6..64bfdaef8 100644 --- a/js/vendor/es6-shim/.bower.json +++ b/js/vendor/es6-shim/.bower.json @@ -27,12 +27,12 @@ "test" ], "homepage": "https://github.com/paulmillr/es6-shim", - "version": "0.33.12", - "_release": "0.33.12", + "version": "0.34.1", + "_release": "0.34.1", "_resolution": { "type": "version", - "tag": "0.33.12", - "commit": "2fc76e7c759cbc1643722bc21132e246f935d4e1" + "tag": "0.34.1", + "commit": "2ab34d846693b4853205873e31cdc961281cb477" }, "_source": "git://github.com/paulmillr/es6-shim.git", "_target": "~0.*", diff --git a/js/vendor/es6-shim/CHANGELOG.md b/js/vendor/es6-shim/CHANGELOG.md index 244cd55d0..5a5768257 100644 --- a/js/vendor/es6-shim/CHANGELOG.md +++ b/js/vendor/es6-shim/CHANGELOG.md @@ -1,5 +1,57 @@ # es6-shim x.x.x (not yet released) +# es6-shim 0.34.1 (5 Jan 2016) +* [Fix] `RegExp#[Symbol.search]` was broken with a regex argument (#394) +* [Fix] ensure that Set#clear works with both primitive and object values +* [Fix] static Promise methods have the wrong length in Firefox +* [Robustness] Cache `Object.keys` +* [Performance] Avoid accessing arguments array without length check +* [Performance] Optimize ES.TypeIsObject (#388) +* [Performance] Promises: lots of improvements (#383) +* [Performance] Only use slow implementation of IsCallable where necessary (old browsers) +* [Performance] Promises: remove unnecessary `.bind` on `setImmediate` +* [Refactor] extract “decode fast Map key” logic +* [Dev Deps] update `s5-shim`, `@ljharb/eslint-config` +* Don’t npmignore tests +* [Tests] Fix a bug with “deep equal” wrt NaN +* [Tests] split up Map and Set test files +* [Tests] up to `node` `v5.3` + +# es6-shim 0.34.0 (14 Dec 2015) +* [Breaking] Remove `Symbol.species` from `Promise.all` and `Promise.race` (#34) +* [Fix] Firefox has enumerable Promise static methods +* [Fix] prevent crashes in older Firefox when checking if Array methods ToLength correctly +* [Fix] `Reflect.enumerate`: ensure correct property ordering in Firefox 19 (and likely others) +* [Fix] Ensure that `toLengthsCorrectly` returns `true` when it passes, instead of `undefined` +* [Fix] Don't call `Reflect.construct` unless it's actually present +* [Fix] Ensure `Map` and `Set` do not have an own `constructor` property (#368) +* [Fix] Add missing checks to Promise.resolve and Promise.reject (#379) +* [Fix] `Map`: older v8s have a SameValueZero bug when a Map has a size > 4 (#378) +* [Fix] `Map`: when provided with an iterable that yields non-Object values, should throw +* [Fix] `Promise`: Make sure to shim broken implementations in Chrome 49 Canary +* [Fix] `Promise`: Chrome does not retrieve a thenable's .then synchronously (#372) +* [New] Add `RegExp.prototype[Symbol.{match,search,split,replace}]` +* [New] support `Symbol.match` in `RegExp` constructor +* [New] add `Symbol.match` and ensure `String#{match, startsWith, endsWith, includes}` support it +* [New] add `Symbol.split` and ensure `String#split` supports it +* [New] add `Symbol.replace` and ensure `String#replace` supports it +* [New] add `Symbol.search` and ensure `String#search` supports it +* [Robustness] Add and use `ES.ToString` so as not to rely on the global `String` +* [Dev Deps] update `eslint`, `jscs`, `mocha`, `uglify-js`, `es5-shim`, `grunt-saucelabs` +* [Tests] bailing out of some tests when the feature isn't present, to clean up native test failure output +* [Tests] up to `node` `v5.2` +* [Tests] fix `npm run test:native` +* [Tests] Ensure `Promise.{reject,resolve}` throws when the receiver is a primitive (#379) +* [Tests] Further ensure that Promise.resolve/reject work with a non-promise receiver (#379) +* [Docs] update README URLs (#375) +* [Docs] fix some typos (#380) + +# es6-shim 0.33.13 (12 Nov 2015) +* [Fix] `Number`: when no arguments are passed, return `+0`. +* [Fix] `Number`: Make sure string values are trimmed before attempting to parse. +* [Tests] cleaning up `Number` tests) +* [Dev Deps] update `uglify-js` + # es6-shim 0.33.12 (11 Nov 2015) * [Fix] IE 8: more NFE madness. * [Dev Deps] update `es5-shim` diff --git a/js/vendor/es6-shim/README.md b/js/vendor/es6-shim/README.md index 5a0955674..6d37667ba 100644 --- a/js/vendor/es6-shim/README.md +++ b/js/vendor/es6-shim/README.md @@ -21,7 +21,7 @@ For `node.js`, `io.js`, or any `npm`-managed workflow (this is the recommended m npm install es6-shim Alternative methods: -* `component install paulmillr/es6-shim` if you’re using [component(1)](https://github.com/component/component). +* `component install paulmillr/es6-shim` if you’re using [component(1)](https://github.com/componentjs/component). * `bower install es6-shim` if you’re using [Bower](http://bower.io/). In both browser and node you may also want to include `unorm`; see the [`String.prototype.normalize`](#stringprototypenormalize) section for details. @@ -43,20 +43,24 @@ In both browser and node you may also want to include `unorm`; see the [`String. * `new RegExp`, when given a RegExp as the pattern, will no longer throw when given a "flags" string argument. (requires ES5) * `RegExp.prototype`: * `flags` (requires ES5) ([a standalone shim is also available](https://github.com/es-shims/RegExp.prototype.flags)) + * `[Symbol.match]` (requires native `Symbol`s) + * `[Symbol.replace]` (requires native `Symbol`s) + * `[Symbol.search]` (requires native `Symbol`s) + * `[Symbol.split]` (requires native `Symbol`s) * `Number`: * binary and octal literals: `Number('0b1')` and `Number('0o7')` * `EPSILON` * `MAX_SAFE_INTEGER` * `MIN_SAFE_INTEGER` - * `isNaN()`([a standalone shim is also available](https://npmjs.org/package/is-nan)) + * `isNaN()`([a standalone shim is also available](https://www.npmjs.com/package/is-nan)) * `isInteger()` * `isSafeInteger()` * `isFinite()` * `parseInt()` * `parseFloat()` * `Array`: - * `from()` ([a standalone shim is also available](https://npmjs.org/package/array.from)) - * `of()` ([a standalone shim is also available](https://npmjs.org/package/array.of)) + * `from()` ([a standalone shim is also available](https://www.npmjs.com/package/array.from)) + * `of()` ([a standalone shim is also available](https://www.npmjs.com/package/array.of)) * `Array.prototype`: * `copyWithin()` * `entries()` @@ -107,8 +111,15 @@ Math functions’ accuracy is 1e-11. * `set()` * `setPrototypeOf()` +* `Symbol` (only if it already exists) + * `match` (and corresponding `String#match`, `String#startsWith`, `String#endsWith`, `String#includes`, `RegExp` support) + * `replace` (and corresponding `String#replace` support) + * `search` (and corresponding `String#search` support) + * `split` (and corresponding `String#split` support) + +Well-known symbols will only be provided if the engine already has `Symbol` support. + * `String.prototype` Annex B HTML methods -These methods are part of "Annex B", which means that although they are a defacto standard, you shouldn't use them. None the less, the `es6-shim` provides them: * `anchor()` * `big()` * `blink()` @@ -123,6 +134,8 @@ These methods are part of "Annex B", which means that although they are a defact * `sub()` * `sup()` +These methods are part of "Annex B", which means that although they are a defacto standard, you shouldn't use them. None the less, the `es6-shim` provides them and normalizes their behavior across browsers. + ## Subclassing The `Map`, `Set`, and `Promise` implementations are subclassable. You should use the following pattern to create a subclass in ES5 which will continue to work in ES6: @@ -237,6 +250,8 @@ Promise.resolve(5).then(function (value) { - `Object.setPrototypeOf` / `Reflect.setPrototypeOf` - Note that null objects (`Object.create(null)`, eg, an object with `null` as its `[[Prototype]]`) can not have their `[[Prototype]]` changed except via a native `Object.setPrototypeOf`. + - Well-known `Symbol`s + - In order to make them work cross-realm, these are created with the global `Symbol` registry via `Symbol.for`. This does not violate the spec, but it does mean that `Symbol.for('Symbol.search') === Symbol.search` will be `true`, which it would not by default in a fresh compliant realm. ## [License][license-url] diff --git a/js/vendor/es6-shim/component.json b/js/vendor/es6-shim/component.json index c0f5fbcd0..c971adf1d 100644 --- a/js/vendor/es6-shim/component.json +++ b/js/vendor/es6-shim/component.json @@ -1,6 +1,6 @@ { "name": "es6-shim", - "version": "0.33.12", + "version": "0.34.1", "repo": "paulmillr/es6-shim", "description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines", "keywords": [ diff --git a/js/vendor/es6-shim/es6-sham.js b/js/vendor/es6-shim/es6-sham.js index 65f0f5cc6..7e49121ae 100644 --- a/js/vendor/es6-shim/es6-sham.js +++ b/js/vendor/es6-shim/es6-sham.js @@ -2,8 +2,8 @@ * https://github.com/paulmillr/es6-shim * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com) * and contributors, MIT License - * es6-sham: v0.33.12 - * see https://github.com/paulmillr/es6-shim/blob/0.33.12/LICENSE + * es6-sham: v0.34.1 + * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE * Details and documentation: * https://github.com/paulmillr/es6-shim/ */ @@ -17,7 +17,7 @@ define(factory); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but - // only CommonJS-like enviroments that support module.exports, + // only CommonJS-like environments that support module.exports, // like Node. module.exports = factory(); } else { @@ -37,7 +37,7 @@ var Object = globals.Object; // NOTE: This versions needs object ownership - // beacuse every promoted object needs to be reassigned + // because every promoted object needs to be reassigned // otherwise uncompatible browsers cannot work as expected // // NOTE: This might need es5-shim or polyfills upfront diff --git a/js/vendor/es6-shim/es6-sham.min.js b/js/vendor/es6-shim/es6-sham.min.js index a0f862efe..1dda0d0ec 100644 --- a/js/vendor/es6-shim/es6-sham.min.js +++ b/js/vendor/es6-shim/es6-sham.min.js @@ -2,8 +2,8 @@ * https://github.com/paulmillr/es6-shim * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com) * and contributors, MIT License - * es6-sham: v0.33.12 - * see https://github.com/paulmillr/es6-shim/blob/0.33.12/LICENSE + * es6-sham: v0.34.1 + * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE * Details and documentation: * https://github.com/paulmillr/es6-shim/ */ diff --git a/js/vendor/es6-shim/es6-shim.js b/js/vendor/es6-shim/es6-shim.js index d1d052fe3..f6058ae2d 100644 --- a/js/vendor/es6-shim/es6-shim.js +++ b/js/vendor/es6-shim/es6-shim.js @@ -2,8 +2,8 @@ * https://github.com/paulmillr/es6-shim * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com) * and contributors, MIT License - * es6-shim: v0.33.12 - * see https://github.com/paulmillr/es6-shim/blob/0.33.12/LICENSE + * es6-shim: v0.34.1 + * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE * Details and documentation: * https://github.com/paulmillr/es6-shim/ */ @@ -17,7 +17,7 @@ define(factory); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but - // only CommonJS-like enviroments that support module.exports, + // only CommonJS-like environments that support module.exports, // like Node. module.exports = factory(); } else { @@ -30,6 +30,7 @@ var _apply = Function.call.bind(Function.apply); var _call = Function.call.bind(Function.call); var isArray = Array.isArray; + var keys = Object.keys; var not = function notThunker(func) { return function notThunk() { return !_apply(func, this, arguments); }; @@ -79,13 +80,65 @@ // Define configurable, writable and non-enumerable props // if they don’t exist. - var defineProperties = function (object, map) { - _forEach(Object.keys(map), function (name) { + var defineProperties = function (object, map, forceOverride) { + _forEach(keys(map), function (name) { var method = map[name]; - defineProperty(object, name, method, false); + defineProperty(object, name, method, !!forceOverride); }); }; + var _toString = Function.call.bind(Object.prototype.toString); + var isCallable = typeof /abc/ === 'function' ? function IsCallableSlow(x) { + // Some old browsers (IE, FF) say that typeof /abc/ === 'function' + return typeof x === 'function' && _toString(x) === '[object Function]'; + } : function IsCallableFast(x) { return typeof x === 'function'; }; + + var Value = { + getter: function (object, name, getter) { + if (!supportsDescriptors) { + throw new TypeError('getters require true ES5 support'); + } + 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'); + } + 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; + } + }, + defineByDescriptor: function (object, property, descriptor) { + if (supportsDescriptors) { + Object.defineProperty(object, property, descriptor); + } else if ('value' in descriptor) { + object[property] = descriptor.value; + } + }, + preserveToString: function (target, source) { + if (source && isCallable(source.toString)) { + defineProperty(target, 'toString', source.toString.bind(source), true); + } + } + }; + // Simple shim for Object.create on ES3 browsers // (unlike real shim, no attempt to support `prototype === null`) var create = Object.create || function (prototype, properties) { @@ -93,7 +146,7 @@ Prototype.prototype = prototype; var object = new Prototype(); if (typeof properties !== 'undefined') { - Object.keys(properties).forEach(function (key) { + keys(properties).forEach(function (key) { Value.defineByDescriptor(object, key, properties[key]); }); } @@ -130,8 +183,8 @@ var globals = getGlobal(); var globalIsFinite = globals.isFinite; var _indexOf = Function.call.bind(String.prototype.indexOf); - var _toString = Function.call.bind(Object.prototype.toString); var _concat = Function.call.bind(Array.prototype.concat); + var _sort = Function.call.bind(Array.prototype.sort); var _strSlice = Function.call.bind(String.prototype.slice); var _push = Function.call.bind(Array.prototype.push); var _pushApply = Function.apply.bind(Array.prototype.push); @@ -186,6 +239,14 @@ } }; + var overrideNative = function overrideNative(object, property, replacement) { + var original = object[property]; + defineProperty(object, property, replacement, true); + Value.preserveToString(object[property], original); + }; + + var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && Type.symbol(Symbol()); + // 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 @@ -205,6 +266,8 @@ } var Reflect = globals.Reflect; + var $String = String; + var ES = { // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args Call: function Call(F, V) { @@ -220,24 +283,30 @@ if (x == null) { throw new TypeError(optMessage || 'Cannot call method on ' + x); } + return x; }, + // This might miss the "(non-standard exotic and does not implement + // [[Call]])" case from + // http://www.ecma-international.org/ecma-262/6.0/#sec-typeof-operator-runtime-semantics-evaluation + // but we can't find any evidence these objects exist in practice. + // If we find some in the future, you could test `Object(x) === x`, + // which is reliable according to + // http://www.ecma-international.org/ecma-262/6.0/#sec-toobject + // but is not well optimized by runtimes and creates an object + // whenever it returns false, and thus is very slow. 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; + if (x === void 0 || x === null || x === true || x === false) { + return false; + } + return typeof x === 'function' || typeof x === 'object'; }, ToObject: function (o, optMessage) { - ES.RequireObjectCoercible(o, optMessage); - return Object(o); + return Object(ES.RequireObjectCoercible(o, optMessage)); }, - IsCallable: function (x) { - // some versions of IE say that typeof /abc/ === 'function' - return typeof x === 'function' && _toString(x) === '[object Function]'; - }, + IsCallable: isCallable, IsConstructor: function (x) { // We can't tell callables from constructors in ES5 @@ -301,7 +370,7 @@ // Better diagnostics if itFn is null or undefined throw new TypeError('value is not an iterable'); } - var it = _call(itFn, o); + var it = ES.Call(itFn, o); if (!ES.TypeIsObject(it)) { throw new TypeError('bad iterator'); } @@ -330,7 +399,7 @@ } var innerResult, innerException; try { - innerResult = _call(returnMethod, iterator); + innerResult = ES.Call(returnMethod, iterator); } catch (e) { innerException = e; } @@ -362,7 +431,7 @@ Construct: function (C, args, newTarget, isES6internal) { var target = typeof newTarget === 'undefined' ? C : newTarget; - if (!isES6internal) { + if (!isES6internal && Reflect.construct) { // Try to use Reflect.construct if available return Reflect.construct(C, args, target); } @@ -400,64 +469,132 @@ }, CreateHTML: function (string, tag, attribute, value) { - var S = String(string); + var S = ES.ToString(string); var p1 = '<' + tag; if (attribute !== '') { - var V = String(value); + var V = ES.ToString(value); var escapedV = V.replace(/"/g, '"'); p1 += ' ' + attribute + '="' + escapedV + '"'; } var p2 = p1 + '>'; var p3 = p2 + S; return p3 + ''; + }, + + IsRegExp: function IsRegExp(argument) { + if (!ES.TypeIsObject(argument)) { + return false; + } + var isRegExp = argument[Symbol.match]; + if (typeof isRegExp !== 'undefined') { + return !!isRegExp; + } + return Type.regex(argument); + }, + + ToString: function ToString(string) { + return $String(string); } }; - var Value = { - getter: function (object, name, getter) { - if (!supportsDescriptors) { - throw new TypeError('getters require true ES5 support'); + // Well-known Symbol shims + if (supportsDescriptors && hasSymbols) { + var defineWellKnownSymbol = function defineWellKnownSymbol(name) { + if (Type.symbol(Symbol[name])) { + return Symbol[name]; } - Object.defineProperty(object, name, { - configurable: true, + var sym = Symbol['for']('Symbol.' + name); + Object.defineProperty(Symbol, name, { + configurable: false, enumerable: false, - get: getter + writable: false, + value: sym }); - }, - proxy: function (originalObject, key, targetObject) { - if (!supportsDescriptors) { - throw new TypeError('getters require true ES5 support'); - } - 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; } + return sym; + }; + if (!Type.symbol(Symbol.search)) { + var symbolSearch = defineWellKnownSymbol('search'); + var originalSearch = String.prototype.search; + defineProperty(RegExp.prototype, symbolSearch, function search(string) { + return ES.Call(originalSearch, string, [this]); }); - }, - 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; - } - }, - defineByDescriptor: function (object, property, descriptor) { - if (supportsDescriptors) { - Object.defineProperty(object, property, descriptor); - } else if ('value' in descriptor) { - object[property] = descriptor.value; - } - }, - preserveToString: function (target, source) { - if (source && ES.IsCallable(source.toString)) { - defineProperty(target, 'toString', source.toString.bind(source), true); - } + var searchShim = function search(regexp) { + var O = ES.RequireObjectCoercible(this); + if (regexp !== null && typeof regexp !== 'undefined') { + var searcher = ES.GetMethod(regexp, symbolSearch); + if (typeof searcher !== 'undefined') { + return ES.Call(searcher, regexp, [O]); + } + } + return ES.Call(originalSearch, O, [ES.ToString(regexp)]); + }; + overrideNative(String.prototype, 'search', searchShim); } - }; + if (!Type.symbol(Symbol.replace)) { + var symbolReplace = defineWellKnownSymbol('replace'); + var originalReplace = String.prototype.replace; + defineProperty(RegExp.prototype, symbolReplace, function replace(string, replaceValue) { + return ES.Call(originalReplace, string, [this, replaceValue]); + }); + var replaceShim = function replace(searchValue, replaceValue) { + var O = ES.RequireObjectCoercible(this); + if (searchValue !== null && typeof searchValue !== 'undefined') { + var replacer = ES.GetMethod(searchValue, symbolReplace); + if (typeof replacer !== 'undefined') { + return ES.Call(replacer, searchValue, [O, replaceValue]); + } + } + return ES.Call(originalReplace, O, [ES.ToString(searchValue), replaceValue]); + }; + overrideNative(String.prototype, 'replace', replaceShim); + } + if (!Type.symbol(Symbol.split)) { + var symbolSplit = defineWellKnownSymbol('split'); + var originalSplit = String.prototype.split; + defineProperty(RegExp.prototype, symbolSplit, function split(string, limit) { + return ES.Call(originalSplit, string, [this, limit]); + }); + var splitShim = function split(separator, limit) { + var O = ES.RequireObjectCoercible(this); + if (separator !== null && typeof separator !== 'undefined') { + var splitter = ES.GetMethod(separator, symbolSplit); + if (typeof splitter !== 'undefined') { + return ES.Call(splitter, separator, [O, limit]); + } + } + return ES.Call(originalSplit, O, [ES.ToString(separator), limit]); + }; + overrideNative(String.prototype, 'split', splitShim); + } + var symbolMatchExists = Type.symbol(Symbol.match); + var stringMatchIgnoresSymbolMatch = symbolMatchExists && (function () { + // Firefox 41, through Nightly 45 has Symbol.match, but String#match ignores it. + // Firefox 40 and below have Symbol.match but String#match works fine. + var o = {}; + o[Symbol.match] = function () { return 42; }; + return 'a'.match(o) !== 42; + }()); + if (!symbolMatchExists || stringMatchIgnoresSymbolMatch) { + var symbolMatch = defineWellKnownSymbol('match'); + + var originalMatch = String.prototype.match; + defineProperty(RegExp.prototype, symbolMatch, function match(string) { + return ES.Call(originalMatch, string, [this]); + }); + + var matchShim = function match(regexp) { + var O = ES.RequireObjectCoercible(this); + if (regexp !== null && typeof regexp !== 'undefined') { + var matcher = ES.GetMethod(regexp, symbolMatch); + if (typeof matcher !== 'undefined') { + return ES.Call(matcher, regexp, [O]); + } + } + return ES.Call(originalMatch, O, [ES.ToString(regexp)]); + }; + overrideNative(String.prototype, 'match', matchShim); + } + } var wrapConstructor = function wrapConstructor(original, replacement, keysToSkip) { Value.preserveToString(replacement, original); @@ -487,12 +624,6 @@ } }; - var overrideNative = function overrideNative(object, property, replacement) { - var original = object[property]; - defineProperty(object, property, replacement, true); - Value.preserveToString(object[property], original); - }; - var addIterator = function (prototype, impl) { var implementation = impl || function iterator() { return this; }; defineProperty(prototype, $iterator$, implementation); @@ -553,7 +684,7 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=1062484 if (String.fromCodePoint && String.fromCodePoint.length !== 1) { var originalFromCodePoint = String.fromCodePoint; - overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return _apply(originalFromCodePoint, this, arguments); }); + overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) { return ES.Call(originalFromCodePoint, this, arguments); }); } var StringShims = { @@ -590,14 +721,14 @@ var nextIndex = 0; var nextKey, next, nextSeg, nextSub; while (nextIndex < literalsegments) { - nextKey = String(nextIndex); - nextSeg = String(rawString[nextKey]); + nextKey = ES.ToString(nextIndex); + nextSeg = ES.ToString(rawString[nextKey]); _push(stringElements, nextSeg); if (nextIndex + 1 >= literalsegments) { break; } next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : ''; - nextSub = String(next); + nextSub = ES.ToString(next); _push(stringElements, nextSub); nextIndex += 1; } @@ -622,8 +753,7 @@ var StringPrototypeShims = { repeat: function repeat(times) { - ES.RequireObjectCoercible(this); - var thisStr = String(this); + var thisStr = ES.ToString(ES.RequireObjectCoercible(this)); var numTimes = ES.ToInteger(times); if (numTimes < 0 || numTimes >= stringMaxLength) { throw new RangeError('repeat count must be less than infinity and not overflow maximum string size'); @@ -632,46 +762,50 @@ }, startsWith: function startsWith(searchString) { - ES.RequireObjectCoercible(this); - var thisStr = String(this); - if (Type.regex(searchString)) { + var S = ES.ToString(ES.RequireObjectCoercible(this)); + if (ES.IsRegExp(searchString)) { throw new TypeError('Cannot call method "startsWith" with a regex'); } - var searchStr = String(searchString); - var startArg = arguments.length > 1 ? arguments[1] : void 0; - var start = _max(ES.ToInteger(startArg), 0); - return _strSlice(thisStr, start, start + searchStr.length) === searchStr; + var searchStr = ES.ToString(searchString); + var position; + if (arguments.length > 1) { + position = arguments[1]; + } + var start = _max(ES.ToInteger(position), 0); + return _strSlice(S, start, start + searchStr.length) === searchStr; }, endsWith: function endsWith(searchString) { - ES.RequireObjectCoercible(this); - var thisStr = String(this); - if (Type.regex(searchString)) { + var S = ES.ToString(ES.RequireObjectCoercible(this)); + if (ES.IsRegExp(searchString)) { throw new TypeError('Cannot call method "endsWith" with a regex'); } - var searchStr = String(searchString); - var thisLen = thisStr.length; - var posArg = arguments.length > 1 ? arguments[1] : void 0; - var pos = typeof posArg === 'undefined' ? thisLen : ES.ToInteger(posArg); - var end = _min(_max(pos, 0), thisLen); - return _strSlice(thisStr, end - searchStr.length, end) === searchStr; + var searchStr = ES.ToString(searchString); + var len = S.length; + var endPosition; + if (arguments.length > 1) { + endPosition = arguments[1]; + } + var pos = typeof endPosition === 'undefined' ? len : ES.ToInteger(endPosition); + var end = _min(_max(pos, 0), len); + return _strSlice(S, end - searchStr.length, end) === searchStr; }, includes: function includes(searchString) { - if (Type.regex(searchString)) { + if (ES.IsRegExp(searchString)) { throw new TypeError('"includes" does not accept a RegExp'); } + var searchStr = ES.ToString(searchString); var position; if (arguments.length > 1) { position = arguments[1]; } // Somehow this trick makes method 100% compat with the spec. - return _indexOf(this, searchString, position) !== -1; + return _indexOf(this, searchStr, position) !== -1; }, codePointAt: function codePointAt(pos) { - ES.RequireObjectCoercible(this); - var thisStr = String(this); + var thisStr = ES.ToString(ES.RequireObjectCoercible(this)); var position = ES.ToInteger(pos); var length = thisStr.length; if (position >= 0 && position < length) { @@ -700,6 +834,32 @@ overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith); } } + if (hasSymbols) { + var startsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () { + var re = /a/; + re[Symbol.match] = false; + return '/a/'.startsWith(re); + }); + if (!startsWithSupportsSymbolMatch) { + overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith); + } + var endsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () { + var re = /a/; + re[Symbol.match] = false; + return '/a/'.endsWith(re); + }); + if (!endsWithSupportsSymbolMatch) { + overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith); + } + var includesSupportsSymbolMatch = valueOrFalseIfThrows(function () { + var re = /a/; + re[Symbol.match] = false; + return '/a/'.includes(re); + }); + if (!includesSupportsSymbolMatch) { + overrideNative(String.prototype, 'includes', StringPrototypeShims.includes); + } + } defineProperties(String.prototype, StringPrototypeShims); @@ -712,10 +872,7 @@ ].join(''); var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g'); var trimShim = function trim() { - if (typeof this === 'undefined' || this === null) { - throw new TypeError("can't convert " + this + ' to object'); - } - return String(this).replace(trimRegexp, ''); + return ES.ToString(ES.RequireObjectCoercible(this)).replace(trimRegexp, ''); }; var nonWS = ['\u0085', '\u200b', '\ufffe'].join(''); var nonWSregex = new RegExp('[' + nonWS + ']', 'g'); @@ -726,7 +883,7 @@ // see https://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype-@@iterator var StringIterator = function (s) { ES.RequireObjectCoercible(s); - this._s = String(s); + this._s = ES.ToString(s); this._i = 0; }; StringIterator.prototype.next = function () { @@ -753,15 +910,20 @@ var ArrayShims = { from: function from(items) { var C = this; - var mapFn = arguments.length > 1 ? arguments[1] : void 0; + var mapFn; + if (arguments.length > 1) { + mapFn = arguments[1]; + } var mapping, T; - if (mapFn === void 0) { + if (typeof mapFn === 'undefined') { mapping = false; } else { if (!ES.IsCallable(mapFn)) { throw new TypeError('Array.from: when provided, the second argument must be a function'); } - T = arguments.length > 2 ? arguments[2] : void 0; + if (arguments.length > 2) { + T = arguments[2]; + } mapping = true; } @@ -784,7 +946,7 @@ nextValue = next.value; try { if (mapping) { - nextValue = T === undefined ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i); + nextValue = typeof T === 'undefined' ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i); } result[i] = nextValue; } catch (e) { @@ -802,7 +964,7 @@ for (i = 0; i < length; ++i) { value = arrayLike[i]; if (mapping) { - value = T !== undefined ? _call(mapFn, T, value, i) : mapFn(value, i); + value = typeof T === 'undefined' ? mapFn(value, i) : _call(mapFn, T, value, i); } result[i] = value; } @@ -869,14 +1031,30 @@ }); addIterator(ArrayIterator.prototype); + var orderKeys = function orderKeys(a, b) { + var aNumeric = String(ES.ToInteger(a)) === a; + var bNumeric = String(ES.ToInteger(b)) === b; + if (aNumeric && bNumeric) { + return b - a; + } else if (aNumeric && !bNumeric) { + return -1; + } else if (!aNumeric && bNumeric) { + return 1; + } else { + return a.localeCompare(b); + } + }; var getAllKeys = function getAllKeys(object) { + var ownKeys = []; var keys = []; for (var key in object) { - _push(keys, key); + _push(_hasOwnProperty(object, key) ? ownKeys : keys, key); } + _sort(ownKeys, orderKeys); + _sort(keys, orderKeys); - return keys; + return _concat(ownKeys, keys); }; var ObjectIterator = function (object, kind) { @@ -935,16 +1113,19 @@ var ArrayPrototypeShims = { copyWithin: function copyWithin(target, start) { - var end = arguments[2]; // copyWithin.length must be 2 var o = ES.ToObject(this); var len = ES.ToLength(o.length); var relativeTarget = ES.ToInteger(target); var relativeStart = ES.ToInteger(start); var to = relativeTarget < 0 ? _max(len + relativeTarget, 0) : _min(relativeTarget, len); var from = relativeStart < 0 ? _max(len + relativeStart, 0) : _min(relativeStart, len); - end = typeof end === 'undefined' ? len : ES.ToInteger(end); - var fin = end < 0 ? _max(len + end, 0) : _min(end, len); - var count = _min(fin - from, len - to); + var end; + if (arguments.length > 2) { + end = arguments[2]; + } + var relativeEnd = typeof end === 'undefined' ? len : ES.ToInteger(end); + var finalItem = relativeEnd < 0 ? _max(len + relativeEnd, 0) : _min(relativeEnd, len); + var count = _min(finalItem - from, len - to); var direction = 1; if (from < to && to < (from + count)) { direction = -1; @@ -965,8 +1146,14 @@ }, fill: function fill(value) { - var start = arguments.length > 1 ? arguments[1] : void 0; - var end = arguments.length > 2 ? arguments[2] : void 0; + var start; + if (arguments.length > 1) { + start = arguments[1]; + } + var end; + if (arguments.length > 2) { + end = arguments[2]; + } var O = ES.ToObject(this); var len = ES.ToLength(O.length); start = ES.ToInteger(typeof start === 'undefined' ? 0 : start); @@ -1048,7 +1235,7 @@ // Chrome 40 defines Array#values with the incorrect name, although Array#{keys,entries} have the correct name if (functionsHaveNames && Array.prototype.values && Array.prototype.values.name !== 'values') { var originalArrayPrototypeValues = Array.prototype.values; - overrideNative(Array.prototype, 'values', function values() { return _call(originalArrayPrototypeValues, this); }); + overrideNative(Array.prototype, 'values', function values() { return ES.Call(originalArrayPrototypeValues, this, arguments); }); defineProperty(Array.prototype, $iterator$, Array.prototype.values, true); } defineProperties(Array.prototype, ArrayPrototypeShims); @@ -1077,70 +1264,72 @@ var arrayFromHandlesUndefinedMapFunction = (function () { // Microsoft Edge v0.11 throws if the mapFn argument is *provided* but undefined, // but the spec doesn't care if it's provided or not - undefined doesn't throw. - return valueOrFalseIfThrows(function () { return Array.from([0], undefined); }); + return valueOrFalseIfThrows(function () { return Array.from([0], void 0); }); }()); if (!arrayFromHandlesUndefinedMapFunction) { var origArrayFrom = Array.from; overrideNative(Array, 'from', function from(items) { - if (arguments.length > 0 && typeof arguments[1] !== 'undefined') { - return _apply(origArrayFrom, this, arguments); + if (arguments.length > 1 && typeof arguments[1] !== 'undefined') { + return ES.Call(origArrayFrom, this, arguments); } else { return _call(origArrayFrom, this, items); } }); } + var int32sAsOne = -(Math.pow(2, 32) - 1); var toLengthsCorrectly = function (method, reversed) { - var obj = { length: -1 }; - obj[reversed ? ((-1 >>> 0) - 1) : 0] = true; + var obj = { length: int32sAsOne }; + obj[reversed ? ((obj.length >>> 0) - 1) : 0] = true; return valueOrFalseIfThrows(function () { _call(method, obj, function () { // note: in nonconforming browsers, this will be called // -1 >>> 0 times, which is 4294967295, so the throw matters. throw new RangeError('should not reach here'); }, []); + return true; }); }; if (!toLengthsCorrectly(Array.prototype.forEach)) { var originalForEach = Array.prototype.forEach; overrideNative(Array.prototype, 'forEach', function forEach(callbackFn) { - return _apply(originalForEach, this.length >= 0 ? this : [], arguments); + return ES.Call(originalForEach, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.map)) { var originalMap = Array.prototype.map; overrideNative(Array.prototype, 'map', function map(callbackFn) { - return _apply(originalMap, this.length >= 0 ? this : [], arguments); + return ES.Call(originalMap, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.filter)) { var originalFilter = Array.prototype.filter; overrideNative(Array.prototype, 'filter', function filter(callbackFn) { - return _apply(originalFilter, this.length >= 0 ? this : [], arguments); + return ES.Call(originalFilter, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.some)) { var originalSome = Array.prototype.some; overrideNative(Array.prototype, 'some', function some(callbackFn) { - return _apply(originalSome, this.length >= 0 ? this : [], arguments); + return ES.Call(originalSome, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.every)) { var originalEvery = Array.prototype.every; overrideNative(Array.prototype, 'every', function every(callbackFn) { - return _apply(originalEvery, this.length >= 0 ? this : [], arguments); + return ES.Call(originalEvery, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.reduce)) { var originalReduce = Array.prototype.reduce; overrideNative(Array.prototype, 'reduce', function reduce(callbackFn) { - return _apply(originalReduce, this.length >= 0 ? this : [], arguments); + return ES.Call(originalReduce, this.length >= 0 ? this : [], arguments); }, true); } if (!toLengthsCorrectly(Array.prototype.reduceRight, true)) { var originalReduceRight = Array.prototype.reduceRight; overrideNative(Array.prototype, 'reduceRight', function reduceRight(callbackFn) { - return _apply(originalReduceRight, this.length >= 0 ? this : [], arguments); + return ES.Call(originalReduceRight, this.length >= 0 ? this : [], arguments); }, true); } @@ -1177,16 +1366,20 @@ var NumberShim = (function () { // this is wrapped in an IIFE because of IE 6-8's wacky scoping issues with named function expressions. var NumberShim = function Number(value) { - var primValue = Type.primitive(value) ? value : toPrimitive(value, 'number'); + var primValue; + if (arguments.length > 0) { + primValue = Type.primitive(value) ? value : toPrimitive(value, 'number'); + } else { + primValue = 0; + } if (typeof primValue === 'string') { + primValue = ES.Call(trimShim, primValue); if (isBinary(primValue)) { primValue = parseInt(_strSlice(primValue, 2), 2); } else if (isOctal(primValue)) { primValue = parseInt(_strSlice(primValue, 2), 8); } else if (hasNonWS(primValue) || isBadHex(primValue)) { primValue = NaN; - } else { - primValue = _call(trimShim, primValue); } } var receiver = this; @@ -1252,6 +1445,11 @@ /*jshint elision: false */ var isEnumerableOn = Function.bind.call(Function.bind, Object.prototype.propertyIsEnumerable); + var ensureEnumerable = function ensureEnumerable(obj, prop) { + if (supportsDescriptors && isEnumerableOn(obj, prop)) { + Object.defineProperty(obj, prop, { enumerable: false }); + } + }; var sliceArgs = function sliceArgs() { // per https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments // and https://gist.github.com/WebReflection/4327762cb87a8c634a29 @@ -1271,19 +1469,19 @@ }; }; var assignReducer = function (target, source) { - var keys = Object.keys(Object(source)); + var sourceKeys = keys(Object(source)); var symbols; if (ES.IsCallable(Object.getOwnPropertySymbols)) { symbols = _filter(Object.getOwnPropertySymbols(Object(source)), isEnumerableOn(source)); } - return _reduce(_concat(keys, symbols || []), assignTo(source), target); + return _reduce(_concat(sourceKeys, symbols || []), assignTo(source), target); }; var ObjectShims = { // 19.1.3.1 assign: function (target, source) { var to = ES.ToObject(target, 'Cannot convert undefined or null to object'); - return _reduce(_apply(sliceArgs, 1, arguments), assignReducer, to); + return _reduce(ES.Call(sliceArgs, 1, arguments), assignReducer, to); }, // Added in WebKit in https://bugs.webkit.org/show_bug.cgi?id=143865 @@ -1391,6 +1589,7 @@ overrideNative(Object, 'keys', function keys(value) { return originalObjectKeys(ES.ToObject(value)); }); + keys = Object.keys; } if (Object.getOwnPropertyNames) { @@ -1522,20 +1721,40 @@ Value.getter(RegExp.prototype, 'flags', regExpFlagsGetter); } - var regExpSupportsFlagsWithRegex = valueOrFalseIfThrows(function () { + var regExpSupportsFlagsWithRegex = supportsDescriptors && valueOrFalseIfThrows(function () { return String(new RegExp(/a/g, 'i')) === '/a/i'; }); + var regExpNeedsToSupportSymbolMatch = hasSymbols && supportsDescriptors && (function () { + // Edge 0.12 supports flags fully, but does not support Symbol.match + var regex = /./; + regex[Symbol.match] = false; + return RegExp(regex) === regex; + }()); + + if (supportsDescriptors && (!regExpSupportsFlagsWithRegex || regExpNeedsToSupportSymbolMatch)) { + var flagsGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + var sourceDesc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source') || {}; + var legacySourceGetter = function () { return this.source; }; // prior to it being a getter, it's own + nonconfigurable + var sourceGetter = ES.IsCallable(sourceDesc.get) ? sourceDesc.get : legacySourceGetter; - if (!regExpSupportsFlagsWithRegex && supportsDescriptors) { var OrigRegExp = RegExp; var RegExpShim = (function () { return function RegExp(pattern, flags) { + var patternIsRegExp = ES.IsRegExp(pattern); var calledWithNew = this instanceof RegExp; - if (!calledWithNew && (Type.regex(pattern) || (pattern && pattern.constructor === RegExp))) { + if (!calledWithNew && patternIsRegExp && typeof flags === 'undefined' && pattern.constructor === RegExp) { return pattern; } - if (Type.regex(pattern) && Type.string(flags)) { - return new RegExp(pattern.source, flags); + + var P = pattern; + var F = flags; + if (Type.regex(pattern)) { + P = ES.Call(sourceGetter, pattern); + F = typeof flags === 'undefined' ? ES.Call(flagsGetter, pattern) : flags; + return new RegExp(P, F); + } else if (patternIsRegExp) { + P = pattern.source; + F = typeof flags === 'undefined' ? pattern.flags : flags; } return new OrigRegExp(pattern, flags); }; @@ -1559,7 +1778,7 @@ leftContext: '$`', rightContext: '$\'' }; - _forEach(Object.keys(regexGlobals), function (prop) { + _forEach(keys(regexGlobals), function (prop) { if (prop in RegExp && !(regexGlobals[prop] in RegExp)) { Value.getter(RegExp, regexGlobals[prop], function get() { return RegExp[prop]; @@ -1630,7 +1849,7 @@ if (number === 0) { return 32; } - return numberCLZ ? _call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * Math.LOG2E); + return numberCLZ ? ES.Call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * Math.LOG2E); }, cosh: function cosh(value) { @@ -1809,7 +2028,7 @@ // Safari 8.0.4 has a length of 1 // fixed in https://bugs.webkit.org/show_bug.cgi?id=143658 overrideNative(Math, 'imul', function imul(x, y) { - return _apply(origImul, Math, arguments); + return ES.Call(origImul, Math, arguments); }); } @@ -1845,6 +2064,9 @@ capability.resolve = resolve; capability.reject = reject; }; + // Initialize fields to inform optimizers about the object shape. + capability.resolve = void 0; + capability.reject = void 0; capability.promise = new C(resolver); if (!(ES.IsCallable(capability.resolve) && ES.IsCallable(capability.reject))) { throw new TypeError('Bad promise constructor'); @@ -1881,14 +2103,15 @@ // global Promise below (in order to workaround bugs) // https://github.com/Raynos/observ-hash/issues/2#issuecomment-35857671 var P = globals.Promise; - return P && P.resolve && function (task) { - return P.resolve().then(task); + var pr = P && P.resolve && P.resolve(); + return pr && function (task) { + return pr.then(task); }; }; /*global process */ /* jscs:disable disallowMultiLineTernary */ var enqueue = ES.IsCallable(globals.setImmediate) ? - globals.setImmediate.bind(globals) : + globals.setImmediate : typeof process === 'object' && process.nextTick ? process.nextTick : makePromiseAsap() || (ES.IsCallable(makeZeroTimeout) ? makeZeroTimeout() : @@ -1896,59 +2119,99 @@ /* jscs:enable disallowMultiLineTernary */ // Constants for Promise implementation - var PROMISE_IDENTITY = 1; - var PROMISE_THROWER = 2; - var PROMISE_PENDING = 3; - var PROMISE_FULFILLED = 4; - var PROMISE_REJECTED = 5; - - var promiseReactionJob = function (reaction, argument) { - var promiseCapability = reaction.capabilities; - var handler = reaction.handler; - var handlerResult, handlerException = false, f; - if (handler === PROMISE_IDENTITY) { - handlerResult = argument; - } else if (handler === PROMISE_THROWER) { - handlerResult = argument; - handlerException = true; - } else { - try { - handlerResult = handler(argument); - } catch (e) { - handlerResult = e; - handlerException = true; - } - } - f = handlerException ? promiseCapability.reject : promiseCapability.resolve; - f(handlerResult); + var PROMISE_IDENTITY = function (x) { return x; }; + var PROMISE_THROWER = function (e) { throw e; }; + var PROMISE_PENDING = 0; + var PROMISE_FULFILLED = 1; + var PROMISE_REJECTED = 2; + // We store fulfill/reject handlers and capabilities in a single array. + var PROMISE_FULFILL_OFFSET = 0; + var PROMISE_REJECT_OFFSET = 1; + var PROMISE_CAPABILITY_OFFSET = 2; + // This is used in an optimization for chaining promises via then. + var PROMISE_FAKE_CAPABILITY = {}; + + var enqueuePromiseReactionJob = function (handler, capability, argument) { + enqueue(function () { + promiseReactionJob(handler, capability, argument); + }); }; - var triggerPromiseReactions = function (reactions, argument) { - _forEach(reactions, function (reaction) { - enqueue(function () { - promiseReactionJob(reaction, argument); - }); - }); + var promiseReactionJob = function (handler, promiseCapability, argument) { + var handlerResult, f; + if (promiseCapability === PROMISE_FAKE_CAPABILITY) { + // Fast case, when we don't actually need to chain through to a + // (real) promiseCapability. + return handler(argument); + } + try { + handlerResult = handler(argument); + f = promiseCapability.resolve; + } catch (e) { + handlerResult = e; + f = promiseCapability.reject; + } + f(handlerResult); }; var fulfillPromise = function (promise, value) { var _promise = promise._promise; - var reactions = _promise.fulfillReactions; + var length = _promise.reactionLength; + if (length > 0) { + enqueuePromiseReactionJob( + _promise.fulfillReactionHandler0, + _promise.reactionCapability0, + value + ); + _promise.fulfillReactionHandler0 = void 0; + _promise.rejectReactions0 = void 0; + _promise.reactionCapability0 = void 0; + if (length > 1) { + for (var i = 1, idx = 0; i < length; i++, idx += 3) { + enqueuePromiseReactionJob( + _promise[idx + PROMISE_FULFILL_OFFSET], + _promise[idx + PROMISE_CAPABILITY_OFFSET], + value + ); + promise[idx + PROMISE_FULFILL_OFFSET] = void 0; + promise[idx + PROMISE_REJECT_OFFSET] = void 0; + promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0; + } + } + } _promise.result = value; - _promise.fulfillReactions = void 0; - _promise.rejectReactions = void 0; _promise.state = PROMISE_FULFILLED; - triggerPromiseReactions(reactions, value); + _promise.reactionLength = 0; }; var rejectPromise = function (promise, reason) { var _promise = promise._promise; - var reactions = _promise.rejectReactions; + var length = _promise.reactionLength; + if (length > 0) { + enqueuePromiseReactionJob( + _promise.rejectReactionHandler0, + _promise.reactionCapability0, + reason + ); + _promise.fulfillReactionHandler0 = void 0; + _promise.rejectReactions0 = void 0; + _promise.reactionCapability0 = void 0; + if (length > 1) { + for (var i = 1, idx = 0; i < length; i++, idx += 3) { + enqueuePromiseReactionJob( + _promise[idx + PROMISE_REJECT_OFFSET], + _promise[idx + PROMISE_CAPABILITY_OFFSET], + reason + ); + promise[idx + PROMISE_FULFILL_OFFSET] = void 0; + promise[idx + PROMISE_REJECT_OFFSET] = void 0; + promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0; + } + } + } _promise.result = reason; - _promise.fulfillReactions = void 0; - _promise.rejectReactions = void 0; _promise.state = PROMISE_REJECTED; - triggerPromiseReactions(reactions, reason); + _promise.reactionLength = 0; }; var createResolvingFunctions = function (promise) { @@ -1983,30 +2246,29 @@ return { resolve: resolve, reject: reject }; }; + var optimizedThen = function (then, thenable, resolve, reject) { + // Optimization: since we discard the result, we can pass our + // own then implementation a special hint to let it know it + // doesn't have to create it. (The PROMISE_FAKE_CAPABILITY + // object is local to this implementation and unforgeable outside.) + if (then === Promise$pr