Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/mono/wasm/runtime/dotnet_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ var DotNetSupportLib = {
return MONO.string_decoder.copy (mono_obj);
}
},

mono_wasm_invoke_js_blazor: function(exceptionMessage, callInfo, arg0, arg1, arg2) {
try {
var blazorExports = DOTNET._dotnet_get_global().Blazor;
if (!blazorExports) {
throw new Error('The blazor.webassembly.js library is not loaded.');
}

return blazorExports._internal.invokeJSFromDotNet(callInfo, arg0, arg1, arg2);
} catch (ex) {
var exceptionJsString = ex.message + '\n' + ex.stack;
var exceptionSystemString = mono_string(exceptionJsString);
setValue (exceptionMessage, exceptionSystemString, 'i32'); // *exceptionMessage = exceptionSystemString;
return 0;
}
},

// This is for back-compat only and will eventually be removed
mono_wasm_invoke_js_marshalled: function(exceptionMessage, asyncHandleLongPtr, functionName, argsJson, treatResultAsVoid) {

var mono_string = DOTNET._dotnet_get_global()._mono_string_cached
Expand Down Expand Up @@ -67,6 +85,8 @@ var DotNetSupportLib = {
return 0;
}
},

// This is for back-compat only and will eventually be removed
mono_wasm_invoke_js_unmarshalled: function(exceptionMessage, funcName, arg0, arg1, arg2) {
try {
// Get the function you're trying to invoke
Expand Down
4 changes: 4 additions & 0 deletions src/mono/wasm/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ void core_initialize_internals ();
#endif

// Blazor specific custom routines - see dotnet_support.js for backing code
extern void* mono_wasm_invoke_js_blazor (MonoString **exceptionMessage, void *callInfo, void* arg0, void* arg1, void* arg2);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for the arg0/arg1/arg2 params is so we can retain the earlier semantics about how reference and value types are represented in the unmarshalled interop cases.

// The following two are for back-compat and will eventually be removed
extern void* mono_wasm_invoke_js_marshalled (MonoString **exceptionMessage, void *asyncHandleLongPtr, MonoString *funcName, MonoString *argsJson);
extern void* mono_wasm_invoke_js_unmarshalled (MonoString **exceptionMessage, MonoString *funcName, void* arg0, void* arg1, void* arg2);

Expand Down Expand Up @@ -348,6 +350,8 @@ void mono_initialize_internals ()
// TODO: what happens when two types in different assemblies have the same FQN?

// Blazor specific custom routines - see dotnet_support.js for backing code
mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJS", mono_wasm_invoke_js_blazor);
// The following two are for back-compat and will eventually be removed
mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJSMarshalled", mono_wasm_invoke_js_marshalled);
mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJSUnmarshalled", mono_wasm_invoke_js_unmarshalled);

Expand Down