Commit 5bd85804 authored by Teddy Zeenny's avatar Teddy Zeenny

Make rsvp promises/A+ spec-1.1 compliant

parent a7f93c16
......@@ -61,12 +61,8 @@ var invokeCallback = function(type, promise, callback, event) {
succeeded = true;
}
if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(value) {
resolve(promise, value);
}, function(error) {
reject(promise, error);
});
if (handleThenable(promise, value)) {
return;
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
......@@ -111,11 +107,27 @@ Promise.prototype = {
EventTarget.mixin(Promise.prototype);
function resolve(promise, value) {
if (promise === value) {
fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) {
} else if (!handleThenable(promise, value)) {
fulfill(promise, value);
}
}
function handleThenable(promise, value) {
var then = null;
if (objectOrFunction(value)) {
try {
then = value.then;
} catch(e) {
reject(promise, e);
return true;
}
if (isFunction(then)) {
try {
then.call(value, function(val) {
if (value !== val) {
resolve(promise, val);
} else {
......@@ -124,9 +136,14 @@ function resolve(promise, value) {
}, function(val) {
reject(promise, val);
});
} else {
fulfill(promise, value);
} catch (e) {
reject(promise, e);
}
return true;
}
}
return false;
}
function fulfill(promise, value) {
......
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