@@ -10,55 +10,22 @@ import { showErrorNotification } from '../../BootErrors';
10
10
import { Platform , System_Array , Pointer , System_Object , System_String , HeapLock , PlatformApi } from '../Platform' ;
11
11
import { WebAssemblyBootResourceType , WebAssemblyStartOptions } from '../WebAssemblyStartOptions' ;
12
12
import { Blazor } from '../../GlobalExports' ;
13
- import { DotnetModuleConfig , EmscriptenModule , MonoConfig , ModuleAPI , RuntimeAPI , GlobalizationMode } from 'dotnet-runtime' ;
14
- import { BINDINGType , MONOType } from 'dotnet-runtime/dotnet-legacy' ;
13
+ import { DotnetModuleConfig , MonoConfig , ModuleAPI , RuntimeAPI , GlobalizationMode } from 'dotnet-runtime' ;
15
14
import { fetchAndInvokeInitializers } from '../../JSInitializers/JSInitializers.WebAssembly' ;
16
15
import { JSInitializer } from '../../JSInitializers/JSInitializers' ;
17
- import { WebRendererId } from '../../Rendering/WebRendererId' ;
18
16
19
17
// initially undefined and only fully initialized after createEmscriptenModuleInstance()
20
- export let BINDING : BINDINGType = undefined as any ;
21
- export let MONO : MONOType = undefined as any ;
22
- export let Module : DotnetModuleConfig & EmscriptenModule = undefined as any ;
23
18
export let dispatcher : DotNet . ICallDispatcher = undefined as any ;
24
19
let MONO_INTERNAL : any = undefined as any ;
25
20
let runtime : RuntimeAPI = undefined as any ;
26
21
let jsInitializer : JSInitializer ;
27
22
28
- const uint64HighOrderShift = Math . pow ( 2 , 32 ) ;
29
- const maxSafeNumberHighPart = Math . pow ( 2 , 21 ) - 1 ; // The high-order int32 from Number.MAX_SAFE_INTEGER
30
-
31
23
let currentHeapLock : MonoHeapLock | null = null ;
32
24
33
- // Memory access helpers
34
- // The implementations are exactly equivalent to what the global getValue(addr, type) function does,
35
- // except without having to parse the 'type' parameter, and with less risk of mistakes at the call site
36
- function getValueI16 ( ptr : number ) {
37
- return MONO . getI16 ( ptr ) ;
38
- }
39
- function getValueI32 ( ptr : number ) {
40
- return MONO . getI32 ( ptr ) ;
41
- }
42
- function getValueFloat ( ptr : number ) {
43
- return MONO . getF32 ( ptr ) ;
44
- }
45
-
46
25
export function getInitializer ( ) {
47
26
return jsInitializer ;
48
27
}
49
28
50
- function getValueU64 ( ptr : number ) {
51
- // There is no Module.HEAPU64, and Module.getValue(..., 'i64') doesn't work because the implementation
52
- // treats 'i64' as being the same as 'i32'. Also we must take care to read both halves as unsigned.
53
- const heapU32Index = ptr >> 2 ;
54
- const highPart = Module . HEAPU32 [ heapU32Index + 1 ] ;
55
- if ( highPart > maxSafeNumberHighPart ) {
56
- throw new Error ( `Cannot read uint64 with high order part ${ highPart } , because the result would exceed Number.MAX_SAFE_INTEGER.` ) ;
57
- }
58
-
59
- return ( highPart * uint64HighOrderShift ) + Module . HEAPU32 [ heapU32Index ] ;
60
- }
61
-
62
29
export const monoPlatform : Platform = {
63
30
load : function load ( options : Partial < WebAssemblyStartOptions > , onConfigLoaded ?: ( loadedConfig : MonoConfig ) => void ) {
64
31
return createRuntimeInstance ( options , onConfigLoaded ) ;
@@ -77,18 +44,6 @@ export const monoPlatform: Platform = {
77
44
}
78
45
} ,
79
46
80
- toUint8Array : function toUint8Array ( array : System_Array < any > ) : Uint8Array {
81
- const dataPtr = getArrayDataPointer ( array ) ;
82
- const length = getValueI32 ( dataPtr ) ;
83
- const uint8Array = new Uint8Array ( length ) ;
84
- uint8Array . set ( Module . HEAPU8 . subarray ( dataPtr + 4 , dataPtr + 4 + length ) ) ;
85
- return uint8Array ;
86
- } ,
87
-
88
- getArrayLength : function getArrayLength ( array : System_Array < any > ) : number {
89
- return getValueI32 ( getArrayDataPointer ( array ) ) ;
90
- } ,
91
-
92
47
getArrayEntryPtr : function getArrayEntryPtr < TPtr extends Pointer > ( array : System_Array < TPtr > , index : number , itemSize : number ) : TPtr {
93
48
// First byte is array length, followed by entries
94
49
const address = getArrayDataPointer ( array ) + 4 + index * itemSize ;
@@ -97,46 +52,42 @@ export const monoPlatform: Platform = {
97
52
98
53
getObjectFieldsBaseAddress : function getObjectFieldsBaseAddress ( referenceTypedObject : System_Object ) : Pointer {
99
54
// The first two int32 values are internal Mono data
100
- return ( referenceTypedObject as any as number + 8 ) as any as Pointer ;
55
+ return ( referenceTypedObject as any + 8 ) as any as Pointer ;
101
56
} ,
102
57
103
58
readInt16Field : function readHeapInt16 ( baseAddress : Pointer , fieldOffset ?: number ) : number {
104
- return getValueI16 ( ( baseAddress as any as number ) + ( fieldOffset || 0 ) ) ;
59
+ return runtime . getHeapI16 ( ( baseAddress as any ) + ( fieldOffset || 0 ) ) ;
105
60
} ,
106
61
107
62
readInt32Field : function readHeapInt32 ( baseAddress : Pointer , fieldOffset ?: number ) : number {
108
- return getValueI32 ( ( baseAddress as unknown as number ) + ( fieldOffset || 0 ) ) ;
63
+ return runtime . getHeapI32 ( ( baseAddress as any ) + ( fieldOffset || 0 ) ) ;
109
64
} ,
110
65
111
66
readUint64Field : function readHeapUint64 ( baseAddress : Pointer , fieldOffset ?: number ) : number {
112
- return getValueU64 ( ( baseAddress as unknown as number ) + ( fieldOffset || 0 ) ) ;
113
- } ,
114
-
115
- readFloatField : function readHeapFloat ( baseAddress : Pointer , fieldOffset ?: number ) : number {
116
- return getValueFloat ( ( baseAddress as unknown as number ) + ( fieldOffset || 0 ) ) ;
67
+ return runtime . getHeapU52 ( ( baseAddress as any ) + ( fieldOffset || 0 ) ) ;
117
68
} ,
118
69
119
- readObjectField : function readHeapObject < T extends System_Object > ( baseAddress : Pointer , fieldOffset ?: number ) : T {
120
- return getValueI32 ( ( baseAddress as unknown as number ) + ( fieldOffset || 0 ) ) as any as T ;
70
+ readObjectField : function readObjectField < T extends System_Object > ( baseAddress : Pointer , fieldOffset ?: number ) : T {
71
+ return runtime . getHeapU32 ( ( baseAddress as any ) + ( fieldOffset || 0 ) ) as any as T ;
121
72
} ,
122
73
123
- readStringField : function readHeapObject ( baseAddress : Pointer , fieldOffset ?: number , readBoolValueAsString ?: boolean ) : string | null {
124
- const fieldValue = getValueI32 ( ( baseAddress as unknown as number ) + ( fieldOffset || 0 ) ) ;
74
+ readStringField : function readStringField ( baseAddress : Pointer , fieldOffset ?: number , readBoolValueAsString ?: boolean ) : string | null {
75
+ const fieldValue = runtime . getHeapU32 ( ( baseAddress as any ) + ( fieldOffset || 0 ) ) ;
125
76
if ( fieldValue === 0 ) {
126
77
return null ;
127
78
}
128
79
129
80
if ( readBoolValueAsString ) {
130
81
// Some fields are stored as a union of bool | string | null values, but need to read as a string.
131
82
// If the stored value is a bool, the behavior we want is empty string ('') for true, or null for false.
132
- const unboxedValue = BINDING . unbox_mono_obj ( fieldValue as any as System_Object ) ;
83
+
84
+ const unboxedValue = MONO_INTERNAL . monoObjectAsBoolOrNullUnsafe ( fieldValue as any as System_Object ) ;
133
85
if ( typeof ( unboxedValue ) === 'boolean' ) {
134
86
return unboxedValue ? '' : null ;
135
87
}
136
- return unboxedValue ;
137
88
}
138
89
139
- return BINDING . conv_string ( fieldValue as any as System_String ) ;
90
+ return MONO_INTERNAL . monoStringToStringUnsafe ( fieldValue as any as System_String ) ;
140
91
} ,
141
92
142
93
readStructField : function readStructField < T extends Pointer > ( baseAddress : Pointer , fieldOffset ?: number ) : T {
@@ -206,13 +157,12 @@ function prepareRuntimeConfig(options: Partial<WebAssemblyStartOptions>, onConfi
206
157
jsInitializer = await fetchAndInvokeInitializers ( options , loadedConfig ) ;
207
158
} ;
208
159
209
- const moduleConfig = ( window [ 'Module' ] || { } ) as typeof Module ;
160
+ const moduleConfig = ( window [ 'Module' ] || { } ) as any ;
210
161
const dotnetModuleConfig : DotnetModuleConfig = {
211
162
...moduleConfig ,
212
163
onConfigLoaded : ( onConfigLoaded as ( config : MonoConfig ) => void | Promise < void > ) ,
213
164
onDownloadResourceProgress : setProgress ,
214
165
config,
215
- disableDotnet6Compatibility : false ,
216
166
out : print ,
217
167
err : printErr ,
218
168
} ;
@@ -251,10 +201,7 @@ async function configureRuntimeInstance(): Promise<PlatformApi> {
251
201
throw new Error ( 'The runtime must be loaded it gets configured.' ) ;
252
202
}
253
203
254
- const { MONO : mono , BINDING : binding , Module : module , setModuleImports, INTERNAL : mono_internal , getConfig, invokeLibraryInitializers } = runtime ;
255
- Module = module ;
256
- BINDING = binding ;
257
- MONO = mono ;
204
+ const { setModuleImports, INTERNAL : mono_internal , getConfig, invokeLibraryInitializers } = runtime ;
258
205
MONO_INTERNAL = mono_internal ;
259
206
260
207
attachDebuggerHotkey ( getConfig ( ) ) ;
@@ -285,7 +232,7 @@ function setProgress(resourcesLoaded, totalResources) {
285
232
286
233
const suppressMessages = [ 'DEBUGGING ENABLED' ] ;
287
234
const print = line => ( suppressMessages . indexOf ( line ) < 0 && console . log ( line ) ) ;
288
- const printErr = line => {
235
+ export const printErr = line => {
289
236
// If anything writes to stderr, treat it as a critical exception. The underlying runtime writes
290
237
// to stderr if a truly critical problem occurs outside .NET code. Note that .NET unhandled
291
238
// exceptions also reach this, but via a different code path - see dotNetCriticalError below.
0 commit comments