Skip to content

Commit ff4791e

Browse files
authored
Use mono wasm method to invoke entry point (#17050)
1 parent 6af7fbe commit ff4791e

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

src/Components/Web.JS/dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Boot.WebAssembly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function boot(options?: any): Promise<void> {
6161

6262
// Start up the application
6363
const mainAssemblyName = getAssemblyNameFromUrl(bootConfig.main);
64-
platform.callEntryPoint(mainAssemblyName, bootConfig.entryPoint, []);
64+
platform.callEntryPoint(mainAssemblyName);
6565
}
6666

6767
async function fetchBootConfigAsync() {

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let assembly_load: (assemblyName: string) => number;
1111
let find_class: (assemblyHandle: number, namespace: string, className: string) => number;
1212
let find_method: (typeHandle: number, methodName: string, unknownArg: number) => MethodHandle;
1313
let invoke_method: (method: MethodHandle, target: System_Object, argsArrayPtr: number, exceptionFlagIntPtr: number) => System_Object;
14+
let mono_call_assembly_entry_point: (assemblyName: string, args: System_Object[]) => System_Object;
1415
let mono_string_get_utf8: (managedString: System_String) => Mono.Utf8Ptr;
1516
let mono_string: (jsString: string) => System_String;
1617
const appBinDirName = 'appBinDir';
@@ -39,21 +40,8 @@ export const monoPlatform: Platform = {
3940

4041
findMethod: findMethod,
4142

42-
callEntryPoint: function callEntryPoint(assemblyName: string, entrypointMethod: string, args: System_Object[]): void {
43-
// Parse the entrypointMethod, which is of the form MyApp.MyNamespace.MyTypeName::MyMethodName
44-
// Note that we don't support specifying a method overload, so it has to be unique
45-
const entrypointSegments = entrypointMethod.split('::');
46-
if (entrypointSegments.length != 2) {
47-
throw new Error('Malformed entry point method name; could not resolve class name and method name.');
48-
}
49-
const typeFullName = entrypointSegments[0];
50-
const methodName = entrypointSegments[1];
51-
const lastDot = typeFullName.lastIndexOf('.');
52-
const namespace = lastDot > -1 ? typeFullName.substring(0, lastDot) : '';
53-
const typeShortName = lastDot > -1 ? typeFullName.substring(lastDot + 1) : typeFullName;
54-
55-
const entryPointMethodHandle = monoPlatform.findMethod(assemblyName, namespace, typeShortName, methodName);
56-
monoPlatform.callMethod(entryPointMethodHandle, null, args);
43+
callEntryPoint: function callEntryPoint(assemblyName: string): System_Object {
44+
return mono_call_assembly_entry_point(assemblyName, []);
5745
},
5846

5947
callMethod: function callMethod(method: MethodHandle, target: System_Object, args: System_Object[]): System_Object {
@@ -272,6 +260,8 @@ function createEmscriptenModuleInstance(loadAssemblyUrls: string[], onReady: ()
272260
'number',
273261
'number',
274262
]);
263+
264+
mono_call_assembly_entry_point = Module.mono_call_assembly_entry_point;
275265
mono_string_get_utf8 = Module.cwrap('mono_wasm_string_get_utf8', 'number', ['number']);
276266
mono_string = Module.cwrap('mono_wasm_string_from_js', 'number', ['string']);
277267

src/Components/Web.JS/src/Platform/Mono/MonoTypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ declare namespace Module {
99
// These should probably be in @types/emscripten
1010
function FS_createPath(parent, path, canRead, canWrite);
1111
function FS_createDataFile(parent, name, data, canRead, canWrite, canOwn);
12+
13+
function mono_call_assembly_entry_point(assemblyName: string, args: any[]): any;
1214
}
1315

1416
// Emscripten declares these globals

src/Components/Web.JS/src/Platform/Platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface Platform {
22
start(loadAssemblyUrls: string[]): Promise<void>;
33

4-
callEntryPoint(assemblyName: string, entrypointMethod: string, args: (System_Object | null)[]);
4+
callEntryPoint(assemblyName: string): System_Object;
55
findMethod(assemblyName: string, namespace: string, className: string, methodName: string): MethodHandle;
66
callMethod(method: MethodHandle, target: System_Object | null, args: (System_Object | null)[]): System_Object;
77

0 commit comments

Comments
 (0)