aboutsummaryrefslogtreecommitdiff
path: root/test/ufuzz/index.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-19 01:32:39 +0100
committerGitHub <noreply@github.com>2020-10-19 08:32:39 +0800
commit96bf7fceabf1670ca07c08a04a3130e742775c8f (patch)
tree71a28df4db6ce0ec1a5e0423dad6b74ab00fa065 /test/ufuzz/index.js
parent6c7226c10ef1328c726ce7c5d364efed8ed0d374 (diff)
downloadtracifyjs-96bf7fceabf1670ca07c08a04a3130e742775c8f.tar.gz
tracifyjs-96bf7fceabf1670ca07c08a04a3130e742775c8f.zip
support `let` (#4227)
Diffstat (limited to 'test/ufuzz/index.js')
-rw-r--r--test/ufuzz/index.js43
1 files changed, 27 insertions, 16 deletions
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 09cad3b2..5f6a3de8 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -381,32 +381,43 @@ function createBlockVariables(recurmax, stmtDepth, canThrow, fn) {
var block_len = block_vars.length;
var var_len = VAR_NAMES.length;
var consts = [];
+ var lets = [];
unique_vars.push("a", "b", "c", "undefined", "NaN", "Infinity");
while (!rng(block_vars.length > block_len ? 10 : 100)) {
var name = createVarName(MANDATORY, DONT_STORE);
- consts.push(name);
+ if (rng(2)) {
+ consts.push(name);
+ } else {
+ lets.push(name);
+ }
block_vars.push(name);
}
unique_vars.length -= 6;
fn(function() {
- var s = [];
- if (consts.length) {
- var save = VAR_NAMES;
- VAR_NAMES = VAR_NAMES.filter(function(name) {
- return consts.indexOf(name) < 0;
- });
- var len = VAR_NAMES.length;
- s.push("const " + consts.map(function(name) {
- var value = createExpression(recurmax, NO_COMMA, stmtDepth, canThrow);
- VAR_NAMES.push(name);
- return name + " = " + value;
- }).join(", ") + ";");
- VAR_NAMES = save.concat(VAR_NAMES.slice(len));
+ if (rng(2)) {
+ return createDefinitions("const", consts) + "\n" + createDefinitions("let", lets) + "\n";
+ } else {
+ return createDefinitions("let", lets) + "\n" + createDefinitions("const", consts) + "\n";
}
- return s.join("\n");
});
block_vars.length = block_len;
- if (consts.length) VAR_NAMES.splice(var_len, consts.length);
+ if (consts.length || lets.length) VAR_NAMES.splice(var_len, consts.length + lets.length);
+
+ function createDefinitions(type, names) {
+ if (!names.length) return "";
+ var save = VAR_NAMES;
+ VAR_NAMES = VAR_NAMES.filter(function(name) {
+ return names.indexOf(name) < 0;
+ });
+ var len = VAR_NAMES.length;
+ var s = type + " " + names.map(function(name) {
+ var value = createExpression(recurmax, NO_COMMA, stmtDepth, canThrow);
+ VAR_NAMES.push(name);
+ return name + " = " + value;
+ }).join(", ") + ";";
+ VAR_NAMES = save.concat(VAR_NAMES.slice(len));
+ return s;
+ }
}
function createFunction(recurmax, allowDefun, canThrow, stmtDepth) {