workaround firefox asm.js quirks (#3650)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 28 Dec 2019 23:14:53 +0000 (23:14 +0000)
committerGitHub <noreply@github.com>
Sat, 28 Dec 2019 23:14:53 +0000 (23:14 +0000)
fixes #3636

lib/scope.js
test/compress/asm.js

index edefc29..896efac 100644 (file)
@@ -428,6 +428,11 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
             if (options.cache && node instanceof AST_Toplevel) {
                 node.globals.each(mangle);
             }
+            if (node instanceof AST_Defun && tw.has_directive("use asm")) {
+                var sym = new AST_SymbolRef(node.name);
+                sym.scope = node;
+                sym.reference(options);
+            }
             node.variables.each(function(def) {
                 if (!defer_redef(def)) mangle(def);
             });
index 1f00f8f..0ea6087 100644 (file)
@@ -166,3 +166,69 @@ asm_nested_functions: {
     }
     expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
 }
+
+issue_3636_1: {
+    mangle = {}
+    input: {
+        function n(stdlib, foreign, buffer) {
+            "use asm";
+            function add(x, y) {
+                x = x | 0;
+                y = y | 0;
+                return x + y | 0;
+            }
+            return {
+                add: add
+            };
+        }
+        console.log(new n().add("foo", 42));
+    }
+    expect: {
+        function n(o, e, u) {
+            "use asm";
+            function d(n, o) {
+                n = n | 0;
+                o = o | 0;
+                return n + o | 0;
+            }
+            return {
+                add: d
+            };
+        }
+        console.log(new n().add("foo", 42));
+    }
+    expect_stdout: "42"
+}
+
+issue_3636_2: {
+    mangle = {}
+    input: {
+        var n = function(stdlib, foreign, buffer) {
+            "use asm";
+            function add(x, y) {
+                x = x | 0;
+                y = y | 0;
+                return x + y | 0;
+            }
+            return {
+                add: add
+            };
+        };
+        console.log(new n().add("foo", 42));
+    }
+    expect: {
+        var n = function(n, o, e) {
+            "use asm";
+            function r(n, o) {
+                n = n | 0;
+                o = o | 0;
+                return n + o | 0;
+            }
+            return {
+                add: r
+            };
+        };
+        console.log(new n().add("foo", 42));
+    }
+    expect_stdout: "42"
+}