Commit f5fb25b2 authored by Domenic Denicola's avatar Domenic Denicola

Fixes to the non-assimilation promise constructor stuff.

parent fe14287a
......@@ -9,6 +9,14 @@ var noop = function() {};
var Promise = function(resolver) {
var promise = this;
if (typeof resolver !== 'function') {
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
if (!(promise instanceof Promise)) {
return new Promise(resolver);
}
var resolvePromise = function(value) {
resolve(promise, value);
resolvePromise = noop;
......@@ -29,9 +37,7 @@ var Promise = function(resolver) {
this.trigger('error', { detail: event.detail });
}, this);
if (resolver) {
resolver(resolvePromise, rejectPromise);
}
resolver(resolvePromise, rejectPromise);
};
var invokeCallback = function(type, promise, callback, event) {
......@@ -69,8 +75,10 @@ var invokeCallback = function(type, promise, callback, event) {
};
Promise.prototype = {
constructor: Promise,
then: function(done, fail) {
var thenPromise = new Promise();
var thenPromise = new Promise(function() {});
if (this.isFulfilled) {
config.async(function() {
......@@ -114,7 +122,7 @@ function reject(promise, value) {
function all(promises) {
var i, results = [];
var allPromise = new Promise();
var allPromise = new Promise(function() {});
var remaining = promises.length;
if (remaining === 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment