aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/autodebugger_js.py2
-rw-r--r--tools/eliminator/eliminator-test-output.js3
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/parse-js.js32
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/process.js72
-rw-r--r--tools/js-optimizer.js1138
-rw-r--r--tools/js_optimizer.py74
-rw-r--r--tools/node_modules/source-map/.npmignore2
-rw-r--r--tools/node_modules/source-map/.travis.yml4
-rw-r--r--tools/node_modules/source-map/CHANGELOG.md58
-rw-r--r--tools/node_modules/source-map/LICENSE28
-rw-r--r--tools/node_modules/source-map/Makefile.dryice.js166
-rw-r--r--tools/node_modules/source-map/README.md347
-rw-r--r--tools/node_modules/source-map/build/assert-shim.js56
-rw-r--r--tools/node_modules/source-map/build/mini-require.js152
-rw-r--r--tools/node_modules/source-map/build/prefix-source-map.jsm20
-rw-r--r--tools/node_modules/source-map/build/prefix-utils.jsm18
-rw-r--r--tools/node_modules/source-map/build/suffix-browser.js8
-rw-r--r--tools/node_modules/source-map/build/suffix-source-map.jsm6
-rw-r--r--tools/node_modules/source-map/build/suffix-utils.jsm21
-rw-r--r--tools/node_modules/source-map/build/test-prefix.js8
-rw-r--r--tools/node_modules/source-map/build/test-suffix.js3
-rw-r--r--tools/node_modules/source-map/lib/source-map.js8
-rw-r--r--tools/node_modules/source-map/lib/source-map/array-set.js96
-rw-r--r--tools/node_modules/source-map/lib/source-map/base64-vlq.js144
-rw-r--r--tools/node_modules/source-map/lib/source-map/base64.js42
-rw-r--r--tools/node_modules/source-map/lib/source-map/binary-search.js81
-rw-r--r--tools/node_modules/source-map/lib/source-map/source-map-consumer.js430
-rw-r--r--tools/node_modules/source-map/lib/source-map/source-map-generator.js381
-rw-r--r--tools/node_modules/source-map/lib/source-map/source-node.js353
-rw-r--r--tools/node_modules/source-map/lib/source-map/util.js117
-rw-r--r--tools/node_modules/source-map/node_modules/amdefine/LICENSE58
-rw-r--r--tools/node_modules/source-map/node_modules/amdefine/README.md119
-rw-r--r--tools/node_modules/source-map/node_modules/amdefine/amdefine.js299
-rw-r--r--tools/node_modules/source-map/node_modules/amdefine/package.json33
-rw-r--r--tools/node_modules/source-map/package.json74
-rwxr-xr-xtools/node_modules/source-map/test/run-tests.js73
-rw-r--r--tools/node_modules/source-map/test/source-map/test-api.js26
-rw-r--r--tools/node_modules/source-map/test/source-map/test-array-set.js71
-rw-r--r--tools/node_modules/source-map/test/source-map/test-base64-vlq.js24
-rw-r--r--tools/node_modules/source-map/test/source-map/test-base64.js35
-rw-r--r--tools/node_modules/source-map/test/source-map/test-binary-search.js54
-rw-r--r--tools/node_modules/source-map/test/source-map/test-dog-fooding.js72
-rw-r--r--tools/node_modules/source-map/test/source-map/test-source-map-consumer.js306
-rw-r--r--tools/node_modules/source-map/test/source-map/test-source-map-generator.js391
-rw-r--r--tools/node_modules/source-map/test/source-map/test-source-node.js282
-rw-r--r--tools/node_modules/source-map/test/source-map/util.js152
-rw-r--r--tools/shared.py96
-rw-r--r--tools/source-maps/sourcemap2json.js15
-rwxr-xr-xtools/source-maps/sourcemapper.js177
-rw-r--r--tools/test-js-optimizer-asm-last-output.js29
-rw-r--r--tools/test-js-optimizer-asm-last.js35
-rw-r--r--tools/test-js-optimizer-asm-outline-output.js570
-rw-r--r--tools/test-js-optimizer-asm-outline.js606
-rw-r--r--tools/test-js-optimizer-asm-pre-output.js18
-rw-r--r--tools/test-js-optimizer-asm-pre.js23
-rw-r--r--tools/test-js-optimizer-asm-relocate-output.js8
-rw-r--r--tools/test-js-optimizer-asm-relocate.js10
57 files changed, 7150 insertions, 376 deletions
diff --git a/tools/autodebugger_js.py b/tools/autodebugger_js.py
index 3f8818c6..1de837f0 100644
--- a/tools/autodebugger_js.py
+++ b/tools/autodebugger_js.py
@@ -33,7 +33,7 @@ for i in range(len(lines)):
(' else' not in lines[i-1] or '{' in lines[i-1]) and \
(' else' not in lines[i+1] or '{' in lines[i+1]):
var = m.groups(1)[0].rstrip().split(' ')[-1]
- if 'STACKTOP' not in lines[i] and 'stackBase' not in lines[i]:
+ if 'STACKTOP' not in lines[i] and 'sp' not in lines[i]:
#lines[i] += ''' print("[%4d] %s = " + %s);''' % (i+1, var, var)
lines[i] += ''' print("%s = " + %s);''' % (var, var)
m = re.match('^ +HEAP.*$', lines[i])
diff --git a/tools/eliminator/eliminator-test-output.js b/tools/eliminator/eliminator-test-output.js
index 801978ed..1a6506ed 100644
--- a/tools/eliminator/eliminator-test-output.js
+++ b/tools/eliminator/eliminator-test-output.js
@@ -2867,7 +2867,6 @@ function _inflate($strm, $flush) {
var $retval_0;
STACKTOP = __stackBase__;
return $retval_0;
- return null;
}
function _malloc($bytes) {
var __label__;
@@ -4482,7 +4481,6 @@ function _malloc($bytes) {
} while (0);
var $mem_0;
return $mem_0;
- return null;
}
function _mallocNoU($bytes) {
var __label__;
@@ -6097,7 +6095,6 @@ function _mallocNoU($bytes) {
} while (0);
var $mem_0;
return $mem_0;
- return null;
}
function asm(x, y) {
x = +x;
diff --git a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
index a89163c6..c7c2025f 100644
--- a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
+++ b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
@@ -679,7 +679,28 @@ function NodeWithToken(str, start, end) {
this.end = end;
};
-NodeWithToken.prototype.toString = function() { return this.name; };
+NodeWithToken.prototype = {
+ get length() {
+ return this.name.length;
+ },
+ set length(v) {
+ return this.name.length = v;
+ },
+ replace: function() { return this.name.replace.apply(this.name, arguments); },
+ concat: function() { return this.name.concat.apply(this.name, arguments); },
+ indexOf: function() { return this.name.indexOf.apply(this.name, arguments); },
+ lastIndexOf: function() { return this.name.lastIndexOf.apply(this.name, arguments); },
+ lastIndexOf: function() { return this.name.lastIndexOf.apply(this.name, arguments); },
+ match: function() { return this.name.match.apply(this.name, arguments); },
+ search: function() { return this.name.search.apply(this.name, arguments); },
+ slice: function() { return this.name.slice.apply(this.name, arguments); },
+ split: function() { return this.name.split.apply(this.name, arguments); },
+ substr: function() { return this.name.substr.apply(this.name, arguments); },
+ substring: function() { return this.name.substring.apply(this.name, arguments); },
+ toString: function() { return this.name; },
+ toJSON: function() { return this.name; },
+ valueOf: function() { return this.name; },
+};
function parse($TEXT, exigent_mode, embed_tokens) {
@@ -765,15 +786,12 @@ function parse($TEXT, exigent_mode, embed_tokens) {
return ex;
};
- function add_tokens(str, start, end) {
- return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end);
- };
-
function maybe_embed_tokens(parser) {
if (embed_tokens) return function() {
var start = S.token;
var ast = parser.apply(this, arguments);
- ast[0] = add_tokens(ast[0], start, prev());
+ ast.start = start;
+ ast.end = prev;
return ast;
};
else return parser;
@@ -1314,7 +1332,7 @@ function characters(str) {
function member(name, array) {
for (var i = array.length; --i >= 0;)
- if (array[i] === name)
+ if (array[i] == name)
return true;
return false;
};
diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js
index c3abb6f8..e1d692b2 100644
--- a/tools/eliminator/node_modules/uglify-js/lib/process.js
+++ b/tools/eliminator/node_modules/uglify-js/lib/process.js
@@ -64,6 +64,19 @@ var jsp = require("./parse-js"),
PRECEDENCE = jsp.PRECEDENCE,
OPERATORS = jsp.OPERATORS;
+function NodeWithLine(str, line) {
+ this.str = str;
+ this.line = line;
+}
+
+NodeWithLine.prototype = new String();
+NodeWithLine.prototype.toString = function() { return this.str; }
+NodeWithLine.prototype.valueOf = function() { return this.str; }
+NodeWithLine.prototype.lineComment = function() { return " //@line " + this.line; }
+
+// XXX ugly hack
+String.prototype.lineComment = function() { return ""; }
+
/* -----[ helper for AST traversal ]----- */
function ast_walker() {
@@ -1363,6 +1376,7 @@ var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for
function gen_code(ast, options) {
options = defaults(options, {
+ debug: false,
indent_start : 0,
indent_level : 4,
quote_keys : false,
@@ -1422,7 +1436,19 @@ function gen_code(ast, options) {
};
function add_commas(a) {
- return a.join("," + space);
+ var str = a.join("," + space);
+ if (options.debug) {
+ // if a line contains more than one comma-separated segment, assign it the
+ // original line number of the first NodeWithLine segment
+ for (var i = 0, l = a.length; i < l; i ++) {
+ var v = a[i];
+ if (v instanceof NodeWithLine) {
+ v.str = str;
+ return v
+ }
+ }
+ }
+ return str;
};
function parenthesize(expr) {
@@ -1484,7 +1510,10 @@ function gen_code(ast, options) {
a.push(m[2] + "e-" + (m[1].length + m[2].length),
str.substr(str.indexOf(".")));
}
- return best_of(a);
+ var best = best_of(a);
+ if (options.debug && this.start)
+ return new NodeWithLine(best, this.start.line);
+ return best;
};
var w = ast_walker();
@@ -1512,7 +1541,15 @@ function gen_code(ast, options) {
},
"block": make_block,
"var": function(defs) {
- return "var " + add_commas(MAP(defs, make_1vardef)) + ";";
+ var s = "var " + add_commas(MAP(defs, make_1vardef)) + ";";
+ if (options.debug) {
+ // hack: we don't support mapping one optimized line to more than one
+ // generated line, so in case of multiple comma-separated var definitions,
+ // just take the first
+ if (defs[0][1] && defs[0][1].start)
+ return s + (new NodeWithLine(s, defs[0][1].start.line)).lineComment();
+ }
+ return s;
},
"const": function(defs) {
return "const " + add_commas(MAP(defs, make_1vardef)) + ";";
@@ -1567,7 +1604,10 @@ function gen_code(ast, options) {
"assign": function(op, lvalue, rvalue) {
if (op && op !== true) op += "=";
else op = "=";
- return add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]);
+ var s = add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]);
+ if (options.debug && this.start)
+ return new NodeWithLine(s, this.start.line);
+ return s;
},
"dot": function(expr) {
var out = make(expr), i = 1;
@@ -1584,9 +1624,12 @@ function gen_code(ast, options) {
var f = make(func);
if (needs_parens(func))
f = "(" + f + ")";
- return f + "(" + add_commas(MAP(args, function(expr){
+ var str = f + "(" + add_commas(MAP(args, function(expr){
return parenthesize(expr, "seq");
})) + ")";
+ if (options.debug && this.start)
+ return new NodeWithLine(str, this.start.line)
+ return str;
},
"function": make_function,
"defun": make_function,
@@ -1621,8 +1664,9 @@ function gen_code(ast, options) {
},
"return": function(expr) {
var out = [ "return" ];
- if (expr != null) out.push(make(expr));
- return add_spaces(out) + ";";
+ var str = make(expr);
+ if (expr != null) out.push(str);
+ return add_spaces(out) + ";" + (str ? str.lineComment() : '');
},
"binary": function(operator, lvalue, rvalue) {
var left = make(lvalue), right = make(rvalue);
@@ -1642,7 +1686,16 @@ function gen_code(ast, options) {
&& rvalue[0] == "regexp" && /^script/i.test(rvalue[1])) {
right = " " + right;
}
- return add_spaces([ left, operator, right ]);
+ var str = add_spaces([ left, operator, right ]);
+ if (options.debug) {
+ if (this.start)
+ return new NodeWithLine(str, this.start.line);
+ else if (lvalue.start)
+ return new NodeWithLine(str, lvalue.start.line);
+ else if (rvalue.start)
+ return new NodeWithLine(str, rvalue.start.line);
+ }
+ return str;
},
"unary-prefix": function(operator, expr) {
var val = make(expr);
@@ -1698,7 +1751,8 @@ function gen_code(ast, options) {
})), "]" ]);
},
"stat": function(stmt) {
- return make(stmt).replace(/;*\s*$/, ";");
+ var str = make(stmt);
+ return str.replace(/;*\s*$/, ";") + str.lineComment();
},
"seq": function() {
return add_commas(MAP(slice(arguments), make));
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 7561abc8..71a59921 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -11,6 +11,7 @@
// *** Environment setup code ***
var arguments_ = [];
+var debug = false;
var ENVIRONMENT_IS_NODE = typeof process === 'object';
var ENVIRONMENT_IS_WEB = typeof window === 'object';
@@ -102,7 +103,7 @@ function globalEval(x) {
eval.call(null, x);
}
-if (typeof load == 'undefined' && typeof read != 'undefined') {
+if (typeof load === 'undefined' && typeof read != 'undefined') {
this['load'] = function(f) {
globalEval(read(f));
};
@@ -135,6 +136,9 @@ var CONTROL_FLOW = set('do', 'while', 'for', 'if', 'switch');
var NAME_OR_NUM = set('name', 'num');
var ASSOCIATIVE_BINARIES = set('+', '*', '|', '&', '^');
+var BREAK_CAPTURERS = set('do', 'while', 'for', 'switch');
+var CONTINUE_CAPTURERS = LOOP;
+
var NULL_NODE = ['name', 'null'];
var UNDEFINED_NODE = ['unary-prefix', 'void', ['num', 0]];
var TRUE_NODE = ['unary-prefix', '!', ['num', 0]];
@@ -146,11 +150,12 @@ var generatedFunctions = false; // whether we have received only generated funct
var extraInfo = null;
function srcToAst(src) {
- return uglify.parser.parse(src);
+ return uglify.parser.parse(src, false, debug);
}
function astToSrc(ast, minifyWhitespace) {
return uglify.uglify.gen_code(ast, {
+ debug: debug,
ascii_only: true,
beautify: !minifyWhitespace,
indent_level: 1
@@ -162,10 +167,10 @@ function astToSrc(ast, minifyWhitespace) {
function traverseChildren(node, traverse, pre, post, stack) {
for (var i = 0; i < node.length; i++) {
var subnode = node[i];
- if (typeof subnode == 'object' && subnode && subnode.length) {
+ if (Array.isArray(subnode)) {
var subresult = traverse(subnode, pre, post, stack);
- if (subresult == true) return true;
- if (subresult !== null && typeof subresult == 'object') node[i] = subresult;
+ if (subresult === true) return true;
+ if (subresult !== null && typeof subresult === 'object') node[i] = subresult;
}
}
}
@@ -186,16 +191,16 @@ function traverseChildren(node, traverse, pre, post, stack) {
// was stopped, true. Otherwise undefined.
function traverse(node, pre, post, stack) {
var type = node[0], result, len;
- var relevant = typeof type == 'string';
+ var relevant = typeof type === 'string';
if (relevant) {
if (stack) len = stack.length;
var result = pre(node, type, stack);
- if (result == true) return true;
- if (result !== null && typeof result == 'object') node = result; // Continue processing on this node
- if (stack && len == stack.length) stack.push(0);
+ if (result === true) return true;
+ if (result && result !== null) node = result; // Continue processing on this node
+ if (stack && len === stack.length) stack.push(0);
}
if (result !== null) {
- if (traverseChildren(node, traverse, pre, post, stack) == true) return true;
+ if (traverseChildren(node, traverse, pre, post, stack) === true) return true;
}
if (relevant) {
if (post) {
@@ -211,7 +216,7 @@ function traverse(node, pre, post, stack) {
function traverseGenerated(ast, pre, post, stack) {
assert(generatedFunctions);
traverse(ast, function(node) {
- if (node[0] == 'defun') {
+ if (node[0] === 'defun') {
traverse(node, pre, post, stack);
return null;
}
@@ -220,13 +225,13 @@ function traverseGenerated(ast, pre, post, stack) {
function traverseGeneratedFunctions(ast, callback) {
assert(generatedFunctions);
- if (ast[0] == 'toplevel') {
+ if (ast[0] === 'toplevel') {
var stats = ast[1];
for (var i = 0; i < stats.length; i++) {
var curr = stats[i];
- if (curr[0] == 'defun') callback(curr);
+ if (curr[0] === 'defun') callback(curr);
}
- } else if (ast[0] == 'defun') {
+ } else if (ast[0] === 'defun') {
callback(ast);
}
}
@@ -236,7 +241,7 @@ function traverseWithVariables(ast, callback) {
traverse(ast, function(node, type, stack) {
if (type in FUNCTION) {
stack.push({ type: 'function', vars: node[2] });
- } else if (type == 'var') {
+ } else if (type === 'var') {
// Find our function, add our vars
var func = stack[stack.length-1];
if (func) {
@@ -244,12 +249,12 @@ function traverseWithVariables(ast, callback) {
}
}
}, function(node, type, stack) {
- if (type == 'toplevel' || type in FUNCTION) {
+ if (type === 'toplevel' || type in FUNCTION) {
// We know all of the variables that are seen here, proceed to do relevant replacements
var allVars = stack.map(function(item) { return item ? item.vars : [] }).reduce(concatenator, []); // FIXME dictionary for speed?
traverse(node, function(node2, type2, stack2) {
// Be careful not to look into our inner functions. They have already been processed.
- if (sum(stack2) > 1 || (type == 'toplevel' && sum(stack2) == 1)) return;
+ if (sum(stack2) > 1 || (type === 'toplevel' && sum(stack2) === 1)) return;
if (type2 in FUNCTION) stack2.push(1);
return callback(node2, type2, allVars);
}, null, []);
@@ -262,7 +267,7 @@ function emptyNode() { // XXX do we need to create new nodes here? can't we reus
}
function isEmptyNode(node) {
- return node.length == 2 && node[0] == 'toplevel' && node[1].length == 0;
+ return node.length === 2 && node[0] === 'toplevel' && node[1].length === 0;
}
// Passes
@@ -284,7 +289,7 @@ function unGlobalize(ast) {
throw 'this is deprecated!'; // and does not work with parallel compilation
- assert(ast[0] == 'toplevel');
+ assert(ast[0] === 'toplevel');
var values = {};
// Find global renamings of the relevant values
ast[1].forEach(function(node, i) {
@@ -305,7 +310,7 @@ function unGlobalize(ast) {
ast[1][i][1][j] = emptyNode();
var assigned = false;
traverseWithVariables(ast, function(node, type, allVars) {
- if (type == 'assign' && node[2][0] == 'name' && node[2][1] == ident) assigned = true;
+ if (type === 'assign' && node[2][0] === 'name' && node[2][1] === ident) assigned = true;
});
ast[1][i][1][j] = [ident, value];
if (!assigned) {
@@ -315,12 +320,12 @@ function unGlobalize(ast) {
return true;
});
- if (node[1].length == 0) {
+ if (node[1].length === 0) {
ast[1][i] = emptyNode();
}
});
traverseWithVariables(ast, function(node, type, allVars) {
- if (type == 'name') {
+ if (type === 'name') {
var ident = node[1];
if (ident in values && allVars.indexOf(ident) < 0) {
return copy(values[ident]);
@@ -343,9 +348,9 @@ function unGlobalize(ast) {
// is now explicit.
function removeAssignsToUndefined(ast) {
traverse(ast, function(node, type) {
- if (type == 'assign' && jsonCompare(node[3], ['unary-prefix', 'void', ['num', 0]])) {
+ if (type === 'assign' && jsonCompare(node[3], ['unary-prefix', 'void', ['num', 0]])) {
return emptyNode();
- } else if (type == 'var') {
+ } else if (type === 'var') {
node[1] = node[1].map(function(varItem, j) {
var ident = varItem[0];
var value = varItem[1];
@@ -359,10 +364,10 @@ function removeAssignsToUndefined(ast) {
while (modified) {
modified = false;
traverse(ast, function(node, type) {
- if (type == 'assign' && jsonCompare(node[3], emptyNode())) {
+ if (type === 'assign' && jsonCompare(node[3], emptyNode())) {
modified = true;
return emptyNode();
- } else if (type == 'var') {
+ } else if (type === 'var') {
node[1] = node[1].map(function(varItem, j) {
var ident = varItem[0];
var value = varItem[1];
@@ -380,19 +385,19 @@ function removeAssignsToUndefined(ast) {
// are actually necessary. It's easy to clean those up now.
function removeUnneededLabelSettings(ast) {
traverse(ast, function(node, type) {
- if (type == 'defun') { // all of our compiled code is in defun nodes
+ if (type === 'defun') { // all of our compiled code is in defun nodes
// Find all checks
var checked = {};
traverse(node, function(node, type) {
- if (type == 'binary' && node[1] == '==' && node[2][0] == 'name' && node[2][1] == 'label') {
- assert(node[3][0] == 'num');
+ if (type === 'binary' && node[1] === '==' && node[2][0] === 'name' && node[2][1] === 'label') {
+ assert(node[3][0] === 'num');
checked[node[3][1]] = 1;
}
});
// Remove unneeded sets
traverse(node, function(node, type) {
- if (type == 'assign' && node[2][0] == 'name' && node[2][1] == 'label') {
- assert(node[3][0] == 'num');
+ if (type === 'assign' && node[2][0] === 'name' && node[2][1] === 'label') {
+ assert(node[3][0] === 'num');
if (!(node[3][1] in checked)) return emptyNode();
}
});
@@ -403,21 +408,33 @@ function removeUnneededLabelSettings(ast) {
// Various expression simplifications. Pre run before closure (where we still have metadata), Post run after.
var USEFUL_BINARY_OPS = set('<<', '>>', '|', '&', '^');
+var COMPARE_OPS = set('<', '<=', '>', '>=', '==', '===', '!=', '!==');
function simplifyExpressionsPre(ast) {
- // Look for (x&A)<<B>>B and replace it with X&A if possible.
- function simplifySignExtends(ast) {
+ // Simplify common expressions used to perform integer conversion operations
+ // in cases where no conversion is needed.
+ function simplifyIntegerConversions(ast) {
traverse(ast, function(node, type) {
- if (type == 'binary' && node[1] == '>>