@@ -425,7 +425,7 @@ function createTopLevelCode() {
425425 if ( rng ( 2 ) ) {
426426 s . push ( createStatements ( 3 , MAX_GENERATION_RECURSION_DEPTH , CANNOT_THROW , CANNOT_BREAK , CANNOT_CONTINUE , CANNOT_RETURN , 0 ) ) ;
427427 } else {
428- s . push ( createFunctions ( rng ( MAX_GENERATED_TOPLEVELS_PER_RUN ) + 1 , MAX_GENERATION_RECURSION_DEPTH , DEFUN_OK , CANNOT_THROW , 0 ) ) ;
428+ s . push ( createFunctions ( MAX_GENERATED_TOPLEVELS_PER_RUN , MAX_GENERATION_RECURSION_DEPTH , DEFUN_OK , CANNOT_THROW , 0 ) ) ;
429429 }
430430 } ) ;
431431 // preceding `null` makes for a cleaner output (empty string still shows up etc)
@@ -440,6 +440,7 @@ function createFunctions(n, recurmax, allowDefun, canThrow, stmtDepth) {
440440 var s = "" ;
441441 while ( n -- > 0 ) {
442442 s += createFunction ( recurmax , allowDefun , canThrow , stmtDepth ) + "\n" ;
443+ if ( rng ( 2 ) ) break ;
443444 }
444445 return s ;
445446}
@@ -455,7 +456,7 @@ function createParams(was_async, was_generator, noDuplicate) {
455456 if ( ! generator ) generator = was_generator ;
456457 var len = unique_vars . length ;
457458 var params = [ ] ;
458- for ( var n = rng ( 4 ) ; -- n >= 0 ; ) {
459+ for ( var n = 3 ; -- n >= 0 && rng ( 2 ) ; ) {
459460 var name = createVarName ( MANDATORY ) ;
460461 if ( noDuplicate || in_class ) unique_vars . push ( name ) ;
461462 params . push ( name ) ;
@@ -470,7 +471,7 @@ function createArgs(recurmax, stmtDepth, canThrow, noTemplate) {
470471 recurmax -- ;
471472 if ( SUPPORT . template && ! noTemplate && rng ( 20 ) == 0 ) return createTemplateLiteral ( recurmax , stmtDepth , canThrow ) ;
472473 var args = [ ] ;
473- for ( var n = rng ( 4 ) ; -- n >= 0 ; ) switch ( SUPPORT . spread ? rng ( 50 ) : 3 ) {
474+ for ( var n = 3 ; -- n >= 0 && rng ( 2 ) ; ) switch ( SUPPORT . spread ? rng ( 50 ) : 3 ) {
474475 case 0 :
475476 case 1 :
476477 var name = getVarName ( ) ;
@@ -850,7 +851,7 @@ function createFunction(recurmax, allowDefun, canThrow, stmtDepth) {
850851 s . push ( defns ( ) ) ;
851852 if ( rng ( 5 ) === 0 ) {
852853 // functions with functions. lower the recursion to prevent a mess.
853- s . push ( createFunctions ( rng ( 5 ) + 1 , Math . ceil ( recurmax * 0.7 ) , DEFUN_OK , canThrow , stmtDepth ) ) ;
854+ s . push ( createFunctions ( 5 , Math . ceil ( recurmax * 0.7 ) , DEFUN_OK , canThrow , stmtDepth ) ) ;
854855 } else {
855856 // functions with statements
856857 s . push ( _createStatements ( 3 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ) ;
@@ -884,6 +885,7 @@ function _createStatements(n, recurmax, canThrow, canBreak, canContinue, cannotR
884885 var s = "" ;
885886 while ( -- n > 0 ) {
886887 s += createStatement ( recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) + "\n" ;
888+ if ( rng ( 2 ) ) break ;
887889 }
888890 return s ;
889891}
@@ -963,7 +965,7 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
963965 switch ( target ) {
964966 case STMT_BLOCK :
965967 var label = createLabel ( canBreak ) ;
966- return label . target + "{" + createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , label . break , canContinue , cannotReturn , stmtDepth ) + "}" ;
968+ return label . target + "{" + createStatements ( 5 , recurmax , canThrow , label . break , canContinue , cannotReturn , stmtDepth ) + "}" ;
967969 case STMT_IF_ELSE :
968970 return "if (" + createExpression ( recurmax , COMMA_OK , stmtDepth , canThrow ) + ")" + createStatement ( recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) + ( rng ( 2 ) ? " else " + createStatement ( recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) : "" ) ;
969971 case STMT_DO_WHILE :
@@ -1076,7 +1078,7 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
10761078 s += " * as " + createImportAlias ( ) ;
10771079 } else {
10781080 var names = [ ] ;
1079- for ( var i = rng ( 4 ) ; -- i >= 0 ; ) {
1081+ for ( var i = 3 ; -- i >= 0 && rng ( 2 ) ; ) {
10801082 var name = createImportAlias ( ) ;
10811083 names . push ( rng ( 2 ) ? getDotKey ( ) + " as " + name : name ) ;
10821084 }
@@ -1184,7 +1186,7 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
11841186 }
11851187 if ( n !== 0 ) s += [
11861188 " finally { " ,
1187- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
1189+ createStatements ( 5 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
11881190 " }" ,
11891191 ] . join ( "" ) ;
11901192 return s ;
@@ -1204,15 +1206,15 @@ function createSwitchParts(recurmax, n, canThrow, canBreak, canContinue, cannotR
12041206 if ( hadDefault || rng ( 5 ) > 0 ) {
12051207 s . push (
12061208 "case " + createExpression ( recurmax , NO_COMMA , stmtDepth , canThrow ) + ":" ,
1207- _createStatements ( rng ( 3 ) + 1 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
1209+ _createStatements ( 3 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
12081210 rng ( 10 ) > 0 ? " break;" : "/* fall-through */" ,
12091211 ""
12101212 ) ;
12111213 } else {
12121214 hadDefault = true ;
12131215 s . push (
12141216 "default:" ,
1215- _createStatements ( rng ( 3 ) + 1 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
1217+ _createStatements ( 3 , recurmax , canThrow , canBreak , canContinue , cannotReturn , stmtDepth ) ,
12161218 ""
12171219 ) ;
12181220 }
@@ -1343,7 +1345,7 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
13431345 "(" + params + "{" ,
13441346 strictMode ( ) ,
13451347 defns ( ) ,
1346- _createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth )
1348+ _createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth )
13471349 ) ;
13481350 suffix = "})" ;
13491351 } else {
@@ -1375,7 +1377,7 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
13751377 s . push (
13761378 "(" + makeFunction ( name ) + "(){" ,
13771379 strictMode ( ) ,
1378- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
1380+ createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
13791381 rng ( 2 ) ? "})" : "})()" + invokeGenerator ( save_generator )
13801382 ) ;
13811383 }
@@ -1384,23 +1386,23 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
13841386 s . push (
13851387 "+" + makeFunction ( name ) + "(){" ,
13861388 strictMode ( ) ,
1387- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
1389+ createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
13881390 "}()" + invokeGenerator ( save_generator )
13891391 ) ;
13901392 break ;
13911393 case 2 :
13921394 s . push (
13931395 "!" + makeFunction ( name ) + "(){" ,
13941396 strictMode ( ) ,
1395- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
1397+ createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
13961398 "}()" + invokeGenerator ( save_generator )
13971399 ) ;
13981400 break ;
13991401 case 3 :
14001402 s . push (
14011403 "void " + makeFunction ( name ) + "(){" ,
14021404 strictMode ( ) ,
1403- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
1405+ createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ,
14041406 "}()" + invokeGenerator ( save_generator )
14051407 ) ;
14061408 break ;
@@ -1416,10 +1418,10 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
14161418 var add_new_target = SUPPORT . new_target && VALUES . indexOf ( "new.target" ) < 0 ;
14171419 if ( add_new_target ) VALUES . push ( "new.target" ) ;
14181420 s . push ( defns ( ) ) ;
1419- if ( instantiate ) for ( var i = rng ( 4 ) ; -- i >= 0 ; ) {
1421+ if ( instantiate ) for ( var i = 3 ; -- i >= 0 && rng ( 2 ) ; ) {
14201422 s . push ( ( in_class ? "if (this) " : "" ) + createThisAssignment ( recurmax , stmtDepth , canThrow ) ) ;
14211423 }
1422- s . push ( _createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ) ;
1424+ s . push ( _createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) ) ;
14231425 if ( add_new_target ) VALUES . splice ( VALUES . indexOf ( "new.target" ) , 1 ) ;
14241426 } ) ;
14251427 generator = save_generator ;
@@ -1565,7 +1567,7 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
15651567function createArrayLiteral ( recurmax , stmtDepth , canThrow ) {
15661568 recurmax -- ;
15671569 var arr = [ ] ;
1568- for ( var i = rng ( 6 ) ; -- i >= 0 ; ) switch ( SUPPORT . spread ? rng ( 50 ) : 3 + rng ( 47 ) ) {
1570+ for ( var i = 5 ; -- i >= 0 && rng ( 2 ) ; ) switch ( SUPPORT . spread ? rng ( 50 ) : 3 + rng ( 47 ) ) {
15691571 case 0 :
15701572 case 1 :
15711573 var name = getVarName ( ) ;
@@ -1594,7 +1596,7 @@ function createTemplateLiteral(recurmax, stmtDepth, canThrow) {
15941596 recurmax -- ;
15951597 var s = [ ] ;
15961598 addText ( ) ;
1597- for ( var i = rng ( 6 ) ; -- i >= 0 ; ) {
1599+ for ( var i = 5 ; -- i >= 0 && rng ( 2 ) ; ) {
15981600 s . push ( "${" , createExpression ( recurmax , COMMA_OK , stmtDepth , canThrow ) , "}" ) ;
15991601 addText ( ) ;
16001602 }
@@ -1749,7 +1751,7 @@ function createObjectFunction(recurmax, stmtDepth, canThrow, internal, isClazz)
17491751 s . push ( _createStatements ( 2 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CANNOT_RETURN , stmtDepth ) ) ;
17501752 if ( internal == "super" ) s . push ( "super" + createArgs ( recurmax , stmtDepth , canThrow , NO_TEMPLATE ) + ";" ) ;
17511753 allow_this = save_allow ;
1752- if ( / ^ ( c o n s t r u c t o r | s u p e r ) $ / . test ( internal ) || rng ( 10 ) == 0 ) for ( var i = rng ( 4 ) ; -- i >= 0 ; ) {
1754+ if ( / ^ ( c o n s t r u c t o r | s u p e r ) $ / . test ( internal ) || rng ( 10 ) == 0 ) for ( var i = 3 ; -- i >= 0 && rng ( 2 ) ; ) {
17531755 s . push ( rng ( 2 ) ? createSuperAssignment ( recurmax , stmtDepth , canThrow ) : createThisAssignment ( recurmax , stmtDepth , canThrow ) ) ;
17541756 }
17551757 s . push ( _createStatements ( 2 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CAN_RETURN , stmtDepth ) , "}" ) ;
@@ -1768,7 +1770,7 @@ function createObjectLiteral(recurmax, stmtDepth, canThrow) {
17681770 var obj = [ "({" ] ;
17691771 var offset = SUPPORT . spread_object ? 0 : SUPPORT . computed_key ? 2 : 4 ;
17701772 var has_proto = false ;
1771- for ( var i = rng ( 6 ) ; -- i >= 0 ; ) switch ( offset + rng ( 50 - offset ) ) {
1773+ for ( var i = 5 ; -- i >= 0 && rng ( 2 ) ; ) switch ( offset + rng ( 50 - offset ) ) {
17721774 case 0 :
17731775 obj . push ( "..." + getVarName ( ) + "," ) ;
17741776 break ;
@@ -1815,7 +1817,7 @@ function createClassLiteral(recurmax, stmtDepth, canThrow, name) {
18151817 }
18161818 s += " {\n" ;
18171819 var declared = [ ] ;
1818- for ( var i = rng ( 6 ) ; -- i >= 0 ; ) {
1820+ for ( var i = 5 ; -- i >= 0 && rng ( 2 ) ; ) {
18191821 var fixed = false ;
18201822 if ( rng ( 5 ) == 0 ) {
18211823 fixed = true ;
@@ -1849,7 +1851,7 @@ function createClassLiteral(recurmax, stmtDepth, canThrow, name) {
18491851 generator = false ;
18501852 s += [
18511853 "{ " ,
1852- createStatements ( rng ( 5 ) + 1 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CANNOT_RETURN , stmtDepth ) ,
1854+ createStatements ( 5 , recurmax , canThrow , CANNOT_BREAK , CANNOT_CONTINUE , CANNOT_RETURN , stmtDepth ) ,
18531855 " }\n" ,
18541856 ] . join ( "" ) ;
18551857 generator = save_generator ;
0 commit comments