Skip to content

Commit

Permalink
[browser][MT] JSImport with DiscardNoWait is OK in the middle of pend…
Browse files Browse the repository at this point in the history
…ing synchronous call (#101044)
  • Loading branch information
pavelsavara authored Apr 15, 2024
1 parent 4f3a2f0 commit 0e6cc4a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public static void BeforeSyncJSExport(JSMarshalerArgument* arguments_buffer)
try
{
var ctx = arg_exc.AssertCurrentThreadContext();
// note that this method is only executed when the caller is on another thread, via mono_wasm_invoke_jsexport_sync -> mono_wasm_install_js_worker_interop_wrapper
ctx.IsPendingSynchronousCall = true;
if (ctx.IsMainThread)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ internal static unsafe void InvokeJSImportImpl(JSFunctionBinding signature, Span
#if FEATURE_WASM_MANAGED_THREADS
else
{
if (targetContext.IsPendingSynchronousCall && targetContext.IsMainThread)
if (targetContext.IsPendingSynchronousCall && targetContext.IsMainThread && !signature.IsDiscardNoWait)
{
throw new PlatformNotSupportedException("Cannot call synchronous JS function from inside a synchronous call to a C# method.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ static void LocalCtsIgnoringCall(Action<CancellationToken> action)
new NamedCall { IsBlocking = false, Name = "new Timer", Call = delegate (CancellationToken ct) {
new Timer((_) => { }, null, 1, -1);
}},
new NamedCall { IsBlocking = false, Name = "JSType.DiscardNoWait", Call = delegate (CancellationToken ct) {
WebWorkerTestHelper.Log("DiscardNoWait");
}},

// things which should throw PNSE on sync JSExport and JSWebWorker
new NamedCall { IsBlocking = true, Name = "Task.Wait", Call = delegate (CancellationToken ct) { Task.Delay(30, ct).Wait(ct); }},
Expand Down

0 comments on commit 0e6cc4a

Please sign in to comment.