diff --git a/external/builder/builder.js b/external/builder/builder.js index 6eb0cd6ae..d4e47fc63 100644 --- a/external/builder/builder.js +++ b/external/builder/builder.js @@ -27,7 +27,8 @@ function preprocess(inFilename, outFilename, defines) { } return null; } - var writeLine = typeof outFilename === 'function' ? outFilename : function(line) { + var writeLine = typeof outFilename === 'function' ? outFilename : + function(line) { out += line + '\n'; } function include(file) { @@ -47,7 +48,8 @@ function preprocess(inFilename, outFilename, defines) { } var s, state = 0, stack = []; - var control = /^(?:\/\/|)?$)?/; + var control = + /^(?:\/\/|)?$)?/; var lineNumber = 0; while ((s = readLine()) !== null) { ++lineNumber; @@ -82,8 +84,8 @@ function preprocess(inFilename, outFilename, defines) { } else { if (state === 0) { writeLine(s); - } else if(state === 3) { - writeLine(s.replace(/^\/\/|^/g, " ")); + } else if (state === 3) { + writeLine(s.replace(/^\/\/|^/g, ' ')); } } } @@ -96,11 +98,11 @@ exports.preprocess = preprocess; /** * Simplifies common build steps. - * @param setup + * @param {object} setup * .defines defines for preprocessors * .copy array of arrays of source and destination pairs of files to copy * .preprocess array of arrays of source and destination pairs of files - * run through preprocessor + * run through preprocessor. */ function build(setup) { var defines = setup.defines; diff --git a/external/crlfchecker/crlfchecker.js b/external/crlfchecker/crlfchecker.js new file mode 100644 index 000000000..50522475e --- /dev/null +++ b/external/crlfchecker/crlfchecker.js @@ -0,0 +1,25 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +function checkIfCrlfIsPresent(files) { + var failed = []; + + (ls(files)).forEach(function checkCrlf(file) { + if ((cat(file)).match(/.*\r.*/)) { + failed.push(file); + } + }); + + if (failed.length) { + var errorMessage = + 'Please remove carriage return\'s from\n' + failed.join('\n') + '\n' + + 'Also check your setting for: git config core.autocrlf.'; + + echo(); + echo(errorMessage); + exit(1); + } +} + +exports.checkIfCrlfIsPresent = checkIfCrlfIsPresent; + diff --git a/make.js b/make.js index a4483c7eb..8b7be49da 100755 --- a/make.js +++ b/make.js @@ -1,6 +1,7 @@ #!/usr/bin/env node require('./external/shelljs/make'); var builder = require('./external/builder/builder.js'); +var crlfchecker = require('./external/crlfchecker/crlfchecker.js'); var ROOT_DIR = __dirname + '/', // absolute path to project's root BUILD_DIR = 'build/', @@ -218,6 +219,8 @@ target.bundle = function() { bundleVersion = exec('git log --format="%h" -n 1', {silent: true}).output.replace('\n', ''); + crlfchecker.checkIfCrlfIsPresent(SRC_FILES); + // This just preprocesses the empty pdf.js file, we don't actually want to // preprocess everything yet since other build targets use this file. builder.preprocess('pdf.js', ROOT_DIR + BUILD_TARGET, @@ -673,15 +676,17 @@ target.lint = function() { echo(); echo('### Linting JS files (this can take a while!)'); - var LINT_FILES = 'src/*.js \ - web/*.js \ - test/*.js \ - test/unit/*.js \ - extensions/firefox/*.js \ - extensions/firefox/components/*.js \ - extensions/chrome/*.js'; + var LINT_FILES = ['src/*.js', + 'web/*.js', + 'test/*.js', + 'test/unit/*.js', + 'extensions/firefox/*.js', + 'extensions/firefox/components/*.js', + 'extensions/chrome/*.js']; - exec('gjslint --nojsdoc ' + LINT_FILES); + exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); + + crlfchecker.checkIfCrlfIsPresent(LINT_FILES); }; // @@ -694,3 +699,4 @@ target.clean = function() { rm('-rf', BUILD_DIR); }; + diff --git a/src/fonts.js b/src/fonts.js index f0e1bd4d3..eda67df33 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -4100,7 +4100,7 @@ Type1Font.prototype = { // charstring changes size - can't cache .length in loop for (var i = 0; i < charstring.length; i++) { var command = charstring[i]; - if (command.charAt) { + if (typeof command === 'string') { var cmd = map[command]; assert(cmd, 'Unknow command: ' + command);