aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-23 03:15:41 +0000
committerGitHub <noreply@github.com>2021-03-23 11:15:41 +0800
commit44394e61c95e29bcae68087d5ada2036be9b073d (patch)
tree8fbc33fe20d541919030f52f61cb5e1477f9b73e
parentf9055df44d86c8537afc34f00bd255792f80422f (diff)
downloadtracifyjs-44394e61c95e29bcae68087d5ada2036be9b073d.tar.gz
tracifyjs-44394e61c95e29bcae68087d5ada2036be9b073d.zip
workaround `toString()` quirks on global context (#4814)
-rw-r--r--test/compress/sandbox.js12
-rw-r--r--test/mocha/reduce.js2
-rw-r--r--test/sandbox.js18
-rw-r--r--test/ufuzz/index.js3
4 files changed, 16 insertions, 19 deletions
diff --git a/test/compress/sandbox.js b/test/compress/sandbox.js
index f932dcf5..9111e319 100644
--- a/test/compress/sandbox.js
+++ b/test/compress/sandbox.js
@@ -176,13 +176,13 @@ issue_4054: {
issue_4811_1: {
input: {
for (var PASS in this);
- console.log(PASS, this);
+ console.log(PASS, this, {} < this);
}
expect: {
for (var PASS in this);
- console.log(PASS, this);
+ console.log(PASS, this, {} < this);
}
- expect_stdout: "PASS [object global]"
+ expect_stdout: "PASS [object global] true"
}
issue_4811_2: {
@@ -192,12 +192,12 @@ issue_4811_2: {
input: {
(async function() {});
for (var PASS in this);
- console.log(PASS, this);
+ console.log(PASS, this, {} < this);
}
expect: {
for (var PASS in this);
- console.log(PASS, this);
+ console.log(PASS, this, {} < this);
}
- expect_stdout: "PASS [object global]"
+ expect_stdout: "PASS [object global] true"
node_version: ">=8"
}
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index 238d11ef..64fea56d 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -366,7 +366,7 @@ describe("test/reduce.js", function() {
var code = [
"(async function() {});",
"for (var k in this);",
- "console.log(k);",
+ "console.log(k, 42 + this);",
].join("\n");
var result = reduce_test(code, {
mangle: false,
diff --git a/test/sandbox.js b/test/sandbox.js
index 9a49fd94..630a605c 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -170,12 +170,6 @@ 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 },
};
[
@@ -205,15 +199,19 @@ function setup(global, builtins, setup_log, setup_tty) {
} catch (e) {}
});
Object.defineProperties(global, props);
+ // for Node.js v8+
+ if (global.toString !== Object.prototype.toString) {
+ global.__proto__ = Object.defineProperty(Object.create(global.__proto__), "toString", {
+ value: 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":
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index e2bcdf2c..768009a9 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -2206,8 +2206,7 @@ function log(options) {
function sort_globals(code) {
var globals = run_code("throw Object.keys(this).sort(" + function(global) {
return function(m, n) {
- return (n == "toString") - (m == "toString")
- || (typeof global[n] == "function") - (typeof global[m] == "function")
+ return (typeof global[n] == "function") - (typeof global[m] == "function")
|| (m < n ? -1 : m > n ? 1 : 0);
};
} + "(this));" + code);