fix `unsafe` `evaluate` of `Object` static methods (#2232)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 14 Jul 2017 11:52:01 +0000 (19:52 +0800)
committerGitHub <noreply@github.com>
Fri, 14 Jul 2017 11:52:01 +0000 (19:52 +0800)
fixes #2231

lib/compress.js
test/compress/evaluate.js

index 3a5694f..0330c68 100644 (file)
@@ -1853,10 +1853,6 @@ merge(Compressor.prototype, {
                 "isFinite",
                 "isNaN",
             ],
-            Object: [
-                "keys",
-                "getOwnPropertyNames",
-            ],
             String: [
                 "fromCharCode",
             ],
@@ -3496,7 +3492,9 @@ merge(Compressor.prototype, {
                                 operator: car.operator,
                                 expression: left
                             });
-                        } else car.write_only = false;
+                        } else {
+                            car.write_only = false;
+                        }
                         if (parent) {
                             parent[field] = car;
                             expressions[i] = expressions[j];
index 38e9cdc..1c73706 100644 (file)
@@ -1157,3 +1157,31 @@ issue_2207_3: {
     }
     expect_stdout: true
 }
+
+issue_2231_1: {
+    options = {
+        evaluate: true,
+        unsafe: true,
+    }
+    input: {
+        console.log(Object.keys(void 0));
+    }
+    expect: {
+        console.log(Object.keys(void 0));
+    }
+    expect_stdout: true
+}
+
+issue_2231_2: {
+    options = {
+        evaluate: true,
+        unsafe: true,
+    }
+    input: {
+        console.log(Object.getOwnPropertyNames(null));
+    }
+    expect: {
+        console.log(Object.getOwnPropertyNames(null));
+    }
+    expect_stdout: true
+}