aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-22 14:43:33 +0000
committerGitHub <noreply@github.com>2021-03-22 22:43:33 +0800
commit51bdb7281bb555f0cc56ca15560a8ab514b0a632 (patch)
treece38e29273cbb503083ae096ae987f44270638e9
parent9c01511f840aa8675f6dab4358b96d821283597a (diff)
downloadtracifyjs-51bdb7281bb555f0cc56ca15560a8ab514b0a632.tar.gz
tracifyjs-51bdb7281bb555f0cc56ca15560a8ab514b0a632.zip
improve global context enumeration under `sandbox` (#4812)
fixes #4811
-rw-r--r--test/compress/sandbox.js29
-rw-r--r--test/mocha/reduce.js18
-rw-r--r--test/sandbox.js14
3 files changed, 57 insertions, 4 deletions
diff --git a/test/compress/sandbox.js b/test/compress/sandbox.js
index 9cf76725..f932dcf5 100644
--- a/test/compress/sandbox.js
+++ b/test/compress/sandbox.js
@@ -172,3 +172,32 @@ issue_4054: {
}
expect_stdout: "{ p: [Setter] }"
}
+
+issue_4811_1: {
+ input: {
+ for (var PASS in this);
+ console.log(PASS, this);
+ }
+ expect: {
+ for (var PASS in this);
+ console.log(PASS, this);
+ }
+ expect_stdout: "PASS [object global]"
+}
+
+issue_4811_2: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ (async function() {});
+ for (var PASS in this);
+ console.log(PASS, this);
+ }
+ expect: {
+ for (var PASS in this);
+ console.log(PASS, this);
+ }
+ expect_stdout: "PASS [object global]"
+ node_version: ">=8"
+}
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index 9e3fc8be..238d11ef 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -361,4 +361,22 @@ describe("test/reduce.js", function() {
if (result.error) throw result.error;
assert.strictEqual(result.code, read("test/input/reduce/destructured_catch.reduced.js"));
});
+ it("Should not enumerate `toString` over global context", function() {
+ if (semver.satisfies(process.version, "<8")) return;
+ var code = [
+ "(async function() {});",
+ "for (var k in this);",
+ "console.log(k);",
+ ].join("\n");
+ var result = reduce_test(code, {
+ mangle: false,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "// Can't reproduce test failure",
+ "// minify options: {",
+ '// "mangle": false',
+ "// }",
+ ].join("\n"));
+ });
});
diff --git a/test/sandbox.js b/test/sandbox.js
index 18934f45..9a49fd94 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -170,6 +170,12 @@ function setup(global, builtins, setup_log, setup_tty) {
},
global: { get: self },
self: { get: self },
+ // for Node.js v8+
+ toString: {
+ get: function() {
+ return global_toString;
+ },
+ },
window: { get: self },
};
[
@@ -199,15 +205,15 @@ function setup(global, builtins, setup_log, setup_tty) {
} catch (e) {}
});
Object.defineProperties(global, props);
- // for Node.js v8+
- global.toString = function() {
- return "[object global]";
- };
function self() {
return this;
}
+ function global_toString() {
+ return "[object global]";
+ }
+
function safe_log(arg, cache) {
if (arg) switch (typeof arg) {
case "function":