2017-03-24 17:46:12 +00:00
|
|
|
// ufuzz.js
|
|
|
|
|
// derived from https://github.com/qfox/uglyfuzzer by Peter van der Zee
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2017-03-31 09:23:50 +00:00
|
|
|
// check both cli and file modes of nodejs (!). See #1695 for details. and the various settings of uglify.
|
|
|
|
|
// 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
|
|
|
|
|
|
2017-03-24 17:46:12 +00:00
|
|
|
// workaround for tty output truncation upon process.exit()
|
|
|
|
|
[process.stdout, process.stderr].forEach(function(stream){
|
|
|
|
|
if (stream._handle && stream._handle.setBlocking)
|
|
|
|
|
stream._handle.setBlocking(true);
|
|
|
|
|
});
|
|
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
var UglifyJS = require("..");
|
2017-04-01 09:09:52 +00:00
|
|
|
var randomBytes = require("crypto").randomBytes;
|
2017-03-31 21:47:11 +00:00
|
|
|
var sandbox = require("./sandbox");
|
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-03-31 09:23:50 +00:00
|
|
|
var STMT_BLOCK = 0;
|
|
|
|
|
var STMT_IF_ELSE = 1;
|
|
|
|
|
var STMT_DO_WHILE = 2;
|
|
|
|
|
var STMT_WHILE = 3;
|
|
|
|
|
var STMT_FOR_LOOP = 4;
|
|
|
|
|
var STMT_SEMI = 5;
|
|
|
|
|
var STMT_EXPR = 6;
|
|
|
|
|
var STMT_SWITCH = 7;
|
|
|
|
|
var STMT_VAR = 8;
|
|
|
|
|
var STMT_RETURN_ETC = 9;
|
|
|
|
|
var STMT_FUNC_EXPR = 10;
|
|
|
|
|
var STMT_TRY = 11;
|
|
|
|
|
var STMT_C = 12;
|
|
|
|
|
var STMTS_TO_USE = [
|
|
|
|
|
STMT_BLOCK,
|
|
|
|
|
STMT_IF_ELSE,
|
|
|
|
|
STMT_DO_WHILE,
|
|
|
|
|
STMT_WHILE,
|
|
|
|
|
STMT_FOR_LOOP,
|
|
|
|
|
STMT_SEMI,
|
|
|
|
|
STMT_EXPR,
|
|
|
|
|
STMT_SWITCH,
|
|
|
|
|
STMT_VAR,
|
|
|
|
|
STMT_RETURN_ETC,
|
|
|
|
|
STMT_FUNC_EXPR,
|
|
|
|
|
STMT_TRY,
|
|
|
|
|
STMT_C,
|
|
|
|
|
];
|
|
|
|
|
var STMT_ARG_TO_ID = {
|
|
|
|
|
block: STMT_BLOCK,
|
|
|
|
|
ifelse: STMT_IF_ELSE,
|
|
|
|
|
dowhile: STMT_DO_WHILE,
|
|
|
|
|
while: STMT_WHILE,
|
|
|
|
|
forloop: STMT_FOR_LOOP,
|
|
|
|
|
semi: STMT_SEMI,
|
|
|
|
|
expr: STMT_EXPR,
|
|
|
|
|
switch: STMT_SWITCH,
|
|
|
|
|
var: STMT_VAR,
|
|
|
|
|
stop: STMT_RETURN_ETC,
|
|
|
|
|
funcexpr: STMT_FUNC_EXPR,
|
|
|
|
|
try: STMT_TRY,
|
|
|
|
|
c: STMT_C,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
for (var i = 2; i < process.argv.length; ++i) {
|
|
|
|
|
switch (process.argv[i]) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case '-v':
|
|
|
|
|
verbose = true;
|
|
|
|
|
break;
|
|
|
|
|
case '-V':
|
|
|
|
|
verbose_interval = true;
|
|
|
|
|
break;
|
|
|
|
|
case '-t':
|
|
|
|
|
MAX_GENERATED_TOPLEVELS_PER_RUN = +process.argv[++i];
|
|
|
|
|
if (!MAX_GENERATED_TOPLEVELS_PER_RUN) throw new Error('Must generate at least one toplevel per run');
|
|
|
|
|
break;
|
|
|
|
|
case '-r':
|
|
|
|
|
MAX_GENERATION_RECURSION_DEPTH = +process.argv[++i];
|
|
|
|
|
if (!MAX_GENERATION_RECURSION_DEPTH) throw new Error('Recursion depth must be at least 1');
|
|
|
|
|
break;
|
|
|
|
|
case '-s1':
|
|
|
|
|
var name = process.argv[++i];
|
|
|
|
|
STMT_FIRST_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name];
|
|
|
|
|
if (!(STMT_FIRST_LEVEL_OVERRIDE >= 0)) throw new Error('Unknown statement name; use -? to get a list');
|
|
|
|
|
break;
|
|
|
|
|
case '-s2':
|
|
|
|
|
var name = process.argv[++i];
|
|
|
|
|
STMT_SECOND_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name];
|
|
|
|
|
if (!(STMT_SECOND_LEVEL_OVERRIDE >= 0)) throw new Error('Unknown statement name; use -? to get a list');
|
|
|
|
|
break;
|
|
|
|
|
case '--stmt-depth-from-func':
|
|
|
|
|
STMT_COUNT_FROM_GLOBAL = false;
|
|
|
|
|
break;
|
|
|
|
|
case '--only-stmt':
|
|
|
|
|
STMTS_TO_USE = process.argv[++i].split(',').map(function(name){ return STMT_ARG_TO_ID[name]; });
|
|
|
|
|
break;
|
|
|
|
|
case '--without-stmt':
|
|
|
|
|
// meh. it runs once it's fine.
|
|
|
|
|
process.argv[++i].split(',').forEach(function(name){
|
|
|
|
|
var omit = STMT_ARG_TO_ID[name];
|
|
|
|
|
STMTS_TO_USE = STMTS_TO_USE.filter(function(id){ return id !== omit; })
|
|
|
|
|
});
|
|
|
|
|
break;
|
2017-04-01 19:17:01 +00:00
|
|
|
case '--help':
|
|
|
|
|
case '-h':
|
2017-03-31 21:47:11 +00:00
|
|
|
case '-?':
|
|
|
|
|
console.log('** UglifyJS fuzzer help **');
|
|
|
|
|
console.log('Valid options (optional):');
|
|
|
|
|
console.log('<number>: generate this many cases (if used must be first arg)');
|
|
|
|
|
console.log('-v: print every generated test case');
|
|
|
|
|
console.log('-V: print every 100th generated test case');
|
|
|
|
|
console.log('-t <int>: generate this many toplevels per run (more take longer)');
|
|
|
|
|
console.log('-r <int>: maximum recursion depth for generator (higher takes longer)');
|
|
|
|
|
console.log('-s1 <statement name>: force the first level statement to be this one (see list below)');
|
|
|
|
|
console.log('-s2 <statement name>: force the second level statement to be this one (see list below)');
|
|
|
|
|
console.log('--stmt-depth-from-func: reset statement depth counter at each function, counts from global otherwise');
|
|
|
|
|
console.log('--only-stmt <statement names>: a comma delimited white list of statements that may be generated');
|
|
|
|
|
console.log('--without-stmt <statement names>: a comma delimited black list of statements never to generate');
|
|
|
|
|
console.log('List of accepted statement names: ' + Object.keys(STMT_ARG_TO_ID));
|
|
|
|
|
console.log('** UglifyJS fuzzer exiting **');
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
// first arg may be a number.
|
2017-04-01 19:17:01 +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 = [
|
2017-04-02 20:00:33 +00:00
|
|
|
'""',
|
2017-03-31 09:23:50 +00:00
|
|
|
'true',
|
|
|
|
|
'false',
|
2017-04-01 18:08:46 +00:00
|
|
|
' /[a2][^e]+$/ ',
|
|
|
|
|
'(-1)',
|
|
|
|
|
'(-2)',
|
|
|
|
|
'(-3)',
|
|
|
|
|
'(-4)',
|
|
|
|
|
'(-5)',
|
2017-03-31 09:23:50 +00:00
|
|
|
'0',
|
2017-04-01 18:08:46 +00:00
|
|
|
'1',
|
|
|
|
|
'2',
|
|
|
|
|
'3',
|
|
|
|
|
'4',
|
|
|
|
|
'5',
|
|
|
|
|
'22',
|
2017-03-31 09:23:50 +00:00
|
|
|
'-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
|
|
|
|
|
'"foo"',
|
2017-04-01 18:08:46 +00:00
|
|
|
'"bar"',
|
|
|
|
|
'"undefined"',
|
|
|
|
|
'"object"',
|
|
|
|
|
'"number"',
|
|
|
|
|
'"function"',
|
|
|
|
|
];
|
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 = [
|
2017-03-31 09:23:50 +00:00
|
|
|
' + ', // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors)
|
|
|
|
|
' - ',
|
|
|
|
|
'/',
|
|
|
|
|
'*',
|
|
|
|
|
'&',
|
|
|
|
|
'|',
|
|
|
|
|
'^',
|
|
|
|
|
'<',
|
|
|
|
|
'<=',
|
|
|
|
|
'>',
|
|
|
|
|
'>=',
|
|
|
|
|
'==',
|
|
|
|
|
'===',
|
|
|
|
|
'!=',
|
|
|
|
|
'!==',
|
|
|
|
|
'<<',
|
|
|
|
|
'>>',
|
|
|
|
|
'>>>',
|
|
|
|
|
'%',
|
|
|
|
|
'&&',
|
|
|
|
|
'||',
|
|
|
|
|
'^' ];
|
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 = [','].concat(BINARY_OPS_NO_COMMA);
|
|
|
|
|
|
|
|
|
|
var ASSIGNMENTS = [
|
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 UNARY_OPS = [
|
2017-03-31 09:23:50 +00:00
|
|
|
'--',
|
|
|
|
|
'++',
|
|
|
|
|
'~',
|
|
|
|
|
'!',
|
|
|
|
|
'void ',
|
|
|
|
|
'delete ', // should be safe, even `delete foo` and `delete f()` shouldn't crash
|
|
|
|
|
' - ',
|
|
|
|
|
' + ' ];
|
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;
|
|
|
|
|
var NOT_GLOBAL = true;
|
|
|
|
|
var IN_GLOBAL = true;
|
|
|
|
|
var ANY_TYPE = false;
|
|
|
|
|
var NO_DECL = true;
|
|
|
|
|
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 = [
|
2017-03-31 09:23:50 +00:00
|
|
|
'foo',
|
|
|
|
|
'bar',
|
|
|
|
|
'a',
|
|
|
|
|
'b',
|
|
|
|
|
'c', // prevent redeclaring this, avoid assigning to this
|
|
|
|
|
'undefined', // fun!
|
|
|
|
|
'eval', // mmmm, ok, also fun!
|
|
|
|
|
'NaN', // mmmm, ok, also fun!
|
|
|
|
|
'Infinity', // the fun never ends!
|
|
|
|
|
'arguments', // this one is just creepy
|
|
|
|
|
'Math', // since Math is assumed to be a non-constructor/function it may trip certain cases
|
|
|
|
|
'parseInt',
|
|
|
|
|
'parseFloat',
|
|
|
|
|
'isNaN',
|
|
|
|
|
'isFinite',
|
|
|
|
|
'decodeURI',
|
|
|
|
|
'decodeURIComponent',
|
|
|
|
|
'encodeURI',
|
|
|
|
|
'encodeURIComponent',
|
2017-04-01 09:09:52 +00:00
|
|
|
'Object'];
|
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 = [
|
2017-04-01 18:08:46 +00:00
|
|
|
'function',
|
2017-03-31 09:23:50 +00:00
|
|
|
'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-03-31 09:23:50 +00:00
|
|
|
var loops = 0;
|
|
|
|
|
var funcs = 0;
|
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-03-31 09:23:50 +00:00
|
|
|
function createTopLevelCode() {
|
2017-04-01 21:11:29 +00:00
|
|
|
if (rng(2) === 0) return createStatements(3, MAX_GENERATION_RECURSION_DEPTH, CANNOT_THROW, CANNOT_BREAK, CANNOT_CONTINUE, CANNOT_RETURN, 0);
|
|
|
|
|
return createFunctions(rng(MAX_GENERATED_TOPLEVELS_PER_RUN) + 1, MAX_GENERATION_RECURSION_DEPTH, IN_GLOBAL, ANY_TYPE, CANNOT_THROW, 0);
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 09:23:50 +00:00
|
|
|
function createFunctions(n, recurmax, inGlobal, noDecl, canThrow, stmtDepth) {
|
|
|
|
|
if (--recurmax < 0) { return ';'; }
|
|
|
|
|
var s = '';
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
|
s += createFunction(recurmax, inGlobal, noDecl, canThrow, stmtDepth) + '\n';
|
|
|
|
|
}
|
|
|
|
|
return s;
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 09:23:50 +00:00
|
|
|
function createFunction(recurmax, inGlobal, noDecl, canThrow, stmtDepth) {
|
|
|
|
|
if (--recurmax < 0) { return ';'; }
|
|
|
|
|
if (!STMT_COUNT_FROM_GLOBAL) stmtDepth = 0;
|
|
|
|
|
var func = funcs++;
|
|
|
|
|
var namesLenBefore = VAR_NAMES.length;
|
2017-03-31 21:47:11 +00:00
|
|
|
var name = (inGlobal || rng(5) > 0) ? 'f' + func : createVarName(MANDATORY, noDecl);
|
2017-03-31 09:23:50 +00:00
|
|
|
if (name === 'a' || name === 'b' || name === 'c') name = 'f' + func; // quick hack to prevent assignment to func names of being called
|
|
|
|
|
var s = '';
|
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-03-31 21:47:11 +00:00
|
|
|
s = 'function ' + name + '(' + createVarName(MANDATORY) + '){' + createFunctions(rng(5) + 1, Math.ceil(recurmax * 0.7), NOT_GLOBAL, ANY_TYPE, canThrow, stmtDepth) + '}\n';
|
2017-03-31 09:23:50 +00:00
|
|
|
} else {
|
|
|
|
|
// functions with statements
|
2017-03-31 21:47:11 +00:00
|
|
|
s = 'function ' + name + '(' + createVarName(MANDATORY) + '){' + createStatements(3, recurmax, canThrow, CANNOT_THROW, CANNOT_CONTINUE, CAN_RETURN, stmtDepth) + '}\n';
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAR_NAMES.length = namesLenBefore;
|
|
|
|
|
|
|
|
|
|
if (noDecl) s = '!' + s + '(' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ')';
|
|
|
|
|
// avoid "function statements" (decl inside statements)
|
|
|
|
|
else if (inGlobal || rng(10) > 0) s += name + '();'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
2017-03-31 09:23:50 +00:00
|
|
|
if (--recurmax < 0) { return ';'; }
|
|
|
|
|
var s = '';
|
|
|
|
|
while (--n > 0) {
|
2017-03-31 21:47:11 +00:00
|
|
|
s += createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '\n';
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:47:11 +00:00
|
|
|
function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) {
|
2017-03-31 09:23:50 +00:00
|
|
|
++stmtDepth;
|
|
|
|
|
var loop = ++loops;
|
|
|
|
|
if (--recurmax < 0) {
|
|
|
|
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ';';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allow to forcefully generate certain structures at first or second recursion level
|
|
|
|
|
var target = 0;
|
|
|
|
|
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)];
|
|
|
|
|
|
|
|
|
|
switch (target) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case STMT_BLOCK:
|
|
|
|
|
return '{' + createStatements(rng(5) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '}';
|
|
|
|
|
case STMT_IF_ELSE:
|
|
|
|
|
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) : '');
|
|
|
|
|
case STMT_DO_WHILE:
|
|
|
|
|
return '{var brake' + loop + ' = 5; do {' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE, cannotReturn, stmtDepth) + '} while ((' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && --brake' + loop + ' > 0);}';
|
|
|
|
|
case STMT_WHILE:
|
|
|
|
|
return '{var brake' + loop + ' = 5; while ((' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && --brake' + loop + ' > 0)' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE, cannotReturn, stmtDepth) + '}';
|
|
|
|
|
case STMT_FOR_LOOP:
|
|
|
|
|
return 'for (var brake' + loop + ' = 5; (' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && brake' + loop + ' > 0; --brake' + loop + ')' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE, cannotReturn, stmtDepth);
|
|
|
|
|
case STMT_SEMI:
|
|
|
|
|
return ';';
|
|
|
|
|
case STMT_EXPR:
|
|
|
|
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ';';
|
|
|
|
|
case STMT_SWITCH:
|
|
|
|
|
// note: case args are actual expressions
|
|
|
|
|
// note: default does not _need_ to be last
|
|
|
|
|
return 'switch (' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') { ' + createSwitchParts(recurmax, 4, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '}';
|
|
|
|
|
case STMT_VAR:
|
|
|
|
|
switch (rng(3)) {
|
|
|
|
|
case 0:
|
|
|
|
|
var name = createVarName(MANDATORY);
|
|
|
|
|
if (name === 'c') name = 'a';
|
|
|
|
|
return 'var ' + name + ';';
|
|
|
|
|
case 1:
|
|
|
|
|
// initializer can only have one expression
|
|
|
|
|
var name = createVarName(MANDATORY);
|
|
|
|
|
if (name === 'c') name = 'b';
|
|
|
|
|
return 'var ' + name + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';';
|
|
|
|
|
default:
|
|
|
|
|
// initializer can only have one expression
|
|
|
|
|
var n1 = createVarName(MANDATORY);
|
|
|
|
|
if (n1 === 'c') n1 = 'b';
|
|
|
|
|
var n2 = createVarName(MANDATORY);
|
|
|
|
|
if (n2 === 'c') n2 = 'b';
|
|
|
|
|
return 'var ' + n1 + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ', ' + n2 + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';';
|
|
|
|
|
}
|
|
|
|
|
case STMT_RETURN_ETC:
|
|
|
|
|
switch (rng(3)) {
|
|
|
|
|
case 1:
|
|
|
|
|
if (canBreak && rng(5) === 0) return 'break;';
|
|
|
|
|
if (canContinue && rng(5) === 0) return 'continue;';
|
|
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';';
|
|
|
|
|
return '/*3*/return;';
|
|
|
|
|
case 2:
|
|
|
|
|
// must wrap in curlies to prevent orphaned `else` statement
|
|
|
|
|
if (canThrow && rng(5) === 0) return '{ throw ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}';
|
|
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';';
|
|
|
|
|
return '{ /*1*/ return ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}';
|
|
|
|
|
default:
|
|
|
|
|
// 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
|
|
|
|
|
if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';';
|
|
|
|
|
return '{ /*2*/ return\n' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}';
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
return '{' + createFunction(recurmax, NOT_GLOBAL, NO_DECL, canThrow, stmtDepth) + '}';
|
|
|
|
|
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
|
|
|
|
|
var s = 'try {' + createStatement(recurmax, n === 1 ? CANNOT_THROW : CAN_THROW, canBreak, canContinue, cannotReturn, stmtDepth) + ' }';
|
|
|
|
|
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;
|
|
|
|
|
s += ' catch (' + catchName + ') { ' + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + ' }';
|
|
|
|
|
if (freshCatchName) VAR_NAMES.splice(nameLenBefore, 1); // remove catch name
|
|
|
|
|
}
|
|
|
|
|
if (n !== 0) s += ' finally { ' + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + ' }';
|
|
|
|
|
return s;
|
|
|
|
|
case STMT_C:
|
|
|
|
|
return 'c = c + 1;';
|
|
|
|
|
default:
|
|
|
|
|
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;
|
|
|
|
|
var s = '';
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
|
//hadDefault = n > 0; // disables weird `default` clause positioning (use when handling destabilizes)
|
|
|
|
|
if (hadDefault || rng(5) > 0) {
|
|
|
|
|
s += '' +
|
|
|
|
|
'case ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ':\n' +
|
2017-03-31 21:47:11 +00:00
|
|
|
createStatements(rng(3) + 1, recurmax, canThrow, CAN_BREAK, canContinue, cannotReturn, stmtDepth) +
|
2017-03-31 09:23:50 +00:00
|
|
|
'\n' +
|
|
|
|
|
(rng(10) > 0 ? ' break;' : '/* fall-through */') +
|
|
|
|
|
'\n';
|
|
|
|
|
} else {
|
|
|
|
|
hadDefault = true;
|
|
|
|
|
s += '' +
|
|
|
|
|
'default:\n' +
|
2017-03-31 21:47:11 +00:00
|
|
|
createStatements(rng(3) + 1, recurmax, canThrow, CAN_BREAK, canContinue, cannotReturn, stmtDepth) +
|
2017-03-31 09:23:50 +00:00
|
|
|
'\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
|
|
|
return s;
|
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) {
|
|
|
|
|
return '(c = 1 + c, ' + createNestedBinaryExpr(recurmax, noComma) + ')'; // note: should return a simple non-recursing expression value!
|
|
|
|
|
}
|
|
|
|
|
// since `a` and `b` are our canaries we want them more frequently than other expressions (1/3rd chance of a canary)
|
|
|
|
|
var r = rng(6);
|
|
|
|
|
if (r < 1) return 'a++ + ' + _createExpression(recurmax, noComma, stmtDepth, canThrow);
|
|
|
|
|
if (r < 2) return '(--b) + ' + _createExpression(recurmax, noComma, stmtDepth, canThrow);
|
|
|
|
|
if (r < 3) return '(c = c + 1) + ' + _createExpression(recurmax, noComma, stmtDepth, canThrow); // c only gets incremented
|
|
|
|
|
|
|
|
|
|
return _createExpression(recurmax, noComma, stmtDepth, canThrow);
|
|
|
|
|
}
|
|
|
|
|
function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
2017-04-02 20:00:33 +00:00
|
|
|
switch (rng(31)) {
|
2017-03-31 21:47:11 +00:00
|
|
|
case 0:
|
|
|
|
|
case 1:
|
2017-04-02 20:00:33 +00:00
|
|
|
return createUnaryOp() + (rng(2) === 1 ? 'a' : 'b');
|
2017-03-31 21:47:11 +00:00
|
|
|
case 2:
|
2017-04-02 20:00:33 +00:00
|
|
|
case 3:
|
|
|
|
|
return 'a' + (rng(2) == 1 ? '++' : '--');
|
|
|
|
|
case 4:
|
|
|
|
|
case 5:
|
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
|
|
|
|
|
return '(b ' + createAssignment() + ' a)';
|
2017-04-02 20:00:33 +00:00
|
|
|
case 6:
|
|
|
|
|
case 7:
|
2017-03-31 21:47:11 +00:00
|
|
|
return rng(2) + ' === 1 ? a : b';
|
2017-04-02 20:00:33 +00:00
|
|
|
case 8:
|
|
|
|
|
case 9:
|
2017-03-31 21:47:11 +00:00
|
|
|
return createNestedBinaryExpr(recurmax, noComma) + createBinaryOp(noComma) + createExpression(recurmax, noComma, stmtDepth, canThrow);
|
2017-04-02 20:00:33 +00:00
|
|
|
case 10:
|
|
|
|
|
case 11:
|
2017-03-31 21:47:11 +00:00
|
|
|
return createValue();
|
2017-04-02 20:00:33 +00:00
|
|
|
case 12:
|
2017-03-31 21:47:11 +00:00
|
|
|
return '(' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ')';
|
2017-04-02 20:00:33 +00:00
|
|
|
case 13:
|
2017-03-31 21:47:11 +00:00
|
|
|
return createExpression(recurmax, noComma, stmtDepth, canThrow) + '?' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ':' + createExpression(recurmax, noComma, stmtDepth, canThrow);
|
2017-04-02 20:00:33 +00:00
|
|
|
case 14:
|
2017-03-31 21:47:11 +00:00
|
|
|
var nameLenBefore = VAR_NAMES.length;
|
|
|
|
|
var name = createVarName(MAYBE); // note: this name is only accessible from _within_ the function. and immutable at that.
|
|
|
|
|
if (name === 'c') name = 'a';
|
|
|
|
|
var s = '';
|
|
|
|
|
switch(rng(4)) {
|
|
|
|
|
case 0:
|
|
|
|
|
s = '(function ' + name + '(){' + createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth) + '})()';
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
s = '+function ' + name + '(){' + createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth) + '}()';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
s = '!function ' + name + '(){' + createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth) + '}()';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
s = 'void function ' + name + '(){' + createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth) + '}()';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
VAR_NAMES.length = nameLenBefore;
|
|
|
|
|
return s;
|
2017-04-02 20:00:33 +00:00
|
|
|
case 15:
|
|
|
|
|
case 16:
|
2017-04-01 21:11:29 +00:00
|
|
|
return createTypeofExpr(recurmax, stmtDepth, canThrow);
|
2017-04-02 20:00:33 +00:00
|
|
|
case 17:
|
2017-03-31 21:47:11 +00:00
|
|
|
// you could statically infer that this is just `Math`, regardless of the other expression
|
|
|
|
|
// I don't think Uglify does this at this time...
|
|
|
|
|
return ''+
|
|
|
|
|
'new function(){ \n' +
|
|
|
|
|
(rng(2) === 1 ? createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + '\n' : '') +
|
|
|
|
|
'return Math;\n' +
|
|
|
|
|
'}';
|
2017-04-02 20:00:33 +00:00
|
|
|
case 18:
|
|
|
|
|
case 19:
|
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:
|
|
|
|
|
return 'a/* ignore */++';
|
|
|
|
|
case 1:
|
|
|
|
|
return 'b/* ignore */--';
|
|
|
|
|
case 2:
|
|
|
|
|
return '(++/* ignore */a)';
|
|
|
|
|
case 3:
|
|
|
|
|
return '(--/* ignore */b)';
|
|
|
|
|
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...
|
|
|
|
|
return '(--(b))';
|
|
|
|
|
case 5:
|
|
|
|
|
// classic 0.3-0.1 case; 1-0.1-0.1-0.1 is not 0.7 :)
|
|
|
|
|
return 'b + 1-0.1-0.1-0.1';
|
|
|
|
|
default:
|
|
|
|
|
return '(--/* ignore */b)';
|
|
|
|
|
}
|
2017-04-02 20:00:33 +00:00
|
|
|
case 20:
|
|
|
|
|
case 21:
|
2017-03-31 21:47:11 +00:00
|
|
|
return createNestedBinaryExpr(recurmax, noComma);
|
2017-04-02 20:00:33 +00:00
|
|
|
case 22:
|
2017-04-01 18:08:46 +00:00
|
|
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || a || 3).toString() ";
|
2017-04-02 20:00:33 +00:00
|
|
|
case 23:
|
2017-04-01 18:08:46 +00:00
|
|
|
return " /[abc4]/.test(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) ";
|
2017-04-02 20:00:33 +00:00
|
|
|
case 24:
|
|
|
|
|
return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) +
|
|
|
|
|
") || " + rng(10) + ").toString()[" +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "] ";
|
|
|
|
|
case 25:
|
|
|
|
|
return createArrayLiteral(recurmax, COMMA_OK, stmtDepth, canThrow);
|
|
|
|
|
case 26:
|
|
|
|
|
return createObjectLiteral(recurmax, COMMA_OK, stmtDepth, canThrow);
|
|
|
|
|
case 27:
|
|
|
|
|
return '(' + createArrayLiteral(recurmax, COMMA_OK, stmtDepth, canThrow) + '[' +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]) ";
|
|
|
|
|
case 28:
|
|
|
|
|
return '(' + createObjectLiteral(recurmax, COMMA_OK, stmtDepth, canThrow) + '[' +
|
|
|
|
|
createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "]) ";
|
|
|
|
|
case 29:
|
|
|
|
|
return '(' + createArrayLiteral(recurmax, COMMA_OK, stmtDepth, canThrow) + '.' +
|
|
|
|
|
SAFE_KEYS[rng(SAFE_KEYS.length)] + ") ";
|
|
|
|
|
case 30:
|
|
|
|
|
return '(' + createObjectLiteral(recurmax, COMMA_OK, stmtDepth, canThrow) + '.' +
|
|
|
|
|
SAFE_KEYS[rng(SAFE_KEYS.length)] + ") ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createArrayLiteral(recurmax, noComma, stmtDepth, canThrow) {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
function createObjectLiteral(recurmax, noComma, stmtDepth, canThrow) {
|
|
|
|
|
recurmax--;
|
|
|
|
|
var obj = "({";
|
|
|
|
|
for (var i = rng(6); --i >= 0;) {
|
|
|
|
|
var key = KEYS[rng(KEYS.length)];
|
|
|
|
|
obj += key + ":(" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "), ";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2017-04-02 20:00:33 +00:00
|
|
|
return obj + "})";
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createNestedBinaryExpr(recurmax, noComma) {
|
|
|
|
|
recurmax = 3; // note that this generates 2^recurmax expression parts... make sure to cap it
|
|
|
|
|
return _createSimpleBinaryExpr(recurmax, noComma);
|
|
|
|
|
}
|
|
|
|
|
function _createSimpleBinaryExpr(recurmax, noComma) {
|
|
|
|
|
// intentionally generate more hardcore ops
|
|
|
|
|
if (--recurmax < 0) return createValue();
|
|
|
|
|
var r = rng(30);
|
2017-04-01 21:11:29 +00:00
|
|
|
if (r === 0) return '(c = c + 1, ' + _createSimpleBinaryExpr(recurmax, noComma) + ')';
|
2017-03-31 09:23:50 +00:00
|
|
|
var s = _createSimpleBinaryExpr(recurmax, noComma) + createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma);
|
|
|
|
|
if (r === 1) {
|
|
|
|
|
// try to get a generated name reachable from current scope. default to just `a`
|
|
|
|
|
var assignee = VAR_NAMES[INITIAL_NAMES_LEN + rng(VAR_NAMES.length - INITIAL_NAMES_LEN)] || 'a';
|
|
|
|
|
return '( ' + assignee + createAssignment() + s + ')';
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
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:
|
|
|
|
|
return 'typeof ' + createVarName(MANDATORY, DONT_STORE) + ' === "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '"';
|
|
|
|
|
case 1:
|
|
|
|
|
return 'typeof ' + createVarName(MANDATORY, DONT_STORE) + ' !== "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '"';
|
|
|
|
|
case 2:
|
|
|
|
|
return 'typeof ' + createVarName(MANDATORY, DONT_STORE) + ' == "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '"';
|
|
|
|
|
case 3:
|
|
|
|
|
return 'typeof ' + createVarName(MANDATORY, DONT_STORE) + ' != "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '"';
|
|
|
|
|
case 4:
|
|
|
|
|
return 'typeof ' + createVarName(MANDATORY, DONT_STORE);
|
2017-04-01 21:11:29 +00:00
|
|
|
default:
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createUnaryOp() {
|
2017-03-31 09:23:50 +00:00
|
|
|
return UNARY_OPS[rng(UNARY_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-31 21:47:11 +00:00
|
|
|
function createVarName(maybe, dontStore) {
|
2017-03-31 09:23:50 +00:00
|
|
|
if (!maybe || rng(2) === 1) {
|
2017-03-31 21:47:11 +00:00
|
|
|
var r = rng(VAR_NAMES.length);
|
|
|
|
|
var suffixed = rng(5) > 0;
|
|
|
|
|
var name = VAR_NAMES[r] + (suffixed ? '_' + (++loops) : '');
|
2017-03-31 09:23:50 +00:00
|
|
|
if (!dontStore && suffixed) VAR_NAMES.push(name);
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
return '';
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:47:11 +00:00
|
|
|
function try_beautify(code, result) {
|
|
|
|
|
try {
|
2017-04-01 18:10:50 +00:00
|
|
|
var beautified = UglifyJS.minify(code, {
|
2017-03-31 21:47:11 +00:00
|
|
|
fromString: true,
|
|
|
|
|
compress: false,
|
|
|
|
|
mangle: false,
|
|
|
|
|
output: {
|
|
|
|
|
beautify: true,
|
|
|
|
|
bracketize: true,
|
|
|
|
|
},
|
|
|
|
|
}).code;
|
|
|
|
|
if (sandbox.same_stdout(sandbox.run_code(beautified), result)) {
|
|
|
|
|
console.log("// (beautified)");
|
|
|
|
|
console.log(beautified);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("// !!! beautify failed !!!");
|
|
|
|
|
console.log(e.stack);
|
|
|
|
|
}
|
|
|
|
|
console.log("//");
|
|
|
|
|
console.log(code);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
function infer_options(ctor) {
|
|
|
|
|
try {
|
|
|
|
|
ctor({ 0: 0 });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return e.defs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var default_options = {
|
|
|
|
|
compress: infer_options(UglifyJS.Compressor),
|
|
|
|
|
mangle: {
|
|
|
|
|
"cache": null,
|
|
|
|
|
"eval": false,
|
|
|
|
|
"keep_fnames": false,
|
|
|
|
|
"screw_ie8": true,
|
|
|
|
|
"toplevel": false,
|
|
|
|
|
},
|
|
|
|
|
output: infer_options(UglifyJS.OutputStream),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function log_suspects(minify_options, component) {
|
|
|
|
|
var options = component in minify_options ? minify_options[component] : true;
|
|
|
|
|
if (!options) return;
|
|
|
|
|
options = UglifyJS.defaults(options, default_options[component]);
|
|
|
|
|
var suspects = Object.keys(default_options[component]).filter(function(name) {
|
|
|
|
|
if (options[name]) {
|
|
|
|
|
var m = JSON.parse(JSON.stringify(minify_options));
|
|
|
|
|
var o = JSON.parse(JSON.stringify(options));
|
|
|
|
|
o[name] = false;
|
|
|
|
|
m[component] = o;
|
|
|
|
|
try {
|
|
|
|
|
var r = sandbox.run_code(UglifyJS.minify(original_code, m).code);
|
|
|
|
|
return sandbox.same_stdout(original_result, r);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Error testing options." + component + "." + name);
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (suspects.length > 0) {
|
|
|
|
|
console.log("Suspicious", component, "options:");
|
|
|
|
|
suspects.forEach(function(name) {
|
|
|
|
|
console.log(" " + name);
|
|
|
|
|
});
|
|
|
|
|
console.log();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function log(options) {
|
2017-03-31 09:23:50 +00:00
|
|
|
if (!ok) console.log('\n\n\n\n\n\n!!!!!!!!!!\n\n\n');
|
2017-03-24 17:46:12 +00:00
|
|
|
console.log("//=============================================================");
|
2017-03-31 09:23:50 +00:00
|
|
|
if (!ok) console.log("// !!!!!! Failed... round", round);
|
2017-03-24 17:46:12 +00:00
|
|
|
console.log("// original code");
|
2017-03-31 21:47:11 +00:00
|
|
|
try_beautify(original_code, original_result);
|
2017-03-24 17:46:12 +00:00
|
|
|
console.log();
|
|
|
|
|
console.log();
|
2017-03-31 21:47:11 +00:00
|
|
|
console.log("//-------------------------------------------------------------");
|
|
|
|
|
if (typeof uglify_code == "string") {
|
|
|
|
|
console.log("// uglified code");
|
|
|
|
|
try_beautify(uglify_code, uglify_result);
|
2017-03-31 09:23:50 +00:00
|
|
|
console.log();
|
|
|
|
|
console.log();
|
2017-03-31 21:47:11 +00:00
|
|
|
console.log("original result:");
|
|
|
|
|
console.log(original_result);
|
|
|
|
|
console.log("uglified result:");
|
|
|
|
|
console.log(uglify_result);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("// !!! uglify failed !!!");
|
|
|
|
|
console.log(uglify_code.stack);
|
2017-03-31 09:23:50 +00:00
|
|
|
}
|
2017-04-01 18:10:50 +00:00
|
|
|
console.log("minify(options):");
|
|
|
|
|
options = JSON.parse(options);
|
|
|
|
|
console.log(options);
|
|
|
|
|
console.log();
|
|
|
|
|
if (!ok) {
|
|
|
|
|
Object.keys(default_options).forEach(log_suspects.bind(null, options));
|
|
|
|
|
console.log("!!!!!! Failed... round", round);
|
|
|
|
|
}
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
var minify_options = require("./ufuzz.json").map(function(options) {
|
|
|
|
|
options.fromString = true;
|
|
|
|
|
return JSON.stringify(options);
|
|
|
|
|
});
|
|
|
|
|
var original_code, original_result;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
VAR_NAMES.length = INITIAL_NAMES_LEN; // prune any previous names still in the list
|
|
|
|
|
loops = 0;
|
|
|
|
|
funcs = 0;
|
|
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
original_code = [
|
2017-03-31 09:23:50 +00:00
|
|
|
"var a = 100, b = 10, c = 0;",
|
2017-04-01 21:11:29 +00:00
|
|
|
createTopLevelCode(),
|
2017-03-31 21:47:11 +00:00
|
|
|
"console.log(null, a, b, c);" // preceding `null` makes for a cleaner output (empty string still shows up etc)
|
2017-03-24 17:46:12 +00:00
|
|
|
].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-04-01 18:10:50 +00:00
|
|
|
minify_options.forEach(function(options) {
|
|
|
|
|
try {
|
|
|
|
|
uglify_code = UglifyJS.minify(original_code, JSON.parse(options)).code;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
uglify_code = e;
|
|
|
|
|
}
|
2017-03-31 21:47:11 +00:00
|
|
|
|
2017-04-01 18:10:50 +00:00
|
|
|
ok = typeof uglify_code == "string";
|
|
|
|
|
if (ok) {
|
|
|
|
|
original_result = sandbox.run_code(original_code);
|
|
|
|
|
uglify_result = sandbox.run_code(uglify_code);
|
|
|
|
|
ok = sandbox.same_stdout(original_result, uglify_result);
|
|
|
|
|
}
|
|
|
|
|
if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options);
|
|
|
|
|
if (!ok && isFinite(num_iterations)) process.exit(1);
|
|
|
|
|
});
|
2017-03-24 17:46:12 +00:00
|
|
|
}
|