diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 5c5b6f841f90fa..5e592ecc1301cf 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -224,8 +224,8 @@ NativeSubDirectory="src" IsNative="true" /> - <_WasmNativeFileForLinking Include="@(NativeFileReference)" /> diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 557db242b43fa2..99d2f7cf02ba9e 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -275,7 +275,6 @@ <_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" /> - <_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\es6\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" /> <_WasmNativeFileForLinking Include="@(NativeFileReference)" /> diff --git a/src/mono/wasm/runtime/.eslintignore b/src/mono/wasm/runtime/.eslintignore index 682049e38a9267..d42206b84f0a97 100644 --- a/src/mono/wasm/runtime/.eslintignore +++ b/src/mono/wasm/runtime/.eslintignore @@ -1,2 +1,2 @@ -jiterpreter-opcodes.ts -jiterpreter-tables.ts +jiterpreter/opcodes.ts +jiterpreter/tables.ts diff --git a/src/mono/wasm/runtime/.eslintrc.cjs b/src/mono/wasm/runtime/.eslintrc.cjs index 5cdee1555241ad..7d0f0def553f5a 100644 --- a/src/mono/wasm/runtime/.eslintrc.cjs +++ b/src/mono/wasm/runtime/.eslintrc.cjs @@ -19,9 +19,9 @@ module.exports = { "ignorePatterns": [ "node_modules/**/*.*", "bin/**/*.*", - "es6/*.js", - "jiterpreter-opcodes.ts", - "jiterpreter-tables.ts", + "native*.js", + "jiterpreter/opcodes.ts", + "jiterpreter/tables.ts", ], "rules": { "@typescript-eslint/no-explicit-any": "off", diff --git a/src/mono/wasm/runtime/assets.ts b/src/mono/wasm/runtime/core/assets.ts similarity index 97% rename from src/mono/wasm/runtime/assets.ts rename to src/mono/wasm/runtime/core/assets.ts index 07e63b71261b6a..58669b4bc99713 100644 --- a/src/mono/wasm/runtime/assets.ts +++ b/src/mono/wasm/runtime/core/assets.ts @@ -7,9 +7,9 @@ import { ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, Module, loaderHelpers, mono_a import { mono_log_info, mono_log_debug, mono_log_warn, parseSymbolMapFile } from "./logging"; import { mono_wasm_load_bytes_into_heap } from "./memory"; import { endMeasure, MeasuredBlock, startMeasure } from "./profiler"; -import { AssetEntryInternal } from "./types/internal"; -import { AssetEntry } from "./types"; -import { InstantiateWasmSuccessCallback, VoidPtr } from "./types/emscripten"; +import { AssetEntryInternal } from "../types/internal"; +import { AssetEntry } from "../types"; +import { InstantiateWasmSuccessCallback, VoidPtr } from "../types/emscripten"; // this need to be run only after onRuntimeInitialized event, when the memory is ready export function instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Array): void { diff --git a/src/mono/wasm/runtime/base64.ts b/src/mono/wasm/runtime/core/base64.ts similarity index 100% rename from src/mono/wasm/runtime/base64.ts rename to src/mono/wasm/runtime/core/base64.ts diff --git a/src/mono/wasm/runtime/cancelable-promise.ts b/src/mono/wasm/runtime/core/cancelable-promise.ts similarity index 92% rename from src/mono/wasm/runtime/cancelable-promise.ts rename to src/mono/wasm/runtime/core/cancelable-promise.ts index 2fbb648c249ff7..ccea19d19637c0 100644 --- a/src/mono/wasm/runtime/cancelable-promise.ts +++ b/src/mono/wasm/runtime/core/cancelable-promise.ts @@ -3,8 +3,8 @@ import { _lookup_js_owned_object } from "./gc-handles"; import { createPromiseController, loaderHelpers, mono_assert } from "./globals"; -import { TaskCallbackHolder } from "./marshal-to-cs"; -import { ControllablePromise, GCHandle } from "./types/internal"; +import { TaskCallbackHolder } from "../interop/marshal-to-cs"; +import { ControllablePromise, GCHandle } from "../types/internal"; export const _are_promises_supported = ((typeof Promise === "object") || (typeof Promise === "function")) && (typeof Promise.resolve === "function"); diff --git a/src/mono/wasm/runtime/class-loader.ts b/src/mono/wasm/runtime/core/class-loader.ts similarity index 98% rename from src/mono/wasm/runtime/class-loader.ts rename to src/mono/wasm/runtime/core/class-loader.ts index 892aa7bf024506..8cb0b9c96cd1ab 100644 --- a/src/mono/wasm/runtime/class-loader.ts +++ b/src/mono/wasm/runtime/core/class-loader.ts @@ -1,4 +1,4 @@ -import { MonoAssembly, MonoClass, MonoType, MonoTypeNull, MonoAssemblyNull } from "./types/internal"; +import { MonoAssembly, MonoClass, MonoType, MonoTypeNull, MonoAssemblyNull } from "../types/internal"; import cwraps from "./cwraps"; const _assembly_cache_by_name = new Map(); diff --git a/src/mono/wasm/runtime/cuint64.ts b/src/mono/wasm/runtime/core/cuint64.ts similarity index 100% rename from src/mono/wasm/runtime/cuint64.ts rename to src/mono/wasm/runtime/core/cuint64.ts diff --git a/src/mono/wasm/runtime/cwraps.ts b/src/mono/wasm/runtime/core/cwraps.ts similarity index 99% rename from src/mono/wasm/runtime/cwraps.ts rename to src/mono/wasm/runtime/core/cwraps.ts index f8c283eae52cf1..7aa899e3b0929e 100644 --- a/src/mono/wasm/runtime/cwraps.ts +++ b/src/mono/wasm/runtime/core/cwraps.ts @@ -8,8 +8,8 @@ import type { MonoArray, MonoAssembly, MonoClass, MonoMethod, MonoObject, MonoType, MonoObjectRef, MonoStringRef, JSMarshalerArguments -} from "./types/internal"; -import type { VoidPtr, CharPtrPtr, Int32Ptr, CharPtr, ManagedPointer } from "./types/emscripten"; +} from "../types/internal"; +import type { VoidPtr, CharPtrPtr, Int32Ptr, CharPtr, ManagedPointer } from "../types/emscripten"; import { linkerDisableLegacyJsInterop, linkerEnableAotProfiler, linkerEnableBrowserProfiler, Module } from "./globals"; import { mono_log_error } from "./logging"; import { mono_assert } from "./globals"; diff --git a/src/mono/wasm/runtime/debug.ts b/src/mono/wasm/runtime/core/debug.ts similarity index 99% rename from src/mono/wasm/runtime/debug.ts rename to src/mono/wasm/runtime/core/debug.ts index 0bc38cf21ad9ae..68ca75f71218ef 100644 --- a/src/mono/wasm/runtime/debug.ts +++ b/src/mono/wasm/runtime/core/debug.ts @@ -5,7 +5,7 @@ import BuildConfiguration from "consts:configuration"; import { INTERNAL, Module, runtimeHelpers } from "./globals"; import { toBase64StringImpl } from "./base64"; import cwraps from "./cwraps"; -import { VoidPtr, CharPtr } from "./types/emscripten"; +import { VoidPtr, CharPtr } from "../types/emscripten"; import { mono_log_warn } from "./logging"; import { localHeapViewU8 } from "./memory"; import { utf8ToString } from "./strings"; diff --git a/src/mono/wasm/runtime/export-api.ts b/src/mono/wasm/runtime/core/export-api.ts similarity index 92% rename from src/mono/wasm/runtime/export-api.ts rename to src/mono/wasm/runtime/core/export-api.ts index 1b4b596bdb6e33..c58b58a4e86210 100644 --- a/src/mono/wasm/runtime/export-api.ts +++ b/src/mono/wasm/runtime/core/export-api.ts @@ -1,10 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import type { MonoConfig, APIType } from "./types"; +import type { MonoConfig, APIType } from "../types"; -import { mono_wasm_get_assembly_exports } from "./invoke-cs"; -import { mono_wasm_set_module_imports } from "./invoke-js"; +import { mono_wasm_get_assembly_exports } from "../interop/invoke-cs"; +import { mono_wasm_set_module_imports } from "../interop/invoke-js"; import { getB32, getF32, getF64, getI16, getI32, getI52, getI64Big, getI8, getU16, getU32, getU52, getU8, localHeapViewF32, localHeapViewF64, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewI8, localHeapViewU16, localHeapViewU32, localHeapViewU8, setB32, setF32, setF64, setI16, setI32, setI52, setI64Big, setI8, setU16, setU32, setU52, setU8 } from "./memory"; import { mono_run_main, mono_run_main_and_exit } from "./run"; import { mono_wasm_setenv } from "./startup"; diff --git a/src/mono/wasm/runtime/exports-binding.ts b/src/mono/wasm/runtime/core/exports-binding.ts similarity index 84% rename from src/mono/wasm/runtime/exports-binding.ts rename to src/mono/wasm/runtime/core/exports-binding.ts index e3143c04f973be..3b47ad962309c2 100644 --- a/src/mono/wasm/runtime/exports-binding.ts +++ b/src/mono/wasm/runtime/core/exports-binding.ts @@ -6,35 +6,35 @@ import WasmEnableLegacyJsInterop from "consts:wasmEnableLegacyJsInterop"; 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_cs_function } from "./invoke-cs"; -import { mono_wasm_bind_js_function, mono_wasm_invoke_bound_function, mono_wasm_invoke_import } from "./invoke-js"; -import { mono_interp_tier_prepare_jiterpreter, mono_jiterp_free_method_data_js } 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, mono_jiterp_do_jit_call_indirect } from "./jiterpreter-jit-call"; -import { mono_wasm_marshal_promise } from "./marshal-to-js"; -import { mono_wasm_eventloop_has_unsettled_interop_promises } from "./pthreads/shared/eventloop"; -import { mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_detached } from "./pthreads/worker"; +import { mono_wasm_bind_cs_function } from "../interop/invoke-cs"; +import { mono_wasm_bind_js_function, mono_wasm_invoke_bound_function, mono_wasm_invoke_import } from "../interop/invoke-js"; +import { mono_interp_tier_prepare_jiterpreter, mono_jiterp_free_method_data_js } from "../jiterpreter/index"; +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, mono_jiterp_do_jit_call_indirect } from "../jiterpreter/jit-call"; +import { mono_wasm_marshal_promise } from "../interop/marshal-to-js"; +import { mono_wasm_eventloop_has_unsettled_interop_promises } from "../pthreads/shared/eventloop"; +import { mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_detached } from "../pthreads/worker"; import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling"; import { mono_wasm_asm_loaded } from "./startup"; -import { mono_wasm_diagnostic_server_on_server_thread_created } from "./diagnostics/server_pthread"; -import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pipe_early_startup_callback } from "./diagnostics"; -import { mono_wasm_diagnostic_server_stream_signal_work_available } from "./diagnostics/server_pthread/stream-queue"; +import { mono_wasm_diagnostic_server_on_server_thread_created } from "../diagnostics/server_pthread"; +import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pipe_early_startup_callback } from "../diagnostics"; +import { mono_wasm_diagnostic_server_stream_signal_work_available } from "../diagnostics/server_pthread/stream-queue"; import { mono_log_debug, mono_log_warn, mono_wasm_trace_logger } from "./logging"; import { mono_wasm_profiler_leave, mono_wasm_profiler_enter } from "./profiler"; -import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "./hybrid-globalization/change-case"; -import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with, mono_wasm_index_of } from "./hybrid-globalization/collations"; -import { mono_wasm_get_calendar_info } from "./hybrid-globalization/calendar"; -import { mono_wasm_install_js_worker_interop, mono_wasm_uninstall_js_worker_interop } from "./pthreads/shared"; +import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "../hybrid-globalization/change-case"; +import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with, mono_wasm_index_of } from "../hybrid-globalization/collations"; +import { mono_wasm_get_calendar_info } from "../hybrid-globalization/calendar"; +import { mono_wasm_install_js_worker_interop, mono_wasm_uninstall_js_worker_interop } from "../pthreads/shared"; import { mono_wasm_invoke_js_blazor, mono_wasm_invoke_js_with_args_ref, mono_wasm_get_object_property_ref, mono_wasm_set_object_property_ref, mono_wasm_get_by_index_ref, mono_wasm_set_by_index_ref, mono_wasm_get_global_object_ref -} from "./net6-legacy/method-calls"; -import { mono_wasm_create_cs_owned_object_ref } from "./net6-legacy/cs-to-js"; -import { mono_wasm_typed_array_to_array_ref } from "./net6-legacy/js-to-cs"; -import { mono_wasm_typed_array_from_ref } from "./net6-legacy/buffers"; -import { mono_wasm_get_culture_info } from "./hybrid-globalization/culture-info"; -import { mono_wasm_get_first_day_of_week, mono_wasm_get_first_week_of_year } from "./hybrid-globalization/locales"; +} from "../net6-legacy/method-calls"; +import { mono_wasm_create_cs_owned_object_ref } from "../net6-legacy/cs-to-js"; +import { mono_wasm_typed_array_to_array_ref } from "../net6-legacy/js-to-cs"; +import { mono_wasm_typed_array_from_ref } from "../net6-legacy/buffers"; +import { mono_wasm_get_culture_info } from "../hybrid-globalization/culture-info"; +import { mono_wasm_get_first_day_of_week, mono_wasm_get_first_week_of_year } from "../hybrid-globalization/locales"; // the JS methods would be visible to EMCC linker and become imports of the WASM module diff --git a/src/mono/wasm/runtime/exports-internal.ts b/src/mono/wasm/runtime/core/exports-internal.ts similarity index 95% rename from src/mono/wasm/runtime/exports-internal.ts rename to src/mono/wasm/runtime/core/exports-internal.ts index 2ff2dea5f9896a..b68720d8b046d1 100644 --- a/src/mono/wasm/runtime/exports-internal.ts +++ b/src/mono/wasm/runtime/core/exports-internal.ts @@ -6,12 +6,12 @@ import cwraps, { profiler_c_functions } from "./cwraps"; import { mono_wasm_send_dbg_command_with_parms, mono_wasm_send_dbg_command, mono_wasm_get_dbg_command_info, mono_wasm_get_details, mono_wasm_release_object, mono_wasm_call_function_on, mono_wasm_debugger_resume, mono_wasm_detach_debugger, mono_wasm_raise_debug_event, mono_wasm_change_debugger_log_level, mono_wasm_debugger_attached } from "./debug"; import { http_wasm_supports_streaming_request, http_wasm_supports_streaming_response, http_wasm_create_abort_controler, http_wasm_abort_request, http_wasm_abort_response, http_wasm_create_transform_stream, http_wasm_transform_stream_write, http_wasm_transform_stream_close, http_wasm_transform_stream_abort, http_wasm_fetch, http_wasm_fetch_stream, http_wasm_fetch_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_bytes, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes } from "./http"; import { exportedRuntimeAPI, Module, runtimeHelpers } from "./globals"; -import { get_property, set_property, has_property, get_typeof_property, get_global_this, dynamic_import } from "./invoke-js"; +import { get_property, set_property, has_property, get_typeof_property, get_global_this, dynamic_import } from "../interop/invoke-js"; import { mono_wasm_stringify_as_error_with_stack } from "./logging"; import { ws_wasm_create, ws_wasm_open, ws_wasm_send, ws_wasm_receive, ws_wasm_close, ws_wasm_abort } from "./web-socket"; import { mono_wasm_get_loaded_files } from "./assets"; -import { jiterpreter_dump_stats } from "./jiterpreter"; -import { getOptions, applyOptions } from "./jiterpreter-support"; +import { jiterpreter_dump_stats } from "../jiterpreter/index"; +import { getOptions, applyOptions } from "../jiterpreter/support"; import { mono_wasm_gc_lock, mono_wasm_gc_unlock } from "./gc-lock"; import { loadLazyAssembly } from "./lazyLoading"; import { loadSatelliteAssemblies } from "./satelliteAssemblies"; diff --git a/src/mono/wasm/runtime/exports-linker.ts b/src/mono/wasm/runtime/core/exports-linker.ts similarity index 100% rename from src/mono/wasm/runtime/exports-linker.ts rename to src/mono/wasm/runtime/core/exports-linker.ts diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/core/exports.ts similarity index 94% rename from src/mono/wasm/runtime/exports.ts rename to src/mono/wasm/runtime/core/exports.ts index 6e50e26e164c0c..bf562da41ab28e 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/core/exports.ts @@ -4,10 +4,10 @@ import ProductVersion from "consts:productVersion"; import BuildConfiguration from "consts:configuration"; import WasmEnableLegacyJsInterop from "consts:wasmEnableLegacyJsInterop"; -import type { RuntimeAPI } from "./types"; +import type { RuntimeAPI } from "../types"; import { Module, linkerDisableLegacyJsInterop, exportedRuntimeAPI, passEmscriptenInternals, runtimeHelpers, setRuntimeGlobals, } from "./globals"; -import { GlobalObjects, is_nullish } from "./types/internal"; +import { GlobalObjects, is_nullish } from "../types/internal"; import { configureEmscriptenStartup, configureRuntimeStartup, configureWorkerStartup } from "./startup"; import { create_weak_ref } from "./weak-ref"; @@ -16,12 +16,12 @@ import { export_api } from "./export-api"; import { initializeReplacements } from "./polyfills"; // legacy -import { mono_bind_static_method } from "./net6-legacy/method-calls"; -import { export_binding_api, export_internal_api, export_mono_api } from "./net6-legacy/exports-legacy"; -import { initializeLegacyExports } from "./net6-legacy/globals"; +import { mono_bind_static_method } from "../net6-legacy/method-calls"; +import { export_binding_api, export_internal_api, export_mono_api } from "../net6-legacy/exports-legacy"; +import { initializeLegacyExports } from "../net6-legacy/globals"; import { mono_log_warn, mono_wasm_stringify_as_error_with_stack } from "./logging"; import { instantiate_asset, instantiate_symbols_asset } from "./assets"; -import { jiterpreter_dump_stats } from "./jiterpreter"; +import { jiterpreter_dump_stats } from "../jiterpreter"; import { forceDisposeProxies } from "./gc-handles"; function initializeExports(globalObjects: GlobalObjects): RuntimeAPI { diff --git a/src/mono/wasm/runtime/gc-handles.ts b/src/mono/wasm/runtime/core/gc-handles.ts similarity index 98% rename from src/mono/wasm/runtime/gc-handles.ts rename to src/mono/wasm/runtime/core/gc-handles.ts index 857b73782992b7..54660901f954c0 100644 --- a/src/mono/wasm/runtime/gc-handles.ts +++ b/src/mono/wasm/runtime/core/gc-handles.ts @@ -5,12 +5,12 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import BuildConfiguration from "consts:configuration"; import { loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; -import { fn_wrapper_by_fn_handle } from "./invoke-js"; +import { fn_wrapper_by_fn_handle } from "../interop/invoke-js"; import { mono_log_info, mono_log_warn } from "./logging"; -import { bound_cs_function_symbol, imported_js_function_symbol, proxy_debug_symbol } from "./marshal"; -import { GCHandle, GCHandleNull, JSHandle, JSHandleDisposed, JSHandleNull } from "./types/internal"; +import { bound_cs_function_symbol, imported_js_function_symbol, proxy_debug_symbol } from "../interop/marshal"; +import { GCHandle, GCHandleNull, JSHandle, JSHandleDisposed, JSHandleNull } from "../types/internal"; import { _use_weak_ref, create_weak_ref } from "./weak-ref"; -import { exportsByAssembly } from "./invoke-cs"; +import { exportsByAssembly } from "../interop/invoke-cs"; const _use_finalization_registry = typeof globalThis.FinalizationRegistry === "function"; let _js_owned_object_registry: FinalizationRegistry; diff --git a/src/mono/wasm/runtime/gc-lock.ts b/src/mono/wasm/runtime/core/gc-lock.ts similarity index 100% rename from src/mono/wasm/runtime/gc-lock.ts rename to src/mono/wasm/runtime/core/gc-lock.ts diff --git a/src/mono/wasm/runtime/globals.ts b/src/mono/wasm/runtime/core/globals.ts similarity index 96% rename from src/mono/wasm/runtime/globals.ts rename to src/mono/wasm/runtime/core/globals.ts index 031613799ea38f..b223343ab495e1 100644 --- a/src/mono/wasm/runtime/globals.ts +++ b/src/mono/wasm/runtime/core/globals.ts @@ -2,13 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. /* eslint-disable @typescript-eslint/triple-slash-reference */ -/// -/// +/// +/// import gitHash from "consts:gitHash"; -import { RuntimeAPI } from "./types/index"; -import type { GlobalObjects, EmscriptenInternals, RuntimeHelpers, LoaderHelpers, DotnetModuleInternal, PromiseAndController } from "./types/internal"; +import { RuntimeAPI } from "../types/index"; +import type { GlobalObjects, EmscriptenInternals, RuntimeHelpers, LoaderHelpers, DotnetModuleInternal, PromiseAndController } from "../types/internal"; // these are our public API (except internal) export let Module: DotnetModuleInternal; diff --git a/src/mono/wasm/runtime/guarded-promise.ts b/src/mono/wasm/runtime/core/guarded-promise.ts similarity index 100% rename from src/mono/wasm/runtime/guarded-promise.ts rename to src/mono/wasm/runtime/core/guarded-promise.ts diff --git a/src/mono/wasm/runtime/http.ts b/src/mono/wasm/runtime/core/http.ts similarity index 98% rename from src/mono/wasm/runtime/http.ts rename to src/mono/wasm/runtime/core/http.ts index cdb60bd862ab08..20d975132a9595 100644 --- a/src/mono/wasm/runtime/http.ts +++ b/src/mono/wasm/runtime/core/http.ts @@ -1,12 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +import type { VoidPtr } from "../types/emscripten"; +import type { ControllablePromise } from "../types/internal"; import { wrap_as_cancelable_promise } from "./cancelable-promise"; import { ENVIRONMENT_IS_NODE, Module, loaderHelpers, mono_assert } from "./globals"; -import { MemoryViewType, Span } from "./marshal"; -import type { VoidPtr } from "./types/emscripten"; -import { ControllablePromise } from "./types/internal"; - +import { MemoryViewType, Span } from "../interop/marshal"; function verifyEnvironment() { if (typeof globalThis.fetch !== "function" || typeof globalThis.AbortController !== "function") { diff --git a/src/mono/wasm/runtime/icu.ts b/src/mono/wasm/runtime/core/icu.ts similarity index 89% rename from src/mono/wasm/runtime/icu.ts rename to src/mono/wasm/runtime/core/icu.ts index 28aa01ad727cfd..4482a27b5e18f8 100644 --- a/src/mono/wasm/runtime/icu.ts +++ b/src/mono/wasm/runtime/core/icu.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import cwraps from "./cwraps"; -import { VoidPtr } from "./types/emscripten"; +import { VoidPtr } from "../types/emscripten"; // @offset must be the address of an ICU data archive in the native heap. // returns true on success. diff --git a/src/mono/wasm/runtime/lazyLoading.ts b/src/mono/wasm/runtime/core/lazyLoading.ts similarity index 98% rename from src/mono/wasm/runtime/lazyLoading.ts rename to src/mono/wasm/runtime/core/lazyLoading.ts index 59c153a9d62365..14f3fd28d0b40a 100644 --- a/src/mono/wasm/runtime/lazyLoading.ts +++ b/src/mono/wasm/runtime/core/lazyLoading.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import { loaderHelpers, runtimeHelpers } from "./globals"; -import { AssetEntry } from "./types"; +import { AssetEntry } from "../types"; export async function loadLazyAssembly(assemblyNameToLoad: string): Promise { const resources = loaderHelpers.config.resources!; diff --git a/src/mono/wasm/runtime/logging.ts b/src/mono/wasm/runtime/core/logging.ts similarity index 98% rename from src/mono/wasm/runtime/logging.ts rename to src/mono/wasm/runtime/core/logging.ts index 869a08e3d685a1..e801c57f7f740f 100644 --- a/src/mono/wasm/runtime/logging.ts +++ b/src/mono/wasm/runtime/core/logging.ts @@ -4,7 +4,7 @@ /* eslint-disable no-console */ import { INTERNAL, runtimeHelpers } from "./globals"; import { utf8ToString } from "./strings"; -import { CharPtr, VoidPtr } from "./types/emscripten"; +import { CharPtr, VoidPtr } from "../types/emscripten"; let prefix = "MONO_WASM: "; diff --git a/src/mono/wasm/runtime/managed-exports.ts b/src/mono/wasm/runtime/core/managed-exports.ts similarity index 97% rename from src/mono/wasm/runtime/managed-exports.ts rename to src/mono/wasm/runtime/core/managed-exports.ts index 49b16f7ae34776..f3171be14002db 100644 --- a/src/mono/wasm/runtime/managed-exports.ts +++ b/src/mono/wasm/runtime/core/managed-exports.ts @@ -3,13 +3,13 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { GCHandle, MarshalerToCs, MarshalerToJs, MarshalerType, MonoMethod } from "./types/internal"; +import { GCHandle, MarshalerToCs, MarshalerToJs, MarshalerType, MonoMethod } from "../types/internal"; import cwraps from "./cwraps"; import { runtimeHelpers, Module, loaderHelpers, mono_assert } from "./globals"; -import { alloc_stack_frame, get_arg, get_arg_gc_handle, set_arg_type, set_gc_handle } from "./marshal"; -import { invoke_method_and_handle_exception } from "./invoke-cs"; -import { marshal_array_to_cs, marshal_array_to_cs_impl, marshal_exception_to_cs, marshal_intptr_to_cs } from "./marshal-to-cs"; -import { marshal_int32_to_js, marshal_string_to_js, marshal_task_to_js } from "./marshal-to-js"; +import { alloc_stack_frame, get_arg, get_arg_gc_handle, set_arg_type, set_gc_handle } from "../interop/marshal"; +import { invoke_method_and_handle_exception } from "../interop/invoke-cs"; +import { marshal_array_to_cs, marshal_array_to_cs_impl, marshal_exception_to_cs, marshal_intptr_to_cs } from "../interop/marshal-to-cs"; +import { marshal_int32_to_js, marshal_string_to_js, marshal_task_to_js } from "../interop/marshal-to-js"; import { do_not_force_dispose } from "./gc-handles"; export function init_managed_exports(): void { diff --git a/src/mono/wasm/runtime/memory.ts b/src/mono/wasm/runtime/core/memory.ts similarity index 99% rename from src/mono/wasm/runtime/memory.ts rename to src/mono/wasm/runtime/core/memory.ts index 6de09caa18e9db..3d1e212f88fbb5 100644 --- a/src/mono/wasm/runtime/memory.ts +++ b/src/mono/wasm/runtime/core/memory.ts @@ -3,8 +3,8 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { MemOffset, NumberOrPointer } from "./types/internal"; -import { VoidPtr, CharPtr } from "./types/emscripten"; +import { MemOffset, NumberOrPointer } from "../types/internal"; +import { VoidPtr, CharPtr } from "../types/emscripten"; import cwraps, { I52Error } from "./cwraps"; import { Module, runtimeHelpers } from "./globals"; import { utf8ToString } from "./strings"; diff --git a/src/mono/wasm/runtime/polyfills.ts b/src/mono/wasm/runtime/core/polyfills.ts similarity index 97% rename from src/mono/wasm/runtime/polyfills.ts rename to src/mono/wasm/runtime/core/polyfills.ts index 2ce605955db512..4db55b33f9c8ed 100644 --- a/src/mono/wasm/runtime/polyfills.ts +++ b/src/mono/wasm/runtime/core/polyfills.ts @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. import MonoWasmThreads from "consts:monoWasmThreads"; -import type { EmscriptenReplacements } from "./types/internal"; -import type { TypedArray } from "./types/emscripten"; +import type { EmscriptenReplacements } from "../types/internal"; +import type { TypedArray } from "../types/emscripten"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_PTHREAD, ENVIRONMENT_IS_WEB, INTERNAL, Module, loaderHelpers, runtimeHelpers } from "./globals"; -import { replaceEmscriptenPThreadLibrary } from "./pthreads/shared/emscripten-replacements"; +import { replaceEmscriptenPThreadLibrary } from "../pthreads/shared/emscripten-replacements"; const dummyPerformance = { now: function () { diff --git a/src/mono/wasm/runtime/profiler.ts b/src/mono/wasm/runtime/core/profiler.ts similarity index 99% rename from src/mono/wasm/runtime/profiler.ts rename to src/mono/wasm/runtime/core/profiler.ts index af4775f66fe974..514f865a572085 100644 --- a/src/mono/wasm/runtime/profiler.ts +++ b/src/mono/wasm/runtime/core/profiler.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import { ENVIRONMENT_IS_WEB, linkerEnableAotProfiler, linkerEnableBrowserProfiler, mono_assert, runtimeHelpers } from "./globals"; -import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions } from "./types/internal"; +import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions } from "../types/internal"; import { profiler_c_functions as cwraps } from "./cwraps"; import { utf8ToString } from "./strings"; diff --git a/src/mono/wasm/runtime/queue.ts b/src/mono/wasm/runtime/core/queue.ts similarity index 100% rename from src/mono/wasm/runtime/queue.ts rename to src/mono/wasm/runtime/core/queue.ts diff --git a/src/mono/wasm/runtime/roots.ts b/src/mono/wasm/runtime/core/roots.ts similarity index 99% rename from src/mono/wasm/runtime/roots.ts rename to src/mono/wasm/runtime/core/roots.ts index 21f9f18077b7c7..7c9cca5117a81f 100644 --- a/src/mono/wasm/runtime/roots.ts +++ b/src/mono/wasm/runtime/core/roots.ts @@ -3,8 +3,8 @@ import cwraps from "./cwraps"; import { Module } from "./globals"; -import { VoidPtr, ManagedPointer, NativePointer } from "./types/emscripten"; -import { MonoObjectRef, MonoObjectRefNull, MonoObject, is_nullish, WasmRoot, WasmRootBuffer } from "./types/internal"; +import { VoidPtr, ManagedPointer, NativePointer } from "../types/emscripten"; +import { MonoObjectRef, MonoObjectRefNull, MonoObject, is_nullish, WasmRoot, WasmRootBuffer } from "../types/internal"; import { _zero_region, localHeapViewU32 } from "./memory"; const maxScratchRoots = 8192; diff --git a/src/mono/wasm/runtime/run.ts b/src/mono/wasm/runtime/core/run.ts similarity index 97% rename from src/mono/wasm/runtime/run.ts rename to src/mono/wasm/runtime/core/run.ts index 184a8d6c8d9ffc..190d8cce82c59d 100644 --- a/src/mono/wasm/runtime/run.ts +++ b/src/mono/wasm/runtime/core/run.ts @@ -7,7 +7,7 @@ import { mono_wasm_set_main_args } from "./startup"; import cwraps from "./cwraps"; import { assembly_load } from "./class-loader"; import { mono_log_info } from "./logging"; -import { assert_bindings } from "./invoke-js"; +import { assert_bindings } from "../interop/invoke-js"; /** * Possible signatures are described here https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line diff --git a/src/mono/wasm/runtime/satelliteAssemblies.ts b/src/mono/wasm/runtime/core/satelliteAssemblies.ts similarity index 97% rename from src/mono/wasm/runtime/satelliteAssemblies.ts rename to src/mono/wasm/runtime/core/satelliteAssemblies.ts index 100af0696aae4d..99f1f6e703a457 100644 --- a/src/mono/wasm/runtime/satelliteAssemblies.ts +++ b/src/mono/wasm/runtime/core/satelliteAssemblies.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import { loaderHelpers, runtimeHelpers } from "./globals"; -import { AssetEntry } from "./types"; +import { AssetEntry } from "../types"; export async function loadSatelliteAssemblies(culturesToLoad: string[]): Promise { const satelliteResources = loaderHelpers.config.resources!.satelliteResources; diff --git a/src/mono/wasm/runtime/scheduling.ts b/src/mono/wasm/runtime/core/scheduling.ts similarity index 100% rename from src/mono/wasm/runtime/scheduling.ts rename to src/mono/wasm/runtime/core/scheduling.ts diff --git a/src/mono/wasm/runtime/snapshot.ts b/src/mono/wasm/runtime/core/snapshot.ts similarity index 100% rename from src/mono/wasm/runtime/snapshot.ts rename to src/mono/wasm/runtime/core/snapshot.ts diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/core/startup.ts similarity index 97% rename from src/mono/wasm/runtime/startup.ts rename to src/mono/wasm/runtime/core/startup.ts index 84a335bf6c0e6e..32261d2c6262ee 100644 --- a/src/mono/wasm/runtime/startup.ts +++ b/src/mono/wasm/runtime/core/startup.ts @@ -4,36 +4,36 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import WasmEnableLegacyJsInterop from "consts:wasmEnableLegacyJsInterop"; -import { DotnetModuleInternal, CharPtrNull } from "./types/internal"; +import { DotnetModuleInternal, CharPtrNull } from "../types/internal"; import { linkerDisableLegacyJsInterop, ENVIRONMENT_IS_PTHREAD, exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, createPromiseController, mono_assert, linkerWasmEnableSIMD, linkerWasmEnableEH } from "./globals"; import cwraps, { init_c_exports } from "./cwraps"; import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug"; import { toBase64StringImpl } from "./base64"; import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler } from "./profiler"; -import { initialize_marshalers_to_cs } from "./marshal-to-cs"; -import { initialize_marshalers_to_js } from "./marshal-to-js"; +import { initialize_marshalers_to_cs } from "../interop/marshal-to-cs"; +import { initialize_marshalers_to_js } from "../interop/marshal-to-js"; import { init_polyfills_async } from "./polyfills"; import { strings_init, utf8ToString } from "./strings"; import { init_managed_exports } from "./managed-exports"; import { cwraps_internal } from "./exports-internal"; -import { CharPtr, InstantiateWasmCallBack, InstantiateWasmSuccessCallback } from "./types/emscripten"; +import { CharPtr, InstantiateWasmCallBack, InstantiateWasmSuccessCallback } from "../types/emscripten"; import { instantiate_wasm_asset, wait_for_all_assets } from "./assets"; -import { mono_wasm_init_diagnostics } from "./diagnostics"; +import { mono_wasm_init_diagnostics } from "../diagnostics"; import { replace_linker_placeholders } from "./exports-binding"; import { endMeasure, MeasuredBlock, startMeasure } from "./profiler"; import { checkMemorySnapshotSize, getMemorySnapshot, storeMemorySnapshot } from "./snapshot"; import { mono_log_debug, mono_log_error, mono_log_warn, mono_set_thread_id } from "./logging"; // threads -import { preAllocatePThreadWorkerPool, instantiateWasmPThreadWorkerPool } from "./pthreads/browser"; -import { currentWorkerThreadEvents, dotnetPthreadCreated, initWorkerThreadEvents } from "./pthreads/worker"; -import { getBrowserThreadID } from "./pthreads/shared"; -import { jiterpreter_allocate_tables } from "./jiterpreter-support"; +import { preAllocatePThreadWorkerPool, instantiateWasmPThreadWorkerPool } from "../pthreads/browser"; +import { currentWorkerThreadEvents, dotnetPthreadCreated, initWorkerThreadEvents } from "../pthreads/worker"; +import { getBrowserThreadID } from "../pthreads/shared"; +import { jiterpreter_allocate_tables } from "../jiterpreter/support"; // legacy -import { init_legacy_exports } from "./net6-legacy/corebindings"; -import { cwraps_binding_api, cwraps_mono_api } from "./net6-legacy/exports-legacy"; -import { BINDING, MONO } from "./net6-legacy/globals"; +import { init_legacy_exports } from "../net6-legacy/corebindings"; +import { cwraps_binding_api, cwraps_mono_api } from "../net6-legacy/exports-legacy"; +import { BINDING, MONO } from "../net6-legacy/globals"; import { localHeapViewU8 } from "./memory"; import { assertNoProxies } from "./gc-handles"; diff --git a/src/mono/wasm/runtime/strings.ts b/src/mono/wasm/runtime/core/strings.ts similarity index 99% rename from src/mono/wasm/runtime/strings.ts rename to src/mono/wasm/runtime/core/strings.ts index f4cfa442386183..fc6daaab9b3b57 100644 --- a/src/mono/wasm/runtime/strings.ts +++ b/src/mono/wasm/runtime/core/strings.ts @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. import { mono_wasm_new_root_buffer } from "./roots"; -import { MonoString, MonoStringNull, WasmRoot, WasmRootBuffer } from "./types/internal"; +import { MonoString, MonoStringNull, WasmRoot, WasmRootBuffer } from "../types/internal"; import { Module } from "./globals"; import cwraps from "./cwraps"; import { isSharedArrayBuffer, localHeapViewU8, getU32_local, setU16_local, localHeapViewU32, getU16_local, localHeapViewU16 } from "./memory"; -import { NativePointer, CharPtr } from "./types/emscripten"; +import { NativePointer, CharPtr } from "../types/emscripten"; export const interned_js_string_table = new Map(); export const mono_wasm_empty_string = ""; diff --git a/src/mono/wasm/runtime/weak-ref.ts b/src/mono/wasm/runtime/core/weak-ref.ts similarity index 100% rename from src/mono/wasm/runtime/weak-ref.ts rename to src/mono/wasm/runtime/core/weak-ref.ts diff --git a/src/mono/wasm/runtime/web-socket.ts b/src/mono/wasm/runtime/core/web-socket.ts similarity index 99% rename from src/mono/wasm/runtime/web-socket.ts rename to src/mono/wasm/runtime/core/web-socket.ts index 7469d27cd7501e..c302686f81c07f 100644 --- a/src/mono/wasm/runtime/web-socket.ts +++ b/src/mono/wasm/runtime/core/web-socket.ts @@ -7,11 +7,11 @@ import { prevent_timer_throttling } from "./scheduling"; import { Queue } from "./queue"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, createPromiseController, mono_assert } from "./globals"; import { setI32, localHeapViewU8 } from "./memory"; -import { VoidPtr } from "./types/emscripten"; -import { PromiseController } from "./types/internal"; +import { VoidPtr } from "../types/emscripten"; +import { PromiseController } from "../types/internal"; import { mono_log_warn } from "./logging"; import { viewOrCopy, utf8ToStringRelaxed, stringToUTF8 } from "./strings"; -import { IDisposable } from "./marshal"; +import { IDisposable } from "../interop/marshal"; const wasm_ws_pending_send_buffer = Symbol.for("wasm ws_pending_send_buffer"); const wasm_ws_pending_send_buffer_offset = Symbol.for("wasm ws_pending_send_buffer_offset"); diff --git a/src/mono/wasm/runtime/diagnostics/browser/controller.ts b/src/mono/wasm/runtime/diagnostics/browser/controller.ts index d891710b8763b9..bc44db5a4412ae 100644 --- a/src/mono/wasm/runtime/diagnostics/browser/controller.ts +++ b/src/mono/wasm/runtime/diagnostics/browser/controller.ts @@ -3,10 +3,10 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { diagnostics_c_functions as cwraps } from "../../cwraps"; -import { INTERNAL, mono_assert } from "../../globals"; -import { mono_log_info, mono_log_debug, mono_log_warn } from "../../logging"; -import { withStackAlloc, getI32 } from "../../memory"; +import { diagnostics_c_functions as cwraps } from "../../core/cwraps"; +import { INTERNAL, mono_assert } from "../../core/globals"; +import { mono_log_info, mono_log_debug, mono_log_warn } from "../../core/logging"; +import { withStackAlloc, getI32 } from "../../core/memory"; import { Thread, waitForThread } from "../../pthreads/browser"; import { isDiagnosticMessage, makeDiagnosticServerControlCommand } from "../shared/controller-commands"; import monoDiagnosticsMock from "consts:monoDiagnosticsMock"; diff --git a/src/mono/wasm/runtime/diagnostics/index.ts b/src/mono/wasm/runtime/diagnostics/index.ts index 1d93725a640b8a..8d4a5f3f8c8f93 100644 --- a/src/mono/wasm/runtime/diagnostics/index.ts +++ b/src/mono/wasm/runtime/diagnostics/index.ts @@ -9,9 +9,9 @@ import type { import { is_nullish } from "../types/internal"; import type { VoidPtr } from "../types/emscripten"; import { getController, startDiagnosticServer } from "./browser/controller"; -import * as memory from "../memory"; -import { mono_log_warn } from "../logging"; -import { mono_assert, runtimeHelpers } from "../globals"; +import * as memory from "../core/memory"; +import { mono_log_warn } from "../core/logging"; +import { mono_assert, runtimeHelpers } from "../core/globals"; // called from C on the main thread diff --git a/src/mono/wasm/runtime/diagnostics/mock/environment.ts b/src/mono/wasm/runtime/diagnostics/mock/environment.ts index bcbdf390a4dfe2..5c1e66577f6488 100644 --- a/src/mono/wasm/runtime/diagnostics/mock/environment.ts +++ b/src/mono/wasm/runtime/diagnostics/mock/environment.ts @@ -7,7 +7,7 @@ import Serializer from "../server_pthread/ipc-protocol/base-serializer"; import { CommandSetId, EventPipeCommandId, ProcessCommandId } from "../server_pthread/ipc-protocol/types"; import { assertNever } from "../../types/internal"; import { pthread_self } from "../../pthreads/worker"; -import { createPromiseController, mono_assert } from "../../globals"; +import { createPromiseController, mono_assert } from "../../core/globals"; function expectAdvertise(data: ArrayBuffer): boolean { diff --git a/src/mono/wasm/runtime/diagnostics/mock/index.ts b/src/mono/wasm/runtime/diagnostics/mock/index.ts index 81304154071332..60581891c1ba64 100644 --- a/src/mono/wasm/runtime/diagnostics/mock/index.ts +++ b/src/mono/wasm/runtime/diagnostics/mock/index.ts @@ -6,7 +6,7 @@ import monoDiagnosticsMock from "consts:monoDiagnosticsMock"; import { createMockEnvironment } from "./environment"; import type { MockEnvironment, MockScriptConnection } from "./export-types"; import { assertNever } from "../../types/internal"; -import { mono_log_debug, mono_log_warn } from "../../logging"; +import { mono_log_debug, mono_log_warn } from "../../core/logging"; export interface MockRemoteSocket extends EventTarget { addEventListener(type: T, listener: (this: MockRemoteSocket, ev: WebSocketEventMap[T]) => any, options?: boolean | AddEventListenerOptions): void; diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/index.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/index.ts index 4023df9e5134eb..4de4b4abb000f6 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/index.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/index.ts @@ -7,8 +7,8 @@ import monoDiagnosticsMock from "consts:monoDiagnosticsMock"; import { PromiseAndController, assertNever } from "../../types/internal"; import { pthread_self } from "../../pthreads/worker"; -import { createPromiseController, mono_assert } from "../../globals"; -import { diagnostics_c_functions as cwraps } from "../../cwraps"; +import { createPromiseController, mono_assert } from "../../core/globals"; +import { diagnostics_c_functions as cwraps } from "../../core/cwraps"; import { EventPipeSessionIDImpl } from "../shared/types"; import { CharPtr } from "../../types/emscripten"; import { @@ -47,8 +47,8 @@ import { createAdvertise, createBinaryCommandOKReply, } from "./ipc-protocol/serializer"; -import { mono_log_error, mono_log_info, mono_log_debug, mono_log_warn } from "../../logging"; -import { utf8ToString } from "../../strings"; +import { mono_log_error, mono_log_info, mono_log_debug, mono_log_warn } from "../../core/logging"; +import { utf8ToString } from "../../core/strings"; function addOneShotProtocolCommandEventListener(src: EventTarget): Promise { return new Promise((resolve) => { diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/parser.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/parser.ts index 765e16718c9533..cb4150e35d04ad 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/parser.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/parser.ts @@ -19,7 +19,7 @@ import { EventPipeCommandId, ProcessCommandId, } from "./types"; -import { mono_log_warn } from "../../../logging"; +import { mono_log_warn } from "../../../core/logging"; interface ParseClientCommandResultOk extends ParseResultOk { readonly result: C; diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/serializer.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/serializer.ts index 6b67488c5fdac7..12cd8de8f645dd 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/serializer.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/ipc-protocol/serializer.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { mono_assert } from "../../../globals"; +import { mono_assert } from "../../../core/globals"; import Serializer from "./base-serializer"; import { CommandSetId, ServerCommandId } from "./types"; diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/protocol-socket.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/protocol-socket.ts index 7bd03e0d003a34..6a849b19f9ecdf 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/protocol-socket.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/protocol-socket.ts @@ -10,7 +10,7 @@ import { import Magic from "./ipc-protocol/magic"; import Parser from "./ipc-protocol/base-parser"; import { assertNever } from "../../types/internal"; -import { mono_log_debug, mono_log_warn } from "../../logging"; +import { mono_log_debug, mono_log_warn } from "../../core/logging"; export const dotnetDiagnosticsServerProtocolCommandEvent = "dotnet:diagnostics:protocolCommand" as const; diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/socket-connection.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/socket-connection.ts index d02ae16e3403a0..d3386e0870ecc6 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/socket-connection.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/socket-connection.ts @@ -4,8 +4,8 @@ import { assertNever } from "../../types/internal"; import { VoidPtr } from "../../types/emscripten"; import type { CommonSocket } from "./common-socket"; -import { mono_log_debug, mono_log_warn } from "../../logging"; -import { localHeapViewU8 } from "../../memory"; +import { mono_log_debug, mono_log_warn } from "../../core/logging"; +import { localHeapViewU8 } from "../../core/memory"; enum ListenerState { Sending, Closed, diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/stream-queue.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/stream-queue.ts index c7b9f13db7e393..2b4668dfca08fe 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/stream-queue.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/stream-queue.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import { VoidPtr } from "../../types/emscripten"; -import * as Memory from "../../memory"; +import * as Memory from "../../core/memory"; /// One-reader, one-writer, size 1 queue for messages from an EventPipe streaming thread to diff --git a/src/mono/wasm/runtime/diagnostics/server_pthread/streaming-session.ts b/src/mono/wasm/runtime/diagnostics/server_pthread/streaming-session.ts index b8830ae488b84f..eea8b6ca7b33d9 100644 --- a/src/mono/wasm/runtime/diagnostics/server_pthread/streaming-session.ts +++ b/src/mono/wasm/runtime/diagnostics/server_pthread/streaming-session.ts @@ -7,13 +7,13 @@ import { EventPipeSocketConnection, takeOverSocket } from "./socket-connection"; import { StreamQueue, allocateQueue } from "./stream-queue"; import type { MockRemoteSocket } from "../mock"; import type { VoidPtr } from "../../types/emscripten"; -import { diagnostics_c_functions as cwraps } from "../../cwraps"; +import { diagnostics_c_functions as cwraps } from "../../core/cwraps"; import { EventPipeCommandCollectTracing2, EventPipeCollectTracingCommandProvider, } from "./protocol-client-commands"; import { createEventPipeStreamingSession } from "../shared/create-session"; -import { mono_assert } from "../../globals"; +import { mono_assert } from "../../core/globals"; /// The streaming session holds all the pieces of an event pipe streaming session that the /// diagnostic server knows about: the session ID, a diff --git a/src/mono/wasm/runtime/diagnostics/shared/create-session.ts b/src/mono/wasm/runtime/diagnostics/shared/create-session.ts index e6d80d2cb3a246..625af62b4f21a9 100644 --- a/src/mono/wasm/runtime/diagnostics/shared/create-session.ts +++ b/src/mono/wasm/runtime/diagnostics/shared/create-session.ts @@ -1,9 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import * as memory from "../../memory"; +import * as memory from "../../core/memory"; import { VoidPtr } from "../../types/emscripten"; -import { diagnostics_c_functions as cwraps } from "../../cwraps"; +import { diagnostics_c_functions as cwraps } from "../../core/cwraps"; import type { EventPipeSessionIDImpl } from "./types"; const sizeOfInt32 = 4; diff --git a/src/mono/wasm/runtime/hybrid-globalization/calendar.ts b/src/mono/wasm/runtime/hybrid-globalization/calendar.ts index 8f399f05887f51..4e4bf40340bee8 100644 --- a/src/mono/wasm/runtime/hybrid-globalization/calendar.ts +++ b/src/mono/wasm/runtime/hybrid-globalization/calendar.ts @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. /* eslint-disable no-inner-declarations */ -import { mono_wasm_new_external_root } from "../roots"; -import { monoStringToString, stringToUTF16 } from "../strings"; +import { mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString, stringToUTF16 } from "../core/strings"; import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal"; import { Int32Ptr } from "../types/emscripten"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; import { INNER_SEPARATOR, OUTER_SEPARATOR } from "./helpers"; const MONTH_CODE = "MMMM"; @@ -14,8 +14,7 @@ const YEAR_CODE = "yyyy"; const DAY_CODE = "d"; // this function joins all calendar info with OUTER_SEPARATOR into one string and returns it back to managed code -export function mono_wasm_get_calendar_info(culture: MonoStringRef, calendarId: number, dst: number, dstLength: number, isException: Int32Ptr, exAddress: MonoObjectRef): number -{ +export function mono_wasm_get_calendar_info(culture: MonoStringRef, calendarId: number, dst: number, dstLength: number, isException: Int32Ptr, exAddress: MonoObjectRef): number { const cultureRoot = mono_wasm_new_external_root(culture), exceptionRoot = mono_wasm_new_external_root(exAddress); try { @@ -55,10 +54,9 @@ export function mono_wasm_get_calendar_info(culture: MonoStringRef, calendarId: const eraNames = getEraNames(date, locale, calendarId); calendarInfo.EraNames = eraNames.eraNames; calendarInfo.AbbreviatedEraNames = eraNames.abbreviatedEraNames; - + const result = Object.values(calendarInfo).join(OUTER_SEPARATOR); - if (result.length > dstLength) - { + if (result.length > dstLength) { throw new Error(`Calendar info exceeds length of ${dstLength}.`); } stringToUTF16(dst, dst + 2 * result.length, result); @@ -75,15 +73,14 @@ export function mono_wasm_get_calendar_info(culture: MonoStringRef, calendarId: } } -function getCalendarName(locale: any){ +function getCalendarName(locale: any) { const calendars = getCalendarInfo(locale); if (!calendars || calendars.length == 0) return ""; return calendars[0]; } -function getCalendarInfo(locale: string) -{ +function getCalendarInfo(locale: string) { try { // most tools have it implemented as a property return (new Intl.Locale(locale) as any).calendars; @@ -100,13 +97,11 @@ function getCalendarInfo(locale: string) } } -function getMonthYearPattern(locale: string | undefined, date: Date): string -{ +function getMonthYearPattern(locale: string | undefined, date: Date): string { let pattern = date.toLocaleDateString(locale, { year: "numeric", month: "long" }).toLowerCase(); // pattern has month name as string or as number const monthName = date.toLocaleString(locale, { month: "long" }).toLowerCase().trim(); - if (monthName.charAt(monthName.length - 1) == "\u6708") - { + if (monthName.charAt(monthName.length - 1) == "\u6708") { // Chineese-like patterns: return "yyyy\u5e74M\u6708"; } @@ -117,13 +112,11 @@ function getMonthYearPattern(locale: string | undefined, date: Date): string return pattern.replace(yearStr, YEAR_CODE); } -function getMonthDayPattern(locale: string | undefined, date: Date): string -{ - let pattern = date.toLocaleDateString(locale, { month: "long", day: "numeric"}).toLowerCase(); +function getMonthDayPattern(locale: string | undefined, date: Date): string { + let pattern = date.toLocaleDateString(locale, { month: "long", day: "numeric" }).toLowerCase(); // pattern has month name as string or as number const monthName = date.toLocaleString(locale, { month: "long" }).toLowerCase().trim(); - if (monthName.charAt(monthName.length - 1) == "\u6708") - { + if (monthName.charAt(monthName.length - 1) == "\u6708") { // Chineese-like patterns: return "M\u6708d\u65e5"; } @@ -135,10 +128,8 @@ function getMonthDayPattern(locale: string | undefined, date: Date): string return pattern.replace(dayStr, DAY_CODE); } -function getShortDatePattern(locale: string | undefined): string -{ - if (locale?.substring(0, 2) == "fa") - { +function getShortDatePattern(locale: string | undefined): string { + if (locale?.substring(0, 2) == "fa") { // persian calendar is shifted and it has no lapping dates with // arabic and gregorian calendars, so that both day and month would be < 10 return "yyyy/M/d"; @@ -153,75 +144,65 @@ function getShortDatePattern(locale: string | undefined): string const shortMonthStr = "1"; const longDayStr = "02"; const shortDayStr = "2"; - let pattern = date.toLocaleDateString(locale, {dateStyle: "short"}); + let pattern = date.toLocaleDateString(locale, { dateStyle: "short" }); // each date part might be in localized numbers or standard arabic numbers // toLocaleDateString returns not compatible data, // e.g. { dateStyle: "short" } sometimes contains localized year number // while { year: "numeric" } contains non-localized year number and vice versa - if (pattern.includes(shortYearStr)) - { + if (pattern.includes(shortYearStr)) { pattern = pattern.replace(longYearStr, YEAR_CODE); pattern = pattern.replace(shortYearStr, YEAR_CODE); } - else - { + else { const yearStr = date.toLocaleDateString(locale, { year: "numeric" }); const yearStrShort = yearStr.substring(yearStr.length - 2, yearStr.length); pattern = pattern.replace(yearStr, YEAR_CODE); if (yearStrShort) pattern = pattern.replace(yearStrShort, YEAR_CODE); } - - if (pattern.includes(shortMonthStr)) - { + + if (pattern.includes(shortMonthStr)) { pattern = pattern.replace(longMonthStr, "MM"); pattern = pattern.replace(shortMonthStr, "M"); } - else - { + else { const monthStr = date.toLocaleDateString(locale, { month: "numeric" }); const localizedMonthCode = monthStr.length == 1 ? "M" : "MM"; pattern = pattern.replace(monthStr, localizedMonthCode); } - if (pattern.includes(shortDayStr)) - { + if (pattern.includes(shortDayStr)) { pattern = pattern.replace(longDayStr, "dd"); pattern = pattern.replace(shortDayStr, "d"); } - else - { + else { const dayStr = date.toLocaleDateString(locale, { day: "numeric" }); const localizedDayCode = dayStr.length == 1 ? "d" : "dd"; pattern = pattern.replace(dayStr, localizedDayCode); } - - + + return pattern; } -function getLongDatePattern(locale: string | undefined, date: Date): string -{ - if (locale == "th-TH") - { +function getLongDatePattern(locale: string | undefined, date: Date): string { + if (locale == "th-TH") { // cannot be caught with regexes return "ddddที่ d MMMM g yyyy"; } - let pattern = new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", month: "long", day: "numeric"}).format(date).toLowerCase(); + let pattern = new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", month: "long", day: "numeric" }).format(date).toLowerCase(); const monthName = date.toLocaleString(locale, { month: "long" }).trim().toLowerCase(); // pattern has month name as string or as number const monthSuffix = monthName.charAt(monthName.length - 1); - if (monthSuffix == "\u6708" || monthSuffix == "\uc6d4") - { + if (monthSuffix == "\u6708" || monthSuffix == "\uc6d4") { // Asian-like patterns: const shortMonthName = date.toLocaleString(locale, { month: "short" }); pattern = pattern.replace(shortMonthName, `M${monthSuffix}`); } - else - { - const replacedMonthName = getGenitiveForName(date, pattern, monthName, new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", day: "numeric"})); - pattern = pattern.replace(replacedMonthName, MONTH_CODE); + else { + const replacedMonthName = getGenitiveForName(date, pattern, monthName, new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", day: "numeric" })); + pattern = pattern.replace(replacedMonthName, MONTH_CODE); } pattern = pattern.replace("999", YEAR_CODE); // sometimes the number is localized and the above does not have an effect, @@ -229,21 +210,19 @@ function getLongDatePattern(locale: string | undefined, date: Date): string const yearStr = date.toLocaleDateString(locale, { year: "numeric" }); pattern = pattern.replace(yearStr, YEAR_CODE); const weekday = date.toLocaleDateString(locale, { weekday: "long" }).toLowerCase(); - const replacedWeekday = getGenitiveForName(date, pattern, weekday, new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric"})); + const replacedWeekday = getGenitiveForName(date, pattern, weekday, new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric" })); pattern = pattern.replace(replacedWeekday, "dddd"); pattern = pattern.replace("22", DAY_CODE); const dayStr = date.toLocaleDateString(locale, { day: "numeric" }); // should we replace it for localized digits? return pattern.replace(dayStr, DAY_CODE); } -function getGenitiveForName(date: Date, pattern: string, name: string, formatWithoutName: Intl.DateTimeFormat) -{ +function getGenitiveForName(date: Date, pattern: string, name: string, formatWithoutName: Intl.DateTimeFormat) { let genitiveName = name; const nameStart = pattern.indexOf(name); if (nameStart == -1 || // genitive month name can include monthName and monthName can include spaces, e.g. "tháng 11":, so we cannot use pattern.includes() or pattern.split(" ").includes() - (nameStart != -1 && pattern.length > nameStart + name.length && pattern[nameStart + name.length] != " " && pattern[nameStart + name.length] != "," && pattern[nameStart + name.length] != "\u060c")) - { + (nameStart != -1 && pattern.length > nameStart + name.length && pattern[nameStart + name.length] != " " && pattern[nameStart + name.length] != "," && pattern[nameStart + name.length] != "\u060c")) { // needs to be in Genitive form to be useful // e.g. // pattern = '999 m. lapkričio 22 d., šeštadienis', @@ -256,24 +235,21 @@ function getGenitiveForName(date: Date, pattern: string, name: string, formatWit return genitiveName; } -function getDayNames(locale: string | undefined) : { long: string[], abbreviated: string[], shortest: string[] } -{ +function getDayNames(locale: string | undefined): { long: string[], abbreviated: string[], shortest: string[] } { const weekDay = new Date(2023, 5, 25); // Sunday const dayNames = []; const dayNamesAbb = []; const dayNamesSS = []; - for(let i=0; i<7; i++) - { + for (let i = 0; i < 7; i++) { dayNames[i] = weekDay.toLocaleDateString(locale, { weekday: "long" }); dayNamesAbb[i] = weekDay.toLocaleDateString(locale, { weekday: "short" }); dayNamesSS[i] = weekDay.toLocaleDateString(locale, { weekday: "narrow" }); weekDay.setDate(weekDay.getDate() + 1); } - return {long: dayNames, abbreviated: dayNamesAbb, shortest: dayNamesSS }; + return { long: dayNames, abbreviated: dayNamesAbb, shortest: dayNamesSS }; } -function getMonthNames(locale: string | undefined) : { long: string[], abbreviated: string[], longGenitive: string[], abbreviatedGenitive: string[] } -{ +function getMonthNames(locale: string | undefined): { long: string[], abbreviated: string[], longGenitive: string[], abbreviatedGenitive: string[] } { // some calendars have the first month on non-0 index in JS // first month: Muharram ("ar") or Farwardin ("fa") or January const localeLang = locale ? locale.split("-")[0] : ""; @@ -284,8 +260,7 @@ function getMonthNames(locale: string | undefined) : { long: string[], abbreviat const monthsGen: string[] = []; const monthsAbbGen: string[] = []; let isChineeseStyle, isShortFormBroken; - for(let i = firstMonthShift; i < 12 + firstMonthShift; i++) - { + for (let i = firstMonthShift; i < 12 + firstMonthShift; i++) { const monthCnt = i % 12; date.setMonth(monthCnt); @@ -295,36 +270,32 @@ function getMonthNames(locale: string | undefined) : { long: string[], abbreviat monthsAbb[i - firstMonthShift] = monthNameShort; // for Genitive forms: isChineeseStyle = isChineeseStyle ?? monthNameLong.charAt(monthNameLong.length - 1) == "\u6708"; - if (isChineeseStyle) - { + if (isChineeseStyle) { // for Chinese-like calendar's Genitive = Nominative monthsGen[i - firstMonthShift] = monthNameLong; monthsAbbGen[i - firstMonthShift] = monthNameShort; continue; } const formatWithoutMonthName = new Intl.DateTimeFormat(locale, { day: "numeric" }); - const monthWithDayLong = date.toLocaleDateString(locale, { month: "long", day: "numeric"}); + const monthWithDayLong = date.toLocaleDateString(locale, { month: "long", day: "numeric" }); monthsGen[i - firstMonthShift] = getGenitiveForName(date, monthWithDayLong, monthNameLong, formatWithoutMonthName); isShortFormBroken = isShortFormBroken ?? /^\d+$/.test(monthNameShort); - if (isShortFormBroken) - { + if (isShortFormBroken) { // for buggy locales e.g. lt-LT, short month contains only number instead of string // we leave Genitive = Nominative monthsAbbGen[i - firstMonthShift] = monthNameShort; continue; } - const monthWithDayShort = date.toLocaleDateString(locale, { month: "short", day: "numeric"}); + const monthWithDayShort = date.toLocaleDateString(locale, { month: "short", day: "numeric" }); monthsAbbGen[i - firstMonthShift] = getGenitiveForName(date, monthWithDayShort, monthNameShort, formatWithoutMonthName); } - return {long: months, abbreviated: monthsAbb, longGenitive: monthsGen, abbreviatedGenitive: monthsAbbGen }; + return { long: months, abbreviated: monthsAbb, longGenitive: monthsGen, abbreviatedGenitive: monthsAbbGen }; } // .NET expects that only the Japanese calendars have more than 1 era. // So for other calendars, only return the latest era. -function getEraNames(date: Date, locale: string | undefined, calendarId: number) : { eraNames: string, abbreviatedEraNames: string} -{ - if (shouldBePopulatedByManagedCode(calendarId)) - { +function getEraNames(date: Date, locale: string | undefined, calendarId: number): { eraNames: string, abbreviatedEraNames: string } { + if (shouldBePopulatedByManagedCode(calendarId)) { // managed code already handles these calendars, // so empty strings will get overwritten in // InitializeEraNames/InitializeAbbreviatedEraNames @@ -337,7 +308,7 @@ function getEraNames(date: Date, locale: string | undefined, calendarId: number) const dayStr = date.toLocaleDateString(locale, { day: "numeric" }); const eraDate = date.toLocaleDateString(locale, { era: "short" }); const shortEraDate = date.toLocaleDateString(locale, { era: "narrow" }); - + const eraDateParts = eraDate.includes(yearStr) ? getEraDateParts(yearStr) : getEraDateParts(date.getFullYear().toString()); @@ -347,13 +318,11 @@ function getEraNames(date: Date, locale: string | undefined, calendarId: number) abbreviatedEraNames: getEraFromDateParts(eraDateParts.abbrEraDateParts, eraDateParts.ignoredPart) }; - function shouldBePopulatedByManagedCode(calendarId: number) - { + function shouldBePopulatedByManagedCode(calendarId: number) { return (calendarId > 1 && calendarId < 15) || calendarId == 22 || calendarId == 23; } - function getEraFromDateParts(dateParts: string[], ignoredPart: string) : string - { + function getEraFromDateParts(dateParts: string[], ignoredPart: string): string { const regex = new RegExp(`^((?!${ignoredPart}|[0-9]).)*$`); const filteredEra = dateParts.filter(part => regex.test(part)); if (filteredEra.length == 0) @@ -361,17 +330,15 @@ function getEraNames(date: Date, locale: string | undefined, calendarId: number) return filteredEra[0].trim(); } - function getEraDateParts(yearStr: string) - { - if (eraDate.startsWith(yearStr) || eraDate.endsWith(yearStr)) - { - return { + function getEraDateParts(yearStr: string) { + if (eraDate.startsWith(yearStr) || eraDate.endsWith(yearStr)) { + return { eraDateParts: eraDate.split(dayStr), abbrEraDateParts: shortEraDate.split(dayStr), ignoredPart: yearStr, }; } - return { + return { eraDateParts: eraDate.split(yearStr), abbrEraDateParts: shortEraDate.split(yearStr), ignoredPart: dayStr, diff --git a/src/mono/wasm/runtime/hybrid-globalization/change-case.ts b/src/mono/wasm/runtime/hybrid-globalization/change-case.ts index ea6fa2dfa181cd..a0eb837111429a 100644 --- a/src/mono/wasm/runtime/hybrid-globalization/change-case.ts +++ b/src/mono/wasm/runtime/hybrid-globalization/change-case.ts @@ -1,12 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { mono_wasm_new_external_root } from "../roots"; -import { monoStringToString, utf16ToStringLoop, stringToUTF16 } from "../strings"; +import { mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString, utf16ToStringLoop, stringToUTF16 } from "../core/strings"; import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal"; import { Int32Ptr } from "../types/emscripten"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { localHeapViewU16, setU16_local } from "../memory"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { localHeapViewU16, setU16_local } from "../core/memory"; const SURROGATE_HIGHER_START = "\uD800"; const SURROGATE_HIGHER_END = "\uDBFF"; @@ -20,8 +20,7 @@ export function mono_wasm_change_case_invariant(src: number, srcLength: number, const result = toUpper ? input.toUpperCase() : input.toLowerCase(); // Unicode defines some codepoints which expand into multiple codepoints, // originally we do not support this expansion - if (result.length <= dstLength) - { + if (result.length <= dstLength) { stringToUTF16(dst, dst + 2 * dstLength, result); wrap_no_error_root(is_exception, exceptionRoot); return; @@ -30,48 +29,40 @@ export function mono_wasm_change_case_invariant(src: number, srcLength: number, // workaround to maintain the ICU-like behavior const heapI16 = localHeapViewU16(); let jump = 1; - if (toUpper) - { - for (let i=0; i < input.length; i+=jump) - { + if (toUpper) { + for (let i = 0; i < input.length; i += jump) { // surrogate parts have to enter ToUpper/ToLower together to give correct output - if (isSurrogate(input, i)) - { + if (isSurrogate(input, i)) { jump = 2; - const surrogate = input.substring(i, i+2); + const surrogate = input.substring(i, i + 2); const upperSurrogate = surrogate.toUpperCase(); const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate; appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i); } - else - { + else { jump = 1; const upperChar = input[i].toUpperCase(); const appendedChar = upperChar.length > 1 ? input[i] : upperChar; - setU16_local(heapI16, dst + i*2, appendedChar.charCodeAt(0)); + setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0)); } } } - else - { - for (let i=0; i < input.length; i+=jump) - { - if (isSurrogate(input, i)) - { + else { + for (let i = 0; i < input.length; i += jump) { + if (isSurrogate(input, i)) { jump = 2; - const surrogate = input.substring(i, i+2); + const surrogate = input.substring(i, i + 2); const upperSurrogate = surrogate.toLowerCase(); const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate; appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i); } - else - { + else { jump = 1; const upperChar = input[i].toLowerCase(); const appendedChar = upperChar.length > 1 ? input[i] : upperChar; - setU16_local(heapI16, dst + i*2, appendedChar.charCodeAt(0)); + setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0)); } } } @@ -94,8 +85,7 @@ export function mono_wasm_change_case(culture: MonoStringRef, src: number, srcLe const input = utf16ToStringLoop(src, src + 2 * srcLength); const result = toUpper ? input.toLocaleUpperCase(cultureName) : input.toLocaleLowerCase(cultureName); - if (result.length <= input.length) - { + if (result.length <= input.length) { stringToUTF16(dst, dst + 2 * dstLength, result); wrap_no_error_root(is_exception, exceptionRoot); return; @@ -103,48 +93,40 @@ export function mono_wasm_change_case(culture: MonoStringRef, src: number, srcLe // workaround to maintain the ICU-like behavior const heapI16 = localHeapViewU16(); let jump = 1; - if (toUpper) - { - for (let i=0; i < input.length; i+=jump) - { + if (toUpper) { + for (let i = 0; i < input.length; i += jump) { // surrogate parts have to enter ToUpper/ToLower together to give correct output - if (isSurrogate(input, i)) - { + if (isSurrogate(input, i)) { jump = 2; - const surrogate = input.substring(i, i+2); + const surrogate = input.substring(i, i + 2); const upperSurrogate = surrogate.toLocaleUpperCase(cultureName); const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate; appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i); } - else - { + else { jump = 1; const upperChar = input[i].toLocaleUpperCase(cultureName); const appendedChar = upperChar.length > 1 ? input[i] : upperChar; - setU16_local(heapI16, dst + i*2, appendedChar.charCodeAt(0)); + setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0)); } } } - else - { - for (let i=0; i < input.length; i+=jump) - { + else { + for (let i = 0; i < input.length; i += jump) { // surrogate parts have to enter ToUpper/ToLower together to give correct output - if (isSurrogate(input, i)) - { + if (isSurrogate(input, i)) { jump = 2; - const surrogate = input.substring(i, i+2); + const surrogate = input.substring(i, i + 2); const upperSurrogate = surrogate.toLocaleLowerCase(cultureName); const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate; appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i); } - else - { + else { jump = 1; const lowerChar = input[i].toLocaleLowerCase(cultureName); const appendedChar = lowerChar.length > 1 ? input[i] : lowerChar; - setU16_local(heapI16, dst + i*2, appendedChar.charCodeAt(0)); + setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0)); } } } @@ -159,17 +141,15 @@ export function mono_wasm_change_case(culture: MonoStringRef, src: number, srcLe } } -function isSurrogate(str: string, startIdx: number) : boolean -{ +function isSurrogate(str: string, startIdx: number): boolean { return SURROGATE_HIGHER_START <= str[startIdx] && str[startIdx] <= SURROGATE_HIGHER_END && - startIdx+1 < str.length && - SURROGATE_LOWER_START <= str[startIdx+1] && - str[startIdx+1] <= SURROGATE_LOWER_END; + startIdx + 1 < str.length && + SURROGATE_LOWER_START <= str[startIdx + 1] && + str[startIdx + 1] <= SURROGATE_LOWER_END; } -function appendSurrogateToMemory(heapI16: Uint16Array, dst: number, surrogate: string, idx: number) -{ - setU16_local(heapI16, dst + idx*2, surrogate.charCodeAt(0)); - setU16_local(heapI16, dst + (idx+1)*2, surrogate.charCodeAt(1)); +function appendSurrogateToMemory(heapI16: Uint16Array, dst: number, surrogate: string, idx: number) { + setU16_local(heapI16, dst + idx * 2, surrogate.charCodeAt(0)); + setU16_local(heapI16, dst + (idx + 1) * 2, surrogate.charCodeAt(1)); } diff --git a/src/mono/wasm/runtime/hybrid-globalization/collations.ts b/src/mono/wasm/runtime/hybrid-globalization/collations.ts index 9ec14b2a31dde9..339249bcd53035 100644 --- a/src/mono/wasm/runtime/hybrid-globalization/collations.ts +++ b/src/mono/wasm/runtime/hybrid-globalization/collations.ts @@ -1,11 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { mono_wasm_new_external_root } from "../roots"; -import { monoStringToString, utf16ToString } from "../strings"; +import { mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString, utf16ToString } from "../core/strings"; import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal"; import { Int32Ptr } from "../types/emscripten"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; const COMPARISON_ERROR = -2; const INDEXING_ERROR = -1; diff --git a/src/mono/wasm/runtime/hybrid-globalization/culture-info.ts b/src/mono/wasm/runtime/hybrid-globalization/culture-info.ts index 825ff9d709f466..44dd94b658cc11 100644 --- a/src/mono/wasm/runtime/hybrid-globalization/culture-info.ts +++ b/src/mono/wasm/runtime/hybrid-globalization/culture-info.ts @@ -1,15 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { mono_wasm_new_external_root } from "../roots"; -import { monoStringToString, stringToUTF16 } from "../strings"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString, stringToUTF16 } from "../core/strings"; import { Int32Ptr } from "../types/emscripten"; import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal"; import { OUTER_SEPARATOR, normalizeLocale } from "./helpers"; -export function mono_wasm_get_culture_info(culture: MonoStringRef, dst: number, dstLength: number, isException: Int32Ptr, exAddress: MonoObjectRef): number -{ +export function mono_wasm_get_culture_info(culture: MonoStringRef, dst: number, dstLength: number, isException: Int32Ptr, exAddress: MonoObjectRef): number { const cultureRoot = mono_wasm_new_external_root(culture), exceptionRoot = mono_wasm_new_external_root(exAddress); try { @@ -27,8 +26,7 @@ export function mono_wasm_get_culture_info(culture: MonoStringRef, dst: number, cultureInfo.LongTimePattern = getLongTimePattern(canonicalLocale, designators); cultureInfo.ShortTimePattern = getShortTimePattern(cultureInfo.LongTimePattern); const result = Object.values(cultureInfo).join(OUTER_SEPARATOR); - if (result.length > dstLength) - { + if (result.length > dstLength) { throw new Error(`Culture info exceeds length of ${dstLength}.`); } stringToUTF16(dst, dst + 2 * result.length, result); @@ -45,8 +43,7 @@ export function mono_wasm_get_culture_info(culture: MonoStringRef, dst: number, } } -function getAmPmDesignators(locale: any) -{ +function getAmPmDesignators(locale: any) { const pmTime = new Date("August 19, 1975 12:15:33"); // do not change, some PM hours result in hour digits change, e.g. 13 -> 01 or 1 const amTime = new Date("August 19, 1975 11:15:33"); // do not change, some AM hours result in hour digits change, e.g. 9 -> 09 const pmDesignator = getDesignator(pmTime, locale); @@ -57,19 +54,17 @@ function getAmPmDesignators(locale: any) }; } -function getDesignator(time: Date, locale: string) -{ - let withDesignator = time.toLocaleTimeString(locale, { hourCycle: "h12"}); +function getDesignator(time: Date, locale: string) { + let withDesignator = time.toLocaleTimeString(locale, { hourCycle: "h12" }); const localizedZero = (0).toLocaleString(locale); - if (withDesignator.includes(localizedZero)) - { + if (withDesignator.includes(localizedZero)) { // in v8>=11.8 "12" changes to "0" for ja-JP const localizedTwelve = (12).toLocaleString(locale); withDesignator = withDesignator.replace(localizedZero, localizedTwelve); } - const withoutDesignator = time.toLocaleTimeString(locale, { hourCycle: "h24"}); + const withoutDesignator = time.toLocaleTimeString(locale, { hourCycle: "h24" }); const designator = withDesignator.replace(withoutDesignator, "").trim(); - if (new RegExp("[0-9]$").test(designator)){ + if (new RegExp("[0-9]$").test(designator)) { const designatorParts = withDesignator.split(" ").filter(part => new RegExp("^((?![0-9]).)*$").test(part)); if (!designatorParts || designatorParts.length == 0) return ""; @@ -78,8 +73,7 @@ function getDesignator(time: Date, locale: string) return designator; } -function getLongTimePattern(locale: string | undefined, designators: any) : string -{ +function getLongTimePattern(locale: string | undefined, designators: any): string { const hourIn24Format = 18; // later hours than 18 have night designators in some locales (instead of AM designator) const hourIn12Format = 6; const localizedHour24 = (hourIn24Format).toLocaleString(locale); // not all locales use arabic numbers @@ -113,23 +107,19 @@ function getLongTimePattern(locale: string | undefined, designators: any) : stri return pattern; } -function getShortTimePattern(pattern: string) : string -{ +function getShortTimePattern(pattern: string): string { // remove seconds: // short dotnet pattern does not contain seconds while JS's pattern always contains them const secondsIdx = pattern.indexOf("ss"); - if (secondsIdx > 0) - { + if (secondsIdx > 0) { const secondsWithSeparator = `${pattern[secondsIdx - 1]}ss`; // en-US: 12:mm:ss tt -> 12:mm tt; // fr-CA: 12 h mm min ss s -> 12 h mm min s const shortPatternNoSecondsDigits = pattern.replace(secondsWithSeparator, ""); - if (shortPatternNoSecondsDigits.length > secondsIdx && shortPatternNoSecondsDigits[shortPatternNoSecondsDigits.length - 1] != "t") - { + if (shortPatternNoSecondsDigits.length > secondsIdx && shortPatternNoSecondsDigits[shortPatternNoSecondsDigits.length - 1] != "t") { pattern = pattern.split(secondsWithSeparator)[0]; } - else - { + else { pattern = shortPatternNoSecondsDigits; } } diff --git a/src/mono/wasm/runtime/hybrid-globalization/locales.ts b/src/mono/wasm/runtime/hybrid-globalization/locales.ts index 98d3755754a13d..d57430f4afe8a1 100644 --- a/src/mono/wasm/runtime/hybrid-globalization/locales.ts +++ b/src/mono/wasm/runtime/hybrid-globalization/locales.ts @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { wrap_error_root } from "../invoke-js"; -import { mono_wasm_new_external_root } from "../roots"; -import { monoStringToString } from "../strings"; +import { wrap_error_root } from "../interop/invoke-js"; +import { mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString } from "../core/strings"; import { Int32Ptr } from "../types/emscripten"; import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal"; import { normalizeLocale } from "./helpers"; -export function mono_wasm_get_first_day_of_week(culture: MonoStringRef, isException: Int32Ptr, exAddress: MonoObjectRef): number{ +export function mono_wasm_get_first_day_of_week(culture: MonoStringRef, isException: Int32Ptr, exAddress: MonoObjectRef): number { const cultureRoot = mono_wasm_new_external_root(culture), exceptionRoot = mono_wasm_new_external_root(exAddress); @@ -27,7 +27,7 @@ export function mono_wasm_get_first_day_of_week(culture: MonoStringRef, isExcept } } -export function mono_wasm_get_first_week_of_year(culture: MonoStringRef, isException: Int32Ptr, exAddress: MonoObjectRef): number{ +export function mono_wasm_get_first_week_of_year(culture: MonoStringRef, isException: Int32Ptr, exAddress: MonoObjectRef): number { const cultureRoot = mono_wasm_new_external_root(culture), exceptionRoot = mono_wasm_new_external_root(exAddress); @@ -46,36 +46,30 @@ export function mono_wasm_get_first_week_of_year(culture: MonoStringRef, isExcep } } -function getFirstDayOfWeek(locale: string) -{ +function getFirstDayOfWeek(locale: string) { const weekInfo = getWeekInfo(locale); - if (weekInfo) - { + if (weekInfo) { // JS's Sunday == 7 while dotnet's Sunday == 0 return weekInfo.firstDay == 7 ? 0 : weekInfo.firstDay; } // Firefox does not support it rn but we can make a temporary workaround for it, // that should be removed when it starts being supported: - const saturdayLocales = [ "en-AE", "en-SD", "fa-IR" ]; - if (saturdayLocales.includes(locale)) - { + const saturdayLocales = ["en-AE", "en-SD", "fa-IR"]; + if (saturdayLocales.includes(locale)) { return 6; } - const sundayLanguages = [ "zh", "th", "pt", "mr", "ml", "ko", "kn", "ja", "id", "hi", "he", "gu", "fil", "bn", "am", "ar" ]; - const sundayLocales = [ "ta-SG", "ta-IN", "sw-KE", "ms-SG", "fr-CA", "es-MX", "en-US", "en-ZW", "en-ZA", "en-WS", "en-VI", "en-UM", "en-TT", "en-SG", "en-PR", "en-PK", "en-PH", "en-MT", "en-MO", "en-MH", "en-KE", "en-JM", "en-IN", "en-IL", "en-HK", "en-GU", "en-DM", "en-CA", "en-BZ", "en-BW", "en-BS", "en-AU", "en-AS", "en-AG" ]; + const sundayLanguages = ["zh", "th", "pt", "mr", "ml", "ko", "kn", "ja", "id", "hi", "he", "gu", "fil", "bn", "am", "ar"]; + const sundayLocales = ["ta-SG", "ta-IN", "sw-KE", "ms-SG", "fr-CA", "es-MX", "en-US", "en-ZW", "en-ZA", "en-WS", "en-VI", "en-UM", "en-TT", "en-SG", "en-PR", "en-PK", "en-PH", "en-MT", "en-MO", "en-MH", "en-KE", "en-JM", "en-IN", "en-IL", "en-HK", "en-GU", "en-DM", "en-CA", "en-BZ", "en-BW", "en-BS", "en-AU", "en-AS", "en-AG"]; const localeLang = locale.split("-")[0]; - if (sundayLanguages.includes(localeLang) || sundayLocales.includes(locale)) - { + if (sundayLanguages.includes(localeLang) || sundayLocales.includes(locale)) { return 0; } return 1; } -function getFirstWeekOfYear(locale: string) -{ +function getFirstWeekOfYear(locale: string) { const weekInfo = getWeekInfo(locale); - if (weekInfo) - { + if (weekInfo) { // enum CalendarWeekRule // FirstDay = 0, // when minimalDays < 4 // FirstFullWeek = 1, // when miminalDays == 7 @@ -85,18 +79,16 @@ function getFirstWeekOfYear(locale: string) } // Firefox does not support it rn but we can make a temporary workaround for it, // that should be removed when it starts being supported: - const firstFourDayWeekLocales = [ "pt-PT", "fr-CH", "fr-FR", "fr-BE", "es-ES", "en-SE", "en-NL", "en-JE", "en-IM", "en-IE", "en-GI", "en-GG", "en-GB", "en-FJ", "en-FI", "en-DK", "en-DE", "en-CH", "en-BE", "en-AT", "el-GR" ]; - const firstFourDayWeekLanguages = [ "sv", "sk", "ru", "pl", "nl", "no", "lt", "it", "hu", "fi", "et", "de", "da", "cs", "ca", "bg" ]; + const firstFourDayWeekLocales = ["pt-PT", "fr-CH", "fr-FR", "fr-BE", "es-ES", "en-SE", "en-NL", "en-JE", "en-IM", "en-IE", "en-GI", "en-GG", "en-GB", "en-FJ", "en-FI", "en-DK", "en-DE", "en-CH", "en-BE", "en-AT", "el-GR"]; + const firstFourDayWeekLanguages = ["sv", "sk", "ru", "pl", "nl", "no", "lt", "it", "hu", "fi", "et", "de", "da", "cs", "ca", "bg"]; const localeLang = locale.split("-")[0]; - if (firstFourDayWeekLocales.includes(locale) || firstFourDayWeekLanguages.includes(localeLang)) - { + if (firstFourDayWeekLocales.includes(locale) || firstFourDayWeekLanguages.includes(localeLang)) { return 2; } return 0; } -function getWeekInfo(locale: string) -{ +function getWeekInfo(locale: string) { try { // most tools have it implemented as property return (new Intl.Locale(locale) as any).weekInfo; diff --git a/src/mono/wasm/runtime/interop/from-core.ts b/src/mono/wasm/runtime/interop/from-core.ts new file mode 100644 index 00000000000000..722c1a9391752e --- /dev/null +++ b/src/mono/wasm/runtime/interop/from-core.ts @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +export type { Int32Ptr, TypedArray } from "../types/emscripten"; +export { + GCHandleNull, JSHandleNull, MonoObjectNull, MonoObjectRefNull, VoidPtrNull +} from "../types/internal"; +export type { + BoundMarshalerToCs, BoundMarshalerToJs, GCHandle, JSFnHandle, JSFunctionSignature, JSHandle, + JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, MonoMethod, + MonoObject, MonoObjectRef, MonoString, MonoStringRef, WasmRoot +} from "../types/internal"; + +export { isThenable, wrap_as_cancelable_promise } from "../core/cancelable-promise"; +export { assembly_load } from "../core/class-loader"; +export { default as cwraps } from "../core/cwraps"; +export { + _lookup_js_owned_object, assert_not_disposed, cs_owned_js_handle_symbol, js_owned_gc_handle_symbol, + mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, setup_managed_proxy, teardown_managed_proxy +} from "../core/gc-handles"; +export { INTERNAL, Module, createPromiseController, loaderHelpers, mono_assert, runtimeHelpers } from "../core/globals"; +export { mono_log_debug, mono_log_warn, mono_wasm_symbolicate_string } from "../core/logging"; +export { + _zero_region, getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, localHeapViewF64, localHeapViewI32, localHeapViewU8, receiveWorkerHeapViews, setF32, setF64, setI16, setI32, setI32_unchecked, setI64Big, setU16, setU32, setU8 +} from "../core/memory"; +export { MeasuredBlock, endMeasure, startMeasure } from "../core/profiler"; +export { mono_wasm_new_external_root, mono_wasm_new_root } from "../core/roots"; +export { monoStringToString, stringToMonoStringRoot } from "../core/strings"; +export { assert_synchronization_context } from "../pthreads/shared"; +export { addUnsettledPromise, settleUnsettledPromise } from "../pthreads/shared/eventloop"; +export { assert_bindings, wrap_error_root, wrap_no_error_root } from "./invoke-js"; +export { bind_arg_marshal_to_cs, get_marshaler_to_cs_by_type, jsinteropDoc, marshal_exception_to_cs } from "./marshal-to-cs"; +export { bind_arg_marshal_to_js, get_marshaler_to_js_by_type, marshal_exception_to_js } from "./marshal-to-js"; + + diff --git a/src/mono/wasm/runtime/invoke-cs.ts b/src/mono/wasm/runtime/interop/invoke-cs.ts similarity index 93% rename from src/mono/wasm/runtime/invoke-cs.ts rename to src/mono/wasm/runtime/interop/invoke-cs.ts index b38393a6fe6f4e..b7da1bdbe1901b 100644 --- a/src/mono/wasm/runtime/invoke-cs.ts +++ b/src/mono/wasm/runtime/interop/invoke-cs.ts @@ -4,23 +4,21 @@ import BuildConfiguration from "consts:configuration"; import MonoWasmThreads from "consts:monoWasmThreads"; -import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; -import { bind_arg_marshal_to_cs } from "./marshal-to-cs"; -import { marshal_exception_to_js, bind_arg_marshal_to_js } from "./marshal-to-js"; +import { assert_synchronization_context } from "../pthreads/shared"; +import { Int32Ptr } from "../types/emscripten"; +import { BoundMarshalerToCs, BoundMarshalerToJs, JSFunctionSignature, JSMarshalerArguments, MarshalerType, MonoMethod, MonoObject, MonoObjectNull, MonoObjectRef, MonoObjectRefNull, MonoString, MonoStringRef, VoidPtrNull } from "../types/internal"; +import { MeasuredBlock, Module, assembly_load, cwraps, endMeasure, loaderHelpers, monoStringToString, mono_assert, mono_log_debug, mono_wasm_new_external_root, mono_wasm_new_root, runtimeHelpers, startMeasure } from "./from-core"; +import { assert_bindings, wrap_error_root, wrap_no_error_root } from "./invoke-js"; import { - get_arg, get_sig, get_signature_argument_count, is_args_exception, - bound_cs_function_symbol, get_signature_version, alloc_stack_frame, get_signature_type, + alloc_stack_frame, + bound_cs_function_symbol, + get_arg, get_sig, get_signature_argument_count, + get_signature_type, + get_signature_version, + is_args_exception, } from "./marshal"; -import { mono_wasm_new_external_root, mono_wasm_new_root } from "./roots"; -import { monoStringToString } from "./strings"; -import { MonoObjectRef, MonoStringRef, MonoString, MonoObject, MonoMethod, JSMarshalerArguments, JSFunctionSignature, BoundMarshalerToCs, BoundMarshalerToJs, VoidPtrNull, MonoObjectRefNull, MonoObjectNull, MarshalerType } from "./types/internal"; -import { Int32Ptr } from "./types/emscripten"; -import cwraps from "./cwraps"; -import { assembly_load } from "./class-loader"; -import { assert_bindings, wrap_error_root, wrap_no_error_root } from "./invoke-js"; -import { startMeasure, MeasuredBlock, endMeasure } from "./profiler"; -import { mono_log_debug } from "./logging"; -import { assert_synchronization_context } from "./pthreads/shared"; +import { bind_arg_marshal_to_cs } from "./marshal-to-cs"; +import { bind_arg_marshal_to_js, marshal_exception_to_js } from "./marshal-to-js"; export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef, signature_hash: number, signature: JSFunctionSignature, is_exception: Int32Ptr, result_address: MonoObjectRef): void { assert_bindings(); diff --git a/src/mono/wasm/runtime/invoke-js.ts b/src/mono/wasm/runtime/interop/invoke-js.ts similarity index 93% rename from src/mono/wasm/runtime/invoke-js.ts rename to src/mono/wasm/runtime/interop/invoke-js.ts index a17ef89be3f06f..5ad29c350c364a 100644 --- a/src/mono/wasm/runtime/invoke-js.ts +++ b/src/mono/wasm/runtime/interop/invoke-js.ts @@ -1,23 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; import BuildConfiguration from "consts:configuration"; +import MonoWasmThreads from "consts:monoWasmThreads"; -import { marshal_exception_to_cs, bind_arg_marshal_to_cs } from "./marshal-to-cs"; -import { get_signature_argument_count, bound_js_function_symbol, get_sig, get_signature_version, get_signature_type, imported_js_function_symbol } from "./marshal"; -import { setI32, setI32_unchecked, receiveWorkerHeapViews } from "./memory"; -import { monoStringToString, stringToMonoStringRoot } from "./strings"; -import { MonoObject, MonoObjectRef, MonoString, MonoStringRef, JSFunctionSignature, JSMarshalerArguments, WasmRoot, BoundMarshalerToJs, JSFnHandle, BoundMarshalerToCs, JSHandle, MarshalerType } from "./types/internal"; -import { Int32Ptr } from "./types/emscripten"; -import { INTERNAL, Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; +import { assert_synchronization_context } from "../pthreads/shared"; +import { Int32Ptr } from "../types/emscripten"; +import { BoundMarshalerToCs, BoundMarshalerToJs, JSFnHandle, JSFunctionSignature, JSHandle, JSMarshalerArguments, MarshalerType, MonoObject, MonoObjectRef, MonoString, MonoStringRef, WasmRoot } from "../types/internal"; +import { INTERNAL, MeasuredBlock, Module, endMeasure, loaderHelpers, monoStringToString, mono_assert, mono_log_debug, mono_wasm_get_jsobj_from_js_handle, mono_wasm_new_external_root, mono_wasm_symbolicate_string, receiveWorkerHeapViews, runtimeHelpers, setI32, setI32_unchecked, startMeasure, stringToMonoStringRoot, wrap_as_cancelable_promise } from "./from-core"; +import { bound_js_function_symbol, get_sig, get_signature_argument_count, get_signature_type, get_signature_version, imported_js_function_symbol } from "./marshal"; +import { bind_arg_marshal_to_cs, marshal_exception_to_cs } from "./marshal-to-cs"; import { bind_arg_marshal_to_js } from "./marshal-to-js"; -import { mono_wasm_new_external_root } from "./roots"; -import { mono_log_debug, mono_wasm_symbolicate_string } from "./logging"; -import { mono_wasm_get_jsobj_from_js_handle } from "./gc-handles"; -import { endMeasure, MeasuredBlock, startMeasure } from "./profiler"; -import { wrap_as_cancelable_promise } from "./cancelable-promise"; -import { assert_synchronization_context } from "./pthreads/shared"; export const fn_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. diff --git a/src/mono/wasm/runtime/marshal-to-cs.ts b/src/mono/wasm/runtime/interop/marshal-to-cs.ts similarity index 94% rename from src/mono/wasm/runtime/marshal-to-cs.ts rename to src/mono/wasm/runtime/interop/marshal-to-cs.ts index 14d6c7e3dd7479..e3336f6b1acebd 100644 --- a/src/mono/wasm/runtime/marshal-to-cs.ts +++ b/src/mono/wasm/runtime/interop/marshal-to-cs.ts @@ -1,28 +1,21 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; import BuildConfiguration from "consts:configuration"; +import MonoWasmThreads from "consts:monoWasmThreads"; -import { isThenable } from "./cancelable-promise"; -import cwraps from "./cwraps"; -import { assert_not_disposed, cs_owned_js_handle_symbol, js_owned_gc_handle_symbol, mono_wasm_get_js_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; -import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; +import { addUnsettledPromise, settleUnsettledPromise } from "../pthreads/shared/eventloop"; +import { TypedArray } from "../types/emscripten"; +import { BoundMarshalerToCs, GCHandle, GCHandleNull, JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, MarshalerType } from "../types/internal"; +import { Module, _zero_region, assert_not_disposed, cs_owned_js_handle_symbol, cwraps, isThenable, js_owned_gc_handle_symbol, loaderHelpers, localHeapViewF64, localHeapViewI32, localHeapViewU8, mono_assert, mono_log_warn, mono_wasm_get_js_handle, runtimeHelpers, setup_managed_proxy, stringToMonoStringRoot, teardown_managed_proxy } from "./from-core"; import { - ManagedError, - set_gc_handle, set_js_handle, set_arg_type, set_arg_i32, set_arg_f64, set_arg_i52, set_arg_f32, set_arg_i16, set_arg_u8, set_arg_b8, set_arg_date, - set_arg_length, get_arg, get_signature_arg1_type, get_signature_arg2_type, js_to_cs_marshalers, - get_signature_res_type, bound_js_function_symbol, set_arg_u16, array_element_size, - get_string_root, Span, ArraySegment, MemoryViewType, get_signature_arg3_type, set_arg_i64_big, set_arg_intptr, IDisposable, - set_arg_element_type, ManagedObject, JavaScriptMarshalerArgSize, proxy_debug_symbol + ArraySegment, IDisposable, JavaScriptMarshalerArgSize, ManagedError, ManagedObject, MemoryViewType, + Span, array_element_size, bound_js_function_symbol, get_arg, get_signature_arg1_type, get_signature_arg2_type, get_signature_arg3_type, get_signature_res_type, + get_string_root, js_to_cs_marshalers, proxy_debug_symbol, set_arg_b8, set_arg_date, set_arg_element_type, set_arg_f32, + set_arg_f64, set_arg_i16, set_arg_i32, set_arg_i52, set_arg_i64_big, set_arg_intptr, set_arg_length, + set_arg_type, set_arg_u16, set_arg_u8, set_gc_handle, set_js_handle } from "./marshal"; import { get_marshaler_to_js_by_type } from "./marshal-to-js"; -import { _zero_region, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory"; -import { stringToMonoStringRoot } from "./strings"; -import { GCHandle, GCHandleNull, JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, BoundMarshalerToCs, MarshalerType } from "./types/internal"; -import { TypedArray } from "./types/emscripten"; -import { addUnsettledPromise, settleUnsettledPromise } from "./pthreads/shared/eventloop"; -import { mono_log_warn } from "./logging"; export const jsinteropDoc = "For more information see https://aka.ms/dotnet-wasm-jsinterop"; diff --git a/src/mono/wasm/runtime/marshal-to-js.ts b/src/mono/wasm/runtime/interop/marshal-to-js.ts similarity index 94% rename from src/mono/wasm/runtime/marshal-to-js.ts rename to src/mono/wasm/runtime/interop/marshal-to-js.ts index 1ad71dbc4ae784..a04548c90e0a54 100644 --- a/src/mono/wasm/runtime/marshal-to-js.ts +++ b/src/mono/wasm/runtime/interop/marshal-to-js.ts @@ -1,25 +1,21 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; import BuildConfiguration from "consts:configuration"; +import MonoWasmThreads from "consts:monoWasmThreads"; -import cwraps from "./cwraps"; -import { _lookup_js_owned_object, mono_wasm_get_jsobj_from_js_handle, mono_wasm_get_js_handle, setup_managed_proxy, teardown_managed_proxy } from "./gc-handles"; -import { Module, createPromiseController, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; +import { TypedArray } from "../types/emscripten"; +import { BoundMarshalerToJs, GCHandleNull, JSHandleNull, JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, MarshalerType } from "../types/internal"; +import { Module, _lookup_js_owned_object, createPromiseController, cwraps, loaderHelpers, localHeapViewF64, localHeapViewI32, localHeapViewU8, monoStringToString, mono_assert, mono_wasm_get_js_handle, mono_wasm_get_jsobj_from_js_handle, runtimeHelpers, setup_managed_proxy, teardown_managed_proxy } from "./from-core"; import { - ManagedObject, ManagedError, - get_arg_gc_handle, get_arg_js_handle, get_arg_type, get_arg_i32, get_arg_f64, get_arg_i52, get_arg_i16, get_arg_u8, get_arg_f32, - get_arg_b8, get_arg_date, get_arg_length, set_js_handle, get_arg, set_arg_type, - get_signature_arg2_type, get_signature_arg1_type, cs_to_js_marshalers, - get_signature_res_type, get_arg_u16, array_element_size, get_string_root, - ArraySegment, Span, MemoryViewType, get_signature_arg3_type, get_arg_i64_big, get_arg_intptr, get_arg_element_type, JavaScriptMarshalerArgSize, proxy_debug_symbol + ArraySegment, JavaScriptMarshalerArgSize, ManagedError, ManagedObject, MemoryViewType, Span, array_element_size, + cs_to_js_marshalers, get_arg, get_arg_b8, get_arg_date, get_arg_element_type, get_arg_f32, get_arg_f64, get_arg_gc_handle, + get_arg_i16, get_arg_i32, get_arg_i52, get_arg_i64_big, get_arg_intptr, get_arg_js_handle, get_arg_length, + get_arg_type, get_arg_u16, get_arg_u8, get_signature_arg1_type, + get_signature_arg2_type, get_signature_arg3_type, get_signature_res_type, get_string_root, + proxy_debug_symbol, set_arg_type, set_js_handle } from "./marshal"; -import { monoStringToString } from "./strings"; -import { JSHandleNull, GCHandleNull, JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, BoundMarshalerToJs, MarshalerType } from "./types/internal"; -import { TypedArray } from "./types/emscripten"; import { get_marshaler_to_cs_by_type, jsinteropDoc } from "./marshal-to-cs"; -import { localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory"; export function initialize_marshalers_to_js(): void { if (cs_to_js_marshalers.size == 0) { diff --git a/src/mono/wasm/runtime/marshal.ts b/src/mono/wasm/runtime/interop/marshal.ts similarity index 95% rename from src/mono/wasm/runtime/marshal.ts rename to src/mono/wasm/runtime/interop/marshal.ts index 262051dab6fb3a..fcfa3005f56d48 100644 --- a/src/mono/wasm/runtime/marshal.ts +++ b/src/mono/wasm/runtime/interop/marshal.ts @@ -3,12 +3,9 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { js_owned_gc_handle_symbol, teardown_managed_proxy } from "./gc-handles"; -import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; -import { getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, localHeapViewF64, localHeapViewI32, localHeapViewU8 } from "./memory"; -import { mono_wasm_new_external_root } from "./roots"; -import { GCHandle, JSHandle, MonoObject, MonoString, GCHandleNull, JSMarshalerArguments, JSFunctionSignature, JSMarshalerType, JSMarshalerArgument, MarshalerToJs, MarshalerToCs, WasmRoot, MarshalerType } from "./types/internal"; -import { CharPtr, TypedArray, VoidPtr } from "./types/emscripten"; +import { CharPtr, TypedArray, VoidPtr } from "../types/emscripten"; +import { GCHandle, GCHandleNull, JSFunctionSignature, JSHandle, JSMarshalerArgument, JSMarshalerArguments, JSMarshalerType, MarshalerToCs, MarshalerToJs, MarshalerType, MonoObject, MonoString, WasmRoot } from "../types/internal"; +import { Module, getF32, getF64, getI16, getI32, getI64Big, getU16, getU32, getU8, js_owned_gc_handle_symbol, loaderHelpers, localHeapViewF64, localHeapViewI32, localHeapViewU8, mono_assert, mono_wasm_new_external_root, runtimeHelpers, setF32, setF64, setI16, setI32, setI64Big, setU16, setU32, setU8, teardown_managed_proxy } from "./from-core"; export const cs_to_js_marshalers = new Map(); export const js_to_cs_marshalers = new Map(); diff --git a/src/mono/wasm/runtime/jiterpreter-enums.ts b/src/mono/wasm/runtime/jiterpreter/enums.ts similarity index 100% rename from src/mono/wasm/runtime/jiterpreter-enums.ts rename to src/mono/wasm/runtime/jiterpreter/enums.ts diff --git a/src/mono/wasm/runtime/jiterpreter-feature-detect.ts b/src/mono/wasm/runtime/jiterpreter/feature-detect.ts similarity index 91% rename from src/mono/wasm/runtime/jiterpreter-feature-detect.ts rename to src/mono/wasm/runtime/jiterpreter/feature-detect.ts index b17f78483da444..196f38860442de 100644 --- a/src/mono/wasm/runtime/jiterpreter-feature-detect.ts +++ b/src/mono/wasm/runtime/jiterpreter/feature-detect.ts @@ -1,11 +1,11 @@ import { WasmValtype, WasmOpcode, WasmSimdOpcode -} from "./jiterpreter-opcodes"; +} from "./opcodes"; import { WasmBuilder, -} from "./jiterpreter-support"; +} from "./support"; -export function compileDoJitCall () : WebAssembly.Module { +export function compileDoJitCall(): WebAssembly.Module { const builder = new WasmBuilder(0); builder.defineType("jit_call_cb", { "cb_data": WasmValtype.i32, @@ -42,7 +42,7 @@ export function compileDoJitCall () : WebAssembly.Module { return new WebAssembly.Module(buffer); } -export function compileSimdFeatureDetect () : WebAssembly.Module { +export function compileSimdFeatureDetect(): WebAssembly.Module { const builder = new WasmBuilder(0); builder.defineType("test", {}, WasmValtype.void, true); builder.defineFunction({ diff --git a/src/mono/wasm/runtime/jiterpreter.ts b/src/mono/wasm/runtime/jiterpreter/index.ts similarity index 98% rename from src/mono/wasm/runtime/jiterpreter.ts rename to src/mono/wasm/runtime/jiterpreter/index.ts index f47149dda1eb15..cb114790f15c15 100644 --- a/src/mono/wasm/runtime/jiterpreter.ts +++ b/src/mono/wasm/runtime/jiterpreter/index.ts @@ -1,31 +1,31 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { MonoMethod } from "./types/internal"; -import { NativePointer } from "./types/emscripten"; -import { Module, mono_assert, runtimeHelpers } from "./globals"; -import { getU16, getU32_unaligned, localHeapViewU8 } from "./memory"; -import { WasmValtype, WasmOpcode, getOpcodeName } from "./jiterpreter-opcodes"; -import { MintOpcode } from "./mintops"; -import cwraps from "./cwraps"; +import { MonoMethod } from "../types/internal"; +import { NativePointer } from "../types/emscripten"; +import { Module, mono_assert, runtimeHelpers } from "../core/globals"; +import { getU16, getU32_unaligned, localHeapViewU8 } from "../core/memory"; +import { WasmValtype, WasmOpcode, getOpcodeName } from "./opcodes"; +import { MintOpcode } from "../mintops"; +import cwraps from "../core/cwraps"; import { MintOpcodePtr, WasmBuilder, addWasmFunctionPointer, _now, isZeroPageReserved, getRawCwrap, importDef, JiterpreterOptions, getOptions, recordFailure, getMemberOffset, getCounter, modifyCounter, simdFallbackCounters, getWasmFunctionTable -} from "./jiterpreter-support"; +} from "./support"; import { JiterpMember, BailoutReasonNames, BailoutReason, JiterpreterTable, JiterpCounter, -} from "./jiterpreter-enums"; +} from "./enums"; import { generateWasmBody -} from "./jiterpreter-trace-generator"; -import { mono_jiterp_free_method_data_interp_entry } from "./jiterpreter-interp-entry"; -import { mono_jiterp_free_method_data_jit_call } from "./jiterpreter-jit-call"; -import { mono_log_error, mono_log_info, mono_log_warn } from "./logging"; -import { utf8ToString } from "./strings"; +} from "./trace-generator"; +import { mono_jiterp_free_method_data_interp_entry } from "./interp-entry"; +import { mono_jiterp_free_method_data_jit_call } from "./jit-call"; +import { mono_log_error, mono_log_info, mono_log_warn } from "../core/logging"; +import { utf8ToString } from "../core/strings"; // Controls miscellaneous diagnostic output. export const trace = 0; @@ -886,7 +886,7 @@ function generate_wasm( rejected = false; mono_assert(!runtimeHelpers.storeMemorySnapshotPending, "Attempting to set function into table during creation of memory snapshot"); - let idx : number; + let idx: number; if (presetFunctionPointer) { const fnTable = getWasmFunctionTable(); fnTable.set(presetFunctionPointer, fn); diff --git a/src/mono/wasm/runtime/jiterpreter-interp-entry.ts b/src/mono/wasm/runtime/jiterpreter/interp-entry.ts similarity index 97% rename from src/mono/wasm/runtime/jiterpreter-interp-entry.ts rename to src/mono/wasm/runtime/jiterpreter/interp-entry.ts index cedf54cdde9306..ca0449b09b412e 100644 --- a/src/mono/wasm/runtime/jiterpreter-interp-entry.ts +++ b/src/mono/wasm/runtime/jiterpreter/interp-entry.ts @@ -1,27 +1,27 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { MonoMethod, MonoType } from "./types/internal"; -import { NativePointer } from "./types/emscripten"; -import { Module, mono_assert } from "./globals"; +import { MonoMethod, MonoType } from "../types/internal"; +import { NativePointer } from "../types/emscripten"; +import { Module, mono_assert } from "../core/globals"; import { setI32, getU32_unaligned, _zero_region -} from "./memory"; -import { WasmOpcode } from "./jiterpreter-opcodes"; -import cwraps from "./cwraps"; +} from "../core/memory"; +import { WasmOpcode } from "./opcodes"; +import cwraps from "../core/cwraps"; import { WasmBuilder, addWasmFunctionPointer, _now, getRawCwrap, importDef, getWasmFunctionTable, recordFailure, getOptions, JiterpreterOptions, getMemberOffset, getCounter, modifyCounter -} from "./jiterpreter-support"; -import { WasmValtype } from "./jiterpreter-opcodes"; -import { mono_log_error, mono_log_info } from "./logging"; -import { utf8ToString } from "./strings"; +} from "./support"; +import { WasmValtype } from "./opcodes"; +import { mono_log_error, mono_log_info } from "../core/logging"; +import { utf8ToString } from "../core/strings"; import { JiterpreterTable, JiterpCounter, JiterpMember, JitQueue -} from "./jiterpreter-enums"; +} from "./enums"; // Controls miscellaneous diagnostic output. const trace = 0; @@ -228,7 +228,7 @@ function ensure_jit_is_scheduled() { } function flush_wasm_entry_trampoline_jit_queue() { - const jitQueue : TrampolineInfo[] = []; + const jitQueue: TrampolineInfo[] = []; let methodPtr = 0; while ((methodPtr = cwraps.mono_jiterp_tlqueue_next(JitQueue.InterpEntry)) != 0) { const info = infoTable[methodPtr]; diff --git a/src/mono/wasm/runtime/jiterpreter-jit-call.ts b/src/mono/wasm/runtime/jiterpreter/jit-call.ts similarity index 98% rename from src/mono/wasm/runtime/jiterpreter-jit-call.ts rename to src/mono/wasm/runtime/jiterpreter/jit-call.ts index 1af011764e7d8e..a131d3fe773677 100644 --- a/src/mono/wasm/runtime/jiterpreter-jit-call.ts +++ b/src/mono/wasm/runtime/jiterpreter/jit-call.ts @@ -2,27 +2,27 @@ // The .NET Foundation licenses this file to you under the MIT license. import MonoWasmThreads from "consts:monoWasmThreads"; -import { MonoType, MonoMethod } from "./types/internal"; -import { NativePointer, Int32Ptr, VoidPtr } from "./types/emscripten"; -import { Module, mono_assert, runtimeHelpers } from "./globals"; +import { MonoType, MonoMethod } from "../types/internal"; +import { NativePointer, Int32Ptr, VoidPtr } from "../types/emscripten"; +import { Module, mono_assert, runtimeHelpers } from "../core/globals"; import { getU8, getI32_unaligned, getU32_unaligned, setU32_unchecked, receiveWorkerHeapViews -} from "./memory"; -import { WasmOpcode, WasmValtype } from "./jiterpreter-opcodes"; +} from "../core/memory"; +import { WasmOpcode, WasmValtype } from "./opcodes"; import { WasmBuilder, addWasmFunctionPointer, _now, getWasmFunctionTable, applyOptions, recordFailure, getOptions, getCounter, modifyCounter, jiterpreter_allocate_tables -} from "./jiterpreter-support"; -import { JiterpreterTable, JiterpCounter, JitQueue } from "./jiterpreter-enums"; +} from "./support"; +import { JiterpreterTable, JiterpCounter, JitQueue } from "./enums"; import { compileDoJitCall -} from "./jiterpreter-feature-detect"; -import cwraps from "./cwraps"; -import { mono_log_error, mono_log_info } from "./logging"; -import { utf8ToString } from "./strings"; +} from "./feature-detect"; +import cwraps from "../core/cwraps"; +import { mono_log_error, mono_log_info } from "../core/logging"; +import { utf8ToString } from "../core/strings"; // Controls miscellaneous diagnostic output. const trace = 0; @@ -348,7 +348,7 @@ export function mono_jiterp_do_jit_call_indirect( } export function mono_interp_flush_jitcall_queue(): void { - const jitQueue : TrampolineInfo[] = []; + const jitQueue: TrampolineInfo[] = []; let methodPtr = 0; while ((methodPtr = cwraps.mono_jiterp_tlqueue_next(JitQueue.JitCall)) != 0) { const infos = infosByMethod[methodPtr]; diff --git a/src/mono/wasm/runtime/jiterpreter-opcodes.ts b/src/mono/wasm/runtime/jiterpreter/opcodes.ts similarity index 99% rename from src/mono/wasm/runtime/jiterpreter-opcodes.ts rename to src/mono/wasm/runtime/jiterpreter/opcodes.ts index 9c046ebf8319c0..4da6f2ac37736b 100644 --- a/src/mono/wasm/runtime/jiterpreter-opcodes.ts +++ b/src/mono/wasm/runtime/jiterpreter/opcodes.ts @@ -3,9 +3,9 @@ // Keep this file in sync with mintops.def. The order and values need to match exactly. -import cwraps from "./cwraps"; -import { utf8ToString } from "./strings"; -import { OpcodeInfoType } from "./jiterpreter-enums"; +import cwraps from "../core/cwraps"; +import { utf8ToString } from "../core/strings"; +import { OpcodeInfoType } from "./enums"; export type OpcodeNameTable = { [key: number]: string; diff --git a/src/mono/wasm/runtime/jiterpreter-support.ts b/src/mono/wasm/runtime/jiterpreter/support.ts similarity index 99% rename from src/mono/wasm/runtime/jiterpreter-support.ts rename to src/mono/wasm/runtime/jiterpreter/support.ts index 06e1e6569ffc8e..35ac5a8c95c122 100644 --- a/src/mono/wasm/runtime/jiterpreter-support.ts +++ b/src/mono/wasm/runtime/jiterpreter/support.ts @@ -2,18 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. import MonoWasmThreads from "consts:monoWasmThreads"; -import { NativePointer, ManagedPointer, VoidPtr } from "./types/emscripten"; -import { Module, mono_assert, runtimeHelpers, linkerRunAOTCompilation } from "./globals"; -import { WasmOpcode, WasmSimdOpcode, WasmValtype } from "./jiterpreter-opcodes"; -import { MintOpcode } from "./mintops"; -import cwraps from "./cwraps"; -import { mono_log_error, mono_log_info } from "./logging"; -import { localHeapViewU8, localHeapViewU32 } from "./memory"; -import { utf8ToString } from "./strings"; +import { NativePointer, ManagedPointer, VoidPtr } from "../types/emscripten"; +import { Module, mono_assert, runtimeHelpers, linkerRunAOTCompilation } from "../core/globals"; +import { WasmOpcode, WasmSimdOpcode, WasmValtype } from "./opcodes"; +import { MintOpcode } from "../mintops"; +import cwraps from "../core/cwraps"; +import { mono_log_error, mono_log_info } from "../core/logging"; +import { localHeapViewU8, localHeapViewU32 } from "../core/memory"; +import { utf8ToString } from "../core/strings"; import { JiterpNumberMode, BailoutReason, JiterpreterTable, JiterpCounter, JiterpMember -} from "./jiterpreter-enums"; +} from "./enums"; export const maxFailures = 2, maxMemsetSize = 64, @@ -1507,8 +1507,8 @@ export function copyIntoScratchBuffer(src: NativePointer, size: number): NativeP export function getWasmFunctionTable(module?: any) { const theModule = (Module || module); - mono_assert (theModule, "Module not available yet"); - mono_assert (theModule["asm"], "Module['asm'] not available yet"); + mono_assert(theModule, "Module not available yet"); + mono_assert(theModule["asm"], "Module['asm'] not available yet"); if (!wasmTable) wasmTable = theModule["asm"]["__indirect_function_table"]; if (!wasmTable) diff --git a/src/mono/wasm/runtime/jiterpreter-tables.ts b/src/mono/wasm/runtime/jiterpreter/tables.ts similarity index 99% rename from src/mono/wasm/runtime/jiterpreter-tables.ts rename to src/mono/wasm/runtime/jiterpreter/tables.ts index 71a3eb86c9f014..b1be07f519842b 100644 --- a/src/mono/wasm/runtime/jiterpreter-tables.ts +++ b/src/mono/wasm/runtime/jiterpreter/tables.ts @@ -1,9 +1,9 @@ import { WasmOpcode, WasmSimdOpcode, JiterpSpecialOpcode -} from "./jiterpreter-opcodes"; +} from "./opcodes"; import { MintOpcode, SimdIntrinsic2, SimdIntrinsic3, SimdIntrinsic4 -} from "./mintops"; +} from "../mintops"; export const ldcTable: { [opcode: number]: [WasmOpcode, number] } = { [MintOpcode.MINT_LDC_I4_M1]: [WasmOpcode.i32_const, -1], diff --git a/src/mono/wasm/runtime/jiterpreter-trace-generator.ts b/src/mono/wasm/runtime/jiterpreter/trace-generator.ts similarity index 99% rename from src/mono/wasm/runtime/jiterpreter-trace-generator.ts rename to src/mono/wasm/runtime/jiterpreter/trace-generator.ts index 2c7bb17ef9e82c..78a2a90b186fa4 100644 --- a/src/mono/wasm/runtime/jiterpreter-trace-generator.ts +++ b/src/mono/wasm/runtime/jiterpreter/trace-generator.ts @@ -1,25 +1,25 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { MonoMethod } from "./types/internal"; -import { NativePointer } from "./types/emscripten"; +import { MonoMethod } from "../types/internal"; +import { NativePointer } from "../types/emscripten"; import { getU16, getI16, getU32_unaligned, getI32_unaligned, getF32_unaligned, getF64_unaligned, localHeapViewU8, -} from "./memory"; +} from "../core/memory"; import { WasmOpcode, WasmSimdOpcode, WasmValtype, getOpcodeName, -} from "./jiterpreter-opcodes"; +} from "./opcodes"; import { MintOpcode, SimdInfo, SimdIntrinsic2, SimdIntrinsic3, SimdIntrinsic4 -} from "./mintops"; -import cwraps from "./cwraps"; +} from "../mintops"; +import cwraps from "../core/cwraps"; import { OpcodeInfoType, JiterpMember, BailoutReason, JiterpCounter, -} from "./jiterpreter-enums"; +} from "./enums"; import { MintOpcodePtr, WasmBuilder, append_memset_dest, append_bailout, append_exit, @@ -27,8 +27,8 @@ import { try_append_memmove_fast, getOpcodeTableValue, getMemberOffset, isZeroPageReserved, CfgBranchType, append_safepoint, modifyCounter, simdFallbackCounters, -} from "./jiterpreter-support"; -import { compileSimdFeatureDetect } from "./jiterpreter-feature-detect"; +} from "./support"; +import { compileSimdFeatureDetect } from "./feature-detect"; import { sizeOfDataItem, sizeOfV128, sizeOfStackval, @@ -44,7 +44,7 @@ import { mostRecentOptions, record_abort, -} from "./jiterpreter"; +} from "./index"; import { ldcTable, OpRec3, OpRec4, floatToIntTable, unopTable, @@ -55,9 +55,9 @@ import { bitmaskTable, createScalarTable, simdExtractTable, simdReplaceTable, simdLoadTable, simdStoreTable, -} from "./jiterpreter-tables"; -import { mono_log_error, mono_log_info } from "./logging"; -import { mono_assert } from "./globals"; +} from "./tables"; +import { mono_log_error, mono_log_info } from "../core/logging"; +import { mono_assert } from "../core/globals"; // indexPlusOne so that ip[1] in the interpreter becomes getArgU16(ip, 1) function getArgU16(ip: MintOpcodePtr, indexPlusOne: number) { diff --git a/src/mono/wasm/runtime/CMakeLists.txt b/src/mono/wasm/runtime/native/CMakeLists.txt similarity index 84% rename from src/mono/wasm/runtime/CMakeLists.txt rename to src/mono/wasm/runtime/native/CMakeLists.txt index 6d939088d74314..fb230fc5c96001 100644 --- a/src/mono/wasm/runtime/CMakeLists.txt +++ b/src/mono/wasm/runtime/native/CMakeLists.txt @@ -6,7 +6,7 @@ option(DISABLE_THREADS "defined if the build does NOT support multithreading" ON option(DISABLE_LEGACY_JS_INTEROP "defined if the build does not support legacy JavaScript interop" OFF) set(CMAKE_EXECUTABLE_SUFFIX ".js") -add_executable(dotnet.native corebindings.c driver.c pinvoke.c) +add_executable(dotnet.native native/corebindings.c native/driver.c native/pinvoke.c) target_include_directories(dotnet.native PUBLIC ${MONO_INCLUDES} ${MONO_OBJ_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/include/wasm) target_compile_options(dotnet.native PUBLIC @${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-compile.rsp -DGEN_PINVOKE=1 ${CONFIGURATION_COMPILE_OPTIONS}) @@ -34,8 +34,8 @@ target_link_libraries(dotnet.native ${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a) set_target_properties(dotnet.native PROPERTIES - LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/pal_random.lib.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js;" - LINK_FLAGS "@${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-link.rsp ${CONFIGURATION_LINK_FLAGS} --pre-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js --js-library ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js --js-library ${NATIVE_BIN_DIR}/src/pal_random.lib.js --extern-post-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js " + LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/pal_random.lib.js;${NATIVE_BIN_DIR}/src/dotnet.es6.extpost.js;" + LINK_FLAGS "@${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-link.rsp ${CONFIGURATION_LINK_FLAGS} --pre-js ${NATIVE_BIN_DIR}/src/dotnet.es6.pre.js --js-library ${NATIVE_BIN_DIR}/src/dotnet.es6.lib.js --js-library ${NATIVE_BIN_DIR}/src/pal_random.lib.js --extern-post-js ${NATIVE_BIN_DIR}/src/dotnet.es6.extpost.js " RUNTIME_OUTPUT_DIRECTORY "${NATIVE_BIN_DIR}") set(ignoreMeWasmOptFlags "${CONFIGURATION_WASM_OPT_FLAGS}") diff --git a/src/mono/wasm/runtime/corebindings.c b/src/mono/wasm/runtime/native/corebindings.c similarity index 100% rename from src/mono/wasm/runtime/corebindings.c rename to src/mono/wasm/runtime/native/corebindings.c diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.extpost.js b/src/mono/wasm/runtime/native/dotnet.es6.extpost.js similarity index 100% rename from src/mono/wasm/runtime/es6/dotnet.es6.extpost.js rename to src/mono/wasm/runtime/native/dotnet.es6.extpost.js diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/native/dotnet.es6.lib.js similarity index 100% rename from src/mono/wasm/runtime/es6/dotnet.es6.lib.js rename to src/mono/wasm/runtime/native/dotnet.es6.lib.js diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.pre.js b/src/mono/wasm/runtime/native/dotnet.es6.pre.js similarity index 100% rename from src/mono/wasm/runtime/es6/dotnet.es6.pre.js rename to src/mono/wasm/runtime/native/dotnet.es6.pre.js diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/native/driver.c similarity index 100% rename from src/mono/wasm/runtime/driver.c rename to src/mono/wasm/runtime/native/driver.c diff --git a/src/mono/wasm/runtime/gc-common.h b/src/mono/wasm/runtime/native/gc-common.h similarity index 100% rename from src/mono/wasm/runtime/gc-common.h rename to src/mono/wasm/runtime/native/gc-common.h diff --git a/src/mono/wasm/runtime/genmintops.py b/src/mono/wasm/runtime/native/genmintops.py old mode 100755 new mode 100644 similarity index 98% rename from src/mono/wasm/runtime/genmintops.py rename to src/mono/wasm/runtime/native/genmintops.py index 33c370690f8c0d..fc8ee039056841 --- a/src/mono/wasm/runtime/genmintops.py +++ b/src/mono/wasm/runtime/native/genmintops.py @@ -69,7 +69,7 @@ // Generated by genmintops.py from mintops.def. // Do not manually edit this file. -import {{ MintOpArgType, SimdInfoTable }} from "./jiterpreter-opcodes"; +import {{ MintOpArgType, SimdInfoTable }} from "./jiterpreter/opcodes"; export const enum MintOpcode {{ {enum_values} diff --git a/src/mono/wasm/runtime/pinvoke.c b/src/mono/wasm/runtime/native/pinvoke.c similarity index 100% rename from src/mono/wasm/runtime/pinvoke.c rename to src/mono/wasm/runtime/native/pinvoke.c diff --git a/src/mono/wasm/runtime/pinvoke.h b/src/mono/wasm/runtime/native/pinvoke.h similarity index 100% rename from src/mono/wasm/runtime/pinvoke.h rename to src/mono/wasm/runtime/native/pinvoke.h diff --git a/src/mono/wasm/runtime/wasm-config.h.in b/src/mono/wasm/runtime/native/wasm-config.h.in similarity index 100% rename from src/mono/wasm/runtime/wasm-config.h.in rename to src/mono/wasm/runtime/native/wasm-config.h.in diff --git a/src/mono/wasm/runtime/net6-legacy/buffers.ts b/src/mono/wasm/runtime/net6-legacy/buffers.ts index d2b963ee58fde9..db125f0a6a2050 100644 --- a/src/mono/wasm/runtime/net6-legacy/buffers.ts +++ b/src/mono/wasm/runtime/net6-legacy/buffers.ts @@ -1,12 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { mono_wasm_new_external_root } from "../roots"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { mono_wasm_new_external_root } from "../core/roots"; import { MonoArray, MonoObjectRef, MonoObject } from "../types/internal"; import { Int32Ptr, TypedArray } from "../types/emscripten"; import { js_to_mono_obj_root } from "./js-to-cs"; -import { localHeapViewU8 } from "../memory"; +import { localHeapViewU8 } from "../core/memory"; // eslint-disable-next-line @typescript-eslint/no-unused-vars export function mono_wasm_typed_array_from_ref(pinned_array: MonoArray, begin: number, end: number, bytes_per_element: number, type: number, is_exception: Int32Ptr, result_address: MonoObjectRef): void { diff --git a/src/mono/wasm/runtime/net6-legacy/corebindings.ts b/src/mono/wasm/runtime/net6-legacy/corebindings.ts index fd4d85aa021304..e6614c0bcbd0bc 100644 --- a/src/mono/wasm/runtime/net6-legacy/corebindings.ts +++ b/src/mono/wasm/runtime/net6-legacy/corebindings.ts @@ -3,11 +3,11 @@ import { JSHandle, GCHandle, MonoObjectRef, MonoMethod, MonoObject, WasmRoot, PromiseController } from "../types/internal"; import { mono_bind_method, _create_primitive_converters } from "./method-binding"; -import { mono_wasm_new_root } from "../roots"; -import { Module, runtimeHelpers } from "../globals"; -import cwraps from "../cwraps"; +import { mono_wasm_new_root } from "../core/roots"; +import { Module, runtimeHelpers } from "../core/globals"; +import cwraps from "../core/cwraps"; import { legacyHelpers, wasm_type_symbol } from "./globals"; -import { find_corlib_class } from "../class-loader"; +import { find_corlib_class } from "../core/class-loader"; type SigLine = [lazy: boolean, jsname: string, csname: string, signature: string/*ArgsMarshalString*/]; const fn_signatures: SigLine[] = [ [true, "_get_cs_owned_object_by_js_handle_ref", "GetCSOwnedObjectByJSHandleRef", "iim"], diff --git a/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts b/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts index 1400f7f84ed263..179dfe1b60c6dc 100644 --- a/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts +++ b/src/mono/wasm/runtime/net6-legacy/cs-to-js.ts @@ -3,19 +3,19 @@ import { Int32Ptr, VoidPtr } from "../types/emscripten"; import { MarshalType, MonoType, MarshalError, MonoTypeNull, MonoArray, MonoArrayNull, MonoObject, MonoObjectNull, GCHandle, MonoStringRef, MonoObjectRef, MonoString, JSHandleDisposed, is_nullish, WasmRoot } from "../types/internal"; -import { _are_promises_supported } from "../cancelable-promise"; -import { legacy_c_functions as cwraps } from "../cwraps"; -import { mono_wasm_get_jsobj_from_js_handle, _lookup_js_owned_object, setup_managed_proxy, mono_wasm_get_js_handle, teardown_managed_proxy, assert_not_disposed } from "../gc-handles"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { ManagedObject } from "../marshal"; -import { getU32, getI32, getF32, getF64, setI32_unchecked } from "../memory"; -import { mono_wasm_new_root, mono_wasm_new_external_root } from "../roots"; -import { monoStringToString } from "../strings"; +import { _are_promises_supported } from "../core/cancelable-promise"; +import { legacy_c_functions as cwraps } from "../core/cwraps"; +import { mono_wasm_get_jsobj_from_js_handle, _lookup_js_owned_object, setup_managed_proxy, mono_wasm_get_js_handle, teardown_managed_proxy, assert_not_disposed } from "../core/gc-handles"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { ManagedObject } from "../interop/marshal"; +import { getU32, getI32, getF32, getF64, setI32_unchecked } from "../core/memory"; +import { mono_wasm_new_root, mono_wasm_new_external_root } from "../core/roots"; +import { monoStringToString } from "../core/strings"; import { legacyManagedExports } from "./corebindings"; import { legacyHelpers } from "./globals"; import { js_to_mono_obj_root } from "./js-to-cs"; import { assert_legacy_interop, mono_bind_method, mono_method_get_call_signature_ref } from "./method-binding"; -import { createPromiseController } from "../globals"; +import { createPromiseController } from "../core/globals"; import { monoStringToStringUnsafe } from "./strings"; const delegate_invoke_symbol = Symbol.for("wasm delegate_invoke"); diff --git a/src/mono/wasm/runtime/net6-legacy/exports-legacy.ts b/src/mono/wasm/runtime/net6-legacy/exports-legacy.ts index b2f8aeda4953b6..f35059eac15eea 100644 --- a/src/mono/wasm/runtime/net6-legacy/exports-legacy.ts +++ b/src/mono/wasm/runtime/net6-legacy/exports-legacy.ts @@ -1,21 +1,21 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { legacy_c_functions as cwraps } from "../cwraps"; -import { mono_wasm_runtime_ready } from "../debug"; -import { mono_wasm_load_icu_data } from "../icu"; -import { mono_wasm_load_bytes_into_heap, setB32, setI8, setI16, setI32, setI52, setU52, setI64Big, setU8, setU16, setU32, setF32, setF64, getB32, getI8, getI16, getI32, getI52, getU52, getI64Big, getU8, getU16, getU32, getF32, getF64 } from "../memory"; -import { mono_wasm_new_root_buffer, mono_wasm_new_root, mono_wasm_new_external_root, mono_wasm_release_roots } from "../roots"; -import { mono_run_main, mono_run_main_and_exit } from "../run"; -import { mono_wasm_setenv } from "../startup"; -import { stringToMonoStringRoot, monoStringToString } from "../strings"; +import { legacy_c_functions as cwraps } from "../core/cwraps"; +import { mono_wasm_runtime_ready } from "../core/debug"; +import { mono_wasm_load_icu_data } from "../core/icu"; +import { mono_wasm_load_bytes_into_heap, setB32, setI8, setI16, setI32, setI52, setU52, setI64Big, setU8, setU16, setU32, setF32, setF64, getB32, getI8, getI16, getI32, getI52, getU52, getI64Big, getU8, getU16, getU32, getF32, getF64 } from "../core/memory"; +import { mono_wasm_new_root_buffer, mono_wasm_new_root, mono_wasm_new_external_root, mono_wasm_release_roots } from "../core/roots"; +import { mono_run_main, mono_run_main_and_exit } from "../core/run"; +import { mono_wasm_setenv } from "../core/startup"; +import { stringToMonoStringRoot, monoStringToString } from "../core/strings"; import { mono_array_to_js_array, unbox_mono_obj, unbox_mono_obj_root, mono_array_root_to_js_array, conv_string } from "./cs-to-js"; import { js_typed_array_to_array, js_to_mono_obj, js_typed_array_to_array_root, js_to_mono_obj_root } from "./js-to-cs"; import { mono_bind_static_method, mono_call_assembly_entry_point } from "./method-calls"; -import { mono_wasm_load_runtime } from "../startup"; +import { mono_wasm_load_runtime } from "../core/startup"; import { BINDINGType, MONOType } from "./export-types"; import { mono_method_resolve } from "./method-binding"; -import { runtimeHelpers } from "../globals"; +import { runtimeHelpers } from "../core/globals"; import { stringToMonoStringIntern, stringToMonoStringUnsafe } from "./strings"; export function export_mono_api(): MONOType { diff --git a/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts b/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts index 9e9f5d9bb7c028..52585fe8ffdd74 100644 --- a/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts +++ b/src/mono/wasm/runtime/net6-legacy/js-to-cs.ts @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { isThenable } from "../cancelable-promise"; -import { legacy_c_functions as cwraps } from "../cwraps"; -import { js_owned_gc_handle_symbol, assert_not_disposed, cs_owned_js_handle_symbol, mono_wasm_get_js_handle, setup_managed_proxy, mono_wasm_release_cs_owned_object, teardown_managed_proxy, mono_wasm_get_jsobj_from_js_handle } from "../gc-handles"; -import { Module } from "../globals"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { setI32_unchecked, setU32_unchecked, setF64, setB32, localHeapViewU8 } from "../memory"; -import { mono_wasm_new_root, mono_wasm_release_roots, mono_wasm_new_external_root } from "../roots"; -import { stringToMonoStringRoot, stringToInternedMonoStringRoot } from "../strings"; +import { isThenable } from "../core/cancelable-promise"; +import { legacy_c_functions as cwraps } from "../core/cwraps"; +import { js_owned_gc_handle_symbol, assert_not_disposed, cs_owned_js_handle_symbol, mono_wasm_get_js_handle, setup_managed_proxy, mono_wasm_release_cs_owned_object, teardown_managed_proxy, mono_wasm_get_jsobj_from_js_handle } from "../core/gc-handles"; +import { Module } from "../core/globals"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { setI32_unchecked, setU32_unchecked, setF64, setB32, localHeapViewU8 } from "../core/memory"; +import { mono_wasm_new_root, mono_wasm_release_roots, mono_wasm_new_external_root } from "../core/roots"; +import { stringToMonoStringRoot, stringToInternedMonoStringRoot } from "../core/strings"; import { MonoObject, is_nullish, MonoClass, MonoArray, MonoObjectNull, JSHandle, MonoObjectRef, JSHandleNull, JSHandleDisposed, WasmRoot } from "../types/internal"; import { TypedArray, Int32Ptr } from "../types/emscripten"; import { has_backing_array_buffer } from "./buffers"; diff --git a/src/mono/wasm/runtime/net6-legacy/method-binding.ts b/src/mono/wasm/runtime/net6-legacy/method-binding.ts index 2d38c950674a9f..cc0a323281787d 100644 --- a/src/mono/wasm/runtime/net6-legacy/method-binding.ts +++ b/src/mono/wasm/runtime/net6-legacy/method-binding.ts @@ -3,12 +3,12 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { legacy_c_functions as cwraps } from "../cwraps"; -import { ENVIRONMENT_IS_PTHREAD, Module, mono_assert } from "../globals"; -import { parseFQN } from "../invoke-cs"; -import { setI32, setU32, setF32, setF64, setU52, setI52, setB32, setI32_unchecked, setU32_unchecked, _zero_region, _create_temp_frame, getB32, getI32, getU32, getF32, getF64 } from "../memory"; -import { mono_wasm_new_external_root, mono_wasm_new_root } from "../roots"; -import { stringToMonoStringRoot, stringToInternedMonoStringRoot, monoStringToString } from "../strings"; +import { legacy_c_functions as cwraps } from "../core/cwraps"; +import { ENVIRONMENT_IS_PTHREAD, Module, mono_assert } from "../core/globals"; +import { parseFQN } from "../interop/invoke-cs"; +import { setI32, setU32, setF32, setF64, setU52, setI52, setB32, setI32_unchecked, setU32_unchecked, _zero_region, _create_temp_frame, getB32, getI32, getU32, getF32, getF64 } from "../core/memory"; +import { mono_wasm_new_external_root, mono_wasm_new_root } from "../core/roots"; +import { stringToMonoStringRoot, stringToInternedMonoStringRoot, monoStringToString } from "../core/strings"; import { MonoMethod, MonoObject, VoidPtrNull, MarshalType, MonoString, MonoObjectNull, WasmRootBuffer, WasmRoot } from "../types/internal"; import { VoidPtr } from "../types/emscripten"; import { legacyManagedExports } from "./corebindings"; @@ -16,8 +16,8 @@ import { get_js_owned_object_by_gc_handle_ref, _unbox_mono_obj_root_with_known_n import { legacyHelpers } from "./globals"; import { js_to_mono_obj_root, _js_to_mono_uri_root, js_to_mono_enum } from "./js-to-cs"; import { _teardown_after_call } from "./method-calls"; -import { mono_log_warn } from "../logging"; -import { assert_bindings } from "../invoke-js"; +import { mono_log_warn } from "../core/logging"; +import { assert_bindings } from "../interop/invoke-js"; const escapeRE = /[^A-Za-z0-9_$]/g; diff --git a/src/mono/wasm/runtime/net6-legacy/method-calls.ts b/src/mono/wasm/runtime/net6-legacy/method-calls.ts index 825e5e7d4107f3..6e4c2a0102f498 100644 --- a/src/mono/wasm/runtime/net6-legacy/method-calls.ts +++ b/src/mono/wasm/runtime/net6-legacy/method-calls.ts @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { get_js_obj, mono_wasm_get_jsobj_from_js_handle } from "../gc-handles"; -import { Module, INTERNAL, loaderHelpers } from "../globals"; -import { wrap_error_root, wrap_no_error_root } from "../invoke-js"; -import { _release_temp_frame } from "../memory"; -import { mono_wasm_new_external_root, mono_wasm_new_root } from "../roots"; -import { find_entry_point } from "../run"; -import { monoStringToString, stringToMonoStringRoot } from "../strings"; +import { get_js_obj, mono_wasm_get_jsobj_from_js_handle } from "../core/gc-handles"; +import { Module, INTERNAL, loaderHelpers } from "../core/globals"; +import { wrap_error_root, wrap_no_error_root } from "../interop/invoke-js"; +import { _release_temp_frame } from "../core/memory"; +import { mono_wasm_new_external_root, mono_wasm_new_root } from "../core/roots"; +import { find_entry_point } from "../core/run"; +import { monoStringToString, stringToMonoStringRoot } from "../core/strings"; import { JSHandle, MonoStringRef, MonoObjectRef, MonoArray, MonoString, MonoObject, is_nullish, WasmRoot } from "../types/internal"; import { Int32Ptr, VoidPtr } from "../types/emscripten"; import { mono_array_root_to_js_array, unbox_mono_obj_root } from "./cs-to-js"; diff --git a/src/mono/wasm/runtime/net6-legacy/strings.ts b/src/mono/wasm/runtime/net6-legacy/strings.ts index 1f6dadab26173f..e973a704abc1af 100644 --- a/src/mono/wasm/runtime/net6-legacy/strings.ts +++ b/src/mono/wasm/runtime/net6-legacy/strings.ts @@ -1,9 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { mono_assert } from "../globals"; -import { mono_wasm_new_root } from "../roots"; -import { interned_string_table, monoStringToString, mono_wasm_empty_string, stringToInternedMonoStringRoot, stringToMonoStringRoot } from "../strings"; +import { mono_assert } from "../core/globals"; +import { mono_wasm_new_root } from "../core/roots"; +import { interned_string_table, monoStringToString, mono_wasm_empty_string, stringToInternedMonoStringRoot, stringToMonoStringRoot } from "../core/strings"; import { MonoString, MonoStringNull, is_nullish } from "../types/internal"; let mono_wasm_string_root: any; diff --git a/src/mono/wasm/runtime/pthreads/browser/index.ts b/src/mono/wasm/runtime/pthreads/browser/index.ts index a4e0428812d9f9..e9cb561a2ba758 100644 --- a/src/mono/wasm/runtime/pthreads/browser/index.ts +++ b/src/mono/wasm/runtime/pthreads/browser/index.ts @@ -5,10 +5,10 @@ import { isMonoWorkerMessageChannelCreated, monoSymbol, makeMonoThreadMessageApp import { pthreadPtr } from "../shared/types"; import { MonoThreadMessage } from "../shared"; import Internals from "../shared/emscripten-internals"; -import { createPromiseController, mono_assert, runtimeHelpers } from "../../globals"; +import { createPromiseController, mono_assert, runtimeHelpers } from "../../core/globals"; import { PromiseController } from "../../types/internal"; import { MonoConfig } from "../../types"; -import { mono_log_debug } from "../../logging"; +import { mono_log_debug } from "../../core/logging"; const threads: Map = new Map(); diff --git a/src/mono/wasm/runtime/pthreads/shared/emscripten-internals.ts b/src/mono/wasm/runtime/pthreads/shared/emscripten-internals.ts index 0b71fcecb988b8..789c366555b1ca 100644 --- a/src/mono/wasm/runtime/pthreads/shared/emscripten-internals.ts +++ b/src/mono/wasm/runtime/pthreads/shared/emscripten-internals.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { Module } from "../../globals"; +import { Module } from "../../core/globals"; import { pthreadPtr } from "./types"; /** @module emscripten-internals accessors to the functions in the emscripten PThreads library, including diff --git a/src/mono/wasm/runtime/pthreads/shared/emscripten-replacements.ts b/src/mono/wasm/runtime/pthreads/shared/emscripten-replacements.ts index 9b5b9fa0b388b3..31ed00b8ed667d 100644 --- a/src/mono/wasm/runtime/pthreads/shared/emscripten-replacements.ts +++ b/src/mono/wasm/runtime/pthreads/shared/emscripten-replacements.ts @@ -5,9 +5,9 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import { afterLoadWasmModuleToWorker } from "../browser"; import { afterThreadInitTLS } from "../worker"; import Internals from "./emscripten-internals"; -import { loaderHelpers, mono_assert } from "../../globals"; +import { loaderHelpers, mono_assert } from "../../core/globals"; import { PThreadReplacements } from "../../types/internal"; -import { mono_log_debug } from "../../logging"; +import { mono_log_debug } from "../../core/logging"; /** @module emscripten-replacements Replacements for individual functions in the emscripten PThreads library. * These have a hard dependency on the version of Emscripten that we are using and may need to be kept in sync with diff --git a/src/mono/wasm/runtime/pthreads/shared/index.ts b/src/mono/wasm/runtime/pthreads/shared/index.ts index c8557755062a2f..39cdc31952e7f1 100644 --- a/src/mono/wasm/runtime/pthreads/shared/index.ts +++ b/src/mono/wasm/runtime/pthreads/shared/index.ts @@ -4,12 +4,12 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import BuildConfiguration from "consts:configuration"; -import { Module, mono_assert, runtimeHelpers } from "../../globals"; +import { Module, mono_assert, runtimeHelpers } from "../../core/globals"; import { MonoConfig } from "../../types"; import { pthreadPtr } from "./types"; -import { mono_log_debug } from "../../logging"; -import { bindings_init } from "../../startup"; -import { forceDisposeProxies } from "../../gc-handles"; +import { mono_log_debug } from "../../core/logging"; +import { bindings_init } from "../../core/startup"; +import { forceDisposeProxies } from "../../core/gc-handles"; import { pthread_self } from "../worker"; export interface PThreadInfo { diff --git a/src/mono/wasm/runtime/pthreads/worker/index.ts b/src/mono/wasm/runtime/pthreads/worker/index.ts index 2ac8feb10a9a54..45b9027f19fadd 100644 --- a/src/mono/wasm/runtime/pthreads/worker/index.ts +++ b/src/mono/wasm/runtime/pthreads/worker/index.ts @@ -5,7 +5,7 @@ import MonoWasmThreads from "consts:monoWasmThreads"; -import { Module, ENVIRONMENT_IS_PTHREAD, mono_assert } from "../../globals"; +import { Module, ENVIRONMENT_IS_PTHREAD, mono_assert } from "../../core/globals"; import { makeChannelCreatedMonoMessage, set_thread_info } from "../shared"; import type { pthreadPtr } from "../shared/types"; import { is_nullish } from "../../types/internal"; @@ -17,10 +17,10 @@ import { dotnetPthreadAttached, WorkerThreadEventTarget } from "./events"; -import { postRunWorker, preRunWorker } from "../../startup"; -import { mono_log_debug } from "../../logging"; -import { mono_set_thread_id } from "../../logging"; -import { jiterpreter_allocate_tables } from "../../jiterpreter-support"; +import { postRunWorker, preRunWorker } from "../../core/startup"; +import { mono_log_debug } from "../../core/logging"; +import { mono_set_thread_id } from "../../core/logging"; +import { jiterpreter_allocate_tables } from "../../jiterpreter/support"; // re-export some of the events types export { diff --git a/src/mono/wasm/runtime/rollup.config.js b/src/mono/wasm/runtime/rollup.config.js index 50bcfc3110d933..b27eec42314bd5 100644 --- a/src/mono/wasm/runtime/rollup.config.js +++ b/src/mono/wasm/runtime/rollup.config.js @@ -169,7 +169,7 @@ const loaderConfig = { }; const runtimeConfig = { treeshake: !isDebug, - input: "exports.ts", + input: "core/exports.ts", output: [ { format: "es", @@ -186,7 +186,7 @@ const runtimeConfig = { }; const wasmImportsConfig = { treeshake: true, - input: "exports-linker.ts", + input: "core/exports-linker.ts", output: [ { format: "iife", diff --git a/src/mono/wasm/runtime/types/export-types.ts b/src/mono/wasm/runtime/types/export-types.ts index cdd34f35178ab5..60263c87d2b37a 100644 --- a/src/mono/wasm/runtime/types/export-types.ts +++ b/src/mono/wasm/runtime/types/export-types.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import type { IMemoryView } from "../marshal"; +import type { IMemoryView } from "../interop/marshal"; import type { CreateDotnetRuntimeType, DotnetHostBuilder, DotnetModuleConfig, RuntimeAPI, MonoConfig, ModuleAPI, AssetEntry, GlobalizationMode, AssetBehaviors } from "."; import type { EmscriptenModule } from "./emscripten"; import type { dotnet, exit } from "../loader/index"; diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 539def55f13130..8c56eee46a37c3 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -378,7 +378,7 @@ -DEMSDK_PATH="$(EMSDK_PATH.TrimEnd('\/').Replace('\','/'))" - emcmake cmake $(MSBuildThisFileDirectory)runtime + emcmake cmake $(MSBuildThisFileDirectory)runtime/native $(CMakeBuildRuntimeConfigureCmd) -DCMAKE_BUILD_TYPE=$(Configuration) $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_EMCC_FLAGS="$(CMakeConfigurationEmccFlags)" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_LINK_FLAGS="$(CMakeConfigurationLinkFlags)" @@ -421,28 +421,28 @@ DestinationFolder="$(MonoObjDir)" SkipUnchangedFiles="true" /> - - - - @@ -465,7 +465,7 @@ $(_EmccCompileRspPath); $(_EmccLinkRspPath); $(NativeBinDir)src\emcc-props.json" /> - + @@ -499,7 +499,7 @@ SkipUnchangedFiles="true" /> - +