From 8e2dff632e2c6e696b8bd874f61ec1685306da41 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 12 Jul 2021 21:10:59 +0100 Subject: suppress false positives in `ufuzz` (#5078) --- test/ufuzz/index.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'test/ufuzz/index.js') diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index 09375ecb..b10367e8 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -2256,7 +2256,7 @@ function sort_globals(code) { return (typeof global[n] == "function") - (typeof global[m] == "function") || (m < n ? -1 : m > n ? 1 : 0); }; - } + "(this));" + code); + } + "(this));\n" + code); if (!Array.isArray(globals)) { errorln(); errorln(); @@ -2294,6 +2294,20 @@ function fuzzy_match(original, uglified) { } } +function patch_proto() { + [ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(type) { + [ "toString", "valueOf" ].forEach(function(prop) { + type.prototype[prop] = function(fn) { + return function() { + try { + return fn.apply(this, arguments); + } catch (e) {} + }; + }(type.prototype[prop]); + }); + }); +} + function is_error_timeout(ex) { return /timed out/.test(ex.message); } @@ -2500,8 +2514,8 @@ for (var round = 1; round <= num_iterations; round++) { if (!ok && errored && uglify_result.name == "ReferenceError" && original_result.name == "ReferenceError") ok = true; // ignore difference due to implicit strict-mode in `class` if (!ok && /\bclass\b/.test(original_code)) { - var original_strict = run_code('"use strict";' + original_code, toplevel); - var uglify_strict = run_code('"use strict";' + uglify_code, toplevel); + var original_strict = run_code('"use strict";\n' + original_code, toplevel); + var uglify_strict = run_code('"use strict";\n' + uglify_code, toplevel); if (typeof original_strict != "string") { ok = typeof uglify_strict != "string"; } else { @@ -2512,6 +2526,12 @@ for (var round = 1; round <= num_iterations; round++) { if (!ok && errored && /\bimport\b/.test(original_code)) { if (is_error_redeclaration(uglify_result) && is_error_redeclaration(original_result)) ok = true; } + // ignore difference due to `__proto__` assignment + if (!ok && /\b__proto__\b/.test(original_code)) { + var original_proto = run_code("(" + patch_proto + ")();\n" + original_code, toplevel); + var uglify_proto = run_code("(" + patch_proto + ")();\n" + uglify_code, toplevel); + ok = sandbox.same_stdout(original_proto, uglify_proto); + } // ignore difference in error message caused by `in` if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true; // ignore difference in error message caused by spread syntax -- cgit v1.2.3