Skip to content

Commit 90599c6

Browse files
Update JSInProcessObjectReference.cs (#48287)
* Update JSInProcessObjectReference.cs Fix for bug #48280 * Add JSObjectReferences dispose tests --------- Co-authored-by: Mackinnon Buck <[email protected]>
1 parent 91d702c commit 90599c6

File tree

9 files changed

+29
-8
lines changed

9 files changed

+29
-8
lines changed

src/Components/Web.JS/dist/Release/blazor.server.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/dist/Release/blazor.web.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/dist/Release/blazor.webview.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/test/E2ETest/Tests/InteropTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void CanInvokeDotNetMethods()
9191
["invokeAsyncThrowsSerializingCircularStructure"] = "Success",
9292
["invokeAsyncThrowsUndefinedJSObjectReference"] = "Success",
9393
["invokeAsyncThrowsNullJSObjectReference"] = "Success",
94+
["disposeJSObjectReferenceAsync"] = "Success",
9495
};
9596

9697
var expectedSyncValues = new Dictionary<string, string>
@@ -143,6 +144,7 @@ public void CanInvokeDotNetMethods()
143144
["genericInstanceMethod"] = @"""Updated value 2""",
144145
["requestDotNetStreamReference"] = @"""Success""",
145146
["requestDotNetStreamWrapperReference"] = @"""Success""",
147+
["disposeJSInProcessObjectReference"] = "Success",
146148
};
147149

148150
// Include the sync assertions only when running under WebAssembly

src/Components/test/testassets/BasicTestApp/InteropComponent.razor

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@
221221
JSObjectReferenceInvokeNonFunctionException = e;
222222
}
223223

224+
try
225+
{
226+
await jsObjectReference.DisposeAsync();
227+
ReturnValues["disposeJSObjectReferenceAsync"] = "Success";
228+
}
229+
catch (Exception ex)
230+
{
231+
ReturnValues["disposeJSObjectReferenceAsync"] = $"Failure: {ex.Message}";
232+
}
233+
224234
var module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/testmodule.js");
225235
ReturnValues["jsObjectReferenceModule"] = await module.InvokeAsync<string>("identity", "Returned from module!");
226236

@@ -408,6 +418,15 @@
408418
NumberField = 41,
409419
}).ToString();
410420

421+
try
422+
{
423+
jsInProcObjectReference.Dispose();
424+
ReturnValues["disposeJSInProcessObjectReference"] = "Success";
425+
}
426+
catch (Exception ex)
427+
{
428+
ReturnValues["disposeJSInProcessObjectReference"] = $"Failure: {ex.Message}";
429+
}
411430

412431
var unmarshalledRuntime = (IJSUnmarshalledRuntime)JSRuntime;
413432
var jsUnmarshalledReference = unmarshalledRuntime.InvokeUnmarshalled<IJSUnmarshalledObjectReference>("returnJSObjectReference");

src/JSInterop/Microsoft.JSInterop.JS/src/src/Microsoft.JSInterop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export module DotNet {
555555
throw new Error(`JS object instance with ID ${targetInstanceId} does not exist (has it been disposed?).`);
556556
}
557557

558-
function disposeJSObjectReferenceById(id: number) {
558+
export function disposeJSObjectReferenceById(id: number) {
559559
delete cachedJSObjectsById[id];
560560
}
561561

src/JSInterop/Microsoft.JSInterop/src/Implementation/JSInProcessObjectReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public void Dispose()
4444
}
4545
}
4646

47-
[JSImport("DotNet.jsCallDispatcher.disposeJSObjectReferenceById", "blazor-internal")]
47+
[JSImport("globalThis.DotNet.disposeJSObjectReferenceById")]
4848
private static partial void DisposeJSObjectReferenceById([JSMarshalAs<JSType.Number>] long id);
4949
}

src/JSInterop/Microsoft.JSInterop/src/Implementation/JSObjectReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class JSObjectReference : IJSObjectReference
2121
protected internal long Id { get; }
2222

2323
/// <summary>
24-
/// Inititializes a new <see cref="JSObjectReference"/> instance.
24+
/// Initializes a new <see cref="JSObjectReference"/> instance.
2525
/// </summary>
2626
/// <param name="jsRuntime">The <see cref="JSRuntime"/> used for invoking JS interop calls.</param>
2727
/// <param name="id">The unique identifier.</param>
@@ -55,7 +55,7 @@ public async ValueTask DisposeAsync()
5555
{
5656
Disposed = true;
5757

58-
await _jsRuntime.InvokeVoidAsync("DotNet.jsCallDispatcher.disposeJSObjectReferenceById", Id);
58+
await _jsRuntime.InvokeVoidAsync("DotNet.disposeJSObjectReferenceById", Id);
5959
}
6060
}
6161

src/JSInterop/Microsoft.JSInterop/src/Implementation/JSStreamReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class JSStreamReference : JSObjectReference, IJSStreamReference
1414
public long Length { get; }
1515

1616
/// <summary>
17-
/// Inititializes a new <see cref="JSStreamReference"/> instance.
17+
/// Initializes a new <see cref="JSStreamReference"/> instance.
1818
/// </summary>
1919
/// <param name="jsRuntime">The <see cref="JSRuntime"/> used for invoking JS interop calls.</param>
2020
/// <param name="id">The unique identifier.</param>

0 commit comments

Comments
 (0)