Skip to content

Commit

Permalink
fix null reference issues on callbacks called on disposed context
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Dec 21, 2024
1 parent 4cf07f9 commit 8a4c3c0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Runtime/Helpers/Callback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -114,33 +114,33 @@ 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
#if REACT_QUICKJS
else if (callback is QuickJS.ScriptFunction sf)
{
var res = sf.Invoke<object>(args);
QuickJS.ScriptEngine.GetRuntime(sf.ctx).ExecutePendingJob();
QuickJS.ScriptEngine.GetRuntime(sf.ctx)?.ExecutePendingJob();
return res;
}
else if (callback is QuickJS.ScriptValue sv)
{
var sff = new QuickJS.ScriptFunction(QuickJS.ScriptEngine.GetContext(sv.ctx), sv);
var res = sff.Invoke<object>(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<object>(args);
sff.Dispose();
eg?.Runtime.ExecutePendingJob();
eg?.Runtime?.ExecutePendingJob();
return res;
}
#endif
Expand Down

0 comments on commit 8a4c3c0

Please sign in to comment.