Skip to content

Commit

Permalink
[wasm] MonoProxy.cs: Avoid some errors by pre-emptively checking (#67243
Browse files Browse the repository at this point in the history
)

.. inspired by #66149 .
  • Loading branch information
radical authored Mar 28, 2022
1 parent d69bd06 commit 819b654
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,22 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, string meth
if (type == "debug")
{
JToken a = args["args"];
if (a?[0]?["value"]?.ToString() == MonoConstants.RUNTIME_IS_READY &&
a?[1]?["value"]?.ToString() == "fe00e07a-5519-4dfe-b35a-f867dbaf2e28")
if (a is null)
break;

int aCount = a.Count();
if (aCount >= 2 &&
a[0]?["value"]?.ToString() == MonoConstants.RUNTIME_IS_READY &&
a[1]?["value"]?.ToString() == "fe00e07a-5519-4dfe-b35a-f867dbaf2e28")
{
if (a.Count() > 2)
if (aCount > 2)
{
try
{
// The optional 3rd argument is the stringified assembly
// list so that we don't have to make more round trips
ExecutionContext context = GetContext(sessionId);
string loaded = a?[2]?["value"]?.ToString();
string loaded = a[2]?["value"]?.ToString();
if (loaded != null)
context.LoadedFiles = JToken.Parse(loaded).ToObject<string[]>();
}
Expand All @@ -110,15 +115,16 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, string meth
}
await RuntimeReady(sessionId, token);
}
else if (a?[0]?["value"]?.ToString() == MonoConstants.EVENT_RAISED)
else if (aCount > 1 && a[0]?["value"]?.ToString() == MonoConstants.EVENT_RAISED)
{
if (a.Type != JTokenType.Array)
{
logger.LogDebug($"Invalid event raised args, expected an array: {a.Type}");
}
else
{
if (JObjectTryParse(a?[2]?["value"]?.Value<string>(), out JObject raiseArgs) &&
if (aCount > 2 &&
JObjectTryParse(a?[2]?["value"]?.Value<string>(), out JObject raiseArgs) &&
JObjectTryParse(a?[1]?["value"]?.Value<string>(), out JObject eventArgs))
{
await OnJSEventRaised(sessionId, eventArgs, token);
Expand Down

0 comments on commit 819b654

Please sign in to comment.