[wasm][bindings] Treat null string as null when converting (#47341)
authorLarry Ewing <lewing@microsoft.com>
Sat, 13 Feb 2021 02:40:32 +0000 (20:40 -0600)
committerGitHub <noreply@github.com>
Sat, 13 Feb 2021 02:40:32 +0000 (20:40 -0600)
* Treat null string as null objects

src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs
src/mono/wasm/runtime/binding_support.js

index 934673c..029a215 100644 (file)
@@ -86,6 +86,14 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
         }
 
         [Fact]
+        public static void MarshalNullStringToCS()
+        {
+            HelperMarshal._stringResource = null;
+            Runtime.InvokeJS("App.call_test_method(\"InvokeString\", [ null ])");
+            Assert.Null(HelperMarshal._stringResource);
+        }
+
+        [Fact]
         public static void MarshalStringToJS()
         {
             HelperMarshal._marshalledString = HelperMarshal._stringResource = null;
index 4617772..8d2ab92 100644 (file)
@@ -226,7 +226,9 @@ var BindingSupportLib = {
                },
 
                js_string_to_mono_string: function (string) {
-                       if (typeof (string) === "symbol")
+                       if (string === null)
+                               return null;
+                       else if (typeof (string) === "symbol")
                                return this.js_string_to_mono_string_interned (string);
                        else if (typeof (string) !== "string")
                                throw new Error ("Expected string argument");