From 8a4c3c040fc0b92fc6a56848d24c4cc780d2cb88 Mon Sep 17 00:00:00 2001 From: Gokhan Kurt Date: Sat, 21 Dec 2024 22:45:13 +0300 Subject: [PATCH] fix null reference issues on callbacks called on disposed context --- Runtime/Helpers/Callback.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Runtime/Helpers/Callback.cs b/Runtime/Helpers/Callback.cs index ce6f47e9..2f7219a8 100644 --- a/Runtime/Helpers/Callback.cs +++ b/Runtime/Helpers/Callback.cs @@ -104,7 +104,7 @@ public object Call(params object[] args) { var res = context.FireEventByRefCallback?.Call(i, args); #if REACT_QUICKJS - (context.Script.Engine as Scripting.QuickJSEngine)?.Runtime.ExecutePendingJob(); + (context.Script.Engine as Scripting.QuickJSEngine)?.Runtime?.ExecutePendingJob(); #endif return res; } @@ -114,7 +114,7 @@ public object Call(params object[] args) // TODO: because of an error in ClearScipt, arrays cannot be iterated (Mono bug?) so.Engine.Global.SetProperty("__temp__", so); so.Engine.Global.SetProperty("__args__", args?.ToList()); - var res = so.Engine.Evaluate(null, true, "var res = __temp__(...(__args__ || [])); delete __temp__; delete __args__; res;"); + var res = so.Engine?.Evaluate(null, true, "var res = __temp__(...(__args__ || [])); delete __temp__; delete __args__; res;"); return res; } #endif @@ -122,7 +122,7 @@ public object Call(params object[] args) else if (callback is QuickJS.ScriptFunction sf) { var res = sf.Invoke(args); - QuickJS.ScriptEngine.GetRuntime(sf.ctx).ExecutePendingJob(); + QuickJS.ScriptEngine.GetRuntime(sf.ctx)?.ExecutePendingJob(); return res; } else if (callback is QuickJS.ScriptValue sv) @@ -130,17 +130,17 @@ public object Call(params object[] args) var sff = new QuickJS.ScriptFunction(QuickJS.ScriptEngine.GetContext(sv.ctx), sv); var res = sff.Invoke(args); sff.Dispose(); - QuickJS.ScriptEngine.GetRuntime(sv.ctx).ExecutePendingJob(); + QuickJS.ScriptEngine.GetRuntime(sv.ctx)?.ExecutePendingJob(); return res; } else if (callback is QuickJS.Native.JSValue qf) { - var eg = (context?.Script.Engine as Scripting.QuickJSEngine); + var eg = (context?.Script?.Engine as Scripting.QuickJSEngine); if (eg == null) return null; var sff = new QuickJS.ScriptFunction(eg.MainContext, qf); var res = sff.Invoke(args); sff.Dispose(); - eg?.Runtime.ExecutePendingJob(); + eg?.Runtime?.ExecutePendingJob(); return res; } #endif