From b13798f16c28b033910a59a6183c0398f0d75480 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 18 Aug 2012 23:01:01 +0300 Subject: [PATCH 1/6] Add carriage return checks to make.js. The target.bundle and target.lint will throw if carriage return's are present in the files that are being processed. --- make.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/make.js b/make.js index 1d2e5cfcf..94d0dee19 100755 --- a/make.js +++ b/make.js @@ -27,6 +27,16 @@ var DEFINES = { CHROME: false }; +// +// Helper functions +// +function throwIfCarriageReturnIsPresent(string) { + if (string.match(/.*\r.*/)) { + throw('Carriage Return\'s should not be present. Please remove them.\n' + + 'Also check your setting for: git config core.autocrlf'); + } +} + // // make all // @@ -218,6 +228,9 @@ target.bundle = function() { bundleVersion = exec('git log --format="%h" -n 1', {silent: true}).output.replace('\n', ''); + // Handle only src/*.js for now. + throwIfCarriageReturnIsPresent(cat('*.js')); + // 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, @@ -671,15 +684,18 @@ 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); + // Handle only src/*.js for now. + throwIfCarriageReturnIsPresent(cat('src/*.js')); + + exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); }; // @@ -692,3 +708,4 @@ target.clean = function() { rm('-rf', BUILD_DIR); }; + From 83eb405f2f9f2e20dab28d315233eb114143ba7b Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sun, 19 Aug 2012 00:55:23 +0300 Subject: [PATCH 2/6] Make lint warn if Carriage Returns are present instead of throwing. --- make.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/make.js b/make.js index 94d0dee19..bc04e8530 100755 --- a/make.js +++ b/make.js @@ -30,13 +30,29 @@ var DEFINES = { // // Helper functions // -function throwIfCarriageReturnIsPresent(string) { +function checkIfCarriageReturnsArePresent(string, throwOnError) { if (string.match(/.*\r.*/)) { - throw('Carriage Return\'s should not be present. Please remove them.\n' + - 'Also check your setting for: git config core.autocrlf'); + var errorMessage = + 'Carriage Return\'s should not be present. Please remove them.\n' + + 'Also check your setting for: git config core.autocrlf.'; + + if (throwOnError) { + throw(errorMessage); + } else { + echo(); + echo(errorMessage); + } } } +function throwIfCarriageReturnsArePresent(string) { + checkIfCarriageReturnsArePresent(string, true); +} + +function warnIfCarriageReturnsArePresent(string) { + checkIfCarriageReturnsArePresent(string, false); +} + // // make all // @@ -229,7 +245,7 @@ target.bundle = function() { {silent: true}).output.replace('\n', ''); // Handle only src/*.js for now. - throwIfCarriageReturnIsPresent(cat('*.js')); + throwIfCarriageReturnsArePresent(cat('*.js')); // This just preprocesses the empty pdf.js file, we don't actually want to // preprocess everything yet since other build targets use this file. @@ -692,10 +708,10 @@ target.lint = function() { 'extensions/firefox/components/*.js', 'extensions/chrome/*.js']; - // Handle only src/*.js for now. - throwIfCarriageReturnIsPresent(cat('src/*.js')); - exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); + + // Handle only src/*.js for now. + warnIfCarriageReturnsArePresent(cat('src/*.js')); }; // From 2ffd3ae1c73c17cd4513c28d03933b0d27d4a29f Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Mon, 20 Aug 2012 20:33:41 +0300 Subject: [PATCH 3/6] Create crlfchecker module and use it in make.js. Provide names of the files that contain crlf in the output. Exit(1) is used instead of throw. --- external/crlfchecker/crlfchecker.js | 25 +++++++++++++++++++++++ make.js | 31 +++-------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 external/crlfchecker/crlfchecker.js 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 bc04e8530..3ff04dedf 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/', @@ -27,32 +28,6 @@ var DEFINES = { CHROME: false }; -// -// Helper functions -// -function checkIfCarriageReturnsArePresent(string, throwOnError) { - if (string.match(/.*\r.*/)) { - var errorMessage = - 'Carriage Return\'s should not be present. Please remove them.\n' + - 'Also check your setting for: git config core.autocrlf.'; - - if (throwOnError) { - throw(errorMessage); - } else { - echo(); - echo(errorMessage); - } - } -} - -function throwIfCarriageReturnsArePresent(string) { - checkIfCarriageReturnsArePresent(string, true); -} - -function warnIfCarriageReturnsArePresent(string) { - checkIfCarriageReturnsArePresent(string, false); -} - // // make all // @@ -245,7 +220,7 @@ target.bundle = function() { {silent: true}).output.replace('\n', ''); // Handle only src/*.js for now. - throwIfCarriageReturnsArePresent(cat('*.js')); + crlfchecker.checkIfCrlfIsPresent(['*.js']); // This just preprocesses the empty pdf.js file, we don't actually want to // preprocess everything yet since other build targets use this file. @@ -711,7 +686,7 @@ target.lint = function() { exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); // Handle only src/*.js for now. - warnIfCarriageReturnsArePresent(cat('src/*.js')); + crlfchecker.checkIfCrlfIsPresent(['src/*.js']); }; // From 288705dab453ecce157d3f6c504580d7fff48e14 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Wed, 22 Aug 2012 12:22:58 +0300 Subject: [PATCH 4/6] Use crlf check for LINT_FILES and SRC_FILES. --- make.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/make.js b/make.js index 3ff04dedf..997a7e8f7 100755 --- a/make.js +++ b/make.js @@ -219,8 +219,7 @@ target.bundle = function() { bundleVersion = exec('git log --format="%h" -n 1', {silent: true}).output.replace('\n', ''); - // Handle only src/*.js for now. - crlfchecker.checkIfCrlfIsPresent(['*.js']); + 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. @@ -685,8 +684,7 @@ target.lint = function() { exec('gjslint --nojsdoc ' + LINT_FILES.join(' ')); - // Handle only src/*.js for now. - crlfchecker.checkIfCrlfIsPresent(['src/*.js']); + crlfchecker.checkIfCrlfIsPresent(LINT_FILES); }; // From 7bbf65f56e6c9670314dd1515669dde927c5616b Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Wed, 22 Aug 2012 12:48:47 +0300 Subject: [PATCH 5/6] Correct gjslint warnings in builder.js. --- external/builder/builder.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; From fad38f8286acc0a23b10cc95dda800530adaf160 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 21 Aug 2012 23:14:07 +0300 Subject: [PATCH 6/6] Update src/fonts.js One simple thing that came up while looking at the new Octane benchmark. --- src/fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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);