2017-03-24 17:46:12 +00:00
|
|
|
// derived from https://github.com/qfox/uglyfuzzer by Peter van der Zee
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2017-04-15 15:50:50 +00:00
|
|
|
// check both CLI and file modes of nodejs (!). See #1695 for details. and the various settings of uglify.
|
2017-03-31 09:23:50 +00:00
|
|
|
// bin/uglifyjs s.js -c && bin/uglifyjs s.js -c passes=3 && bin/uglifyjs s.js -c passes=3 -m
|
|
|
|
|
// cat s.js | node && node s.js && bin/uglifyjs s.js -c | node && bin/uglifyjs s.js -c passes=3 | node && bin/uglifyjs s.js -c passes=3 -m | node
|
|
|
|
|
|
2019-10-20 20:11:14 +00:00
|
|
|
require("../../tools/exit");
|
2017-03-24 17:46:12 +00:00
|
|
|
|
2019-10-20 20:11:14 +00:00
|
|
|
var UglifyJS = require("../..");
|
2017-04-01 09:09:52 +00:00
|
|
|
var randomBytes = require("crypto").randomBytes;
|
2019-10-20 20:11:14 +00:00
|
|
|
var sandbox = require("../sandbox");
|
2020-02-06 02:50:59 +00:00
|
|
|
var reduce_test = require("../reduce");
|
2017-03-24 17:46:12 +00:00
|
|
|
|
2017-04-01 21:11:29 +00:00
|
|
|
var MAX_GENERATED_TOPLEVELS_PER_RUN = 1;
|
2017-03-31 09:23:50 +00:00
|
|
|
var MAX_GENERATION_RECURSION_DEPTH = 12;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
var INTERVAL_COUNT = 100;
|
|
|
|
|
|
2017-04-22 14:15:04 +00:00
|
|
|
var STMT_ARG_TO_ID = Object.create(null);
|
|
|
|
|
var STMTS_TO_USE = [];
|
|
|
|
|
function STMT_(name) {
|
|
|
|
|
return STMT_ARG_TO_ID[name] = STMTS_TO_USE.push(STMTS_TO_USE.length) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var STMT_BLOCK = STMT_("block");
|
|
|
|
|
var STMT_IF_ELSE = STMT_("ifelse");
|
|
|
|
|
var STMT_DO_WHILE = STMT_("dowhile");
|
|
|
|
|
var STMT_WHILE = STMT_("while");
|
|
|
|
|
var STMT_FOR_LOOP = STMT_("forloop");
|
|
|
|
|
var STMT_FOR_IN = STMT_("forin");
|
|
|
|
|
var STMT_SEMI = STMT_("semi");
|
|
|
|
|
var STMT_EXPR = STMT_("expr");
|
|
|
|
|
var STMT_SWITCH = STMT_("switch");
|
|
|
|
|
var STMT_VAR = STMT_("var");
|
|
|
|
|
var STMT_RETURN_ETC = STMT_("stop");
|
|
|
|
|
var STMT_FUNC_EXPR = STMT_("funcexpr");
|
|
|
|
|
var STMT_TRY = STMT_("try");
|
|
|
|
|
var STMT_C = STMT_("c");
|
2017-03-31 09:23:50 +00:00
|
|
|
|
|
|
|
|
var STMT_FIRST_LEVEL_OVERRIDE = -1;
|
|
|
|
|
var STMT_SECOND_LEVEL_OVERRIDE = -1;
|
|
|
|
|
var STMT_COUNT_FROM_GLOBAL = true; // count statement depth from nearest function scope or just global scope?
|
|
|
|
|
|
|
|
|
|
var num_iterations = +process.argv[2] || 1/0;
|
|
|
|
|
var verbose = false; // log every generated test
|
|
|
|
|
var verbose_interval = false; // log every 100 generated tests
|
2017-04-23 12:05:22 +00:00
|
|
|
var use_strict = false;
|
2017-05-14 18:37:53 +00:00
|
|
|
var catch_redef = require.main === module;
|
|
|
|
|
var generate_directive = require.main === module;
|
2017-03-31 09:23:50 +00:00
|
|
|
for (var i = 2; i < process.argv.length; ++i) {
|
|
|
|
|
switch (process.argv[i]) {
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-v":
|
2017-03-31 21:47:11 +00:00
|
|
|
verbose = true;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-V":
|
2017-03-31 21:47:11 +00:00
|
|
|
verbose_interval = true;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-t":
|
2017-03-31 21:47:11 +00:00
|
|
|
MAX_GENERATED_TOPLEVELS_PER_RUN = +process.argv[++i];
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!MAX_GENERATED_TOPLEVELS_PER_RUN) throw new Error("Must generate at least one toplevel per run");
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-r":
|
2017-03-31 21:47:11 +00:00
|
|
|
MAX_GENERATION_RECURSION_DEPTH = +process.argv[++i];
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!MAX_GENERATION_RECURSION_DEPTH) throw new Error("Recursion depth must be at least 1");
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-s1":
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = process.argv[++i];
|
|
|
|
|
STMT_FIRST_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name];
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!(STMT_FIRST_LEVEL_OVERRIDE >= 0)) throw new Error("Unknown statement name; use -? to get a list");
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "-s2":
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = process.argv[++i];
|
|
|
|
|
STMT_SECOND_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name];
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!(STMT_SECOND_LEVEL_OVERRIDE >= 0)) throw new Error("Unknown statement name; use -? to get a list");
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--no-catch-redef":
|
2017-05-14 18:37:53 +00:00
|
|
|
catch_redef = false;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--no-directive":
|
2017-05-14 18:37:53 +00:00
|
|
|
generate_directive = false;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--use-strict":
|
2017-04-23 12:05:22 +00:00
|
|
|
use_strict = true;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--stmt-depth-from-func":
|
2017-03-31 21:47:11 +00:00
|
|
|
STMT_COUNT_FROM_GLOBAL = false;
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--only-stmt":
|
|
|
|
|
STMTS_TO_USE = process.argv[++i].split(",").map(function(name) {
|
|
|
|
|
return STMT_ARG_TO_ID[name];
|
|
|
|
|
});
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--without-stmt":
|
2017-03-31 21:47:11 +00:00
|
|
|
// meh. it runs once it's fine.
|
2019-10-27 06:17:35 +00:00
|
|
|
process.argv[++i].split(",").forEach(function(name) {
|
2017-03-31 21:47:11 +00:00
|
|
|
var omit = STMT_ARG_TO_ID[name];
|
2019-10-27 06:17:35 +00:00
|
|
|
STMTS_TO_USE = STMTS_TO_USE.filter(function(id) {
|
|
|
|
|
return id !== omit;
|
|
|
|
|
});
|
2017-03-31 21:47:11 +00:00
|
|
|
});
|
|
|
|
|
break;
|
2019-10-27 06:17:35 +00:00
|
|
|
case "--help":
|
|
|
|
|
case "-h":
|
|
|
|
|
case "-?":
|
|
|
|
|
println("** UglifyJS fuzzer help **");
|
|
|
|
|
println("Valid options (optional):");
|
|
|
|
|
println("<number>: generate this many cases (if used must be first arg)");
|
|
|
|
|
println("-v: print every generated test case");
|
|
|
|
|
println("-V: print every 100th generated test case");
|
|
|
|
|
println("-t <int>: generate this many toplevels per run (more take longer)");
|
|
|
|
|
println("-r <int>: maximum recursion depth for generator (higher takes longer)");
|
|
|
|
|
println("-s1 <statement name>: force the first level statement to be this one (see list below)");
|
|
|
|
|
println("-s2 <statement name>: force the second level statement to be this one (see list below)");
|
|
|
|
|
println("--no-catch-redef: do not redefine catch variables");
|
|
|
|
|
println("--no-directive: do not generate directives");
|
2017-06-09 07:56:28 +00:00
|
|
|
println('--use-strict: generate "use strict"');
|
2019-10-27 06:17:35 +00:00
|
|
|
println("--stmt-depth-from-func: reset statement depth counter at each function, counts from global otherwise");
|
|
|
|
|
println("--only-stmt <statement names>: a comma delimited white list of statements that may be generated");
|
|
|
|
|
println("--without-stmt <statement names>: a comma delimited black list of statements never to generate");
|
|
|
|
|
println("List of accepted statement names: " + Object.keys(STMT_ARG_TO_ID));
|
|
|
|
|
println("** UglifyJS fuzzer exiting **");
|
2017-03-31 21:47:11 +00:00
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
// first arg may be a number.
|
2019-10-27 06:17:35 +00:00
|
|
|
if (i > 2 || !parseInt(process.argv[i], 10)) throw new Error("Unknown argument[" + process.argv[i] + "]; see -h for help");
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
var VALUES = [
|
2018-01-05 21:54:53 +00:00
|
|
|
'"a"',
|
|
|
|
|
'"b"',
|
|
|
|
|
'"c"',
|
2017-04-02 20:00:33 +00:00
|
|
|
'""',
|
2019-10-27 06:17:35 +00:00
|
|
|
"true",
|
|
|
|
|
"false",
|
|
|
|
|
" /[a2][^e]+$/ ",
|
|
|
|
|
"(-1)",
|
|
|
|
|
"(-2)",
|
|
|
|
|
"(-3)",
|
|
|
|
|
"(-4)",
|
|
|
|
|
"(-5)",
|
|
|
|
|
"0",
|
|
|
|
|
"1",
|
|
|
|
|
"2",
|
|
|
|
|
"3",
|
|
|
|
|
"4",
|
|
|
|
|
"5",
|
|
|
|
|
"22",
|
|
|
|
|
"-0", // 0/-0 !== 0
|
|
|
|
|
"23..toString()",
|
|
|
|
|
"24 .toString()",
|
|
|
|
|
"25. ",
|
|
|
|
|
"0x26.toString()",
|
|
|
|
|
"NaN",
|
|
|
|
|
"undefined",
|
|
|
|
|
"Infinity",
|
|
|
|
|
"null",
|
|
|
|
|
"[]",
|
|
|
|
|
"[,0][1]", // an array with elisions... but this is always false
|
|
|
|
|
"([,0].length === 2)", // an array with elisions... this is always true
|
|
|
|
|
"({})", // wrapped the object causes too many syntax errors in statements
|
2017-03-31 09:23:50 +00:00
|
|
|
'"foo"',
|
2017-04-01 18:08:46 +00:00
|
|
|
'"bar"',
|
|
|
|
|
'"undefined"',
|
|
|
|
|
'"object"',
|
|
|
|
|
'"number"',
|
|
|
|
|
'"function"',
|
2019-10-27 06:17:35 +00:00
|
|
|
"this",
|
2017-04-01 18:08:46 +00:00
|
|
|
];
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
|
|
|
|
var BINARY_OPS_NO_COMMA = [
|
2019-10-27 06:17:35 +00:00
|
|
|
" + ", // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors)
|
|
|
|
|
" - ",
|
|
|
|
|
"/",
|
|
|
|
|
"*",
|
|
|
|
|
"&",
|
|
|
|
|
"|",
|
|
|
|
|
"^",
|
|
|
|
|
"<",
|
|
|
|
|
"<=",
|
|
|
|
|
">",
|
|
|
|
|
">=",
|
|
|
|
|
"==",
|
|
|
|
|
"===",
|
|
|
|
|
"!=",
|
|
|
|
|
"!==",
|
|
|
|
|
"<<",
|
|
|
|
|
">>",
|
|
|
|
|
">>>",
|
|
|
|
|
"%",
|
|
|
|
|
"&&",
|
|
|
|
|
"||",
|
|
|
|
|
"^" ];
|
|
|
|
|
|
|
|
|
|
var BINARY_OPS = [","].concat(BINARY_OPS_NO_COMMA);
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
|
|
|
|
var ASSIGNMENTS = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
"=",
|
|
|
|
|
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
"+=",
|
|
|
|
|
|
|
|
|
|
"-=",
|
|
|
|
|
"*=",
|
|
|
|
|
"/=",
|
|
|
|
|
"&=",
|
|
|
|
|
"|=",
|
|
|
|
|
"^=",
|
|
|
|
|
"<<=",
|
|
|
|
|
">>=",
|
|
|
|
|
">>>=",
|
|
|
|
|
"%=",
|
2017-05-13 18:10:34 +00:00
|
|
|
];
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
2017-04-07 10:47:30 +00:00
|
|
|
var UNARY_SAFE = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"+",
|
|
|
|
|
"-",
|
|
|
|
|
"~",
|
|
|
|
|
"!",
|
|
|
|
|
"void ",
|
|
|
|
|
"delete ",
|
2017-04-07 10:47:30 +00:00
|
|
|
];
|
|
|
|
|
var UNARY_POSTFIX = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"++",
|
|
|
|
|
"--",
|
2017-04-07 10:47:30 +00:00
|
|
|
];
|
|
|
|
|
var UNARY_PREFIX = UNARY_POSTFIX.concat(UNARY_SAFE);
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
|
|
|
|
var NO_COMMA = true;
|
2017-03-31 09:23:50 +00:00
|
|
|
var COMMA_OK = false;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
var MAYBE = true;
|
2017-03-31 09:23:50 +00:00
|
|
|
var MANDATORY = false;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
var CAN_THROW = true;
|
|
|
|
|
var CANNOT_THROW = false;
|
|
|
|
|
var CAN_BREAK = true;
|
2017-03-31 09:23:50 +00:00
|
|
|
var CANNOT_BREAK = false;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
var CAN_CONTINUE = true;
|
2017-03-31 09:23:50 +00:00
|
|
|
var CANNOT_CONTINUE = false;
|
|
|
|
|
var CAN_RETURN = false;
|
|
|
|
|
var CANNOT_RETURN = true;
|
2017-12-20 15:52:18 +00:00
|
|
|
var NO_DEFUN = false;
|
|
|
|
|
var DEFUN_OK = true;
|
2017-03-31 09:23:50 +00:00
|
|
|
var DONT_STORE = true;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
|
|
|
|
var VAR_NAMES = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"a",
|
|
|
|
|
"a",
|
|
|
|
|
"a",
|
|
|
|
|
"a",
|
|
|
|
|
"b",
|
|
|
|
|
"b",
|
|
|
|
|
"b",
|
|
|
|
|
"b",
|
|
|
|
|
"c", // prevent redeclaring this, avoid assigning to this
|
|
|
|
|
"foo",
|
|
|
|
|
"foo",
|
|
|
|
|
"bar",
|
|
|
|
|
"bar",
|
|
|
|
|
"undefined",
|
|
|
|
|
"NaN",
|
|
|
|
|
"Infinity",
|
|
|
|
|
"arguments",
|
|
|
|
|
"Math",
|
|
|
|
|
"parseInt",
|
2017-04-07 10:47:30 +00:00
|
|
|
];
|
2017-03-31 09:23:50 +00:00
|
|
|
var INITIAL_NAMES_LEN = VAR_NAMES.length;
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
|
|
|
|
var TYPEOF_OUTCOMES = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"function",
|
|
|
|
|
"undefined",
|
|
|
|
|
"string",
|
|
|
|
|
"number",
|
|
|
|
|
"object",
|
|
|
|
|
"boolean",
|
|
|
|
|
"special",
|
|
|
|
|
"unknown",
|
|
|
|
|
"symbol",
|
|
|
|
|
"crap",
|
|
|
|
|
];
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
|
2017-05-14 18:37:53 +00:00
|
|
|
var unique_vars = [];
|
2017-03-31 09:23:50 +00:00
|
|
|
var loops = 0;
|
|
|
|
|
var funcs = 0;
|
2017-12-20 15:52:18 +00:00
|
|
|
var called = Object.create(null);
|
2017-04-22 14:15:04 +00:00
|
|
|
var labels = 10000;
|
2017-03-26 10:18:44 +00:00
|
|
|
|
2017-03-24 17:46:12 +00:00
|
|
|
function rng(max) {
|
2017-04-01 21:11:29 +00:00
|
|
|
var r = randomBytes(2).readUInt16LE(0) / 65536;
|
2017-04-01 09:09:52 +00:00
|
|
|
return Math.floor(max * r);
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-23 12:05:22 +00:00
|
|
|
function strictMode() {
|
2019-10-27 06:17:35 +00:00
|
|
|
return use_strict && rng(4) == 0 ? '"use strict";' : "";
|
2017-04-23 12:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 09:23:50 +00:00
|
|
|
function createTopLevelCode() {
|
2017-05-14 18:37:53 +00:00
|
|
|
VAR_NAMES.length = INITIAL_NAMES_LEN; // prune any previous names still in the list
|
|
|
|
|
unique_vars.length = 0;
|
|
|
|
|
loops = 0;
|
|
|
|
|
funcs = 0;
|
2017-12-20 15:52:18 +00:00
|
|
|
called = Object.create(null);
|
2017-04-23 12:05:22 +00:00
|
|
|
return [
|
|
|
|
|
strictMode(),
|
2019-10-27 06:17:35 +00:00
|
|
|
"var _calls_ = 10, a = 100, b = 10, c = 0;",
|
2017-04-23 12:05:22 +00:00
|
|
|
rng(2) == 0
|
|
|
|
|
? createStatements(3, MAX_GENERATION_RECURSION_DEPTH, CANNOT_THROW, CANNOT_BREAK, CANNOT_CONTINUE, CANNOT_RETURN, 0)
|
2017-12-20 15:52:18 +00:00
|
|
|
: createFunctions(rng(MAX_GENERATED_TOPLEVELS_PER_RUN) + 1, MAX_GENERATION_RECURSION_DEPTH, DEFUN_OK, CANNOT_THROW, 0),
|
2017-12-28 07:36:55 +00:00
|
|
|
// preceding `null` makes for a cleaner output (empty string still shows up etc)
|
2019-10-27 06:17:35 +00:00
|
|
|
"console.log(null, a, b, c, Infinity, NaN, undefined);"
|
|
|
|
|
].join("\n");
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 15:52:18 +00:00
|
|
|
function createFunctions(n, recurmax, allowDefun, canThrow, stmtDepth) {
|
2019-10-27 06:17:35 +00:00
|
|
|
if (--recurmax < 0) { return ";"; }
|
|
|
|
|
var s = "";
|
2017-03-31 09:23:50 +00:00
|
|
|
while (n-- > 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
s += createFunction(recurmax, allowDefun, canThrow, stmtDepth) + "\n";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
return s;
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-07 10:47:30 +00:00
|
|
|
function createParams() {
|
|
|
|
|
var params = [];
|
|
|
|
|
for (var n = rng(4); --n >= 0;) {
|
|
|
|
|
params.push(createVarName(MANDATORY));
|
|
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
return params.join(", ");
|
2017-04-07 10:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-04 08:29:42 +00:00
|
|
|
function createArgs(recurmax, stmtDepth, canThrow) {
|
2017-04-07 10:47:30 +00:00
|
|
|
var args = [];
|
|
|
|
|
for (var n = rng(4); --n >= 0;) {
|
2017-11-05 04:49:14 +00:00
|
|
|
args.push(rng(2) ? createValue() : createExpression(recurmax - 1, COMMA_OK, stmtDepth, canThrow));
|
2017-04-07 10:47:30 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
return args.join(", ");
|
2017-04-07 10:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-14 18:37:53 +00:00
|
|
|
function filterDirective(s) {
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!generate_directive && !s[1] && /\("/.test(s[2])) s[2] = ";" + s[2];
|
2017-05-14 18:37:53 +00:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 15:52:18 +00:00
|
|
|
function createFunction(recurmax, allowDefun, canThrow, stmtDepth) {
|
2019-10-27 06:17:35 +00:00
|
|
|
if (--recurmax < 0) { return ";"; }
|
2017-03-31 09:23:50 +00:00
|
|
|
if (!STMT_COUNT_FROM_GLOBAL) stmtDepth = 0;
|
|
|
|
|
var namesLenBefore = VAR_NAMES.length;
|
2017-05-14 18:37:53 +00:00
|
|
|
var name;
|
2017-12-20 15:52:18 +00:00
|
|
|
if (allowDefun || rng(5) > 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
name = "f" + funcs++;
|
2017-12-20 15:52:18 +00:00
|
|
|
} else {
|
2019-10-27 06:17:35 +00:00
|
|
|
unique_vars.push("a", "b", "c");
|
2017-12-20 15:52:18 +00:00
|
|
|
name = createVarName(MANDATORY, !allowDefun);
|
2017-05-14 18:37:53 +00:00
|
|
|
unique_vars.length -= 3;
|
|
|
|
|
}
|
|
|
|
|
var s = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"function " + name + "(" + createParams() + "){",
|
2017-05-14 18:37:53 +00:00
|
|
|
strictMode()
|
|
|
|
|
];
|
2017-04-01 21:11:29 +00:00
|
|
|
if (rng(5) === 0) {
|
2017-03-31 09:23:50 +00:00
|
|
|
// functions with functions. lower the recursion to prevent a mess.
|
2017-12-20 15:52:18 +00:00
|
|
|
s.push(createFunctions(rng(5) + 1, Math.ceil(recurmax * 0.7), DEFUN_OK, canThrow, stmtDepth));
|
2017-03-31 09:23:50 +00:00
|
|
|
} else {
|
|
|
|
|
// functions with statements
|
2017-05-14 18:37:53 +00:00
|
|
|
s.push(createStatements(3, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth));
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
s.push("}", "");
|
|
|
|
|
s = filterDirective(s).join("\n");
|
2017-03-31 09:23:50 +00:00
|
|
|
|
|
|
|
|
VAR_NAMES.length = namesLenBefore;
|
|
|
|
|
|
2017-12-20 15:52:18 +00:00
|
|
|
if (!allowDefun) {
|
|
|
|
|
// avoid "function statements" (decl inside statements)
|
2019-10-27 06:17:35 +00:00
|
|
|
s = "var " + createVarName(MANDATORY) + " = " + s;
|
|
|
|
|
s += "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
2017-12-20 15:52:18 +00:00
|
|
|
} else if (!(name in called) || rng(3) > 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
s += "var " + createVarName(MANDATORY) + " = " + name;
|
|
|
|
|
s += "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
2017-12-20 15:52:18 +00:00
|
|
|
}
|
2017-03-31 09:23:50 +00:00
|
|
|
|
2019-10-27 06:17:35 +00:00
|
|
|
return s + ";";
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:47:11 +00:00
|
|
|
function createStatements(n, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) {
|
2019-10-27 06:17:35 +00:00
|
|
|
if (--recurmax < 0) { return ";"; }
|
|
|
|
|
var s = "";
|
2017-03-31 09:23:50 +00:00
|
|
|
while (--n > 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
s += createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "\n";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 14:15:04 +00:00
|
|
|
function enableLoopControl(flag, defaultValue) {
|
|
|
|
|
return Array.isArray(flag) && flag.indexOf("") < 0 ? flag.concat("") : flag || defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createLabel(canBreak, canContinue) {
|
|
|
|
|
var label;
|
|
|
|
|
if (rng(10) < 3) {
|
|
|
|
|
label = ++labels;
|
|
|
|
|
if (Array.isArray(canBreak)) {
|
|
|
|
|
canBreak = canBreak.slice();
|
|
|
|
|
} else {
|
|
|
|
|
canBreak = canBreak ? [ "" ] : [];
|
|
|
|
|
}
|
|
|
|
|
canBreak.push(label);
|
|
|
|
|
if (Array.isArray(canContinue)) {
|
|
|
|
|
canContinue = canContinue.slice();
|
|
|
|
|
} else {
|
|
|
|
|
canContinue = canContinue ? [ "" ] : [];
|
|
|
|
|
}
|
|
|
|
|
canContinue.push(label);
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
break: canBreak,
|
|
|
|
|
continue: canContinue,
|
|
|
|
|
target: label ? "L" + label + ": " : ""
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getLabel(label) {
|
|
|
|
|
if (!Array.isArray(label)) return "";
|
|
|
|
|
label = label[rng(label.length)];
|
|
|
|
|
return label && " L" + label;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 18:10:34 +00:00
|
|
|
function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth, target) {
|
2017-03-31 09:23:50 +00:00
|
|
|
++stmtDepth;
|
|
|
|
|
var loop = ++loops;
|
|
|
|
|
if (--recurmax < 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ";";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allow to forcefully generate certain structures at first or second recursion level
|
2017-05-13 18:10:34 +00:00
|
|
|
if (target === undefined) {
|
|
|
|
|
if (stmtDepth === 1 && STMT_FIRST_LEVEL_OVERRIDE >= 0) target = STMT_FIRST_LEVEL_OVERRIDE;
|
|
|
|
|
else if (stmtDepth === 2 && STMT_SECOND_LEVEL_OVERRIDE >= 0) target = STMT_SECOND_LEVEL_OVERRIDE;
|
|
|
|
|
else target = STMTS_TO_USE[rng(STMTS_TO_USE.length)];
|
|
|
|
|
}
|
2017-03-31 09:23:50 +00:00
|
|
|
|
|
|
|
|
switch (target) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_BLOCK:
|
2017-04-22 14:15:04 +00:00
|
|
|
var label = createLabel(canBreak);
|
2019-10-27 06:17:35 +00:00
|
|
|
return label.target + "{" + createStatements(rng(5) + 1, recurmax, canThrow, label.break, canContinue, cannotReturn, stmtDepth) + "}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_IF_ELSE:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "if (" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ")" + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + (rng(2) === 1 ? " else " + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) : "");
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_DO_WHILE:
|
2017-04-22 14:15:04 +00:00
|
|
|
var label = createLabel(canBreak, canContinue);
|
|
|
|
|
canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK);
|
|
|
|
|
canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE);
|
2019-10-27 06:17:35 +00:00
|
|
|
return "{var brake" + loop + " = 5; " + label.target + "do {" + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "} while ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") && --brake" + loop + " > 0);}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_WHILE:
|
2017-04-22 14:15:04 +00:00
|
|
|
var label = createLabel(canBreak, canContinue);
|
|
|
|
|
canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK);
|
|
|
|
|
canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE);
|
2019-10-27 06:17:35 +00:00
|
|
|
return "{var brake" + loop + " = 5; " + label.target + "while ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") && --brake" + loop + " > 0)" + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_FOR_LOOP:
|
2017-04-22 14:15:04 +00:00
|
|
|
var label = createLabel(canBreak, canContinue);
|
|
|
|
|
canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK);
|
|
|
|
|
canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE);
|
2019-10-27 06:17:35 +00:00
|
|
|
return label.target + "for (var brake" + loop + " = 5; (" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") && brake" + loop + " > 0; --brake" + loop + ")" + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth);
|
2017-04-22 14:15:04 +00:00
|
|
|
case STMT_FOR_IN:
|
|
|
|
|
var label = createLabel(canBreak, canContinue);
|
|
|
|
|
canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK);
|
|
|
|
|
canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE);
|
2019-10-27 06:17:35 +00:00
|
|
|
var optElementVar = "";
|
2017-04-22 14:15:04 +00:00
|
|
|
if (rng(5) > 1) {
|
2019-10-27 06:17:35 +00:00
|
|
|
optElementVar = "c = 1 + c; var " + createVarName(MANDATORY) + " = expr" + loop + "[key" + loop + "]; ";
|
2017-04-22 14:15:04 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
return "{var expr" + loop + " = " + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "; " + label.target + " for (var key" + loop + " in expr" + loop + ") {" + optElementVar + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "}}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_SEMI:
|
2019-10-27 06:17:35 +00:00
|
|
|
return use_strict && rng(20) === 0 ? '"use strict";' : ";";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_EXPR:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ";";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_SWITCH:
|
|
|
|
|
// note: case args are actual expressions
|
|
|
|
|
// note: default does not _need_ to be last
|
2019-10-27 06:17:35 +00:00
|
|
|
return "switch (" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") { " + createSwitchParts(recurmax, 4, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_VAR:
|
|
|
|
|
switch (rng(3)) {
|
|
|
|
|
case 0:
|
2019-10-27 06:17:35 +00:00
|
|
|
unique_vars.push("c");
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = createVarName(MANDATORY);
|
2017-05-14 18:37:53 +00:00
|
|
|
unique_vars.pop();
|
2019-10-27 06:17:35 +00:00
|
|
|
return "var " + name + ";";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 1:
|
|
|
|
|
// initializer can only have one expression
|
2019-10-27 06:17:35 +00:00
|
|
|
unique_vars.push("c");
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = createVarName(MANDATORY);
|
2017-05-14 18:37:53 +00:00
|
|
|
unique_vars.pop();
|
2019-10-27 06:17:35 +00:00
|
|
|
return "var " + name + " = " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
2017-03-31 21:47:11 +00:00
|
|
|
default:
|
|
|
|
|
// initializer can only have one expression
|
2019-10-27 06:17:35 +00:00
|
|
|
unique_vars.push("c");
|
2017-03-31 21:47:11 +00:00
|
|
|
var n1 = createVarName(MANDATORY);
|
|
|
|
|
var n2 = createVarName(MANDATORY);
|
2017-05-14 18:37:53 +00:00
|
|
|
unique_vars.pop();
|
2019-10-27 06:17:35 +00:00
|
|
|
return "var " + n1 + " = " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ", " + n2 + " = " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
|
|
|
|
case STMT_RETURN_ETC:
|
2017-04-08 17:36:38 +00:00
|
|
|
switch (rng(8)) {
|
|
|
|
|
case 0:
|
2017-03-31 21:47:11 +00:00
|
|
|
case 1:
|
2017-04-08 17:36:38 +00:00
|
|
|
case 2:
|
|
|
|
|
case 3:
|
2019-10-27 06:17:35 +00:00
|
|
|
if (canBreak && rng(5) === 0) return "break" + getLabel(canBreak) + ";";
|
|
|
|
|
if (canContinue && rng(5) === 0) return "continue" + getLabel(canContinue) + ";";
|
|
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
|
|
|
|
if (rng(3) == 0) return "/*3*/return;";
|
|
|
|
|
return "return " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
2017-04-08 17:36:38 +00:00
|
|
|
case 4:
|
2017-03-31 21:47:11 +00:00
|
|
|
// this is actually more like a parser test, but perhaps it hits some dead code elimination traps
|
|
|
|
|
// must wrap in curlies to prevent orphaned `else` statement
|
|
|
|
|
// note: you can't `throw` without an expression so don't put a `throw` option in this case
|
2019-10-27 06:17:35 +00:00
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
|
|
|
|
return "{ /*2*/ return\n" + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + "}";
|
2017-04-08 17:36:38 +00:00
|
|
|
default:
|
|
|
|
|
// must wrap in curlies to prevent orphaned `else` statement
|
2019-10-27 06:17:35 +00:00
|
|
|
if (canThrow && rng(5) === 0) return "{ throw " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + "}";
|
|
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ";";
|
|
|
|
|
return "{ return " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + "}";
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
|
|
|
|
case STMT_FUNC_EXPR:
|
|
|
|
|
// "In non-strict mode code, functions can only be declared at top level, inside a block, or ..."
|
|
|
|
|
// (dont both with func decls in `if`; it's only a parser thing because you cant call them without a block)
|
2019-10-27 06:17:35 +00:00
|
|
|
return "{" + createFunction(recurmax, NO_DEFUN, canThrow, stmtDepth) + "}";
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_TRY:
|
|
|
|
|
// catch var could cause some problems
|
|
|
|
|
// note: the "blocks" are syntactically mandatory for try/catch/finally
|
|
|
|
|
var n = rng(3); // 0=only catch, 1=only finally, 2=catch+finally
|
2019-10-27 06:17:35 +00:00
|
|
|
var s = "try {" + createStatement(recurmax, n === 1 ? CANNOT_THROW : CAN_THROW, canBreak, canContinue, cannotReturn, stmtDepth) + " }";
|
2017-03-31 21:47:11 +00:00
|
|
|
if (n !== 1) {
|
|
|
|
|
// the catch var should only be accessible in the catch clause...
|
|
|
|
|
// we have to do go through some trouble here to prevent leaking it
|
|
|
|
|
var nameLenBefore = VAR_NAMES.length;
|
|
|
|
|
var catchName = createVarName(MANDATORY);
|
|
|
|
|
var freshCatchName = VAR_NAMES.length !== nameLenBefore;
|
2017-05-14 18:37:53 +00:00
|
|
|
if (!catch_redef) unique_vars.push(catchName);
|
2019-10-27 06:17:35 +00:00
|
|
|
s += " catch (" + catchName + ") { " + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + " }";
|
2017-05-14 18:37:53 +00:00
|
|
|
// remove catch name
|
|
|
|
|
if (!catch_redef) unique_vars.pop();
|
|
|
|
|
if (freshCatchName) VAR_NAMES.splice(nameLenBefore, 1);
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
if (n !== 0) s += " finally { " + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + " }";
|
2017-03-31 21:47:11 +00:00
|
|
|
return s;
|
|
|
|
|
case STMT_C:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "c = c + 1;";
|
2017-03-31 21:47:11 +00:00
|
|
|
default:
|
2019-10-27 06:17:35 +00:00
|
|
|
throw "no";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:47:11 +00:00
|
|
|
function createSwitchParts(recurmax, n, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) {
|
2017-03-31 09:23:50 +00:00
|
|
|
var hadDefault = false;
|
2019-10-27 06:17:35 +00:00
|
|
|
var s = [""];
|
2017-04-22 14:15:04 +00:00
|
|
|
canBreak = enableLoopControl(canBreak, CAN_BREAK);
|
2017-03-31 09:23:50 +00:00
|
|
|
while (n-- > 0) {
|
|
|
|
|
//hadDefault = n > 0; // disables weird `default` clause positioning (use when handling destabilizes)
|
|
|
|
|
if (hadDefault || rng(5) > 0) {
|
2017-04-22 14:15:04 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"case " + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ":",
|
2017-04-22 14:15:04 +00:00
|
|
|
createStatements(rng(3) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
rng(10) > 0 ? " break;" : "/* fall-through */",
|
|
|
|
|
""
|
2017-04-22 14:15:04 +00:00
|
|
|
);
|
2017-03-31 09:23:50 +00:00
|
|
|
} else {
|
|
|
|
|
hadDefault = true;
|
2017-04-22 14:15:04 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"default:",
|
2017-04-22 14:15:04 +00:00
|
|
|
createStatements(rng(3) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
""
|
2017-04-22 14:15:04 +00:00
|
|
|
);
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
return s.join("\n");
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 09:23:50 +00:00
|
|
|
function createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|
|
|
|
if (--recurmax < 0) {
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(c = 1 + c, " + createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")"; // note: should return a simple non-recursing expression value!
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
// since `a` and `b` are our canaries we want them more frequently than other expressions (1/3rd chance of a canary)
|
2017-04-07 10:47:30 +00:00
|
|
|
switch (rng(6)) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case 0:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(a++ + (" + _createExpression(recurmax, noComma, stmtDepth, canThrow) + "))";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 1:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "((--b) + (" + _createExpression(recurmax, noComma, stmtDepth, canThrow) + "))";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 2:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "((c = c + 1) + (" + _createExpression(recurmax, noComma, stmtDepth, canThrow) + "))"; // c only gets incremented
|
2017-04-07 10:47:30 +00:00
|
|
|
default:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(" + _createExpression(recurmax, noComma, stmtDepth, canThrow) + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
|
2017-04-07 10:47:30 +00:00
|
|
|
function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|
|
|
|
var p = 0;
|
|
|
|
|
switch (rng(_createExpression.N)) {
|
|
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createUnaryPrefix() + (rng(2) === 1 ? "a" : "b");
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return (rng(2) === 1 ? "a" : "b") + createUnaryPostfix();
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2017-03-31 21:47:11 +00:00
|
|
|
// parens needed because assignments aren't valid unless they're the left-most op(s) in an expression
|
2019-10-27 06:17:35 +00:00
|
|
|
return "b " + createAssignment() + " a";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return rng(2) + " === 1 ? a : b";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2017-03-31 21:47:11 +00:00
|
|
|
return createValue();
|
2017-11-04 08:29:42 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
|
|
|
|
return getVarName();
|
2017-12-28 07:36:55 +00:00
|
|
|
case p++:
|
|
|
|
|
return getVarName() + createAssignment() + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createExpression(recurmax, noComma, stmtDepth, canThrow) + "?" + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ":" + createExpression(recurmax, noComma, stmtDepth, canThrow);
|
2017-04-23 12:05:22 +00:00
|
|
|
case p++:
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-03-31 21:47:11 +00:00
|
|
|
var nameLenBefore = VAR_NAMES.length;
|
2019-10-27 06:17:35 +00:00
|
|
|
unique_vars.push("c");
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = createVarName(MAYBE); // note: this name is only accessible from _within_ the function. and immutable at that.
|
2017-05-14 18:37:53 +00:00
|
|
|
unique_vars.pop();
|
2017-04-23 12:05:22 +00:00
|
|
|
var s = [];
|
|
|
|
|
switch (rng(5)) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case 0:
|
2017-04-23 12:05:22 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"(function " + name + "(){",
|
2017-04-23 12:05:22 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
rng(2) == 0 ? "})" : "})()"
|
2017-04-23 12:05:22 +00:00
|
|
|
);
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-04-23 12:05:22 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"+function " + name + "(){",
|
2017-04-23 12:05:22 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
"}()"
|
2017-04-23 12:05:22 +00:00
|
|
|
);
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2017-04-23 12:05:22 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"!function " + name + "(){",
|
2017-04-23 12:05:22 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
"}()"
|
2017-04-23 12:05:22 +00:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
"void function " + name + "(){",
|
2017-04-23 12:05:22 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
"}()"
|
2017-04-23 12:05:22 +00:00
|
|
|
);
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2019-10-27 06:17:35 +00:00
|
|
|
var instantiate = rng(4) ? "new " : "";
|
2017-04-23 19:15:03 +00:00
|
|
|
s.push(
|
2019-10-27 06:17:35 +00:00
|
|
|
instantiate + "function " + name + "(){",
|
2017-04-23 19:15:03 +00:00
|
|
|
strictMode()
|
|
|
|
|
);
|
|
|
|
|
if (instantiate) for (var i = rng(4); --i >= 0;) {
|
2019-10-27 06:17:35 +00:00
|
|
|
if (rng(2)) s.push("this." + getDotKey(true) + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ";");
|
|
|
|
|
else s.push("this[" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]" + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ";");
|
2017-04-23 12:05:22 +00:00
|
|
|
}
|
|
|
|
|
s.push(
|
|
|
|
|
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
rng(2) == 0 ? "}" : "}()"
|
2017-04-23 12:05:22 +00:00
|
|
|
);
|
2017-03-31 21:47:11 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
VAR_NAMES.length = nameLenBefore;
|
2019-10-27 06:17:35 +00:00
|
|
|
return filterDirective(s).join("\n");
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2017-04-01 21:11:29 +00:00
|
|
|
return createTypeofExpr(recurmax, stmtDepth, canThrow);
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2017-03-31 21:47:11 +00:00
|
|
|
// more like a parser test but perhaps comment nodes mess up the analysis?
|
|
|
|
|
// note: parens not needed for post-fix (since that's the default when ambiguous)
|
|
|
|
|
// for prefix ops we need parens to prevent accidental syntax errors.
|
|
|
|
|
switch (rng(6)) {
|
|
|
|
|
case 0:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "a/* ignore */++";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 1:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "b/* ignore */--";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 2:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "++/* ignore */a";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 3:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "--/* ignore */b";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 4:
|
|
|
|
|
// only groups that wrap a single variable return a "Reference", so this is still valid.
|
|
|
|
|
// may just be a parser edge case that is invisible to uglify...
|
2019-10-27 06:17:35 +00:00
|
|
|
return "--(b)";
|
2017-03-31 21:47:11 +00:00
|
|
|
case 5:
|
|
|
|
|
// classic 0.3-0.1 case; 1-0.1-0.1-0.1 is not 0.7 :)
|
2019-10-27 06:17:35 +00:00
|
|
|
return "b + 1 - 0.1 - 0.1 - 0.1";
|
2017-03-31 21:47:11 +00:00
|
|
|
default:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "--/* ignore */b";
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
|
|
|
|
return createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow);
|
|
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createUnarySafePrefix() + "(" + createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-04-01 18:08:46 +00:00
|
|
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || a || 3).toString() ";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-04-01 18:08:46 +00:00
|
|
|
return " /[abc4]/.test(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
2020-02-18 19:35:37 +00:00
|
|
|
case p++:
|
|
|
|
|
return " /[abc4]/g.exec(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-04-02 20:00:33 +00:00
|
|
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) +
|
|
|
|
|
") || " + rng(10) + ").toString()[" +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "] ";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-05-13 18:10:34 +00:00
|
|
|
return createArrayLiteral(recurmax, stmtDepth, canThrow);
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2017-05-13 18:10:34 +00:00
|
|
|
return createObjectLiteral(recurmax, stmtDepth, canThrow);
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createArrayLiteral(recurmax, stmtDepth, canThrow) + "[" +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createObjectLiteral(recurmax, stmtDepth, canThrow) + "[" +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]";
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createArrayLiteral(recurmax, stmtDepth, canThrow) + "." + getDotKey();
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
return createObjectLiteral(recurmax, stmtDepth, canThrow) + "." + getDotKey();
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
var name = getVarName();
|
2020-04-17 23:12:13 +00:00
|
|
|
var s = name + "[" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]";
|
|
|
|
|
return canThrow && rng(8) == 0 ? s : name + " && " + s;
|
2017-04-07 10:47:30 +00:00
|
|
|
case p++:
|
|
|
|
|
var name = getVarName();
|
2020-04-17 23:12:13 +00:00
|
|
|
var s = name + "." + getDotKey();
|
|
|
|
|
return canThrow && rng(8) == 0 ? s : name + " && " + s;
|
|
|
|
|
case p++:
|
|
|
|
|
case p++:
|
|
|
|
|
var name = getVarName();
|
|
|
|
|
var s = name + "." + getDotKey();
|
|
|
|
|
s = "typeof " + s + ' == "function" && --_calls_ >= 0 && ' + s + "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
|
|
|
|
return canThrow && rng(8) == 0 ? s : name + " && " + s;
|
2017-12-20 15:52:18 +00:00
|
|
|
case p++:
|
|
|
|
|
case p++:
|
|
|
|
|
case p++:
|
|
|
|
|
case p++:
|
2019-10-27 06:17:35 +00:00
|
|
|
var name = rng(3) == 0 ? getVarName() : "f" + rng(funcs + 2);
|
2017-12-20 15:52:18 +00:00
|
|
|
called[name] = true;
|
2019-10-27 06:17:35 +00:00
|
|
|
return "typeof " + name + ' == "function" && --_calls_ >= 0 && ' + name + "(" + createArgs(recurmax, stmtDepth, canThrow) + ")";
|
2017-04-02 20:00:33 +00:00
|
|
|
}
|
2017-04-07 10:47:30 +00:00
|
|
|
_createExpression.N = p;
|
|
|
|
|
return _createExpression(recurmax, noComma, stmtDepth, canThrow);
|
2017-04-02 20:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-13 18:10:34 +00:00
|
|
|
function createArrayLiteral(recurmax, stmtDepth, canThrow) {
|
2017-04-02 20:00:33 +00:00
|
|
|
recurmax--;
|
|
|
|
|
var arr = "[";
|
|
|
|
|
for (var i = rng(6); --i >= 0;) {
|
|
|
|
|
// in rare cases produce an array hole element
|
|
|
|
|
var element = rng(20) ? createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) : "";
|
|
|
|
|
arr += element + ", ";
|
|
|
|
|
}
|
|
|
|
|
return arr + "]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var SAFE_KEYS = [
|
|
|
|
|
"length",
|
|
|
|
|
"foo",
|
|
|
|
|
"a",
|
|
|
|
|
"b",
|
|
|
|
|
"c",
|
|
|
|
|
"undefined",
|
|
|
|
|
"null",
|
|
|
|
|
"NaN",
|
|
|
|
|
"Infinity",
|
|
|
|
|
"in",
|
|
|
|
|
"var",
|
|
|
|
|
];
|
|
|
|
|
var KEYS = [
|
|
|
|
|
"''",
|
|
|
|
|
'"\t"',
|
|
|
|
|
'"-2"',
|
|
|
|
|
"0",
|
|
|
|
|
"1.5",
|
|
|
|
|
"3",
|
|
|
|
|
].concat(SAFE_KEYS);
|
|
|
|
|
|
2017-05-13 18:10:34 +00:00
|
|
|
function getDotKey(assign) {
|
|
|
|
|
var key;
|
|
|
|
|
do {
|
|
|
|
|
key = SAFE_KEYS[rng(SAFE_KEYS.length)];
|
|
|
|
|
} while (assign && key == "length");
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createAccessor(recurmax, stmtDepth, canThrow) {
|
|
|
|
|
var namesLenBefore = VAR_NAMES.length;
|
|
|
|
|
var s;
|
|
|
|
|
var prop1 = getDotKey();
|
|
|
|
|
if (rng(2) == 0) {
|
|
|
|
|
s = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"get " + prop1 + "(){",
|
2017-05-13 18:10:34 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
|
|
|
|
createStatement(recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth, STMT_RETURN_ETC),
|
2019-10-27 06:17:35 +00:00
|
|
|
"},"
|
2017-05-14 18:37:53 +00:00
|
|
|
];
|
2017-05-13 18:10:34 +00:00
|
|
|
} else {
|
|
|
|
|
var prop2;
|
|
|
|
|
do {
|
|
|
|
|
prop2 = getDotKey();
|
|
|
|
|
} while (prop1 == prop2);
|
|
|
|
|
s = [
|
2019-10-27 06:17:35 +00:00
|
|
|
"set " + prop1 + "(" + createVarName(MANDATORY) + "){",
|
2017-05-13 18:10:34 +00:00
|
|
|
strictMode(),
|
|
|
|
|
createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
|
2019-10-27 06:17:35 +00:00
|
|
|
"this." + prop2 + createAssignment() + _createBinaryExpr(recurmax, COMMA_OK, stmtDepth, canThrow) + ";",
|
|
|
|
|
"},"
|
2017-05-14 18:37:53 +00:00
|
|
|
];
|
2017-05-13 18:10:34 +00:00
|
|
|
}
|
|
|
|
|
VAR_NAMES.length = namesLenBefore;
|
2019-10-27 06:17:35 +00:00
|
|
|
return filterDirective(s).join("\n");
|
2017-04-07 10:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-13 18:10:34 +00:00
|
|
|
function createObjectLiteral(recurmax, stmtDepth, canThrow) {
|
2017-04-02 20:00:33 +00:00
|
|
|
recurmax--;
|
2019-10-27 06:17:35 +00:00
|
|
|
var obj = ["({"];
|
2017-04-02 20:00:33 +00:00
|
|
|
for (var i = rng(6); --i >= 0;) {
|
2017-05-13 18:10:34 +00:00
|
|
|
if (rng(20) == 0) {
|
|
|
|
|
obj.push(createAccessor(recurmax, stmtDepth, canThrow));
|
|
|
|
|
} else {
|
|
|
|
|
var key = KEYS[rng(KEYS.length)];
|
2019-10-27 06:17:35 +00:00
|
|
|
obj.push(key + ":(" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "),");
|
2017-05-13 18:10:34 +00:00
|
|
|
}
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
obj.push("})");
|
|
|
|
|
return obj.join("\n");
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-07 10:47:30 +00:00
|
|
|
function createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) {
|
2017-03-31 09:23:50 +00:00
|
|
|
recurmax = 3; // note that this generates 2^recurmax expression parts... make sure to cap it
|
2017-04-07 10:47:30 +00:00
|
|
|
return _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow);
|
|
|
|
|
}
|
|
|
|
|
function _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) {
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(" + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow)
|
|
|
|
|
+ createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2017-04-07 10:47:30 +00:00
|
|
|
function _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) {
|
2017-03-31 09:23:50 +00:00
|
|
|
// intentionally generate more hardcore ops
|
|
|
|
|
if (--recurmax < 0) return createValue();
|
2017-04-23 12:05:22 +00:00
|
|
|
var assignee, expr;
|
2017-04-07 10:47:30 +00:00
|
|
|
switch (rng(30)) {
|
|
|
|
|
case 0:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(c = c + 1, " + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
case 1:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(" + createUnarySafePrefix() + "(" + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + "))";
|
2017-04-07 10:47:30 +00:00
|
|
|
case 2:
|
2017-04-23 12:05:22 +00:00
|
|
|
assignee = getVarName();
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(" + assignee + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
case 3:
|
2017-04-23 12:05:22 +00:00
|
|
|
assignee = getVarName();
|
2019-10-27 06:17:35 +00:00
|
|
|
expr = "(" + assignee + "[" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow)
|
|
|
|
|
+ "]" + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
|
|
|
|
return canThrow && rng(10) == 0 ? expr : "(" + assignee + " && " + expr + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
case 4:
|
2017-04-23 12:05:22 +00:00
|
|
|
assignee = getVarName();
|
2019-10-27 06:17:35 +00:00
|
|
|
expr = "(" + assignee + "." + getDotKey(true) + createAssignment()
|
|
|
|
|
+ _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ")";
|
|
|
|
|
return canThrow && rng(10) == 0 ? expr : "(" + assignee + " && " + expr + ")";
|
2017-04-07 10:47:30 +00:00
|
|
|
default:
|
|
|
|
|
return _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow);
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-01 21:11:29 +00:00
|
|
|
function createTypeofExpr(recurmax, stmtDepth, canThrow) {
|
2017-04-01 18:08:46 +00:00
|
|
|
switch (rng(8)) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case 0:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createVarName(MANDATORY, DONT_STORE) + ' === "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
2017-03-31 21:47:11 +00:00
|
|
|
case 1:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createVarName(MANDATORY, DONT_STORE) + ' !== "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
2017-03-31 21:47:11 +00:00
|
|
|
case 2:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createVarName(MANDATORY, DONT_STORE) + ' == "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
2017-03-31 21:47:11 +00:00
|
|
|
case 3:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createVarName(MANDATORY, DONT_STORE) + ' != "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
2017-03-31 21:47:11 +00:00
|
|
|
case 4:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createVarName(MANDATORY, DONT_STORE) + ")";
|
2017-04-01 21:11:29 +00:00
|
|
|
default:
|
2019-10-27 06:17:35 +00:00
|
|
|
return "(typeof " + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ")";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
function createValue() {
|
2017-03-31 09:23:50 +00:00
|
|
|
return VALUES[rng(VALUES.length)];
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createBinaryOp(noComma) {
|
2017-03-31 09:23:50 +00:00
|
|
|
if (noComma) return BINARY_OPS_NO_COMMA[rng(BINARY_OPS_NO_COMMA.length)];
|
|
|
|
|
return BINARY_OPS[rng(BINARY_OPS.length)];
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-24 17:46:12 +00:00
|
|
|
function createAssignment() {
|
2017-03-31 09:23:50 +00:00
|
|
|
return ASSIGNMENTS[rng(ASSIGNMENTS.length)];
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-07 10:47:30 +00:00
|
|
|
function createUnarySafePrefix() {
|
|
|
|
|
return UNARY_SAFE[rng(UNARY_SAFE.length)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createUnaryPrefix() {
|
|
|
|
|
return UNARY_PREFIX[rng(UNARY_PREFIX.length)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createUnaryPostfix() {
|
|
|
|
|
return UNARY_POSTFIX[rng(UNARY_POSTFIX.length)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getVarName() {
|
|
|
|
|
// try to get a generated name reachable from current scope. default to just `a`
|
2019-10-27 06:17:35 +00:00
|
|
|
return VAR_NAMES[INITIAL_NAMES_LEN + rng(VAR_NAMES.length - INITIAL_NAMES_LEN)] || "a";
|
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:47:11 +00:00
|
|
|
function createVarName(maybe, dontStore) {
|
2017-04-07 10:47:30 +00:00
|
|
|
if (!maybe || rng(2)) {
|
|
|
|
|
var suffix = rng(3);
|
2017-05-14 18:37:53 +00:00
|
|
|
var name;
|
|
|
|
|
do {
|
|
|
|
|
name = VAR_NAMES[rng(VAR_NAMES.length)];
|
2019-10-27 06:17:35 +00:00
|
|
|
if (suffix) name += "_" + suffix;
|
2017-05-14 18:37:53 +00:00
|
|
|
} while (unique_vars.indexOf(name) >= 0);
|
|
|
|
|
if (suffix && !dontStore) VAR_NAMES.push(name);
|
2017-03-31 09:23:50 +00:00
|
|
|
return name;
|
|
|
|
|
}
|
2019-10-27 06:17:35 +00:00
|
|
|
return "";
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-14 18:37:53 +00:00
|
|
|
if (require.main !== module) {
|
|
|
|
|
exports.createTopLevelCode = createTopLevelCode;
|
|
|
|
|
exports.num_iterations = num_iterations;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 22:29:02 +00:00
|
|
|
function writeln(stream, msg) {
|
|
|
|
|
if (typeof msg != "undefined") {
|
|
|
|
|
stream.write(typeof msg == "string" ? msg : msg.stack || "" + msg);
|
|
|
|
|
}
|
|
|
|
|
stream.write("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 07:56:28 +00:00
|
|
|
function println(msg) {
|
2019-10-16 22:29:02 +00:00
|
|
|
writeln(process.stdout, msg);
|
2017-06-09 07:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function errorln(msg) {
|
2019-10-16 22:29:02 +00:00
|
|
|
writeln(process.stderr, msg);
|
2017-06-09 07:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 15:26:57 +00:00
|
|
|
function try_beautify(code, toplevel, result, printfn) {
|
2017-05-09 07:58:46 +00:00
|
|
|
var beautified = UglifyJS.minify(code, {
|
|
|
|
|
compress: false,
|
|
|
|
|
mangle: false,
|
|
|
|
|
output: {
|
|
|
|
|
beautify: true,
|
2018-03-15 07:46:45 +00:00
|
|
|
braces: true,
|
2017-05-09 07:58:46 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (beautified.error) {
|
2017-06-09 07:56:28 +00:00
|
|
|
printfn("// !!! beautify failed !!!");
|
2019-10-07 06:36:00 +00:00
|
|
|
printfn(beautified.error);
|
2019-05-15 15:26:57 +00:00
|
|
|
} else if (sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) {
|
2017-06-09 07:56:28 +00:00
|
|
|
printfn("// (beautified)");
|
|
|
|
|
printfn(beautified.code);
|
2017-05-09 07:58:46 +00:00
|
|
|
return;
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
2017-06-09 07:56:28 +00:00
|
|
|
printfn("//");
|
|
|
|
|
printfn(code);
|
2017-03-31 21:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-28 10:21:44 +00:00
|
|
|
var default_options = UglifyJS.default_options();
|
2017-04-01 18:10:50 +00:00
|
|
|
|
|
|
|
|
function log_suspects(minify_options, component) {
|
|
|
|
|
var options = component in minify_options ? minify_options[component] : true;
|
|
|
|
|
if (!options) return;
|
2017-05-28 10:21:44 +00:00
|
|
|
if (typeof options != "object") options = {};
|
|
|
|
|
var defs = default_options[component];
|
2020-05-17 13:35:17 +00:00
|
|
|
var toplevel = sandbox.has_toplevel(minify_options);
|
2017-05-28 10:21:44 +00:00
|
|
|
var suspects = Object.keys(defs).filter(function(name) {
|
2018-01-18 06:08:05 +00:00
|
|
|
var flip = name == "keep_fargs";
|
2020-05-08 07:03:48 +00:00
|
|
|
if (flip !== (name in options ? options : defs)[name]) {
|
2017-04-01 18:10:50 +00:00
|
|
|
var m = JSON.parse(JSON.stringify(minify_options));
|
|
|
|
|
var o = JSON.parse(JSON.stringify(options));
|
2018-01-18 06:08:05 +00:00
|
|
|
o[name] = flip;
|
2017-04-01 18:10:50 +00:00
|
|
|
m[component] = o;
|
2017-05-09 07:58:46 +00:00
|
|
|
var result = UglifyJS.minify(original_code, m);
|
|
|
|
|
if (result.error) {
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("Error testing options." + component + "." + name);
|
2019-10-07 06:36:00 +00:00
|
|
|
errorln(result.error);
|
2017-05-09 07:58:46 +00:00
|
|
|
} else {
|
2020-05-17 13:35:17 +00:00
|
|
|
var r = sandbox.run_code(result.code, toplevel);
|
2020-04-26 16:59:26 +00:00
|
|
|
return !sandbox.same_stdout(uglify_result, r);
|
2017-04-01 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (suspects.length > 0) {
|
2017-06-09 16:11:40 +00:00
|
|
|
errorln("Suspicious " + component + " options:");
|
2017-04-01 18:10:50 +00:00
|
|
|
suspects.forEach(function(name) {
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln(" " + name);
|
2017-04-01 18:10:50 +00:00
|
|
|
});
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln();
|
2017-04-01 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 13:35:17 +00:00
|
|
|
function log_suspects_global(options, toplevel) {
|
2020-04-18 10:03:06 +00:00
|
|
|
var suspects = Object.keys(default_options).filter(function(component) {
|
|
|
|
|
return typeof default_options[component] != "object";
|
2020-03-12 20:03:47 +00:00
|
|
|
}).filter(function(component) {
|
|
|
|
|
var m = JSON.parse(options);
|
|
|
|
|
m[component] = false;
|
|
|
|
|
var result = UglifyJS.minify(original_code, m);
|
|
|
|
|
if (result.error) {
|
|
|
|
|
errorln("Error testing options." + component);
|
|
|
|
|
errorln(result.error);
|
|
|
|
|
} else {
|
2020-05-17 13:35:17 +00:00
|
|
|
var r = sandbox.run_code(result.code, toplevel);
|
2020-04-26 16:59:26 +00:00
|
|
|
return !sandbox.same_stdout(uglify_result, r);
|
2018-01-18 06:08:05 +00:00
|
|
|
}
|
2020-03-12 20:03:47 +00:00
|
|
|
});
|
|
|
|
|
if (suspects.length > 0) {
|
|
|
|
|
errorln("Suspicious options:");
|
|
|
|
|
suspects.forEach(function(name) {
|
|
|
|
|
errorln(" " + name);
|
|
|
|
|
});
|
|
|
|
|
errorln();
|
2018-01-18 06:08:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
function log(options) {
|
2020-02-29 17:33:48 +00:00
|
|
|
var toplevel = sandbox.has_toplevel(JSON.parse(options));
|
2019-10-27 06:17:35 +00:00
|
|
|
if (!ok) errorln("\n\n\n\n\n\n!!!!!!!!!!\n\n\n");
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("//=============================================================");
|
2017-06-09 16:11:40 +00:00
|
|
|
if (!ok) errorln("// !!!!!! Failed... round " + round);
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("// original code");
|
2020-02-29 17:33:48 +00:00
|
|
|
try_beautify(original_code, toplevel, original_result, errorln);
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln();
|
|
|
|
|
errorln();
|
|
|
|
|
errorln("//-------------------------------------------------------------");
|
2017-03-31 21:47:11 +00:00
|
|
|
if (typeof uglify_code == "string") {
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("// uglified code");
|
2020-02-29 17:33:48 +00:00
|
|
|
try_beautify(uglify_code, toplevel, uglify_result, errorln);
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln();
|
|
|
|
|
errorln();
|
|
|
|
|
errorln("original result:");
|
2019-10-07 06:36:00 +00:00
|
|
|
errorln(original_result);
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("uglified result:");
|
2019-10-07 06:36:00 +00:00
|
|
|
errorln(uglify_result);
|
2020-02-06 02:50:59 +00:00
|
|
|
errorln("//-------------------------------------------------------------");
|
2020-02-29 17:33:48 +00:00
|
|
|
var reduced = reduce_test(original_code, JSON.parse(options), {
|
2020-02-06 02:50:59 +00:00
|
|
|
verbose: false,
|
|
|
|
|
}).code;
|
|
|
|
|
if (reduced) {
|
|
|
|
|
errorln();
|
|
|
|
|
errorln("// reduced test case (output will differ)");
|
|
|
|
|
errorln();
|
|
|
|
|
errorln(reduced);
|
|
|
|
|
errorln();
|
|
|
|
|
errorln("//-------------------------------------------------------------");
|
|
|
|
|
}
|
2017-03-31 21:47:11 +00:00
|
|
|
} else {
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("// !!! uglify failed !!!");
|
2019-10-07 06:36:00 +00:00
|
|
|
errorln(uglify_code);
|
2019-05-15 15:26:57 +00:00
|
|
|
if (errored) {
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln();
|
|
|
|
|
errorln();
|
|
|
|
|
errorln("original stacktrace:");
|
2019-10-07 06:36:00 +00:00
|
|
|
errorln(original_result);
|
2017-04-23 12:05:22 +00:00
|
|
|
}
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln("minify(options):");
|
2020-02-29 17:33:48 +00:00
|
|
|
errorln(JSON.stringify(JSON.parse(options), null, 2));
|
2017-06-09 07:56:28 +00:00
|
|
|
errorln();
|
2017-04-22 14:15:04 +00:00
|
|
|
if (!ok && typeof uglify_code == "string") {
|
2020-04-18 10:03:06 +00:00
|
|
|
Object.keys(default_options).filter(function(component) {
|
|
|
|
|
var defs = default_options[component];
|
|
|
|
|
return defs && typeof defs == "object";
|
|
|
|
|
}).forEach(log_suspects.bind(null, JSON.parse(options)));
|
2020-05-17 13:35:17 +00:00
|
|
|
log_suspects_global(options, toplevel);
|
2017-06-09 16:11:40 +00:00
|
|
|
errorln("!!!!!! Failed... round " + round);
|
2017-04-01 18:10:50 +00:00
|
|
|
}
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-16 15:32:47 +00:00
|
|
|
function fuzzy_match(original, uglified) {
|
2020-01-06 03:26:15 +00:00
|
|
|
uglified = uglified.split(" ");
|
|
|
|
|
var i = uglified.length;
|
|
|
|
|
original = original.split(" ", i);
|
|
|
|
|
while (--i >= 0) {
|
2019-12-16 15:32:47 +00:00
|
|
|
if (original[i] === uglified[i]) continue;
|
|
|
|
|
var a = +original[i];
|
|
|
|
|
var b = +uglified[i];
|
|
|
|
|
if (Math.abs((b - a) / a) < 1e-10) continue;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:07:49 +00:00
|
|
|
function skip_infinite_recursion(orig, toplevel) {
|
|
|
|
|
var code = orig;
|
|
|
|
|
var tries = [];
|
|
|
|
|
var offset = 0;
|
|
|
|
|
var re = /(?:(?:^|[\s{};])try|}\s*catch\s*\(([^)]+)\)|}\s*finally)\s*(?={)/g;
|
|
|
|
|
var match;
|
|
|
|
|
while (match = re.exec(code)) {
|
|
|
|
|
if (/}\s*finally\s*$/.test(match[0])) {
|
|
|
|
|
tries.shift();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (tries.length && tries[0].catch) tries.shift();
|
|
|
|
|
var index = match.index + match[0].length + 1;
|
|
|
|
|
if (/(?:^|[\s{};])try\s*$/.test(match[0])) {
|
|
|
|
|
tries.unshift({ try: index - offset });
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
tries[0].catch = index;
|
|
|
|
|
var insert = "throw " + match[1] + ".ufuzz_skip || (" + match[1] + ".ufuzz_skip = " + tries[0].try + "), " + match[1] + ";";
|
|
|
|
|
var new_code = code.slice(0, index) + insert + code.slice(index);
|
|
|
|
|
var result = sandbox.run_code(new_code, toplevel);
|
|
|
|
|
if (typeof result != "object" || typeof result.name != "string" || typeof result.message != "string") {
|
|
|
|
|
offset += insert.length;
|
|
|
|
|
code = new_code;
|
|
|
|
|
} else if (result.name == "RangeError" && result.message == "Maximum call stack size exceeded") {
|
|
|
|
|
index = result.ufuzz_skip;
|
|
|
|
|
return orig.slice(0, index) + 'throw new Error("skipping infinite recursion");' + orig.slice(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 12:05:22 +00:00
|
|
|
var fallback_options = [ JSON.stringify({
|
|
|
|
|
compress: false,
|
|
|
|
|
mangle: false
|
|
|
|
|
}) ];
|
2019-10-20 20:11:14 +00:00
|
|
|
var minify_options = require("./options.json").map(JSON.stringify);
|
2020-05-07 19:21:44 +00:00
|
|
|
var sort_globals = [
|
|
|
|
|
"Object.keys(this).sort().forEach(function(name) {",
|
|
|
|
|
" var value = this[name];",
|
|
|
|
|
" delete this[name];",
|
|
|
|
|
" this[name] = value;",
|
|
|
|
|
"});",
|
|
|
|
|
"",
|
|
|
|
|
].join("\n");
|
2019-05-15 15:26:57 +00:00
|
|
|
var original_code, original_result, errored;
|
2017-04-01 18:10:50 +00:00
|
|
|
var uglify_code, uglify_result, ok;
|
2017-04-01 19:17:01 +00:00
|
|
|
for (var round = 1; round <= num_iterations; round++) {
|
2017-03-24 17:46:12 +00:00
|
|
|
process.stdout.write(round + " of " + num_iterations + "\r");
|
2017-03-31 09:23:50 +00:00
|
|
|
|
2017-04-23 12:05:22 +00:00
|
|
|
original_code = createTopLevelCode();
|
2019-05-15 15:26:57 +00:00
|
|
|
var orig_result = [ sandbox.run_code(original_code) ];
|
|
|
|
|
errored = typeof orig_result[0] != "string";
|
2019-10-28 10:08:51 +00:00
|
|
|
if (!errored) orig_result.push(sandbox.run_code(original_code, true));
|
2019-05-15 15:26:57 +00:00
|
|
|
(errored ? fallback_options : minify_options).forEach(function(options) {
|
|
|
|
|
var o = JSON.parse(options);
|
2020-02-29 17:33:48 +00:00
|
|
|
var toplevel = sandbox.has_toplevel(o);
|
2020-05-09 21:25:44 +00:00
|
|
|
o.validate = true;
|
2019-05-15 15:26:57 +00:00
|
|
|
uglify_code = UglifyJS.minify(original_code, o);
|
2020-02-29 17:33:48 +00:00
|
|
|
original_result = orig_result[toplevel ? 1 : 0];
|
2017-05-09 07:58:46 +00:00
|
|
|
if (!uglify_code.error) {
|
|
|
|
|
uglify_code = uglify_code.code;
|
2020-02-29 17:33:48 +00:00
|
|
|
uglify_result = sandbox.run_code(uglify_code, toplevel);
|
2017-04-01 18:10:50 +00:00
|
|
|
ok = sandbox.same_stdout(original_result, uglify_result);
|
2020-05-07 19:21:44 +00:00
|
|
|
// ignore declaration order of global variables
|
|
|
|
|
if (!ok && !toplevel) {
|
|
|
|
|
ok = sandbox.same_stdout(sandbox.run_code(sort_globals + original_code), sandbox.run_code(sort_globals + uglify_code));
|
|
|
|
|
}
|
|
|
|
|
// ignore numerical imprecision caused by `unsafe_math`
|
2020-04-17 18:53:26 +00:00
|
|
|
if (!ok && typeof uglify_result == "string" && o.compress && o.compress.unsafe_math) {
|
2019-12-16 15:32:47 +00:00
|
|
|
ok = fuzzy_match(original_result, uglify_result);
|
|
|
|
|
if (!ok) {
|
2020-02-29 17:33:48 +00:00
|
|
|
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"), toplevel);
|
2020-01-06 03:26:15 +00:00
|
|
|
ok = sandbox.same_stdout(fuzzy_result, uglify_result);
|
2019-12-16 15:32:47 +00:00
|
|
|
}
|
2019-10-28 10:08:51 +00:00
|
|
|
}
|
2020-05-12 23:07:49 +00:00
|
|
|
// ignore difference in depth of termination caused by infinite recursion
|
|
|
|
|
if (!ok) {
|
|
|
|
|
var orig_skipped = skip_infinite_recursion(original_code, toplevel);
|
|
|
|
|
var uglify_skipped = skip_infinite_recursion(uglify_code, toplevel);
|
|
|
|
|
if (orig_skipped && uglify_skipped) {
|
|
|
|
|
ok = sandbox.same_stdout(sandbox.run_code(orig_skipped, toplevel), sandbox.run_code(uglify_skipped, toplevel));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-09 07:58:46 +00:00
|
|
|
} else {
|
2020-05-10 23:32:21 +00:00
|
|
|
uglify_code = uglify_code.error;
|
|
|
|
|
ok = errored && uglify_code.name == original_result.name;
|
2017-04-01 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options);
|
2019-05-15 15:26:57 +00:00
|
|
|
else if (errored) {
|
2017-06-09 07:56:28 +00:00
|
|
|
println("//=============================================================");
|
|
|
|
|
println("// original code");
|
2020-02-29 17:33:48 +00:00
|
|
|
try_beautify(original_code, toplevel, original_result, println);
|
2017-06-09 07:56:28 +00:00
|
|
|
println();
|
|
|
|
|
println();
|
|
|
|
|
println("original result:");
|
2019-10-07 06:36:00 +00:00
|
|
|
println(original_result);
|
2017-06-09 07:56:28 +00:00
|
|
|
println();
|
2017-04-08 17:36:38 +00:00
|
|
|
}
|
|
|
|
|
if (!ok && isFinite(num_iterations)) {
|
2017-06-09 07:56:28 +00:00
|
|
|
println();
|
2017-04-08 17:36:38 +00:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
2017-04-01 18:10:50 +00:00
|
|
|
});
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
2017-06-09 07:56:28 +00:00
|
|
|
println();
|