diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-03-12 20:03:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 04:03:47 +0800 |
commit | 03e968be62ac6484a24edd24453e118b56e5af15 (patch) | |
tree | 5e5a85f9c917d2812844d265995f9dbdac188f64 /test | |
parent | 421bb7083a9300b09e1da191a1e574b2be3a339e (diff) | |
download | tracifyjs-03e968be62ac6484a24edd24453e118b56e5af15.tar.gz tracifyjs-03e968be62ac6484a24edd24453e118b56e5af15.zip |
improve suspicious option detection (#3749)
Diffstat (limited to 'test')
-rw-r--r-- | test/ufuzz/index.js | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index e462d9da..f1fce6a1 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -1012,7 +1012,7 @@ function log_suspects(minify_options, component) { var defs = default_options[component]; var suspects = Object.keys(defs).filter(function(name) { var flip = name == "keep_fargs"; - if (flip ? name in options : (name in options ? options : defs)[name]) { + if (flip === !(name in options ? options : defs)[name]) { var m = JSON.parse(JSON.stringify(minify_options)); var o = JSON.parse(JSON.stringify(options)); o[name] = flip; @@ -1036,20 +1036,29 @@ function log_suspects(minify_options, component) { } } -function log_rename(options) { - var m = JSON.parse(options); - m.rename = false; - var result = UglifyJS.minify(original_code, m); - if (result.error) { - errorln("Error testing options.rename"); - errorln(result.error); - } else { - var r = sandbox.run_code(result.code, sandbox.has_toplevel(m)); - if (sandbox.same_stdout(original_result, r)) { - errorln("Suspicious options:"); - errorln(" rename"); - errorln(); +function log_suspects_global(options) { + var o = {}; + UglifyJS.minify("", o); + var suspects = Object.keys(o).filter(function(component) { + return typeof o[component] != "object"; + }).filter(function(component) { + var m = JSON.parse(options); + m[component] = false; + var result = UglifyJS.minify(original_code, m); + if (result.error) { + errorln("Error testing options." + component); + errorln(result.error); + } else { + var r = sandbox.run_code(result.code, sandbox.has_toplevel(m)); + return sandbox.same_stdout(original_result, r); } + }); + if (suspects.length > 0) { + errorln("Suspicious options:"); + suspects.forEach(function(name) { + errorln(" " + name); + }); + errorln(); } } @@ -1099,7 +1108,7 @@ function log(options) { errorln(); if (!ok && typeof uglify_code == "string") { Object.keys(default_options).forEach(log_suspects.bind(null, JSON.parse(options))); - log_rename(options); + log_suspects_global(options); errorln("!!!!!! Failed... round " + round); } } |