Shift Fuzzer
generates random valid Shift ASTs
Introduction
The Shift Fuzzer generates a random, valid Shift AST, and may generate any JavaScript program up to a given complexity (AST depth) with a non-zero probability. Additional APIs exist for generating only certain node types and for integrating a custom pseudo-random number generator for deterministic and reproducible fuzzing.
Demo
This demo uses the fuzzer to generate a random Shift AST and renders it using the Shift Code Generator. Press the green button in the upper right corner of the demo to begin cycling through random programs. If the fuzzer finds a program that cannot be parsed, you will be prompted to open an issue on GitHub because at least one of the fuzzer, the code generator, or the parser will have a bug.
Installation
npm install shift-fuzzer
Usage
import fuzzProgram, {FuzzerState, fuzzFunctionDeclaration} from "shift-fuzzer";
import render from "shift-codegen";
// generate random program
let randomProgramAst = fuzzProgram();
let randomProgram = render(randomProgramAst);
console.log(randomProgram);
// generate random FunctionDeclaration
let randomFunctionAst = fuzzFunctionDeclaration(new FuzzerState({maxDepth: 7}));
let randomFunction = render(randomFunctionAst);
console.log(randomFunction);
// generate random program from a seed
const RNG_SEED = 0xBADBE1BE1;
let prng =
(function(state){
return function nextDouble() {
// implementation left as an exercise for the reader
};
}(RNG_SEED));
let seededRandomProgramAst = fuzzProgram(new FuzzerState({rng: prng, maxDepth: 7}));
let seededRandomProgram = render(seededRandomProgramAst);
console.log(seededRandomProgram);