esfuzz
Version:
JS fuzzer for generative testing of parsers that implement the SpiderMonkey Reflect.parse API
83 lines (82 loc) • 2.49 kB
JavaScript
// Generated by CoffeeScript 2.0.0-beta7
void function () {
var breakable, BreakStatement, cache$, construct, FUNCTIONS, Identifier, ITERATION_STATEMENTS, labels, maybe, Node, randomElement, Statement;
Node = require('../node');
Statement = require('../classes/Statement');
Identifier = require('./Identifier');
cache$ = require('../combinators');
construct = cache$.construct;
maybe = cache$.maybe;
randomElement = require('../random').randomElement;
FUNCTIONS = [
'FunctionDeclaration',
'FunctionExpression'
];
ITERATION_STATEMENTS = [
'ForStatement',
'ForInStatement',
'DoWhileStatement',
'WhileStatement'
];
breakable = function (ancestors) {
var ancestor;
for (var i$ = 0, length$ = ancestors.length; i$ < length$; ++i$) {
ancestor = ancestors[i$];
if (in$(ancestor.type, FUNCTIONS))
return false;
if (in$(ancestor.type, ITERATION_STATEMENTS) || ancestor.type === 'SwitchStatement')
return true;
}
return false;
};
labels = function (ancestors) {
var accum, ancestor;
accum = [];
for (var i$ = 0, length$ = ancestors.length; i$ < length$; ++i$) {
ancestor = ancestors[i$];
if (in$(ancestor.type, FUNCTIONS))
break;
if (ancestor.type === 'LabeledStatement')
accum.push(ancestor.label);
}
return accum;
};
BreakStatement = function (super$) {
extends$(BreakStatement, super$);
BreakStatement.prototype.type = BreakStatement.name;
BreakStatement.prototype.label = null;
function BreakStatement(depth, ancestors) {
--depth;
if (depth > 0 && breakable(ancestors)) {
this.label = maybe(function () {
return randomElement(labels(ancestors));
})(depth);
} else {
return Statement(0);
}
}
return BreakStatement;
}(Node);
module.exports = construct(BreakStatement);
function in$(member, list) {
for (var i = 0, length = list.length; i < length; ++i)
if (i in list && list[i] === member)
return true;
return false;
}
function isOwn$(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function extends$(child, parent) {
for (var key in parent)
if (isOwn$(parent, key))
child[key] = parent[key];
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
}
}.call(this);