Description
Description
In dotnet new wasmbrowser
template I have really weird situation with JSObject.GetPropertyAsJSObject
where the order of calls makes different output.
When I execute JSHost.GlobalThis.GetPropertyAsJSObject("Window")
alone, it works great, but if I execute it after I execute JSHost.GlobalThis.GetPropertyAsJSObject("EventTarget")
, looks like it returns the EventTarget
instead of Window
.
Reproduction Steps
Here is a minimal change to template. Just replace Program.cs
with the following:
using System.Runtime.InteropServices.JavaScript;
public partial class MyClass
{
public static void Main()
{
}
[JSExport]
internal static string Greeting()
{
var temp1 = JSHost.GlobalThis.GetPropertyAsJSObject("EventTarget");
var temp2 = JSHost.GlobalThis.GetPropertyAsJSObject("Window");
return $"Hello from Greeting, it should return False: but got {temp1 == temp2}";
}
}
With this output it prints ...got True
, but if we flip the variables temp1
and temp2
, like the following, it prints ...got False
:
using System.Runtime.InteropServices.JavaScript;
public partial class MyClass
{
public static void Main()
{
}
[JSExport]
internal static string Greeting()
{
var temp2 = JSHost.GlobalThis.GetPropertyAsJSObject("Window");
var temp1 = JSHost.GlobalThis.GetPropertyAsJSObject("EventTarget");
return $"Hello from Greeting, it should return False: but got {temp1 == temp2}";
}
}
Expected behavior
It should write ...got False
in both cases.
Actual behavior
When JSHost.GlobalThis.GetPropertyAsJSObject("EventTarget")
is executed before JSHost.GlobalThis.GetPropertyAsJSObject("Window")
, JSHost.GlobalThis.GetPropertyAsJSObject("Window")
returns EventTarget
instead of Window
constructor.
Regression?
No response
Known Workarounds
No response
Configuration
dotnet --info
output:
.NET SDK:
Version: 9.0.101
Commit: f303476b53
Workload version: 9.0.101
MSBuild version: 17.12.12+f303476b5
Runtime Environment:
OS Name: Mac OS X
OS Version: 15.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /opt/homebrew/Cellar/dotnet/9.0.101/libexec/sdk/9.0.101/
.NET workloads installed:
[wasm-tools]
Installation Source: SDK 9.0.100
Manifest Version: 9.0.0/9.0.100
Manifest Path: /Users/<My User>/.dotnet/sdk-manifests/9.0.100/microsoft.net.workload.mono.toolchain.current/9.0.0/WorkloadManifest.json
Install Type: FileBased
Configured to use workload sets when installing new manifests.
Host:
Version: 9.0.0
Architecture: arm64
Commit: f303476b53
.NET SDKs installed:
9.0.101 [/opt/homebrew/Cellar/dotnet/9.0.101/libexec/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.0 [/opt/homebrew/Cellar/dotnet/9.0.101/libexec/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.0 [/opt/homebrew/Cellar/dotnet/9.0.101/libexec/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/opt/homebrew/Cellar/dotnet/9.0.101/libexec]
global.json file:
Not found
Browser Chrome Version 131.0.6778.140 (Official Build) (arm64)
Other information
No response