Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][MT] JSImport with DiscardNoWait is OK in the middle of pending synchronous call #101044

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading