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() {}; ...@@ -9,6 +9,14 @@ var noop = function() {};
var Promise = function(resolver) { var Promise = function(resolver) {
var promise = this; 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) { var resolvePromise = function(value) {
resolve(promise, value); resolve(promise, value);
resolvePromise = noop; resolvePromise = noop;
...@@ -29,9 +37,7 @@ var Promise = function(resolver) { ...@@ -29,9 +37,7 @@ var Promise = function(resolver) {
this.trigger('error', { detail: event.detail }); this.trigger('error', { detail: event.detail });
}, this); }, this);
if (resolver) { resolver(resolvePromise, rejectPromise);
resolver(resolvePromise, rejectPromise);
}
}; };
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
...@@ -69,8 +75,10 @@ var invokeCallback = function(type, promise, callback, event) { ...@@ -69,8 +75,10 @@ var invokeCallback = function(type, promise, callback, event) {
}; };
Promise.prototype = { Promise.prototype = {
constructor: Promise,
then: function(done, fail) { then: function(done, fail) {
var thenPromise = new Promise(); var thenPromise = new Promise(function() {});
if (this.isFulfilled) { if (this.isFulfilled) {
config.async(function() { config.async(function() {
...@@ -114,7 +122,7 @@ function reject(promise, value) { ...@@ -114,7 +122,7 @@ function reject(promise, value) {
function all(promises) { function all(promises) {
var i, results = []; var i, results = [];
var allPromise = new Promise(); var allPromise = new Promise(function() {});
var remaining = promises.length; var remaining = promises.length;
if (remaining === 0) { 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