Skip to content

Commit

Permalink
Fix csscritic-phantom.js runner choking on style elements
Browse files Browse the repository at this point in the history
Conflicts:
	Gruntfile.js
	test/run-csscritic-phantomjs.js
  • Loading branch information
Christoph Burgmer committed Mar 6, 2014
1 parent 6dc741d commit 86cf468
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function (grunt) {
' * imagediff.js (MIT License),\n' +
' * rasterizeHTML.js (MIT License) */\n\n'
},
src: ['src/utils.js', 'bower_components/jssha/src/sha256.js', 'bower_components/rasterizeHTML.js/dist/rasterizeHTML.allinone.js', 'bower_components/js-imagediff/imagediff.js', 'src/phantomjsrenderer.js', 'src/filestorage.js', 'src/<%= pkg.name %>.js', 'src/signoffreporter.js', 'src/terminalreporter.js', 'src/htmlfilereporter.js', 'src/phantomjs_runner.js'],
src: ['src/phantomjsbind.js', 'src/utils.js', 'bower_components/jssha/src/sha256.js', 'bower_components/rasterizeHTML.js/dist/rasterizeHTML.allinone.js', 'bower_components/js-imagediff/imagediff.js', 'src/phantomjsrenderer.js', 'src/filestorage.js', 'src/<%= pkg.name %>.js', 'src/signoffreporter.js', 'src/terminalreporter.js', 'src/htmlfilereporter.js', 'src/phantomjs_runner.js'],
dest: 'dist/<%= pkg.name %>-phantom.js'
},
server: {
Expand Down Expand Up @@ -148,7 +148,8 @@ module.exports = function (grunt) {
console: true,
require: true,
csscritic: true
}
},
ignores: ['src/phantomjsbind.js']
},
src: 'src/*.js',
},
Expand Down
25 changes: 25 additions & 0 deletions dist/csscritic-phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@
* imagediff.js (MIT License),
* rasterizeHTML.js (MIT License) */

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
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;
};
}

window.csscritic = (function (module) {
module.util = {};

Expand Down
24 changes: 24 additions & 0 deletions src/phantomjsbind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
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;
};
}
1 change: 1 addition & 0 deletions test/run-csscritic-phantomjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
phantom.injectJs("bower_components/js-imagediff/imagediff.js");
phantom.injectJs("bower_components/jssha/src/sha256.js");
phantom.injectJs("bower_components/rasterizeHTML.js/dist/rasterizeHTML.allinone.js");
phantom.injectJs("src/phantomjsbind.js");
phantom.injectJs("src/utils.js");
phantom.injectJs("src/phantomjsrenderer.js");
phantom.injectJs("src/signoffreporter.js");
Expand Down

0 comments on commit 86cf468

Please sign in to comment.