Commit 0a7c079b authored by Stefan Penner's avatar Stefan Penner

some cross browser fixes

- toString.call([]) angers IE, use Object.prototype.toString instead
- getPrototypeOf polyfil
parent 3e0c95f7
/*global describe, specify, it, assert */ /*global describe, specify, it, assert */
if (typeof Object.getPrototypeOf !== "function") {
Object.getPrototypeOf = "".__proto__ === String.prototype
? function (object) {
return object.__proto__;
}
: function (object) {
// May break if the constructor has been tampered with
return object.constructor.prototype;
};
}
function objectEquals(obj1, obj2) {
for (var i in obj1) {
if (obj1.hasOwnProperty(i)) {
if (!obj2.hasOwnProperty(i)) return false;
if (obj1[i] != obj2[i]) return false;
}
}
for (var i in obj2) {
if (obj2.hasOwnProperty(i)) {
if (!obj1.hasOwnProperty(i)) return false;
if (obj1[i] != obj2[i]) return false;
}
}
return true;
}
describe("RSVP extensions", function() { describe("RSVP extensions", function() {
describe("self fulfillment", function(){ describe("self fulfillment", function(){
it("treats self fulfillment as the recursive base case", function(done){ it("treats self fulfillment as the recursive base case", function(done){
...@@ -304,7 +332,7 @@ describe("RSVP extensions", function() { ...@@ -304,7 +332,7 @@ describe("RSVP extensions", function() {
var denodeifiedFunc = RSVP.denodeify(nodeFunc); var denodeifiedFunc = RSVP.denodeify(nodeFunc);
denodeifiedFunc(1, 2, 3).then(function() { denodeifiedFunc(1, 2, 3).then(function() {
assert.deepEqual(args, [1, 2, 3]); assert(objectEquals(args, [1, 2, 3]));
done(); done();
}); });
}); });
...@@ -340,7 +368,7 @@ describe("RSVP extensions", function() { ...@@ -340,7 +368,7 @@ describe("RSVP extensions", function() {
var thenable = { then: function (onFulfilled) { onFulfilled(2); } }; var thenable = { then: function (onFulfilled) { onFulfilled(2); } };
var nonPromise = 3; var nonPromise = 3;
denodeifiedFunc(promise, thenable, nonPromise).then(function() { denodeifiedFunc(promise, thenable, nonPromise).then(function() {
assert.deepEqual(args, [1, 2, 3]); assert(objectEquals(args, [1, 2, 3]));
done(); done();
}); });
}); });
...@@ -366,7 +394,7 @@ describe("RSVP extensions", function() { ...@@ -366,7 +394,7 @@ describe("RSVP extensions", function() {
var denodeifiedFunc = RSVP.denodeify(nodeFunc); var denodeifiedFunc = RSVP.denodeify(nodeFunc);
denodeifiedFunc().then(function(value) { denodeifiedFunc().then(function(value) {
assert.deepEqual(value, [1, 2, 3]); assert(objectEquals(value, [1, 2, 3]));
done(); done();
}); });
}); });
...@@ -422,7 +450,7 @@ describe("RSVP extensions", function() { ...@@ -422,7 +450,7 @@ describe("RSVP extensions", function() {
var denodeifiedWriteFile = RSVP.denodeify(writeFile); var denodeifiedWriteFile = RSVP.denodeify(writeFile);
denodeifiedWriteFile('dest.txt', denodeifiedReadFile('src.txt')).then(function () { denodeifiedWriteFile('dest.txt', denodeifiedReadFile('src.txt')).then(function () {
assert.deepEqual(writtenTo, ['dest.txt', 'contents of src.txt']); assert(objectEquals(writtenTo, ['dest.txt', 'contents of src.txt']));
done(); done();
}); });
}); });
...@@ -495,7 +523,7 @@ describe("RSVP extensions", function() { ...@@ -495,7 +523,7 @@ describe("RSVP extensions", function() {
specify('resolves an empty hash passed to RSVP.all()', function(done) { specify('resolves an empty hash passed to RSVP.all()', function(done) {
RSVP.hash({}).then(function(results) { RSVP.hash({}).then(function(results) {
assert.deepEqual(results, {}); assert(objectEquals(results, {}), 'expected fulfillment');
done(); done();
}); });
}); });
...@@ -507,7 +535,7 @@ describe("RSVP extensions", function() { ...@@ -507,7 +535,7 @@ describe("RSVP extensions", function() {
var nonPromise = 4; var nonPromise = 4;
RSVP.hash({ promise: promise, syncThenable: syncThenable, asyncThenable: asyncThenable, nonPromise: nonPromise }).then(function(results) { RSVP.hash({ promise: promise, syncThenable: syncThenable, asyncThenable: asyncThenable, nonPromise: nonPromise }).then(function(results) {
assert.deepEqual(results, { promise: 1, syncThenable: 2, asyncThenable: 3, nonPromise: 4 }); assert(objectEquals(results, { promise: 1, syncThenable: 2, asyncThenable: 3, nonPromise: 4 }));
done(); done();
}); });
}); });
...@@ -635,7 +663,7 @@ describe("RSVP extensions", function() { ...@@ -635,7 +663,7 @@ describe("RSVP extensions", function() {
var nonPromise = 4; var nonPromise = 4;
RSVP.all([promise, syncThenable, asyncThenable, nonPromise]).then(function(results) { RSVP.all([promise, syncThenable, asyncThenable, nonPromise]).then(function(results) {
assert.deepEqual(results, [1, 2, 3, 4]); assert(objectEquals(results, [1, 2, 3, 4]));
done(); done();
}); });
}); });
...@@ -766,6 +794,9 @@ describe("RSVP extensions", function() { ...@@ -766,6 +794,9 @@ describe("RSVP extensions", function() {
accessCount = 0; accessCount = 0;
thenable = { }; thenable = { };
// we likely don't need to test this, if the browser doesn't support it
if (typeof Object.defineProperty !== "function") { done(); return; }
Object.defineProperty(thenable, 'then', { Object.defineProperty(thenable, 'then', {
get: function(){ get: function(){
accessCount++; accessCount++;
...@@ -793,6 +824,9 @@ describe("RSVP extensions", function() { ...@@ -793,6 +824,9 @@ describe("RSVP extensions", function() {
expectedError = new Error(); expectedError = new Error();
thenable = { }; thenable = { };
// we likely don't need to test this, if the browser doesn't support it
if (typeof Object.defineProperty !== "function") { done(); return; }
Object.defineProperty(thenable, 'then', { Object.defineProperty(thenable, 'then', {
get: function(){ get: function(){
throw expectedError; throw expectedError;
......
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