forked from microsoft/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBugFixTest.cs
2475 lines (2084 loc) · 103 KB
/
BugFixTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.ClearScript.Util;
using Microsoft.ClearScript.V8;
using Microsoft.CSharp.RuntimeBinder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Microsoft.ClearScript.Test
{
// ReSharper disable once PartialTypeWithSinglePart
[TestClass]
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Test classes use TestCleanupAttribute for deterministic teardown.")]
[SuppressMessage("ReSharper", "StringLiteralTypo", Justification = "Typos in test code are acceptable.")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Typos in test code are acceptable.")]
public partial class BugFixTest : ClearScriptTest
{
#region setup / teardown
private ScriptEngine engine;
[TestInitialize]
public void TestInitialize()
{
engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
}
[TestCleanup]
public void TestCleanup()
{
engine.Dispose();
BaseTestCleanup();
}
#endregion
#region test methods
// ReSharper disable InconsistentNaming
[TestMethod, TestCategory("BugFix")]
public void BugFix_NullArgBinding()
{
var value = 123.456 as IConvertible;
engine.AddRestrictedHostObject("value", value);
Assert.AreEqual(value.ToString(null), engine.Evaluate("value.ToString(null)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NullArgBinding_Ambiguous()
{
engine.AddHostObject("lib", new HostTypeCollection("mscorlib"));
TestUtil.AssertException<RuntimeBinderException, AmbiguousMatchException>(() => engine.Execute("lib.System.Console.WriteLine(null)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_DelegateConstructionSyntax()
{
engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
var func = (Func<int, int>)engine.Evaluate("new (System.Func(System.Int32, System.Int32))(function (x) {return x * x; })");
Assert.AreEqual(25, func(5));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_DelegateConstructionSyntax_DoubleWrap()
{
engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
engine.Execute("cb = new (System.Func(System.Int32, System.Int32))(function (x) {return x * x; })");
var func = (Func<int, int>)engine.Evaluate("new (System.Func(System.Int32, System.Int32))(cb)");
Assert.AreEqual(25, func(5));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8ScriptInterruptCrash()
{
// run the test several times to verify post-interrupt engine functionality
for (var iteration = 0; iteration < 16; iteration++)
{
var context = new PropertyBag();
engine.AddHostObject("context", context);
using (var startEvent = new ManualResetEventSlim(false))
{
context["startEvent"] = startEvent;
var interrupted = false;
var thread = new Thread(() =>
{
try
{
engine.Execute("while (true) { context.startEvent.Set(); }");
}
catch (ScriptInterruptedException)
{
interrupted = true;
}
});
thread.Start();
startEvent.Wait();
engine.Interrupt();
thread.Join();
Assert.IsTrue(interrupted);
}
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_InheritedInterfaceMethod()
{
var list = new List<int> { 123 };
var enumerator = list.AsEnumerable().GetEnumerator();
engine.AddRestrictedHostObject("enumerator", enumerator);
Assert.IsTrue((bool)engine.Evaluate("enumerator.MoveNext()"));
Assert.AreEqual(123, engine.Evaluate("enumerator.Current"));
Assert.IsFalse((bool)engine.Evaluate("enumerator.MoveNext()"));
engine.Execute("enumerator.Dispose()");
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_EnumEquality()
{
engine.AddHostObject("host", new HostFunctions());
engine.AddHostType("DayOfWeek", typeof(DayOfWeek));
engine.AddHostType("BindingFlags", typeof(BindingFlags));
Assert.IsTrue((bool)engine.Evaluate("DayOfWeek.Wednesday == DayOfWeek.Wednesday"));
Assert.IsTrue((bool)engine.Evaluate("host.flags(BindingFlags.Public, BindingFlags.Instance) == host.flags(BindingFlags.Public, BindingFlags.Instance)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_FloatParameterBinding()
{
engine.AddHostType("Convert", typeof(Convert));
engine.Script.list = new List<float>();
const float floatPi = (float)Math.PI;
engine.Execute("list.Add(Convert.ToSingle(Math.PI))");
Assert.AreEqual(floatPi, engine.Script.list[0]);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_UInt32RoundTrip()
{
engine.AddHostType("UInt32", typeof(uint));
Assert.AreEqual((long)uint.MaxValue, engine.Evaluate("UInt32.MaxValue"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AutoInt64FromDouble()
{
engine.AddHostType("Int32", typeof(int));
Assert.AreEqual((long)int.MaxValue * 123 + 1, engine.Evaluate("Int32.MaxValue * 123 + 1"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8CompiledScriptResult()
{
engine.Script.host = new HostFunctions();
using (var script = ((V8ScriptEngine)engine).Compile("host"))
{
Assert.IsInstanceOfType(((V8ScriptEngine)engine).Evaluate(script), typeof(HostFunctions));
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_GenericDelegateConstructorWithArgument()
{
engine.AddHostType("Func", "System.Func");
engine.AddHostType("StringT", typeof(string));
engine.AddHostType("IntT", typeof(int));
var func = (Func<string, int>)engine.Evaluate("new Func(StringT, IntT, function (s) { return s.length; })");
const string testString = "floccinaucinihilipilification";
Assert.AreEqual(testString.Length, func(testString));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_HostMethodAsArgument()
{
var testObject = new TestObject();
engine.Script.testObject = testObject;
engine.Script.expando = new ExpandoObject();
engine.AddHostType("DateTime", typeof(DateTime));
engine.Execute("expando.method = testObject.Method");
Assert.AreEqual(testObject.Method("foo", 123), engine.Evaluate("expando.method('foo', 123)"));
Assert.AreEqual(testObject.Method<DateTime>(456), engine.Evaluate("expando.method(DateTime, 456)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_HostIndexedPropertyAsArgument()
{
var testObject = new TestObject();
engine.Script.testObject = testObject;
engine.Script.expando = new ExpandoObject();
engine.Execute("expando.property = testObject.Item");
Assert.AreEqual("foo", engine.Evaluate("expando.property.set(123, 'foo')"));
Assert.AreEqual("foo", engine.Evaluate("expando.property.get(123)"));
Assert.AreEqual("foo", engine.Evaluate("expando.property(123)"));
Assert.AreEqual(456, engine.Evaluate("expando.property.set('bar', 456)"));
Assert.AreEqual(456, engine.Evaluate("expando.property.get('bar')"));
Assert.AreEqual(456, engine.Evaluate("expando.property('bar')"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Nullable_Field()
{
engine.Script.test = new NullableTest();
Assert.IsNull(engine.Evaluate("test.Field"));
Assert.IsTrue((bool)engine.Evaluate("test.Field === null"));
engine.Execute("test.Field = 123");
Assert.AreEqual(123, engine.Evaluate("test.Field"));
Assert.IsTrue((bool)engine.Evaluate("test.Field === 123"));
engine.Execute("test.Field = null");
Assert.IsNull(engine.Evaluate("test.Field"));
Assert.IsTrue((bool)engine.Evaluate("test.Field === null"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Nullable_Property()
{
engine.Script.test = new NullableTest();
Assert.IsNull(engine.Evaluate("test.Property"));
Assert.IsTrue((bool)engine.Evaluate("test.Property === null"));
engine.Execute("test.Property = 123");
Assert.AreEqual(123, engine.Evaluate("test.Property"));
Assert.IsTrue((bool)engine.Evaluate("test.Property === 123"));
engine.Execute("test.Property = null");
Assert.IsNull(engine.Evaluate("test.Property"));
Assert.IsTrue((bool)engine.Evaluate("test.Property === null"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Nullable_ArgBinding()
{
var test = new NullableTest();
engine.Script.test = test;
Assert.IsNull(engine.Evaluate("test.Method(null)"));
Assert.AreEqual(test.Method(5), engine.Evaluate("test.Method(5)"));
Assert.AreEqual(test.Method(5.1), engine.Evaluate("test.Method(5.1)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_GlobalObjectCrash()
{
engine.AddHostObject("random", HostItemFlags.GlobalMembers, new Random());
Assert.AreEqual("[object Object]", engine.ExecuteCommand("this"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_VBDynamicArgMarshaling_Numeric()
{
var result = TestUtil.InvokeVBTestFunction(@"
Using engine As New V8ScriptEngine
engine.Execute(""data = [5, 4, 'qux', 2, 1]; function getElement(i1, i2, i3) { return data[i1 + i2 - i3]; }"")
TestFunction = engine.Script.getElement(CShort(1), CLng(99), CStr(98))
End Using
");
Assert.AreEqual("qux", result);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_VBDynamicArgMarshaling_String()
{
var result = TestUtil.InvokeVBTestFunction(@"
Using engine As New V8ScriptEngine
engine.Execute(""data = { foo26: 123, bar97: 456.789 }; function getElement(i1, i2) { return data[i1 + i2]; }"")
TestFunction = engine.Script.getElement(""bar"", CLng(97))
End Using
");
Assert.AreEqual(456.789, result);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AmbiguousAttribute()
{
engine.Script.foo = new AmbiguousAttributeTest();
engine.Execute("foo.Foo()");
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_CoreBindCache()
{
HostItem.ClearCoreBindCache();
engine.Dispose();
for (var i = 0; i < 10; i++)
{
using (engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging))
{
engine.Script.host = new HostFunctions();
Assert.AreEqual(' ', engine.Evaluate("host.toChar(32)"));
Assert.AreEqual('A', engine.Evaluate("host.toChar(65)"));
Assert.AreEqual(0.0F, engine.Evaluate("host.toSingle(0)"));
Assert.AreEqual(1.0F, engine.Evaluate("host.toSingle(1)"));
Assert.AreEqual(123.0F, engine.Evaluate("host.toSingle(123)"));
}
}
Assert.AreEqual(3L, HostItem.GetCoreBindCount());
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_StringWithNullChar()
{
const string value = "abc\0def";
const string value2 = "ghi\0jkl";
dynamic func = engine.Evaluate("(function (x) { return x.length; }).valueOf()");
Assert.AreEqual(value.Length, func(value));
Assert.AreEqual(value, engine.Evaluate(@"'abc\0def'"));
dynamic obj = engine.Evaluate(@"({ 'abc\0def': 'ghi\0jkl' })");
Assert.IsTrue(((DynamicObject)obj).GetDynamicMemberNames().Contains(value));
Assert.AreEqual(value2, obj[value]);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8ScriptItemWeakBinding()
{
// This test verifies that V8 script items no longer prevent their isolates from being
// destroyed. Previously it exhausted address space and crashed in 32-bit mode.
for (var i = 0; i < 128; i++)
{
using (var tempEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging))
{
tempEngine.Evaluate("(function () {}).valueOf()");
}
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8ScriptItemDispose()
{
dynamic item1;
using (var tempEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging))
{
item1 = tempEngine.Evaluate("(function () { return 123; }).valueOf()");
Assert.AreEqual(123, item1());
dynamic item2 = tempEngine.Evaluate("(function () { return 456; }).valueOf()");
using (item2 as IDisposable)
{
Assert.AreEqual(456, item2());
}
}
using (item1 as IDisposable)
{
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8CompiledScriptWeakBinding()
{
// This test verifies that V8 compiled scripts no longer prevent their isolates from
// being destroyed. Previously it exhausted address space and crashed in 32-bit mode.
for (var i = 0; i < 128; i++)
{
using (var tempEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging))
{
tempEngine.Compile("(function () {}).valueOf()");
}
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8CompiledScriptDispose()
{
V8Script script1;
using (var tempEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging))
{
script1 = tempEngine.Compile("(function () { return 123; })()");
Assert.AreEqual(123, tempEngine.Evaluate(script1));
V8Script script2 = tempEngine.Compile("(function () { return 456; })()");
using (script2)
{
Assert.AreEqual(456, tempEngine.Evaluate(script2));
}
}
using (script1)
{
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8ArrayBufferAllocator()
{
engine.Execute("buffer = new ArrayBuffer(12345)");
Assert.AreEqual(12345, engine.Script.buffer.byteLength);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8CachedObjectLeak()
{
WeakReference wr = null;
new Action(() =>
{
// ReSharper disable RedundantAssignment
object x = null;
using (var tempEngine = new V8ScriptEngine())
{
tempEngine.AddHostType("Action", typeof(Action));
x = tempEngine.Evaluate("action = new Action(function () {})");
wr = new WeakReference(tempEngine);
}
Assert.IsInstanceOfType(x, typeof(Action));
TestUtil.AssertException<ObjectDisposedException>((Action)x);
x = null;
// ReSharper restore RedundantAssignment
})();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
Assert.IsFalse(wr.IsAlive);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Resurrection_V8ScriptEngine()
{
for (var index = 0; index < 256; index++)
{
// ReSharper disable UnusedVariable
var wrapper = new ResurrectionTestWrapper(new V8ScriptEngine());
GC.Collect();
// ReSharper restore UnusedVariable
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Resurrection_V8Runtime()
{
for (var index = 0; index < 256; index++)
{
// ReSharper disable UnusedVariable
var wrapper = new ResurrectionTestWrapper(new V8Runtime());
GC.Collect();
// ReSharper restore UnusedVariable
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Resurrection_V8Script()
{
for (var index = 0; index < 256; index++)
{
// ReSharper disable UnusedVariable
var tempEngine = new V8ScriptEngine();
var wrapper = new ResurrectionTestWrapper(tempEngine.Compile("function foo() {}"));
GC.Collect();
// ReSharper restore UnusedVariable
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_Resurrection_V8ScriptItem()
{
TestV8ScriptItemResurrection();
GC.Collect();
GC.WaitForPendingFinalizers();
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8GlobalMembers_ReadOnlyPropertyCrash()
{
// this test is for a crash that occurred only on debug V8 builds
engine.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
engine.AddHostObject("test", HostItemFlags.GlobalMembers, new { foo = 123 });
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute("foo = 456"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8GlobalMembers_ReadOnlyPropertyCrash_Index()
{
// this test is for a crash that occurred only on debug V8 builds
engine.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
engine.AddHostObject("test", HostItemFlags.GlobalMembers, new ReadOnlyCollection<int>(new[] { 5, 4, 3, 2, 1 }));
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute("this[2] = 123"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8GlobalMembers_NativeFunctionHiding()
{
engine.Execute("function toString() { return 'ABC'; }");
engine.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
Assert.AreEqual("ABC", engine.Evaluate("toString()"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_CallHostObjectFunctionAsConstructor()
{
engine.Script.random = new Random();
engine.AddHostType("Random", typeof(Random));
var result = engine.Evaluate(@"
(function () {
var x = new Random().NextDouble();
try {
return new random.constructor();
}
catch (ex) {
return new Random().NextDouble() * x;
}
return false;
})()
");
Assert.IsInstanceOfType(result, typeof(double));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_HostItemCachingForHostVariables()
{
var foo = new HostFunctions().newVar(new object());
engine.Script.foo1 = foo;
engine.Script.foo2 = foo;
Assert.IsTrue(Convert.ToBoolean(engine.Evaluate("foo1 === foo2")));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_MetaScriptItem_GetDynamicMemberNames()
{
var dmop = (IDynamicMetaObjectProvider)engine.Evaluate("({ foo: 123, bar: 456, baz: 789 })");
var dmo = dmop.GetMetaObject(Expression.Constant(dmop));
var names = dmo.GetDynamicMemberNames().ToArray();
Assert.IsTrue(names.Contains("foo"));
Assert.IsTrue(names.Contains("bar"));
Assert.IsTrue(names.Contains("baz"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AmbiguousIndexer()
{
IAmbiguousIndexer indexer = new AmbiguousIndexer();
engine.AddRestrictedHostObject("indexer", indexer);
engine.AddHostType("DayOfWeek", typeof(DayOfWeek));
engine.Execute("indexer.Item.set(123, 456)");
Assert.AreEqual(456, engine.Evaluate("indexer.Item(123)"));
Assert.IsNull(engine.Evaluate("indexer.Item(789)"));
engine.Execute("indexer.Item.set(DayOfWeek.Thursday, DayOfWeek.Sunday)");
Assert.AreEqual(DayOfWeek.Sunday, engine.Evaluate("indexer.Item(DayOfWeek.Thursday)"));
Assert.IsNull(engine.Evaluate("indexer.Item(DayOfWeek.Tuesday)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AmbiguousIndexer_ImplicitConversion()
{
IAmbiguousIndexer indexer = new AmbiguousIndexer();
engine.AddRestrictedHostObject("indexer", indexer);
engine.AddHostType("DayOfWeek", typeof(MyDayOfWeek));
engine.Execute("indexer.Item.set(123, 456)");
Assert.AreEqual(456, engine.Evaluate("indexer.Item(123)"));
Assert.IsNull(engine.Evaluate("indexer.Item(789)"));
engine.Execute("indexer.Item.set(DayOfWeek.Thursday, DayOfWeek.Sunday)");
Assert.AreEqual(MyDayOfWeek.Sunday, engine.Evaluate("indexer.Item(DayOfWeek.Thursday)"));
Assert.IsNull(engine.Evaluate("indexer.Item(DayOfWeek.Tuesday)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AmbiguousIndexer_ImplicitConversion_Nullable()
{
IAmbiguousIndexer2 indexer = new AmbiguousIndexer();
engine.AddRestrictedHostObject("indexer", indexer);
engine.AddHostType("DayOfWeek", typeof(MyDayOfWeek));
engine.Execute("indexer.Item.set(123, 456)");
Assert.AreEqual(456, engine.Evaluate("indexer.Item(123)"));
Assert.IsNull(engine.Evaluate("indexer.Item(789)"));
engine.Execute("indexer.Item.set(DayOfWeek.Thursday, DayOfWeek.Sunday)");
Assert.AreEqual(MyDayOfWeek.Sunday, engine.Evaluate("indexer.Item(DayOfWeek.Thursday)"));
Assert.IsNull(engine.Evaluate("indexer.Item(DayOfWeek.Tuesday)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_InaccessiblePropertyAccessors()
{
engine.Script.foo = new InaccessiblePropertyAccessors();
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.NoGetter"));
Assert.AreEqual(123, engine.Evaluate("foo.NoGetter = 123"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.PrivateGetter"));
Assert.AreEqual(456, engine.Evaluate("foo.PrivateGetter = 456"));
Assert.AreEqual(456, engine.Evaluate("foo.NoSetter"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.NoSetter = 789"));
Assert.AreEqual(456, engine.Evaluate("foo.PrivateSetter"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.PrivateSetter = 789"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_InaccessiblePropertyAccessors_Static()
{
engine.AddHostType("foo", typeof(InaccessiblePropertyAccessorsStatic));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.NoGetter"));
Assert.AreEqual(123, engine.Evaluate("foo.NoGetter = 123"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.PrivateGetter"));
Assert.AreEqual(456, engine.Evaluate("foo.PrivateGetter = 456"));
Assert.AreEqual(456, engine.Evaluate("foo.NoSetter"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.NoSetter = 789"));
Assert.AreEqual(456, engine.Evaluate("foo.PrivateSetter"));
TestUtil.AssertException<UnauthorizedAccessException>(() => engine.Evaluate("foo.PrivateSetter = 789"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_V8RuntimeConstraintScale()
{
const int maxNewSpaceSize = 16;
const int maxOldSpaceSize = 512;
const double tolerance = .05;
var constraints = new V8RuntimeConstraints
{
MaxNewSpaceSize = maxNewSpaceSize,
MaxOldSpaceSize = maxOldSpaceSize
};
using (var tempEngine = new V8ScriptEngine(constraints))
{
Assert.AreEqual(Math.PI, tempEngine.Evaluate("Math.PI"));
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
var ratio = actual / expected;
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
}
constraints = new V8RuntimeConstraints
{
MaxNewSpaceSize = maxNewSpaceSize * 1024 * 1024,
MaxOldSpaceSize = maxOldSpaceSize * 1024 * 1024
};
using (var tempEngine = new V8ScriptEngine(constraints))
{
Assert.AreEqual(Math.E, tempEngine.Evaluate("Math.E"));
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
var ratio = actual / expected;
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_AssemblyHelpersClass()
{
Assert.IsTrue(typeof(AssemblyHelpers).IsStatic());
Assert.IsNull(typeof(AssemblyHelpers).TypeInitializer);
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_FinalizerHang_V8ScriptItem()
{
engine.Script.foo = new Action<object>(_ => {});
engine.Script.bar = new Action(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
});
engine.Execute(@"
for (var i = 0; i < 100; i++) {
foo({ index: i });
}
bar();
");
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_FinalizerHang_V8Script()
{
engine.Script.bar = new Action(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
});
for (var index = 0; index < 100; index++)
{
((V8ScriptEngine)engine).Compile("function foo() { return " + index + "; }");
}
engine.Execute("bar()");
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_FinalizerHang_V8ScriptEngine()
{
engine.Dispose();
using (var runtime = new V8Runtime(V8RuntimeFlags.EnableDebugging))
{
engine = runtime.CreateScriptEngine();
engine.Script.bar = new Action(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
});
for (var index = 0; index < 100; index++)
{
runtime.CreateScriptEngine();
}
engine.Execute("bar()");
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_DynamicMethodArgs()
{
engine.Script.foo = new DynamicMethodArgTest();
Assert.AreEqual("123 456.789 hello", engine.Evaluate("foo.RunTest(123, 456.789, 'hello')"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NestedInterrupt()
{
var context = new PropertyBag();
engine.AddHostObject("context", context);
using (var startEvent = new ManualResetEventSlim(false))
{
object result = null;
var interruptedInner = false;
var interruptedOuter = false;
context["startEvent"] = startEvent;
context["foo"] = new Action(() =>
{
try
{
engine.Execute("while (true) { context.startEvent.Set(); }");
}
catch (ScriptInterruptedException)
{
interruptedInner = true;
}
});
var thread = new Thread(() =>
{
try
{
result = engine.Evaluate("context.foo(); 123");
}
catch (ScriptInterruptedException)
{
interruptedOuter = true;
}
});
thread.Start();
startEvent.Wait();
engine.Interrupt();
thread.Join();
Assert.IsTrue(interruptedInner);
Assert.IsFalse(interruptedOuter);
Assert.AreEqual(123, result);
}
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NumericArgConversion_Delegate()
{
engine.Script.host = new HostFunctions();
engine.Script.sbyteFunc = new Func<sbyte, sbyte>(arg => arg);
engine.Script.nullableSByteFunc = new Func<sbyte?, sbyte?>(arg => arg);
engine.Script.floatFunc = new Func<float, float>(arg => arg);
engine.Script.nullableFloatFunc = new Func<float?, float?>(arg => arg);
engine.Script.doubleFunc = new Func<double, double>(arg => arg);
engine.Script.nullableDoubleFunc = new Func<double?, double?>(arg => arg);
engine.Script.decimalFunc = new Func<decimal, decimal>(arg => arg);
engine.Script.nullableDecimalFunc = new Func<decimal?, decimal?>(arg => arg);
Assert.AreEqual(123, engine.Evaluate("sbyteFunc(123)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("sbyteFunc(234)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("sbyteFunc(123.5)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("sbyteFunc(Math.PI)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("sbyteFunc(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("nullableSByteFunc(123)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("nullableSByteFunc(234)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("nullableSByteFunc(123.5)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("nullableSByteFunc(Math.PI)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("nullableSByteFunc(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("nullableSByteFunc(null)"));
Assert.AreEqual(123, engine.Evaluate("floatFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("floatFunc(123.5)"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("floatFunc(Math.PI)"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("floatFunc(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("nullableFloatFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("nullableFloatFunc(123.5)"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("nullableFloatFunc(Math.PI)"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("nullableFloatFunc(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("nullableFloatFunc(null)"));
Assert.AreEqual(123, engine.Evaluate("doubleFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("doubleFunc(123.5)"));
Assert.AreEqual(Math.PI, engine.Evaluate("doubleFunc(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("doubleFunc(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("nullableDoubleFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("nullableDoubleFunc(123.5)"));
Assert.AreEqual(Math.PI, engine.Evaluate("nullableDoubleFunc(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("nullableDoubleFunc(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("nullableDoubleFunc(null)"));
Assert.AreEqual(123, engine.Evaluate("decimalFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("decimalFunc(123.5)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("decimalFunc(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("decimalFunc(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("nullableDecimalFunc(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("nullableDecimalFunc(123.5)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("nullableDecimalFunc(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("nullableDecimalFunc(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("nullableDecimalFunc(null)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NumericArgConversion_Field()
{
engine.Script.host = new HostFunctions();
engine.Script.test = new NumericArgConversionTest();
Assert.AreEqual(123, engine.Evaluate("test.SByteField = 123; test.SByteField"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteField = 234"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteField = 123.5"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteField = Math.PI"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteField = host.toDecimal(Math.PI)"));
Assert.AreEqual(123, engine.Evaluate("test.NullableSByteField = 123; test.NullableSByteField"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteField = 234"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteField = 123.5"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteField = Math.PI"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteField = host.toDecimal(Math.PI)"));
Assert.IsNull(engine.Evaluate("test.NullableSByteField = null; test.NullableSByteField"));
Assert.AreEqual(123, engine.Evaluate("test.FloatField = 123; test.FloatField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.FloatField = 123.5; test.FloatField"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.FloatField = Math.PI; test.FloatField"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.FloatField = host.toDecimal(Math.PI); test.FloatField"));
Assert.AreEqual(123, engine.Evaluate("test.NullableFloatField = 123; test.NullableFloatField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableFloatField = 123.5; test.NullableFloatField"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.NullableFloatField = Math.PI; test.NullableFloatField"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.NullableFloatField = host.toDecimal(Math.PI); test.NullableFloatField"));
Assert.IsNull(engine.Evaluate("test.NullableFloatField = null; test.NullableFloatField"));
Assert.AreEqual(123, engine.Evaluate("test.DoubleField = 123; test.DoubleField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.DoubleField = 123.5; test.DoubleField"));
Assert.AreEqual(Math.PI, engine.Evaluate("test.DoubleField = Math.PI; test.DoubleField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.DoubleField = host.toDecimal(Math.PI); test.DoubleField"));
Assert.AreEqual(123, engine.Evaluate("test.NullableDoubleField = 123; test.NullableDoubleField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableDoubleField = 123.5; test.NullableDoubleField"));
Assert.AreEqual(Math.PI, engine.Evaluate("test.NullableDoubleField = Math.PI; test.NullableDoubleField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.NullableDoubleField = host.toDecimal(Math.PI); test.NullableDoubleField"));
Assert.IsNull(engine.Evaluate("test.NullableDoubleField = null; test.NullableDoubleField"));
Assert.AreEqual(123, engine.Evaluate("test.DecimalField = 123; test.DecimalField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.DecimalField = 123.5; test.DecimalField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.DecimalField = Math.PI; test.DecimalField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.DecimalField = host.toDecimal(Math.PI); test.DecimalField"));
Assert.AreEqual(123, engine.Evaluate("test.NullableDecimalField = 123; test.NullableDecimalField"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableDecimalField = 123.5; test.NullableDecimalField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.NullableDecimalField = Math.PI; test.NullableDecimalField"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.NullableDecimalField = host.toDecimal(Math.PI); test.NullableDecimalField"));
Assert.IsNull(engine.Evaluate("test.NullableDecimalField = null; test.NullableDecimalField"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NumericArgConversion_Method()
{
engine.Script.host = new HostFunctions();
engine.Script.test = new NumericArgConversionTest();
Assert.AreEqual(123, engine.Evaluate("test.SByteMethod(123)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteMethod(234)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.SByteMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.SByteMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.SByteMethod(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("test.NullableSByteMethod(123)"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteMethod(234)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableSByteMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableSByteMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableSByteMethod(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("test.NullableSByteMethod(null)"));
Assert.AreEqual(123, engine.Evaluate("test.FloatMethod(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("test.FloatMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.FloatMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.FloatMethod(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("test.NullableFloatMethod(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableFloatMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableFloatMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableFloatMethod(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("test.NullableFloatMethod(null)"));
Assert.AreEqual(123, engine.Evaluate("test.DoubleMethod(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("test.DoubleMethod(123.5)"));
Assert.AreEqual(Math.PI, engine.Evaluate("test.DoubleMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.DoubleMethod(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("test.NullableDoubleMethod(123)"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableDoubleMethod(123.5)"));
Assert.AreEqual(Math.PI, engine.Evaluate("test.NullableDoubleMethod(Math.PI)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableDoubleMethod(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("test.NullableDoubleMethod(null)"));
Assert.AreEqual(123, engine.Evaluate("test.DecimalMethod(123)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.DecimalMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.DecimalMethod(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.DecimalMethod(host.toDecimal(Math.PI))"));
Assert.AreEqual(123, engine.Evaluate("test.NullableDecimalMethod(123)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableDecimalMethod(123.5)"));
TestUtil.AssertMethodBindException(() => engine.Execute("test.NullableDecimalMethod(Math.PI)"));
Assert.AreEqual((double)(decimal)Math.PI, engine.Evaluate("test.NullableDecimalMethod(host.toDecimal(Math.PI))"));
Assert.IsNull(engine.Evaluate("test.NullableDecimalMethod(null)"));
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_NumericArgConversion_Property()
{
engine.Script.host = new HostFunctions();
engine.Script.test = new NumericArgConversionTest();
Assert.AreEqual(123, engine.Evaluate("test.SByteProperty = 123; test.SByteProperty"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteProperty = 234"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteProperty = 123.5"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteProperty = Math.PI"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.SByteProperty = host.toDecimal(Math.PI)"));
Assert.AreEqual(123, engine.Evaluate("test.NullableSByteProperty = 123; test.NullableSByteProperty"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteProperty = 234"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteProperty = 123.5"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteProperty = Math.PI"));
TestUtil.AssertException<ArgumentException>(() => engine.Execute("test.NullableSByteProperty = host.toDecimal(Math.PI)"));
Assert.IsNull(engine.Evaluate("test.NullableSByteProperty = null; test.NullableSByteProperty"));
Assert.AreEqual(123, engine.Evaluate("test.FloatProperty = 123; test.FloatProperty"));
Assert.AreEqual(123.5f, engine.Evaluate("test.FloatProperty = 123.5; test.FloatProperty"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.FloatProperty = Math.PI; test.FloatProperty"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.FloatProperty = host.toDecimal(Math.PI); test.FloatProperty"));
Assert.AreEqual(123, engine.Evaluate("test.NullableFloatProperty = 123; test.NullableFloatProperty"));
Assert.AreEqual(123.5f, engine.Evaluate("test.NullableFloatProperty = 123.5; test.NullableFloatProperty"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.NullableFloatProperty = Math.PI; test.NullableFloatProperty"));
Assert.AreEqual((float)Math.PI, engine.Evaluate("test.NullableFloatProperty = host.toDecimal(Math.PI); test.NullableFloatProperty"));
Assert.IsNull(engine.Evaluate("test.NullableFloatProperty = null; test.NullableFloatProperty"));
Assert.AreEqual(123, engine.Evaluate("test.DoubleProperty = 123; test.DoubleProperty"));