From 0d1a9a72d9a737835e1c926609e0b9ed26fc137b Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Wed, 28 Sep 2016 11:49:07 -0700 Subject: [PATCH] Fix spy arity stuff to work in IE8 --- lib/jasmine-core/jasmine.js | 3 ++- spec/core/SpySpec.js | 4 ++-- src/core/Spy.js | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 9642905b..b0e9e62c 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2058,7 +2058,8 @@ getJasmineRequireObj().Spy = function (j$) { More explanation here (look at comments): http://www.bennadel.com/blog/1909-javascript-function-constructor-does-not-create-a-closure.htm */ /* jshint evil: true */ - wrapper = eval('(function (' + args + ') { return spy.apply(this, Array.prototype.slice.call(arguments)); })'), + wrapper = eval('(0, function (' + args + ') { return spy.apply(this, Array.prototype.slice.call(arguments)); })'), + /* jshint evil: false */ spyStrategy = new j$.SpyStrategy({ name: name, fn: originalFn, diff --git a/spec/core/SpySpec.js b/spec/core/SpySpec.js index e472aa9c..acaefae9 100644 --- a/spec/core/SpySpec.js +++ b/spec/core/SpySpec.js @@ -69,8 +69,8 @@ describe('Spies', function () { function senary (arg1, arg2, arg3, arg4, arg5, arg6) {} ]; - functions.forEach(function (someFunction, arity) { - var spy = jasmineUnderTest.createSpy(someFunction.name, someFunction); + for (var arity = 0; arity < functions.length; arity++) { + var spy = jasmineUnderTest.createSpy(functions[arity].name, someFunction); expect(spy.length).toEqual(arity); }); diff --git a/src/core/Spy.js b/src/core/Spy.js index a2a09b33..bd5ae01b 100644 --- a/src/core/Spy.js +++ b/src/core/Spy.js @@ -8,7 +8,8 @@ getJasmineRequireObj().Spy = function (j$) { More explanation here (look at comments): http://www.bennadel.com/blog/1909-javascript-function-constructor-does-not-create-a-closure.htm */ /* jshint evil: true */ - wrapper = eval('(function (' + args + ') { return spy.apply(this, Array.prototype.slice.call(arguments)); })'), + wrapper = eval('(0, function (' + args + ') { return spy.apply(this, Array.prototype.slice.call(arguments)); })'), + /* jshint evil: false */ spyStrategy = new j$.SpyStrategy({ name: name, fn: originalFn,