From cafc0fc0a6491e95f133b85b3fde449b14fc7cca Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 5 Mar 2024 18:41:53 +0100 Subject: [PATCH] attempt to fix https://github.com/dotnet/runtime/issues/98406 --- .../Runtime/InteropServices/JavaScript/JSProxyContext.cs | 6 ++---- .../JavaScript/Marshaling/JSMarshalerArgument.Task.cs | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSProxyContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSProxyContext.cs index 7b481d24658a0..f8cc312f1c2f2 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSProxyContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSProxyContext.cs @@ -280,16 +280,14 @@ public nint AllocJSVHandle() { lock (this) { + ObjectDisposedException.ThrowIf(_isDisposed, this); + if (JSVHandleFreeList.Count > 0) { var jsvHandle = JSVHandleFreeList[JSVHandleFreeList.Count - 1]; JSVHandleFreeList.RemoveAt(JSVHandleFreeList.Count - 1); return jsvHandle; } - if (NextJSVHandle == IntPtr.Zero) - { - NextJSVHandle = -2; - } return NextJSVHandle--; } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs index eee6b5f3037cf..e01b292cc172b 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs @@ -189,7 +189,7 @@ internal void ToJSDynamic(Task? value) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); #if FEATURE_WASM_MANAGED_THREADS - task.ContinueWith(Complete, taskHolder, TaskScheduler.FromCurrentSynchronizationContext()); + task.ContinueWith(Complete, taskHolder, CancellationToken.None, TaskContinuationOptions.RunContinuationsAsynchronously, TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, taskHolder, TaskScheduler.Current); #endif @@ -273,7 +273,7 @@ public void ToJS(Task? value) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); #if FEATURE_WASM_MANAGED_THREADS - task.ContinueWith(Complete, taskHolder, TaskScheduler.FromCurrentSynchronizationContext()); + task.ContinueWith(Complete, taskHolder, CancellationToken.None, TaskContinuationOptions.RunContinuationsAsynchronously, TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, taskHolder, TaskScheduler.Current); #endif @@ -350,7 +350,7 @@ public void ToJS(Task? value, ArgumentToJSCallback marshaler) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); #if FEATURE_WASM_MANAGED_THREADS - task.ContinueWith(Complete, new HolderAndMarshaler(taskHolder, marshaler), TaskScheduler.FromCurrentSynchronizationContext()); + task.ContinueWith(Complete, new HolderAndMarshaler(taskHolder, marshaler), CancellationToken.None, TaskContinuationOptions.RunContinuationsAsynchronously, TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, new HolderAndMarshaler(taskHolder, marshaler), TaskScheduler.Current); #endif