Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[browser] Separate hybrid globalization JS code to es6 module #101543

Merged
merged 33 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0c17d0c
dotnet.hybrid.js module creation when MT is off
ilonatommy Apr 25, 2024
2f8cbcc
Improvement but not fix.
ilonatommy Apr 25, 2024
e6dcc49
More improvements, still failing.
ilonatommy Apr 25, 2024
aafd997
Importing module
ilonatommy Apr 26, 2024
27ea4c4
Flip condition - load HG with ST only.
ilonatommy Apr 26, 2024
192bef5
Remove globalization code from main module, create the globalization …
ilonatommy Apr 26, 2024
66c074d
Missing change.
ilonatommy Apr 26, 2024
825c6ae
Fix for `blazor.boot.config` ST/MT. Still errors in the runtime.
ilonatommy Apr 26, 2024
eb2c26d
Fix: `runtimeHelper` is not null if we cache it on module init.
ilonatommy May 7, 2024
8669727
Fix: `segmentationRules` throwing "Cannot convert undefined or null t…
ilonatommy May 7, 2024
07154e6
Change flag to HG.
ilonatommy May 7, 2024
40f292a
Merge branch 'main' into 98483-hg-modularization
ilonatommy May 7, 2024
08df581
Fix MT.
ilonatommy May 13, 2024
faea49d
Merge branch 'main' into 98483-hg-modularization
ilonatommy May 13, 2024
f577ac3
Cleanup.
ilonatommy May 13, 2024
6bcad7d
Remove duplicates.
ilonatommy May 13, 2024
759803a
Export functions used by hybrid globalization only when HG is on.
ilonatommy May 13, 2024
602c1f9
Do not try to call when methods are not initialized.
ilonatommy May 13, 2024
a6a36b6
Fix previous commit.
ilonatommy May 13, 2024
e6f81d7
`mono_wasm_get_locale_info` is used also in non-HG mode, add it to th…
ilonatommy May 13, 2024
ff3c1d4
Feedback - cleanup.
ilonatommy May 13, 2024
43f0fbf
Check WBT for presence of globalization module if HG is switched on.
ilonatommy May 13, 2024
b0bc1fe
Fix MT globalization tests - NativeName is fixed there.
ilonatommy May 14, 2024
be4ad97
Missing change to the prev commit.
ilonatommy May 14, 2024
f0b442d
Trying to fix WBT.
ilonatommy May 14, 2024
c91b076
Merge branch 'main' into 98483-hg-modularization
ilonatommy May 14, 2024
2881009
Semicolon should not be in the souce name.
ilonatommy May 14, 2024
64bb2ea
Fix.
ilonatommy May 14, 2024
586cc37
Fix hybrid change case.
ilonatommy May 14, 2024
4051775
Globalization module is not expected to change on relink.
ilonatommy May 14, 2024
265d39c
Fix blazor's assets + remove duplicated asset entry.
ilonatommy May 15, 2024
b1e7448
Merge remote-tracking branch 'origin/main' into 98483-hg-modularization
ilonatommy May 15, 2024
96ab2f1
Feedback
ilonatommy May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/mono/browser/runtime/corebindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ extern void mono_wasm_invoke_jsimport_ST (int function_handle, void *args);
#endif /* DISABLE_THREADS */

// HybridGlobalization
#ifdef DISABLE_THREADS // CHANGE to HybridGlobalization later
extern char16_t* mono_wasm_change_case_invariant (const uint16_t* src, int32_t srcLength, uint16_t* dst, int32_t dstLength, mono_bool bToUpper);
extern char16_t* mono_wasm_change_case (const uint16_t* culture, int32_t cultureLength, const uint16_t* src, int32_t srcLength, uint16_t* dst, int32_t dstLength, mono_bool bToUpper);
extern char16_t* mono_wasm_compare_string (const uint16_t* culture, int32_t cultureLength, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options, int *resultPtr);
Expand All @@ -71,7 +70,6 @@ extern char16_t* mono_wasm_get_culture_info (const uint16_t* culture, int32_t cu
extern char16_t* mono_wasm_get_locale_info (const uint16_t* locale, int32_t localeLength, const uint16_t* culture, int32_t cultureLength, const uint16_t* result, int32_t resultMaxLength, int *resultLength);
extern char16_t* mono_wasm_get_first_day_of_week (const uint16_t* culture, int32_t cultureLength, int *resultPtr);
extern char16_t* mono_wasm_get_first_week_of_year (const uint16_t* culture, int32_t cultureLength, int *resultPtr);
#endif /* DISABLE_THREADS */

void bindings_initialize_internals (void)
{
Expand Down Expand Up @@ -106,7 +104,6 @@ void bindings_initialize_internals (void)
mono_add_internal_call ("System.ConsolePal::Clear", mono_wasm_console_clear);

// HybridGlobalization
#ifdef DISABLE_THREADS // CHANGE to HybridGlobalization later
mono_add_internal_call ("Interop/JsGlobalization::ChangeCaseInvariant", mono_wasm_change_case_invariant);
mono_add_internal_call ("Interop/JsGlobalization::ChangeCase", mono_wasm_change_case);
mono_add_internal_call ("Interop/JsGlobalization::CompareString", mono_wasm_compare_string);
Expand All @@ -118,7 +115,6 @@ void bindings_initialize_internals (void)
mono_add_internal_call ("Interop/JsGlobalization::GetCultureInfo", mono_wasm_get_culture_info);
mono_add_internal_call ("Interop/JsGlobalization::GetFirstDayOfWeek", mono_wasm_get_first_day_of_week);
mono_add_internal_call ("Interop/JsGlobalization::GetFirstWeekOfYear", mono_wasm_get_first_week_of_year);
#endif /* DISABLE_THREADS */
}

static MonoAssembly* _mono_wasm_assembly_load (char *assembly_name)
Expand Down
52 changes: 46 additions & 6 deletions src/mono/browser/runtime/exports-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pip
import { mono_wasm_diagnostic_server_stream_signal_work_available } from "./diagnostics/server_pthread/stream-queue";
import { mono_log_warn, mono_wasm_console_clear, 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_get_culture_info } from "./hybrid-globalization/culture-info";
import { mono_wasm_get_locale_info, mono_wasm_get_first_day_of_week, mono_wasm_get_first_week_of_year } from "./hybrid-globalization/locales";
import { mono_wasm_browser_entropy } from "./crypto";
import { mono_wasm_cancel_promise } from "./cancelable-promise";

Expand All @@ -33,6 +27,8 @@ import {
} from "./pthreads";
import { mono_wasm_dump_threads } from "./pthreads/ui-thread";
import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared";
import { Int32Ptr, VoidPtr } from "./types/emscripten";
import { runtimeHelpers } from "./globals";

// the JS methods would be visible to EMCC linker and become imports of the WASM module

Expand Down Expand Up @@ -103,6 +99,50 @@ export const mono_wasm_imports = [
mono_wasm_cancel_promise,
];

function mono_wasm_change_case_invariant (src: number, srcLength: number, dst: number, dstLength: number, toUpper: number) : VoidPtr {
return runtimeHelpers.mono_wasm_change_case_invariant(src, srcLength, dst, dstLength, toUpper);
}

function mono_wasm_change_case (culture: number, cultureLength: number, src: number, srcLength: number, dst: number, dstLength: number, toUpper: number) : VoidPtr {
return runtimeHelpers.mono_wasm_change_case(culture, cultureLength, src, srcLength, dst, dstLength, toUpper);
}

function mono_wasm_compare_string (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr) : VoidPtr {
return runtimeHelpers.mono_wasm_compare_string(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr);
}

function mono_wasm_starts_with (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_starts_with(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr);
}

function mono_wasm_ends_with (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_ends_with(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr);
}

function mono_wasm_index_of (culture: number, cultureLength: number, needlePtr: number, needleLength: number, srcPtr: number, srcLength: number, options: number, fromBeginning: number, resultPtr: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_index_of(culture, cultureLength, needlePtr, needleLength, srcPtr, srcLength, options, fromBeginning, resultPtr);
}

function mono_wasm_get_calendar_info (culture: number, cultureLength: number, calendarId: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_get_calendar_info(culture, cultureLength, calendarId, dst, dstMaxLength, dstLength);
}

function mono_wasm_get_culture_info (culture: number, cultureLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_get_culture_info(culture, cultureLength, dst, dstMaxLength, dstLength);
}

function mono_wasm_get_locale_info (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_get_locale_info(culture, cultureLength, locale, localeLength, dst, dstMaxLength, dstLength);
}

function mono_wasm_get_first_day_of_week (culture: number, cultureLength: number, resultPtr: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_get_first_day_of_week(culture, cultureLength, resultPtr);
}

function mono_wasm_get_first_week_of_year (culture: number, cultureLength: number, resultPtr: Int32Ptr): VoidPtr {
return runtimeHelpers.mono_wasm_get_first_week_of_year(culture, cultureLength, resultPtr);
}

export const mono_wasm_hybrid_globalization_imports = WasmEnableThreads ? [] : [ // ToDo: change it to rely on HybridGlobalization
mono_wasm_change_case_invariant,
mono_wasm_change_case,
Expand Down
27 changes: 21 additions & 6 deletions src/mono/browser/runtime/hybrid-globalization/module-exports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
export * from "./calendar";
export * from "./culture-info";
export * from "./helpers";
export * from "./change-case";
export * from "./locales";
export * from "./collations";
import { RuntimeHelpers } from "../types/internal";
import { mono_wasm_get_calendar_info } from "./calendar";
import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "./change-case";
import { mono_wasm_compare_string, mono_wasm_starts_with, mono_wasm_ends_with, mono_wasm_index_of } from "./collations";
import { mono_wasm_get_culture_info } from "./culture-info";
import { mono_wasm_get_locale_info, mono_wasm_get_first_day_of_week, mono_wasm_get_first_week_of_year } from "./locales";

export function initHybrid (rh: RuntimeHelpers) {
rh.mono_wasm_change_case_invariant = mono_wasm_change_case_invariant;
rh.mono_wasm_change_case = mono_wasm_change_case;
rh.mono_wasm_compare_string = mono_wasm_compare_string;
rh.mono_wasm_starts_with = mono_wasm_starts_with;
rh.mono_wasm_ends_with = mono_wasm_ends_with;
rh.mono_wasm_index_of = mono_wasm_index_of;
rh.mono_wasm_get_calendar_info = mono_wasm_get_calendar_info;
rh.mono_wasm_get_culture_info = mono_wasm_get_culture_info;
rh.mono_wasm_get_locale_info = mono_wasm_get_locale_info;
rh.mono_wasm_get_first_day_of_week = mono_wasm_get_first_day_of_week;
rh.mono_wasm_get_first_week_of_year = mono_wasm_get_first_week_of_year;
}

12 changes: 12 additions & 0 deletions src/mono/browser/runtime/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ export type RuntimeHelpers = {
localHeapViewU16: () => Uint16Array,
setU16_local: (heap: Uint16Array, ptr: number, value: number) => void,
setI32: (offset: MemOffset, value: number) => void,

mono_wasm_change_case_invariant: (src: number, srcLength: number, dst: number, dstLength: number, toUpper: number) => VoidPtr;
mono_wasm_change_case: (culture: number, cultureLength: number, src: number, srcLength: number, dst: number, dstLength: number, toUpper: number) => VoidPtr;
mono_wasm_compare_string: (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr) => VoidPtr;
mono_wasm_starts_with: (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr) => VoidPtr;
mono_wasm_ends_with: (culture: number, cultureLength: number, str1: number, str1Length: number, str2: number, str2Length: number, options: number, resultPtr: Int32Ptr) => VoidPtr;
mono_wasm_index_of: (culture: number, cultureLength: number, needlePtr: number, needleLength: number, srcPtr: number, srcLength: number, options: number, fromBeginning: number, resultPtr: Int32Ptr) => VoidPtr;
mono_wasm_get_calendar_info: (culture: number, cultureLength: number, calendarId: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr) => VoidPtr;
mono_wasm_get_culture_info: (culture: number, cultureLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr) => VoidPtr;
mono_wasm_get_locale_info: (culture: number, cultureLength: number, locale: number, localeLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr) => VoidPtr;
mono_wasm_get_first_day_of_week: (culture: number, cultureLength: number, resultPtr: Int32Ptr) => VoidPtr;
mono_wasm_get_first_week_of_year: (culture: number, cultureLength: number, resultPtr: Int32Ptr) => VoidPtr;
}

export type AOTProfilerOptions = {
Expand Down
Loading