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