diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-19 01:15:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-19 01:15:05 +0800 |
commit | 4facd94029f146c7f6e379d4b5a50c18459db768 (patch) | |
tree | 9604f6b1c75198d54020da4ed1c239c06cac767b | |
parent | 4b5993ff15bc99bcb897611974529cbc92543211 (diff) | |
download | tracifyjs-4facd94029f146c7f6e379d4b5a50c18459db768.tar.gz tracifyjs-4facd94029f146c7f6e379d4b5a50c18459db768.zip |
reduce false positives from noop (#2933)
-rw-r--r-- | test/sandbox.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/sandbox.js b/test/sandbox.js index c477a8a2..2c2c21a8 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -27,9 +27,10 @@ var FUNC_TOSTRING = [ "});", "Function.prototype.toString = function() {", " var id = 100000;", + " var toString = Function.prototype.toString;", " return function() {", " var n = this.name;", - ' if (!/^F[0-9]{6}N$/.test(n)) {', + " if (!/^F[0-9]{6}N$/.test(n)) {", ' n = "F" + ++id + "N";', ].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [ ' Object.defineProperty(this, "name", {', @@ -39,12 +40,19 @@ var FUNC_TOSTRING = [ " });", ] : [], [ " }", - ' return "function " + n + "() {' + function() { - var s = "\7"; - for (var i = 10; --i >= 0;) s += s; + " var body = toString.call(this);", + ' body = body.slice(body.indexOf("{") + 1, -1);', + ' if (/^(?:\\s|\\{|\\}|;|[0-9\\.]+|"[^"]*"|var [^=;]+|\\/\\/.*|\\/\\*[\\s\\S]*\\*\\/)*(?:$|return(?:;|\\n))/.test(body)) {', + ' body = "";', + " } else {", + ' body = n + "' + function() { + var s = ";"; + for (var i = 7; --i >= 0;) s += s; return s; - }() + '}";', - " }", + }() + '";', + " }", + ' return "function(){" + body + "}";', + " };", "}();", ]).join("\n"); exports.run_code = function(code) { |