@@ -3,11 +3,11 @@ 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
9
8
let mono_wasm_add_assembly : ( name : string , heapAddress : number , length : number ) => void ;
10
9
const appBinDirName = 'appBinDir' ;
10
+ const icuDataResourceName = 'icudt.dat' ;
11
11
const uint64HighOrderShift = Math . pow ( 2 , 32 ) ;
12
12
const maxSafeNumberHighPart = Math . pow ( 2 , 21 ) - 1 ; // The high-order int32 from Number.MAX_SAFE_INTEGER
13
13
@@ -239,14 +239,26 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
239
239
/* hash */ resourceLoader . bootConfig . resources . runtime [ dotnetWasmResourceName ] ,
240
240
/* type */ 'dotnetwasm' ) ;
241
241
242
- const dotnetTimeZoneResourceName = 'dotnet.timezones.dat ' ;
242
+ const dotnetTimeZoneResourceName = 'dotnet.timezones.blat ' ;
243
243
let timeZoneResource : LoadingResource | undefined ;
244
244
if ( resourceLoader . bootConfig . resources . runtime . hasOwnProperty ( dotnetTimeZoneResourceName ) ) {
245
245
timeZoneResource = resourceLoader . loadResource (
246
246
dotnetTimeZoneResourceName ,
247
247
`_framework/${ dotnetTimeZoneResourceName } ` ,
248
248
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" ) ;
250
262
}
251
263
252
264
// 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
274
286
loadTimezone ( timeZoneResource ) ;
275
287
}
276
288
289
+ if ( icuDataResource ) {
290
+ loadICUData ( icuDataResource ) ;
291
+ }
292
+
277
293
// Fetch the assemblies and PDBs in the background, telling Mono to wait until they are loaded
278
294
// Mono requires the assembly filenames to have a '.dll' extension, so supply such names regardless
279
295
// of the extensions in the URLs. This allows loading assemblies with arbitrary filenames.
@@ -358,7 +374,11 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
358
374
resourceLoader . purgeUnusedCacheEntriesAsync ( ) ; // Don't await - it's fine to run in background
359
375
360
376
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 ) ;
362
382
// Turn off full-gc to prevent browser freezing.
363
383
const mono_wasm_enable_on_demand_gc = cwrap ( 'mono_wasm_enable_on_demand_gc' , null , [ 'number' ] ) ;
364
384
mono_wasm_enable_on_demand_gc ( 0 ) ;
@@ -459,8 +479,27 @@ async function loadTimezone(timeZoneResource: LoadingResource) : Promise<void> {
459
479
460
480
const request = await timeZoneResource . response ;
461
481
const arrayBuffer = await request . arrayBuffer ( ) ;
462
- loadTimezoneData ( arrayBuffer )
463
482
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
+ }
464
503
removeRunDependency ( runDependencyId ) ;
465
504
}
466
505
0 commit comments