diff --git a/es6-shim.js b/es6-shim.js index ad82a093..3ab21af3 100644 --- a/es6-shim.js +++ b/es6-shim.js @@ -2965,11 +2965,12 @@ if (arguments.length > 0) { addIterableToMap(Map, m, arguments[0]); } + delete m.constructor; Object.setPrototypeOf(m, globals.Map.prototype); - defineProperty(m, 'constructor', Map, true); return m; }; globals.Map.prototype = create(OrigMapNoArgs.prototype); + defineProperty(globals.Map.prototype, 'constructor', globals.Map, true); Value.preserveToString(globals.Map, OrigMapNoArgs); } var testMap = new Map(); @@ -3053,11 +3054,12 @@ if (arguments.length > 0) { addIterableToMap(Map, m, arguments[0]); } + delete m.constructor; Object.setPrototypeOf(m, Map.prototype); - defineProperty(m, 'constructor', Map, true); return m; }; globals.Map.prototype = OrigMap.prototype; + defineProperty(globals.Map.prototype, 'constructor', globals.Map, true); Value.preserveToString(globals.Map, OrigMap); } var setSupportsSubclassing = supportsSubclassing(globals.Set, function (S) { @@ -3083,11 +3085,12 @@ if (arguments.length > 0) { addIterableToSet(Set, s, arguments[0]); } + delete s.constructor; Object.setPrototypeOf(s, Set.prototype); - defineProperty(s, 'constructor', Set, true); return s; }; globals.Set.prototype = OrigSet.prototype; + defineProperty(globals.Set.prototype, 'constructor', globals.Set, true); Value.preserveToString(globals.Set, OrigSet); } var mapIterationThrowsStopIterator = !valueOrFalseIfThrows(function () { diff --git a/test/collections.js b/test/collections.js index 349090f3..7a48f34d 100644 --- a/test/collections.js +++ b/test/collections.js @@ -251,6 +251,12 @@ describe('Collections', function () { expectNotEnumerable(new Map()); }); + it('should not have an own constructor', function () { + var m = new Map(); + expect(m).not.to.haveOwnPropertyDescriptor('constructor'); + expect(m.constructor).to.equal(Map); + }); + it('should allow common ecmascript idioms', function () { expect(map).to.be.an.instanceOf(Map); expect(typeof Map.prototype.get).to.equal('function'); @@ -259,6 +265,10 @@ describe('Collections', function () { expect(typeof Map.prototype['delete']).to.equal('function'); }); + it('should have a unique constructor', function () { + expect(Map.prototype).to.not.equal(Object.prototype); + }); + describe('#clear()', function () { ifFunctionsHaveNamesIt('has the right name', function () { expect(Map.prototype.clear).to.have.property('name', 'clear'); @@ -351,10 +361,6 @@ describe('Collections', function () { }); }); - it('should has unique constructor', function () { - expect(Map.prototype).to.not.equal(Object.prototype); - }); - describe('#size', function () { it('throws TypeError when accessed directly', function () { // see https://github.com/paulmillr/es6-shim/issues/176 @@ -913,6 +919,12 @@ describe('Collections', function () { expectNotEnumerable(new Set()); }); + it('should not have an own constructor', function () { + var s = new Set(); + expect(s).not.to.haveOwnPropertyDescriptor('constructor'); + expect(s.constructor).to.equal(Set); + }); + it('should allow common ecmascript idioms', function () { expect(set instanceof Set).to.equal(true); expect(typeof Set.prototype.add).to.equal('function'); @@ -920,7 +932,7 @@ describe('Collections', function () { expect(typeof Set.prototype['delete']).to.equal('function'); }); - it('should has unique constructor', function () { + it('should have a unique constructor', function () { expect(Set.prototype).to.not.equal(Object.prototype); });