Skip to content

Commit

Permalink
On IE <= 10, Object.setPrototypeOf is impossible to shim.
Browse files Browse the repository at this point in the history
Update test suite so that we don't test functions we can't provide.
  • Loading branch information
cscott committed Feb 28, 2014
1 parent 6ccc610 commit ce763b2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ details.
* `keys()` (ES5)
* `is()` ([a standalone shim is also available](https://github.com/ljharb/object-is))
* `assign()`
* `setPrototypeOf()`
* `setPrototypeOf()` (IE >= 11)
* `Math`:
* `acosh()`
* `asinh()`
Expand Down
3 changes: 2 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@

// Workaround bug in Opera 12 where setPrototypeOf(x, null) doesn't work,
// but Object.create(null) does.
if (Object.getPrototypeOf(Object.setPrototypeOf({}, null)) !== null &&
if (Object.setPrototypeOf && Object.getPrototypeOf &&
Object.getPrototypeOf(Object.setPrototypeOf({}, null)) !== null &&
Object.getPrototypeOf(Object.create(null)) === null) {
(function() {
var FAKENULL = Object.create(null);
Expand Down
4 changes: 2 additions & 2 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Collections', function() {

it('should be subclassable', function() {
var MyMap = function() { Map.call(this, [['a','b']]); }
if (!MyMap.__proto__) { return; } // skip test if on IE < 11
if (!Object.setPrototypeOf) { return; } // skip test if on IE < 11
Object.setPrototypeOf(MyMap, Map);
MyMap.prototype = Object.create(Map.prototype, {
constructor: { value: MyMap }
Expand Down Expand Up @@ -440,7 +440,7 @@ describe('Collections', function() {

it('should be subclassable', function() {
var MySet = function() { Set.call(this, ['a', 'b']); }
if (!MySet.__proto__) { return; } // skip test if on IE < 11
if (!Object.setPrototypeOf) { return; } // skip test if on IE < 11
Object.setPrototypeOf(MySet, Set);
MySet.prototype = Object.create(Set.prototype, {
constructor: { value: MySet }
Expand Down
4 changes: 4 additions & 0 deletions test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ describe('Object', function() {
});

describe('Object.setPrototypeOf()', function() {
if (!Object.setPrototypeOf) {
return; // IE < 11
}

describe('argument checking', function() {
it('should throw TypeError if first arg is not object', function() {
var nonObjects = [null, undefined, true, false, 1, 3, 'foo'];
Expand Down
2 changes: 1 addition & 1 deletion test/promise/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe("Promise.all", function () {
Promise.call(this, resolver);
}
};
if (!P.__proto__) { return done(); } // skip test if on IE < 11
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(P, Promise);
P.prototype = Object.create(Promise.prototype, {
constructor: { value: P }
Expand Down
2 changes: 1 addition & 1 deletion test/promise/evil-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("Evil promises should not be able to break invariants", function () {
// note that we have to create a trivial subclass, as otherwise the
// Promise.resolve(evilPromise) is just the identity function.
var EvilPromise = function(executor) { Promise.call(this, executor); };
if (!EvilPromise.__proto__) { return; } // skip test if on IE < 11
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(EvilPromise, Promise);
EvilPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: EvilPromise }
Expand Down
2 changes: 1 addition & 1 deletion test/promise/subclass.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("Support user subclassing of Promise", function() {
Promise.call(this, executor);
this.mine = 'yeah';
};
if (!MyPromise.__proto__) { return; } // skip test if on IE < 11
if (!Object.setPrototypeOf) { return done(); } // skip test if on IE < 11
Object.setPrototypeOf(MyPromise, Promise);
MyPromise.prototype = Object.create(Promise.prototype, {
constructor: { value: MyPromise }
Expand Down

0 comments on commit ce763b2

Please sign in to comment.