From 62e0db7c9b2e9eeb429bf36fd3c918dd7f597236 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 23 Jan 2014 00:30:59 -0800 Subject: [PATCH] Fix `Function.prototype.toString` mock in test/ to avoid errors in Firefox. --- test/index.html | 21 ++++++++++++++------- test/test.js | 16 +++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/test/index.html b/test/index.html index 08387de05..8dcb56517 100644 --- a/test/index.html +++ b/test/index.html @@ -52,11 +52,18 @@ Function.prototype._method = function() {}; // allow bypassing native checks - var _toString = Function.prototype.toString; - setProperty(Function.prototype, '_toString', _toString); - setProperty(Function.prototype, 'toString', function() { - return this === Set ? this.toString() : _toString.call(this); - }); + var _fnToString = Function.prototype.toString; + setProperty(Function.prototype, '_toString', _fnToString); + + setProperty(Function.prototype, 'toString', (function() { + function fnToString() { + setProperty(Function.prototype, 'toString', _fnToString); + var result = this === Set ? this.toString() : _fnToString.call(this); + setProperty(Function.prototype, 'toString', fnToString); + return result; + } + return fnToString; + }())); // set bad shims setProperty(Array, '_isArray', Array.isArray); @@ -198,7 +205,7 @@ var reBasename = /[\w.-]+$/, basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''), modulePath = ui.buildPath.replace(/\.js$/, ''), - locationPath = modulePath.replace(reBasename, ''), + locationPath = modulePath.replace(reBasename, '').replace(/\/$/, ''), moduleMain = modulePath.match(reBasename)[0], uid = +new Date; @@ -227,7 +234,7 @@ }, { 'name': 'test', - 'location': basePath + '/test', + 'location': basePath + 'test', 'main': 'test', 'config': { // work around no global being exported diff --git a/test/test.js b/test/test.js index b57cbe23f..5c5b7753a 100644 --- a/test/test.js +++ b/test/test.js @@ -272,10 +272,16 @@ }); // allow bypassing native checks - var _toString = Function.prototype.toString; - setProperty(Function.prototype, 'toString', function() { - return this === Set ? this.toString() : _toString.call(this); - }); + var _fnToString = Function.prototype.toString; + setProperty(Function.prototype, 'toString', (function() { + function fnToString() { + setProperty(Function.prototype, 'toString', _fnToString); + var result = this === Set ? this.toString() : _fnToString.call(this); + setProperty(Function.prototype, 'toString', fnToString); + return result; + } + return fnToString; + }())); // add extensions Function.prototype._method = function() {}; @@ -325,7 +331,7 @@ setProperty(Object, 'getPrototypeOf', _getPrototypeOf); setProperty(Object, 'keys', _keys); - setProperty(Function.prototype, 'toString', _toString); + setProperty(Function.prototype, 'toString', _fnToString); _.forOwn({ 'contains': _contains,