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] improve promise resolve marshaling after exit #94288

Merged
merged 2 commits into from
Nov 2, 2023
Merged
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
11 changes: 9 additions & 2 deletions src/mono/wasm/runtime/marshal-to-cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { stringToMonoStringRoot } from "./strings";
import { JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, BoundMarshalerToCs, MarshalerType } from "./types/internal";
import { TypedArray } from "./types/emscripten";
import { addUnsettledPromise, settleUnsettledPromise } from "./pthreads/shared/eventloop";
import { mono_log_debug } from "./logging";

export const jsinteropDoc = "For more information see https://aka.ms/dotnet-wasm-jsinterop";

Expand Down Expand Up @@ -318,8 +319,11 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
addUnsettledPromise();

value.then(data => {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise can't be propagated to managed code, mono runtime already exited.");
return;
}
try {
loaderHelpers.assert_runtime_running();
mono_assert(!holder.isDisposed, "This promise can't be propagated to managed code, because the Task was already freed.");
if (MonoWasmThreads)
settleUnsettledPromise();
Expand All @@ -330,8 +334,11 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise<any>, _?:
runtimeHelpers.abort(ex);
}
}).catch(reason => {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise can't be propagated to managed code, mono runtime already exited.", reason);
return;
}
try {
loaderHelpers.assert_runtime_running();
mono_assert(!holder.isDisposed, "This promise can't be propagated to managed code, because the Task was already freed.");
if (MonoWasmThreads)
settleUnsettledPromise();
Expand Down
Loading