Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate framework use of 'IJSUnmarshalledRuntime' #46693

Merged
merged 12 commits into from
Mar 7, 2023
Merged
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.webview.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/Components/Web.JS/src/GlobalExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { NavigationLock } from './NavigationLock';
import { DefaultReconnectionHandler } from './Platform/Circuits/DefaultReconnectionHandler';
import { CircuitStartOptions } from './Platform/Circuits/CircuitStartOptions';
import { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions';
import { Platform, Pointer, System_String, System_Array, System_Boolean, System_Byte, System_Int } from './Platform/Platform';
import { Platform, Pointer } from './Platform/Platform';
import { getNextChunk, receiveDotNetDataStream } from './StreamingInterop';
import { RootComponentsFunctions } from './Rendering/JSRootComponents';
import { attachWebRendererInterop } from './Rendering/WebRendererInteropMethods';
Expand Down Expand Up @@ -62,10 +62,12 @@ interface IBlazor {
attachWebRendererInterop?: typeof attachWebRendererInterop;

// JSExport APIs
InvokeDotNet?: (assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number, argsJson: string) => string | null;
EndInvokeJS?: (argsJson: string) => void;
BeginInvokeDotNet?: (callId: string | null, assemblyNameOrDotNetObjectId: string, methodIdentifier: string, argsJson: string) => void;
ReceiveByteArrayFromJS?: (id: number, data: Uint8Array) => void;
dotNetExports?: {
InvokeDotNet: (assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number, argsJson: string) => string | null;
EndInvokeJS: (argsJson: string) => void;
BeginInvokeDotNet: (callId: string | null, assemblyNameOrDotNetObjectId: string, methodIdentifier: string, argsJson: string) => void;
ReceiveByteArrayFromJS: (id: number, data: Uint8Array) => void;
}

// APIs invoked by hot reload
initHotReload?: (url: string) => Promise<void>;
Expand Down
13 changes: 7 additions & 6 deletions src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ async function createRuntimeInstance(resourceLoader: WebAssemblyResourceLoader):
});
const exports = await runtime.getAssemblyExports('Microsoft.AspNetCore.Components.WebAssembly');
Object.assign(Blazor._internal, {
...exports.Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime,
dotNetExports: {
...exports.Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime,
},
});
MackinnonBuck marked this conversation as resolved.
Show resolved Hide resolved
attachInteropInvoker();
if (resourceLoader.bootConfig.debugBuild && resourceLoader.bootConfig.cacheBootResources) {
Expand Down Expand Up @@ -416,7 +418,6 @@ async function loadSatelliteAssemblies(resourceLoader: WebAssemblyResourceLoader
}));
}


async function loadLazyAssembly(resourceLoader: WebAssemblyResourceLoader, assemblyNameToLoad: string): Promise<{ dll: Uint8Array, pdb: Uint8Array | null }> {
const resources = resourceLoader.bootConfig.resources;
const lazyAssemblies = resources.lazyAssembly;
Expand Down Expand Up @@ -466,22 +467,22 @@ function attachInteropInvoker(): void {
? dotNetObjectId.toString()
: assemblyName;

Blazor._internal.BeginInvokeDotNet!(
Blazor._internal.dotNetExports!.BeginInvokeDotNet!(
callId ? callId.toString() : null,
assemblyNameOrDotNetObjectId,
methodIdentifier,
argsJson,
);
},
endInvokeJSFromDotNet: (asyncHandle, succeeded, serializedArgs): void => {
Blazor._internal.EndInvokeJS!(serializedArgs);
Blazor._internal.dotNetExports!.EndInvokeJS(serializedArgs);
},
sendByteArray: (id: number, data: Uint8Array): void => {
Blazor._internal.ReceiveByteArrayFromJS!(id, data);
Blazor._internal.dotNetExports!.ReceiveByteArrayFromJS(id, data);
},
invokeDotNetFromJS: (assemblyName, methodIdentifier, dotNetObjectId, argsJson) => {
assertHeapIsNotLocked();
return Blazor._internal.InvokeDotNet!(
return Blazor._internal.dotNetExports!.InvokeDotNet(
assemblyName ? assemblyName : null,
methodIdentifier,
dotNetObjectId ?? 0,
Expand Down
5 changes: 0 additions & 5 deletions src/Components/Web/src/Forms/InputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public ElementReference? Element
protected set => _inputFileElement = value!.Value;
}

/// <inheritdoc/>
protected override void OnInitialized()
{
}

/// <inheritdoc/>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
Expand Down
1 change: 1 addition & 0 deletions src/Components/Web/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
*REMOVED*override Microsoft.AspNetCore.Components.Forms.InputFile.OnInitialized() -> void
12 changes: 4 additions & 8 deletions src/Components/WebAssembly/JSInterop/src/InternalCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@

namespace WebAssembly.JSInterop;

/// <summary>
/// Methods that map to the functions compiled into the Mono WebAssembly runtime,
/// as defined by 'mono_add_internal_call' calls in driver.c.
/// </summary>
internal static partial class InternalCalls
{
// The exact namespace, type, and method names must match the corresponding entries
// in driver.c in the Mono distribution
/// See: https://github.com/mono/mono/blob/90574987940959fe386008a850982ea18236a533/sdks/wasm/src/driver.c#L318-L319

// This method only exists for backwards compatibility and will be removed in the future.
// The exact namespace, type, and method name must match the corresponding entries
// in driver.c in the Mono distribution.
// See: https://github.com/mono/mono/blob/90574987940959fe386008a850982ea18236a533/sdks/wasm/src/driver.c#L318-L319
[MethodImpl(MethodImplOptions.InternalCall)]
[Obsolete]
MackinnonBuck marked this conversation as resolved.
Show resolved Hide resolved
public static extern TRes InvokeJS<T0, T1, T2, TRes>(out string exception, ref JSCallInfo callInfo, [AllowNull] T0 arg0, [AllowNull] T1 arg1, [AllowNull] T2 arg2);
Expand Down
8 changes: 4 additions & 4 deletions src/Components/test/E2ETest/Tests/InteropTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void CanInvokeDotNetMethods()
["result8Async"] = @"[{""id"":7,""isValid"":false,""data"":{""source"":""Some random text with at least 7 characters"",""start"":7,""length"":7}},7,123,28,56,7.25,[0.5,1.5,2.5,3.5,4.5,5.5,6.5]]",
["result9Async"] = @"[{""id"":8,""isValid"":true,""data"":{""source"":""Some random text with at least 8 characters"",""start"":8,""length"":8}},8,123,32,64,8.25,[0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5],{""source"":""Some random text with at least 7 characters"",""start"":9,""length"":9}]",
["roundTripJSObjectReferenceAsync"] = @"""successful""",
["invokeDisposedJSObjectReferenceExceptionAsync"] = @"""JS object instance with ID",
["invokeDisposedJSObjectReferenceExceptionAsync"] = @"""Error: JS object instance with ID",
["roundTripByteArrayAsyncFromJS"] = @"{""0"":1,""1"":5,""2"":7,""3"":17,""4"":200,""5"":138}",
["roundTripByteArrayWrapperObjectAsyncFromJS"] = @"{""strVal"":""Some string"",""byteArrayVal"":{""0"":1,""1"":5,""2"":7,""3"":17,""4"":200,""5"":138},""intVal"":42}",
["roundTripByteArrayAsyncFromDotNet"] = @"1,5,7,15,35,200",
Expand All @@ -65,9 +65,9 @@ public void CanInvokeDotNetMethods()
["jsToDotNetStreamWrapperObjectParameterAsync"] = @"""Success""",
["AsyncThrowSyncException"] = @"""System.InvalidOperationException: Threw a sync exception!",
["AsyncThrowAsyncException"] = @"""System.InvalidOperationException: Threw an async exception!",
["SyncExceptionFromAsyncMethod"] = "Function threw a sync exception!",
["AsyncExceptionFromAsyncMethod"] = "Function threw an async exception!",
["JSObjectReferenceInvokeNonFunctionException"] = "The value 'nonFunction' is not a function.",
["SyncExceptionFromAsyncMethod"] = "Error: Function threw a sync exception!",
["AsyncExceptionFromAsyncMethod"] = "Error: Function threw an async exception!",
["JSObjectReferenceInvokeNonFunctionException"] = "Error: The value 'nonFunction' is not a function.",
["resultReturnDotNetObjectByRefAsync"] = "1001",
["instanceMethodThisTypeNameAsync"] = @"""JavaScriptInterop""",
["instanceMethodStringValueUpperAsync"] = @"""MY STRING""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export module DotNet {

function formatError(error: Error | string): string {
if (error instanceof Error) {
return `${error.message}\n${error.stack}`;
return error.stack ?? error.message;
MackinnonBuck marked this conversation as resolved.
Show resolved Hide resolved
}

return error ? error.toString() : "null";
Expand Down