From 38f046a1eb6dc7ecfec22258c556304c785604cc Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sun, 23 Apr 2017 15:44:57 +0800 Subject: [PATCH] generate expressions with `this` --- test/ufuzz.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/ufuzz.js b/test/ufuzz.js index b32564f0..c6a94f2d 100644 --- a/test/ufuzz.js +++ b/test/ufuzz.js @@ -630,8 +630,12 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) { ); break; default: + if (rng(4) == 0) s.push('function ' + name + '(){'); + else { + VAR_NAMES.push('this'); + s.push('new function ' + name + '(){'); + } s.push( - (rng(4) == 0 ? '' : 'new ') + 'function ' + name + '(){', strictMode(), createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), '}' @@ -764,22 +768,24 @@ function _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { function _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { // intentionally generate more hardcore ops if (--recurmax < 0) return createValue(); + var assignee, expr; switch (rng(30)) { case 0: return '(c = c + 1, ' + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; case 1: return '(' + createUnarySafePrefix() + '(' + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + '))'; case 2: - var assignee = getVarName(); + assignee = getVarName(); + if (assignee == 'this') assignee = 'a'; return '(' + assignee + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; case 3: - var assignee = getVarName(); - var expr = '(' + assignee + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + assignee = getVarName(); + expr = '(' + assignee + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']' + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; return canThrow && rng(10) == 0 ? expr : '(' + assignee + ' && ' + expr + ')'; case 4: - var assignee = getVarName(); - var expr = '(' + assignee + '.' + getDotKey() + createAssignment() + assignee = getVarName(); + expr = '(' + assignee + '.' + getDotKey() + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; return canThrow && rng(10) == 0 ? expr : '(' + assignee + ' && ' + expr + ')'; default: