diff --git a/es6-sham.js b/es6-sham.js index 8e405b02..93f15b2b 100644 --- a/es6-sham.js +++ b/es6-sham.js @@ -151,6 +151,9 @@ configurable: true, enumerable: false, get: function () { + if (this === Function.prototype) { + return ''; + } var str = _call(functionToString, this); var match = _call(_strMatch, str, /\s*function\s+([^(\s]*)\s*/); var name = match && match[1]; diff --git a/test-sham/function.js b/test-sham/function.js index 9b83a6a5..bbf5e8a2 100644 --- a/test-sham/function.js +++ b/test-sham/function.js @@ -17,6 +17,12 @@ describe('Function', function () { }); }); + it('does not poison every name when accessed on Function.prototype', function () { + expect((function foo() {}).name).to.equal('foo'); + expect(Function.prototype.name).to.equal(''); + expect((function foo() {}).name).to.equal('foo'); + }); + it('returns empty string for anonymous functions', function () { var anon = identity(function () {}); expect(anon.name).to.equal(''); diff --git a/test-sham/set-prototype-of.js b/test-sham/set-prototype-of.js index 80448b3e..ac044a13 100644 --- a/test-sham/set-prototype-of.js +++ b/test-sham/set-prototype-of.js @@ -5,22 +5,22 @@ describe('Object.setPrototypeOf(o, p)', function () { it('changes prototype to regular objects', function () { var obj = { a: 123 }; - expect(obj).to.be.an.instanceOf(Object); + expect(obj instanceof Object).to.equal(true); // sham requires assignment to work cross browser obj = Object.setPrototypeOf(obj, null); - expect(obj).not.to.be.an.instanceOf(Object); + expect(obj instanceof Object).to.equal(false); expect(obj.a).to.equal(123); }); it('changes prototype to null objects', function () { var obj = Object.create(null); obj.a = 456; - expect(obj).not.to.be.an.instanceOf(Object); + expect(obj instanceof Object).to.equal(false); expect(obj.a).to.equal(456); // sham requires assignment to work cross browser - obj = Object.setPrototypeOf(obj, {}); - expect(obj).to.be.an.instanceOf(Object); + obj = Object.setPrototypeOf(obj, { b: 789 }); + expect(obj instanceof Object).to.equal(true); expect(obj.a).to.equal(456); + expect(obj.b).to.equal(789); }); - });