UNPKG

esfuzz

Version:

JS fuzzer for generative testing of parsers that implement the SpiderMonkey Reflect.parse API

122 lines (121 loc) 4.05 kB
// Generated by CoffeeScript 2.0.0-beta7 void function () { var $0, cache$, counter, fuzz, fuzzAndRoundtrip, generate, knownOpts, nonstandardParsers, nopt, optAliases, options, parsers, path, recur; path = require('path'); nopt = require('nopt'); cache$ = require('./index'); generate = cache$.generate; fuzz = cache$.fuzz; fuzzAndRoundtrip = cache$.fuzzAndRoundtrip; knownOpts = { acorn: Boolean, es6: Boolean, esprima: Boolean, help: Boolean, iterations: Number, 'max-depth': Number, reflect: Boolean, reflectjs: Boolean, zeparser: Boolean, uglifyjs: Boolean, version: Boolean }; optAliases = { n: '--iterations', d: '--max-depth' }; options = nopt(knownOpts, optAliases, process.argv, 2); if (null != options.esprima) options.esprima; else options.esprima = true; if (null != options.acorn) options.acorn; else options.acorn = true; if (null != options.reflect) options.reflect; else options.reflect = 'undefined' !== typeof Reflect && null != Reflect && 'function' === typeof Reflect.parse; if (null != options.iterations) options.iterations; else options.iterations = 1 / 0; if (null != options['max-depth']) options['max-depth']; else options['max-depth'] = 7; options.maxDepth = options['max-depth']; parsers = []; nonstandardParsers = []; if (options.esprima) try { parsers.push(require('esprima')); } catch (e$) { } if (options.acorn) try { parsers.push(require('acorn')); } catch (e$1) { } if (options.reflectjs) try { parsers.push(require('reflect')); } catch (e$2) { } if (options.reflect) try { parsers.push(Reflect); } catch (e$3) { } if (options.uglifyjs) try { nonstandardParsers.push(require('uglify-js')); } catch (e$4) { } if (options.zeparser) try { nonstandardParsers.push(require('zeparser').ZeParser); } catch (e$5) { } if (options.help) { $0 = process.argv[0] === 'node' ? process.argv[1] : process.argv[0]; $0 = path.basename($0); console.log('\n Usage: ' + $0 + ' OPT*\n\n -n, --iterations NUM use at most NUM programs; default: unlimited\n -d, --max-depth NUM create ASTs with a height no greater than NUM; default: 8\n --acorn enable marijnh/acorn parser; default: on\n --es6 allow ECMAScript 6 features in generated programs\n --esprima enable ariya/esprima parser; default: on\n --help display this help message and exit\n --reflect enable Reflect.parse parser; default: on if it exists\n --reflectjs enable zaach/reflect.js parser\n --uglifyjs enable limited support for mishoo/UglifyJS2\n --version display the version number and exit\n --zeparser enable limited support for qfox/ZeParser\n'); process.exit(0); } if (options.version) { console.log(require('../package.json').version); process.exit(0); } process.on('SIGINT', function () { process.stdout.write(' \n'); return process.exit(0); }); counter = 0; (recur = function () { var ast, cache$1, err, js, message, name, program, stack; if (counter < options.iterations) { process.stdout.write('\b\b\b\b\b\b\b\b\b\b\b\b\b\b' + ++counter); try { program = generate({ maxDepth: options.maxDepth }); fuzzAndRoundtrip(program, parsers); if (nonstandardParsers.length) fuzz(program, nonstandardParsers); } catch (e$6) { err = e$6; cache$1 = err; stack = cache$1.stack; ast = cache$1.ast; js = cache$1.js; name = cache$1.name; message = cache$1.message; console.error('\b\b\b\b\b\b\b\b\b\b\b\b\b' + name + ': ' + message + '\n\n' + stack + '\n\n' + js + '\n\n' + ast); process.exit(1); } setImmediate(recur); } else { process.stdout.write('\n'); } })(); }.call(this);