var start = S.token;
var type = start.type;
var name = as_property_name();
+ if (is("punc", "(")) {
+ var func_start = S.token;
+ var func = function_(AST_Function);
+ func.start = func_start;
+ func.end = prev();
+ a.push(new AST_ObjectKeyVal({
+ start: start,
+ quote: start.quote,
+ key: "" + name,
+ value: func,
+ end: prev(),
+ }));
+ continue;
+ }
if (!is("punc", ":") && type == "name") switch (name) {
case "get":
a.push(new AST_ObjectGetter({
}
expect(":");
a.push(new AST_ObjectKeyVal({
- start : start,
- quote : start.quote,
- key : "" + name,
- value : expression(false),
- end : prev()
+ start: start,
+ quote: start.quote,
+ key: "" + name,
+ value: expression(false),
+ end: prev(),
}));
}
next();
var DEFUN_OK = true;
var DONT_STORE = true;
var NO_CONST = true;
+var NO_DUPLICATE = true;
var VAR_NAMES = [
"a",
return s;
}
-function createParams() {
+function createParams(noDuplicate) {
+ var len = unique_vars.length;
var params = [];
for (var n = rng(4); --n >= 0;) {
- params.push(createVarName(MANDATORY));
+ var name = createVarName(MANDATORY);
+ if (noDuplicate) unique_vars.push(name);
+ params.push(name);
}
+ unique_vars.length = len;
return params.join(", ");
}
return key;
}
-function createAccessor(recurmax, stmtDepth, canThrow) {
+function createObjectFunction(type, recurmax, stmtDepth, canThrow) {
var namesLenBefore = VAR_NAMES.length;
var s;
createBlockVariables(recurmax, stmtDepth, canThrow, function(defns) {
- var prop1 = getDotKey();
- if (rng(2) == 0) {
+ switch (type) {
+ case "get":
s = [
- "get " + prop1 + "(){",
+ "get " + getDotKey() + "(){",
strictMode(),
defns(),
_createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
createStatement(recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth, STMT_RETURN_ETC),
- "},"
+ "},",
];
- } else {
+ break;
+ case "set":
+ var prop1 = getDotKey();
var prop2;
do {
prop2 = getDotKey();
defns(),
_createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
"this." + prop2 + createAssignment() + _createBinaryExpr(recurmax, COMMA_OK, stmtDepth, canThrow) + ";",
- "},"
+ "},",
];
+ break;
+ default:
+ s = [
+ type + "(" + createParams(NO_DUPLICATE) + "){",
+ strictMode(),
+ defns(),
+ _createStatements(3, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth),
+ "},",
+ ]
+ break;
}
});
VAR_NAMES.length = namesLenBefore;
function createObjectLiteral(recurmax, stmtDepth, canThrow) {
recurmax--;
var obj = ["({"];
- for (var i = rng(6); --i >= 0;) switch (rng(20)) {
+ for (var i = rng(6); --i >= 0;) switch (rng(50)) {
case 0:
- obj.push(createAccessor(recurmax, stmtDepth, canThrow));
+ obj.push(createObjectFunction("get", recurmax, stmtDepth, canThrow));
break;
case 1:
+ obj.push(createObjectFunction("set", recurmax, stmtDepth, canThrow));
+ break;
+ case 2:
+ obj.push(createObjectFunction(KEYS[rng(KEYS.length)], recurmax, stmtDepth, canThrow));
+ break;
+ case 3:
obj.push(getVarName() + ",");
break;
default: