@@ -3,12 +3,12 @@ import { attachDebuggerHotkey, hasDebuggingEnabled } from './MonoDebugger';
3
3
import { showErrorNotification } from '../../BootErrors' ;
4
4
import { WebAssemblyResourceLoader , LoadingResource } from '../WebAssemblyResourceLoader' ;
5
5
import { Platform , System_Array , Pointer , System_Object , System_String , HeapLock } from '../Platform' ;
6
- import { loadTimezoneData } from './TimezoneDataFile' ;
7
6
import { WebAssemblyBootResourceType } from '../WebAssemblyStartOptions' ;
8
7
import { initializeProfiling } from '../Profiling' ;
9
8
10
9
let mono_wasm_add_assembly : ( name : string , heapAddress : number , length : number ) => void ;
11
10
const appBinDirName = 'appBinDir' ;
11
+ const icuDataResourceName = 'icudt.dat' ;
12
12
const uint64HighOrderShift = Math . pow ( 2 , 32 ) ;
13
13
const maxSafeNumberHighPart = Math . pow ( 2 , 21 ) - 1 ; // The high-order int32 from Number.MAX_SAFE_INTEGER
14
14
@@ -244,14 +244,26 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
244
244
/* hash */ resourceLoader . bootConfig . resources . runtime [ dotnetWasmResourceName ] ,
245
245
/* type */ 'dotnetwasm' ) ;
246
246
247
- const dotnetTimeZoneResourceName = 'dotnet.timezones.dat ' ;
247
+ const dotnetTimeZoneResourceName = 'dotnet.timezones.blat ' ;
248
248
let timeZoneResource : LoadingResource | undefined ;
249
249
if ( resourceLoader . bootConfig . resources . runtime . hasOwnProperty ( dotnetTimeZoneResourceName ) ) {
250
250
timeZoneResource = resourceLoader . loadResource (
251
251
dotnetTimeZoneResourceName ,
252
252
`_framework/${ dotnetTimeZoneResourceName } ` ,
253
253
resourceLoader . bootConfig . resources . runtime [ dotnetTimeZoneResourceName ] ,
254
- 'timezonedata' ) ;
254
+ 'globalization' ) ;
255
+ }
256
+
257
+ let icuDataResource : LoadingResource | undefined ;
258
+ if ( resourceLoader . bootConfig . resources . runtime . hasOwnProperty ( icuDataResourceName ) ) {
259
+ icuDataResource = resourceLoader . loadResource (
260
+ icuDataResourceName ,
261
+ `_framework/${ icuDataResourceName } ` ,
262
+ resourceLoader . bootConfig . resources . runtime [ icuDataResourceName ] ,
263
+ 'globalization' ) ;
264
+ } else {
265
+ // Use invariant culture if the app does not carry icu data.
266
+ MONO . mono_wasm_setenv ( "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT" , "1" ) ;
255
267
}
256
268
257
269
// Override the mechanism for fetching the main wasm file so we can connect it to our cache
@@ -279,6 +291,10 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
279
291
loadTimezone ( timeZoneResource ) ;
280
292
}
281
293
294
+ if ( icuDataResource ) {
295
+ loadICUData ( icuDataResource ) ;
296
+ }
297
+
282
298
// Fetch the assemblies and PDBs in the background, telling Mono to wait until they are loaded
283
299
// Mono requires the assembly filenames to have a '.dll' extension, so supply such names regardless
284
300
// of the extensions in the URLs. This allows loading assemblies with arbitrary filenames.
@@ -363,7 +379,11 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
363
379
resourceLoader . purgeUnusedCacheEntriesAsync ( ) ; // Don't await - it's fine to run in background
364
380
365
381
MONO . mono_wasm_setenv ( "MONO_URI_DOTNETRELATIVEORABSOLUTE" , "true" ) ;
366
- MONO . mono_wasm_setenv ( "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT" , "1" ) ;
382
+ let timeZone = "UTC" ;
383
+ try {
384
+ timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
385
+ } catch { }
386
+ MONO . mono_wasm_setenv ( "TZ" , timeZone ) ;
367
387
const load_runtime = cwrap ( 'mono_wasm_load_runtime' , null , [ 'string' , 'number' ] ) ;
368
388
// -1 enables debugging with logging disabled. 0 disables debugging entirely.
369
389
load_runtime ( appBinDirName , hasDebuggingEnabled ( ) ? - 1 : 0 ) ;
@@ -461,8 +481,27 @@ async function loadTimezone(timeZoneResource: LoadingResource) : Promise<void> {
461
481
462
482
const request = await timeZoneResource . response ;
463
483
const arrayBuffer = await request . arrayBuffer ( ) ;
464
- loadTimezoneData ( arrayBuffer )
465
484
485
+ Module [ 'FS_createPath' ] ( '/' , 'usr' , true , true ) ;
486
+ Module [ 'FS_createPath' ] ( '/usr/' , 'share' , true , true ) ;
487
+ Module [ 'FS_createPath' ] ( '/usr/share/' , 'zoneinfo' , true , true ) ;
488
+ MONO . mono_wasm_load_data_archive ( new Uint8Array ( arrayBuffer ) , '/usr/share/zoneinfo/' ) ;
489
+
490
+ removeRunDependency ( runDependencyId ) ;
491
+ }
492
+
493
+ async function loadICUData ( icuDataResource : LoadingResource ) : Promise < void > {
494
+ const runDependencyId = `blazor:icudata` ;
495
+ addRunDependency ( runDependencyId ) ;
496
+
497
+ const request = await icuDataResource . response ;
498
+ const array = new Uint8Array ( await request . arrayBuffer ( ) ) ;
499
+
500
+ const offset = MONO . mono_wasm_load_bytes_into_heap ( array ) ;
501
+ if ( ! MONO . mono_wasm_load_icu_data ( offset ) )
502
+ {
503
+ throw new Error ( "Error loading ICU asset." ) ;
504
+ }
466
505
removeRunDependency ( runDependencyId ) ;
467
506
}
468
507
0 commit comments