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:
authorLarry Ewing <lewing@microsoft.com>2019-12-18 07:47:23 +0300
committerGitHub <noreply@github.com>2019-12-18 07:47:23 +0300
commit60f081c0778e21c4efc36bc5799896d2728b6ad9 (patch)
tree3b2394fe294b163927a8dfb1e09e3a64a4d735de /sdks
parentf46d5fda1d91c665b45df94ff134024c842b15b7 (diff)
[wasm] handle completed Tasks and exceptions when resolving Task prom… (#18215)
* [wasm] handle completed Tasks and exceptions when resolving Task promises * Preserve the old void invoke behaviour
Diffstat (limited to 'sdks')
-rw-r--r--sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs54
1 files changed, 21 insertions, 33 deletions
diff --git a/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs b/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
index 0d6bb9b1bf5..a90805cf340 100644
--- a/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
+++ b/sdks/wasm/framework/src/WebAssembly.Bindings/Runtime.cs
@@ -391,46 +391,34 @@ namespace WebAssembly {
}
-
- static MethodInfo gsjsc;
- static void GenericSetupJSContinuation<T> (Task<T> task, JSObject cont_obj)
- {
- task.GetAwaiter ().OnCompleted ((Action)(() => {
-
- if (task.Exception != null)
- cont_obj.Invoke ((string)"reject", task.Exception.ToString ());
- else {
- cont_obj.Invoke ((string)"resolve", task.Result);
- }
-
- cont_obj.Dispose ();
- FreeObject (task);
-
- }));
- }
-
static void SetupJSContinuation (Task task, JSObject cont_obj)
{
- if (task.GetType () == typeof (Task)) {
- task.GetAwaiter ().OnCompleted ((Action)(() => {
-
- if (task.Exception != null)
- cont_obj.Invoke ((string)"reject", task.Exception.ToString ());
- else
- cont_obj.Invoke ((string)"resolve", (object [])null);
-
+ if (task.IsCompleted)
+ Complete ();
+ else
+ task.GetAwaiter ().OnCompleted (Complete);
+
+ void Complete () {
+ try {
+ if (task.Exception == null) {
+ var resultProperty = task.GetType ().GetProperty("Result");
+
+ if (resultProperty == null)
+ cont_obj.Invoke ("resolve", (object[])null);
+ else
+ cont_obj.Invoke ("resolve", resultProperty.GetValue(task));
+ } else {
+ cont_obj.Invoke ("reject", task.Exception.ToString ());
+ }
+ } catch (Exception e) {
+ cont_obj.Invoke ("reject", e.ToString ());
+ } finally {
cont_obj.Dispose ();
FreeObject (task);
- }));
- } else {
- //FIXME this is horrible codegen, we can do better with per-method glue
- if (gsjsc == null)
- gsjsc = typeof (Runtime).GetMethod ("GenericSetupJSContinuation", BindingFlags.NonPublic | BindingFlags.Static);
- gsjsc.MakeGenericMethod (task.GetType ().GetGenericArguments ()).Invoke (null, new object [] { task, cont_obj });
+ }
}
}
-
/// <summary>
/// Fetches a global object from the Javascript world, either from the current brower window or from the node.js global context.
/// </summary>