diff --git a/Gruntfile.js b/Gruntfile.js index b7f0f3b3..ef66d7e8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -118,6 +118,13 @@ module.exports = function(grunt) { cwd: 'node_modules/', src: ['mocha/mocha.css', 'mocha/mocha.js', 'chai/chai.js', 'es6-promise/dist/promise*.js'], dest: 'test/lib/' + }, + polyfill: { + expand: true, + flatten: true, + cwd: 'node_modules/', + src: ['es6-promise/dist/promise*.js'], + dest: 'dist/' } }, clean: ['dist/'], diff --git a/src/worker/worker.js b/src/worker/worker.js index 5e6baeb9..7f122b00 100644 --- a/src/worker/worker.js +++ b/src/worker/worker.js @@ -17,6 +17,32 @@ window = {}; // to make UMD bundles work +// 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; + }; +} + +if (typeof Promise === 'undefined') { + // promises polyfill + importScripts('promise-1.0.0.js'); +} importScripts('openpgp.js'); var MIN_SIZE_RANDOM_BUFFER = 40000;