未验证 提交 819b654e 编写于 作者: A Ankit Jain 提交者: GitHub

[wasm] MonoProxy.cs: Avoid some errors by pre-emptively checking (#67243)

.. inspired by https://github.com/dotnet/runtime/issues/66149 .
上级 d69bd061
......@@ -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[]>();
}
......@@ -110,7 +115,7 @@ 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)
{
......@@ -118,7 +123,8 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, string meth
}
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册