Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sdks
diff options
context:
space:
mode:
authorKenneth Pouncey <kjpou@pt.lu>2019-12-09 15:32:17 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2019-12-09 15:32:17 +0300
commit1462208991862fa795d36ec5df52eab938a4242e (patch)
tree0d6bb5b621bcb0936c0971c54a18489eec2d46b1 /sdks
parented6b8024b0eb933d78ecc2e54bc8a798f868cf7e (diff)
[wasm][bcl][websockets] Add WebSocket support. (#18062)
Add the ability to initialize a `WebAssembly.Net.WebSockets::ClientWebSocket` from `System.Net.WebSockets.ClientWebSocket`. `System.Net.WebSockets.ClientWebSocket` will delegate all calls to the WebAssembly ClientWebSocket. - Add support for marshaling `Uri` class correctly. This was a cause of failures. - Add bindings tests for `Uri` marhaling.
Diffstat (limited to 'sdks')
-rw-r--r--sdks/wasm/Makefile4
-rw-r--r--sdks/wasm/framework/src/WebAssembly.Bindings/LinkDescriptor/WebAssembly.Bindings.xml1
-rw-r--r--sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs6
-rw-r--r--sdks/wasm/framework/src/WebAssembly.Net.WebSockets/ClientWebSocket.cs7
-rw-r--r--sdks/wasm/src/binding_support.js19
-rw-r--r--sdks/wasm/src/driver.c17
-rw-r--r--sdks/wasm/tests/browser/src/BindingsTestSuite/BindingsTestSuite.cs4
-rw-r--r--sdks/wasm/tests/browser/src/BrowserTestSuite/core-bindings-spec.js6
-rw-r--r--sdks/wasm/tests/browser/src/WebSocketTestSuite/WebSocketTestSuite.cs19
9 files changed, 65 insertions, 18 deletions
diff --git a/sdks/wasm/Makefile b/sdks/wasm/Makefile
index 049cdf6c772..2c12f997830 100644
--- a/sdks/wasm/Makefile
+++ b/sdks/wasm/Makefile
@@ -630,9 +630,11 @@ run-all-%:
test-debugger: build-debugger-test-app build-dbg-testsuite
dotnet test DebuggerTestSuite
-run-browser-tests: $(BROWSER_TEST)/.stamp-browser-test-suite
+run-browser-tests: build-browser-test-suite
(cd $(BROWSER_TEST) && npm test)
+build-browser-test-suite: $(BROWSER_TEST)/.stamp-browser-test-suite
+
run-browser-threads-tests: $(BROWSER_TEST_THREADS)/.stamp-browser-test-threads-suite
(cd $(BROWSER_TEST_THREADS) && npm test)
diff --git a/sdks/wasm/framework/src/WebAssembly.Bindings/LinkDescriptor/WebAssembly.Bindings.xml b/sdks/wasm/framework/src/WebAssembly.Bindings/LinkDescriptor/WebAssembly.Bindings.xml
index f3b8dd2c1f7..d8892b5852a 100644
--- a/sdks/wasm/framework/src/WebAssembly.Bindings/LinkDescriptor/WebAssembly.Bindings.xml
+++ b/sdks/wasm/framework/src/WebAssembly.Bindings/LinkDescriptor/WebAssembly.Bindings.xml
@@ -28,6 +28,7 @@
<method name="ObjectToString" />
<method name="GetDateValue" />
<method name="CreateDateTime" />
+ <method name="CreateUri" />
<method name="ObjectToEnum" />
<method name="DumpAotProfileData" />
</type>
diff --git a/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs b/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
index c5e6c50fb2d..0d6bb9b1bf5 100644
--- a/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
+++ b/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
@@ -363,6 +363,8 @@ namespace WebAssembly {
default:
if (t == typeof(IntPtr)) {
res += "i";
+ } else if (t == typeof (Uri)) {
+ res += "u";
} else {
if (t.IsValueType)
throw new Exception("Can't handle VT arguments");
@@ -493,6 +495,10 @@ namespace WebAssembly {
var unixTime = DateTimeOffset.FromUnixTimeMilliseconds((Int64)ticks);
return unixTime.DateTime;
}
+ static Uri CreateUri (string uri)
+ {
+ return new Uri(uri);
+ }
// This is simple right now and will include FlagsAttribute later.
public static Enum EnumFromExportContract (Type enumType, object value)
diff --git a/sdks/wasm/framework/src/WebAssembly.Net.WebSockets/ClientWebSocket.cs b/sdks/wasm/framework/src/WebAssembly.Net.WebSockets/ClientWebSocket.cs
index 7b92a6d4392..a1d62f8d0e2 100644
--- a/sdks/wasm/framework/src/WebAssembly.Net.WebSockets/ClientWebSocket.cs
+++ b/sdks/wasm/framework/src/WebAssembly.Net.WebSockets/ClientWebSocket.cs
@@ -151,13 +151,6 @@ namespace WebAssembly.Net.WebSockets {
/// <param name="cancellationToken">Cancellation token.</param>
public Task ConnectAsync (Uri uri, CancellationToken cancellationToken)
{
- if (uri == null) {
- throw new ArgumentNullException (nameof (uri));
- }
- if (!uri.IsAbsoluteUri) {
- throw new ArgumentException ("Uri is not absolute", nameof (uri));
- }
-
// Check that we have not started already
int priorState = Interlocked.CompareExchange (ref state, connecting, created);
if (priorState == disposed) {
diff --git a/sdks/wasm/src/binding_support.js b/sdks/wasm/src/binding_support.js
index bc6b9386e20..c3dd2d37a22 100644
--- a/sdks/wasm/src/binding_support.js
+++ b/sdks/wasm/src/binding_support.js
@@ -98,6 +98,7 @@ var BindingSupportLib = {
this.object_to_string = get_method ("ObjectToString");
this.get_date_value = get_method ("GetDateValue");
this.create_date_time = get_method ("CreateDateTime");
+ this.create_uri = get_method ("CreateUri");
this.object_to_enum = get_method ("ObjectToEnum");
this.init = true;
@@ -228,6 +229,9 @@ var BindingSupportLib = {
case 21: // clr .NET DateTimeOffset
var dateoffsetValue = this.call_method(this.object_to_string, null, "m", [ mono_obj ]);
return dateoffsetValue;
+ case 22: // clr .NET Uri
+ var uriValue = this.call_method(this.object_to_string, null, "m", [ mono_obj ]);
+ return uriValue;
default:
throw new Error ("no idea on how to unbox object kind " + type);
}
@@ -305,6 +309,19 @@ var BindingSupportLib = {
return this.extract_mono_obj (js_obj);
}
},
+ js_to_mono_uri: function (js_obj) {
+ this.bindings_lazy_init ();
+
+ switch (true) {
+ case js_obj === null:
+ case typeof js_obj === "undefined":
+ return 0;
+ case typeof js_obj === "string":
+ return this.call_method(this.create_uri, null, "sm", [ js_obj ])
+ default:
+ return this.extract_mono_obj (js_obj);
+ }
+ },
js_typed_array_to_array : function (js_obj) {
// JavaScript typed arrays are array-like objects and provide a mechanism for accessing
@@ -634,6 +651,8 @@ var BindingSupportLib = {
Module.setValue (args_mem + i * 4, args [i], "i32");
} else if (args_marshal[i] == 'o') {
Module.setValue (args_mem + i * 4, this.js_to_mono_obj (args [i]), "i32");
+ } else if (args_marshal[i] == 'u') {
+ Module.setValue (args_mem + i * 4, this.js_to_mono_uri (args [i]), "i32");
} else if (args_marshal[i] == 'j' || args_marshal[i] == 'k') {
var enumVal = this.js_to_mono_enum(method, i, args[i]);
diff --git a/sdks/wasm/src/driver.c b/sdks/wasm/src/driver.c
index 129f0056efb..a7ace636961 100644
--- a/sdks/wasm/src/driver.c
+++ b/sdks/wasm/src/driver.c
@@ -44,6 +44,7 @@ void mono_free (void*);
static MonoClass* datetime_class;
static MonoClass* datetimeoffset_class;
+static MonoClass* uri_class;
int mono_wasm_enable_gc;
@@ -488,6 +489,15 @@ class_is_task (MonoClass *klass)
return 0;
}
+MonoClass* mono_get_uri_class(MonoException** exc)
+{
+ MonoAssembly* assembly = mono_wasm_assembly_load ("System");
+ if (!assembly)
+ return NULL;
+ MonoClass* klass = mono_wasm_assembly_find_class(assembly, "System", "Uri");
+ return klass;
+}
+
#define MARSHAL_TYPE_INT 1
#define MARSHAL_TYPE_FP 2
#define MARSHAL_TYPE_STRING 3
@@ -499,6 +509,7 @@ class_is_task (MonoClass *klass)
#define MARSHAL_TYPE_ENUM 9
#define MARSHAL_TYPE_DATE 20
#define MARSHAL_TYPE_DATEOFFSET 21
+#define MARSHAL_TYPE_URI 22
// typed array marshalling
#define MARSHAL_ARRAY_BYTE 11
@@ -520,6 +531,10 @@ mono_wasm_get_obj_type (MonoObject *obj)
datetime_class = mono_class_from_name (mono_get_corlib(), "System", "DateTime");
if (!datetimeoffset_class)
datetimeoffset_class = mono_class_from_name (mono_get_corlib(), "System", "DateTimeOffset");
+ if (!uri_class) {
+ MonoException** exc = NULL;
+ uri_class = mono_get_uri_class(exc);
+ }
MonoClass *klass = mono_object_get_class (obj);
MonoType *type = mono_class_get_type (klass);
@@ -573,6 +588,8 @@ mono_wasm_get_obj_type (MonoObject *obj)
return MARSHAL_TYPE_DATE;
if (klass == datetimeoffset_class)
return MARSHAL_TYPE_DATEOFFSET;
+ if (uri_class && mono_class_is_assignable_from(uri_class, klass))
+ return MARSHAL_TYPE_URI;
if (mono_class_is_enum (klass))
return MARSHAL_TYPE_ENUM;
if (!mono_type_is_reference (type)) //vt
diff --git a/sdks/wasm/tests/browser/src/BindingsTestSuite/BindingsTestSuite.cs b/sdks/wasm/tests/browser/src/BindingsTestSuite/BindingsTestSuite.cs
index 4bed4df1f7c..01b6d60c6d8 100644
--- a/sdks/wasm/tests/browser/src/BindingsTestSuite/BindingsTestSuite.cs
+++ b/sdks/wasm/tests/browser/src/BindingsTestSuite/BindingsTestSuite.cs
@@ -280,5 +280,9 @@ namespace BindingsTestSuite
{
return param1 == null;
}
+ public static Uri StringToUri (string uri)
+ {
+ return new Uri(uri);
+ }
}
}
diff --git a/sdks/wasm/tests/browser/src/BrowserTestSuite/core-bindings-spec.js b/sdks/wasm/tests/browser/src/BrowserTestSuite/core-bindings-spec.js
index 5b2ae792307..a4b55ae89a5 100644
--- a/sdks/wasm/tests/browser/src/BrowserTestSuite/core-bindings-spec.js
+++ b/sdks/wasm/tests/browser/src/BrowserTestSuite/core-bindings-spec.js
@@ -700,4 +700,10 @@ describe("The WebAssembly Core Bindings Test Suite",function(){
var result = _document.Module.BINDING.call_static_method("[BindingsTestSuite]BindingsTestSuite.Program:StringArrayIsNull", [null]);
assert.isTrue(result);
}, DEFAULT_TIMEOUT);
+ it('BindingTestSuite: Should return Uri as string.', () => {
+ //karmaHTML.corebindingsspec.document gives the access to the Document object of 'http-spec.html' file
+ var _document = karmaHTML.corebindingsspec.document;
+ var result = _document.Module.BINDING.call_static_method("[BindingsTestSuite]BindingsTestSuite.Program:StringToUri", ["ws://localhost"]);
+ assert.equal(result, "ws://localhost/", "result does not match value ws://localhost/.");
+ }, DEFAULT_TIMEOUT);
});
diff --git a/sdks/wasm/tests/browser/src/WebSocketTestSuite/WebSocketTestSuite.cs b/sdks/wasm/tests/browser/src/WebSocketTestSuite/WebSocketTestSuite.cs
index 40d22f1ec22..54972df9f71 100644
--- a/sdks/wasm/tests/browser/src/WebSocketTestSuite/WebSocketTestSuite.cs
+++ b/sdks/wasm/tests/browser/src/WebSocketTestSuite/WebSocketTestSuite.cs
@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using System.Threading;
-using ClientWebSocket = WebAssembly.Net.WebSockets.ClientWebSocket;
using System.Net.WebSockets;
using System.Text;
@@ -39,7 +38,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -64,7 +63,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -90,7 +89,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -118,7 +117,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -152,7 +151,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -186,7 +185,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -220,7 +219,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -253,7 +252,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{
@@ -278,7 +277,7 @@ namespace TestSuite
}
catch (Exception exc)
{
- Console.WriteLine($"{exc.Message} / {exc.InnerException.Message}");
+ Console.WriteLine($"{exc.Message} / {exc.InnerException?.Message}");
}
finally
{