[Pkg-javascript-commits] [uglifyjs] 444/491: fix & improve `test/ufuzz.js` (#2815)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:02 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit ac9a168fba726d9ab437478c81626f098997d116
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Jan 19 14:07:20 2018 +0800

    fix & improve `test/ufuzz.js` (#2815)
    
    - use correct `options` when testing `rename`
    - mask arbitrarily assigned function IDs to reduce rate of false positives
---
 test/sandbox.js | 24 +++++++++++++++---------
 test/ufuzz.js   |  2 +-
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/test/sandbox.js b/test/sandbox.js
index 2ce9f6e..c660353 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -17,24 +17,30 @@ function safe_log(arg, level) {
     return arg;
 }
 
+function strip_func_ids(text) {
+    return text.toString().replace(/F[0-9]{6}N/g, "<F<>N>");
+}
+
 var FUNC_TOSTRING = [
+    "[ Array, Boolean, Error, Function, Number, Object, RegExp, String].forEach(function(f) {",
+    "    f.toString = Function.prototype.toString;",
+    "    f.valueOf = Function.prototype.valueOf;",
+    "});",
     "Function.prototype.toString = Function.prototype.valueOf = function() {",
     "    var id = 100000;",
     "    return function() {",
-    '        if (this === Array) return "[Function: Array]";',
-    '        if (this === Object) return "[Function: Object]";',
-    "        var i = this.name;",
-    '        if (typeof i != "number") {',
-    "            i = ++id;",
+    "        var n = this.name;",
+    '        if (!/^F[0-9]{6}N$/.test(n)) {',
+    '            n = "F" + ++id + "N";',
 ].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
     '            Object.defineProperty(this, "name", {',
     "                get: function() {",
-    "                    return i;",
+    "                    return n;",
     "                }",
     "            });",
 ] : [], [
     "        }",
-    '        return "[Function: " + i + "]";',
+    '        return "[Function: " + n + "]";',
     "    }",
     "}();",
     'Object.defineProperty(Function.prototype, "valueOf", { enumerable: false });',
@@ -77,7 +83,7 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
         expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
         actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
     }
-    return expected == actual;
+    return strip_func_ids(expected) == strip_func_ids(actual);
 } : function(expected, actual) {
-    return typeof expected == typeof actual && expected.toString() == actual.toString();
+    return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
 };
diff --git a/test/ufuzz.js b/test/ufuzz.js
index 07b67a8..bbf4fa0 100644
--- a/test/ufuzz.js
+++ b/test/ufuzz.js
@@ -1025,7 +1025,7 @@ function log_suspects(minify_options, component) {
 
 function log_rename(options) {
     if (!options.rename) return;
-    var m = JSON.parse(JSON.stringify(minify_options));
+    var m = JSON.parse(JSON.stringify(options));
     m.rename = false;
     var result = UglifyJS.minify(original_code, m);
     if (result.error) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list