vendor/assets/javascripts/promise.js in es6-promise-rails-3.0.2 vs vendor/assets/javascripts/promise.js in es6-promise-rails-3.2.1
- old
+ new
@@ -1,11 +1,11 @@
/*!
* @overview es6-promise - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
- * @version 3.0.2
+ * @version 3.2.1
*/
(function() {
"use strict";
function lib$es6$promise$utils$$objectOrFunction(x) {
@@ -29,11 +29,10 @@
lib$es6$promise$utils$$_isArray = Array.isArray;
}
var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
var lib$es6$promise$asap$$len = 0;
- var lib$es6$promise$asap$$toString = {}.toString;
var lib$es6$promise$asap$$vertxNext;
var lib$es6$promise$asap$$customSchedulerFn;
var lib$es6$promise$asap$$asap = function asap(callback, arg) {
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
@@ -60,11 +59,11 @@
}
var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
- var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
+ var lib$es6$promise$asap$$isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
// test for web worker but not in IE10
var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
typeof importScripts !== 'undefined' &&
typeof MessageChannel !== 'undefined';
@@ -148,11 +147,48 @@
} else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx();
} else {
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
}
+ function lib$es6$promise$then$$then(onFulfillment, onRejection) {
+ var parent = this;
+ var child = new this.constructor(lib$es6$promise$$internal$$noop);
+
+ if (child[lib$es6$promise$$internal$$PROMISE_ID] === undefined) {
+ lib$es6$promise$$internal$$makePromise(child);
+ }
+
+ var state = parent._state;
+
+ if (state) {
+ var callback = arguments[state - 1];
+ lib$es6$promise$asap$$asap(function(){
+ lib$es6$promise$$internal$$invokeCallback(state, child, callback, parent._result);
+ });
+ } else {
+ lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
+ }
+
+ return child;
+ }
+ var lib$es6$promise$then$$default = lib$es6$promise$then$$then;
+ function lib$es6$promise$promise$resolve$$resolve(object) {
+ /*jshint validthis:true */
+ var Constructor = this;
+
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
+ return object;
+ }
+
+ var promise = new Constructor(lib$es6$promise$$internal$$noop);
+ lib$es6$promise$$internal$$resolve(promise, object);
+ return promise;
+ }
+ var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
+ var lib$es6$promise$$internal$$PROMISE_ID = Math.random().toString(36).substring(16);
+
function lib$es6$promise$$internal$$noop() {}
var lib$es6$promise$$internal$$PENDING = void 0;
var lib$es6$promise$$internal$$FULFILLED = 1;
var lib$es6$promise$$internal$$REJECTED = 2;
@@ -221,16 +257,16 @@
lib$es6$promise$$internal$$reject(promise, reason);
});
}
}
- function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) {
- if (maybeThenable.constructor === promise.constructor) {
+ function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable, then) {
+ if (maybeThenable.constructor === promise.constructor &&
+ then === lib$es6$promise$then$$default &&
+ constructor.resolve === lib$es6$promise$promise$resolve$$default) {
lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
} else {
- var then = lib$es6$promise$$internal$$getThen(maybeThenable);
-
if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
} else if (then === undefined) {
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
} else if (lib$es6$promise$utils$$isFunction(then)) {
@@ -243,11 +279,11 @@
function lib$es6$promise$$internal$$resolve(promise, value) {
if (promise === value) {
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFulfillment());
} else if (lib$es6$promise$utils$$objectOrFunction(value)) {
- lib$es6$promise$$internal$$handleMaybeThenable(promise, value);
+ lib$es6$promise$$internal$$handleMaybeThenable(promise, value, lib$es6$promise$$internal$$getThen(value));
} else {
lib$es6$promise$$internal$$fulfill(promise, value);
}
}
@@ -378,163 +414,53 @@
} catch(e) {
lib$es6$promise$$internal$$reject(promise, e);
}
}
- function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
- var enumerator = this;
+ var lib$es6$promise$$internal$$id = 0;
+ function lib$es6$promise$$internal$$nextId() {
+ return lib$es6$promise$$internal$$id++;
+ }
- enumerator._instanceConstructor = Constructor;
- enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop);
-
- if (enumerator._validateInput(input)) {
- enumerator._input = input;
- enumerator.length = input.length;
- enumerator._remaining = input.length;
-
- enumerator._init();
-
- if (enumerator.length === 0) {
- lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
- } else {
- enumerator.length = enumerator.length || 0;
- enumerator._enumerate();
- if (enumerator._remaining === 0) {
- lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result);
- }
- }
- } else {
- lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError());
- }
+ function lib$es6$promise$$internal$$makePromise(promise) {
+ promise[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$id++;
+ promise._state = undefined;
+ promise._result = undefined;
+ promise._subscribers = [];
}
- lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) {
- return lib$es6$promise$utils$$isArray(input);
- };
-
- lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() {
- return new Error('Array Methods must be provided an Array');
- };
-
- lib$es6$promise$enumerator$$Enumerator.prototype._init = function() {
- this._result = new Array(this.length);
- };
-
- var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
-
- lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
- var enumerator = this;
-
- var length = enumerator.length;
- var promise = enumerator.promise;
- var input = enumerator._input;
-
- for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
- enumerator._eachEntry(input[i], i);
- }
- };
-
- lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
- var enumerator = this;
- var c = enumerator._instanceConstructor;
-
- if (lib$es6$promise$utils$$isMaybeThenable(entry)) {
- if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) {
- entry._onerror = null;
- enumerator._settledAt(entry._state, i, entry._result);
- } else {
- enumerator._willSettleAt(c.resolve(entry), i);
- }
- } else {
- enumerator._remaining--;
- enumerator._result[i] = entry;
- }
- };
-
- lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
- var enumerator = this;
- var promise = enumerator.promise;
-
- if (promise._state === lib$es6$promise$$internal$$PENDING) {
- enumerator._remaining--;
-
- if (state === lib$es6$promise$$internal$$REJECTED) {
- lib$es6$promise$$internal$$reject(promise, value);
- } else {
- enumerator._result[i] = value;
- }
- }
-
- if (enumerator._remaining === 0) {
- lib$es6$promise$$internal$$fulfill(promise, enumerator._result);
- }
- };
-
- lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
- var enumerator = this;
-
- lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
- enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
- }, function(reason) {
- enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
- });
- };
function lib$es6$promise$promise$all$$all(entries) {
return new lib$es6$promise$enumerator$$default(this, entries).promise;
}
var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
function lib$es6$promise$promise$race$$race(entries) {
/*jshint validthis:true */
var Constructor = this;
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
-
if (!lib$es6$promise$utils$$isArray(entries)) {
- lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
- return promise;
+ return new Constructor(function(resolve, reject) {
+ reject(new TypeError('You must pass an array to race.'));
+ });
+ } else {
+ return new Constructor(function(resolve, reject) {
+ var length = entries.length;
+ for (var i = 0; i < length; i++) {
+ Constructor.resolve(entries[i]).then(resolve, reject);
+ }
+ });
}
-
- var length = entries.length;
-
- function onFulfillment(value) {
- lib$es6$promise$$internal$$resolve(promise, value);
- }
-
- function onRejection(reason) {
- lib$es6$promise$$internal$$reject(promise, reason);
- }
-
- for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
- lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
- }
-
- return promise;
}
var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
- function lib$es6$promise$promise$resolve$$resolve(object) {
- /*jshint validthis:true */
- var Constructor = this;
-
- if (object && typeof object === 'object' && object.constructor === Constructor) {
- return object;
- }
-
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
- lib$es6$promise$$internal$$resolve(promise, object);
- return promise;
- }
- var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
function lib$es6$promise$promise$reject$$reject(reason) {
/*jshint validthis:true */
var Constructor = this;
var promise = new Constructor(lib$es6$promise$$internal$$noop);
lib$es6$promise$$internal$$reject(promise, reason);
return promise;
}
var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
- var lib$es6$promise$promise$$counter = 0;
function lib$es6$promise$promise$$needsResolver() {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
@@ -645,25 +571,17 @@
@param {function} resolver
Useful for tooling.
@constructor
*/
function lib$es6$promise$promise$$Promise(resolver) {
- this._id = lib$es6$promise$promise$$counter++;
- this._state = undefined;
- this._result = undefined;
+ this[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$nextId();
+ this._result = this._state = undefined;
this._subscribers = [];
if (lib$es6$promise$$internal$$noop !== resolver) {
- if (!lib$es6$promise$utils$$isFunction(resolver)) {
- lib$es6$promise$promise$$needsResolver();
- }
-
- if (!(this instanceof lib$es6$promise$promise$$Promise)) {
- lib$es6$promise$promise$$needsNew();
- }
-
- lib$es6$promise$$internal$$initializePromise(this, resolver);
+ typeof resolver !== 'function' && lib$es6$promise$promise$$needsResolver();
+ this instanceof lib$es6$promise$promise$$Promise ? lib$es6$promise$$internal$$initializePromise(this, resolver) : lib$es6$promise$promise$$needsNew();
}
}
lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
@@ -867,33 +785,12 @@
@param {Function} onFulfilled
@param {Function} onRejected
Useful for tooling.
@return {Promise}
*/
- then: function(onFulfillment, onRejection) {
- var parent = this;
- var state = parent._state;
+ then: lib$es6$promise$then$$default,
- if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) {
- return this;
- }
-
- var child = new this.constructor(lib$es6$promise$$internal$$noop);
- var result = parent._result;
-
- if (state) {
- var callback = arguments[state - 1];
- lib$es6$promise$asap$$asap(function(){
- lib$es6$promise$$internal$$invokeCallback(state, child, callback, result);
- });
- } else {
- lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
- }
-
- return child;
- },
-
/**
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
as the catch block of a try/catch statement.
```js
@@ -920,9 +817,104 @@
@return {Promise}
*/
'catch': function(onRejection) {
return this.then(null, onRejection);
}
+ };
+ var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
+ function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
+ this._instanceConstructor = Constructor;
+ this.promise = new Constructor(lib$es6$promise$$internal$$noop);
+
+ if (!this.promise[lib$es6$promise$$internal$$PROMISE_ID]) {
+ lib$es6$promise$$internal$$makePromise(this.promise);
+ }
+
+ if (Array.isArray(input)) {
+ this._input = input;
+ this.length = input.length;
+ this._remaining = input.length;
+
+ this._result = new Array(this.length);
+
+ if (this.length === 0) {
+ lib$es6$promise$$internal$$fulfill(this.promise, this._result);
+ } else {
+ this.length = this.length || 0;
+ this._enumerate();
+ if (this._remaining === 0) {
+ lib$es6$promise$$internal$$fulfill(this.promise, this._result);
+ }
+ }
+ } else {
+ lib$es6$promise$$internal$$reject(this.promise, lib$es6$promise$enumerator$$validationError());
+ }
+ }
+
+ function lib$es6$promise$enumerator$$validationError() {
+ return new Error('Array Methods must be provided an Array');
+ }
+
+ lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
+ var length = this.length;
+ var input = this._input;
+
+ for (var i = 0; this._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
+ this._eachEntry(input[i], i);
+ }
+ };
+
+ lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
+ var c = this._instanceConstructor;
+ var resolve = c.resolve;
+
+ if (resolve === lib$es6$promise$promise$resolve$$default) {
+ var then = lib$es6$promise$$internal$$getThen(entry);
+
+ if (then === lib$es6$promise$then$$default &&
+ entry._state !== lib$es6$promise$$internal$$PENDING) {
+ this._settledAt(entry._state, i, entry._result);
+ } else if (typeof then !== 'function') {
+ this._remaining--;
+ this._result[i] = entry;
+ } else if (c === lib$es6$promise$promise$$default) {
+ var promise = new c(lib$es6$promise$$internal$$noop);
+ lib$es6$promise$$internal$$handleMaybeThenable(promise, entry, then);
+ this._willSettleAt(promise, i);
+ } else {
+ this._willSettleAt(new c(function(resolve) { resolve(entry); }), i);
+ }
+ } else {
+ this._willSettleAt(resolve(entry), i);
+ }
+ };
+
+ lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
+ var promise = this.promise;
+
+ if (promise._state === lib$es6$promise$$internal$$PENDING) {
+ this._remaining--;
+
+ if (state === lib$es6$promise$$internal$$REJECTED) {
+ lib$es6$promise$$internal$$reject(promise, value);
+ } else {
+ this._result[i] = value;
+ }
+ }
+
+ if (this._remaining === 0) {
+ lib$es6$promise$$internal$$fulfill(promise, this._result);
+ }
+ };
+
+ lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
+ var enumerator = this;
+
+ lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
+ enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
+ }, function(reason) {
+ enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
+ });
};
function lib$es6$promise$polyfill$$polyfill() {
var local;
if (typeof global !== 'undefined') {