@@ -3,11 +3,11 @@ import { attachDebuggerHotkey, hasDebuggingEnabled } from './MonoDebugger';
33import { showErrorNotification } from '../../BootErrors' ;
44import { WebAssemblyResourceLoader , LoadingResource } from '../WebAssemblyResourceLoader' ;
55import { Platform , System_Array , Pointer , System_Object , System_String , HeapLock } from '../Platform' ;
6- import { loadTimezoneData } from './TimezoneDataFile' ;
76import { WebAssemblyBootResourceType } from '../WebAssemblyStartOptions' ;
87
98let mono_wasm_add_assembly : ( name : string , heapAddress : number , length : number ) => void ;
109const appBinDirName = 'appBinDir' ;
10+ const icuDataResourceName = 'icudt.dat' ;
1111const uint64HighOrderShift = Math . pow ( 2 , 32 ) ;
1212const maxSafeNumberHighPart = Math . pow ( 2 , 21 ) - 1 ; // The high-order int32 from Number.MAX_SAFE_INTEGER
1313
@@ -239,14 +239,26 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
239239 /* hash */ resourceLoader . bootConfig . resources . runtime [ dotnetWasmResourceName ] ,
240240 /* type */ 'dotnetwasm' ) ;
241241
242- const dotnetTimeZoneResourceName = 'dotnet.timezones.dat ' ;
242+ const dotnetTimeZoneResourceName = 'dotnet.timezones.blat ' ;
243243 let timeZoneResource : LoadingResource | undefined ;
244244 if ( resourceLoader . bootConfig . resources . runtime . hasOwnProperty ( dotnetTimeZoneResourceName ) ) {
245245 timeZoneResource = resourceLoader . loadResource (
246246 dotnetTimeZoneResourceName ,
247247 `_framework/${ dotnetTimeZoneResourceName } ` ,
248248 resourceLoader . bootConfig . resources . runtime [ dotnetTimeZoneResourceName ] ,
249- 'timezonedata' ) ;
249+ 'globalization' ) ;
250+ }
251+
252+ let icuDataResource : LoadingResource | undefined ;
253+ if ( resourceLoader . bootConfig . resources . runtime . hasOwnProperty ( icuDataResourceName ) ) {
254+ icuDataResource = resourceLoader . loadResource (
255+ icuDataResourceName ,
256+ `_framework/${ icuDataResourceName } ` ,
257+ resourceLoader . bootConfig . resources . runtime [ icuDataResourceName ] ,
258+ 'globalization' ) ;
259+ } else {
260+ // Use invariant culture if the app does not carry icu data.
261+ MONO . mono_wasm_setenv ( "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT" , "1" ) ;
250262 }
251263
252264 // Override the mechanism for fetching the main wasm file so we can connect it to our cache
@@ -274,6 +286,10 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
274286 loadTimezone ( timeZoneResource ) ;
275287 }
276288
289+ if ( icuDataResource ) {
290+ loadICUData ( icuDataResource ) ;
291+ }
292+
277293 // Fetch the assemblies and PDBs in the background, telling Mono to wait until they are loaded
278294 // Mono requires the assembly filenames to have a '.dll' extension, so supply such names regardless
279295 // of the extensions in the URLs. This allows loading assemblies with arbitrary filenames.
@@ -358,7 +374,11 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
358374 resourceLoader . purgeUnusedCacheEntriesAsync ( ) ; // Don't await - it's fine to run in background
359375
360376 MONO . mono_wasm_setenv ( "MONO_URI_DOTNETRELATIVEORABSOLUTE" , "true" ) ;
361- MONO . mono_wasm_setenv ( "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT" , "1" ) ;
377+ let timeZone = "UTC" ;
378+ try {
379+ timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
380+ } catch { }
381+ MONO . mono_wasm_setenv ( "TZ" , timeZone ) ;
362382 // Turn off full-gc to prevent browser freezing.
363383 const mono_wasm_enable_on_demand_gc = cwrap ( 'mono_wasm_enable_on_demand_gc' , null , [ 'number' ] ) ;
364384 mono_wasm_enable_on_demand_gc ( 0 ) ;
@@ -459,8 +479,27 @@ async function loadTimezone(timeZoneResource: LoadingResource) : Promise<void> {
459479
460480 const request = await timeZoneResource . response ;
461481 const arrayBuffer = await request . arrayBuffer ( ) ;
462- loadTimezoneData ( arrayBuffer )
463482
483+ Module [ 'FS_createPath' ] ( '/' , 'usr' , true , true ) ;
484+ Module [ 'FS_createPath' ] ( '/usr/' , 'share' , true , true ) ;
485+ Module [ 'FS_createPath' ] ( '/usr/share/' , 'zoneinfo' , true , true ) ;
486+ MONO . mono_wasm_load_data_archive ( new Uint8Array ( arrayBuffer ) , '/usr/share/zoneinfo/' ) ;
487+
488+ removeRunDependency ( runDependencyId ) ;
489+ }
490+
491+ async function loadICUData ( icuDataResource : LoadingResource ) : Promise < void > {
492+ const runDependencyId = `blazor:icudata` ;
493+ addRunDependency ( runDependencyId ) ;
494+
495+ const request = await icuDataResource . response ;
496+ const array = new Uint8Array ( await request . arrayBuffer ( ) ) ;
497+
498+ const offset = MONO . mono_wasm_load_bytes_into_heap ( array ) ;
499+ if ( ! MONO . mono_wasm_load_icu_data ( offset ) )
500+ {
501+ throw new Error ( "Error loading ICU asset." ) ;
502+ }
464503 removeRunDependency ( runDependencyId ) ;
465504}
466505
0 commit comments