From c335fee0d5fb77d0954163c89698c485c996677b Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 2 Jul 2014 16:46:17 +0200 Subject: [PATCH] add Function.prototype.bind polyfill in tests because phantomjs is buggy --- test/integration/main.js | 22 ++++++++++++++++++++++ test/unit/main.js | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/test/integration/main.js b/test/integration/main.js index ccd3062..fcec906 100644 --- a/test/integration/main.js +++ b/test/integration/main.js @@ -1,5 +1,27 @@ 'use strict'; +// Mozilla bind polyfill because phantomjs is stupid +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== "function") { + // closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + FNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof FNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + FNOP.prototype = this.prototype; + fBound.prototype = new FNOP(); + + return fBound; + }; +} + require(['src/require-config'], function() { require.config({ baseUrl: 'src/lib', diff --git a/test/unit/main.js b/test/unit/main.js index 446fe13..aa52777 100644 --- a/test/unit/main.js +++ b/test/unit/main.js @@ -1,5 +1,27 @@ 'use strict'; +// Mozilla bind polyfill because phantomjs is stupid +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== "function") { + // closest thing possible to the ECMAScript 5 internal IsCallable function + throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + FNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof FNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + FNOP.prototype = this.prototype; + fBound.prototype = new FNOP(); + + return fBound; + }; +} + require(['../../src/require-config'], function() { require.config({ baseUrl: '../../src/lib',