From a264177a2d06247d6bd7249f5457e1dd3c562c9a Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sat, 13 Sep 2025 10:08:44 +0200 Subject: [PATCH 1/7] rename C symbols --- src/coreclr/vm/wasm/helpers.cpp | 4 +- .../JavaScript/Interop/JavaScriptExports.cs | 2 +- .../JavaScript/JSFunctionBinding.cs | 2 +- .../Marshaling/JSMarshalerArgument.Task.cs | 2 +- .../browser/runtime/cancelable-promise.ts | 8 +- src/mono/browser/runtime/corebindings.c | 122 +++++++++--------- src/mono/browser/runtime/crypto.ts | 2 +- src/mono/browser/runtime/cwraps.ts | 8 +- src/mono/browser/runtime/driver.c | 6 +- src/mono/browser/runtime/export-api.ts | 4 +- src/mono/browser/runtime/exports-binding.ts | 40 +++--- src/mono/browser/runtime/gc-common.h | 4 +- src/mono/browser/runtime/gc-handles.ts | 2 +- .../browser/runtime/globalization-locale.ts | 2 +- src/mono/browser/runtime/invoke-cs.ts | 2 +- src/mono/browser/runtime/invoke-js.ts | 12 +- src/mono/browser/runtime/logging.ts | 2 +- src/mono/browser/runtime/marshal-to-cs.ts | 4 +- src/mono/browser/runtime/marshal-to-js.ts | 18 +-- src/mono/browser/runtime/pthreads/index.ts | 4 +- .../runtime/pthreads/worker-interop.ts | 2 +- src/mono/browser/runtime/roots.ts | 4 +- src/mono/browser/runtime/web-socket.ts | 2 +- src/mono/mono/metadata/gc.c | 2 +- src/mono/mono/metadata/sgen-mono.c | 2 +- src/mono/mono/mini/mini-wasm.c | 10 +- src/mono/mono/mini/mini-wasm.h | 2 +- src/mono/mono/utils/mono-threads-wasm.c | 6 +- src/mono/mono/utils/mono-threads.h | 4 +- src/mono/wasi/runtime/driver.c | 4 +- src/mono/wasm/threads.md | 4 +- src/native/minipal/random.c | 4 +- 32 files changed, 148 insertions(+), 148 deletions(-) diff --git a/src/coreclr/vm/wasm/helpers.cpp b/src/coreclr/vm/wasm/helpers.cpp index c4d28e3cba506b..0cb4f33110a66f 100644 --- a/src/coreclr/vm/wasm/helpers.cpp +++ b/src/coreclr/vm/wasm/helpers.cpp @@ -379,9 +379,9 @@ void _DacGlobals::Initialize() // Incorrectly typed temporary symbol to satisfy the linker. int g_pDebugger; -extern "C" int32_t mono_wasm_browser_entropy(uint8_t* buffer, int32_t bufferLength) +extern "C" int32_t dotnet_browser_entropy(uint8_t* buffer, int32_t bufferLength) { - PORTABILITY_ASSERT("mono_wasm_browser_entropy is not implemented"); + PORTABILITY_ASSERT("dotnet_browser_entropy is not implemented"); return -1; } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs index 596c47f144e36e..d24a18f247ef3b 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs @@ -291,7 +291,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 + // note that this method is only executed when the caller is on another thread, via mono_wasm_invoke_jsexport_sync -> dotnet_browser_install_js_worker_interop_wrapper ctx.IsPendingSynchronousCall = true; if (ctx.IsMainThread) { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs index 7f1447673f85e6..b26f1f3e4e503d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs @@ -478,7 +478,7 @@ internal static unsafe void ResolveOrRejectPromise(JSProxyContext targetContext, // meaning JS side needs to dispose it exc.slot.ReceiverShouldFree = true; - // this copy is freed in mono_wasm_resolve_or_reject_promise + // this copy is freed in dotnet_browser_resolve_or_reject_promise var bytes = sizeof(JSMarshalerArgument) * arguments.Length; void* cpy = (void*)Marshal.AllocHGlobal(bytes); arguments.CopyTo(new Span(cpy, arguments.Length)); 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 99c2730f8fe8dd..b5918b9b941dc1 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 @@ -425,7 +425,7 @@ private bool CanMarshalTaskResultOnSameCall(JSProxyContext ctx) } // Otherwise this is JSExport return value and we can't use the args buffer, because the args buffer arrived in async message and nobody is reading after this. - // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `mono_wasm_resolve_or_reject_promise_post` + // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `dotnet_browser_resolve_or_reject_promise_post` // there is JSVHandle in this arg return false; } diff --git a/src/mono/browser/runtime/cancelable-promise.ts b/src/mono/browser/runtime/cancelable-promise.ts index fa4e11fe07ee08..4bfcb688c6fcf4 100644 --- a/src/mono/browser/runtime/cancelable-promise.ts +++ b/src/mono/browser/runtime/cancelable-promise.ts @@ -35,12 +35,12 @@ export function wrap_as_cancelable (inner: Promise): ControllablePromise mono_wasm_cancel_promise_impl(task_holder_gc_handle)); +export function dotnet_browser_cancel_promise (task_holder_gc_handle: GCHandle): void { + // cancelation should not arrive earlier than the promise created by marshaling in dotnet_browser_invoke_jsimport_mt + invoke_later_when_on_ui_thread_async(() => dotnet_browser_cancel_promise_impl(task_holder_gc_handle)); } -export function mono_wasm_cancel_promise_impl (task_holder_gc_handle: GCHandle): void { +export function dotnet_browser_cancel_promise_impl (task_holder_gc_handle: GCHandle): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise can't be canceled, mono runtime already exited."); return; diff --git a/src/mono/browser/runtime/corebindings.c b/src/mono/browser/runtime/corebindings.c index 29db5546f09948..b2104bc3d818be 100644 --- a/src/mono/browser/runtime/corebindings.c +++ b/src/mono/browser/runtime/corebindings.c @@ -21,81 +21,81 @@ #include "gc-common.h" //JS funcs -extern void mono_wasm_release_cs_owned_object (int js_handle); -extern void mono_wasm_resolve_or_reject_promise (void *args); -extern void mono_wasm_cancel_promise (int task_holder_gc_handle); -extern void mono_wasm_console_clear (); +extern void dotnet_browser_release_cs_owned_object (int js_handle); +extern void dotnet_browser_resolve_or_reject_promise (void *args); +extern void dotnet_browser_cancel_promise (int task_holder_gc_handle); +extern void dotnet_browser_console_clear (); extern void mono_wasm_set_entrypoint_breakpoint (int entry_point_metadata_token); extern void mono_wasm_trace_logger (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data); -extern void mono_wasm_invoke_js_function (int function_js_handle, void *args); +extern void dotnet_browser_invoke_js_function (int function_js_handle, void *args); extern int mono_runtime_run_module_cctor (MonoImage *image, MonoError *error); typedef void (*background_job_cb)(void); typedef int (*ds_job_cb)(void* data); -void mono_wasm_bind_assembly_exports (char *assembly_name); -void mono_wasm_assembly_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); -void mono_wasm_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); +void dotnet_browser_bind_assembly_exports (char *assembly_name); +void dotnet_browser_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); +void dotnet_browser_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); #ifndef DISABLE_THREADS -void mono_wasm_release_cs_owned_object_post (pthread_t target_tid, int js_handle); -void mono_wasm_resolve_or_reject_promise_post (pthread_t target_tid, void *args); -void mono_wasm_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle); +void dotnet_browser_release_cs_owned_object_post (pthread_t target_tid, int js_handle); +void dotnet_browser_resolve_or_reject_promise_post (pthread_t target_tid, void *args); +void dotnet_browser_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle); extern void mono_wasm_install_js_worker_interop (int context_gc_handle); -void mono_wasm_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); -extern void mono_wasm_uninstall_js_worker_interop (); -extern void mono_wasm_invoke_jsimport_MT (void* signature, void* args); -void mono_wasm_invoke_jsimport_async_post (pthread_t target_tid, void* signature, void* args); -void mono_wasm_invoke_jsimport_sync_send (pthread_t target_tid, void* signature, void* args); -void mono_wasm_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args); +void dotnet_browser_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); +extern void dotnet_browser_uninstall_js_worker_interop (); +extern void dotnet_browser_invoke_jsimport_mt (void* signature, void* args); +void dotnet_browser_jsimport_async_post (pthread_t target_tid, void* signature, void* args); +void dotnet_browser_jsimport_sync_send (pthread_t target_tid, void* signature, void* args); +void dotnet_browser_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args); extern void mono_threads_wasm_async_run_in_target_thread_vi (pthread_t target_thread, void (*func) (gpointer), gpointer user_data1); extern void mono_threads_wasm_async_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer user_data2); extern void mono_threads_wasm_sync_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer args); -extern void mono_wasm_warn_about_blocking_wait (void* ptr, int32_t length); +extern void dotnet_browser_warn_about_blocking_wait (void* ptr, int32_t length); #else -extern void* mono_wasm_bind_js_import_ST (void *signature); -extern void mono_wasm_invoke_jsimport_ST (int function_handle, void *args); +extern void* dotnet_browser_bind_js_import_st (void *signature); +extern void dotnet_browser_invoke_jsimport_st (int function_handle, void *args); #endif /* DISABLE_THREADS */ // JS-based globalization -extern char16_t* mono_wasm_get_locale_info (const uint16_t* locale, int32_t localeLength, const uint16_t* culture, int32_t cultureLength, const uint16_t* result, int32_t resultMaxLength, int *resultLength); +extern char16_t* dotnet_browser_get_locale_info (const uint16_t* locale, int32_t localeLength, const uint16_t* culture, int32_t cultureLength, const uint16_t* result, int32_t resultMaxLength, int *resultLength); void bindings_initialize_internals (void) { #ifndef ENABLE_JS_INTEROP_BY_VALUE - mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", mono_wasm_register_root); - mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", mono_wasm_deregister_root); + mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", dotnet_browser_register_root); + mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", dotnet_browser_unregister_root); #endif /* ENABLE_JS_INTEROP_BY_VALUE */ #ifndef DISABLE_THREADS - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", mono_wasm_release_cs_owned_object_post); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", mono_wasm_resolve_or_reject_promise_post); - mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", mono_wasm_install_js_worker_interop_wrapper); - mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", mono_wasm_uninstall_js_worker_interop); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", mono_wasm_invoke_jsimport_MT); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", mono_wasm_invoke_jsimport_sync_send); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", mono_wasm_invoke_jsimport_async_post); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", mono_wasm_invoke_js_function_send); - mono_add_internal_call ("Interop/Runtime::CancelPromisePost", mono_wasm_cancel_promise_post); - mono_add_internal_call ("System.Threading.Thread::WarnAboutBlockingWait", mono_wasm_warn_about_blocking_wait); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", dotnet_browser_release_cs_owned_object_post); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", dotnet_browser_resolve_or_reject_promise_post); + mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", dotnet_browser_install_js_worker_interop_wrapper); + mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", dotnet_browser_uninstall_js_worker_interop); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", dotnet_browser_invoke_jsimport_mt); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", dotnet_browser_jsimport_sync_send); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", dotnet_browser_jsimport_async_post); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", dotnet_browser_invoke_js_function_send); + mono_add_internal_call ("Interop/Runtime::CancelPromisePost", dotnet_browser_cancel_promise_post); + mono_add_internal_call ("System.Threading.Thread::WarnAboutBlockingWait", dotnet_browser_warn_about_blocking_wait); #else - mono_add_internal_call ("Interop/Runtime::BindJSImportST", mono_wasm_bind_js_import_ST); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", mono_wasm_invoke_jsimport_ST); + mono_add_internal_call ("Interop/Runtime::BindJSImportST", dotnet_browser_bind_js_import_st); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", dotnet_browser_invoke_jsimport_st); #endif /* DISABLE_THREADS */ - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", mono_wasm_release_cs_owned_object); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", mono_wasm_resolve_or_reject_promise); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", mono_wasm_invoke_js_function); - mono_add_internal_call ("Interop/Runtime::CancelPromise", mono_wasm_cancel_promise); - mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", mono_wasm_assembly_get_entry_point); - mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", mono_wasm_bind_assembly_exports); - mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", mono_wasm_get_assembly_export); - mono_add_internal_call ("System.ConsolePal::Clear", mono_wasm_console_clear); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", dotnet_browser_release_cs_owned_object); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", dotnet_browser_resolve_or_reject_promise); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", dotnet_browser_invoke_js_function); + mono_add_internal_call ("Interop/Runtime::CancelPromise", dotnet_browser_cancel_promise); + mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", dotnet_browser_get_entry_point); + mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", dotnet_browser_bind_assembly_exports); + mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", dotnet_browser_get_assembly_export); + mono_add_internal_call ("System.ConsolePal::Clear", dotnet_browser_console_clear); // JS-based globalization - mono_add_internal_call ("Interop/JsGlobalization::GetLocaleInfo", mono_wasm_get_locale_info); + mono_add_internal_call ("Interop/JsGlobalization::GetLocaleInfo", dotnet_browser_get_locale_info); } static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name) @@ -112,7 +112,7 @@ static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name) return res; } -void mono_wasm_assembly_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) +void dotnet_browser_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) { assert (assembly_name); *method_out = NULL; @@ -176,7 +176,7 @@ void mono_wasm_assembly_get_entry_point (char *assembly_name, int auto_insert_br *method_out = method; } -void mono_wasm_bind_assembly_exports (char *assembly_name) +void dotnet_browser_bind_assembly_exports (char *assembly_name) { MonoError error; MonoAssembly* assembly; @@ -200,7 +200,7 @@ void mono_wasm_bind_assembly_exports (char *assembly_name) PVOLATILE(MonoObject) exc2 = NULL; store_volatile((MonoObject**)&temp_exc, (MonoObject*)mono_object_to_string ((MonoObject*)temp_exc, (MonoObject **)&exc2)); if (exc2) { - mono_wasm_trace_logger ("jsinterop", "critical", "mono_wasm_bind_assembly_exports unexpected double fault", 1, NULL); + mono_wasm_trace_logger ("jsinterop", "critical", "dotnet_browser_bind_assembly_exports unexpected double fault", 1, NULL); } else { mono_wasm_trace_logger ("jsinterop", "critical", mono_string_to_utf8((MonoString*)temp_exc), 1, NULL); } @@ -213,7 +213,7 @@ void mono_wasm_bind_assembly_exports (char *assembly_name) } } -void mono_wasm_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) +void dotnet_browser_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) { MonoError error; MonoAssembly* assembly; @@ -251,7 +251,7 @@ void* before_sync_js_import; void* after_sync_js_import; void* synchronization_context_pump_handler; -void mono_wasm_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) +void dotnet_browser_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) { before_sync_js_import = beforeSyncJSImport; after_sync_js_import = afterSyncJSImport; @@ -260,39 +260,39 @@ void mono_wasm_install_js_worker_interop_wrapper (int context_gc_handle, void* b } // async -void mono_wasm_release_cs_owned_object_post (pthread_t target_tid, int js_handle) +void dotnet_browser_release_cs_owned_object_post (pthread_t target_tid, int js_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))mono_wasm_release_cs_owned_object, (gpointer)js_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_release_cs_owned_object, (gpointer)js_handle); } // async -void mono_wasm_resolve_or_reject_promise_post (pthread_t target_tid, void* args) +void dotnet_browser_resolve_or_reject_promise_post (pthread_t target_tid, void* args) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))mono_wasm_resolve_or_reject_promise, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_resolve_or_reject_promise, (gpointer)args); } // async -void mono_wasm_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle) +void dotnet_browser_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))mono_wasm_cancel_promise, (gpointer)task_holder_gc_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_cancel_promise, (gpointer)task_holder_gc_handle); } // async -void mono_wasm_invoke_jsimport_async_post (pthread_t target_tid, void* signature, void* args) +void dotnet_browser_jsimport_async_post (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))mono_wasm_invoke_jsimport_MT, (gpointer)signature, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_jsimport_mt, (gpointer)signature, (gpointer)args); } // sync -void mono_wasm_invoke_jsimport_sync_send (pthread_t target_tid, void* signature, void* args) +void dotnet_browser_jsimport_sync_send (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))mono_wasm_invoke_jsimport_MT, (gpointer)signature, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_jsimport_mt, (gpointer)signature, (gpointer)args); } // sync -void mono_wasm_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args) +void dotnet_browser_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))mono_wasm_invoke_js_function, (gpointer)function_js_handle, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_js_function, (gpointer)function_js_handle, (gpointer)args); } #endif /* DISABLE_THREADS */ diff --git a/src/mono/browser/runtime/crypto.ts b/src/mono/browser/runtime/crypto.ts index 754e1c81fe7ef8..dc3a6d55ea9438 100644 --- a/src/mono/browser/runtime/crypto.ts +++ b/src/mono/browser/runtime/crypto.ts @@ -7,7 +7,7 @@ import { isSharedArrayBuffer, localHeapViewU8 } from "./memory"; const batchedQuotaMax = 65536; let warnOnce = true; -export function mono_wasm_browser_entropy (bufferPtr: number, bufferLength: number): number { +export function dotnet_browser_entropy (bufferPtr: number, bufferLength: number): number { if (!globalThis.crypto || !globalThis.crypto.getRandomValues) { if (warnOnce) { mono_log_warn("This engine doesn't support crypto.getRandomValues. Please use a modern version or provide polyfill for 'globalThis.crypto.getRandomValues'."); diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index e693c52236357c..f13f304b0b542e 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -31,8 +31,8 @@ const threading_cwraps: SigLine[] = WasmEnableThreads ? [ // when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call const fn_signatures: SigLine[] = [ - [true, "mono_wasm_register_root", "number", ["number", "number", "string"]], - [true, "mono_wasm_deregister_root", null, ["number"]], + [true, "dotnet_browser_register_root", "number", ["number", "number", "string"]], + [true, "dotnet_browser_unregister_root", null, ["number"]], [true, "mono_wasm_string_get_data_ref", null, ["number", "number", "number", "number"]], [true, "mono_wasm_set_is_debugger_attached", "void", ["bool"]], [true, "mono_wasm_send_dbg_command", "bool", ["number", "number", "number", "number", "number"]], @@ -158,8 +158,8 @@ export interface t_ProfilerCwraps { } export interface t_Cwraps { - mono_wasm_register_root(start: VoidPtr, size: number, name: string): number; - mono_wasm_deregister_root(addr: VoidPtr): void; + dotnet_browser_register_root(start: VoidPtr, size: number, name: string): number; + dotnet_browser_unregister_root(addr: VoidPtr): void; mono_wasm_string_get_data_ref(stringRef: MonoStringRef, outChars: CharPtrPtr, outLengthBytes: Int32Ptr, outIsInterned: Int32Ptr): void; mono_wasm_set_is_debugger_attached(value: boolean): void; mono_wasm_send_dbg_command(id: number, command_set: number, command: number, data: VoidPtr, size: number): boolean; diff --git a/src/mono/browser/runtime/driver.c b/src/mono/browser/runtime/driver.c index 8306e961908cb6..2bfa644a9540e6 100644 --- a/src/mono/browser/runtime/driver.c +++ b/src/mono/browser/runtime/driver.c @@ -77,17 +77,17 @@ MONO_API int mono_gc_register_root (char *start, size_t size, MonoGCDescriptor void mono_gc_deregister_root (char* addr); EMSCRIPTEN_KEEPALIVE int -mono_wasm_register_root (char *start, size_t size, const char *name) +dotnet_browser_register_root (char *start, size_t size, const char *name) { int result; MONO_ENTER_GC_UNSAFE; - result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "mono_wasm_register_root"); + result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "dotnet_browser_register_root"); MONO_EXIT_GC_UNSAFE; return result; } EMSCRIPTEN_KEEPALIVE void -mono_wasm_deregister_root (char *addr) +dotnet_browser_unregister_root (char *addr) { MONO_ENTER_GC_UNSAFE; mono_gc_deregister_root (addr); diff --git a/src/mono/browser/runtime/export-api.ts b/src/mono/browser/runtime/export-api.ts index 1f496ce7a49ae4..00ac8e3d659658 100644 --- a/src/mono/browser/runtime/export-api.ts +++ b/src/mono/browser/runtime/export-api.ts @@ -3,7 +3,7 @@ import type { MonoConfig, APIType } from "./types"; -import { mono_wasm_get_assembly_exports } from "./invoke-cs"; +import { dotnet_browser_get_assembly_exports } from "./invoke-cs"; import { mono_wasm_set_module_imports } from "./invoke-js"; import { getB32, getB8, getF32, getF64, getI16, getI32, getI52, getI64Big, getI8, getU16, getU32, getU52, getU8, localHeapViewF32, localHeapViewF64, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewI8, localHeapViewU16, localHeapViewU32, localHeapViewU8, setB32, setB8, setF32, setF64, setI16, setI32, setI52, setI64Big, setI8, setU16, setU32, setU52, setU8 } from "./memory"; import { mono_run_main, mono_run_main_and_exit } from "./run"; @@ -16,7 +16,7 @@ export function export_api (): any { runMainAndExit: mono_run_main_and_exit, exit: loaderHelpers.mono_exit, setEnvironmentVariable: mono_wasm_setenv, - getAssemblyExports: mono_wasm_get_assembly_exports, + getAssemblyExports: dotnet_browser_get_assembly_exports, setModuleImports: mono_wasm_set_module_imports, getConfig: (): MonoConfig => { return runtimeHelpers.config; diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index fbed0f8a2d3fc2..890779dbcedde4 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -4,26 +4,26 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug"; -import { mono_wasm_release_cs_owned_object } from "./gc-handles"; -import { mono_wasm_bind_js_import_ST, mono_wasm_invoke_js_function, mono_wasm_invoke_jsimport_MT, mono_wasm_invoke_jsimport_ST } from "./invoke-js"; +import { dotnet_browser_release_cs_owned_object } from "./gc-handles"; +import { dotnet_browser_bind_js_import_st, dotnet_browser_invoke_js_function, dotnet_browser_invoke_jsimport_mt, dotnet_browser_invoke_jsimport_st } from "./invoke-js"; import { mono_interp_tier_prepare_jiterpreter, mono_wasm_free_method_data } from "./jiterpreter"; import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry"; import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue } from "./jiterpreter-jit-call"; -import { mono_wasm_resolve_or_reject_promise } from "./marshal-to-js"; +import { dotnet_browser_resolve_or_reject_promise } from "./marshal-to-js"; import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling"; import { mono_wasm_asm_loaded, mono_wasm_process_current_pid } from "./startup"; -import { mono_log_warn, mono_wasm_console_clear, mono_wasm_trace_logger } from "./logging"; -import { mono_wasm_browser_entropy } from "./crypto"; -import { mono_wasm_cancel_promise } from "./cancelable-promise"; +import { mono_log_warn, dotnet_browser_console_clear, mono_wasm_trace_logger } from "./logging"; +import { dotnet_browser_entropy } from "./crypto"; +import { dotnet_browser_cancel_promise } from "./cancelable-promise"; import { mono_wasm_start_deputy_thread_async, mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_unregistered, - mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, mono_wasm_install_js_worker_interop, mono_wasm_uninstall_js_worker_interop, mono_wasm_start_io_thread_async, mono_wasm_warn_about_blocking_wait + mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, mono_wasm_install_js_worker_interop, dotnet_browser_uninstall_js_worker_interop, mono_wasm_start_io_thread_async, dotnet_browser_warn_about_blocking_wait } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; -import { mono_wasm_get_locale_info } from "./globalization-locale"; +import { dotnet_browser_get_locale_info } from "./globalization-locale"; import { mono_wasm_profiler_record, mono_wasm_profiler_now } from "./profiler"; import { ds_rt_websocket_create, ds_rt_websocket_send, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_close } from "./diagnostics"; @@ -45,9 +45,9 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ // corebindings.c mono_wasm_install_js_worker_interop, - mono_wasm_uninstall_js_worker_interop, - mono_wasm_invoke_jsimport_MT, - mono_wasm_warn_about_blocking_wait, + dotnet_browser_uninstall_js_worker_interop, + dotnet_browser_invoke_jsimport_mt, + dotnet_browser_warn_about_blocking_wait, ]; export const mono_wasm_imports = [ @@ -81,20 +81,20 @@ export const mono_wasm_imports = [ mono_wasm_set_entrypoint_breakpoint, // src/native/minipal/random.c - mono_wasm_browser_entropy, + dotnet_browser_entropy, // mono-proclib.c mono_wasm_process_current_pid, // corebindings.c - mono_wasm_console_clear, - mono_wasm_release_cs_owned_object, - mono_wasm_bind_js_import_ST, - mono_wasm_invoke_js_function, - mono_wasm_invoke_jsimport_ST, - mono_wasm_resolve_or_reject_promise, - mono_wasm_cancel_promise, - mono_wasm_get_locale_info, + dotnet_browser_console_clear, + dotnet_browser_release_cs_owned_object, + dotnet_browser_bind_js_import_st, + dotnet_browser_invoke_js_function, + dotnet_browser_invoke_jsimport_st, + dotnet_browser_resolve_or_reject_promise, + dotnet_browser_cancel_promise, + dotnet_browser_get_locale_info, //event pipe ds_rt_websocket_create, diff --git a/src/mono/browser/runtime/gc-common.h b/src/mono/browser/runtime/gc-common.h index 4432633db76459..4d075f5c95341a 100644 --- a/src/mono/browser/runtime/gc-common.h +++ b/src/mono/browser/runtime/gc-common.h @@ -67,7 +67,7 @@ copy_volatile (PPVOLATILE(MonoObject) destination, PPVOLATILE(MonoObject) source } EMSCRIPTEN_KEEPALIVE int -mono_wasm_register_root (char *start, size_t size, const char *name); +dotnet_browser_register_root (char *start, size_t size, const char *name); EMSCRIPTEN_KEEPALIVE void -mono_wasm_deregister_root (char *addr); \ No newline at end of file +dotnet_browser_unregister_root (char *addr); \ No newline at end of file diff --git a/src/mono/browser/runtime/gc-handles.ts b/src/mono/browser/runtime/gc-handles.ts index 4809b00cc56ccb..0528aeb9ddaa33 100644 --- a/src/mono/browser/runtime/gc-handles.ts +++ b/src/mono/browser/runtime/gc-handles.ts @@ -105,7 +105,7 @@ export function register_with_jsv_handle (js_obj: any, jsv_handle: JSHandle) { } // note: in MT, this is called from locked JSProxyContext. Don't call anything that would need locking. -export function mono_wasm_release_cs_owned_object (js_handle: JSHandle): void { +export function dotnet_browser_release_cs_owned_object (js_handle: JSHandle): void { let obj: any; if (is_js_handle(js_handle)) { obj = _cs_owned_objects_by_js_handle[js_handle]; diff --git a/src/mono/browser/runtime/globalization-locale.ts b/src/mono/browser/runtime/globalization-locale.ts index 5bacd6cf4231ab..2f80e9dd9314ac 100644 --- a/src/mono/browser/runtime/globalization-locale.ts +++ b/src/mono/browser/runtime/globalization-locale.ts @@ -25,7 +25,7 @@ function normalizeLocale (locale: string | null) { } } -export function mono_wasm_get_locale_info (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr { +export function dotnet_browser_get_locale_info (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr { try { const localeNameOriginal = utf16ToString(locale, (locale + 2 * localeLength)); const localeName = normalizeLocale(localeNameOriginal); diff --git a/src/mono/browser/runtime/invoke-cs.ts b/src/mono/browser/runtime/invoke-cs.ts index 89da4c4c04b0e2..82a6e02aadb25d 100644 --- a/src/mono/browser/runtime/invoke-cs.ts +++ b/src/mono/browser/runtime/invoke-cs.ts @@ -379,7 +379,7 @@ function _walk_exports_to_set_function (assembly: string, namespace: string, cla scope[`${methodname}.${signature_hash}`] = fn; } -export async function mono_wasm_get_assembly_exports (assembly: string): Promise { +export async function dotnet_browser_get_assembly_exports (assembly: string): Promise { assert_js_interop(); const result = exportsByAssembly.get(assembly); if (!result) { diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index 777fdb2d329af1..57b7b8fbe460ce 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -21,7 +21,7 @@ import { stringToUTF16Ptr } from "./strings"; export const js_import_wrapper_by_fn_handle: Function[] = [null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached. -export function mono_wasm_bind_js_import_ST (signature: JSFunctionSignature): VoidPtr { +export function dotnet_browser_bind_js_import_st (signature: JSFunctionSignature): VoidPtr { if (WasmEnableThreads) return VoidPtrNull; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -33,7 +33,7 @@ export function mono_wasm_bind_js_import_ST (signature: JSFunctionSignature): Vo } } -export function mono_wasm_invoke_jsimport_MT (signature: JSFunctionSignature, args: JSMarshalerArguments) { +export function dotnet_browser_invoke_jsimport_mt (signature: JSFunctionSignature, args: JSMarshalerArguments) { if (!WasmEnableThreads) return; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -73,7 +73,7 @@ export function mono_wasm_invoke_jsimport_MT (signature: JSFunctionSignature, ar bound_fn(args); } -export function mono_wasm_invoke_jsimport_ST (function_handle: JSFnHandle, args: JSMarshalerArguments): void { +export function dotnet_browser_invoke_jsimport_st (function_handle: JSFnHandle, args: JSMarshalerArguments): void { if (WasmEnableThreads) return; loaderHelpers.assert_runtime_running(); args = fixupPointer(args, 0); @@ -360,11 +360,11 @@ type BindingClosure = { arg_cleanup: (Function | undefined)[] } -export function mono_wasm_invoke_js_function (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { - invoke_later_when_on_ui_thread_sync(() => mono_wasm_invoke_js_function_impl(bound_function_js_handle, args), args); +export function dotnet_browser_invoke_js_function (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { + invoke_later_when_on_ui_thread_sync(() => dotnet_browser_invoke_js_function_impl(bound_function_js_handle, args), args); } -export function mono_wasm_invoke_js_function_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { +export function dotnet_browser_invoke_js_function_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { loaderHelpers.assert_runtime_running(); const bound_fn = mono_wasm_get_jsobj_from_js_handle(bound_function_js_handle); mono_assert(bound_fn && typeof (bound_fn) === "function" && bound_fn[bound_js_function_symbol], () => `Bound function handle expected ${bound_function_js_handle}`); diff --git a/src/mono/browser/runtime/logging.ts b/src/mono/browser/runtime/logging.ts index 5518069c3ac7ae..93243bc755aa5d 100644 --- a/src/mono/browser/runtime/logging.ts +++ b/src/mono/browser/runtime/logging.ts @@ -212,6 +212,6 @@ export function mono_wasm_get_func_id_to_name_mappings () { return [...wasm_func_map.values()]; } -export function mono_wasm_console_clear () { +export function dotnet_browser_console_clear () { console.clear(); } diff --git a/src/mono/browser/runtime/marshal-to-cs.ts b/src/mono/browser/runtime/marshal-to-cs.ts index 326905214f9778..49e7e16d2a4bae 100644 --- a/src/mono/browser/runtime/marshal-to-cs.ts +++ b/src/mono/browser/runtime/marshal-to-cs.ts @@ -464,7 +464,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling strings by reference is not supported in multithreaded mode"); - cwraps.mono_wasm_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.dotnet_browser_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); @@ -475,7 +475,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.mono_wasm_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.dotnet_browser_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); diff --git a/src/mono/browser/runtime/marshal-to-js.ts b/src/mono/browser/runtime/marshal-to-js.ts index 29d9f56ff6fb3a..02a85face53934 100644 --- a/src/mono/browser/runtime/marshal-to-js.ts +++ b/src/mono/browser/runtime/marshal-to-js.ts @@ -6,7 +6,7 @@ import BuildConfiguration from "consts:configuration"; import WasmEnableJsInteropByValue from "consts:wasmEnableJsInteropByValue"; import cwraps from "./cwraps"; -import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, mono_wasm_release_cs_owned_object, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; +import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, dotnet_browser_release_cs_owned_object, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; import { loaderHelpers, mono_assert } from "./globals"; import { ManagedObject, ManagedError, @@ -271,7 +271,7 @@ export function end_marshal_task_to_js (args: JSMarshalerArguments, res_converte // otherwise drop the eagerPromise's handle const js_handle = mono_wasm_get_js_handle(eagerPromise); - mono_wasm_release_cs_owned_object(js_handle); + dotnet_browser_release_cs_owned_object(js_handle); // get the synchronous result const promise = try_marshal_sync_task_to_js(res, type, res_converter); @@ -331,16 +331,16 @@ function create_task_holder (res_converter?: MarshalerToJs) { } else { mono_assert(false, () => `Unexpected type ${type}`); } - mono_wasm_release_cs_owned_object(js_handle); + dotnet_browser_release_cs_owned_object(js_handle); }); return holder; } -export function mono_wasm_resolve_or_reject_promise (args: JSMarshalerArguments): void { - // rejection/resolution should not arrive earlier than the promise created by marshaling in mono_wasm_invoke_jsimport_MT - invoke_later_when_on_ui_thread_async(() => mono_wasm_resolve_or_reject_promise_impl(args)); +export function dotnet_browser_resolve_or_reject_promise (args: JSMarshalerArguments): void { + // rejection/resolution should not arrive earlier than the promise created by marshaling in dotnet_browser_invoke_jsimport_mt + invoke_later_when_on_ui_thread_async(() => dotnet_browser_resolve_or_reject_promise_impl(args)); } -export function mono_wasm_resolve_or_reject_promise_impl (args: JSMarshalerArguments): void { +export function dotnet_browser_resolve_or_reject_promise_impl (args: JSMarshalerArguments): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise resolution/rejection can't be propagated to managed code, mono runtime already exited."); return; @@ -506,7 +506,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling string by reference is not supported in multithreaded mode"); - cwraps.mono_wasm_deregister_root(buffer_ptr); + cwraps.dotnet_browser_unregister_root(buffer_ptr); } } else if (element_type == MarshalerType.Object) { result = new Array(length); @@ -516,7 +516,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.mono_wasm_deregister_root(buffer_ptr); + cwraps.dotnet_browser_unregister_root(buffer_ptr); } } else if (element_type == MarshalerType.JSObject) { result = new Array(length); diff --git a/src/mono/browser/runtime/pthreads/index.ts b/src/mono/browser/runtime/pthreads/index.ts index 87ed1b006184db..1b22a396390f2f 100644 --- a/src/mono/browser/runtime/pthreads/index.ts +++ b/src/mono/browser/runtime/pthreads/index.ts @@ -8,7 +8,7 @@ export { mono_wasm_main_thread_ptr, mono_wasm_pthread_ptr, update_thread_info, isMonoThreadMessage, monoThreadInfo, } from "./shared"; -export { mono_wasm_install_js_worker_interop, mono_wasm_uninstall_js_worker_interop } from "./worker-interop"; +export { mono_wasm_install_js_worker_interop, dotnet_browser_uninstall_js_worker_interop } from "./worker-interop"; export { mono_wasm_dump_threads, postCancelThreads, populateEmscriptenPool, mono_wasm_init_threads, @@ -23,7 +23,7 @@ export { export { mono_wasm_start_deputy_thread_async } from "./deputy-thread"; export { mono_wasm_start_io_thread_async } from "./io-thread"; -export function mono_wasm_warn_about_blocking_wait (ptr: number, length: number) { +export function dotnet_browser_warn_about_blocking_wait (ptr: number, length: number) { const warning = utf16ToString(ptr, ptr + (length * 2)); mono_log_warn(warning); } diff --git a/src/mono/browser/runtime/pthreads/worker-interop.ts b/src/mono/browser/runtime/pthreads/worker-interop.ts index 35a8ff61a8a1fa..f900a33715c55e 100644 --- a/src/mono/browser/runtime/pthreads/worker-interop.ts +++ b/src/mono/browser/runtime/pthreads/worker-interop.ts @@ -31,7 +31,7 @@ export function mono_wasm_install_js_worker_interop (context_gc_handle: GCHandle } } -export function mono_wasm_uninstall_js_worker_interop (): void { +export function dotnet_browser_uninstall_js_worker_interop (): void { if (!WasmEnableThreads) return; mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "JS interop is not installed on this worker."); mono_assert(runtimeHelpers.proxyGCHandle, "JSSynchronizationContext is not installed on this worker."); diff --git a/src/mono/browser/runtime/roots.ts b/src/mono/browser/runtime/roots.ts index 5b81331c29ff25..a4f39dfd4a7423 100644 --- a/src/mono/browser/runtime/roots.ts +++ b/src/mono/browser/runtime/roots.ts @@ -176,7 +176,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { this.__count = capacity; this.length = capacity; mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when creating a GC root"); - this.__handle = cwraps.mono_wasm_register_root(offset, capacityBytes, name || "noname"); + this.__handle = cwraps.dotnet_browser_register_root(offset, capacityBytes, name || "noname"); this.__ownsAllocation = ownsAllocation; } @@ -236,7 +236,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { release (): void { if (this.__offset && this.__ownsAllocation) { mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when disposing a GC root"); - cwraps.mono_wasm_deregister_root(this.__offset); + cwraps.dotnet_browser_unregister_root(this.__offset); _zero_region(this.__offset, this.__count * 4); free(this.__offset); } diff --git a/src/mono/browser/runtime/web-socket.ts b/src/mono/browser/runtime/web-socket.ts index b26d5fff443826..532cd8c31a640f 100644 --- a/src/mono/browser/runtime/web-socket.ts +++ b/src/mono/browser/runtime/web-socket.ts @@ -517,7 +517,7 @@ function resolvedPromise (): Promise | null { // passing synchronous `null` as value of the result of the async JSImport function is not possible when there is message sent across threads. const resolved = Promise.resolve(); // the C# code in the BrowserWebSocket expects that promise returned from this code is instance of `ControllablePromise` - // so that C# side could call `mono_wasm_cancel_promise` on it. + // so that C# side could call `dotnet_browser_cancel_promise` on it. // in practice the `resolve()` callback would arrive before the `reject()` of the cancelation. return wrap_as_cancelable(resolved); } diff --git a/src/mono/mono/metadata/gc.c b/src/mono/mono/metadata/gc.c index 7065b6fe85fabd..061f232c7f605e 100644 --- a/src/mono/mono/metadata/gc.c +++ b/src/mono/mono/metadata/gc.c @@ -668,7 +668,7 @@ mono_gc_finalize_notify (void) #if defined(HOST_WASI) && defined(DISABLE_THREADS) mono_runtime_do_background_work (); #elif defined(HOST_WASM) && defined(DISABLE_THREADS) - mono_main_thread_schedule_background_job (mono_runtime_do_background_work); + dotnet_browser_main_thread_schedule_background_job (mono_runtime_do_background_work); #else mono_coop_sem_post (&finalizer_sem); #endif diff --git a/src/mono/mono/metadata/sgen-mono.c b/src/mono/mono/metadata/sgen-mono.c index e7611b1b98deb4..86ec8d7ca6d887 100644 --- a/src/mono/mono/metadata/sgen-mono.c +++ b/src/mono/mono/metadata/sgen-mono.c @@ -2888,7 +2888,7 @@ sgen_client_binary_protocol_collection_end (int minor_gc_count, int generation, void sgen_client_schedule_background_job (void (*cb)(void)) { - mono_main_thread_schedule_background_job (cb); + dotnet_browser_main_thread_schedule_background_job (cb); } #endif diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index be863e82f73f30..563edd5e1af613 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -456,7 +456,7 @@ EMSCRIPTEN_KEEPALIVE void mono_background_exec (void); EMSCRIPTEN_KEEPALIVE void mono_wasm_ds_exec (void); extern void mono_wasm_schedule_timer (int shortestDueTimeMs); #else -extern void mono_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); +extern void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS G_END_DECLS @@ -621,7 +621,7 @@ mono_wasm_execute_timer (void) } void -mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs) +dotnet_browser_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs) { // NOTE: here the `timerHandler` callback is [UnmanagedCallersOnly] which wraps it with MONO_ENTER_GC_UNSAFE/MONO_EXIT_GC_UNSAFE @@ -637,10 +637,10 @@ mono_arch_register_icall (void) { #ifdef HOST_BROWSER #ifdef DISABLE_THREADS - mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", mono_wasm_main_thread_schedule_timer); - mono_add_internal_call_internal ("System.Threading.ThreadPool::MainThreadScheduleBackgroundJob", mono_main_thread_schedule_background_job); + mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", dotnet_browser_main_thread_schedule_timer); + mono_add_internal_call_internal ("System.Threading.ThreadPool::MainThreadScheduleBackgroundJob", dotnet_browser_main_thread_schedule_background_job); #else - mono_add_internal_call_internal ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleSynchronizationContext", mono_target_thread_schedule_synchronization_context); + mono_add_internal_call_internal ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleSynchronizationContext", dotnet_browser_target_thread_schedule_synchronization_context); #endif /* DISABLE_THREADS */ #endif /* HOST_BROWSER */ } diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index a3c1c56f506533..7b00b97756f77d 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -106,7 +106,7 @@ G_EXTERN_C int mono_wasm_get_debug_level (void); //JS functions imported that we use #ifdef DISABLE_THREADS void mono_wasm_execute_timer (void); -void mono_wasm_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs); +void dotnet_browser_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs); #endif // DISABLE_THREADS void mono_wasm_print_stack_trace (void); diff --git a/src/mono/mono/utils/mono-threads-wasm.c b/src/mono/mono/utils/mono-threads-wasm.c index 82a0d40be64833..740a0b4544a3c2 100644 --- a/src/mono/mono/utils/mono-threads-wasm.c +++ b/src/mono/mono/utils/mono-threads-wasm.c @@ -326,10 +326,10 @@ GSList *jobs; GSList *jobs_ds; void -mono_main_thread_schedule_background_job (background_job_cb cb) +dotnet_browser_main_thread_schedule_background_job (background_job_cb cb) { g_assert (cb); - THREADS_DEBUG ("mono_main_thread_schedule_background_job: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); + THREADS_DEBUG ("dotnet_browser_main_thread_schedule_background_job: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); if (!jobs) schedule_background_exec (); @@ -401,7 +401,7 @@ mono_wasm_ds_exec (void) extern void mono_wasm_schedule_synchronization_context (); -void mono_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread) +void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread) { emscripten_dispatch_to_thread_async ((pthread_t) target_thread, EM_FUNC_SIG_V, mono_wasm_schedule_synchronization_context, NULL); } diff --git a/src/mono/mono/utils/mono-threads.h b/src/mono/mono/utils/mono-threads.h index 44f2535fb3c45c..f38eab76d2622b 100644 --- a/src/mono/mono/utils/mono-threads.h +++ b/src/mono/mono/utils/mono-threads.h @@ -847,10 +847,10 @@ void mono_threads_join_unlock (void); typedef void (*background_job_cb)(void); typedef gsize (*ds_job_cb)(void* data); #ifdef DISABLE_THREADS -void mono_main_thread_schedule_background_job (background_job_cb cb); +void dotnet_browser_main_thread_schedule_background_job (background_job_cb cb); void mono_schedule_ds_job (ds_job_cb cb, void* data); #else -void mono_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); +void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS #endif diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 5d0a72250e9067..0e8db4e686f685 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -33,8 +33,8 @@ #include "driver.h" #include "runtime.h" -int mono_wasm_register_root (char *start, size_t size, const char *name); -void mono_wasm_deregister_root (char *addr); +int dotnet_browser_register_root (char *start, size_t size, const char *name); +void dotnet_browser_unregister_root (char *addr); char *monoeg_g_getenv(const char *variable); int monoeg_g_setenv(const char *variable, const char *value, int overwrite); diff --git a/src/mono/wasm/threads.md b/src/mono/wasm/threads.md index 798f03518efb23..b87ed3eee59468 100644 --- a/src/mono/wasm/threads.md +++ b/src/mono/wasm/threads.md @@ -62,10 +62,10 @@ Mono exposes these functions as `mono_threads_wasm_async_run_in_main_thread`, et ## Background tasks ## -The runtime has a number of tasks that are scheduled with `mono_main_thread_schedule_background_job` +The runtime has a number of tasks that are scheduled with `dotnet_browser_main_thread_schedule_background_job` (pumping the threadpool task queue, running GC finalizers, etc). -The background tasks will run on the main thread. Calling `mono_main_thread_schedule_background_job` on +The background tasks will run on the main thread. Calling `dotnet_browser_main_thread_schedule_background_job` on a worker thread will use `async_run_in_main_thread` to queue up work for the main thread. ## JS interop on dedicated threads ## diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 3c2b33ac7463b0..85bd0d37172255 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -78,11 +78,11 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 assert(buffer != NULL); #ifdef __EMSCRIPTEN__ - extern int32_t mono_wasm_browser_entropy(uint8_t* buffer, int32_t bufferLength); + extern int32_t dotnet_browser_entropy(uint8_t* buffer, int32_t bufferLength); static bool sMissingBrowserCrypto; if (!sMissingBrowserCrypto) { - int32_t bff = mono_wasm_browser_entropy(buffer, bufferLength); + int32_t bff = dotnet_browser_entropy(buffer, bufferLength); if (bff == -1) sMissingBrowserCrypto = true; else From 135bc3aab5dcc884c2f4a604f1fd768f0697e988 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Sat, 13 Sep 2025 10:21:58 +0200 Subject: [PATCH 2/7] more --- src/coreclr/vm/wasm/helpers.cpp | 4 ++-- src/mono/browser/runtime/crypto.ts | 2 +- src/mono/browser/runtime/exports-binding.ts | 4 ++-- src/native/minipal/random.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/vm/wasm/helpers.cpp b/src/coreclr/vm/wasm/helpers.cpp index 0cb4f33110a66f..7b3f8ef8a8e646 100644 --- a/src/coreclr/vm/wasm/helpers.cpp +++ b/src/coreclr/vm/wasm/helpers.cpp @@ -379,9 +379,9 @@ void _DacGlobals::Initialize() // Incorrectly typed temporary symbol to satisfy the linker. int g_pDebugger; -extern "C" int32_t dotnet_browser_entropy(uint8_t* buffer, int32_t bufferLength) +extern "C" int32_t dotnet_browser_random_bytes(uint8_t* buffer, int32_t bufferLength) { - PORTABILITY_ASSERT("dotnet_browser_entropy is not implemented"); + PORTABILITY_ASSERT("dotnet_browser_random_bytes is not implemented"); return -1; } diff --git a/src/mono/browser/runtime/crypto.ts b/src/mono/browser/runtime/crypto.ts index dc3a6d55ea9438..cf8401f35e1a3b 100644 --- a/src/mono/browser/runtime/crypto.ts +++ b/src/mono/browser/runtime/crypto.ts @@ -7,7 +7,7 @@ import { isSharedArrayBuffer, localHeapViewU8 } from "./memory"; const batchedQuotaMax = 65536; let warnOnce = true; -export function dotnet_browser_entropy (bufferPtr: number, bufferLength: number): number { +export function dotnet_browser_random_bytes (bufferPtr: number, bufferLength: number): number { if (!globalThis.crypto || !globalThis.crypto.getRandomValues) { if (warnOnce) { mono_log_warn("This engine doesn't support crypto.getRandomValues. Please use a modern version or provide polyfill for 'globalThis.crypto.getRandomValues'."); diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index 890779dbcedde4..79eafbef665628 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -13,7 +13,7 @@ import { dotnet_browser_resolve_or_reject_promise } from "./marshal-to-js"; import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling"; import { mono_wasm_asm_loaded, mono_wasm_process_current_pid } from "./startup"; import { mono_log_warn, dotnet_browser_console_clear, mono_wasm_trace_logger } from "./logging"; -import { dotnet_browser_entropy } from "./crypto"; +import { dotnet_browser_random_bytes } from "./crypto"; import { dotnet_browser_cancel_promise } from "./cancelable-promise"; import { @@ -81,7 +81,7 @@ export const mono_wasm_imports = [ mono_wasm_set_entrypoint_breakpoint, // src/native/minipal/random.c - dotnet_browser_entropy, + dotnet_browser_random_bytes, // mono-proclib.c mono_wasm_process_current_pid, diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 85bd0d37172255..8d20800b374194 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -78,11 +78,11 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 assert(buffer != NULL); #ifdef __EMSCRIPTEN__ - extern int32_t dotnet_browser_entropy(uint8_t* buffer, int32_t bufferLength); + extern int32_t dotnet_browser_random_bytes(uint8_t* buffer, int32_t bufferLength); static bool sMissingBrowserCrypto; if (!sMissingBrowserCrypto) { - int32_t bff = dotnet_browser_entropy(buffer, bufferLength); + int32_t bff = dotnet_browser_random_bytes(buffer, bufferLength); if (bff == -1) sMissingBrowserCrypto = true; else From fd6fe3e0b7fd738bb91da1a722a6a1d979fada5c Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 15 Sep 2025 10:57:36 +0200 Subject: [PATCH 3/7] update to follow existing style if native exports --- src/coreclr/vm/wasm/helpers.cpp | 4 +- .../JavaScript/Interop/JavaScriptExports.cs | 2 +- .../JavaScript/JSFunctionBinding.cs | 2 +- .../Marshaling/JSMarshalerArgument.Task.cs | 2 +- .../InteropServices/JavaScript/timers.mjs | 2 +- .../browser/runtime/cancelable-promise.ts | 8 +- src/mono/browser/runtime/corebindings.c | 128 +++++++++--------- src/mono/browser/runtime/crypto.ts | 2 +- src/mono/browser/runtime/cwraps.ts | 8 +- .../runtime/diagnostics/client-commands.ts | 2 +- src/mono/browser/runtime/driver.c | 6 +- src/mono/browser/runtime/export-api.ts | 4 +- src/mono/browser/runtime/exports-binding.ts | 52 +++---- src/mono/browser/runtime/exports.ts | 4 +- src/mono/browser/runtime/gc-common.h | 4 +- src/mono/browser/runtime/gc-handles.ts | 2 +- .../browser/runtime/globalization-locale.ts | 2 +- src/mono/browser/runtime/invoke-cs.ts | 2 +- src/mono/browser/runtime/invoke-js.ts | 12 +- src/mono/browser/runtime/logging.ts | 2 +- src/mono/browser/runtime/marshal-to-cs.ts | 4 +- src/mono/browser/runtime/marshal-to-js.ts | 18 +-- src/mono/browser/runtime/pthreads/index.ts | 4 +- .../runtime/pthreads/worker-interop.ts | 4 +- src/mono/browser/runtime/rollup.config.js | 38 +++--- src/mono/browser/runtime/roots.ts | 4 +- src/mono/browser/runtime/scheduling.ts | 8 +- src/mono/browser/runtime/startup.ts | 2 +- src/mono/browser/runtime/types/internal.ts | 2 +- src/mono/browser/runtime/web-socket.ts | 2 +- src/mono/mono/metadata/gc.c | 2 +- src/mono/mono/metadata/sgen-mono.c | 2 +- src/mono/mono/mini/mini-wasm.c | 14 +- src/mono/mono/mini/mini-wasm.h | 2 +- src/mono/mono/utils/mono-proclib.c | 4 +- src/mono/mono/utils/mono-threads-wasm.c | 10 +- src/mono/mono/utils/mono-threads.h | 4 +- src/mono/wasi/runtime/driver.c | 4 +- src/mono/wasm/threads.md | 4 +- src/native/minipal/random.c | 4 +- 40 files changed, 193 insertions(+), 193 deletions(-) diff --git a/src/coreclr/vm/wasm/helpers.cpp b/src/coreclr/vm/wasm/helpers.cpp index 7b3f8ef8a8e646..23c8a03d13fe10 100644 --- a/src/coreclr/vm/wasm/helpers.cpp +++ b/src/coreclr/vm/wasm/helpers.cpp @@ -379,9 +379,9 @@ void _DacGlobals::Initialize() // Incorrectly typed temporary symbol to satisfy the linker. int g_pDebugger; -extern "C" int32_t dotnet_browser_random_bytes(uint8_t* buffer, int32_t bufferLength) +extern "C" int32_t SystemJS_RandomBytes(uint8_t* buffer, int32_t bufferLength) { - PORTABILITY_ASSERT("dotnet_browser_random_bytes is not implemented"); + PORTABILITY_ASSERT("SystemJS_RandomBytes is not implemented"); return -1; } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs index d24a18f247ef3b..d6bfbc7a4e6d9f 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs @@ -291,7 +291,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 -> dotnet_browser_install_js_worker_interop_wrapper + // note that this method is only executed when the caller is on another thread, via mono_wasm_invoke_jsexport_sync -> SystemJSInterop_InstallWebWorkerInterop ctx.IsPendingSynchronousCall = true; if (ctx.IsMainThread) { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs index b26f1f3e4e503d..39f6e6e5240eea 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs @@ -478,7 +478,7 @@ internal static unsafe void ResolveOrRejectPromise(JSProxyContext targetContext, // meaning JS side needs to dispose it exc.slot.ReceiverShouldFree = true; - // this copy is freed in dotnet_browser_resolve_or_reject_promise + // this copy is freed in SystemJSInterop_ResolveOrRejectPromise var bytes = sizeof(JSMarshalerArgument) * arguments.Length; void* cpy = (void*)Marshal.AllocHGlobal(bytes); arguments.CopyTo(new Span(cpy, arguments.Length)); 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 b5918b9b941dc1..92990d59ca2e47 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 @@ -425,7 +425,7 @@ private bool CanMarshalTaskResultOnSameCall(JSProxyContext ctx) } // Otherwise this is JSExport return value and we can't use the args buffer, because the args buffer arrived in async message and nobody is reading after this. - // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `dotnet_browser_resolve_or_reject_promise_post` + // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `SystemJSInterop_ResolveOrRejectPromisePost` // there is JSVHandle in this arg return false; } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs index c2895c38bdcaa6..cf089962dd2bd6 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs @@ -8,7 +8,7 @@ export function log(message) { export function install() { const Module = globalThis.App.runtime.Module; - const measuredCallbackName = "mono_wasm_schedule_timer_tick"; + const measuredCallbackName = "SystemJS_ScheduleTimerJs_tick"; globalThis.registerCount = 0; globalThis.hitCount = 0; log("install") diff --git a/src/mono/browser/runtime/cancelable-promise.ts b/src/mono/browser/runtime/cancelable-promise.ts index 4bfcb688c6fcf4..67e643881ddff4 100644 --- a/src/mono/browser/runtime/cancelable-promise.ts +++ b/src/mono/browser/runtime/cancelable-promise.ts @@ -35,12 +35,12 @@ export function wrap_as_cancelable (inner: Promise): ControllablePromise dotnet_browser_cancel_promise_impl(task_holder_gc_handle)); +export function SystemJSInterop_CancelPromise (task_holder_gc_handle: GCHandle): void { + // cancelation should not arrive earlier than the promise created by marshaling in SystemJSInterop_InvokeJSImportSync + invoke_later_when_on_ui_thread_async(() => SystemJSInterop_CancelPromise_impl(task_holder_gc_handle)); } -export function dotnet_browser_cancel_promise_impl (task_holder_gc_handle: GCHandle): void { +export function SystemJSInterop_CancelPromise_impl (task_holder_gc_handle: GCHandle): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise can't be canceled, mono runtime already exited."); return; diff --git a/src/mono/browser/runtime/corebindings.c b/src/mono/browser/runtime/corebindings.c index b2104bc3d818be..e6fac9fa5e53bb 100644 --- a/src/mono/browser/runtime/corebindings.c +++ b/src/mono/browser/runtime/corebindings.c @@ -21,81 +21,81 @@ #include "gc-common.h" //JS funcs -extern void dotnet_browser_release_cs_owned_object (int js_handle); -extern void dotnet_browser_resolve_or_reject_promise (void *args); -extern void dotnet_browser_cancel_promise (int task_holder_gc_handle); -extern void dotnet_browser_console_clear (); +extern void SystemJSInterop_ReleaseCSOwnedObject (int js_handle); +extern void SystemJSInterop_ResolveOrRejectPromise (void *args); +extern void SystemJSInterop_CancelPromise (int task_holder_gc_handle); +extern void SystemJS_ConsoleClear (); extern void mono_wasm_set_entrypoint_breakpoint (int entry_point_metadata_token); extern void mono_wasm_trace_logger (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data); -extern void dotnet_browser_invoke_js_function (int function_js_handle, void *args); +extern void SystemJSInterop_InvokeJSFunction (int function_js_handle, void *args); extern int mono_runtime_run_module_cctor (MonoImage *image, MonoError *error); typedef void (*background_job_cb)(void); typedef int (*ds_job_cb)(void* data); -void dotnet_browser_bind_assembly_exports (char *assembly_name); -void dotnet_browser_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); -void dotnet_browser_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); +void SystemJSInterop_BindAssemblyExports (char *assembly_name); +void SystemJSInterop_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); +void SystemJSInterop_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); #ifndef DISABLE_THREADS -void dotnet_browser_release_cs_owned_object_post (pthread_t target_tid, int js_handle); -void dotnet_browser_resolve_or_reject_promise_post (pthread_t target_tid, void *args); -void dotnet_browser_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle); - -extern void mono_wasm_install_js_worker_interop (int context_gc_handle); -void dotnet_browser_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); -extern void dotnet_browser_uninstall_js_worker_interop (); -extern void dotnet_browser_invoke_jsimport_mt (void* signature, void* args); -void dotnet_browser_jsimport_async_post (pthread_t target_tid, void* signature, void* args); -void dotnet_browser_jsimport_sync_send (pthread_t target_tid, void* signature, void* args); -void dotnet_browser_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args); +void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle); +void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void *args); +void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle); + +extern void SystemJSInterop_InstallWebWorkerInteropJs (int context_gc_handle); +void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); +extern void SystemJSInterop_UninstallWebWorkerInterop (); +extern void SystemJSInterop_InvokeJSImportSync (void* signature, void* args); +void SystemJSInterop_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args); +void SystemJSInterop_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args); +void SystemJSInterop_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args); extern void mono_threads_wasm_async_run_in_target_thread_vi (pthread_t target_thread, void (*func) (gpointer), gpointer user_data1); extern void mono_threads_wasm_async_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer user_data2); extern void mono_threads_wasm_sync_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer args); -extern void dotnet_browser_warn_about_blocking_wait (void* ptr, int32_t length); +extern void SystemJS_WarnAboutBlockingWait (void* ptr, int32_t length); #else -extern void* dotnet_browser_bind_js_import_st (void *signature); -extern void dotnet_browser_invoke_jsimport_st (int function_handle, void *args); +extern void* SystemJSInterop_BindJSImportST (void *signature); +extern void SystemJSInterop_InvokeJSImportST (int function_handle, void *args); #endif /* DISABLE_THREADS */ // JS-based globalization -extern char16_t* dotnet_browser_get_locale_info (const uint16_t* locale, int32_t localeLength, const uint16_t* culture, int32_t cultureLength, const uint16_t* result, int32_t resultMaxLength, int *resultLength); +extern char16_t* SystemJS_GetLocaleInfo (const uint16_t* locale, int32_t localeLength, const uint16_t* culture, int32_t cultureLength, const uint16_t* result, int32_t resultMaxLength, int *resultLength); void bindings_initialize_internals (void) { #ifndef ENABLE_JS_INTEROP_BY_VALUE - mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", dotnet_browser_register_root); - mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", dotnet_browser_unregister_root); + mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", SystemJSInterop_RegisterGCRoot); + mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", SystemJSInterop_DeregisterGCRoot); #endif /* ENABLE_JS_INTEROP_BY_VALUE */ #ifndef DISABLE_THREADS - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", dotnet_browser_release_cs_owned_object_post); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", dotnet_browser_resolve_or_reject_promise_post); - mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", dotnet_browser_install_js_worker_interop_wrapper); - mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", dotnet_browser_uninstall_js_worker_interop); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", dotnet_browser_invoke_jsimport_mt); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", dotnet_browser_jsimport_sync_send); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", dotnet_browser_jsimport_async_post); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", dotnet_browser_invoke_js_function_send); - mono_add_internal_call ("Interop/Runtime::CancelPromisePost", dotnet_browser_cancel_promise_post); - mono_add_internal_call ("System.Threading.Thread::WarnAboutBlockingWait", dotnet_browser_warn_about_blocking_wait); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", SystemJSInterop_ReleaseCSOwnedObjectPost); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", SystemJSInterop_ResolveOrRejectPromisePost); + mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", SystemJSInterop_InstallWebWorkerInterop); + mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", SystemJSInterop_UninstallWebWorkerInterop); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", SystemJSInterop_InvokeJSImportSync); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", SystemJSInterop_InvokeJSImportSyncSend); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", SystemJSInterop_InvokeJSImportAsyncPost); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", SystemJSInterop_InvokeJSFunctionSend); + mono_add_internal_call ("Interop/Runtime::CancelPromisePost", SystemJSInterop_CancelPromisePost); + mono_add_internal_call ("System.Threading.Thread::WarnAboutBlockingWait", SystemJS_WarnAboutBlockingWait); #else - mono_add_internal_call ("Interop/Runtime::BindJSImportST", dotnet_browser_bind_js_import_st); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", dotnet_browser_invoke_jsimport_st); + mono_add_internal_call ("Interop/Runtime::BindJSImportST", SystemJSInterop_BindJSImportST); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", SystemJSInterop_InvokeJSImportST); #endif /* DISABLE_THREADS */ - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", dotnet_browser_release_cs_owned_object); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", dotnet_browser_resolve_or_reject_promise); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", dotnet_browser_invoke_js_function); - mono_add_internal_call ("Interop/Runtime::CancelPromise", dotnet_browser_cancel_promise); - mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", dotnet_browser_get_entry_point); - mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", dotnet_browser_bind_assembly_exports); - mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", dotnet_browser_get_assembly_export); - mono_add_internal_call ("System.ConsolePal::Clear", dotnet_browser_console_clear); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", SystemJSInterop_ReleaseCSOwnedObject); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", SystemJSInterop_ResolveOrRejectPromise); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", SystemJSInterop_InvokeJSFunction); + mono_add_internal_call ("Interop/Runtime::CancelPromise", SystemJSInterop_CancelPromise); + mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", SystemJSInterop_AssemblyGetEntryPoint); + mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", SystemJSInterop_BindAssemblyExports); + mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", SystemJSInterop_GetAssemblyExport); + mono_add_internal_call ("System.ConsolePal::Clear", SystemJS_ConsoleClear); // JS-based globalization - mono_add_internal_call ("Interop/JsGlobalization::GetLocaleInfo", dotnet_browser_get_locale_info); + mono_add_internal_call ("Interop/JsGlobalization::GetLocaleInfo", SystemJS_GetLocaleInfo); } static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name) @@ -112,7 +112,7 @@ static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name) return res; } -void dotnet_browser_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) +void SystemJSInterop_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) { assert (assembly_name); *method_out = NULL; @@ -176,7 +176,7 @@ void dotnet_browser_get_entry_point (char *assembly_name, int auto_insert_breakp *method_out = method; } -void dotnet_browser_bind_assembly_exports (char *assembly_name) +void SystemJSInterop_BindAssemblyExports (char *assembly_name) { MonoError error; MonoAssembly* assembly; @@ -200,7 +200,7 @@ void dotnet_browser_bind_assembly_exports (char *assembly_name) PVOLATILE(MonoObject) exc2 = NULL; store_volatile((MonoObject**)&temp_exc, (MonoObject*)mono_object_to_string ((MonoObject*)temp_exc, (MonoObject **)&exc2)); if (exc2) { - mono_wasm_trace_logger ("jsinterop", "critical", "dotnet_browser_bind_assembly_exports unexpected double fault", 1, NULL); + mono_wasm_trace_logger ("jsinterop", "critical", "SystemJSInterop_BindAssemblyExports unexpected double fault", 1, NULL); } else { mono_wasm_trace_logger ("jsinterop", "critical", mono_string_to_utf8((MonoString*)temp_exc), 1, NULL); } @@ -213,7 +213,7 @@ void dotnet_browser_bind_assembly_exports (char *assembly_name) } } -void dotnet_browser_get_assembly_export (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) +void SystemJSInterop_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) { MonoError error; MonoAssembly* assembly; @@ -251,48 +251,48 @@ void* before_sync_js_import; void* after_sync_js_import; void* synchronization_context_pump_handler; -void dotnet_browser_install_js_worker_interop_wrapper (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) +void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) { before_sync_js_import = beforeSyncJSImport; after_sync_js_import = afterSyncJSImport; synchronization_context_pump_handler = pumpHandler; - mono_wasm_install_js_worker_interop (context_gc_handle); + SystemJSInterop_InstallWebWorkerInteropJs (context_gc_handle); } // async -void dotnet_browser_release_cs_owned_object_post (pthread_t target_tid, int js_handle) +void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_release_cs_owned_object, (gpointer)js_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_ReleaseCSOwnedObject, (gpointer)js_handle); } // async -void dotnet_browser_resolve_or_reject_promise_post (pthread_t target_tid, void* args) +void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void* args) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_resolve_or_reject_promise, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_ResolveOrRejectPromise, (gpointer)args); } // async -void dotnet_browser_cancel_promise_post (pthread_t target_tid, int task_holder_gc_handle) +void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))dotnet_browser_cancel_promise, (gpointer)task_holder_gc_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_CancelPromise, (gpointer)task_holder_gc_handle); } // async -void dotnet_browser_jsimport_async_post (pthread_t target_tid, void* signature, void* args) +void SystemJSInterop_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_jsimport_mt, (gpointer)signature, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSImportSync, (gpointer)signature, (gpointer)args); } // sync -void dotnet_browser_jsimport_sync_send (pthread_t target_tid, void* signature, void* args) +void SystemJSInterop_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_jsimport_mt, (gpointer)signature, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSImportSync, (gpointer)signature, (gpointer)args); } // sync -void dotnet_browser_invoke_js_function_send (pthread_t target_tid, int function_js_handle, void *args) +void SystemJSInterop_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))dotnet_browser_invoke_js_function, (gpointer)function_js_handle, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSFunction, (gpointer)function_js_handle, (gpointer)args); } #endif /* DISABLE_THREADS */ diff --git a/src/mono/browser/runtime/crypto.ts b/src/mono/browser/runtime/crypto.ts index cf8401f35e1a3b..896783a40e3ad8 100644 --- a/src/mono/browser/runtime/crypto.ts +++ b/src/mono/browser/runtime/crypto.ts @@ -7,7 +7,7 @@ import { isSharedArrayBuffer, localHeapViewU8 } from "./memory"; const batchedQuotaMax = 65536; let warnOnce = true; -export function dotnet_browser_random_bytes (bufferPtr: number, bufferLength: number): number { +export function SystemJS_RandomBytes (bufferPtr: number, bufferLength: number): number { if (!globalThis.crypto || !globalThis.crypto.getRandomValues) { if (warnOnce) { mono_log_warn("This engine doesn't support crypto.getRandomValues. Please use a modern version or provide polyfill for 'globalThis.crypto.getRandomValues'."); diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index f13f304b0b542e..7f7b119750b73d 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -31,8 +31,8 @@ const threading_cwraps: SigLine[] = WasmEnableThreads ? [ // when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call const fn_signatures: SigLine[] = [ - [true, "dotnet_browser_register_root", "number", ["number", "number", "string"]], - [true, "dotnet_browser_unregister_root", null, ["number"]], + [true, "SystemJSInterop_RegisterGCRoot", "number", ["number", "number", "string"]], + [true, "SystemJSInterop_DeregisterGCRoot", null, ["number"]], [true, "mono_wasm_string_get_data_ref", null, ["number", "number", "number", "number"]], [true, "mono_wasm_set_is_debugger_attached", "void", ["bool"]], [true, "mono_wasm_send_dbg_command", "bool", ["number", "number", "number", "number", "number"]], @@ -158,8 +158,8 @@ export interface t_ProfilerCwraps { } export interface t_Cwraps { - dotnet_browser_register_root(start: VoidPtr, size: number, name: string): number; - dotnet_browser_unregister_root(addr: VoidPtr): void; + SystemJSInterop_RegisterGCRoot(start: VoidPtr, size: number, name: string): number; + SystemJSInterop_DeregisterGCRoot(addr: VoidPtr): void; mono_wasm_string_get_data_ref(stringRef: MonoStringRef, outChars: CharPtrPtr, outLengthBytes: Int32Ptr, outIsInterned: Int32Ptr): void; mono_wasm_set_is_debugger_attached(value: boolean): void; mono_wasm_send_dbg_command(id: number, command_set: number, command: number, data: VoidPtr, size: number): boolean; diff --git a/src/mono/browser/runtime/diagnostics/client-commands.ts b/src/mono/browser/runtime/diagnostics/client-commands.ts index 91f9db34a83a7f..c59bc5396b2a1c 100644 --- a/src/mono/browser/runtime/diagnostics/client-commands.ts +++ b/src/mono/browser/runtime/diagnostics/client-commands.ts @@ -21,7 +21,7 @@ export function advertise () { globalThis.crypto.getRandomValues(uuid); uuid[7] = (uuid[7] & 0xf) | 0x40;// version 4 - const pid = runtimeHelpers.mono_wasm_process_current_pid(); + const pid = runtimeHelpers.SystemJS_GetCurrentProcessId(); return Uint8Array.from([ ...advert1, diff --git a/src/mono/browser/runtime/driver.c b/src/mono/browser/runtime/driver.c index 2bfa644a9540e6..18018774eb73f9 100644 --- a/src/mono/browser/runtime/driver.c +++ b/src/mono/browser/runtime/driver.c @@ -77,17 +77,17 @@ MONO_API int mono_gc_register_root (char *start, size_t size, MonoGCDescriptor void mono_gc_deregister_root (char* addr); EMSCRIPTEN_KEEPALIVE int -dotnet_browser_register_root (char *start, size_t size, const char *name) +SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name) { int result; MONO_ENTER_GC_UNSAFE; - result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "dotnet_browser_register_root"); + result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "SystemJSInterop_RegisterGCRoot"); MONO_EXIT_GC_UNSAFE; return result; } EMSCRIPTEN_KEEPALIVE void -dotnet_browser_unregister_root (char *addr) +SystemJSInterop_DeregisterGCRoot (char *addr) { MONO_ENTER_GC_UNSAFE; mono_gc_deregister_root (addr); diff --git a/src/mono/browser/runtime/export-api.ts b/src/mono/browser/runtime/export-api.ts index 00ac8e3d659658..ec730c7e3bc8c7 100644 --- a/src/mono/browser/runtime/export-api.ts +++ b/src/mono/browser/runtime/export-api.ts @@ -3,7 +3,7 @@ import type { MonoConfig, APIType } from "./types"; -import { dotnet_browser_get_assembly_exports } from "./invoke-cs"; +import { SystemJSInterop_GetAssemblyExports } from "./invoke-cs"; import { mono_wasm_set_module_imports } from "./invoke-js"; import { getB32, getB8, getF32, getF64, getI16, getI32, getI52, getI64Big, getI8, getU16, getU32, getU52, getU8, localHeapViewF32, localHeapViewF64, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewI8, localHeapViewU16, localHeapViewU32, localHeapViewU8, setB32, setB8, setF32, setF64, setI16, setI32, setI52, setI64Big, setI8, setU16, setU32, setU52, setU8 } from "./memory"; import { mono_run_main, mono_run_main_and_exit } from "./run"; @@ -16,7 +16,7 @@ export function export_api (): any { runMainAndExit: mono_run_main_and_exit, exit: loaderHelpers.mono_exit, setEnvironmentVariable: mono_wasm_setenv, - getAssemblyExports: dotnet_browser_get_assembly_exports, + getAssemblyExports: SystemJSInterop_GetAssemblyExports, setModuleImports: mono_wasm_set_module_imports, getConfig: (): MonoConfig => { return runtimeHelpers.config; diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index 79eafbef665628..3b5ae940c16d48 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -4,26 +4,26 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug"; -import { dotnet_browser_release_cs_owned_object } from "./gc-handles"; -import { dotnet_browser_bind_js_import_st, dotnet_browser_invoke_js_function, dotnet_browser_invoke_jsimport_mt, dotnet_browser_invoke_jsimport_st } from "./invoke-js"; +import { SystemJSInterop_ReleaseCSOwnedObject } from "./gc-handles"; +import { SystemJSInterop_BindJSImportST, SystemJSInterop_InvokeJSFunction, SystemJSInterop_InvokeJSImportSync, SystemJSInterop_InvokeJSImportST } from "./invoke-js"; import { mono_interp_tier_prepare_jiterpreter, mono_wasm_free_method_data } from "./jiterpreter"; import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry"; import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue } from "./jiterpreter-jit-call"; -import { dotnet_browser_resolve_or_reject_promise } from "./marshal-to-js"; -import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling"; -import { mono_wasm_asm_loaded, mono_wasm_process_current_pid } from "./startup"; -import { mono_log_warn, dotnet_browser_console_clear, mono_wasm_trace_logger } from "./logging"; -import { dotnet_browser_random_bytes } from "./crypto"; -import { dotnet_browser_cancel_promise } from "./cancelable-promise"; +import { SystemJSInterop_ResolveOrRejectPromise } from "./marshal-to-js"; +import { SystemJS_ScheduleTimerJs, SystemJS_ScheduleBackgroundJobJs } from "./scheduling"; +import { mono_wasm_asm_loaded, SystemJS_GetCurrentProcessId } from "./startup"; +import { mono_log_warn, SystemJS_ConsoleClear, mono_wasm_trace_logger } from "./logging"; +import { SystemJS_RandomBytes } from "./crypto"; +import { SystemJSInterop_CancelPromise } from "./cancelable-promise"; import { mono_wasm_start_deputy_thread_async, mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_unregistered, - mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, mono_wasm_install_js_worker_interop, dotnet_browser_uninstall_js_worker_interop, mono_wasm_start_io_thread_async, dotnet_browser_warn_about_blocking_wait + mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropJs, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; -import { dotnet_browser_get_locale_info } from "./globalization-locale"; +import { SystemJS_GetLocaleInfo } from "./globalization-locale"; import { mono_wasm_profiler_record, mono_wasm_profiler_now } from "./profiler"; import { ds_rt_websocket_create, ds_rt_websocket_send, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_close } from "./diagnostics"; @@ -44,15 +44,15 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ mono_wasm_dump_threads, // corebindings.c - mono_wasm_install_js_worker_interop, - dotnet_browser_uninstall_js_worker_interop, - dotnet_browser_invoke_jsimport_mt, - dotnet_browser_warn_about_blocking_wait, + SystemJSInterop_InstallWebWorkerInteropJs, + SystemJSInterop_UninstallWebWorkerInterop, + SystemJSInterop_InvokeJSImportSync, + SystemJS_WarnAboutBlockingWait, ]; export const mono_wasm_imports = [ // mini-wasm.c - mono_wasm_schedule_timer, + SystemJS_ScheduleTimerJs, // mini-wasm-debugger.c mono_wasm_asm_loaded, @@ -61,7 +61,7 @@ export const mono_wasm_imports = [ mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause, // mono-threads-wasm.c - schedule_background_exec, + SystemJS_ScheduleBackgroundJobJs, // interp.c and jiterpreter.c mono_interp_tier_prepare_jiterpreter, @@ -81,20 +81,20 @@ export const mono_wasm_imports = [ mono_wasm_set_entrypoint_breakpoint, // src/native/minipal/random.c - dotnet_browser_random_bytes, + SystemJS_RandomBytes, // mono-proclib.c - mono_wasm_process_current_pid, + SystemJS_GetCurrentProcessId, // corebindings.c - dotnet_browser_console_clear, - dotnet_browser_release_cs_owned_object, - dotnet_browser_bind_js_import_st, - dotnet_browser_invoke_js_function, - dotnet_browser_invoke_jsimport_st, - dotnet_browser_resolve_or_reject_promise, - dotnet_browser_cancel_promise, - dotnet_browser_get_locale_info, + SystemJS_ConsoleClear, + SystemJSInterop_ReleaseCSOwnedObject, + SystemJSInterop_BindJSImportST, + SystemJSInterop_InvokeJSFunction, + SystemJSInterop_InvokeJSImportST, + SystemJSInterop_ResolveOrRejectPromise, + SystemJSInterop_CancelPromise, + SystemJS_GetLocaleInfo, //event pipe ds_rt_websocket_create, diff --git a/src/mono/browser/runtime/exports.ts b/src/mono/browser/runtime/exports.ts index af519bc4b908aa..95d464a64b068a 100644 --- a/src/mono/browser/runtime/exports.ts +++ b/src/mono/browser/runtime/exports.ts @@ -11,7 +11,7 @@ import { type RuntimeAPI } from "./types"; import { Module, exportedRuntimeAPI, loaderHelpers, passEmscriptenInternals, runtimeHelpers, setRuntimeGlobals, } from "./globals"; import { GlobalObjects, RuntimeHelpers } from "./types/internal"; -import { configureEmscriptenStartup, configureRuntimeStartup, configureWorkerStartup, mono_wasm_process_current_pid } from "./startup"; +import { configureEmscriptenStartup, configureRuntimeStartup, configureWorkerStartup, SystemJS_GetCurrentProcessId } from "./startup"; import { create_weak_ref } from "./weak-ref"; import { export_internal } from "./exports-internal"; @@ -42,7 +42,7 @@ function initializeExports (globalObjects: GlobalObjects): RuntimeAPI { jiterpreter_dump_stats, forceDisposeProxies, utf8ToString, - mono_wasm_process_current_pid, + SystemJS_GetCurrentProcessId, mono_background_exec: () => tcwraps.mono_background_exec(), mono_wasm_ds_exec: () => tcwraps.mono_wasm_ds_exec(), }; diff --git a/src/mono/browser/runtime/gc-common.h b/src/mono/browser/runtime/gc-common.h index 4d075f5c95341a..9af1980d75aaf4 100644 --- a/src/mono/browser/runtime/gc-common.h +++ b/src/mono/browser/runtime/gc-common.h @@ -67,7 +67,7 @@ copy_volatile (PPVOLATILE(MonoObject) destination, PPVOLATILE(MonoObject) source } EMSCRIPTEN_KEEPALIVE int -dotnet_browser_register_root (char *start, size_t size, const char *name); +SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); EMSCRIPTEN_KEEPALIVE void -dotnet_browser_unregister_root (char *addr); \ No newline at end of file +SystemJSInterop_DeregisterGCRoot (char *addr); \ No newline at end of file diff --git a/src/mono/browser/runtime/gc-handles.ts b/src/mono/browser/runtime/gc-handles.ts index 0528aeb9ddaa33..c718177d677e47 100644 --- a/src/mono/browser/runtime/gc-handles.ts +++ b/src/mono/browser/runtime/gc-handles.ts @@ -105,7 +105,7 @@ export function register_with_jsv_handle (js_obj: any, jsv_handle: JSHandle) { } // note: in MT, this is called from locked JSProxyContext. Don't call anything that would need locking. -export function dotnet_browser_release_cs_owned_object (js_handle: JSHandle): void { +export function SystemJSInterop_ReleaseCSOwnedObject (js_handle: JSHandle): void { let obj: any; if (is_js_handle(js_handle)) { obj = _cs_owned_objects_by_js_handle[js_handle]; diff --git a/src/mono/browser/runtime/globalization-locale.ts b/src/mono/browser/runtime/globalization-locale.ts index 2f80e9dd9314ac..716ad2e6820ff7 100644 --- a/src/mono/browser/runtime/globalization-locale.ts +++ b/src/mono/browser/runtime/globalization-locale.ts @@ -25,7 +25,7 @@ function normalizeLocale (locale: string | null) { } } -export function dotnet_browser_get_locale_info (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr { +export function SystemJS_GetLocaleInfo (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr { try { const localeNameOriginal = utf16ToString(locale, (locale + 2 * localeLength)); const localeName = normalizeLocale(localeNameOriginal); diff --git a/src/mono/browser/runtime/invoke-cs.ts b/src/mono/browser/runtime/invoke-cs.ts index 82a6e02aadb25d..23320c5a4153e9 100644 --- a/src/mono/browser/runtime/invoke-cs.ts +++ b/src/mono/browser/runtime/invoke-cs.ts @@ -379,7 +379,7 @@ function _walk_exports_to_set_function (assembly: string, namespace: string, cla scope[`${methodname}.${signature_hash}`] = fn; } -export async function dotnet_browser_get_assembly_exports (assembly: string): Promise { +export async function SystemJSInterop_GetAssemblyExports (assembly: string): Promise { assert_js_interop(); const result = exportsByAssembly.get(assembly); if (!result) { diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index 57b7b8fbe460ce..c3430a80d96552 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -21,7 +21,7 @@ import { stringToUTF16Ptr } from "./strings"; export const js_import_wrapper_by_fn_handle: Function[] = [null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached. -export function dotnet_browser_bind_js_import_st (signature: JSFunctionSignature): VoidPtr { +export function SystemJSInterop_BindJSImportST (signature: JSFunctionSignature): VoidPtr { if (WasmEnableThreads) return VoidPtrNull; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -33,7 +33,7 @@ export function dotnet_browser_bind_js_import_st (signature: JSFunctionSignature } } -export function dotnet_browser_invoke_jsimport_mt (signature: JSFunctionSignature, args: JSMarshalerArguments) { +export function SystemJSInterop_InvokeJSImportSync (signature: JSFunctionSignature, args: JSMarshalerArguments) { if (!WasmEnableThreads) return; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -73,7 +73,7 @@ export function dotnet_browser_invoke_jsimport_mt (signature: JSFunctionSignatur bound_fn(args); } -export function dotnet_browser_invoke_jsimport_st (function_handle: JSFnHandle, args: JSMarshalerArguments): void { +export function SystemJSInterop_InvokeJSImportST (function_handle: JSFnHandle, args: JSMarshalerArguments): void { if (WasmEnableThreads) return; loaderHelpers.assert_runtime_running(); args = fixupPointer(args, 0); @@ -360,11 +360,11 @@ type BindingClosure = { arg_cleanup: (Function | undefined)[] } -export function dotnet_browser_invoke_js_function (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { - invoke_later_when_on_ui_thread_sync(() => dotnet_browser_invoke_js_function_impl(bound_function_js_handle, args), args); +export function SystemJSInterop_InvokeJSFunction (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { + invoke_later_when_on_ui_thread_sync(() => SystemJSInterop_InvokeJSFunction_impl(bound_function_js_handle, args), args); } -export function dotnet_browser_invoke_js_function_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { +export function SystemJSInterop_InvokeJSFunction_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { loaderHelpers.assert_runtime_running(); const bound_fn = mono_wasm_get_jsobj_from_js_handle(bound_function_js_handle); mono_assert(bound_fn && typeof (bound_fn) === "function" && bound_fn[bound_js_function_symbol], () => `Bound function handle expected ${bound_function_js_handle}`); diff --git a/src/mono/browser/runtime/logging.ts b/src/mono/browser/runtime/logging.ts index 93243bc755aa5d..acb184e9630cbf 100644 --- a/src/mono/browser/runtime/logging.ts +++ b/src/mono/browser/runtime/logging.ts @@ -212,6 +212,6 @@ export function mono_wasm_get_func_id_to_name_mappings () { return [...wasm_func_map.values()]; } -export function dotnet_browser_console_clear () { +export function SystemJS_ConsoleClear () { console.clear(); } diff --git a/src/mono/browser/runtime/marshal-to-cs.ts b/src/mono/browser/runtime/marshal-to-cs.ts index 49e7e16d2a4bae..61f8b6753cc9da 100644 --- a/src/mono/browser/runtime/marshal-to-cs.ts +++ b/src/mono/browser/runtime/marshal-to-cs.ts @@ -464,7 +464,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling strings by reference is not supported in multithreaded mode"); - cwraps.dotnet_browser_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.SystemJSInterop_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); @@ -475,7 +475,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.dotnet_browser_register_root(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.SystemJSInterop_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); diff --git a/src/mono/browser/runtime/marshal-to-js.ts b/src/mono/browser/runtime/marshal-to-js.ts index 02a85face53934..dfa6622fbdde90 100644 --- a/src/mono/browser/runtime/marshal-to-js.ts +++ b/src/mono/browser/runtime/marshal-to-js.ts @@ -6,7 +6,7 @@ import BuildConfiguration from "consts:configuration"; import WasmEnableJsInteropByValue from "consts:wasmEnableJsInteropByValue"; import cwraps from "./cwraps"; -import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, dotnet_browser_release_cs_owned_object, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; +import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, SystemJSInterop_ReleaseCSOwnedObject, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; import { loaderHelpers, mono_assert } from "./globals"; import { ManagedObject, ManagedError, @@ -271,7 +271,7 @@ export function end_marshal_task_to_js (args: JSMarshalerArguments, res_converte // otherwise drop the eagerPromise's handle const js_handle = mono_wasm_get_js_handle(eagerPromise); - dotnet_browser_release_cs_owned_object(js_handle); + SystemJSInterop_ReleaseCSOwnedObject(js_handle); // get the synchronous result const promise = try_marshal_sync_task_to_js(res, type, res_converter); @@ -331,16 +331,16 @@ function create_task_holder (res_converter?: MarshalerToJs) { } else { mono_assert(false, () => `Unexpected type ${type}`); } - dotnet_browser_release_cs_owned_object(js_handle); + SystemJSInterop_ReleaseCSOwnedObject(js_handle); }); return holder; } -export function dotnet_browser_resolve_or_reject_promise (args: JSMarshalerArguments): void { - // rejection/resolution should not arrive earlier than the promise created by marshaling in dotnet_browser_invoke_jsimport_mt - invoke_later_when_on_ui_thread_async(() => dotnet_browser_resolve_or_reject_promise_impl(args)); +export function SystemJSInterop_ResolveOrRejectPromise (args: JSMarshalerArguments): void { + // rejection/resolution should not arrive earlier than the promise created by marshaling in SystemJSInterop_InvokeJSImportSync + invoke_later_when_on_ui_thread_async(() => SystemJSInterop_ResolveOrRejectPromise_impl(args)); } -export function dotnet_browser_resolve_or_reject_promise_impl (args: JSMarshalerArguments): void { +export function SystemJSInterop_ResolveOrRejectPromise_impl (args: JSMarshalerArguments): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise resolution/rejection can't be propagated to managed code, mono runtime already exited."); return; @@ -506,7 +506,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling string by reference is not supported in multithreaded mode"); - cwraps.dotnet_browser_unregister_root(buffer_ptr); + cwraps.SystemJSInterop_DeregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.Object) { result = new Array(length); @@ -516,7 +516,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.dotnet_browser_unregister_root(buffer_ptr); + cwraps.SystemJSInterop_DeregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.JSObject) { result = new Array(length); diff --git a/src/mono/browser/runtime/pthreads/index.ts b/src/mono/browser/runtime/pthreads/index.ts index 1b22a396390f2f..d0ccf13f1abe53 100644 --- a/src/mono/browser/runtime/pthreads/index.ts +++ b/src/mono/browser/runtime/pthreads/index.ts @@ -8,7 +8,7 @@ export { mono_wasm_main_thread_ptr, mono_wasm_pthread_ptr, update_thread_info, isMonoThreadMessage, monoThreadInfo, } from "./shared"; -export { mono_wasm_install_js_worker_interop, dotnet_browser_uninstall_js_worker_interop } from "./worker-interop"; +export { SystemJSInterop_InstallWebWorkerInteropJs, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; export { mono_wasm_dump_threads, postCancelThreads, populateEmscriptenPool, mono_wasm_init_threads, @@ -23,7 +23,7 @@ export { export { mono_wasm_start_deputy_thread_async } from "./deputy-thread"; export { mono_wasm_start_io_thread_async } from "./io-thread"; -export function dotnet_browser_warn_about_blocking_wait (ptr: number, length: number) { +export function SystemJS_WarnAboutBlockingWait (ptr: number, length: number) { const warning = utf16ToString(ptr, ptr + (length * 2)); mono_log_warn(warning); } diff --git a/src/mono/browser/runtime/pthreads/worker-interop.ts b/src/mono/browser/runtime/pthreads/worker-interop.ts index f900a33715c55e..3de56340956348 100644 --- a/src/mono/browser/runtime/pthreads/worker-interop.ts +++ b/src/mono/browser/runtime/pthreads/worker-interop.ts @@ -11,7 +11,7 @@ import { forceDisposeProxies } from "../gc-handles"; import { GCHandleNull, WorkerToMainMessageType } from "../types/internal"; import { monoThreadInfo, postMessageToMain, update_thread_info } from "./shared"; -export function mono_wasm_install_js_worker_interop (context_gc_handle: GCHandle): void { +export function SystemJSInterop_InstallWebWorkerInteropJs (context_gc_handle: GCHandle): void { if (!WasmEnableThreads) return; bindings_init(); mono_assert(!runtimeHelpers.proxyGCHandle, "JS interop should not be already installed on this worker."); @@ -31,7 +31,7 @@ export function mono_wasm_install_js_worker_interop (context_gc_handle: GCHandle } } -export function dotnet_browser_uninstall_js_worker_interop (): void { +export function SystemJSInterop_UninstallWebWorkerInterop (): void { if (!WasmEnableThreads) return; mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "JS interop is not installed on this worker."); mono_assert(runtimeHelpers.proxyGCHandle, "JSSynchronizationContext is not installed on this worker."); diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index e5c7d033ddb5dd..72d5f7199755e0 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -24,7 +24,7 @@ const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false; // because of stack walk at src/mono/browser/debugger/BrowserDebugProxy/MonoProxy.cs // and unit test at with timers.mjs -const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|mono_wasm_schedule_timer_tick)/; +const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|SystemJS_ScheduleTimerJs_tick)/; const keep_classnames = /(ManagedObject|ManagedError|Span|ArraySegment)/; const terserConfig = { compress: { @@ -120,7 +120,7 @@ const envConstants = { }; const locationCache = {}; -function sourcemapPathTransform (relativeSourcePath, sourcemapPath) { +function sourcemapPathTransform(relativeSourcePath, sourcemapPath) { let res = locationCache[relativeSourcePath]; if (res === undefined) { if (!isContinuousIntegrationBuild) { @@ -138,7 +138,7 @@ function sourcemapPathTransform (relativeSourcePath, sourcemapPath) { return res; } -function consts (dict) { +function consts(dict) { // implement rollup-plugin-const in terms of @rollup/plugin-virtual // It's basically the same thing except "consts" names all its modules with a "consts:" prefix, // and the virtual module always exports a single default binding (the const value). @@ -269,14 +269,14 @@ const allConfigs = [ .concat(diagnosticMockTypesConfig ? [diagnosticMockTypesConfig] : []); export default defineConfig(allConfigs); -function evalCodePlugin () { +function evalCodePlugin() { return { name: "evalCode", generateBundle: evalCode }; } -async function evalCode (options, bundle) { +async function evalCode(options, bundle) { try { const name = Object.keys(bundle)[0]; const asset = bundle[name]; @@ -292,7 +292,7 @@ async function evalCode (options, bundle) { // this would create .sha256 file next to the output file, so that we do not touch datetime of the file if it's same -> faster incremental build. -function writeOnChangePlugin () { +function writeOnChangePlugin() { return { name: "writeOnChange", generateBundle: writeWhenChanged @@ -300,7 +300,7 @@ function writeOnChangePlugin () { } // force always unix line ending -function alwaysLF () { +function alwaysLF() { return { name: "writeOnChange", generateBundle: (options, bundle) => { @@ -312,7 +312,7 @@ function alwaysLF () { }; } -async function writeWhenChanged (options, bundle) { +async function writeWhenChanged(options, bundle) { try { const name = Object.keys(bundle)[0]; const asset = bundle[name]; @@ -343,31 +343,31 @@ async function writeWhenChanged (options, bundle) { } } -function checkFileExists (file) { +function checkFileExists(file) { return fs.promises.access(file, fs.constants.F_OK) .then(() => true) .catch(() => false); } -function regexCheck (checks = []) { +function regexCheck(checks = []) { const filter = createFilter("**/*.ts"); return { name: "regexCheck", - renderChunk (code, chunk) { + renderChunk(code, chunk) { const id = chunk.fileName; if (!filter(id)) return null; return executeCheck(this, code, id); }, - transform (code, id) { + transform(code, id) { if (!filter(id)) return null; return executeCheck(this, code, id); } }; - function executeCheck (self, code, id) { + function executeCheck(self, code, id) { // self.warn("executeCheck" + id); for (const rep of checks) { const { pattern, failure } = rep; @@ -383,25 +383,25 @@ function regexCheck (checks = []) { } -function regexReplace (replacements = []) { +function regexReplace(replacements = []) { const filter = createFilter("**/*.ts"); return { name: "regexReplace", - renderChunk (code, chunk) { + renderChunk(code, chunk) { const id = chunk.fileName; if (!filter(id)) return null; return executeReplacement(this, code, id); }, - transform (code, id) { + transform(code, id) { if (!filter(id)) return null; return executeReplacement(this, code, id); } }; - function executeReplacement (_, code, id) { + function executeReplacement(_, code, id) { const magicString = new MagicString(code); if (!codeHasReplacements(code, id, magicString)) { return null; @@ -412,7 +412,7 @@ function regexReplace (replacements = []) { return result; } - function codeHasReplacements (code, id, magicString) { + function codeHasReplacements(code, id, magicString) { let result = false; let match; for (const rep of replacements) { @@ -432,7 +432,7 @@ function regexReplace (replacements = []) { } } -function onwarn (warning) { +function onwarn(warning) { if (warning.code === "CIRCULAR_DEPENDENCY") { return; } diff --git a/src/mono/browser/runtime/roots.ts b/src/mono/browser/runtime/roots.ts index a4f39dfd4a7423..4a597e3834949f 100644 --- a/src/mono/browser/runtime/roots.ts +++ b/src/mono/browser/runtime/roots.ts @@ -176,7 +176,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { this.__count = capacity; this.length = capacity; mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when creating a GC root"); - this.__handle = cwraps.dotnet_browser_register_root(offset, capacityBytes, name || "noname"); + this.__handle = cwraps.SystemJSInterop_RegisterGCRoot(offset, capacityBytes, name || "noname"); this.__ownsAllocation = ownsAllocation; } @@ -236,7 +236,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { release (): void { if (this.__offset && this.__ownsAllocation) { mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when disposing a GC root"); - cwraps.dotnet_browser_unregister_root(this.__offset); + cwraps.SystemJSInterop_DeregisterGCRoot(this.__offset); _zero_region(this.__offset, this.__count * 4); free(this.__offset); } diff --git a/src/mono/browser/runtime/scheduling.ts b/src/mono/browser/runtime/scheduling.ts index e04afa97b7acfe..f8cc616421145d 100644 --- a/src/mono/browser/runtime/scheduling.ts +++ b/src/mono/browser/runtime/scheduling.ts @@ -57,7 +57,7 @@ function mono_background_exec_until_done () { } let lastScheduledBackground: any = undefined; -export function schedule_background_exec (): void { +export function SystemJS_ScheduleBackgroundJobJs (): void { if (WasmEnableThreads) return; if (!lastScheduledBackground) { lastScheduledBackground = Module.safeSetTimeout(mono_background_exec_until_done, 0); @@ -65,16 +65,16 @@ export function schedule_background_exec (): void { } let lastScheduledTimeoutId: any = undefined; -export function mono_wasm_schedule_timer (shortestDueTimeMs: number): void { +export function SystemJS_ScheduleTimerJs (shortestDueTimeMs: number): void { if (WasmEnableThreads) return; if (lastScheduledTimeoutId) { globalThis.clearTimeout(lastScheduledTimeoutId); lastScheduledTimeoutId = undefined; } - lastScheduledTimeoutId = Module.safeSetTimeout(mono_wasm_schedule_timer_tick, shortestDueTimeMs); + lastScheduledTimeoutId = Module.safeSetTimeout(SystemJS_ScheduleTimerJs_tick, shortestDueTimeMs); } -function mono_wasm_schedule_timer_tick () { +function SystemJS_ScheduleTimerJs_tick () { if (WasmEnableThreads) return; Module.maybeExit(); forceThreadMemoryViewRefresh(); diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 9df5b30c434ad4..7fc2cefef1ca7d 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -36,7 +36,7 @@ import { replaceEmscriptenPThreadInit } from "./pthreads/worker-thread"; // make pid positive 31bit integer based on startup time const pid = ((globalThis.performance?.timeOrigin ?? Date.now()) | 0) & 0x7FFFFFFF; -export function mono_wasm_process_current_pid ():number { +export function SystemJS_GetCurrentProcessId ():number { return pid; } diff --git a/src/mono/browser/runtime/types/internal.ts b/src/mono/browser/runtime/types/internal.ts index 1e43b096125376..21952f0c01f187 100644 --- a/src/mono/browser/runtime/types/internal.ts +++ b/src/mono/browser/runtime/types/internal.ts @@ -242,7 +242,7 @@ export type RuntimeHelpers = { utf8ToString: (ptr: CharPtr) => string, mono_background_exec: () => void, mono_wasm_ds_exec: () => void, - mono_wasm_process_current_pid: () => number, + SystemJS_GetCurrentProcessId: () => number, } export type DiagnosticHelpers = { diff --git a/src/mono/browser/runtime/web-socket.ts b/src/mono/browser/runtime/web-socket.ts index 532cd8c31a640f..92fa329cee43a4 100644 --- a/src/mono/browser/runtime/web-socket.ts +++ b/src/mono/browser/runtime/web-socket.ts @@ -517,7 +517,7 @@ function resolvedPromise (): Promise | null { // passing synchronous `null` as value of the result of the async JSImport function is not possible when there is message sent across threads. const resolved = Promise.resolve(); // the C# code in the BrowserWebSocket expects that promise returned from this code is instance of `ControllablePromise` - // so that C# side could call `dotnet_browser_cancel_promise` on it. + // so that C# side could call `SystemJSInterop_CancelPromise` on it. // in practice the `resolve()` callback would arrive before the `reject()` of the cancelation. return wrap_as_cancelable(resolved); } diff --git a/src/mono/mono/metadata/gc.c b/src/mono/mono/metadata/gc.c index 061f232c7f605e..4a4f24f39d2be5 100644 --- a/src/mono/mono/metadata/gc.c +++ b/src/mono/mono/metadata/gc.c @@ -668,7 +668,7 @@ mono_gc_finalize_notify (void) #if defined(HOST_WASI) && defined(DISABLE_THREADS) mono_runtime_do_background_work (); #elif defined(HOST_WASM) && defined(DISABLE_THREADS) - dotnet_browser_main_thread_schedule_background_job (mono_runtime_do_background_work); + SystemJS_ScheduleBackgroundJob (mono_runtime_do_background_work); #else mono_coop_sem_post (&finalizer_sem); #endif diff --git a/src/mono/mono/metadata/sgen-mono.c b/src/mono/mono/metadata/sgen-mono.c index 86ec8d7ca6d887..07628a6de0a5c0 100644 --- a/src/mono/mono/metadata/sgen-mono.c +++ b/src/mono/mono/metadata/sgen-mono.c @@ -2888,7 +2888,7 @@ sgen_client_binary_protocol_collection_end (int minor_gc_count, int generation, void sgen_client_schedule_background_job (void (*cb)(void)) { - dotnet_browser_main_thread_schedule_background_job (cb); + SystemJS_ScheduleBackgroundJob (cb); } #endif diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 563edd5e1af613..9bcefa4571aa7a 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -454,9 +454,9 @@ G_BEGIN_DECLS EMSCRIPTEN_KEEPALIVE void mono_wasm_execute_timer (void); EMSCRIPTEN_KEEPALIVE void mono_background_exec (void); EMSCRIPTEN_KEEPALIVE void mono_wasm_ds_exec (void); -extern void mono_wasm_schedule_timer (int shortestDueTimeMs); +extern void SystemJS_ScheduleTimerJs (int shortestDueTimeMs); #else -extern void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); +extern void SystemJS_ScheduleSynchronizationContext(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS G_END_DECLS @@ -621,13 +621,13 @@ mono_wasm_execute_timer (void) } void -dotnet_browser_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs) +SystemJS_ScheduleTimer (void *timerHandler, int shortestDueTimeMs) { // NOTE: here the `timerHandler` callback is [UnmanagedCallersOnly] which wraps it with MONO_ENTER_GC_UNSAFE/MONO_EXIT_GC_UNSAFE g_assert (timerHandler); timer_handler = timerHandler; - mono_wasm_schedule_timer (shortestDueTimeMs); + SystemJS_ScheduleTimerJs (shortestDueTimeMs); } #endif #endif @@ -637,10 +637,10 @@ mono_arch_register_icall (void) { #ifdef HOST_BROWSER #ifdef DISABLE_THREADS - mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", dotnet_browser_main_thread_schedule_timer); - mono_add_internal_call_internal ("System.Threading.ThreadPool::MainThreadScheduleBackgroundJob", dotnet_browser_main_thread_schedule_background_job); + mono_add_internal_call_internal ("System.Threading.TimerQueue::MainThreadScheduleTimer", SystemJS_ScheduleTimer); + mono_add_internal_call_internal ("System.Threading.ThreadPool::MainThreadScheduleBackgroundJob", SystemJS_ScheduleBackgroundJob); #else - mono_add_internal_call_internal ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleSynchronizationContext", dotnet_browser_target_thread_schedule_synchronization_context); + mono_add_internal_call_internal ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleSynchronizationContext", SystemJS_ScheduleSynchronizationContext); #endif /* DISABLE_THREADS */ #endif /* HOST_BROWSER */ } diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index 7b00b97756f77d..59b5fa4980d6d2 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -106,7 +106,7 @@ G_EXTERN_C int mono_wasm_get_debug_level (void); //JS functions imported that we use #ifdef DISABLE_THREADS void mono_wasm_execute_timer (void); -void dotnet_browser_main_thread_schedule_timer (void *timerHandler, int shortestDueTimeMs); +void SystemJS_ScheduleTimer (void *timerHandler, int shortestDueTimeMs); #endif // DISABLE_THREADS void mono_wasm_print_stack_trace (void); diff --git a/src/mono/mono/utils/mono-proclib.c b/src/mono/mono/utils/mono-proclib.c index 0daec1915691c0..d20bb3c903f727 100644 --- a/src/mono/mono/utils/mono-proclib.c +++ b/src/mono/mono/utils/mono-proclib.c @@ -30,7 +30,7 @@ #endif #if defined(HOST_BROWSER) -int mono_wasm_process_current_pid (); +int SystemJS_GetCurrentProcessId (); #endif int @@ -39,7 +39,7 @@ mono_process_current_pid (void) #ifdef HOST_WIN32 return (int) GetCurrentProcessId (); #elif defined(HOST_BROWSER) - return mono_wasm_process_current_pid (); + return SystemJS_GetCurrentProcessId (); #elif defined(HAVE_GETPID) return (int) getpid (); #elif defined(HOST_WASI) diff --git a/src/mono/mono/utils/mono-threads-wasm.c b/src/mono/mono/utils/mono-threads-wasm.c index 740a0b4544a3c2..c7f574a317fc3a 100644 --- a/src/mono/mono/utils/mono-threads-wasm.c +++ b/src/mono/mono/utils/mono-threads-wasm.c @@ -316,7 +316,7 @@ mono_memory_barrier_process_wide (void) #ifdef HOST_BROWSER G_EXTERN_C -extern void schedule_background_exec (void); +extern void SystemJS_ScheduleBackgroundJobJs (void); // when this is called from ThreadPool, the cb would be System.Threading.ThreadPool.BackgroundJobHandler // when this is called from sgen it would be wrapper of sgen_perform_collection_inner @@ -326,13 +326,13 @@ GSList *jobs; GSList *jobs_ds; void -dotnet_browser_main_thread_schedule_background_job (background_job_cb cb) +SystemJS_ScheduleBackgroundJob (background_job_cb cb) { g_assert (cb); - THREADS_DEBUG ("dotnet_browser_main_thread_schedule_background_job: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); + THREADS_DEBUG ("SystemJS_ScheduleBackgroundJob: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); if (!jobs) - schedule_background_exec (); + SystemJS_ScheduleBackgroundJobJs (); if (!g_slist_find (jobs, (gconstpointer)cb)) jobs = g_slist_prepend (jobs, (gpointer)cb); @@ -401,7 +401,7 @@ mono_wasm_ds_exec (void) extern void mono_wasm_schedule_synchronization_context (); -void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread) +void SystemJS_ScheduleSynchronizationContext(MonoNativeThreadId target_thread) { emscripten_dispatch_to_thread_async ((pthread_t) target_thread, EM_FUNC_SIG_V, mono_wasm_schedule_synchronization_context, NULL); } diff --git a/src/mono/mono/utils/mono-threads.h b/src/mono/mono/utils/mono-threads.h index f38eab76d2622b..0cd83701898047 100644 --- a/src/mono/mono/utils/mono-threads.h +++ b/src/mono/mono/utils/mono-threads.h @@ -847,10 +847,10 @@ void mono_threads_join_unlock (void); typedef void (*background_job_cb)(void); typedef gsize (*ds_job_cb)(void* data); #ifdef DISABLE_THREADS -void dotnet_browser_main_thread_schedule_background_job (background_job_cb cb); +void SystemJS_ScheduleBackgroundJob (background_job_cb cb); void mono_schedule_ds_job (ds_job_cb cb, void* data); #else -void dotnet_browser_target_thread_schedule_synchronization_context(MonoNativeThreadId target_thread); +void SystemJS_ScheduleSynchronizationContext(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS #endif diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 0e8db4e686f685..647600d3dfbd9d 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -33,8 +33,8 @@ #include "driver.h" #include "runtime.h" -int dotnet_browser_register_root (char *start, size_t size, const char *name); -void dotnet_browser_unregister_root (char *addr); +int SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); +void SystemJSInterop_DeregisterGCRoot (char *addr); char *monoeg_g_getenv(const char *variable); int monoeg_g_setenv(const char *variable, const char *value, int overwrite); diff --git a/src/mono/wasm/threads.md b/src/mono/wasm/threads.md index b87ed3eee59468..6e73bfb0b575e6 100644 --- a/src/mono/wasm/threads.md +++ b/src/mono/wasm/threads.md @@ -62,10 +62,10 @@ Mono exposes these functions as `mono_threads_wasm_async_run_in_main_thread`, et ## Background tasks ## -The runtime has a number of tasks that are scheduled with `dotnet_browser_main_thread_schedule_background_job` +The runtime has a number of tasks that are scheduled with `SystemJS_ScheduleBackgroundJob` (pumping the threadpool task queue, running GC finalizers, etc). -The background tasks will run on the main thread. Calling `dotnet_browser_main_thread_schedule_background_job` on +The background tasks will run on the main thread. Calling `SystemJS_ScheduleBackgroundJob` on a worker thread will use `async_run_in_main_thread` to queue up work for the main thread. ## JS interop on dedicated threads ## diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 8d20800b374194..4dae7f4d9c487a 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -78,11 +78,11 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 assert(buffer != NULL); #ifdef __EMSCRIPTEN__ - extern int32_t dotnet_browser_random_bytes(uint8_t* buffer, int32_t bufferLength); + extern int32_t SystemJS_RandomBytes(uint8_t* buffer, int32_t bufferLength); static bool sMissingBrowserCrypto; if (!sMissingBrowserCrypto) { - int32_t bff = dotnet_browser_random_bytes(buffer, bufferLength); + int32_t bff = SystemJS_RandomBytes(buffer, bufferLength); if (bff == -1) sMissingBrowserCrypto = true; else From 005f7c409c4047be7b25d09a1d9a2e0e2a5a6d38 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 15 Sep 2025 14:04:34 +0200 Subject: [PATCH 4/7] feedback: capitalize JS suffix --- .../Runtime/InteropServices/JavaScript/timers.mjs | 2 +- src/mono/browser/runtime/corebindings.c | 4 ++-- src/mono/browser/runtime/exports-binding.ts | 10 +++++----- src/mono/browser/runtime/pthreads/index.ts | 2 +- src/mono/browser/runtime/pthreads/worker-interop.ts | 2 +- src/mono/browser/runtime/rollup.config.js | 2 +- src/mono/browser/runtime/scheduling.ts | 8 ++++---- src/mono/mono/mini/mini-wasm.c | 4 ++-- src/mono/mono/utils/mono-threads-wasm.c | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs index cf089962dd2bd6..862a96cd663080 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs @@ -8,7 +8,7 @@ export function log(message) { export function install() { const Module = globalThis.App.runtime.Module; - const measuredCallbackName = "SystemJS_ScheduleTimerJs_tick"; + const measuredCallbackName = "SystemJS_ScheduleTimerJS_tick"; globalThis.registerCount = 0; globalThis.hitCount = 0; log("install") diff --git a/src/mono/browser/runtime/corebindings.c b/src/mono/browser/runtime/corebindings.c index e6fac9fa5e53bb..a8c0c9fa688ce5 100644 --- a/src/mono/browser/runtime/corebindings.c +++ b/src/mono/browser/runtime/corebindings.c @@ -43,7 +43,7 @@ void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_hand void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void *args); void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle); -extern void SystemJSInterop_InstallWebWorkerInteropJs (int context_gc_handle); +extern void SystemJSInterop_InstallWebWorkerInteropJS (int context_gc_handle); void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); extern void SystemJSInterop_UninstallWebWorkerInterop (); extern void SystemJSInterop_InvokeJSImportSync (void* signature, void* args); @@ -256,7 +256,7 @@ void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* befor before_sync_js_import = beforeSyncJSImport; after_sync_js_import = afterSyncJSImport; synchronization_context_pump_handler = pumpHandler; - SystemJSInterop_InstallWebWorkerInteropJs (context_gc_handle); + SystemJSInterop_InstallWebWorkerInteropJS (context_gc_handle); } // async diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index 3b5ae940c16d48..36a8ee4fcb80bc 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -10,7 +10,7 @@ import { mono_interp_tier_prepare_jiterpreter, mono_wasm_free_method_data } from import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry"; import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue } from "./jiterpreter-jit-call"; import { SystemJSInterop_ResolveOrRejectPromise } from "./marshal-to-js"; -import { SystemJS_ScheduleTimerJs, SystemJS_ScheduleBackgroundJobJs } from "./scheduling"; +import { SystemJS_ScheduleTimerJS, SystemJS_ScheduleBackgroundJobJS } from "./scheduling"; import { mono_wasm_asm_loaded, SystemJS_GetCurrentProcessId } from "./startup"; import { mono_log_warn, SystemJS_ConsoleClear, mono_wasm_trace_logger } from "./logging"; import { SystemJS_RandomBytes } from "./crypto"; @@ -19,7 +19,7 @@ import { SystemJSInterop_CancelPromise } from "./cancelable-promise"; import { mono_wasm_start_deputy_thread_async, mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_unregistered, - mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropJs, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait + mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropJS, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; @@ -44,7 +44,7 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ mono_wasm_dump_threads, // corebindings.c - SystemJSInterop_InstallWebWorkerInteropJs, + SystemJSInterop_InstallWebWorkerInteropJS, SystemJSInterop_UninstallWebWorkerInterop, SystemJSInterop_InvokeJSImportSync, SystemJS_WarnAboutBlockingWait, @@ -52,7 +52,7 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ export const mono_wasm_imports = [ // mini-wasm.c - SystemJS_ScheduleTimerJs, + SystemJS_ScheduleTimerJS, // mini-wasm-debugger.c mono_wasm_asm_loaded, @@ -61,7 +61,7 @@ export const mono_wasm_imports = [ mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause, // mono-threads-wasm.c - SystemJS_ScheduleBackgroundJobJs, + SystemJS_ScheduleBackgroundJobJS, // interp.c and jiterpreter.c mono_interp_tier_prepare_jiterpreter, diff --git a/src/mono/browser/runtime/pthreads/index.ts b/src/mono/browser/runtime/pthreads/index.ts index d0ccf13f1abe53..bfcae2b1befb37 100644 --- a/src/mono/browser/runtime/pthreads/index.ts +++ b/src/mono/browser/runtime/pthreads/index.ts @@ -8,7 +8,7 @@ export { mono_wasm_main_thread_ptr, mono_wasm_pthread_ptr, update_thread_info, isMonoThreadMessage, monoThreadInfo, } from "./shared"; -export { SystemJSInterop_InstallWebWorkerInteropJs, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; +export { SystemJSInterop_InstallWebWorkerInteropJS, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; export { mono_wasm_dump_threads, postCancelThreads, populateEmscriptenPool, mono_wasm_init_threads, diff --git a/src/mono/browser/runtime/pthreads/worker-interop.ts b/src/mono/browser/runtime/pthreads/worker-interop.ts index 3de56340956348..ab5d9d4cf8059c 100644 --- a/src/mono/browser/runtime/pthreads/worker-interop.ts +++ b/src/mono/browser/runtime/pthreads/worker-interop.ts @@ -11,7 +11,7 @@ import { forceDisposeProxies } from "../gc-handles"; import { GCHandleNull, WorkerToMainMessageType } from "../types/internal"; import { monoThreadInfo, postMessageToMain, update_thread_info } from "./shared"; -export function SystemJSInterop_InstallWebWorkerInteropJs (context_gc_handle: GCHandle): void { +export function SystemJSInterop_InstallWebWorkerInteropJS (context_gc_handle: GCHandle): void { if (!WasmEnableThreads) return; bindings_init(); mono_assert(!runtimeHelpers.proxyGCHandle, "JS interop should not be already installed on this worker."); diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index 72d5f7199755e0..b7c90a337b1654 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -24,7 +24,7 @@ const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false; // because of stack walk at src/mono/browser/debugger/BrowserDebugProxy/MonoProxy.cs // and unit test at with timers.mjs -const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|SystemJS_ScheduleTimerJs_tick)/; +const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|SystemJS_ScheduleTimerJS_tick)/; const keep_classnames = /(ManagedObject|ManagedError|Span|ArraySegment)/; const terserConfig = { compress: { diff --git a/src/mono/browser/runtime/scheduling.ts b/src/mono/browser/runtime/scheduling.ts index f8cc616421145d..1ac6e28f5a70ed 100644 --- a/src/mono/browser/runtime/scheduling.ts +++ b/src/mono/browser/runtime/scheduling.ts @@ -57,7 +57,7 @@ function mono_background_exec_until_done () { } let lastScheduledBackground: any = undefined; -export function SystemJS_ScheduleBackgroundJobJs (): void { +export function SystemJS_ScheduleBackgroundJobJS (): void { if (WasmEnableThreads) return; if (!lastScheduledBackground) { lastScheduledBackground = Module.safeSetTimeout(mono_background_exec_until_done, 0); @@ -65,16 +65,16 @@ export function SystemJS_ScheduleBackgroundJobJs (): void { } let lastScheduledTimeoutId: any = undefined; -export function SystemJS_ScheduleTimerJs (shortestDueTimeMs: number): void { +export function SystemJS_ScheduleTimerJS (shortestDueTimeMs: number): void { if (WasmEnableThreads) return; if (lastScheduledTimeoutId) { globalThis.clearTimeout(lastScheduledTimeoutId); lastScheduledTimeoutId = undefined; } - lastScheduledTimeoutId = Module.safeSetTimeout(SystemJS_ScheduleTimerJs_tick, shortestDueTimeMs); + lastScheduledTimeoutId = Module.safeSetTimeout(SystemJS_ScheduleTimerJS_tick, shortestDueTimeMs); } -function SystemJS_ScheduleTimerJs_tick () { +function SystemJS_ScheduleTimerJS_tick () { if (WasmEnableThreads) return; Module.maybeExit(); forceThreadMemoryViewRefresh(); diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 9bcefa4571aa7a..044bcf1b532e41 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -454,7 +454,7 @@ G_BEGIN_DECLS EMSCRIPTEN_KEEPALIVE void mono_wasm_execute_timer (void); EMSCRIPTEN_KEEPALIVE void mono_background_exec (void); EMSCRIPTEN_KEEPALIVE void mono_wasm_ds_exec (void); -extern void SystemJS_ScheduleTimerJs (int shortestDueTimeMs); +extern void SystemJS_ScheduleTimerJS (int shortestDueTimeMs); #else extern void SystemJS_ScheduleSynchronizationContext(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS @@ -627,7 +627,7 @@ SystemJS_ScheduleTimer (void *timerHandler, int shortestDueTimeMs) g_assert (timerHandler); timer_handler = timerHandler; - SystemJS_ScheduleTimerJs (shortestDueTimeMs); + SystemJS_ScheduleTimerJS (shortestDueTimeMs); } #endif #endif diff --git a/src/mono/mono/utils/mono-threads-wasm.c b/src/mono/mono/utils/mono-threads-wasm.c index c7f574a317fc3a..a028a3ff562b68 100644 --- a/src/mono/mono/utils/mono-threads-wasm.c +++ b/src/mono/mono/utils/mono-threads-wasm.c @@ -316,7 +316,7 @@ mono_memory_barrier_process_wide (void) #ifdef HOST_BROWSER G_EXTERN_C -extern void SystemJS_ScheduleBackgroundJobJs (void); +extern void SystemJS_ScheduleBackgroundJobJS (void); // when this is called from ThreadPool, the cb would be System.Threading.ThreadPool.BackgroundJobHandler // when this is called from sgen it would be wrapper of sgen_perform_collection_inner @@ -332,7 +332,7 @@ SystemJS_ScheduleBackgroundJob (background_job_cb cb) THREADS_DEBUG ("SystemJS_ScheduleBackgroundJob: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); if (!jobs) - SystemJS_ScheduleBackgroundJobJs (); + SystemJS_ScheduleBackgroundJobJS (); if (!g_slist_find (jobs, (gconstpointer)cb)) jobs = g_slist_prepend (jobs, (gpointer)cb); From 2734bbcae6c30d8526555e41b23e744ff7d15133 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 15 Sep 2025 16:26:49 +0200 Subject: [PATCH 5/7] - revert mono_wasm_schedule_timer_tick - fix SystemJSInterop_CancelPromiseImpl - JS -> Impl suffix - SystemJSInterop_UnregisterGCRoot - fix rollup.config --- src/coreclr/hosts/CMakeLists.txt | 6 --- .../InteropServices/JavaScript/timers.mjs | 2 +- .../browser/runtime/cancelable-promise.ts | 4 +- src/mono/browser/runtime/corebindings.c | 6 +-- src/mono/browser/runtime/cwraps.ts | 4 +- src/mono/browser/runtime/driver.c | 2 +- src/mono/browser/runtime/exports-binding.ts | 10 ++--- src/mono/browser/runtime/gc-common.h | 2 +- src/mono/browser/runtime/marshal-to-js.ts | 8 ++-- src/mono/browser/runtime/pthreads/index.ts | 2 +- .../runtime/pthreads/worker-interop.ts | 2 +- src/mono/browser/runtime/rollup.config.js | 38 +++++++++---------- src/mono/browser/runtime/roots.ts | 2 +- src/mono/browser/runtime/scheduling.ts | 8 ++-- src/mono/mono/mini/mini-wasm.c | 4 +- src/mono/mono/utils/mono-threads-wasm.c | 4 +- src/mono/wasi/runtime/driver.c | 2 +- 17 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/coreclr/hosts/CMakeLists.txt b/src/coreclr/hosts/CMakeLists.txt index 529a06b916760a..d9a78125c84d2a 100644 --- a/src/coreclr/hosts/CMakeLists.txt +++ b/src/coreclr/hosts/CMakeLists.txt @@ -3,9 +3,3 @@ include_directories(inc) if(CLR_CMAKE_HOST_WIN32) add_subdirectory(coreshim) endif(CLR_CMAKE_HOST_WIN32) - -if (CLR_CMAKE_TARGET_ARCH_WASM) - add_subdirectory(corewasmrun) -endif() - -add_subdirectory(corerun) \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs index 862a96cd663080..c2895c38bdcaa6 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/timers.mjs @@ -8,7 +8,7 @@ export function log(message) { export function install() { const Module = globalThis.App.runtime.Module; - const measuredCallbackName = "SystemJS_ScheduleTimerJS_tick"; + const measuredCallbackName = "mono_wasm_schedule_timer_tick"; globalThis.registerCount = 0; globalThis.hitCount = 0; log("install") diff --git a/src/mono/browser/runtime/cancelable-promise.ts b/src/mono/browser/runtime/cancelable-promise.ts index 67e643881ddff4..cf8078ca8061d3 100644 --- a/src/mono/browser/runtime/cancelable-promise.ts +++ b/src/mono/browser/runtime/cancelable-promise.ts @@ -37,10 +37,10 @@ export function wrap_as_cancelable (inner: Promise): ControllablePromise SystemJSInterop_CancelPromise_impl(task_holder_gc_handle)); + invoke_later_when_on_ui_thread_async(() => SystemJSInterop_CancelPromiseImpl(task_holder_gc_handle)); } -export function SystemJSInterop_CancelPromise_impl (task_holder_gc_handle: GCHandle): void { +export function SystemJSInterop_CancelPromiseImpl (task_holder_gc_handle: GCHandle): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise can't be canceled, mono runtime already exited."); return; diff --git a/src/mono/browser/runtime/corebindings.c b/src/mono/browser/runtime/corebindings.c index a8c0c9fa688ce5..fd8256dc01db95 100644 --- a/src/mono/browser/runtime/corebindings.c +++ b/src/mono/browser/runtime/corebindings.c @@ -43,7 +43,7 @@ void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_hand void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void *args); void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle); -extern void SystemJSInterop_InstallWebWorkerInteropJS (int context_gc_handle); +extern void SystemJSInterop_InstallWebWorkerInteropImpl (int context_gc_handle); void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); extern void SystemJSInterop_UninstallWebWorkerInterop (); extern void SystemJSInterop_InvokeJSImportSync (void* signature, void* args); @@ -66,7 +66,7 @@ void bindings_initialize_internals (void) { #ifndef ENABLE_JS_INTEROP_BY_VALUE mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", SystemJSInterop_RegisterGCRoot); - mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", SystemJSInterop_DeregisterGCRoot); + mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", SystemJSInterop_UnregisterGCRoot); #endif /* ENABLE_JS_INTEROP_BY_VALUE */ #ifndef DISABLE_THREADS @@ -256,7 +256,7 @@ void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* befor before_sync_js_import = beforeSyncJSImport; after_sync_js_import = afterSyncJSImport; synchronization_context_pump_handler = pumpHandler; - SystemJSInterop_InstallWebWorkerInteropJS (context_gc_handle); + SystemJSInterop_InstallWebWorkerInteropImpl (context_gc_handle); } // async diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index 7f7b119750b73d..8da6498460fbea 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -32,7 +32,7 @@ const threading_cwraps: SigLine[] = WasmEnableThreads ? [ // when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call const fn_signatures: SigLine[] = [ [true, "SystemJSInterop_RegisterGCRoot", "number", ["number", "number", "string"]], - [true, "SystemJSInterop_DeregisterGCRoot", null, ["number"]], + [true, "SystemJSInterop_UnregisterGCRoot", null, ["number"]], [true, "mono_wasm_string_get_data_ref", null, ["number", "number", "number", "number"]], [true, "mono_wasm_set_is_debugger_attached", "void", ["bool"]], [true, "mono_wasm_send_dbg_command", "bool", ["number", "number", "number", "number", "number"]], @@ -159,7 +159,7 @@ export interface t_ProfilerCwraps { export interface t_Cwraps { SystemJSInterop_RegisterGCRoot(start: VoidPtr, size: number, name: string): number; - SystemJSInterop_DeregisterGCRoot(addr: VoidPtr): void; + SystemJSInterop_UnregisterGCRoot(addr: VoidPtr): void; mono_wasm_string_get_data_ref(stringRef: MonoStringRef, outChars: CharPtrPtr, outLengthBytes: Int32Ptr, outIsInterned: Int32Ptr): void; mono_wasm_set_is_debugger_attached(value: boolean): void; mono_wasm_send_dbg_command(id: number, command_set: number, command: number, data: VoidPtr, size: number): boolean; diff --git a/src/mono/browser/runtime/driver.c b/src/mono/browser/runtime/driver.c index 18018774eb73f9..3deaf1859ea6e0 100644 --- a/src/mono/browser/runtime/driver.c +++ b/src/mono/browser/runtime/driver.c @@ -87,7 +87,7 @@ SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name) } EMSCRIPTEN_KEEPALIVE void -SystemJSInterop_DeregisterGCRoot (char *addr) +SystemJSInterop_UnregisterGCRoot (char *addr) { MONO_ENTER_GC_UNSAFE; mono_gc_deregister_root (addr); diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index 36a8ee4fcb80bc..b3192217416ff7 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -10,7 +10,7 @@ import { mono_interp_tier_prepare_jiterpreter, mono_wasm_free_method_data } from import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry"; import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue } from "./jiterpreter-jit-call"; import { SystemJSInterop_ResolveOrRejectPromise } from "./marshal-to-js"; -import { SystemJS_ScheduleTimerJS, SystemJS_ScheduleBackgroundJobJS } from "./scheduling"; +import { SystemJS_ScheduleTimerImpl, SystemJS_ScheduleBackgroundJobImpl } from "./scheduling"; import { mono_wasm_asm_loaded, SystemJS_GetCurrentProcessId } from "./startup"; import { mono_log_warn, SystemJS_ConsoleClear, mono_wasm_trace_logger } from "./logging"; import { SystemJS_RandomBytes } from "./crypto"; @@ -19,7 +19,7 @@ import { SystemJSInterop_CancelPromise } from "./cancelable-promise"; import { mono_wasm_start_deputy_thread_async, mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_unregistered, - mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropJS, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait + mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropImpl, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; @@ -44,7 +44,7 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ mono_wasm_dump_threads, // corebindings.c - SystemJSInterop_InstallWebWorkerInteropJS, + SystemJSInterop_InstallWebWorkerInteropImpl, SystemJSInterop_UninstallWebWorkerInterop, SystemJSInterop_InvokeJSImportSync, SystemJS_WarnAboutBlockingWait, @@ -52,7 +52,7 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ export const mono_wasm_imports = [ // mini-wasm.c - SystemJS_ScheduleTimerJS, + SystemJS_ScheduleTimerImpl, // mini-wasm-debugger.c mono_wasm_asm_loaded, @@ -61,7 +61,7 @@ export const mono_wasm_imports = [ mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause, // mono-threads-wasm.c - SystemJS_ScheduleBackgroundJobJS, + SystemJS_ScheduleBackgroundJobImpl, // interp.c and jiterpreter.c mono_interp_tier_prepare_jiterpreter, diff --git a/src/mono/browser/runtime/gc-common.h b/src/mono/browser/runtime/gc-common.h index 9af1980d75aaf4..910db2cb7a6466 100644 --- a/src/mono/browser/runtime/gc-common.h +++ b/src/mono/browser/runtime/gc-common.h @@ -70,4 +70,4 @@ EMSCRIPTEN_KEEPALIVE int SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); EMSCRIPTEN_KEEPALIVE void -SystemJSInterop_DeregisterGCRoot (char *addr); \ No newline at end of file +SystemJSInterop_UnregisterGCRoot (char *addr); \ No newline at end of file diff --git a/src/mono/browser/runtime/marshal-to-js.ts b/src/mono/browser/runtime/marshal-to-js.ts index dfa6622fbdde90..5a4ea305ebed08 100644 --- a/src/mono/browser/runtime/marshal-to-js.ts +++ b/src/mono/browser/runtime/marshal-to-js.ts @@ -338,9 +338,9 @@ function create_task_holder (res_converter?: MarshalerToJs) { export function SystemJSInterop_ResolveOrRejectPromise (args: JSMarshalerArguments): void { // rejection/resolution should not arrive earlier than the promise created by marshaling in SystemJSInterop_InvokeJSImportSync - invoke_later_when_on_ui_thread_async(() => SystemJSInterop_ResolveOrRejectPromise_impl(args)); + invoke_later_when_on_ui_thread_async(() => SystemJSInterop_ResolveOrRejectPromiseImpl(args)); } -export function SystemJSInterop_ResolveOrRejectPromise_impl (args: JSMarshalerArguments): void { +export function SystemJSInterop_ResolveOrRejectPromiseImpl (args: JSMarshalerArguments): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise resolution/rejection can't be propagated to managed code, mono runtime already exited."); return; @@ -506,7 +506,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling string by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_DeregisterGCRoot(buffer_ptr); + cwraps.SystemJSInterop_UnregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.Object) { result = new Array(length); @@ -516,7 +516,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_DeregisterGCRoot(buffer_ptr); + cwraps.SystemJSInterop_UnregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.JSObject) { result = new Array(length); diff --git a/src/mono/browser/runtime/pthreads/index.ts b/src/mono/browser/runtime/pthreads/index.ts index bfcae2b1befb37..ccb0867862f46a 100644 --- a/src/mono/browser/runtime/pthreads/index.ts +++ b/src/mono/browser/runtime/pthreads/index.ts @@ -8,7 +8,7 @@ export { mono_wasm_main_thread_ptr, mono_wasm_pthread_ptr, update_thread_info, isMonoThreadMessage, monoThreadInfo, } from "./shared"; -export { SystemJSInterop_InstallWebWorkerInteropJS, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; +export { SystemJSInterop_InstallWebWorkerInteropImpl, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; export { mono_wasm_dump_threads, postCancelThreads, populateEmscriptenPool, mono_wasm_init_threads, diff --git a/src/mono/browser/runtime/pthreads/worker-interop.ts b/src/mono/browser/runtime/pthreads/worker-interop.ts index ab5d9d4cf8059c..8d4fe6d9f2c527 100644 --- a/src/mono/browser/runtime/pthreads/worker-interop.ts +++ b/src/mono/browser/runtime/pthreads/worker-interop.ts @@ -11,7 +11,7 @@ import { forceDisposeProxies } from "../gc-handles"; import { GCHandleNull, WorkerToMainMessageType } from "../types/internal"; import { monoThreadInfo, postMessageToMain, update_thread_info } from "./shared"; -export function SystemJSInterop_InstallWebWorkerInteropJS (context_gc_handle: GCHandle): void { +export function SystemJSInterop_InstallWebWorkerInteropImpl (context_gc_handle: GCHandle): void { if (!WasmEnableThreads) return; bindings_init(); mono_assert(!runtimeHelpers.proxyGCHandle, "JS interop should not be already installed on this worker."); diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index b7c90a337b1654..e5c7d033ddb5dd 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -24,7 +24,7 @@ const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false; // because of stack walk at src/mono/browser/debugger/BrowserDebugProxy/MonoProxy.cs // and unit test at with timers.mjs -const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|SystemJS_ScheduleTimerJS_tick)/; +const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|mono_wasm_schedule_timer_tick)/; const keep_classnames = /(ManagedObject|ManagedError|Span|ArraySegment)/; const terserConfig = { compress: { @@ -120,7 +120,7 @@ const envConstants = { }; const locationCache = {}; -function sourcemapPathTransform(relativeSourcePath, sourcemapPath) { +function sourcemapPathTransform (relativeSourcePath, sourcemapPath) { let res = locationCache[relativeSourcePath]; if (res === undefined) { if (!isContinuousIntegrationBuild) { @@ -138,7 +138,7 @@ function sourcemapPathTransform(relativeSourcePath, sourcemapPath) { return res; } -function consts(dict) { +function consts (dict) { // implement rollup-plugin-const in terms of @rollup/plugin-virtual // It's basically the same thing except "consts" names all its modules with a "consts:" prefix, // and the virtual module always exports a single default binding (the const value). @@ -269,14 +269,14 @@ const allConfigs = [ .concat(diagnosticMockTypesConfig ? [diagnosticMockTypesConfig] : []); export default defineConfig(allConfigs); -function evalCodePlugin() { +function evalCodePlugin () { return { name: "evalCode", generateBundle: evalCode }; } -async function evalCode(options, bundle) { +async function evalCode (options, bundle) { try { const name = Object.keys(bundle)[0]; const asset = bundle[name]; @@ -292,7 +292,7 @@ async function evalCode(options, bundle) { // this would create .sha256 file next to the output file, so that we do not touch datetime of the file if it's same -> faster incremental build. -function writeOnChangePlugin() { +function writeOnChangePlugin () { return { name: "writeOnChange", generateBundle: writeWhenChanged @@ -300,7 +300,7 @@ function writeOnChangePlugin() { } // force always unix line ending -function alwaysLF() { +function alwaysLF () { return { name: "writeOnChange", generateBundle: (options, bundle) => { @@ -312,7 +312,7 @@ function alwaysLF() { }; } -async function writeWhenChanged(options, bundle) { +async function writeWhenChanged (options, bundle) { try { const name = Object.keys(bundle)[0]; const asset = bundle[name]; @@ -343,31 +343,31 @@ async function writeWhenChanged(options, bundle) { } } -function checkFileExists(file) { +function checkFileExists (file) { return fs.promises.access(file, fs.constants.F_OK) .then(() => true) .catch(() => false); } -function regexCheck(checks = []) { +function regexCheck (checks = []) { const filter = createFilter("**/*.ts"); return { name: "regexCheck", - renderChunk(code, chunk) { + renderChunk (code, chunk) { const id = chunk.fileName; if (!filter(id)) return null; return executeCheck(this, code, id); }, - transform(code, id) { + transform (code, id) { if (!filter(id)) return null; return executeCheck(this, code, id); } }; - function executeCheck(self, code, id) { + function executeCheck (self, code, id) { // self.warn("executeCheck" + id); for (const rep of checks) { const { pattern, failure } = rep; @@ -383,25 +383,25 @@ function regexCheck(checks = []) { } -function regexReplace(replacements = []) { +function regexReplace (replacements = []) { const filter = createFilter("**/*.ts"); return { name: "regexReplace", - renderChunk(code, chunk) { + renderChunk (code, chunk) { const id = chunk.fileName; if (!filter(id)) return null; return executeReplacement(this, code, id); }, - transform(code, id) { + transform (code, id) { if (!filter(id)) return null; return executeReplacement(this, code, id); } }; - function executeReplacement(_, code, id) { + function executeReplacement (_, code, id) { const magicString = new MagicString(code); if (!codeHasReplacements(code, id, magicString)) { return null; @@ -412,7 +412,7 @@ function regexReplace(replacements = []) { return result; } - function codeHasReplacements(code, id, magicString) { + function codeHasReplacements (code, id, magicString) { let result = false; let match; for (const rep of replacements) { @@ -432,7 +432,7 @@ function regexReplace(replacements = []) { } } -function onwarn(warning) { +function onwarn (warning) { if (warning.code === "CIRCULAR_DEPENDENCY") { return; } diff --git a/src/mono/browser/runtime/roots.ts b/src/mono/browser/runtime/roots.ts index 4a597e3834949f..3c2bc06a9c06f6 100644 --- a/src/mono/browser/runtime/roots.ts +++ b/src/mono/browser/runtime/roots.ts @@ -236,7 +236,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { release (): void { if (this.__offset && this.__ownsAllocation) { mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when disposing a GC root"); - cwraps.SystemJSInterop_DeregisterGCRoot(this.__offset); + cwraps.SystemJSInterop_UnregisterGCRoot(this.__offset); _zero_region(this.__offset, this.__count * 4); free(this.__offset); } diff --git a/src/mono/browser/runtime/scheduling.ts b/src/mono/browser/runtime/scheduling.ts index 1ac6e28f5a70ed..93dde2a5525281 100644 --- a/src/mono/browser/runtime/scheduling.ts +++ b/src/mono/browser/runtime/scheduling.ts @@ -57,7 +57,7 @@ function mono_background_exec_until_done () { } let lastScheduledBackground: any = undefined; -export function SystemJS_ScheduleBackgroundJobJS (): void { +export function SystemJS_ScheduleBackgroundJobImpl (): void { if (WasmEnableThreads) return; if (!lastScheduledBackground) { lastScheduledBackground = Module.safeSetTimeout(mono_background_exec_until_done, 0); @@ -65,16 +65,16 @@ export function SystemJS_ScheduleBackgroundJobJS (): void { } let lastScheduledTimeoutId: any = undefined; -export function SystemJS_ScheduleTimerJS (shortestDueTimeMs: number): void { +export function SystemJS_ScheduleTimerImpl (shortestDueTimeMs: number): void { if (WasmEnableThreads) return; if (lastScheduledTimeoutId) { globalThis.clearTimeout(lastScheduledTimeoutId); lastScheduledTimeoutId = undefined; } - lastScheduledTimeoutId = Module.safeSetTimeout(SystemJS_ScheduleTimerJS_tick, shortestDueTimeMs); + lastScheduledTimeoutId = Module.safeSetTimeout(mono_wasm_schedule_timer_tick, shortestDueTimeMs); } -function SystemJS_ScheduleTimerJS_tick () { +function mono_wasm_schedule_timer_tick () { if (WasmEnableThreads) return; Module.maybeExit(); forceThreadMemoryViewRefresh(); diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 044bcf1b532e41..b27a9835c4d3c2 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -454,7 +454,7 @@ G_BEGIN_DECLS EMSCRIPTEN_KEEPALIVE void mono_wasm_execute_timer (void); EMSCRIPTEN_KEEPALIVE void mono_background_exec (void); EMSCRIPTEN_KEEPALIVE void mono_wasm_ds_exec (void); -extern void SystemJS_ScheduleTimerJS (int shortestDueTimeMs); +extern void SystemJS_ScheduleTimerImpl (int shortestDueTimeMs); #else extern void SystemJS_ScheduleSynchronizationContext(MonoNativeThreadId target_thread); #endif // DISABLE_THREADS @@ -627,7 +627,7 @@ SystemJS_ScheduleTimer (void *timerHandler, int shortestDueTimeMs) g_assert (timerHandler); timer_handler = timerHandler; - SystemJS_ScheduleTimerJS (shortestDueTimeMs); + SystemJS_ScheduleTimerImpl (shortestDueTimeMs); } #endif #endif diff --git a/src/mono/mono/utils/mono-threads-wasm.c b/src/mono/mono/utils/mono-threads-wasm.c index a028a3ff562b68..f43e46c4ffa20a 100644 --- a/src/mono/mono/utils/mono-threads-wasm.c +++ b/src/mono/mono/utils/mono-threads-wasm.c @@ -316,7 +316,7 @@ mono_memory_barrier_process_wide (void) #ifdef HOST_BROWSER G_EXTERN_C -extern void SystemJS_ScheduleBackgroundJobJS (void); +extern void SystemJS_ScheduleBackgroundJobImpl (void); // when this is called from ThreadPool, the cb would be System.Threading.ThreadPool.BackgroundJobHandler // when this is called from sgen it would be wrapper of sgen_perform_collection_inner @@ -332,7 +332,7 @@ SystemJS_ScheduleBackgroundJob (background_job_cb cb) THREADS_DEBUG ("SystemJS_ScheduleBackgroundJob: thread %p queued job %p to current thread\n", (gpointer)pthread_self(), (gpointer) cb); if (!jobs) - SystemJS_ScheduleBackgroundJobJS (); + SystemJS_ScheduleBackgroundJobImpl (); if (!g_slist_find (jobs, (gconstpointer)cb)) jobs = g_slist_prepend (jobs, (gpointer)cb); diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 647600d3dfbd9d..0373e4a66570ea 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -34,7 +34,7 @@ #include "runtime.h" int SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); -void SystemJSInterop_DeregisterGCRoot (char *addr); +void SystemJSInterop_UnregisterGCRoot (char *addr); char *monoeg_g_getenv(const char *variable); int monoeg_g_setenv(const char *variable, const char *value, int overwrite); From e6e8778f3b9bb50aa6933b9c0946b6188f336d5b Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 15 Sep 2025 16:35:07 +0200 Subject: [PATCH 6/7] revert --- src/coreclr/hosts/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/hosts/CMakeLists.txt b/src/coreclr/hosts/CMakeLists.txt index d9a78125c84d2a..529a06b916760a 100644 --- a/src/coreclr/hosts/CMakeLists.txt +++ b/src/coreclr/hosts/CMakeLists.txt @@ -3,3 +3,9 @@ include_directories(inc) if(CLR_CMAKE_HOST_WIN32) add_subdirectory(coreshim) endif(CLR_CMAKE_HOST_WIN32) + +if (CLR_CMAKE_TARGET_ARCH_WASM) + add_subdirectory(corewasmrun) +endif() + +add_subdirectory(corerun) \ No newline at end of file From b011ecdd0b77de7a1722bdf90982a37855d190f2 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 15 Sep 2025 19:09:23 +0200 Subject: [PATCH 7/7] feedback SystemJSInterop_ -> SystemInteropJS_ --- .../JavaScript/Interop/JavaScriptExports.cs | 2 +- .../JavaScript/JSFunctionBinding.cs | 2 +- .../Marshaling/JSMarshalerArgument.Task.cs | 2 +- .../browser/runtime/cancelable-promise.ts | 8 +- src/mono/browser/runtime/corebindings.c | 116 +++++++++--------- src/mono/browser/runtime/cwraps.ts | 8 +- src/mono/browser/runtime/driver.c | 6 +- src/mono/browser/runtime/export-api.ts | 4 +- src/mono/browser/runtime/exports-binding.ts | 28 ++--- src/mono/browser/runtime/gc-common.h | 4 +- src/mono/browser/runtime/gc-handles.ts | 2 +- src/mono/browser/runtime/invoke-cs.ts | 2 +- src/mono/browser/runtime/invoke-js.ts | 12 +- src/mono/browser/runtime/marshal-to-cs.ts | 4 +- src/mono/browser/runtime/marshal-to-js.ts | 18 +-- src/mono/browser/runtime/pthreads/index.ts | 2 +- .../runtime/pthreads/worker-interop.ts | 4 +- src/mono/browser/runtime/roots.ts | 4 +- src/mono/browser/runtime/web-socket.ts | 2 +- src/mono/wasi/runtime/driver.c | 4 +- 20 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs index d6bfbc7a4e6d9f..559a7921352a3b 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs @@ -291,7 +291,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 -> SystemJSInterop_InstallWebWorkerInterop + // note that this method is only executed when the caller is on another thread, via mono_wasm_invoke_jsexport_sync -> SystemInteropJS_InstallWebWorkerInterop ctx.IsPendingSynchronousCall = true; if (ctx.IsMainThread) { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs index 39f6e6e5240eea..b7e4adf82ce3d0 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs @@ -478,7 +478,7 @@ internal static unsafe void ResolveOrRejectPromise(JSProxyContext targetContext, // meaning JS side needs to dispose it exc.slot.ReceiverShouldFree = true; - // this copy is freed in SystemJSInterop_ResolveOrRejectPromise + // this copy is freed in SystemInteropJS_ResolveOrRejectPromise var bytes = sizeof(JSMarshalerArgument) * arguments.Length; void* cpy = (void*)Marshal.AllocHGlobal(bytes); arguments.CopyTo(new Span(cpy, arguments.Length)); 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 92990d59ca2e47..38a8e20487571c 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 @@ -425,7 +425,7 @@ private bool CanMarshalTaskResultOnSameCall(JSProxyContext ctx) } // Otherwise this is JSExport return value and we can't use the args buffer, because the args buffer arrived in async message and nobody is reading after this. - // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `SystemJSInterop_ResolveOrRejectPromisePost` + // In such case the JS side already pre-created the Promise and we have to use it, to resolve it in separate call via `SystemInteropJS_ResolveOrRejectPromisePost` // there is JSVHandle in this arg return false; } diff --git a/src/mono/browser/runtime/cancelable-promise.ts b/src/mono/browser/runtime/cancelable-promise.ts index cf8078ca8061d3..81b19380f9c17f 100644 --- a/src/mono/browser/runtime/cancelable-promise.ts +++ b/src/mono/browser/runtime/cancelable-promise.ts @@ -35,12 +35,12 @@ export function wrap_as_cancelable (inner: Promise): ControllablePromise SystemJSInterop_CancelPromiseImpl(task_holder_gc_handle)); +export function SystemInteropJS_CancelPromise (task_holder_gc_handle: GCHandle): void { + // cancelation should not arrive earlier than the promise created by marshaling in SystemInteropJS_InvokeJSImportSync + invoke_later_when_on_ui_thread_async(() => SystemInteropJS_CancelPromiseImpl(task_holder_gc_handle)); } -export function SystemJSInterop_CancelPromiseImpl (task_holder_gc_handle: GCHandle): void { +export function SystemInteropJS_CancelPromiseImpl (task_holder_gc_handle: GCHandle): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise can't be canceled, mono runtime already exited."); return; diff --git a/src/mono/browser/runtime/corebindings.c b/src/mono/browser/runtime/corebindings.c index fd8256dc01db95..cc8c058f9a1294 100644 --- a/src/mono/browser/runtime/corebindings.c +++ b/src/mono/browser/runtime/corebindings.c @@ -21,42 +21,42 @@ #include "gc-common.h" //JS funcs -extern void SystemJSInterop_ReleaseCSOwnedObject (int js_handle); -extern void SystemJSInterop_ResolveOrRejectPromise (void *args); -extern void SystemJSInterop_CancelPromise (int task_holder_gc_handle); +extern void SystemInteropJS_ReleaseCSOwnedObject (int js_handle); +extern void SystemInteropJS_ResolveOrRejectPromise (void *args); +extern void SystemInteropJS_CancelPromise (int task_holder_gc_handle); extern void SystemJS_ConsoleClear (); extern void mono_wasm_set_entrypoint_breakpoint (int entry_point_metadata_token); extern void mono_wasm_trace_logger (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data); -extern void SystemJSInterop_InvokeJSFunction (int function_js_handle, void *args); +extern void SystemInteropJS_InvokeJSFunction (int function_js_handle, void *args); extern int mono_runtime_run_module_cctor (MonoImage *image, MonoError *error); typedef void (*background_job_cb)(void); typedef int (*ds_job_cb)(void* data); -void SystemJSInterop_BindAssemblyExports (char *assembly_name); -void SystemJSInterop_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); -void SystemJSInterop_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); +void SystemInteropJS_BindAssemblyExports (char *assembly_name); +void SystemInteropJS_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out); +void SystemInteropJS_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out); #ifndef DISABLE_THREADS -void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle); -void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void *args); -void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle); - -extern void SystemJSInterop_InstallWebWorkerInteropImpl (int context_gc_handle); -void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); -extern void SystemJSInterop_UninstallWebWorkerInterop (); -extern void SystemJSInterop_InvokeJSImportSync (void* signature, void* args); -void SystemJSInterop_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args); -void SystemJSInterop_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args); -void SystemJSInterop_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args); +void SystemInteropJS_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle); +void SystemInteropJS_ResolveOrRejectPromisePost (pthread_t target_tid, void *args); +void SystemInteropJS_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle); + +extern void SystemInteropJS_InstallWebWorkerInteropImpl (int context_gc_handle); +void SystemInteropJS_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler); +extern void SystemInteropJS_UninstallWebWorkerInterop (); +extern void SystemInteropJS_InvokeJSImportSync (void* signature, void* args); +void SystemInteropJS_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args); +void SystemInteropJS_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args); +void SystemInteropJS_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args); extern void mono_threads_wasm_async_run_in_target_thread_vi (pthread_t target_thread, void (*func) (gpointer), gpointer user_data1); extern void mono_threads_wasm_async_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer user_data2); extern void mono_threads_wasm_sync_run_in_target_thread_vii (pthread_t target_thread, void (*func) (gpointer, gpointer), gpointer user_data1, gpointer args); extern void SystemJS_WarnAboutBlockingWait (void* ptr, int32_t length); #else -extern void* SystemJSInterop_BindJSImportST (void *signature); -extern void SystemJSInterop_InvokeJSImportST (int function_handle, void *args); +extern void* SystemInteropJS_BindJSImportST (void *signature); +extern void SystemInteropJS_InvokeJSImportST (int function_handle, void *args); #endif /* DISABLE_THREADS */ // JS-based globalization @@ -65,33 +65,33 @@ extern char16_t* SystemJS_GetLocaleInfo (const uint16_t* locale, int32_t localeL void bindings_initialize_internals (void) { #ifndef ENABLE_JS_INTEROP_BY_VALUE - mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", SystemJSInterop_RegisterGCRoot); - mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", SystemJSInterop_UnregisterGCRoot); + mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", SystemInteropJS_RegisterGCRoot); + mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", SystemInteropJS_UnregisterGCRoot); #endif /* ENABLE_JS_INTEROP_BY_VALUE */ #ifndef DISABLE_THREADS - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", SystemJSInterop_ReleaseCSOwnedObjectPost); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", SystemJSInterop_ResolveOrRejectPromisePost); - mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", SystemJSInterop_InstallWebWorkerInterop); - mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", SystemJSInterop_UninstallWebWorkerInterop); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", SystemJSInterop_InvokeJSImportSync); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", SystemJSInterop_InvokeJSImportSyncSend); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", SystemJSInterop_InvokeJSImportAsyncPost); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", SystemJSInterop_InvokeJSFunctionSend); - mono_add_internal_call ("Interop/Runtime::CancelPromisePost", SystemJSInterop_CancelPromisePost); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObjectPost", SystemInteropJS_ReleaseCSOwnedObjectPost); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromisePost", SystemInteropJS_ResolveOrRejectPromisePost); + mono_add_internal_call ("Interop/Runtime::InstallWebWorkerInterop", SystemInteropJS_InstallWebWorkerInterop); + mono_add_internal_call ("Interop/Runtime::UninstallWebWorkerInterop", SystemInteropJS_UninstallWebWorkerInterop); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSync", SystemInteropJS_InvokeJSImportSync); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportSyncSend", SystemInteropJS_InvokeJSImportSyncSend); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportAsyncPost", SystemInteropJS_InvokeJSImportAsyncPost); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunctionSend", SystemInteropJS_InvokeJSFunctionSend); + mono_add_internal_call ("Interop/Runtime::CancelPromisePost", SystemInteropJS_CancelPromisePost); mono_add_internal_call ("System.Threading.Thread::WarnAboutBlockingWait", SystemJS_WarnAboutBlockingWait); #else - mono_add_internal_call ("Interop/Runtime::BindJSImportST", SystemJSInterop_BindJSImportST); - mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", SystemJSInterop_InvokeJSImportST); + mono_add_internal_call ("Interop/Runtime::BindJSImportST", SystemInteropJS_BindJSImportST); + mono_add_internal_call ("Interop/Runtime::InvokeJSImportST", SystemInteropJS_InvokeJSImportST); #endif /* DISABLE_THREADS */ - mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", SystemJSInterop_ReleaseCSOwnedObject); - mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", SystemJSInterop_ResolveOrRejectPromise); - mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", SystemJSInterop_InvokeJSFunction); - mono_add_internal_call ("Interop/Runtime::CancelPromise", SystemJSInterop_CancelPromise); - mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", SystemJSInterop_AssemblyGetEntryPoint); - mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", SystemJSInterop_BindAssemblyExports); - mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", SystemJSInterop_GetAssemblyExport); + mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", SystemInteropJS_ReleaseCSOwnedObject); + mono_add_internal_call ("Interop/Runtime::ResolveOrRejectPromise", SystemInteropJS_ResolveOrRejectPromise); + mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", SystemInteropJS_InvokeJSFunction); + mono_add_internal_call ("Interop/Runtime::CancelPromise", SystemInteropJS_CancelPromise); + mono_add_internal_call ("Interop/Runtime::AssemblyGetEntryPoint", SystemInteropJS_AssemblyGetEntryPoint); + mono_add_internal_call ("Interop/Runtime::BindAssemblyExports", SystemInteropJS_BindAssemblyExports); + mono_add_internal_call ("Interop/Runtime::GetAssemblyExport", SystemInteropJS_GetAssemblyExport); mono_add_internal_call ("System.ConsolePal::Clear", SystemJS_ConsoleClear); // JS-based globalization @@ -112,7 +112,7 @@ static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name) return res; } -void SystemJSInterop_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) +void SystemInteropJS_AssemblyGetEntryPoint (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out) { assert (assembly_name); *method_out = NULL; @@ -176,7 +176,7 @@ void SystemJSInterop_AssemblyGetEntryPoint (char *assembly_name, int auto_insert *method_out = method; } -void SystemJSInterop_BindAssemblyExports (char *assembly_name) +void SystemInteropJS_BindAssemblyExports (char *assembly_name) { MonoError error; MonoAssembly* assembly; @@ -200,7 +200,7 @@ void SystemJSInterop_BindAssemblyExports (char *assembly_name) PVOLATILE(MonoObject) exc2 = NULL; store_volatile((MonoObject**)&temp_exc, (MonoObject*)mono_object_to_string ((MonoObject*)temp_exc, (MonoObject **)&exc2)); if (exc2) { - mono_wasm_trace_logger ("jsinterop", "critical", "SystemJSInterop_BindAssemblyExports unexpected double fault", 1, NULL); + mono_wasm_trace_logger ("jsinterop", "critical", "SystemInteropJS_BindAssemblyExports unexpected double fault", 1, NULL); } else { mono_wasm_trace_logger ("jsinterop", "critical", mono_string_to_utf8((MonoString*)temp_exc), 1, NULL); } @@ -213,7 +213,7 @@ void SystemJSInterop_BindAssemblyExports (char *assembly_name) } } -void SystemJSInterop_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) +void SystemInteropJS_GetAssemblyExport (char *assembly_name, char *namespace, char *classname, char *methodname, int signature_hash, MonoMethod **method_out) { MonoError error; MonoAssembly* assembly; @@ -251,48 +251,48 @@ void* before_sync_js_import; void* after_sync_js_import; void* synchronization_context_pump_handler; -void SystemJSInterop_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) +void SystemInteropJS_InstallWebWorkerInterop (int context_gc_handle, void* beforeSyncJSImport, void* afterSyncJSImport, void* pumpHandler) { before_sync_js_import = beforeSyncJSImport; after_sync_js_import = afterSyncJSImport; synchronization_context_pump_handler = pumpHandler; - SystemJSInterop_InstallWebWorkerInteropImpl (context_gc_handle); + SystemInteropJS_InstallWebWorkerInteropImpl (context_gc_handle); } // async -void SystemJSInterop_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle) +void SystemInteropJS_ReleaseCSOwnedObjectPost (pthread_t target_tid, int js_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_ReleaseCSOwnedObject, (gpointer)js_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemInteropJS_ReleaseCSOwnedObject, (gpointer)js_handle); } // async -void SystemJSInterop_ResolveOrRejectPromisePost (pthread_t target_tid, void* args) +void SystemInteropJS_ResolveOrRejectPromisePost (pthread_t target_tid, void* args) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_ResolveOrRejectPromise, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemInteropJS_ResolveOrRejectPromise, (gpointer)args); } // async -void SystemJSInterop_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle) +void SystemInteropJS_CancelPromisePost (pthread_t target_tid, int task_holder_gc_handle) { - mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemJSInterop_CancelPromise, (gpointer)task_holder_gc_handle); + mono_threads_wasm_async_run_in_target_thread_vi (target_tid, (void (*) (gpointer))SystemInteropJS_CancelPromise, (gpointer)task_holder_gc_handle); } // async -void SystemJSInterop_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args) +void SystemInteropJS_InvokeJSImportAsyncPost (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSImportSync, (gpointer)signature, (gpointer)args); + mono_threads_wasm_async_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemInteropJS_InvokeJSImportSync, (gpointer)signature, (gpointer)args); } // sync -void SystemJSInterop_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args) +void SystemInteropJS_InvokeJSImportSyncSend (pthread_t target_tid, void* signature, void* args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSImportSync, (gpointer)signature, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemInteropJS_InvokeJSImportSync, (gpointer)signature, (gpointer)args); } // sync -void SystemJSInterop_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args) +void SystemInteropJS_InvokeJSFunctionSend (pthread_t target_tid, int function_js_handle, void *args) { - mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemJSInterop_InvokeJSFunction, (gpointer)function_js_handle, (gpointer)args); + mono_threads_wasm_sync_run_in_target_thread_vii (target_tid, (void (*) (gpointer, gpointer))SystemInteropJS_InvokeJSFunction, (gpointer)function_js_handle, (gpointer)args); } #endif /* DISABLE_THREADS */ diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index 8da6498460fbea..9af3351e34f454 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -31,8 +31,8 @@ const threading_cwraps: SigLine[] = WasmEnableThreads ? [ // when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call const fn_signatures: SigLine[] = [ - [true, "SystemJSInterop_RegisterGCRoot", "number", ["number", "number", "string"]], - [true, "SystemJSInterop_UnregisterGCRoot", null, ["number"]], + [true, "SystemInteropJS_RegisterGCRoot", "number", ["number", "number", "string"]], + [true, "SystemInteropJS_UnregisterGCRoot", null, ["number"]], [true, "mono_wasm_string_get_data_ref", null, ["number", "number", "number", "number"]], [true, "mono_wasm_set_is_debugger_attached", "void", ["bool"]], [true, "mono_wasm_send_dbg_command", "bool", ["number", "number", "number", "number", "number"]], @@ -158,8 +158,8 @@ export interface t_ProfilerCwraps { } export interface t_Cwraps { - SystemJSInterop_RegisterGCRoot(start: VoidPtr, size: number, name: string): number; - SystemJSInterop_UnregisterGCRoot(addr: VoidPtr): void; + SystemInteropJS_RegisterGCRoot(start: VoidPtr, size: number, name: string): number; + SystemInteropJS_UnregisterGCRoot(addr: VoidPtr): void; mono_wasm_string_get_data_ref(stringRef: MonoStringRef, outChars: CharPtrPtr, outLengthBytes: Int32Ptr, outIsInterned: Int32Ptr): void; mono_wasm_set_is_debugger_attached(value: boolean): void; mono_wasm_send_dbg_command(id: number, command_set: number, command: number, data: VoidPtr, size: number): boolean; diff --git a/src/mono/browser/runtime/driver.c b/src/mono/browser/runtime/driver.c index 3deaf1859ea6e0..bec1286055708a 100644 --- a/src/mono/browser/runtime/driver.c +++ b/src/mono/browser/runtime/driver.c @@ -77,17 +77,17 @@ MONO_API int mono_gc_register_root (char *start, size_t size, MonoGCDescriptor void mono_gc_deregister_root (char* addr); EMSCRIPTEN_KEEPALIVE int -SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name) +SystemInteropJS_RegisterGCRoot (char *start, size_t size, const char *name) { int result; MONO_ENTER_GC_UNSAFE; - result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "SystemJSInterop_RegisterGCRoot"); + result = mono_gc_register_root (start, size, (MonoGCDescriptor)NULL, MONO_ROOT_SOURCE_EXTERNAL, NULL, name ? name : "SystemInteropJS_RegisterGCRoot"); MONO_EXIT_GC_UNSAFE; return result; } EMSCRIPTEN_KEEPALIVE void -SystemJSInterop_UnregisterGCRoot (char *addr) +SystemInteropJS_UnregisterGCRoot (char *addr) { MONO_ENTER_GC_UNSAFE; mono_gc_deregister_root (addr); diff --git a/src/mono/browser/runtime/export-api.ts b/src/mono/browser/runtime/export-api.ts index ec730c7e3bc8c7..0e4887770e1806 100644 --- a/src/mono/browser/runtime/export-api.ts +++ b/src/mono/browser/runtime/export-api.ts @@ -3,7 +3,7 @@ import type { MonoConfig, APIType } from "./types"; -import { SystemJSInterop_GetAssemblyExports } from "./invoke-cs"; +import { SystemInteropJS_GetAssemblyExports } from "./invoke-cs"; import { mono_wasm_set_module_imports } from "./invoke-js"; import { getB32, getB8, getF32, getF64, getI16, getI32, getI52, getI64Big, getI8, getU16, getU32, getU52, getU8, localHeapViewF32, localHeapViewF64, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewI8, localHeapViewU16, localHeapViewU32, localHeapViewU8, setB32, setB8, setF32, setF64, setI16, setI32, setI52, setI64Big, setI8, setU16, setU32, setU52, setU8 } from "./memory"; import { mono_run_main, mono_run_main_and_exit } from "./run"; @@ -16,7 +16,7 @@ export function export_api (): any { runMainAndExit: mono_run_main_and_exit, exit: loaderHelpers.mono_exit, setEnvironmentVariable: mono_wasm_setenv, - getAssemblyExports: SystemJSInterop_GetAssemblyExports, + getAssemblyExports: SystemInteropJS_GetAssemblyExports, setModuleImports: mono_wasm_set_module_imports, getConfig: (): MonoConfig => { return runtimeHelpers.config; diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index b3192217416ff7..bbc012dc0d77ad 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -4,22 +4,22 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug"; -import { SystemJSInterop_ReleaseCSOwnedObject } from "./gc-handles"; -import { SystemJSInterop_BindJSImportST, SystemJSInterop_InvokeJSFunction, SystemJSInterop_InvokeJSImportSync, SystemJSInterop_InvokeJSImportST } from "./invoke-js"; +import { SystemInteropJS_ReleaseCSOwnedObject } from "./gc-handles"; +import { SystemInteropJS_BindJSImportST, SystemInteropJS_InvokeJSFunction, SystemInteropJS_InvokeJSImportSync, SystemInteropJS_InvokeJSImportST } from "./invoke-js"; import { mono_interp_tier_prepare_jiterpreter, mono_wasm_free_method_data } from "./jiterpreter"; import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry"; import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue } from "./jiterpreter-jit-call"; -import { SystemJSInterop_ResolveOrRejectPromise } from "./marshal-to-js"; +import { SystemInteropJS_ResolveOrRejectPromise } from "./marshal-to-js"; import { SystemJS_ScheduleTimerImpl, SystemJS_ScheduleBackgroundJobImpl } from "./scheduling"; import { mono_wasm_asm_loaded, SystemJS_GetCurrentProcessId } from "./startup"; import { mono_log_warn, SystemJS_ConsoleClear, mono_wasm_trace_logger } from "./logging"; import { SystemJS_RandomBytes } from "./crypto"; -import { SystemJSInterop_CancelPromise } from "./cancelable-promise"; +import { SystemInteropJS_CancelPromise } from "./cancelable-promise"; import { mono_wasm_start_deputy_thread_async, mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_unregistered, - mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemJSInterop_InstallWebWorkerInteropImpl, SystemJSInterop_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait + mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, SystemInteropJS_InstallWebWorkerInteropImpl, SystemInteropJS_UninstallWebWorkerInterop, mono_wasm_start_io_thread_async, SystemJS_WarnAboutBlockingWait } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; @@ -44,9 +44,9 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ mono_wasm_dump_threads, // corebindings.c - SystemJSInterop_InstallWebWorkerInteropImpl, - SystemJSInterop_UninstallWebWorkerInterop, - SystemJSInterop_InvokeJSImportSync, + SystemInteropJS_InstallWebWorkerInteropImpl, + SystemInteropJS_UninstallWebWorkerInterop, + SystemInteropJS_InvokeJSImportSync, SystemJS_WarnAboutBlockingWait, ]; @@ -88,12 +88,12 @@ export const mono_wasm_imports = [ // corebindings.c SystemJS_ConsoleClear, - SystemJSInterop_ReleaseCSOwnedObject, - SystemJSInterop_BindJSImportST, - SystemJSInterop_InvokeJSFunction, - SystemJSInterop_InvokeJSImportST, - SystemJSInterop_ResolveOrRejectPromise, - SystemJSInterop_CancelPromise, + SystemInteropJS_ReleaseCSOwnedObject, + SystemInteropJS_BindJSImportST, + SystemInteropJS_InvokeJSFunction, + SystemInteropJS_InvokeJSImportST, + SystemInteropJS_ResolveOrRejectPromise, + SystemInteropJS_CancelPromise, SystemJS_GetLocaleInfo, //event pipe diff --git a/src/mono/browser/runtime/gc-common.h b/src/mono/browser/runtime/gc-common.h index 910db2cb7a6466..4a37bdda5ccfb3 100644 --- a/src/mono/browser/runtime/gc-common.h +++ b/src/mono/browser/runtime/gc-common.h @@ -67,7 +67,7 @@ copy_volatile (PPVOLATILE(MonoObject) destination, PPVOLATILE(MonoObject) source } EMSCRIPTEN_KEEPALIVE int -SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); +SystemInteropJS_RegisterGCRoot (char *start, size_t size, const char *name); EMSCRIPTEN_KEEPALIVE void -SystemJSInterop_UnregisterGCRoot (char *addr); \ No newline at end of file +SystemInteropJS_UnregisterGCRoot (char *addr); \ No newline at end of file diff --git a/src/mono/browser/runtime/gc-handles.ts b/src/mono/browser/runtime/gc-handles.ts index c718177d677e47..cd8bebeb4877b9 100644 --- a/src/mono/browser/runtime/gc-handles.ts +++ b/src/mono/browser/runtime/gc-handles.ts @@ -105,7 +105,7 @@ export function register_with_jsv_handle (js_obj: any, jsv_handle: JSHandle) { } // note: in MT, this is called from locked JSProxyContext. Don't call anything that would need locking. -export function SystemJSInterop_ReleaseCSOwnedObject (js_handle: JSHandle): void { +export function SystemInteropJS_ReleaseCSOwnedObject (js_handle: JSHandle): void { let obj: any; if (is_js_handle(js_handle)) { obj = _cs_owned_objects_by_js_handle[js_handle]; diff --git a/src/mono/browser/runtime/invoke-cs.ts b/src/mono/browser/runtime/invoke-cs.ts index 23320c5a4153e9..3e78c48301774a 100644 --- a/src/mono/browser/runtime/invoke-cs.ts +++ b/src/mono/browser/runtime/invoke-cs.ts @@ -379,7 +379,7 @@ function _walk_exports_to_set_function (assembly: string, namespace: string, cla scope[`${methodname}.${signature_hash}`] = fn; } -export async function SystemJSInterop_GetAssemblyExports (assembly: string): Promise { +export async function SystemInteropJS_GetAssemblyExports (assembly: string): Promise { assert_js_interop(); const result = exportsByAssembly.get(assembly); if (!result) { diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index c3430a80d96552..63e6731f46b909 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -21,7 +21,7 @@ import { stringToUTF16Ptr } from "./strings"; export const js_import_wrapper_by_fn_handle: Function[] = [null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached. -export function SystemJSInterop_BindJSImportST (signature: JSFunctionSignature): VoidPtr { +export function SystemInteropJS_BindJSImportST (signature: JSFunctionSignature): VoidPtr { if (WasmEnableThreads) return VoidPtrNull; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -33,7 +33,7 @@ export function SystemJSInterop_BindJSImportST (signature: JSFunctionSignature): } } -export function SystemJSInterop_InvokeJSImportSync (signature: JSFunctionSignature, args: JSMarshalerArguments) { +export function SystemInteropJS_InvokeJSImportSync (signature: JSFunctionSignature, args: JSMarshalerArguments) { if (!WasmEnableThreads) return; assert_js_interop(); signature = fixupPointer(signature, 0); @@ -73,7 +73,7 @@ export function SystemJSInterop_InvokeJSImportSync (signature: JSFunctionSignatu bound_fn(args); } -export function SystemJSInterop_InvokeJSImportST (function_handle: JSFnHandle, args: JSMarshalerArguments): void { +export function SystemInteropJS_InvokeJSImportST (function_handle: JSFnHandle, args: JSMarshalerArguments): void { if (WasmEnableThreads) return; loaderHelpers.assert_runtime_running(); args = fixupPointer(args, 0); @@ -360,11 +360,11 @@ type BindingClosure = { arg_cleanup: (Function | undefined)[] } -export function SystemJSInterop_InvokeJSFunction (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { - invoke_later_when_on_ui_thread_sync(() => SystemJSInterop_InvokeJSFunction_impl(bound_function_js_handle, args), args); +export function SystemInteropJS_InvokeJSFunction (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { + invoke_later_when_on_ui_thread_sync(() => SystemInteropJS_InvokeJSFunction_impl(bound_function_js_handle, args), args); } -export function SystemJSInterop_InvokeJSFunction_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { +export function SystemInteropJS_InvokeJSFunction_impl (bound_function_js_handle: JSHandle, args: JSMarshalerArguments): void { loaderHelpers.assert_runtime_running(); const bound_fn = mono_wasm_get_jsobj_from_js_handle(bound_function_js_handle); mono_assert(bound_fn && typeof (bound_fn) === "function" && bound_fn[bound_js_function_symbol], () => `Bound function handle expected ${bound_function_js_handle}`); diff --git a/src/mono/browser/runtime/marshal-to-cs.ts b/src/mono/browser/runtime/marshal-to-cs.ts index 61f8b6753cc9da..27824796fac699 100644 --- a/src/mono/browser/runtime/marshal-to-cs.ts +++ b/src/mono/browser/runtime/marshal-to-cs.ts @@ -464,7 +464,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling strings by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.SystemInteropJS_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); @@ -475,7 +475,7 @@ export function marshal_array_to_cs_impl (arg: JSMarshalerArgument, value: Array _zero_region(buffer_ptr, buffer_length); if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); + cwraps.SystemInteropJS_RegisterGCRoot(buffer_ptr, buffer_length, "marshal_array_to_cs"); } for (let index = 0; index < length; index++) { const element_arg = get_arg(buffer_ptr, index); diff --git a/src/mono/browser/runtime/marshal-to-js.ts b/src/mono/browser/runtime/marshal-to-js.ts index 5a4ea305ebed08..7746a98a16843d 100644 --- a/src/mono/browser/runtime/marshal-to-js.ts +++ b/src/mono/browser/runtime/marshal-to-js.ts @@ -6,7 +6,7 @@ import BuildConfiguration from "consts:configuration"; import WasmEnableJsInteropByValue from "consts:wasmEnableJsInteropByValue"; import cwraps from "./cwraps"; -import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, SystemJSInterop_ReleaseCSOwnedObject, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; +import { _lookup_js_owned_object, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, SystemInteropJS_ReleaseCSOwnedObject, register_with_jsv_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; import { loaderHelpers, mono_assert } from "./globals"; import { ManagedObject, ManagedError, @@ -271,7 +271,7 @@ export function end_marshal_task_to_js (args: JSMarshalerArguments, res_converte // otherwise drop the eagerPromise's handle const js_handle = mono_wasm_get_js_handle(eagerPromise); - SystemJSInterop_ReleaseCSOwnedObject(js_handle); + SystemInteropJS_ReleaseCSOwnedObject(js_handle); // get the synchronous result const promise = try_marshal_sync_task_to_js(res, type, res_converter); @@ -331,16 +331,16 @@ function create_task_holder (res_converter?: MarshalerToJs) { } else { mono_assert(false, () => `Unexpected type ${type}`); } - SystemJSInterop_ReleaseCSOwnedObject(js_handle); + SystemInteropJS_ReleaseCSOwnedObject(js_handle); }); return holder; } -export function SystemJSInterop_ResolveOrRejectPromise (args: JSMarshalerArguments): void { - // rejection/resolution should not arrive earlier than the promise created by marshaling in SystemJSInterop_InvokeJSImportSync - invoke_later_when_on_ui_thread_async(() => SystemJSInterop_ResolveOrRejectPromiseImpl(args)); +export function SystemInteropJS_ResolveOrRejectPromise (args: JSMarshalerArguments): void { + // rejection/resolution should not arrive earlier than the promise created by marshaling in SystemInteropJS_InvokeJSImportSync + invoke_later_when_on_ui_thread_async(() => SystemInteropJS_ResolveOrRejectPromiseImpl(args)); } -export function SystemJSInterop_ResolveOrRejectPromiseImpl (args: JSMarshalerArguments): void { +export function SystemInteropJS_ResolveOrRejectPromiseImpl (args: JSMarshalerArguments): void { if (!loaderHelpers.is_runtime_running()) { mono_log_debug("This promise resolution/rejection can't be propagated to managed code, mono runtime already exited."); return; @@ -506,7 +506,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling string by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_UnregisterGCRoot(buffer_ptr); + cwraps.SystemInteropJS_UnregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.Object) { result = new Array(length); @@ -516,7 +516,7 @@ function _marshal_array_to_js_impl (arg: JSMarshalerArgument, element_type: Mars } if (!WasmEnableJsInteropByValue) { mono_assert(!WasmEnableThreads, "Marshaling objects by reference is not supported in multithreaded mode"); - cwraps.SystemJSInterop_UnregisterGCRoot(buffer_ptr); + cwraps.SystemInteropJS_UnregisterGCRoot(buffer_ptr); } } else if (element_type == MarshalerType.JSObject) { result = new Array(length); diff --git a/src/mono/browser/runtime/pthreads/index.ts b/src/mono/browser/runtime/pthreads/index.ts index ccb0867862f46a..484f66ddf3c9aa 100644 --- a/src/mono/browser/runtime/pthreads/index.ts +++ b/src/mono/browser/runtime/pthreads/index.ts @@ -8,7 +8,7 @@ export { mono_wasm_main_thread_ptr, mono_wasm_pthread_ptr, update_thread_info, isMonoThreadMessage, monoThreadInfo, } from "./shared"; -export { SystemJSInterop_InstallWebWorkerInteropImpl, SystemJSInterop_UninstallWebWorkerInterop } from "./worker-interop"; +export { SystemInteropJS_InstallWebWorkerInteropImpl, SystemInteropJS_UninstallWebWorkerInterop } from "./worker-interop"; export { mono_wasm_dump_threads, postCancelThreads, populateEmscriptenPool, mono_wasm_init_threads, diff --git a/src/mono/browser/runtime/pthreads/worker-interop.ts b/src/mono/browser/runtime/pthreads/worker-interop.ts index 8d4fe6d9f2c527..5b1baeaf424b84 100644 --- a/src/mono/browser/runtime/pthreads/worker-interop.ts +++ b/src/mono/browser/runtime/pthreads/worker-interop.ts @@ -11,7 +11,7 @@ import { forceDisposeProxies } from "../gc-handles"; import { GCHandleNull, WorkerToMainMessageType } from "../types/internal"; import { monoThreadInfo, postMessageToMain, update_thread_info } from "./shared"; -export function SystemJSInterop_InstallWebWorkerInteropImpl (context_gc_handle: GCHandle): void { +export function SystemInteropJS_InstallWebWorkerInteropImpl (context_gc_handle: GCHandle): void { if (!WasmEnableThreads) return; bindings_init(); mono_assert(!runtimeHelpers.proxyGCHandle, "JS interop should not be already installed on this worker."); @@ -31,7 +31,7 @@ export function SystemJSInterop_InstallWebWorkerInteropImpl (context_gc_handle: } } -export function SystemJSInterop_UninstallWebWorkerInterop (): void { +export function SystemInteropJS_UninstallWebWorkerInterop (): void { if (!WasmEnableThreads) return; mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "JS interop is not installed on this worker."); mono_assert(runtimeHelpers.proxyGCHandle, "JSSynchronizationContext is not installed on this worker."); diff --git a/src/mono/browser/runtime/roots.ts b/src/mono/browser/runtime/roots.ts index 3c2bc06a9c06f6..0afee175f4ae5c 100644 --- a/src/mono/browser/runtime/roots.ts +++ b/src/mono/browser/runtime/roots.ts @@ -176,7 +176,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { this.__count = capacity; this.length = capacity; mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when creating a GC root"); - this.__handle = cwraps.SystemJSInterop_RegisterGCRoot(offset, capacityBytes, name || "noname"); + this.__handle = cwraps.SystemInteropJS_RegisterGCRoot(offset, capacityBytes, name || "noname"); this.__ownsAllocation = ownsAllocation; } @@ -236,7 +236,7 @@ export class WasmRootBufferImpl implements WasmRootBuffer { release (): void { if (this.__offset && this.__ownsAllocation) { mono_assert(!WasmEnableThreads || !gc_locked, "GC must not be locked when disposing a GC root"); - cwraps.SystemJSInterop_UnregisterGCRoot(this.__offset); + cwraps.SystemInteropJS_UnregisterGCRoot(this.__offset); _zero_region(this.__offset, this.__count * 4); free(this.__offset); } diff --git a/src/mono/browser/runtime/web-socket.ts b/src/mono/browser/runtime/web-socket.ts index 92fa329cee43a4..fd18955f68dc01 100644 --- a/src/mono/browser/runtime/web-socket.ts +++ b/src/mono/browser/runtime/web-socket.ts @@ -517,7 +517,7 @@ function resolvedPromise (): Promise | null { // passing synchronous `null` as value of the result of the async JSImport function is not possible when there is message sent across threads. const resolved = Promise.resolve(); // the C# code in the BrowserWebSocket expects that promise returned from this code is instance of `ControllablePromise` - // so that C# side could call `SystemJSInterop_CancelPromise` on it. + // so that C# side could call `SystemInteropJS_CancelPromise` on it. // in practice the `resolve()` callback would arrive before the `reject()` of the cancelation. return wrap_as_cancelable(resolved); } diff --git a/src/mono/wasi/runtime/driver.c b/src/mono/wasi/runtime/driver.c index 0373e4a66570ea..b9f01df2c659af 100644 --- a/src/mono/wasi/runtime/driver.c +++ b/src/mono/wasi/runtime/driver.c @@ -33,8 +33,8 @@ #include "driver.h" #include "runtime.h" -int SystemJSInterop_RegisterGCRoot (char *start, size_t size, const char *name); -void SystemJSInterop_UnregisterGCRoot (char *addr); +int SystemInteropJS_RegisterGCRoot (char *start, size_t size, const char *name); +void SystemInteropJS_UnregisterGCRoot (char *addr); char *monoeg_g_getenv(const char *variable); int monoeg_g_setenv(const char *variable, const char *value, int overwrite);