Commit 55398c39 authored by Stefan Penner's avatar Stefan Penner

short-circuit RSVP.resolve is resolving RSVP.Promise

parent 889827fd
...@@ -566,12 +566,15 @@ define("rsvp/resolve", ...@@ -566,12 +566,15 @@ define("rsvp/resolve",
"use strict"; "use strict";
var Promise = __dependency1__.Promise; var Promise = __dependency1__.Promise;
function objectOrFunction(x) { function objectOrFunction(x) {
return typeof x === "function" || (typeof x === "object" && x !== null); return typeof x === "function" || (typeof x === "object" && x !== null);
} }
function resolve(thenable){ function resolve(thenable){
if (thenable instanceof Promise) {
return thenable;
}
var promise = new Promise(function(resolve, reject){ var promise = new Promise(function(resolve, reject){
var then; var then;
......
This diff is collapsed.
...@@ -4,12 +4,15 @@ define( ...@@ -4,12 +4,15 @@ define(
"use strict"; "use strict";
var Promise = __dependency1__.Promise; var Promise = __dependency1__.Promise;
function objectOrFunction(x) { function objectOrFunction(x) {
return typeof x === "function" || (typeof x === "object" && x !== null); return typeof x === "function" || (typeof x === "object" && x !== null);
} }
function resolve(thenable){ function resolve(thenable){
if (thenable instanceof Promise) {
return thenable;
}
var promise = new Promise(function(resolve, reject){ var promise = new Promise(function(resolve, reject){
var then; var then;
......
import { Promise } from "rsvp/promise"; import { Promise } from "rsvp/promise";
function objectOrFunction(x) { function objectOrFunction(x) {
return typeof x === "function" || (typeof x === "object" && x !== null); return typeof x === "function" || (typeof x === "object" && x !== null);
} }
function resolve(thenable){ function resolve(thenable){
if (thenable instanceof Promise) {
return thenable;
}
var promise = new Promise(function(resolve, reject){ var promise = new Promise(function(resolve, reject){
var then; var then;
......
...@@ -613,6 +613,12 @@ describe("RSVP extensions", function() { ...@@ -613,6 +613,12 @@ describe("RSVP extensions", function() {
assert(RSVP.resolve); assert(RSVP.resolve);
}); });
specify("it short circuits if RSVP.promise", function(){
var deferred = new RSVP.defer();
assert.equal(RSVP.resolve(deferred.promise), deferred.promise);
});
describe("1. If x is a promise, adopt its state ", function(){ describe("1. If x is a promise, adopt its state ", function(){
specify("1.1 If x is pending, promise must remain pending until x is fulfilled or rejected.", function(done){ specify("1.1 If x is pending, promise must remain pending until x is fulfilled or rejected.", function(done){
var expectedValue, resolver, thenable, wrapped; var expectedValue, resolver, thenable, wrapped;
......
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