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-04-15 15:50:50 +00:00
// check both CLI and file modes of nodejs (!). See #1695 for details. and the various settings of uglify.
2017-03-31 09:23:50 +00:00
// bin/uglifyjs s.js -c && bin/uglifyjs s.js -c passes=3 && bin/uglifyjs s.js -c passes=3 -m
// cat s.js | node && node s.js && bin/uglifyjs s.js -c | node && bin/uglifyjs s.js -c passes=3 | node && bin/uglifyjs s.js -c passes=3 -m | node
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-04-21 06:11:15 +00:00
var STMT _ARG _TO _ID = Object . create ( null ) ;
var STMTS _TO _USE = [ ] ;
function STMT _ ( name ) {
return STMT _ARG _TO _ID [ name ] = STMTS _TO _USE . push ( STMTS _TO _USE . length ) - 1 ;
}
var STMT _BLOCK = STMT _ ( "block" ) ;
var STMT _IF _ELSE = STMT _ ( "ifelse" ) ;
var STMT _DO _WHILE = STMT _ ( "dowhile" ) ;
var STMT _WHILE = STMT _ ( "while" ) ;
var STMT _FOR _LOOP = STMT _ ( "forloop" ) ;
var STMT _FOR _IN = STMT _ ( "forin" ) ;
var STMT _SEMI = STMT _ ( "semi" ) ;
var STMT _EXPR = STMT _ ( "expr" ) ;
var STMT _SWITCH = STMT _ ( "switch" ) ;
var STMT _VAR = STMT _ ( "var" ) ;
var STMT _RETURN _ETC = STMT _ ( "stop" ) ;
var STMT _FUNC _EXPR = STMT _ ( "funcexpr" ) ;
var STMT _TRY = STMT _ ( "try" ) ;
var STMT _C = STMT _ ( "c" ) ;
2017-03-31 09:23:50 +00:00
var STMT _FIRST _LEVEL _OVERRIDE = - 1 ;
var STMT _SECOND _LEVEL _OVERRIDE = - 1 ;
var STMT _COUNT _FROM _GLOBAL = true ; // count statement depth from nearest function scope or just global scope?
var num _iterations = + process . argv [ 2 ] || 1 / 0 ;
var verbose = false ; // log every generated test
var verbose _interval = false ; // log every 100 generated tests
2017-04-08 17:36:38 +00:00
var verbose _error = false ;
2017-03-31 09:23:50 +00:00
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 ;
2017-04-08 17:36:38 +00:00
case '-E' :
verbose _error = true ;
break ;
2017-03-31 21:47:11 +00:00
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' ) ;
2017-04-08 17:36:38 +00:00
console . log ( '-E: print generated test case with runtime error' ) ;
2017-03-31 21:47:11 +00:00
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
2017-04-07 10:47:30 +00:00
var UNARY _SAFE = [
'+' ,
'-' ,
2017-03-31 09:23:50 +00:00
'~' ,
'!' ,
'void ' ,
2017-04-07 10:47:30 +00:00
'delete ' ,
] ;
var UNARY _POSTFIX = [
'++' ,
'--' ,
] ;
var UNARY _PREFIX = UNARY _POSTFIX . concat ( UNARY _SAFE ) ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
var NO _COMMA = true ;
2017-03-31 09:23:50 +00:00
var COMMA _OK = false ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
var MAYBE = true ;
2017-03-31 09:23:50 +00:00
var MANDATORY = false ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
var CAN _THROW = true ;
var CANNOT _THROW = false ;
var CAN _BREAK = true ;
2017-03-31 09:23:50 +00:00
var CANNOT _BREAK = false ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
var CAN _CONTINUE = true ;
2017-03-31 09:23:50 +00:00
var CANNOT _CONTINUE = false ;
var CAN _RETURN = false ;
var CANNOT _RETURN = true ;
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
'a' ,
2017-04-07 10:47:30 +00:00
'a' ,
'a' ,
'a' ,
'b' ,
'b' ,
'b' ,
2017-03-31 09:23:50 +00:00
'b' ,
'c' , // prevent redeclaring this, avoid assigning to this
2017-04-07 10:47:30 +00:00
'foo' ,
'foo' ,
'bar' ,
'bar' ,
'undefined' ,
'NaN' ,
'Infinity' ,
'arguments' ,
'Math' ,
2017-03-31 09:23:50 +00:00
'parseInt' ,
2017-04-07 10:47:30 +00:00
] ;
2017-03-31 09:23:50 +00:00
var INITIAL _NAMES _LEN = VAR _NAMES . length ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
var TYPEOF _OUTCOMES = [
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-04-07 10:47:30 +00:00
function createParams ( ) {
var params = [ ] ;
for ( var n = rng ( 4 ) ; -- n >= 0 ; ) {
params . push ( createVarName ( MANDATORY ) ) ;
}
return params . join ( ', ' ) ;
}
function createArgs ( ) {
var args = [ ] ;
for ( var n = rng ( 4 ) ; -- n >= 0 ; ) {
args . push ( createValue ( ) ) ;
}
return args . join ( ', ' ) ;
}
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-04-07 10:47:30 +00:00
s = 'function ' + name + '(' + createParams ( ) + '){' + 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-04-21 06:11:15 +00:00
s = 'function ' + name + '(' + createParams ( ) + '){' + createStatements ( 3 , recurmax , canThrow , CANNOT _BREAK , CANNOT _CONTINUE , CAN _RETURN , stmtDepth ) + '}\n' ;
2017-03-31 09:23:50 +00:00
}
VAR _NAMES . length = namesLenBefore ;
2017-04-07 10:47:30 +00:00
if ( noDecl ) s = 'var ' + createVarName ( MANDATORY ) + ' = ' + s + '(' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ');' ;
2017-03-31 09:23:50 +00:00
// avoid "function statements" (decl inside statements)
2017-04-07 10:47:30 +00:00
else if ( inGlobal || rng ( 10 ) > 0 ) s += 'var ' + createVarName ( MANDATORY ) + ' = ' + name + '(' + createArgs ( ) + ');' ;
2017-03-31 09:23:50 +00:00
return s ;
2017-03-24 17:46:12 +00:00
}
2017-03-31 21:47:11 +00:00
function createStatements ( n , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) {
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-04-21 06:11:15 +00:00
function createLabel ( canBreak , canContinue ) {
var label ;
if ( rng ( 10 ) < 3 ) {
if ( Array . isArray ( canBreak ) ) {
canBreak = canBreak . slice ( ) ;
label = canBreak [ canBreak . length - 1 ] + 1 ;
} else {
canBreak = canBreak ? [ "" ] : [ ] ;
label = 1 ;
}
canBreak . push ( label ) ;
if ( Array . isArray ( canContinue ) ) {
canContinue = canContinue . slice ( ) ;
} else {
canContinue = canContinue ? [ "" ] : [ ] ;
}
canContinue . push ( label ) ;
}
return {
break : CAN _BREAK && canBreak ,
continue : CAN _CONTINUE && canContinue ,
target : label ? "L" + label + ": " : ""
} ;
}
function getLabel ( label ) {
label = label [ rng ( label . length ) ] ;
return label && " L" + label ;
}
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 :
2017-04-21 06:11:15 +00:00
var label = createLabel ( canBreak ) ;
return label . target + '{' + createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , label . break , canContinue , cannotReturn , stmtDepth ) + '}' ;
2017-03-31 21:47:11 +00:00
case STMT _IF _ELSE :
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 :
2017-04-21 06:11:15 +00:00
var label = createLabel ( canBreak , canContinue ) ;
return '{var brake' + loop + ' = 5; ' + label . target + 'do {' + createStatement ( recurmax , canThrow , label . break , label . continue , cannotReturn , stmtDepth ) + '} while ((' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ') && --brake' + loop + ' > 0);}' ;
2017-03-31 21:47:11 +00:00
case STMT _WHILE :
2017-04-21 06:11:15 +00:00
var label = createLabel ( canBreak , canContinue ) ;
return '{var brake' + loop + ' = 5; ' + label . target + 'while ((' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ') && --brake' + loop + ' > 0)' + createStatement ( recurmax , canThrow , label . break , label . continue , cannotReturn , stmtDepth ) + '}' ;
2017-03-31 21:47:11 +00:00
case STMT _FOR _LOOP :
2017-04-21 06:11:15 +00:00
var label = createLabel ( canBreak , canContinue ) ;
return label . target + 'for (var brake' + loop + ' = 5; (' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ') && brake' + loop + ' > 0; --brake' + loop + ')' + createStatement ( recurmax , canThrow , label . break , label . continue , cannotReturn , stmtDepth ) ;
case STMT _FOR _IN :
var label = createLabel ( canBreak , canContinue ) ;
var optElementVar = '' ;
if ( rng ( 5 ) > 1 ) {
optElementVar = 'var ' + createVarName ( MANDATORY ) + ' = expr' + loop + '[key' + loop + ']; ' ;
}
return label . target + ' for (var key' + loop + ' in ' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ') {' + optElementVar + createStatement ( recurmax , canThrow , label . break , label . continue , cannotReturn , stmtDepth ) + '}' ;
2017-03-31 21:47:11 +00:00
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 :
2017-04-08 17:36:38 +00:00
switch ( rng ( 8 ) ) {
case 0 :
2017-03-31 21:47:11 +00:00
case 1 :
2017-04-08 17:36:38 +00:00
case 2 :
case 3 :
2017-04-21 06:11:15 +00:00
if ( canBreak && rng ( 5 ) === 0 ) return 'break' + getLabel ( canBreak ) + ';' ;
if ( canContinue && rng ( 5 ) === 0 ) return 'continue' + getLabel ( canContinue ) + ';' ;
2017-03-31 21:47:11 +00:00
if ( cannotReturn ) return createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + ';' ;
2017-04-07 10:47:30 +00:00
if ( rng ( 3 ) == 0 ) return '/*3*/return;' ;
2017-04-08 17:36:38 +00:00
return 'return ' + createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + ';' ;
case 4 :
2017-03-31 21:47:11 +00:00
// this is actually more like a parser test, but perhaps it hits some dead code elimination traps
// must wrap in curlies to prevent orphaned `else` statement
// note: you can't `throw` without an expression so don't put a `throw` option in this case
if ( cannotReturn ) return createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + ';' ;
return '{ /*2*/ return\n' + createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + '}' ;
2017-04-08 17:36:38 +00:00
default :
// must wrap in curlies to prevent orphaned `else` statement
if ( canThrow && rng ( 5 ) === 0 ) return '{ throw ' + createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + '}' ;
if ( cannotReturn ) return createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + ';' ;
return '{ return ' + createExpression ( recurmax , NO _COMMA , stmtDepth , canThrow ) + '}' ;
2017-03-31 21:47:11 +00:00
}
case STMT _FUNC _EXPR :
// "In non-strict mode code, functions can only be declared at top level, inside a block, or ..."
// (dont both with func decls in `if`; it's only a parser thing because you cant call them without a block)
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-04-21 06:11:15 +00:00
createStatements ( rng ( 3 ) + 1 , recurmax , canThrow , canBreak || 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-04-21 06:11:15 +00:00
createStatements ( rng ( 3 ) + 1 , recurmax , canThrow , canBreak || 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 ) {
2017-04-07 10:47:30 +00:00
return '(c = 1 + c, ' + createNestedBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ; // note: should return a simple non-recursing expression value!
2017-03-31 09:23:50 +00:00
}
// since `a` and `b` are our canaries we want them more frequently than other expressions (1/3rd chance of a canary)
2017-04-07 10:47:30 +00:00
switch ( rng ( 6 ) ) {
2017-03-31 21:47:11 +00:00
case 0 :
2017-04-07 10:47:30 +00:00
return '(a++ + (' + _createExpression ( recurmax , noComma , stmtDepth , canThrow ) + '))' ;
2017-03-31 21:47:11 +00:00
case 1 :
2017-04-07 10:47:30 +00:00
return '((--b) + (' + _createExpression ( recurmax , noComma , stmtDepth , canThrow ) + '))' ;
2017-03-31 21:47:11 +00:00
case 2 :
2017-04-07 10:47:30 +00:00
return '((c = c + 1) + (' + _createExpression ( recurmax , noComma , stmtDepth , canThrow ) + '))' ; // c only gets incremented
default :
return '(' + _createExpression ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
}
}
function _createExpression ( recurmax , noComma , stmtDepth , canThrow ) {
var p = 0 ;
switch ( rng ( _createExpression . N ) ) {
case p ++ :
case p ++ :
return createUnaryPrefix ( ) + ( rng ( 2 ) === 1 ? 'a' : 'b' ) ;
case p ++ :
case p ++ :
return ( rng ( 2 ) === 1 ? 'a' : 'b' ) + createUnaryPostfix ( ) ;
case p ++ :
case p ++ :
2017-03-31 21:47:11 +00:00
// parens needed because assignments aren't valid unless they're the left-most op(s) in an expression
2017-04-07 10:47:30 +00:00
return 'b ' + createAssignment ( ) + ' a' ;
case p ++ :
case p ++ :
2017-03-31 21:47:11 +00:00
return rng ( 2 ) + ' === 1 ? a : b' ;
2017-04-07 10:47:30 +00:00
case p ++ :
case p ++ :
2017-03-31 21:47:11 +00:00
return createValue ( ) ;
2017-04-07 10:47:30 +00:00
case p ++ :
return createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) ;
case p ++ :
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-07 10:47:30 +00:00
case p ++ :
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-07 10:47:30 +00:00
case p ++ :
case p ++ :
2017-04-01 21:11:29 +00:00
return createTypeofExpr ( recurmax , stmtDepth , canThrow ) ;
2017-04-07 10:47:30 +00:00
case p ++ :
return [
'new function() {' ,
rng ( 2 ) ? '' : createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ';' ,
'return ' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ';' ,
'}'
] . join ( '\n' ) ;
case p ++ :
case p ++ :
2017-03-31 21:47:11 +00:00
// more like a parser test but perhaps comment nodes mess up the analysis?
// note: parens not needed for post-fix (since that's the default when ambiguous)
// for prefix ops we need parens to prevent accidental syntax errors.
switch ( rng ( 6 ) ) {
case 0 :
return 'a/* ignore */++' ;
case 1 :
return 'b/* ignore */--' ;
case 2 :
2017-04-07 10:47:30 +00:00
return '++/* ignore */a' ;
2017-03-31 21:47:11 +00:00
case 3 :
2017-04-07 10:47:30 +00:00
return '--/* ignore */b' ;
2017-03-31 21:47:11 +00:00
case 4 :
// only groups that wrap a single variable return a "Reference", so this is still valid.
// may just be a parser edge case that is invisible to uglify...
2017-04-07 10:47:30 +00:00
return '--(b)' ;
2017-03-31 21:47:11 +00:00
case 5 :
// classic 0.3-0.1 case; 1-0.1-0.1-0.1 is not 0.7 :)
return 'b + 1-0.1-0.1-0.1' ;
default :
2017-04-07 10:47:30 +00:00
return '--/* ignore */b' ;
2017-03-31 21:47:11 +00:00
}
2017-04-07 10:47:30 +00:00
case p ++ :
case p ++ :
return createNestedBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) ;
case p ++ :
case p ++ :
return createUnarySafePrefix ( ) + '(' + createNestedBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
case p ++ :
2017-04-01 18:08:46 +00:00
return " ((" + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ") || a || 3).toString() " ;
2017-04-07 10:47:30 +00:00
case p ++ :
2017-04-01 18:08:46 +00:00
return " /[abc4]/.test(((" + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ") || b || 5).toString()) " ;
2017-04-07 10:47:30 +00:00
case p ++ :
2017-04-02 20:00:33 +00:00
return " ((" + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) +
") || " + rng ( 10 ) + ").toString()[" +
createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + "] " ;
2017-04-07 10:47:30 +00:00
case p ++ :
2017-04-02 20:00:33 +00:00
return createArrayLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) ;
2017-04-07 10:47:30 +00:00
case p ++ :
2017-04-02 20:00:33 +00:00
return createObjectLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) ;
2017-04-07 10:47:30 +00:00
case p ++ :
return createArrayLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) + '[' +
createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ']' ;
case p ++ :
return createObjectLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) + '[' +
createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ']' ;
case p ++ :
return createArrayLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) + '.' + getDotKey ( ) ;
case p ++ :
return createObjectLiteral ( recurmax , COMMA _OK , stmtDepth , canThrow ) + '.' + getDotKey ( ) ;
case p ++ :
var name = getVarName ( ) ;
return name + ' && ' + name + '[' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow ) + ']' ;
case p ++ :
var name = getVarName ( ) ;
return name + ' && ' + name + '.' + getDotKey ( ) ;
2017-04-02 20:00:33 +00:00
}
2017-04-07 10:47:30 +00:00
_createExpression . N = p ;
return _createExpression ( recurmax , noComma , stmtDepth , canThrow ) ;
2017-04-02 20:00:33 +00:00
}
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 ) ;
2017-04-07 10:47:30 +00:00
function getDotKey ( ) {
return SAFE _KEYS [ rng ( SAFE _KEYS . length ) ] ;
}
2017-04-02 20:00:33 +00:00
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
}
2017-04-07 10:47:30 +00:00
function createNestedBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) {
2017-03-31 09:23:50 +00:00
recurmax = 3 ; // note that this generates 2^recurmax expression parts... make sure to cap it
2017-04-07 10:47:30 +00:00
return _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) ;
}
function _createBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) {
return '(' + _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow )
+ createBinaryOp ( noComma ) + _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
2017-03-31 09:23:50 +00:00
}
2017-04-07 10:47:30 +00:00
function _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) {
2017-03-31 09:23:50 +00:00
// intentionally generate more hardcore ops
if ( -- recurmax < 0 ) return createValue ( ) ;
2017-04-07 10:47:30 +00:00
switch ( rng ( 30 ) ) {
case 0 :
return '(c = c + 1, ' + _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
case 1 :
return '(' + createUnarySafePrefix ( ) + '(' + _createSimpleBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + '))' ;
case 2 :
var assignee = getVarName ( ) ;
return '(' + assignee + createAssignment ( ) + _createBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
case 3 :
var assignee = getVarName ( ) ;
var expr = '(' + assignee + '[' + createExpression ( recurmax , COMMA _OK , stmtDepth , canThrow )
+ ']' + createAssignment ( ) + _createBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
return canThrow && rng ( 10 ) == 0 ? expr : '(' + assignee + ' && ' + expr + ')' ;
case 4 :
var assignee = getVarName ( ) ;
var expr = '(' + assignee + '.' + getDotKey ( ) + createAssignment ( )
+ _createBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) + ')' ;
return canThrow && rng ( 10 ) == 0 ? expr : '(' + assignee + ' && ' + expr + ')' ;
default :
return _createBinaryExpr ( recurmax , noComma , stmtDepth , canThrow ) ;
2017-03-31 09:23:50 +00:00
}
}
2017-04-01 21:11:29 +00:00
function createTypeofExpr ( recurmax , stmtDepth , canThrow ) {
2017-04-01 18:08:46 +00:00
switch ( rng ( 8 ) ) {
2017-03-31 21:47:11 +00:00
case 0 :
2017-04-07 10:47:30 +00:00
return '(typeof ' + createVarName ( MANDATORY , DONT _STORE ) + ' === "' + TYPEOF _OUTCOMES [ rng ( TYPEOF _OUTCOMES . length ) ] + '")' ;
2017-03-31 21:47:11 +00:00
case 1 :
2017-04-07 10:47:30 +00:00
return '(typeof ' + createVarName ( MANDATORY , DONT _STORE ) + ' !== "' + TYPEOF _OUTCOMES [ rng ( TYPEOF _OUTCOMES . length ) ] + '")' ;
2017-03-31 21:47:11 +00:00
case 2 :
2017-04-07 10:47:30 +00:00
return '(typeof ' + createVarName ( MANDATORY , DONT _STORE ) + ' == "' + TYPEOF _OUTCOMES [ rng ( TYPEOF _OUTCOMES . length ) ] + '")' ;
2017-03-31 21:47:11 +00:00
case 3 :
2017-04-07 10:47:30 +00:00
return '(typeof ' + createVarName ( MANDATORY , DONT _STORE ) + ' != "' + TYPEOF _OUTCOMES [ rng ( TYPEOF _OUTCOMES . length ) ] + '")' ;
2017-03-31 21:47:11 +00:00
case 4 :
2017-04-07 10:47:30 +00:00
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
}
2017-04-07 10:47:30 +00:00
function createUnarySafePrefix ( ) {
return UNARY _SAFE [ rng ( UNARY _SAFE . length ) ] ;
}
function createUnaryPrefix ( ) {
return UNARY _PREFIX [ rng ( UNARY _PREFIX . length ) ] ;
}
function createUnaryPostfix ( ) {
return UNARY _POSTFIX [ rng ( UNARY _POSTFIX . length ) ] ;
}
function getVarName ( ) {
// try to get a generated name reachable from current scope. default to just `a`
return VAR _NAMES [ INITIAL _NAMES _LEN + rng ( VAR _NAMES . length - INITIAL _NAMES _LEN ) ] || 'a' ;
Improve fuzzer. :) (#1665)
@qfox Put value constants in a global constant 74c0fb9
@qfox And the other string based values as well a5033c5
@qfox Be more strict about parameters, allow max to be optional 9c7ce70
@qfox Support a `V` (capital) flag to only log out at intervals 2d822c7
@qfox Fewer magic variables a6a9a7c
@qfox Fix decrement such that a function is created when n=1 7e4b017
@qfox Add more values 64e596e
@qfox Make `b` appear more often d33191a
@qfox Add functions that contain (only..) functions 29a86e3
@qfox Allow the block statement to contain multiple statements 7570484
@qfox Make the interval count a constant d587ad8
@qfox Enable mangling, disable post-processing … 4dc8d35
@qfox Add more simple value that may trigger syntactic errors 8496d58
@qfox Add `else` to some `if` statements a4aed65
@qfox Move iife to expr generator, fix missing recursion arg e453159
@qfox Improve output on error where it wasnt printing the last code properly 4565a1a
@qfox Add switch statement to generator ceafa76
@qfox Add var statement, support optional comma for expr generator b83921b
@qfox Expression generator should use a simple value instead of `0` as recu… … 9d1a5c7
@qfox const -> var to keep things es5... 0143099
@qfox Add more simple values that may trigger edge cases 5e124f1
@qfox Add central name generator, take special care for global functions aeb7682
@qfox Add some `return` and function declaration cases to statement generator 6c9c3cc
@qfox Exclude switches from generator for now 91124b2
Put value constants in a global constant
And the other string based values as well
Be more strict about parameters, allow max to be optional
Support a `V` (capital) flag to only log out at intervals
Fewer magic variables
Fix decrement such that a function is created when n=1
Add more values
Make `b` appear more often
Add functions that contain (only..) functions
Allow the block statement to contain multiple statements
Make the interval count a constant
Enable mangling, disable post-processing
Mangling is kind of the whole point...
Similarly, to beautify the minified code afterwards may supress bugs so it's probably best not to beautify the code prematurely. And there's no point anyways since you won't see it most of the time and only care about the main input anyways.
Add more simple value that may trigger syntactic errors
Add `else` to some `if` statements
Move iife to expr generator, fix missing recursion arg
Improve output on error where it wasnt printing the last code properly
Add switch statement to generator
Add var statement, support optional comma for expr generator
Expression generator should use a simple value instead of `0` as recursion default
const -> var to keep things es5...
Add more simple values that may trigger edge cases
Add central name generator, take special care for global functions
Add some `return` and function declaration cases to statement generator
Exclude switches from generator for now
Enable switch generation because #1667 was merged
Add typeof generator
Add some elision tests
Add a new edge case that returns an object explicitly
Add all binary ops to try and cover more paths
Forgot four binops and added `Math` to var name pool
Harden the incremental pre/postfix tests
Improve switch generator, allow `default` to appear at any clause index
Add try/catch/finally generation
Prevent function statements being generated
Add edge case with decremental op and a group
Disable switch generation until #1679 and #1680 are solved
Only allow `default` clause as last clause for now
Tentatively enable `throw`, `break` and `continue` statements when in valid contexts
2017-03-26 04:04:50 +00:00
}
2017-03-31 21:47:11 +00:00
function createVarName ( maybe , dontStore ) {
2017-04-07 10:47:30 +00:00
if ( ! maybe || rng ( 2 ) ) {
var name = VAR _NAMES [ rng ( VAR _NAMES . length ) ] ;
var suffix = rng ( 3 ) ;
if ( suffix ) {
name += '_' + suffix ;
if ( ! dontStore ) VAR _NAMES . push ( name ) ;
}
2017-03-31 09:23:50 +00:00
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
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 ,
2017-04-15 15:50:50 +00:00
"ie8" : false ,
2017-04-01 18:10:50 +00:00
"keep_fnames" : false ,
"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 ( ) ;
2017-04-21 06:11:15 +00:00
if ( ! ok && typeof uglify _code == "string" ) {
2017-04-01 18:10:50 +00:00
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-15 15:50:50 +00:00
var minify _options = require ( "./ufuzz.json" ) . map ( JSON . stringify ) ;
2017-04-01 18:10:50 +00:00
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 ) ;
2017-04-08 17:36:38 +00:00
else if ( verbose _error && typeof original _result != "string" ) {
console . log ( "//=============================================================" ) ;
console . log ( "// original code" ) ;
try _beautify ( original _code , original _result ) ;
console . log ( ) ;
console . log ( ) ;
console . log ( "original result:" ) ;
console . log ( original _result ) ;
console . log ( ) ;
}
if ( ! ok && isFinite ( num _iterations ) ) {
console . log ( ) ;
process . exit ( 1 ) ;
}
2017-04-01 18:10:50 +00:00
} ) ;
2017-03-24 17:46:12 +00:00
}
2017-04-08 17:36:38 +00:00
console . log ( ) ;