Skip to content

Commit 9477f48

Browse files
authored
[browser] don't set js_handle for js prototypes (#115773)
1 parent 4e0dc08 commit 9477f48

File tree

2 files changed

+12
-1
lines changed
  • src
    • libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript
    • mono/browser/runtime

2 files changed

+12
-1
lines changed

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public unsafe void StructSize()
2020
Assert.Equal(32, sizeof(JSMarshalerArgument));
2121
}
2222

23+
[Fact]
24+
public unsafe void PrototypeNotEqual()
25+
{
26+
using var temp1 = JSHost.GlobalThis.GetPropertyAsJSObject("EventTarget");
27+
using var temp2 = JSHost.GlobalThis.GetPropertyAsJSObject("Window");
28+
Assert.NotEqual(temp1, temp2);
29+
}
30+
2331
[Fact]
2432
public async Task MultipleImportAsync()
2533
{

src/mono/browser/runtime/gc-handles.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export function mono_wasm_get_js_handle (js_obj: any): JSHandle {
8181
_cs_owned_objects_by_js_handle[<any>js_handle] = js_obj;
8282

8383
if (Object.isExtensible(js_obj)) {
84-
js_obj[cs_owned_js_handle_symbol] = js_handle;
84+
const is_prototype = typeof js_obj === "function" && Object.prototype.hasOwnProperty.call(js_obj, "prototype");
85+
if (!is_prototype) {
86+
js_obj[cs_owned_js_handle_symbol] = js_handle;
87+
}
8588
}
8689
// else
8790
// The consequence of not adding the cs_owned_js_handle_symbol is, that we could have multiple JSHandles and multiple proxy instances.

0 commit comments

Comments
 (0)