Skip to content

Commit

Permalink
fixes for old unity versions
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Feb 17, 2024
1 parent 5bdbcd3 commit 6b051df
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Runtime/Helpers/ReactInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ReactInterop : Dictionary<string, object>, IDisposable
#endif
{
private readonly IJavaScriptEngine Engine;
ConcurrentDictionary<string, object> typeCache = new();
ConcurrentDictionary<string, object> namespaceCache = new();
ConcurrentDictionary<string, object> typeCache = new ConcurrentDictionary<string, object>();
ConcurrentDictionary<string, object> namespaceCache = new ConcurrentDictionary<string, object>();


public ReactInterop(IJavaScriptEngine engine)
Expand Down
11 changes: 10 additions & 1 deletion Runtime/Helpers/ReactProfiling.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Runtime/Helpers/StringHelpers.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Runtime/Scripting/QuickJS/QuickJSApiBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public JSValue NewBridgeObject(QScriptContext context, object o, JSValue proto)
{
proxy = CreateListProxy(context, val);
}
else if (typeof(Task).IsAssignableFrom(o.GetType()) || typeof(ValueTask).IsAssignableFrom(o.GetType()))
else if (typeof(Task).IsAssignableFrom(o.GetType()))
{
proxy = CreateTaskProxy(context, val);
}
Expand Down Expand Up @@ -488,9 +488,8 @@ function asPromise() {
createTaskProxyCreator;
", "ReactUnity/quickjs/createTaskProxy");

var then = new Action<object, Action<object>, Action<object>>(
(obj, resolve, reject) => {
var task = obj is ValueTask vt ? vt.AsTask() : obj as Task;
var then = new Action<Task, Action<object>, Action<object>>(
(task, resolve, reject) => {
var awaiter = task.GetAwaiter();
awaiter.OnCompleted(() => {
if (task.IsFaulted) reject(task.Exception.InnerException);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripting/ScriptNamespaceReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ScriptNamespaceReference :
{
readonly IJavaScriptEngine _engine;
readonly Assembly[] _allowedAssemblies;
readonly ConcurrentDictionary<string, object> cache = new();
readonly ConcurrentDictionary<string, object> cache = new ConcurrentDictionary<string, object>();
readonly string _path;

private ICollection<string> keys;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Types/AssetReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected UnityWebRequest GetWebRequest(ReactContext context, AssetReferenceType
var dh = req.downloadHandler;
try
{
if (!dh.nativeData.IsCreated || (dh.isDone && dh.data == null))
if (dh.isDone && dh.data == null)
WebCache.Remove(Value);
else return req;
}
Expand Down
19 changes: 0 additions & 19 deletions Tests/Editor/Core/InteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ public IEnumerator ArrayItemsCanBeAccessedNaturally()
Globals.task3Done = true;
Assert.True(failed);
})();
(async function() {
const res = await Globals.task4;
Assert.AreEqual(7, res);
Globals.task4Done = true;
})();
", AutoRender = false)]
public IEnumerator TasksCanBeUsedNaturally()
{
Expand All @@ -213,20 +207,16 @@ public IEnumerator TasksCanBeUsedNaturally()
var t1 = new TaskCompletionSource<int>();
var t2 = new TaskCompletionSource<int>();
var t3 = new TaskCompletionSource<int>();
var t4 = new TaskCompletionSource<int>();
var valueTask = new ValueTask(t4.Task);

Globals["task0"] = t0;
Globals["task1"] = t1.Task;
Globals["task2"] = t2.Task;
Globals["task3"] = t3.Task;
Globals["task4"] = valueTask;

Globals["task0Done"] = false;
Globals["task1Done"] = false;
Globals["task2Done"] = false;
Globals["task3Done"] = false;
Globals["task4Done"] = false;

Render();

Expand All @@ -237,7 +227,6 @@ public IEnumerator TasksCanBeUsedNaturally()
Assert.False((bool) Globals["task1Done"]);
Assert.False((bool) Globals["task2Done"]);
Assert.False((bool) Globals["task3Done"]);
Assert.False((bool) Globals["task4Done"]);

t1.SetResult(0);
t1.Task.Wait();
Expand All @@ -259,14 +248,6 @@ public IEnumerator TasksCanBeUsedNaturally()
try { t3.Task.Wait(); } catch { }
yield return null;
Assert.True((bool) Globals["task3Done"]);


// Value tasks aren't supported in ClearScript

t4.SetResult(7);
t4.Task.Wait();
yield return null;
Assert.True((bool) Globals["task4Done"]);
}
}
}
Expand Down

0 comments on commit 6b051df

Please sign in to comment.