workaround `toString()` quirks on global context (#5198)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 27 Nov 2021 15:17:51 +0000 (15:17 +0000)
committerGitHub <noreply@github.com>
Sat, 27 Nov 2021 15:17:51 +0000 (23:17 +0800)
closes #5197

test/compress/sandbox.js
test/sandbox.js

index 9111e31..ac12061 100644 (file)
@@ -201,3 +201,20 @@ issue_4811_2: {
     expect_stdout: "PASS [object global] true"
     node_version: ">=8"
 }
+
+issue_5197: {
+    rename = true
+    input: {
+        function f(async) {
+            async(")=>{}");
+        }
+        console.log("" + this.__proto__);
+    }
+    expect: {
+        function f(a) {
+            a(")=>{}");
+        }
+        console.log("" + this.__proto__);
+    }
+    expect_stdout: "[object global]"
+}
index 7266345..355b9c0 100644 (file)
@@ -202,13 +202,11 @@ function setup(global, builtins, setup_log, setup_tty) {
     });
     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]";
-            },
-        });
-    }
+    global.__proto__ = Object.defineProperty(Object.create(global.__proto__), "toString", {
+        value: function() {
+            return "[object global]";
+        },
+    });
 
     function self() {
         return this;