Skip to content

Commit

Permalink
Use an object instead of a sparse array, for IE 11 TP. Also, add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 10, 2015
1 parent 99a40ce commit 1d80b06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,7 @@
var assignHasPendingExceptions = Object.assign && Object.preventExtensions && (function () {
// Firefox 37 still has "pending exception" logic in its Object.assign implementation,
// which is 72% slower than our shim, and Firefox 40's native implementation.
/*jshint elision: true */
var thrower = Object.preventExtensions([,1]);
/*jshint elision: false */
var thrower = Object.preventExtensions({ 1: 2 });
try {
Object.assign(thrower, 'xy');
} catch (e) {
Expand Down
9 changes: 9 additions & 0 deletions test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('Object', function () {

var functionsHaveNames = (function foo() {}).name === 'foo';
var ifFunctionsHaveNamesIt = functionsHaveNames ? it : xit;
var ifExtensionsPreventable = Object.preventExtensions ? it : xit;

if (Object.getOwnPropertyNames) {
describe('Object.getOwnPropertyNames()', function () {
Expand Down Expand Up @@ -202,6 +203,14 @@ describe('Object', function () {
expect(Object.assign({ a: 1 }, undefined, { b: 2 })).to.eql({ a: 1, b: 2 });
expect(Object.assign({ a: 1 }, { b: 2 }, null)).to.eql({ a: 1, b: 2 });
});

ifExtensionsPreventable('does not have pending exceptions', function () {
// Firefox 37 still has "pending exception" logic in its Object.assign implementation,
// which is 72% slower than our shim, and Firefox 40's native implementation.
var thrower = Object.preventExtensions({ 1: 2 });
try { Object.assign(thrower, 'xy'); } catch (e) {}
expect(thrower).to.have.property(1, 2);
});
});

describe('Object.setPrototypeOf()', function () {
Expand Down

0 comments on commit 1d80b06

Please sign in to comment.