Skip to content

Commit

Permalink
Repro for issue with sending arrays into the javascript engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Whittaker authored and David Whittaker committed Sep 6, 2017
1 parent 7c86e4f commit e4d020d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
27 changes: 26 additions & 1 deletion Tests/TestEspressoCore/Tests/Test1.cs
@@ -1,7 +1,7 @@
//MIT, 2015-2017, WinterDev, EngineKit, brezza92
using System;
using Espresso;


namespace TestEspressoCore
{
public class Test1
Expand Down Expand Up @@ -95,5 +95,30 @@ static void TestCase2()
//Assert.That(result, Is.EqualTo(100));
}
}
[Test("3", "TestColl1")]
static void TestColl1()
{
#if DEBUG
JsBridge.dbugTestCallbacks();
#endif
//create js engine and context

using (JsEngine engine = new JsEngine())
using (JsContext ctx = engine.CreateContext())
{
GC.Collect();
System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
stwatch.Start();

string[] ta = { "test" };
ctx.SetVariableFromAny("ta", ta);
object result = ctx.Execute("(function(){return JSON.stringify(ta);})()");
if ((string)result != ta[0]) throw new Exception("It should return the first element");

stwatch.Stop();
Console.WriteLine("met2 managed reflection:" + stwatch.ElapsedMilliseconds.ToString());
//Assert.That(result, Is.EqualTo(100));
}
}
}
}
8 changes: 6 additions & 2 deletions src/1_Core/JsConvert.cs
Expand Up @@ -502,7 +502,11 @@ public void AnyToJsValue(object obj, ref JsValue output)
JsValue** jsarr = (JsValue**)output.Ptr;
for (int i = 0; i < arrLen; i++)
{
AnyToJsValuePtr(array[i], jsarr[i]);
//AnyToJsValuePtr(array[i], jsarr[i]);
JsValue entry = new JsValue();
AnyToJsValue(array[i], ref entry);
jsarr[i] = &entry;
_context.KeepAliveAdd(entry);
}
}
return;
Expand Down Expand Up @@ -544,7 +548,7 @@ public unsafe void AnyToJsValuePtr(object obj, JsValue* output)
//-----
Type type = obj.GetType();
// Check for nullable types (we will cast the value out of the box later).
type = type.ExtGetInnerTypeIfNullableValue();
type = type.ExtGetInnerTypeIfNullableValue() ?? type;
if (type == typeof(Boolean))
{
output->Type = JsValueType.Boolean;
Expand Down

0 comments on commit e4d020d

Please sign in to comment.