From 30a68e2b6c76ce58d3c58dae0b426bfe46e1a20e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Apr 2014 17:12:02 +0200 Subject: [PATCH 01/16] Initial Commit --- + | 692 ++++++++++++++++++++++++++++++++++++ JSIL/AssemblyTranslator.cs | 4 +- JSIL/JavascriptFormatter.cs | 2 +- Libraries/JSIL.Bootstrap.js | 115 ++++-- Libraries/JSIL.Core.js | 36 +- Libraries/JSIL.js | 2 +- Proxies/Activator.cs | 44 +++ Proxies/Array.cs | 7 + Proxies/Collections.cs | 34 +- Proxies/Encoding.cs | 132 +++++++ Proxies/Enum.cs | 64 ++++ Proxies/EventInfo.cs | 60 ++++ Proxies/IO.cs | 20 ++ Proxies/Math.cs | 22 ++ Proxies/MonoProxy.cs | 10 + Proxies/Object.cs | 7 +- Proxies/Proxies.4.0.csproj | 5 + Proxies/String.cs | 65 ++++ 18 files changed, 1261 insertions(+), 60 deletions(-) create mode 100644 + create mode 100644 Proxies/Activator.cs create mode 100644 Proxies/Encoding.cs create mode 100644 Proxies/Enum.cs create mode 100644 Proxies/EventInfo.cs create mode 100644 Proxies/MonoProxy.cs diff --git a/+ b/+ new file mode 100644 index 000000000..1342f5b28 --- /dev/null +++ b/+ @@ -0,0 +1,692 @@ +diff --git a/JSIL/AssemblyTranslator.cs b/JSIL/AssemblyTranslator.cs +index 2e0670d..aea7162 100644 +--- a/JSIL/AssemblyTranslator.cs ++++ b/JSIL/AssemblyTranslator.cs +@@ -2687,7 +2687,9 @@ namespace JSIL { + output.Identifier("Overrides"); + output.LPar(); + +- var interfaceIndex = typeInfo.AllInterfacesRecursive.TakeWhile( ++ var interfaces = typeInfo.AllInterfacesRecursive.Where((tuple) => (tuple.Item1 == typeInfo && !tuple.Item2.IsIgnored)); ++ ++ var interfaceIndex = interfaces.TakeWhile( + (tuple) => !TypeUtil.TypesAreEqual(tuple.Item3, @override.InterfaceType) + ).Count(); + +diff --git a/JSIL/JavascriptFormatter.cs b/JSIL/JavascriptFormatter.cs +index 0671c79..bb5a4a2 100644 +--- a/JSIL/JavascriptFormatter.cs ++++ b/JSIL/JavascriptFormatter.cs +@@ -159,6 +159,7 @@ namespace JSIL.Internal { + Configuration configuration, bool stubbed + ) { + Output = output; ++ //Output = Console.Out; + TypeInfo = typeInfo; + Manifest = manifest; + Assembly = assembly; +@@ -459,7 +460,6 @@ namespace JSIL.Internal { + protected void TypeReferenceInternal (GenericParameter gp, TypeReferenceContext context) { + var ownerType = gp.Owner as TypeReference; + var ownerMethod = gp.Owner as MethodReference; +- + if (context != null) { + if (ownerType != null) { + if (TypeUtil.TypesAreAssignable(TypeInfo, ownerType, context.SignatureMethodType)) { +diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js +index b3d6e3a..f3efd96 100644 +--- a/Libraries/JSIL.Bootstrap.js ++++ b/Libraries/JSIL.Bootstrap.js +@@ -1379,7 +1379,7 @@ $jsilcore.$ListExternals = function ($, T, type) { + ); + }; + +-JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { ++/*JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); + + $jsilcore.$ListExternals($, T, "List"); +@@ -1402,7 +1402,7 @@ JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { + } + ); + +-}); ++});*/ + + $jsilcore.$ArrayListExternals = function ($) { + $jsilcore.$ListExternals($, $.Object, "ArrayList"); +@@ -2221,8 +2221,55 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) + } + ); + ++ /*$.Method({ Static: false, Public: false }, "CopyTo", ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), ++ Dictionary$b2_CopyTo ++ ); ++ ++ $.Method({ Static: false, Public: false }, "CopyToCheck", ++ new JSIL.MethodSignature(null, [$asm02.TypeRef("System.Array"), $asm02.TypeRef("System.Int32")], []), ++ Dictionary$b2_CopyToCheck ++ ); ++ ++ $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.Generic.ICollection$lSystem.Collections.Generic.KeyValuePair$lTKey$cmTValue$g$g.CopyTo", ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), ++ Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_CopyTo ++ ) ++.Overrides(1, "CopyTo"); ++ ++ function Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_Contains(keyValuePair) { ++ return $thisType.Of($thisType.TKey.get(this), $thisType.TValue.get(this)).prototype.ContainsKeyValuePair.call(this, keyValuePair); ++ }; ++ ++ function Dictionary$b2_CopyTo(array, index) { ++ var $temp00; ++ ++ for (var i = 0; i < this.touchedSlots; i = ((i + 1) | 0)) { ++ if ((this.linkSlots[i].HashCode & -2147483648) !== 0) { ++ array[($temp00 = index, ++ index = ((index + 1) | 0), ++ $temp00)] = new ($asm02.System.Collections.Generic.KeyValuePair$b2.Of($thisType.TKey.get(this), $thisType.TValue.get(this)))(JSIL.CloneParameter($thisType.TKey.get(this), this.keySlots[i]), JSIL.CloneParameter($thisType.TValue.get(this), this.valueSlots[i])); ++ } ++ } ++ }; ++ ++ function Dictionary$b2_CopyToCheck(array, index) { ++ if (array === null) { ++ throw $S00().Construct("array"); ++ } ++ if (index < 0) { ++ throw $S02().Construct("index"); ++ } ++ if (index > array.length) { ++ throw $S01().Construct("index larger than largest valid index of array"); ++ } ++ if (((array.length - index) | 0) < this.get_Count()) { ++ throw $S01().Construct("Destination array cannot hold the requested elements!"); ++ } ++ };*/ ++ + $.Method({Static:false, Public:true }, "get_Keys", +- (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), ++ (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Keys () { + if (this.tKeyCollection === null) { + this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; +@@ -2234,7 +2281,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) + ); + + $.Method({Static:false, Public:true }, "get_Values", +- (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), ++ (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Values () { + if (this.tValueCollection === null) { + this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; +@@ -2246,7 +2293,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) + ); + + $.Method({Static:false, Public:true }, "GetEnumerator", +- (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), ++ (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function GetEnumerator () { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; +@@ -2316,11 +2363,11 @@ JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($ + + }); + +-JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", function ($interfaceBuilder) { ++JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.Method({Static:false, Public:true }, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection")])], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), + function _ctor (dictionary) { + this.dictionary = dictionary; + } +@@ -2334,7 +2381,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", + ); + + $.Method({Static:false, Public:true }, "GetEnumerator", +- new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection")]), [], []), ++ new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), + function GetEnumerator () { + return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + } +@@ -2349,11 +2396,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", + .Overrides(3, "GetEnumerator"); + }); + +-JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection", function ($interfaceBuilder) { ++JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.Method({Static:false, Public:true }, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection")])], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), + function _ctor (dictionary) { + this.dictionary = dictionary; + } +@@ -2367,7 +2414,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection + ); + + $.Method({Static:false, Public:true }, "GetEnumerator", +- new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection")]), [], []), ++ new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), + function GetEnumerator () { + return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); + } +@@ -2382,11 +2429,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection + .Overrides(3, "GetEnumerator"); + }); + +-JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", function ($interfaceBuilder) { ++JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.Method({Static:false, Public:false}, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator")])], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), + function _ctor (dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; +@@ -2413,7 +2460,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/E + ); + + $.Method({Static:false, Public:true , Virtual:true }, "get_Current", +- new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator"), [], []), ++ new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), + function get_Current () { + return this.kvpEnumerator.get_Current().key; + } +@@ -2443,11 +2490,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/E + .Overrides(2, "Reset"); + }); + +-JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", function ($interfaceBuilder) { ++JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.Method({Static:false, Public:false}, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator")])], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), + function _ctor (dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; +@@ -2474,7 +2521,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection + ); + + $.Method({Static:false, Public:true , Virtual:true }, "get_Current", +- new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator"), [], []), ++ new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), + function get_Current () { + return this.kvpEnumerator.get_Current().value; + } +@@ -2525,9 +2572,9 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, + ); + }); + +-JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2/Enumerator", false, ["TKey", "TValue"], function ($) { ++JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2+Enumerator", false, ["TKey", "TValue"], function ($) { + $.ImplementInterfaces( +- /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")])]), ++ /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), + /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") +@@ -2536,7 +2583,7 @@ JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Gener + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.Object"), +- Name: "System.Collections.Generic.Dictionary`2/KeyCollection", ++ Name: "System.Collections.Generic.Dictionary`2+KeyCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], +@@ -2546,7 +2593,7 @@ JSIL.MakeType({ + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.Object"), +- Name: "System.Collections.Generic.Dictionary`2/ValueCollection", ++ Name: "System.Collections.Generic.Dictionary`2+ValueCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], +@@ -2556,7 +2603,7 @@ JSIL.MakeType({ + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.ValueType"), +- Name: "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", ++ Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], +@@ -2566,7 +2613,7 @@ JSIL.MakeType({ + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.ValueType"), +- Name: "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", ++ Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], +@@ -2574,7 +2621,7 @@ JSIL.MakeType({ + }, function ($) { + }); + +-JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", function ($interfaceBuilder) { ++JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.RawMethod(false, "__CopyMembers__", +@@ -2585,7 +2632,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu + ); + + $.Method({Static:false, Public:false}, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")])], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), + function _ctor (dictionary) { + this.dictionary = dictionary; + +@@ -2605,7 +2652,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu + ); + + $.Method({Static:false, Public:false}, ".ctor", +- new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")]), $.Int32], []), ++ new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), + function _ctor (dictionary, getEnumeratorRetType) { + throw new Error('Not implemented'); + } +@@ -2620,7 +2667,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu + ); + + $.Method({Static:false, Public:true , Virtual:true }, "get_Current", +- new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")]), [], []), ++ new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), + function get_Current () { + return this.state.current.MemberwiseClone(); + } +@@ -4750,6 +4797,20 @@ JSIL.ImplementExternals("System.Array", function ($) { + } + ); + ++ $.Method({ Static: true, Public: true }, "Sort", ++ (new JSIL.MethodSignature(null, [ ++ $jsilcore.TypeRef("System.Array", ["!!0"]), ++ $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), ++ function Sort(type, array, comparer) { ++ var tComparer = System.Collections.Generic.IComparer$b1.Of(type); ++ var compare = tComparer.Compare; ++ ++ Array.prototype.sort.call(array, function (lhs, rhs) { ++ return compare.Call(comparer, null, lhs, rhs); ++ }); ++ } ++); ++ + $.Method({Static:true , Public:true }, "Copy", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array"), $.Int32, +diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js +index 8d5d108..a3d007a 100644 +--- a/Libraries/JSIL.Core.js ++++ b/Libraries/JSIL.Core.js +@@ -6825,7 +6825,7 @@ JSIL.InterfaceMethod.prototype.Rebind = function (newTypeObject, newSignature) { + + JSIL.InterfaceMethod.prototype.GetVariantInvocationCandidates = function (thisReference) { + var cache = this.variantInvocationCandidateCache; +- var typeId = thisReference.__TypeId__; ++ var typeId = thisReference.__ThisTypeId__; + + var result = cache[typeId]; + +@@ -6859,7 +6859,7 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { + } + + if (!result) +- result = this.fallbackMethod; ++ result = this.fallbackMethod ? this.fallbackMethod(this.typeObject) : null; + + if (!result) { + var errorString = "Method '" + this.signature.toString(this.methodName) + "' of interface '" + +@@ -7883,14 +7883,21 @@ JSIL.GetEqualsSignature = function () { + return JSIL.$equalsSignature; + } + ++JSIL.ObjectEqualsStaticHelper = function (lhs, rhs) { ++ if (lhs["Object_Equals"] != null) ++ return lhs["Object_Equals"](rhs); ++ return JSIL.ObjectEquals(lhs, rhs); ++} ++ + JSIL.ObjectEquals = function (lhs, rhs) { + if ((lhs === null) || (rhs === null)) + return lhs === rhs; + if (lhs === rhs) + return true; +- + switch (typeof (lhs)) { ++ + case "string": ++ case "boolean": + case "number": + return lhs == rhs; + break; +@@ -8491,14 +8498,21 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature + return result; + }; + +-JSIL.$GetEnumeratorFallback = function () { +- if (typeof (this) === "string") +- return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); +- else if (JSIL.IsArray(this)) +- // HACK: Too hard to detect the correct element type here. +- return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); +- else +- JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); ++JSIL.$GetEnumeratorFallback = function (thisTypeObject) { ++ var interfaceTypeObject = thisTypeObject; ++ return function () { ++ if (typeof (this) === "string") ++ return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); ++ else if (JSIL.IsArray(this)) { ++ if (interfaceTypeObject.IsGenericType) { ++ return JSIL.GetEnumerator(this, thisTypeObject.__GenericArgumentValues__[0], true); ++ } ++ // HACK: Too hard to detect the correct element type here. ++ return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); ++ } ++ else ++ JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); ++ }; + }; + + // FIXME: This can probably be replaced with compiler and/or runtime intelligence +diff --git a/Libraries/JSIL.js b/Libraries/JSIL.js +index 6c08c88..1b7e405 100644 +--- a/Libraries/JSIL.js ++++ b/Libraries/JSIL.js +@@ -179,7 +179,7 @@ var $jsilloaderstate = { + environment.loadScript(libraryRoot + "JSIL.Bootstrap.DateTime.js"); + environment.loadScript(libraryRoot + "JSIL.Bootstrap.Text.js"); + environment.loadScript(libraryRoot + "JSIL.Bootstrap.Resources.js"); +- environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); ++ //environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); + + if (config.testFixture || environment.getUserSetting("testFixture")) + environment.loadScript(libraryRoot + "JSIL.TestFixture.js"); +diff --git a/Proxies/Array.cs b/Proxies/Array.cs +index 7d32bae..806591c 100644 +--- a/Proxies/Array.cs ++++ b/Proxies/Array.cs +@@ -1,6 +1,7 @@ + using System; + using JSIL.Meta; + using JSIL.Proxy; ++using System.Collections.Generic; + + namespace JSIL.Proxies { + [JSProxy( +@@ -98,6 +99,12 @@ namespace JSIL.Proxies { + throw new InvalidOperationException(); + } + ++ /*[JSReplacement("Array.prototype.sort.call($array)")] ++ public static void Sort (T[] array, IComparer comparer) ++ { ++ throw new InvalidOperationException(); ++ }*/ ++ + [JSReplacement("JSIL.GetEnumerator($this)")] + [JSIsPure] + [JSResultIsNew] +diff --git a/Proxies/Collections.cs b/Proxies/Collections.cs +index 7f18c79..331bfa3 100644 +--- a/Proxies/Collections.cs ++++ b/Proxies/Collections.cs +@@ -14,10 +14,10 @@ namespace JSIL.Proxies { + "System.Collections.Generic.Stack`1", + "System.Collections.Generic.Queue`1", + "System.Collections.Generic.HashSet`1", +- "System.Collections.Hashtable/KeyCollection", +- "System.Collections.Hashtable/ValueCollection", +- "System.Collections.Generic.Dictionary`2/KeyCollection", +- "System.Collections.Generic.Dictionary`2/ValueCollection" ++ "System.Collections.Hashtable+KeyCollection", ++ "System.Collections.Hashtable+ValueCollection", ++ "System.Collections.Generic.Dictionary`2+KeyCollection", ++ "System.Collections.Generic.Dictionary`2+ValueCollection" + }, + memberPolicy: JSProxyMemberPolicy.ReplaceNone, + inheritable: false +@@ -84,15 +84,15 @@ namespace JSIL.Proxies { + + [JSProxy( + new[] { +- "System.Collections.ArrayList/ArrayListEnumerator", +- "System.Collections.Hashtable/HashtableEnumerator", +- "System.Collections.Generic.List`1/Enumerator", +- "System.Collections.Generic.Stack`1/Enumerator", +- "System.Collections.Generic.Queue`1/Enumerator", +- "System.Collections.Generic.HashSet`1/Enumerator", +- "System.Collections.Generic.Dictionary`2/Enumerator", +- "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", +- "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator" ++ "System.Collections.ArrayList+ArrayListEnumerator", ++ "System.Collections.Hashtable+HashtableEnumerator", ++ "System.Collections.Generic.List`1+Enumerator", ++ "System.Collections.Generic.Stack`1+Enumerator", ++ "System.Collections.Generic.Queue`1+Enumerator", ++ "System.Collections.Generic.HashSet`1+Enumerator", ++ "System.Collections.Generic.Dictionary`2+Enumerator", ++ "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", ++ "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator" + }, + memberPolicy: JSProxyMemberPolicy.ReplaceNone, + inheritable: false +@@ -103,10 +103,10 @@ namespace JSIL.Proxies { + + [JSProxy( + new[] { +- "System.Collections.ArrayList/ArrayListEnumerator", +- "System.Collections.Generic.List`1/Enumerator", +- "System.Collections.Generic.Stack`1/Enumerator", +- "System.Collections.Generic.Queue`1/Enumerator", ++ "System.Collections.ArrayList+ArrayListEnumerator", ++ "System.Collections.Generic.List`1+Enumerator", ++ "System.Collections.Generic.Stack`1+Enumerator", ++ "System.Collections.Generic.Queue`1+Enumerator", + }, + memberPolicy: JSProxyMemberPolicy.ReplaceNone, + inheritable: false +diff --git a/Proxies/IO.cs b/Proxies/IO.cs +index fc2b0db..c0dfe93 100644 +--- a/Proxies/IO.cs ++++ b/Proxies/IO.cs +@@ -38,6 +38,26 @@ namespace JSIL.Proxies { + public FileStreamProxy (SafeFileHandle handle, AnyType access, int bufferSize, bool isAsync) { + throw new NotImplementedException(); + } ++ } ++ ++ [JSProxy( ++ typeof(TextReader), ++ JSProxyMemberPolicy.ReplaceDeclared ++ )] ++ public abstract class TextReaderProxy ++ { ++ [JSReplacement("System.IO.TextReader.Dispose()")] ++ [JSIsPure] ++ public void Dispose() ++ { ++ throw new InvalidOperationException(); ++ } + ++ [JSReplacement("System.IO.TextReader.Dispose($b)")] ++ [JSIsPure] ++ public void Dispose(bool b) ++ { ++ throw new InvalidOperationException(); ++ } + } + } +diff --git a/Proxies/Math.cs b/Proxies/Math.cs +index 736da79..c50c21f 100644 +--- a/Proxies/Math.cs ++++ b/Proxies/Math.cs +@@ -121,5 +121,27 @@ namespace JSIL.Proxies { + public static AnyType Pow (AnyType @base, AnyType exponent) { + throw new InvalidOperationException(); + } ++ ++ // ADDED: Missing math methods ++ [JSReplacement("System.Math.IEEERemainder($x, $y)")] ++ [JSIsPure] ++ public static double IEEERemainder(double x, double y) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.Math.Round($value, $places)")] ++ [JSIsPure] ++ public static double Round(double value, int places) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.Math.Sign($value)")] ++ [JSIsPure] ++ public static int Sign(AnyType value) ++ { ++ throw new InvalidOperationException(); ++ } + } + } +diff --git a/Proxies/Object.cs b/Proxies/Object.cs +index 51f1795..8340be2 100644 +--- a/Proxies/Object.cs ++++ b/Proxies/Object.cs +@@ -24,11 +24,11 @@ namespace JSIL.Proxies { + [JSRuntimeDispatch] + new abstract public string ToString (); + +- [JSIsPure] ++ /*[JSIsPure] + [JSChangeName("Object.Equals")] + [JSNeverReplace] + [JSRuntimeDispatch] +- new public abstract bool Equals (object obj); ++ new public abstract bool Equals (object obj);*/ + + [JSIsPure] + [JSReplacement("JSIL.ObjectEquals($objA, $objB)")] +@@ -41,5 +41,8 @@ namespace JSIL.Proxies { + public static bool ReferenceEquals (object objA, object objB) { + throw new InvalidOperationException(); + } ++ ++ [JSReplacement("JSIL.ObjectEqualsStaticHelper($this, $obj)")] ++ new public abstract bool Equals(object obj); + } + } +diff --git a/Proxies/Proxies.4.0.csproj b/Proxies/Proxies.4.0.csproj +index 61b837c..ed51b68 100644 +--- a/Proxies/Proxies.4.0.csproj ++++ b/Proxies/Proxies.4.0.csproj +@@ -34,9 +34,14 @@ + + + ++ + + + ++ ++ ++ ++ + + + +diff --git a/Proxies/String.cs b/Proxies/String.cs +index 34359ba..47524d5 100644 +--- a/Proxies/String.cs ++++ b/Proxies/String.cs +@@ -79,6 +79,7 @@ namespace JSIL.Proxies { + throw new InvalidOperationException(); + } + ++ + [JSIsPure] + [JSReplacement("JSIL.SplitString($this, $dividers)")] + public abstract string[] Split (AnyType[] dividers); +@@ -317,5 +318,69 @@ namespace JSIL.Proxies { + public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count) { + throw new InvalidOperationException(); + } ++ ++ // ADD: String Compare methods and missing concat methods ++ [JSReplacement("System.String.Compare($strA, $strB)")] ++ [JSIsPure] ++ public static int Compare(string strA, string strB) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.Compare($strA, $strB, $ignoreCase)")] ++ [JSIsPure] ++ public static int Compare(string strA, string strB, bool ignoreCase) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.Compare($strA, $strB, $comparisonType)")] ++ [JSIsPure] ++ public static int Compare(string strA, string strB, StringComparison comparisonType) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.Concat($values)")] ++ [JSIsPure] ++ public static string Concat(IEnumerable values) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.Concat($values)")] ++ [JSIsPure] ++ public static string Concat(IEnumerable values) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.IndexOfAny($chars, $startIndex)")] ++ [JSIsPure] ++ public static int IndexOfAny(char[] chars, int startIndex) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.LastIndexOfAny($chars, $startIndex)")] ++ [JSIsPure] ++ public static int LastIndexOfAny(char[] chars, int startIndex) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.IsNullOrEmpty($value)")] ++ [JSIsPure] ++ public static bool IsNullOrEmpty(string value) ++ { ++ throw new InvalidOperationException(); ++ } ++ ++ [JSReplacement("System.String.IsNullOrWhiteSpace($value)")] ++ [JSIsPure] ++ public static bool IsNullOrWhiteSpace(string value) ++ { ++ throw new InvalidOperationException(); ++ } + } + } diff --git a/JSIL/AssemblyTranslator.cs b/JSIL/AssemblyTranslator.cs index 2e0670d06..aea7162ba 100644 --- a/JSIL/AssemblyTranslator.cs +++ b/JSIL/AssemblyTranslator.cs @@ -2687,7 +2687,9 @@ protected void TranslateOverrides ( output.Identifier("Overrides"); output.LPar(); - var interfaceIndex = typeInfo.AllInterfacesRecursive.TakeWhile( + var interfaces = typeInfo.AllInterfacesRecursive.Where((tuple) => (tuple.Item1 == typeInfo && !tuple.Item2.IsIgnored)); + + var interfaceIndex = interfaces.TakeWhile( (tuple) => !TypeUtil.TypesAreEqual(tuple.Item3, @override.InterfaceType) ).Count(); diff --git a/JSIL/JavascriptFormatter.cs b/JSIL/JavascriptFormatter.cs index 0671c79c6..bb5a4a2e3 100644 --- a/JSIL/JavascriptFormatter.cs +++ b/JSIL/JavascriptFormatter.cs @@ -159,6 +159,7 @@ public JavascriptFormatter ( Configuration configuration, bool stubbed ) { Output = output; + //Output = Console.Out; TypeInfo = typeInfo; Manifest = manifest; Assembly = assembly; @@ -459,7 +460,6 @@ protected void WriteGenericParameterAttributes (GenericParameter gp) { protected void TypeReferenceInternal (GenericParameter gp, TypeReferenceContext context) { var ownerType = gp.Owner as TypeReference; var ownerMethod = gp.Owner as MethodReference; - if (context != null) { if (ownerType != null) { if (TypeUtil.TypesAreAssignable(TypeInfo, ownerType, context.SignatureMethodType)) { diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index b3d6e3a91..f3efd96ee 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1379,7 +1379,7 @@ $jsilcore.$ListExternals = function ($, T, type) { ); }; -JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { +/*JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); $jsilcore.$ListExternals($, T, "List"); @@ -1402,7 +1402,7 @@ JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { } ); -}); +});*/ $jsilcore.$ArrayListExternals = function ($) { $jsilcore.$ListExternals($, $.Object, "ArrayList"); @@ -2221,8 +2221,55 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); + /*$.Method({ Static: false, Public: false }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), + Dictionary$b2_CopyTo + ); + + $.Method({ Static: false, Public: false }, "CopyToCheck", + new JSIL.MethodSignature(null, [$asm02.TypeRef("System.Array"), $asm02.TypeRef("System.Int32")], []), + Dictionary$b2_CopyToCheck + ); + + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.Generic.ICollection$lSystem.Collections.Generic.KeyValuePair$lTKey$cmTValue$g$g.CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), + Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_CopyTo + ) +.Overrides(1, "CopyTo"); + + function Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_Contains(keyValuePair) { + return $thisType.Of($thisType.TKey.get(this), $thisType.TValue.get(this)).prototype.ContainsKeyValuePair.call(this, keyValuePair); + }; + + function Dictionary$b2_CopyTo(array, index) { + var $temp00; + + for (var i = 0; i < this.touchedSlots; i = ((i + 1) | 0)) { + if ((this.linkSlots[i].HashCode & -2147483648) !== 0) { + array[($temp00 = index, + index = ((index + 1) | 0), + $temp00)] = new ($asm02.System.Collections.Generic.KeyValuePair$b2.Of($thisType.TKey.get(this), $thisType.TValue.get(this)))(JSIL.CloneParameter($thisType.TKey.get(this), this.keySlots[i]), JSIL.CloneParameter($thisType.TValue.get(this), this.valueSlots[i])); + } + } + }; + + function Dictionary$b2_CopyToCheck(array, index) { + if (array === null) { + throw $S00().Construct("array"); + } + if (index < 0) { + throw $S02().Construct("index"); + } + if (index > array.length) { + throw $S01().Construct("index larger than largest valid index of array"); + } + if (((array.length - index) | 0) < this.get_Count()) { + throw $S01().Construct("Destination array cannot hold the requested elements!"); + } + };*/ + $.Method({Static:false, Public:true }, "get_Keys", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), function get_Keys () { if (this.tKeyCollection === null) { this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; @@ -2234,7 +2281,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) ); $.Method({Static:false, Public:true }, "get_Values", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), function get_Values () { if (this.tValueCollection === null) { this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; @@ -2246,7 +2293,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) ); $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), function GetEnumerator () { if (this.tEnumerator === null) { this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; @@ -2316,11 +2363,11 @@ JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($ }); -JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", function ($interfaceBuilder) { +JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", function ($interfaceBuilder) { var $ = $interfaceBuilder; $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), function _ctor (dictionary) { this.dictionary = dictionary; } @@ -2334,7 +2381,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", ); $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection")]), [], []), + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), function GetEnumerator () { return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); } @@ -2349,11 +2396,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection", .Overrides(3, "GetEnumerator"); }); -JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection", function ($interfaceBuilder) { +JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection", function ($interfaceBuilder) { var $ = $interfaceBuilder; $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), function _ctor (dictionary) { this.dictionary = dictionary; } @@ -2367,7 +2414,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection ); $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection")]), [], []), + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), function GetEnumerator () { return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); } @@ -2382,11 +2429,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection .Overrides(3, "GetEnumerator"); }); -JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", function ($interfaceBuilder) { +JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", function ($interfaceBuilder) { var $ = $interfaceBuilder; $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), function _ctor (dictionary) { this.dictionary = dictionary; this.kvpEnumerator = null; @@ -2413,7 +2460,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/E ); $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator"), [], []), + new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), function get_Current () { return this.kvpEnumerator.get_Current().key; } @@ -2443,11 +2490,11 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/KeyCollection/E .Overrides(2, "Reset"); }); -JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", function ($interfaceBuilder) { +JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", function ($interfaceBuilder) { var $ = $interfaceBuilder; $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), function _ctor (dictionary) { this.dictionary = dictionary; this.kvpEnumerator = null; @@ -2474,7 +2521,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/ValueCollection ); $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator"), [], []), + new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), function get_Current () { return this.kvpEnumerator.get_Current().value; } @@ -2525,9 +2572,9 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, ); }); -JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2/Enumerator", false, ["TKey", "TValue"], function ($) { +JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2+Enumerator", false, ["TKey", "TValue"], function ($) { $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")])]), + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), /* 1 */ $jsilcore.TypeRef("System.IDisposable"), /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") @@ -2536,7 +2583,7 @@ JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Gener JSIL.MakeType({ BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2/KeyCollection", + Name: "System.Collections.Generic.Dictionary`2+KeyCollection", IsPublic: true, IsReferenceType: true, GenericParameters: ["TKey", "TValue"], @@ -2546,7 +2593,7 @@ JSIL.MakeType({ JSIL.MakeType({ BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2/ValueCollection", + Name: "System.Collections.Generic.Dictionary`2+ValueCollection", IsPublic: true, IsReferenceType: true, GenericParameters: ["TKey", "TValue"], @@ -2556,7 +2603,7 @@ JSIL.MakeType({ JSIL.MakeType({ BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", + Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", IsPublic: true, IsReferenceType: false, GenericParameters: ["TKey", "TValue"], @@ -2566,7 +2613,7 @@ JSIL.MakeType({ JSIL.MakeType({ BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator", + Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", IsPublic: true, IsReferenceType: false, GenericParameters: ["TKey", "TValue"], @@ -2574,7 +2621,7 @@ JSIL.MakeType({ }, function ($) { }); -JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", function ($interfaceBuilder) { +JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", function ($interfaceBuilder) { var $ = $interfaceBuilder; $.RawMethod(false, "__CopyMembers__", @@ -2585,7 +2632,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu ); $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), function _ctor (dictionary) { this.dictionary = dictionary; @@ -2605,7 +2652,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu ); $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")]), $.Int32], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), function _ctor (dictionary, getEnumeratorRetType) { throw new Error('Not implemented'); } @@ -2620,7 +2667,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2/Enumerator", fu ); $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2/Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2/Enumerator")]), [], []), + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), function get_Current () { return this.state.current.MemberwiseClone(); } @@ -4750,6 +4797,20 @@ JSIL.ImplementExternals("System.Array", function ($) { } ); + $.Method({ Static: true, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array", ["!!0"]), + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), + function Sort(type, array, comparer) { + var tComparer = System.Collections.Generic.IComparer$b1.Of(type); + var compare = tComparer.Compare; + + Array.prototype.sort.call(array, function (lhs, rhs) { + return compare.Call(comparer, null, lhs, rhs); + }); + } +); + $.Method({Static:true , Public:true }, "Copy", new JSIL.MethodSignature(null, [ $jsilcore.TypeRef("System.Array"), $.Int32, diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 8d5d1087d..a3d007ade 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -6825,7 +6825,7 @@ JSIL.InterfaceMethod.prototype.Rebind = function (newTypeObject, newSignature) { JSIL.InterfaceMethod.prototype.GetVariantInvocationCandidates = function (thisReference) { var cache = this.variantInvocationCandidateCache; - var typeId = thisReference.__TypeId__; + var typeId = thisReference.__ThisTypeId__; var result = cache[typeId]; @@ -6859,7 +6859,7 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { } if (!result) - result = this.fallbackMethod; + result = this.fallbackMethod ? this.fallbackMethod(this.typeObject) : null; if (!result) { var errorString = "Method '" + this.signature.toString(this.methodName) + "' of interface '" + @@ -7883,14 +7883,21 @@ JSIL.GetEqualsSignature = function () { return JSIL.$equalsSignature; } +JSIL.ObjectEqualsStaticHelper = function (lhs, rhs) { + if (lhs["Object_Equals"] != null) + return lhs["Object_Equals"](rhs); + return JSIL.ObjectEquals(lhs, rhs); +} + JSIL.ObjectEquals = function (lhs, rhs) { if ((lhs === null) || (rhs === null)) return lhs === rhs; if (lhs === rhs) return true; - switch (typeof (lhs)) { + case "string": + case "boolean": case "number": return lhs == rhs; break; @@ -8491,14 +8498,21 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature return result; }; -JSIL.$GetEnumeratorFallback = function () { - if (typeof (this) === "string") - return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); - else if (JSIL.IsArray(this)) - // HACK: Too hard to detect the correct element type here. - return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); - else - JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); +JSIL.$GetEnumeratorFallback = function (thisTypeObject) { + var interfaceTypeObject = thisTypeObject; + return function () { + if (typeof (this) === "string") + return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); + else if (JSIL.IsArray(this)) { + if (interfaceTypeObject.IsGenericType) { + return JSIL.GetEnumerator(this, thisTypeObject.__GenericArgumentValues__[0], true); + } + // HACK: Too hard to detect the correct element type here. + return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); + } + else + JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); + }; }; // FIXME: This can probably be replaced with compiler and/or runtime intelligence diff --git a/Libraries/JSIL.js b/Libraries/JSIL.js index 6c08c880d..1b7e405f6 100644 --- a/Libraries/JSIL.js +++ b/Libraries/JSIL.js @@ -179,7 +179,7 @@ var $jsilloaderstate = { environment.loadScript(libraryRoot + "JSIL.Bootstrap.DateTime.js"); environment.loadScript(libraryRoot + "JSIL.Bootstrap.Text.js"); environment.loadScript(libraryRoot + "JSIL.Bootstrap.Resources.js"); - environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); + //environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); if (config.testFixture || environment.getUserSetting("testFixture")) environment.loadScript(libraryRoot + "JSIL.TestFixture.js"); diff --git a/Proxies/Activator.cs b/Proxies/Activator.cs new file mode 100644 index 000000000..8c4f2cd5d --- /dev/null +++ b/Proxies/Activator.cs @@ -0,0 +1,44 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Globalization; +using System.Reflection; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(Activator), + JSProxyMemberPolicy.ReplaceDeclared + )] + public abstract class ActivatorProxy + { + [JSReplacement("System.Activator.CreateInstance($type)")] + [JSIsPure] + public static Object CreateInstance(Type type) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Activator.CreateInstance($type, $array)")] + [JSIsPure] + public static Object CreateInstance(Type type, Object[] array) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Activator.CreateInstance()")] + [JSIsPure] + public static T CreateInstance() + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Activator.CreateInstance($type, $bindingAttr, $binder, $args, $culture)")] + [JSIsPure] + public static Object CreateInstance(Type type, BindingFlags bindingAttr, + Binder binder, Object[] args, CultureInfo culture) + { + throw new InvalidOperationException(); + } + } +} diff --git a/Proxies/Array.cs b/Proxies/Array.cs index 7d32bae95..806591cf1 100644 --- a/Proxies/Array.cs +++ b/Proxies/Array.cs @@ -1,6 +1,7 @@ using System; using JSIL.Meta; using JSIL.Proxy; +using System.Collections.Generic; namespace JSIL.Proxies { [JSProxy( @@ -98,6 +99,12 @@ public static void Sort (T[] array) { throw new InvalidOperationException(); } + /*[JSReplacement("Array.prototype.sort.call($array)")] + public static void Sort (T[] array, IComparer comparer) + { + throw new InvalidOperationException(); + }*/ + [JSReplacement("JSIL.GetEnumerator($this)")] [JSIsPure] [JSResultIsNew] diff --git a/Proxies/Collections.cs b/Proxies/Collections.cs index 7f18c7992..331bfa355 100644 --- a/Proxies/Collections.cs +++ b/Proxies/Collections.cs @@ -14,10 +14,10 @@ namespace JSIL.Proxies { "System.Collections.Generic.Stack`1", "System.Collections.Generic.Queue`1", "System.Collections.Generic.HashSet`1", - "System.Collections.Hashtable/KeyCollection", - "System.Collections.Hashtable/ValueCollection", - "System.Collections.Generic.Dictionary`2/KeyCollection", - "System.Collections.Generic.Dictionary`2/ValueCollection" + "System.Collections.Hashtable+KeyCollection", + "System.Collections.Hashtable+ValueCollection", + "System.Collections.Generic.Dictionary`2+KeyCollection", + "System.Collections.Generic.Dictionary`2+ValueCollection" }, memberPolicy: JSProxyMemberPolicy.ReplaceNone, inheritable: false @@ -84,15 +84,15 @@ public AnyType this[AnyType index] { [JSProxy( new[] { - "System.Collections.ArrayList/ArrayListEnumerator", - "System.Collections.Hashtable/HashtableEnumerator", - "System.Collections.Generic.List`1/Enumerator", - "System.Collections.Generic.Stack`1/Enumerator", - "System.Collections.Generic.Queue`1/Enumerator", - "System.Collections.Generic.HashSet`1/Enumerator", - "System.Collections.Generic.Dictionary`2/Enumerator", - "System.Collections.Generic.Dictionary`2/KeyCollection/Enumerator", - "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator" + "System.Collections.ArrayList+ArrayListEnumerator", + "System.Collections.Hashtable+HashtableEnumerator", + "System.Collections.Generic.List`1+Enumerator", + "System.Collections.Generic.Stack`1+Enumerator", + "System.Collections.Generic.Queue`1+Enumerator", + "System.Collections.Generic.HashSet`1+Enumerator", + "System.Collections.Generic.Dictionary`2+Enumerator", + "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", + "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator" }, memberPolicy: JSProxyMemberPolicy.ReplaceNone, inheritable: false @@ -103,10 +103,10 @@ public abstract class CollectionEnumeratorProxy { [JSProxy( new[] { - "System.Collections.ArrayList/ArrayListEnumerator", - "System.Collections.Generic.List`1/Enumerator", - "System.Collections.Generic.Stack`1/Enumerator", - "System.Collections.Generic.Queue`1/Enumerator", + "System.Collections.ArrayList+ArrayListEnumerator", + "System.Collections.Generic.List`1+Enumerator", + "System.Collections.Generic.Stack`1+Enumerator", + "System.Collections.Generic.Queue`1+Enumerator", }, memberPolicy: JSProxyMemberPolicy.ReplaceNone, inheritable: false diff --git a/Proxies/Encoding.cs b/Proxies/Encoding.cs new file mode 100644 index 000000000..d5cfaf303 --- /dev/null +++ b/Proxies/Encoding.cs @@ -0,0 +1,132 @@ +using System; +using JSIL.Meta; +using JSIL.Proxy; +using System.Text; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(Encoding), + JSProxyMemberPolicy.ReplaceDeclared + )] + public abstract class EncodingProxy + { + [JSReplacement("System.Text.Encoding.get_ASCII()")] + [JSIsPure] + public static Encoding ASCII { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Text.Encoding.get_UTF8()")] + [JSIsPure] + public static Encoding UTF8 { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Text.Encoding.get_UTF7()")] + [JSIsPure] + public static Encoding UTF7 { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Text.Encoding.get_Unicode()")] + [JSIsPure] + public static Encoding Unicode { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Text.Encoding.get_BigEndianUnicode()")] + [JSIsPure] + public static Encoding BigEndianUnicode { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Text.Encoding.GetByteCount($chars)")] + [JSIsPure] + public int GetByteCount(Char[] chars) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetByteCount($chars)")] + [JSIsPure] + public int GetByteCount(string s) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetByteCount($chars, $a, $b)")] + [JSIsPure] + public int GetByteCount(Char[] chars, int a, int b) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetBytes($arg)")] + [JSIsPure] + public byte[] GetBytes(Char[] chars) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetBytes($arg, $a, $b)")] + [JSIsPure] + public byte[] GetBytes(Char[] chars, int a, int b) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetBytes($arg, $a, $b, $bytes, $c)")] + [JSIsPure] + public int GetBytes(Char[] chars, int a, int b, byte[] bytes, int c) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetBytes($arg)")] + [JSIsPure] + public byte[] GetBytes(string s) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetBytes($arg, $a, $b, $bytes, $c)")] + [JSIsPure] + public int GetBytes(string s, int a, int b, byte[] bytes, int c) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetCharCount($arg)")] + [JSIsPure] + public int GetCharCount(byte[] bytes) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetCharCount($arg, $a, $b)")] + [JSIsPure] + public int GetCharCount(byte[] bytes, int a ,int b) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetChars($arg)")] + [JSIsPure] + public Char[] GetChars(byte[] bytes) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetChars($arg, $a, $b)")] + [JSIsPure] + public Char[] GetChars(byte[] bytes, int a, int b) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetString($arg)")] + [JSIsPure] + public string GetString(byte[] bytes) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Text.Encoding.GetString($arg, $a, $b)")] + [JSIsPure] + public string GetString(byte[] bytes, int a, int b) + { + throw new InvalidOperationException(); + } + } +} diff --git a/Proxies/Enum.cs b/Proxies/Enum.cs new file mode 100644 index 000000000..f5127ec63 --- /dev/null +++ b/Proxies/Enum.cs @@ -0,0 +1,64 @@ +using JSIL.Proxy; +using System; +using JSIL.Meta; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(Enum), + JSProxyMemberPolicy.ReplaceDeclared + )] + public abstract class EnumProxy + { + [JSReplacement("System.Enum.Parse($type, $value)")] + [JSIsPure] + public static Object Parse(Type type, string value) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.Parse($type, $value, $ignoreCase)")] + [JSIsPure] + public static Object Parse(Type type, string value, bool ignoreCase) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.TryParse($value, $result)")] + [JSIsPure] + public static bool TryParse(string value, out TEnum result) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.TryParse($value, $ignoreCase, $result)")] + [JSIsPure] + public static bool TryParse(string value, bool ignoreCase, out TEnum result) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.GetNames($type)")] + [JSIsPure] + public static string[] GetNames(Type enumType) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.GetValues($type)")] + [JSIsPure] + public static Array GetValues(Type enumType) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Enum.ToObject($type, $value)")] + [JSIsPure] + public static Object ToObject(Type enumType, int value) + { + throw new InvalidOperationException(); + } + + + } +} diff --git a/Proxies/EventInfo.cs b/Proxies/EventInfo.cs new file mode 100644 index 000000000..e3cc61289 --- /dev/null +++ b/Proxies/EventInfo.cs @@ -0,0 +1,60 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Reflection; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(EventInfo), + JSProxyMemberPolicy.ReplaceDeclared + )] + public abstract class EventInfoProxy + { + [JSReplacement("System.Reflection.EventInfo.AddEventHandler($object, $delegate)")] + [JSIsPure] + public virtual void AddEventHandler(Object obj, Delegate del) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Reflection.EventInfo.RemoveEventHandler($object, $delegate)")] + [JSIsPure] + public virtual void RemoveEventHandler(Object obj, Delegate del) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Reflection.EventInfo.GetAddMethod()")] + [JSIsPure] + public MethodInfo GetAddMethod() + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Reflection.EventInfo.GetAddMethod($b)")] + [JSIsPure] + public MethodInfo GetAddMethod(bool b) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Reflection.EventInfo.GetRemoveMethod()")] + [JSIsPure] + public MethodInfo GetRemoveMethod() + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Reflection.EventInfo.GetRemoveMethod($b)")] + [JSIsPure] + public MethodInfo GetRemoveMethod(bool b) + { + throw new InvalidOperationException(); + } + + + + + } +} diff --git a/Proxies/IO.cs b/Proxies/IO.cs index fc2b0db5b..c0dfe93cb 100644 --- a/Proxies/IO.cs +++ b/Proxies/IO.cs @@ -38,6 +38,26 @@ public FileStreamProxy(SafeFileHandle handle, AnyType access, int bufferSize) { public FileStreamProxy (SafeFileHandle handle, AnyType access, int bufferSize, bool isAsync) { throw new NotImplementedException(); } + } + + [JSProxy( + typeof(TextReader), + JSProxyMemberPolicy.ReplaceDeclared + )] + public abstract class TextReaderProxy + { + [JSReplacement("System.IO.TextReader.Dispose()")] + [JSIsPure] + public void Dispose() + { + throw new InvalidOperationException(); + } + [JSReplacement("System.IO.TextReader.Dispose($b)")] + [JSIsPure] + public void Dispose(bool b) + { + throw new InvalidOperationException(); + } } } diff --git a/Proxies/Math.cs b/Proxies/Math.cs index 736da799f..c50c21fb1 100644 --- a/Proxies/Math.cs +++ b/Proxies/Math.cs @@ -121,5 +121,27 @@ public static double Ceiling (double d) { public static AnyType Pow (AnyType @base, AnyType exponent) { throw new InvalidOperationException(); } + + // ADDED: Missing math methods + [JSReplacement("System.Math.IEEERemainder($x, $y)")] + [JSIsPure] + public static double IEEERemainder(double x, double y) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Math.Round($value, $places)")] + [JSIsPure] + public static double Round(double value, int places) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Math.Sign($value)")] + [JSIsPure] + public static int Sign(AnyType value) + { + throw new InvalidOperationException(); + } } } diff --git a/Proxies/MonoProxy.cs b/Proxies/MonoProxy.cs new file mode 100644 index 000000000..0390d1873 --- /dev/null +++ b/Proxies/MonoProxy.cs @@ -0,0 +1,10 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(System.Runtime.CompilerServices.RuntimeHelpers))] + [JSIgnore] + public abstract class RuntimeHelpers { } +} diff --git a/Proxies/Object.cs b/Proxies/Object.cs index 51f17959e..8340be23c 100644 --- a/Proxies/Object.cs +++ b/Proxies/Object.cs @@ -24,11 +24,11 @@ public abstract class ObjectProxy { [JSRuntimeDispatch] new abstract public string ToString (); - [JSIsPure] + /*[JSIsPure] [JSChangeName("Object.Equals")] [JSNeverReplace] [JSRuntimeDispatch] - new public abstract bool Equals (object obj); + new public abstract bool Equals (object obj);*/ [JSIsPure] [JSReplacement("JSIL.ObjectEquals($objA, $objB)")] @@ -41,5 +41,8 @@ public static bool Equals (object objA, object objB) { public static bool ReferenceEquals (object objA, object objB) { throw new InvalidOperationException(); } + + [JSReplacement("JSIL.ObjectEqualsStaticHelper($this, $obj)")] + new public abstract bool Equals(object obj); } } diff --git a/Proxies/Proxies.4.0.csproj b/Proxies/Proxies.4.0.csproj index 61b837c84..ed51b684b 100644 --- a/Proxies/Proxies.4.0.csproj +++ b/Proxies/Proxies.4.0.csproj @@ -34,9 +34,14 @@ + + + + + diff --git a/Proxies/String.cs b/Proxies/String.cs index 34359bae4..47524d509 100644 --- a/Proxies/String.cs +++ b/Proxies/String.cs @@ -79,6 +79,7 @@ public static string Concat (string lhs, char ch) { throw new InvalidOperationException(); } + [JSIsPure] [JSReplacement("JSIL.SplitString($this, $dividers)")] public abstract string[] Split (AnyType[] dividers); @@ -317,5 +318,69 @@ public string Remove (int startIndex, int count) { public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count) { throw new InvalidOperationException(); } + + // ADD: String Compare methods and missing concat methods + [JSReplacement("System.String.Compare($strA, $strB)")] + [JSIsPure] + public static int Compare(string strA, string strB) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.Compare($strA, $strB, $ignoreCase)")] + [JSIsPure] + public static int Compare(string strA, string strB, bool ignoreCase) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.Compare($strA, $strB, $comparisonType)")] + [JSIsPure] + public static int Compare(string strA, string strB, StringComparison comparisonType) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.Concat($values)")] + [JSIsPure] + public static string Concat(IEnumerable values) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.Concat($values)")] + [JSIsPure] + public static string Concat(IEnumerable values) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.IndexOfAny($chars, $startIndex)")] + [JSIsPure] + public static int IndexOfAny(char[] chars, int startIndex) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.LastIndexOfAny($chars, $startIndex)")] + [JSIsPure] + public static int LastIndexOfAny(char[] chars, int startIndex) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.IsNullOrEmpty($value)")] + [JSIsPure] + public static bool IsNullOrEmpty(string value) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.String.IsNullOrWhiteSpace($value)")] + [JSIsPure] + public static bool IsNullOrWhiteSpace(string value) + { + throw new InvalidOperationException(); + } } } From 2ec109f4e82acfe6c9d1a3211d55ed3ae84af9f8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Apr 2014 08:53:07 +0200 Subject: [PATCH 02/16] Added more proxies --- JSIL/AssemblyTranslator.cs | 1 + JSIL/JavascriptFormatter.cs | 2 +- Libraries/JSIL.Bootstrap.DateTime.js | 4 +- Libraries/JSIL.Bootstrap.js | 7513 +++++++++++++------------- Libraries/JSIL.Core.Types.js | 24 + Meta/Attributes.cs | 408 +- Proxies/Array.cs | 1 + Proxies/Bootstrap.cs | 117 + Proxies/Collections.cs | 9 + Proxies/DateTime.cs | 189 + Proxies/Environment.cs | 28 + Proxies/Exceptions.cs | 93 + Proxies/Proxies.4.0.csproj | 6 + Proxies/Random.cs | 12 + Proxies/Resources.cs | 273 + Proxies/Threading.cs | 19 + 16 files changed, 4718 insertions(+), 3981 deletions(-) create mode 100644 Proxies/Bootstrap.cs create mode 100644 Proxies/Environment.cs create mode 100644 Proxies/Exceptions.cs create mode 100644 Proxies/Random.cs create mode 100644 Proxies/Resources.cs create mode 100644 Proxies/Threading.cs diff --git a/JSIL/AssemblyTranslator.cs b/JSIL/AssemblyTranslator.cs index aea7162ba..283b1ed06 100644 --- a/JSIL/AssemblyTranslator.cs +++ b/JSIL/AssemblyTranslator.cs @@ -2615,6 +2615,7 @@ protected void DefineMethod ( output.Comma(); output.Value(Util.EscapeIdentifier(methodInfo.GetName(true), EscapingMode.String)); + output.Comma(); output.NewLine(); diff --git a/JSIL/JavascriptFormatter.cs b/JSIL/JavascriptFormatter.cs index bb5a4a2e3..9f67c26ca 100644 --- a/JSIL/JavascriptFormatter.cs +++ b/JSIL/JavascriptFormatter.cs @@ -647,7 +647,7 @@ public void TypeReference (TypeReference type, TypeReferenceContext context) { (context != null) && (context.EnclosingType != null) ) { - if (TypeUtil.TypesAreEqual(type, context.EnclosingType)) { + if (TypeUtil.TypesAreEqual(type, context.EnclosingType, true)) { // Types can reference themselves, so this prevents recursive initialization. if (Stubbed && Configuration.GenerateSkeletonsForStubbedAssemblies.GetValueOrDefault(false)) { } else { diff --git a/Libraries/JSIL.Bootstrap.DateTime.js b/Libraries/JSIL.Bootstrap.DateTime.js index 2e32c4cef..8025c9a61 100644 --- a/Libraries/JSIL.Bootstrap.DateTime.js +++ b/Libraries/JSIL.Bootstrap.DateTime.js @@ -84,7 +84,7 @@ JSIL.ImplementExternals( fromTicks ); - $.Method({Static:true , Public:true }, "op_Addition", + /*$.Method({Static:true , Public:true }, "op_Addition", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), function op_Addition (t1, t2) { return fromTicks($jsilcore.System.Int64.op_Addition(t1._ticks, t2._ticks, TempI64A)); @@ -145,7 +145,7 @@ JSIL.ImplementExternals( function op_UnaryNegation (self) { return fromTicks($jsilcore.System.Int64.op_UnaryNegation(self._ticks)); } - ); + );*/ $.RawMethod(false, "$accumulate", function (multiplier, amount) { // FIXME: unnecessary garbage diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index f3efd96ee..d0dcfef87 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1,10 +1,10 @@ "use strict"; if (typeof (JSIL) === "undefined") - throw new Error("JSIL.Core is required"); + throw new Error("JSIL.Core is required"); -if (!$jsilcore) - throw new Error("JSIL.Core is required"); +if (!$jsilcore) + throw new Error("JSIL.Core is required"); JSIL.DeclareNamespace("System.ComponentModel"); JSIL.DeclareNamespace("System.IO"); @@ -13,268 +13,268 @@ JSIL.DeclareNamespace("System.Diagnostics"); // HACK: Unfortunately necessary :-( String.prototype.Object_Equals = function (rhs) { - return this === rhs; + return this === rhs; }; String.prototype.GetHashCode = function () { - var h = 0; - - for (var i = 0; i < this.length; i++) { - h = ((h << 5) - h + this.charCodeAt(i)) & ~0; - } - - return h; + var h = 0; + + for (var i = 0; i < this.length; i++) { + h = ((h << 5) - h + this.charCodeAt(i)) & ~0; + } + + return h; }; // HACK: Nasty compatibility shim for JS Error <-> C# Exception Error.prototype.get_Message = function () { - return String(this); + return String(this); }; Error.prototype.get_StackTrace = function () { - return this.stack || ""; + return this.stack || ""; }; $jsilcore.$ParseBoolean = function (text) { - if (arguments.length !== 1) - throw new Error("NumberStyles not supported"); + if (arguments.length !== 1) + throw new Error("NumberStyles not supported"); - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseBoolean(text, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseBoolean(text, temp)) + return temp.get(); - throw new System.Exception("Invalid boolean"); + throw new System.Exception("Invalid boolean"); }; $jsilcore.$TryParseBoolean = function (text, result) { - text = text.toLowerCase().trim(); + text = text.toLowerCase().trim(); - if (text === "true") { - result.set(true); - return true; - } else if (text === "false") { - result.set(false); - return true; - } + if (text === "true") { + result.set(true); + return true; + } else if (text === "false") { + result.set(false); + return true; + } - return false; + return false; }; $jsilcore.$MakeParseExternals = function ($, type, parse, tryParse) { - $.Method({Static:true , Public:true }, "Parse", - (new JSIL.MethodSignature(type, [$.String], [])), - parse - ); + $.Method({ Static: true, Public: true }, "Parse", + (new JSIL.MethodSignature(type, [$.String], [])), + parse + ); - $.Method({Static:true , Public:true }, "Parse", - (new JSIL.MethodSignature(type, [$.String, $jsilcore.TypeRef("System.Globalization.NumberStyles")], [])), - parse - ); + $.Method({ Static: true, Public: true }, "Parse", + (new JSIL.MethodSignature(type, [$.String, $jsilcore.TypeRef("System.Globalization.NumberStyles")], [])), + parse + ); - $.Method({Static:true , Public:true }, "TryParse", - (new JSIL.MethodSignature($.Boolean, [$.String, $jsilcore.TypeRef("JSIL.Reference", [type])], [])), - tryParse - ); + $.Method({ Static: true, Public: true }, "TryParse", + (new JSIL.MethodSignature($.Boolean, [$.String, $jsilcore.TypeRef("JSIL.Reference", [type])], [])), + tryParse + ); }; JSIL.ImplementExternals( "System.Boolean", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (value === false) || (value === true); - }); + $.RawMethod(true, "CheckType", function (value) { + return (value === false) || (value === true); + }); - $jsilcore.$MakeParseExternals($, $.Boolean, $jsilcore.$ParseBoolean, $jsilcore.$TryParseBoolean); + $jsilcore.$MakeParseExternals($, $.Boolean, $jsilcore.$ParseBoolean, $jsilcore.$TryParseBoolean); } ); JSIL.MakeNumericType(Boolean, "System.Boolean", true); JSIL.ImplementExternals( "System.Char", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "string") && (value.length == 1); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "string") && (value.length == 1); + }); - $.Constant({Public: true, Static: true}, "MaxValue", "\uffff"); - $.Constant({Public: true, Static: true}, "MinValue", "\0"); + $.Constant({ Public: true, Static: true }, "MaxValue", "\uffff"); + $.Constant({ Public: true, Static: true }, "MinValue", "\0"); } ); JSIL.MakeNumericType(String, "System.Char", true); JSIL.ImplementExternals( "System.Byte", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0) && (value <= 255); - }); - - $.Constant({Public: true, Static: true}, "MinValue", 0); - $.Constant({Public: true, Static: true}, "MaxValue", 255); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0) && (value <= 255); + }); + + $.Constant({ Public: true, Static: true }, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 255); } ); JSIL.MakeNumericType(Number, "System.Byte", true, "Uint8Array"); JSIL.ImplementExternals( "System.SByte", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= -128) && (value <= 127); - }); - - $.Constant({Public: true, Static: true}, "MinValue", -128); - $.Constant({Public: true, Static: true}, "MaxValue", 127); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= -128) && (value <= 127); + }); + + $.Constant({ Public: true, Static: true }, "MinValue", -128); + $.Constant({ Public: true, Static: true }, "MaxValue", 127); } ); JSIL.MakeNumericType(Number, "System.SByte", true, "Int8Array"); $jsilcore.$ParseInt = function (text, style) { - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseInt(text, style, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseInt(text, style, temp)) + return temp.get(); - throw new System.Exception("Invalid integer"); + throw new System.Exception("Invalid integer"); }; $jsilcore.$TryParseInt = function (text, style, result) { - if (arguments.length === 2) { - result = style; - style = 0; - } + if (arguments.length === 2) { + result = style; + style = 0; + } - var radix = 10; + var radix = 10; - if (style & System.Globalization.NumberStyles.AllowHexSpecifier) - radix = 16; + if (style & System.Globalization.NumberStyles.AllowHexSpecifier) + radix = 16; - var parsed; - result.set(parsed = parseInt(text, radix)); - return !isNaN(parsed); + var parsed; + result.set(parsed = parseInt(text, radix)); + return !isNaN(parsed); }; JSIL.ImplementExternals( "System.UInt16", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0); + }); - $jsilcore.$MakeParseExternals($, $.UInt16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.UInt16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({Public: true, Static: true}, "MaxValue", 65535); - $.Constant({Public: true, Static: true}, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 65535); + $.Constant({ Public: true, Static: true }, "MinValue", 0); } ); JSIL.MakeNumericType(Number, "System.UInt16", true, "Uint16Array"); JSIL.ImplementExternals( "System.Int16", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Int16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - - $.Constant({Public: true, Static: true}, "MaxValue", 32767); - $.Constant({Public: true, Static: true}, "MinValue", -32768); + $jsilcore.$MakeParseExternals($, $.Int16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + + $.Constant({ Public: true, Static: true }, "MaxValue", 32767); + $.Constant({ Public: true, Static: true }, "MinValue", -32768); } ); JSIL.MakeNumericType(Number, "System.Int16", true, "Int16Array"); JSIL.ImplementExternals( "System.UInt32", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0); + }); - $jsilcore.$MakeParseExternals($, $.UInt32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.UInt32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({Public: true, Static: true}, "MaxValue", 4294967295); - $.Constant({Public: true, Static: true}, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 4294967295); + $.Constant({ Public: true, Static: true }, "MinValue", 0); } ); JSIL.MakeNumericType(Number, "System.UInt32", true, "Uint32Array"); JSIL.ImplementExternals( "System.Int32", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); + + $jsilcore.$MakeParseExternals($, $.Int32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $jsilcore.$MakeParseExternals($, $.Int32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - - $.Constant({Public: true, Static: true}, "MaxValue", 2147483647); - $.Constant({Public: true, Static: true}, "MinValue", -2147483648); + $.Constant({ Public: true, Static: true }, "MaxValue", 2147483647); + $.Constant({ Public: true, Static: true }, "MinValue", -2147483648); } ); JSIL.MakeNumericType(Number, "System.Int32", true, "Int32Array"); $jsilcore.$ParseFloat = function (text, style) { - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseFloat(text, style, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseFloat(text, style, temp)) + return temp.get(); - throw new System.Exception("Invalid float"); + throw new System.Exception("Invalid float"); }; $jsilcore.$TryParseFloat = function (text, style, result) { - if (arguments.length === 2) { - result = style; - style = 0; - } - - var parsed; - result.set(parsed = parseFloat(text)); - - if (isNaN(parsed)) { - var lowered = text.toLowerCase(); - - if (lowered === "nan") { - result.set(Number.NaN); - return true; - } else if (lowered === "-infinity") { - result.set(Number.NEGATIVE_INFINITY); - return true; - } else if ((lowered === "+infinity") || (lowered === "infinity")) { - result.set(Number.POSITIVE_INFINITY); - return true; + if (arguments.length === 2) { + result = style; + style = 0; + } + + var parsed; + result.set(parsed = parseFloat(text)); + + if (isNaN(parsed)) { + var lowered = text.toLowerCase(); + + if (lowered === "nan") { + result.set(Number.NaN); + return true; + } else if (lowered === "-infinity") { + result.set(Number.NEGATIVE_INFINITY); + return true; + } else if ((lowered === "+infinity") || (lowered === "infinity")) { + result.set(Number.POSITIVE_INFINITY); + return true; + } else { + return false; + } } else { - return false; + return true; } - } else { - return true; - } }; JSIL.ImplementExternals( "System.Single", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); + $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); - $.Constant({Public: true, Static: true}, "MinValue", -3.4028234663852886E+38); - $.Constant({Public: true, Static: true}, "Epsilon", 1.4012984643248171E-45); - $.Constant({Public: true, Static: true}, "MaxValue", 3.4028234663852886E+38); - $.Constant({Public: true, Static: true}, "PositiveInfinity", Infinity); - $.Constant({Public: true, Static: true}, "NegativeInfinity", -Infinity); - $.Constant({Public: true, Static: true}, "NaN", NaN); + $.Constant({ Public: true, Static: true }, "MinValue", -3.4028234663852886E+38); + $.Constant({ Public: true, Static: true }, "Epsilon", 1.4012984643248171E-45); + $.Constant({ Public: true, Static: true }, "MaxValue", 3.4028234663852886E+38); + $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); + $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); + $.Constant({ Public: true, Static: true }, "NaN", NaN); } ); JSIL.MakeNumericType(Number, "System.Single", false, "Float32Array"); JSIL.ImplementExternals( "System.Double", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); + $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); - $.Constant({Public: true, Static: true}, "MinValue", -1.7976931348623157E+308); - $.Constant({Public: true, Static: true}, "MaxValue", 1.7976931348623157E+308); - $.Constant({Public: true, Static: true}, "Epsilon", 4.94065645841247E-324); - $.Constant({Public: true, Static: true}, "NegativeInfinity", -Infinity); - $.Constant({Public: true, Static: true}, "PositiveInfinity", Infinity); - $.Constant({Public: true, Static: true}, "NaN", NaN); + $.Constant({ Public: true, Static: true }, "MinValue", -1.7976931348623157E+308); + $.Constant({ Public: true, Static: true }, "MaxValue", 1.7976931348623157E+308); + $.Constant({ Public: true, Static: true }, "Epsilon", 4.94065645841247E-324); + $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); + $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); + $.Constant({ Public: true, Static: true }, "NaN", NaN); } ); JSIL.MakeNumericType(Number, "System.Double", false, "Float64Array"); @@ -285,183 +285,183 @@ JSIL.MakeClass("System.Object", "System.ComponentModel.TypeConverter", true); JSIL.MakeClass("System.ComponentModel.TypeConverter", "System.ComponentModel.ExpandableObjectConverter", true); $jsilcore.$GetInvocationList = function (delegate) { - if (delegate === null) { - return [ ]; - } else if (typeof (delegate.__delegates__) !== "undefined") { - return delegate.__delegates__; - } else if (typeof (delegate) === "function") { - return [ delegate ]; - } else { - return null; - } + if (delegate === null) { + return []; + } else if (typeof (delegate.__delegates__) !== "undefined") { + return delegate.__delegates__; + } else if (typeof (delegate) === "function") { + return [delegate]; + } else { + return null; + } }; $jsilcore.$CompareSinglecastDelegate = function (lhs, rhs) { - if (lhs.__object__ !== rhs.__object__) - return false; + if (lhs.__object__ !== rhs.__object__) + return false; - if (lhs.__method__ !== rhs.__method__) - return false; + if (lhs.__method__ !== rhs.__method__) + return false; - return true; + return true; }; $jsilcore.$CompareMulticastDelegate = function (lhs, rhs) { - var lhsInvocationList = $jsilcore.$GetInvocationList(lhs); - var rhsInvocationList = $jsilcore.$GetInvocationList(rhs); + var lhsInvocationList = $jsilcore.$GetInvocationList(lhs); + var rhsInvocationList = $jsilcore.$GetInvocationList(rhs); - if (lhsInvocationList.length !== rhsInvocationList.length) - return false; + if (lhsInvocationList.length !== rhsInvocationList.length) + return false; - for (var i = 0, l = lhsInvocationList.length; i < l; i++) { - if (!$jsilcore.$AreDelegatesEqual(lhsInvocationList[i], rhsInvocationList[i])) - return false; - } + for (var i = 0, l = lhsInvocationList.length; i < l; i++) { + if (!$jsilcore.$AreDelegatesEqual(lhsInvocationList[i], rhsInvocationList[i])) + return false; + } - return true; + return true; }; $jsilcore.$AreDelegatesEqual = function (lhs, rhs) { - if (lhs === rhs) - return true; + if (lhs === rhs) + return true; - var singleMethod, otherMethod; - if (!lhs.__isMulticast__) - return $jsilcore.$CompareSinglecastDelegate(lhs, rhs); - else if (!rhs.__isMulticast__) - return $jsilcore.$CompareSinglecastDelegate(rhs, lhs); - else - return $jsilcore.$CompareMulticastDelegate(lhs, rhs); + var singleMethod, otherMethod; + if (!lhs.__isMulticast__) + return $jsilcore.$CompareSinglecastDelegate(lhs, rhs); + else if (!rhs.__isMulticast__) + return $jsilcore.$CompareSinglecastDelegate(rhs, lhs); + else + return $jsilcore.$CompareMulticastDelegate(lhs, rhs); }; $jsilcore.$CombineDelegates = function (lhs, rhs) { - if (rhs === null) { - return lhs; - } else if (lhs === null) { - return rhs; - } + if (rhs === null) { + return lhs; + } else if (lhs === null) { + return rhs; + } - var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); - newList.push.apply(newList, $jsilcore.$GetInvocationList(rhs)); - var result = JSIL.MulticastDelegate.New(newList); - return result; + var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); + newList.push.apply(newList, $jsilcore.$GetInvocationList(rhs)); + var result = JSIL.MulticastDelegate.New(newList); + return result; }; $jsilcore.$RemoveDelegate = function (lhs, rhs) { - if (rhs === null) - return lhs; - if (lhs === null) - return null; - - var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); - - for (var i = 0; i < newList.length; i++) { - var item = newList[i]; - if ($jsilcore.$AreDelegatesEqual(item, rhs)) { - newList.splice(i, 1); - break; + if (rhs === null) + return lhs; + if (lhs === null) + return null; + + var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); + + for (var i = 0; i < newList.length; i++) { + var item = newList[i]; + if ($jsilcore.$AreDelegatesEqual(item, rhs)) { + newList.splice(i, 1); + break; + } } - } - if (newList.length == 0) - return null; - else if (newList.length == 1) - return newList[0]; - else - return JSIL.MulticastDelegate.New(newList); + if (newList.length == 0) + return null; + else if (newList.length == 1) + return newList[0]; + else + return JSIL.MulticastDelegate.New(newList); }; JSIL.ImplementExternals("System.Delegate", function ($) { - var tDelegate = $jsilcore.TypeRef("System.Delegate"); + var tDelegate = $jsilcore.TypeRef("System.Delegate"); + + $.RawMethod(false, "Invoke", function () { + return this.__method__.apply(this.__object__, arguments); + }); - $.RawMethod(false, "Invoke", function () { - return this.__method__.apply(this.__object__, arguments); - }); + $.Method({ Static: false, Public: true }, "GetInvocationList", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [tDelegate]), [], [])), + function GetInvocationList() { + return [this]; + } + ); - $.Method({Static:false, Public:true }, "GetInvocationList", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [tDelegate]), [], [])), - function GetInvocationList () { - return [ this ]; - } - ); + $.Method({ Static: true, Public: true }, "CreateDelegate", + (new JSIL.MethodSignature(tDelegate, [ + $jsilcore.TypeRef("System.Type"), $.Object, + $jsilcore.TypeRef("System.Reflection.MethodInfo") + ], [])), + function CreateDelegate(delegateType, firstArgument, method) { + var impl = JSIL.$GetMethodImplementation(method); - $.Method({Static:true , Public:true }, "CreateDelegate", - (new JSIL.MethodSignature(tDelegate, [ - $jsilcore.TypeRef("System.Type"), $.Object, - $jsilcore.TypeRef("System.Reflection.MethodInfo") - ], [])), - function CreateDelegate (delegateType, firstArgument, method) { - var impl = JSIL.$GetMethodImplementation(method); + if (typeof (impl) !== "function") + throw new System.Exception("Failed to bind delegate"); - if (typeof (impl) !== "function") - throw new System.Exception("Failed to bind delegate"); + var delegatePublicInterface = delegateType.__PublicInterface__; - var delegatePublicInterface = delegateType.__PublicInterface__; + if (typeof (delegatePublicInterface.New) !== "function") { + JSIL.Host.abort(new Error("Invalid delegate type")); + } - if (typeof (delegatePublicInterface.New) !== "function") { - JSIL.Host.abort(new Error("Invalid delegate type")); + return delegatePublicInterface.New(firstArgument, impl); } + ); - return delegatePublicInterface.New(firstArgument, impl); - } - ); - - $.Method({Static:true , Public:true }, "op_Equality", - (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), - $jsilcore.$AreDelegatesEqual - ); + $.Method({ Static: true, Public: true }, "op_Equality", + (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), + $jsilcore.$AreDelegatesEqual + ); - $.Method({Static:true , Public:true }, "op_Inequality", - (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), - function op_Inequality (d1, d2) { - return !$jsilcore.$AreDelegatesEqual(d1, d2); - } - ); + $.Method({ Static: true, Public: true }, "op_Inequality", + (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), + function op_Inequality(d1, d2) { + return !$jsilcore.$AreDelegatesEqual(d1, d2); + } + ); - $.Method({Static:true , Public:true }, "Combine", - (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), - $jsilcore.$CombineDelegates - ); + $.Method({ Static: true, Public: true }, "Combine", + (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), + $jsilcore.$CombineDelegates + ); - $.Method({Static:true , Public:true }, "Remove", - (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), - $jsilcore.$RemoveDelegate - ); + $.Method({ Static: true, Public: true }, "Remove", + (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), + $jsilcore.$RemoveDelegate + ); }); JSIL.ImplementExternals("System.MulticastDelegate", function ($) { - $.RawMethod(false, "Invoke", function () { - return this.apply(null, arguments); - }); - - $.Method({Static:false, Public:true }, "GetInvocationList", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Delegate")]), [], [])), - function GetInvocationList () { - return this.__delegates__; - } - ); + $.RawMethod(false, "Invoke", function () { + return this.apply(null, arguments); + }); + + $.Method({ Static: false, Public: true }, "GetInvocationList", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Delegate")]), [], [])), + function GetInvocationList() { + return this.__delegates__; + } + ); }); JSIL.MakeClass("System.Object", "System.Delegate", true, []); JSIL.MakeClass("System.Object", "System.MulticastDelegate", true, []); JSIL.MulticastDelegate.New = function (delegates) { - var delegatesCopy = Array.prototype.slice.call(delegates); - var delegateCount = delegates.length; + var delegatesCopy = Array.prototype.slice.call(delegates); + var delegateCount = delegates.length; - var resultDelegate = function MulticastDelegate_Invoke () { - var result; + var resultDelegate = function MulticastDelegate_Invoke() { + var result; - for (var i = 0; i < delegateCount; i++) { - var d = delegatesCopy[i]; - // FIXME: bind, call and apply suck - result = d.apply(d.__object__ || null, arguments); - } + for (var i = 0; i < delegateCount; i++) { + var d = delegatesCopy[i]; + // FIXME: bind, call and apply suck + result = d.apply(d.__object__ || null, arguments); + } - return result; - }; + return result; + }; - JSIL.SetValueProperty(resultDelegate, "__delegates__", delegatesCopy); - JSIL.SetValueProperty(resultDelegate, "__isMulticast__", true); - JSIL.SetValueProperty(resultDelegate, "__ThisType__", delegates[0].__ThisType__); - JSIL.SetValueProperty(resultDelegate, "toString", delegates[0].toString); + JSIL.SetValueProperty(resultDelegate, "__delegates__", delegatesCopy); + JSIL.SetValueProperty(resultDelegate, "__isMulticast__", true); + JSIL.SetValueProperty(resultDelegate, "__ThisType__", delegates[0].__ThisType__); + JSIL.SetValueProperty(resultDelegate, "toString", delegates[0].toString); - return resultDelegate; + return resultDelegate; }; JSIL.MakeDelegate("System.Action", true, []); @@ -476,153 +476,153 @@ JSIL.MakeDelegate("System.Func`4", true, ["T1", "T2", "T3", "TResult"]); JSIL.ImplementExternals( "System.Exception", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - function captureStackTrace () { - var e = new Error(); - var stackText = e.stack || ""; - return stackText; - }; + function captureStackTrace() { + var e = new Error(); + var stackText = e.stack || ""; + return stackText; + }; - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this._message = null; - this._stackTrace = captureStackTrace(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this._message = null; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String], [])), - function _ctor (message) { - this._message = message; - this._stackTrace = captureStackTrace(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String], [])), + function _ctor(message) { + this._message = message; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String, mscorlib.TypeRef("System.Exception")], [])), - function _ctor (message, innerException) { - this._message = message; - this._innerException = innerException; - this._stackTrace = captureStackTrace(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String, mscorlib.TypeRef("System.Exception")], [])), + function _ctor(message, innerException) { + this._message = message; + this._innerException = innerException; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({Static:false, Public:true }, "get_InnerException", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Exception"), [], [])), - function get_InnerException () { - return this._innerException; - } - ); + $.Method({ Static: false, Public: true }, "get_InnerException", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Exception"), [], [])), + function get_InnerException() { + return this._innerException; + } + ); - $.Method({Static: false, Public: true }, "get_Message", - new JSIL.MethodSignature($.String, []), - function () { - if ((typeof (this._message) === "undefined") || (this._message === null)) - return System.String.Format("Exception of type '{0}' was thrown.", JSIL.GetTypeName(this)); - else - return this._message; - } - ); + $.Method({ Static: false, Public: true }, "get_Message", + new JSIL.MethodSignature($.String, []), + function () { + if ((typeof (this._message) === "undefined") || (this._message === null)) + return System.String.Format("Exception of type '{0}' was thrown.", JSIL.GetTypeName(this)); + else + return this._message; + } + ); - $.Method({Static: false, Public: true }, "get_StackTrace", - new JSIL.MethodSignature($.String, []), - function () { - return this._stackTrace || ""; - } - ); + $.Method({ Static: false, Public: true }, "get_StackTrace", + new JSIL.MethodSignature($.String, []), + function () { + return this._stackTrace || ""; + } + ); - $.Method({Static: false, Public: true }, "toString", - new JSIL.MethodSignature($.String, []), - function () { - var message = this.Message; - var result = System.String.Format("{0}: {1}", JSIL.GetTypeName(this), message); + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature($.String, []), + function () { + var message = this.Message; + var result = System.String.Format("{0}: {1}", JSIL.GetTypeName(this), message); - if (this._innerException) { - result += "\n-- Inner exception follows --\n"; - result += this._innerException.toString(); - } + if (this._innerException) { + result += "\n-- Inner exception follows --\n"; + result += this._innerException.toString(); + } - return result; - } - ); + return result; + } + ); } ); JSIL.ImplementExternals( "System.SystemException", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [], []), - function () { - System.Exception.prototype._ctor.call(this); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [], []), + function () { + System.Exception.prototype._ctor.call(this); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( - "System.InvalidCastException", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + "System.InvalidCastException", function ($) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( - "System.InvalidOperationException", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + "System.InvalidOperationException", function ($) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( - "System.IO.FileNotFoundException", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + "System.IO.FileNotFoundException", function ($) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String, $.String], [])), - function _ctor (message, fileName) { - System.Exception.prototype._ctor.call(this, message); - this._fileName = fileName; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String, $.String], [])), + function _ctor(message, fileName) { + System.Exception.prototype._ctor.call(this, message); + this._fileName = fileName; + } + ); } ); JSIL.ImplementExternals( - "System.FormatException", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + "System.FormatException", function ($) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.MakeClass("System.Object", "System.Exception", true, [], function ($) { - $.Property({Public: true , Static: false, Virtual: true }, "Message"); - $.Property({Public: true , Static: false}, "InnerException"); + $.Property({ Public: true, Static: false, Virtual: true }, "Message"); + $.Property({ Public: true, Static: false }, "InnerException"); }); JSIL.MakeClass("System.Exception", "System.SystemException", true); @@ -646,2267 +646,2232 @@ JSIL.MakeClass("System.SystemException", "System.ArithmeticException", true); JSIL.MakeClass("System.ArithmeticException", "System.OverflowException", true); JSIL.ImplementExternals("System.Console", function ($) { - $.RawMethod(true, "WriteLine", function () { - var text = ""; - if ((arguments.length > 0) && (arguments[0] !== null)) { - text = System.String.Format.apply(System.String, arguments); - } + $.RawMethod(true, "WriteLine", function () { + var text = ""; + if ((arguments.length > 0) && (arguments[0] !== null)) { + text = System.String.Format.apply(System.String, arguments); + } - JSIL.Host.logWriteLine(text); - }); + JSIL.Host.logWriteLine(text); + }); - $.RawMethod(true, "Write", function () { - var text = ""; - if ((arguments.length > 0) && (arguments[0] !== null)) { - text = System.String.Format.apply(System.String, arguments); - } + $.RawMethod(true, "Write", function () { + var text = ""; + if ((arguments.length > 0) && (arguments[0] !== null)) { + text = System.String.Format.apply(System.String, arguments); + } - JSIL.Host.logWrite(text); - }); + JSIL.Host.logWrite(text); + }); }); JSIL.ImplementExternals( "System.Diagnostics.Debug", function ($) { - $.Method({Static:true , Public:true }, "WriteLine", - (new JSIL.MethodSignature(null, [$.String], [])), - function WriteLine (message) { - JSIL.Host.logWriteLine(message); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + (new JSIL.MethodSignature(null, [$.String], [])), + function WriteLine(message) { + JSIL.Host.logWriteLine(message); + } + ); - $.Method({Static:true , Public:true }, "Write", - (new JSIL.MethodSignature(null, [$.String], [])), - function Write (message) { - JSIL.Host.logWrite(message); - } - ); + $.Method({ Static: true, Public: true }, "Write", + (new JSIL.MethodSignature(null, [$.String], [])), + function Write(message) { + JSIL.Host.logWrite(message); + } + ); } ); JSIL.MakeStaticClass("System.Console", true, [], function ($) { - $.Property({Static: true, Public: true}, "In"); - $.Property({Static: true, Public: true}, "Out"); + $.Property({ Static: true, Public: true }, "In"); + $.Property({ Static: true, Public: true }, "Out"); }); JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($) { - $.RawMethod(false, "__CopyMembers__", - function ArrayEnumerator_CopyMembers (source, target) { - target._array = source._array; - target._length = source._length; - target._index = source._index; - } - ); + $.RawMethod(false, "__CopyMembers__", + function ArrayEnumerator_CopyMembers(source, target) { + target._array = source._array; + target._length = source._length; + target._index = source._index; + } + ); - $.Method({Public: true , Static: false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32]), - function (array, startPosition) { - this._array = array; - this._length = array.length; - if (typeof (startPosition) !== "number") - JSIL.RuntimeError("ArrayEnumerator ctor second argument must be number"); + $.Method({ Public: true, Static: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32]), + function (array, startPosition) { + this._array = array; + this._length = array.length; + if (typeof (startPosition) !== "number") + JSIL.RuntimeError("ArrayEnumerator ctor second argument must be number"); - this._index = startPosition; - } - ); + this._index = startPosition; + } + ); - $.Method({Public: true , Static: false}, "Reset", - new JSIL.MethodSignature(null, []), - function () { - if (this._array === null) - JSIL.RuntimeError("Enumerator is disposed or not initialized"); + $.Method({ Public: true, Static: false }, "Reset", + new JSIL.MethodSignature(null, []), + function () { + if (this._array === null) + JSIL.RuntimeError("Enumerator is disposed or not initialized"); - this._index = -1; - } - ); - $.Method({Public: true , Static: false}, "MoveNext", - new JSIL.MethodSignature(System.Boolean, []), - function () { - return (++this._index < this._length); - } - ); - $.Method({Public: true , Static: false}, "Dispose", - new JSIL.MethodSignature(null, []), - function () { - this._array = null; - this._index = 0; - this._length = -1; - } - ); - $.Method({Public: true , Static: false}, "get_Current", - new JSIL.MethodSignature(System.Object, []), - function () { - return this._array[this._index]; - } - ); + this._index = -1; + } + ); + $.Method({ Public: true, Static: false }, "MoveNext", + new JSIL.MethodSignature(System.Boolean, []), + function () { + return (++this._index < this._length); + } + ); + $.Method({ Public: true, Static: false }, "Dispose", + new JSIL.MethodSignature(null, []), + function () { + this._array = null; + this._index = 0; + this._length = -1; + } + ); + $.Method({ Public: true, Static: false }, "get_Current", + new JSIL.MethodSignature(System.Object, []), + function () { + return this._array[this._index]; + } + ); - $.Property({Public: true , Static: false, Virtual: true }, "Current"); + $.Property({ Public: true, Static: false, Virtual: true }, "Current"); - $.ImplementInterfaces( - System.IDisposable, System.Collections.IEnumerator, - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) - ); + $.ImplementInterfaces( + System.IDisposable, System.Collections.IEnumerator, + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) + ); }); JSIL.MakeClass("System.Object", "JSIL.ArrayInterfaceOverlay", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.ArrayInterfaceOverlay"); + var T = new JSIL.GenericParameter("T", "JSIL.ArrayInterfaceOverlay"); - $.RawMethod(false, ".ctor", - function (array) { - this._array = array; - } - ); + $.RawMethod(false, ".ctor", + function (array) { + this._array = array; + } + ); - $.RawMethod(false, "$overlayToArray", - function (T) { - // We don't want to allow conversion to an unrelated array type. - // FIXME: Covariance? Contravariance? - if (T.__IsArray__ && (T.__ElementType__ === this.T)) - return this._array; - else - return null; - } - ); + $.RawMethod(false, "$overlayToArray", + function (T) { + // We don't want to allow conversion to an unrelated array type. + // FIXME: Covariance? Contravariance? + if (T.__IsArray__ && (T.__ElementType__ === this.T)) + return this._array; + else + return null; + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function () { - return JSIL.GetEnumerator(this._array, this.T); - } - ) - .Overrides(0, "GetEnumerator"); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function () { + return JSIL.GetEnumerator(this._array, this.T); + } + ) + .Overrides(0, "GetEnumerator"); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), - function () { - return JSIL.GetEnumerator(this._array, this.T); - } - ) - .Overrides(1, "GetEnumerator"); - - // FIXME: Implement actual members of IList. - - $.Method({Static:false, Public:true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), - function CopyTo (array, arrayIndex) { - JSIL.Array.CopyTo(this._array, array, arrayIndex); - } - ); - - $.Method({Static:false, Public:true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count () { - return this._array.length; - } - ); - - $.Method({Static:false, Public:true }, "get_Item", - new JSIL.MethodSignature(T, [$.Int32], []), - function get_Item (index) { - return this._array[index]; - } - ); - - $.Method({Static:false, Public:true }, "set_Item", - new JSIL.MethodSignature(null, [$.Int32, T], []), - function set_Item (index, value) { - this._array[index] = value; - } - ); - - $.Method({Static:false, Public:true }, "Contains", - new JSIL.MethodSignature($.Boolean, [T], []), - function Contains (value) { - return (this._array.indexOf(value) >= 0); - } - ); - - $.Method({Static:false, Public:true }, "IndexOf", - new JSIL.MethodSignature($.Int32, [T], []), - function IndexOf (value) { - return this._array.indexOf(value); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), + function () { + return JSIL.GetEnumerator(this._array, this.T); + } + ) + .Overrides(1, "GetEnumerator"); - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), - /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), - /* 2 */ $jsilcore.TypeRef("System.Collections.ICollection"), - /* 3 */ $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [T]), - /* 4 */ $jsilcore.TypeRef("System.Collections.IList"), - /* 5 */ $jsilcore.TypeRef("System.Collections.Generic.IList`1", [T]) - ); -}); + // FIXME: Implement actual members of IList. -JSIL.ImplementExternals( - "System.Threading.Thread", function ($) { - $.Method({Static:true , Public:true }, ".cctor2", - (new JSIL.MethodSignature(null, [], [])), - function () { - // This type already has a cctor, so we add a second one. - System.Threading.Thread._currentThread = JSIL.CreateInstanceOfType( - System.Threading.Thread.__Type__, - null - ); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), + function CopyTo(array, arrayIndex) { + JSIL.Array.CopyTo(this._array, array, arrayIndex); } ); - $.Method({Static:true , Public:true }, "get_CurrentThread", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Thread"), [], [])), - function get_CurrentThread () { - return System.Threading.Thread._currentThread; + $.Method({ Static: false, Public: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this._array.length; } ); - $.Method({Static:false, Public:true }, "get_ManagedThreadId", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_ManagedThreadId () { - return 0; + $.Method({ Static: false, Public: true }, "get_Item", + new JSIL.MethodSignature(T, [$.Int32], []), + function get_Item(index) { + return this._array[index]; + } + ); + + $.Method({ Static: false, Public: true }, "set_Item", + new JSIL.MethodSignature(null, [$.Int32, T], []), + function set_Item(index, value) { + this._array[index] = value; + } + ); + + $.Method({ Static: false, Public: true }, "Contains", + new JSIL.MethodSignature($.Boolean, [T], []), + function Contains(value) { + return (this._array.indexOf(value) >= 0); + } + ); + + $.Method({ Static: false, Public: true }, "IndexOf", + new JSIL.MethodSignature($.Int32, [T], []), + function IndexOf(value) { + return this._array.indexOf(value); } ); + + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), + /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), + /* 2 */ $jsilcore.TypeRef("System.Collections.ICollection"), + /* 3 */ $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [T]), + /* 4 */ $jsilcore.TypeRef("System.Collections.IList"), + /* 5 */ $jsilcore.TypeRef("System.Collections.Generic.IList`1", [T]) + ); +}); + +JSIL.ImplementExternals( + "System.Threading.Thread", function ($) { + $.Method({ Static: true, Public: true }, ".cctor2", + (new JSIL.MethodSignature(null, [], [])), + function () { + // This type already has a cctor, so we add a second one. + System.Threading.Thread._currentThread = JSIL.CreateInstanceOfType( + System.Threading.Thread.__Type__, + null + ); + } + ); + + $.Method({ Static: true, Public: true }, "get_CurrentThread", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Thread"), [], [])), + function get_CurrentThread() { + return System.Threading.Thread._currentThread; + } + ); + + $.Method({ Static: false, Public: true }, "get_ManagedThreadId", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_ManagedThreadId() { + return 0; + } + ); } ); JSIL.MakeClass("System.Object", "System.Threading.Thread", true, [], function ($) { - $.Field({Public: false, Static: true}, "_currentThread", $.Type, function ($) { return null; }); + $.Field({ Public: false, Static: true }, "_currentThread", $.Type, function ($) { return null; }); - $.ExternalMethod( - {Public: true , Static: true }, "get_CurrentThread", - new JSIL.MethodSignature($.Type, []) - ); - $.ExternalMethod( - {Public: true , Static: true }, "get_ManagedThreadId", - new JSIL.MethodSignature(System.Int32, []) - ); + $.ExternalMethod( + { Public: true, Static: true }, "get_CurrentThread", + new JSIL.MethodSignature($.Type, []) + ); + $.ExternalMethod( + { Public: true, Static: true }, "get_ManagedThreadId", + new JSIL.MethodSignature(System.Int32, []) + ); - $.Property({Public: true , Static: true }, "CurrentThread"); - $.Property({Public: true , Static: true }, "ManagedThreadId"); + $.Property({ Public: true, Static: true }, "CurrentThread"); + $.Property({ Public: true, Static: true }, "ManagedThreadId"); }); $jsilcore.InitResizableArray = function (target, elementType, initialSize) { - target._items = new Array(); + target._items = new Array(); }; $jsilcore.$ListExternals = function ($, T, type) { - var mscorlib = JSIL.GetCorlib(); - - if (typeof (T) === "undefined") - JSIL.RuntimeError("Invalid use of $ListExternals"); + var mscorlib = JSIL.GetCorlib(); - var getT; + if (typeof (T) === "undefined") + JSIL.RuntimeError("Invalid use of $ListExternals"); - switch (type) { - case "ArrayList": - case "ObjectCollection": - getT = function () { return System.Object; } - break; - default: - getT = function (self) { return self.T; } - break; - } + var getT; - var indexOfImpl = function List_IndexOf (value) { - for (var i = 0, l = this._size; i < l; i++) { - if (JSIL.ObjectEquals(this._items[i], value)) - return i; + switch (type) { + case "ArrayList": + case "ObjectCollection": + getT = function () { return System.Object; } + break; + default: + getT = function (self) { return self.T; } + break; } - return -1; - }; + var indexOfImpl = function List_IndexOf(value) { + for (var i = 0, l = this._size; i < l; i++) { + if (JSIL.ObjectEquals(this._items[i], value)) + return i; + } + + return -1; + }; - var findIndexImpl = function List_FindIndex (predicate) { - for (var i = 0, l = this._size; i < l; i++) { - if (predicate(this._items[i])) - return i; - } + var findIndexImpl = function List_FindIndex(predicate) { + for (var i = 0, l = this._size; i < l; i++) { + if (predicate(this._items[i])) + return i; + } - return -1; - }; + return -1; + }; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [], []), - function () { - $jsilcore.InitResizableArray(this, getT(this), 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [], []), + function () { + $jsilcore.InitResizableArray(this, getT(this), 16); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (size) { - $jsilcore.InitResizableArray(this, getT(this), size); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (size) { + $jsilcore.InitResizableArray(this, getT(this), size); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), - function (values) { - this._items = JSIL.EnumerableToArray(values); - this._capacity = this._items.length; - this._size = this._items.length; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), + function (values) { + this._items = JSIL.EnumerableToArray(values); + this._capacity = this._items.length; + this._size = this._items.length; + } + ); - var addImpl = function (item) { - this.InsertItem(this._size, item); - return this._size; - }; - - switch (type) { - case "ArrayList": - case "ObjectCollection": - $.Method({Static:false, Public:true }, "Add", - new JSIL.MethodSignature($.Int32, [T], []), - addImpl - ); - break; - default: - $.Method({Static:false, Public:true }, "Add", - new JSIL.MethodSignature(null, [T], []), - addImpl - ); - break; - } + var addImpl = function (item) { + this.InsertItem(this._size, item); + return this._size; + }; - $.Method({Static:false, Public:true }, "AddRange", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), - function (items) { - var e = JSIL.GetEnumerator(items, this.T); - var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; - var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; - try { - while (moveNext.Call(e)) - this.Add(getCurrent.Call(e)); - } finally { - JSIL.Dispose(e); + switch (type) { + case "ArrayList": + case "ObjectCollection": + $.Method({ Static: false, Public: true }, "Add", + new JSIL.MethodSignature($.Int32, [T], []), + addImpl + ); + break; + default: + $.Method({ Static: false, Public: true }, "Add", + new JSIL.MethodSignature(null, [T], []), + addImpl + ); + break; + } + + $.Method({ Static: false, Public: true }, "AddRange", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), + function (items) { + var e = JSIL.GetEnumerator(items, this.T); + var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; + var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; + try { + while (moveNext.Call(e)) + this.Add(getCurrent.Call(e)); + } finally { + JSIL.Dispose(e); + } } - } - ); + ); - $.Method({Static:false, Public:true }, "AsReadOnly", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.ObjectModel.ReadOnlyCollection`1", [T]), [], []), - function () { - // FIXME - if (typeof (this.tReadOnlyCollection) === "undefined") { - this.tReadOnlyCollection = System.Collections.ObjectModel.ReadOnlyCollection$b1.Of(this.T).__Type__; + $.Method({ Static: false, Public: true }, "AsReadOnly", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.ObjectModel.ReadOnlyCollection`1", [T]), [], []), + function () { + // FIXME + if (typeof (this.tReadOnlyCollection) === "undefined") { + this.tReadOnlyCollection = System.Collections.ObjectModel.ReadOnlyCollection$b1.Of(this.T).__Type__; + } + + return JSIL.CreateInstanceOfType(this.tReadOnlyCollection, "$listCtor", [this]); } + ); - return JSIL.CreateInstanceOfType(this.tReadOnlyCollection , "$listCtor", [this]); - } - ); + $.Method({ Static: false, Public: true }, "Clear", + new JSIL.MethodSignature(null, [], []), + function () { + this.ClearItems(); + } + ); - $.Method({Static:false, Public:true }, "Clear", - new JSIL.MethodSignature(null, [], []), - function () { - this.ClearItems(); - } - ); + $.Method({ Static: false, Public: true }, "set_Capacity", + new JSIL.MethodSignature(null, [$.Int32], []), + function List_set_Capacity(value) { + // FIXME + return; + } + ); - $.Method({Static:false, Public:true }, "set_Capacity", - new JSIL.MethodSignature(null, [$.Int32], []), - function List_set_Capacity (value) { - // FIXME - return; - } - ); + $.Method({ Static: false, Public: true }, "Contains", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), + function List_Contains(value) { + return this.IndexOf(value) >= 0; + } + ); - $.Method({Static:false, Public:true }, "Contains", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), - function List_Contains (value) { - return this.IndexOf(value) >= 0; - } - ); + $.Method({ Static: false, Public: true }, "Exists", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function List_Exists(predicate) { + return this.FindIndex(predicate) >= 0; + } + ); - $.Method({Static:false, Public:true }, "Exists", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function List_Exists (predicate) { - return this.FindIndex(predicate) >= 0; - } - ); + $.Method({ Static: false, Public: true }, "ForEach", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Action`1", [T])], []), + function ForEach(action) { + for (var i = 0, sz = this._size; i < sz; i++) { + var item = this._items[i]; - $.Method({Static:false, Public:true }, "ForEach", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Action`1", [T])], []), - function ForEach (action) { - for (var i = 0, sz = this._size; i < sz; i++) { - var item = this._items[i]; + action(item); + } + } + ); - action(item); + $.Method({ Static: false, Public: true }, "Find", + new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function List_Find(predicate) { + var index = this.FindIndex(predicate); + if (index >= 0) + return this._items[index]; + else + return JSIL.DefaultValue(this.T); } - } - ); + ); - $.Method({Static:false, Public:true }, "Find", - new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function List_Find (predicate) { - var index = this.FindIndex(predicate); - if (index >= 0) - return this._items[index]; - else - return JSIL.DefaultValue(this.T); - } - ); + $.Method({ Static: false, Public: true }, "FindAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1", [T]), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function FindAll(predicate) { + var thisType = this.GetType(); - $.Method({Static:false, Public:true }, "FindAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1", [T]), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function (predicate) { - var thisType = this.GetType(); + // Manually initialize the result since we don't want to hassle with overloaded ctors + var result = JSIL.CreateInstanceOfType(thisType, null); + result._items = []; - // Manually initialize the result since we don't want to hassle with overloaded ctors - var result = JSIL.CreateInstanceOfType(thisType, null); - result._items = []; + for (var i = 0, sz = this._size; i < sz; i++) { + var item = this._items[i]; - for (var i = 0, sz = this._size; i < sz; i++) { - var item = this._items[i]; + if (predicate(item)) + result._items.push(item); + } - if (predicate(item)) - result._items.push(item); + result._capacity = result._size = result._items.length; + return result; } + ); - result._capacity = result._size = result._items.length; - return result; - } - ); - - $.Method({Static:false, Public:true }, "FindIndex", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - findIndexImpl - ); - - $.Method({Static:false, Public:true }, "get_Capacity", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), - function () { - return this._items.length; - } - ); + $.Method({ Static: false, Public: true }, "FindIndex", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + findIndexImpl + ); - $.Method({Static:false, Public:true }, "get_Count", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), - function () { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Capacity", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), + function () { + return this._items.length; + } + ); - var rangeCheckImpl = function (index, size) { - return (index >= 0) && (size > index); - } + $.Method({ Static: false, Public: true }, "get_Count", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), + function () { + return this._size; + } + ); - $.Method({Static:false, Public:true }, "get_Item", - new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Int32")], []), - function (index) { - if (rangeCheckImpl(index, this._size)) - return this._items[index]; - else - throw new System.ArgumentOutOfRangeException("index"); + var rangeCheckImpl = function (index, size) { + return (index >= 0) && (size > index); } - ); - $.Method({Static: false, Public: true }, "set_Item", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), T], []), - function (index, value) { - if (rangeCheckImpl(index, this._size)) - this.SetItem(index, value); - else - throw new System.ArgumentOutOfRangeException("index"); - } - ); + $.Method({ Static: false, Public: true }, "get_Item", + new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Int32")], []), + function (index) { + if (rangeCheckImpl(index, this._size)) + return this._items[index]; + else + throw new System.ArgumentOutOfRangeException("index"); + } + ); - var getEnumeratorType = function (self) { - if (self.$enumeratorType) - return self.$enumeratorType; + $.Method({ Static: false, Public: true }, "set_Item", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), T], []), + function (index, value) { + if (rangeCheckImpl(index, this._size)) + this.SetItem(index, value); + else + throw new System.ArgumentOutOfRangeException("index"); + } + ); - var T = getT(self); - return self.$enumeratorType = System.Collections.Generic.List$b1_Enumerator.Of(T); - }; + var getEnumeratorType = function (self) { + if (self.$enumeratorType) + return self.$enumeratorType; - var getEnumeratorImpl = function () { - var enumeratorType = getEnumeratorType(this); + var T = getT(self); + return self.$enumeratorType = System.Collections.Generic.List$b1_Enumerator.Of(T); + }; - return new enumeratorType(this); - }; + var getEnumeratorImpl = function () { + var enumeratorType = getEnumeratorType(this); - switch (type) { - case "List": - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1/Enumerator", [T]), [], [])), - getEnumeratorImpl - ); - break; - } + return new enumeratorType(this); + }; - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], []), - getEnumeratorImpl - ) - .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + switch (type) { + case "List": + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1+Enumerator", [T]), [], [])), + getEnumeratorImpl + ); + break; + } - if (type !== "ArrayList") { - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], []), getEnumeratorImpl ) - .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); - } - - $.RawMethod(false, "$GetEnumerator", getEnumeratorImpl); + .Overrides("System.Collections.IEnumerable", "GetEnumerator"); - $.Method({Static:false, Public:true }, "Insert", - (new JSIL.MethodSignature(null, [$.Int32, T], [])), - function Insert (index, item) { - this.InsertItem(index, item); + if (type !== "ArrayList") { + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), + getEnumeratorImpl + ) + .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); } - ); - $.Method({Static:false, Public:true }, "IndexOf", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [T], []), - indexOfImpl - ); + $.RawMethod(false, "$GetEnumerator", getEnumeratorImpl); - var removeImpl = function (item) { - var index = this._items.indexOf(item); - if (index === -1) - return false; + $.Method({ Static: false, Public: true }, "Insert", + (new JSIL.MethodSignature(null, [$.Int32, T], [])), + function Insert(index, item) { + this.InsertItem(index, item); + } + ); - this.RemoveAt(index); - return true; - }; - - switch (type) { - case "ArrayList": - case "ObjectCollection": - $.Method({Static:false, Public:true }, "Remove", - new JSIL.MethodSignature(null, [T], []), - removeImpl - ); - break; - default: - $.Method({Static:false, Public:true }, "Remove", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), - removeImpl - ); - break; - } + $.Method({ Static: false, Public: true }, "IndexOf", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [T], []), + indexOfImpl + ); + + var removeImpl = function (item) { + var index = this._items.indexOf(item); + if (index === -1) + return false; - $.Method({Static:false, Public:true }, "RemoveAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function (predicate) { - var result = 0; + this.RemoveAt(index); + return true; + }; - for (var i = 0; i < this._size; i++) { - var item = this._items[i]; + switch (type) { + case "ArrayList": + case "ObjectCollection": + $.Method({ Static: false, Public: true }, "Remove", + new JSIL.MethodSignature(null, [T], []), + removeImpl + ); + break; + default: + $.Method({ Static: false, Public: true }, "Remove", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), + removeImpl + ); + break; + } + + $.Method({ Static: false, Public: true }, "RemoveAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function (predicate) { + var result = 0; + + for (var i = 0; i < this._size; i++) { + var item = this._items[i]; + + if (predicate(item)) { + this.RemoveItem(i); + i -= 1; + result += 1; + } + } - if (predicate(item)) { - this.RemoveItem(i); - i -= 1; - result += 1; - } + return result; } + ); - return result; - } - ); + $.Method({ Static: false, Public: true }, "RemoveAt", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (index) { + if (!rangeCheckImpl(index, this._size)) + throw new System.ArgumentOutOfRangeException("index"); - $.Method({Static:false, Public:true }, "RemoveAt", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (index) { - if (!rangeCheckImpl(index, this._size)) - throw new System.ArgumentOutOfRangeException("index"); + this.RemoveItem(index); + } + ); - this.RemoveItem(index); - } - ); + $.Method({ Static: false, Public: true }, "RemoveRange", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (index, count) { + if (index < 0) + throw new System.ArgumentOutOfRangeException("index"); + else if (count < 0) + throw new System.ArgumentOutOfRangeException("count"); + else if (!rangeCheckImpl(index, this._size)) + throw new System.ArgumentException(); + else if (!rangeCheckImpl(index + count - 1, this._size)) + throw new System.ArgumentException(); + + this._items.splice(index, count); + this._size -= count; + } + ); - $.Method({Static:false, Public:true }, "RemoveRange", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (index, count) { - if (index < 0) - throw new System.ArgumentOutOfRangeException("index"); - else if (count < 0) - throw new System.ArgumentOutOfRangeException("count"); - else if (!rangeCheckImpl(index, this._size)) - throw new System.ArgumentException(); - else if (!rangeCheckImpl(index + count - 1, this._size)) - throw new System.ArgumentException(); - - this._items.splice(index, count); - this._size -= count; - } - ); + $.Method({ Static: false, Public: true }, "Sort", + new JSIL.MethodSignature(null, [], []), + function () { + this._items.sort(JSIL.CompareValues); + } + ); - $.Method({Static:false, Public:true }, "Sort", - new JSIL.MethodSignature(null, [], []), - function () { - this._items.sort(JSIL.CompareValues); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Comparison`1", [T])], []), + function (comparison) { + this._items.sort(comparison); + } + ); - $.Method({Static:false, Public:true }, "Sort", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Comparison`1", [T])], []), - function (comparison) { - this._items.sort(comparison); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.IComparer")], [])), + function Sort(comparer) { + this._items.sort(function (lhs, rhs) { + return comparer.Compare(lhs, rhs); + }); + } + ); - $.Method({Static:false, Public:true }, "Sort", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.IComparer")], [])), - function Sort (comparer) { - this._items.sort(function (lhs, rhs) { - return comparer.Compare(lhs, rhs); - }); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T])], [])), + function Sort(comparer) { + var tComparer = System.Collections.Generic.IComparer$b1.Of(this.T); + var compare = tComparer.Compare; - $.Method({Static:false, Public:true }, "Sort", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T])], [])), - function Sort (comparer) { - var tComparer = System.Collections.Generic.IComparer$b1.Of(this.T); - var compare = tComparer.Compare; + this._items.sort(function (lhs, rhs) { + return compare.Call(comparer, null, lhs, rhs); + }); + } + ); - this._items.sort(function (lhs, rhs) { - return compare.Call(comparer, null, lhs, rhs); - }); - } - ); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [ + $.Int32, $.Int32, + T, + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) + ], [])), + function BinarySearch(index, count, item, comparer) { + return JSIL.BinarySearch( + this.T, this._items, index, count, + item, comparer + ); + } + ); - $.Method({Static:false, Public:true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [ - $.Int32, $.Int32, - T, - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) - ], [])), - function BinarySearch (index, count, item, comparer) { - return JSIL.BinarySearch( - this.T, this._items, index, count, - item, comparer - ); - } - ); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [T], [])), + function BinarySearch(item) { + return JSIL.BinarySearch( + this.T, this._items, 0, this._size, + item, null + ); + } + ); - $.Method({Static:false, Public:true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [T], [])), - function BinarySearch (item) { - return JSIL.BinarySearch( - this.T, this._items, 0, this._size, - item, null - ); - } - ); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [ + T, + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) + ], [])), + function BinarySearch(item, comparer) { + return JSIL.BinarySearch( + this.T, this._items, 0, this._size, + item, comparer + ); + } + ); - $.Method({Static:false, Public:true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [ - T, - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) - ], [])), - function BinarySearch (item, comparer) { - return JSIL.BinarySearch( - this.T, this._items, 0, this._size, - item, comparer - ); - } - ); + $.Method({ Static: false, Public: true }, "ToArray", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [T]), [], []), + function () { + var result = JSIL.Array.New(this.T, this._size); - $.Method({Static:false, Public:true }, "ToArray", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [T]), [], []), - function () { - var result = JSIL.Array.New(this.T, this._size); + for (var i = 0, l = this._size, items = this._items; i < l; i++) { + result[i] = items[i]; + } - for (var i = 0, l = this._size, items = this._items; i < l; i++) { - result[i] = items[i]; + return result; } + ); - return result; - } - ); + $.Method({ Static: false, Public: true }, "TrueForAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function (predicate) { + for (var i = 0; i < this._size; i++) { + var item = this._items[i]; - $.Method({Static:false, Public:true }, "TrueForAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function (predicate) { - for (var i = 0; i < this._size; i++) { - var item = this._items[i]; + if (!predicate(item)) + return false; + } - if (!predicate(item)) - return false; + return true; } + ); - return true; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "ClearItems", + new JSIL.MethodSignature(null, [], []), + function ClearItems() { + // Necessary to clear any element values. + var oldLength = this._items.length; + this._items.length = 0; + this._items.length = oldLength; - $.Method({Static:false, Public:false, Virtual:true }, "ClearItems", - new JSIL.MethodSignature(null, [], []), - function ClearItems () { - // Necessary to clear any element values. - var oldLength = this._items.length; - this._items.length = 0; - this._items.length = oldLength; + this._size = 0; + } + ); - this._size = 0; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "InsertItem", + new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), + function InsertItem(index, item) { + index = index | 0; + + if (index >= this._items.length) { + this._items.push(item); + } else if (index >= this._size) { + this._items[index] = item; + } else { + this._items.splice(index, 0, item); + } - $.Method({Static:false, Public:false, Virtual:true }, "InsertItem", - new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), - function InsertItem (index, item) { - index = index | 0; + this._size += 1; - if (index >= this._items.length) { - this._items.push(item); - } else if (index >= this._size) { - this._items[index] = item; - } else { - this._items.splice(index, 0, item); + if (this.$OnItemAdded) + this.$OnItemAdded(item); } + ); - this._size += 1; - - if (this.$OnItemAdded) - this.$OnItemAdded(item); - } - ); - - $.Method({Static:false, Public:false, Virtual:true }, "RemoveItem", - new JSIL.MethodSignature(null, [$.Int32], []), - function RemoveItem (index) { - this._items.splice(index, 1); - this._size -= 1; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "RemoveItem", + new JSIL.MethodSignature(null, [$.Int32], []), + function RemoveItem(index) { + this._items.splice(index, 1); + this._size -= 1; + } + ); - $.Method({Static:false, Public:false, Virtual:true }, "SetItem", - new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), - function SetItem (index, item) { - this._items[index] = item; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "SetItem", + new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), + function SetItem(index, item) { + this._items[index] = item; + } + ); }; -/*JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); - - $jsilcore.$ListExternals($, T, "List"); +JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); - $.Method({ Static: false, Public: true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), - function (array, arrayindex) { - if (arrayindex != 0) { - JSIL.RuntimeError("List.CopyTo not supported for non-zero indexes"); - } + $jsilcore.$ListExternals($, T, "List"); - JSIL.Array.ShallowCopy(array, this._items); - } - ); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), + function (array, arrayindex) { + if (arrayindex != 0) { + JSIL.RuntimeError("List.CopyTo not supported for non-zero indexes"); + } - $.Method({Static:false, Public:true }, "get_IsReadOnly", - new JSIL.MethodSignature($.Boolean, [], []), - function () { - return false; - } - ); + JSIL.Array.ShallowCopy(array, this._items); + } + ); -});*/ + $.Method({ Static: false, Public: true }, "get_IsReadOnly", + new JSIL.MethodSignature($.Boolean, [], []), + function () { + return false; + } + ); +}); $jsilcore.$ArrayListExternals = function ($) { - $jsilcore.$ListExternals($, $.Object, "ArrayList"); + $jsilcore.$ListExternals($, $.Object, "ArrayList"); - var mscorlib = JSIL.GetCorlib(); - var toArrayImpl = function () { - return Array.prototype.slice.call(this._items, 0, this._size); - }; + var mscorlib = JSIL.GetCorlib(); + var toArrayImpl = function () { + return Array.prototype.slice.call(this._items, 0, this._size); + }; - $.Method({Static:false, Public:true }, "ToArray", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Array"), [$.Object], []), - toArrayImpl - ); + $.Method({ Static: false, Public: true }, "ToArray", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Array"), [$.Object], []), + toArrayImpl + ); }; // Lazy way of sharing method implementations between ArrayList, Collection and List. JSIL.ImplementExternals("System.Collections.ArrayList", $jsilcore.$ArrayListExternals); $jsilcore.$CollectionExternals = function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1"); - $jsilcore.$ListExternals($, T, "List"); + var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1"); + $jsilcore.$ListExternals($, T, "List"); - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), - function (list) { - this._items = JSIL.EnumerableToArray(list); - this._capacity = this._size = this._items.length; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), + function (list) { + this._items = JSIL.EnumerableToArray(list); + this._capacity = this._size = this._items.length; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")]), $.Int32], []), - function CopyTo (array, index) { - JSIL.Array.CopyTo(this._items, array, index); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")]), $.Int32], []), + function CopyTo(array, index) { + JSIL.Array.CopyTo(this._items, array, index); + } + ); }; JSIL.ImplementExternals("System.Collections.ObjectModel.Collection`1", $jsilcore.$CollectionExternals); $jsilcore.$ReadOnlyCollectionExternals = function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.ReadOnlyCollection`1"); - $jsilcore.$ListExternals($, T, "ReadOnlyCollection"); + var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.ReadOnlyCollection`1"); + $jsilcore.$ListExternals($, T, "ReadOnlyCollection"); - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var IListCtor = function (list) { - this._list = list; + var IListCtor = function (list) { + this._list = list; - if (JSIL.IsArray(list._array)) { - Object.defineProperty(this, "_items", { - get: function () { - return list._array; - } - }); + if (JSIL.IsArray(list._array)) { + Object.defineProperty(this, "_items", { + get: function () { + return list._array; + } + }); - Object.defineProperty(this, "_size", { - get: function () { - return list._array.length; - } - }); - } else { - if (!list._items || (typeof(list._size) !== "number")) - JSIL.RuntimeError("argument must be a list"); + Object.defineProperty(this, "_size", { + get: function () { + return list._array.length; + } + }); + } else { + if (!list._items || (typeof (list._size) !== "number")) + JSIL.RuntimeError("argument must be a list"); - Object.defineProperty(this, "_items", { - get: function () { - return list._items; - } - }); + Object.defineProperty(this, "_items", { + get: function () { + return list._items; + } + }); - Object.defineProperty(this, "_size", { - get: function () { - return list._size; + Object.defineProperty(this, "_size", { + get: function () { + return list._size; + } + }); } - }); - } - }; + }; - $.RawMethod(false, "$listCtor", IListCtor); + $.RawMethod(false, "$listCtor", IListCtor); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), - IListCtor - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), + IListCtor + ); - $.SetValue("Add", null); - $.SetValue("Clear", null); - $.SetValue("Remove", null); - $.SetValue("RemoveAt", null); - $.SetValue("RemoveAll", null); - $.SetValue("Sort", null); + $.SetValue("Add", null); + $.SetValue("Clear", null); + $.SetValue("Remove", null); + $.SetValue("RemoveAt", null); + $.SetValue("RemoveAll", null); + $.SetValue("Sort", null); }; JSIL.ImplementExternals("System.Collections.ObjectModel.ReadOnlyCollection`1", $jsilcore.$ReadOnlyCollectionExternals); JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { - var system = JSIL.GetAssembly("System", true); + var system = JSIL.GetAssembly("System", true); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - $jsilcore.InitResizableArray(this, this.T, 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + $jsilcore.InitResizableArray(this, this.T, 16); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor (capacity) { - $jsilcore.InitResizableArray(this, this.T, capacity); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + $jsilcore.InitResizableArray(this, this.T, capacity); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear () { - this._items.length = this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._items.length = this._size = 0; + } + ); - $.Method({Static:false, Public:true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count () { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._size; + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), - function GetEnumerator () { - return this.$GetEnumerator(); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), + function GetEnumerator() { + return this.$GetEnumerator(); + } + ); - $.Method({Static:false, Public:true }, "Peek", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), - function Peek () { - if (this._size <= 0) - throw new System.InvalidOperationException("Stack is empty"); + $.Method({ Static: false, Public: true }, "Peek", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + function Peek() { + if (this._size <= 0) + throw new System.InvalidOperationException("Stack is empty"); - return this._items[this._size - 1]; - } - ); + return this._items[this._size - 1]; + } + ); - $.Method({Static:false, Public:true }, "Pop", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), - function Pop () { - var result = this._items.pop(); - this._size -= 1; + $.Method({ Static: false, Public: true }, "Pop", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + function Pop() { + var result = this._items.pop(); + this._size -= 1; - return result; - } - ); + return result; + } + ); - $.Method({Static:false, Public:true }, "Push", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")], [])), - function Push (item) { - this._items.push(item) - this._size += 1; - } - ); + $.Method({ Static: false, Public: true }, "Push", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")], [])), + function Push(item) { + this._items.push(item) + this._size += 1; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.Queue`1", function ($) { - var system = JSIL.GetAssembly("System", true); + var system = JSIL.GetAssembly("System", true); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - $jsilcore.InitResizableArray(this, this.T, 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + $jsilcore.InitResizableArray(this, this.T, 16); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor (capacity) { - $jsilcore.InitResizableArray(this, this.T, capacity); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + $jsilcore.InitResizableArray(this, this.T, capacity); + this._size = 0; + } + ); - $.Method({Static:false, Public:true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear () { - this._items.length = this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._items.length = this._size = 0; + } + ); - $.Method({Static:false, Public:true }, "Dequeue", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1"), [], [])), - function Dequeue () { - var result = this._items.shift(); - this._size -= 1; - return result; - } - ); + $.Method({ Static: false, Public: true }, "Dequeue", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1"), [], [])), + function Dequeue() { + var result = this._items.shift(); + this._size -= 1; + return result; + } + ); - $.Method({Static:false, Public:true }, "Enqueue", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")], [])), - function Enqueue (item) { - this._items.push(item); - this._size += 1; - } - ); + $.Method({ Static: false, Public: true }, "Enqueue", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")], [])), + function Enqueue(item) { + this._items.push(item); + this._size += 1; + } + ); - $.Method({Static:false, Public:true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count () { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._size; + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), - function GetEnumerator () { - return this.$GetEnumerator(); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), + function GetEnumerator() { + return this.$GetEnumerator(); + } + ); }); JSIL.MakeClass("System.Object", "System.Collections.ArrayList", true, [], function ($) { - $.Property({Public: true , Static: false}, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - "System.Collections.IEnumerable" - ); + $.ImplementInterfaces( + "System.Collections.IEnumerable" + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.List`1", true, ["T"], function ($) { - $.Property({Public: true , Static: false}, "Count"); - $.Property({Public: false, Static: false}, "IsReadOnly"); - - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.IEnumerable"), - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), - $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), - $jsilcore.TypeRef("System.Collections.Generic.IList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]) - ); + $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: false, Static: false }, "IsReadOnly"); + + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.IEnumerable"), + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), + $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), + $jsilcore.TypeRef("System.Collections.Generic.IList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]) + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.Stack`1", true, ["T"], function ($) { - $.Property({Public: true , Static: false}, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), "System.Collections.IEnumerable" ); }); // TODO: This type is actually a struct in the CLR JSIL.MakeClass($jsilcore.TypeRef("JSIL.ArrayEnumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]), "System.Collections.Generic.List`1/Enumerator", true, ["T"], function ($) { - $.Field({Public: false, Static: false}, "_array", Array, function ($) { return null; }); - $.Field({Public: false, Static: false}, "_length", Number, function ($) { return 0; }); - $.Field({Public: false, Static: false}, "_index", Number, function ($) { return -1; }); - - $.Method({Public: true, Static: false}, ".ctor", - new JSIL.MethodSignature(null, ["System.Collections.Generic.List`1"]), - function (list) { - this._array = list._items; - this._length = list._size; - } - ); + $.Field({ Public: false, Static: false }, "_array", Array, function ($) { return null; }); + $.Field({ Public: false, Static: false }, "_length", Number, function ($) { return 0; }); + $.Field({ Public: false, Static: false }, "_index", Number, function ($) { return -1; }); + + $.Method({ Public: true, Static: false }, ".ctor", + new JSIL.MethodSignature(null, ["System.Collections.Generic.List`1"]), + function (list) { + this._array = list._items; + this._length = list._size; + } + ); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]) - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]) + ); }); JSIL.ImplementExternals( "System.Threading.Interlocked", function ($) { - var cmpxchg = function (targetRef, value, comparand) { - var currentValue = targetRef.get(); + var cmpxchg = function (targetRef, value, comparand) { + var currentValue = targetRef.get(); - if (currentValue === comparand) - targetRef.set(value); + if (currentValue === comparand) + targetRef.set(value); - return currentValue; - }; + return currentValue; + }; - $.Method({Public: true , Static: true }, "CompareExchange", - new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]), - function (T, targetRef, value, comparand) { - return cmpxchg(targetRef, value, comparand); - } - ); + $.Method({ Public: true, Static: true }, "CompareExchange", + new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]), + function (T, targetRef, value, comparand) { + return cmpxchg(targetRef, value, comparand); + } + ); - $.Method({Static:true , Public:true }, "CompareExchange", - (new JSIL.MethodSignature($.Int32, [ - $jsilcore.TypeRef("JSIL.Reference", [$.Int32]), $.Int32, - $.Int32 - ], [])), - function CompareExchange (/* ref */ location1, value, comparand) { - return cmpxchg(location1, value, comparand); - } - ); + $.Method({ Static: true, Public: true }, "CompareExchange", + (new JSIL.MethodSignature($.Int32, [ + $jsilcore.TypeRef("JSIL.Reference", [$.Int32]), $.Int32, + $.Int32 + ], [])), + function CompareExchange(/* ref */ location1, value, comparand) { + return cmpxchg(location1, value, comparand); + } + ); } ); JSIL.ImplementExternals("System.Threading.Monitor", function ($) { - var enterImpl = function (obj) { - var current = (obj.__LockCount__ || 0); - if (current >= 1) - JSIL.Host.warning("Warning: lock recursion " + obj); + var enterImpl = function (obj) { + var current = (obj.__LockCount__ || 0); + if (current >= 1) + JSIL.Host.warning("Warning: lock recursion " + obj); - obj.__LockCount__ = current + 1; + obj.__LockCount__ = current + 1; - return true; - }; + return true; + }; - $.Method({Static:true , Public:true }, "Enter", - (new JSIL.MethodSignature(null, [$.Object], [])), - function Enter (obj) { - enterImpl(obj); - } - ); + $.Method({ Static: true, Public: true }, "Enter", + (new JSIL.MethodSignature(null, [$.Object], [])), + function Enter(obj) { + enterImpl(obj); + } + ); - $.Method({Static:true , Public:true }, "Enter", - (new JSIL.MethodSignature(null, [$.Object, $jsilcore.TypeRef("JSIL.Reference", [$.Boolean])], [])), - function Enter (obj, /* ref */ lockTaken) { - lockTaken.set(enterImpl(obj)); - } - ); + $.Method({ Static: true, Public: true }, "Enter", + (new JSIL.MethodSignature(null, [$.Object, $jsilcore.TypeRef("JSIL.Reference", [$.Boolean])], [])), + function Enter(obj, /* ref */ lockTaken) { + lockTaken.set(enterImpl(obj)); + } + ); - $.Method({Static:true , Public:true }, "Exit", - (new JSIL.MethodSignature(null, [$.Object], [])), - function Exit (obj) { - var current = (obj.__LockCount__ || 0); - if (current <= 0) - JSIL.Host.warning("Warning: unlocking an object that is not locked " + obj); + $.Method({ Static: true, Public: true }, "Exit", + (new JSIL.MethodSignature(null, [$.Object], [])), + function Exit(obj) { + var current = (obj.__LockCount__ || 0); + if (current <= 0) + JSIL.Host.warning("Warning: unlocking an object that is not locked " + obj); - obj.__LockCount__ = current - 1; - } - ); + obj.__LockCount__ = current - 1; + } + ); }); JSIL.MakeStaticClass("System.Threading.Interlocked", true, [], function ($) { - $.ExternalMethod({Public: true , Static: true }, "CompareExchange", - new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]) - ); + $.ExternalMethod({ Public: true, Static: true }, "CompareExchange", + new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]) + ); }); JSIL.MakeStaticClass("System.Threading.Monitor", true, []); JSIL.ImplementExternals("System.Random", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this.mt = new MersenneTwister(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.mt = new MersenneTwister(); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor (Seed) { - this.mt = new MersenneTwister(Seed); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(Seed) { + this.mt = new MersenneTwister(Seed); + } + ); - $.Method({Static:false, Public:true }, "Next", - (new JSIL.MethodSignature($.Int32, [], [])), - function Next () { - var unsigned32 = this.mt.genrand_int32(); - return unsigned32 << 0; - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [], [])), + function Next() { + var unsigned32 = this.mt.genrand_int32(); + return unsigned32 << 0; + } + ); - $.Method({Static:false, Public:true }, "Next", - (new JSIL.MethodSignature($.Int32, [$.Int32, $.Int32], [])), - function Next (minValue, maxValue) { - var real = this.mt.genrand_real1(); - return Math.floor(real * (maxValue - minValue)) + minValue; - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [$.Int32, $.Int32], [])), + function Next(minValue, maxValue) { + var real = this.mt.genrand_real1(); + return Math.floor(real * (maxValue - minValue)) + minValue; + } + ); - $.Method({Static:false, Public:true }, "Next", - (new JSIL.MethodSignature($.Int32, [$.Int32], [])), - function Next (maxValue) { - var real = this.mt.genrand_real1(); - return Math.floor(real * maxValue); - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [$.Int32], [])), + function Next(maxValue) { + var real = this.mt.genrand_real1(); + return Math.floor(real * maxValue); + } + ); - $.Method({Static:false, Public:true }, "NextDouble", - (new JSIL.MethodSignature($.Double, [], [])), - function NextDouble () { - return this.mt.genrand_real1(); - } - ); + $.Method({ Static: false, Public: true }, "NextDouble", + (new JSIL.MethodSignature($.Double, [], [])), + function NextDouble() { + return this.mt.genrand_real1(); + } + ); }); JSIL.MakeClass("System.Object", "System.Random", true, [], function ($) { }); JSIL.$MathSign = function (value) { - if (value > 0) - return 1; - else if (value < 0) - return -1; - else - return 0; + if (value > 0) + return 1; + else if (value < 0) + return -1; + else + return 0; }; JSIL.ImplementExternals("System.Math", function ($) { - $.RawMethod(true, "Max", Math.max); - $.RawMethod(true, "Min", Math.min); - $.RawMethod(true, "Exp", Math.exp); - - $.Method({Static:true , Public:true }, "Round", - (new JSIL.MethodSignature($.Double, [$.Double, $.Int32], [])), - function Round (value, digits) { - var multiplier = Math.pow(10, digits); - var result = Math.round(value * multiplier) / multiplier; - return result; - } - ); + $.RawMethod(true, "Max", Math.max); + $.RawMethod(true, "Min", Math.min); + $.RawMethod(true, "Exp", Math.exp); + + $.Method({ Static: true, Public: true }, "Round", + (new JSIL.MethodSignature($.Double, [$.Double, $.Int32], [])), + function Round(value, digits) { + var multiplier = Math.pow(10, digits); + var result = Math.round(value * multiplier) / multiplier; + return result; + } + ); - $.Method({Static:true , Public:true }, "Atan2", - (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), - Math.atan2 - ); + $.Method({ Static: true, Public: true }, "Atan2", + (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), + Math.atan2 + ); - $.Method({Static:true , Public:true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.SByte], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.SByte], [])), + JSIL.$MathSign + ); - $.Method({Static:true , Public:true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Int16], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Int16], [])), + JSIL.$MathSign + ); - $.Method({Static:true , Public:true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Int32], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Int32], [])), + JSIL.$MathSign + ); - $.Method({Static:true , Public:true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Single], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Single], [])), + JSIL.$MathSign + ); - $.Method({Static:true , Public:true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Double], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Double], [])), + JSIL.$MathSign + ); - $.Method({Static:true , Public:true }, "IEEERemainder", - (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), - function IEEERemainder (x, y) { - if (y === 0.0) - return NaN; + $.Method({ Static: true, Public: true }, "IEEERemainder", + (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), + function IEEERemainder(x, y) { + if (y === 0.0) + return NaN; - var result = x - y * Math.round(x / y); - if (result !== 0.0) - return result; + var result = x - y * Math.round(x / y); + if (result !== 0.0) + return result; - if (x <= 0.0) - // FIXME: -0? - return 0; - else - return 0; - } - ); + if (x <= 0.0) + // FIXME: -0? + return 0; + else + return 0; + } + ); }); JSIL.MakeStaticClass("System.Math", true, [], function ($) { }); JSIL.MakeStruct("System.ValueType", "System.Decimal", true, [], function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var ctorImpl = function (value) { - this.value = value.valueOf(); - }; + var ctorImpl = function (value) { + this.value = value.valueOf(); + }; - var decimalToNumber = function (decimal) { - return decimal.valueOf(); - }; + var decimalToNumber = function (decimal) { + return decimal.valueOf(); + }; - var numberToDecimal = function (value) { - var result = JSIL.CreateInstanceOfType($.Type, null); - result.value = value.valueOf(); - return result; - }; + var numberToDecimal = function (value) { + var result = JSIL.CreateInstanceOfType($.Type, null); + result.value = value.valueOf(); + return result; + }; - $.RawMethod(false, "valueOf", function () { - return this.value; - }); + $.RawMethod(false, "valueOf", function () { + return this.value; + }); - $.Method({Static: false, Public: true }, "toString", - new JSIL.MethodSignature("System.String", []), - function (format) { - return this.value.toString(); - } - ); + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature("System.String", []), + function (format) { + return this.value.toString(); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], [])), + ctorImpl + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt32")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt32")], [])), + ctorImpl + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int64")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int64")], [])), + ctorImpl + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt64")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt64")], [])), + ctorImpl + ); - $.Method({Static:true , Public:true }, "op_Equality", - (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), - function (lhs, rhs) { - return decimalToNumber(lhs) === decimalToNumber(rhs); - } - ); + $.Method({ Static: true, Public: true }, "op_Equality", + (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), + function (lhs, rhs) { + return decimalToNumber(lhs) === decimalToNumber(rhs); + } + ); - $.Method({Static:true , Public:true }, "op_Inequality", - (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), - function (lhs, rhs) { - return decimalToNumber(lhs) !== decimalToNumber(rhs); - } - ); + $.Method({ Static: true, Public: true }, "op_Inequality", + (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), + function (lhs, rhs) { + return decimalToNumber(lhs) !== decimalToNumber(rhs); + } + ); - $.Method({Static:true , Public:true }, "op_Addition", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) + decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Addition", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) + decimalToNumber(rhs)); + } + ); - $.Method({Static:true , Public:true }, "op_Division", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) / decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Division", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) / decimalToNumber(rhs)); + } + ); - $.Method({Static:true , Public:true }, "op_Multiply", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) * decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Multiply", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) * decimalToNumber(rhs)); + } + ); - $.Method({Static:true , Public:true }, "op_Subtraction", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) - decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Subtraction", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) - decimalToNumber(rhs)); + } + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Single")], [])), - numberToDecimal - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Single")], [])), + numberToDecimal + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Double")], [])), - numberToDecimal - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Double")], [])), + numberToDecimal + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.SByte"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.SByte"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int16"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int16"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt16"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt16"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt32"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt32"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt64"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt64"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Single"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Single"), [$.Type], [])), + decimalToNumber + ); - $.Method({Static:true , Public:true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Double"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Double"), [$.Type], [])), + decimalToNumber + ); - $.Field({Static: false, Public: false }, "value", mscorlib.TypeRef("System.Double"), function () { - return 0; - }); + $.Field({ Static: false, Public: false }, "value", mscorlib.TypeRef("System.Double"), function () { + return 0; + }); }); JSIL.ImplementExternals("System.Environment", function ($) { - $.Method({Static:true , Public:true }, "GetFolderPath", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment/SpecialFolder")], [])), - function GetFolderPath (folder) { - // FIXME - return folder.name; - } - ); + $.Method({ Static: true, Public: true }, "GetFolderPath", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment/SpecialFolder")], [])), + function GetFolderPath(folder) { + // FIXME + return folder.name; + } + ); - $.Method({Static:true , Public:true }, "get_NewLine", - (new JSIL.MethodSignature($.String, [], [])), - function get_NewLine () { - // FIXME: Maybe this should just be \n? - return "\r\n"; - } - ); + $.Method({ Static: true, Public: true }, "get_NewLine", + (new JSIL.MethodSignature($.String, [], [])), + function get_NewLine() { + // FIXME: Maybe this should just be \n? + return "\r\n"; + } + ); - $.Method({Static:true , Public:true }, "get_TickCount", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_TickCount () { - return JSIL.Host.getTickCount() | 0; - } - ); + $.Method({ Static: true, Public: true }, "get_TickCount", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_TickCount() { + return JSIL.Host.getTickCount() | 0; + } + ); }); JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Environment", false, [], function ($) { - $.Property({Static:true , Public:true }, "CurrentManagedThreadId", $.Int32); - - $.Property({Static:true , Public:true }, "TickCount"); + $.Property({ Static: true, Public: true }, "CurrentManagedThreadId", $.Int32); + + $.Property({ Static: true, Public: true }, "TickCount"); }); $jsilcore.hashContainerBase = function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var BucketEntry = function (key, value) { - this.key = key; - this.value = value; - }; + var BucketEntry = function (key, value) { + this.key = key; + this.value = value; + }; - $.RawMethod(false, "$areEqual", function HashContainer_AreEqual (lhs, rhs) { - if (lhs === rhs) - return true; + $.RawMethod(false, "$areEqual", function HashContainer_AreEqual(lhs, rhs) { + if (lhs === rhs) + return true; - return JSIL.ObjectEquals(lhs, rhs); - }); + return JSIL.ObjectEquals(lhs, rhs); + }); - $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket (key) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - return null; + $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket(key) { + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + return null; - for (var i = 0, l = bucket.length; i < l; i++) { - var bucketEntry = bucket[i]; + for (var i = 0, l = bucket.length; i < l; i++) { + var bucketEntry = bucket[i]; - if (this.$areEqual(bucketEntry.key, key)) - return bucketEntry; - } + if (this.$areEqual(bucketEntry.key, key)) + return bucketEntry; + } - return null; - }); + return null; + }); - $.RawMethod(false, "$removeByKey", function HashContainer_Remove (key) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - return false; + $.RawMethod(false, "$removeByKey", function HashContainer_Remove(key) { + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + return false; - for (var i = 0, l = bucket.length; i < l; i++) { - var bucketEntry = bucket[i]; + for (var i = 0, l = bucket.length; i < l; i++) { + var bucketEntry = bucket[i]; - if (this.$areEqual(bucketEntry.key, key)) { - bucket.splice(i, 1); - this._count -= 1; - return true; - } - } + if (this.$areEqual(bucketEntry.key, key)) { + bucket.splice(i, 1); + this._count -= 1; + return true; + } + } - return false; - }); - - $.RawMethod(false, "$addToBucket", function HashContainer_Add (key, value) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - this._dict[hashCode] = bucket = []; - - bucket.push(new BucketEntry(key, value)); - this._count += 1; - return value; - }); + return false; + }); + + $.RawMethod(false, "$addToBucket", function HashContainer_Add(key, value) { + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + this._dict[hashCode] = bucket = []; + + bucket.push(new BucketEntry(key, value)); + this._count += 1; + return value; + }); }; JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", $jsilcore.hashContainerBase); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) { - var mscorlib = JSIL.GetCorlib(); - - function initFields (self) { - self._dict = JSIL.CreateDictionaryObject(null); - self._count = 0; - self.tKeyCollection = null; - self.tValueCollection = null; - self.tKeyEnumerator = null; - self.tValueEnumerator = null; - self.tEnumerator = null; - }; - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - initFields(this); - } - ); - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor (capacity) { - initFields(this); - } - ); - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IDictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), - function _ctor (dictionary) { - initFields(this); - - var enumerator = JSIL.GetEnumerator(dictionary); - while (enumerator.MoveNext()) - this.Add(enumerator.Current.Key, enumerator.Current.Value); - enumerator.Dispose(); - } - ); - - $.Method({Static:false, Public:true }, "Add", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function Add (key, value) { - var bucketEntry = this.$searchBucket(key); - - if (bucketEntry !== null) - throw new System.ArgumentException("Key already exists"); - - return this.$addToBucket(key, value); - } - ); - - $.Method({Static:false, Public:true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear () { - this._dict = {} - this._count = 0; - } - ); - - $.Method({Static:false, Public:true }, "ContainsKey", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function ContainsKey (key) { - return this.$searchBucket(key) !== null; - } - ); - - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function Remove (key) { - return this.$removeByKey(key); - } - ); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count () { - return this._count; - } - ); + function initFields(self) { + self._dict = JSIL.CreateDictionaryObject(null); + self._count = 0; + self.tKeyCollection = null; + self.tValueCollection = null; + self.tKeyEnumerator = null; + self.tValueEnumerator = null; + self.tEnumerator = null; + }; - $.Method({Static:false, Public:true }, "get_Item", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2"), [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function get_Item (key) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) - return bucketEntry.value; - else - throw new System.Exception("Key not found"); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + initFields(this); + } + ); - /*$.Method({ Static: false, Public: false }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), - Dictionary$b2_CopyTo - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + initFields(this); + } + ); - $.Method({ Static: false, Public: false }, "CopyToCheck", - new JSIL.MethodSignature(null, [$asm02.TypeRef("System.Array"), $asm02.TypeRef("System.Int32")], []), - Dictionary$b2_CopyToCheck - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IDictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), + function _ctor(dictionary) { + initFields(this); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.Generic.ICollection$lSystem.Collections.Generic.KeyValuePair$lTKey$cmTValue$g$g.CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$asm02.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), $asm02.TypeRef("System.Int32")], []), - Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_CopyTo - ) -.Overrides(1, "CopyTo"); + var enumerator = JSIL.GetEnumerator(dictionary); + while (enumerator.MoveNext()) + this.Add(enumerator.Current.Key, enumerator.Current.Value); + enumerator.Dispose(); + } + ); - function Dictionary$b2_System_Collections_Generic_ICollection$lSystem_Collections_Generic_KeyValuePair$lTKey$cmTValue$g$g_Contains(keyValuePair) { - return $thisType.Of($thisType.TKey.get(this), $thisType.TValue.get(this)).prototype.ContainsKeyValuePair.call(this, keyValuePair); - }; + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function Add(key, value) { + var bucketEntry = this.$searchBucket(key); - function Dictionary$b2_CopyTo(array, index) { - var $temp00; + if (bucketEntry !== null) + throw new System.ArgumentException("Key already exists"); - for (var i = 0; i < this.touchedSlots; i = ((i + 1) | 0)) { - if ((this.linkSlots[i].HashCode & -2147483648) !== 0) { - array[($temp00 = index, - index = ((index + 1) | 0), - $temp00)] = new ($asm02.System.Collections.Generic.KeyValuePair$b2.Of($thisType.TKey.get(this), $thisType.TValue.get(this)))(JSIL.CloneParameter($thisType.TKey.get(this), this.keySlots[i]), JSIL.CloneParameter($thisType.TValue.get(this), this.valueSlots[i])); - } + return this.$addToBucket(key, value); } - }; + ); - function Dictionary$b2_CopyToCheck(array, index) { - if (array === null) { - throw $S00().Construct("array"); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._dict = {} + this._count = 0; } - if (index < 0) { - throw $S02().Construct("index"); + ); + + $.Method({ Static: false, Public: true }, "ContainsKey", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function ContainsKey(key) { + return this.$searchBucket(key) !== null; } - if (index > array.length) { - throw $S01().Construct("index larger than largest valid index of array"); + ); + + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function Remove(key) { + return this.$removeByKey(key); } - if (((array.length - index) | 0) < this.get_Count()) { - throw $S01().Construct("Destination array cannot hold the requested elements!"); + ); + + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; } - };*/ + ); - $.Method({Static:false, Public:true }, "get_Keys", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Keys () { - if (this.tKeyCollection === null) { - this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; - this.tKeyEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; + $.Method({ Static: false, Public: true }, "get_Item", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2"), [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function get_Item(key) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) + return bucketEntry.value; + else + throw new System.Exception("Key not found"); } + ); - return JSIL.CreateInstanceOfType(this.tKeyCollection, [this]); - } - ); + $.Method({ Static: false, Public: true }, "get_Keys", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Keys() { + if (this.tKeyCollection === null) { + this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; + this.tKeyEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; + } - $.Method({Static:false, Public:true }, "get_Values", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Values () { - if (this.tValueCollection === null) { - this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; - this.tValueEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; + return JSIL.CreateInstanceOfType(this.tKeyCollection, [this]); } + ); - return JSIL.CreateInstanceOfType(this.tValueCollection, [this]); - } - ); + $.Method({ Static: false, Public: true }, "get_Values", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Values() { + if (this.tValueCollection === null) { + this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; + this.tValueEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; + } - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function GetEnumerator () { - if (this.tEnumerator === null) { - this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; + return JSIL.CreateInstanceOfType(this.tValueCollection, [this]); } + ); - return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function GetEnumerator() { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; + } - $.Method({Static:false, Public:true }, "set_Item", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function set_Item (key, value) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) - return bucketEntry.value = value; - else - return this.$addToBucket(key, value); - } - ); + return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + } + ); - $.Method({Static:false, Public:true }, "TryGetValue", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), $jsilcore.TypeRef("JSIL.Reference", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), - function TryGetValue (key, /* ref */ value) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) { - value.set(bucketEntry.value); - return true; - } else { - value.set(JSIL.DefaultValue(this.TValue)); + $.Method({ Static: false, Public: true }, "set_Item", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function set_Item(key, value) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) + return bucketEntry.value = value; + else + return this.$addToBucket(key, value); } + ); - return false; - } - ); + $.Method({ Static: false, Public: true }, "TryGetValue", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), $jsilcore.TypeRef("JSIL.Reference", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), + function TryGetValue(key, value) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) { + value.set(bucketEntry.value); + return true; + } else { + value.set(JSIL.DefaultValue(this.TValue)); + } + + return false; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2")], [])), - function _ctor (key, value) { - this.key = key; - this.value = value; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2")], [])), + function _ctor(key, value) { + this.key = key; + this.value = value; + } + ); - $.Method({Static:false, Public:true }, "get_Key", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), [], [])), - function get_Key () { - return this.key; - } - ); + $.Method({ Static: false, Public: true }, "get_Key", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), [], [])), + function get_Key() { + return this.key; + } + ); - $.Method({Static:false, Public:true }, "get_Value", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2"), [], [])), - function get_Value () { - return this.value; - } - ); + $.Method({ Static: false, Public: true }, "get_Value", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2"), [], [])), + function get_Value() { + return this.value; + } + ); - $.Method({Static:false, Public:true }, "toString", - (new JSIL.MethodSignature($.String, [], [])), - function toString () { - return "[" + String(this.key) + ", " + String(this.value) + "]"; - } - ); + $.Method({ Static: false, Public: true }, "toString", + (new JSIL.MethodSignature($.String, [], [])), + function toString() { + return "[" + String(this.key) + ", " + String(this.value) + "]"; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", function ($interfaceBuilder) { - var $ = $interfaceBuilder; + var $ = $interfaceBuilder; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), - function _ctor (dictionary) { - this.dictionary = dictionary; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count () { - return this.dictionary.get_Count(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this.dictionary.get_Count(); + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), - function GetEnumerator () { - return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), + function GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + } + ); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerable.GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function System_Collections_IEnumerable_GetEnumerator () { - return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); - } - ) - .Overrides(3, "GetEnumerator"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function System_Collections_IEnumerable_GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + } + ) + .Overrides(3, "GetEnumerator"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection", function ($interfaceBuilder) { - var $ = $interfaceBuilder; + var $ = $interfaceBuilder; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), - function _ctor (dictionary) { - this.dictionary = dictionary; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count () { - return this.dictionary.get_Count(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this.dictionary.get_Count(); + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), - function GetEnumerator () { - return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); - } - ); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), $asm20.TypeRef("System.Int32")], []), + function Dictionary_CopyTo(array, index) { + // TODO: Implement checks + var enumerator = JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this]); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerable.GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function System_Collections_IEnumerable_GetEnumerator () { - return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); - } - ) - .Overrides(3, "GetEnumerator"); + while (enumerator.MoveNext()) { + array[index] = enumerator.get_Current(); + index++; + } + } + ); + + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), + function GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); + } + ); + + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function System_Collections_IEnumerable_GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); + } + ) + .Overrides(3, "GetEnumerator"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; - - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), - function _ctor (dictionary) { - this.dictionary = dictionary; - this.kvpEnumerator = null; - this.System_Collections_IEnumerator_Reset(); - } - ); + var $ = $interfaceBuilder; + + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; + this.System_Collections_IEnumerator_Reset(); + } + ); - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__ (source, target) { - target.dictionary = source.dictionary; - if (source.kvpEnumerator) - target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); - } - ); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + if (source.kvpEnumerator) + target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose () { - if (this.kvpEnumerator) - this.kvpEnumerator.Dispose(); + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + if (this.kvpEnumerator) + this.kvpEnumerator.Dispose(); - this.kvpEnumerator = null; - } - ); + this.kvpEnumerator = null; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), - function get_Current () { - return this.kvpEnumerator.get_Current().key; - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), + function get_Current() { + return this.kvpEnumerator.get_Current().key; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext () { - return this.kvpEnumerator.MoveNext(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + return this.kvpEnumerator.MoveNext(); + } + ); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current () { - return this.kvpEnumerator.get_Current().key; - } - ) - .Overrides(2, "get_Current"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.kvpEnumerator.get_Current().key; + } + ) + .Overrides(2, "get_Current"); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset () { - this.kvpEnumerator = this.dictionary.GetEnumerator(); - } - ) - .Overrides(2, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.kvpEnumerator = this.dictionary.GetEnumerator(); + } + ) + .Overrides(2, "Reset"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; - - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), - function _ctor (dictionary) { - this.dictionary = dictionary; - this.kvpEnumerator = null; - this.System_Collections_IEnumerator_Reset(); - } - ); + var $ = $interfaceBuilder; + + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; + this.System_Collections_IEnumerator_Reset(); + } + ); - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__ (source, target) { - target.dictionary = source.dictionary; - if (source.kvpEnumerator) - target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); - } - ); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + if (source.kvpEnumerator) + target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose () { - if (this.kvpEnumerator) - this.kvpEnumerator.Dispose(); + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + if (this.kvpEnumerator) + this.kvpEnumerator.Dispose(); - this.kvpEnumerator = null; - } - ); + this.kvpEnumerator = null; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), - function get_Current () { - return this.kvpEnumerator.get_Current().value; - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), + function get_Current() { + return this.kvpEnumerator.get_Current().value; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext () { - return this.kvpEnumerator.MoveNext(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + return this.kvpEnumerator.MoveNext(); + } + ); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current () { - return this.kvpEnumerator.get_Current().value; - } - ) - .Overrides(2, "get_Current"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.kvpEnumerator.get_Current().value; + } + ) + .Overrides(2, "get_Current"); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset () { - this.kvpEnumerator = this.dictionary.GetEnumerator(); - } - ) - .Overrides(2, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.kvpEnumerator = this.dictionary.GetEnumerator(); + } + ) + .Overrides(2, "Reset"); }); JSIL.MakeStruct("System.ValueType", "System.Collections.Generic.KeyValuePair`2", true, ["TKey", "TValue"], function ($) { - $.Field({Static:false, Public:false}, "key", $.GenericParameter("TKey")); + $.Field({ Static: false, Public: false }, "key", $.GenericParameter("TKey")); - $.Field({Static:false, Public:false}, "value", $.GenericParameter("TValue")); + $.Field({ Static: false, Public: false }, "value", $.GenericParameter("TValue")); - $.Property({Static:false, Public:true }, "Key"); + $.Property({ Static: false, Public: true }, "Key"); - $.Property({Static:false, Public:true }, "Value"); + $.Property({ Static: false, Public: true }, "Value"); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, ["TKey", "TValue"], function ($) { - $.Property({Public: true , Static: false}, "Count"); - $.Property({Public: true , Static: false}, "Keys"); - $.Property({Public: true , Static: false}, "Values"); + $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: true, Static: false }, "Keys"); + $.Property({ Public: true, Static: false }, "Values"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), - $jsilcore.TypeRef("System.Collections.IEnumerable") - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), + $jsilcore.TypeRef("System.Collections.IEnumerable") + ); }); JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2+Enumerator", false, ["TKey", "TValue"], function ($) { - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), - /* 1 */ $jsilcore.TypeRef("System.IDisposable"), - /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), - /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") - ); + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), + /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") + ); }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; + var $ = $interfaceBuilder; - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__ (source, target) { - target.dictionary = source.dictionary; - target.state = source.state; - } - ); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + target.state = source.state; + } + ); - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), - function _ctor (dictionary) { - this.dictionary = dictionary; - - var tKey = dictionary.TKey, tValue = dictionary.TValue; - var tKvp = System.Collections.Generic.KeyValuePair$b2.Of(tKey, tValue).__Type__; - - this.state = { - tKey: tKey, - tValue: tValue, - tKvp: tKvp, - bucketIndex: 0, - valueIndex: -1, - keys: Object.keys(dictionary._dict), - current: JSIL.CreateInstanceOfType(tKvp, "_ctor", [JSIL.DefaultValue(tKey), JSIL.DefaultValue(tValue)]) - }; - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + + var tKey = dictionary.TKey, tValue = dictionary.TValue; + var tKvp = System.Collections.Generic.KeyValuePair$b2.Of(tKey, tValue).__Type__; + + this.state = { + tKey: tKey, + tValue: tValue, + tKvp: tKvp, + bucketIndex: 0, + valueIndex: -1, + keys: Object.keys(dictionary._dict), + current: JSIL.CreateInstanceOfType(tKvp, "_ctor", [JSIL.DefaultValue(tKey), JSIL.DefaultValue(tValue)]) + }; + } + ); - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), - function _ctor (dictionary, getEnumeratorRetType) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), + function _ctor(dictionary, getEnumeratorRetType) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose () { - this.state = null; - this.dictionary = null; - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + this.state = null; + this.dictionary = null; + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), - function get_Current () { - return this.state.current.MemberwiseClone(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), + function get_Current() { + return this.state.current.MemberwiseClone(); + } + ); - $.Method({Static:false, Public:true , Virtual:true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext () { - var state = this.state; - var dict = this.dictionary._dict; - var keys = state.keys; - var valueIndex = ++(state.valueIndex); - var bucketIndex = state.bucketIndex; - - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[state.bucketIndex]; - var bucket = dict[bucketKey]; - - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - var current = state.current; - current.key = bucket[valueIndex].key; - current.value = bucket[valueIndex].value; - return true; - } else { - bucketIndex = ++(state.bucketIndex); - valueIndex = 0; - } + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + var state = this.state; + var dict = this.dictionary._dict; + var keys = state.keys; + var valueIndex = ++(state.valueIndex); + var bucketIndex = state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + var current = state.current; + current.key = bucket[valueIndex].key; + current.value = bucket[valueIndex].value; + return true; + } else { + bucketIndex = ++(state.bucketIndex); + valueIndex = 0; + } + } + + return false; } + ); - return false; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.state.current.MemberwiseClone(); + } + ) + .Overrides(3, "get_Current"); - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current () { - return this.state.current.MemberwiseClone(); - } - ) - .Overrides(3, "get_Current"); - - $.Method({Static:false, Public:false, Virtual:true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset () { - this.state.bucketIndex = 0; - this.state.valueIndex = -1; - } - ) - .Overrides(3, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.state.bucketIndex = 0; + this.state.valueIndex = -1; + } + ) + .Overrides(3, "Reset"); }); $jsilcore.$tArrayEnumerator = null; JSIL.MakeArrayEnumerator = function (array, elementType) { - var tArrayEnumerator; + var tArrayEnumerator; - if (!elementType) { - if ($jsilcore.$tArrayEnumerator === null) - $jsilcore.$tArrayEnumerator = JSIL.ArrayEnumerator.Of(System.Object); + if (!elementType) { + if ($jsilcore.$tArrayEnumerator === null) + $jsilcore.$tArrayEnumerator = JSIL.ArrayEnumerator.Of(System.Object); - tArrayEnumerator = $jsilcore.$tArrayEnumerator; - } else { - tArrayEnumerator = JSIL.ArrayEnumerator.Of(elementType); - } + tArrayEnumerator = $jsilcore.$tArrayEnumerator; + } else { + tArrayEnumerator = JSIL.ArrayEnumerator.Of(elementType); + } - return new tArrayEnumerator(array, -1); + return new tArrayEnumerator(array, -1); }; JSIL.Dispose = function (disposable) { - if (typeof (disposable) === "undefined") - JSIL.RuntimeError("Disposable is undefined"); - else if (disposable === null) - return false; + if (typeof (disposable) === "undefined") + JSIL.RuntimeError("Disposable is undefined"); + else if (disposable === null) + return false; - var tIDisposable = $jsilcore.System.IDisposable; + var tIDisposable = $jsilcore.System.IDisposable; - if (tIDisposable.$Is(disposable)) - tIDisposable.Dispose.Call(disposable); - else if (typeof (disposable.Dispose) === "function") - disposable.Dispose(); - else - return false; + if (tIDisposable.$Is(disposable)) + tIDisposable.Dispose.Call(disposable); + else if (typeof (disposable.Dispose) === "function") + disposable.Dispose(); + else + return false; - return true; + return true; }; JSIL.GetEnumerator = function (enumerable, elementType, fallbackMethodInvoke) { - if ((typeof (enumerable) === "undefined") || (enumerable === null)) - JSIL.RuntimeError("Enumerable is null or undefined"); - - var tIEnumerable = $jsilcore.System.Collections.IEnumerable; - var tIEnumerable$b1 = null; - - if (!elementType) - elementType = $jsilcore.System.Object.__Type__; - else - tIEnumerable$b1 = $jsilcore.System.Collections.Generic.IEnumerable$b1.Of(elementType); - - var result = null; - if (JSIL.IsArray(enumerable)) - result = JSIL.MakeArrayEnumerator(enumerable, elementType); - else if (typeof (enumerable) === "string") - result = JSIL.MakeArrayEnumerator(enumerable, elementType); - else if ((fallbackMethodInvoke !== true) && tIEnumerable$b1 && tIEnumerable$b1.$Is(enumerable)) - result = tIEnumerable$b1.GetEnumerator.Call(enumerable); - else if ((fallbackMethodInvoke !== true) && tIEnumerable.$Is(enumerable)) - result = tIEnumerable.GetEnumerator.Call(enumerable); - else if ((fallbackMethodInvoke !== true) && (typeof (enumerable.GetEnumerator) === "function")) - // HACK: This is gross. - result = enumerable.GetEnumerator(); - else - JSIL.RuntimeError("Value is not enumerable"); - - if (!result) - JSIL.RuntimeError("Value's GetEnumerator method did not return an enumerable."); - - return result; + if ((typeof (enumerable) === "undefined") || (enumerable === null)) + JSIL.RuntimeError("Enumerable is null or undefined"); + + var tIEnumerable = $jsilcore.System.Collections.IEnumerable; + var tIEnumerable$b1 = null; + + if (!elementType) + elementType = $jsilcore.System.Object.__Type__; + else + tIEnumerable$b1 = $jsilcore.System.Collections.Generic.IEnumerable$b1.Of(elementType); + + var result = null; + if (JSIL.IsArray(enumerable)) + result = JSIL.MakeArrayEnumerator(enumerable, elementType); + else if (typeof (enumerable) === "string") + result = JSIL.MakeArrayEnumerator(enumerable, elementType); + else if ((fallbackMethodInvoke !== true) && tIEnumerable$b1 && tIEnumerable$b1.$Is(enumerable)) + result = tIEnumerable$b1.GetEnumerator.Call(enumerable); + else if ((fallbackMethodInvoke !== true) && tIEnumerable.$Is(enumerable)) + result = tIEnumerable.GetEnumerator.Call(enumerable); + else if ((fallbackMethodInvoke !== true) && (typeof (enumerable.GetEnumerator) === "function")) + // HACK: This is gross. + result = enumerable.GetEnumerator(); + else + JSIL.RuntimeError("Value is not enumerable"); + + if (!result) + JSIL.RuntimeError("Value's GetEnumerator method did not return an enumerable."); + + return result; }; JSIL.EnumerableToArray = function (enumerable) { - var e = JSIL.GetEnumerator(enumerable); - var result = []; + var e = JSIL.GetEnumerator(enumerable); + var result = []; - var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; - var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; + var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; + var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; - try { - while (moveNext.Call(e)) - result.push(getCurrent.Call(e)); - } finally { - JSIL.Dispose(e); - } + try { + while (moveNext.Call(e)) + result.push(getCurrent.Call(e)); + } finally { + JSIL.Dispose(e); + } - return result; + return result; }; JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.AbstractEnumerator"); - - $.RawMethod(false, "__CopyMembers__", - function AbstractEnumerator_CopyMembers (source, target) { - target._getNextItem = source._getNextItem; - target._reset = source._reset; - target._dispose = source._dispose; - target._first = source._first; - target._needDispose = source._needDispose; - target._current = new JSIL.BoxedVariable(source._current.get()); - target._state = source._state; - } - ); - - $.Method({Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [JSIL.AnyType, JSIL.AnyType, JSIL.AnyType]), - function (getNextItem, reset, dispose) { - this._getNextItem = getNextItem; - this._reset = reset; - this._dispose = dispose; - this._first = true; - this._needDispose = false; - this._current = new JSIL.BoxedVariable(null); - } - ); + var T = new JSIL.GenericParameter("T", "JSIL.AbstractEnumerator"); + + $.RawMethod(false, "__CopyMembers__", + function AbstractEnumerator_CopyMembers(source, target) { + target._getNextItem = source._getNextItem; + target._reset = source._reset; + target._dispose = source._dispose; + target._first = source._first; + target._needDispose = source._needDispose; + target._current = new JSIL.BoxedVariable(source._current.get()); + target._state = source._state; + } + ); - $.Method({Static: false, Public: true }, "Reset", - new JSIL.MethodSignature(null, []), - function () { - if (this._needDispose) - this._dispose(); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [JSIL.AnyType, JSIL.AnyType, JSIL.AnyType]), + function (getNextItem, reset, dispose) { + this._getNextItem = getNextItem; + this._reset = reset; + this._dispose = dispose; + this._first = true; + this._needDispose = false; + this._current = new JSIL.BoxedVariable(null); + } + ); - this._first = false; - this._needDispose = true; - this._reset(); - } - ); + $.Method({ Static: false, Public: true }, "Reset", + new JSIL.MethodSignature(null, []), + function () { + if (this._needDispose) + this._dispose(); - $.Method({Static: false, Public: true }, "MoveNext", - new JSIL.MethodSignature("System.Boolean", []), - function () { - if (this._first) { - this._reset(); - this._needDispose = true; - this._first = false; + this._first = false; + this._needDispose = true; + this._reset(); } + ); - return this._getNextItem(this._current); - } - ); + $.Method({ Static: false, Public: true }, "MoveNext", + new JSIL.MethodSignature("System.Boolean", []), + function () { + if (this._first) { + this._reset(); + this._needDispose = true; + this._first = false; + } - $.Method({Static: false, Public: true }, "Dispose", - new JSIL.MethodSignature(null, []), - function () { - if (this._needDispose) - this._dispose(); + return this._getNextItem(this._current); + } + ); - this._needDispose = false; - } - ); + $.Method({ Static: false, Public: true }, "Dispose", + new JSIL.MethodSignature(null, []), + function () { + if (this._needDispose) + this._dispose(); - $.Method({Static: false, Public: true }, "get_Current", - new JSIL.MethodSignature(T, []), - function () { - return this._current.get(); - } - ); + this._needDispose = false; + } + ); + + $.Method({ Static: false, Public: true }, "get_Current", + new JSIL.MethodSignature(T, []), + function () { + return this._current.get(); + } + ); - $.Property({Static: false, Public: true, Virtual: true }, "Current"); + $.Property({ Static: false, Public: true, Virtual: true }, "Current"); - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerator"), - /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), - /* 2 */ $jsilcore.TypeRef("System.IDisposable") - ); + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerator"), + /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), + /* 2 */ $jsilcore.TypeRef("System.IDisposable") + ); }); JSIL.ImplementExternals("System.Nullable", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:true , Public:true }, "GetUnderlyingType", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Type"), [mscorlib.TypeRef("System.Type")], [])), - function GetUnderlyingType (nullableType) { - if (nullableType.__FullName__.indexOf("System.Nullable`1") !== 0) { - return null; - } else { - return nullableType.__PublicInterface__.T; + $.Method({ Static: true, Public: true }, "GetUnderlyingType", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Type"), [mscorlib.TypeRef("System.Type")], [])), + function GetUnderlyingType(nullableType) { + if (nullableType.__FullName__.indexOf("System.Nullable`1") !== 0) { + return null; + } else { + return nullableType.__PublicInterface__.T; + } } - } - ); + ); }); JSIL.MakeStaticClass("System.Nullable", true, [], function ($) { }); JSIL.ImplementExternals("System.Nullable`1", function ($) { - $.RawMethod(true, "CheckType", function (value) { - if (this.T.$Is(value)) - return true; + $.RawMethod(true, "CheckType", function (value) { + if (this.T.$Is(value)) + return true; - return false; - }); + return false; + }); }); JSIL.MakeStruct("System.ValueType", "System.Nullable`1", true, ["T"], function ($) { @@ -2918,252 +2883,252 @@ JSIL.ImplementExternals("System.Xml.Serialization.XmlSerializer", function ($) { }); JSIL.ImplementExternals("System.Diagnostics.StackTrace", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this.CaptureStackTrace(0, false, null, null); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.CaptureStackTrace(0, false, null, null); + } + ); - $.Method({Static:false, Public:false}, "CaptureStackTrace", - (new JSIL.MethodSignature(null, [ - $.Int32, $.Boolean, - mscorlib.TypeRef("System.Threading.Thread"), mscorlib.TypeRef("System.Exception") - ], [])), - function CaptureStackTrace (iSkip, fNeedFileInfo, targetThread, e) { - // FIXME - this.frames = []; - } - ); + $.Method({ Static: false, Public: false }, "CaptureStackTrace", + (new JSIL.MethodSignature(null, [ + $.Int32, $.Boolean, + mscorlib.TypeRef("System.Threading.Thread"), mscorlib.TypeRef("System.Exception") + ], [])), + function CaptureStackTrace(iSkip, fNeedFileInfo, targetThread, e) { + // FIXME + this.frames = []; + } + ); - $.Method({Static:false, Public:true }, "GetFrame", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), - function GetFrame (index) { - // FIXME - return new System.Diagnostics.StackFrame(); - } - ); + $.Method({ Static: false, Public: true }, "GetFrame", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), + function GetFrame(index) { + // FIXME + return new System.Diagnostics.StackFrame(); + } + ); }); JSIL.ImplementExternals("System.Diagnostics.StackFrame", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - // FIXME - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + // FIXME + } + ); - $.Method({Static:false, Public:true }, "GetMethod", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Reflection.MethodBase"), [], [])), - function GetMethod () { - // FIXME - return new System.Reflection.MethodBase(); - } - ); + $.Method({ Static: false, Public: true }, "GetMethod", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Reflection.MethodBase"), [], [])), + function GetMethod() { + // FIXME + return new System.Reflection.MethodBase(); + } + ); }); JSIL.ImplementExternals( - "System.Enum", function ($) { - $.RawMethod(true, "CheckType", - function (value) { - if (typeof (value) === "object") { - if ((value !== null) && (typeof (value.GetType) === "function")) - return value.GetType().IsEnum; + "System.Enum", function ($) { + $.RawMethod(true, "CheckType", + function (value) { + if (typeof (value) === "object") { + if ((value !== null) && (typeof (value.GetType) === "function")) + return value.GetType().IsEnum; + } + + return false; } + ); - return false; - } - ); + var internalTryParse; - var internalTryParse; + var internalTryParseFlags = function (TEnum, text, ignoreCase, result) { + var items = text.split(","); - var internalTryParseFlags = function (TEnum, text, ignoreCase, result) { - var items = text.split(","); + var resultValue = 0; + var temp = new JSIL.BoxedVariable(); - var resultValue = 0; - var temp = new JSIL.BoxedVariable(); + var publicInterface = TEnum.__PublicInterface__; - var publicInterface = TEnum.__PublicInterface__; + for (var i = 0, l = items.length; i < l; i++) { + var item = items[i].trim(); + if (item.length === 0) + continue; - for (var i = 0, l = items.length; i < l; i++) { - var item = items[i].trim(); - if (item.length === 0) - continue; + if (internalTryParse(TEnum, item, ignoreCase, temp)) { + resultValue = resultValue | temp.get(); + } else { + return false; + } + } - if (internalTryParse(TEnum, item, ignoreCase, temp)) { - resultValue = resultValue | temp.get(); - } else { - return false; - } - } + var name = TEnum.__ValueToName__[resultValue]; - var name = TEnum.__ValueToName__[resultValue]; + if (typeof (name) === "undefined") { + result.set(publicInterface.$MakeValue(resultValue, null)); + return true; + } else { + result.set(publicInterface[name]); + return true; + } + }; - if (typeof (name) === "undefined") { - result.set(publicInterface.$MakeValue(resultValue, null)); - return true; - } else { - result.set(publicInterface[name]); - return true; - } - }; + internalTryParse = function (TEnum, text, ignoreCase, result) { + // Detect and handle flags enums + var commaPos = text.indexOf(","); + if (commaPos >= 0) + return internalTryParseFlags(TEnum, text, ignoreCase, result); + + var num = parseInt(text, 10); + + var publicInterface = TEnum.__PublicInterface__; + + if (isNaN(num)) { + if (ignoreCase) { + var names = TEnum.__Names__; + for (var i = 0; i < names.length; i++) { + var isMatch = (names[i].toLowerCase() == text.toLowerCase()); + + if (isMatch) { + result.set(publicInterface[names[i]]); + break; + } + } + } else { + result.set(publicInterface[text]); + } + + return (typeof (result.get()) !== "undefined"); + } else { + var name = TEnum.__ValueToName__[num]; + + if (typeof (name) === "undefined") { + result.set(publicInterface.$MakeValue(num, null)); + return true; + } else { + result.set(publicInterface[name]); + return true; + } + } + }; - internalTryParse = function (TEnum, text, ignoreCase, result) { - // Detect and handle flags enums - var commaPos = text.indexOf(","); - if (commaPos >= 0) - return internalTryParseFlags(TEnum, text, ignoreCase, result); + var internalParse = function (enm, text, ignoreCase) { + var result = new JSIL.BoxedVariable(); + if (internalTryParse(enm, text, ignoreCase, result)) + return result.get(); - var num = parseInt(text, 10); + throw new System.Exception("Failed to parse enum"); + }; - var publicInterface = TEnum.__PublicInterface__; + $.Method({ Static: true, Public: true }, "Parse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String")], []), + function (enm, text) { + return internalParse(enm, text, false); + } + ); - if (isNaN(num)) { - if (ignoreCase) { - var names = TEnum.__Names__; - for (var i = 0; i < names.length; i++) { - var isMatch = (names[i].toLowerCase() == text.toLowerCase()); + $.Method({ Static: true, Public: true }, "Parse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [ + $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String"), + $jsilcore.TypeRef("System.Boolean") + ], []), + internalParse + ); - if (isMatch) { - result.set(publicInterface[names[i]]); - break; - } - } - } else { - result.set(publicInterface[text]); + $.Method({ Static: true, Public: true }, "TryParse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [$jsilcore.TypeRef("System.String"), "JSIL.Reference" /* !!0& */], ["TEnum"]), + function (TEnum, text, result) { + return internalTryParse(TEnum, text, result); } + ); - return (typeof (result.get()) !== "undefined"); - } else { - var name = TEnum.__ValueToName__[num]; + $.Method({ Static: true, Public: true }, "TryParse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [ + $jsilcore.TypeRef("System.String"), $jsilcore.TypeRef("System.Boolean"), + "JSIL.Reference" /* !!0& */ + ], ["TEnum"]), + internalTryParse + ); - if (typeof (name) === "undefined") { - result.set(publicInterface.$MakeValue(num, null)); - return true; - } else { - result.set(publicInterface[name]); - return true; + $.Method({ Static: true, Public: true }, "GetNames", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$jsilcore.TypeRef("System.Type")], []), + function (enm) { + return enm.__Names__; } - } - }; + ); - var internalParse = function (enm, text, ignoreCase) { - var result = new JSIL.BoxedVariable(); - if (internalTryParse(enm, text, ignoreCase, result)) - return result.get(); + $.Method({ Static: true, Public: true }, "GetValues", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array"), [$jsilcore.TypeRef("System.Type")], []), + function (enm) { + var names = enm.__Names__; + var publicInterface = enm.__PublicInterface__; + var result = new Array(names.length); - throw new System.Exception("Failed to parse enum"); - }; + for (var i = 0; i < result.length; i++) + result[i] = publicInterface[names[i]]; - $.Method({Static:true , Public:true }, "Parse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String")], []), - function (enm, text) { - return internalParse(enm, text, false); - } - ); + return result; + } + ); + } +); - $.Method({Static:true , Public:true }, "Parse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [ - $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String"), - $jsilcore.TypeRef("System.Boolean") - ], []), - internalParse - ); +JSIL.ImplementExternals("System.Activator", function ($) { + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:true , Public:true }, "TryParse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [$jsilcore.TypeRef("System.String"), "JSIL.Reference" /* !!0& */ ], ["TEnum"]), - function (TEnum, text, result) { - return internalTryParse(TEnum, text, result); + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type")], [])), + function CreateInstance(type) { + return JSIL.CreateInstanceOfType(type, []); } ); - $.Method({Static:true , Public:true }, "TryParse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [ - $jsilcore.TypeRef("System.String"), $jsilcore.TypeRef("System.Boolean"), - "JSIL.Reference" /* !!0& */ - ], ["TEnum"]), - internalTryParse - ); + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Array", [$.Object])], [])), + function CreateInstance(type, args) { + if (!args) + args = []; - $.Method({Static:true , Public:true }, "GetNames", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$jsilcore.TypeRef("System.Type")], []), - function (enm) { - return enm.__Names__; + return JSIL.CreateInstanceOfType(type, args); } ); - $.Method({Static:true , Public:true }, "GetValues", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array"), [$jsilcore.TypeRef("System.Type")], []), - function (enm) { - var names = enm.__Names__; - var publicInterface = enm.__PublicInterface__; - var result = new Array(names.length); - - for (var i = 0; i < result.length; i++) - result[i] = publicInterface[names[i]]; - - return result; + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature("!!0", [], ["T"])), + function CreateInstance(T) { + return JSIL.CreateInstanceOfType(T, []); } ); - } -); - -JSIL.ImplementExternals("System.Activator", function ($) { - var mscorlib = JSIL.GetCorlib(); - - $.Method({Static:true , Public:true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type")], [])), - function CreateInstance (type) { - return JSIL.CreateInstanceOfType(type, []); - } - ); - - $.Method({Static:true , Public:true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Array", [$.Object])], [])), - function CreateInstance (type, args) { - if (!args) - args = []; - - return JSIL.CreateInstanceOfType(type, args); - } - ); - - $.Method({Static:true , Public:true }, "CreateInstance", - (new JSIL.MethodSignature("!!0", [], ["T"])), - function CreateInstance (T) { - return JSIL.CreateInstanceOfType(T, []); - } - ); - $.Method({Static:true , Public:true }, "CreateInstance", - (new JSIL.MethodSignature("!!0", [mscorlib.TypeRef("System.Array", [$.Object])], ["T"])), - function CreateInstance (T, args) { - if (!args) - args = []; + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature("!!0", [mscorlib.TypeRef("System.Array", [$.Object])], ["T"])), + function CreateInstance(T, args) { + if (!args) + args = []; - return JSIL.CreateInstanceOfType(T, args); - } - ); + return JSIL.CreateInstanceOfType(T, args); + } + ); - $.Method({Static:true , Public:true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [ - $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.Reflection.BindingFlags"), - $jsilcore.TypeRef("System.Reflection.Binder"), $jsilcore.TypeRef("System.Array", [$.Object]), - $jsilcore.TypeRef("System.Globalization.CultureInfo") - ], [])), - function CreateInstance (type, bindingAttr, binder, args, culture) { - // FIXME - if (!args) - args = []; - - return JSIL.CreateInstanceOfType(type, args); - } - ); + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [ + $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.Reflection.BindingFlags"), + $jsilcore.TypeRef("System.Reflection.Binder"), $jsilcore.TypeRef("System.Array", [$.Object]), + $jsilcore.TypeRef("System.Globalization.CultureInfo") + ], [])), + function CreateInstance(type, bindingAttr, binder, args, culture) { + // FIXME + if (!args) + args = []; + + return JSIL.CreateInstanceOfType(type, args); + } + ); }); @@ -3171,105 +3136,105 @@ JSIL.MakeStaticClass("System.Activator", true, [], function ($) { }); JSIL.ImplementExternals("System.Diagnostics.Stopwatch", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this.Reset(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.Reset(); + } + ); - $.Method({Static:false, Public:true }, "get_Elapsed", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.TimeSpan"), [], [])), - function get_Elapsed () { - return System.TimeSpan.FromMilliseconds(this.get_ElapsedMilliseconds()); - } - ); + $.Method({ Static: false, Public: true }, "get_Elapsed", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.TimeSpan"), [], [])), + function get_Elapsed() { + return System.TimeSpan.FromMilliseconds(this.get_ElapsedMilliseconds()); + } + ); - $.Method({Static:false, Public:true }, "get_ElapsedMilliseconds", - (new JSIL.MethodSignature($.Int64, [], [])), - function get_ElapsedMilliseconds () { - var result = this.elapsed; - if (this.isRunning) - result += JSIL.Host.getTickCount() - this.startedWhen; + $.Method({ Static: false, Public: true }, "get_ElapsedMilliseconds", + (new JSIL.MethodSignature($.Int64, [], [])), + function get_ElapsedMilliseconds() { + var result = this.elapsed; + if (this.isRunning) + result += JSIL.Host.getTickCount() - this.startedWhen; - return $jsilcore.System.Int64.FromNumber(result); - } - ); + return $jsilcore.System.Int64.FromNumber(result); + } + ); - $.Method({Static:false, Public:true }, "get_ElapsedTicks", - (new JSIL.MethodSignature($.Int64, [], [])), - function get_ElapsedTicks () { - var result = this.elapsed; - if (this.isRunning) - result += JSIL.Host.getTickCount() - this.startedWhen; + $.Method({ Static: false, Public: true }, "get_ElapsedTicks", + (new JSIL.MethodSignature($.Int64, [], [])), + function get_ElapsedTicks() { + var result = this.elapsed; + if (this.isRunning) + result += JSIL.Host.getTickCount() - this.startedWhen; - result *= 10000; + result *= 10000; - return $jsilcore.System.Int64.FromNumber(result); - } - ); + return $jsilcore.System.Int64.FromNumber(result); + } + ); - $.Method({Static:false, Public:true }, "get_IsRunning", - (new JSIL.MethodSignature($.Boolean, [], [])), - function get_IsRunning () { - return this.isRunning; - } - ); + $.Method({ Static: false, Public: true }, "get_IsRunning", + (new JSIL.MethodSignature($.Boolean, [], [])), + function get_IsRunning() { + return this.isRunning; + } + ); - $.Method({Static:false, Public:true }, "Reset", - (new JSIL.MethodSignature(null, [], [])), - function Reset () { - this.elapsed = 0; - this.isRunning = false; - this.startedWhen = 0; - } - ); + $.Method({ Static: false, Public: true }, "Reset", + (new JSIL.MethodSignature(null, [], [])), + function Reset() { + this.elapsed = 0; + this.isRunning = false; + this.startedWhen = 0; + } + ); - $.Method({Static:false, Public:true }, "Restart", - (new JSIL.MethodSignature(null, [], [])), - function Restart () { - this.elapsed = 0; - this.isRunning = true; - this.startedWhen = JSIL.Host.getTickCount(); - } - ); + $.Method({ Static: false, Public: true }, "Restart", + (new JSIL.MethodSignature(null, [], [])), + function Restart() { + this.elapsed = 0; + this.isRunning = true; + this.startedWhen = JSIL.Host.getTickCount(); + } + ); - $.Method({Static:false, Public:true }, "Start", - (new JSIL.MethodSignature(null, [], [])), - function Start () { - if (!this.isRunning) { - this.startedWhen = JSIL.Host.getTickCount(); - this.isRunning = true; + $.Method({ Static: false, Public: true }, "Start", + (new JSIL.MethodSignature(null, [], [])), + function Start() { + if (!this.isRunning) { + this.startedWhen = JSIL.Host.getTickCount(); + this.isRunning = true; + } } - } - ); + ); - $.Method({Static:true , Public:true }, "StartNew", - (new JSIL.MethodSignature($.Type, [], [])), - function StartNew () { - var result = new System.Diagnostics.Stopwatch(); - result.Start(); - return result; - } - ); + $.Method({ Static: true, Public: true }, "StartNew", + (new JSIL.MethodSignature($.Type, [], [])), + function StartNew() { + var result = new System.Diagnostics.Stopwatch(); + result.Start(); + return result; + } + ); - $.Method({Static:false, Public:true }, "Stop", - (new JSIL.MethodSignature(null, [], [])), - function Stop () { - if (this.isRunning) { - this.isRunning = false; + $.Method({ Static: false, Public: true }, "Stop", + (new JSIL.MethodSignature(null, [], [])), + function Stop() { + if (this.isRunning) { + this.isRunning = false; - var now = JSIL.Host.getTickCount(); - var elapsed = now - this.startedWhen; + var now = JSIL.Host.getTickCount(); + var elapsed = now - this.startedWhen; - this.elapsed += elapsed; - if (this.elapsed < 0) - this.elapsed = 0; + this.elapsed += elapsed; + if (this.elapsed < 0) + this.elapsed = 0; + } } - } - ); + ); }); @@ -3277,720 +3242,720 @@ JSIL.MakeClass("System.Object", "System.Diagnostics.Stopwatch", true, [], functi }); JSIL.MakeStruct("System.ValueType", "System.EventArgs", true, [], function ($) { - $.Field({Static:true , Public:true }, "Empty", $jsilcore.TypeRef("System.EventArgs"), function ($) { - return new System.EventArgs(); - }); + $.Field({ Static: true, Public: true }, "Empty", $jsilcore.TypeRef("System.EventArgs"), function ($) { + return new System.EventArgs(); + }); }); JSIL.ImplementExternals("System.Diagnostics.Debug", function ($) { - $.Method({Static:true , Public:true }, "Assert", - (new JSIL.MethodSignature(null, [$.Boolean], [])), - function Assert (condition) { - if (!condition) - JSIL.Host.assertionFailed("Assertion Failed"); - } - ); + $.Method({ Static: true, Public: true }, "Assert", + (new JSIL.MethodSignature(null, [$.Boolean], [])), + function Assert(condition) { + if (!condition) + JSIL.Host.assertionFailed("Assertion Failed"); + } + ); - $.Method({Static:true , Public:true }, "Assert", - (new JSIL.MethodSignature(null, [$.Boolean, $.String], [])), - function Assert (condition, message) { - if (!condition) - JSIL.Host.assertionFailed(message); - } - ); + $.Method({ Static: true, Public: true }, "Assert", + (new JSIL.MethodSignature(null, [$.Boolean, $.String], [])), + function Assert(condition, message) { + if (!condition) + JSIL.Host.assertionFailed(message); + } + ); }); JSIL.MakeEnum( "System.IO.FileMode", true, { - CreateNew: 1, - Create: 2, - Open: 3, - OpenOrCreate: 4, - Truncate: 5, - Append: 6 + CreateNew: 1, + Create: 2, + Open: 3, + OpenOrCreate: 4, + Truncate: 5, + Append: 6 }, false ); JSIL.ImplementExternals("System.GC", function ($) { - var getMemoryImpl = function () { - var svc = JSIL.Host.getService("window"); - return svc.getPerformanceUsedJSHeapSize(); - }; - - $.Method({Static:true , Public:false}, "GetTotalMemory", - (new JSIL.MethodSignature($.Int64, [], [])), - function GetTotalMemory () { - return getMemoryImpl(); - } - ); + var getMemoryImpl = function () { + var svc = JSIL.Host.getService("window"); + return svc.getPerformanceUsedJSHeapSize(); + }; - $.Method({Static:true , Public:true }, "GetTotalMemory", - (new JSIL.MethodSignature($.Int64, [$.Boolean], [])), - function GetTotalMemory (forceFullCollection) { - // FIXME: forceFullCollection + $.Method({ Static: true, Public: false }, "GetTotalMemory", + (new JSIL.MethodSignature($.Int64, [], [])), + function GetTotalMemory() { + return getMemoryImpl(); + } + ); - return getMemoryImpl(); - } - ); + $.Method({ Static: true, Public: true }, "GetTotalMemory", + (new JSIL.MethodSignature($.Int64, [$.Boolean], [])), + function GetTotalMemory(forceFullCollection) { + // FIXME: forceFullCollection - $.Method({Static:true , Public:false}, "IsServerGC", - (new JSIL.MethodSignature($.Boolean, [], [])), - function IsServerGC () { - return false; - } - ); + return getMemoryImpl(); + } + ); + + $.Method({ Static: true, Public: false }, "IsServerGC", + (new JSIL.MethodSignature($.Boolean, [], [])), + function IsServerGC() { + return false; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", $jsilcore.hashContainerBase); JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { - var mscorlib = JSIL.GetCorlib(); - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this._dict = {}; - this._count = 0; - this._comparer = null; - } - ); - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor (comparer) { - this._dict = {}; - this._count = 0; - this._comparer = comparer; - } - ); - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor (collection) { - this._dict = {}; - this._count = 0; - this._comparer = null; - this.$addRange(collection); - } - ); + var mscorlib = JSIL.GetCorlib(); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor (collection, comparer) { - this._dict = {}; - this._count = 0; - this._comparer = comparer; - this.$addRange(collection); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this._dict = {}; + this._count = 0; + this._comparer = null; + } + ); - $.Method({Static:false, Public:true }, "Add", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Add (item) { - var bucketEntry = this.$searchBucket(item); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(comparer) { + this._dict = {}; + this._count = 0; + this._comparer = comparer; + } + ); - if (bucketEntry !== null) - return false; + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection) { + this._dict = {}; + this._count = 0; + this._comparer = null; + this.$addRange(collection); + } + ); - this.$addToBucket(item, true); - return true; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection, comparer) { + this._dict = {}; + this._count = 0; + this._comparer = comparer; + this.$addRange(collection); + } + ); - $.RawMethod(false, "$addRange", function (enumerable) { - var values = JSIL.EnumerableToArray(enumerable); + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Add(item) { + var bucketEntry = this.$searchBucket(item); - for (var i = 0; i < values.length; i++) - this.Add(values[i]); - }); + if (bucketEntry !== null) + return false; - $.Method({Static:false, Public:true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear () { - this._dict = {}; - this._count = 0; - } - ); + this.$addToBucket(item, true); + return true; + } + ); - $.Method({Static:false, Public:true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Contains (item) { - return this.$searchBucket(item) !== null; - } - ); + $.RawMethod(false, "$addRange", function (enumerable) { + var values = JSIL.EnumerableToArray(enumerable); - $.Method({Static:false, Public:true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count () { - return this._count; - } - ); + for (var i = 0; i < values.length; i++) + this.Add(values[i]); + }); - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Remove (item) { - return this.$removeByKey(item); - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._dict = {}; + this._count = 0; + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), - function GetEnumerator () { - var dict = this._dict; + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Contains(item) { + return this.$searchBucket(item) !== null; + } + ); - return new (JSIL.AbstractEnumerator.Of(this.T)) ( - function getNext (result) { - var keys = this._state.keys; - var valueIndex = ++(this._state.valueIndex); - var bucketIndex = this._state.bucketIndex; + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; + } + ); - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[this._state.bucketIndex]; - var bucket = dict[bucketKey]; + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Remove(item) { + return this.$removeByKey(item); + } + ); - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - result.set(bucket[valueIndex].key); - return true; - } else { - bucketIndex = ++(this._state.bucketIndex); - valueIndex = 0; + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), + function GetEnumerator() { + var dict = this._dict; + + return new (JSIL.AbstractEnumerator.Of(this.T))( + function getNext(result) { + var keys = this._state.keys; + var valueIndex = ++(this._state.valueIndex); + var bucketIndex = this._state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[this._state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + result.set(bucket[valueIndex].key); + return true; + } else { + bucketIndex = ++(this._state.bucketIndex); + valueIndex = 0; + } + } + + return false; + }, + function reset() { + this._state = { + current: JSIL.DefaultValue(this.T), + keys: Object.keys(dict), + bucketIndex: 0, + valueIndex: -1 + }; + }, + function dispose() { + this._state = null; } - } - - return false; - }, - function reset () { - this._state = { - current: JSIL.DefaultValue(this.T), - keys: Object.keys(dict), - bucketIndex: 0, - valueIndex: -1 - }; - }, - function dispose () { - this._state = null; - } - ); - } - ); + ); + } + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, ["T"], function ($) { - $.Property({Public: true , Static: false}, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), - $jsilcore.TypeRef("System.Collections.IEnumerable") -// $jsilcore.TypeRef("System.Collections.Generic.ISet`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), -// $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), + $jsilcore.TypeRef("System.Collections.IEnumerable") + // $jsilcore.TypeRef("System.Collections.Generic.ISet`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), + // $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), + ); }); JSIL.MakeEnum( "System.Globalization.NumberStyles", true, { - None: 0, - AllowLeadingWhite: 1, - AllowTrailingWhite: 2, - AllowLeadingSign: 4, - Integer: 7, - AllowTrailingSign: 8, - AllowParentheses: 16, - AllowDecimalPoint: 32, - AllowThousands: 64, - Number: 111, - AllowExponent: 128, - Float: 167, - AllowCurrencySymbol: 256, - Currency: 383, - Any: 511, - AllowHexSpecifier: 512, - HexNumber: 515 + None: 0, + AllowLeadingWhite: 1, + AllowTrailingWhite: 2, + AllowLeadingSign: 4, + Integer: 7, + AllowTrailingSign: 8, + AllowParentheses: 16, + AllowDecimalPoint: 32, + AllowThousands: 64, + Number: 111, + AllowExponent: 128, + Float: 167, + AllowCurrencySymbol: 256, + Currency: 383, + Any: 511, + AllowHexSpecifier: 512, + HexNumber: 515 }, true ); JSIL.ImplementExternals("System.Convert", function ($) { - $.Method({Static:true , Public:true }, "ChangeType", - (new JSIL.MethodSignature($.Object, [$.Object, $jsilcore.TypeRef("System.Type")], [])), - function ChangeType (value, conversionType) { - // FIXME: Actually compatible? - if (value && $jsilcore.System.IConvertible.$Is(value)) { - // FIXME: provider - return $jsilcore.System.IConvertible.ToType.Call(value, null, conversionType, null); - } else { - return conversionType.__PublicInterface__.$As(value); + $.Method({ Static: true, Public: true }, "ChangeType", + (new JSIL.MethodSignature($.Object, [$.Object, $jsilcore.TypeRef("System.Type")], [])), + function ChangeType(value, conversionType) { + // FIXME: Actually compatible? + if (value && $jsilcore.System.IConvertible.$Is(value)) { + // FIXME: provider + return $jsilcore.System.IConvertible.ToType.Call(value, null, conversionType, null); + } else { + return conversionType.__PublicInterface__.$As(value); + } } - } - ); + ); - var returnSame = function (value) { - return value; - }; + var returnSame = function (value) { + return value; + }; - var returnValueOf = function (value) { - return value.valueOf(); - }; + var returnValueOf = function (value) { + return value.valueOf(); + }; - var makeAdapter = function (adapter) { - if (!adapter) - JSIL.RuntimeError("No adapter provided"); + var makeAdapter = function (adapter) { + if (!adapter) + JSIL.RuntimeError("No adapter provided"); - return function (value) { - return adapter(value); + return function (value) { + return adapter(value); + }; }; - }; - var boolToInt = function (b) { - return b ? 1 : 0; - }; + var boolToInt = function (b) { + return b ? 1 : 0; + }; - var boolToString = function (b) { - return b ? "True" : "False"; - }; + var boolToString = function (b) { + return b ? "True" : "False"; + }; - var makeConvertMethods = function (typeName, to, from) { - // FIXME: We currently ignore the format provider argument - // FIXME: Range checks/clipping/saturation are not performed for the integer types + var makeConvertMethods = function (typeName, to, from) { + // FIXME: We currently ignore the format provider argument + // FIXME: Range checks/clipping/saturation are not performed for the integer types - var methodName = "To" + typeName; + var methodName = "To" + typeName; - var descriptor = {Static:true , Public: true }; - var tFormatProvider = $jsilcore.TypeRef("System.IFormatProvider"); + var descriptor = { Static: true, Public: true }; + var tFormatProvider = $jsilcore.TypeRef("System.IFormatProvider"); - var toType = JSIL.ResolveTypeReference(to)[0]; - - var makeSignature = function (argType, formatProvider) { - if (formatProvider) - return new JSIL.MethodSignature(to, [argType, tFormatProvider], []); - else - return new JSIL.MethodSignature(to, [argType], []); - }; - - if (from.boolean) { - $.Method(descriptor, methodName, makeSignature($.Boolean), from.boolean); + var toType = JSIL.ResolveTypeReference(to)[0]; - $.Method(descriptor, methodName, makeSignature($.Boolean, true), from.boolean); - } + var makeSignature = function (argType, formatProvider) { + if (formatProvider) + return new JSIL.MethodSignature(to, [argType, tFormatProvider], []); + else + return new JSIL.MethodSignature(to, [argType], []); + }; - $.Method(descriptor, methodName, makeSignature($.SByte), from.int); - $.Method(descriptor, methodName, makeSignature($.Int16), from.int); - $.Method(descriptor, methodName, makeSignature($.Int32), from.int); - - $.Method(descriptor, methodName, makeSignature($.SByte, true), from.int); - $.Method(descriptor, methodName, makeSignature($.Int16, true), from.int); - $.Method(descriptor, methodName, makeSignature($.Int32, true), from.int); - - $.Method(descriptor, methodName, makeSignature($.Byte), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt16), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt32), from.uint); - - $.Method(descriptor, methodName, makeSignature($.Byte, true), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt16, true), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt32, true), from.uint); - - if (from.int64) { - $.Method(descriptor, methodName, makeSignature($.Int64), from.int64); - $.Method(descriptor, methodName, makeSignature($.Int64, true), from.int64); - } + if (from.boolean) { + $.Method(descriptor, methodName, makeSignature($.Boolean), from.boolean); - if (from.uint64) { - $.Method(descriptor, methodName, makeSignature($.UInt64), from.uint64); - $.Method(descriptor, methodName, makeSignature($.UInt64, true), from.uint64); - } + $.Method(descriptor, methodName, makeSignature($.Boolean, true), from.boolean); + } - if (from.float) { - $.Method(descriptor, methodName, makeSignature($.Single), from.float); - $.Method(descriptor, methodName, makeSignature($.Double), from.float); + $.Method(descriptor, methodName, makeSignature($.SByte), from.int); + $.Method(descriptor, methodName, makeSignature($.Int16), from.int); + $.Method(descriptor, methodName, makeSignature($.Int32), from.int); - $.Method(descriptor, methodName, makeSignature($.Single, true), from.float); - $.Method(descriptor, methodName, makeSignature($.Double, true), from.float); - } + $.Method(descriptor, methodName, makeSignature($.SByte, true), from.int); + $.Method(descriptor, methodName, makeSignature($.Int16, true), from.int); + $.Method(descriptor, methodName, makeSignature($.Int32, true), from.int); - if (from.string) { - $.Method(descriptor, methodName, makeSignature($.String), from.string); + $.Method(descriptor, methodName, makeSignature($.Byte), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt16), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt32), from.uint); - $.Method(descriptor, methodName, makeSignature($.String, true), from.string); - } + $.Method(descriptor, methodName, makeSignature($.Byte, true), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt16, true), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt32, true), from.uint); - var fromObject = function Convert_FromObject (value) { - if (value === null) { - if (to === $.String) { - return $jsilcore.System.String.Empty; + if (from.int64) { + $.Method(descriptor, methodName, makeSignature($.Int64), from.int64); + $.Method(descriptor, methodName, makeSignature($.Int64, true), from.int64); } - - return JSIL.DefaultValue(toType); - } - - if ($jsilcore.System.IConvertible.$Is(value)) { - var conversionMethod = $jsilcore.System.IConvertible["To" + typeName]; - - if (conversionMethod) { - return conversionMethod.Call(value, null, null); + + if (from.uint64) { + $.Method(descriptor, methodName, makeSignature($.UInt64), from.uint64); + $.Method(descriptor, methodName, makeSignature($.UInt64, true), from.uint64); } - } - - if (to === $.String) { - return value.toString(); - } - - if ($jsilcore.System.String.$Is(value)) - return from.string(value); - else if (from.int64 && $jsilcore.System.Int64.$Is(value)) - return from.int64(value); - else if (from.uint64 && $jsilcore.System.UInt64.$Is(value)) - return from.uint64(value); - else if ($jsilcore.System.Int32.$Is(value)) - return from.int(value); - else if ($jsilcore.System.UInt32.$Is(value)) - return from.uint(value); - else if ($jsilcore.System.Boolean.$Is(value)) - return from.boolean(value); - else if ($jsilcore.System.Double.$Is(value)) - return from.float(value); - else - throw new System.NotImplementedException( - "Conversion from type '" + JSIL.GetType(value) + "' to type '" + typeName + "' not implemented." - ); + + if (from.float) { + $.Method(descriptor, methodName, makeSignature($.Single), from.float); + $.Method(descriptor, methodName, makeSignature($.Double), from.float); + + $.Method(descriptor, methodName, makeSignature($.Single, true), from.float); + $.Method(descriptor, methodName, makeSignature($.Double, true), from.float); + } + + if (from.string) { + $.Method(descriptor, methodName, makeSignature($.String), from.string); + + $.Method(descriptor, methodName, makeSignature($.String, true), from.string); + } + + var fromObject = function Convert_FromObject(value) { + if (value === null) { + if (to === $.String) { + return $jsilcore.System.String.Empty; + } + + return JSIL.DefaultValue(toType); + } + + if ($jsilcore.System.IConvertible.$Is(value)) { + var conversionMethod = $jsilcore.System.IConvertible["To" + typeName]; + + if (conversionMethod) { + return conversionMethod.Call(value, null, null); + } + } + + if (to === $.String) { + return value.toString(); + } + + if ($jsilcore.System.String.$Is(value)) + return from.string(value); + else if (from.int64 && $jsilcore.System.Int64.$Is(value)) + return from.int64(value); + else if (from.uint64 && $jsilcore.System.UInt64.$Is(value)) + return from.uint64(value); + else if ($jsilcore.System.Int32.$Is(value)) + return from.int(value); + else if ($jsilcore.System.UInt32.$Is(value)) + return from.uint(value); + else if ($jsilcore.System.Boolean.$Is(value)) + return from.boolean(value); + else if ($jsilcore.System.Double.$Is(value)) + return from.float(value); + else + throw new System.NotImplementedException( + "Conversion from type '" + JSIL.GetType(value) + "' to type '" + typeName + "' not implemented." + ); + }; + + $.Method(descriptor, methodName, makeSignature($.Object, false), fromObject); }; - $.Method(descriptor, methodName, makeSignature($.Object, false), fromObject); - }; - - makeConvertMethods("Boolean", $.Boolean, { - boolean: returnSame, - uint: makeAdapter(Boolean), - int: makeAdapter(Boolean), - float: makeAdapter(Boolean), - int64: makeAdapter(Boolean), - uint64: makeAdapter(Boolean), - string: makeAdapter($jsilcore.$ParseBoolean) - }); - - makeConvertMethods("Byte", $.Byte, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - makeConvertMethods("SByte", $.SByte, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - makeConvertMethods("UInt16", $.UInt16, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - makeConvertMethods("Int16", $.Int16, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - makeConvertMethods("UInt32", $.UInt32, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - makeConvertMethods("Int32", $.Int32, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); - - var boolToUInt64 = function (b) { - return $jsilcore.System.UInt64.FromInt32(b ? 1 : 0); - }; - - var intToUInt64 = function (i) { - return $jsilcore.System.UInt64.FromInt32(i); - }; - - var uintToUInt64 = function (u) { - return $jsilcore.System.UInt64.FromUInt32(u); - }; - - var parseUInt64 = function (text) { - return $jsilcore.System.UInt64.Parse(text); - }; - - makeConvertMethods("UInt64", $.UInt64, { - boolean: boolToUInt64, - uint: uintToUInt64, - int: intToUInt64, - string: parseUInt64 - }); - - var boolToInt64 = function (b) { - return $jsilcore.System.Int64.FromInt32(b ? 1 : 0); - } + makeConvertMethods("Boolean", $.Boolean, { + boolean: returnSame, + uint: makeAdapter(Boolean), + int: makeAdapter(Boolean), + float: makeAdapter(Boolean), + int64: makeAdapter(Boolean), + uint64: makeAdapter(Boolean), + string: makeAdapter($jsilcore.$ParseBoolean) + }); - var intToInt64 = function (i) { - return $jsilcore.System.Int64.FromInt32(i); - }; + makeConvertMethods("Byte", $.Byte, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - var uintToInt64 = function (u) { - return $jsilcore.System.Int64.FromUInt32(u); - }; + makeConvertMethods("SByte", $.SByte, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - var parseInt64 = function (text) { - return $jsilcore.System.Int64.Parse(text); - }; + makeConvertMethods("UInt16", $.UInt16, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - var intToChar = function (i) { - return String.fromCharCode(i | 0); - }; + makeConvertMethods("Int16", $.Int16, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - var valueOfToChar = function (obj) { - return String.fromCharCode(obj.valueOf() | 0); - }; + makeConvertMethods("UInt32", $.UInt32, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - makeConvertMethods("Int64", $.Int64, { - boolean: boolToInt64, - uint: uintToInt64, - int: intToInt64, - string: parseInt64 - }); - - makeConvertMethods("Single", $.Single, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseFloat) - }); - - makeConvertMethods("Double", $.Double, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseFloat) - }); - - makeConvertMethods("Char", $.Char, { - uint: intToChar, - int: intToChar, - int64: valueOfToChar, - uint64: valueOfToChar - }); - - makeConvertMethods("String", $.String, { - boolean: boolToString, - uint: makeAdapter(String), - int: makeAdapter(String), - float: makeAdapter(String), - int64: makeAdapter(String), - uint64: makeAdapter(String), - string: returnSame - }); - - var base64IgnoredCodepoints = [ - 9, 10, 13, 32 - ]; - - var base64Table = [ - 'A', 'B', 'C', 'D', - 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', - 'Y', 'Z', - 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', - 'y', 'z', - '0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', - '+', '/' - ]; - - var base64CodeTable = new Array(base64Table.length); - for (var i = 0; i < base64Table.length; i++) - base64CodeTable[i] = base64Table[i].charCodeAt(0); - - var toBase64StringImpl = function ToBase64String (inArray, offset, length, options) { - if (options) - JSIL.RuntimeError("Base64FormattingOptions not implemented"); - - var reader = $jsilcore.makeByteReader(inArray, offset, length); - var result = ""; - var ch1 = 0, ch2 = 0, ch3 = 0, bits = 0, equalsCount = 0, sum = 0; - var mask1 = (1 << 24) - 1, mask2 = (1 << 18) - 1, mask3 = (1 << 12) - 1, mask4 = (1 << 6) - 1; - var shift1 = 18, shift2 = 12, shift3 = 6, shift4 = 0; - - while (true) { - ch1 = reader.read(); - ch2 = reader.read(); - ch3 = reader.read(); - - if (ch1 === false) - break; - if (ch2 === false) { - ch2 = 0; - equalsCount += 1; - } - if (ch3 === false) { - ch3 = 0; - equalsCount += 1; - } - - // Seems backwards, but is right! - sum = (ch1 << 16) | (ch2 << 8) | (ch3 << 0); - - bits = (sum & mask1) >> shift1; - result += base64Table[bits]; - bits = (sum & mask2) >> shift2; - result += base64Table[bits]; - - if (equalsCount < 2) { - bits = (sum & mask3) >> shift3; - result += base64Table[bits]; - } - - if (equalsCount === 2) { - result += "=="; - } else if (equalsCount === 1) { - result += "="; - } else { - bits = (sum & mask4) >> shift4; - result += base64Table[bits]; - } - } + makeConvertMethods("Int32", $.Int32, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); - return result; - }; + var boolToUInt64 = function (b) { + return $jsilcore.System.UInt64.FromInt32(b ? 1 : 0); + }; - $.Method({Static:true , Public:true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), - function ToBase64String (inArray) { - return toBase64StringImpl(inArray, 0, inArray.length, 0); - } - ); + var intToUInt64 = function (i) { + return $jsilcore.System.UInt64.FromInt32(i); + }; - $.Method({Static:true , Public:true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $jsilcore.TypeRef("System.Base64FormattingOptions")], [])), - function ToBase64String (inArray, options) { - return toBase64StringImpl(inArray, 0, inArray.length, options); - } - ); + var uintToUInt64 = function (u) { + return $jsilcore.System.UInt64.FromUInt32(u); + }; - $.Method({Static:true , Public:true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32 - ], [])), - function ToBase64String (inArray, offset, length) { - return toBase64StringImpl(inArray, offset, length, 0); + var parseUInt64 = function (text) { + return $jsilcore.System.UInt64.Parse(text); + }; + + makeConvertMethods("UInt64", $.UInt64, { + boolean: boolToUInt64, + uint: uintToUInt64, + int: intToUInt64, + string: parseUInt64 + }); + + var boolToInt64 = function (b) { + return $jsilcore.System.Int64.FromInt32(b ? 1 : 0); } - ); - $.Method({Static:true , Public:true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32, $jsilcore.TypeRef("System.Base64FormattingOptions") - ], [])), - toBase64StringImpl - ); + var intToInt64 = function (i) { + return $jsilcore.System.Int64.FromInt32(i); + }; - $.Method({Static:true , Public:true }, "FromBase64String", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.String], [])), - function FromBase64String (s) { - var lengthErrorMessage = "Invalid length for a Base-64 char array."; - var contentErrorMessage = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."; - - var result = []; - var reader = $jsilcore.makeCharacterReader(s); - var sum = 0; - var ch0 = 0, ch1 = 0, ch2 = 0, ch3 = 0; - var index0 = -1, index1 = -1, index2 = -1, index3 = -1; - var equals = "=".charCodeAt(0); - - while (true) { - ch0 = reader.read(); - if (ch0 === false) - break; - if (base64IgnoredCodepoints.indexOf(ch0) >= 0) - continue; - - ch1 = reader.read(); - ch2 = reader.read(); - ch3 = reader.read(); - - if ((ch1 === false) || (ch2 === false) || (ch3 === false)) - throw new System.FormatException(lengthErrorMessage); - - index0 = base64CodeTable.indexOf(ch0); - index1 = base64CodeTable.indexOf(ch1); - index2 = base64CodeTable.indexOf(ch2); - index3 = base64CodeTable.indexOf(ch3); - - if ( - (index0 < 0) || (index0 > 63) || - (index1 < 0) || (index1 > 63) - ) - throw new System.FormatException(contentErrorMessage); + var uintToInt64 = function (u) { + return $jsilcore.System.Int64.FromUInt32(u); + }; + + var parseInt64 = function (text) { + return $jsilcore.System.Int64.Parse(text); + }; + + var intToChar = function (i) { + return String.fromCharCode(i | 0); + }; + + var valueOfToChar = function (obj) { + return String.fromCharCode(obj.valueOf() | 0); + }; + + makeConvertMethods("Int64", $.Int64, { + boolean: boolToInt64, + uint: uintToInt64, + int: intToInt64, + string: parseInt64 + }); + + makeConvertMethods("Single", $.Single, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseFloat) + }); + + makeConvertMethods("Double", $.Double, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseFloat) + }); + + makeConvertMethods("Char", $.Char, { + uint: intToChar, + int: intToChar, + int64: valueOfToChar, + uint64: valueOfToChar + }); + + makeConvertMethods("String", $.String, { + boolean: boolToString, + uint: makeAdapter(String), + int: makeAdapter(String), + float: makeAdapter(String), + int64: makeAdapter(String), + uint64: makeAdapter(String), + string: returnSame + }); + + var base64IgnoredCodepoints = [ + 9, 10, 13, 32 + ]; + + var base64Table = [ + 'A', 'B', 'C', 'D', + 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', + 'Y', 'Z', + 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', + 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', + 'y', 'z', + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', + '+', '/' + ]; + + var base64CodeTable = new Array(base64Table.length); + for (var i = 0; i < base64Table.length; i++) + base64CodeTable[i] = base64Table[i].charCodeAt(0); + + var toBase64StringImpl = function ToBase64String(inArray, offset, length, options) { + if (options) + JSIL.RuntimeError("Base64FormattingOptions not implemented"); + + var reader = $jsilcore.makeByteReader(inArray, offset, length); + var result = ""; + var ch1 = 0, ch2 = 0, ch3 = 0, bits = 0, equalsCount = 0, sum = 0; + var mask1 = (1 << 24) - 1, mask2 = (1 << 18) - 1, mask3 = (1 << 12) - 1, mask4 = (1 << 6) - 1; + var shift1 = 18, shift2 = 12, shift3 = 6, shift4 = 0; + + while (true) { + ch1 = reader.read(); + ch2 = reader.read(); + ch3 = reader.read(); + + if (ch1 === false) + break; + if (ch2 === false) { + ch2 = 0; + equalsCount += 1; + } + if (ch3 === false) { + ch3 = 0; + equalsCount += 1; + } + + // Seems backwards, but is right! + sum = (ch1 << 16) | (ch2 << 8) | (ch3 << 0); + + bits = (sum & mask1) >> shift1; + result += base64Table[bits]; + bits = (sum & mask2) >> shift2; + result += base64Table[bits]; + + if (equalsCount < 2) { + bits = (sum & mask3) >> shift3; + result += base64Table[bits]; + } + + if (equalsCount === 2) { + result += "=="; + } else if (equalsCount === 1) { + result += "="; + } else { + bits = (sum & mask4) >> shift4; + result += base64Table[bits]; + } + } - sum = (index0 << 18) | (index1 << 12); + return result; + }; - if (index2 >= 0) - sum |= (index2 << 6); - else if (ch2 !== equals) - throw new System.FormatException(contentErrorMessage); + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), + function ToBase64String(inArray) { + return toBase64StringImpl(inArray, 0, inArray.length, 0); + } + ); - if (index3 >= 0) - sum |= (index3 << 0); - else if (ch3 !== equals) - throw new System.FormatException(contentErrorMessage); + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $jsilcore.TypeRef("System.Base64FormattingOptions")], [])), + function ToBase64String(inArray, options) { + return toBase64StringImpl(inArray, 0, inArray.length, options); + } + ); - result.push((sum >> 16) & 0xFF); - if (index2 >= 0) - result.push((sum >> 8) & 0xFF); - if (index3 >= 0) - result.push(sum & 0xFF); + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32 + ], [])), + function ToBase64String(inArray, offset, length) { + return toBase64StringImpl(inArray, offset, length, 0); } + ); - return JSIL.Array.New($jsilcore.System.Byte, result); - } - ); + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32, $jsilcore.TypeRef("System.Base64FormattingOptions") + ], [])), + toBase64StringImpl + ); + + $.Method({ Static: true, Public: true }, "FromBase64String", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.String], [])), + function FromBase64String(s) { + var lengthErrorMessage = "Invalid length for a Base-64 char array."; + var contentErrorMessage = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."; + + var result = []; + var reader = $jsilcore.makeCharacterReader(s); + var sum = 0; + var ch0 = 0, ch1 = 0, ch2 = 0, ch3 = 0; + var index0 = -1, index1 = -1, index2 = -1, index3 = -1; + var equals = "=".charCodeAt(0); + + while (true) { + ch0 = reader.read(); + if (ch0 === false) + break; + if (base64IgnoredCodepoints.indexOf(ch0) >= 0) + continue; + + ch1 = reader.read(); + ch2 = reader.read(); + ch3 = reader.read(); + + if ((ch1 === false) || (ch2 === false) || (ch3 === false)) + throw new System.FormatException(lengthErrorMessage); + + index0 = base64CodeTable.indexOf(ch0); + index1 = base64CodeTable.indexOf(ch1); + index2 = base64CodeTable.indexOf(ch2); + index3 = base64CodeTable.indexOf(ch3); + + if ( + (index0 < 0) || (index0 > 63) || + (index1 < 0) || (index1 > 63) + ) + throw new System.FormatException(contentErrorMessage); + + sum = (index0 << 18) | (index1 << 12); + + if (index2 >= 0) + sum |= (index2 << 6); + else if (ch2 !== equals) + throw new System.FormatException(contentErrorMessage); + + if (index3 >= 0) + sum |= (index3 << 0); + else if (ch3 !== equals) + throw new System.FormatException(contentErrorMessage); + + result.push((sum >> 16) & 0xFF); + if (index2 >= 0) + result.push((sum >> 8) & 0xFF); + if (index3 >= 0) + result.push(sum & 0xFF); + } + + return JSIL.Array.New($jsilcore.System.Byte, result); + } + ); }); JSIL.MakeStaticClass("System.Convert", true, [], function ($) { @@ -3999,727 +3964,727 @@ JSIL.MakeStaticClass("System.Convert", true, [], function ($) { $jsilcore.SerializationScratchBuffers = null; $jsilcore.GetSerializationScratchBuffers = function () { - if (!$jsilcore.SerializationScratchBuffers) { - var uint8 = new Uint8Array(32); - var buffer = uint8.buffer; - - $jsilcore.SerializationScratchBuffers = { - uint8: uint8, - uint16: new Uint16Array(buffer), - uint32: new Uint32Array(buffer), - int8: new Int8Array(buffer), - int16: new Int16Array(buffer), - int32: new Int32Array(buffer), - float32: new Float32Array(buffer), - float64: new Float64Array(buffer), - slice: function (byteCount) { - byteCount = byteCount | 0; - - var result = new Uint8Array(byteCount); - for (var i = 0; i < byteCount; i++) - result[i] = this.uint8[i]; - - return result; - }, - fillFrom: function (bytes, offset, count) { - offset = offset | 0; - count = count | 0; - - for (var i = 0; i < count; i++) - this.uint8[i] = bytes[offset + i]; - } - }; - } + if (!$jsilcore.SerializationScratchBuffers) { + var uint8 = new Uint8Array(32); + var buffer = uint8.buffer; + + $jsilcore.SerializationScratchBuffers = { + uint8: uint8, + uint16: new Uint16Array(buffer), + uint32: new Uint32Array(buffer), + int8: new Int8Array(buffer), + int16: new Int16Array(buffer), + int32: new Int32Array(buffer), + float32: new Float32Array(buffer), + float64: new Float64Array(buffer), + slice: function (byteCount) { + byteCount = byteCount | 0; + + var result = new Uint8Array(byteCount); + for (var i = 0; i < byteCount; i++) + result[i] = this.uint8[i]; + + return result; + }, + fillFrom: function (bytes, offset, count) { + offset = offset | 0; + count = count | 0; + + for (var i = 0; i < count; i++) + this.uint8[i] = bytes[offset + i]; + } + }; + } - return $jsilcore.SerializationScratchBuffers; + return $jsilcore.SerializationScratchBuffers; }; $jsilcore.BytesFromBoolean = function (value) { - return [value ? 1 : 0]; + return [value ? 1 : 0]; }; $jsilcore.BytesFromSingle = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.float32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.float32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromDouble = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.float64[0] = value; - return bufs.slice(8); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.float64[0] = value; + return bufs.slice(8); }; $jsilcore.BytesFromInt16 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.int16[0] = value; - return bufs.slice(2); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.int16[0] = value; + return bufs.slice(2); }; $jsilcore.BytesFromInt32 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.int32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.int32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromInt64 = function (value) { - return [ - (value.a >> 0) & 0xFF, - (value.a >> 8) & 0xFF, - (value.a >> 16) & 0xFF, - (value.b >> 0) & 0xFF, - (value.b >> 8) & 0xFF, - (value.b >> 16) & 0xFF, - (value.c >> 0) & 0xFF, - (value.c >> 8) & 0xFF - ]; + return [ + (value.a >> 0) & 0xFF, + (value.a >> 8) & 0xFF, + (value.a >> 16) & 0xFF, + (value.b >> 0) & 0xFF, + (value.b >> 8) & 0xFF, + (value.b >> 16) & 0xFF, + (value.c >> 0) & 0xFF, + (value.c >> 8) & 0xFF + ]; }; // FIXME: Are these unsigned versions right? $jsilcore.BytesFromUInt16 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.uint16[0] = value; - return bufs.slice(2); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.uint16[0] = value; + return bufs.slice(2); }; $jsilcore.BytesFromUInt32 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.uint32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.uint32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromUInt64 = function (value) { - return [ - (value.a >>> 0) & 0xFF, - (value.a >>> 8) & 0xFF, - (value.a >>> 16) & 0xFF, - (value.b >>> 0) & 0xFF, - (value.b >>> 8) & 0xFF, - (value.b >>> 16) & 0xFF, - (value.c >>> 0) & 0xFF, - (value.c >>> 8) & 0xFF - ]; + return [ + (value.a >>> 0) & 0xFF, + (value.a >>> 8) & 0xFF, + (value.a >>> 16) & 0xFF, + (value.b >>> 0) & 0xFF, + (value.b >>> 8) & 0xFF, + (value.b >>> 16) & 0xFF, + (value.c >>> 0) & 0xFF, + (value.c >>> 8) & 0xFF + ]; }; $jsilcore.BytesToBoolean = function (bytes, offset) { - return bytes[offset] !== 0; + return bytes[offset] !== 0; }; $jsilcore.BytesToInt16 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 2); - return bufs.int16[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 2); + return bufs.int16[0]; }; $jsilcore.BytesToInt32 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.int32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.int32[0]; }; $jsilcore.BytesToInt64 = function (bytes, offset) { - return $jsilcore.System.Int64.FromBytes(bytes, offset); + return $jsilcore.System.Int64.FromBytes(bytes, offset); }; $jsilcore.BytesToUInt16 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 2); - return bufs.uint16[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 2); + return bufs.uint16[0]; }; $jsilcore.BytesToUInt32 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.uint32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.uint32[0]; }; $jsilcore.BytesToUInt64 = function (bytes, offset) { - return $jsilcore.System.UInt64.FromBytes(bytes, offset); + return $jsilcore.System.UInt64.FromBytes(bytes, offset); }; $jsilcore.BytesToSingle = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.float32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.float32[0]; }; $jsilcore.BytesToDouble = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 8); - return bufs.float64[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 8); + return bufs.float64[0]; }; JSIL.ImplementExternals("System.BitConverter", function ($) { - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Boolean], [])), - $jsilcore.BytesFromBoolean - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int16], [])), - $jsilcore.BytesFromInt16 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int32], [])), - $jsilcore.BytesFromInt32 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int64], [])), - $jsilcore.BytesFromInt64 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt16], [])), - $jsilcore.BytesFromUInt16 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt32], [])), - $jsilcore.BytesFromUInt32 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt64], [])), - $jsilcore.BytesFromUInt64 - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Single], [])), - $jsilcore.BytesFromSingle - ); - - $.Method({Static:true , Public:true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Double], [])), - $jsilcore.BytesFromDouble - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Boolean], [])), + $jsilcore.BytesFromBoolean + ); - /* + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int16], [])), + $jsilcore.BytesFromInt16 + ); - $.Method({Static:true , Public:false}, "GetHexValue", - (new JSIL.MethodSignature($.Char, [$.Int32], [])), - function GetHexValue (i) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int32], [])), + $jsilcore.BytesFromInt32 + ); - $.Method({Static:true , Public:true }, "Int64BitsToDouble", - (new JSIL.MethodSignature($.Double, [$.Int64], [])), - function Int64BitsToDouble (value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int64], [])), + $jsilcore.BytesFromInt64 + ); - $.Method({Static:true , Public:true }, "ToChar", - (new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - function ToChar (value, startIndex) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt16], [])), + $jsilcore.BytesFromUInt16 + ); - */ + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt32], [])), + $jsilcore.BytesFromUInt32 + ); - $.Method({Static:true , Public:true }, "ToBoolean", - (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToBoolean - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt64], [])), + $jsilcore.BytesFromUInt64 + ); - $.Method({Static:true , Public:true }, "ToInt16", - (new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt16 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Single], [])), + $jsilcore.BytesFromSingle + ); - $.Method({Static:true , Public:true }, "ToInt32", - (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt32 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Double], [])), + $jsilcore.BytesFromDouble + ); - $.Method({Static:true , Public:true }, "ToInt64", - (new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt64 - ); + /* + + $.Method({Static:true , Public:false}, "GetHexValue", + (new JSIL.MethodSignature($.Char, [$.Int32], [])), + function GetHexValue (i) { + throw new Error('Not implemented'); + } + ); + + $.Method({Static:true , Public:true }, "Int64BitsToDouble", + (new JSIL.MethodSignature($.Double, [$.Int64], [])), + function Int64BitsToDouble (value) { + throw new Error('Not implemented'); + } + ); + + $.Method({Static:true , Public:true }, "ToChar", + (new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + function ToChar (value, startIndex) { + throw new Error('Not implemented'); + } + ); + + */ - /* + $.Method({ Static: true, Public: true }, "ToBoolean", + (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToBoolean + ); - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32 - ], [])), - function ToString (value, startIndex, length) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "ToInt16", + (new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt16 + ); - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), - function ToString (value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "ToInt32", + (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt32 + ); - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - function ToString (value, startIndex) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: true, Public: true }, "ToInt64", + (new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt64 + ); - */ + /* + + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32 + ], [])), + function ToString (value, startIndex, length) { + throw new Error('Not implemented'); + } + ); + + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), + function ToString (value) { + throw new Error('Not implemented'); + } + ); + + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + function ToString (value, startIndex) { + throw new Error('Not implemented'); + } + ); + + */ - $.Method({Static:true , Public:true }, "ToUInt16", - (new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt16 - ); + $.Method({ Static: true, Public: true }, "ToUInt16", + (new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt16 + ); - $.Method({Static:true , Public:true }, "ToUInt32", - (new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt32 - ); + $.Method({ Static: true, Public: true }, "ToUInt32", + (new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt32 + ); - $.Method({Static:true , Public:true }, "ToUInt64", - (new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt64 - ); + $.Method({ Static: true, Public: true }, "ToUInt64", + (new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt64 + ); - $.Method({Static:true , Public:true }, "ToSingle", - (new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToSingle - ); + $.Method({ Static: true, Public: true }, "ToSingle", + (new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToSingle + ); - $.Method({Static:true , Public:true }, "ToDouble", - (new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToDouble - ); + $.Method({ Static: true, Public: true }, "ToDouble", + (new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToDouble + ); }); JSIL.MakeStaticClass("System.BitConverter", true, [], function ($) { }); JSIL.ParseDataURL = function (dataUrl) { - var colonIndex = dataUrl.indexOf(":"); - if ((colonIndex != 4) || (dataUrl.substr(0, 5) !== "data:")) - JSIL.RuntimeError("Invalid Data URL header"); + var colonIndex = dataUrl.indexOf(":"); + if ((colonIndex != 4) || (dataUrl.substr(0, 5) !== "data:")) + JSIL.RuntimeError("Invalid Data URL header"); - var semicolonIndex = dataUrl.indexOf(";"); - var mimeType = dataUrl.substr(colonIndex + 1, semicolonIndex - colonIndex - 1); + var semicolonIndex = dataUrl.indexOf(";"); + var mimeType = dataUrl.substr(colonIndex + 1, semicolonIndex - colonIndex - 1); - var commaIndex = dataUrl.indexOf(","); - if (commaIndex <= semicolonIndex) - JSIL.RuntimeError("Invalid Data URL header"); + var commaIndex = dataUrl.indexOf(","); + if (commaIndex <= semicolonIndex) + JSIL.RuntimeError("Invalid Data URL header"); - var encodingType = dataUrl.substr(semicolonIndex + 1, commaIndex - semicolonIndex - 1); - if (encodingType.toLowerCase() !== "base64") - JSIL.RuntimeError("Invalid Data URL encoding type: " + encodingType); + var encodingType = dataUrl.substr(semicolonIndex + 1, commaIndex - semicolonIndex - 1); + if (encodingType.toLowerCase() !== "base64") + JSIL.RuntimeError("Invalid Data URL encoding type: " + encodingType); - var base64 = dataUrl.substr(commaIndex + 1); - var bytes = System.Convert.FromBase64String(base64); + var base64 = dataUrl.substr(commaIndex + 1); + var bytes = System.Convert.FromBase64String(base64); - return [mimeType, bytes]; + return [mimeType, bytes]; }; JSIL.ImplementExternals("System.Collections.Generic.LinkedList`1", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor () { - this.Clear(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.Clear(); + } + ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function _ctor (collection) { - this.Clear(); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function _ctor(collection) { + this.Clear(); - throw new Error('Not implemented'); - } - ); + throw new Error('Not implemented'); + } + ); - var makeNode = function (self, value) { - var tNode = System.Collections.Generic.LinkedListNode$b1.Of(self.T).__Type__; - return JSIL.CreateInstanceOfType(tNode, [self, value]); - }; - - var addIntoEmptyImpl = function (self, node) { - if ((!self._head) && (!self._tail)) { - node._list = self; - self._head = self._tail = node; - self._count = 1; - return true; - } + var makeNode = function (self, value) { + var tNode = System.Collections.Generic.LinkedListNode$b1.Of(self.T).__Type__; + return JSIL.CreateInstanceOfType(tNode, [self, value]); + }; - return false; - } + var addIntoEmptyImpl = function (self, node) { + if ((!self._head) && (!self._tail)) { + node._list = self; + self._head = self._tail = node; + self._count = 1; + return true; + } - var addBeforeImpl = function (self, beforeNode, node) { - if (addIntoEmptyImpl(self, node)) - return; + return false; + } - node._list = self; - node._next = beforeNode; + var addBeforeImpl = function (self, beforeNode, node) { + if (addIntoEmptyImpl(self, node)) + return; - if (beforeNode) - beforeNode._previous = node; + node._list = self; + node._next = beforeNode; - if (self._head === beforeNode) - self._head = node; + if (beforeNode) + beforeNode._previous = node; - self._count += 1; - }; + if (self._head === beforeNode) + self._head = node; - var addAfterImpl = function (self, afterNode, node) { - if (addIntoEmptyImpl(self, node)) - return; + self._count += 1; + }; - node._list = self; - node._previous = afterNode; + var addAfterImpl = function (self, afterNode, node) { + if (addIntoEmptyImpl(self, node)) + return; - if (afterNode) - afterNode._next = node; + node._list = self; + node._previous = afterNode; - if (self._tail === afterNode) - self._tail = node; + if (afterNode) + afterNode._next = node; - self._count += 1; - }; + if (self._tail === afterNode) + self._tail = node; - var addFirstImpl = function (self, node) { - addBeforeImpl(self, self._head, node); - }; + self._count += 1; + }; - var addLastImpl = function (self, node) { - addAfterImpl(self, self._tail, node); - }; + var addFirstImpl = function (self, node) { + addBeforeImpl(self, self._head, node); + }; - $.Method({Static:false, Public:true }, "AddAfter", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddAfter (node, value) { - var newNode = makeNode(self, value); - addAfterImpl(this, node, newNode); - return newNode; - } - ); + var addLastImpl = function (self, node) { + addAfterImpl(self, self._tail, node); + }; - $.Method({Static:false, Public:true }, "AddAfter", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddAfter (node, newNode) { - addAfterImpl(this, node, newNode); - } - ); + $.Method({ Static: false, Public: true }, "AddAfter", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddAfter(node, value) { + var newNode = makeNode(self, value); + addAfterImpl(this, node, newNode); + return newNode; + } + ); - $.Method({Static:false, Public:true }, "AddBefore", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddBefore (node, value) { - var newNode = makeNode(self, value); - addBeforeImpl(this, node, newNode); - return newNode; - } - ); + $.Method({ Static: false, Public: true }, "AddAfter", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddAfter(node, newNode) { + addAfterImpl(this, node, newNode); + } + ); - $.Method({Static:false, Public:true }, "AddBefore", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddBefore (node, newNode) { - addBeforeImpl(this, node, newNode); - } - ); + $.Method({ Static: false, Public: true }, "AddBefore", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddBefore(node, value) { + var newNode = makeNode(self, value); + addBeforeImpl(this, node, newNode); + return newNode; + } + ); - $.Method({Static:false, Public:true }, "AddFirst", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddFirst (value) { - var node = makeNode(this, value); - addFirstImpl(this, node); - return node; - } - ); + $.Method({ Static: false, Public: true }, "AddBefore", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddBefore(node, newNode) { + addBeforeImpl(this, node, newNode); + } + ); - $.Method({Static:false, Public:true }, "AddFirst", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddFirst (node) { - addFirstImpl(this, node); - } - ); + $.Method({ Static: false, Public: true }, "AddFirst", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddFirst(value) { + var node = makeNode(this, value); + addFirstImpl(this, node); + return node; + } + ); - $.Method({Static:false, Public:true }, "AddLast", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddLast (value) { - var node = makeNode(this, value); - addLastImpl(this, node); - return node; - } - ); + $.Method({ Static: false, Public: true }, "AddFirst", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddFirst(node) { + addFirstImpl(this, node); + } + ); - $.Method({Static:false, Public:true }, "AddLast", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddLast (node) { - addLastImpl(this, node); - } - ); + $.Method({ Static: false, Public: true }, "AddLast", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddLast(value) { + var node = makeNode(this, value); + addLastImpl(this, node); + return node; + } + ); - $.Method({Static:false, Public:true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear () { - this._head = null; - this._tail = null; - this._count = 0; - } - ); + $.Method({ Static: false, Public: true }, "AddLast", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddLast(node) { + addLastImpl(this, node); + } + ); - $.Method({Static:false, Public:true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Contains (value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._head = null; + this._tail = null; + this._count = 0; + } + ); - $.Method({Static:false, Public:true }, "CopyTo", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $.Int32], [])), - function CopyTo (array, index) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Contains(value) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true }, "Find", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Find (value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "CopyTo", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $.Int32], [])), + function CopyTo(array, index) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true }, "FindLast", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function FindLast (value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Find", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Find(value) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count () { - return this._count; - } - ); + $.Method({ Static: false, Public: true }, "FindLast", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function FindLast(value) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true }, "get_First", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function get_First () { - return this._head; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; + } + ); - $.Method({Static:false, Public:true }, "get_Last", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function get_Last () { - return this._tail; - } - ); + $.Method({ Static: false, Public: true }, "get_First", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function get_First() { + return this._head; + } + ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function GetEnumerator () { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "get_Last", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function get_Last() { + return this._tail; + } + ); - $.RawMethod(false, "$removeNode", function Remove_Node (node) { - if (node._list !== this) - JSIL.RuntimeError("Node is not a member of this list"); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function GetEnumerator() { + throw new Error('Not implemented'); + } + ); - var previous = node._previous || null; - var next = node._next || null; + $.RawMethod(false, "$removeNode", function Remove_Node(node) { + if (node._list !== this) + JSIL.RuntimeError("Node is not a member of this list"); - if (previous) - previous._next = next; - if (next) - next._previous = previous; + var previous = node._previous || null; + var next = node._next || null; - if (this._head === node) - this._head = next; - else if (this._tail === node) - this._tail = previous; + if (previous) + previous._next = next; + if (next) + next._previous = previous; - node._list = null; - node._count -= 1; - }); + if (this._head === node) + this._head = next; + else if (this._tail === node) + this._tail = previous; - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Remove (value) { - throw new Error('Not implemented'); - } - ); + node._list = null; + node._count -= 1; + }); - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function Remove (node) { - this.$removeNode(node); - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Remove(value) { + throw new Error('Not implemented'); + } + ); - $.Method({Static:false, Public:true }, "RemoveFirst", - (new JSIL.MethodSignature(null, [], [])), - function RemoveFirst () { - this.$removeNode(this._head); - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function Remove(node) { + this.$removeNode(node); + } + ); - $.Method({Static:false, Public:true }, "RemoveLast", - (new JSIL.MethodSignature(null, [], [])), - function RemoveLast () { - this.$removeNode(this._tail); - } - ); + $.Method({ Static: false, Public: true }, "RemoveFirst", + (new JSIL.MethodSignature(null, [], [])), + function RemoveFirst() { + this.$removeNode(this._head); + } + ); + + $.Method({ Static: false, Public: true }, "RemoveLast", + (new JSIL.MethodSignature(null, [], [])), + function RemoveLast() { + this.$removeNode(this._tail); + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.LinkedListNode`1", function ($) { - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function _ctor (value) { - this._list = null; - this._value = value; - this._previous = null; - this._next = null; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function _ctor(value) { + this._list = null; + this._value = value; + this._previous = null; + this._next = null; + } + ); - $.Method({Static:false, Public:false}, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function _ctor (list, value) { - this._list = list; - this._value = value; - this._previous = null; - this._next = null; - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function _ctor(list, value) { + this._list = list; + this._value = value; + this._previous = null; + this._next = null; + } + ); - $.Method({Static:false, Public:true }, "get_List", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_List () { - return this._list; - } - ); + $.Method({ Static: false, Public: true }, "get_List", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_List() { + return this._list; + } + ); - $.Method({Static:false, Public:true }, "get_Next", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_Next () { - return this._next; - } - ); + $.Method({ Static: false, Public: true }, "get_Next", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_Next() { + return this._next; + } + ); - $.Method({Static:false, Public:true }, "get_Previous", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_Previous () { - return this._previous; - } - ); + $.Method({ Static: false, Public: true }, "get_Previous", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_Previous() { + return this._previous; + } + ); - $.Method({Static:false, Public:true }, "get_Value", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1"), [], [])), - function get_Value () { - return this._value; - } - ); + $.Method({ Static: false, Public: true }, "get_Value", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1"), [], [])), + function get_Value() { + return this._value; + } + ); - $.Method({Static:false, Public:true }, "set_Value", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function set_Value (value) { - this._value = value; - } - ); + $.Method({ Static: false, Public: true }, "set_Value", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function set_Value(value) { + this._value = value; + } + ); }); JSIL.MakeInterface( - "System.Collections.IComparer", true, [], + "System.Collections.IComparer", true, [], function ($) { - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [$.Object, $.Object], []) - ); + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [$.Object, $.Object], []) + ); }, [] ); JSIL.MakeInterface( - "System.Collections.Generic.IComparer`1", true, ["in T"], + "System.Collections.Generic.IComparer`1", true, ["in T"], function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.IComparer`1").in(); + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.IComparer`1").in(); - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [T, T], []) - ); + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [T, T], []) + ); }, [] ); JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Collections.Generic.Comparer`1", true, ["T"], function ($) { - var $thisType = $.publicInterface; + var $thisType = $.publicInterface; - $.ExternalMethod({Static:true , Public:true }, "get_Default", - new JSIL.MethodSignature($.Type, [], []) - ); + $.ExternalMethod({ Static: true, Public: true }, "get_Default", + new JSIL.MethodSignature($.Type, [], []) + ); - $.GenericProperty({Static:true , Public:true }, "Default", $.Type); + $.GenericProperty({ Static: true, Public: true }, "Default", $.Type); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.IComparer"), - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [ - new JSIL.GenericParameter("T", "System.Collections.Generic.Comparer`1") - ]) - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.IComparer"), + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [ + new JSIL.GenericParameter("T", "System.Collections.Generic.Comparer`1") + ]) + ); }); JSIL.ImplementExternals("System.Collections.Generic.Comparer`1", function ($) { - $.Method({Static:true , Public:true }, "get_Default", - new JSIL.MethodSignature($.Type, [], []), - function get_Default () { - // HACK - return new (JSIL.DefaultComparer$b1.Of(this.T)); - } - ); + $.Method({ Static: true, Public: true }, "get_Default", + new JSIL.MethodSignature($.Type, [], []), + function get_Default() { + // HACK + return new (JSIL.DefaultComparer$b1.Of(this.T)); + } + ); }); JSIL.MakeClass( - $jsilcore.TypeRef("System.Collections.Generic.Comparer`1", [new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1")]), - "JSIL.DefaultComparer`1", true, ["T"], + $jsilcore.TypeRef("System.Collections.Generic.Comparer`1", [new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1")]), + "JSIL.DefaultComparer`1", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1"); - - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [T, T], []), - function Compare (lhs, rhs) { - if (lhs === null) { - if (rhs === null) - return 0; - else - return -1; - } else if (rhs === null) - return 1; - - if (typeof (lhs.CompareTo) === "function") - return lhs.CompareTo(rhs); - - if (lhs < rhs) - return -1; - else if (lhs > rhs) - return 1; - else - return 0; - } - ); + var T = new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1"); + + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [T, T], []), + function Compare(lhs, rhs) { + if (lhs === null) { + if (rhs === null) + return 0; + else + return -1; + } else if (rhs === null) + return 1; + + if (typeof (lhs.CompareTo) === "function") + return lhs.CompareTo(rhs); + + if (lhs < rhs) + return -1; + else if (lhs > rhs) + return 1; + else + return 0; + } + ); } ); JSIL.MakeInterface( "System.ITuple", false, [], function ($) { - $.Method({}, "ToString", (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Text.StringBuilder")], []))); - $.Method({}, "GetHashCode", (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Collections.IEqualityComparer")], []))); - $.Method({}, "get_Size", (new JSIL.MethodSignature($.Int32, [], []))); - $.Property({}, "Size"); + $.Method({}, "ToString", (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Text.StringBuilder")], []))); + $.Method({}, "GetHashCode", (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Collections.IEqualityComparer")], []))); + $.Method({}, "get_Size", (new JSIL.MethodSignature($.Int32, [], []))); + $.Property({}, "Size"); }, []); JSIL.MakeStaticClass("System.Tuple", true, [], function ($) { @@ -4754,191 +4719,191 @@ JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Tuple`9", true, ["T1" JSIL.MakeInterface( "System.IAsyncResult", true, [], function ($) { - $.Method({}, "get_IsCompleted", new JSIL.MethodSignature($.Boolean, [], [])); - $.Method({}, "get_AsyncWaitHandle", new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.WaitHandle"), [], [])); - $.Method({}, "get_AsyncState", new JSIL.MethodSignature($.Object, [], [])); - $.Method({}, "get_CompletedSynchronously", new JSIL.MethodSignature($.Boolean, [], [])); - $.Property({}, "IsCompleted"); - $.Property({}, "AsyncWaitHandle"); - $.Property({}, "AsyncState"); - $.Property({}, "CompletedSynchronously"); + $.Method({}, "get_IsCompleted", new JSIL.MethodSignature($.Boolean, [], [])); + $.Method({}, "get_AsyncWaitHandle", new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.WaitHandle"), [], [])); + $.Method({}, "get_AsyncState", new JSIL.MethodSignature($.Object, [], [])); + $.Method({}, "get_CompletedSynchronously", new JSIL.MethodSignature($.Boolean, [], [])); + $.Property({}, "IsCompleted"); + $.Property({}, "AsyncWaitHandle"); + $.Property({}, "AsyncState"); + $.Property({}, "CompletedSynchronously"); }, []); JSIL.ImplementExternals("System.Array", function ($) { - var copyImpl = function (sourceArray, sourceIndex, destinationArray, destinationIndex, length) { - if (length < 0) - throw new System.ArgumentException("length"); - if (sourceIndex < 0) - throw new System.ArgumentException("sourceIndex"); - if (destinationIndex < 0) - throw new System.ArgumentException("destinationIndex"); - - var maxLength = Math.min( - (sourceArray.length - sourceIndex) | 0, - (destinationArray.length - destinationIndex) | 0 - ); - if (length > maxLength) - throw new System.ArgumentException("length"); - - length = length | 0; - - for (var i = 0; i < length; i = (i + 1) | 0) { - destinationArray[i + destinationIndex] = sourceArray[i + sourceIndex]; - } - }; - - $.Method({Static:true , Public:true }, "Copy", - new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array"), $jsilcore.TypeRef("System.Array"), - $.Int32 - ], []), - function Copy (sourceArray, destinationArray, length) { - copyImpl(sourceArray, 0, destinationArray, 0, length); - } - ); + var copyImpl = function (sourceArray, sourceIndex, destinationArray, destinationIndex, length) { + if (length < 0) + throw new System.ArgumentException("length"); + if (sourceIndex < 0) + throw new System.ArgumentException("sourceIndex"); + if (destinationIndex < 0) + throw new System.ArgumentException("destinationIndex"); + + var maxLength = Math.min( + (sourceArray.length - sourceIndex) | 0, + (destinationArray.length - destinationIndex) | 0 + ); + if (length > maxLength) + throw new System.ArgumentException("length"); - $.Method({ Static: true, Public: true }, "Sort", - (new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array", ["!!0"]), - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), - function Sort(type, array, comparer) { - var tComparer = System.Collections.Generic.IComparer$b1.Of(type); - var compare = tComparer.Compare; + length = length | 0; - Array.prototype.sort.call(array, function (lhs, rhs) { - return compare.Call(comparer, null, lhs, rhs); - }); + for (var i = 0; i < length; i = (i + 1) | 0) { + destinationArray[i + destinationIndex] = sourceArray[i + sourceIndex]; } -); + }; - $.Method({Static:true , Public:true }, "Copy", - new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array"), $.Int32, - $jsilcore.TypeRef("System.Array"), $.Int32, - $.Int32 - ], []), - function Copy (sourceArray, sourceIndex, destinationArray, destinationIndex, length) { - copyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length); - } + $.Method({ Static: true, Public: true }, "Copy", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array"), $jsilcore.TypeRef("System.Array"), + $.Int32 + ], []), + function Copy(sourceArray, destinationArray, length) { + copyImpl(sourceArray, 0, destinationArray, 0, length); + } + ); + + $.Method({ Static: true, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array", ["!!0"]), + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), + function Sort(type, array, comparer) { + var tComparer = System.Collections.Generic.IComparer$b1.Of(type); + var compare = tComparer.Compare; + + Array.prototype.sort.call(array, function (lhs, rhs) { + return compare.Call(comparer, null, lhs, rhs); + }); + } ); + + $.Method({ Static: true, Public: true }, "Copy", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array"), $.Int32, + $jsilcore.TypeRef("System.Array"), $.Int32, + $.Int32 + ], []), + function Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) { + copyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length); + } + ); }); JSIL.MakeInterface( "System.IConvertible", true, [], function ($) { - $.Method({}, "GetTypeCode", new JSIL.MethodSignature($jsilcore.TypeRef("System.TypeCode"), [], [])); - $.Method({}, "ToBoolean", new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToChar", new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToSByte", new JSIL.MethodSignature($.SByte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToByte", new JSIL.MethodSignature($.Byte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt16", new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt16", new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt32", new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt32", new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt64", new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt64", new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToSingle", new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDouble", new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDecimal", new JSIL.MethodSignature($jsilcore.TypeRef("System.Decimal"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDateTime", new JSIL.MethodSignature($jsilcore.TypeRef("System.DateTime"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToString", new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToType", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "GetTypeCode", new JSIL.MethodSignature($jsilcore.TypeRef("System.TypeCode"), [], [])); + $.Method({}, "ToBoolean", new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToChar", new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToSByte", new JSIL.MethodSignature($.SByte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToByte", new JSIL.MethodSignature($.Byte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt16", new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt16", new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt32", new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt32", new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt64", new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt64", new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToSingle", new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDouble", new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDecimal", new JSIL.MethodSignature($jsilcore.TypeRef("System.Decimal"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDateTime", new JSIL.MethodSignature($jsilcore.TypeRef("System.DateTime"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToString", new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToType", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.IFormatProvider")], [])); }, []); - + JSIL.MakeInterface( "System.IFormatProvider", true, [], function ($) { - $.Method({}, "GetFormat", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type")], [])); + $.Method({}, "GetFormat", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type")], [])); }, []); JSIL.ImplementExternals("System.WeakReference", function ($) { - var warnedAboutWeakReferences = false; - - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Object], [])), - function _ctor (target) { - // FIXME - if (!warnedAboutWeakReferences) { - warnedAboutWeakReferences = true; - JSIL.Host.warning("Weak references are not supported by JavaScript"); + var warnedAboutWeakReferences = false; + + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Object], [])), + function _ctor(target) { + // FIXME + if (!warnedAboutWeakReferences) { + warnedAboutWeakReferences = true; + JSIL.Host.warning("Weak references are not supported by JavaScript"); + } } - } - ); + ); }); JSIL.ImplementExternals("System.Diagnostics.Trace", function ($) { - $.Method({Static:true , Public:true }, "TraceError", - new JSIL.MethodSignature(null, [$.String], []), - function TraceError (message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.error(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceError", + new JSIL.MethodSignature(null, [$.String], []), + function TraceError(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.error(message); + } + ); - $.Method({Static:true , Public:true }, "TraceError", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceError (format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.error(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceError", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceError(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.error(message); + } + ); - $.Method({Static:true , Public:true }, "TraceInformation", - new JSIL.MethodSignature(null, [$.String], []), - function TraceInformation (message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.information(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceInformation", + new JSIL.MethodSignature(null, [$.String], []), + function TraceInformation(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.information(message); + } + ); - $.Method({Static:true , Public:true }, "TraceInformation", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceInformation (format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.information(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceInformation", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceInformation(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.information(message); + } + ); - $.Method({Static:true , Public:true }, "TraceWarning", - new JSIL.MethodSignature(null, [$.String], []), - function TraceWarning (message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.warning(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceWarning", + new JSIL.MethodSignature(null, [$.String], []), + function TraceWarning(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.warning(message); + } + ); - $.Method({Static:true , Public:true }, "TraceWarning", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceWarning (format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.warning(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceWarning", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceWarning(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.warning(message); + } + ); - $.Method({Static:true , Public:true }, "WriteLine", - new JSIL.MethodSignature(null, [$.String], []), - function WriteLine (message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.write(message); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + new JSIL.MethodSignature(null, [$.String], []), + function WriteLine(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.write(message); + } + ); - $.Method({Static:true , Public:true }, "WriteLine", - new JSIL.MethodSignature(null, [$.String, $.String], []), - function WriteLine (message, category) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.write(message, category); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + new JSIL.MethodSignature(null, [$.String, $.String], []), + function WriteLine(message, category) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.write(message, category); + } + ); }); JSIL.MakeStaticClass("System.Diagnostics.Trace", true, [], function ($) { diff --git a/Libraries/JSIL.Core.Types.js b/Libraries/JSIL.Core.Types.js index f734a2e51..5675b8e5f 100644 --- a/Libraries/JSIL.Core.Types.js +++ b/Libraries/JSIL.Core.Types.js @@ -524,6 +524,30 @@ JSIL.ImplementExternals( arr.set(newArray); } ); + + $.Method({ Static: true, Public: false }, "UnsafeStore", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32, + "!!0" + ], ["T"]), + function (T, array, index, value) { + array[index] = value; + } + ); + + $.Method({ Static: true, Public: false }, "UnsafeLoad", + new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32], ["T"]), + function(T, array, index) { + return array[index]; + } + ); + + $.Method({ Static: true, Public: false }, "UnsafeMov", + new JSIL.MethodSignature("!!1", ["!!0"], ["S", "R"]), + function (S, R, instance) { + return R.$Cast(instance); + } + ); } ); diff --git a/Meta/Attributes.cs b/Meta/Attributes.cs index e07cbc0d9..4e9e6d7d9 100644 --- a/Meta/Attributes.cs +++ b/Meta/Attributes.cs @@ -1,209 +1,209 @@ -using System; - -namespace JSIL.Meta { - public enum JSReadPolicy { - Unmodified, - LogWarning, - ThrowError, - ReturnDefaultValue - } - - public enum JSInvokePolicy { - Unmodified, - LogWarning, - ThrowError, - ReturnDefaultValue - } - - public enum JSWritePolicy { - Unmodified, - LogWarning, - ThrowError, - DiscardValue - } - - /// - /// Specifies that a class, method, property or field should be ignored when translating code to JavaScript. - /// - [AttributeUsage( - AttributeTargets.Class | AttributeTargets.Method | - AttributeTargets.Property | AttributeTargets.Field | - AttributeTargets.Event | AttributeTargets.Constructor | - AttributeTargets.Module | AttributeTargets.Struct | - AttributeTargets.Enum | AttributeTargets.Interface - )] - public class JSIgnore : Attribute { +using System; + +namespace JSIL.Meta { + public enum JSReadPolicy { + Unmodified, + LogWarning, + ThrowError, + ReturnDefaultValue + } + + public enum JSInvokePolicy { + Unmodified, + LogWarning, + ThrowError, + ReturnDefaultValue + } + + public enum JSWritePolicy { + Unmodified, + LogWarning, + ThrowError, + DiscardValue + } + + /// + /// Specifies that a class, method, property or field should be ignored when translating code to JavaScript. + /// + [AttributeUsage( + AttributeTargets.Class | AttributeTargets.Method | + AttributeTargets.Property | AttributeTargets.Field | + AttributeTargets.Event | AttributeTargets.Constructor | + AttributeTargets.Module | AttributeTargets.Struct | + AttributeTargets.Enum | AttributeTargets.Interface + )] + public class JSIgnore : Attribute { } /// /// Specifies that this type is implemented externally and only stub should be generated when translating code to JavaScript /// (but does not prevent use of the type like and does.) - /// - [AttributeUsage(AttributeTargets.Class)] - public class JSStubOnly : Attribute - { - } - - /// - /// Specifies a policy to apply to reads, writes, or invocations of a member when translating code to JavaScript. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Property | - AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Constructor - )] - public class JSPolicy : Attribute { - public JSPolicy ( - JSReadPolicy read = JSReadPolicy.Unmodified, - JSWritePolicy write = JSWritePolicy.Unmodified, - JSInvokePolicy invoke = JSInvokePolicy.Unmodified - ) { - } - } - - /// - /// Specifies that references to this identifier should be replaced with a specified javascript expression when translating code to JavaScript. - /// To refer to a parameter within the replacement expression, prefix the parameter name with a dollar sign - the this-reference becomes $this, for example. - /// To insert a dollar sign into the replacement expression, write '$$'. - /// When replacing a constructor, '$this' can be used to refer to the this-reference if the constructor is being called in-place on a struct instance. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Constructor | - AttributeTargets.Property | AttributeTargets.Class | - AttributeTargets.Struct - )] - public class JSReplacement : Attribute { - public JSReplacement (string expression) { - } - } - - /// - /// Specifies that the name of this member or type should be changed when translating code to javascript. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Field | - AttributeTargets.Property | AttributeTargets.Class | - AttributeTargets.Struct | AttributeTargets.Enum - )] - public class JSChangeName : Attribute { - public JSChangeName (string newName) { - } - } - - /// - /// Specifies that uses of this constructor should be replaced with invocations of a static method. - /// - [AttributeUsage( - AttributeTargets.Constructor - )] - public class JSChangeToStaticMethod : Attribute { - public JSChangeToStaticMethod (string staticMethodName) { - } - } - - /// - /// Specifies that, if overloaded, the correct overload of this method to invoke should be decided at runtime instead of compile time. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Constructor | - AttributeTargets.Property - )] - public class JSRuntimeDispatch : Attribute { - } - - /// - /// Specifies that this member or type is implemented externally and should not be generated when translating code to JavaScript - /// (but does not prevent use of the member/type like does.) - /// Note that while external methods will generate a clear warning at runtime if used without being defined, the same is not true - /// for fields or classes - fields will simply be undefined, and classes may produce a JavaScript TypeError or ReferenceError. - /// The behavior of external properties depends on where you apply the attribute: Marking the property itself as external means - /// that the property definition will be omitted and the getter and setter will not be translated. - /// Marking a property's getter or setter as external behaves the same as marking a method as external - the property definition - /// will still be translated, so once the externals are implemented the property will work as expected. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Constructor | - AttributeTargets.Property | AttributeTargets.Class | - AttributeTargets.Field - )] - public class JSExternal : Attribute { - } - - /// - /// Specifies that this method should be renamed to .cctor2 so that it runs as a second static constructor for the containing - /// type in JS. If the method is part of a proxy, it will run as the second static constructor for the proxied type(s). - /// - [AttributeUsage( - AttributeTargets.Constructor - )] - public class JSExtraStaticConstructor : Attribute { - } - - /// - /// Specifies that you wish to replace an existing constructor with one from your proxy. This is necessary because - /// the compiler automatically generates hidden constructors for your proxy classes. - /// - [AttributeUsage( - AttributeTargets.Constructor - )] - public class JSReplaceConstructor : Attribute { - } - - /// - /// If applied to a field, specifies that you wish for JSIL to treat the specified field as if it is immutable. - /// Struct copies will not be generated for the annotated field or any of its members. - /// If applied to a class/struct, the class/struct and all its fields are treated as if they are immutable. - /// - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Class | AttributeTargets.Struct - )] - public class JSImmutable : Attribute { - } - - /// - /// Specifies that it is invalid to access this property by invoking its getter/setter - /// methods directly in JavaScript. - /// - [AttributeUsage( - AttributeTargets.Property - )] - public class JSAlwaysAccessAsProperty : Attribute { - } - - /// - /// Specifies that the target should be represented as a packed struct array in JavaScript - /// instead of as a normal JavaScript array containing object instances. - /// - [AttributeUsage(AttributeTargets.Field)] - [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] - public class JSPackedArray : Attribute { - } - - /// - /// Specifies that JSIL should represent the named argument(s) as packed arrays. - /// - [AttributeUsage(AttributeTargets.Method)] - [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] - public class JSPackedArrayArgumentsAttribute : Attribute { - public readonly string[] ArgumentNames; - - public JSPackedArrayArgumentsAttribute (params string[] argumentNames) { - ArgumentNames = argumentNames; - } - } - - /// - /// Specifies that JSIL should represent the function's return value as a packed array. - /// - [AttributeUsage(AttributeTargets.Method)] - [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] - public class JSPackedArrayReturnValueAttribute : Attribute { - } - - /// - /// Specifies that the function can accept arguments that are packed arrays but does not require them. - /// - [AttributeUsage(AttributeTargets.Method)] - public class JSAllowPackedArrayArgumentsAttribute : Attribute { - } -} + /// + [AttributeUsage(AttributeTargets.Class)] + public class JSStubOnly : Attribute + { + } + + /// + /// Specifies a policy to apply to reads, writes, or invocations of a member when translating code to JavaScript. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Property | + AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Constructor + )] + public class JSPolicy : Attribute { + public JSPolicy ( + JSReadPolicy read = JSReadPolicy.Unmodified, + JSWritePolicy write = JSWritePolicy.Unmodified, + JSInvokePolicy invoke = JSInvokePolicy.Unmodified + ) { + } + } + + /// + /// Specifies that references to this identifier should be replaced with a specified javascript expression when translating code to JavaScript. + /// To refer to a parameter within the replacement expression, prefix the parameter name with a dollar sign - the this-reference becomes $this, for example. + /// To insert a dollar sign into the replacement expression, write '$$'. + /// When replacing a constructor, '$this' can be used to refer to the this-reference if the constructor is being called in-place on a struct instance. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Constructor | + AttributeTargets.Property | AttributeTargets.Class | + AttributeTargets.Struct + )] + public class JSReplacement : Attribute { + public JSReplacement (string expression) { + } + } + + /// + /// Specifies that the name of this member or type should be changed when translating code to javascript. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Field | + AttributeTargets.Property | AttributeTargets.Class | + AttributeTargets.Struct | AttributeTargets.Enum + )] + public class JSChangeName : Attribute { + public JSChangeName (string newName) { + } + } + + /// + /// Specifies that uses of this constructor should be replaced with invocations of a static method. + /// + [AttributeUsage( + AttributeTargets.Constructor + )] + public class JSChangeToStaticMethod : Attribute { + public JSChangeToStaticMethod (string staticMethodName) { + } + } + + /// + /// Specifies that, if overloaded, the correct overload of this method to invoke should be decided at runtime instead of compile time. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Constructor | + AttributeTargets.Property + )] + public class JSRuntimeDispatch : Attribute { + } + + /// + /// Specifies that this member or type is implemented externally and should not be generated when translating code to JavaScript + /// (but does not prevent use of the member/type like does.) + /// Note that while external methods will generate a clear warning at runtime if used without being defined, the same is not true + /// for fields or classes - fields will simply be undefined, and classes may produce a JavaScript TypeError or ReferenceError. + /// The behavior of external properties depends on where you apply the attribute: Marking the property itself as external means + /// that the property definition will be omitted and the getter and setter will not be translated. + /// Marking a property's getter or setter as external behaves the same as marking a method as external - the property definition + /// will still be translated, so once the externals are implemented the property will work as expected. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Constructor | + AttributeTargets.Property | AttributeTargets.Class | + AttributeTargets.Field + )] + public class JSExternal : Attribute { + } + + /// + /// Specifies that this method should be renamed to .cctor2 so that it runs as a second static constructor for the containing + /// type in JS. If the method is part of a proxy, it will run as the second static constructor for the proxied type(s). + /// + [AttributeUsage( + AttributeTargets.Constructor + )] + public class JSExtraStaticConstructor : Attribute { + } + + /// + /// Specifies that you wish to replace an existing constructor with one from your proxy. This is necessary because + /// the compiler automatically generates hidden constructors for your proxy classes. + /// + [AttributeUsage( + AttributeTargets.Constructor + )] + public class JSReplaceConstructor : Attribute { + } + + /// + /// If applied to a field, specifies that you wish for JSIL to treat the specified field as if it is immutable. + /// Struct copies will not be generated for the annotated field or any of its members. + /// If applied to a class/struct, the class/struct and all its fields are treated as if they are immutable. + /// + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Class | AttributeTargets.Struct + )] + public class JSImmutable : Attribute { + } + + /// + /// Specifies that it is invalid to access this property by invoking its getter/setter + /// methods directly in JavaScript. + /// + [AttributeUsage( + AttributeTargets.Property + )] + public class JSAlwaysAccessAsProperty : Attribute { + } + + /// + /// Specifies that the target should be represented as a packed struct array in JavaScript + /// instead of as a normal JavaScript array containing object instances. + /// + [AttributeUsage(AttributeTargets.Field)] + [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] + public class JSPackedArray : Attribute { + } + + /// + /// Specifies that JSIL should represent the named argument(s) as packed arrays. + /// + [AttributeUsage(AttributeTargets.Method)] + [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] + public class JSPackedArrayArgumentsAttribute : Attribute { + public readonly string[] ArgumentNames; + + public JSPackedArrayArgumentsAttribute (params string[] argumentNames) { + ArgumentNames = argumentNames; + } + } + + /// + /// Specifies that JSIL should represent the function's return value as a packed array. + /// + [AttributeUsage(AttributeTargets.Method)] + [JSIL.Runtime.LinkedType(typeof(JSIL.Runtime.IPackedArray<>))] + public class JSPackedArrayReturnValueAttribute : Attribute { + } + + /// + /// Specifies that the function can accept arguments that are packed arrays but does not require them. + /// + [AttributeUsage(AttributeTargets.Method)] + public class JSAllowPackedArrayArgumentsAttribute : Attribute { + } +} diff --git a/Proxies/Array.cs b/Proxies/Array.cs index 806591cf1..0aae65d57 100644 --- a/Proxies/Array.cs +++ b/Proxies/Array.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace JSIL.Proxies { + [JSProxy( typeof(Array), memberPolicy: JSProxyMemberPolicy.ReplaceDeclared diff --git a/Proxies/Bootstrap.cs b/Proxies/Bootstrap.cs new file mode 100644 index 000000000..78bf21efd --- /dev/null +++ b/Proxies/Bootstrap.cs @@ -0,0 +1,117 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(ArrayList), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_ArrayList + { + } + + [JSProxy("System.Collections.ObjectModel.Collection`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_ObjectModel_Collection_1 + { + } + + [JSProxy("System.Collections.ObjectModel.ReadOnlyCollection`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_ObjectModel_ReadOnlyCollection_1 + { + } + + + [JSProxy("System.Collections.Generic.List`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_List_1 + { + } + + [JSProxy("System.Collections.Generic.Stack`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_Stack_1 + { + } + + [JSProxy("System.Collections.Generic.List`1+Enumerator", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_List_1_Enumerator + { + } + + [JSProxy("System.Collections.Generic.Queue`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_Queue_1 + { + } + + [JSProxy(typeof(Interlocked), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Threading_Interlocked + { + } + + [JSProxy("System.Collections.Generic.KeyValuePair`2", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_KeyValuePair_2 + { + } + + [JSProxy("System.Collections.Generic.Dictionary`2", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_Dictionary_2 + { + } + + [JSProxy("System.Collections.Generic.Dictionary`2/Enumerator", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_Dictionary_2_Enumerator + { + } + + [JSProxy("System.Collections.Generic.HashSet`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_HashSet_1 + { + } + + [JSProxy("System.Collections.Generic.LinkedList`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Collections_Generic_LinkedList_1 + { + } + + [JSProxy("System.Collections.Generic.LinkedListNode`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Collections_Generic_LinkedListNode_1 + { + } + + [JSProxy("System.Collections.Generic.Comparer`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Collections_Generic_Comparer_1 + { + } + + [JSProxy(typeof(Tuple), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Tuple + { + } + + [JSProxy(typeof(StackTrace), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Diagnostics_StackTrace + { + } + +} diff --git a/Proxies/Collections.cs b/Proxies/Collections.cs index 331bfa355..e17875876 100644 --- a/Proxies/Collections.cs +++ b/Proxies/Collections.cs @@ -114,4 +114,13 @@ public abstract class CollectionEnumeratorProxy { [JSIsArrayEnumerator("_array", "_index", "_length")] public abstract class ArrayEnumeratorProxy { } + + /*[JSProxy(new[] { + "System.Collections.Generic.Dictionary`2" + })] + [JSStubOnly] + public abstract class GenericDictionaryProxy + { + + }*/ } diff --git a/Proxies/DateTime.cs b/Proxies/DateTime.cs index d33b3c474..c370fee0d 100644 --- a/Proxies/DateTime.cs +++ b/Proxies/DateTime.cs @@ -1,6 +1,7 @@ using System; using JSIL.Meta; using JSIL.Proxy; +using System.Globalization; namespace JSIL.Proxies { [JSProxy( @@ -17,6 +18,142 @@ public abstract class TimeSpanProxy { public static TimeSpanProxy operator - (TimeSpanProxy lhs, TimeSpanProxy rhs) { throw new InvalidOperationException(); } + + + } + + [JSProxy( + typeof(TimeSpan), + JSProxyMemberPolicy.ReplaceDeclared)] + public abstract class TSProxy + { + [JSReplacement("System.TimeSpan.FromMilliseconds($type)")] + [JSIsPure] + public static TimeSpan FromMilliseconds(double d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.FromSeconds($type)")] + [JSIsPure] + public static TimeSpan FromSeconds(double d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.FromMinutes($type)")] + [JSIsPure] + public static TimeSpan FromMinutes(double d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.FromHours($type)")] + [JSIsPure] + public static TimeSpan FromHours(double d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.FromDays($type)")] + [JSIsPure] + public static TimeSpan FromDays(double d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.FromTicks($type)")] + [JSIsPure] + public static TimeSpan FromTicks(long d) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.ctor($type)")] + [JSIsPure] + public TSProxy(long arg) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.ctor($a1, $a2, $a3)")] + [JSIsPure] + public TSProxy(int arg1, int arg2, int arg3) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.ctor($a1, $a2, $a3, $a4)")] + [JSIsPure] + public TSProxy(int arg1, int arg2, int arg3, int arg4) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.ctor($a1, $a2, $a3, $a4, $a5)")] + [JSIsPure] + public TSProxy(int arg1, int arg2, int arg3, int arg4, int arg5) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.get_Days()")] + [JSIsPure] + public int Days { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_Hours()")] + [JSIsPure] + public int Hours { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_Milliseconds()")] + [JSIsPure] + public int Milliseconds { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_Minutes()")] + [JSIsPure] + public int Minutes { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_Seconds()")] + [JSIsPure] + public int Seconds { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_Ticks()")] + [JSIsPure] + public long Ticks { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_TotalMilliseconds()")] + [JSIsPure] + public double TotalMilliseconds { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_TotalSeconds()")] + [JSIsPure] + public double TotalSeconds { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_TotalMinutes()")] + [JSIsPure] + public double TotalMinutes { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_TotalHours()")] + [JSIsPure] + public double TotalHours { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.get_TotalDays()")] + [JSIsPure] + public double TotalDays { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.TimeSpan.Parse($s)")] + [JSIsPure] + public static TimeSpan Parse(string s) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.toString()")] + [JSIsPure] + public static string ToString() + { + throw new InvalidOperationException(); + } } [JSProxy( @@ -29,4 +166,56 @@ public abstract class DateTimeProxy { throw new InvalidOperationException(); } } + + [JSProxy(typeof(DateTime), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + public class System_DateTime + { + [JSExternal] + public System_DateTime(long ticks) + { + throw new NotImplementedException(); + } + + [JSExternal] + private System_DateTime(ulong dateData) + { + throw new NotImplementedException(); + } + + [JSExternal] + public System_DateTime(int year, int month, int day) + { + throw new NotImplementedException(); + } + + [JSExternal] + public System_DateTime(int year, int month, int day, Calendar calendar) + { + throw new NotImplementedException(); + } + + [JSExternal] + public static System.DateTime Now + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public static System.DateTime UtcNow + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public string ToLongTimeString() + { + throw new NotImplementedException(); + } + } } diff --git a/Proxies/Environment.cs b/Proxies/Environment.cs new file mode 100644 index 000000000..e0cd48d34 --- /dev/null +++ b/Proxies/Environment.cs @@ -0,0 +1,28 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(Environment), + JSProxyMemberPolicy.ReplaceDeclared + )] + public class EnvironmentProxy + { + [JSReplacement("System.Environment.GetFolderPath($folder)")] + [JSIsPure] + public static string GetFolderPath(System.Environment.SpecialFolder folder) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.Environment.get_NewLine()")] + [JSIsPure] + public static string NewLine { get { throw new InvalidOperationException(); } } + + [JSReplacement("System.Environment.get_TickCount()")] + [JSIsPure] + public static int TickCount { get { throw new InvalidOperationException(); } } + } +} diff --git a/Proxies/Exceptions.cs b/Proxies/Exceptions.cs new file mode 100644 index 000000000..b245073dc --- /dev/null +++ b/Proxies/Exceptions.cs @@ -0,0 +1,93 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.IO; +using System.Reflection; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(Exception), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Exception + { + } + + [JSProxy(typeof(SystemException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_SystemException + { + } + + [JSProxy(typeof(FormatException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_FormatException + { + } + + [JSProxy(typeof(InvalidCastException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_InvalidCastException + { + } + + [JSProxy(typeof(InvalidOperationException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_InvalidOperationException + { + } + + [JSProxy(typeof(NotImplementedException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_NotImplementedException + { + } + + [JSProxy(typeof(AmbiguousMatchException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_AmbiguousMatchException + { + } + + [JSProxy(typeof(ArgumentException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArgumentException + { + } + + [JSProxy(typeof(ArgumentOutOfRangeException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArgumentOutOfRangeException + { + } + + [JSProxy(typeof(IOException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IOException + { + } + + [JSProxy(typeof(FileNotFoundException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileNotFoundException + { + } + + [JSProxy(typeof(EndOfStreamException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_EndOfStreamException + { + } + + [JSProxy(typeof(ArithmeticException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArithmeticException + { + } + + [JSProxy(typeof(OverflowException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_OverflowException + { + } + +} diff --git a/Proxies/Proxies.4.0.csproj b/Proxies/Proxies.4.0.csproj index ed51b684b..5c1c9d3ad 100644 --- a/Proxies/Proxies.4.0.csproj +++ b/Proxies/Proxies.4.0.csproj @@ -36,12 +36,18 @@ + + + + + + diff --git a/Proxies/Random.cs b/Proxies/Random.cs new file mode 100644 index 000000000..874e9ac96 --- /dev/null +++ b/Proxies/Random.cs @@ -0,0 +1,12 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(Random), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Random + { + } +} diff --git a/Proxies/Resources.cs b/Proxies/Resources.cs new file mode 100644 index 000000000..cd5ea4f36 --- /dev/null +++ b/Proxies/Resources.cs @@ -0,0 +1,273 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Globalization; +using System.Resources; +using System.Text; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(ResourceManager), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Resources_ResourceManager + { + } + + [JSProxy(typeof(ResourceSet), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Resources_ResourceSet + { + } + + [JSProxy(typeof(CultureInfo), JSProxyMemberPolicy.ReplaceDeclared, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + public class System_Globalization_CultureInfo + { + private NumberFormatInfo _numberFormat; + private DateTimeFormatInfo _dateTimeFormat; + + [JSExternal] + public System_Globalization_CultureInfo(string cultureId) + { + + } + + [JSExternal] + public System_Globalization_CultureInfo(string str, bool boolean) + { + + } + + [JSExternal] + public string Name + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public string TwoLetterISOLanguageName + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public bool UseUserOverride + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public CultureInfo CurrentCulture + { + get + { + throw new NotImplementedException(); + } + } + + [JSExternal] + public CultureInfo CurrentUICulture + { + get + { + throw new NotImplementedException(); + } + } + + public Calendar Calendar + { + get { return DateTimeFormat.Calendar; } + } + + public NumberFormatInfo NumberFormat + { + get + { + if (_numberFormat == null) + { + _numberFormat = new NumberFormatInfo + { + CurrencyDecimalDigits = 2, + CurrencyDecimalSeparator = ".", + CurrencyGroupSeparator = ",", + CurrencyGroupSizes = new[] { 3 }, + CurrencyNegativePattern = 0, + CurrencyPositivePattern = 0, + CurrencySymbol = "$", + DigitSubstitution = DigitShapes.None, + NaNSymbol = "NaN", + NativeDigits = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, + NegativeInfinitySymbol = "-Infinity", + NegativeSign = "-", + NumberDecimalDigits = 2, + NumberDecimalSeparator = ".", + NumberGroupSeparator = ",", + NumberGroupSizes = new[] { 3 }, + NumberNegativePattern = 1, + PerMilleSymbol = "‰", + PercentDecimalDigits = 2, + PercentDecimalSeparator = ".", + PercentGroupSeparator = ",", + PercentGroupSizes = new[] { 3 }, + PercentNegativePattern = 0, + PercentPositivePattern = 0, + PercentSymbol = "%", + PositiveInfinitySymbol = "Infinity", + PositiveSign = "+" + }; + } + return _numberFormat; + } + } + + public DateTimeFormatInfo DateTimeFormat + { + get + { + if (_dateTimeFormat == null) + { + _dateTimeFormat = new DateTimeFormatInfo + { + AbbreviatedDayNames = new[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, + AbbreviatedMonthGenitiveNames = + new[] + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + string.Empty + }, + AbbreviatedMonthNames = + new[] + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + string.Empty + }, + AMDesignator = "AM", + Calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish), + CalendarWeekRule = CalendarWeekRule.FirstDay, + DateSeparator = "/", + DayNames = new[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }, + + FirstDayOfWeek = DayOfWeek.Sunday, + FullDateTimePattern = "dddd, MMMM dd, yyyy h:mm:ss tt", + LongDatePattern = "dddd, MMMM dd, yyyy", + LongTimePattern = "h:mm:ss tt", + MonthDayPattern = "MMMM dd", + MonthGenitiveNames = + new[] + { + "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December", string.Empty + }, + MonthNames = + new[] + { + "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December", string.Empty + }, + PMDesignator = "PM", + ShortDatePattern = "M/d/yyyy", + ShortestDayNames = new[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" }, + ShortTimePattern = "h:mm tt", + TimeSeparator = ":", + YearMonthPattern = "MMMM, yyyy" + }; + } + return _dateTimeFormat; + } + } + + [JSExternal] + public virtual object Clone() + { + throw new NotImplementedException(); + } + + [JSExternal] + public CultureInfo GetCultureByName(string str, bool boolean) + { + throw new NotImplementedException(); + } + + [JSExternal] + public CultureInfo GetCultureInfo(string str) + { + throw new NotImplementedException(); + } + + [JSExternal] + public CultureInfo GetCultureInfoByIetfLanguageTag(string str) + { + throw new NotImplementedException(); + } + + private static string GetDefaultLocaleName(int localeType) + { + return "en-us"; + } + + private static string GetUserDefaultUILanguage() + { + return "en-us"; + } + + private static string GetSystemDefaultUILanguage() + { + return "en-us"; + } + } + + [JSProxy(typeof(DateTimeFormatInfo), JSProxyMemberPolicy.ReplaceDeclared, JSProxyAttributePolicy.ReplaceDeclared, + JSProxyInterfacePolicy.ReplaceNone, false)] + public class System_Globalization_DateTimeFormatInfo + { + internal Calendar calendar; + public Calendar Calendar { set { calendar = value; } get { return calendar; } } + } + + + + [JSProxy("System.DateTimeFormat", JSProxyMemberPolicy.ReplaceDeclared, JSProxyAttributePolicy.ReplaceDeclared, + JSProxyInterfacePolicy.ReplaceNone, false)] + public class System__DateTimeFormat + { + internal static void FormatDigits(StringBuilder outputBuffer, int value, int len, bool overrideLengthLimit) + { + if (!overrideLengthLimit && len > 2) + { + len = 2; + } + + var chars = new char[16]; + + var ptr2 = 16; + var num = value; + do + { + chars[ptr2] = (char)(num % 10 + 48); + ptr2--; + num /= 10; + } + while (num != 0 && ptr2 != 0); + var num2 = (16 - ptr2); + while (num2 < len && ptr2 != 0) + { + chars[ptr2] = '0'; + ptr2--; + num2++; + } + + for (var i = 0; i < num2; i++) + { + outputBuffer.Append(chars[ptr2 + i]); + } + } + } +} diff --git a/Proxies/Threading.cs b/Proxies/Threading.cs new file mode 100644 index 000000000..92c130145 --- /dev/null +++ b/Proxies/Threading.cs @@ -0,0 +1,19 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Threading; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(Thread), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Threading_Thread + { + } + + [JSProxy(typeof(Monitor), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Threading_Monitor + { + } +} From b3f80092c4ec436a6a8fe38c40ed072da8946244 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Apr 2014 14:40:40 +0200 Subject: [PATCH 03/16] Added an AppDomain fallback and Type.IsAbstract --- JSIL/AssemblyTranslator.cs | 5 +++ Libraries/JSIL.Core.Reflection.js | 16 ++++++++ Libraries/JSIL.Core.js | 9 ++++- Libraries/JSIL.HeuristicLab.js | 29 ++++++++++++++ Libraries/JSIL.js | 1 + Proxies/AppDomain.cs | 28 +++++++++++++ Proxies/Proxies.4.0.csproj | 2 + Proxies/Regex.cs | 52 +++++++++++++++++++++++++ Tests/ReflectionTestCases/IsAbstract.cs | 28 +++++++++++++ Tests/Tests.csproj | 3 +- 10 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 Libraries/JSIL.HeuristicLab.js create mode 100644 Proxies/AppDomain.cs create mode 100644 Proxies/Regex.cs create mode 100644 Tests/ReflectionTestCases/IsAbstract.cs diff --git a/JSIL/AssemblyTranslator.cs b/JSIL/AssemblyTranslator.cs index 283b1ed06..8a7ee1edb 100644 --- a/JSIL/AssemblyTranslator.cs +++ b/JSIL/AssemblyTranslator.cs @@ -1224,6 +1224,11 @@ protected void DeclareType ( output.Comma(); output.NewLine(); + output.WriteRaw("IsAbstract: "); + output.Value(typedef.IsAbstract); + output.Comma(); + output.NewLine(); + output.WriteRaw("IsReferenceType: "); output.Value(!typedef.IsValueType); output.Comma(); diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index 1231ace89..4396940ea 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -94,6 +94,8 @@ JSIL.ImplementExternals( new JSIL.MethodSignature($.Boolean, []), JSIL.TypeObjectPrototype.get_IsArray ); + + $.Method({Public: true , Static: false}, "get_IsValueType", new JSIL.MethodSignature($.Boolean, []), @@ -111,6 +113,20 @@ JSIL.ImplementExternals( return this.__ElementType__; } ); + + $.Method({ Static: false, Public: true }, "get_IsAbstract", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__IsAbstract__; + } + ); + + $.Method({ Static: false, Public: true }, "get_HasElementType", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__ElementType__ != null; + }); + $.Method({Public: true , Static: false}, "get_BaseType", new JSIL.MethodSignature($.Type, []), diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index a3d007ade..6de6c9a26 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -4869,11 +4869,12 @@ JSIL.MakeType = function (typeArgs, initializer) { var fullName = typeArgs.Name || null; var isReferenceType = Boolean(typeArgs.IsReferenceType); var isPublic = Boolean(typeArgs.IsPublic); + var isAbstract = Boolean(typeArgs.IsAbstract); var genericArguments = typeArgs.GenericParameters || []; var maxConstructorArguments = typeArgs.MaximumConstructorArguments; if (typeof (isPublic) === "undefined") - JSIL.Host.abort(new Error("Must specify isPublic")); + JSIL.Host.abort(new Error("Must specify isPublic")); var assembly = $private; var localName = JSIL.GetLocalName(fullName); @@ -4935,6 +4936,7 @@ JSIL.MakeType = function (typeArgs, initializer) { typeObject.__InheritanceDepth__ = (typeObject.__BaseType__.__InheritanceDepth__ || 0) + 1; typeObject.__IsArray__ = false; + typeObject.__IsAbstract__ = isAbstract; typeObject.__FieldList__ = $jsilcore.ArrayNotInitialized; typeObject.__FieldInitializer__ = $jsilcore.FunctionNotInitialized; typeObject.__MemberCopier__ = $jsilcore.FunctionNotInitialized; @@ -5143,7 +5145,10 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + if (typeOfValue.__AssignableTypes__ != null) { + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + } + return false; }; JSIL.MakeCastMethods(publicInterface, typeObject, "interface"); diff --git a/Libraries/JSIL.HeuristicLab.js b/Libraries/JSIL.HeuristicLab.js new file mode 100644 index 000000000..f242ea498 --- /dev/null +++ b/Libraries/JSIL.HeuristicLab.js @@ -0,0 +1,29 @@ +// JavaScript source code +"use strict"; + +if (typeof (JSIL) === "undefined") + throw new Error("JSIL.Core is required"); + +if (!$jsilcore) + throw new Error("JSIL.Core is required"); + +function get_CurrentDomain() { + console.log("CurrentDomain called"); +} + +function GetAssemblies() { + var result = []; + for (var asm in JSIL.PrivateNamespaces) { + var assembly = JSIL.GetAssembly(asm, true); + if (assembly != null) { + result.push(assembly.__Assembly__); + } + } + return result; +} + +function HLGetTypes(type, onlyInstantiable, includeGenericTypeDefinitions) { + console.log("GetTypes called"); +} + + diff --git a/Libraries/JSIL.js b/Libraries/JSIL.js index 1b7e405f6..d5de64180 100644 --- a/Libraries/JSIL.js +++ b/Libraries/JSIL.js @@ -179,6 +179,7 @@ var $jsilloaderstate = { environment.loadScript(libraryRoot + "JSIL.Bootstrap.DateTime.js"); environment.loadScript(libraryRoot + "JSIL.Bootstrap.Text.js"); environment.loadScript(libraryRoot + "JSIL.Bootstrap.Resources.js"); + environment.loadScript(libraryRoot + "JSIL.HeuristicLab.js"); //environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); if (config.testFixture || environment.getUserSetting("testFixture")) diff --git a/Proxies/AppDomain.cs b/Proxies/AppDomain.cs new file mode 100644 index 000000000..2fe846c8b --- /dev/null +++ b/Proxies/AppDomain.cs @@ -0,0 +1,28 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace JSIL.Proxies +{ + [JSProxy( + typeof(AppDomain), + JSProxyMemberPolicy.ReplaceDeclared + )] + public sealed class AppDomainProxy + { + [JSReplacement("get_CurrentDomain()")] + [JSIsPure] + public static AppDomain CurrentDomain { get { throw new InvalidOperationException(); } } + + [JSReplacement("GetAssemblies()")] + [JSIsPure] + public Assembly[] GetAssemblies() + { + throw new InvalidOperationException(); + } + } +} diff --git a/Proxies/Proxies.4.0.csproj b/Proxies/Proxies.4.0.csproj index 5c1c9d3ad..67ddfd3e0 100644 --- a/Proxies/Proxies.4.0.csproj +++ b/Proxies/Proxies.4.0.csproj @@ -35,6 +35,7 @@ + @@ -46,6 +47,7 @@ + diff --git a/Proxies/Regex.cs b/Proxies/Regex.cs new file mode 100644 index 000000000..cc260e07a --- /dev/null +++ b/Proxies/Regex.cs @@ -0,0 +1,52 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(RegexOptions), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_RegexOptions + { + } + + [JSProxy(typeof(Regex), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_Regex + { + } + + [JSProxy(typeof(MatchCollection), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_MatchCollection + { + } + + [JSProxy(typeof(Capture), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_Capture + { + } + + [JSProxy(typeof(Group), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_Group + { + } + + [JSProxy(typeof(Match), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_Match + { + } + + [JSProxy(typeof(GroupCollection), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_RegularExpressions_GroupCollection + { + } +} diff --git a/Tests/ReflectionTestCases/IsAbstract.cs b/Tests/ReflectionTestCases/IsAbstract.cs new file mode 100644 index 000000000..9eb5aa3e9 --- /dev/null +++ b/Tests/ReflectionTestCases/IsAbstract.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace JSIL.Tests.ReflectionTestCases +{ + public class Program + { + public static void Main(string[] args) + { + Type abstractType = typeof(AbstractClass); + Type nonAbstractType = typeof(NonAbstractClass); + + Console.WriteLine("Should be true: {0}, Should be false: {1}", abstractType.IsAbstract, nonAbstractType.IsAbstract); + } + } + + public abstract class AbstractClass + { + + } + + public class NonAbstractClass + { + + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 2f3bbcdcd..db8ec240e 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -270,6 +270,7 @@ + @@ -822,7 +823,7 @@ - + From 825ede1e3507eef24d1163264acf1f8c025b7e3f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 Apr 2014 12:45:57 +0200 Subject: [PATCH 04/16] Added lots of stuff --- Libraries/JSIL.Bootstrap.Int64.js | 1260 ++--- Libraries/JSIL.Bootstrap.js | 7433 +++++++++++++++-------------- Libraries/JSIL.Core.Reflection.js | 53 +- Libraries/JSIL.Core.js | 37 +- Libraries/JSIL.HeuristicLab.js | 129 +- Proxies/Bootstrap.cs | 340 +- Proxies/Diagnostics.cs | 13 + Proxies/IO.cs | 66 + Proxies/Proxies.4.0.csproj | 6 +- Proxies/Reflection.cs | 61 + Proxies/Text.cs | 78 + Proxies/Unsafe.cs | 61 + Proxies/XmlSerializer.cs | 11 + 13 files changed, 5173 insertions(+), 4375 deletions(-) create mode 100644 Proxies/Diagnostics.cs create mode 100644 Proxies/Text.cs create mode 100644 Proxies/XmlSerializer.cs diff --git a/Libraries/JSIL.Bootstrap.Int64.js b/Libraries/JSIL.Bootstrap.Int64.js index 4d68c4303..9e00ac4aa 100644 --- a/Libraries/JSIL.Bootstrap.Int64.js +++ b/Libraries/JSIL.Bootstrap.Int64.js @@ -3,7 +3,7 @@ if (typeof (JSIL) === "undefined") throw new Error("JSIL.Core is required"); -if (!$jsilcore) +if (!$jsilcore) throw new Error("JSIL.Core is required"); // @@ -12,17 +12,17 @@ JSIL.Make64BitInt = function ($, _me) { var mscorlib = JSIL.GetCorlib(); function lazy(f) { - var state = null; - return function getLazyValue () { - if (state === null) - state = f(); - return state; - }; + var state = null; + return function getLazyValue() { + if (state === null) + state = f(); + return state; + }; }; var me = lazy(_me); - var ctor = function ctor (a, b, c) { + var ctor = function ctor(a, b, c) { return new (me())(a, b, c); }; @@ -33,22 +33,22 @@ JSIL.Make64BitInt = function ($, _me) { }; var maxValue = lazy(function () { - return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); + return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); }); var zero = lazy(function () { - return ctor(0, 0, 0); + return ctor(0, 0, 0); }); var one = lazy(function () { - return ctor(1, 0, 0); + return ctor(1, 0, 0); }); var tempLS = mktemp(); var tempMul1 = mktemp(); var tempMul2 = mktemp(); - var makeOrReturn = function makeOrReturn (result, a, b, c) { + var makeOrReturn = function makeOrReturn(result, a, b, c) { if (result) { result.a = a & 0xffffff; result.b = b & 0xffffff; @@ -60,7 +60,7 @@ JSIL.Make64BitInt = function ($, _me) { }; var tryParse = - function xInt64_TryParse (text, style, result) { + function xInt64_TryParse(text, style, result) { var r = zero(); var radix = 10; @@ -92,11 +92,11 @@ JSIL.Make64BitInt = function ($, _me) { return true; }; - $.RawMethod(true, "Create", function xInt64_Create (a, b, c) { + $.RawMethod(true, "Create", function xInt64_Create(a, b, c) { return new (me())(a, b, c); }); - $.RawMethod(true, "FromBytes", function xInt64_FromBytes (bytes, offset) { + $.RawMethod(true, "FromBytes", function xInt64_FromBytes(bytes, offset) { var a = (bytes[offset + 0] << 0) | (bytes[offset + 1] << 8) | (bytes[offset + 2] << 16); @@ -108,7 +108,7 @@ JSIL.Make64BitInt = function ($, _me) { return new (me())(a, b, c); }); - $.RawMethod(false, ".ctor", function xInt64__ctor (a, b, c) { + $.RawMethod(false, ".ctor", function xInt64__ctor(a, b, c) { this.a = a | 0; this.b = b | 0; this.c = c | 0; @@ -116,7 +116,7 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "Parse", (new JSIL.MethodSignature($.Type, ["System.String"], [])), - function xInt64_Parse (text) { + function xInt64_Parse(text) { var result = new JSIL.BoxedVariable(null); if (!tryParse(text, 0, result)) throw new System.Exception("NumberParseException"); @@ -126,7 +126,7 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "op_Addition", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_Addition (a, b, result) { + function xInt64_op_Addition(a, b, result) { var ca = a.a + b.a; var ra = (ca & 0xffffff000000) >> 24; var cb = ra + a.b + b.b; @@ -138,7 +138,7 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "op_Subtraction", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_Subtraction (a, b, result) { + function xInt64_op_Subtraction(a, b, result) { var ca = (a.a - b.a) | 0; var ra = 0; if (ca < 0) { @@ -161,69 +161,69 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "op_LeftShift", (new JSIL.MethodSignature($.Type, [$.Type, mscorlib.TypeRef("System.Int32")], [])), - function xInt64_op_LeftShift (a, n, result) { // a is UInt64, n is Int32 - if (!result) - result = ctor(0, 0, 0); + function xInt64_op_LeftShift(a, n, result) { // a is UInt64, n is Int32 + if (!result) + result = ctor(0, 0, 0); - n = n & 0x3f; + n = n & 0x3f; - var maxShift = 8; - if (n > 8) { - return me().op_LeftShift(me().op_LeftShift(a, maxShift, tempLS()), n - maxShift, result); - } - - var bat = a.a << n; - var ba = bat & 0xffffff; - var ra = (bat >>> 24) & 0xffffff; - var bbt = (a.b << n) | ra; - var bb = bbt & 0xffffff; - var rb = (bbt >>> 24) & 0xffff; - var bct = a.c << n; - var bc = (bct & 0xffff) | rb; - - return makeOrReturn(result, ba, bb, bc); - }); + var maxShift = 8; + if (n > 8) { + return me().op_LeftShift(me().op_LeftShift(a, maxShift, tempLS()), n - maxShift, result); + } + + var bat = a.a << n; + var ba = bat & 0xffffff; + var ra = (bat >>> 24) & 0xffffff; + var bbt = (a.b << n) | ra; + var bb = bbt & 0xffffff; + var rb = (bbt >>> 24) & 0xffff; + var bct = a.c << n; + var bc = (bct & 0xffff) | rb; + + return makeOrReturn(result, ba, bb, bc); + }); $.Method({ Static: true, Public: true }, "op_OnesComplement", (new JSIL.MethodSignature($.Type, [$.Type], [])), - function xInt64_op_OnesComplement (a, result) { + function xInt64_op_OnesComplement(a, result) { return makeOrReturn(result, ~a.a, ~a.b, ~a.c); }); $.Method({ Static: true, Public: true }, "op_ExclusiveOr", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_ExclusiveOr (a, b, result) { + function xInt64_op_ExclusiveOr(a, b, result) { return makeOrReturn(result, a.a ^ b.a, a.b ^ b.b, a.c ^ b.c); }); $.Method({ Static: true, Public: true }, "op_BitwiseAnd", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_BitwiseAnd (a, b, result) { + function xInt64_op_BitwiseAnd(a, b, result) { return makeOrReturn(result, a.a & b.a, a.b & b.b, a.c & b.c); }); $.Method({ Static: true, Public: true }, "op_BitwiseOr", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_BitwiseOr (a, b, result) { + function xInt64_op_BitwiseOr(a, b, result) { return makeOrReturn(result, a.a | b.a, a.b | b.b, a.c | b.c); }); $.Method({ Static: true, Public: true }, "op_Equality", (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function xInt64_op_Equality (a, b) { + function xInt64_op_Equality(a, b) { return a.a === b.a && a.b === b.b && a.c === b.c; }); $.Method({ Static: true, Public: true }, "op_Inequality", (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function xInt64_op_Inequality (a, b) { + function xInt64_op_Inequality(a, b) { return a.a !== b.a || a.b !== b.b || a.c !== b.c; }); $.Method({ Static: true, Public: true }, "op_Decrement", (new JSIL.MethodSignature($.Type, [$.Type], [])), - function xInt64_op_Decrement (a, result) { + function xInt64_op_Decrement(a, result) { if (a.a > 0) return makeOrReturn(result, a.a - 1, a.b, a.c); else @@ -232,7 +232,7 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "op_Increment", (new JSIL.MethodSignature($.Type, [$.Type], [])), - function xInt64_op_Increment (a, result) { + function xInt64_op_Increment(a, result) { if (a.a < 0xffffff) return makeOrReturn(result, a.a + 1, a.b, a.c); else @@ -241,7 +241,7 @@ JSIL.Make64BitInt = function ($, _me) { $.Method({ Static: true, Public: true }, "op_Multiplication", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function xInt64_op_Multiplication (a, b, result) { + function xInt64_op_Multiplication(a, b, result) { if (me().op_Equality(a, zero()) || me().op_Equality(b, zero())) return zero(); @@ -271,35 +271,35 @@ JSIL.Make64BitInt = function ($, _me) { return s; }); - $.RawMethod(true, "CheckType", function xInt64_CheckType (value) { - return value && - (typeof value.a === "number") && - (typeof value.b === "number") && + $.RawMethod(true, "CheckType", function xInt64_CheckType(value) { + return value && + (typeof value.a === "number") && + (typeof value.b === "number") && (typeof value.c === "number"); }); - $.RawMethod(false, "valueOf", function xInt64_valueOf () { + $.RawMethod(false, "valueOf", function xInt64_valueOf() { return this.ToNumber(); }); $.RawMethod(true, "FromNumberImpl", function (n, makeResult) { - if (n < 0) - JSIL.RuntimeError("cannot construct UInt64 from negative number"); + if (n < 0) + JSIL.RuntimeError("cannot construct UInt64 from negative number"); - var bits24 = 0xffffff; + var bits24 = 0xffffff; - var floorN = Math.floor(n); - var n0 = floorN | 0; - var n1 = (floorN / 0x1000000) | 0; - var n2 = (floorN / 0x1000000000000) | 0; + var floorN = Math.floor(n); + var n0 = floorN | 0; + var n1 = (floorN / 0x1000000) | 0; + var n2 = (floorN / 0x1000000000000) | 0; - return makeResult( - (n0 & bits24), - (n1 & bits24), - (n2 & bits24) - ); + return makeResult( + (n0 & bits24), + (n1 & bits24), + (n2 & bits24) + ); }); - + return { lazy: lazy, me: me, @@ -309,667 +309,669 @@ JSIL.Make64BitInt = function ($, _me) { }; JSIL.ImplementExternals("System.UInt64", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var locals = JSIL.Make64BitInt($, function () { - return mscorlib.System.UInt64; - }); - var lazy = locals.lazy; - var me = locals.me; - var ctor = locals.ctor; - var mktemp = locals.mktemp; + var locals = JSIL.Make64BitInt($, function () { + return mscorlib.System.UInt64; + }); + var lazy = locals.lazy; + var me = locals.me; + var ctor = locals.ctor; + var mktemp = locals.mktemp; - var maxValue = lazy(function () { - return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); - }); + var maxValue = lazy(function () { + return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); + }); - var minValue = lazy(function () { - return ctor(0, 0, 0); - }); + var minValue = lazy(function () { + return ctor(0, 0, 0); + }); - var zero = lazy(function () { - return ctor(0, 0, 0); - }); + var zero = lazy(function () { + return ctor(0, 0, 0); + }); - var one = lazy(function () { - return ctor(1, 0, 0); - }); + var one = lazy(function () { + return ctor(1, 0, 0); + }); - var tempRS = mktemp(); - var tempDiv = mktemp(); - - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_Division", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function UInt64_op_Division (n, d, result) { - var equality = me().op_Equality, - greaterThanOrEqual = me().op_GreaterThanOrEqual, - subtraction = me().op_Subtraction, - leftShift = me().op_LeftShift; - - if (equality(d, minValue())) - throw new Error("System.DivideByZeroException"); - - var q = result; - if (q) - q.a = q.b = q.c = 0; - else - q = ctor(0, 0, 0); + var tempRS = mktemp(); + var tempDiv = mktemp(); - var r = tempDiv(); - r.a = r.b = r.c = 0; + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_Division", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function UInt64_op_Division(n, d, result) { + var equality = me().op_Equality, + greaterThanOrEqual = me().op_GreaterThanOrEqual, + subtraction = me().op_Subtraction, + leftShift = me().op_LeftShift; - for (var i = 63; i >= 0; i--) { - r = leftShift(r, 1, r); + if (equality(d, minValue())) + throw new Error("System.DivideByZeroException"); - var li = i < 24 ? 0 : - i < 48 ? 1 : 2; - var lk = i < 24 ? "a" : - i < 48 ? "b" : "c"; - var s = (i - 24 * li); + var q = result; + if (q) + q.a = q.b = q.c = 0; + else + q = ctor(0, 0, 0); - r.a |= (n[lk] & (1 << s)) >>> s; + var r = tempDiv(); + r.a = r.b = r.c = 0; - if (greaterThanOrEqual(r, d)) { - r = subtraction(r, d, r); - q[lk] |= 1 << s; - } - } + for (var i = 63; i >= 0; i--) { + r = leftShift(r, 1, r); - return q; - }); + var li = i < 24 ? 0 : + i < 48 ? 1 : 2; + var lk = i < 24 ? "a" : + i < 48 ? "b" : "c"; + var s = (i - 24 * li); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_Modulus", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function UInt64_op_Modulus (n, d, result) { - var equality = me().op_Equality, - greaterThanOrEqual = me().op_GreaterThanOrEqual, - subtraction = me().op_Subtraction, - leftShift = me().op_LeftShift; + r.a |= (n[lk] & (1 << s)) >>> s; - if (equality(d, minValue())) - throw new Error("System.DivideByZeroException"); + if (greaterThanOrEqual(r, d)) { + r = subtraction(r, d, r); + q[lk] |= 1 << s; + } + } - var r = result || ctor(0, 0, 0); - r.a = r.b = r.c = 0; + return q; + }); - for (var i = 63; i >= 0; i--) { - r = leftShift(r, 1, r); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_Modulus", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function UInt64_op_Modulus(n, d, result) { + var equality = me().op_Equality, + greaterThanOrEqual = me().op_GreaterThanOrEqual, + subtraction = me().op_Subtraction, + leftShift = me().op_LeftShift; - var li = i < 24 ? 0 : - i < 48 ? 1 : 2; - var lk = i < 24 ? "a" : - i < 48 ? "b" : "c"; - var s = (i - 24 * li); + if (equality(d, minValue())) + throw new Error("System.DivideByZeroException"); - r.a |= (n[lk] & (1 << s)) >>> s; + var r = result || ctor(0, 0, 0); + r.a = r.b = r.c = 0; - if (greaterThanOrEqual(r, d)) { - r = subtraction(r, d, r); - } - } + for (var i = 63; i >= 0; i--) { + r = leftShift(r, 1, r); - return r; - }); + var li = i < 24 ? 0 : + i < 48 ? 1 : 2; + var lk = i < 24 ? "a" : + i < 48 ? "b" : "c"; + var s = (i - 24 * li); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_RightShift", - (new JSIL.MethodSignature($.Type, [$.Type, mscorlib.TypeRef("System.Int32")], [])), - function UInt64_op_RightShift (a, n, result) { - - n = n & 0x3f; - - if (n > 24) { - return mscorlib.System.UInt64.op_RightShift( - mscorlib.System.UInt64.op_RightShift(a, 24, tempRS()), n - 24, result - ); - } + r.a |= (n[lk] & (1 << s)) >>> s; - var m = (1 << n) - 1; - var cr = (a.c & m) << (24 - n); - var ct = a.c >>> n; - var br = (a.b & m) << (24 - n); - var bt = a.b >>> n; - var at = a.a >>> n; - - if (!result) { - result = ctor(at | br, bt | cr, ct); - } else { - result.a = at | br; - result.b = bt | cr; - result.c = ct; - } + if (greaterThanOrEqual(r, d)) { + r = subtraction(r, d, r); + } + } - return result; - }); + return r; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_LessThan", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function UInt64_op_LessThan (a, b) { - var adiff = a.c - b.c; - if (adiff < 0) - return true; + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_RightShift", + (new JSIL.MethodSignature($.Type, [$.Type, mscorlib.TypeRef("System.Int32")], [])), + function UInt64_op_RightShift(a, n, result) { - if (adiff > 0) - return false; + n = n & 0x3f; - var bdiff = a.b - b.b; - if (bdiff < 0) - return true; + if (n > 24) { + return mscorlib.System.UInt64.op_RightShift( + mscorlib.System.UInt64.op_RightShift(a, 24, tempRS()), n - 24, result + ); + } - if (bdiff > 0) - return false; + var m = (1 << n) - 1; + var cr = (a.c & m) << (24 - n); + var ct = a.c >>> n; + var br = (a.b & m) << (24 - n); + var bt = a.b >>> n; + var at = a.a >>> n; + + if (!result) { + result = ctor(at | br, bt | cr, ct); + } else { + result.a = at | br; + result.b = bt | cr; + result.c = ct; + } - return a.a < b.a; + return result; }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_LessThanOrEqual", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function UInt64_op_LessThanOrEqual (a, b) { - var adiff = a.c - b.c; - if (adiff < 0) - return true; + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_LessThan", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function UInt64_op_LessThan(a, b) { + var adiff = a.c - b.c; + if (adiff < 0) + return true; - if (adiff > 0) - return false; + if (adiff > 0) + return false; - var bdiff = a.b - b.b; - if (bdiff < 0) - return true; + var bdiff = a.b - b.b; + if (bdiff < 0) + return true; - if (bdiff > 0) - return false; + if (bdiff > 0) + return false; - return a.a <= b.a; - }); + return a.a < b.a; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_GreaterThan", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function UInt64_op_GreaterThan (a, b) { - var adiff = a.c - b.c; - if (adiff > 0) - return true; + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_LessThanOrEqual", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function UInt64_op_LessThanOrEqual(a, b) { + var adiff = a.c - b.c; + if (adiff < 0) + return true; - if (adiff < 0) - return false; + if (adiff > 0) + return false; - var bdiff = a.b - b.b; - if (bdiff > 0) - return true; + var bdiff = a.b - b.b; + if (bdiff < 0) + return true; - if (bdiff < 0) - return false; + if (bdiff > 0) + return false; - return a.a > b.a; - }); + return a.a <= b.a; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_GreaterThanOrEqual", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function UInt64_op_GreaterThanOrEqual (a, b) { - var adiff = a.c - b.c; - if (adiff > 0) - return true; + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_GreaterThan", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function UInt64_op_GreaterThan(a, b) { + var adiff = a.c - b.c; + if (adiff > 0) + return true; - if (adiff < 0) - return false; + if (adiff < 0) + return false; - var bdiff = a.b - b.b; - if (bdiff > 0) - return true; + var bdiff = a.b - b.b; + if (bdiff > 0) + return true; - if (bdiff < 0) - return false; + if (bdiff < 0) + return false; - return a.a >= b.a; - }); + return a.a > b.a; + }); - $.Method({ Static: false, Public: true }, "toString", - new JSIL.MethodSignature("System.String", []), - function UInt64_toString () { - var a = this; - var ten = me().FromNumber(10); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_GreaterThanOrEqual", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function UInt64_op_GreaterThanOrEqual(a, b) { + var adiff = a.c - b.c; + if (adiff > 0) + return true; - var s = ""; + if (adiff < 0) + return false; - do { - var r = me().op_Modulus(a, ten); - s = r.a.toString() + s; - a = me().op_Division(a, ten); - } while (me().op_GreaterThan(a, minValue())); + var bdiff = a.b - b.b; + if (bdiff > 0) + return true; - return s; - }); + if (bdiff < 0) + return false; - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToHex", - new JSIL.MethodSignature("System.String", []), - function UInt64_ToHex () { - var s = this.a.toString(16); + return a.a >= b.a; + }); - if (this.b > 0 || this.c > 0) { - if (s.length < 6) - s = (new Array(6 - s.length + 1)).join('0') + s; + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature("System.String", []), + function UInt64_toString() { + var a = this; + var ten = me().FromNumber(10); - s = this.b.toString(16) + s; + var s = ""; - if (this.c > 0) { - if (s.length < 12) - s = (new Array(12 - s.length + 1)).join('0') + s; + do { + var r = me().op_Modulus(a, ten); + s = r.a.toString() + s; + a = me().op_Division(a, ten); + } while (me().op_GreaterThan(a, minValue())); - s = this.c.toString(16) + s; - } - } + return s; + }); - return s; - }); + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToHex", + new JSIL.MethodSignature("System.String", []), + function UInt64_ToHex() { + var s = this.a.toString(16); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToInt64", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), []), - function UInt64_ToInt64 () { - return new mscorlib.System.Int64(this.a, this.b, this.c); - }); + if (this.b > 0 || this.c > 0) { + if (s.length < 6) + s = (new Array(6 - s.length + 1)).join('0') + s; - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "Clone", - new JSIL.MethodSignature($.Type, []), - function UInt64_Clone () { - return ctor(this.a, this.b, this.c); - }); + s = this.b.toString(16) + s; - $.Method({ Static: false, Public: true }, "Object.Equals", - new JSIL.MethodSignature(System.Boolean, [System.Object]), - function UInt64_Equals (rhs) { - return UInt64.op_Equality(this, rhs); - }); + if (this.c > 0) { + if (s.length < 12) + s = (new Array(12 - s.length + 1)).join('0') + s; - // Not present in mscorlib - $.Method({ Static: true, Public: false }, "FromInt32", - (new JSIL.MethodSignature($.Type, [$.Int32], [])), - function UInt64_FromInt32 (n) { - if (n < 0) - JSIL.RuntimeError("cannot construct UInt64 from negative number"); + s = this.c.toString(16) + s; + } + } - // only using 48 bits + return s; + }); - var n0 = Math.floor(n); - return ctor( - (n0 & 0xffffff), - (n0 >>> 24) & 0xffffff, - 0); - }); + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToInt64", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), []), + function UInt64_ToInt64() { + return new mscorlib.System.Int64(this.a, this.b, this.c); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: false }, "FromNumber", - (new JSIL.MethodSignature($.Type, [$.Double], [])), - function UInt64_FromNumber (n) { - return me().FromNumberImpl(n, ctor); - }); + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "Clone", + new JSIL.MethodSignature($.Type, []), + function UInt64_Clone() { + return ctor(this.a, this.b, this.c); + }); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToUInt32", - (new JSIL.MethodSignature($.UInt32, [], [])), - function UInt64_FromUInt32 () { - return ((0x1000000 * this.b) + this.a) >>> 0; - }); + $.Method({ Static: false, Public: true }, "Object.Equals", + new JSIL.MethodSignature(System.Boolean, [System.Object]), + function UInt64_Equals(rhs) { + return UInt64.op_Equality(this, rhs); + }); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToNumber", - (new JSIL.MethodSignature($.Double, [], [])), - function UInt64_ToNumber(maxValue, signed) { - if (arguments.length === 0 || maxValue == -1) - return 0x1000000 * (0x1000000 * this.c + this.b) + this.a; - - var truncated = me() - .op_BitwiseAnd(this, me().FromNumber(maxValue)) - .ToNumber(); - - if (signed) { - var maxPlusOne = maxValue + 1; - var signedMaxValue = maxValue >>> 1; - if (truncated > signedMaxValue) - return truncated - signedMaxValue; - else - return truncated; - } - else { - return truncated; - } - }); + // Not present in mscorlib + $.Method({ Static: true, Public: false }, "FromInt32", + (new JSIL.MethodSignature($.Type, [$.Int32], [])), + function UInt64_FromInt32(n) { + if (n < 0) + JSIL.RuntimeError("cannot construct UInt64 from negative number"); + + // only using 48 bits + + var n0 = Math.floor(n); + return ctor( + (n0 & 0xffffff), + (n0 >>> 24) & 0xffffff, + 0); + }); + + // Not present in mscorlib + $.Method({ Static: true, Public: false }, "FromNumber", + (new JSIL.MethodSignature($.Type, [$.Double], [])), + function UInt64_FromNumber(n) { + if (n == -2) // Apparently UInt32.MaxValue -1 gets translated to -2... + n = 4294967295 - 1; + return me().FromNumberImpl(n, ctor); + }); + + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToUInt32", + (new JSIL.MethodSignature($.UInt32, [], [])), + function UInt64_FromUInt32() { + return ((0x1000000 * this.b) + this.a) >>> 0; + }); + + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToNumber", + (new JSIL.MethodSignature($.Double, [], [])), + function UInt64_ToNumber(maxValue, signed) { + if (arguments.length === 0 || maxValue == -1) + return 0x1000000 * (0x1000000 * this.c + this.b) + this.a; + + var truncated = me() + .op_BitwiseAnd(this, me().FromNumber(maxValue)) + .ToNumber(); + + if (signed) { + var maxPlusOne = maxValue + 1; + var signedMaxValue = maxValue >>> 1; + if (truncated > signedMaxValue) + return truncated - signedMaxValue; + else + return truncated; + } + else { + return truncated; + } + }); }); JSIL.ImplementExternals("System.Int64", function ($) { - // The unsigned range 0 to 0x7FFFFFFFFFFFFFFF (= Int64.MaxValue) is positive: 0 to 9223372036854775807 - // The directly following unsigned range 0x8000000000000000 (= Int64.MaxValue + 1 = Int64.MinValue) to 0xFFFFFFFFFFFFFFFF is negative: -9223372036854775808 to -1 - // - // signed value - // ^ - // | / - // | / - // | / - // |/z - // ------------------> unsigned value - // | / - // | / - // | / - // | / - // - - var mscorlib = JSIL.GetCorlib(); - - var locals = JSIL.Make64BitInt($, function () { - return mscorlib.System.Int64; - }); - var lazy = locals.lazy; - var me = locals.me; - var ctor = locals.ctor; - var mktemp = locals.mktemp; + // The unsigned range 0 to 0x7FFFFFFFFFFFFFFF (= Int64.MaxValue) is positive: 0 to 9223372036854775807 + // The directly following unsigned range 0x8000000000000000 (= Int64.MaxValue + 1 = Int64.MinValue) to 0xFFFFFFFFFFFFFFFF is negative: -9223372036854775808 to -1 + // + // signed value + // ^ + // | / + // | / + // | / + // |/z + // ------------------> unsigned value + // | / + // | / + // | / + // | / + // - var zero = lazy(function () { - return ctor(0, 0, 0); - }); + var mscorlib = JSIL.GetCorlib(); - var one = lazy(function () { - return ctor(1, 0, 0); - }); + var locals = JSIL.Make64BitInt($, function () { + return mscorlib.System.Int64; + }); + var lazy = locals.lazy; + var me = locals.me; + var ctor = locals.ctor; + var mktemp = locals.mktemp; - var minusOne = lazy(function () { - return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); - }); + var zero = lazy(function () { + return ctor(0, 0, 0); + }); - var signedMaxValue = lazy(function () { - return ctor(0xFFFFFF, 0xFFFFFF, 0x7FFF); - }); + var one = lazy(function () { + return ctor(1, 0, 0); + }); - var unsignedMaxValue = lazy(function () { - return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); - }); + var minusOne = lazy(function () { + return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); + }); - var tempRS = mktemp(); - var tempRS1 = mktemp(); - var tempRS2 = mktemp(); - var tempRS3 = mktemp(); - - var tempTS = mktemp(); - var tempDiv = mktemp(); - var tempDiv2 = mktemp(); - var tempDiv3 = mktemp(); - var tempDiv4 = mktemp(); - var tempMod = mktemp(); - var tempMod2 = mktemp(); - var tempMod3 = mktemp(); - var tempMod4 = mktemp(); - var tempN = mktemp(); - - var isNegative = function Int64_IsNegative (a) { - return mscorlib.System.UInt64.op_GreaterThan(a, signedMaxValue()); - }; + var signedMaxValue = lazy(function () { + return ctor(0xFFFFFF, 0xFFFFFF, 0x7FFF); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_UnaryNegation", - (new JSIL.MethodSignature($.Type, [$.Type], [])), - function Int64_op_UnaryNegation (a, result) { - var complement = me().op_Subtraction(unsignedMaxValue(), a, tempN()); - return me().op_Addition(complement, one(), result); - }); + var unsignedMaxValue = lazy(function () { + return ctor(0xFFFFFF, 0xFFFFFF, 0xFFFF); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_Division", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function Int64_op_Division (n, d, result) { - if (me().op_Equality(d, zero())) - throw new Error("System.DivideByZeroException"); - - if (!result) - result = ctor(0, 0, 0); - else - result.a = result.b = result.c = 0; - - if (isNegative(d)) - return me().op_Division( - me().op_UnaryNegation(n, tempDiv()), me().op_UnaryNegation(d, tempDiv2()), result - ); - else if (isNegative(n)) - return me().op_UnaryNegation( - me().op_Division( - me().op_UnaryNegation(n, tempDiv3()), d, tempDiv4() - ), result - ); - else - return mscorlib.System.UInt64.op_Division(n, d, result); - }); + var tempRS = mktemp(); + var tempRS1 = mktemp(); + var tempRS2 = mktemp(); + var tempRS3 = mktemp(); + + var tempTS = mktemp(); + var tempDiv = mktemp(); + var tempDiv2 = mktemp(); + var tempDiv3 = mktemp(); + var tempDiv4 = mktemp(); + var tempMod = mktemp(); + var tempMod2 = mktemp(); + var tempMod3 = mktemp(); + var tempMod4 = mktemp(); + var tempN = mktemp(); + + var isNegative = function Int64_IsNegative(a) { + return mscorlib.System.UInt64.op_GreaterThan(a, signedMaxValue()); + }; - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_Modulus", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function Int64_op_Modulus (n, d, result) { - if (me().op_Equality(d, zero())) - throw new Error("System.DivideByZeroException"); - - if (!result) - result = ctor(0, 0, 0); - - if (isNegative(d)) - return me().op_Modulus( - me().op_UnaryNegation(n, tempMod()), me().op_UnaryNegation(d, tempMod2()), result - ); - else if (isNegative(n)) - return me().op_UnaryNegation( - me().op_Modulus( - me().op_UnaryNegation(n, tempMod3()), d, tempMod4() - ), result - ); - else - // fix return type error - return mscorlib.System.UInt64.op_Modulus(n, d, result); - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_UnaryNegation", + (new JSIL.MethodSignature($.Type, [$.Type], [])), + function Int64_op_UnaryNegation(a, result) { + var complement = me().op_Subtraction(unsignedMaxValue(), a, tempN()); + return me().op_Addition(complement, one(), result); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_RightShift", - (new JSIL.MethodSignature($.Type, [$.Type, mscorlib.TypeRef("System.Int32")], [])), - function Int64_op_RightShift (a, n, result) { - // Int64 (signed) uses arithmetic shift, UIn64 (unsigned) uses logical shift - if (!result) - result = ctor(0, 0, 0); - - if (n === 0) { - var result2 = a; - } else if (n > 32) { - result2 = me().op_RightShift(me().op_RightShift(a, 32), n - 32); - } else { - var unsignedShift = mscorlib.System.UInt64.op_RightShift(a, n); - - if (isNegative(a)) { - var outshift = mscorlib.System.UInt64.op_RightShift(mscorlib.System.UInt64.Create(16777215, 16777215, 65535), n); - var inshift = mscorlib.System.UInt64.op_LeftShift(outshift, 64 - n); - var uresult = mscorlib.System.UInt64.op_BitwiseOr(unsignedShift, inshift); - } else { - uresult = unsignedShift; - } - result2 = (uresult).ToInt64(); - } - return result2; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_Division", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function Int64_op_Division(n, d, result) { + if (me().op_Equality(d, zero())) + throw new Error("System.DivideByZeroException"); + + if (!result) + result = ctor(0, 0, 0); + else + result.a = result.b = result.c = 0; + + if (isNegative(d)) + return me().op_Division( + me().op_UnaryNegation(n, tempDiv()), me().op_UnaryNegation(d, tempDiv2()), result + ); + else if (isNegative(n)) + return me().op_UnaryNegation( + me().op_Division( + me().op_UnaryNegation(n, tempDiv3()), d, tempDiv4() + ), result + ); + else + return mscorlib.System.UInt64.op_Division(n, d, result); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_GreaterThan", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function Int64_op_GreaterThan (a, b) { - var an = isNegative(a); - var bn = isNegative(b); - - if (an === bn) - return mscorlib.System.UInt64.op_GreaterThan(a, b); - else - return bn; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_Modulus", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function Int64_op_Modulus(n, d, result) { + if (me().op_Equality(d, zero())) + throw new Error("System.DivideByZeroException"); + + if (!result) + result = ctor(0, 0, 0); + + if (isNegative(d)) + return me().op_Modulus( + me().op_UnaryNegation(n, tempMod()), me().op_UnaryNegation(d, tempMod2()), result + ); + else if (isNegative(n)) + return me().op_UnaryNegation( + me().op_Modulus( + me().op_UnaryNegation(n, tempMod3()), d, tempMod4() + ), result + ); + else + // fix return type error + return mscorlib.System.UInt64.op_Modulus(n, d, result); + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_GreaterThanOrEqual", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function Int64_op_GreaterThanOrEqual (a, b) { - var an = isNegative(a); - var bn = isNegative(b); - - if (an === bn) - return mscorlib.System.UInt64.op_GreaterThanOrEqual(a, b); - else - return bn; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_RightShift", + (new JSIL.MethodSignature($.Type, [$.Type, mscorlib.TypeRef("System.Int32")], [])), + function Int64_op_RightShift(a, n, result) { + // Int64 (signed) uses arithmetic shift, UIn64 (unsigned) uses logical shift + if (!result) + result = ctor(0, 0, 0); + + if (n === 0) { + var result2 = a; + } else if (n > 32) { + result2 = me().op_RightShift(me().op_RightShift(a, 32), n - 32); + } else { + var unsignedShift = mscorlib.System.UInt64.op_RightShift(a, n); + + if (isNegative(a)) { + var outshift = mscorlib.System.UInt64.op_RightShift(mscorlib.System.UInt64.Create(16777215, 16777215, 65535), n); + var inshift = mscorlib.System.UInt64.op_LeftShift(outshift, 64 - n); + var uresult = mscorlib.System.UInt64.op_BitwiseOr(unsignedShift, inshift); + } else { + uresult = unsignedShift; + } + result2 = (uresult).ToInt64(); + } + return result2; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_LessThan", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function Int64_op_LessThan (a, b) { - var an = isNegative(a); - var bn = isNegative(b); - - if (an === bn) - return mscorlib.System.UInt64.op_LessThan(a, b); - else - return an; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_GreaterThan", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function Int64_op_GreaterThan(a, b) { + var an = isNegative(a); + var bn = isNegative(b); + + if (an === bn) + return mscorlib.System.UInt64.op_GreaterThan(a, b); + else + return bn; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: true }, "op_LessThanOrEqual", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), - function Int64_op_LessThanOrEqual (a, b) { - var an = isNegative(a); - var bn = isNegative(b); - - if (an === bn) - return mscorlib.System.UInt64.op_LessThanOrEqual(a, b); - else - return an; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_GreaterThanOrEqual", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function Int64_op_GreaterThanOrEqual(a, b) { + var an = isNegative(a); + var bn = isNegative(b); + + if (an === bn) + return mscorlib.System.UInt64.op_GreaterThanOrEqual(a, b); + else + return bn; + }); - // Might need to be implemented externally - $.Method({ Static: false, Public: true }, "Equals", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), []), - function Int64_Equals (a) { - return me().op_Equality(this, a); - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_LessThan", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function Int64_op_LessThan(a, b) { + var an = isNegative(a); + var bn = isNegative(b); + + if (an === bn) + return mscorlib.System.UInt64.op_LessThan(a, b); + else + return an; + }); - // Might need to be implemented externally - $.Method({ Static: false, Public: true }, "toString", - new JSIL.MethodSignature("System.String", []), - function Int64_toString () { - var s = ""; - var a = this; - if (isNegative(this)) { - s += "-"; - a = me().op_UnaryNegation(this, tempTS()); - } - s += mscorlib.System.UInt64.prototype.toString.apply(a); - return s; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: true }, "op_LessThanOrEqual", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [$.Type, $.Type], [])), + function Int64_op_LessThanOrEqual(a, b) { + var an = isNegative(a); + var bn = isNegative(b); + + if (an === bn) + return mscorlib.System.UInt64.op_LessThanOrEqual(a, b); + else + return an; + }); - // Not present in mscorlib - $.Method({ Static: true, Public: false }, "FromInt32", - (new JSIL.MethodSignature($.Type, [$.Int32], [])), - function Int64_FromInt32 (n) { - var sign = n < 0 ? -1 : 1; - n = Math.abs(n); + // Might need to be implemented externally + $.Method({ Static: false, Public: true }, "Equals", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), []), + function Int64_Equals(a) { + return me().op_Equality(this, a); + }); - var n0 = Math.floor(n); - var r = ctor(n0 & 0xffffff, (n0 >>> 24) & 0xffffff, 0); + // Might need to be implemented externally + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature("System.String", []), + function Int64_toString() { + var s = ""; + var a = this; + if (isNegative(this)) { + s += "-"; + a = me().op_UnaryNegation(this, tempTS()); + } + s += mscorlib.System.UInt64.prototype.toString.apply(a); + return s; + }); - if (sign == -1) - return me().op_UnaryNegation(r); - else - return r; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: false }, "FromInt32", + (new JSIL.MethodSignature($.Type, [$.Int32], [])), + function Int64_FromInt32(n) { + var sign = n < 0 ? -1 : 1; + n = Math.abs(n); - // Not present in mscorlib - $.Method({ Static: true, Public: false }, "FromNumber", - (new JSIL.MethodSignature($.Type, [$.Double], [])), - function Int64_FromNumber (n) { - var sign = n < 0 ? -1 : 1; - var r = me().FromNumberImpl(Math.abs(n), ctor); - - if (sign == -1) - return me().op_UnaryNegation(r, r); - else - return r; - }); + var n0 = Math.floor(n); + var r = ctor(n0 & 0xffffff, (n0 >>> 24) & 0xffffff, 0); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToUInt64", - new JSIL.MethodSignature($.UInt64, []), - function Int64_ToUInt64 () { - return new mscorlib.System.UInt64(this.a, this.b, this.c); - }); + if (sign == -1) + return me().op_UnaryNegation(r); + else + return r; + }); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToInt32", - (new JSIL.MethodSignature($.Int32, [], [])), - function Int64_ToInt32 () { - var neg = isNegative(this); - var n = neg ? me().op_UnaryNegation(this) : this; - var r = (0x1000000 * (n.b) + n.a) >>> 0; - - if (neg) - return -r; - else - return r; - }); + // Not present in mscorlib + $.Method({ Static: true, Public: false }, "FromNumber", + (new JSIL.MethodSignature($.Type, [$.Double], [])), + function Int64_FromNumber(n) { + var sign = n < 0 ? -1 : 1; + var r = me().FromNumberImpl(Math.abs(n), ctor); + + if (sign == -1) + return me().op_UnaryNegation(r, r); + else + return r; + }); - // Not present in mscorlib - $.Method({ Static: false, Public: true }, "ToNumber", - (new JSIL.MethodSignature($.Double, [], [])), - function Int64_ToNumber (maxValue, signed) { - if (arguments.length === 0 || maxValue == -1) { - var neg = isNegative(this); - var n = neg ? me().op_UnaryNegation(this) : this; - var r = 0x1000000 * (0x1000000 * n.c + n.b) + n.a; - - if (neg) - return -r; - else - return r; - } + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToUInt64", + new JSIL.MethodSignature($.UInt64, []), + function Int64_ToUInt64() { + return new mscorlib.System.UInt64(this.a, this.b, this.c); + }); - - var truncated = me() - .op_BitwiseAnd(this, me().FromNumber(maxValue)) - .ToNumber(); + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToInt32", + (new JSIL.MethodSignature($.Int32, [], [])), + function Int64_ToInt32() { + var neg = isNegative(this); + var n = neg ? me().op_UnaryNegation(this) : this; + var r = (0x1000000 * (n.b) + n.a) >>> 0; + + if (neg) + return -r; + else + return r; + }); - if (signed) { - var maxPlusOne = maxValue + 1; - var signedMaxValue = maxValue >>> 1; - if (truncated > signedMaxValue) - return truncated - signedMaxValue; - else - return truncated; - } - else { - return truncated; - } - }); + // Not present in mscorlib + $.Method({ Static: false, Public: true }, "ToNumber", + (new JSIL.MethodSignature($.Double, [], [])), + function Int64_ToNumber(maxValue, signed) { + if (arguments.length === 0 || maxValue == -1) { + var neg = isNegative(this); + var n = neg ? me().op_UnaryNegation(this) : this; + var r = 0x1000000 * (0x1000000 * n.c + n.b) + n.a; + + if (neg) + return -r; + else + return r; + } + + + var truncated = me() + .op_BitwiseAnd(this, me().FromNumber(maxValue)) + .ToNumber(); + + if (signed) { + var maxPlusOne = maxValue + 1; + var signedMaxValue = maxValue >>> 1; + if (truncated > signedMaxValue) + return truncated - signedMaxValue; + else + return truncated; + } + else { + return truncated; + } + }); }); JSIL.MakeStruct("System.ValueType", "System.UInt64", true, [], function ($) { - $.Field({ Static: false, Public: false}, "a", $.Int32); - $.Field({ Static: false, Public: false}, "b", $.Int32); - $.Field({ Static: false, Public: false}, "c", $.Int32); + $.Field({ Static: false, Public: false }, "a", $.Int32); + $.Field({ Static: false, Public: false }, "b", $.Int32); + $.Field({ Static: false, Public: false }, "c", $.Int32); - JSIL.MakeCastMethods( - $.publicInterface, $.typeObject, "int64" - ); + JSIL.MakeCastMethods( + $.publicInterface, $.typeObject, "int64" + ); }); JSIL.MakeStruct("System.ValueType", "System.Int64", true, [], function ($) { - $.Field({ Static: false, Public: false}, "a", $.Int32); - $.Field({ Static: false, Public: false}, "b", $.Int32); - $.Field({ Static: false, Public: false}, "c", $.Int32); + $.Field({ Static: false, Public: false }, "a", $.Int32); + $.Field({ Static: false, Public: false }, "b", $.Int32); + $.Field({ Static: false, Public: false }, "c", $.Int32); - JSIL.MakeCastMethods( - $.publicInterface, $.typeObject, "int64" - ); + JSIL.MakeCastMethods( + $.publicInterface, $.typeObject, "int64" + ); }); diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index d0dcfef87..69128764b 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1,10 +1,10 @@ "use strict"; if (typeof (JSIL) === "undefined") - throw new Error("JSIL.Core is required"); + throw new Error("JSIL.Core is required"); if (!$jsilcore) - throw new Error("JSIL.Core is required"); + throw new Error("JSIL.Core is required"); JSIL.DeclareNamespace("System.ComponentModel"); JSIL.DeclareNamespace("System.IO"); @@ -13,268 +13,268 @@ JSIL.DeclareNamespace("System.Diagnostics"); // HACK: Unfortunately necessary :-( String.prototype.Object_Equals = function (rhs) { - return this === rhs; + return this === rhs; }; String.prototype.GetHashCode = function () { - var h = 0; + var h = 0; - for (var i = 0; i < this.length; i++) { - h = ((h << 5) - h + this.charCodeAt(i)) & ~0; - } + for (var i = 0; i < this.length; i++) { + h = ((h << 5) - h + this.charCodeAt(i)) & ~0; + } - return h; + return h; }; // HACK: Nasty compatibility shim for JS Error <-> C# Exception Error.prototype.get_Message = function () { - return String(this); + return String(this); }; Error.prototype.get_StackTrace = function () { - return this.stack || ""; + return this.stack || ""; }; $jsilcore.$ParseBoolean = function (text) { - if (arguments.length !== 1) - throw new Error("NumberStyles not supported"); + if (arguments.length !== 1) + throw new Error("NumberStyles not supported"); - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseBoolean(text, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseBoolean(text, temp)) + return temp.get(); - throw new System.Exception("Invalid boolean"); + throw new System.Exception("Invalid boolean"); }; $jsilcore.$TryParseBoolean = function (text, result) { - text = text.toLowerCase().trim(); + text = text.toLowerCase().trim(); - if (text === "true") { - result.set(true); - return true; - } else if (text === "false") { - result.set(false); - return true; - } + if (text === "true") { + result.set(true); + return true; + } else if (text === "false") { + result.set(false); + return true; + } - return false; + return false; }; $jsilcore.$MakeParseExternals = function ($, type, parse, tryParse) { - $.Method({ Static: true, Public: true }, "Parse", - (new JSIL.MethodSignature(type, [$.String], [])), - parse - ); + $.Method({ Static: true, Public: true }, "Parse", + (new JSIL.MethodSignature(type, [$.String], [])), + parse + ); - $.Method({ Static: true, Public: true }, "Parse", - (new JSIL.MethodSignature(type, [$.String, $jsilcore.TypeRef("System.Globalization.NumberStyles")], [])), - parse - ); + $.Method({ Static: true, Public: true }, "Parse", + (new JSIL.MethodSignature(type, [$.String, $jsilcore.TypeRef("System.Globalization.NumberStyles")], [])), + parse + ); - $.Method({ Static: true, Public: true }, "TryParse", - (new JSIL.MethodSignature($.Boolean, [$.String, $jsilcore.TypeRef("JSIL.Reference", [type])], [])), - tryParse - ); + $.Method({ Static: true, Public: true }, "TryParse", + (new JSIL.MethodSignature($.Boolean, [$.String, $jsilcore.TypeRef("JSIL.Reference", [type])], [])), + tryParse + ); }; JSIL.ImplementExternals( "System.Boolean", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (value === false) || (value === true); - }); + $.RawMethod(true, "CheckType", function (value) { + return (value === false) || (value === true); + }); - $jsilcore.$MakeParseExternals($, $.Boolean, $jsilcore.$ParseBoolean, $jsilcore.$TryParseBoolean); + $jsilcore.$MakeParseExternals($, $.Boolean, $jsilcore.$ParseBoolean, $jsilcore.$TryParseBoolean); } ); JSIL.MakeNumericType(Boolean, "System.Boolean", true); JSIL.ImplementExternals( "System.Char", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "string") && (value.length == 1); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "string") && (value.length == 1); + }); - $.Constant({ Public: true, Static: true }, "MaxValue", "\uffff"); - $.Constant({ Public: true, Static: true }, "MinValue", "\0"); + $.Constant({ Public: true, Static: true }, "MaxValue", "\uffff"); + $.Constant({ Public: true, Static: true }, "MinValue", "\0"); } ); JSIL.MakeNumericType(String, "System.Char", true); JSIL.ImplementExternals( "System.Byte", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0) && (value <= 255); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0) && (value <= 255); + }); - $.Constant({ Public: true, Static: true }, "MinValue", 0); - $.Constant({ Public: true, Static: true }, "MaxValue", 255); + $.Constant({ Public: true, Static: true }, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 255); } ); JSIL.MakeNumericType(Number, "System.Byte", true, "Uint8Array"); JSIL.ImplementExternals( "System.SByte", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= -128) && (value <= 127); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= -128) && (value <= 127); + }); - $.Constant({ Public: true, Static: true }, "MinValue", -128); - $.Constant({ Public: true, Static: true }, "MaxValue", 127); + $.Constant({ Public: true, Static: true }, "MinValue", -128); + $.Constant({ Public: true, Static: true }, "MaxValue", 127); } ); JSIL.MakeNumericType(Number, "System.SByte", true, "Int8Array"); $jsilcore.$ParseInt = function (text, style) { - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseInt(text, style, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseInt(text, style, temp)) + return temp.get(); - throw new System.Exception("Invalid integer"); + throw new System.Exception("Invalid integer"); }; $jsilcore.$TryParseInt = function (text, style, result) { - if (arguments.length === 2) { - result = style; - style = 0; - } + if (arguments.length === 2) { + result = style; + style = 0; + } - var radix = 10; + var radix = 10; - if (style & System.Globalization.NumberStyles.AllowHexSpecifier) - radix = 16; + if (style & System.Globalization.NumberStyles.AllowHexSpecifier) + radix = 16; - var parsed; - result.set(parsed = parseInt(text, radix)); - return !isNaN(parsed); + var parsed; + result.set(parsed = parseInt(text, radix)); + return !isNaN(parsed); }; JSIL.ImplementExternals( "System.UInt16", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0); + }); - $jsilcore.$MakeParseExternals($, $.UInt16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.UInt16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({ Public: true, Static: true }, "MaxValue", 65535); - $.Constant({ Public: true, Static: true }, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 65535); + $.Constant({ Public: true, Static: true }, "MinValue", 0); } ); JSIL.MakeNumericType(Number, "System.UInt16", true, "Uint16Array"); JSIL.ImplementExternals( "System.Int16", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Int16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.Int16, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({ Public: true, Static: true }, "MaxValue", 32767); - $.Constant({ Public: true, Static: true }, "MinValue", -32768); + $.Constant({ Public: true, Static: true }, "MaxValue", 32767); + $.Constant({ Public: true, Static: true }, "MinValue", -32768); } ); JSIL.MakeNumericType(Number, "System.Int16", true, "Int16Array"); JSIL.ImplementExternals( "System.UInt32", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number") && (value >= 0); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number") && (value >= 0); + }); - $jsilcore.$MakeParseExternals($, $.UInt32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.UInt32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({ Public: true, Static: true }, "MaxValue", 4294967295); - $.Constant({ Public: true, Static: true }, "MinValue", 0); + $.Constant({ Public: true, Static: true }, "MaxValue", 4294967295); + $.Constant({ Public: true, Static: true }, "MinValue", 0); } ); JSIL.MakeNumericType(Number, "System.UInt32", true, "Uint32Array"); JSIL.ImplementExternals( "System.Int32", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Int32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); + $jsilcore.$MakeParseExternals($, $.Int32, $jsilcore.$ParseInt, $jsilcore.$TryParseInt); - $.Constant({ Public: true, Static: true }, "MaxValue", 2147483647); - $.Constant({ Public: true, Static: true }, "MinValue", -2147483648); + $.Constant({ Public: true, Static: true }, "MaxValue", 2147483647); + $.Constant({ Public: true, Static: true }, "MinValue", -2147483648); } ); JSIL.MakeNumericType(Number, "System.Int32", true, "Int32Array"); $jsilcore.$ParseFloat = function (text, style) { - var temp = new JSIL.BoxedVariable(null); - if ($jsilcore.$TryParseFloat(text, style, temp)) - return temp.get(); + var temp = new JSIL.BoxedVariable(null); + if ($jsilcore.$TryParseFloat(text, style, temp)) + return temp.get(); - throw new System.Exception("Invalid float"); + throw new System.Exception("Invalid float"); }; $jsilcore.$TryParseFloat = function (text, style, result) { - if (arguments.length === 2) { - result = style; - style = 0; - } - - var parsed; - result.set(parsed = parseFloat(text)); - - if (isNaN(parsed)) { - var lowered = text.toLowerCase(); - - if (lowered === "nan") { - result.set(Number.NaN); - return true; - } else if (lowered === "-infinity") { - result.set(Number.NEGATIVE_INFINITY); - return true; - } else if ((lowered === "+infinity") || (lowered === "infinity")) { - result.set(Number.POSITIVE_INFINITY); - return true; - } else { - return false; - } + if (arguments.length === 2) { + result = style; + style = 0; + } + + var parsed; + result.set(parsed = parseFloat(text)); + + if (isNaN(parsed)) { + var lowered = text.toLowerCase(); + + if (lowered === "nan") { + result.set(Number.NaN); + return true; + } else if (lowered === "-infinity") { + result.set(Number.NEGATIVE_INFINITY); + return true; + } else if ((lowered === "+infinity") || (lowered === "infinity")) { + result.set(Number.POSITIVE_INFINITY); + return true; } else { - return true; + return false; } + } else { + return true; + } }; JSIL.ImplementExternals( "System.Single", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); + $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); - $.Constant({ Public: true, Static: true }, "MinValue", -3.4028234663852886E+38); - $.Constant({ Public: true, Static: true }, "Epsilon", 1.4012984643248171E-45); - $.Constant({ Public: true, Static: true }, "MaxValue", 3.4028234663852886E+38); - $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); - $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); - $.Constant({ Public: true, Static: true }, "NaN", NaN); + $.Constant({ Public: true, Static: true }, "MinValue", -3.4028234663852886E+38); + $.Constant({ Public: true, Static: true }, "Epsilon", 1.4012984643248171E-45); + $.Constant({ Public: true, Static: true }, "MaxValue", 3.4028234663852886E+38); + $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); + $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); + $.Constant({ Public: true, Static: true }, "NaN", NaN); } ); JSIL.MakeNumericType(Number, "System.Single", false, "Float32Array"); JSIL.ImplementExternals( "System.Double", function ($) { - $.RawMethod(true, "CheckType", function (value) { - return (typeof (value) === "number"); - }); + $.RawMethod(true, "CheckType", function (value) { + return (typeof (value) === "number"); + }); - $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); + $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); - $.Constant({ Public: true, Static: true }, "MinValue", -1.7976931348623157E+308); - $.Constant({ Public: true, Static: true }, "MaxValue", 1.7976931348623157E+308); - $.Constant({ Public: true, Static: true }, "Epsilon", 4.94065645841247E-324); - $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); - $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); - $.Constant({ Public: true, Static: true }, "NaN", NaN); + $.Constant({ Public: true, Static: true }, "MinValue", -1.7976931348623157E+308); + $.Constant({ Public: true, Static: true }, "MaxValue", 1.7976931348623157E+308); + $.Constant({ Public: true, Static: true }, "Epsilon", 4.94065645841247E-324); + $.Constant({ Public: true, Static: true }, "NegativeInfinity", -Infinity); + $.Constant({ Public: true, Static: true }, "PositiveInfinity", Infinity); + $.Constant({ Public: true, Static: true }, "NaN", NaN); } ); JSIL.MakeNumericType(Number, "System.Double", false, "Float64Array"); @@ -285,183 +285,183 @@ JSIL.MakeClass("System.Object", "System.ComponentModel.TypeConverter", true); JSIL.MakeClass("System.ComponentModel.TypeConverter", "System.ComponentModel.ExpandableObjectConverter", true); $jsilcore.$GetInvocationList = function (delegate) { - if (delegate === null) { - return []; - } else if (typeof (delegate.__delegates__) !== "undefined") { - return delegate.__delegates__; - } else if (typeof (delegate) === "function") { - return [delegate]; - } else { - return null; - } + if (delegate === null) { + return []; + } else if (typeof (delegate.__delegates__) !== "undefined") { + return delegate.__delegates__; + } else if (typeof (delegate) === "function") { + return [delegate]; + } else { + return null; + } }; $jsilcore.$CompareSinglecastDelegate = function (lhs, rhs) { - if (lhs.__object__ !== rhs.__object__) - return false; + if (lhs.__object__ !== rhs.__object__) + return false; - if (lhs.__method__ !== rhs.__method__) - return false; + if (lhs.__method__ !== rhs.__method__) + return false; - return true; + return true; }; $jsilcore.$CompareMulticastDelegate = function (lhs, rhs) { - var lhsInvocationList = $jsilcore.$GetInvocationList(lhs); - var rhsInvocationList = $jsilcore.$GetInvocationList(rhs); + var lhsInvocationList = $jsilcore.$GetInvocationList(lhs); + var rhsInvocationList = $jsilcore.$GetInvocationList(rhs); - if (lhsInvocationList.length !== rhsInvocationList.length) - return false; + if (lhsInvocationList.length !== rhsInvocationList.length) + return false; - for (var i = 0, l = lhsInvocationList.length; i < l; i++) { - if (!$jsilcore.$AreDelegatesEqual(lhsInvocationList[i], rhsInvocationList[i])) - return false; - } + for (var i = 0, l = lhsInvocationList.length; i < l; i++) { + if (!$jsilcore.$AreDelegatesEqual(lhsInvocationList[i], rhsInvocationList[i])) + return false; + } - return true; + return true; }; $jsilcore.$AreDelegatesEqual = function (lhs, rhs) { - if (lhs === rhs) - return true; + if (lhs === rhs) + return true; - var singleMethod, otherMethod; - if (!lhs.__isMulticast__) - return $jsilcore.$CompareSinglecastDelegate(lhs, rhs); - else if (!rhs.__isMulticast__) - return $jsilcore.$CompareSinglecastDelegate(rhs, lhs); - else - return $jsilcore.$CompareMulticastDelegate(lhs, rhs); + var singleMethod, otherMethod; + if (!lhs.__isMulticast__) + return $jsilcore.$CompareSinglecastDelegate(lhs, rhs); + else if (!rhs.__isMulticast__) + return $jsilcore.$CompareSinglecastDelegate(rhs, lhs); + else + return $jsilcore.$CompareMulticastDelegate(lhs, rhs); }; $jsilcore.$CombineDelegates = function (lhs, rhs) { - if (rhs === null) { - return lhs; - } else if (lhs === null) { - return rhs; - } + if (rhs === null) { + return lhs; + } else if (lhs === null) { + return rhs; + } - var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); - newList.push.apply(newList, $jsilcore.$GetInvocationList(rhs)); - var result = JSIL.MulticastDelegate.New(newList); - return result; + var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); + newList.push.apply(newList, $jsilcore.$GetInvocationList(rhs)); + var result = JSIL.MulticastDelegate.New(newList); + return result; }; $jsilcore.$RemoveDelegate = function (lhs, rhs) { - if (rhs === null) - return lhs; - if (lhs === null) - return null; - - var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); - - for (var i = 0; i < newList.length; i++) { - var item = newList[i]; - if ($jsilcore.$AreDelegatesEqual(item, rhs)) { - newList.splice(i, 1); - break; - } + if (rhs === null) + return lhs; + if (lhs === null) + return null; + + var newList = Array.prototype.slice.call($jsilcore.$GetInvocationList(lhs)); + + for (var i = 0; i < newList.length; i++) { + var item = newList[i]; + if ($jsilcore.$AreDelegatesEqual(item, rhs)) { + newList.splice(i, 1); + break; } + } - if (newList.length == 0) - return null; - else if (newList.length == 1) - return newList[0]; - else - return JSIL.MulticastDelegate.New(newList); + if (newList.length == 0) + return null; + else if (newList.length == 1) + return newList[0]; + else + return JSIL.MulticastDelegate.New(newList); }; JSIL.ImplementExternals("System.Delegate", function ($) { - var tDelegate = $jsilcore.TypeRef("System.Delegate"); - - $.RawMethod(false, "Invoke", function () { - return this.__method__.apply(this.__object__, arguments); - }); + var tDelegate = $jsilcore.TypeRef("System.Delegate"); - $.Method({ Static: false, Public: true }, "GetInvocationList", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [tDelegate]), [], [])), - function GetInvocationList() { - return [this]; - } - ); + $.RawMethod(false, "Invoke", function () { + return this.__method__.apply(this.__object__, arguments); + }); - $.Method({ Static: true, Public: true }, "CreateDelegate", - (new JSIL.MethodSignature(tDelegate, [ - $jsilcore.TypeRef("System.Type"), $.Object, - $jsilcore.TypeRef("System.Reflection.MethodInfo") - ], [])), - function CreateDelegate(delegateType, firstArgument, method) { - var impl = JSIL.$GetMethodImplementation(method); + $.Method({ Static: false, Public: true }, "GetInvocationList", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [tDelegate]), [], [])), + function GetInvocationList() { + return [this]; + } + ); - if (typeof (impl) !== "function") - throw new System.Exception("Failed to bind delegate"); + $.Method({ Static: true, Public: true }, "CreateDelegate", + (new JSIL.MethodSignature(tDelegate, [ + $jsilcore.TypeRef("System.Type"), $.Object, + $jsilcore.TypeRef("System.Reflection.MethodInfo") + ], [])), + function CreateDelegate(delegateType, firstArgument, method) { + var impl = JSIL.$GetMethodImplementation(method); - var delegatePublicInterface = delegateType.__PublicInterface__; + if (typeof (impl) !== "function") + throw new System.Exception("Failed to bind delegate"); - if (typeof (delegatePublicInterface.New) !== "function") { - JSIL.Host.abort(new Error("Invalid delegate type")); - } + var delegatePublicInterface = delegateType.__PublicInterface__; - return delegatePublicInterface.New(firstArgument, impl); + if (typeof (delegatePublicInterface.New) !== "function") { + JSIL.Host.abort(new Error("Invalid delegate type")); } - ); - $.Method({ Static: true, Public: true }, "op_Equality", - (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), - $jsilcore.$AreDelegatesEqual - ); + return delegatePublicInterface.New(firstArgument, impl); + } + ); - $.Method({ Static: true, Public: true }, "op_Inequality", - (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), - function op_Inequality(d1, d2) { - return !$jsilcore.$AreDelegatesEqual(d1, d2); - } - ); + $.Method({ Static: true, Public: true }, "op_Equality", + (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), + $jsilcore.$AreDelegatesEqual + ); - $.Method({ Static: true, Public: true }, "Combine", - (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), - $jsilcore.$CombineDelegates - ); + $.Method({ Static: true, Public: true }, "op_Inequality", + (new JSIL.MethodSignature($.Boolean, [tDelegate, tDelegate], [])), + function op_Inequality(d1, d2) { + return !$jsilcore.$AreDelegatesEqual(d1, d2); + } + ); - $.Method({ Static: true, Public: true }, "Remove", - (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), - $jsilcore.$RemoveDelegate - ); + $.Method({ Static: true, Public: true }, "Combine", + (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), + $jsilcore.$CombineDelegates + ); + + $.Method({ Static: true, Public: true }, "Remove", + (new JSIL.MethodSignature(tDelegate, [tDelegate, tDelegate], [])), + $jsilcore.$RemoveDelegate + ); }); JSIL.ImplementExternals("System.MulticastDelegate", function ($) { - $.RawMethod(false, "Invoke", function () { - return this.apply(null, arguments); - }); - - $.Method({ Static: false, Public: true }, "GetInvocationList", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Delegate")]), [], [])), - function GetInvocationList() { - return this.__delegates__; - } - ); + $.RawMethod(false, "Invoke", function () { + return this.apply(null, arguments); + }); + + $.Method({ Static: false, Public: true }, "GetInvocationList", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Delegate")]), [], [])), + function GetInvocationList() { + return this.__delegates__; + } + ); }); JSIL.MakeClass("System.Object", "System.Delegate", true, []); JSIL.MakeClass("System.Object", "System.MulticastDelegate", true, []); JSIL.MulticastDelegate.New = function (delegates) { - var delegatesCopy = Array.prototype.slice.call(delegates); - var delegateCount = delegates.length; + var delegatesCopy = Array.prototype.slice.call(delegates); + var delegateCount = delegates.length; - var resultDelegate = function MulticastDelegate_Invoke() { - var result; + var resultDelegate = function MulticastDelegate_Invoke() { + var result; - for (var i = 0; i < delegateCount; i++) { - var d = delegatesCopy[i]; - // FIXME: bind, call and apply suck - result = d.apply(d.__object__ || null, arguments); - } + for (var i = 0; i < delegateCount; i++) { + var d = delegatesCopy[i]; + // FIXME: bind, call and apply suck + result = d.apply(d.__object__ || null, arguments); + } - return result; - }; + return result; + }; - JSIL.SetValueProperty(resultDelegate, "__delegates__", delegatesCopy); - JSIL.SetValueProperty(resultDelegate, "__isMulticast__", true); - JSIL.SetValueProperty(resultDelegate, "__ThisType__", delegates[0].__ThisType__); - JSIL.SetValueProperty(resultDelegate, "toString", delegates[0].toString); + JSIL.SetValueProperty(resultDelegate, "__delegates__", delegatesCopy); + JSIL.SetValueProperty(resultDelegate, "__isMulticast__", true); + JSIL.SetValueProperty(resultDelegate, "__ThisType__", delegates[0].__ThisType__); + JSIL.SetValueProperty(resultDelegate, "toString", delegates[0].toString); - return resultDelegate; + return resultDelegate; }; JSIL.MakeDelegate("System.Action", true, []); @@ -476,153 +476,153 @@ JSIL.MakeDelegate("System.Func`4", true, ["T1", "T2", "T3", "TResult"]); JSIL.ImplementExternals( "System.Exception", function ($) { - var mscorlib = JSIL.GetCorlib(); - - function captureStackTrace() { - var e = new Error(); - var stackText = e.stack || ""; - return stackText; - }; + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this._message = null; - this._stackTrace = captureStackTrace(); - } - ); + function captureStackTrace() { + var e = new Error(); + var stackText = e.stack || ""; + return stackText; + }; - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String], [])), - function _ctor(message) { - this._message = message; - this._stackTrace = captureStackTrace(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this._message = null; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String, mscorlib.TypeRef("System.Exception")], [])), - function _ctor(message, innerException) { - this._message = message; - this._innerException = innerException; - this._stackTrace = captureStackTrace(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String], [])), + function _ctor(message) { + this._message = message; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({ Static: false, Public: true }, "get_InnerException", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Exception"), [], [])), - function get_InnerException() { - return this._innerException; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String, mscorlib.TypeRef("System.Exception")], [])), + function _ctor(message, innerException) { + this._message = message; + this._innerException = innerException; + this._stackTrace = captureStackTrace(); + } + ); - $.Method({ Static: false, Public: true }, "get_Message", - new JSIL.MethodSignature($.String, []), - function () { - if ((typeof (this._message) === "undefined") || (this._message === null)) - return System.String.Format("Exception of type '{0}' was thrown.", JSIL.GetTypeName(this)); - else - return this._message; - } - ); + $.Method({ Static: false, Public: true }, "get_InnerException", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Exception"), [], [])), + function get_InnerException() { + return this._innerException; + } + ); - $.Method({ Static: false, Public: true }, "get_StackTrace", - new JSIL.MethodSignature($.String, []), - function () { - return this._stackTrace || ""; - } - ); + $.Method({ Static: false, Public: true }, "get_Message", + new JSIL.MethodSignature($.String, []), + function () { + if ((typeof (this._message) === "undefined") || (this._message === null)) + return System.String.Format("Exception of type '{0}' was thrown.", JSIL.GetTypeName(this)); + else + return this._message; + } + ); - $.Method({ Static: false, Public: true }, "toString", - new JSIL.MethodSignature($.String, []), - function () { - var message = this.Message; - var result = System.String.Format("{0}: {1}", JSIL.GetTypeName(this), message); + $.Method({ Static: false, Public: true }, "get_StackTrace", + new JSIL.MethodSignature($.String, []), + function () { + return this._stackTrace || ""; + } + ); - if (this._innerException) { - result += "\n-- Inner exception follows --\n"; - result += this._innerException.toString(); - } + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature($.String, []), + function () { + var message = this.Message; + var result = System.String.Format("{0}: {1}", JSIL.GetTypeName(this), message); - return result; + if (this._innerException) { + result += "\n-- Inner exception follows --\n"; + result += this._innerException.toString(); } - ); + + return result; + } + ); } ); JSIL.ImplementExternals( "System.SystemException", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [], []), - function () { - System.Exception.prototype._ctor.call(this); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [], []), + function () { + System.Exception.prototype._ctor.call(this); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( "System.InvalidCastException", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( "System.InvalidOperationException", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.ImplementExternals( "System.IO.FileNotFoundException", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String, $.String], [])), - function _ctor(message, fileName) { - System.Exception.prototype._ctor.call(this, message); - this._fileName = fileName; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String, $.String], [])), + function _ctor(message, fileName) { + System.Exception.prototype._ctor.call(this, message); + this._fileName = fileName; + } + ); } ); JSIL.ImplementExternals( "System.FormatException", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$.String], []), - function (message) { - System.Exception.prototype._ctor.call(this, message); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$.String], []), + function (message) { + System.Exception.prototype._ctor.call(this, message); + } + ); } ); JSIL.MakeClass("System.Object", "System.Exception", true, [], function ($) { - $.Property({ Public: true, Static: false, Virtual: true }, "Message"); - $.Property({ Public: true, Static: false }, "InnerException"); + $.Property({ Public: true, Static: false, Virtual: true }, "Message"); + $.Property({ Public: true, Static: false }, "InnerException"); }); JSIL.MakeClass("System.Exception", "System.SystemException", true); @@ -646,2232 +646,2243 @@ JSIL.MakeClass("System.SystemException", "System.ArithmeticException", true); JSIL.MakeClass("System.ArithmeticException", "System.OverflowException", true); JSIL.ImplementExternals("System.Console", function ($) { - $.RawMethod(true, "WriteLine", function () { - var text = ""; - if ((arguments.length > 0) && (arguments[0] !== null)) { - text = System.String.Format.apply(System.String, arguments); - } + $.RawMethod(true, "WriteLine", function () { + var text = ""; + if ((arguments.length > 0) && (arguments[0] !== null)) { + text = System.String.Format.apply(System.String, arguments); + } - JSIL.Host.logWriteLine(text); - }); + JSIL.Host.logWriteLine(text); + }); - $.RawMethod(true, "Write", function () { - var text = ""; - if ((arguments.length > 0) && (arguments[0] !== null)) { - text = System.String.Format.apply(System.String, arguments); - } + $.RawMethod(true, "Write", function () { + var text = ""; + if ((arguments.length > 0) && (arguments[0] !== null)) { + text = System.String.Format.apply(System.String, arguments); + } - JSIL.Host.logWrite(text); - }); + JSIL.Host.logWrite(text); + }); }); JSIL.ImplementExternals( "System.Diagnostics.Debug", function ($) { - $.Method({ Static: true, Public: true }, "WriteLine", - (new JSIL.MethodSignature(null, [$.String], [])), - function WriteLine(message) { - JSIL.Host.logWriteLine(message); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + (new JSIL.MethodSignature(null, [$.String], [])), + function WriteLine(message) { + JSIL.Host.logWriteLine(message); + } + ); - $.Method({ Static: true, Public: true }, "Write", - (new JSIL.MethodSignature(null, [$.String], [])), - function Write(message) { - JSIL.Host.logWrite(message); - } - ); + $.Method({ Static: true, Public: true }, "Write", + (new JSIL.MethodSignature(null, [$.String], [])), + function Write(message) { + JSIL.Host.logWrite(message); + } + ); } ); JSIL.MakeStaticClass("System.Console", true, [], function ($) { - $.Property({ Static: true, Public: true }, "In"); - $.Property({ Static: true, Public: true }, "Out"); + $.Property({ Static: true, Public: true }, "In"); + $.Property({ Static: true, Public: true }, "Out"); }); JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($) { - $.RawMethod(false, "__CopyMembers__", - function ArrayEnumerator_CopyMembers(source, target) { - target._array = source._array; - target._length = source._length; - target._index = source._index; - } - ); + $.RawMethod(false, "__CopyMembers__", + function ArrayEnumerator_CopyMembers(source, target) { + target._array = source._array; + target._length = source._length; + target._index = source._index; + } + ); - $.Method({ Public: true, Static: false }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32]), - function (array, startPosition) { - this._array = array; - this._length = array.length; - if (typeof (startPosition) !== "number") - JSIL.RuntimeError("ArrayEnumerator ctor second argument must be number"); + $.Method({ Public: true, Static: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", ["!!0"]), $.Int32]), + function (array, startPosition) { + this._array = array; + this._length = array.length; + if (typeof (startPosition) !== "number") + JSIL.RuntimeError("ArrayEnumerator ctor second argument must be number"); - this._index = startPosition; - } - ); + this._index = startPosition; + } + ); - $.Method({ Public: true, Static: false }, "Reset", - new JSIL.MethodSignature(null, []), - function () { - if (this._array === null) - JSIL.RuntimeError("Enumerator is disposed or not initialized"); + $.Method({ Public: true, Static: false }, "Reset", + new JSIL.MethodSignature(null, []), + function () { + if (this._array === null) + JSIL.RuntimeError("Enumerator is disposed or not initialized"); - this._index = -1; - } - ); - $.Method({ Public: true, Static: false }, "MoveNext", - new JSIL.MethodSignature(System.Boolean, []), - function () { - return (++this._index < this._length); - } - ); - $.Method({ Public: true, Static: false }, "Dispose", - new JSIL.MethodSignature(null, []), - function () { - this._array = null; - this._index = 0; - this._length = -1; - } - ); - $.Method({ Public: true, Static: false }, "get_Current", - new JSIL.MethodSignature(System.Object, []), - function () { - return this._array[this._index]; - } - ); + this._index = -1; + } + ); + $.Method({ Public: true, Static: false }, "MoveNext", + new JSIL.MethodSignature(System.Boolean, []), + function () { + return (++this._index < this._length); + } + ); + $.Method({ Public: true, Static: false }, "Dispose", + new JSIL.MethodSignature(null, []), + function () { + this._array = null; + this._index = 0; + this._length = -1; + } + ); + $.Method({ Public: true, Static: false }, "get_Current", + new JSIL.MethodSignature(System.Object, []), + function () { + return this._array[this._index]; + } + ); - $.Property({ Public: true, Static: false, Virtual: true }, "Current"); + $.Property({ Public: true, Static: false, Virtual: true }, "Current"); - $.ImplementInterfaces( - System.IDisposable, System.Collections.IEnumerator, - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) - ); + $.ImplementInterfaces( + System.IDisposable, System.Collections.IEnumerator, + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) + ); }); JSIL.MakeClass("System.Object", "JSIL.ArrayInterfaceOverlay", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.ArrayInterfaceOverlay"); - - $.RawMethod(false, ".ctor", - function (array) { - this._array = array; - } - ); + var T = new JSIL.GenericParameter("T", "JSIL.ArrayInterfaceOverlay"); - $.RawMethod(false, "$overlayToArray", - function (T) { - // We don't want to allow conversion to an unrelated array type. - // FIXME: Covariance? Contravariance? - if (T.__IsArray__ && (T.__ElementType__ === this.T)) - return this._array; - else - return null; - } - ); + $.RawMethod(false, ".ctor", + function (array) { + this._array = array; + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function () { - return JSIL.GetEnumerator(this._array, this.T); - } - ) - .Overrides(0, "GetEnumerator"); + $.RawMethod(false, "$overlayToArray", + function (T) { + // We don't want to allow conversion to an unrelated array type. + // FIXME: Covariance? Contravariance? + if (T.__IsArray__ && (T.__ElementType__ === this.T)) + return this._array; + else + return null; + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), - function () { - return JSIL.GetEnumerator(this._array, this.T); - } - ) - .Overrides(1, "GetEnumerator"); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function () { + return JSIL.GetEnumerator(this._array, this.T); + } + ) + .Overrides(0, "GetEnumerator"); - // FIXME: Implement actual members of IList. + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), + function () { + return JSIL.GetEnumerator(this._array, this.T); + } + ) + .Overrides(1, "GetEnumerator"); - $.Method({ Static: false, Public: true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), - function CopyTo(array, arrayIndex) { - JSIL.Array.CopyTo(this._array, array, arrayIndex); - } - ); + // FIXME: Implement actual members of IList. - $.Method({ Static: false, Public: true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count() { - return this._array.length; - } - ); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), + function CopyTo(array, arrayIndex) { + JSIL.Array.CopyTo(this._array, array, arrayIndex); + } + ); - $.Method({ Static: false, Public: true }, "get_Item", - new JSIL.MethodSignature(T, [$.Int32], []), - function get_Item(index) { - return this._array[index]; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this._array.length; + } + ); - $.Method({ Static: false, Public: true }, "set_Item", - new JSIL.MethodSignature(null, [$.Int32, T], []), - function set_Item(index, value) { - this._array[index] = value; - } - ); + $.Method({ Static: false, Public: true }, "get_Item", + new JSIL.MethodSignature(T, [$.Int32], []), + function get_Item(index) { + return this._array[index]; + } + ); - $.Method({ Static: false, Public: true }, "Contains", - new JSIL.MethodSignature($.Boolean, [T], []), - function Contains(value) { - return (this._array.indexOf(value) >= 0); - } - ); + $.Method({ Static: false, Public: true }, "set_Item", + new JSIL.MethodSignature(null, [$.Int32, T], []), + function set_Item(index, value) { + this._array[index] = value; + } + ); - $.Method({ Static: false, Public: true }, "IndexOf", - new JSIL.MethodSignature($.Int32, [T], []), - function IndexOf(value) { - return this._array.indexOf(value); - } - ); + $.Method({ Static: false, Public: true }, "Contains", + new JSIL.MethodSignature($.Boolean, [T], []), + function Contains(value) { + return (this._array.indexOf(value) >= 0); + } + ); - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), - /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), - /* 2 */ $jsilcore.TypeRef("System.Collections.ICollection"), - /* 3 */ $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [T]), - /* 4 */ $jsilcore.TypeRef("System.Collections.IList"), - /* 5 */ $jsilcore.TypeRef("System.Collections.Generic.IList`1", [T]) - ); + $.Method({ Static: false, Public: true }, "IndexOf", + new JSIL.MethodSignature($.Int32, [T], []), + function IndexOf(value) { + return this._array.indexOf(value); + } + ); + + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), + /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), + /* 2 */ $jsilcore.TypeRef("System.Collections.ICollection"), + /* 3 */ $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [T]), + /* 4 */ $jsilcore.TypeRef("System.Collections.IList"), + /* 5 */ $jsilcore.TypeRef("System.Collections.Generic.IList`1", [T]) + ); }); JSIL.ImplementExternals( "System.Threading.Thread", function ($) { - $.Method({ Static: true, Public: true }, ".cctor2", - (new JSIL.MethodSignature(null, [], [])), - function () { - // This type already has a cctor, so we add a second one. - System.Threading.Thread._currentThread = JSIL.CreateInstanceOfType( - System.Threading.Thread.__Type__, - null - ); - } - ); + $.Method({ Static: true, Public: true }, ".cctor2", + (new JSIL.MethodSignature(null, [], [])), + function () { + // This type already has a cctor, so we add a second one. + System.Threading.Thread._currentThread = JSIL.CreateInstanceOfType( + System.Threading.Thread.__Type__, + null + ); + } + ); - $.Method({ Static: true, Public: true }, "get_CurrentThread", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Thread"), [], [])), - function get_CurrentThread() { - return System.Threading.Thread._currentThread; - } - ); + $.Method({ Static: true, Public: true }, "get_CurrentThread", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Thread"), [], [])), + function get_CurrentThread() { + return System.Threading.Thread._currentThread; + } + ); - $.Method({ Static: false, Public: true }, "get_ManagedThreadId", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_ManagedThreadId() { - return 0; - } - ); + $.Method({ Static: false, Public: true }, "get_ManagedThreadId", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_ManagedThreadId() { + return 0; + } + ); } ); JSIL.MakeClass("System.Object", "System.Threading.Thread", true, [], function ($) { - $.Field({ Public: false, Static: true }, "_currentThread", $.Type, function ($) { return null; }); + $.Field({ Public: false, Static: true }, "_currentThread", $.Type, function ($) { return null; }); - $.ExternalMethod( - { Public: true, Static: true }, "get_CurrentThread", - new JSIL.MethodSignature($.Type, []) - ); - $.ExternalMethod( - { Public: true, Static: true }, "get_ManagedThreadId", - new JSIL.MethodSignature(System.Int32, []) - ); + $.ExternalMethod( + { Public: true, Static: true }, "get_CurrentThread", + new JSIL.MethodSignature($.Type, []) + ); + $.ExternalMethod( + { Public: true, Static: true }, "get_ManagedThreadId", + new JSIL.MethodSignature(System.Int32, []) + ); - $.Property({ Public: true, Static: true }, "CurrentThread"); - $.Property({ Public: true, Static: true }, "ManagedThreadId"); + $.Property({ Public: true, Static: true }, "CurrentThread"); + $.Property({ Public: true, Static: true }, "ManagedThreadId"); }); $jsilcore.InitResizableArray = function (target, elementType, initialSize) { - target._items = new Array(); + target._items = new Array(); }; $jsilcore.$ListExternals = function ($, T, type) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - if (typeof (T) === "undefined") - JSIL.RuntimeError("Invalid use of $ListExternals"); + if (typeof (T) === "undefined") + JSIL.RuntimeError("Invalid use of $ListExternals"); - var getT; + var getT; - switch (type) { - case "ArrayList": - case "ObjectCollection": - getT = function () { return System.Object; } - break; - default: - getT = function (self) { return self.T; } - break; - } + switch (type) { + case "ArrayList": + case "ObjectCollection": + getT = function () { return System.Object; } + break; + default: + getT = function (self) { return self.T; } + break; + } - var indexOfImpl = function List_IndexOf(value) { - for (var i = 0, l = this._size; i < l; i++) { - if (JSIL.ObjectEquals(this._items[i], value)) - return i; - } + var indexOfImpl = function List_IndexOf(value) { + for (var i = 0, l = this._size; i < l; i++) { + if (JSIL.ObjectEquals(this._items[i], value)) + return i; + } - return -1; - }; + return -1; + }; - var findIndexImpl = function List_FindIndex(predicate) { - for (var i = 0, l = this._size; i < l; i++) { - if (predicate(this._items[i])) - return i; - } + var findIndexImpl = function List_FindIndex(predicate) { + for (var i = 0, l = this._size; i < l; i++) { + if (predicate(this._items[i])) + return i; + } - return -1; - }; + return -1; + }; - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [], []), - function () { - $jsilcore.InitResizableArray(this, getT(this), 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [], []), + function () { + $jsilcore.InitResizableArray(this, getT(this), 16); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (size) { - $jsilcore.InitResizableArray(this, getT(this), size); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (size) { + $jsilcore.InitResizableArray(this, getT(this), size); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), - function (values) { - this._items = JSIL.EnumerableToArray(values); - this._capacity = this._items.length; - this._size = this._items.length; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), + function (values) { + this._items = JSIL.EnumerableToArray(values); + this._capacity = this._items.length; + this._size = this._items.length; + } + ); - var addImpl = function (item) { - this.InsertItem(this._size, item); - return this._size; - }; + var addImpl = function (item) { + this.InsertItem(this._size, item); + return this._size; + }; + + switch (type) { + case "ArrayList": + case "ObjectCollection": + $.Method({ Static: false, Public: true }, "Add", + new JSIL.MethodSignature($.Int32, [T], []), + addImpl + ); + break; + default: + $.Method({ Static: false, Public: true }, "Add", + new JSIL.MethodSignature(null, [T], []), + addImpl + ); + break; + } - switch (type) { - case "ArrayList": - case "ObjectCollection": - $.Method({ Static: false, Public: true }, "Add", - new JSIL.MethodSignature($.Int32, [T], []), - addImpl - ); - break; - default: - $.Method({ Static: false, Public: true }, "Add", - new JSIL.MethodSignature(null, [T], []), - addImpl - ); - break; - } - - $.Method({ Static: false, Public: true }, "AddRange", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), - function (items) { - var e = JSIL.GetEnumerator(items, this.T); - var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; - var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; - try { - while (moveNext.Call(e)) - this.Add(getCurrent.Call(e)); - } finally { - JSIL.Dispose(e); - } + $.Method({ Static: false, Public: true }, "AddRange", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), + function (items) { + var e = JSIL.GetEnumerator(items, this.T); + var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; + var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; + try { + while (moveNext.Call(e)) + this.Add(getCurrent.Call(e)); + } finally { + JSIL.Dispose(e); } - ); - - $.Method({ Static: false, Public: true }, "AsReadOnly", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.ObjectModel.ReadOnlyCollection`1", [T]), [], []), - function () { - // FIXME - if (typeof (this.tReadOnlyCollection) === "undefined") { - this.tReadOnlyCollection = System.Collections.ObjectModel.ReadOnlyCollection$b1.Of(this.T).__Type__; - } + } + ); - return JSIL.CreateInstanceOfType(this.tReadOnlyCollection, "$listCtor", [this]); + $.Method({ Static: false, Public: true }, "AsReadOnly", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.ObjectModel.ReadOnlyCollection`1", [T]), [], []), + function () { + // FIXME + if (typeof (this.tReadOnlyCollection) === "undefined") { + this.tReadOnlyCollection = System.Collections.ObjectModel.ReadOnlyCollection$b1.Of(this.T).__Type__; } - ); - $.Method({ Static: false, Public: true }, "Clear", - new JSIL.MethodSignature(null, [], []), - function () { - this.ClearItems(); - } - ); + return JSIL.CreateInstanceOfType(this.tReadOnlyCollection, "$listCtor", [this]); + } + ); - $.Method({ Static: false, Public: true }, "set_Capacity", - new JSIL.MethodSignature(null, [$.Int32], []), - function List_set_Capacity(value) { - // FIXME - return; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + new JSIL.MethodSignature(null, [], []), + function () { + this.ClearItems(); + } + ); - $.Method({ Static: false, Public: true }, "Contains", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), - function List_Contains(value) { - return this.IndexOf(value) >= 0; - } - ); + $.Method({ Static: false, Public: true }, "set_Capacity", + new JSIL.MethodSignature(null, [$.Int32], []), + function List_set_Capacity(value) { + // FIXME + return; + } + ); - $.Method({ Static: false, Public: true }, "Exists", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function List_Exists(predicate) { - return this.FindIndex(predicate) >= 0; - } - ); + $.Method({ Static: false, Public: true }, "Contains", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), + function List_Contains(value) { + return this.IndexOf(value) >= 0; + } + ); - $.Method({ Static: false, Public: true }, "ForEach", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Action`1", [T])], []), - function ForEach(action) { - for (var i = 0, sz = this._size; i < sz; i++) { - var item = this._items[i]; + $.Method({ Static: false, Public: true }, "Exists", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function List_Exists(predicate) { + return this.FindIndex(predicate) >= 0; + } + ); - action(item); - } - } - ); + $.Method({ Static: false, Public: true }, "ForEach", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Action`1", [T])], []), + function ForEach(action) { + for (var i = 0, sz = this._size; i < sz; i++) { + var item = this._items[i]; - $.Method({ Static: false, Public: true }, "Find", - new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function List_Find(predicate) { - var index = this.FindIndex(predicate); - if (index >= 0) - return this._items[index]; - else - return JSIL.DefaultValue(this.T); + action(item); } - ); + } + ); - $.Method({ Static: false, Public: true }, "FindAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1", [T]), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function FindAll(predicate) { - var thisType = this.GetType(); + $.Method({ Static: false, Public: true }, "Find", + new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function List_Find(predicate) { + var index = this.FindIndex(predicate); + if (index >= 0) + return this._items[index]; + else + return JSIL.DefaultValue(this.T); + } + ); - // Manually initialize the result since we don't want to hassle with overloaded ctors - var result = JSIL.CreateInstanceOfType(thisType, null); - result._items = []; + $.Method({ Static: false, Public: true }, "FindAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1", [T]), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function FindAll(predicate) { + var thisType = this.GetType(); - for (var i = 0, sz = this._size; i < sz; i++) { - var item = this._items[i]; + // Manually initialize the result since we don't want to hassle with overloaded ctors + var result = JSIL.CreateInstanceOfType(thisType, null); + result._items = []; - if (predicate(item)) - result._items.push(item); - } + for (var i = 0, sz = this._size; i < sz; i++) { + var item = this._items[i]; - result._capacity = result._size = result._items.length; - return result; + if (predicate(item)) + result._items.push(item); } - ); - $.Method({ Static: false, Public: true }, "FindIndex", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - findIndexImpl - ); + result._capacity = result._size = result._items.length; + return result; + } + ); - $.Method({ Static: false, Public: true }, "get_Capacity", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), - function () { - return this._items.length; - } - ); + $.Method({ Static: false, Public: true }, "FindIndex", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + findIndexImpl + ); - $.Method({ Static: false, Public: true }, "get_Count", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), - function () { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Capacity", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), + function () { + return this._items.length; + } + ); - var rangeCheckImpl = function (index, size) { - return (index >= 0) && (size > index); + $.Method({ Static: false, Public: true }, "get_Count", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [], []), + function () { + return this._size; } + ); - $.Method({ Static: false, Public: true }, "get_Item", - new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Int32")], []), - function (index) { - if (rangeCheckImpl(index, this._size)) - return this._items[index]; - else - throw new System.ArgumentOutOfRangeException("index"); - } - ); + var rangeCheckImpl = function (index, size) { + return (index >= 0) && (size > index); + } - $.Method({ Static: false, Public: true }, "set_Item", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), T], []), - function (index, value) { - if (rangeCheckImpl(index, this._size)) - this.SetItem(index, value); - else - throw new System.ArgumentOutOfRangeException("index"); - } - ); + $.Method({ Static: false, Public: true }, "get_Item", + new JSIL.MethodSignature(T, [mscorlib.TypeRef("System.Int32")], []), + function (index) { + if (rangeCheckImpl(index, this._size)) + return this._items[index]; + else + throw new System.ArgumentOutOfRangeException("index"); + } + ); - var getEnumeratorType = function (self) { - if (self.$enumeratorType) - return self.$enumeratorType; + $.Method({ Static: false, Public: true }, "set_Item", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), T], []), + function (index, value) { + if (rangeCheckImpl(index, this._size)) + this.SetItem(index, value); + else + throw new System.ArgumentOutOfRangeException("index"); + } + ); - var T = getT(self); - return self.$enumeratorType = System.Collections.Generic.List$b1_Enumerator.Of(T); - }; + var getEnumeratorType = function (self) { + if (self.$enumeratorType) + return self.$enumeratorType; - var getEnumeratorImpl = function () { - var enumeratorType = getEnumeratorType(this); + var T = getT(self); + return self.$enumeratorType = System.Collections.Generic.List$b1_Enumerator.Of(T); + }; - return new enumeratorType(this); - }; + var getEnumeratorImpl = function () { + var enumeratorType = getEnumeratorType(this); - switch (type) { - case "List": - $.Method({ Static: false, Public: true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1+Enumerator", [T]), [], [])), - getEnumeratorImpl - ); - break; - } + return new enumeratorType(this); + }; + + switch (type) { + case "List": + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1+Enumerator", [T]), [], [])), + getEnumeratorImpl + ); + break; + } + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], []), + getEnumeratorImpl + ) + .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + + if (type !== "ArrayList") { $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], []), + new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), getEnumeratorImpl ) - .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); + } - if (type !== "ArrayList") { - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], []), - getEnumeratorImpl - ) - .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); - } + $.RawMethod(false, "$GetEnumerator", getEnumeratorImpl); - $.RawMethod(false, "$GetEnumerator", getEnumeratorImpl); + $.Method({ Static: false, Public: true }, "Insert", + (new JSIL.MethodSignature(null, [$.Int32, T], [])), + function Insert(index, item) { + this.InsertItem(index, item); + } + ); - $.Method({ Static: false, Public: true }, "Insert", - (new JSIL.MethodSignature(null, [$.Int32, T], [])), - function Insert(index, item) { - this.InsertItem(index, item); - } - ); + $.Method({ Static: false, Public: true }, "IndexOf", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [T], []), + indexOfImpl + ); - $.Method({ Static: false, Public: true }, "IndexOf", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [T], []), - indexOfImpl - ); + var removeImpl = function (item) { + var index = this._items.indexOf(item); + if (index === -1) + return false; - var removeImpl = function (item) { - var index = this._items.indexOf(item); - if (index === -1) - return false; + this.RemoveAt(index); + return true; + }; + + switch (type) { + case "ArrayList": + case "ObjectCollection": + $.Method({ Static: false, Public: true }, "Remove", + new JSIL.MethodSignature(null, [T], []), + removeImpl + ); + break; + default: + $.Method({ Static: false, Public: true }, "Remove", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), + removeImpl + ); + break; + } - this.RemoveAt(index); - return true; - }; + $.Method({ Static: false, Public: true }, "RemoveAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function (predicate) { + var result = 0; - switch (type) { - case "ArrayList": - case "ObjectCollection": - $.Method({ Static: false, Public: true }, "Remove", - new JSIL.MethodSignature(null, [T], []), - removeImpl - ); - break; - default: - $.Method({ Static: false, Public: true }, "Remove", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), - removeImpl - ); - break; - } - - $.Method({ Static: false, Public: true }, "RemoveAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function (predicate) { - var result = 0; - - for (var i = 0; i < this._size; i++) { - var item = this._items[i]; - - if (predicate(item)) { - this.RemoveItem(i); - i -= 1; - result += 1; - } - } + for (var i = 0; i < this._size; i++) { + var item = this._items[i]; - return result; + if (predicate(item)) { + this.RemoveItem(i); + i -= 1; + result += 1; + } } - ); - $.Method({ Static: false, Public: true }, "RemoveAt", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (index) { - if (!rangeCheckImpl(index, this._size)) - throw new System.ArgumentOutOfRangeException("index"); + return result; + } + ); - this.RemoveItem(index); - } - ); + $.Method({ Static: false, Public: true }, "RemoveAt", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (index) { + if (!rangeCheckImpl(index, this._size)) + throw new System.ArgumentOutOfRangeException("index"); - $.Method({ Static: false, Public: true }, "RemoveRange", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), - function (index, count) { - if (index < 0) - throw new System.ArgumentOutOfRangeException("index"); - else if (count < 0) - throw new System.ArgumentOutOfRangeException("count"); - else if (!rangeCheckImpl(index, this._size)) - throw new System.ArgumentException(); - else if (!rangeCheckImpl(index + count - 1, this._size)) - throw new System.ArgumentException(); - - this._items.splice(index, count); - this._size -= count; - } - ); + this.RemoveItem(index); + } + ); - $.Method({ Static: false, Public: true }, "Sort", - new JSIL.MethodSignature(null, [], []), - function () { - this._items.sort(JSIL.CompareValues); - } - ); + $.Method({ Static: false, Public: true }, "RemoveRange", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], []), + function (index, count) { + if (index < 0) + throw new System.ArgumentOutOfRangeException("index"); + else if (count < 0) + throw new System.ArgumentOutOfRangeException("count"); + else if (!rangeCheckImpl(index, this._size)) + throw new System.ArgumentException(); + else if (!rangeCheckImpl(index + count - 1, this._size)) + throw new System.ArgumentException(); + + this._items.splice(index, count); + this._size -= count; + } + ); - $.Method({ Static: false, Public: true }, "Sort", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Comparison`1", [T])], []), - function (comparison) { - this._items.sort(comparison); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + new JSIL.MethodSignature(null, [], []), + function () { + this._items.sort(JSIL.CompareValues); + } + ); - $.Method({ Static: false, Public: true }, "Sort", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.IComparer")], [])), - function Sort(comparer) { - this._items.sort(function (lhs, rhs) { - return comparer.Compare(lhs, rhs); - }); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Comparison`1", [T])], []), + function (comparison) { + this._items.sort(comparison); + } + ); - $.Method({ Static: false, Public: true }, "Sort", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T])], [])), - function Sort(comparer) { - var tComparer = System.Collections.Generic.IComparer$b1.Of(this.T); - var compare = tComparer.Compare; + $.Method({ Static: false, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.IComparer")], [])), + function Sort(comparer) { + this._items.sort(function (lhs, rhs) { + return comparer.Compare(lhs, rhs); + }); + } + ); - this._items.sort(function (lhs, rhs) { - return compare.Call(comparer, null, lhs, rhs); - }); - } - ); + $.Method({ Static: false, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T])], [])), + function Sort(comparer) { + var tComparer = System.Collections.Generic.IComparer$b1.Of(this.T); + var compare = tComparer.Compare; - $.Method({ Static: false, Public: true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [ - $.Int32, $.Int32, - T, - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) - ], [])), - function BinarySearch(index, count, item, comparer) { - return JSIL.BinarySearch( - this.T, this._items, index, count, - item, comparer - ); - } - ); + this._items.sort(function (lhs, rhs) { + return compare.Call(comparer, null, lhs, rhs); + }); + } + ); - $.Method({ Static: false, Public: true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [T], [])), - function BinarySearch(item) { - return JSIL.BinarySearch( - this.T, this._items, 0, this._size, - item, null - ); - } - ); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [ + $.Int32, $.Int32, + T, + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) + ], [])), + function BinarySearch(index, count, item, comparer) { + return JSIL.BinarySearch( + this.T, this._items, index, count, + item, comparer + ); + } + ); - $.Method({ Static: false, Public: true }, "BinarySearch", - (new JSIL.MethodSignature($.Int32, [ - T, - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) - ], [])), - function BinarySearch(item, comparer) { - return JSIL.BinarySearch( - this.T, this._items, 0, this._size, - item, comparer - ); - } - ); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [T], [])), + function BinarySearch(item) { + return JSIL.BinarySearch( + this.T, this._items, 0, this._size, + item, null + ); + } + ); - $.Method({ Static: false, Public: true }, "ToArray", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [T]), [], []), - function () { - var result = JSIL.Array.New(this.T, this._size); + $.Method({ Static: false, Public: true }, "BinarySearch", + (new JSIL.MethodSignature($.Int32, [ + T, + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [T]) + ], [])), + function BinarySearch(item, comparer) { + return JSIL.BinarySearch( + this.T, this._items, 0, this._size, + item, comparer + ); + } + ); - for (var i = 0, l = this._size, items = this._items; i < l; i++) { - result[i] = items[i]; - } + $.Method({ Static: false, Public: true }, "ToArray", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [T]), [], []), + function () { + var result = JSIL.Array.New(this.T, this._size); - return result; + for (var i = 0, l = this._size, items = this._items; i < l; i++) { + result[i] = items[i]; } - ); - $.Method({ Static: false, Public: true }, "TrueForAll", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), - function (predicate) { - for (var i = 0; i < this._size; i++) { - var item = this._items[i]; + return result; + } + ); - if (!predicate(item)) - return false; - } + $.Method({ Static: false, Public: true }, "TrueForAll", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), + function (predicate) { + for (var i = 0; i < this._size; i++) { + var item = this._items[i]; - return true; + if (!predicate(item)) + return false; } - ); - $.Method({ Static: false, Public: false, Virtual: true }, "ClearItems", - new JSIL.MethodSignature(null, [], []), - function ClearItems() { - // Necessary to clear any element values. - var oldLength = this._items.length; - this._items.length = 0; - this._items.length = oldLength; + return true; + } + ); - this._size = 0; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "ClearItems", + new JSIL.MethodSignature(null, [], []), + function ClearItems() { + // Necessary to clear any element values. + var oldLength = this._items.length; + this._items.length = 0; + this._items.length = oldLength; - $.Method({ Static: false, Public: false, Virtual: true }, "InsertItem", - new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), - function InsertItem(index, item) { - index = index | 0; - - if (index >= this._items.length) { - this._items.push(item); - } else if (index >= this._size) { - this._items[index] = item; - } else { - this._items.splice(index, 0, item); - } + this._size = 0; + } + ); - this._size += 1; + $.Method({ Static: false, Public: false, Virtual: true }, "InsertItem", + new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), + function InsertItem(index, item) { + index = index | 0; - if (this.$OnItemAdded) - this.$OnItemAdded(item); + if (index >= this._items.length) { + this._items.push(item); + } else if (index >= this._size) { + this._items[index] = item; + } else { + this._items.splice(index, 0, item); } - ); - $.Method({ Static: false, Public: false, Virtual: true }, "RemoveItem", - new JSIL.MethodSignature(null, [$.Int32], []), - function RemoveItem(index) { - this._items.splice(index, 1); - this._size -= 1; - } - ); + this._size += 1; + + if (this.$OnItemAdded) + this.$OnItemAdded(item); + } + ); + + $.Method({ Static: false, Public: false, Virtual: true }, "RemoveItem", + new JSIL.MethodSignature(null, [$.Int32], []), + function RemoveItem(index) { + this._items.splice(index, 1); + this._size -= 1; + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "SetItem", - new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), - function SetItem(index, item) { - this._items[index] = item; - } - ); + $.Method({ Static: false, Public: false, Virtual: true }, "SetItem", + new JSIL.MethodSignature(null, [$.Int32, new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")], []), + function SetItem(index, item) { + this._items[index] = item; + } + ); }; JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); - - $jsilcore.$ListExternals($, T, "List"); + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); - $.Method({ Static: false, Public: true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), - function (array, arrayindex) { - if (arrayindex != 0) { - JSIL.RuntimeError("List.CopyTo not supported for non-zero indexes"); - } + $jsilcore.$ListExternals($, T, "List"); - JSIL.Array.ShallowCopy(array, this._items); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T]), $.Int32], []), + function (array, arrayindex) { + if (arrayindex != 0) { + JSIL.RuntimeError("List.CopyTo not supported for non-zero indexes"); } - ); - $.Method({ Static: false, Public: true }, "get_IsReadOnly", - new JSIL.MethodSignature($.Boolean, [], []), - function () { - return false; - } - ); + JSIL.Array.ShallowCopy(array, this._items); + } + ); + + $.Method({ Static: false, Public: true }, "get_IsReadOnly", + new JSIL.MethodSignature($.Boolean, [], []), + function () { + return false; + } + ); }); $jsilcore.$ArrayListExternals = function ($) { - $jsilcore.$ListExternals($, $.Object, "ArrayList"); + $jsilcore.$ListExternals($, $.Object, "ArrayList"); - var mscorlib = JSIL.GetCorlib(); - var toArrayImpl = function () { - return Array.prototype.slice.call(this._items, 0, this._size); - }; + var mscorlib = JSIL.GetCorlib(); + var toArrayImpl = function () { + return Array.prototype.slice.call(this._items, 0, this._size); + }; - $.Method({ Static: false, Public: true }, "ToArray", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Array"), [$.Object], []), - toArrayImpl - ); + $.Method({ Static: false, Public: true }, "ToArray", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Array"), [$.Object], []), + toArrayImpl + ); }; // Lazy way of sharing method implementations between ArrayList, Collection and List. JSIL.ImplementExternals("System.Collections.ArrayList", $jsilcore.$ArrayListExternals); $jsilcore.$CollectionExternals = function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1"); - $jsilcore.$ListExternals($, T, "List"); + var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1"); + $jsilcore.$ListExternals($, T, "List"); - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), - function (list) { - this._items = JSIL.EnumerableToArray(list); - this._capacity = this._size = this._items.length; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), + function (list) { + this._items = JSIL.EnumerableToArray(list); + this._capacity = this._size = this._items.length; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")]), $.Int32], []), - function CopyTo(array, index) { - JSIL.Array.CopyTo(this._items, array, index); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.ObjectModel.Collection`1")]), $.Int32], []), + function CopyTo(array, index) { + JSIL.Array.CopyTo(this._items, array, index); + } + ); }; JSIL.ImplementExternals("System.Collections.ObjectModel.Collection`1", $jsilcore.$CollectionExternals); $jsilcore.$ReadOnlyCollectionExternals = function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.ReadOnlyCollection`1"); - $jsilcore.$ListExternals($, T, "ReadOnlyCollection"); + var T = new JSIL.GenericParameter("T", "System.Collections.ObjectModel.ReadOnlyCollection`1"); + $jsilcore.$ListExternals($, T, "ReadOnlyCollection"); - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var IListCtor = function (list) { - this._list = list; - - if (JSIL.IsArray(list._array)) { - Object.defineProperty(this, "_items", { - get: function () { - return list._array; - } - }); - - Object.defineProperty(this, "_size", { - get: function () { - return list._array.length; - } - }); - } else { - if (!list._items || (typeof (list._size) !== "number")) - JSIL.RuntimeError("argument must be a list"); - - Object.defineProperty(this, "_items", { - get: function () { - return list._items; - } - }); - - Object.defineProperty(this, "_size", { - get: function () { - return list._size; - } - }); + var IListCtor = function (list) { + this._list = list; + + if (JSIL.IsArray(list._array)) { + Object.defineProperty(this, "_items", { + get: function () { + return list._array; } - }; + }); - $.RawMethod(false, "$listCtor", IListCtor); + Object.defineProperty(this, "_size", { + get: function () { + return list._array.length; + } + }); + } else { + if (!list._items || (typeof (list._size) !== "number")) + JSIL.RuntimeError("argument must be a list"); - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), - IListCtor - ); + Object.defineProperty(this, "_items", { + get: function () { + return list._items; + } + }); + + Object.defineProperty(this, "_size", { + get: function () { + return list._size; + } + }); + } + }; + + $.RawMethod(false, "$listCtor", IListCtor); - $.SetValue("Add", null); - $.SetValue("Clear", null); - $.SetValue("Remove", null); - $.SetValue("RemoveAt", null); - $.SetValue("RemoveAll", null); - $.SetValue("Sort", null); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), + IListCtor + ); + + $.SetValue("Add", null); + $.SetValue("Clear", null); + $.SetValue("Remove", null); + $.SetValue("RemoveAt", null); + $.SetValue("RemoveAll", null); + $.SetValue("Sort", null); }; JSIL.ImplementExternals("System.Collections.ObjectModel.ReadOnlyCollection`1", $jsilcore.$ReadOnlyCollectionExternals); JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { - var system = JSIL.GetAssembly("System", true); + var system = JSIL.GetAssembly("System", true); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - $jsilcore.InitResizableArray(this, this.T, 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + $jsilcore.InitResizableArray(this, this.T, 16); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor(capacity) { - $jsilcore.InitResizableArray(this, this.T, capacity); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + $jsilcore.InitResizableArray(this, this.T, capacity); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear() { - this._items.length = this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._items.length = this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count() { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._size; + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), - function GetEnumerator() { - return this.$GetEnumerator(); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), + function GetEnumerator() { + return this.$GetEnumerator(); + } + ); - $.Method({ Static: false, Public: true }, "Peek", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), - function Peek() { - if (this._size <= 0) - throw new System.InvalidOperationException("Stack is empty"); + $.Method({ Static: false, Public: true }, "Peek", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + function Peek() { + if (this._size <= 0) + throw new System.InvalidOperationException("Stack is empty"); - return this._items[this._size - 1]; - } - ); + return this._items[this._size - 1]; + } + ); - $.Method({ Static: false, Public: true }, "Pop", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), - function Pop() { - var result = this._items.pop(); - this._size -= 1; + $.Method({ Static: false, Public: true }, "Pop", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + function Pop() { + var result = this._items.pop(); + this._size -= 1; - return result; - } - ); + return result; + } + ); - $.Method({ Static: false, Public: true }, "Push", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")], [])), - function Push(item) { - this._items.push(item) - this._size += 1; - } - ); + $.Method({ Static: false, Public: true }, "Push", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")], [])), + function Push(item) { + this._items.push(item) + this._size += 1; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.Queue`1", function ($) { - var system = JSIL.GetAssembly("System", true); + var system = JSIL.GetAssembly("System", true); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - $jsilcore.InitResizableArray(this, this.T, 16); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + $jsilcore.InitResizableArray(this, this.T, 16); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor(capacity) { - $jsilcore.InitResizableArray(this, this.T, capacity); - this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + $jsilcore.InitResizableArray(this, this.T, capacity); + this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear() { - this._items.length = this._size = 0; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._items.length = this._size = 0; + } + ); - $.Method({ Static: false, Public: true }, "Dequeue", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1"), [], [])), - function Dequeue() { - var result = this._items.shift(); - this._size -= 1; - return result; - } - ); + $.Method({ Static: false, Public: true }, "Dequeue", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1"), [], [])), + function Dequeue() { + var result = this._items.shift(); + this._size -= 1; + return result; + } + ); - $.Method({ Static: false, Public: true }, "Enqueue", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")], [])), - function Enqueue(item) { - this._items.push(item); - this._size += 1; - } - ); + $.Method({ Static: false, Public: true }, "Enqueue", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")], [])), + function Enqueue(item) { + this._items.push(item); + this._size += 1; + } + ); - $.Method({ Static: false, Public: true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count() { - return this._size; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._size; + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), - function GetEnumerator() { - return this.$GetEnumerator(); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), + function GetEnumerator() { + return this.$GetEnumerator(); + } + ); }); JSIL.MakeClass("System.Object", "System.Collections.ArrayList", true, [], function ($) { - $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - "System.Collections.IEnumerable" - ); + $.ImplementInterfaces( + "System.Collections.IEnumerable" + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.List`1", true, ["T"], function ($) { - $.Property({ Public: true, Static: false }, "Count"); - $.Property({ Public: false, Static: false }, "IsReadOnly"); - - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.IEnumerable"), - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), - $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), - $jsilcore.TypeRef("System.Collections.Generic.IList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]) - ); + $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: false, Static: false }, "IsReadOnly"); + + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.IEnumerable"), + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), + $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]), + $jsilcore.TypeRef("System.Collections.Generic.IList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1")]) + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.Stack`1", true, ["T"], function ($) { - $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), - "System.Collections.IEnumerable" - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), + "System.Collections.IEnumerable" +); }); // TODO: This type is actually a struct in the CLR JSIL.MakeClass($jsilcore.TypeRef("JSIL.ArrayEnumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]), "System.Collections.Generic.List`1/Enumerator", true, ["T"], function ($) { - $.Field({ Public: false, Static: false }, "_array", Array, function ($) { return null; }); - $.Field({ Public: false, Static: false }, "_length", Number, function ($) { return 0; }); - $.Field({ Public: false, Static: false }, "_index", Number, function ($) { return -1; }); - - $.Method({ Public: true, Static: false }, ".ctor", - new JSIL.MethodSignature(null, ["System.Collections.Generic.List`1"]), - function (list) { - this._array = list._items; - this._length = list._size; - } - ); + $.Field({ Public: false, Static: false }, "_array", Array, function ($) { return null; }); + $.Field({ Public: false, Static: false }, "_length", Number, function ($) { return 0; }); + $.Field({ Public: false, Static: false }, "_index", Number, function ($) { return -1; }); + + $.Method({ Public: true, Static: false }, ".ctor", + new JSIL.MethodSignature(null, ["System.Collections.Generic.List`1"]), + function (list) { + this._array = list._items; + this._length = list._size; + } + ); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]) - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.List`1/Enumerator")]) + ); }); JSIL.ImplementExternals( "System.Threading.Interlocked", function ($) { - var cmpxchg = function (targetRef, value, comparand) { - var currentValue = targetRef.get(); + var cmpxchg = function (targetRef, value, comparand) { + var currentValue = targetRef.get(); - if (currentValue === comparand) - targetRef.set(value); + if (currentValue === comparand) + targetRef.set(value); - return currentValue; - }; + return currentValue; + }; - $.Method({ Public: true, Static: true }, "CompareExchange", - new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]), - function (T, targetRef, value, comparand) { - return cmpxchg(targetRef, value, comparand); - } - ); + $.Method({ Public: true, Static: true }, "CompareExchange", + new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]), + function (T, targetRef, value, comparand) { + return cmpxchg(targetRef, value, comparand); + } + ); - $.Method({ Static: true, Public: true }, "CompareExchange", - (new JSIL.MethodSignature($.Int32, [ - $jsilcore.TypeRef("JSIL.Reference", [$.Int32]), $.Int32, - $.Int32 - ], [])), - function CompareExchange(/* ref */ location1, value, comparand) { - return cmpxchg(location1, value, comparand); - } - ); + $.Method({ Static: true, Public: true }, "CompareExchange", + (new JSIL.MethodSignature($.Int32, [ + $jsilcore.TypeRef("JSIL.Reference", [$.Int32]), $.Int32, + $.Int32 + ], [])), + function CompareExchange(/* ref */ location1, value, comparand) { + return cmpxchg(location1, value, comparand); + } + ); } ); JSIL.ImplementExternals("System.Threading.Monitor", function ($) { - var enterImpl = function (obj) { - var current = (obj.__LockCount__ || 0); - if (current >= 1) - JSIL.Host.warning("Warning: lock recursion " + obj); + var enterImpl = function (obj) { + var current = (obj.__LockCount__ || 0); + if (current >= 1) + JSIL.Host.warning("Warning: lock recursion " + obj); - obj.__LockCount__ = current + 1; + obj.__LockCount__ = current + 1; - return true; - }; + return true; + }; - $.Method({ Static: true, Public: true }, "Enter", - (new JSIL.MethodSignature(null, [$.Object], [])), - function Enter(obj) { - enterImpl(obj); - } - ); + $.Method({ Static: true, Public: true }, "Enter", + (new JSIL.MethodSignature(null, [$.Object], [])), + function Enter(obj) { + enterImpl(obj); + } + ); - $.Method({ Static: true, Public: true }, "Enter", - (new JSIL.MethodSignature(null, [$.Object, $jsilcore.TypeRef("JSIL.Reference", [$.Boolean])], [])), - function Enter(obj, /* ref */ lockTaken) { - lockTaken.set(enterImpl(obj)); - } - ); + $.Method({ Static: true, Public: true }, "Enter", + (new JSIL.MethodSignature(null, [$.Object, $jsilcore.TypeRef("JSIL.Reference", [$.Boolean])], [])), + function Enter(obj, /* ref */ lockTaken) { + lockTaken.set(enterImpl(obj)); + } + ); - $.Method({ Static: true, Public: true }, "Exit", - (new JSIL.MethodSignature(null, [$.Object], [])), - function Exit(obj) { - var current = (obj.__LockCount__ || 0); - if (current <= 0) - JSIL.Host.warning("Warning: unlocking an object that is not locked " + obj); + $.Method({ Static: true, Public: true }, "Exit", + (new JSIL.MethodSignature(null, [$.Object], [])), + function Exit(obj) { + var current = (obj.__LockCount__ || 0); + if (current <= 0) + JSIL.Host.warning("Warning: unlocking an object that is not locked " + obj); - obj.__LockCount__ = current - 1; - } - ); + obj.__LockCount__ = current - 1; + } + ); }); JSIL.MakeStaticClass("System.Threading.Interlocked", true, [], function ($) { - $.ExternalMethod({ Public: true, Static: true }, "CompareExchange", - new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]) - ); + $.ExternalMethod({ Public: true, Static: true }, "CompareExchange", + new JSIL.MethodSignature("!!0", [JSIL.Reference.Of("!!0"), "!!0", "!!0"], ["T"]) + ); }); JSIL.MakeStaticClass("System.Threading.Monitor", true, []); JSIL.ImplementExternals("System.Random", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this.mt = new MersenneTwister(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.mt = new MersenneTwister(); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor(Seed) { - this.mt = new MersenneTwister(Seed); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(Seed) { + this.mt = new MersenneTwister(Seed); + } + ); - $.Method({ Static: false, Public: true }, "Next", - (new JSIL.MethodSignature($.Int32, [], [])), - function Next() { - var unsigned32 = this.mt.genrand_int32(); - return unsigned32 << 0; - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [], [])), + function Next() { + var unsigned32 = this.mt.genrand_int32(); + return unsigned32 << 0; + } + ); - $.Method({ Static: false, Public: true }, "Next", - (new JSIL.MethodSignature($.Int32, [$.Int32, $.Int32], [])), - function Next(minValue, maxValue) { - var real = this.mt.genrand_real1(); - return Math.floor(real * (maxValue - minValue)) + minValue; - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [$.Int32, $.Int32], [])), + function Next(minValue, maxValue) { + var real = this.mt.genrand_real1(); + return Math.floor(real * (maxValue - minValue)) + minValue; + } + ); - $.Method({ Static: false, Public: true }, "Next", - (new JSIL.MethodSignature($.Int32, [$.Int32], [])), - function Next(maxValue) { - var real = this.mt.genrand_real1(); - return Math.floor(real * maxValue); - } - ); + $.Method({ Static: false, Public: true }, "Next", + (new JSIL.MethodSignature($.Int32, [$.Int32], [])), + function Next(maxValue) { + var real = this.mt.genrand_real1(); + return Math.floor(real * maxValue); + } + ); - $.Method({ Static: false, Public: true }, "NextDouble", - (new JSIL.MethodSignature($.Double, [], [])), - function NextDouble() { - return this.mt.genrand_real1(); - } - ); + $.Method({ Static: false, Public: true }, "NextDouble", + (new JSIL.MethodSignature($.Double, [], [])), + function NextDouble() { + return this.mt.genrand_real1(); + } + ); }); JSIL.MakeClass("System.Object", "System.Random", true, [], function ($) { }); JSIL.$MathSign = function (value) { - if (value > 0) - return 1; - else if (value < 0) - return -1; - else - return 0; + if (value > 0) + return 1; + else if (value < 0) + return -1; + else + return 0; }; JSIL.ImplementExternals("System.Math", function ($) { - $.RawMethod(true, "Max", Math.max); - $.RawMethod(true, "Min", Math.min); - $.RawMethod(true, "Exp", Math.exp); - - $.Method({ Static: true, Public: true }, "Round", - (new JSIL.MethodSignature($.Double, [$.Double, $.Int32], [])), - function Round(value, digits) { - var multiplier = Math.pow(10, digits); - var result = Math.round(value * multiplier) / multiplier; - return result; - } - ); + $.RawMethod(true, "Max", Math.max); + $.RawMethod(true, "Min", Math.min); + $.RawMethod(true, "Exp", Math.exp); + + $.Method({ Static: true, Public: true }, "Round", + (new JSIL.MethodSignature($.Double, [$.Double, $.Int32], [])), + function Round(value, digits) { + var multiplier = Math.pow(10, digits); + var result = Math.round(value * multiplier) / multiplier; + return result; + } + ); - $.Method({ Static: true, Public: true }, "Atan2", - (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), - Math.atan2 - ); + $.Method({ Static: true, Public: true }, "Atan2", + (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), + Math.atan2 + ); - $.Method({ Static: true, Public: true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.SByte], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.SByte], [])), + JSIL.$MathSign + ); - $.Method({ Static: true, Public: true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Int16], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Int16], [])), + JSIL.$MathSign + ); - $.Method({ Static: true, Public: true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Int32], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Int32], [])), + JSIL.$MathSign + ); - $.Method({ Static: true, Public: true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Single], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Single], [])), + JSIL.$MathSign + ); - $.Method({ Static: true, Public: true }, "Sign", - (new JSIL.MethodSignature($.Int32, [$.Double], [])), - JSIL.$MathSign - ); + $.Method({ Static: true, Public: true }, "Sign", + (new JSIL.MethodSignature($.Int32, [$.Double], [])), + JSIL.$MathSign + ); - $.Method({ Static: true, Public: true }, "IEEERemainder", - (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), - function IEEERemainder(x, y) { - if (y === 0.0) - return NaN; + $.Method({ Static: true, Public: true }, "IEEERemainder", + (new JSIL.MethodSignature($.Double, [$.Double, $.Double], [])), + function IEEERemainder(x, y) { + if (y === 0.0) + return NaN; - var result = x - y * Math.round(x / y); - if (result !== 0.0) - return result; + var result = x - y * Math.round(x / y); + if (result !== 0.0) + return result; - if (x <= 0.0) - // FIXME: -0? - return 0; - else - return 0; - } - ); + if (x <= 0.0) + // FIXME: -0? + return 0; + else + return 0; + } + ); }); JSIL.MakeStaticClass("System.Math", true, [], function ($) { }); JSIL.MakeStruct("System.ValueType", "System.Decimal", true, [], function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - var ctorImpl = function (value) { - this.value = value.valueOf(); - }; + var ctorImpl = function (value) { + this.value = value.valueOf(); + }; - var decimalToNumber = function (decimal) { - return decimal.valueOf(); - }; + var decimalToNumber = function (decimal) { + return decimal.valueOf(); + }; - var numberToDecimal = function (value) { - var result = JSIL.CreateInstanceOfType($.Type, null); - result.value = value.valueOf(); - return result; - }; + var numberToDecimal = function (value) { + var result = JSIL.CreateInstanceOfType($.Type, null); + result.value = value.valueOf(); + return result; + }; - $.RawMethod(false, "valueOf", function () { - return this.value; - }); + $.RawMethod(false, "valueOf", function () { + return this.value; + }); - $.Method({ Static: false, Public: true }, "toString", - new JSIL.MethodSignature("System.String", []), - function (format) { - return this.value.toString(); - } - ); + $.Method({ Static: false, Public: true }, "toString", + new JSIL.MethodSignature("System.String", []), + function (format) { + return this.value.toString(); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32")], [])), + ctorImpl + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt32")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt32")], [])), + ctorImpl + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int64")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int64")], [])), + ctorImpl + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt64")], [])), - ctorImpl - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.UInt64")], [])), + ctorImpl + ); - $.Method({ Static: true, Public: true }, "op_Equality", - (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), - function (lhs, rhs) { - return decimalToNumber(lhs) === decimalToNumber(rhs); - } - ); + $.Method({ Static: true, Public: true }, "op_Equality", + (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), + function (lhs, rhs) { + return decimalToNumber(lhs) === decimalToNumber(rhs); + } + ); - $.Method({ Static: true, Public: true }, "op_Inequality", - (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), - function (lhs, rhs) { - return decimalToNumber(lhs) !== decimalToNumber(rhs); - } - ); + $.Method({ Static: true, Public: true }, "op_Inequality", + (new JSIL.MethodSignature($.Boolean, [$.Type, $.Type], [])), + function (lhs, rhs) { + return decimalToNumber(lhs) !== decimalToNumber(rhs); + } + ); - $.Method({ Static: true, Public: true }, "op_Addition", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) + decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Addition", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) + decimalToNumber(rhs)); + } + ); - $.Method({ Static: true, Public: true }, "op_Division", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) / decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Division", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) / decimalToNumber(rhs)); + } + ); - $.Method({ Static: true, Public: true }, "op_Multiply", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) * decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Multiply", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) * decimalToNumber(rhs)); + } + ); - $.Method({ Static: true, Public: true }, "op_Subtraction", - (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), - function (lhs, rhs) { - return numberToDecimal(decimalToNumber(lhs) - decimalToNumber(rhs)); - } - ); + $.Method({ Static: true, Public: true }, "op_Subtraction", + (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), + function (lhs, rhs) { + return numberToDecimal(decimalToNumber(lhs) - decimalToNumber(rhs)); + } + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Single")], [])), - numberToDecimal - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Single")], [])), + numberToDecimal + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Double")], [])), - numberToDecimal - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature($.Type, [mscorlib.TypeRef("System.Double")], [])), + numberToDecimal + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.SByte"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.SByte"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int16"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int16"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt16"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt16"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt32"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt32"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Int64"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt64"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.UInt64"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Single"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Single"), [$.Type], [])), + decimalToNumber + ); - $.Method({ Static: true, Public: true }, "op_Explicit", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Double"), [$.Type], [])), - decimalToNumber - ); + $.Method({ Static: true, Public: true }, "op_Explicit", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Double"), [$.Type], [])), + decimalToNumber + ); - $.Field({ Static: false, Public: false }, "value", mscorlib.TypeRef("System.Double"), function () { - return 0; - }); + $.Field({ Static: false, Public: false }, "value", mscorlib.TypeRef("System.Double"), function () { + return 0; + }); }); JSIL.ImplementExternals("System.Environment", function ($) { - $.Method({ Static: true, Public: true }, "GetFolderPath", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment/SpecialFolder")], [])), - function GetFolderPath(folder) { - // FIXME - return folder.name; - } - ); + $.Method({ Static: true, Public: true }, "GetFolderPath", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment/SpecialFolder")], [])), + function GetFolderPath(folder) { + // FIXME + return folder.name; + } + ); - $.Method({ Static: true, Public: true }, "get_NewLine", - (new JSIL.MethodSignature($.String, [], [])), - function get_NewLine() { - // FIXME: Maybe this should just be \n? - return "\r\n"; - } - ); + $.Method({ Static: true, Public: true }, "get_NewLine", + (new JSIL.MethodSignature($.String, [], [])), + function get_NewLine() { + // FIXME: Maybe this should just be \n? + return "\r\n"; + } + ); - $.Method({ Static: true, Public: true }, "get_TickCount", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_TickCount() { - return JSIL.Host.getTickCount() | 0; - } - ); + $.Method({ Static: true, Public: true }, "get_TickCount", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_TickCount() { + return JSIL.Host.getTickCount() | 0; + } + ); }); JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Environment", false, [], function ($) { - $.Property({ Static: true, Public: true }, "CurrentManagedThreadId", $.Int32); + $.Property({ Static: true, Public: true }, "CurrentManagedThreadId", $.Int32); - $.Property({ Static: true, Public: true }, "TickCount"); + $.Property({ Static: true, Public: true }, "TickCount"); }); $jsilcore.hashContainerBase = function ($) { - var mscorlib = JSIL.GetCorlib(); - - var BucketEntry = function (key, value) { - this.key = key; - this.value = value; - }; - - $.RawMethod(false, "$areEqual", function HashContainer_AreEqual(lhs, rhs) { - if (lhs === rhs) - return true; + var mscorlib = JSIL.GetCorlib(); - return JSIL.ObjectEquals(lhs, rhs); - }); + var BucketEntry = function (key, value) { + this.key = key; + this.value = value; + }; - $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket(key) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - return null; + $.RawMethod(false, "$areEqual", function HashContainer_AreEqual(lhs, rhs) { + if (lhs === rhs) + return true; - for (var i = 0, l = bucket.length; i < l; i++) { - var bucketEntry = bucket[i]; + return JSIL.ObjectEquals(lhs, rhs); + }); - if (this.$areEqual(bucketEntry.key, key)) - return bucketEntry; - } + $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket(key) { + if (key == null) + return null; + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + return null; - return null; - }); + for (var i = 0, l = bucket.length; i < l; i++) { + var bucketEntry = bucket[i]; - $.RawMethod(false, "$removeByKey", function HashContainer_Remove(key) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - return false; + if (this.$areEqual(bucketEntry.key, key)) + return bucketEntry; + } - for (var i = 0, l = bucket.length; i < l; i++) { - var bucketEntry = bucket[i]; + return null; + }); - if (this.$areEqual(bucketEntry.key, key)) { - bucket.splice(i, 1); - this._count -= 1; - return true; - } - } + $.RawMethod(false, "$removeByKey", function HashContainer_Remove(key) { + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + return false; - return false; - }); + for (var i = 0, l = bucket.length; i < l; i++) { + var bucketEntry = bucket[i]; - $.RawMethod(false, "$addToBucket", function HashContainer_Add(key, value) { - var hashCode = JSIL.ObjectHashCode(key); - var bucket = this._dict[hashCode]; - if (!bucket) - this._dict[hashCode] = bucket = []; + if (this.$areEqual(bucketEntry.key, key)) { + bucket.splice(i, 1); + this._count -= 1; + return true; + } + } - bucket.push(new BucketEntry(key, value)); - this._count += 1; - return value; - }); + return false; + }); + + $.RawMethod(false, "$addToBucket", function HashContainer_Add(key, value) { + var hashCode = JSIL.ObjectHashCode(key); + var bucket = this._dict[hashCode]; + if (!bucket) + this._dict[hashCode] = bucket = []; + + bucket.push(new BucketEntry(key, value)); + this._count += 1; + return value; + }); }; JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", $jsilcore.hashContainerBase); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); + + function initFields(self) { + self._dict = JSIL.CreateDictionaryObject(null); + self._count = 0; + self.tKeyCollection = null; + self.tValueCollection = null; + self.tKeyEnumerator = null; + self.tValueEnumerator = null; + self.tEnumerator = null; + }; + + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + initFields(this); + } + ); - function initFields(self) { - self._dict = JSIL.CreateDictionaryObject(null); - self._count = 0; - self.tKeyCollection = null; - self.tValueCollection = null; - self.tKeyEnumerator = null; - self.tValueEnumerator = null; - self.tEnumerator = null; - }; + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function _ctor(capacity) { + initFields(this); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - initFields(this); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IDictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), + function _ctor(dictionary) { + initFields(this); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Int32], [])), - function _ctor(capacity) { - initFields(this); - } - ); + var enumerator = JSIL.GetEnumerator(dictionary); + while (enumerator.MoveNext()) + this.Add(enumerator.Current.Key, enumerator.Current.Value); + enumerator.Dispose(); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IDictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), - function _ctor(dictionary) { - initFields(this); - - var enumerator = JSIL.GetEnumerator(dictionary); - while (enumerator.MoveNext()) - this.Add(enumerator.Current.Key, enumerator.Current.Value); - enumerator.Dispose(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")])], [])), + function _ctor(comparer) { + initFields(this); - $.Method({ Static: false, Public: true }, "Add", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function Add(key, value) { - var bucketEntry = this.$searchBucket(key); + // TODO: Use comparer in some way + } + ); - if (bucketEntry !== null) - throw new System.ArgumentException("Key already exists"); + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function Add(key, value) { + var bucketEntry = this.$searchBucket(key); - return this.$addToBucket(key, value); - } - ); + if (bucketEntry !== null) + throw new System.ArgumentException("Key already exists"); - $.Method({ Static: false, Public: true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear() { - this._dict = {} - this._count = 0; - } - ); + return this.$addToBucket(key, value); + } + ); - $.Method({ Static: false, Public: true }, "ContainsKey", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function ContainsKey(key) { - return this.$searchBucket(key) !== null; - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._dict = {} + this._count = 0; + } + ); - $.Method({ Static: false, Public: true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function Remove(key) { - return this.$removeByKey(key); - } - ); + $.Method({ Static: false, Public: true }, "ContainsKey", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function ContainsKey(key) { + return this.$searchBucket(key) !== null; + } + ); - $.Method({ Static: false, Public: true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count() { - return this._count; - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function Remove(key) { + return this.$removeByKey(key); + } + ); - $.Method({ Static: false, Public: true }, "get_Item", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2"), [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), - function get_Item(key) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) - return bucketEntry.value; - else - throw new System.Exception("Key not found"); - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; + } + ); - $.Method({ Static: false, Public: true }, "get_Keys", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Keys() { - if (this.tKeyCollection === null) { - this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; - this.tKeyEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; - } + $.Method({ Static: false, Public: true }, "get_Item", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2"), [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2")], [])), + function get_Item(key) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) + return bucketEntry.value; + else + throw new System.Exception("Key not found"); + } + ); - return JSIL.CreateInstanceOfType(this.tKeyCollection, [this]); + $.Method({ Static: false, Public: true }, "get_Keys", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Keys() { + if (this.tKeyCollection === null) { + this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; + this.tKeyEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; } - ); - $.Method({ Static: false, Public: true }, "get_Values", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Values() { - if (this.tValueCollection === null) { - this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; - this.tValueEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; - } + return JSIL.CreateInstanceOfType(this.tKeyCollection, [this]); + } + ); - return JSIL.CreateInstanceOfType(this.tValueCollection, [this]); + $.Method({ Static: false, Public: true }, "get_Values", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Values() { + if (this.tValueCollection === null) { + this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; + this.tValueEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; } - ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function GetEnumerator() { - if (this.tEnumerator === null) { - this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; - } + return JSIL.CreateInstanceOfType(this.tValueCollection, [this]); + } + ); - return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function GetEnumerator() { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; } - ); - $.Method({ Static: false, Public: true }, "set_Item", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function set_Item(key, value) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) - return bucketEntry.value = value; - else - return this.$addToBucket(key, value); - } - ); + return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + } + ); - $.Method({ Static: false, Public: true }, "TryGetValue", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), $jsilcore.TypeRef("JSIL.Reference", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), - function TryGetValue(key, value) { - var bucketEntry = this.$searchBucket(key); - if (bucketEntry !== null) { - value.set(bucketEntry.value); - return true; - } else { - value.set(JSIL.DefaultValue(this.TValue)); - } + $.Method({ Static: false, Public: true }, "set_Item", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function set_Item(key, value) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) + return bucketEntry.value = value; + else + return this.$addToBucket(key, value); + } + ); - return false; + $.Method({ Static: false, Public: true }, "TryGetValue", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), $jsilcore.TypeRef("JSIL.Reference", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])], [])), + function TryGetValue(key, value) { + var bucketEntry = this.$searchBucket(key); + if (bucketEntry !== null) { + value.set(bucketEntry.value); + return true; + } else { + value.set(JSIL.DefaultValue(this.TValue)); } - ); + + return false; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2")], [])), - function _ctor(key, value) { - this.key = key; - this.value = value; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2")], [])), + function _ctor(key, value) { + this.key = key; + this.value = value; + } + ); - $.Method({ Static: false, Public: true }, "get_Key", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), [], [])), - function get_Key() { - return this.key; - } - ); + $.Method({ Static: false, Public: true }, "get_Key", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.KeyValuePair`2"), [], [])), + function get_Key() { + return this.key; + } + ); - $.Method({ Static: false, Public: true }, "get_Value", - (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2"), [], [])), - function get_Value() { - return this.value; - } - ); + $.Method({ Static: false, Public: true }, "get_Value", + (new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.KeyValuePair`2"), [], [])), + function get_Value() { + return this.value; + } + ); - $.Method({ Static: false, Public: true }, "toString", - (new JSIL.MethodSignature($.String, [], [])), - function toString() { - return "[" + String(this.key) + ", " + String(this.value) + "]"; - } - ); + $.Method({ Static: false, Public: true }, "toString", + (new JSIL.MethodSignature($.String, [], [])), + function toString() { + return "[" + String(this.key) + ", " + String(this.value) + "]"; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", function ($interfaceBuilder) { - var $ = $interfaceBuilder; + var $ = $interfaceBuilder; - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), - function _ctor(dictionary) { - this.dictionary = dictionary; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count() { - return this.dictionary.get_Count(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this.dictionary.get_Count(); + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), - function GetEnumerator() { - return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), + function GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function System_Collections_IEnumerable_GetEnumerator() { - return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); - } - ) - .Overrides(3, "GetEnumerator"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function System_Collections_IEnumerable_GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + } + ) + .Overrides(3, "GetEnumerator"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection", function ($interfaceBuilder) { - var $ = $interfaceBuilder; + var $ = $interfaceBuilder; - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), - function _ctor(dictionary) { - this.dictionary = dictionary; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", - new JSIL.MethodSignature($.Int32, [], []), - function get_Count() { - return this.dictionary.get_Count(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Count", + new JSIL.MethodSignature($.Int32, [], []), + function get_Count() { + return this.dictionary.get_Count(); + } + ); - $.Method({ Static: false, Public: true }, "CopyTo", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), $asm20.TypeRef("System.Int32")], []), - function Dictionary_CopyTo(array, index) { - // TODO: Implement checks - var enumerator = JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this]); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), $jsilcore.TypeRef("System.Int32")], []), + function Dictionary_CopyTo(array, index) { + // TODO: Implement checks + var enumerator = JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); - while (enumerator.MoveNext()) { - array[index] = enumerator.get_Current(); - index++; - } + while (enumerator.MoveNext()) { + array[index] = enumerator.get_Current(); + index++; } - ); + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), - function GetEnumerator() { - return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")]), [], []), + function GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), - function System_Collections_IEnumerable_GetEnumerator() { - return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); - } - ) - .Overrides(3, "GetEnumerator"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerable.GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), [], []), + function System_Collections_IEnumerable_GetEnumerator() { + return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); + } + ) + .Overrides(3, "GetEnumerator"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; - - $.Method({ Static: false, Public: false }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), - function _ctor(dictionary) { - this.dictionary = dictionary; - this.kvpEnumerator = null; - this.System_Collections_IEnumerator_Reset(); - } - ); + var $ = $interfaceBuilder; + + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; + this.System_Collections_IEnumerator_Reset(); + } + ); - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__(source, target) { - target.dictionary = source.dictionary; - if (source.kvpEnumerator) - target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); - } - ); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + if (source.kvpEnumerator) + target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose() { - if (this.kvpEnumerator) - this.kvpEnumerator.Dispose(); + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + if (this.kvpEnumerator) + this.kvpEnumerator.Dispose(); - this.kvpEnumerator = null; - } - ); + this.kvpEnumerator = null; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), - function get_Current() { - return this.kvpEnumerator.get_Current().key; - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), + function get_Current() { + return this.kvpEnumerator.get_Current().key; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext() { - return this.kvpEnumerator.MoveNext(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + return this.kvpEnumerator.MoveNext(); + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current() { - return this.kvpEnumerator.get_Current().key; - } - ) - .Overrides(2, "get_Current"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.kvpEnumerator.get_Current().key; + } + ) + .Overrides(2, "get_Current"); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset() { - this.kvpEnumerator = this.dictionary.GetEnumerator(); - } - ) - .Overrides(2, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.kvpEnumerator = this.dictionary.GetEnumerator(); + } + ) + .Overrides(2, "Reset"); }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; - - $.Method({ Static: false, Public: false }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), - function _ctor(dictionary) { - this.dictionary = dictionary; - this.kvpEnumerator = null; - this.System_Collections_IEnumerator_Reset(); - } - ); - - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__(source, target) { - target.dictionary = source.dictionary; - if (source.kvpEnumerator) - target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); - } - ); + var $ = $interfaceBuilder; + + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + this.kvpEnumerator = null; + this.System_Collections_IEnumerator_Reset(); + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose() { - if (this.kvpEnumerator) - this.kvpEnumerator.Dispose(); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + if (source.kvpEnumerator) + target.kvpEnumerator = source.kvpEnumerator.MemberwiseClone(); + } + ); - this.kvpEnumerator = null; - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + if (this.kvpEnumerator) + this.kvpEnumerator.Dispose(); - $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), - function get_Current() { - return this.kvpEnumerator.get_Current().value; - } - ); + this.kvpEnumerator = null; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext() { - return this.kvpEnumerator.MoveNext(); - } - ); + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), + function get_Current() { + return this.kvpEnumerator.get_Current().value; + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current() { - return this.kvpEnumerator.get_Current().value; - } - ) - .Overrides(2, "get_Current"); + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + return this.kvpEnumerator.MoveNext(); + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset() { - this.kvpEnumerator = this.dictionary.GetEnumerator(); - } - ) - .Overrides(2, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.kvpEnumerator.get_Current().value; + } + ) + .Overrides(2, "get_Current"); + + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.kvpEnumerator = this.dictionary.GetEnumerator(); + } + ) + .Overrides(2, "Reset"); }); JSIL.MakeStruct("System.ValueType", "System.Collections.Generic.KeyValuePair`2", true, ["TKey", "TValue"], function ($) { - $.Field({ Static: false, Public: false }, "key", $.GenericParameter("TKey")); + $.Field({ Static: false, Public: false }, "key", $.GenericParameter("TKey")); - $.Field({ Static: false, Public: false }, "value", $.GenericParameter("TValue")); + $.Field({ Static: false, Public: false }, "value", $.GenericParameter("TValue")); - $.Property({ Static: false, Public: true }, "Key"); + $.Property({ Static: false, Public: true }, "Key"); - $.Property({ Static: false, Public: true }, "Value"); + $.Property({ Static: false, Public: true }, "Value"); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, ["TKey", "TValue"], function ($) { - $.Property({ Public: true, Static: false }, "Count"); - $.Property({ Public: true, Static: false }, "Keys"); - $.Property({ Public: true, Static: false }, "Values"); + $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: true, Static: false }, "Keys"); + $.Property({ Public: true, Static: false }, "Values"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), - $jsilcore.TypeRef("System.Collections.IEnumerable") - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")])]), + $jsilcore.TypeRef("System.Collections.IEnumerable") + ); }); JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2+Enumerator", false, ["TKey", "TValue"], function ($) { - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), - /* 1 */ $jsilcore.TypeRef("System.IDisposable"), - /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), - /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") - ); + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), + /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") + ); }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, }, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, }, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, }, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, }, function ($) { }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", function ($interfaceBuilder) { - var $ = $interfaceBuilder; - - $.RawMethod(false, "__CopyMembers__", - function __CopyMembers__(source, target) { - target.dictionary = source.dictionary; - target.state = source.state; - } - ); - - $.Method({ Static: false, Public: false }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), - function _ctor(dictionary) { - this.dictionary = dictionary; - - var tKey = dictionary.TKey, tValue = dictionary.TValue; - var tKvp = System.Collections.Generic.KeyValuePair$b2.Of(tKey, tValue).__Type__; - - this.state = { - tKey: tKey, - tValue: tValue, - tKvp: tKvp, - bucketIndex: 0, - valueIndex: -1, - keys: Object.keys(dictionary._dict), - current: JSIL.CreateInstanceOfType(tKvp, "_ctor", [JSIL.DefaultValue(tKey), JSIL.DefaultValue(tValue)]) - }; - } - ); + var $ = $interfaceBuilder; - $.Method({ Static: false, Public: false }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), - function _ctor(dictionary, getEnumeratorRetType) { - throw new Error('Not implemented'); - } - ); + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.dictionary = source.dictionary; + target.state = source.state; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", - new JSIL.MethodSignature(null, [], []), - function Dispose() { - this.state = null; - this.dictionary = null; - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), + function _ctor(dictionary) { + this.dictionary = dictionary; + + var tKey = dictionary.TKey, tValue = dictionary.TValue; + var tKvp = System.Collections.Generic.KeyValuePair$b2.Of(tKey, tValue).__Type__; + + this.state = { + tKey: tKey, + tValue: tValue, + tKvp: tKvp, + bucketIndex: 0, + valueIndex: -1, + keys: Object.keys(dictionary._dict), + current: JSIL.CreateInstanceOfType(tKvp, "_ctor", [JSIL.DefaultValue(tKey), JSIL.DefaultValue(tValue)]) + }; + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), - function get_Current() { - return this.state.current.MemberwiseClone(); - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), + function _ctor(dictionary, getEnumeratorRetType) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", - new JSIL.MethodSignature($.Boolean, [], []), - function MoveNext() { - var state = this.state; - var dict = this.dictionary._dict; - var keys = state.keys; - var valueIndex = ++(state.valueIndex); - var bucketIndex = state.bucketIndex; + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + new JSIL.MethodSignature(null, [], []), + function Dispose() { + this.state = null; + this.dictionary = null; + } + ); - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[state.bucketIndex]; - var bucket = dict[bucketKey]; - - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - var current = state.current; - current.key = bucket[valueIndex].key; - current.value = bucket[valueIndex].value; - return true; - } else { - bucketIndex = ++(state.bucketIndex); - valueIndex = 0; - } - } + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), + function get_Current() { + return this.state.current.MemberwiseClone(); + } + ); - return false; + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + var state = this.state; + var dict = this.dictionary._dict; + var keys = state.keys; + var valueIndex = ++(state.valueIndex); + var bucketIndex = state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + var current = state.current; + current.key = bucket[valueIndex].key; + current.value = bucket[valueIndex].value; + return true; + } else { + bucketIndex = ++(state.bucketIndex); + valueIndex = 0; + } } - ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", - new JSIL.MethodSignature($.Object, [], []), - function System_Collections_IEnumerator_get_Current() { - return this.state.current.MemberwiseClone(); - } - ) - .Overrides(3, "get_Current"); + return false; + } + ); - $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", - new JSIL.MethodSignature(null, [], []), - function System_Collections_IEnumerator_Reset() { - this.state.bucketIndex = 0; - this.state.valueIndex = -1; - } - ) - .Overrides(3, "Reset"); + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.get_Current", + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.state.current.MemberwiseClone(); + } + ) + .Overrides(3, "get_Current"); + + $.Method({ Static: false, Public: false, Virtual: true }, "System.Collections.IEnumerator.Reset", + new JSIL.MethodSignature(null, [], []), + function System_Collections_IEnumerator_Reset() { + this.state.bucketIndex = 0; + this.state.valueIndex = -1; + } + ) + .Overrides(3, "Reset"); }); $jsilcore.$tArrayEnumerator = null; JSIL.MakeArrayEnumerator = function (array, elementType) { - var tArrayEnumerator; + var tArrayEnumerator; - if (!elementType) { - if ($jsilcore.$tArrayEnumerator === null) - $jsilcore.$tArrayEnumerator = JSIL.ArrayEnumerator.Of(System.Object); + if (!elementType) { + if ($jsilcore.$tArrayEnumerator === null) + $jsilcore.$tArrayEnumerator = JSIL.ArrayEnumerator.Of(System.Object); - tArrayEnumerator = $jsilcore.$tArrayEnumerator; - } else { - tArrayEnumerator = JSIL.ArrayEnumerator.Of(elementType); - } + tArrayEnumerator = $jsilcore.$tArrayEnumerator; + } else { + tArrayEnumerator = JSIL.ArrayEnumerator.Of(elementType); + } - return new tArrayEnumerator(array, -1); + return new tArrayEnumerator(array, -1); }; JSIL.Dispose = function (disposable) { - if (typeof (disposable) === "undefined") - JSIL.RuntimeError("Disposable is undefined"); - else if (disposable === null) - return false; + if (typeof (disposable) === "undefined") + JSIL.RuntimeError("Disposable is undefined"); + else if (disposable === null) + return false; - var tIDisposable = $jsilcore.System.IDisposable; + var tIDisposable = $jsilcore.System.IDisposable; - if (tIDisposable.$Is(disposable)) - tIDisposable.Dispose.Call(disposable); - else if (typeof (disposable.Dispose) === "function") - disposable.Dispose(); - else - return false; + if (tIDisposable.$Is(disposable)) + tIDisposable.Dispose.Call(disposable); + else if (typeof (disposable.Dispose) === "function") + disposable.Dispose(); + else + return false; - return true; + return true; }; JSIL.GetEnumerator = function (enumerable, elementType, fallbackMethodInvoke) { - if ((typeof (enumerable) === "undefined") || (enumerable === null)) - JSIL.RuntimeError("Enumerable is null or undefined"); - - var tIEnumerable = $jsilcore.System.Collections.IEnumerable; - var tIEnumerable$b1 = null; - - if (!elementType) - elementType = $jsilcore.System.Object.__Type__; - else - tIEnumerable$b1 = $jsilcore.System.Collections.Generic.IEnumerable$b1.Of(elementType); - - var result = null; - if (JSIL.IsArray(enumerable)) - result = JSIL.MakeArrayEnumerator(enumerable, elementType); - else if (typeof (enumerable) === "string") - result = JSIL.MakeArrayEnumerator(enumerable, elementType); - else if ((fallbackMethodInvoke !== true) && tIEnumerable$b1 && tIEnumerable$b1.$Is(enumerable)) - result = tIEnumerable$b1.GetEnumerator.Call(enumerable); - else if ((fallbackMethodInvoke !== true) && tIEnumerable.$Is(enumerable)) - result = tIEnumerable.GetEnumerator.Call(enumerable); - else if ((fallbackMethodInvoke !== true) && (typeof (enumerable.GetEnumerator) === "function")) - // HACK: This is gross. - result = enumerable.GetEnumerator(); - else - JSIL.RuntimeError("Value is not enumerable"); - - if (!result) - JSIL.RuntimeError("Value's GetEnumerator method did not return an enumerable."); - - return result; + if ((typeof (enumerable) === "undefined") || (enumerable === null)) + JSIL.RuntimeError("Enumerable is null or undefined"); + + var tIEnumerable = $jsilcore.System.Collections.IEnumerable; + var tIEnumerable$b1 = null; + + if (!elementType) + elementType = $jsilcore.System.Object.__Type__; + else + tIEnumerable$b1 = $jsilcore.System.Collections.Generic.IEnumerable$b1.Of(elementType); + + var result = null; + if (JSIL.IsArray(enumerable)) + result = JSIL.MakeArrayEnumerator(enumerable, elementType); + else if (typeof (enumerable) === "string") + result = JSIL.MakeArrayEnumerator(enumerable, elementType); + else if ((fallbackMethodInvoke !== true) && tIEnumerable$b1 && tIEnumerable$b1.$Is(enumerable)) + result = tIEnumerable$b1.GetEnumerator.Call(enumerable); + else if ((fallbackMethodInvoke !== true) && tIEnumerable.$Is(enumerable)) + result = tIEnumerable.GetEnumerator.Call(enumerable); + else if ((fallbackMethodInvoke !== true) && (typeof (enumerable.GetEnumerator) === "function")) + // HACK: This is gross. + result = enumerable.GetEnumerator(); + else + JSIL.RuntimeError("Value is not enumerable"); + + if (!result) + JSIL.RuntimeError("Value's GetEnumerator method did not return an enumerable."); + + return result; }; JSIL.EnumerableToArray = function (enumerable) { - var e = JSIL.GetEnumerator(enumerable); - var result = []; + var e = JSIL.GetEnumerator(enumerable); + var result = []; - var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; - var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; + var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; + var getCurrent = $jsilcore.System.Collections.IEnumerator.get_Current; - try { - while (moveNext.Call(e)) - result.push(getCurrent.Call(e)); - } finally { - JSIL.Dispose(e); - } + try { + while (moveNext.Call(e)) + result.push(getCurrent.Call(e)); + } finally { + JSIL.Dispose(e); + } - return result; + return result; }; JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.AbstractEnumerator"); - - $.RawMethod(false, "__CopyMembers__", - function AbstractEnumerator_CopyMembers(source, target) { - target._getNextItem = source._getNextItem; - target._reset = source._reset; - target._dispose = source._dispose; - target._first = source._first; - target._needDispose = source._needDispose; - target._current = new JSIL.BoxedVariable(source._current.get()); - target._state = source._state; - } - ); - - $.Method({ Static: false, Public: true }, ".ctor", - new JSIL.MethodSignature(null, [JSIL.AnyType, JSIL.AnyType, JSIL.AnyType]), - function (getNextItem, reset, dispose) { - this._getNextItem = getNextItem; - this._reset = reset; - this._dispose = dispose; - this._first = true; - this._needDispose = false; - this._current = new JSIL.BoxedVariable(null); - } - ); + var T = new JSIL.GenericParameter("T", "JSIL.AbstractEnumerator"); + + $.RawMethod(false, "__CopyMembers__", + function AbstractEnumerator_CopyMembers(source, target) { + target._getNextItem = source._getNextItem; + target._reset = source._reset; + target._dispose = source._dispose; + target._first = source._first; + target._needDispose = source._needDispose; + target._current = new JSIL.BoxedVariable(source._current.get()); + target._state = source._state; + } + ); - $.Method({ Static: false, Public: true }, "Reset", - new JSIL.MethodSignature(null, []), - function () { - if (this._needDispose) - this._dispose(); + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [JSIL.AnyType, JSIL.AnyType, JSIL.AnyType]), + function (getNextItem, reset, dispose) { + this._getNextItem = getNextItem; + this._reset = reset; + this._dispose = dispose; + this._first = true; + this._needDispose = false; + this._current = new JSIL.BoxedVariable(null); + } + ); - this._first = false; - this._needDispose = true; - this._reset(); - } - ); + $.Method({ Static: false, Public: true }, "Reset", + new JSIL.MethodSignature(null, []), + function () { + if (this._needDispose) + this._dispose(); - $.Method({ Static: false, Public: true }, "MoveNext", - new JSIL.MethodSignature("System.Boolean", []), - function () { - if (this._first) { - this._reset(); - this._needDispose = true; - this._first = false; - } + this._first = false; + this._needDispose = true; + this._reset(); + } + ); - return this._getNextItem(this._current); + $.Method({ Static: false, Public: true }, "MoveNext", + new JSIL.MethodSignature("System.Boolean", []), + function () { + if (this._first) { + this._reset(); + this._needDispose = true; + this._first = false; } - ); - $.Method({ Static: false, Public: true }, "Dispose", - new JSIL.MethodSignature(null, []), - function () { - if (this._needDispose) - this._dispose(); + return this._getNextItem(this._current); + } + ); - this._needDispose = false; - } - ); + $.Method({ Static: false, Public: true }, "Dispose", + new JSIL.MethodSignature(null, []), + function () { + if (this._needDispose) + this._dispose(); - $.Method({ Static: false, Public: true }, "get_Current", - new JSIL.MethodSignature(T, []), - function () { - return this._current.get(); - } - ); + this._needDispose = false; + } + ); + + $.Method({ Static: false, Public: true }, "get_Current", + new JSIL.MethodSignature(T, []), + function () { + return this._current.get(); + } + ); - $.Property({ Static: false, Public: true, Virtual: true }, "Current"); + $.Property({ Static: false, Public: true, Virtual: true }, "Current"); - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerator"), - /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), - /* 2 */ $jsilcore.TypeRef("System.IDisposable") - ); + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerator"), + /* 1 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), + /* 2 */ $jsilcore.TypeRef("System.IDisposable") + ); }); JSIL.ImplementExternals("System.Nullable", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: true, Public: true }, "GetUnderlyingType", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Type"), [mscorlib.TypeRef("System.Type")], [])), - function GetUnderlyingType(nullableType) { - if (nullableType.__FullName__.indexOf("System.Nullable`1") !== 0) { - return null; - } else { - return nullableType.__PublicInterface__.T; - } + $.Method({ Static: true, Public: true }, "GetUnderlyingType", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Type"), [mscorlib.TypeRef("System.Type")], [])), + function GetUnderlyingType(nullableType) { + if (nullableType.__FullName__.indexOf("System.Nullable`1") !== 0) { + return null; + } else { + return nullableType.__PublicInterface__.T; } - ); + } + ); }); JSIL.MakeStaticClass("System.Nullable", true, [], function ($) { }); JSIL.ImplementExternals("System.Nullable`1", function ($) { - $.RawMethod(true, "CheckType", function (value) { - if (this.T.$Is(value)) - return true; + $.RawMethod(true, "CheckType", function (value) { + if (this.T.$Is(value)) + return true; - return false; - }); + return false; + }); }); JSIL.MakeStruct("System.ValueType", "System.Nullable`1", true, ["T"], function ($) { @@ -2883,252 +2894,252 @@ JSIL.ImplementExternals("System.Xml.Serialization.XmlSerializer", function ($) { }); JSIL.ImplementExternals("System.Diagnostics.StackTrace", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this.CaptureStackTrace(0, false, null, null); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.CaptureStackTrace(0, false, null, null); + } + ); - $.Method({ Static: false, Public: false }, "CaptureStackTrace", - (new JSIL.MethodSignature(null, [ - $.Int32, $.Boolean, - mscorlib.TypeRef("System.Threading.Thread"), mscorlib.TypeRef("System.Exception") - ], [])), - function CaptureStackTrace(iSkip, fNeedFileInfo, targetThread, e) { - // FIXME - this.frames = []; - } - ); + $.Method({ Static: false, Public: false }, "CaptureStackTrace", + (new JSIL.MethodSignature(null, [ + $.Int32, $.Boolean, + mscorlib.TypeRef("System.Threading.Thread"), mscorlib.TypeRef("System.Exception") + ], [])), + function CaptureStackTrace(iSkip, fNeedFileInfo, targetThread, e) { + // FIXME + this.frames = []; + } + ); - $.Method({ Static: false, Public: true }, "GetFrame", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), - function GetFrame(index) { - // FIXME - return new System.Diagnostics.StackFrame(); - } - ); + $.Method({ Static: false, Public: true }, "GetFrame", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), + function GetFrame(index) { + // FIXME + return new System.Diagnostics.StackFrame(); + } + ); }); JSIL.ImplementExternals("System.Diagnostics.StackFrame", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - // FIXME - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + // FIXME + } + ); - $.Method({ Static: false, Public: true }, "GetMethod", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Reflection.MethodBase"), [], [])), - function GetMethod() { - // FIXME - return new System.Reflection.MethodBase(); - } - ); + $.Method({ Static: false, Public: true }, "GetMethod", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Reflection.MethodBase"), [], [])), + function GetMethod() { + // FIXME + return new System.Reflection.MethodBase(); + } + ); }); JSIL.ImplementExternals( "System.Enum", function ($) { - $.RawMethod(true, "CheckType", - function (value) { - if (typeof (value) === "object") { - if ((value !== null) && (typeof (value.GetType) === "function")) - return value.GetType().IsEnum; - } - - return false; + $.RawMethod(true, "CheckType", + function (value) { + if (typeof (value) === "object") { + if ((value !== null) && (typeof (value.GetType) === "function")) + return value.GetType().IsEnum; } - ); - var internalTryParse; + return false; + } + ); - var internalTryParseFlags = function (TEnum, text, ignoreCase, result) { - var items = text.split(","); + var internalTryParse; - var resultValue = 0; - var temp = new JSIL.BoxedVariable(); + var internalTryParseFlags = function (TEnum, text, ignoreCase, result) { + var items = text.split(","); - var publicInterface = TEnum.__PublicInterface__; + var resultValue = 0; + var temp = new JSIL.BoxedVariable(); - for (var i = 0, l = items.length; i < l; i++) { - var item = items[i].trim(); - if (item.length === 0) - continue; + var publicInterface = TEnum.__PublicInterface__; - if (internalTryParse(TEnum, item, ignoreCase, temp)) { - resultValue = resultValue | temp.get(); - } else { - return false; - } - } + for (var i = 0, l = items.length; i < l; i++) { + var item = items[i].trim(); + if (item.length === 0) + continue; - var name = TEnum.__ValueToName__[resultValue]; + if (internalTryParse(TEnum, item, ignoreCase, temp)) { + resultValue = resultValue | temp.get(); + } else { + return false; + } + } - if (typeof (name) === "undefined") { - result.set(publicInterface.$MakeValue(resultValue, null)); - return true; - } else { - result.set(publicInterface[name]); - return true; - } - }; + var name = TEnum.__ValueToName__[resultValue]; - internalTryParse = function (TEnum, text, ignoreCase, result) { - // Detect and handle flags enums - var commaPos = text.indexOf(","); - if (commaPos >= 0) - return internalTryParseFlags(TEnum, text, ignoreCase, result); - - var num = parseInt(text, 10); - - var publicInterface = TEnum.__PublicInterface__; - - if (isNaN(num)) { - if (ignoreCase) { - var names = TEnum.__Names__; - for (var i = 0; i < names.length; i++) { - var isMatch = (names[i].toLowerCase() == text.toLowerCase()); - - if (isMatch) { - result.set(publicInterface[names[i]]); - break; - } - } - } else { - result.set(publicInterface[text]); - } - - return (typeof (result.get()) !== "undefined"); - } else { - var name = TEnum.__ValueToName__[num]; - - if (typeof (name) === "undefined") { - result.set(publicInterface.$MakeValue(num, null)); - return true; - } else { - result.set(publicInterface[name]); - return true; - } - } - }; + if (typeof (name) === "undefined") { + result.set(publicInterface.$MakeValue(resultValue, null)); + return true; + } else { + result.set(publicInterface[name]); + return true; + } + }; - var internalParse = function (enm, text, ignoreCase) { - var result = new JSIL.BoxedVariable(); - if (internalTryParse(enm, text, ignoreCase, result)) - return result.get(); + internalTryParse = function (TEnum, text, ignoreCase, result) { + // Detect and handle flags enums + var commaPos = text.indexOf(","); + if (commaPos >= 0) + return internalTryParseFlags(TEnum, text, ignoreCase, result); - throw new System.Exception("Failed to parse enum"); - }; + var num = parseInt(text, 10); - $.Method({ Static: true, Public: true }, "Parse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String")], []), - function (enm, text) { - return internalParse(enm, text, false); - } - ); + var publicInterface = TEnum.__PublicInterface__; - $.Method({ Static: true, Public: true }, "Parse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [ - $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String"), - $jsilcore.TypeRef("System.Boolean") - ], []), - internalParse - ); + if (isNaN(num)) { + if (ignoreCase) { + var names = TEnum.__Names__; + for (var i = 0; i < names.length; i++) { + var isMatch = (names[i].toLowerCase() == text.toLowerCase()); - $.Method({ Static: true, Public: true }, "TryParse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [$jsilcore.TypeRef("System.String"), "JSIL.Reference" /* !!0& */], ["TEnum"]), - function (TEnum, text, result) { - return internalTryParse(TEnum, text, result); + if (isMatch) { + result.set(publicInterface[names[i]]); + break; + } + } + } else { + result.set(publicInterface[text]); } - ); - $.Method({ Static: true, Public: true }, "TryParse", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [ - $jsilcore.TypeRef("System.String"), $jsilcore.TypeRef("System.Boolean"), - "JSIL.Reference" /* !!0& */ - ], ["TEnum"]), - internalTryParse - ); + return (typeof (result.get()) !== "undefined"); + } else { + var name = TEnum.__ValueToName__[num]; - $.Method({ Static: true, Public: true }, "GetNames", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$jsilcore.TypeRef("System.Type")], []), - function (enm) { - return enm.__Names__; + if (typeof (name) === "undefined") { + result.set(publicInterface.$MakeValue(num, null)); + return true; + } else { + result.set(publicInterface[name]); + return true; } - ); - - $.Method({ Static: true, Public: true }, "GetValues", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Array"), [$jsilcore.TypeRef("System.Type")], []), - function (enm) { - var names = enm.__Names__; - var publicInterface = enm.__PublicInterface__; - var result = new Array(names.length); - - for (var i = 0; i < result.length; i++) - result[i] = publicInterface[names[i]]; + } + }; - return result; - } - ); - } -); + var internalParse = function (enm, text, ignoreCase) { + var result = new JSIL.BoxedVariable(); + if (internalTryParse(enm, text, ignoreCase, result)) + return result.get(); -JSIL.ImplementExternals("System.Activator", function ($) { - var mscorlib = JSIL.GetCorlib(); + throw new System.Exception("Failed to parse enum"); + }; - $.Method({ Static: true, Public: true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type")], [])), - function CreateInstance(type) { - return JSIL.CreateInstanceOfType(type, []); + $.Method({ Static: true, Public: true }, "Parse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String")], []), + function (enm, text) { + return internalParse(enm, text, false); } ); - $.Method({ Static: true, Public: true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Array", [$.Object])], [])), - function CreateInstance(type, args) { - if (!args) - args = []; - - return JSIL.CreateInstanceOfType(type, args); - } + $.Method({ Static: true, Public: true }, "Parse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Object"), [ + $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.String"), + $jsilcore.TypeRef("System.Boolean") + ], []), + internalParse ); - $.Method({ Static: true, Public: true }, "CreateInstance", - (new JSIL.MethodSignature("!!0", [], ["T"])), - function CreateInstance(T) { - return JSIL.CreateInstanceOfType(T, []); + $.Method({ Static: true, Public: true }, "TryParse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [$jsilcore.TypeRef("System.String"), "JSIL.Reference" /* !!0& */], ["TEnum"]), + function (TEnum, text, result) { + return internalTryParse(TEnum, text, result); } ); - $.Method({ Static: true, Public: true }, "CreateInstance", - (new JSIL.MethodSignature("!!0", [mscorlib.TypeRef("System.Array", [$.Object])], ["T"])), - function CreateInstance(T, args) { - if (!args) - args = []; + $.Method({ Static: true, Public: true }, "TryParse", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [ + $jsilcore.TypeRef("System.String"), $jsilcore.TypeRef("System.Boolean"), + "JSIL.Reference" /* !!0& */ + ], ["TEnum"]), + internalTryParse + ); - return JSIL.CreateInstanceOfType(T, args); + $.Method({ Static: true, Public: true }, "GetNames", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.String]), [$jsilcore.TypeRef("System.Type")], []), + function (enm) { + return enm.__Names__; } ); - $.Method({ Static: true, Public: true }, "CreateInstance", - (new JSIL.MethodSignature($.Object, [ - $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.Reflection.BindingFlags"), - $jsilcore.TypeRef("System.Reflection.Binder"), $jsilcore.TypeRef("System.Array", [$.Object]), - $jsilcore.TypeRef("System.Globalization.CultureInfo") - ], [])), - function CreateInstance(type, bindingAttr, binder, args, culture) { - // FIXME - if (!args) - args = []; + $.Method({ Static: true, Public: true }, "GetValues", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array"), [$jsilcore.TypeRef("System.Type")], []), + function (enm) { + var names = enm.__Names__; + var publicInterface = enm.__PublicInterface__; + var result = new Array(names.length); + + for (var i = 0; i < result.length; i++) + result[i] = publicInterface[names[i]]; - return JSIL.CreateInstanceOfType(type, args); + return result; } ); + } +); + +JSIL.ImplementExternals("System.Activator", function ($) { + var mscorlib = JSIL.GetCorlib(); + + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type")], [])), + function CreateInstance(type) { + return JSIL.CreateInstanceOfType(type, []); + } + ); + + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Array", [$.Object])], [])), + function CreateInstance(type, args) { + if (!args) + args = []; + + return JSIL.CreateInstanceOfType(type, args); + } + ); + + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature("!!0", [], ["T"])), + function CreateInstance(T) { + return JSIL.CreateInstanceOfType(T, []); + } + ); + + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature("!!0", [mscorlib.TypeRef("System.Array", [$.Object])], ["T"])), + function CreateInstance(T, args) { + if (!args) + args = []; + + return JSIL.CreateInstanceOfType(T, args); + } + ); + + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [ + $jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.Reflection.BindingFlags"), + $jsilcore.TypeRef("System.Reflection.Binder"), $jsilcore.TypeRef("System.Array", [$.Object]), + $jsilcore.TypeRef("System.Globalization.CultureInfo") + ], [])), + function CreateInstance(type, bindingAttr, binder, args, culture) { + // FIXME + if (!args) + args = []; + + return JSIL.CreateInstanceOfType(type, args); + } + ); }); @@ -3136,105 +3147,105 @@ JSIL.MakeStaticClass("System.Activator", true, [], function ($) { }); JSIL.ImplementExternals("System.Diagnostics.Stopwatch", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this.Reset(); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.Reset(); + } + ); - $.Method({ Static: false, Public: true }, "get_Elapsed", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.TimeSpan"), [], [])), - function get_Elapsed() { - return System.TimeSpan.FromMilliseconds(this.get_ElapsedMilliseconds()); - } - ); + $.Method({ Static: false, Public: true }, "get_Elapsed", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.TimeSpan"), [], [])), + function get_Elapsed() { + return System.TimeSpan.FromMilliseconds(this.get_ElapsedMilliseconds()); + } + ); - $.Method({ Static: false, Public: true }, "get_ElapsedMilliseconds", - (new JSIL.MethodSignature($.Int64, [], [])), - function get_ElapsedMilliseconds() { - var result = this.elapsed; - if (this.isRunning) - result += JSIL.Host.getTickCount() - this.startedWhen; + $.Method({ Static: false, Public: true }, "get_ElapsedMilliseconds", + (new JSIL.MethodSignature($.Int64, [], [])), + function get_ElapsedMilliseconds() { + var result = this.elapsed; + if (this.isRunning) + result += JSIL.Host.getTickCount() - this.startedWhen; - return $jsilcore.System.Int64.FromNumber(result); - } - ); + return $jsilcore.System.Int64.FromNumber(result); + } + ); - $.Method({ Static: false, Public: true }, "get_ElapsedTicks", - (new JSIL.MethodSignature($.Int64, [], [])), - function get_ElapsedTicks() { - var result = this.elapsed; - if (this.isRunning) - result += JSIL.Host.getTickCount() - this.startedWhen; + $.Method({ Static: false, Public: true }, "get_ElapsedTicks", + (new JSIL.MethodSignature($.Int64, [], [])), + function get_ElapsedTicks() { + var result = this.elapsed; + if (this.isRunning) + result += JSIL.Host.getTickCount() - this.startedWhen; - result *= 10000; + result *= 10000; - return $jsilcore.System.Int64.FromNumber(result); - } - ); + return $jsilcore.System.Int64.FromNumber(result); + } + ); - $.Method({ Static: false, Public: true }, "get_IsRunning", - (new JSIL.MethodSignature($.Boolean, [], [])), - function get_IsRunning() { - return this.isRunning; - } - ); + $.Method({ Static: false, Public: true }, "get_IsRunning", + (new JSIL.MethodSignature($.Boolean, [], [])), + function get_IsRunning() { + return this.isRunning; + } + ); - $.Method({ Static: false, Public: true }, "Reset", - (new JSIL.MethodSignature(null, [], [])), - function Reset() { - this.elapsed = 0; - this.isRunning = false; - this.startedWhen = 0; - } - ); + $.Method({ Static: false, Public: true }, "Reset", + (new JSIL.MethodSignature(null, [], [])), + function Reset() { + this.elapsed = 0; + this.isRunning = false; + this.startedWhen = 0; + } + ); - $.Method({ Static: false, Public: true }, "Restart", - (new JSIL.MethodSignature(null, [], [])), - function Restart() { - this.elapsed = 0; - this.isRunning = true; - this.startedWhen = JSIL.Host.getTickCount(); - } - ); + $.Method({ Static: false, Public: true }, "Restart", + (new JSIL.MethodSignature(null, [], [])), + function Restart() { + this.elapsed = 0; + this.isRunning = true; + this.startedWhen = JSIL.Host.getTickCount(); + } + ); - $.Method({ Static: false, Public: true }, "Start", - (new JSIL.MethodSignature(null, [], [])), - function Start() { - if (!this.isRunning) { - this.startedWhen = JSIL.Host.getTickCount(); - this.isRunning = true; - } + $.Method({ Static: false, Public: true }, "Start", + (new JSIL.MethodSignature(null, [], [])), + function Start() { + if (!this.isRunning) { + this.startedWhen = JSIL.Host.getTickCount(); + this.isRunning = true; } - ); + } + ); - $.Method({ Static: true, Public: true }, "StartNew", - (new JSIL.MethodSignature($.Type, [], [])), - function StartNew() { - var result = new System.Diagnostics.Stopwatch(); - result.Start(); - return result; - } - ); + $.Method({ Static: true, Public: true }, "StartNew", + (new JSIL.MethodSignature($.Type, [], [])), + function StartNew() { + var result = new System.Diagnostics.Stopwatch(); + result.Start(); + return result; + } + ); - $.Method({ Static: false, Public: true }, "Stop", - (new JSIL.MethodSignature(null, [], [])), - function Stop() { - if (this.isRunning) { - this.isRunning = false; + $.Method({ Static: false, Public: true }, "Stop", + (new JSIL.MethodSignature(null, [], [])), + function Stop() { + if (this.isRunning) { + this.isRunning = false; - var now = JSIL.Host.getTickCount(); - var elapsed = now - this.startedWhen; + var now = JSIL.Host.getTickCount(); + var elapsed = now - this.startedWhen; - this.elapsed += elapsed; - if (this.elapsed < 0) - this.elapsed = 0; - } + this.elapsed += elapsed; + if (this.elapsed < 0) + this.elapsed = 0; } - ); + } + ); }); @@ -3242,720 +3253,720 @@ JSIL.MakeClass("System.Object", "System.Diagnostics.Stopwatch", true, [], functi }); JSIL.MakeStruct("System.ValueType", "System.EventArgs", true, [], function ($) { - $.Field({ Static: true, Public: true }, "Empty", $jsilcore.TypeRef("System.EventArgs"), function ($) { - return new System.EventArgs(); - }); + $.Field({ Static: true, Public: true }, "Empty", $jsilcore.TypeRef("System.EventArgs"), function ($) { + return new System.EventArgs(); + }); }); JSIL.ImplementExternals("System.Diagnostics.Debug", function ($) { - $.Method({ Static: true, Public: true }, "Assert", - (new JSIL.MethodSignature(null, [$.Boolean], [])), - function Assert(condition) { - if (!condition) - JSIL.Host.assertionFailed("Assertion Failed"); - } - ); + $.Method({ Static: true, Public: true }, "Assert", + (new JSIL.MethodSignature(null, [$.Boolean], [])), + function Assert(condition) { + if (!condition) + JSIL.Host.assertionFailed("Assertion Failed"); + } + ); - $.Method({ Static: true, Public: true }, "Assert", - (new JSIL.MethodSignature(null, [$.Boolean, $.String], [])), - function Assert(condition, message) { - if (!condition) - JSIL.Host.assertionFailed(message); - } - ); + $.Method({ Static: true, Public: true }, "Assert", + (new JSIL.MethodSignature(null, [$.Boolean, $.String], [])), + function Assert(condition, message) { + if (!condition) + JSIL.Host.assertionFailed(message); + } + ); }); JSIL.MakeEnum( "System.IO.FileMode", true, { - CreateNew: 1, - Create: 2, - Open: 3, - OpenOrCreate: 4, - Truncate: 5, - Append: 6 + CreateNew: 1, + Create: 2, + Open: 3, + OpenOrCreate: 4, + Truncate: 5, + Append: 6 }, false ); JSIL.ImplementExternals("System.GC", function ($) { - var getMemoryImpl = function () { - var svc = JSIL.Host.getService("window"); - return svc.getPerformanceUsedJSHeapSize(); - }; - - $.Method({ Static: true, Public: false }, "GetTotalMemory", - (new JSIL.MethodSignature($.Int64, [], [])), - function GetTotalMemory() { - return getMemoryImpl(); - } - ); + var getMemoryImpl = function () { + var svc = JSIL.Host.getService("window"); + return svc.getPerformanceUsedJSHeapSize(); + }; + + $.Method({ Static: true, Public: false }, "GetTotalMemory", + (new JSIL.MethodSignature($.Int64, [], [])), + function GetTotalMemory() { + return getMemoryImpl(); + } + ); - $.Method({ Static: true, Public: true }, "GetTotalMemory", - (new JSIL.MethodSignature($.Int64, [$.Boolean], [])), - function GetTotalMemory(forceFullCollection) { - // FIXME: forceFullCollection + $.Method({ Static: true, Public: true }, "GetTotalMemory", + (new JSIL.MethodSignature($.Int64, [$.Boolean], [])), + function GetTotalMemory(forceFullCollection) { + // FIXME: forceFullCollection - return getMemoryImpl(); - } - ); + return getMemoryImpl(); + } + ); - $.Method({ Static: true, Public: false }, "IsServerGC", - (new JSIL.MethodSignature($.Boolean, [], [])), - function IsServerGC() { - return false; - } - ); + $.Method({ Static: true, Public: false }, "IsServerGC", + (new JSIL.MethodSignature($.Boolean, [], [])), + function IsServerGC() { + return false; + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", $jsilcore.hashContainerBase); JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { - var mscorlib = JSIL.GetCorlib(); + var mscorlib = JSIL.GetCorlib(); + + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this._dict = {}; + this._count = 0; + this._comparer = null; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this._dict = {}; - this._count = 0; - this._comparer = null; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(comparer) { + this._dict = {}; + this._count = 0; + this._comparer = comparer; + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(comparer) { - this._dict = {}; - this._count = 0; - this._comparer = comparer; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection) { + this._dict = {}; + this._count = 0; + this._comparer = null; + this.$addRange(collection); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(collection) { - this._dict = {}; - this._count = 0; - this._comparer = null; - this.$addRange(collection); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection, comparer) { + this._dict = {}; + this._count = 0; + this._comparer = comparer; + this.$addRange(collection); + } + ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(collection, comparer) { - this._dict = {}; - this._count = 0; - this._comparer = comparer; - this.$addRange(collection); - } - ); + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Add(item) { + var bucketEntry = this.$searchBucket(item); - $.Method({ Static: false, Public: true }, "Add", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Add(item) { - var bucketEntry = this.$searchBucket(item); + if (bucketEntry !== null) + return false; - if (bucketEntry !== null) - return false; + this.$addToBucket(item, true); + return true; + } + ); - this.$addToBucket(item, true); - return true; - } - ); + $.RawMethod(false, "$addRange", function (enumerable) { + var values = JSIL.EnumerableToArray(enumerable); - $.RawMethod(false, "$addRange", function (enumerable) { - var values = JSIL.EnumerableToArray(enumerable); + for (var i = 0; i < values.length; i++) + this.Add(values[i]); + }); - for (var i = 0; i < values.length; i++) - this.Add(values[i]); - }); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._dict = {}; + this._count = 0; + } + ); - $.Method({ Static: false, Public: true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear() { - this._dict = {}; - this._count = 0; - } - ); + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Contains(item) { + return this.$searchBucket(item) !== null; + } + ); - $.Method({ Static: false, Public: true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Contains(item) { - return this.$searchBucket(item) !== null; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; + } + ); - $.Method({ Static: false, Public: true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count() { - return this._count; - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Remove(item) { + return this.$removeByKey(item); + } + ); - $.Method({ Static: false, Public: true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Remove(item) { - return this.$removeByKey(item); - } - ); + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), + function GetEnumerator() { + var dict = this._dict; - $.Method({ Static: false, Public: true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), - function GetEnumerator() { - var dict = this._dict; - - return new (JSIL.AbstractEnumerator.Of(this.T))( - function getNext(result) { - var keys = this._state.keys; - var valueIndex = ++(this._state.valueIndex); - var bucketIndex = this._state.bucketIndex; - - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[this._state.bucketIndex]; - var bucket = dict[bucketKey]; - - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - result.set(bucket[valueIndex].key); - return true; - } else { - bucketIndex = ++(this._state.bucketIndex); - valueIndex = 0; - } - } - - return false; - }, - function reset() { - this._state = { - current: JSIL.DefaultValue(this.T), - keys: Object.keys(dict), - bucketIndex: 0, - valueIndex: -1 - }; - }, - function dispose() { - this._state = null; + return new (JSIL.AbstractEnumerator.Of(this.T))( + function getNext(result) { + var keys = this._state.keys; + var valueIndex = ++(this._state.valueIndex); + var bucketIndex = this._state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[this._state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + result.set(bucket[valueIndex].key); + return true; + } else { + bucketIndex = ++(this._state.bucketIndex); + valueIndex = 0; } - ); - } - ); + } + + return false; + }, + function reset() { + this._state = { + current: JSIL.DefaultValue(this.T), + keys: Object.keys(dict), + bucketIndex: 0, + valueIndex: -1 + }; + }, + function dispose() { + this._state = null; + } + ); + } + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, ["T"], function ($) { - $.Property({ Public: true, Static: false }, "Count"); + $.Property({ Public: true, Static: false }, "Count"); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), - $jsilcore.TypeRef("System.Collections.IEnumerable") - // $jsilcore.TypeRef("System.Collections.Generic.ISet`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), - // $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), + $jsilcore.TypeRef("System.Collections.IEnumerable") +// $jsilcore.TypeRef("System.Collections.Generic.ISet`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), +// $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), + ); }); JSIL.MakeEnum( "System.Globalization.NumberStyles", true, { - None: 0, - AllowLeadingWhite: 1, - AllowTrailingWhite: 2, - AllowLeadingSign: 4, - Integer: 7, - AllowTrailingSign: 8, - AllowParentheses: 16, - AllowDecimalPoint: 32, - AllowThousands: 64, - Number: 111, - AllowExponent: 128, - Float: 167, - AllowCurrencySymbol: 256, - Currency: 383, - Any: 511, - AllowHexSpecifier: 512, - HexNumber: 515 + None: 0, + AllowLeadingWhite: 1, + AllowTrailingWhite: 2, + AllowLeadingSign: 4, + Integer: 7, + AllowTrailingSign: 8, + AllowParentheses: 16, + AllowDecimalPoint: 32, + AllowThousands: 64, + Number: 111, + AllowExponent: 128, + Float: 167, + AllowCurrencySymbol: 256, + Currency: 383, + Any: 511, + AllowHexSpecifier: 512, + HexNumber: 515 }, true ); JSIL.ImplementExternals("System.Convert", function ($) { - $.Method({ Static: true, Public: true }, "ChangeType", - (new JSIL.MethodSignature($.Object, [$.Object, $jsilcore.TypeRef("System.Type")], [])), - function ChangeType(value, conversionType) { - // FIXME: Actually compatible? - if (value && $jsilcore.System.IConvertible.$Is(value)) { - // FIXME: provider - return $jsilcore.System.IConvertible.ToType.Call(value, null, conversionType, null); - } else { - return conversionType.__PublicInterface__.$As(value); - } + $.Method({ Static: true, Public: true }, "ChangeType", + (new JSIL.MethodSignature($.Object, [$.Object, $jsilcore.TypeRef("System.Type")], [])), + function ChangeType(value, conversionType) { + // FIXME: Actually compatible? + if (value && $jsilcore.System.IConvertible.$Is(value)) { + // FIXME: provider + return $jsilcore.System.IConvertible.ToType.Call(value, null, conversionType, null); + } else { + return conversionType.__PublicInterface__.$As(value); } - ); - - var returnSame = function (value) { - return value; - }; - - var returnValueOf = function (value) { - return value.valueOf(); - }; + } + ); - var makeAdapter = function (adapter) { - if (!adapter) - JSIL.RuntimeError("No adapter provided"); + var returnSame = function (value) { + return value; + }; - return function (value) { - return adapter(value); - }; - }; + var returnValueOf = function (value) { + return value.valueOf(); + }; - var boolToInt = function (b) { - return b ? 1 : 0; - }; + var makeAdapter = function (adapter) { + if (!adapter) + JSIL.RuntimeError("No adapter provided"); - var boolToString = function (b) { - return b ? "True" : "False"; + return function (value) { + return adapter(value); }; + }; - var makeConvertMethods = function (typeName, to, from) { - // FIXME: We currently ignore the format provider argument - // FIXME: Range checks/clipping/saturation are not performed for the integer types - - var methodName = "To" + typeName; - - var descriptor = { Static: true, Public: true }; - var tFormatProvider = $jsilcore.TypeRef("System.IFormatProvider"); - - var toType = JSIL.ResolveTypeReference(to)[0]; - - var makeSignature = function (argType, formatProvider) { - if (formatProvider) - return new JSIL.MethodSignature(to, [argType, tFormatProvider], []); - else - return new JSIL.MethodSignature(to, [argType], []); - }; - - if (from.boolean) { - $.Method(descriptor, methodName, makeSignature($.Boolean), from.boolean); - - $.Method(descriptor, methodName, makeSignature($.Boolean, true), from.boolean); - } - - $.Method(descriptor, methodName, makeSignature($.SByte), from.int); - $.Method(descriptor, methodName, makeSignature($.Int16), from.int); - $.Method(descriptor, methodName, makeSignature($.Int32), from.int); - - $.Method(descriptor, methodName, makeSignature($.SByte, true), from.int); - $.Method(descriptor, methodName, makeSignature($.Int16, true), from.int); - $.Method(descriptor, methodName, makeSignature($.Int32, true), from.int); - - $.Method(descriptor, methodName, makeSignature($.Byte), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt16), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt32), from.uint); - - $.Method(descriptor, methodName, makeSignature($.Byte, true), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt16, true), from.uint); - $.Method(descriptor, methodName, makeSignature($.UInt32, true), from.uint); - - if (from.int64) { - $.Method(descriptor, methodName, makeSignature($.Int64), from.int64); - $.Method(descriptor, methodName, makeSignature($.Int64, true), from.int64); - } - - if (from.uint64) { - $.Method(descriptor, methodName, makeSignature($.UInt64), from.uint64); - $.Method(descriptor, methodName, makeSignature($.UInt64, true), from.uint64); - } - - if (from.float) { - $.Method(descriptor, methodName, makeSignature($.Single), from.float); - $.Method(descriptor, methodName, makeSignature($.Double), from.float); - - $.Method(descriptor, methodName, makeSignature($.Single, true), from.float); - $.Method(descriptor, methodName, makeSignature($.Double, true), from.float); - } - - if (from.string) { - $.Method(descriptor, methodName, makeSignature($.String), from.string); - - $.Method(descriptor, methodName, makeSignature($.String, true), from.string); - } + var boolToInt = function (b) { + return b ? 1 : 0; + }; - var fromObject = function Convert_FromObject(value) { - if (value === null) { - if (to === $.String) { - return $jsilcore.System.String.Empty; - } + var boolToString = function (b) { + return b ? "True" : "False"; + }; - return JSIL.DefaultValue(toType); - } + var makeConvertMethods = function (typeName, to, from) { + // FIXME: We currently ignore the format provider argument + // FIXME: Range checks/clipping/saturation are not performed for the integer types - if ($jsilcore.System.IConvertible.$Is(value)) { - var conversionMethod = $jsilcore.System.IConvertible["To" + typeName]; + var methodName = "To" + typeName; - if (conversionMethod) { - return conversionMethod.Call(value, null, null); - } - } + var descriptor = { Static: true, Public: true }; + var tFormatProvider = $jsilcore.TypeRef("System.IFormatProvider"); - if (to === $.String) { - return value.toString(); - } + var toType = JSIL.ResolveTypeReference(to)[0]; - if ($jsilcore.System.String.$Is(value)) - return from.string(value); - else if (from.int64 && $jsilcore.System.Int64.$Is(value)) - return from.int64(value); - else if (from.uint64 && $jsilcore.System.UInt64.$Is(value)) - return from.uint64(value); - else if ($jsilcore.System.Int32.$Is(value)) - return from.int(value); - else if ($jsilcore.System.UInt32.$Is(value)) - return from.uint(value); - else if ($jsilcore.System.Boolean.$Is(value)) - return from.boolean(value); - else if ($jsilcore.System.Double.$Is(value)) - return from.float(value); - else - throw new System.NotImplementedException( - "Conversion from type '" + JSIL.GetType(value) + "' to type '" + typeName + "' not implemented." - ); - }; - - $.Method(descriptor, methodName, makeSignature($.Object, false), fromObject); + var makeSignature = function (argType, formatProvider) { + if (formatProvider) + return new JSIL.MethodSignature(to, [argType, tFormatProvider], []); + else + return new JSIL.MethodSignature(to, [argType], []); }; - makeConvertMethods("Boolean", $.Boolean, { - boolean: returnSame, - uint: makeAdapter(Boolean), - int: makeAdapter(Boolean), - float: makeAdapter(Boolean), - int64: makeAdapter(Boolean), - uint64: makeAdapter(Boolean), - string: makeAdapter($jsilcore.$ParseBoolean) - }); - - makeConvertMethods("Byte", $.Byte, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + if (from.boolean) { + $.Method(descriptor, methodName, makeSignature($.Boolean), from.boolean); - makeConvertMethods("SByte", $.SByte, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + $.Method(descriptor, methodName, makeSignature($.Boolean, true), from.boolean); + } - makeConvertMethods("UInt16", $.UInt16, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + $.Method(descriptor, methodName, makeSignature($.SByte), from.int); + $.Method(descriptor, methodName, makeSignature($.Int16), from.int); + $.Method(descriptor, methodName, makeSignature($.Int32), from.int); - makeConvertMethods("Int16", $.Int16, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + $.Method(descriptor, methodName, makeSignature($.SByte, true), from.int); + $.Method(descriptor, methodName, makeSignature($.Int16, true), from.int); + $.Method(descriptor, methodName, makeSignature($.Int32, true), from.int); - makeConvertMethods("UInt32", $.UInt32, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + $.Method(descriptor, methodName, makeSignature($.Byte), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt16), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt32), from.uint); - makeConvertMethods("Int32", $.Int32, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseInt) - }); + $.Method(descriptor, methodName, makeSignature($.Byte, true), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt16, true), from.uint); + $.Method(descriptor, methodName, makeSignature($.UInt32, true), from.uint); - var boolToUInt64 = function (b) { - return $jsilcore.System.UInt64.FromInt32(b ? 1 : 0); - }; + if (from.int64) { + $.Method(descriptor, methodName, makeSignature($.Int64), from.int64); + $.Method(descriptor, methodName, makeSignature($.Int64, true), from.int64); + } - var intToUInt64 = function (i) { - return $jsilcore.System.UInt64.FromInt32(i); - }; + if (from.uint64) { + $.Method(descriptor, methodName, makeSignature($.UInt64), from.uint64); + $.Method(descriptor, methodName, makeSignature($.UInt64, true), from.uint64); + } - var uintToUInt64 = function (u) { - return $jsilcore.System.UInt64.FromUInt32(u); - }; + if (from.float) { + $.Method(descriptor, methodName, makeSignature($.Single), from.float); + $.Method(descriptor, methodName, makeSignature($.Double), from.float); - var parseUInt64 = function (text) { - return $jsilcore.System.UInt64.Parse(text); - }; + $.Method(descriptor, methodName, makeSignature($.Single, true), from.float); + $.Method(descriptor, methodName, makeSignature($.Double, true), from.float); + } - makeConvertMethods("UInt64", $.UInt64, { - boolean: boolToUInt64, - uint: uintToUInt64, - int: intToUInt64, - string: parseUInt64 - }); + if (from.string) { + $.Method(descriptor, methodName, makeSignature($.String), from.string); - var boolToInt64 = function (b) { - return $jsilcore.System.Int64.FromInt32(b ? 1 : 0); + $.Method(descriptor, methodName, makeSignature($.String, true), from.string); } - var intToInt64 = function (i) { - return $jsilcore.System.Int64.FromInt32(i); - }; + var fromObject = function Convert_FromObject(value) { + if (value === null) { + if (to === $.String) { + return $jsilcore.System.String.Empty; + } - var uintToInt64 = function (u) { - return $jsilcore.System.Int64.FromUInt32(u); - }; + return JSIL.DefaultValue(toType); + } - var parseInt64 = function (text) { - return $jsilcore.System.Int64.Parse(text); - }; + if ($jsilcore.System.IConvertible.$Is(value)) { + var conversionMethod = $jsilcore.System.IConvertible["To" + typeName]; - var intToChar = function (i) { - return String.fromCharCode(i | 0); - }; + if (conversionMethod) { + return conversionMethod.Call(value, null, null); + } + } - var valueOfToChar = function (obj) { - return String.fromCharCode(obj.valueOf() | 0); + if (to === $.String) { + return value.toString(); + } + + if ($jsilcore.System.String.$Is(value)) + return from.string(value); + else if (from.int64 && $jsilcore.System.Int64.$Is(value)) + return from.int64(value); + else if (from.uint64 && $jsilcore.System.UInt64.$Is(value)) + return from.uint64(value); + else if ($jsilcore.System.Int32.$Is(value)) + return from.int(value); + else if ($jsilcore.System.UInt32.$Is(value)) + return from.uint(value); + else if ($jsilcore.System.Boolean.$Is(value)) + return from.boolean(value); + else if ($jsilcore.System.Double.$Is(value)) + return from.float(value); + else + throw new System.NotImplementedException( + "Conversion from type '" + JSIL.GetType(value) + "' to type '" + typeName + "' not implemented." + ); }; - makeConvertMethods("Int64", $.Int64, { - boolean: boolToInt64, - uint: uintToInt64, - int: intToInt64, - string: parseInt64 - }); - - makeConvertMethods("Single", $.Single, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseFloat) - }); - - makeConvertMethods("Double", $.Double, { - boolean: boolToInt, - uint: returnSame, - int: returnSame, - float: returnSame, - int64: returnValueOf, - uint64: returnValueOf, - string: makeAdapter($jsilcore.$ParseFloat) - }); + $.Method(descriptor, methodName, makeSignature($.Object, false), fromObject); + }; + + makeConvertMethods("Boolean", $.Boolean, { + boolean: returnSame, + uint: makeAdapter(Boolean), + int: makeAdapter(Boolean), + float: makeAdapter(Boolean), + int64: makeAdapter(Boolean), + uint64: makeAdapter(Boolean), + string: makeAdapter($jsilcore.$ParseBoolean) + }); + + makeConvertMethods("Byte", $.Byte, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + makeConvertMethods("SByte", $.SByte, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + makeConvertMethods("UInt16", $.UInt16, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + makeConvertMethods("Int16", $.Int16, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + makeConvertMethods("UInt32", $.UInt32, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + makeConvertMethods("Int32", $.Int32, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseInt) + }); + + var boolToUInt64 = function (b) { + return $jsilcore.System.UInt64.FromInt32(b ? 1 : 0); + }; + + var intToUInt64 = function (i) { + return $jsilcore.System.UInt64.FromInt32(i); + }; + + var uintToUInt64 = function (u) { + return $jsilcore.System.UInt64.FromUInt32(u); + }; + + var parseUInt64 = function (text) { + return $jsilcore.System.UInt64.Parse(text); + }; + + makeConvertMethods("UInt64", $.UInt64, { + boolean: boolToUInt64, + uint: uintToUInt64, + int: intToUInt64, + string: parseUInt64 + }); + + var boolToInt64 = function (b) { + return $jsilcore.System.Int64.FromInt32(b ? 1 : 0); + } - makeConvertMethods("Char", $.Char, { - uint: intToChar, - int: intToChar, - int64: valueOfToChar, - uint64: valueOfToChar - }); + var intToInt64 = function (i) { + return $jsilcore.System.Int64.FromInt32(i); + }; + + var uintToInt64 = function (u) { + return $jsilcore.System.Int64.FromUInt32(u); + }; + + var parseInt64 = function (text) { + return $jsilcore.System.Int64.Parse(text); + }; + + var intToChar = function (i) { + return String.fromCharCode(i | 0); + }; + + var valueOfToChar = function (obj) { + return String.fromCharCode(obj.valueOf() | 0); + }; + + makeConvertMethods("Int64", $.Int64, { + boolean: boolToInt64, + uint: uintToInt64, + int: intToInt64, + string: parseInt64 + }); + + makeConvertMethods("Single", $.Single, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseFloat) + }); + + makeConvertMethods("Double", $.Double, { + boolean: boolToInt, + uint: returnSame, + int: returnSame, + float: returnSame, + int64: returnValueOf, + uint64: returnValueOf, + string: makeAdapter($jsilcore.$ParseFloat) + }); + + makeConvertMethods("Char", $.Char, { + uint: intToChar, + int: intToChar, + int64: valueOfToChar, + uint64: valueOfToChar + }); + + makeConvertMethods("String", $.String, { + boolean: boolToString, + uint: makeAdapter(String), + int: makeAdapter(String), + float: makeAdapter(String), + int64: makeAdapter(String), + uint64: makeAdapter(String), + string: returnSame + }); + + var base64IgnoredCodepoints = [ + 9, 10, 13, 32 + ]; + + var base64Table = [ + 'A', 'B', 'C', 'D', + 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', + 'Y', 'Z', + 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', + 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', + 'y', 'z', + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', + '+', '/' + ]; + + var base64CodeTable = new Array(base64Table.length); + for (var i = 0; i < base64Table.length; i++) + base64CodeTable[i] = base64Table[i].charCodeAt(0); + + var toBase64StringImpl = function ToBase64String(inArray, offset, length, options) { + if (options) + JSIL.RuntimeError("Base64FormattingOptions not implemented"); + + var reader = $jsilcore.makeByteReader(inArray, offset, length); + var result = ""; + var ch1 = 0, ch2 = 0, ch3 = 0, bits = 0, equalsCount = 0, sum = 0; + var mask1 = (1 << 24) - 1, mask2 = (1 << 18) - 1, mask3 = (1 << 12) - 1, mask4 = (1 << 6) - 1; + var shift1 = 18, shift2 = 12, shift3 = 6, shift4 = 0; + + while (true) { + ch1 = reader.read(); + ch2 = reader.read(); + ch3 = reader.read(); + + if (ch1 === false) + break; + if (ch2 === false) { + ch2 = 0; + equalsCount += 1; + } + if (ch3 === false) { + ch3 = 0; + equalsCount += 1; + } + + // Seems backwards, but is right! + sum = (ch1 << 16) | (ch2 << 8) | (ch3 << 0); + + bits = (sum & mask1) >> shift1; + result += base64Table[bits]; + bits = (sum & mask2) >> shift2; + result += base64Table[bits]; + + if (equalsCount < 2) { + bits = (sum & mask3) >> shift3; + result += base64Table[bits]; + } + + if (equalsCount === 2) { + result += "=="; + } else if (equalsCount === 1) { + result += "="; + } else { + bits = (sum & mask4) >> shift4; + result += base64Table[bits]; + } + } - makeConvertMethods("String", $.String, { - boolean: boolToString, - uint: makeAdapter(String), - int: makeAdapter(String), - float: makeAdapter(String), - int64: makeAdapter(String), - uint64: makeAdapter(String), - string: returnSame - }); + return result; + }; - var base64IgnoredCodepoints = [ - 9, 10, 13, 32 - ]; - - var base64Table = [ - 'A', 'B', 'C', 'D', - 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', - 'Y', 'Z', - 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', - 'y', 'z', - '0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', - '+', '/' - ]; - - var base64CodeTable = new Array(base64Table.length); - for (var i = 0; i < base64Table.length; i++) - base64CodeTable[i] = base64Table[i].charCodeAt(0); - - var toBase64StringImpl = function ToBase64String(inArray, offset, length, options) { - if (options) - JSIL.RuntimeError("Base64FormattingOptions not implemented"); - - var reader = $jsilcore.makeByteReader(inArray, offset, length); - var result = ""; - var ch1 = 0, ch2 = 0, ch3 = 0, bits = 0, equalsCount = 0, sum = 0; - var mask1 = (1 << 24) - 1, mask2 = (1 << 18) - 1, mask3 = (1 << 12) - 1, mask4 = (1 << 6) - 1; - var shift1 = 18, shift2 = 12, shift3 = 6, shift4 = 0; - - while (true) { - ch1 = reader.read(); - ch2 = reader.read(); - ch3 = reader.read(); - - if (ch1 === false) - break; - if (ch2 === false) { - ch2 = 0; - equalsCount += 1; - } - if (ch3 === false) { - ch3 = 0; - equalsCount += 1; - } + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), + function ToBase64String(inArray) { + return toBase64StringImpl(inArray, 0, inArray.length, 0); + } + ); - // Seems backwards, but is right! - sum = (ch1 << 16) | (ch2 << 8) | (ch3 << 0); + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $jsilcore.TypeRef("System.Base64FormattingOptions")], [])), + function ToBase64String(inArray, options) { + return toBase64StringImpl(inArray, 0, inArray.length, options); + } + ); - bits = (sum & mask1) >> shift1; - result += base64Table[bits]; - bits = (sum & mask2) >> shift2; - result += base64Table[bits]; + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32 + ], [])), + function ToBase64String(inArray, offset, length) { + return toBase64StringImpl(inArray, offset, length, 0); + } + ); - if (equalsCount < 2) { - bits = (sum & mask3) >> shift3; - result += base64Table[bits]; - } + $.Method({ Static: true, Public: true }, "ToBase64String", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32, $jsilcore.TypeRef("System.Base64FormattingOptions") + ], [])), + toBase64StringImpl + ); - if (equalsCount === 2) { - result += "=="; - } else if (equalsCount === 1) { - result += "="; - } else { - bits = (sum & mask4) >> shift4; - result += base64Table[bits]; - } - } + $.Method({ Static: true, Public: true }, "FromBase64String", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.String], [])), + function FromBase64String(s) { + var lengthErrorMessage = "Invalid length for a Base-64 char array."; + var contentErrorMessage = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."; + + var result = []; + var reader = $jsilcore.makeCharacterReader(s); + var sum = 0; + var ch0 = 0, ch1 = 0, ch2 = 0, ch3 = 0; + var index0 = -1, index1 = -1, index2 = -1, index3 = -1; + var equals = "=".charCodeAt(0); + + while (true) { + ch0 = reader.read(); + if (ch0 === false) + break; + if (base64IgnoredCodepoints.indexOf(ch0) >= 0) + continue; + + ch1 = reader.read(); + ch2 = reader.read(); + ch3 = reader.read(); + + if ((ch1 === false) || (ch2 === false) || (ch3 === false)) + throw new System.FormatException(lengthErrorMessage); + + index0 = base64CodeTable.indexOf(ch0); + index1 = base64CodeTable.indexOf(ch1); + index2 = base64CodeTable.indexOf(ch2); + index3 = base64CodeTable.indexOf(ch3); + + if ( + (index0 < 0) || (index0 > 63) || + (index1 < 0) || (index1 > 63) + ) + throw new System.FormatException(contentErrorMessage); - return result; - }; + sum = (index0 << 18) | (index1 << 12); - $.Method({ Static: true, Public: true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), - function ToBase64String(inArray) { - return toBase64StringImpl(inArray, 0, inArray.length, 0); - } - ); + if (index2 >= 0) + sum |= (index2 << 6); + else if (ch2 !== equals) + throw new System.FormatException(contentErrorMessage); - $.Method({ Static: true, Public: true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $jsilcore.TypeRef("System.Base64FormattingOptions")], [])), - function ToBase64String(inArray, options) { - return toBase64StringImpl(inArray, 0, inArray.length, options); - } - ); + if (index3 >= 0) + sum |= (index3 << 0); + else if (ch3 !== equals) + throw new System.FormatException(contentErrorMessage); - $.Method({ Static: true, Public: true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32 - ], [])), - function ToBase64String(inArray, offset, length) { - return toBase64StringImpl(inArray, offset, length, 0); + result.push((sum >> 16) & 0xFF); + if (index2 >= 0) + result.push((sum >> 8) & 0xFF); + if (index3 >= 0) + result.push(sum & 0xFF); } - ); - $.Method({ Static: true, Public: true }, "ToBase64String", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32, $jsilcore.TypeRef("System.Base64FormattingOptions") - ], [])), - toBase64StringImpl - ); - - $.Method({ Static: true, Public: true }, "FromBase64String", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.String], [])), - function FromBase64String(s) { - var lengthErrorMessage = "Invalid length for a Base-64 char array."; - var contentErrorMessage = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."; - - var result = []; - var reader = $jsilcore.makeCharacterReader(s); - var sum = 0; - var ch0 = 0, ch1 = 0, ch2 = 0, ch3 = 0; - var index0 = -1, index1 = -1, index2 = -1, index3 = -1; - var equals = "=".charCodeAt(0); - - while (true) { - ch0 = reader.read(); - if (ch0 === false) - break; - if (base64IgnoredCodepoints.indexOf(ch0) >= 0) - continue; - - ch1 = reader.read(); - ch2 = reader.read(); - ch3 = reader.read(); - - if ((ch1 === false) || (ch2 === false) || (ch3 === false)) - throw new System.FormatException(lengthErrorMessage); - - index0 = base64CodeTable.indexOf(ch0); - index1 = base64CodeTable.indexOf(ch1); - index2 = base64CodeTable.indexOf(ch2); - index3 = base64CodeTable.indexOf(ch3); - - if ( - (index0 < 0) || (index0 > 63) || - (index1 < 0) || (index1 > 63) - ) - throw new System.FormatException(contentErrorMessage); - - sum = (index0 << 18) | (index1 << 12); - - if (index2 >= 0) - sum |= (index2 << 6); - else if (ch2 !== equals) - throw new System.FormatException(contentErrorMessage); - - if (index3 >= 0) - sum |= (index3 << 0); - else if (ch3 !== equals) - throw new System.FormatException(contentErrorMessage); - - result.push((sum >> 16) & 0xFF); - if (index2 >= 0) - result.push((sum >> 8) & 0xFF); - if (index3 >= 0) - result.push(sum & 0xFF); - } - - return JSIL.Array.New($jsilcore.System.Byte, result); - } - ); + return JSIL.Array.New($jsilcore.System.Byte, result); + } + ); }); JSIL.MakeStaticClass("System.Convert", true, [], function ($) { @@ -3964,727 +3975,727 @@ JSIL.MakeStaticClass("System.Convert", true, [], function ($) { $jsilcore.SerializationScratchBuffers = null; $jsilcore.GetSerializationScratchBuffers = function () { - if (!$jsilcore.SerializationScratchBuffers) { - var uint8 = new Uint8Array(32); - var buffer = uint8.buffer; - - $jsilcore.SerializationScratchBuffers = { - uint8: uint8, - uint16: new Uint16Array(buffer), - uint32: new Uint32Array(buffer), - int8: new Int8Array(buffer), - int16: new Int16Array(buffer), - int32: new Int32Array(buffer), - float32: new Float32Array(buffer), - float64: new Float64Array(buffer), - slice: function (byteCount) { - byteCount = byteCount | 0; - - var result = new Uint8Array(byteCount); - for (var i = 0; i < byteCount; i++) - result[i] = this.uint8[i]; - - return result; - }, - fillFrom: function (bytes, offset, count) { - offset = offset | 0; - count = count | 0; - - for (var i = 0; i < count; i++) - this.uint8[i] = bytes[offset + i]; - } - }; - } + if (!$jsilcore.SerializationScratchBuffers) { + var uint8 = new Uint8Array(32); + var buffer = uint8.buffer; + + $jsilcore.SerializationScratchBuffers = { + uint8: uint8, + uint16: new Uint16Array(buffer), + uint32: new Uint32Array(buffer), + int8: new Int8Array(buffer), + int16: new Int16Array(buffer), + int32: new Int32Array(buffer), + float32: new Float32Array(buffer), + float64: new Float64Array(buffer), + slice: function (byteCount) { + byteCount = byteCount | 0; + + var result = new Uint8Array(byteCount); + for (var i = 0; i < byteCount; i++) + result[i] = this.uint8[i]; + + return result; + }, + fillFrom: function (bytes, offset, count) { + offset = offset | 0; + count = count | 0; + + for (var i = 0; i < count; i++) + this.uint8[i] = bytes[offset + i]; + } + }; + } - return $jsilcore.SerializationScratchBuffers; + return $jsilcore.SerializationScratchBuffers; }; $jsilcore.BytesFromBoolean = function (value) { - return [value ? 1 : 0]; + return [value ? 1 : 0]; }; $jsilcore.BytesFromSingle = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.float32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.float32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromDouble = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.float64[0] = value; - return bufs.slice(8); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.float64[0] = value; + return bufs.slice(8); }; $jsilcore.BytesFromInt16 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.int16[0] = value; - return bufs.slice(2); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.int16[0] = value; + return bufs.slice(2); }; $jsilcore.BytesFromInt32 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.int32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.int32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromInt64 = function (value) { - return [ - (value.a >> 0) & 0xFF, - (value.a >> 8) & 0xFF, - (value.a >> 16) & 0xFF, - (value.b >> 0) & 0xFF, - (value.b >> 8) & 0xFF, - (value.b >> 16) & 0xFF, - (value.c >> 0) & 0xFF, - (value.c >> 8) & 0xFF - ]; + return [ + (value.a >> 0) & 0xFF, + (value.a >> 8) & 0xFF, + (value.a >> 16) & 0xFF, + (value.b >> 0) & 0xFF, + (value.b >> 8) & 0xFF, + (value.b >> 16) & 0xFF, + (value.c >> 0) & 0xFF, + (value.c >> 8) & 0xFF + ]; }; // FIXME: Are these unsigned versions right? $jsilcore.BytesFromUInt16 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.uint16[0] = value; - return bufs.slice(2); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.uint16[0] = value; + return bufs.slice(2); }; $jsilcore.BytesFromUInt32 = function (value) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.uint32[0] = value; - return bufs.slice(4); + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.uint32[0] = value; + return bufs.slice(4); }; $jsilcore.BytesFromUInt64 = function (value) { - return [ - (value.a >>> 0) & 0xFF, - (value.a >>> 8) & 0xFF, - (value.a >>> 16) & 0xFF, - (value.b >>> 0) & 0xFF, - (value.b >>> 8) & 0xFF, - (value.b >>> 16) & 0xFF, - (value.c >>> 0) & 0xFF, - (value.c >>> 8) & 0xFF - ]; + return [ + (value.a >>> 0) & 0xFF, + (value.a >>> 8) & 0xFF, + (value.a >>> 16) & 0xFF, + (value.b >>> 0) & 0xFF, + (value.b >>> 8) & 0xFF, + (value.b >>> 16) & 0xFF, + (value.c >>> 0) & 0xFF, + (value.c >>> 8) & 0xFF + ]; }; $jsilcore.BytesToBoolean = function (bytes, offset) { - return bytes[offset] !== 0; + return bytes[offset] !== 0; }; $jsilcore.BytesToInt16 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 2); - return bufs.int16[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 2); + return bufs.int16[0]; }; $jsilcore.BytesToInt32 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.int32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.int32[0]; }; $jsilcore.BytesToInt64 = function (bytes, offset) { - return $jsilcore.System.Int64.FromBytes(bytes, offset); + return $jsilcore.System.Int64.FromBytes(bytes, offset); }; $jsilcore.BytesToUInt16 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 2); - return bufs.uint16[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 2); + return bufs.uint16[0]; }; $jsilcore.BytesToUInt32 = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.uint32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.uint32[0]; }; $jsilcore.BytesToUInt64 = function (bytes, offset) { - return $jsilcore.System.UInt64.FromBytes(bytes, offset); + return $jsilcore.System.UInt64.FromBytes(bytes, offset); }; $jsilcore.BytesToSingle = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 4); - return bufs.float32[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 4); + return bufs.float32[0]; }; $jsilcore.BytesToDouble = function (bytes, offset) { - var bufs = $jsilcore.GetSerializationScratchBuffers(); - bufs.fillFrom(bytes, offset, 8); - return bufs.float64[0]; + var bufs = $jsilcore.GetSerializationScratchBuffers(); + bufs.fillFrom(bytes, offset, 8); + return bufs.float64[0]; }; JSIL.ImplementExternals("System.BitConverter", function ($) { - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Boolean], [])), - $jsilcore.BytesFromBoolean - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Boolean], [])), + $jsilcore.BytesFromBoolean + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int16], [])), - $jsilcore.BytesFromInt16 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int16], [])), + $jsilcore.BytesFromInt16 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int32], [])), - $jsilcore.BytesFromInt32 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int32], [])), + $jsilcore.BytesFromInt32 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int64], [])), - $jsilcore.BytesFromInt64 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Int64], [])), + $jsilcore.BytesFromInt64 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt16], [])), - $jsilcore.BytesFromUInt16 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt16], [])), + $jsilcore.BytesFromUInt16 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt32], [])), - $jsilcore.BytesFromUInt32 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt32], [])), + $jsilcore.BytesFromUInt32 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt64], [])), - $jsilcore.BytesFromUInt64 - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.UInt64], [])), + $jsilcore.BytesFromUInt64 + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Single], [])), - $jsilcore.BytesFromSingle - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Single], [])), + $jsilcore.BytesFromSingle + ); - $.Method({ Static: true, Public: true }, "GetBytes", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Double], [])), - $jsilcore.BytesFromDouble - ); + $.Method({ Static: true, Public: true }, "GetBytes", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Byte]), [$.Double], [])), + $jsilcore.BytesFromDouble + ); - /* - - $.Method({Static:true , Public:false}, "GetHexValue", - (new JSIL.MethodSignature($.Char, [$.Int32], [])), - function GetHexValue (i) { - throw new Error('Not implemented'); - } - ); - - $.Method({Static:true , Public:true }, "Int64BitsToDouble", - (new JSIL.MethodSignature($.Double, [$.Int64], [])), - function Int64BitsToDouble (value) { - throw new Error('Not implemented'); - } - ); - - $.Method({Static:true , Public:true }, "ToChar", - (new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - function ToChar (value, startIndex) { - throw new Error('Not implemented'); - } - ); - - */ + /* - $.Method({ Static: true, Public: true }, "ToBoolean", - (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToBoolean - ); + $.Method({Static:true , Public:false}, "GetHexValue", + (new JSIL.MethodSignature($.Char, [$.Int32], [])), + function GetHexValue (i) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: true, Public: true }, "ToInt16", - (new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt16 - ); + $.Method({Static:true , Public:true }, "Int64BitsToDouble", + (new JSIL.MethodSignature($.Double, [$.Int64], [])), + function Int64BitsToDouble (value) { + throw new Error('Not implemented'); + } + ); + + $.Method({Static:true , Public:true }, "ToChar", + (new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + function ToChar (value, startIndex) { + throw new Error('Not implemented'); + } + ); + + */ + + $.Method({ Static: true, Public: true }, "ToBoolean", + (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToBoolean + ); + + $.Method({ Static: true, Public: true }, "ToInt16", + (new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt16 + ); + + $.Method({ Static: true, Public: true }, "ToInt32", + (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt32 + ); + + $.Method({ Static: true, Public: true }, "ToInt64", + (new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToInt64 + ); + + /* + + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [ + $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, + $.Int32 + ], [])), + function ToString (value, startIndex, length) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: true, Public: true }, "ToInt32", - (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt32 - ); + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), + function ToString (value) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: true, Public: true }, "ToInt64", - (new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToInt64 - ); + $.Method({Static:true , Public:true }, "ToString", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + function ToString (value, startIndex) { + throw new Error('Not implemented'); + } + ); - /* - - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [ - $jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32, - $.Int32 - ], [])), - function ToString (value, startIndex, length) { - throw new Error('Not implemented'); - } - ); - - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte])], [])), - function ToString (value) { - throw new Error('Not implemented'); - } - ); - - $.Method({Static:true , Public:true }, "ToString", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - function ToString (value, startIndex) { - throw new Error('Not implemented'); - } - ); - - */ + */ - $.Method({ Static: true, Public: true }, "ToUInt16", - (new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt16 - ); + $.Method({ Static: true, Public: true }, "ToUInt16", + (new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt16 + ); - $.Method({ Static: true, Public: true }, "ToUInt32", - (new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt32 - ); + $.Method({ Static: true, Public: true }, "ToUInt32", + (new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt32 + ); - $.Method({ Static: true, Public: true }, "ToUInt64", - (new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToUInt64 - ); + $.Method({ Static: true, Public: true }, "ToUInt64", + (new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToUInt64 + ); - $.Method({ Static: true, Public: true }, "ToSingle", - (new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToSingle - ); + $.Method({ Static: true, Public: true }, "ToSingle", + (new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToSingle + ); - $.Method({ Static: true, Public: true }, "ToDouble", - (new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), - $jsilcore.BytesToDouble - ); + $.Method({ Static: true, Public: true }, "ToDouble", + (new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.Array", [$.Byte]), $.Int32], [])), + $jsilcore.BytesToDouble + ); }); JSIL.MakeStaticClass("System.BitConverter", true, [], function ($) { }); JSIL.ParseDataURL = function (dataUrl) { - var colonIndex = dataUrl.indexOf(":"); - if ((colonIndex != 4) || (dataUrl.substr(0, 5) !== "data:")) - JSIL.RuntimeError("Invalid Data URL header"); + var colonIndex = dataUrl.indexOf(":"); + if ((colonIndex != 4) || (dataUrl.substr(0, 5) !== "data:")) + JSIL.RuntimeError("Invalid Data URL header"); - var semicolonIndex = dataUrl.indexOf(";"); - var mimeType = dataUrl.substr(colonIndex + 1, semicolonIndex - colonIndex - 1); + var semicolonIndex = dataUrl.indexOf(";"); + var mimeType = dataUrl.substr(colonIndex + 1, semicolonIndex - colonIndex - 1); - var commaIndex = dataUrl.indexOf(","); - if (commaIndex <= semicolonIndex) - JSIL.RuntimeError("Invalid Data URL header"); + var commaIndex = dataUrl.indexOf(","); + if (commaIndex <= semicolonIndex) + JSIL.RuntimeError("Invalid Data URL header"); - var encodingType = dataUrl.substr(semicolonIndex + 1, commaIndex - semicolonIndex - 1); - if (encodingType.toLowerCase() !== "base64") - JSIL.RuntimeError("Invalid Data URL encoding type: " + encodingType); + var encodingType = dataUrl.substr(semicolonIndex + 1, commaIndex - semicolonIndex - 1); + if (encodingType.toLowerCase() !== "base64") + JSIL.RuntimeError("Invalid Data URL encoding type: " + encodingType); - var base64 = dataUrl.substr(commaIndex + 1); - var bytes = System.Convert.FromBase64String(base64); + var base64 = dataUrl.substr(commaIndex + 1); + var bytes = System.Convert.FromBase64String(base64); - return [mimeType, bytes]; + return [mimeType, bytes]; }; JSIL.ImplementExternals("System.Collections.Generic.LinkedList`1", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [], [])), - function _ctor() { - this.Clear(); - } - ); - - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function _ctor(collection) { - this.Clear(); - - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor() { + this.Clear(); + } + ); - var makeNode = function (self, value) { - var tNode = System.Collections.Generic.LinkedListNode$b1.Of(self.T).__Type__; - return JSIL.CreateInstanceOfType(tNode, [self, value]); - }; + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function _ctor(collection) { + this.Clear(); - var addIntoEmptyImpl = function (self, node) { - if ((!self._head) && (!self._tail)) { - node._list = self; - self._head = self._tail = node; - self._count = 1; - return true; - } + throw new Error('Not implemented'); + } + ); - return false; + var makeNode = function (self, value) { + var tNode = System.Collections.Generic.LinkedListNode$b1.Of(self.T).__Type__; + return JSIL.CreateInstanceOfType(tNode, [self, value]); + }; + + var addIntoEmptyImpl = function (self, node) { + if ((!self._head) && (!self._tail)) { + node._list = self; + self._head = self._tail = node; + self._count = 1; + return true; } - var addBeforeImpl = function (self, beforeNode, node) { - if (addIntoEmptyImpl(self, node)) - return; + return false; + } - node._list = self; - node._next = beforeNode; + var addBeforeImpl = function (self, beforeNode, node) { + if (addIntoEmptyImpl(self, node)) + return; - if (beforeNode) - beforeNode._previous = node; + node._list = self; + node._next = beforeNode; - if (self._head === beforeNode) - self._head = node; + if (beforeNode) + beforeNode._previous = node; - self._count += 1; - }; + if (self._head === beforeNode) + self._head = node; - var addAfterImpl = function (self, afterNode, node) { - if (addIntoEmptyImpl(self, node)) - return; + self._count += 1; + }; - node._list = self; - node._previous = afterNode; + var addAfterImpl = function (self, afterNode, node) { + if (addIntoEmptyImpl(self, node)) + return; - if (afterNode) - afterNode._next = node; + node._list = self; + node._previous = afterNode; - if (self._tail === afterNode) - self._tail = node; + if (afterNode) + afterNode._next = node; - self._count += 1; - }; + if (self._tail === afterNode) + self._tail = node; - var addFirstImpl = function (self, node) { - addBeforeImpl(self, self._head, node); - }; + self._count += 1; + }; - var addLastImpl = function (self, node) { - addAfterImpl(self, self._tail, node); - }; + var addFirstImpl = function (self, node) { + addBeforeImpl(self, self._head, node); + }; - $.Method({ Static: false, Public: true }, "AddAfter", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddAfter(node, value) { - var newNode = makeNode(self, value); - addAfterImpl(this, node, newNode); - return newNode; - } - ); + var addLastImpl = function (self, node) { + addAfterImpl(self, self._tail, node); + }; - $.Method({ Static: false, Public: true }, "AddAfter", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddAfter(node, newNode) { - addAfterImpl(this, node, newNode); - } - ); + $.Method({ Static: false, Public: true }, "AddAfter", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddAfter(node, value) { + var newNode = makeNode(self, value); + addAfterImpl(this, node, newNode); + return newNode; + } + ); - $.Method({ Static: false, Public: true }, "AddBefore", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddBefore(node, value) { - var newNode = makeNode(self, value); - addBeforeImpl(this, node, newNode); - return newNode; - } - ); + $.Method({ Static: false, Public: true }, "AddAfter", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddAfter(node, newNode) { + addAfterImpl(this, node, newNode); + } + ); - $.Method({ Static: false, Public: true }, "AddBefore", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddBefore(node, newNode) { - addBeforeImpl(this, node, newNode); - } - ); + $.Method({ Static: false, Public: true }, "AddBefore", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddBefore(node, value) { + var newNode = makeNode(self, value); + addBeforeImpl(this, node, newNode); + return newNode; + } + ); - $.Method({ Static: false, Public: true }, "AddFirst", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddFirst(value) { - var node = makeNode(this, value); - addFirstImpl(this, node); - return node; - } - ); + $.Method({ Static: false, Public: true }, "AddBefore", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddBefore(node, newNode) { + addBeforeImpl(this, node, newNode); + } + ); - $.Method({ Static: false, Public: true }, "AddFirst", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddFirst(node) { - addFirstImpl(this, node); - } - ); + $.Method({ Static: false, Public: true }, "AddFirst", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddFirst(value) { + var node = makeNode(this, value); + addFirstImpl(this, node); + return node; + } + ); - $.Method({ Static: false, Public: true }, "AddLast", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function AddLast(value) { - var node = makeNode(this, value); - addLastImpl(this, node); - return node; - } - ); + $.Method({ Static: false, Public: true }, "AddFirst", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddFirst(node) { + addFirstImpl(this, node); + } + ); - $.Method({ Static: false, Public: true }, "AddLast", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function AddLast(node) { - addLastImpl(this, node); - } - ); + $.Method({ Static: false, Public: true }, "AddLast", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function AddLast(value) { + var node = makeNode(this, value); + addLastImpl(this, node); + return node; + } + ); - $.Method({ Static: false, Public: true }, "Clear", - (new JSIL.MethodSignature(null, [], [])), - function Clear() { - this._head = null; - this._tail = null; - this._count = 0; - } - ); + $.Method({ Static: false, Public: true }, "AddLast", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function AddLast(node) { + addLastImpl(this, node); + } + ); - $.Method({ Static: false, Public: true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Contains(value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Clear", + (new JSIL.MethodSignature(null, [], [])), + function Clear() { + this._head = null; + this._tail = null; + this._count = 0; + } + ); - $.Method({ Static: false, Public: true }, "CopyTo", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $.Int32], [])), - function CopyTo(array, index) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Contains(value) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true }, "Find", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Find(value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "CopyTo", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), $.Int32], [])), + function CopyTo(array, index) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true }, "FindLast", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function FindLast(value) { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "Find", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Find(value) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true }, "get_Count", - (new JSIL.MethodSignature($.Int32, [], [])), - function get_Count() { - return this._count; - } - ); + $.Method({ Static: false, Public: true }, "FindLast", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function FindLast(value) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true }, "get_First", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function get_First() { - return this._head; - } - ); + $.Method({ Static: false, Public: true }, "get_Count", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Count() { + return this._count; + } + ); - $.Method({ Static: false, Public: true }, "get_Last", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function get_Last() { - return this._tail; - } - ); + $.Method({ Static: false, Public: true }, "get_First", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function get_First() { + return this._head; + } + ); - $.Method({ Static: false, Public: true }, "GetEnumerator", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function GetEnumerator() { - throw new Error('Not implemented'); - } - ); + $.Method({ Static: false, Public: true }, "get_Last", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function get_Last() { + return this._tail; + } + ); - $.RawMethod(false, "$removeNode", function Remove_Node(node) { - if (node._list !== this) - JSIL.RuntimeError("Node is not a member of this list"); + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1/Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function GetEnumerator() { + throw new Error('Not implemented'); + } + ); - var previous = node._previous || null; - var next = node._next || null; + $.RawMethod(false, "$removeNode", function Remove_Node(node) { + if (node._list !== this) + JSIL.RuntimeError("Node is not a member of this list"); - if (previous) - previous._next = next; - if (next) - next._previous = previous; + var previous = node._previous || null; + var next = node._next || null; - if (this._head === node) - this._head = next; - else if (this._tail === node) - this._tail = previous; + if (previous) + previous._next = next; + if (next) + next._previous = previous; - node._list = null; - node._count -= 1; - }); + if (this._head === node) + this._head = next; + else if (this._tail === node) + this._tail = previous; - $.Method({ Static: false, Public: true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), - function Remove(value) { - throw new Error('Not implemented'); - } - ); + node._list = null; + node._count -= 1; + }); - $.Method({ Static: false, Public: true }, "Remove", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), - function Remove(node) { - this.$removeNode(node); - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")], [])), + function Remove(value) { + throw new Error('Not implemented'); + } + ); - $.Method({ Static: false, Public: true }, "RemoveFirst", - (new JSIL.MethodSignature(null, [], [])), - function RemoveFirst() { - this.$removeNode(this._head); - } - ); + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")])], [])), + function Remove(node) { + this.$removeNode(node); + } + ); - $.Method({ Static: false, Public: true }, "RemoveLast", - (new JSIL.MethodSignature(null, [], [])), - function RemoveLast() { - this.$removeNode(this._tail); - } - ); + $.Method({ Static: false, Public: true }, "RemoveFirst", + (new JSIL.MethodSignature(null, [], [])), + function RemoveFirst() { + this.$removeNode(this._head); + } + ); + + $.Method({ Static: false, Public: true }, "RemoveLast", + (new JSIL.MethodSignature(null, [], [])), + function RemoveLast() { + this.$removeNode(this._tail); + } + ); }); JSIL.ImplementExternals("System.Collections.Generic.LinkedListNode`1", function ($) { - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function _ctor(value) { - this._list = null; - this._value = value; - this._previous = null; - this._next = null; - } - ); + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function _ctor(value) { + this._list = null; + this._value = value; + this._previous = null; + this._next = null; + } + ); - $.Method({ Static: false, Public: false }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function _ctor(list, value) { - this._list = list; - this._value = value; - this._previous = null; - this._next = null; - } - ); + $.Method({ Static: false, Public: false }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function _ctor(list, value) { + this._list = list; + this._value = value; + this._previous = null; + this._next = null; + } + ); - $.Method({ Static: false, Public: true }, "get_List", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_List() { - return this._list; - } - ); + $.Method({ Static: false, Public: true }, "get_List", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_List() { + return this._list; + } + ); - $.Method({ Static: false, Public: true }, "get_Next", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_Next() { - return this._next; - } - ); + $.Method({ Static: false, Public: true }, "get_Next", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_Next() { + return this._next; + } + ); - $.Method({ Static: false, Public: true }, "get_Previous", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), - function get_Previous() { - return this._previous; - } - ); + $.Method({ Static: false, Public: true }, "get_Previous", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedListNode`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")]), [], [])), + function get_Previous() { + return this._previous; + } + ); - $.Method({ Static: false, Public: true }, "get_Value", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1"), [], [])), - function get_Value() { - return this._value; - } - ); + $.Method({ Static: false, Public: true }, "get_Value", + (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1"), [], [])), + function get_Value() { + return this._value; + } + ); - $.Method({ Static: false, Public: true }, "set_Value", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), - function set_Value(value) { - this._value = value; - } - ); + $.Method({ Static: false, Public: true }, "set_Value", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedListNode`1")], [])), + function set_Value(value) { + this._value = value; + } + ); }); JSIL.MakeInterface( "System.Collections.IComparer", true, [], function ($) { - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [$.Object, $.Object], []) - ); + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [$.Object, $.Object], []) + ); }, [] ); JSIL.MakeInterface( "System.Collections.Generic.IComparer`1", true, ["in T"], function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.IComparer`1").in(); + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.IComparer`1").in(); - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [T, T], []) - ); + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [T, T], []) + ); }, [] ); JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Collections.Generic.Comparer`1", true, ["T"], function ($) { - var $thisType = $.publicInterface; + var $thisType = $.publicInterface; - $.ExternalMethod({ Static: true, Public: true }, "get_Default", - new JSIL.MethodSignature($.Type, [], []) - ); + $.ExternalMethod({ Static: true, Public: true }, "get_Default", + new JSIL.MethodSignature($.Type, [], []) + ); - $.GenericProperty({ Static: true, Public: true }, "Default", $.Type); + $.GenericProperty({ Static: true, Public: true }, "Default", $.Type); - $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.IComparer"), - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [ - new JSIL.GenericParameter("T", "System.Collections.Generic.Comparer`1") - ]) - ); + $.ImplementInterfaces( + $jsilcore.TypeRef("System.Collections.IComparer"), + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", [ + new JSIL.GenericParameter("T", "System.Collections.Generic.Comparer`1") + ]) + ); }); JSIL.ImplementExternals("System.Collections.Generic.Comparer`1", function ($) { - $.Method({ Static: true, Public: true }, "get_Default", - new JSIL.MethodSignature($.Type, [], []), - function get_Default() { - // HACK - return new (JSIL.DefaultComparer$b1.Of(this.T)); - } - ); + $.Method({ Static: true, Public: true }, "get_Default", + new JSIL.MethodSignature($.Type, [], []), + function get_Default() { + // HACK + return new (JSIL.DefaultComparer$b1.Of(this.T)); + } + ); }); JSIL.MakeClass( $jsilcore.TypeRef("System.Collections.Generic.Comparer`1", [new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1")]), "JSIL.DefaultComparer`1", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1"); - - $.Method({}, "Compare", - new JSIL.MethodSignature($.Int32, [T, T], []), - function Compare(lhs, rhs) { - if (lhs === null) { - if (rhs === null) - return 0; - else - return -1; - } else if (rhs === null) - return 1; - - if (typeof (lhs.CompareTo) === "function") - return lhs.CompareTo(rhs); - - if (lhs < rhs) - return -1; - else if (lhs > rhs) - return 1; - else - return 0; - } - ); + var T = new JSIL.GenericParameter("T", "JSIL.DefaultComparer`1"); + + $.Method({}, "Compare", + new JSIL.MethodSignature($.Int32, [T, T], []), + function Compare(lhs, rhs) { + if (lhs === null) { + if (rhs === null) + return 0; + else + return -1; + } else if (rhs === null) + return 1; + + if (typeof (lhs.CompareTo) === "function") + return lhs.CompareTo(rhs); + + if (lhs < rhs) + return -1; + else if (lhs > rhs) + return 1; + else + return 0; + } + ); } ); JSIL.MakeInterface( "System.ITuple", false, [], function ($) { - $.Method({}, "ToString", (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Text.StringBuilder")], []))); - $.Method({}, "GetHashCode", (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Collections.IEqualityComparer")], []))); - $.Method({}, "get_Size", (new JSIL.MethodSignature($.Int32, [], []))); - $.Property({}, "Size"); + $.Method({}, "ToString", (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Text.StringBuilder")], []))); + $.Method({}, "GetHashCode", (new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.Collections.IEqualityComparer")], []))); + $.Method({}, "get_Size", (new JSIL.MethodSignature($.Int32, [], []))); + $.Property({}, "Size"); }, []); JSIL.MakeStaticClass("System.Tuple", true, [], function ($) { @@ -4719,191 +4730,191 @@ JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Tuple`9", true, ["T1" JSIL.MakeInterface( "System.IAsyncResult", true, [], function ($) { - $.Method({}, "get_IsCompleted", new JSIL.MethodSignature($.Boolean, [], [])); - $.Method({}, "get_AsyncWaitHandle", new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.WaitHandle"), [], [])); - $.Method({}, "get_AsyncState", new JSIL.MethodSignature($.Object, [], [])); - $.Method({}, "get_CompletedSynchronously", new JSIL.MethodSignature($.Boolean, [], [])); - $.Property({}, "IsCompleted"); - $.Property({}, "AsyncWaitHandle"); - $.Property({}, "AsyncState"); - $.Property({}, "CompletedSynchronously"); + $.Method({}, "get_IsCompleted", new JSIL.MethodSignature($.Boolean, [], [])); + $.Method({}, "get_AsyncWaitHandle", new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.WaitHandle"), [], [])); + $.Method({}, "get_AsyncState", new JSIL.MethodSignature($.Object, [], [])); + $.Method({}, "get_CompletedSynchronously", new JSIL.MethodSignature($.Boolean, [], [])); + $.Property({}, "IsCompleted"); + $.Property({}, "AsyncWaitHandle"); + $.Property({}, "AsyncState"); + $.Property({}, "CompletedSynchronously"); }, []); JSIL.ImplementExternals("System.Array", function ($) { - var copyImpl = function (sourceArray, sourceIndex, destinationArray, destinationIndex, length) { - if (length < 0) - throw new System.ArgumentException("length"); - if (sourceIndex < 0) - throw new System.ArgumentException("sourceIndex"); - if (destinationIndex < 0) - throw new System.ArgumentException("destinationIndex"); - - var maxLength = Math.min( - (sourceArray.length - sourceIndex) | 0, - (destinationArray.length - destinationIndex) | 0 - ); - if (length > maxLength) - throw new System.ArgumentException("length"); - - length = length | 0; - - for (var i = 0; i < length; i = (i + 1) | 0) { - destinationArray[i + destinationIndex] = sourceArray[i + sourceIndex]; - } - }; + var copyImpl = function (sourceArray, sourceIndex, destinationArray, destinationIndex, length) { + if (length < 0) + throw new System.ArgumentException("length"); + if (sourceIndex < 0) + throw new System.ArgumentException("sourceIndex"); + if (destinationIndex < 0) + throw new System.ArgumentException("destinationIndex"); - $.Method({ Static: true, Public: true }, "Copy", - new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array"), $jsilcore.TypeRef("System.Array"), - $.Int32 - ], []), - function Copy(sourceArray, destinationArray, length) { - copyImpl(sourceArray, 0, destinationArray, 0, length); - } + var maxLength = Math.min( + (sourceArray.length - sourceIndex) | 0, + (destinationArray.length - destinationIndex) | 0 ); + if (length > maxLength) + throw new System.ArgumentException("length"); - $.Method({ Static: true, Public: true }, "Sort", - (new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array", ["!!0"]), - $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), - function Sort(type, array, comparer) { - var tComparer = System.Collections.Generic.IComparer$b1.Of(type); - var compare = tComparer.Compare; - - Array.prototype.sort.call(array, function (lhs, rhs) { - return compare.Call(comparer, null, lhs, rhs); - }); - } + length = length | 0; + + for (var i = 0; i < length; i = (i + 1) | 0) { + destinationArray[i + destinationIndex] = sourceArray[i + sourceIndex]; + } + }; + + $.Method({ Static: true, Public: true }, "Copy", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array"), $jsilcore.TypeRef("System.Array"), + $.Int32 + ], []), + function Copy(sourceArray, destinationArray, length) { + copyImpl(sourceArray, 0, destinationArray, 0, length); + } ); - $.Method({ Static: true, Public: true }, "Copy", - new JSIL.MethodSignature(null, [ - $jsilcore.TypeRef("System.Array"), $.Int32, - $jsilcore.TypeRef("System.Array"), $.Int32, - $.Int32 - ], []), - function Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) { - copyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length); - } - ); + $.Method({ Static: true, Public: true }, "Sort", + (new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array", ["!!0"]), + $jsilcore.TypeRef("System.Collections.Generic.IComparer`1", ["!!0"])], ["T"])), + function Sort(type, array, comparer) { + var tComparer = System.Collections.Generic.IComparer$b1.Of(type); + var compare = tComparer.Compare; + + Array.prototype.sort.call(array, function (lhs, rhs) { + return compare.Call(comparer, null, lhs, rhs); + }); + } +); + + $.Method({ Static: true, Public: true }, "Copy", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("System.Array"), $.Int32, + $jsilcore.TypeRef("System.Array"), $.Int32, + $.Int32 + ], []), + function Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) { + copyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length); + } + ); }); JSIL.MakeInterface( "System.IConvertible", true, [], function ($) { - $.Method({}, "GetTypeCode", new JSIL.MethodSignature($jsilcore.TypeRef("System.TypeCode"), [], [])); - $.Method({}, "ToBoolean", new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToChar", new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToSByte", new JSIL.MethodSignature($.SByte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToByte", new JSIL.MethodSignature($.Byte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt16", new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt16", new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt32", new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt32", new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToInt64", new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToUInt64", new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToSingle", new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDouble", new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDecimal", new JSIL.MethodSignature($jsilcore.TypeRef("System.Decimal"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToDateTime", new JSIL.MethodSignature($jsilcore.TypeRef("System.DateTime"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToString", new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.IFormatProvider")], [])); - $.Method({}, "ToType", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "GetTypeCode", new JSIL.MethodSignature($jsilcore.TypeRef("System.TypeCode"), [], [])); + $.Method({}, "ToBoolean", new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToChar", new JSIL.MethodSignature($.Char, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToSByte", new JSIL.MethodSignature($.SByte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToByte", new JSIL.MethodSignature($.Byte, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt16", new JSIL.MethodSignature($.Int16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt16", new JSIL.MethodSignature($.UInt16, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt32", new JSIL.MethodSignature($.Int32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt32", new JSIL.MethodSignature($.UInt32, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToInt64", new JSIL.MethodSignature($.Int64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToUInt64", new JSIL.MethodSignature($.UInt64, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToSingle", new JSIL.MethodSignature($.Single, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDouble", new JSIL.MethodSignature($.Double, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDecimal", new JSIL.MethodSignature($jsilcore.TypeRef("System.Decimal"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToDateTime", new JSIL.MethodSignature($jsilcore.TypeRef("System.DateTime"), [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToString", new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.IFormatProvider")], [])); + $.Method({}, "ToType", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type"), $jsilcore.TypeRef("System.IFormatProvider")], [])); }, []); JSIL.MakeInterface( "System.IFormatProvider", true, [], function ($) { - $.Method({}, "GetFormat", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type")], [])); + $.Method({}, "GetFormat", new JSIL.MethodSignature($.Object, [$jsilcore.TypeRef("System.Type")], [])); }, []); JSIL.ImplementExternals("System.WeakReference", function ($) { - var warnedAboutWeakReferences = false; + var warnedAboutWeakReferences = false; - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$.Object], [])), - function _ctor(target) { - // FIXME - if (!warnedAboutWeakReferences) { - warnedAboutWeakReferences = true; - JSIL.Host.warning("Weak references are not supported by JavaScript"); - } + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Object], [])), + function _ctor(target) { + // FIXME + if (!warnedAboutWeakReferences) { + warnedAboutWeakReferences = true; + JSIL.Host.warning("Weak references are not supported by JavaScript"); } - ); + } + ); }); JSIL.ImplementExternals("System.Diagnostics.Trace", function ($) { - $.Method({ Static: true, Public: true }, "TraceError", - new JSIL.MethodSignature(null, [$.String], []), - function TraceError(message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.error(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceError", + new JSIL.MethodSignature(null, [$.String], []), + function TraceError(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.error(message); + } + ); - $.Method({ Static: true, Public: true }, "TraceError", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceError(format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.error(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceError", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceError(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.error(message); + } + ); - $.Method({ Static: true, Public: true }, "TraceInformation", - new JSIL.MethodSignature(null, [$.String], []), - function TraceInformation(message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.information(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceInformation", + new JSIL.MethodSignature(null, [$.String], []), + function TraceInformation(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.information(message); + } + ); - $.Method({ Static: true, Public: true }, "TraceInformation", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceInformation(format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.information(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceInformation", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceInformation(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.information(message); + } + ); - $.Method({ Static: true, Public: true }, "TraceWarning", - new JSIL.MethodSignature(null, [$.String], []), - function TraceWarning(message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.warning(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceWarning", + new JSIL.MethodSignature(null, [$.String], []), + function TraceWarning(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.warning(message); + } + ); - $.Method({ Static: true, Public: true }, "TraceWarning", - new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), - function TraceWarning(format, args) { - var svc = JSIL.Host.getService("trace", true); - var message = System.String.Format(format, args); - if (svc) - svc.warning(message); - } - ); + $.Method({ Static: true, Public: true }, "TraceWarning", + new JSIL.MethodSignature(null, [$.String, $jsilcore.TypeRef("System.Array", [$.Object])], []), + function TraceWarning(format, args) { + var svc = JSIL.Host.getService("trace", true); + var message = System.String.Format(format, args); + if (svc) + svc.warning(message); + } + ); - $.Method({ Static: true, Public: true }, "WriteLine", - new JSIL.MethodSignature(null, [$.String], []), - function WriteLine(message) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.write(message); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + new JSIL.MethodSignature(null, [$.String], []), + function WriteLine(message) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.write(message); + } + ); - $.Method({ Static: true, Public: true }, "WriteLine", - new JSIL.MethodSignature(null, [$.String, $.String], []), - function WriteLine(message, category) { - var svc = JSIL.Host.getService("trace", true); - if (svc) - svc.write(message, category); - } - ); + $.Method({ Static: true, Public: true }, "WriteLine", + new JSIL.MethodSignature(null, [$.String, $.String], []), + function WriteLine(message, category) { + var svc = JSIL.Host.getService("trace", true); + if (svc) + svc.write(message, category); + } + ); }); JSIL.MakeStaticClass("System.Diagnostics.Trace", true, [], function ($) { diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index 4396940ea..f9fa999a1 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -95,7 +95,25 @@ JSIL.ImplementExternals( JSIL.TypeObjectPrototype.get_IsArray ); + $.Method({ Static: false, Public: true }, "get_IsAbstract", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__IsAbstract__; + } + ); + $.Method({ Static: false, Public: true }, "get_IsPrimitive", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__IsPrimitive__; + } + ); + + $.Method({ Static: false, Public: true }, "get_HasElementType", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__ElementType__ != null; + }); $.Method({Public: true , Static: false}, "get_IsValueType", new JSIL.MethodSignature($.Boolean, []), @@ -113,20 +131,6 @@ JSIL.ImplementExternals( return this.__ElementType__; } ); - - $.Method({ Static: false, Public: true }, "get_IsAbstract", - new JSIL.MethodSignature($.Boolean, []), - function () { - return this.__IsAbstract__; - } - ); - - $.Method({ Static: false, Public: true }, "get_HasElementType", - new JSIL.MethodSignature($.Boolean, []), - function () { - return this.__ElementType__ != null; - }); - $.Method({Public: true , Static: false}, "get_BaseType", new JSIL.MethodSignature($.Type, []), @@ -388,9 +392,23 @@ JSIL.ImplementExternals( $.Method({Public: true , Static: false}, "GetFields", new JSIL.MethodSignature(fieldArray, [$jsilcore.TypeRef("System.Reflection.BindingFlags")]), function (flags) { - return JSIL.GetMembersInternal( + var result = []; + var tempResult = JSIL.GetMembersInternal( this, flags, "FieldInfo" ); + for (var i = 0; i < tempResult.length; i++) { + var f = tempResult[i]; + var fieldType = f._data.fieldType; + if (typeof (fieldType.get_FullName) != "undefined") { + if (fieldType.get_FullName() != "System.Double[]") { + result.push(f); + } else { + console.log("MultidimensionalArray") + } + } + } + + return result; } ); @@ -885,7 +903,10 @@ JSIL.MakeClass("System.Reflection.MemberInfo", "System.Type", true, [], function $.Property({Public: true , Static: false, Virtual: true }, "IsGenericTypeDefinition"); $.Property({Public: true , Static: false }, "IsArray"); $.Property({Public: true , Static: false }, "IsValueType"); - $.Property({Public: true , Static: false }, "IsEnum"); + $.Property({ Public: true, Static: false }, "IsEnum"); + $.Property({ Public: true, Static: false }, "IsAbstract"); + $.Property({ Public: true, Static: false }, "IsPrimitive"); + $.Property({ Public: true, Static: false }, "HasElementType"); }); JSIL.MakeClass("System.Type", "System.RuntimeType", false, [], function ($) { diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 6de6c9a26..59869cc04 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -310,7 +310,17 @@ JSIL.$GetSpecialType = function (name) { JSIL.TypeObjectPrototype.get_Assembly = function() { return this.__Context__.__Assembly__; }; - JSIL.TypeObjectPrototype.get_BaseType = function() { + JSIL.TypeObjectPrototype.get_BaseType = function () { + var JSILTypes = ["System.Byte", "System.UInt16", "System.UInt32", "System.UInt64", + "System.SByte", "System.Int16", "System.Int32", "System.Int64", + "System.Single", "System.Double", "System.String", "System.Object", + "System.Boolean", "System.Char"]; + if (JSILTypes.indexOf(this.__FullName__) > -1) + return null; + if (typeof (this.__BaseType__.__Type__) != "undefined") + return this.__BaseType__.__Type__; + if (this.__BaseType__.__FullName__.indexOf("JSIL") == 0) + return null; return this.__BaseType__; }; JSIL.TypeObjectPrototype.get_Namespace = function() { @@ -1347,7 +1357,7 @@ JSIL.ImplementExternals = function (namespaceName, externals) { // Deferring the execution of externals functions is important in case they reference // other types or assemblies. - queue.push(function ImplementExternalsImpl () { + queue.push(function ImplementExternalsImpl() { var typeId = JSIL.AssignTypeId(context, namespaceName); var typeObject = { __Members__: [], @@ -3998,7 +4008,7 @@ JSIL.InitializeType = function (type) { else if (typeof (type.__Type__) === "object") typeObject = type.__Type__; else - return; + return; if (typeObject.__TypeInitialized__ || false) return; @@ -4870,12 +4880,16 @@ JSIL.MakeType = function (typeArgs, initializer) { var isReferenceType = Boolean(typeArgs.IsReferenceType); var isPublic = Boolean(typeArgs.IsPublic); var isAbstract = Boolean(typeArgs.IsAbstract); + var isPrimitive = Boolean(typeArgs.IsPrimitive); var genericArguments = typeArgs.GenericParameters || []; var maxConstructorArguments = typeArgs.MaximumConstructorArguments; if (typeof (isPublic) === "undefined") JSIL.Host.abort(new Error("Must specify isPublic")); + if (typeof (isPublic) === "undefined") + JSIL.Host.abort(new Error("Must specify isPrimitive")); + var assembly = $private; var localName = JSIL.GetLocalName(fullName); var memberBuilder = new JSIL.MemberBuilder($private); @@ -4937,6 +4951,7 @@ JSIL.MakeType = function (typeArgs, initializer) { typeObject.__InheritanceDepth__ = (typeObject.__BaseType__.__InheritanceDepth__ || 0) + 1; typeObject.__IsArray__ = false; typeObject.__IsAbstract__ = isAbstract; + typeObject.__IsPrimitive__ = isPrimitive; typeObject.__FieldList__ = $jsilcore.ArrayNotInitialized; typeObject.__FieldInitializer__ = $jsilcore.FunctionNotInitialized; typeObject.__MemberCopier__ = $jsilcore.FunctionNotInitialized; @@ -5008,7 +5023,9 @@ JSIL.MakeType = function (typeArgs, initializer) { } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + //if (typeOfValue.__AssignableTypes__ != null) { + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + //} }; for (var i = 0, l = typeObject.__GenericArguments__.length; i < l; i++) { @@ -7958,8 +7975,16 @@ JSIL.ObjectHashCode = function (obj) { var type = typeof obj; if (type === "object") { - if (obj.GetHashCode) - return (obj.GetHashCode() | 0); + if (obj.GetHashCode) { + try{ + return (obj.GetHashCode() | 0); + } catch(err) { + // HashCode returns null, + return 0; + } + + } + return JSIL.HashCodeInternal(obj); } else { diff --git a/Libraries/JSIL.HeuristicLab.js b/Libraries/JSIL.HeuristicLab.js index f242ea498..a512ee4fe 100644 --- a/Libraries/JSIL.HeuristicLab.js +++ b/Libraries/JSIL.HeuristicLab.js @@ -14,16 +14,135 @@ function get_CurrentDomain() { function GetAssemblies() { var result = []; for (var asm in JSIL.PrivateNamespaces) { - var assembly = JSIL.GetAssembly(asm, true); - if (assembly != null) { - result.push(assembly.__Assembly__); + // Only load HeuristicLab assemblies + if (asm.indexOf("HeuristicLab") !== -1) { + var assembly = JSIL.GetAssembly(asm, true); + if (assembly != null) { + result.push(assembly.__Assembly__); + } } } return result; } -function HLGetTypes(type, onlyInstantiable, includeGenericTypeDefinitions) { - console.log("GetTypes called"); +function HLGetTypes(type, assembly, pOnlyInstantiable, pIncludeGenericTypeDefinitions) { + var assemblyTypes = assembly.GetTypes(); + var onlyInstantiable = true; + if (pOnlyInstantiable == null || typeof (pOnlyInstantiable) == "undefined") + onlyInstantiable = true; + else + onlyInstantiable = Boolean(pOnlyInstantiable); + var includeGenericTypeDefinitions = Boolean(pIncludeGenericTypeDefinitions); + + JSIL.InitializeType(type); + var result = []; + + for (var k = 0; k < assemblyTypes.length; k++) { + JSIL.InitializeType(assemblyTypes[k]); + /*if (assemblyTypes[k].Name == "SequentialEngine") { + console.log("SequentialEngine"); + }*/ + + var t = HLBuildType(assemblyTypes[k], type); + + if (t != null) { + + + if (HLIsSubTypeOf(t, type)) { + if (!HLIsNonDiscoverable(t)) { + if (onlyInstantiable === false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)) { + if (includeGenericTypeDefinitions || !t.IsGenericTypeDefinition) { + result.push(t); + } + } + } + } + } + } + + /*if (result.length > 0) { + console.log("-------------------") + for (var i = 0; i < result.length; i++) { + console.log("Selected type: " + result[i].Name) + } + }*/ + + return result; +} + +function HLIsNonDiscoverable(type) { + if (type.__Attributes__.length != 0) { + var attributes = type.__Attributes__; + for (var i = 0; i < attributes.length; i++) { + if (attributes[i].type.typeName == "HeuristicLab.PluginInfrastructure.NonDiscoverableTypeAttribute") + return true; + } + } + return false; } +function HLBuildType(type, protoType) { + if (type == null || protoType == null) + return null; + + if (!type.IsGenericTypeDefinition) return type; + if (protoType.IsGenericTypeDefinition) return type; + if (!protoType.IsGenericType) return type; + + var typeGenericArguments = type.GetGenericArguments(); + var protoTypeGenericArguments = protoType.GetGenericArguments(); + if (typeGenericArguments.length != protoTypeGenericArguments.length) return null; + + for (var i = 0; i < typeGenericArguments.length; i++) { + var typeGenericArgument = typeGenericArguments[i]; + var protoTypeGenericArgument = protoTypeGenericArguments[i]; + + //check class contraint on generic type parameter + if (typeGenericArgument.GenericParameterAttributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint)) + if (!protoTypeGenericArgument.IsClass && !protoTypeGenericArgument.IsInterface && !protoType.IsArray) return null; + + //check default constructor constraint on generic type parameter + if (typeGenericArgument.GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint)) + if (!protoTypeGenericArgument.IsValueType && protoTypeGenericArgument.GetConstructor(Type.EmptyTypes) == null) return null; + + //check type restrictions on generic type parameter + var constraints = typeGenericArgument.GetGenericParameterConstraints(); + for (var c = 0; c < constraints.length; i++) { + if (!constraints[c].IsAssignableFrom(protoTypeGenericArgument)) return null; + } + } + try { + return type.MakeGenericType(protoTypeGenericArguments); + } catch (err) { + return null; + } +} + +function HLIsSubTypeOf(subType, baseType) { + if (baseType.IsAssignableFrom(subType)) return true; + if (!baseType.IsGenericType) return false; + + if (HLRecursiveCheckGenericTypes(baseType, subType)) return true; + + var interfaces = subType.GetInterfaces(); + for (var i = 0; i < interfaces.length; i++) { + if (interfaces[i].IsGenericType) { + if (baseType.CheckGenericTypes(interfaces[i])) return true; + } + } + + return false; +} + +function HLRecursiveCheckGenericTypes(baseType, subType) { + JSIL.InitializeType(subType); + if (!baseType.IsGenericType) return false; + if (!subType.IsGenericType) return false; + if (baseType.CheckGenericTypes(subType)) return true; + if (subType.BaseType == null) return false; + + return RecursiveCheckGenericTypes(baseType, subType.BaseType); +} + + diff --git a/Proxies/Bootstrap.cs b/Proxies/Bootstrap.cs index 78bf21efd..254ac9944 100644 --- a/Proxies/Bootstrap.cs +++ b/Proxies/Bootstrap.cs @@ -4,13 +4,216 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Diagnostics; +using System.Globalization; +using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading; namespace JSIL.Proxies { + [JSProxy(typeof(Boolean), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Boolean + { + } + + [JSProxy(typeof(Char), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Char + { + } + + [JSProxy(typeof(Byte), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Byte + { + } + + [JSProxy(typeof(SByte), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_SByte + { + } + + [JSProxy(typeof(UInt16), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_UInt16 + { + } + + [JSProxy(typeof(Int16), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Int16 + { + } + + [JSProxy(typeof(UInt32), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_UInt32 + { + } + + [JSProxy(typeof(Int32), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Int32 + { + } + + [JSProxy(typeof(Single), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Single + { + } + + [JSProxy(typeof(Double), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Double + { + } + + [JSProxy(typeof(MemberDescriptor), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ComponentModel_MemberDescriptor + { + } + + [JSProxy(typeof(PropertyDescriptor), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ComponentModel_PropertyDescriptor + { + } + + [JSProxy(typeof(TypeConverter), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ComponentModel_TypeConverter + { + } + + [JSProxy(typeof(ExpandableObjectConverter), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ComponentModel_ExpandableObjectConverter + { + } + + [JSProxy(typeof(Delegate), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Delegate + { + } + + [JSProxy(typeof(MulticastDelegate), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_MulticastDelegate + { + } + + [JSProxy(typeof(Exception), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Exception + { + } + + [JSProxy(typeof(SystemException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_SystemException + { + } + + [JSProxy(typeof(FormatException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_FormatException + { + } + + [JSProxy(typeof(InvalidCastException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_InvalidCastException + { + } + + [JSProxy(typeof(InvalidOperationException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_InvalidOperationException + { + } + + [JSProxy(typeof(NotImplementedException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_NotImplementedException + { + } + + [JSProxy(typeof(AmbiguousMatchException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_AmbiguousMatchException + { + } + + [JSProxy(typeof(ArgumentException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArgumentException + { + } + + [JSProxy(typeof(ArgumentOutOfRangeException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArgumentOutOfRangeException + { + } + + [JSProxy(typeof(IOException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IOException + { + } + + [JSProxy(typeof(FileNotFoundException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileNotFoundException + { + } + + [JSProxy(typeof(EndOfStreamException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_EndOfStreamException + { + } + + [JSProxy(typeof(ArithmeticException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_ArithmeticException + { + } + + [JSProxy(typeof(OverflowException), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_OverflowException + { + } + + [JSProxy(typeof(Console), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Console + { + } + + [JSProxy(typeof(Debug), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Diagnostics_Debug + { + } + + + [JSProxy(typeof(Thread), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Threading_Thread + { + } + [JSProxy(typeof(ArrayList), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] public class System_Collections_ArrayList @@ -28,7 +231,6 @@ public class System_Collections_ObjectModel_Collection_1 public class System_Collections_ObjectModel_ReadOnlyCollection_1 { } - [JSProxy("System.Collections.Generic.List`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] @@ -44,7 +246,7 @@ public class System_Collections_Generic_Stack_1 [JSProxy("System.Collections.Generic.List`1+Enumerator", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] - public class System_Collections_Generic_List_1_Enumerator + public class System_Collections_Generic_Stack_1_Enumerator { } @@ -60,6 +262,36 @@ public static class System_Threading_Interlocked { } + [JSProxy(typeof(Monitor), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Threading_Monitor + { + } + + [JSProxy(typeof(Random), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Random + { + } + + [JSProxy(typeof(Math), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Math + { + } + + [JSProxy(typeof(Decimal), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Decimal + { + } + + [JSProxy(typeof(Environment), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Environment + { + } + [JSProxy("System.Collections.Generic.KeyValuePair`2", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] public class System_Collections_Generic_KeyValuePair_2 @@ -72,18 +304,109 @@ public class System_Collections_Generic_Dictionary_2 { } - [JSProxy("System.Collections.Generic.Dictionary`2/Enumerator", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSProxy("System.Collections.Generic.Dictionary`2+Enumerator", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] public class System_Collections_Generic_Dictionary_2_Enumerator { } + [JSProxy(typeof(Nullable), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Nullable + { + } + + [JSProxy("System.Nullable`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Nullable_1 + { + } + + [JSProxy(typeof(XmlSerializer), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Xml_Serialization_XmlSerializer + { + } + + [JSProxy(typeof(StackTrace), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Diagnostics_StackTrace + { + } + + [JSProxy(typeof(StackFrame), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Diagnostics_StackFrame + { + } + + [JSProxy(typeof(Enum), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Enum + { + } + + [JSProxy(typeof(BindingFlags), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_BindingFlags + { + } + + + [JSProxy(typeof(Activator), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Activator + { + } + + [JSProxy(typeof(Stopwatch), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Diagnostics_Stopwatch + { + } + + [JSProxy(typeof(GC), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_GC + { + } + + [JSProxy(typeof(EventArgs), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_EventArgs + { + } + + [JSProxy(typeof(FileMode), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileMode + { + } + [JSProxy("System.Collections.Generic.HashSet`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] public class System_Collections_Generic_HashSet_1 { } + [JSProxy(typeof(NumberStyles), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Globalization_NumberStyles + { + } + + [JSProxy(typeof(Convert), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Convert + { + } + + [JSProxy(typeof(BitConverter), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_BitConverter + { + } + [JSProxy("System.Collections.Generic.LinkedList`1", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] public static class System_Collections_Generic_LinkedList_1 @@ -108,9 +431,16 @@ public static class System_Tuple { } - [JSProxy(typeof(StackTrace), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + + [JSProxy(typeof(Buffer), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public static class System_Buffer + { + } + + [JSProxy(typeof(WeakReference), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] [JSStubOnly] - public static class System_Diagnostics_StackTrace + public static class System_WeakReference { } diff --git a/Proxies/Diagnostics.cs b/Proxies/Diagnostics.cs new file mode 100644 index 000000000..05e0365f5 --- /dev/null +++ b/Proxies/Diagnostics.cs @@ -0,0 +1,13 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Diagnostics; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(Trace), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + class System_Diagnostics_Trace + { + } +} diff --git a/Proxies/IO.cs b/Proxies/IO.cs index c0dfe93cb..87502d5a7 100644 --- a/Proxies/IO.cs +++ b/Proxies/IO.cs @@ -40,6 +40,12 @@ public FileStreamProxy (SafeFileHandle handle, AnyType access, int bufferSize, b } } + [JSProxy(typeof(FileStream), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileStream + { + } + [JSProxy( typeof(TextReader), JSProxyMemberPolicy.ReplaceDeclared @@ -60,4 +66,64 @@ public void Dispose(bool b) throw new InvalidOperationException(); } } + + [JSProxy(typeof(MarshalByRefObject), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_MarshalByRefObject + { + } + + [JSProxy(typeof(File), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_File + { + } + + [JSProxy(typeof(Path), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_Path + { + } + + [JSProxy(typeof(Stream), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_Stream + { + } + + [JSProxy(typeof(MemoryStream), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_MemoryStream + { + } + + [JSProxy(typeof(SeekOrigin), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_SeekOrigin + { + } + + [JSProxy(typeof(FileSystemInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileSystemInfo + { + } + + [JSProxy(typeof(DirectoryInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_DirectoryInfo + { + } + + [JSProxy(typeof(FileInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileInfo + { + } + + [JSProxy(typeof(Directory), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_Directory + { + } } diff --git a/Proxies/Proxies.4.0.csproj b/Proxies/Proxies.4.0.csproj index 67ddfd3e0..62a12660a 100644 --- a/Proxies/Proxies.4.0.csproj +++ b/Proxies/Proxies.4.0.csproj @@ -40,16 +40,15 @@ + - - - + @@ -60,6 +59,7 @@ + diff --git a/Proxies/Reflection.cs b/Proxies/Reflection.cs index fcf8b8dc7..78523ede2 100644 --- a/Proxies/Reflection.cs +++ b/Proxies/Reflection.cs @@ -1,6 +1,7 @@ using System; using JSIL.Meta; using JSIL.Proxy; +using System.Reflection; namespace JSIL.Proxies { [JSProxy( @@ -48,4 +49,64 @@ public static Type GetType (string typeName, bool throwOnFail, bool ignoreCase) )] public abstract class RuntimeTypeProxy { } + + [JSProxy(typeof(MemberInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_MemberInfo + { + } + + [JSProxy(typeof(MethodBase), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_MethodBase + { + } + + [JSProxy(typeof(MethodInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_MethodInfo + { + } + + [JSProxy(typeof(ConstructorInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_ConstructorInfo + { + } + + [JSProxy(typeof(FieldInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_FieldInfo + { + } + + [JSProxy(typeof(EventInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_EventInfo + { + } + + [JSProxy(typeof(PropertyInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_PropertyInfo + { + } + + [JSProxy(typeof(Assembly), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_Assembly + { + } + + [JSProxy("System.Reflection.RuntimeAssembly", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_RuntimeAssembly + { + } + + [JSProxy(typeof(ParameterInfo), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_ParameterInfo + { + } } diff --git a/Proxies/Text.cs b/Proxies/Text.cs new file mode 100644 index 000000000..c98dd2197 --- /dev/null +++ b/Proxies/Text.cs @@ -0,0 +1,78 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace JSIL.Proxies +{ + [JSProxy(typeof(String), JSProxyMemberPolicy.ReplaceDeclared, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_String + { + [JSReplacement("System.String.StartsWith($this, $text)")] + [JSIsPure] + public bool StartsWith(string text, StringComparison comparisonType) + { + throw new InvalidOperationException(); + } + + [JSReplacement("$this.indexOf($value)")] + [JSIsPure] + public int IndexOf(string value, StringComparison comparisonType) + { + throw new InvalidOperationException(); + } + + [JSReplacement("$this.indexOf($value, $startIndex)")] + [JSIsPure] + public int IndexOf(string value, int startIndex, StringComparison comparisonType) + { + throw new InvalidOperationException(); + } + } + + [JSProxy(typeof(StringComparison), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_StringComparison + { + } + + [JSProxy(typeof(Encoding), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_Encoding + { + } + + [JSProxy(typeof(ASCIIEncoding), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_ASCIIEncoding + { + } + + [JSProxy(typeof(UTF8Encoding), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_UTF8Encoding + { + } + + [JSProxy(typeof(UTF7Encoding), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_UTF7Encoding + { + } + + [JSProxy(typeof(UnicodeEncoding), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_UnicodeEncoding + { + } + + [JSProxy(typeof(StringBuilder), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Text_StringBuilder + { + } +} diff --git a/Proxies/Unsafe.cs b/Proxies/Unsafe.cs index 00f5301f9..12ba76671 100644 --- a/Proxies/Unsafe.cs +++ b/Proxies/Unsafe.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using JSIL.Meta; using JSIL.Proxy; +using System.IO; namespace JSIL.Proxies { [JSProxy( @@ -20,4 +21,64 @@ public static GCHandle Alloc (object value, GCHandleType type) { throw new NotImplementedException(); } } + + [JSProxy(typeof(IntPtr), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IntPtr + { + } + + [JSProxy(typeof(UIntPtr), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_UIntPtr + { + } + + [JSProxy("System.Void", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Void + { + } + + [JSProxy(typeof(Marshal), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Runtime_InteropServices_Marshal + { + } + + [JSProxy(typeof(GCHandle), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Runtime_InteropServices_GCHandle + { + } + + [JSProxy(typeof(BinaryWriter), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_BinaryWriter + { + } + + [JSProxy(typeof(BinaryReader), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_BinaryReader + { + } + + [JSProxy(typeof(TextReader), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_TextReader + { + } + + [JSProxy(typeof(StreamReader), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_StreamReader + { + } + + [JSProxy(typeof(TextWriter), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_TextWriter + { + } } diff --git a/Proxies/XmlSerializer.cs b/Proxies/XmlSerializer.cs new file mode 100644 index 000000000..20122bb31 --- /dev/null +++ b/Proxies/XmlSerializer.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace JSIL.Proxies +{ + class XmlSerializer + { + } +} From b4e065980a66eaaa63701bebb467e3aafae606ba Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 Apr 2014 16:38:36 +0200 Subject: [PATCH 05/16] Working Prototype --- JSIL_NoXNA.sln | 4 +++- Libraries/JSIL.Bootstrap.Text.js | 3 +++ Libraries/JSIL.Bootstrap.js | 7 +++++++ Libraries/JSIL.Browser.js | 9 +++++---- Libraries/JSIL.Core.js | 5 ++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/JSIL_NoXNA.sln b/JSIL_NoXNA.sln index d5e91b860..f105bb845 100644 --- a/JSIL_NoXNA.sln +++ b/JSIL_NoXNA.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compiler", "Compiler\Compiler.csproj", "{C7BF4561-20DD-4E49-8B5A-4E8AF032C47A}" ProjectSection(ProjectDependencies) = postProject {984CC812-9470-4A13-AFF9-CC44068D666C} = {984CC812-9470-4A13-AFF9-CC44068D666C} diff --git a/Libraries/JSIL.Bootstrap.Text.js b/Libraries/JSIL.Bootstrap.Text.js index 61b14ab99..0f760eea3 100644 --- a/Libraries/JSIL.Bootstrap.Text.js +++ b/Libraries/JSIL.Bootstrap.Text.js @@ -87,6 +87,7 @@ JSIL.ParseCustomNumberFormat = function (customFormat) { switch (ch) { case "\t": case " ": + case "%": commands.push(rawCharacter.bind(ch)); break; @@ -311,6 +312,8 @@ JSIL.NumberToFormattedString = function (value, alignment, valueFormat, formatPr case 'f': case 'F': + case 'r': + case 'R': result = formatFloat(value, valueFormat.substr(1)); break; diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index 69128764b..bd8419956 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -267,6 +267,13 @@ JSIL.ImplementExternals( return (typeof (value) === "number"); }); + $.Method({ Static: true, Public: true }, "IsInfinity", + (new JSIL.MethodSignature($.Boolean, [$.Double], [])), + function (d) { + return (d == -Infinity || d == Infinity); + } + ); + $jsilcore.$MakeParseExternals($, $.Single, $jsilcore.$ParseFloat, $jsilcore.$TryParseFloat); $.Constant({ Public: true, Static: true }, "MinValue", -1.7976931348623157E+308); diff --git a/Libraries/JSIL.Browser.js b/Libraries/JSIL.Browser.js index f92afefe4..4ce4327a4 100644 --- a/Libraries/JSIL.Browser.js +++ b/Libraries/JSIL.Browser.js @@ -192,10 +192,11 @@ JSIL.Browser.WarningService = function (stream) { JSIL.Browser.WarningService.prototype.write = function (text) { // Quirky behavior, but we suppress warnings from the log if the console is available. if (window.console && window.console.warn) { - if (typeof (text) === "string") - window.console.warn(text.trim()); - else - window.console.warn(text); + if (typeof (text) === "string") { + //window.console.warn(text.trim()); + } + //else + //window.console.warn(text); } else if (this.stream) { this.stream.write(text); } diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 59869cc04..5953e3e82 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -3803,6 +3803,7 @@ JSIL.$CreateMethodMembranes = function (typeObject, publicInterface) { // This can't be done before now due to generic types. for (var i = 0, l = methods.length; i < l; i++) { var method = methods[i]; + var isStatic = method._descriptor.Static; // FIXME: I'm not sure this is right for open generic methods. // I think it might be looking up the old open form of the method signature @@ -7525,7 +7526,9 @@ JSIL.GetMembersInternal = function (typeObject, flags, memberType, name) { for (var i = 0, l = members.length; i < l; i++) { var member = members[i]; - + if (member._data.mangledName == "Method$10=void") { + console.log("Method(param)") + } // HACK: Reflection never seems to enumerate static constructors. This is probably because // it doesn't make any sense to invoke them explicitly anyway, and they don't have arguments... if ( From 10193530102a136f89f4eb089d7f3c9aad8b95f1 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Tue, 22 Apr 2014 14:10:49 +0200 Subject: [PATCH 06/16] Fix UnknownMember being generated when working with anonymous types --- JSIL/CILSupport.cs | 350 +++++++++++++++++++++++---------------------- 1 file changed, 177 insertions(+), 173 deletions(-) diff --git a/JSIL/CILSupport.cs b/JSIL/CILSupport.cs index 2fad8edeb..a224c7738 100644 --- a/JSIL/CILSupport.cs +++ b/JSIL/CILSupport.cs @@ -13,236 +13,240 @@ using Mono.Cecil.Pdb; namespace JSIL.Internal { - public class AssemblyCache : ConcurrentCache { - public bool RegisterAssembly (AssemblyDefinition assembly) { - if (assembly == null) - throw new ArgumentNullException("assembly"); + public class AssemblyCache : ConcurrentCache { + public bool RegisterAssembly(AssemblyDefinition assembly) { + if (assembly == null) + throw new ArgumentNullException("assembly"); - var name = assembly.Name.FullName; + var name = assembly.Name.FullName; - return TryCreate(name, (fullName) => assembly); - } + return TryCreate(name, (fullName) => assembly); } + } - public class AssemblyResolver : BaseAssemblyResolver, IDisposable { - private static readonly byte[] PCLPublicKeyToken = { + public class AssemblyResolver : BaseAssemblyResolver, IDisposable { + private static readonly byte[] PCLPublicKeyToken = { 124, 236, 133, 215, 190, 167, 121, 142 }; - private static readonly byte[] BCLPublicKeyToken = { + private static readonly byte[] BCLPublicKeyToken = { 183, 122, 92, 86, 25, 52, 224, 137 }; - protected readonly Configuration Configuration; - protected readonly AssemblyCache Cache = new AssemblyCache(); - protected readonly bool OwnsCache; - - public AssemblyResolver (IEnumerable dirs, Configuration configuration, AssemblyCache cache = null) { - Configuration = configuration; + protected readonly Configuration Configuration; + protected readonly AssemblyCache Cache = new AssemblyCache(); + protected readonly bool OwnsCache; - OwnsCache = (cache == null); - Cache = cache ?? new AssemblyCache(); + public AssemblyResolver(IEnumerable dirs, Configuration configuration, AssemblyCache cache = null) { + Configuration = configuration; - foreach (var dir in dirs) - AddSearchDirectory(dir); - } + OwnsCache = (cache == null); + Cache = cache ?? new AssemblyCache(); - public void Dispose () { - if (OwnsCache) - Cache.Dispose(); - } + foreach (var dir in dirs) + AddSearchDirectory(dir); + } - public AssemblyNameReference FilterPortableClassLibraryReferences (AssemblyNameReference name) { - // Portable class libraries are pretty shoddily constructed. Who came up with this nonsense? + public void Dispose() { + if (OwnsCache) + Cache.Dispose(); + } - if (!name.PublicKeyToken.SequenceEqual(PCLPublicKeyToken)) - return name; + public AssemblyNameReference FilterPortableClassLibraryReferences(AssemblyNameReference name) { + // Portable class libraries are pretty shoddily constructed. Who came up with this nonsense? - var bclName = new AssemblyNameReference( - name.Name, - // FIXME: Is this right? It was 4.0 before, but that's definitely wrong. - // This should pick the highest appropriate version from the GAC. - null - ) { - Culture = name.Culture, - PublicKeyToken = BCLPublicKeyToken - }; + if (!name.PublicKeyToken.SequenceEqual(PCLPublicKeyToken)) + return name; - return bclName; - } + var bclName = new AssemblyNameReference( + name.Name, + // FIXME: Is this right? It was 4.0 before, but that's definitely wrong. + // This should pick the highest appropriate version from the GAC. + null + ) { + Culture = name.Culture, + PublicKeyToken = BCLPublicKeyToken + }; - public AssemblyNameReference FilterRedirectedReferences (AssemblyNameReference name, out string redirectedFrom) { - redirectedFrom = null; + return bclName; + } - foreach (var kvp in Configuration.Assemblies.Redirects) { - if (Regex.IsMatch(name.FullName, kvp.Key, RegexOptions.IgnoreCase)) { - redirectedFrom = name.FullName; - return AssemblyNameReference.Parse(kvp.Value); - } - } + public AssemblyNameReference FilterRedirectedReferences(AssemblyNameReference name, out string redirectedFrom) { + redirectedFrom = null; - return name; + foreach (var kvp in Configuration.Assemblies.Redirects) { + if (Regex.IsMatch(name.FullName, kvp.Key, RegexOptions.IgnoreCase)) { + redirectedFrom = name.FullName; + return AssemblyNameReference.Parse(kvp.Value); } + } - public override AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters) { - if (name == null) - throw new ArgumentNullException("name"); + return name; + } - var actualName = FilterPortableClassLibraryReferences(name); - string redirectedFrom; - actualName = FilterRedirectedReferences(name, out redirectedFrom); + public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { + if (name == null) + throw new ArgumentNullException("name"); - var result = Cache.GetOrCreate(actualName.FullName, (fullName) => { - if (redirectedFrom != null) - Console.Error.WriteLine("// Redirected '{0}' to '{1}'", redirectedFrom, actualName.FullName); + var actualName = FilterPortableClassLibraryReferences(name); + string redirectedFrom; + actualName = FilterRedirectedReferences(name, out redirectedFrom); - return base.Resolve(actualName, parameters); - }); + var result = Cache.GetOrCreate(actualName.FullName, (fullName) => { + if (redirectedFrom != null) + Console.Error.WriteLine("// Redirected '{0}' to '{1}'", redirectedFrom, actualName.FullName); - return result; - } - } + return base.Resolve(actualName, parameters); + }); - public class NoSymbolsException : FileNotFoundException { - public NoSymbolsException (ModuleDefinition module, string fileName) - : base( - String.Format("Module '{0}' has no symbols.", Path.GetFileName(module.FullyQualifiedName)), fileName - ) { - } + return result; } + } - public class SymbolProvider : ISymbolReaderProvider { - public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName) { - if (String.IsNullOrWhiteSpace(fileName)) - throw new ArgumentException("Invalid path", "fileName"); - - var pdbPath = Path.Combine( - Path.GetDirectoryName(fileName), - Path.GetFileNameWithoutExtension(fileName) + ".pdb" - ); - var mdbPath = Path.Combine( - Path.GetDirectoryName(fileName), - Path.GetFileName(fileName) + ".mdb" - ); - - if (File.Exists(pdbPath)) { - return (new PdbReaderProvider()).GetSymbolReader(module, File.OpenRead(pdbPath)); - } else if (File.Exists(mdbPath)) { - return (new MdbReaderProvider()).GetSymbolReader(module, fileName); - } else { - throw new NoSymbolsException(module, fileName); - } - } + public class NoSymbolsException : FileNotFoundException { + public NoSymbolsException(ModuleDefinition module, string fileName) + : base( + String.Format("Module '{0}' has no symbols.", Path.GetFileName(module.FullyQualifiedName)), fileName + ) { + } + } + + public class SymbolProvider : ISymbolReaderProvider { + public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName) { + if (String.IsNullOrWhiteSpace(fileName)) + throw new ArgumentException("Invalid path", "fileName"); + + var pdbPath = Path.Combine( + Path.GetDirectoryName(fileName), + Path.GetFileNameWithoutExtension(fileName) + ".pdb" + ); + var mdbPath = Path.Combine( + Path.GetDirectoryName(fileName), + Path.GetFileName(fileName) + ".mdb" + ); + + if (File.Exists(pdbPath)) { + return (new PdbReaderProvider()).GetSymbolReader(module, File.OpenRead(pdbPath)); + } else if (File.Exists(mdbPath)) { + return (new MdbReaderProvider()).GetSymbolReader(module, fileName); + } else { + throw new NoSymbolsException(module, fileName); + } + } - public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream) { - // Internal constructor for no reason! Thanks! - return (new PdbReaderProvider()).GetSymbolReader(module, symbolStream); - } + public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream) { + // Internal constructor for no reason! Thanks! + return (new PdbReaderProvider()).GetSymbolReader(module, symbolStream); } + } - public class CachingMetadataResolver : MetadataResolver { - public struct Key { - public readonly int HashCode; + public class CachingMetadataResolver : MetadataResolver { + public struct Key { + public readonly int HashCode; - public readonly string Namespace; - public readonly string Name; - public readonly string DeclaringTypeName; + public readonly string Namespace; + public readonly string Name; + public readonly string DeclaringTypeName; - public Key (TypeReference tr) { - Namespace = tr.Namespace; - Name = tr.Name; + public Key(TypeReference tr) { + if (String.IsNullOrEmpty(tr.Namespace)) { + Namespace = tr.Module.Name; + } else { + Namespace = tr.Namespace; + } + Name = tr.Name; - HashCode = Namespace.GetHashCode() ^ Name.GetHashCode(); + HashCode = Namespace.GetHashCode() ^ Name.GetHashCode(); - if (tr.DeclaringType != null) { - DeclaringTypeName = tr.DeclaringType.FullName; - HashCode = HashCode ^ DeclaringTypeName.GetHashCode(); - } else { - DeclaringTypeName = null; - } - } + if (tr.DeclaringType != null) { + DeclaringTypeName = tr.DeclaringType.FullName; + HashCode = HashCode ^ DeclaringTypeName.GetHashCode(); + } else { + DeclaringTypeName = null; + } + } - public bool Equals (Key rhs) { - return (Namespace == rhs.Namespace) && - (DeclaringTypeName == rhs.DeclaringTypeName) && - (Name == rhs.Name); - } + public bool Equals(Key rhs) { + return (Namespace == rhs.Namespace) && + (DeclaringTypeName == rhs.DeclaringTypeName) && + (Name == rhs.Name); + } - public override bool Equals (object obj) { - if (obj is Key) { - return Equals((Key)obj); - } + public override bool Equals(object obj) { + if (obj is Key) { + return Equals((Key)obj); + } - return base.Equals(obj); - } + return base.Equals(obj); + } - public override int GetHashCode() { - return HashCode; - } - } + public override int GetHashCode() { + return HashCode; + } + } - public class KeyComparer : IEqualityComparer { - public bool Equals (Key x, Key y) { - return x.Equals(y); - } + public class KeyComparer : IEqualityComparer { + public bool Equals(Key x, Key y) { + return x.Equals(y); + } - public int GetHashCode (Key obj) { - return obj.HashCode; - } - } + public int GetHashCode(Key obj) { + return obj.HashCode; + } + } - public readonly ConcurrentCache Cache; - protected readonly ConcurrentCache.CreatorFunction DoResolve; + public readonly ConcurrentCache Cache; + protected readonly ConcurrentCache.CreatorFunction DoResolve; - public CachingMetadataResolver (IAssemblyResolver assemblyResolver) : - base(assemblyResolver) { + public CachingMetadataResolver(IAssemblyResolver assemblyResolver) : + base(assemblyResolver) { - Cache = new ConcurrentCache( - Environment.ProcessorCount, 4096, new KeyComparer() - ); + Cache = new ConcurrentCache( + Environment.ProcessorCount, 4096, new KeyComparer() + ); - DoResolve = (key, type) => { - var result = base.Resolve(type); - return result; - }; - } + DoResolve = (key, type) => { + var result = base.Resolve(type); + return result; + }; + } - public override TypeDefinition Resolve (TypeReference type) { - var key = new Key(type); + public override TypeDefinition Resolve(TypeReference type) { + var key = new Key(type); - var result = Cache.GetOrCreate( - key, type, DoResolve - ); + var result = Cache.GetOrCreate( + key, type, DoResolve + ); - return result; - } + return result; } + } - public class FullNameAssemblyComparer : IEqualityComparer { - public bool Equals (AssemblyDefinition x, AssemblyDefinition y) { - return x.FullName.Equals(y.FullName); - } + public class FullNameAssemblyComparer : IEqualityComparer { + public bool Equals(AssemblyDefinition x, AssemblyDefinition y) { + return x.FullName.Equals(y.FullName); + } - public int GetHashCode (AssemblyDefinition obj) { - return obj.FullName.GetHashCode(); - } + public int GetHashCode(AssemblyDefinition obj) { + return obj.FullName.GetHashCode(); } + } - public static class CecilUtil { - // WHY IS CECIL SO DUMB? - public static MethodReference RebindMethod (MethodReference method, TypeReference newDeclaringType, TypeReference newReturnType = null) { - var result = new MethodReference( - method.Name, newReturnType ?? method.ReturnType, newDeclaringType - ) { - HasThis = method.HasThis, - ExplicitThis = method.ExplicitThis - }; + public static class CecilUtil { + // WHY IS CECIL SO DUMB? + public static MethodReference RebindMethod(MethodReference method, TypeReference newDeclaringType, TypeReference newReturnType = null) { + var result = new MethodReference( + method.Name, newReturnType ?? method.ReturnType, newDeclaringType + ) { + HasThis = method.HasThis, + ExplicitThis = method.ExplicitThis + }; - // TODO: Copy more attributes? + // TODO: Copy more attributes? - return result; - } + return result; } + } } From b8caf0b976f5d04d3d26f7e6d566c2b9f49711a9 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Tue, 22 Apr 2014 14:19:10 +0200 Subject: [PATCH 07/16] Proper fix for UnknownMember bug --- JSIL/CILSupport.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/JSIL/CILSupport.cs b/JSIL/CILSupport.cs index a224c7738..e92e0a3f2 100644 --- a/JSIL/CILSupport.cs +++ b/JSIL/CILSupport.cs @@ -147,18 +147,16 @@ public struct Key { public readonly int HashCode; public readonly string Namespace; + public readonly string Module; public readonly string Name; public readonly string DeclaringTypeName; public Key(TypeReference tr) { - if (String.IsNullOrEmpty(tr.Namespace)) { - Namespace = tr.Module.Name; - } else { - Namespace = tr.Namespace; - } + Namespace = tr.Namespace; + Module = tr.Module.Name; Name = tr.Name; - HashCode = Namespace.GetHashCode() ^ Name.GetHashCode(); + HashCode = Namespace.GetHashCode() ^ Name.GetHashCode() ^ Module.GetHashCode(); if (tr.DeclaringType != null) { DeclaringTypeName = tr.DeclaringType.FullName; @@ -169,7 +167,7 @@ public Key(TypeReference tr) { } public bool Equals(Key rhs) { - return (Namespace == rhs.Namespace) && + return (Namespace == rhs.Namespace) && (Module == rhs.Module) && (DeclaringTypeName == rhs.DeclaringTypeName) && (Name == rhs.Name); } From 4c2bbb0bf307a092edc34ac2ae2369181d103596 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Thu, 24 Apr 2014 09:35:05 +0200 Subject: [PATCH 08/16] Merge with sq/JSIL --- Compiler/Profiles/ResourceConverter.cs | 11 +- Libraries/JSIL.Bootstrap.Linq.js | 25 +- Libraries/JSIL.Bootstrap.js | 256 +++++++---- Libraries/JSIL.Core.Reflection.js | 43 +- Libraries/JSIL.Core.Types.js | 26 +- Libraries/JSIL.Core.js | 579 +++++++++++++++--------- Libraries/XNA/Graphics.js | 51 ++- Tests/FailingTestCases/LinqAggregate.cs | 8 + Tests/SimpleTestCases/Issue298.cs | 72 +++ Tests/Tests.csproj | 1 + 10 files changed, 729 insertions(+), 343 deletions(-) create mode 100644 Tests/FailingTestCases/LinqAggregate.cs create mode 100644 Tests/SimpleTestCases/Issue298.cs diff --git a/Compiler/Profiles/ResourceConverter.cs b/Compiler/Profiles/ResourceConverter.cs index 9b72ecc0d..9a54659c4 100644 --- a/Compiler/Profiles/ResourceConverter.cs +++ b/Compiler/Profiles/ResourceConverter.cs @@ -18,7 +18,7 @@ public static void ConvertResources (Configuration configuration, string assembl ConvertSatelliteResources(configuration, assemblyPath, result); } - public static void ConvertEmbeddedResources (Configuration configuration, string assemblyPath, TranslationResult result) { + public static void ConvertEmbeddedResources (Configuration configuration, string assemblyPath, TranslationResult result) { using (var domain = new TemporaryAppDomain("ConvertEmbeddedResources")) { var resourceExtractor = domain.CreateInstanceAndUnwrap< ManifestResourceExtractor, IManifestResourceExtractor @@ -30,7 +30,12 @@ public static void ConvertEmbeddedResources (Configuration configuration, string var encoding = new UTF8Encoding(false); - foreach (var kvp in manifestResources) { + foreach (var kvp in manifestResources) { + var outputPath = Path.GetFileNameWithoutExtension(kvp.Key) + ".resj"; + // FIXME: We're converting embedded resources multiple times per run :( + if (result.Files.ContainsKey(outputPath)) + continue; + Console.WriteLine(kvp.Key); string resourceJson; @@ -41,7 +46,7 @@ public static void ConvertEmbeddedResources (Configuration configuration, string result.AddFile( "Resources", - Path.GetFileNameWithoutExtension(kvp.Key) + ".resj", + outputPath, new ArraySegment(bytes) ); } diff --git a/Libraries/JSIL.Bootstrap.Linq.js b/Libraries/JSIL.Bootstrap.Linq.js index 421b879dd..2c8091032 100644 --- a/Libraries/JSIL.Bootstrap.Linq.js +++ b/Libraries/JSIL.Bootstrap.Linq.js @@ -24,15 +24,24 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerable", true, ["T"], function } ); + function getEnumeratorImpl () { + if (this._getEnumerator !== null) + return this._getEnumerator(); + else + return new (JSIL.AbstractEnumerator.Of(this.T))(this._getNextItem, this._reset, this._dispose); + }; + + $.Method({Static: false, Public: true }, "IEnumerable_GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), []), + getEnumeratorImpl + ) + .Overrides(0, "GetEnumerator"); + $.Method({Static: false, Public: true }, "GetEnumerator", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), []), - function () { - if (this._getEnumerator !== null) - return this._getEnumerator(); - else - return new (JSIL.AbstractEnumerator.Of(this.T))(this._getNextItem, this._reset, this._dispose); - } - ); + getEnumeratorImpl + ) + .Overrides(1, "GetEnumerator"); $.ImplementInterfaces( /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), @@ -294,7 +303,7 @@ JSIL.ImplementExternals( $.Method({Static:true , Public:true }, "ToArray", new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", ["!!0"]), [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"])], ["TSource"]), function (T, enumerable) { - return JSIL.EnumerableToArray(enumerable); + return JSIL.EnumerableToArray(enumerable, T); } ); diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index c7756c2d3..f5a87c7b8 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -691,13 +691,13 @@ JSIL.ImplementExternals( ); JSIL.MakeStaticClass("System.Console", true, [], function ($) { - $.Property({ Static: true, Public: true }, "In"); - $.Property({ Static: true, Public: true }, "Out"); }); JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($) { - $.RawMethod(false, "__CopyMembers__", - function ArrayEnumerator_CopyMembers(source, target) { + var T = new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator"); + + $.RawMethod(false, "__CopyMembers__", + function ArrayEnumerator_CopyMembers (source, target) { target._array = source._array; target._length = source._length; target._index = source._index; @@ -725,13 +725,15 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ this._index = -1; } ); - $.Method({ Public: true, Static: false }, "MoveNext", + + $.Method({Public: true , Static: false}, "MoveNext", new JSIL.MethodSignature(System.Boolean, []), function () { return (++this._index < this._length); } ); - $.Method({ Public: true, Static: false }, "Dispose", + + $.Method({Public: true , Static: false}, "Dispose", new JSIL.MethodSignature(null, []), function () { this._array = null; @@ -739,18 +741,29 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ this._length = -1; } ); - $.Method({ Public: true, Static: false }, "get_Current", + + $.Method({Public: true , Static: false}, "IEnumerator_get_Current", new JSIL.MethodSignature(System.Object, []), function () { return this._array[this._index]; } - ); + ) + .Overrides(1, "get_Current"); - $.Property({ Public: true, Static: false, Virtual: true }, "Current"); + $.Method({Public: true , Static: false}, "get_Current", + new JSIL.MethodSignature(T, []), + function () { + return this._array[this._index]; + } + ) + .Overrides(2, "get_Current"); + + $.Property({Public: true , Static: false, Virtual: true }, "Current"); $.ImplementInterfaces( - System.IDisposable, System.Collections.IEnumerator, - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) + /* 0 */ System.IDisposable, + /* 1 */ System.Collections.IEnumerator, + /* 2 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) ); }); @@ -948,7 +961,7 @@ $jsilcore.$ListExternals = function ($, T, type) { $.Method({ Static: false, Public: true }, ".ctor", new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), function (values) { - this._items = JSIL.EnumerableToArray(values); + this._items = JSIL.EnumerableToArray(values, this.T); this._capacity = this._items.length; this._size = this._items.length; } @@ -1436,7 +1449,7 @@ $jsilcore.$CollectionExternals = function ($) { $.Method({ Static: false, Public: true }, ".ctor", new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), function (list) { - this._items = JSIL.EnumerableToArray(list); + this._items = JSIL.EnumerableToArray(list, this.T); this._capacity = this._size = this._items.length; } ); @@ -2262,20 +2275,52 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function GetEnumerator () { - if (this.tEnumerator === null) { - this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; - } - - return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + var getEnumeratorImpl = function GetEnumerator () { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; } + + return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + }; + + $.Method({Static:false, Public:true }, "GetEnumerator", + (new JSIL.MethodSignature( + mscorlib.TypeRef( + "System.Collections.Generic.Dictionary`2+Enumerator", [ + new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), + new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") + ] + ), [], []) + ), + getEnumeratorImpl ); - $.Method({ Static: false, Public: true }, "set_Item", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function set_Item(key, value) { + $.Method({Static:false, Public:true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], [])), + getEnumeratorImpl + ) + .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + + $.Method({Static:false, Public:true }, "GetEnumerator", + (new JSIL.MethodSignature( + mscorlib.TypeRef( + "System.Collections.Generic.IEnumerator`1", [ + mscorlib.TypeRef( + "System.Collections.Generic.KeyValuePair`2", [ + new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), + new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") + ] + ) + ] + ), [], []) + ), + getEnumeratorImpl + ) + .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); + + $.Method({Static:false, Public:true }, "set_Item", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function set_Item (key, value) { var bucketEntry = this.$searchBucket(key); if (bucketEntry !== null) return bucketEntry.value = value; @@ -2770,8 +2815,8 @@ JSIL.GetEnumerator = function (enumerable, elementType, fallbackMethodInvoke) { return result; }; -JSIL.EnumerableToArray = function (enumerable) { - var e = JSIL.GetEnumerator(enumerable); +JSIL.EnumerableToArray = function (enumerable, elementType) { + var e = JSIL.GetEnumerator(enumerable, elementType); var result = []; var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; @@ -2849,12 +2894,21 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function } ); - $.Method({ Static: false, Public: true }, "get_Current", + $.Method({Static: false, Public: true }, "IEnumerator_get_Current", + new JSIL.MethodSignature($.Object, []), + function () { + return this._current.get(); + } + ) + .Overrides(0, "get_Current"); + + $.Method({Static: false, Public: true }, "get_Current", new JSIL.MethodSignature(T, []), function () { return this._current.get(); } - ); + ) + .Overrides(1, "get_Current"); $.Property({ Static: false, Public: true, Virtual: true }, "Current"); @@ -3330,6 +3384,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", $jsilcore.hashCo JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { var mscorlib = JSIL.GetCorlib(); + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1"); $.Method({ Static: false, Public: true }, ".ctor", (new JSIL.MethodSignature(null, [], [])), @@ -3340,18 +3395,18 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(comparer) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [T])], [])), + function _ctor (comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; } ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(collection) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], [])), + function _ctor (collection) { this._dict = {}; this._count = 0; this._comparer = null; @@ -3359,9 +3414,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({ Static: false, Public: true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor(collection, comparer) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor (collection, comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; @@ -3369,9 +3424,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({ Static: false, Public: true }, "Add", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Add(item) { + $.Method({Static:false, Public:true }, "Add", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Add (item) { var bucketEntry = this.$searchBucket(item); if (bucketEntry !== null) @@ -3383,7 +3438,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { ); $.RawMethod(false, "$addRange", function (enumerable) { - var values = JSIL.EnumerableToArray(enumerable); + var values = JSIL.EnumerableToArray(enumerable, this.T); for (var i = 0; i < values.length; i++) this.Add(values[i]); @@ -3397,9 +3452,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({ Static: false, Public: true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Contains(item) { + $.Method({Static:false, Public:true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Contains (item) { return this.$searchBucket(item) !== null; } ); @@ -3411,53 +3466,74 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({ Static: false, Public: true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), - function Remove(item) { + $.Method({Static:false, Public:true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Remove (item) { return this.$removeByKey(item); } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), - function GetEnumerator () { - var dict = this._dict; - - return new (JSIL.AbstractEnumerator.Of(this.T))( - function getNext(result) { - var keys = this._state.keys; - var valueIndex = ++(this._state.valueIndex); - var bucketIndex = this._state.bucketIndex; - - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[this._state.bucketIndex]; - var bucket = dict[bucketKey]; - - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - result.set(bucket[valueIndex].key); - return true; - } else { - bucketIndex = ++(this._state.bucketIndex); - valueIndex = 0; - } - } + var getEnumeratorImpl = function GetEnumerator () { + var dict = this._dict; - return false; - }, - function reset() { - this._state = { - current: JSIL.DefaultValue(this.T), - keys: Object.keys(dict), - bucketIndex: 0, - valueIndex: -1 - }; - }, - function dispose() { - this._state = null; + // FIXME: Return an actual instance of HashSet`1+Enumerator. + return new (JSIL.AbstractEnumerator.Of(this.T)) ( + function getNext (result) { + var keys = this._state.keys; + var valueIndex = ++(this._state.valueIndex); + var bucketIndex = this._state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[this._state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + result.set(bucket[valueIndex].key); + return true; + } else { + bucketIndex = ++(this._state.bucketIndex); + valueIndex = 0; + } } - ); - } - ); + + return false; + }, + function reset () { + this._state = { + current: JSIL.DefaultValue(this.T), + keys: Object.keys(dict), + bucketIndex: 0, + valueIndex: -1 + }; + }, + function dispose () { + this._state = null; + } + ); + }; + + $.Method({Static:false, Public:true }, "GetEnumerator", + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.Generic.HashSet`1+Enumerator", [T]), [], [] + ), + getEnumeratorImpl + ) + + $.Method({Static:false, Public:true }, "GetEnumerator", + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], [] + ), + getEnumeratorImpl + ) + .Overrides(0, "GetEnumerator"); + + $.Method({Static:false, Public:true }, "GetEnumerator", + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.IEnumerator", []), [], [] + ), + getEnumeratorImpl + ) + .Overrides(1, "GetEnumerator"); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, ["T"], function ($) { @@ -3471,6 +3547,16 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, [" ); }); +JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.HashSet`1+Enumerator", false, ["T"], function ($) { + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1+Enumerator"); + + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IEnumerator") + ); +}); + JSIL.MakeEnum( "System.Globalization.NumberStyles", true, { None: 0, diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index f9fa999a1..d22c83465 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -196,9 +196,7 @@ JSIL.ImplementExternals( function () { return JSIL.GetMembersInternal( this, - System.Reflection.BindingFlags.Instance | - System.Reflection.BindingFlags.Static | - System.Reflection.BindingFlags.Public + defaultFlags() ); } ); @@ -212,16 +210,22 @@ JSIL.ImplementExternals( } ); - var getMethodImpl = function (type, name, flags, argumentTypes) { + var getMatchingMethodsImpl = function (type, name, flags, argumentTypes, returnType, allMethods) { var methods = JSIL.GetMembersInternal( - type, flags, "MethodInfo", name + type, flags, allMethods ? "$AllMethods" : "MethodInfo", name ); if (argumentTypes) - JSIL.$FilterMethodsByArgumentTypes(methods, argumentTypes); + JSIL.$FilterMethodsByArgumentTypes(methods, argumentTypes, returnType); JSIL.$ApplyMemberHiding(type, methods, type.__PublicInterface__.prototype); + return methods; + } + + var getMethodImpl = function (type, name, flags, argumentTypes) { + var methods = getMatchingMethodsImpl(type, name, flags, argumentTypes); + if (methods.length > 1) { throw new System.Exception("Multiple methods named '" + name + "' were found."); } else if (methods.length < 1) { @@ -231,6 +235,16 @@ JSIL.ImplementExternals( return methods[0]; }; + $.RawMethod(false, "$GetMatchingInstanceMethods", function (name, argumentTypes, returnType) { + var bindingFlags = $jsilcore.BindingFlags; + var flags = bindingFlags.Public | bindingFlags.NonPublic | bindingFlags.Instance; + + return getMatchingMethodsImpl( + this, name, flags, + argumentTypes, returnType, true + ); + }); + $.Method({Public: true , Static: false}, "GetMethod", new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.MethodInfo"), [$.String]), function (name) { @@ -452,7 +466,10 @@ JSIL.ImplementExternals( }; var defaultFlags = function () { - return System.Reflection.BindingFlags.$Flags("Public", "Instance", "Static"); + var bindingFlags = $jsilcore.BindingFlags; + var result = bindingFlags.Public | bindingFlags.Instance | bindingFlags.Static; + return result; + // return System.Reflection.BindingFlags.$Flags("Public", "Instance", "Static"); }; $.Method({Public: true , Static: false}, "GetField", @@ -508,7 +525,7 @@ JSIL.ImplementExternals( $.Method({ Public: true, Static: false }, "GetInterfaces", new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Type]), []), function () { - return this.__Interfaces__; + return JSIL.GetInterfacesImplementedByType(this); } ); } @@ -590,7 +607,15 @@ JSIL.ImplementExternals( (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Type")]), [], [])), function GetParameterTypes () { var signature = this._data.signature; - return signature.argumentTypes; + var argumentTypes = signature.argumentTypes; + var result = []; + + for (var i = 0, l = argumentTypes.length; i < l; i++) { + var argumentType = argumentTypes[i]; + result.push(signature.ResolveTypeReference(argumentType)[1]); + } + + return result; } ); diff --git a/Libraries/JSIL.Core.Types.js b/Libraries/JSIL.Core.Types.js index 5675b8e5f..5a917e8d4 100644 --- a/Libraries/JSIL.Core.Types.js +++ b/Libraries/JSIL.Core.Types.js @@ -216,7 +216,8 @@ JSIL.MakeInterface( "System.Collections.IDictionaryEnumerator", true, [], function ($) { $.Method({}, "get_Key", new JSIL.MethodSignature($.Object, [], [])); $.Method({}, "get_Value", new JSIL.MethodSignature($.Object, [], [])); - $.Method({}, "get_Entry", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.DictionaryEntry"), [], [])); + // FIXME + // $.Method({}, "get_Entry", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.DictionaryEntry"), [], [])); $.Property({}, "Key"); $.Property({}, "Value"); $.Property({}, "Entry"); @@ -592,3 +593,26 @@ JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Attribute", true, [], } ); }); + +JSIL.MakeEnum( + "System.TypeCode", true, { + Empty: 0, + Object: 1, + DBNull: 2, + Boolean: 3, + Char: 4, + SByte: 5, + Byte: 6, + Int16: 7, + UInt16: 8, + Int32: 9, + UInt32: 10, + Int64: 11, + UInt64: 12, + Single: 13, + Double: 14, + Decimal: 15, + DateTime: 16, + String: 18 + }, false +); diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 5953e3e82..6b5369a7c 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -1289,8 +1289,8 @@ JSIL.AttributeRecord = function (context, type, getConstructorArguments, initial this.initializer = initializer; }; -JSIL.OverrideRecord = function (interfaceIndex, interfaceMemberName) { - this.interfaceIndex = interfaceIndex; +JSIL.OverrideRecord = function (interfaceIndexOrName, interfaceMemberName) { + this.interfaceIndexOrName = interfaceIndexOrName; this.interfaceMemberName = interfaceMemberName; }; @@ -1469,7 +1469,7 @@ JSIL.GenericParameter.prototype.out = function () { }; JSIL.GenericParameter.prototype.get = function (context) { - if ((typeof (context) !== "object") && (typeof (context) !== "function")) { + if (!context) { JSIL.RuntimeError("No context provided when resolving generic parameter '" + this.name + "'"); return JSIL.AnyType; } @@ -1498,6 +1498,8 @@ JSIL.GenericParameter.prototype.get_Name = function () { return this.name.humanReadable; }; +JSIL.GenericParameter.prototype.__IsClosed__ = false; + JSIL.PositionalGenericParameter = function (name, context) { this.index = parseInt(name.substr(2)); @@ -1548,6 +1550,9 @@ JSIL.PositionalGenericParameter.prototype.get_Name = function () { return "!!" + this.index; }; +JSIL.PositionalGenericParameter.prototype.__IsClosed__ = false; + + JSIL.TypeRef = function (context, name, genericArguments) { if (arguments.length === 1) { this.context = null; @@ -2005,7 +2010,7 @@ JSIL.$ResolveGenericTypeReferenceInternal = function (obj, context) { return new JSIL.TypeRef(obj.context, obj.typeName, resolvedGa); else return null; - } else if (!obj.__IsClosed__) { + } else if (obj.__IsClosed__ === false) { if (obj.__IsArray__) { var elementType = JSIL.$ResolveGenericTypeReferenceInternal(obj.__ElementType__, context); if (elementType !== null) @@ -2032,7 +2037,10 @@ JSIL.$ResolveGenericTypeReferenceInternal = function (obj, context) { ); if (!closedParameters[i]) { - if ((Object.getPrototypeOf(existingParameters[i]) === JSIL.GenericParameter.prototype) || (!existingParameters[i].__IsClosed__)) { + if ( + (Object.getPrototypeOf(existingParameters[i]) === JSIL.GenericParameter.prototype) || + (existingParameters[i].__IsClosed__ === false) + ) { if (JSIL.WarnAboutGenericResolveFailures) JSIL.Host.warning("Failed to resolve generic parameter #" + i + " of type reference '" + obj.toString() + "'."); @@ -2249,33 +2257,50 @@ $jsilcore.$Of$NoInitialize = function () { unresolvedBaseType = typeObject.__BaseType__; var resolvedBaseType = unresolvedBaseType; + var resolveContext = null; - if (typeof (staticClassObject.prototype) !== "undefined") { - var resolveContext = JSIL.CreatePrototypeObject(staticClassObject.prototype); - for (var i = 0; i < resolvedArguments.length; i++) { - gaNames[i].set(resolveContext, resolvedArguments[i]); - } + if (staticClassObject.prototype) { + resolveContext = JSIL.CreatePrototypeObject(staticClassObject.prototype); + } else { + resolveContext = JSIL.CreateSingletonObject(null); + } - // We need to resolve any generic arguments contained in the base type so that the base type of a closed generic type is also closed. - // thus, given Derived : Base and Base : Object, Derived.BaseType must be Base, not Base. - resolvedBaseType = JSIL.$ResolveGenericTypeReferenceInternal(resolvedBaseType, resolveContext); - if (!resolvedBaseType) { - resolvedBaseType = unresolvedBaseType; - } + for (var i = 0; i < resolvedArguments.length; i++) { + gaNames[i].set(resolveContext, resolvedArguments[i]); + } - JSIL.$ResolveGenericTypeReferences(typeObject, resolvedArguments); + // We need to resolve any generic arguments contained in the base type so that the base type of a closed generic type is also closed. + // thus, given Derived : Base and Base : Object, Derived.BaseType must be Base, not Base. + resolvedBaseType = JSIL.$ResolveGenericTypeReferenceInternal(resolvedBaseType, resolveContext); + if (!resolvedBaseType) { + resolvedBaseType = unresolvedBaseType; } + JSIL.$ResolveGenericTypeReferences(typeObject, resolvedArguments); + var resultTypeObject = JSIL.CreateSingletonObject(typeObject); + // Since .Of() will now be called even for open types, we need to ensure that we flag + // the type as open if it has any unresolved generic parameters. + var isClosed = true; + for (var i = 0, l = arguments.length; i < l; i++) { + if (Object.getPrototypeOf(resolvedArguments[i]) === JSIL.GenericParameter.prototype) + isClosed = false; + else if (resolvedArguments[i].__IsClosed__ === false) + isClosed = false; + } + resultTypeObject.__IsClosed__ = isClosed; + var constructor; - if (typeObject.IsInterface) + if (typeObject.IsInterface) { constructor = function Interface__ctor () { JSIL.RuntimeError("Cannot construct an instance of an interface"); }; - else + + } else { constructor = JSIL.MakeTypeConstructor(resultTypeObject, typeObject.__MaxConstructorArguments__); + } resultTypeObject.__PublicInterface__ = result = constructor; resultTypeObject.__OpenType__ = typeObject; @@ -2287,7 +2312,7 @@ $jsilcore.$Of$NoInitialize = function () { // Prevents recursion when Of is called indirectly during initialization of the new closed type ofCache[cacheKey] = result; - if (typeof (staticClassObject.prototype) !== "undefined") { + if (staticClassObject.prototype) { // Given Derived : Base and Base : Object, the prototype of Derived instances must have this chain: // Derived -> Base -> Object, not: // Derived -> Derived -> Base -> Object @@ -2380,6 +2405,35 @@ $jsilcore.$Of$NoInitialize = function () { var interfaces = resultTypeObject.__Interfaces__ = []; var sourceInterfaces = typeObject.__Interfaces__; + var writeGenericArgument = function (key, name, resolvedArgument) { + var getter = function GetGenericArgument () { + return name.get(this); + } + + var decl = { + configurable: true, + enumerable: true, + value: resolvedArgument + }; + var getterDecl = { + configurable: true, + enumerable: true, + get: getter + }; + + name.defineProperty(result, decl); + + if (key) + Object.defineProperty(result, key, getterDecl); + + if (result.prototype) { + name.defineProperty(result.prototype, decl); + + if (key) + Object.defineProperty(result.prototype, key, getterDecl); + } + }; + for (var i = 0, l = sourceInterfaces.length; i < l; i++) { var unresolvedInterface = sourceInterfaces[i]; var resolvedInterface = JSIL.$ResolveGenericTypeReferenceInternal(unresolvedInterface, resolveContext); @@ -2392,48 +2446,28 @@ $jsilcore.$Of$NoInitialize = function () { continue; interfaces.push(resolvedInterface); + + if (resolvedInterface !== unresolvedInterface) { + var resolvedInterfaceTypeObj = JSIL.ResolveTypeReference(resolvedInterface)[1]; + var names = resolvedInterfaceTypeObj.__OpenType__.__GenericArgumentNames__; + + for (var j = 0, l2 = names.length; j < l2; j++) { + var name = names[j]; + var value = resolvedInterfaceTypeObj.__GenericArgumentValues__[j]; + writeGenericArgument(null, name, value); + } + } } for (var i = 0, l = resolvedArguments.length; i < l; i++) { var key = ga[i]; var name = new JSIL.Name(key, resultTypeObject.__FullNameWithoutArguments__); - var makeGetter = function (_name) { - return function GetGenericArgument () { - return _name.get(this); - } - }; - - var decl = { - configurable: true, - enumerable: true, - value: resolvedArguments[i] - }; - var getterDecl = { - configurable: true, - enumerable: true, - get: makeGetter(name) - }; - - name.defineProperty(result, decl); - Object.defineProperty(result, key, getterDecl); - - if (typeof (staticClassObject.prototype) !== "undefined") { - name.defineProperty(result.prototype, decl); - Object.defineProperty(result.prototype, key, getterDecl); - } + writeGenericArgument(key, name, resolvedArguments[i]); } - // Since .Of() will now be called even for open types, we need to ensure that we flag - // the type as open if it has any unresolved generic parameters. - var isClosed = true; - for (var i = 0, l = arguments.length; i < l; i++) { - if (Object.getPrototypeOf(resolvedArguments[i]) === JSIL.GenericParameter.prototype) - isClosed = false; - else if (resolvedArguments[i].__IsClosed__ === false) - isClosed = false; - } - resultTypeObject.__IsClosed__ = isClosed; + if (typeObject.IsInterface) + JSIL.CopyObjectValues(resolveContext, result.prototype, false); if (isClosed) { resultTypeObject.__AssignableFromTypes__ = {}; @@ -2496,6 +2530,12 @@ JSIL.$ResolveGenericMethodSignature = function (typeObject, signature, resolveCo if (changed) return new JSIL.MethodSignature(returnType[0], argumentTypes, genericArgumentNames, typeObject.__Context__, signature); + /* + if (!signature.IsClosed) { + console.log("Resolving failed for open signature", signature, "with context", resolveContext); + } + */ + return null; }; @@ -2544,6 +2584,7 @@ JSIL.RenameGenericMethods = function (publicInterface, typeObject) { var rm = typeObject.__RenamedMethods__; var trace = false; + var throwOnFail = false; var isInterface = typeObject.IsInterface; @@ -2573,6 +2614,17 @@ JSIL.RenameGenericMethods = function (publicInterface, typeObject) { if (!oldObject) JSIL.RuntimeError("Failed to find unrenamed generic interface method"); + if (!signature.IsClosed) { + genericSignature = signature; + signature = JSIL.$ResolveGenericMethodSignature( + typeObject, genericSignature, resolveContext + ); + + if (!signature && throwOnFail) { + JSIL.RuntimeError("Failed to resolve generic signature", genericSignature); + } + } + var newObject = oldObject.Rebind(typeObject, signature); JSIL.SetValueProperty(publicInterface, unqualifiedName, newObject); @@ -2674,29 +2726,42 @@ JSIL.InstantiateProperties = function (publicInterface, typeObject) { } }; +$jsilcore.CanFixUpEnumInterfaces = false; + JSIL.FixupInterfaces = function (publicInterface, typeObject) { var trace = false; - var interfaces = typeObject.__Interfaces__; - if (!JSIL.IsArray(interfaces)) + if (typeObject.__FullName__ === "System.Enum") { + if (!$jsilcore.CanFixUpEnumInterfaces) + return; + else + /* trace = true */; + } + + // FIXME: Is this right? I think it might be. We don't actually use the types, + // just use their type objects as tokens for comparisons. + if (typeObject.__IsFixingUpInterfaces__) return; if (typeObject.IsInterface) return; + var interfaces = JSIL.GetInterfacesImplementedByType(typeObject); + if (!interfaces.length) return; + typeObject.__IsFixingUpInterfaces__ = true; + var context = typeObject.__Context__; var typeName = typeObject.__FullName__; var missingMembers = []; + var ambiguousMembers = []; var typeMembers = JSIL.GetMembersInternal(typeObject, $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public")); var resolveContext = typeObject.__IsStatic__ ? publicInterface : publicInterface.prototype; - var namePairs = [[null, null], [null, null]]; - __interfaces__: for (var i = 0, l = interfaces.length; i < l; i++) { var iface = interfaces[i]; @@ -2746,118 +2811,92 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { // In cases where an interface method (IInterface_MethodName) is implemented by a regular method // (MethodName), we make a copy of the regular method with the name of the interface method, so // that attempts to directly invoke the interface method will still work. - var members = JSIL.GetMembersInternal(iface, $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public")); + var members = JSIL.GetMembersInternal( + iface, + $jsilcore.BindingFlags.$Flags("DeclaredOnly", "Instance", "NonPublic", "Public") + ); var proto = publicInterface.prototype; var escapedLocalName = JSIL.EscapeName(ifaceLocalName); - __members__: - for (var j = 0; j < members.length; j++) { - var member = members[j]; - - namePairs[0][0] = member._descriptor.EscapedName; - namePairs[0][1] = JSIL.$GetSignaturePrefixForType(iface) + member._descriptor.EscapedName; - - if (member._data.signature) { - var signature = member._data.signature; - - namePairs[1][0] = signature.GetKey(namePairs[0][0]); - namePairs[1][1] = signature.GetKey(namePairs[0][1]); - namePairs[0][1] = signature.GetKey(namePairs[0][1]); - - if (trace) - console.log(signature.toString(member._descriptor.EscapedName), namePairs[1][1]); - } else { - namePairs[1][0] = null; - namePairs[1][1] = null; - } - - var isMissing = false; - - namePairs.forEach(function (namePair) { - var shortName = namePair[0]; - var qualifiedName = namePair[1]; + var hasOwn = function (name) { + return Object.prototype.hasOwnProperty.call(proto, name); + }; - if (!shortName) - return; + var hasNonPlaceholder = function (obj, name) { + var value = obj[name]; + if ((typeof (value) === "undefined") || + (value === null)) + return false; - if (trace) - console.log(shortName, qualifiedName); + if (value.__IsPlaceholder__) + return false; - var hasShort = proto.hasOwnProperty(shortName); - var hasQualified = proto.hasOwnProperty(qualifiedName); + return true; + } - var hasShortRecursive = JSIL.HasOwnPropertyRecursive(proto, shortName); - var hasQualifiedRecursive = JSIL.HasOwnPropertyRecursive(proto, qualifiedName); + __members__: + for (var j = 0; j < members.length; j++) { + var member = members[j]; + var qualifiedName = JSIL.$GetSignaturePrefixForType(iface) + member._descriptor.EscapedName; + var signature = member._data.signature || null; + var signatureQualifiedName = null; - switch (member.__MemberType__) { - case "MethodInfo": - case "ConstructorInfo": - var shortImpl = proto[shortName]; - var qualifiedImpl = proto[qualifiedName]; - break; + if (signature) { + signatureQualifiedName = signature.GetKey(qualifiedName); + } - case "PropertyInfo": - var shortImpl = JSIL.GetOwnPropertyDescriptorRecursive(proto, shortName); - var qualifiedImpl = JSIL.GetOwnPropertyDescriptorRecursive(proto, qualifiedName); - break; + if (signature + && hasNonPlaceholder(proto, signatureQualifiedName) + && hasOwn(signatureQualifiedName) + ) + continue; - default: - // FIXME - return; - } + if ( + hasNonPlaceholder(proto, qualifiedName) + && hasOwn(qualifiedName) + ) + continue; - if ((typeof (shortImpl) === "undefined") || (shortImpl === null)) - hasShortRecursive = hasShort = false; + var isMissing = false, isAmbiguous = false; - if ((typeof (qualifiedImpl) === "undefined") || (qualifiedImpl === null)) - hasQualifiedRecursive = hasQualified = false; + switch (member.__MemberType__) { + case "MethodInfo": + case "ConstructorInfo": + // FIXME: Match signatures + var matchingMethods = typeObject.$GetMatchingInstanceMethods( + member.get_Name(), member.GetParameterTypes(), member.get_ReturnType() + ); - if ( - hasShortRecursive && - (typeof(shortImpl.__IsPlaceholder__) !== "undefined") && - shortImpl.__IsPlaceholder__ != false - ) { - hasShortRecursive = hasShort = false; - } + if (matchingMethods.length === 0) { + isMissing = true; + } else if (matchingMethods.length > 1) { + isAmbiguous = true; + } else { + var implementation = matchingMethods[0]; - if ( - hasQualifiedRecursive && - (typeof(qualifiedImpl.__IsPlaceholder__) !== "undefined") && - qualifiedImpl.__IsPlaceholder__ != false - ) { - hasQualifiedRecursive = hasQualified = false; - } + var sourceQualifiedName = implementation._data.signature.GetKey(implementation._descriptor.EscapedName); - if (!hasShortRecursive && !hasQualifiedRecursive) { - isMissing = true; - return; - } + if (trace) + console.log(typeName + "::" + signatureQualifiedName + " (" + iface + ") = " + sourceQualifiedName); - if ((!hasQualified && hasShort) || (!hasQualifiedRecursive && hasShortRecursive)) { - if (trace) - console.log(qualifiedName, "->", shortName); + JSIL.SetLazyValueProperty( + proto, signatureQualifiedName, + JSIL.MakeInterfaceMemberGetter(proto, sourceQualifiedName) + ); + } - switch (member.__MemberType__) { - case "MethodInfo": - case "ConstructorInfo": - JSIL.SetLazyValueProperty(proto, qualifiedName, JSIL.MakeInterfaceMemberGetter(proto, shortName)); - JSIL.SetLazyValueProperty(proto, qualifiedName, JSIL.MakeInterfaceMemberGetter(proto, shortName)); - break; + break; - case "PropertyInfo": - Object.defineProperty(proto, qualifiedName, shortImpl); - break; - } - } else { - if (trace) - console.log("Skipping " + qualifiedName); - } - }); + default: + // FIXME: Not implemented + break; + } if (isMissing) - missingMembers.push(namePairs[0][1]); - + missingMembers.push(signatureQualifiedName || qualifiedName); + else if (isAmbiguous) + ambiguousMembers.push(signatureQualifiedName || qualifiedName); } if (interfaces.indexOf(iface) < 0) @@ -2883,32 +2922,41 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { for (var j = 0; j < overrides.length; j++) { var override = overrides[j]; var iface = null; - switch (typeof (override.interfaceIndex)) { + + switch (typeof (override.interfaceIndexOrName)) { case "string": // If the index is a string, search all the interfaces implemented by this type for a substring match. // FIXME: If there are multiple matches this picks the first one. Probably not great... for (var k = 0; k < interfaces.length; k++) { - if (interfaces[k].__FullName__.indexOf(override.interfaceIndex) >= 0) { + if (interfaces[k].__FullName__.indexOf(override.interfaceIndexOrName) >= 0) { iface = interfaces[k]; break; } } + if (iface === null) + JSIL.RuntimeError("Interface index '" + override.interfaceIndexOrName + "' does not match any interfaces"); + break; case "number": - iface = interfaces[override.interfaceIndex]; + iface = interfaces[override.interfaceIndexOrName]; break; } if (!iface) - JSIL.RuntimeError("Member '" + member._descriptor.EscapedName + "' overrides nonexistent interface of type '" + typeObject.__FullName__ + "' with index '" + override.interfaceIndex + "'"); + JSIL.RuntimeError("Member '" + member._descriptor.EscapedName + "' overrides nonexistent interface of type '" + typeObject.__FullName__ + "' with index '" + override.interfaceIndexOrName + "'"); var interfaceQualifiedName = JSIL.$GetSignaturePrefixForType(iface) + JSIL.EscapeName(override.interfaceMemberName); var key = member._data.signature.GetKey(interfaceQualifiedName); - if (trace) - console.log(key, "->", member._descriptor.EscapedName); + var missingIndex = missingMembers.indexOf(key); + if (missingIndex >= 0) + missingMembers.splice(missingIndex, 1); + + if (trace) { + console.log("Overrides set " + typeName + "::" + key + " (#" + override.interfaceIndexOrName + "=" + iface + ") = " + member._descriptor.EscapedName); + } // Important: This may overwrite an existing member with this key, from an automatic interface fixup // like 'Foo.GetEnumerator' -> 'Foo.Ixx$GetEnumerator'. @@ -2922,6 +2970,13 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { if ((JSIL.SuppressInterfaceWarnings !== true) || trace) JSIL.Host.warning("Type '" + typeObject.__FullName__ + "' is missing implementation of interface member(s): " + missingMembers.join(", ")); } + + if (ambiguousMembers.length > 0) { + if ((JSIL.SuppressInterfaceWarnings !== true) || trace) + JSIL.Host.warning("Type '" + typeObject.__FullName__ + "' has ambiguous implementation of interface member(s): " + ambiguousMembers.join(", ")); + } + + typeObject.__IsFixingUpInterfaces__ = false; }; JSIL.GetFieldList = function (typeObject) { @@ -3108,11 +3163,16 @@ JSIL.InitializeInstanceFields = function (instance, typeObject) { fi(instance); }; -JSIL.CopyObjectValues = function (source, target) { +JSIL.CopyObjectValues = function (source, target, allowOverwrite) { for (var k in source) { - if (!source.hasOwnProperty(k)) + if (!Object.prototype.hasOwnProperty.call(source, k)) continue; + if (allowOverwrite === false) { + if (k in target) + continue; + } + target[k] = source[k]; } }; @@ -3258,7 +3318,7 @@ JSIL.$MakeMemberwiseCloner = function (typeObject, publicInterface) { }; JSIL.$BuildFieldList = function (typeObject) { - if (!typeObject.__IsClosed__) + if (typeObject.__IsClosed__ === false) return; var bindingFlags = $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public"); @@ -4034,7 +4094,9 @@ JSIL.InitializeType = function (type) { JSIL.InstantiateProperties(classObject, typeObject); if (typeObject.IsInterface !== true) { - JSIL.FixupInterfaces(classObject, typeObject); + JSIL.QueueTypeInitializer(typeObject, function () { + JSIL.FixupInterfaces(classObject, typeObject); + }); JSIL.RebindRawMethods(classObject, typeObject); } @@ -4807,6 +4869,12 @@ JSIL.$MakeOptimizedNumericSwitch = function (output, variableName, cases, defaul }; JSIL.MakeTypeConstructor = function (typeObject, maxConstructorArguments) { + if (typeObject.__IsClosed__ === false) { + return function () { + JSIL.RuntimeError("Cannot create an instance of an open type"); + }; + } + var ctorClosure = { typeObject: typeObject, fieldInitializer: $jsilcore.FunctionNotInitialized, @@ -5024,9 +5092,7 @@ JSIL.MakeType = function (typeArgs, initializer) { } typeObject._IsAssignableFrom = function (typeOfValue) { - //if (typeOfValue.__AssignableTypes__ != null) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; - //} + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; }; for (var i = 0, l = typeObject.__GenericArguments__.length; i < l; i++) { @@ -5138,8 +5204,10 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer typeObject.__FullName__ = fullName; typeObject.__TypeInitialized__ = false; - if (interfaces && interfaces.length) - JSIL.$CopyInterfaceMethods(interfaces, publicInterface); + if (interfaces && interfaces.length) { + // FIXME: This seems wrong. + // JSIL.$CopyInterfaceMethods(interfaces, publicInterface); + } JSIL.FillTypeObjectGenericArguments(typeObject, genericArguments); @@ -5163,10 +5231,7 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer } typeObject._IsAssignableFrom = function (typeOfValue) { - if (typeOfValue.__AssignableTypes__ != null) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; - } - return false; + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; }; JSIL.MakeCastMethods(publicInterface, typeObject, "interface"); @@ -5350,7 +5415,21 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { // memory usage. var valueCache = {}; + var fixedUpEnumInterfaces = false; + publicInterface.$MakeValue = function (value, name) { + // HACK: Letting System.Enum's interfaces get fixed up normally causes a cycle. + if (!fixedUpEnumInterfaces) { + fixedUpEnumInterfaces = true; + + if (!$jsilcore.CanFixUpEnumInterfaces) { + $jsilcore.CanFixUpEnumInterfaces = true; + JSIL.FixupInterfaces($jsilcore.System.Enum, $jsilcore.System.Enum.__Type__); + JSIL.RunStaticConstructors(publicInterface, typeObject); + JSIL.FixupInterfaces(publicInterface, typeObject); + } + } + var result = valueCache[value]; if (!result) @@ -5390,7 +5469,14 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { $.__Type__.__Names__.push(key); $.__Type__.__ValueToName__[value] = key; - $[key] = $.$MakeValue(value, key); + + var makeGetter = function (key, value) { + return function () { + return $.$MakeValue(value, key); + } + }; + + JSIL.SetLazyValueProperty($, key, makeGetter(key, value)); var descriptor = ib.ParseDescriptor({Public: true, Static: true}, key); var mb = new JSIL.MemberBuilder(context); @@ -5404,7 +5490,7 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { // FIXME: This is doing FixupInterfaces on Enum every time instead of on the specific enum type. // Should be harmless, but...? - JSIL.FixupInterfaces(enumType.__PublicInterface__, enumType); + // JSIL.FixupInterfaces(enumType.__PublicInterface__, enumType); JSIL.MakeCastMethods($, $.__Type__, "enum"); }; @@ -5666,8 +5752,8 @@ JSIL.MemberBuilder.prototype.Attribute = function (attributeType, getConstructor return this; }; -JSIL.MemberBuilder.prototype.Overrides = function (interfaceIndex, interfaceMemberName) { - var record = new JSIL.OverrideRecord(interfaceIndex, interfaceMemberName); +JSIL.MemberBuilder.prototype.Overrides = function (interfaceIndexOrName, interfaceMemberName) { + var record = new JSIL.OverrideRecord(interfaceIndexOrName, interfaceMemberName); this.overrides.push(record); return this; @@ -6164,7 +6250,8 @@ JSIL.InterfaceBuilder.prototype.ExternalMethod = function (_descriptor, methodNa mangledName: mangledName, isExternal: true, isPlaceholder: isPlaceholder, - isConstructor: isConstructor + isConstructor: isConstructor, + parameterInfo: memberBuilder.parameterInfo }, memberBuilder, true); return memberBuilder; @@ -6216,8 +6303,10 @@ JSIL.InterfaceBuilder.prototype.Method = function (_descriptor, methodName, sign var mangledName = signature.GetKey(descriptor.EscapedName); + var memberBuilder = new JSIL.MemberBuilder(this.context); + if (this.typeObject.IsInterface) { - var methodObject = new JSIL.InterfaceMethod(this.typeObject, descriptor.EscapedName, signature); + var methodObject = new JSIL.InterfaceMethod(this.typeObject, descriptor.EscapedName, signature, memberBuilder.parameterInfo); JSIL.SetValueProperty(descriptor.Target, mangledName, methodObject); @@ -6235,8 +6324,6 @@ JSIL.InterfaceBuilder.prototype.Method = function (_descriptor, methodName, sign var isConstructor = (descriptor.EscapedName === "_ctor"); var memberTypeName = isConstructor ? "ConstructorInfo" : "MethodInfo"; - var memberBuilder = new JSIL.MemberBuilder(this.context); - this.PushMember(memberTypeName, descriptor, { signature: signature, genericSignature: null, @@ -6308,7 +6395,8 @@ JSIL.InterfaceBuilder.prototype.InheritBaseMethod = function (name) { mangledName: mangledName, isExternal: false, isConstructor: isConstructor, - isInherited: true + isInherited: true, + parameterInfo: memberBuilder.parameterInfo }, memberBuilder); return memberBuilder; @@ -6464,7 +6552,7 @@ JSIL.MethodSignature.$EmitInvocation = function ( body, callText, thisReferenceArg, prefix, argumentTypes, genericArgumentNames, isInterface ) { var comma; - var needsBindingForm = (isInterface) && (genericArgumentNames) && (genericArgumentNames.length); + var needsBindingForm = false; if (genericArgumentNames) comma = (genericArgumentNames.length + argumentTypes.length) > 0 ? "," : ""; @@ -6552,8 +6640,7 @@ JSIL.MethodSignature.prototype.$MakeCallMethod = function (callMethodType) { } body.push(""); - if (callMethodType === "interface") { - } else if (genericArgumentNames.length > 0) { + if (genericArgumentNames.length > 0) { body.push("if (!ga || ga.length !== " + genericArgumentNames.length + ")"); body.push(" throw new Error('Invalid number of generic arguments');"); body.push("JSIL.ResolveTypeArgumentArray(ga);"); @@ -6609,6 +6696,19 @@ JSIL.MethodSignature.prototype.get_Hash = function () { return this._hash = hash; }; +JSIL.MethodSignature.prototype.get_IsClosed = function () { + if (this.returnType && (this.returnType.__IsClosed__ === false)) + return false; + + for (var i = 0, l = this.argumentTypes.length; i < l; i++) { + var at = this.argumentTypes[i]; + if (at.__IsClosed__ === false) + return false; + } + + return true; +}; + Object.defineProperty(JSIL.MethodSignature.prototype, "GenericSuffix", { configurable: false, enumerable: true, @@ -6621,6 +6721,12 @@ Object.defineProperty(JSIL.MethodSignature.prototype, "Hash", { get: JSIL.MethodSignature.prototype.get_Hash }); +Object.defineProperty(JSIL.MethodSignature.prototype, "IsClosed", { + configurable: false, + enumerable: true, + get: JSIL.MethodSignature.prototype.get_IsClosed +}); + JSIL.ConstructorSignature = function (type, argumentTypes, context) { this._lastKeyName = ""; @@ -6708,7 +6814,7 @@ JSIL.ConstructorSignature.prototype.$MakeConstructMethod = function () { var publicInterface = typeObject.__PublicInterface__; var argumentTypes = this.argumentTypes; - if (!typeObject.__IsClosed__) + if (typeObject.__IsClosed__ === false) return function () { throw new Error("Cannot create an instance of an open type"); }; @@ -6828,11 +6934,12 @@ JSIL.ResolvedMethodSignature.prototype.toString = function () { }; -JSIL.InterfaceMethod = function (typeObject, methodName, signature) { +JSIL.InterfaceMethod = function (typeObject, methodName, signature, parameterInfo) { this.typeObject = typeObject; this.variantGenericArguments = JSIL.$FindVariantGenericArguments(typeObject); this.methodName = methodName; this.signature = signature; + this.parameterInfo = parameterInfo; this.qualifiedName = JSIL.$GetSignaturePrefixForType(typeObject) + this.methodName; this.variantInvocationCandidateCache = JSIL.CreateDictionaryObject(null); this.fallbackMethod = JSIL.$PickFallbackMethodForInterfaceMethod(typeObject, methodName, signature); @@ -6841,7 +6948,7 @@ JSIL.InterfaceMethod = function (typeObject, methodName, signature) { JSIL.SetLazyValueProperty(JSIL.InterfaceMethod.prototype, "Call", function () { return this.$MakeCallMethod(); }, true); JSIL.InterfaceMethod.prototype.Rebind = function (newTypeObject, newSignature) { - var result = new JSIL.InterfaceMethod(newTypeObject, this.methodName, newSignature); + var result = new JSIL.InterfaceMethod(newTypeObject, this.methodName, newSignature, this.parameterInfo); result.fallbackMethod = this.fallbackMethod; return result; }; @@ -6881,8 +6988,9 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { } } - if (!result) + if (!result) { result = this.fallbackMethod ? this.fallbackMethod(this.typeObject) : null; + } if (!result) { var errorString = "Method '" + this.signature.toString(this.methodName) + "' of interface '" + @@ -6910,7 +7018,7 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { }; JSIL.InterfaceMethod.prototype.$MakeCallMethod = function () { - if (this.typeObject.__IsClosed__) { + if (this.typeObject.__IsClosed__ && this.signature.IsClosed) { this.methodKey = this.signature.GetKey(this.qualifiedName); return this.signature.$MakeCallMethod("interface"); } else { @@ -7372,7 +7480,7 @@ JSIL.CreateInstanceOfType = function (type, constructorName, constructorArgument constructor = constructorName; } - if (!type.__IsClosed__) + if (type.__IsClosed__ === false) throw new Error("Cannot create an instance of an open type"); else if (type.__IsInterface__) throw new Error("Cannot create an instance of an interface"); @@ -7526,9 +7634,7 @@ JSIL.GetMembersInternal = function (typeObject, flags, memberType, name) { for (var i = 0, l = members.length; i < l; i++) { var member = members[i]; - if (member._data.mangledName == "Method$10=void") { - console.log("Method(param)") - } + // HACK: Reflection never seems to enumerate static constructors. This is probably because // it doesn't make any sense to invoke them explicitly anyway, and they don't have arguments... if ( @@ -8341,6 +8447,8 @@ JSIL.GetInterfacesImplementedByType = function (typeObject) { JSIL.$EnumInterfacesImplementedByTypeExcludingBases = function (typeObject, resultList) { var interfaces = typeObject.__Interfaces__; + var toEnumerate = []; + if (interfaces && interfaces.length) { for (var i = 0, l = interfaces.length; i < l; i++) { var ifaceRef = interfaces[i]; @@ -8348,11 +8456,15 @@ JSIL.$EnumInterfacesImplementedByTypeExcludingBases = function (typeObject, resu if (iface && (resultList.indexOf(iface) < 0)) { resultList.push(iface); - - JSIL.$EnumInterfacesImplementedByTypeExcludingBases(iface, resultList); + toEnumerate.push(iface); } } } + + for (var i = 0, l = toEnumerate.length; i < l; i++) { + var iface = toEnumerate[i]; + JSIL.$EnumInterfacesImplementedByTypeExcludingBases(iface, resultList); + } }; JSIL.$FindMatchingInterfacesThroughVariance = function (expectedInterfaceObject, actualTypeObject, variantParameters) { @@ -8511,6 +8623,10 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature if (!matchingInterfaces.length) return null; + else if (!signature.openSignature) { + // FIXME: Is this right? + return null; + } var result = []; @@ -8531,21 +8647,14 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature return result; }; -JSIL.$GetEnumeratorFallback = function (thisTypeObject) { - var interfaceTypeObject = thisTypeObject; - return function () { - if (typeof (this) === "string") - return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); - else if (JSIL.IsArray(this)) { - if (interfaceTypeObject.IsGenericType) { - return JSIL.GetEnumerator(this, thisTypeObject.__GenericArgumentValues__[0], true); - } - // HACK: Too hard to detect the correct element type here. - return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); - } - else - JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); - }; +JSIL.$GetEnumeratorFallback = function () { + if (typeof (this) === "string") + return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); + else if (JSIL.IsArray(this)) + // HACK: Too hard to detect the correct element type here. + return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); + else + JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); }; // FIXME: This can probably be replaced with compiler and/or runtime intelligence @@ -8564,7 +8673,21 @@ JSIL.$PickFallbackMethodForInterfaceMethod = function (interfaceObject, methodNa return null; }; -JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes) { +JSIL.$DoTypesMatch = function (expected, type) { + if (expected === null) + return (type === null); + + if (expected === type) + return true; + + if (expected.__FullName__ === "System.Array") + return type.__IsArray__; + + return false; +} + +JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes, returnType) { + var trace = false; var l = methods.length; for (var i = 0; i < l; i++) { @@ -8574,19 +8697,35 @@ JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes) { var parameterInfos = $jsilcore.$MethodGetParameters(method); if (parameterInfos.length !== argumentTypes.length) { + if (trace) + console.log("Dropping because wrong argcount", argumentTypes.length, parameterInfos.length); + remove = true; } else { for (var j = 0; j < argumentTypes.length; j++) { var argumentType = argumentTypes[j]; var argumentTypeB = parameterInfos[j].get_ParameterType(); - if (argumentType !== argumentTypeB) { + if (!JSIL.$DoTypesMatch(argumentType, argumentTypeB)) { + if (trace) + console.log("Dropping because arg mismatch", argumentType.__FullName__, argumentTypeB.__FullName__); + remove = true; break; } } } + if (typeof (returnType) !== "undefined") { + // FIXME: Do a more complete assignability check + if (!JSIL.$DoTypesMatch(returnType, method.get_ReturnType())) { + if (trace) + console.log("Dropping because wrong return type", returnType.__FullName__, method.get_ReturnType().__FullName__); + + remove = true; + } + } + if (remove) { methods[i] = methods[l - 1]; l -= 1; @@ -8648,6 +8787,13 @@ JSIL.$IgnoredPublicInterfaceMembers = [ ]; JSIL.$CopyMembersIndirect = function (target, source, ignoredNames, recursive) { + if (!source) + JSIL.RuntimeError("No source provided for copy"); + + if (source.__ThisType__ && (source.__ThisType__.__FullName__.indexOf("ArrayEnumerator") >= 0)) { + // debugger; + } + // FIXME: for ( in ) is deoptimized in V8. Maybe use Object.keys(), or type metadata? for (var k in source) { if (ignoredNames.indexOf(k) !== -1) @@ -8666,21 +8812,24 @@ JSIL.$CopyMembersIndirect = function (target, source, ignoredNames, recursive) { JSIL.$CopyInterfaceMethods = function (interfaceList, target) { var imProto = JSIL.InterfaceMethod.prototype; + var makeGetter = function (src, key) { + return function () { + return src[key]; + }; + }; + for (var i = 0, l = interfaceList.length; i < l; i++) { var ifaceRef = interfaceList[i]; var iface = JSIL.ResolveTypeReference(ifaceRef)[0]; for (var k in iface) { - var im = iface[k]; + if (!Object.prototype.hasOwnProperty.call(iface, k)) + continue; - if ( - !im || - (typeof(im) !== "object") || - (Object.getPrototypeOf(im) !== imProto) - ) + if (Object.prototype.hasOwnProperty.call(target, k)) continue; - target[k] = iface[k]; + JSIL.SetLazyValueProperty(target, k, makeGetter(iface, k)); } } }; diff --git a/Libraries/XNA/Graphics.js b/Libraries/XNA/Graphics.js index a9343889b..7c613aff0 100644 --- a/Libraries/XNA/Graphics.js +++ b/Libraries/XNA/Graphics.js @@ -2916,6 +2916,34 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.Texture2D", function ( return result; }; + var doUnpremultiply = function (dataBytes, bytes, startIndex, elementCount) { + var pixelCount = (elementCount / 4) | 0; + for (var i = 0; i < pixelCount; i++) { + var p = (i * 4) | 0; + var p1 = (p + 1) | 0; + var p2 = (p + 2) | 0; + var p3 = (p + 3) | 0; + + var a = bytes[p3] | 0; + + if (a <= 0) { + continue; + } else if (a > 254) { + dataBytes[p] = bytes[p]; + dataBytes[p1] = bytes[p1]; + dataBytes[p2] = bytes[p2]; + dataBytes[p3] = a; + } else { + var m = 255 / a; + + dataBytes[p] = (bytes[p] * m) | 0; + dataBytes[p1] = (bytes[p1] * m) | 0; + dataBytes[p2] = (bytes[p2] * m) | 0; + dataBytes[p3] = a; + } + } + }; + $.RawMethod(false, "$makeImageDataForBytes", function $makeImageDataForBytes ( width, height, bytes, startIndex, elementCount, @@ -2938,28 +2966,7 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.Texture2D", function ( // XNA texture colors are premultiplied, but canvas pixels aren't, so we need to try // to reverse the premultiplication. if (unpremultiply) { - var pixelCount = elementCount / 4; - for (var i = 0; i < pixelCount; i++) { - var p = (i * 4) | 0; - - var a = bytes[(p + 3) | 0]; - - if (a <= 0) { - continue; - } else if (a > 254) { - dataBytes[p] = bytes[p]; - dataBytes[(p + 1) | 0] = bytes[(p + 1) | 0]; - dataBytes[(p + 2) | 0] = bytes[(p + 2) | 0]; - dataBytes[(p + 3) | 0] = a; - } else { - var m = 255 / a; - - dataBytes[p] = bytes[p] * m; - dataBytes[(p + 1) | 0] = bytes[(p + 1) | 0] * m; - dataBytes[(p + 2) | 0] = bytes[(p + 2) | 0] * m; - dataBytes[(p + 3) | 0] = a; - } - } + doUnpremultiply(dataBytes, bytes, startIndex, elementCount); } else { fastArrayCopy(dataBytes, 0, bytes, startIndex, elementCount); } diff --git a/Tests/FailingTestCases/LinqAggregate.cs b/Tests/FailingTestCases/LinqAggregate.cs new file mode 100644 index 000000000..9fc232efc --- /dev/null +++ b/Tests/FailingTestCases/LinqAggregate.cs @@ -0,0 +1,8 @@ +using System; +using System.Linq; + +public static class Program { + public static void Main (string[] args) { + Console.WriteLine(new[] { "one", "two" }.Aggregate((x, y) => x + ", " + y)); + } +} \ No newline at end of file diff --git a/Tests/SimpleTestCases/Issue298.cs b/Tests/SimpleTestCases/Issue298.cs new file mode 100644 index 000000000..867acc573 --- /dev/null +++ b/Tests/SimpleTestCases/Issue298.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using JSIL.Meta; + +public static class Program { + public static void Main (string[] args) { + Console.WriteLine(((IMyInterface)new MyClass()).Add()); + } +} + +public interface IMyInterface : IList { + int Add (); +} + +public class MyClass : IMyInterface { + public int Add () { + return 5; + } + + public int IndexOf (int item) { + throw new NotImplementedException(); + } + + public void Insert (int index, int item) { + throw new NotImplementedException(); + } + + public void RemoveAt (int index) { + throw new NotImplementedException(); + } + + public int this[int index] { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public void Add (int item) { + throw new NotImplementedException(); + } + + public void Clear () { + throw new NotImplementedException(); + } + + public bool Contains (int item) { + throw new NotImplementedException(); + } + + public void CopyTo (int[] array, int arrayIndex) { + throw new NotImplementedException(); + } + + public int Count { + get { throw new NotImplementedException(); } + } + + public bool IsReadOnly { + get { throw new NotImplementedException(); } + } + + public bool Remove (int item) { + throw new NotImplementedException(); + } + + public System.Collections.Generic.IEnumerator GetEnumerator () { + throw new NotImplementedException(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 80228d4c9..3e6acd989 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -257,6 +257,7 @@ + From fda94802fb8bd2ce82b36a0f9ede73d6276c19df Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Thu, 24 Apr 2014 11:20:44 +0200 Subject: [PATCH 09/16] Revert to b8caf0b976f5d04d3d26f7e6d566c2b9f49711a9 --- Compiler/Profiles/ResourceConverter.cs | 11 +- Libraries/JSIL.Bootstrap.Linq.js | 25 +- Libraries/JSIL.Bootstrap.js | 256 ++++------- Libraries/JSIL.Core.Reflection.js | 43 +- Libraries/JSIL.Core.Types.js | 26 +- Libraries/JSIL.Core.js | 579 +++++++++--------------- Libraries/XNA/Graphics.js | 51 +-- Tests/FailingTestCases/LinqAggregate.cs | 8 - Tests/SimpleTestCases/Issue298.cs | 72 --- Tests/Tests.csproj | 1 - 10 files changed, 343 insertions(+), 729 deletions(-) delete mode 100644 Tests/FailingTestCases/LinqAggregate.cs delete mode 100644 Tests/SimpleTestCases/Issue298.cs diff --git a/Compiler/Profiles/ResourceConverter.cs b/Compiler/Profiles/ResourceConverter.cs index 9a54659c4..9b72ecc0d 100644 --- a/Compiler/Profiles/ResourceConverter.cs +++ b/Compiler/Profiles/ResourceConverter.cs @@ -18,7 +18,7 @@ public static void ConvertResources (Configuration configuration, string assembl ConvertSatelliteResources(configuration, assemblyPath, result); } - public static void ConvertEmbeddedResources (Configuration configuration, string assemblyPath, TranslationResult result) { + public static void ConvertEmbeddedResources (Configuration configuration, string assemblyPath, TranslationResult result) { using (var domain = new TemporaryAppDomain("ConvertEmbeddedResources")) { var resourceExtractor = domain.CreateInstanceAndUnwrap< ManifestResourceExtractor, IManifestResourceExtractor @@ -30,12 +30,7 @@ public static void ConvertEmbeddedResources (Configuration configuration, string var encoding = new UTF8Encoding(false); - foreach (var kvp in manifestResources) { - var outputPath = Path.GetFileNameWithoutExtension(kvp.Key) + ".resj"; - // FIXME: We're converting embedded resources multiple times per run :( - if (result.Files.ContainsKey(outputPath)) - continue; - + foreach (var kvp in manifestResources) { Console.WriteLine(kvp.Key); string resourceJson; @@ -46,7 +41,7 @@ public static void ConvertEmbeddedResources (Configuration configuration, string result.AddFile( "Resources", - outputPath, + Path.GetFileNameWithoutExtension(kvp.Key) + ".resj", new ArraySegment(bytes) ); } diff --git a/Libraries/JSIL.Bootstrap.Linq.js b/Libraries/JSIL.Bootstrap.Linq.js index 2c8091032..421b879dd 100644 --- a/Libraries/JSIL.Bootstrap.Linq.js +++ b/Libraries/JSIL.Bootstrap.Linq.js @@ -24,24 +24,15 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerable", true, ["T"], function } ); - function getEnumeratorImpl () { - if (this._getEnumerator !== null) - return this._getEnumerator(); - else - return new (JSIL.AbstractEnumerator.Of(this.T))(this._getNextItem, this._reset, this._dispose); - }; - - $.Method({Static: false, Public: true }, "IEnumerable_GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.IEnumerator"), []), - getEnumeratorImpl - ) - .Overrides(0, "GetEnumerator"); - $.Method({Static: false, Public: true }, "GetEnumerator", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), []), - getEnumeratorImpl - ) - .Overrides(1, "GetEnumerator"); + function () { + if (this._getEnumerator !== null) + return this._getEnumerator(); + else + return new (JSIL.AbstractEnumerator.Of(this.T))(this._getNextItem, this._reset, this._dispose); + } + ); $.ImplementInterfaces( /* 0 */ $jsilcore.TypeRef("System.Collections.IEnumerable"), @@ -303,7 +294,7 @@ JSIL.ImplementExternals( $.Method({Static:true , Public:true }, "ToArray", new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", ["!!0"]), [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"])], ["TSource"]), function (T, enumerable) { - return JSIL.EnumerableToArray(enumerable, T); + return JSIL.EnumerableToArray(enumerable); } ); diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index f5a87c7b8..c7756c2d3 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -691,13 +691,13 @@ JSIL.ImplementExternals( ); JSIL.MakeStaticClass("System.Console", true, [], function ($) { + $.Property({ Static: true, Public: true }, "In"); + $.Property({ Static: true, Public: true }, "Out"); }); JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator"); - - $.RawMethod(false, "__CopyMembers__", - function ArrayEnumerator_CopyMembers (source, target) { + $.RawMethod(false, "__CopyMembers__", + function ArrayEnumerator_CopyMembers(source, target) { target._array = source._array; target._length = source._length; target._index = source._index; @@ -725,15 +725,13 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ this._index = -1; } ); - - $.Method({Public: true , Static: false}, "MoveNext", + $.Method({ Public: true, Static: false }, "MoveNext", new JSIL.MethodSignature(System.Boolean, []), function () { return (++this._index < this._length); } ); - - $.Method({Public: true , Static: false}, "Dispose", + $.Method({ Public: true, Static: false }, "Dispose", new JSIL.MethodSignature(null, []), function () { this._array = null; @@ -741,29 +739,18 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ this._length = -1; } ); - - $.Method({Public: true , Static: false}, "IEnumerator_get_Current", + $.Method({ Public: true, Static: false }, "get_Current", new JSIL.MethodSignature(System.Object, []), function () { return this._array[this._index]; } - ) - .Overrides(1, "get_Current"); - - $.Method({Public: true , Static: false}, "get_Current", - new JSIL.MethodSignature(T, []), - function () { - return this._array[this._index]; - } - ) - .Overrides(2, "get_Current"); + ); - $.Property({Public: true , Static: false, Virtual: true }, "Current"); + $.Property({ Public: true, Static: false, Virtual: true }, "Current"); $.ImplementInterfaces( - /* 0 */ System.IDisposable, - /* 1 */ System.Collections.IEnumerator, - /* 2 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) + System.IDisposable, System.Collections.IEnumerator, + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) ); }); @@ -961,7 +948,7 @@ $jsilcore.$ListExternals = function ($, T, type) { $.Method({ Static: false, Public: true }, ".ctor", new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], []), function (values) { - this._items = JSIL.EnumerableToArray(values, this.T); + this._items = JSIL.EnumerableToArray(values); this._capacity = this._items.length; this._size = this._items.length; } @@ -1449,7 +1436,7 @@ $jsilcore.$CollectionExternals = function ($) { $.Method({ Static: false, Public: true }, ".ctor", new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Collections.Generic.IList`1", [T])], []), function (list) { - this._items = JSIL.EnumerableToArray(list, this.T); + this._items = JSIL.EnumerableToArray(list); this._capacity = this._size = this._items.length; } ); @@ -2275,52 +2262,20 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); - var getEnumeratorImpl = function GetEnumerator () { - if (this.tEnumerator === null) { - this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; - } - - return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); - }; - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature( - mscorlib.TypeRef( - "System.Collections.Generic.Dictionary`2+Enumerator", [ - new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), - new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") - ] - ), [], []) - ), - getEnumeratorImpl - ); - - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], [])), - getEnumeratorImpl - ) - .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function GetEnumerator () { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; + } - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature( - mscorlib.TypeRef( - "System.Collections.Generic.IEnumerator`1", [ - mscorlib.TypeRef( - "System.Collections.Generic.KeyValuePair`2", [ - new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), - new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") - ] - ) - ] - ), [], []) - ), - getEnumeratorImpl - ) - .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); + return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + } + ); - $.Method({Static:false, Public:true }, "set_Item", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function set_Item (key, value) { + $.Method({ Static: false, Public: true }, "set_Item", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function set_Item(key, value) { var bucketEntry = this.$searchBucket(key); if (bucketEntry !== null) return bucketEntry.value = value; @@ -2815,8 +2770,8 @@ JSIL.GetEnumerator = function (enumerable, elementType, fallbackMethodInvoke) { return result; }; -JSIL.EnumerableToArray = function (enumerable, elementType) { - var e = JSIL.GetEnumerator(enumerable, elementType); +JSIL.EnumerableToArray = function (enumerable) { + var e = JSIL.GetEnumerator(enumerable); var result = []; var moveNext = $jsilcore.System.Collections.IEnumerator.MoveNext; @@ -2894,21 +2849,12 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function } ); - $.Method({Static: false, Public: true }, "IEnumerator_get_Current", - new JSIL.MethodSignature($.Object, []), - function () { - return this._current.get(); - } - ) - .Overrides(0, "get_Current"); - - $.Method({Static: false, Public: true }, "get_Current", + $.Method({ Static: false, Public: true }, "get_Current", new JSIL.MethodSignature(T, []), function () { return this._current.get(); } - ) - .Overrides(1, "get_Current"); + ); $.Property({ Static: false, Public: true, Virtual: true }, "Current"); @@ -3384,7 +3330,6 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", $jsilcore.hashCo JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { var mscorlib = JSIL.GetCorlib(); - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1"); $.Method({ Static: false, Public: true }, ".ctor", (new JSIL.MethodSignature(null, [], [])), @@ -3395,18 +3340,18 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [T])], [])), - function _ctor (comparer) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], [])), - function _ctor (collection) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection) { this._dict = {}; this._count = 0; this._comparer = null; @@ -3414,9 +3359,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor (collection, comparer) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection, comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; @@ -3424,9 +3369,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Add", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Add (item) { + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Add(item) { var bucketEntry = this.$searchBucket(item); if (bucketEntry !== null) @@ -3438,7 +3383,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { ); $.RawMethod(false, "$addRange", function (enumerable) { - var values = JSIL.EnumerableToArray(enumerable, this.T); + var values = JSIL.EnumerableToArray(enumerable); for (var i = 0; i < values.length; i++) this.Add(values[i]); @@ -3452,9 +3397,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Contains (item) { + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Contains(item) { return this.$searchBucket(item) !== null; } ); @@ -3466,74 +3411,53 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Remove (item) { + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")], [])), + function Remove(item) { return this.$removeByKey(item); } ); - var getEnumeratorImpl = function GetEnumerator () { - var dict = this._dict; - - // FIXME: Return an actual instance of HashSet`1+Enumerator. - return new (JSIL.AbstractEnumerator.Of(this.T)) ( - function getNext (result) { - var keys = this._state.keys; - var valueIndex = ++(this._state.valueIndex); - var bucketIndex = this._state.bucketIndex; - - while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { - var bucketKey = keys[this._state.bucketIndex]; - var bucket = dict[bucketKey]; - - if ((valueIndex >= 0) && (valueIndex < bucket.length)) { - result.set(bucket[valueIndex].key); - return true; - } else { - bucketIndex = ++(this._state.bucketIndex); - valueIndex = 0; - } - } - - return false; - }, - function reset () { - this._state = { - current: JSIL.DefaultValue(this.T), - keys: Object.keys(dict), - bucketIndex: 0, - valueIndex: -1 - }; - }, - function dispose () { - this._state = null; - } - ); - }; - - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature( - $jsilcore.TypeRef("System.Collections.Generic.HashSet`1+Enumerator", [T]), [], [] - ), - getEnumeratorImpl - ) - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], [] - ), - getEnumeratorImpl - ) - .Overrides(0, "GetEnumerator"); + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.HashSet`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")]), [], []), + function GetEnumerator () { + var dict = this._dict; + + return new (JSIL.AbstractEnumerator.Of(this.T))( + function getNext(result) { + var keys = this._state.keys; + var valueIndex = ++(this._state.valueIndex); + var bucketIndex = this._state.bucketIndex; + + while ((bucketIndex >= 0) && (bucketIndex < keys.length)) { + var bucketKey = keys[this._state.bucketIndex]; + var bucket = dict[bucketKey]; + + if ((valueIndex >= 0) && (valueIndex < bucket.length)) { + result.set(bucket[valueIndex].key); + return true; + } else { + bucketIndex = ++(this._state.bucketIndex); + valueIndex = 0; + } + } - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature( - $jsilcore.TypeRef("System.Collections.IEnumerator", []), [], [] - ), - getEnumeratorImpl - ) - .Overrides(1, "GetEnumerator"); + return false; + }, + function reset() { + this._state = { + current: JSIL.DefaultValue(this.T), + keys: Object.keys(dict), + bucketIndex: 0, + valueIndex: -1 + }; + }, + function dispose() { + this._state = null; + } + ); + } + ); }); JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, ["T"], function ($) { @@ -3547,16 +3471,6 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.HashSet`1", true, [" ); }); -JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.HashSet`1+Enumerator", false, ["T"], function ($) { - var T = new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1+Enumerator"); - - $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), - /* 1 */ $jsilcore.TypeRef("System.IDisposable"), - /* 2 */ $jsilcore.TypeRef("System.Collections.IEnumerator") - ); -}); - JSIL.MakeEnum( "System.Globalization.NumberStyles", true, { None: 0, diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index d22c83465..f9fa999a1 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -196,7 +196,9 @@ JSIL.ImplementExternals( function () { return JSIL.GetMembersInternal( this, - defaultFlags() + System.Reflection.BindingFlags.Instance | + System.Reflection.BindingFlags.Static | + System.Reflection.BindingFlags.Public ); } ); @@ -210,22 +212,16 @@ JSIL.ImplementExternals( } ); - var getMatchingMethodsImpl = function (type, name, flags, argumentTypes, returnType, allMethods) { + var getMethodImpl = function (type, name, flags, argumentTypes) { var methods = JSIL.GetMembersInternal( - type, flags, allMethods ? "$AllMethods" : "MethodInfo", name + type, flags, "MethodInfo", name ); if (argumentTypes) - JSIL.$FilterMethodsByArgumentTypes(methods, argumentTypes, returnType); + JSIL.$FilterMethodsByArgumentTypes(methods, argumentTypes); JSIL.$ApplyMemberHiding(type, methods, type.__PublicInterface__.prototype); - return methods; - } - - var getMethodImpl = function (type, name, flags, argumentTypes) { - var methods = getMatchingMethodsImpl(type, name, flags, argumentTypes); - if (methods.length > 1) { throw new System.Exception("Multiple methods named '" + name + "' were found."); } else if (methods.length < 1) { @@ -235,16 +231,6 @@ JSIL.ImplementExternals( return methods[0]; }; - $.RawMethod(false, "$GetMatchingInstanceMethods", function (name, argumentTypes, returnType) { - var bindingFlags = $jsilcore.BindingFlags; - var flags = bindingFlags.Public | bindingFlags.NonPublic | bindingFlags.Instance; - - return getMatchingMethodsImpl( - this, name, flags, - argumentTypes, returnType, true - ); - }); - $.Method({Public: true , Static: false}, "GetMethod", new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.MethodInfo"), [$.String]), function (name) { @@ -466,10 +452,7 @@ JSIL.ImplementExternals( }; var defaultFlags = function () { - var bindingFlags = $jsilcore.BindingFlags; - var result = bindingFlags.Public | bindingFlags.Instance | bindingFlags.Static; - return result; - // return System.Reflection.BindingFlags.$Flags("Public", "Instance", "Static"); + return System.Reflection.BindingFlags.$Flags("Public", "Instance", "Static"); }; $.Method({Public: true , Static: false}, "GetField", @@ -525,7 +508,7 @@ JSIL.ImplementExternals( $.Method({ Public: true, Static: false }, "GetInterfaces", new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Type]), []), function () { - return JSIL.GetInterfacesImplementedByType(this); + return this.__Interfaces__; } ); } @@ -607,15 +590,7 @@ JSIL.ImplementExternals( (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Type")]), [], [])), function GetParameterTypes () { var signature = this._data.signature; - var argumentTypes = signature.argumentTypes; - var result = []; - - for (var i = 0, l = argumentTypes.length; i < l; i++) { - var argumentType = argumentTypes[i]; - result.push(signature.ResolveTypeReference(argumentType)[1]); - } - - return result; + return signature.argumentTypes; } ); diff --git a/Libraries/JSIL.Core.Types.js b/Libraries/JSIL.Core.Types.js index 5a917e8d4..5675b8e5f 100644 --- a/Libraries/JSIL.Core.Types.js +++ b/Libraries/JSIL.Core.Types.js @@ -216,8 +216,7 @@ JSIL.MakeInterface( "System.Collections.IDictionaryEnumerator", true, [], function ($) { $.Method({}, "get_Key", new JSIL.MethodSignature($.Object, [], [])); $.Method({}, "get_Value", new JSIL.MethodSignature($.Object, [], [])); - // FIXME - // $.Method({}, "get_Entry", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.DictionaryEntry"), [], [])); + $.Method({}, "get_Entry", new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.DictionaryEntry"), [], [])); $.Property({}, "Key"); $.Property({}, "Value"); $.Property({}, "Entry"); @@ -593,26 +592,3 @@ JSIL.MakeClass($jsilcore.TypeRef("System.Object"), "System.Attribute", true, [], } ); }); - -JSIL.MakeEnum( - "System.TypeCode", true, { - Empty: 0, - Object: 1, - DBNull: 2, - Boolean: 3, - Char: 4, - SByte: 5, - Byte: 6, - Int16: 7, - UInt16: 8, - Int32: 9, - UInt32: 10, - Int64: 11, - UInt64: 12, - Single: 13, - Double: 14, - Decimal: 15, - DateTime: 16, - String: 18 - }, false -); diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 6b5369a7c..5953e3e82 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -1289,8 +1289,8 @@ JSIL.AttributeRecord = function (context, type, getConstructorArguments, initial this.initializer = initializer; }; -JSIL.OverrideRecord = function (interfaceIndexOrName, interfaceMemberName) { - this.interfaceIndexOrName = interfaceIndexOrName; +JSIL.OverrideRecord = function (interfaceIndex, interfaceMemberName) { + this.interfaceIndex = interfaceIndex; this.interfaceMemberName = interfaceMemberName; }; @@ -1469,7 +1469,7 @@ JSIL.GenericParameter.prototype.out = function () { }; JSIL.GenericParameter.prototype.get = function (context) { - if (!context) { + if ((typeof (context) !== "object") && (typeof (context) !== "function")) { JSIL.RuntimeError("No context provided when resolving generic parameter '" + this.name + "'"); return JSIL.AnyType; } @@ -1498,8 +1498,6 @@ JSIL.GenericParameter.prototype.get_Name = function () { return this.name.humanReadable; }; -JSIL.GenericParameter.prototype.__IsClosed__ = false; - JSIL.PositionalGenericParameter = function (name, context) { this.index = parseInt(name.substr(2)); @@ -1550,9 +1548,6 @@ JSIL.PositionalGenericParameter.prototype.get_Name = function () { return "!!" + this.index; }; -JSIL.PositionalGenericParameter.prototype.__IsClosed__ = false; - - JSIL.TypeRef = function (context, name, genericArguments) { if (arguments.length === 1) { this.context = null; @@ -2010,7 +2005,7 @@ JSIL.$ResolveGenericTypeReferenceInternal = function (obj, context) { return new JSIL.TypeRef(obj.context, obj.typeName, resolvedGa); else return null; - } else if (obj.__IsClosed__ === false) { + } else if (!obj.__IsClosed__) { if (obj.__IsArray__) { var elementType = JSIL.$ResolveGenericTypeReferenceInternal(obj.__ElementType__, context); if (elementType !== null) @@ -2037,10 +2032,7 @@ JSIL.$ResolveGenericTypeReferenceInternal = function (obj, context) { ); if (!closedParameters[i]) { - if ( - (Object.getPrototypeOf(existingParameters[i]) === JSIL.GenericParameter.prototype) || - (existingParameters[i].__IsClosed__ === false) - ) { + if ((Object.getPrototypeOf(existingParameters[i]) === JSIL.GenericParameter.prototype) || (!existingParameters[i].__IsClosed__)) { if (JSIL.WarnAboutGenericResolveFailures) JSIL.Host.warning("Failed to resolve generic parameter #" + i + " of type reference '" + obj.toString() + "'."); @@ -2257,50 +2249,33 @@ $jsilcore.$Of$NoInitialize = function () { unresolvedBaseType = typeObject.__BaseType__; var resolvedBaseType = unresolvedBaseType; - var resolveContext = null; - if (staticClassObject.prototype) { - resolveContext = JSIL.CreatePrototypeObject(staticClassObject.prototype); - } else { - resolveContext = JSIL.CreateSingletonObject(null); - } + if (typeof (staticClassObject.prototype) !== "undefined") { + var resolveContext = JSIL.CreatePrototypeObject(staticClassObject.prototype); + for (var i = 0; i < resolvedArguments.length; i++) { + gaNames[i].set(resolveContext, resolvedArguments[i]); + } - for (var i = 0; i < resolvedArguments.length; i++) { - gaNames[i].set(resolveContext, resolvedArguments[i]); - } + // We need to resolve any generic arguments contained in the base type so that the base type of a closed generic type is also closed. + // thus, given Derived : Base and Base : Object, Derived.BaseType must be Base, not Base. + resolvedBaseType = JSIL.$ResolveGenericTypeReferenceInternal(resolvedBaseType, resolveContext); + if (!resolvedBaseType) { + resolvedBaseType = unresolvedBaseType; + } - // We need to resolve any generic arguments contained in the base type so that the base type of a closed generic type is also closed. - // thus, given Derived : Base and Base : Object, Derived.BaseType must be Base, not Base. - resolvedBaseType = JSIL.$ResolveGenericTypeReferenceInternal(resolvedBaseType, resolveContext); - if (!resolvedBaseType) { - resolvedBaseType = unresolvedBaseType; + JSIL.$ResolveGenericTypeReferences(typeObject, resolvedArguments); } - JSIL.$ResolveGenericTypeReferences(typeObject, resolvedArguments); - var resultTypeObject = JSIL.CreateSingletonObject(typeObject); - // Since .Of() will now be called even for open types, we need to ensure that we flag - // the type as open if it has any unresolved generic parameters. - var isClosed = true; - for (var i = 0, l = arguments.length; i < l; i++) { - if (Object.getPrototypeOf(resolvedArguments[i]) === JSIL.GenericParameter.prototype) - isClosed = false; - else if (resolvedArguments[i].__IsClosed__ === false) - isClosed = false; - } - resultTypeObject.__IsClosed__ = isClosed; - var constructor; - if (typeObject.IsInterface) { + if (typeObject.IsInterface) constructor = function Interface__ctor () { JSIL.RuntimeError("Cannot construct an instance of an interface"); }; - - } else { + else constructor = JSIL.MakeTypeConstructor(resultTypeObject, typeObject.__MaxConstructorArguments__); - } resultTypeObject.__PublicInterface__ = result = constructor; resultTypeObject.__OpenType__ = typeObject; @@ -2312,7 +2287,7 @@ $jsilcore.$Of$NoInitialize = function () { // Prevents recursion when Of is called indirectly during initialization of the new closed type ofCache[cacheKey] = result; - if (staticClassObject.prototype) { + if (typeof (staticClassObject.prototype) !== "undefined") { // Given Derived : Base and Base : Object, the prototype of Derived instances must have this chain: // Derived -> Base -> Object, not: // Derived -> Derived -> Base -> Object @@ -2405,35 +2380,6 @@ $jsilcore.$Of$NoInitialize = function () { var interfaces = resultTypeObject.__Interfaces__ = []; var sourceInterfaces = typeObject.__Interfaces__; - var writeGenericArgument = function (key, name, resolvedArgument) { - var getter = function GetGenericArgument () { - return name.get(this); - } - - var decl = { - configurable: true, - enumerable: true, - value: resolvedArgument - }; - var getterDecl = { - configurable: true, - enumerable: true, - get: getter - }; - - name.defineProperty(result, decl); - - if (key) - Object.defineProperty(result, key, getterDecl); - - if (result.prototype) { - name.defineProperty(result.prototype, decl); - - if (key) - Object.defineProperty(result.prototype, key, getterDecl); - } - }; - for (var i = 0, l = sourceInterfaces.length; i < l; i++) { var unresolvedInterface = sourceInterfaces[i]; var resolvedInterface = JSIL.$ResolveGenericTypeReferenceInternal(unresolvedInterface, resolveContext); @@ -2446,28 +2392,48 @@ $jsilcore.$Of$NoInitialize = function () { continue; interfaces.push(resolvedInterface); - - if (resolvedInterface !== unresolvedInterface) { - var resolvedInterfaceTypeObj = JSIL.ResolveTypeReference(resolvedInterface)[1]; - var names = resolvedInterfaceTypeObj.__OpenType__.__GenericArgumentNames__; - - for (var j = 0, l2 = names.length; j < l2; j++) { - var name = names[j]; - var value = resolvedInterfaceTypeObj.__GenericArgumentValues__[j]; - writeGenericArgument(null, name, value); - } - } } for (var i = 0, l = resolvedArguments.length; i < l; i++) { var key = ga[i]; var name = new JSIL.Name(key, resultTypeObject.__FullNameWithoutArguments__); - writeGenericArgument(key, name, resolvedArguments[i]); + var makeGetter = function (_name) { + return function GetGenericArgument () { + return _name.get(this); + } + }; + + var decl = { + configurable: true, + enumerable: true, + value: resolvedArguments[i] + }; + var getterDecl = { + configurable: true, + enumerable: true, + get: makeGetter(name) + }; + + name.defineProperty(result, decl); + Object.defineProperty(result, key, getterDecl); + + if (typeof (staticClassObject.prototype) !== "undefined") { + name.defineProperty(result.prototype, decl); + Object.defineProperty(result.prototype, key, getterDecl); + } } - if (typeObject.IsInterface) - JSIL.CopyObjectValues(resolveContext, result.prototype, false); + // Since .Of() will now be called even for open types, we need to ensure that we flag + // the type as open if it has any unresolved generic parameters. + var isClosed = true; + for (var i = 0, l = arguments.length; i < l; i++) { + if (Object.getPrototypeOf(resolvedArguments[i]) === JSIL.GenericParameter.prototype) + isClosed = false; + else if (resolvedArguments[i].__IsClosed__ === false) + isClosed = false; + } + resultTypeObject.__IsClosed__ = isClosed; if (isClosed) { resultTypeObject.__AssignableFromTypes__ = {}; @@ -2530,12 +2496,6 @@ JSIL.$ResolveGenericMethodSignature = function (typeObject, signature, resolveCo if (changed) return new JSIL.MethodSignature(returnType[0], argumentTypes, genericArgumentNames, typeObject.__Context__, signature); - /* - if (!signature.IsClosed) { - console.log("Resolving failed for open signature", signature, "with context", resolveContext); - } - */ - return null; }; @@ -2584,7 +2544,6 @@ JSIL.RenameGenericMethods = function (publicInterface, typeObject) { var rm = typeObject.__RenamedMethods__; var trace = false; - var throwOnFail = false; var isInterface = typeObject.IsInterface; @@ -2614,17 +2573,6 @@ JSIL.RenameGenericMethods = function (publicInterface, typeObject) { if (!oldObject) JSIL.RuntimeError("Failed to find unrenamed generic interface method"); - if (!signature.IsClosed) { - genericSignature = signature; - signature = JSIL.$ResolveGenericMethodSignature( - typeObject, genericSignature, resolveContext - ); - - if (!signature && throwOnFail) { - JSIL.RuntimeError("Failed to resolve generic signature", genericSignature); - } - } - var newObject = oldObject.Rebind(typeObject, signature); JSIL.SetValueProperty(publicInterface, unqualifiedName, newObject); @@ -2726,42 +2674,29 @@ JSIL.InstantiateProperties = function (publicInterface, typeObject) { } }; -$jsilcore.CanFixUpEnumInterfaces = false; - JSIL.FixupInterfaces = function (publicInterface, typeObject) { var trace = false; - if (typeObject.__FullName__ === "System.Enum") { - if (!$jsilcore.CanFixUpEnumInterfaces) - return; - else - /* trace = true */; - } - - // FIXME: Is this right? I think it might be. We don't actually use the types, - // just use their type objects as tokens for comparisons. - if (typeObject.__IsFixingUpInterfaces__) + var interfaces = typeObject.__Interfaces__; + if (!JSIL.IsArray(interfaces)) return; if (typeObject.IsInterface) return; - var interfaces = JSIL.GetInterfacesImplementedByType(typeObject); - if (!interfaces.length) return; - typeObject.__IsFixingUpInterfaces__ = true; - var context = typeObject.__Context__; var typeName = typeObject.__FullName__; var missingMembers = []; - var ambiguousMembers = []; var typeMembers = JSIL.GetMembersInternal(typeObject, $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public")); var resolveContext = typeObject.__IsStatic__ ? publicInterface : publicInterface.prototype; + var namePairs = [[null, null], [null, null]]; + __interfaces__: for (var i = 0, l = interfaces.length; i < l; i++) { var iface = interfaces[i]; @@ -2811,92 +2746,118 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { // In cases where an interface method (IInterface_MethodName) is implemented by a regular method // (MethodName), we make a copy of the regular method with the name of the interface method, so // that attempts to directly invoke the interface method will still work. - var members = JSIL.GetMembersInternal( - iface, - $jsilcore.BindingFlags.$Flags("DeclaredOnly", "Instance", "NonPublic", "Public") - ); + var members = JSIL.GetMembersInternal(iface, $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public")); var proto = publicInterface.prototype; var escapedLocalName = JSIL.EscapeName(ifaceLocalName); - var hasOwn = function (name) { - return Object.prototype.hasOwnProperty.call(proto, name); - }; - - var hasNonPlaceholder = function (obj, name) { - var value = obj[name]; - if ((typeof (value) === "undefined") || - (value === null)) - return false; - - if (value.__IsPlaceholder__) - return false; - - return true; - } - __members__: for (var j = 0; j < members.length; j++) { var member = members[j]; - var qualifiedName = JSIL.$GetSignaturePrefixForType(iface) + member._descriptor.EscapedName; - var signature = member._data.signature || null; - var signatureQualifiedName = null; - if (signature) { - signatureQualifiedName = signature.GetKey(qualifiedName); + namePairs[0][0] = member._descriptor.EscapedName; + namePairs[0][1] = JSIL.$GetSignaturePrefixForType(iface) + member._descriptor.EscapedName; + + if (member._data.signature) { + var signature = member._data.signature; + + namePairs[1][0] = signature.GetKey(namePairs[0][0]); + namePairs[1][1] = signature.GetKey(namePairs[0][1]); + namePairs[0][1] = signature.GetKey(namePairs[0][1]); + + if (trace) + console.log(signature.toString(member._descriptor.EscapedName), namePairs[1][1]); + } else { + namePairs[1][0] = null; + namePairs[1][1] = null; } - if (signature - && hasNonPlaceholder(proto, signatureQualifiedName) - && hasOwn(signatureQualifiedName) - ) - continue; + var isMissing = false; - if ( - hasNonPlaceholder(proto, qualifiedName) - && hasOwn(qualifiedName) - ) - continue; + namePairs.forEach(function (namePair) { + var shortName = namePair[0]; + var qualifiedName = namePair[1]; - var isMissing = false, isAmbiguous = false; + if (!shortName) + return; - switch (member.__MemberType__) { - case "MethodInfo": - case "ConstructorInfo": - // FIXME: Match signatures - var matchingMethods = typeObject.$GetMatchingInstanceMethods( - member.get_Name(), member.GetParameterTypes(), member.get_ReturnType() - ); + if (trace) + console.log(shortName, qualifiedName); - if (matchingMethods.length === 0) { - isMissing = true; - } else if (matchingMethods.length > 1) { - isAmbiguous = true; - } else { - var implementation = matchingMethods[0]; + var hasShort = proto.hasOwnProperty(shortName); + var hasQualified = proto.hasOwnProperty(qualifiedName); - var sourceQualifiedName = implementation._data.signature.GetKey(implementation._descriptor.EscapedName); + var hasShortRecursive = JSIL.HasOwnPropertyRecursive(proto, shortName); + var hasQualifiedRecursive = JSIL.HasOwnPropertyRecursive(proto, qualifiedName); - if (trace) - console.log(typeName + "::" + signatureQualifiedName + " (" + iface + ") = " + sourceQualifiedName); + switch (member.__MemberType__) { + case "MethodInfo": + case "ConstructorInfo": + var shortImpl = proto[shortName]; + var qualifiedImpl = proto[qualifiedName]; + break; - JSIL.SetLazyValueProperty( - proto, signatureQualifiedName, - JSIL.MakeInterfaceMemberGetter(proto, sourceQualifiedName) - ); - } + case "PropertyInfo": + var shortImpl = JSIL.GetOwnPropertyDescriptorRecursive(proto, shortName); + var qualifiedImpl = JSIL.GetOwnPropertyDescriptorRecursive(proto, qualifiedName); + break; - break; + default: + // FIXME + return; + } - default: - // FIXME: Not implemented - break; - } + if ((typeof (shortImpl) === "undefined") || (shortImpl === null)) + hasShortRecursive = hasShort = false; + + if ((typeof (qualifiedImpl) === "undefined") || (qualifiedImpl === null)) + hasQualifiedRecursive = hasQualified = false; + + if ( + hasShortRecursive && + (typeof(shortImpl.__IsPlaceholder__) !== "undefined") && + shortImpl.__IsPlaceholder__ != false + ) { + hasShortRecursive = hasShort = false; + } + + if ( + hasQualifiedRecursive && + (typeof(qualifiedImpl.__IsPlaceholder__) !== "undefined") && + qualifiedImpl.__IsPlaceholder__ != false + ) { + hasQualifiedRecursive = hasQualified = false; + } + + if (!hasShortRecursive && !hasQualifiedRecursive) { + isMissing = true; + return; + } + + if ((!hasQualified && hasShort) || (!hasQualifiedRecursive && hasShortRecursive)) { + if (trace) + console.log(qualifiedName, "->", shortName); + + switch (member.__MemberType__) { + case "MethodInfo": + case "ConstructorInfo": + JSIL.SetLazyValueProperty(proto, qualifiedName, JSIL.MakeInterfaceMemberGetter(proto, shortName)); + JSIL.SetLazyValueProperty(proto, qualifiedName, JSIL.MakeInterfaceMemberGetter(proto, shortName)); + break; + + case "PropertyInfo": + Object.defineProperty(proto, qualifiedName, shortImpl); + break; + } + } else { + if (trace) + console.log("Skipping " + qualifiedName); + } + }); if (isMissing) - missingMembers.push(signatureQualifiedName || qualifiedName); - else if (isAmbiguous) - ambiguousMembers.push(signatureQualifiedName || qualifiedName); + missingMembers.push(namePairs[0][1]); + } if (interfaces.indexOf(iface) < 0) @@ -2922,41 +2883,32 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { for (var j = 0; j < overrides.length; j++) { var override = overrides[j]; var iface = null; - - switch (typeof (override.interfaceIndexOrName)) { + switch (typeof (override.interfaceIndex)) { case "string": // If the index is a string, search all the interfaces implemented by this type for a substring match. // FIXME: If there are multiple matches this picks the first one. Probably not great... for (var k = 0; k < interfaces.length; k++) { - if (interfaces[k].__FullName__.indexOf(override.interfaceIndexOrName) >= 0) { + if (interfaces[k].__FullName__.indexOf(override.interfaceIndex) >= 0) { iface = interfaces[k]; break; } } - if (iface === null) - JSIL.RuntimeError("Interface index '" + override.interfaceIndexOrName + "' does not match any interfaces"); - break; case "number": - iface = interfaces[override.interfaceIndexOrName]; + iface = interfaces[override.interfaceIndex]; break; } if (!iface) - JSIL.RuntimeError("Member '" + member._descriptor.EscapedName + "' overrides nonexistent interface of type '" + typeObject.__FullName__ + "' with index '" + override.interfaceIndexOrName + "'"); + JSIL.RuntimeError("Member '" + member._descriptor.EscapedName + "' overrides nonexistent interface of type '" + typeObject.__FullName__ + "' with index '" + override.interfaceIndex + "'"); var interfaceQualifiedName = JSIL.$GetSignaturePrefixForType(iface) + JSIL.EscapeName(override.interfaceMemberName); var key = member._data.signature.GetKey(interfaceQualifiedName); - var missingIndex = missingMembers.indexOf(key); - if (missingIndex >= 0) - missingMembers.splice(missingIndex, 1); - - if (trace) { - console.log("Overrides set " + typeName + "::" + key + " (#" + override.interfaceIndexOrName + "=" + iface + ") = " + member._descriptor.EscapedName); - } + if (trace) + console.log(key, "->", member._descriptor.EscapedName); // Important: This may overwrite an existing member with this key, from an automatic interface fixup // like 'Foo.GetEnumerator' -> 'Foo.Ixx$GetEnumerator'. @@ -2970,13 +2922,6 @@ JSIL.FixupInterfaces = function (publicInterface, typeObject) { if ((JSIL.SuppressInterfaceWarnings !== true) || trace) JSIL.Host.warning("Type '" + typeObject.__FullName__ + "' is missing implementation of interface member(s): " + missingMembers.join(", ")); } - - if (ambiguousMembers.length > 0) { - if ((JSIL.SuppressInterfaceWarnings !== true) || trace) - JSIL.Host.warning("Type '" + typeObject.__FullName__ + "' has ambiguous implementation of interface member(s): " + ambiguousMembers.join(", ")); - } - - typeObject.__IsFixingUpInterfaces__ = false; }; JSIL.GetFieldList = function (typeObject) { @@ -3163,16 +3108,11 @@ JSIL.InitializeInstanceFields = function (instance, typeObject) { fi(instance); }; -JSIL.CopyObjectValues = function (source, target, allowOverwrite) { +JSIL.CopyObjectValues = function (source, target) { for (var k in source) { - if (!Object.prototype.hasOwnProperty.call(source, k)) + if (!source.hasOwnProperty(k)) continue; - if (allowOverwrite === false) { - if (k in target) - continue; - } - target[k] = source[k]; } }; @@ -3318,7 +3258,7 @@ JSIL.$MakeMemberwiseCloner = function (typeObject, publicInterface) { }; JSIL.$BuildFieldList = function (typeObject) { - if (typeObject.__IsClosed__ === false) + if (!typeObject.__IsClosed__) return; var bindingFlags = $jsilcore.BindingFlags.$Flags("Instance", "NonPublic", "Public"); @@ -4094,9 +4034,7 @@ JSIL.InitializeType = function (type) { JSIL.InstantiateProperties(classObject, typeObject); if (typeObject.IsInterface !== true) { - JSIL.QueueTypeInitializer(typeObject, function () { - JSIL.FixupInterfaces(classObject, typeObject); - }); + JSIL.FixupInterfaces(classObject, typeObject); JSIL.RebindRawMethods(classObject, typeObject); } @@ -4869,12 +4807,6 @@ JSIL.$MakeOptimizedNumericSwitch = function (output, variableName, cases, defaul }; JSIL.MakeTypeConstructor = function (typeObject, maxConstructorArguments) { - if (typeObject.__IsClosed__ === false) { - return function () { - JSIL.RuntimeError("Cannot create an instance of an open type"); - }; - } - var ctorClosure = { typeObject: typeObject, fieldInitializer: $jsilcore.FunctionNotInitialized, @@ -5092,7 +5024,9 @@ JSIL.MakeType = function (typeArgs, initializer) { } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + //if (typeOfValue.__AssignableTypes__ != null) { + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + //} }; for (var i = 0, l = typeObject.__GenericArguments__.length; i < l; i++) { @@ -5204,10 +5138,8 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer typeObject.__FullName__ = fullName; typeObject.__TypeInitialized__ = false; - if (interfaces && interfaces.length) { - // FIXME: This seems wrong. - // JSIL.$CopyInterfaceMethods(interfaces, publicInterface); - } + if (interfaces && interfaces.length) + JSIL.$CopyInterfaceMethods(interfaces, publicInterface); JSIL.FillTypeObjectGenericArguments(typeObject, genericArguments); @@ -5231,7 +5163,10 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + if (typeOfValue.__AssignableTypes__ != null) { + return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + } + return false; }; JSIL.MakeCastMethods(publicInterface, typeObject, "interface"); @@ -5415,21 +5350,7 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { // memory usage. var valueCache = {}; - var fixedUpEnumInterfaces = false; - publicInterface.$MakeValue = function (value, name) { - // HACK: Letting System.Enum's interfaces get fixed up normally causes a cycle. - if (!fixedUpEnumInterfaces) { - fixedUpEnumInterfaces = true; - - if (!$jsilcore.CanFixUpEnumInterfaces) { - $jsilcore.CanFixUpEnumInterfaces = true; - JSIL.FixupInterfaces($jsilcore.System.Enum, $jsilcore.System.Enum.__Type__); - JSIL.RunStaticConstructors(publicInterface, typeObject); - JSIL.FixupInterfaces(publicInterface, typeObject); - } - } - var result = valueCache[value]; if (!result) @@ -5469,14 +5390,7 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { $.__Type__.__Names__.push(key); $.__Type__.__ValueToName__[value] = key; - - var makeGetter = function (key, value) { - return function () { - return $.$MakeValue(value, key); - } - }; - - JSIL.SetLazyValueProperty($, key, makeGetter(key, value)); + $[key] = $.$MakeValue(value, key); var descriptor = ib.ParseDescriptor({Public: true, Static: true}, key); var mb = new JSIL.MemberBuilder(context); @@ -5490,7 +5404,7 @@ JSIL.MakeEnum = function (fullName, isPublic, members, isFlagsEnum) { // FIXME: This is doing FixupInterfaces on Enum every time instead of on the specific enum type. // Should be harmless, but...? - // JSIL.FixupInterfaces(enumType.__PublicInterface__, enumType); + JSIL.FixupInterfaces(enumType.__PublicInterface__, enumType); JSIL.MakeCastMethods($, $.__Type__, "enum"); }; @@ -5752,8 +5666,8 @@ JSIL.MemberBuilder.prototype.Attribute = function (attributeType, getConstructor return this; }; -JSIL.MemberBuilder.prototype.Overrides = function (interfaceIndexOrName, interfaceMemberName) { - var record = new JSIL.OverrideRecord(interfaceIndexOrName, interfaceMemberName); +JSIL.MemberBuilder.prototype.Overrides = function (interfaceIndex, interfaceMemberName) { + var record = new JSIL.OverrideRecord(interfaceIndex, interfaceMemberName); this.overrides.push(record); return this; @@ -6250,8 +6164,7 @@ JSIL.InterfaceBuilder.prototype.ExternalMethod = function (_descriptor, methodNa mangledName: mangledName, isExternal: true, isPlaceholder: isPlaceholder, - isConstructor: isConstructor, - parameterInfo: memberBuilder.parameterInfo + isConstructor: isConstructor }, memberBuilder, true); return memberBuilder; @@ -6303,10 +6216,8 @@ JSIL.InterfaceBuilder.prototype.Method = function (_descriptor, methodName, sign var mangledName = signature.GetKey(descriptor.EscapedName); - var memberBuilder = new JSIL.MemberBuilder(this.context); - if (this.typeObject.IsInterface) { - var methodObject = new JSIL.InterfaceMethod(this.typeObject, descriptor.EscapedName, signature, memberBuilder.parameterInfo); + var methodObject = new JSIL.InterfaceMethod(this.typeObject, descriptor.EscapedName, signature); JSIL.SetValueProperty(descriptor.Target, mangledName, methodObject); @@ -6324,6 +6235,8 @@ JSIL.InterfaceBuilder.prototype.Method = function (_descriptor, methodName, sign var isConstructor = (descriptor.EscapedName === "_ctor"); var memberTypeName = isConstructor ? "ConstructorInfo" : "MethodInfo"; + var memberBuilder = new JSIL.MemberBuilder(this.context); + this.PushMember(memberTypeName, descriptor, { signature: signature, genericSignature: null, @@ -6395,8 +6308,7 @@ JSIL.InterfaceBuilder.prototype.InheritBaseMethod = function (name) { mangledName: mangledName, isExternal: false, isConstructor: isConstructor, - isInherited: true, - parameterInfo: memberBuilder.parameterInfo + isInherited: true }, memberBuilder); return memberBuilder; @@ -6552,7 +6464,7 @@ JSIL.MethodSignature.$EmitInvocation = function ( body, callText, thisReferenceArg, prefix, argumentTypes, genericArgumentNames, isInterface ) { var comma; - var needsBindingForm = false; + var needsBindingForm = (isInterface) && (genericArgumentNames) && (genericArgumentNames.length); if (genericArgumentNames) comma = (genericArgumentNames.length + argumentTypes.length) > 0 ? "," : ""; @@ -6640,7 +6552,8 @@ JSIL.MethodSignature.prototype.$MakeCallMethod = function (callMethodType) { } body.push(""); - if (genericArgumentNames.length > 0) { + if (callMethodType === "interface") { + } else if (genericArgumentNames.length > 0) { body.push("if (!ga || ga.length !== " + genericArgumentNames.length + ")"); body.push(" throw new Error('Invalid number of generic arguments');"); body.push("JSIL.ResolveTypeArgumentArray(ga);"); @@ -6696,19 +6609,6 @@ JSIL.MethodSignature.prototype.get_Hash = function () { return this._hash = hash; }; -JSIL.MethodSignature.prototype.get_IsClosed = function () { - if (this.returnType && (this.returnType.__IsClosed__ === false)) - return false; - - for (var i = 0, l = this.argumentTypes.length; i < l; i++) { - var at = this.argumentTypes[i]; - if (at.__IsClosed__ === false) - return false; - } - - return true; -}; - Object.defineProperty(JSIL.MethodSignature.prototype, "GenericSuffix", { configurable: false, enumerable: true, @@ -6721,12 +6621,6 @@ Object.defineProperty(JSIL.MethodSignature.prototype, "Hash", { get: JSIL.MethodSignature.prototype.get_Hash }); -Object.defineProperty(JSIL.MethodSignature.prototype, "IsClosed", { - configurable: false, - enumerable: true, - get: JSIL.MethodSignature.prototype.get_IsClosed -}); - JSIL.ConstructorSignature = function (type, argumentTypes, context) { this._lastKeyName = ""; @@ -6814,7 +6708,7 @@ JSIL.ConstructorSignature.prototype.$MakeConstructMethod = function () { var publicInterface = typeObject.__PublicInterface__; var argumentTypes = this.argumentTypes; - if (typeObject.__IsClosed__ === false) + if (!typeObject.__IsClosed__) return function () { throw new Error("Cannot create an instance of an open type"); }; @@ -6934,12 +6828,11 @@ JSIL.ResolvedMethodSignature.prototype.toString = function () { }; -JSIL.InterfaceMethod = function (typeObject, methodName, signature, parameterInfo) { +JSIL.InterfaceMethod = function (typeObject, methodName, signature) { this.typeObject = typeObject; this.variantGenericArguments = JSIL.$FindVariantGenericArguments(typeObject); this.methodName = methodName; this.signature = signature; - this.parameterInfo = parameterInfo; this.qualifiedName = JSIL.$GetSignaturePrefixForType(typeObject) + this.methodName; this.variantInvocationCandidateCache = JSIL.CreateDictionaryObject(null); this.fallbackMethod = JSIL.$PickFallbackMethodForInterfaceMethod(typeObject, methodName, signature); @@ -6948,7 +6841,7 @@ JSIL.InterfaceMethod = function (typeObject, methodName, signature, parameterInf JSIL.SetLazyValueProperty(JSIL.InterfaceMethod.prototype, "Call", function () { return this.$MakeCallMethod(); }, true); JSIL.InterfaceMethod.prototype.Rebind = function (newTypeObject, newSignature) { - var result = new JSIL.InterfaceMethod(newTypeObject, this.methodName, newSignature, this.parameterInfo); + var result = new JSIL.InterfaceMethod(newTypeObject, this.methodName, newSignature); result.fallbackMethod = this.fallbackMethod; return result; }; @@ -6988,9 +6881,8 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { } } - if (!result) { + if (!result) result = this.fallbackMethod ? this.fallbackMethod(this.typeObject) : null; - } if (!result) { var errorString = "Method '" + this.signature.toString(this.methodName) + "' of interface '" + @@ -7018,7 +6910,7 @@ JSIL.InterfaceMethod.prototype.LookupMethod = function (thisReference) { }; JSIL.InterfaceMethod.prototype.$MakeCallMethod = function () { - if (this.typeObject.__IsClosed__ && this.signature.IsClosed) { + if (this.typeObject.__IsClosed__) { this.methodKey = this.signature.GetKey(this.qualifiedName); return this.signature.$MakeCallMethod("interface"); } else { @@ -7480,7 +7372,7 @@ JSIL.CreateInstanceOfType = function (type, constructorName, constructorArgument constructor = constructorName; } - if (type.__IsClosed__ === false) + if (!type.__IsClosed__) throw new Error("Cannot create an instance of an open type"); else if (type.__IsInterface__) throw new Error("Cannot create an instance of an interface"); @@ -7634,7 +7526,9 @@ JSIL.GetMembersInternal = function (typeObject, flags, memberType, name) { for (var i = 0, l = members.length; i < l; i++) { var member = members[i]; - + if (member._data.mangledName == "Method$10=void") { + console.log("Method(param)") + } // HACK: Reflection never seems to enumerate static constructors. This is probably because // it doesn't make any sense to invoke them explicitly anyway, and they don't have arguments... if ( @@ -8447,8 +8341,6 @@ JSIL.GetInterfacesImplementedByType = function (typeObject) { JSIL.$EnumInterfacesImplementedByTypeExcludingBases = function (typeObject, resultList) { var interfaces = typeObject.__Interfaces__; - var toEnumerate = []; - if (interfaces && interfaces.length) { for (var i = 0, l = interfaces.length; i < l; i++) { var ifaceRef = interfaces[i]; @@ -8456,15 +8348,11 @@ JSIL.$EnumInterfacesImplementedByTypeExcludingBases = function (typeObject, resu if (iface && (resultList.indexOf(iface) < 0)) { resultList.push(iface); - toEnumerate.push(iface); + + JSIL.$EnumInterfacesImplementedByTypeExcludingBases(iface, resultList); } } } - - for (var i = 0, l = toEnumerate.length; i < l; i++) { - var iface = toEnumerate[i]; - JSIL.$EnumInterfacesImplementedByTypeExcludingBases(iface, resultList); - } }; JSIL.$FindMatchingInterfacesThroughVariance = function (expectedInterfaceObject, actualTypeObject, variantParameters) { @@ -8623,10 +8511,6 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature if (!matchingInterfaces.length) return null; - else if (!signature.openSignature) { - // FIXME: Is this right? - return null; - } var result = []; @@ -8647,14 +8531,21 @@ JSIL.$GenerateVariantInvocationCandidates = function (interfaceObject, signature return result; }; -JSIL.$GetEnumeratorFallback = function () { - if (typeof (this) === "string") - return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); - else if (JSIL.IsArray(this)) - // HACK: Too hard to detect the correct element type here. - return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); - else - JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); +JSIL.$GetEnumeratorFallback = function (thisTypeObject) { + var interfaceTypeObject = thisTypeObject; + return function () { + if (typeof (this) === "string") + return JSIL.GetEnumerator(this, $jsilcore.System.Char.__Type__, true); + else if (JSIL.IsArray(this)) { + if (interfaceTypeObject.IsGenericType) { + return JSIL.GetEnumerator(this, thisTypeObject.__GenericArgumentValues__[0], true); + } + // HACK: Too hard to detect the correct element type here. + return JSIL.GetEnumerator(this, $jsilcore.System.Object.__Type__, true); + } + else + JSIL.RuntimeError("Object of type '" + JSIL.GetType(this) + "' has no implementation of GetEnumerator"); + }; }; // FIXME: This can probably be replaced with compiler and/or runtime intelligence @@ -8673,21 +8564,7 @@ JSIL.$PickFallbackMethodForInterfaceMethod = function (interfaceObject, methodNa return null; }; -JSIL.$DoTypesMatch = function (expected, type) { - if (expected === null) - return (type === null); - - if (expected === type) - return true; - - if (expected.__FullName__ === "System.Array") - return type.__IsArray__; - - return false; -} - -JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes, returnType) { - var trace = false; +JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes) { var l = methods.length; for (var i = 0; i < l; i++) { @@ -8697,35 +8574,19 @@ JSIL.$FilterMethodsByArgumentTypes = function (methods, argumentTypes, returnTyp var parameterInfos = $jsilcore.$MethodGetParameters(method); if (parameterInfos.length !== argumentTypes.length) { - if (trace) - console.log("Dropping because wrong argcount", argumentTypes.length, parameterInfos.length); - remove = true; } else { for (var j = 0; j < argumentTypes.length; j++) { var argumentType = argumentTypes[j]; var argumentTypeB = parameterInfos[j].get_ParameterType(); - if (!JSIL.$DoTypesMatch(argumentType, argumentTypeB)) { - if (trace) - console.log("Dropping because arg mismatch", argumentType.__FullName__, argumentTypeB.__FullName__); - + if (argumentType !== argumentTypeB) { remove = true; break; } } } - if (typeof (returnType) !== "undefined") { - // FIXME: Do a more complete assignability check - if (!JSIL.$DoTypesMatch(returnType, method.get_ReturnType())) { - if (trace) - console.log("Dropping because wrong return type", returnType.__FullName__, method.get_ReturnType().__FullName__); - - remove = true; - } - } - if (remove) { methods[i] = methods[l - 1]; l -= 1; @@ -8787,13 +8648,6 @@ JSIL.$IgnoredPublicInterfaceMembers = [ ]; JSIL.$CopyMembersIndirect = function (target, source, ignoredNames, recursive) { - if (!source) - JSIL.RuntimeError("No source provided for copy"); - - if (source.__ThisType__ && (source.__ThisType__.__FullName__.indexOf("ArrayEnumerator") >= 0)) { - // debugger; - } - // FIXME: for ( in ) is deoptimized in V8. Maybe use Object.keys(), or type metadata? for (var k in source) { if (ignoredNames.indexOf(k) !== -1) @@ -8812,24 +8666,21 @@ JSIL.$CopyMembersIndirect = function (target, source, ignoredNames, recursive) { JSIL.$CopyInterfaceMethods = function (interfaceList, target) { var imProto = JSIL.InterfaceMethod.prototype; - var makeGetter = function (src, key) { - return function () { - return src[key]; - }; - }; - for (var i = 0, l = interfaceList.length; i < l; i++) { var ifaceRef = interfaceList[i]; var iface = JSIL.ResolveTypeReference(ifaceRef)[0]; for (var k in iface) { - if (!Object.prototype.hasOwnProperty.call(iface, k)) - continue; + var im = iface[k]; - if (Object.prototype.hasOwnProperty.call(target, k)) + if ( + !im || + (typeof(im) !== "object") || + (Object.getPrototypeOf(im) !== imProto) + ) continue; - JSIL.SetLazyValueProperty(target, k, makeGetter(iface, k)); + target[k] = iface[k]; } } }; diff --git a/Libraries/XNA/Graphics.js b/Libraries/XNA/Graphics.js index 7c613aff0..a9343889b 100644 --- a/Libraries/XNA/Graphics.js +++ b/Libraries/XNA/Graphics.js @@ -2916,34 +2916,6 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.Texture2D", function ( return result; }; - var doUnpremultiply = function (dataBytes, bytes, startIndex, elementCount) { - var pixelCount = (elementCount / 4) | 0; - for (var i = 0; i < pixelCount; i++) { - var p = (i * 4) | 0; - var p1 = (p + 1) | 0; - var p2 = (p + 2) | 0; - var p3 = (p + 3) | 0; - - var a = bytes[p3] | 0; - - if (a <= 0) { - continue; - } else if (a > 254) { - dataBytes[p] = bytes[p]; - dataBytes[p1] = bytes[p1]; - dataBytes[p2] = bytes[p2]; - dataBytes[p3] = a; - } else { - var m = 255 / a; - - dataBytes[p] = (bytes[p] * m) | 0; - dataBytes[p1] = (bytes[p1] * m) | 0; - dataBytes[p2] = (bytes[p2] * m) | 0; - dataBytes[p3] = a; - } - } - }; - $.RawMethod(false, "$makeImageDataForBytes", function $makeImageDataForBytes ( width, height, bytes, startIndex, elementCount, @@ -2966,7 +2938,28 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Graphics.Texture2D", function ( // XNA texture colors are premultiplied, but canvas pixels aren't, so we need to try // to reverse the premultiplication. if (unpremultiply) { - doUnpremultiply(dataBytes, bytes, startIndex, elementCount); + var pixelCount = elementCount / 4; + for (var i = 0; i < pixelCount; i++) { + var p = (i * 4) | 0; + + var a = bytes[(p + 3) | 0]; + + if (a <= 0) { + continue; + } else if (a > 254) { + dataBytes[p] = bytes[p]; + dataBytes[(p + 1) | 0] = bytes[(p + 1) | 0]; + dataBytes[(p + 2) | 0] = bytes[(p + 2) | 0]; + dataBytes[(p + 3) | 0] = a; + } else { + var m = 255 / a; + + dataBytes[p] = bytes[p] * m; + dataBytes[(p + 1) | 0] = bytes[(p + 1) | 0] * m; + dataBytes[(p + 2) | 0] = bytes[(p + 2) | 0] * m; + dataBytes[(p + 3) | 0] = a; + } + } } else { fastArrayCopy(dataBytes, 0, bytes, startIndex, elementCount); } diff --git a/Tests/FailingTestCases/LinqAggregate.cs b/Tests/FailingTestCases/LinqAggregate.cs deleted file mode 100644 index 9fc232efc..000000000 --- a/Tests/FailingTestCases/LinqAggregate.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using System.Linq; - -public static class Program { - public static void Main (string[] args) { - Console.WriteLine(new[] { "one", "two" }.Aggregate((x, y) => x + ", " + y)); - } -} \ No newline at end of file diff --git a/Tests/SimpleTestCases/Issue298.cs b/Tests/SimpleTestCases/Issue298.cs deleted file mode 100644 index 867acc573..000000000 --- a/Tests/SimpleTestCases/Issue298.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using JSIL.Meta; - -public static class Program { - public static void Main (string[] args) { - Console.WriteLine(((IMyInterface)new MyClass()).Add()); - } -} - -public interface IMyInterface : IList { - int Add (); -} - -public class MyClass : IMyInterface { - public int Add () { - return 5; - } - - public int IndexOf (int item) { - throw new NotImplementedException(); - } - - public void Insert (int index, int item) { - throw new NotImplementedException(); - } - - public void RemoveAt (int index) { - throw new NotImplementedException(); - } - - public int this[int index] { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } - } - - public void Add (int item) { - throw new NotImplementedException(); - } - - public void Clear () { - throw new NotImplementedException(); - } - - public bool Contains (int item) { - throw new NotImplementedException(); - } - - public void CopyTo (int[] array, int arrayIndex) { - throw new NotImplementedException(); - } - - public int Count { - get { throw new NotImplementedException(); } - } - - public bool IsReadOnly { - get { throw new NotImplementedException(); } - } - - public bool Remove (int item) { - throw new NotImplementedException(); - } - - public System.Collections.Generic.IEnumerator GetEnumerator () { - throw new NotImplementedException(); - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 3e6acd989..80228d4c9 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -257,7 +257,6 @@ - From ec2542c5f3fe587a34e78db59bf351d604e8d33f Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Fri, 25 Apr 2014 15:44:47 +0200 Subject: [PATCH 10/16] Implemented Type.IsInstanceOfType --- .gitignore | 3 +- Libraries/JSIL.Core.Reflection.js | 27 +++++++++++ .../SameNameDifferentReturnTypes.js | 48 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Tests/JSTestCases/SameNameDifferentReturnTypes.js diff --git a/.gitignore b/.gitignore index 27c196610..b45ea9e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -92,4 +92,5 @@ Corlib/*.js /Upstream/OpenTKBindingGenerator /Upstream/OpenTKHeaderParser *.RuntimeProfile -*.out \ No newline at end of file +*.out +*.orig \ No newline at end of file diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index d22c83465..1fc5e38c3 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -57,6 +57,33 @@ JSIL.ImplementExternals( } ); + $.Method({ Public: true, Static: false, Virtual: true }, "IsInstanceOfType", + new JSIL.MethodSignature($.Boolean, [$.Object]), + function (object) { + var typeObject = object.GetType(); + if (this.get_IsInterface() === true) { + // Check interfaces + + var interfaces = JSIL.GetInterfacesImplementedByType(typeObject); + if (interfaces && interfaces.length) { + for (var i = 0; i < interfaces.length; i++) { + if (interfaces[i].__FullName__ == this.__FullName__) + return true; + } + + } + } else { + // Check inheritance tree + var types = JSIL.GetTypeAndBases(typeObject); + for (var i = 0; i < types.length; i++) { + if (types[i].__FullName__ == this.__FullName__) + return true; + } + } + return false; + } + ); + $.Method({Static:false, Public:true }, "get_IsGenericType", new JSIL.MethodSignature($.Boolean, []), JSIL.TypeObjectPrototype.get_IsGenericType diff --git a/Tests/JSTestCases/SameNameDifferentReturnTypes.js b/Tests/JSTestCases/SameNameDifferentReturnTypes.js new file mode 100644 index 000000000..4c98b3490 --- /dev/null +++ b/Tests/JSTestCases/SameNameDifferentReturnTypes.js @@ -0,0 +1,48 @@ +var $asm = JSIL.DeclareAssembly("Test"); + +JSIL.MakeStaticClass("Program", true, [], function ($) { + $.Method({Static:true , Public:true }, "Main", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [$.String])], []), + function Main (args) { + try { + var inst = new T(); + var x = inst.Method(); + } catch (exc) { + if (String(exc).indexOf("name and argument list") >= 0) { + print(exc); + return; + } else { + throw exc; + } + } + + throw new Error("Should have failed"); + } + ); +}); + +JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "T", + IsPublic: true, + IsReferenceType: true, + }, function ($) { + $.Method( + { Public: true, Static: false}, + "Method", + new JSIL.MethodSignature($.String, null, []), + function () { + return "String Method"; + } + ); + + $.Method( + { Public: true, Static: false}, + "Method", + new JSIL.MethodSignature($.Int32, null, []), + function () { + return "Int32 Method"; + } + ); + } +); \ No newline at end of file From 114974d42a404574c02ab3c414133923864abc6d Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Fri, 25 Apr 2014 15:53:32 +0200 Subject: [PATCH 11/16] Reformatted Boostrap --- Libraries/JSIL.Bootstrap.js | 266 ++++++++++++++++++------------------ 1 file changed, 133 insertions(+), 133 deletions(-) diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index 2fb2c5b4c..0d20698cb 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -698,8 +698,8 @@ JSIL.MakeStaticClass("System.Console", true, [], function ($) { JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($) { var T = new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator"); - $.RawMethod(false, "__CopyMembers__", - function ArrayEnumerator_CopyMembers (source, target) { + $.RawMethod(false, "__CopyMembers__", + function ArrayEnumerator_CopyMembers(source, target) { target._array = source._array; target._length = source._length; target._index = source._index; @@ -727,15 +727,15 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ this._index = -1; } ); - - $.Method({Public: true , Static: false}, "MoveNext", + + $.Method({ Public: true, Static: false }, "MoveNext", new JSIL.MethodSignature(System.Boolean, []), function () { return (++this._index < this._length); } ); - $.Method({Public: true , Static: false}, "Dispose", + $.Method({ Public: true, Static: false }, "Dispose", new JSIL.MethodSignature(null, []), function () { this._array = null; @@ -744,7 +744,7 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ } ); - $.Method({Public: true , Static: false}, "IEnumerator_get_Current", + $.Method({ Public: true, Static: false }, "IEnumerator_get_Current", new JSIL.MethodSignature(System.Object, []), function () { return this._array[this._index]; @@ -752,7 +752,7 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ ) .Overrides(1, "get_Current"); - $.Method({Public: true , Static: false}, "get_Current", + $.Method({ Public: true, Static: false }, "get_Current", new JSIL.MethodSignature(T, []), function () { return this._array[this._index]; @@ -760,10 +760,10 @@ JSIL.MakeClass("System.Object", "JSIL.ArrayEnumerator", true, ["T"], function ($ ) .Overrides(2, "get_Current"); - $.Property({Public: true , Static: false, Virtual: true }, "Current"); + $.Property({ Public: true, Static: false, Virtual: true }, "Current"); $.ImplementInterfaces( - /* 0 */ System.IDisposable, + /* 0 */ System.IDisposable, /* 1 */ System.Collections.IEnumerator, /* 2 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [new JSIL.GenericParameter("T", "JSIL.ArrayEnumerator")]) ); @@ -1148,8 +1148,8 @@ $jsilcore.$ListExternals = function ($, T, type) { switch (type) { case "List": - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1+Enumerator", [T]), [], [])), + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.List`1+Enumerator", [T]), [], [])), getEnumeratorImpl ); break; @@ -1555,9 +1555,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), - function GetEnumerator () { + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), + function GetEnumerator() { return this.$GetEnumerator(); } ); @@ -1642,9 +1642,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Queue`1", function ($) { } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), - function GetEnumerator () { + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Queue`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Queue`1")]), [], [])), + function GetEnumerator() { return this.$GetEnumerator(); } ); @@ -2056,9 +2056,9 @@ JSIL.MakeStruct("System.ValueType", "System.Decimal", true, [], function ($) { }); JSIL.ImplementExternals("System.Environment", function ($) { - $.Method({Static:true , Public:true }, "GetFolderPath", - (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment+SpecialFolder")], [])), - function GetFolderPath (folder) { + $.Method({ Static: true, Public: true }, "GetFolderPath", + (new JSIL.MethodSignature($.String, [$jsilcore.TypeRef("System.Environment+SpecialFolder")], [])), + function GetFolderPath(folder) { // FIXME return folder.name; } @@ -2253,9 +2253,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); - $.Method({Static:false, Public:true }, "get_Keys", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Keys () { + $.Method({ Static: false, Public: true }, "get_Keys", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Keys() { if (this.tKeyCollection === null) { this.tKeyCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection.Of(this.TKey, this.TValue).__Type__; this.tKeyEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_KeyCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; @@ -2265,9 +2265,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); - $.Method({Static:false, Public:true }, "get_Values", - (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), - function get_Values () { + $.Method({ Static: false, Public: true }, "get_Values", + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2+ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + function get_Values() { if (this.tValueCollection === null) { this.tValueCollection = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection.Of(this.TKey, this.TValue).__Type__; this.tValueEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_ValueCollection_Enumerator.Of(this.TKey, this.TValue).__Type__; @@ -2277,7 +2277,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); - var getEnumeratorImpl = function GetEnumerator () { + var getEnumeratorImpl = function GetEnumerator() { if (this.tEnumerator === null) { this.tEnumerator = $jsilcore.System.Collections.Generic.Dictionary$b2_Enumerator.Of(this.TKey, this.TValue).__Type__; } @@ -2285,31 +2285,31 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); }; - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", (new JSIL.MethodSignature( mscorlib.TypeRef( "System.Collections.Generic.Dictionary`2+Enumerator", [ - new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), + new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") ] ), [], []) - ), + ), getEnumeratorImpl ); - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.IEnumerator"), [], [])), getEnumeratorImpl ) .Overrides("System.Collections.IEnumerable", "GetEnumerator"); - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", (new JSIL.MethodSignature( mscorlib.TypeRef( "System.Collections.Generic.IEnumerator`1", [ mscorlib.TypeRef( "System.Collections.Generic.KeyValuePair`2", [ - new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), + new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2") ] ) @@ -2320,9 +2320,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) ) .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); - $.Method({Static:false, Public:true }, "set_Item", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), - function set_Item (key, value) { + $.Method({ Static: false, Public: true }, "set_Item", + (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")], [])), + function set_Item(key, value) { var bucketEntry = this.$searchBucket(key); if (bucketEntry !== null) return bucketEntry.value = value; @@ -2383,9 +2383,9 @@ JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", function ($interfaceBuilder) { var $ = $interfaceBuilder; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), - function _ctor (dictionary) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")])], []), + function _ctor(dictionary) { this.dictionary = dictionary; } ); @@ -2397,9 +2397,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), - function GetEnumerator () { + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection")]), [], []), + function GetEnumerator() { return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); } ); @@ -2416,9 +2416,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection", function ($interfaceBuilder) { var $ = $interfaceBuilder; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), - function _ctor (dictionary) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection")])], []), + function _ctor(dictionary) { this.dictionary = dictionary; } ); @@ -2462,9 +2462,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", function ($interfaceBuilder) { var $ = $interfaceBuilder; - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), - function _ctor (dictionary) { + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator")])], []), + function _ctor(dictionary) { this.dictionary = dictionary; this.kvpEnumerator = null; this.System_Collections_IEnumerator_Reset(); @@ -2489,9 +2489,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+E } ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), - function get_Current () { + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator"), [], []), + function get_Current() { return this.kvpEnumerator.get_Current().key; } ); @@ -2523,9 +2523,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection+E JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", function ($interfaceBuilder) { var $ = $interfaceBuilder; - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), - function _ctor (dictionary) { + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator")])], []), + function _ctor(dictionary) { this.dictionary = dictionary; this.kvpEnumerator = null; this.System_Collections_IEnumerator_Reset(); @@ -2550,9 +2550,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection } ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), - function get_Current () { + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature(new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator"), [], []), + function get_Current() { return this.kvpEnumerator.get_Current().value; } ); @@ -2604,51 +2604,51 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Dictionary`2+Enumerator", false, ["TKey", "TValue"], function ($) { $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), - /* 1 */ $jsilcore.TypeRef("System.IDisposable"), - /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [$jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IDictionaryEnumerator"), /* 3 */ $jsilcore.TypeRef("System.Collections.IEnumerator") ); }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.Object"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection", - IsPublic: true, - IsReferenceType: true, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection", + IsPublic: true, + IsReferenceType: true, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.MakeType({ - BaseType: $jsilcore.TypeRef("System.ValueType"), - Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", - IsPublic: true, - IsReferenceType: false, - GenericParameters: ["TKey", "TValue"], - MaximumConstructorArguments: 1, - }, function ($) { + BaseType: $jsilcore.TypeRef("System.ValueType"), + Name: "System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator", + IsPublic: true, + IsReferenceType: false, + GenericParameters: ["TKey", "TValue"], + MaximumConstructorArguments: 1, +}, function ($) { }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", function ($interfaceBuilder) { @@ -2661,9 +2661,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", fu } ); - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), - function _ctor (dictionary) { + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")])], []), + function _ctor(dictionary) { this.dictionary = dictionary; var tKey = dictionary.TKey, tValue = dictionary.TValue; @@ -2681,9 +2681,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", fu } ); - $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), - function _ctor (dictionary, getEnumeratorRetType) { + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Dictionary`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), $.Int32], []), + function _ctor(dictionary, getEnumeratorRetType) { throw new Error('Not implemented'); } ); @@ -2696,9 +2696,9 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+Enumerator", fu } ); - $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), - function get_Current () { + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.KeyValuePair`2", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+Enumerator"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2+Enumerator")]), [], []), + function get_Current() { return this.state.current.MemberwiseClone(); } ); @@ -2896,7 +2896,7 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function } ); - $.Method({Static: false, Public: true }, "IEnumerator_get_Current", + $.Method({ Static: false, Public: true }, "IEnumerator_get_Current", new JSIL.MethodSignature($.Object, []), function () { return this._current.get(); @@ -2904,7 +2904,7 @@ JSIL.MakeClass("System.Object", "JSIL.AbstractEnumerator", true, ["T"], function ) .Overrides(0, "get_Current"); - $.Method({Static: false, Public: true }, "get_Current", + $.Method({ Static: false, Public: true }, "get_Current", new JSIL.MethodSignature(T, []), function () { return this._current.get(); @@ -3397,18 +3397,18 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [T])], [])), - function _ctor (comparer) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [T])], [])), + function _ctor(comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], [])), - function _ctor (collection) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T])], [])), + function _ctor(collection) { this._dict = {}; this._count = 0; this._comparer = null; @@ -3416,9 +3416,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), - function _ctor (collection, comparer) { + $.Method({ Static: false, Public: true }, ".ctor", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [T]), $jsilcore.TypeRef("System.Collections.Generic.IEqualityComparer`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1")])], [])), + function _ctor(collection, comparer) { this._dict = {}; this._count = 0; this._comparer = comparer; @@ -3426,9 +3426,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Add", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Add (item) { + $.Method({ Static: false, Public: true }, "Add", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Add(item) { var bucketEntry = this.$searchBucket(item); if (bucketEntry !== null) @@ -3454,9 +3454,9 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Contains", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Contains (item) { + $.Method({ Static: false, Public: true }, "Contains", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Contains(item) { return this.$searchBucket(item) !== null; } ); @@ -3468,19 +3468,19 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); - $.Method({Static:false, Public:true }, "Remove", - (new JSIL.MethodSignature($.Boolean, [T], [])), - function Remove (item) { + $.Method({ Static: false, Public: true }, "Remove", + (new JSIL.MethodSignature($.Boolean, [T], [])), + function Remove(item) { return this.$removeByKey(item); } ); - var getEnumeratorImpl = function GetEnumerator () { + var getEnumeratorImpl = function GetEnumerator() { var dict = this._dict; // FIXME: Return an actual instance of HashSet`1+Enumerator. - return new (JSIL.AbstractEnumerator.Of(this.T)) ( - function getNext (result) { + return new (JSIL.AbstractEnumerator.Of(this.T))( + function getNext(result) { var keys = this._state.keys; var valueIndex = ++(this._state.valueIndex); var bucketIndex = this._state.bucketIndex; @@ -3500,7 +3500,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { return false; }, - function reset () { + function reset() { this._state = { current: JSIL.DefaultValue(this.T), keys: Object.keys(dict), @@ -3508,31 +3508,31 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { valueIndex: -1 }; }, - function dispose () { + function dispose() { this._state = null; } ); }; - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", new JSIL.MethodSignature( $jsilcore.TypeRef("System.Collections.Generic.HashSet`1+Enumerator", [T]), [], [] - ), + ), getEnumeratorImpl ) - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", new JSIL.MethodSignature( $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], [] - ), + ), getEnumeratorImpl ) .Overrides(0, "GetEnumerator"); - $.Method({Static:false, Public:true }, "GetEnumerator", + $.Method({ Static: false, Public: true }, "GetEnumerator", new JSIL.MethodSignature( $jsilcore.TypeRef("System.Collections.IEnumerator", []), [], [] - ), + ), getEnumeratorImpl ) .Overrides(1, "GetEnumerator"); @@ -3553,8 +3553,8 @@ JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Gener var T = new JSIL.GenericParameter("T", "System.Collections.Generic.HashSet`1+Enumerator"); $.ImplementInterfaces( - /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), - /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), /* 2 */ $jsilcore.TypeRef("System.Collections.IEnumerator") ); }); @@ -4592,9 +4592,9 @@ JSIL.ImplementExternals("System.Collections.Generic.LinkedList`1", function ($) } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), - function GetEnumerator () { + $.Method({ Static: false, Public: true }, "GetEnumerator", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.LinkedList`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.LinkedList`1")]), [], [])), + function GetEnumerator() { throw new Error('Not implemented'); } ); From c9a3deefa5cdbff4949e3866d05bac135801d331 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Mon, 28 Apr 2014 15:58:55 +0200 Subject: [PATCH 12/16] Added IsAbstract and IsPrimitive for interfaces --- Libraries/JSIL.Core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index b55ac3425..cc07f5c61 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -5325,6 +5325,7 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer typeObject.__IsReferenceType__ = true; typeObject.__AssignableTypes__ = null; typeObject.IsInterface = true; + typeObject.__IsAbstract__ = true; typeObject.__Attributes__ = attributes; typeObject.__Interfaces__ = interfaces || []; @@ -8675,7 +8676,10 @@ JSIL.GetInterfacesImplementedByType = function (typeObject, walkInterfaceBases, JSIL.$EnumInterfacesImplementedByTypeExcludingBases = function (typeObject, resultList, distanceList, walkInterfaceBases, allowDuplicates, distance) { if (arguments.length !== 6) - JSIL.RuntimeError("6 arguments expected"); + JSIL.RuntimeError("6 arguments expected"); + + if (!typeObject) + return; var interfaces = typeObject.__Interfaces__; From befd71710681bd81a987fa1ca4a3adc84080004f Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Wed, 30 Apr 2014 08:56:05 +0200 Subject: [PATCH 13/16] Add web worker support --- Libraries/JSIL.Bootstrap.js | 4 +- Libraries/JSIL.WebWorker.Loaders.js | 481 +++++++++++++++++ Libraries/JSIL.WebWorker.js | 802 ++++++++++++++++++++++++++++ Libraries/JSIL.js | 40 +- 4 files changed, 1320 insertions(+), 7 deletions(-) create mode 100644 Libraries/JSIL.WebWorker.Loaders.js create mode 100644 Libraries/JSIL.WebWorker.js diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index a4149b592..f8d63badd 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1768,8 +1768,8 @@ JSIL.ImplementExternals( JSIL.ImplementExternals("System.Threading.Monitor", function ($) { var enterImpl = function (obj) { var current = (obj.__LockCount__ || 0); - if (current >= 1) - JSIL.Host.warning("Warning: lock recursion " + obj); + /*if (current >= 1) + JSIL.Host.warning("Warning: lock recursion " + obj);*/ obj.__LockCount__ = current + 1; diff --git a/Libraries/JSIL.WebWorker.Loaders.js b/Libraries/JSIL.WebWorker.Loaders.js new file mode 100644 index 000000000..16388a9b1 --- /dev/null +++ b/Libraries/JSIL.WebWorker.Loaders.js @@ -0,0 +1,481 @@ +JSIL.loadGlobalScript = function (uri, onComplete) { + try { + importScripts(uri); + console.log("Loaded: " + uri); + } catch (exc) { + done = true; + onComplete(null, exc); + } +}; + +var warnedAboutOpera = false; +var warnedAboutCORS = false; +var warnedAboutCORSImage = false; +var hasCORSXhr = false, hasCORSImage = false; + +function getAbsoluteUrl (localUrl) { + return location.href + localUrl; +}; + +function doXHR (uri, asBinary, onComplete) { + var req = null, isXDR = false; + + var needCORS = jsilConfig.CORS; + var urlPrefix = location.protocol + "//" + location.host + "/"; + + var absoluteUrl = getAbsoluteUrl(uri); + var sameHost = (absoluteUrl.indexOf(urlPrefix) >= 0); + + needCORS = needCORS && !sameHost; + + if (location.protocol === "file:") { + var errorText = "Loading assets from file:// is not possible in modern web browsers. You must host your application/game on a web server."; + + if (console && console.error) { + console.error(errorText + "\nFailed to load: " + uri); + onComplete(null, errorText); + return; + } else { + throw new Error(errorText); + } + } else { + req = new XMLHttpRequest(); + + if (needCORS && !("withCredentials" in req)) { + if ((!asBinary) && (typeof (XDomainRequest) !== "undefined")) { + isXDR = true; + req = new XDomainRequest(); + } else { + if (!warnedAboutCORS) { + JSIL.Host.logWriteLine("WARNING: This game requires support for CORS, and your browser does not appear to have it. Loading may fail."); + warnedAboutCORS = true; + } + + onComplete(null, "CORS unavailable"); + return; + } + } + } + + var isDone = false; + var releaseEventListeners = function () { + req.onprogress = null; + req.onload = null; + req.onerror = null; + req.ontimeout = null; + req.onreadystatechange = null; + }; + var succeeded = function (response, status, statusText) { + if (isDone) + return; + + isDone = true; + releaseEventListeners(); + + if (status >= 400) { + onComplete( + { + response: response, + status: status, + statusText: statusText + }, + statusText || status + ); + } else { + onComplete( + { + response: response, + status: status, + statusText: statusText + }, null + ); + } + }; + var failed = function (error) { + if (isDone) + return; + + isDone = true; + releaseEventListeners(); + + onComplete(null, error); + }; + + if (isXDR) { + // http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/30ef3add-767c-4436-b8a9-f1ca19b4812e + req.onprogress = function () {}; + + req.onload = function () { + succeeded(req.responseText); + }; + + req.onerror = function () { + failed("Unknown error"); + }; + + req.ontimeout = function () { + failed("Timed out"); + }; + } else { + req.onreadystatechange = function (evt) { + if (req.readyState != 4) + return; + + if (isDone) + return; + + if (asBinary) { + var bytes; + var ieResponseBody = null; + + try { + if ( + (typeof (ArrayBuffer) === "function") && + (typeof (req.response) === "object") && + (req.response !== null) + ) { + var buffer = req.response; + bytes = new Uint8Array(buffer); + } else if ( + (typeof (VBArray) !== "undefined") && + ("responseBody" in req) && + ((ieResponseBody = new VBArray(req.responseBody).toArray()) != null) + ) { + bytes = ieResponseBody; + } else if (req.responseText) { + var text = req.responseText; + bytes = JSIL.StringToByteArray(text); + } else { + failed("Unknown error"); + return; + } + } catch (exc) { + failed(exc); + return; + } + + succeeded(bytes, req.status, req.statusText); + } else { + try { + var responseText = req.responseText; + } catch (exc) { + failed(exc); + return; + } + + succeeded(responseText, req.status, req.statusText); + } + }; + } + + try { + if (isXDR) { + req.open('GET', uri); + } else { + req.open('GET', uri, true); + } + } catch (exc) { + failed(exc); + } + + if (asBinary) { + if (typeof (ArrayBuffer) === "function") { + req.responseType = 'arraybuffer'; + } + + if (typeof (req.overrideMimeType) !== "undefined") { + req.overrideMimeType('application/octet-stream; charset=x-user-defined'); + } else { + req.setRequestHeader('Accept-Charset', 'x-user-defined'); + } + } else { + if (typeof (req.overrideMimeType) !== "undefined") { + req.overrideMimeType('text/plain; charset=x-user-defined'); + } else { + req.setRequestHeader('Accept-Charset', 'x-user-defined'); + } + } + + try { + if (isXDR) { + req.send(null); + } else { + req.send(); + } + } catch (exc) { + failed(exc); + } +}; + +function loadTextAsync (uri, onComplete) { + return doXHR(uri, false, function (result, error) { + if (result) + onComplete(result.response, error); + else + onComplete(null, error); + }); +}; + +function postProcessResultNormal (bytes) { + return bytes; +}; + +function postProcessResultOpera (bytes) { + // Opera sniffs content types on request bodies and if they're text, converts them to 16-bit unicode :| + + if ( + (bytes[1] === 0) && + (bytes[3] === 0) && + (bytes[5] === 0) && + (bytes[7] === 0) + ) { + if (!warnedAboutOpera) { + JSIL.Host.logWriteLine("WARNING: Your version of Opera has a bug that corrupts downloaded file data. Please update to a new version or try a better browser."); + warnedAboutOpera = true; + } + + var resultBytes = new Array(bytes.length / 2); + for (var i = 0, j = 0, l = bytes.length; i < l; i += 2, j += 1) { + resultBytes[j] = bytes[i]; + } + + return resultBytes; + } else { + return bytes; + } +}; + +function loadBinaryFileAsync (uri, onComplete) { + var postProcessResult = postProcessResultNormal; + if (window.navigator.userAgent.indexOf("Opera/") >= 0) { + postProcessResult = postProcessResultOpera; + } + + return doXHR(uri, true, function (result, error) { + if (result) + onComplete(postProcessResult(result.response), error); + else + onComplete(null, error); + }); +} + +var finishLoadingScript = function (state, path, onError) { + state.pendingScriptLoads += 1; + + JSIL.loadGlobalScript(path, function (result, error) { + state.pendingScriptLoads -= 1; + + if (error) { + var errorText = "Network request failed: " + stringifyLoadError(error); + + state.assetLoadFailures.push( + [path, errorText] + ); + + if (jsilConfig.onLoadFailure) { + try { + jsilConfig.onLoadFailure(path, errorText); + } catch (exc2) { + } + } + + onError(errorText); + } + }); +}; + +var loadScriptInternal = function (uri, onError, onDoneLoading, state) { + var absoluteUrl = getAbsoluteUrl(uri); + + var finisher = function () { + finishLoadingScript(state, uri, onError); + }; + + if (absoluteUrl.indexOf("file://") === 0) { + // No browser properly supports XHR against file:// + onDoneLoading(finisher); + } else { + loadTextAsync(uri, function (result, error) { + if ((result !== null) && (!error)) + onDoneLoading(finisher); + else + onError(error); + }); + } +}; + +var assetLoaders = { + "Library": function loadLibrary (filename, data, onError, onDoneLoading, state) { + var uri = jsilConfig.libraryRoot + filename; + loadScriptInternal(uri, onError, onDoneLoading, state); + }, + "Script": function loadScript (filename, data, onError, onDoneLoading, state) { + var uri = jsilConfig.scriptRoot + filename; + loadScriptInternal(uri, onError, onDoneLoading, state); + }, + "Image": function loadImage (filename, data, onError, onDoneLoading) { + var e = document.createElement("img"); + if (jsilConfig.CORS) { + if (hasCORSImage) { + e.crossOrigin = ""; + } else if (hasCORSXhr && ($blobBuilderInfo.hasBlobBuilder || $blobBuilderInfo.hasBlobCtor)) { + if (!warnedAboutCORSImage) { + JSIL.Host.logWriteLine("WARNING: This game requires support for CORS, and your browser does not support it for images. Using workaround..."); + warnedAboutCORSImage = true; + } + + return loadImageCORSHack(filename, data, onError, onDoneLoading); + } else { + if (!warnedAboutCORSImage) { + JSIL.Host.logWriteLine("WARNING: This game requires support for CORS, and your browser does not support it."); + warnedAboutCORSImage = true; + } + + onError("CORS unavailable"); + return; + } + } + + var finisher = function () { + $jsilbrowserstate.allAssetNames.push(filename); + allAssets[getAssetName(filename)] = new HTML5ImageAsset(getAssetName(filename, true), e); + }; + + JSIL.Browser.RegisterOneShotEventListener(e, "error", true, onError); + JSIL.Browser.RegisterOneShotEventListener(e, "load", true, onDoneLoading.bind(null, finisher)); + e.src = jsilConfig.contentRoot + filename; + }, + "File": function loadFile (filename, data, onError, onDoneLoading) { + loadBinaryFileAsync(jsilConfig.fileRoot + filename, function (result, error) { + if ((result !== null) && (!error)) { + $jsilbrowserstate.allFileNames.push(filename); + allFiles[filename.toLowerCase()] = result; + onDoneLoading(null); + } else { + onError(error); + } + }); + }, + "SoundBank": function loadSoundBank (filename, data, onError, onDoneLoading) { + loadTextAsync(jsilConfig.contentRoot + filename, function (result, error) { + if ((result !== null) && (!error)) { + var finisher = function () { + $jsilbrowserstate.allAssetNames.push(filename); + allAssets[getAssetName(filename)] = JSON.parse(result); + }; + onDoneLoading(finisher); + } else { + onError(error); + } + }); + }, + "Resources": function loadResources (filename, data, onError, onDoneLoading) { + loadTextAsync(jsilConfig.scriptRoot + filename, function (result, error) { + if ((result !== null) && (!error)) { + var finisher = function () { + $jsilbrowserstate.allAssetNames.push(filename); + allAssets[getAssetName(filename)] = JSON.parse(result); + }; + onDoneLoading(finisher); + } else { + onError(error); + } + }); + }, + "ManifestResource": function loadManifestResourceStream (filename, data, onError, onDoneLoading) { + loadBinaryFileAsync(jsilConfig.scriptRoot + filename, function (result, error) { + if ((result !== null) && (!error)) { + var dict = allManifestResources[data.assembly]; + if (!dict) + dict = allManifestResources[data.assembly] = Object.create(null); + + dict[filename.toLowerCase()] = result; + + onDoneLoading(null); + } else { + onError(error); + } + }); + } +}; + +function $makeXNBAssetLoader (key, typeName) { + assetLoaders[key] = function (filename, data, onError, onDoneLoading) { + loadBinaryFileAsync(jsilConfig.contentRoot + filename, function (result, error) { + if ((result !== null) && (!error)) { + var finisher = function () { + $jsilbrowserstate.allAssetNames.push(filename); + var key = getAssetName(filename, false); + var assetName = getAssetName(filename, true); + var parsedTypeName = JSIL.ParseTypeName(typeName); + var type = JSIL.GetTypeInternal(parsedTypeName, JSIL.GlobalNamespace, true); + allAssets[key] = JSIL.CreateInstanceOfType(type, [assetName, result]); + }; + onDoneLoading(finisher); + } else { + onError(error); + } + }); + }; +}; + +function loadImageCORSHack (filename, data, onError, onDoneLoading) { + var sourceURL = jsilConfig.contentRoot + filename; + + // FIXME: Pass mime type through from original XHR somehow? + var mimeType = "application/octet-stream"; + var sourceURLLower = sourceURL.toLowerCase(); + if (sourceURLLower.indexOf(".png") >= 0) { + mimeType = "image/png"; + } else if ( + (sourceURLLower.indexOf(".jpg") >= 0) || + (sourceURLLower.indexOf(".jpeg") >= 0) + ) { + mimeType = "image/jpeg"; + } + + loadBinaryFileAsync(sourceURL, function (result, error) { + if ((result !== null) && (!error)) { + var objectURL = null; + try { + objectURL = JSIL.GetObjectURLForBytes(result, mimeType); + } catch (exc) { + onError(exc); + return; + } + + var e = document.createElement("img"); + var finisher = function () { + $jsilbrowserstate.allAssetNames.push(filename); + allAssets[getAssetName(filename)] = new HTML5ImageAsset(getAssetName(filename, true), e); + }; + JSIL.Browser.RegisterOneShotEventListener(e, "error", true, onError); + JSIL.Browser.RegisterOneShotEventListener(e, "load", true, onDoneLoading.bind(null, finisher)); + e.src = objectURL; + } else { + onError(error); + } + }); +}; + +function initCORSHack () { + hasCORSXhr = false; + hasCORSImage = false; + + try { + var xhr = new XMLHttpRequest(); + hasCORSXhr = xhr && ("withCredentials" in xhr); + } catch (exc) { + } + + try { + var img = document.createElement("img"); + hasCORSImage = img && ("crossOrigin" in img); + } catch (exc) { + } +} + +function initAssetLoaders () { + JSIL.InitBlobBuilder(); + initCORSHack(); +}; \ No newline at end of file diff --git a/Libraries/JSIL.WebWorker.js b/Libraries/JSIL.WebWorker.js new file mode 100644 index 000000000..5469602d5 --- /dev/null +++ b/Libraries/JSIL.WebWorker.js @@ -0,0 +1,802 @@ +JSIL.DeclareNamespace("JSIL.WebWorker", false); + +var currentLogLine = null; + +var webglEnabled = false; + +var $jsilbrowserstate = window.$jsilbrowserstate = { + allFileNames: [], + allAssetNames: [], + readOnlyStorage: null, + heldKeys: [], + heldButtons: [], + mousePosition: [0, 0], + isLoading: false, + isLoaded: false, + isMainRunning: false, + hasMainRun: false, + mainRunAtTime: 0, + blockKeyboardInput: false, + blockGamepadInput: false +}; + +JSIL.WebWorker.PageVisibilityService = function () { +}; + +JSIL.WebWorker.PageVisibilityService.prototype.keys = ["hidden", "mozHidden", "msHidden", "webkitHidden"]; + +JSIL.WebWorker.PageVisibilityService.prototype.get = function () { + for (var i = 0, l = this.keys.length; i < l; i++) { + var key = this.keys[i]; + var value = document[key]; + + if (typeof (value) !== "undefined") + return !value; + } + + return true; +}; + + +JSIL.WebWorker.RunLaterService = function () { + this.queue = []; + this.pending = false; + this.boundStep = this.step.bind(this); +}; + +JSIL.WebWorker.RunLaterService.prototype.enqueue = function (callback) { + this.queue.push(callback); + + if (!this.pending) { + this.pending = true; + window.setTimeout(this.boundStep, 0); + } +}; + +JSIL.WebWorker.RunLaterService.prototype.step = function () { + var count = this.queue.length; + this.pending = false; + + for (var i = 0; i < count; i++) { + var item = this.queue[i]; + item(); + } + + this.queue.splice(0, count); +}; + + +JSIL.WebWorker.LogService = function () { + this.currentLine = null; +}; + +JSIL.WebWorker.LogService.prototype.write = function (text) { + postMessage({ operation: 'log', text: text }); +}; + + +JSIL.WebWorker.WarningService = function (stream) { + this.stream = stream; +}; + +JSIL.WebWorker.WarningService.prototype.write = function (text) { + // Quirky behavior, but we suppress warnings from the log if the console is available. + if (console && console.warn) { + if (typeof (text) === "string") { + console.warn(text.trim()); + } + else + console.warn(text); + } else if (this.stream) { + this.stream.write(text); + } +}; + +JSIL.WebWorker.LocalStorageService = function (storage) { + this.storage = storage; +}; + +JSIL.WebWorker.LocalStorageService.prototype.getItem = function (key) { + return this.storage.getItem(key); +}; + +JSIL.WebWorker.LocalStorageService.prototype.setItem = function (key, text) { + return this.storage.setItem(key, text); +}; + +JSIL.WebWorker.LocalStorageService.prototype.removeItem = function (key) { + return this.storage.removeItem(key); +}; + +JSIL.WebWorker.LocalStorageService.prototype.getKeys = function () { + var result = new Array(this.storage.length); + + for (var i = 0, l = result.length; i < l; i++) + result[i] = this.storage.key(i); + + return result; +}; + + +JSIL.WebWorker.WindowService = function (window) { + this.window = window; +}; + +JSIL.WebWorker.WindowService.prototype.alert = function () { + return this.window.alert.apply(this.window, arguments); +}; + +JSIL.WebWorker.WindowService.prototype.prompt = function () { + return this.window.prompt.apply(this.window, arguments); +}; + +JSIL.WebWorker.WindowService.prototype.getTitle = function () { + return this.window.title; +}; + +JSIL.WebWorker.WindowService.prototype.setTitle = function (value) { + return this.window.document.title = this.window.title = value; +}; + +JSIL.WebWorker.WindowService.prototype.getLocationHref = function () { + return this.window.location.href; +}; + +JSIL.WebWorker.WindowService.prototype.getLocationHash = function () { + return this.window.location.hash; +}; + +JSIL.WebWorker.WindowService.prototype.getLocationSearch = function () { + return this.window.location.search; +}; + +JSIL.WebWorker.WindowService.prototype.getNavigatorUserAgent = function () { + return this.window.navigator.userAgent; +}; + +JSIL.WebWorker.WindowService.prototype.getNavigatorLanguage = function () { + return this.window.navigator.language || + this.window.navigator.userLanguage || + this.window.navigator.systemLanguage || + null; +}; + +JSIL.WebWorker.WindowService.prototype.getPerformanceUsedJSHeapSize = function () { + if ( + (typeof (this.window.performance) !== "undefined") && + (typeof (this.window.performance.memory) !== "undefined") + ) { + return this.window.performance.memory.usedJSHeapSize; + } else { + return 0; + } +}; + + +JSIL.WebWorker.HistoryService = function (history) { + this.history = history; + this.canPushState = typeof (this.history.pushState) === "function"; +}; + +JSIL.WebWorker.HistoryService.prototype.pushState = function (a, b, c) { + return this.history.pushState(a, b, c); +}; + +JSIL.WebWorker.HistoryService.prototype.replaceState = function (a, b, c) { + return this.history.replaceState(a, b, c); +}; + +JSIL.WebWorker.TraceService = function (console) { + this.console = console; +}; + +JSIL.WebWorker.TraceService.prototype.write = function (text, category) { + if (this.console) { + if (arguments.length === 2) + this.console.log(category + ": " + text); + else if (arguments.length === 1) + this.console.log(text); + } +}; + +JSIL.WebWorker.TraceService.prototype.information = function (text) { + if (this.console) + this.console.log(text); +}; + +JSIL.WebWorker.TraceService.prototype.warning = function (text) { + if (this.console) + this.console.warn(text); +}; + +JSIL.WebWorker.TraceService.prototype.error = function (text) { + if (this.console) + this.console.error(text); +}; + + +(function () { + var logSvc = new JSIL.WebWorker.LogService(); + + JSIL.Host.registerServices({ + pageVisibility: new JSIL.WebWorker.PageVisibilityService(), + runLater: new JSIL.WebWorker.RunLaterService(), + stdout: logSvc, + stderr: new JSIL.WebWorker.WarningService(logSvc) + }); + + if (typeof (localStorage) !== "undefined") + JSIL.Host.registerService("localStorage", new JSIL.WebWorker.LocalStorageService(localStorage)); +})(); + + +JSIL.Host.translateFilename = function (filename) { + if (filename === null) + return null; + + var slashRe = /\\/g; + + var root = JSIL.Host.getRootDirectory().toLowerCase().replace(slashRe, "/"); + var _fileRoot = jsilConfig.fileRoot.toLowerCase().replace(slashRe, "/"); + var _filename = filename.replace(slashRe, "/").toLowerCase(); + + while (_filename[0] === "/") + _filename = _filename.substr(1); + + if (_filename.indexOf(root) === 0) + _filename = _filename.substr(root.length); + + while (_filename[0] === "/") + _filename = _filename.substr(1); + + if (_filename.indexOf(_fileRoot) === 0) + _filename = _filename.substr(_fileRoot.length); + + while (_filename[0] === "/") + _filename = _filename.substr(1); + + return _filename; +} +JSIL.Host.getImage = function (filename) { + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + throw new System.IO.FileNotFoundException("The image '" + key + "' is not in the asset manifest.", filename); + + return allAssets[key].image; +}; +JSIL.Host.doesAssetExist = function (filename, stripRoot) { + if (filename === null) + return false; + + if (stripRoot === true) { + var backslashRe = /\\/g; + + filename = filename.replace(backslashRe, "/").toLowerCase(); + var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); + + filename = filename.replace(croot, "").toLowerCase(); + } + + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + return false; + + return true; +}; +JSIL.Host.getAsset = function (filename, stripRoot) { + if (filename === null) + throw new System.Exception("Filename was null"); + + if (stripRoot === true) { + var backslashRe = /\\/g; + + filename = filename.replace(backslashRe, "/").toLowerCase(); + var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); + + filename = filename.replace(croot, "").toLowerCase(); + } + + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + throw new System.IO.FileNotFoundException("The asset '" + key + "' is not in the asset manifest.", filename); + + return allAssets[key]; +}; +JSIL.Host.getRootDirectory = function () { + var url = window.location.href; + var lastSlash = url.lastIndexOf("/"); + if (lastSlash === -1) + return url; + else + return url.substr(0, lastSlash); +}; +JSIL.Host.getStorageRoot = function () { + return $jsilbrowserstate.storageRoot; +}; + + +var $logFps = false; + +var allFiles = {}; +var allAssets = {}; +var allManifestResources = {}; + +function getAssetName(filename, preserveCase) { + var backslashRe = /\\/g; + filename = filename.replace(backslashRe, "/"); + + var doubleSlashRe = /\/\//g; + while (filename.indexOf("//") >= 0) + filename = filename.replace(doubleSlashRe, "/"); + + var lastIndex = filename.lastIndexOf("."); + var result; + if (lastIndex === -1) + result = filename; + else + result = filename.substr(0, lastIndex); + + if (preserveCase === true) + return result; + else + return result.toLowerCase(); +}; + +var loadedFontCount = 0; +var loadingPollInterval = 1; +var maxAssetsLoading = 4; +var soundLoadTimeout = 30000; +var fontLoadTimeout = 10000; +var finishStepDuration = 25; + +function finishLoading(st) { + var state = st; + + var started = Date.now(); + var endBy = started + finishStepDuration; + + var initFileStorage = function (volume) { + for (var i = 0, l = $jsilbrowserstate.allFileNames.length; i < l; i++) { + var filename = $jsilbrowserstate.allFileNames[i]; + var file = volume.createFile(filename, false, true); + file.writeAllBytes(allFiles[filename.toLowerCase()]); + } + }; + + var initIfNeeded = function () { + if (!state.jsilInitialized) { + state.jsilInitialized = true; + JSIL.Initialize(); + } + + if (state.initFailed) { + return; + } + + try { + if (typeof ($jsilreadonlystorage) !== "undefined") { + var prefixedFileRoot; + + if (jsilConfig.fileVirtualRoot[0] !== "/") + prefixedFileRoot = "/" + jsilConfig.fileVirtualRoot; + else + prefixedFileRoot = jsilConfig.fileVirtualRoot; + + $jsilbrowserstate.readOnlyStorage = new ReadOnlyStorageVolume("files", prefixedFileRoot, initFileStorage); + } + + JSIL.SetLazyValueProperty($jsilbrowserstate, "storageRoot", function InitStorageRoot() { + var root; + if (JSIL.GetStorageVolumes) { + var volumes = JSIL.GetStorageVolumes(); + + if (volumes.length) { + root = volumes[0]; + } + } + + if (!root && typeof (VirtualVolume) === "function") { + root = new VirtualVolume("root", "/"); + } + + if (root) { + if ($jsilbrowserstate.readOnlyStorage) { + var trimmedRoot = jsilConfig.fileVirtualRoot.trim(); + + if (trimmedRoot !== "/" && trimmedRoot) + root.createJunction(jsilConfig.fileVirtualRoot, $jsilbrowserstate.readOnlyStorage.rootDirectory, false); + else + root = $jsilbrowserstate.readOnlyStorage; + } + + return root; + } + + return null; + }); + + state.initFailed = false; + } catch (exc) { + state.initFailed = true; + + throw exc; + } + }; + + while (state.finishIndex < state.finishQueue.length) { + try { + var item = state.finishQueue[state.finishIndex]; + var cb = item[2]; + + // Ensure that we initialize the JSIL runtime before constructing asset objects. + if ((item[0] != "Script") && (item[0] != "Library")) { + initIfNeeded(); + } + + if (typeof (cb) === "function") { + cb(state); + } + } catch (exc) { + state.assetLoadFailures.push( + [item[3], exc] + ); + + if (jsilConfig.onLoadFailure) { + try { + jsilConfig.onLoadFailure(item[3], exc); + } catch (exc2) { + } + } + } finally { + state.finishIndex += 1; + state.assetsFinished += 1; + } + } + initIfNeeded(); + + var allFailures = $jsilloaderstate.loadFailures.concat(state.assetLoadFailures); + + return; +}; + +function pollAssetQueue(st) { + var state = st; + + var w = 0; + + var makeStepCallback = function (state, type, sizeBytes, i, name) { + return function (finish) { + var realName = name; + + var lastDot = name.lastIndexOf("."); + if (lastDot >= 0) + name = name.substr(0, lastDot); + + var firstComma = name.indexOf(","); + if (firstComma >= 0) + name = name.substr(0, firstComma); + + if (typeof (finish) === "function") + state.finishQueue.push([type, i, finish, name]); + + delete state.assetsLoadingNames[realName]; + state.assetsLoading -= 1; + state.assetsLoaded += 1; + + state.bytesLoaded += sizeBytes; + }; + }; + + var makeErrorCallback = function (assetPath, assetSpec) { + return function (e) { + delete state.assetsLoadingNames[getAssetName(assetPath)]; + state.assetsLoading -= 1; + state.assetsLoaded += 1; + + allAssets[getAssetName(assetPath)] = null; + + var errorText = stringifyLoadError(e); + + state.assetLoadFailures.push( + [assetPath, errorText] + ); + + if (jsilConfig.onLoadFailure) { + try { + jsilConfig.onLoadFailure(item[3], errorText); + } catch (exc2) { + } + } + + JSIL.Host.logWriteLine("The asset '" + assetPath + "' could not be loaded: " + errorText); + }; + }; + + while ((state.assetsLoading < maxAssetsLoading) && (state.loadIndex < state.assetCount)) { + try { + var assetSpec = state.assets[state.loadIndex]; + + var assetType = assetSpec[0]; + var assetPath = assetSpec[1]; + var assetData = assetSpec[2] || null; + var assetLoader = assetLoaders[assetType]; + + var sizeBytes = 1; + if (assetData !== null) + sizeBytes = assetData.sizeBytes || 1; + + var stepCallback = makeStepCallback(state, assetType, sizeBytes, state.loadIndex, assetPath); + var errorCallback = makeErrorCallback(assetPath, assetSpec); + + if (typeof (assetLoader) !== "function") { + errorCallback("No asset loader registered for type '" + assetType + "'."); + } else { + state.assetsLoading += 1; + state.assetsLoadingNames[assetPath] = assetLoader; + assetLoader(assetPath, assetData, errorCallback, stepCallback, state); + } + } finally { + state.loadIndex += 1; + } + } + + if (state.assetsLoaded >= state.assetCount) { + state.assetsLoadingNames = {}; + + state.finishQueue.sort(function (lhs, rhs) { + var lhsTypeIndex = 2, rhsTypeIndex = 2; + var lhsIndex = lhs[1]; + var rhsIndex = rhs[1]; + + switch (lhs[0]) { + case "Library": + lhsTypeIndex = 0; + break; + case "Script": + lhsTypeIndex = 1; + break; + } + + switch (rhs[0]) { + case "Library": + rhsTypeIndex = 0; + break; + case "Script": + rhsTypeIndex = 1; + break; + } + + var result = JSIL.CompareValues(lhsTypeIndex, rhsTypeIndex); + if (result === 0) + result = JSIL.CompareValues(lhsIndex, rhsIndex); + + return result; + }); + + finishLoading(state); + + return; + } +}; + +function loadAssets(assets) { + var state = { + assetBytes: 0, + assetCount: assets.length, + bytesLoaded: 0, + assetsLoaded: 0, + assetsFinished: 0, + assetsLoading: 0, + assets: assets, + interval: null, + finishQueue: [], + loadIndex: 0, + finishIndex: 0, + pendingScriptLoads: 0, + jsilInitialized: false, + assetsLoadingNames: {}, + assetLoadFailures: [], + failedFinishes: 0 + }; + + for (var i = 0, l = assets.length; i < l; i++) { + var properties = assets[i][2]; + + if (typeof (properties) !== "object") { + state.assetBytes += 1; + continue; + } + + var sizeBytes = properties.sizeBytes || 1; + state.assetBytes += sizeBytes; + } + + pollAssetQueue(state); +}; + +function beginLoading() { + initAssetLoaders(); + + var seenFilenames = {}; + + var pushAsset = function (assetSpec) { + var filename = assetSpec[1]; + if (seenFilenames[filename]) + return; + + seenFilenames[filename] = true; + allAssetsToLoad.push(assetSpec); + } + + var allAssetsToLoad = []; + if (typeof (window.assetsToLoad) !== "undefined") { + for (var i = 0, l = assetsToLoad.length; i < l; i++) + pushAsset(assetsToLoad[i]); + } + + if (typeof (contentManifest) === "object") { + for (var k in contentManifest) { + var subManifest = contentManifest[k]; + + for (var i = 0, l = subManifest.length; i < l; i++) + pushAsset(subManifest[i]); + + } + } + + postMessage("Loading data ... "); + loadAssets(allAssetsToLoad); +}; + +function registerErrorHandler() { + var oldErrorHandler = window.onerror; + + window.onerror = function JSIL_OnUnhandledException(errorMsg, url, lineNumber) { + JSIL.Host.logWriteLine("Unhandled exception at " + url + " line " + lineNumber + ":"); + JSIL.Host.logWriteLine(errorMsg); + + if (typeof (oldErrorHandler) === "function") + return oldErrorHandler(errorMsg, url, lineNumber); + else + return false; + }; +}; + +function stringifyLoadError(error) { + if (error && error.statusText) + return error.statusText; + else if ( + error && + (typeof (error) === "object") && + (error.toString().indexOf("[object") === 0) + ) + return "Unknown error"; + else + return String(error); +}; + +function showSaveRecordingDialog() { + try { + Microsoft.Xna.Framework.Game.ForcePause(); + } catch (exc) { + } + + var theDialog = document.getElementById("saveRecordingDialog"); + if (!theDialog) { + var dialog = document.createElement("div"); + dialog.id = "saveRecordingDialog"; + + dialog.innerHTML = + ' ' + + '
' + + 'Save to Local Storage | ' + + 'Download | ' + + 'Close'; + + dialog.style.position = "absolute"; + dialog.style.background = "rgba(240, 240, 240, 0.9)"; + dialog.style.color = "black"; + dialog.style.padding = "24px"; + dialog.style.borderRadius = "8px 8px 8px 8px"; + dialog.style.boxShadow = "2px 2px 4px rgba(0, 0, 0, 0.75)"; + + var body = document.getElementsByTagName("body")[0]; + + body.appendChild(dialog); + theDialog = dialog; + + document.getElementById("saveRecordingToLocalStorage").addEventListener("click", saveRecordingToLocalStorage, true); + document.getElementById("cancelSaveRecording").addEventListener("click", hideSaveRecordingDialog, true); + + var inputField = document.getElementById("recordingName") + inputField.addEventListener("input", updateSaveLinkDownloadAttribute, true); + inputField.addEventListener("change", updateSaveLinkDownloadAttribute, true); + inputField.addEventListener("blur", updateSaveLinkDownloadAttribute, true); + } + + var saveLink = document.getElementById("saveRecordingAsFile"); + + try { + // FIXME: Memory leak + var json = JSIL.Replay.SaveAsJSON(); + var bytes = JSIL.StringToByteArray(json); + + saveLink.href = JSIL.GetObjectURLForBytes(bytes, "application/json"); + } catch (exc) { + } + + var x = (document.documentElement.clientWidth - theDialog.clientWidth) / 2; + var y = (document.documentElement.clientHeight - theDialog.clientHeight) / 2; + theDialog.style.left = x + "px"; + theDialog.style.top = y + "px"; + theDialog.style.display = "block"; +}; + +function updateSaveLinkDownloadAttribute(evt) { + var saveLink = document.getElementById("saveRecordingAsFile"); + var recordingName = document.getElementById("recordingName").value.trim() || "untitled"; + + saveLink.download = recordingName + ".replay"; +}; + +function saveRecordingToLocalStorage(evt) { + if (evt) { + evt.preventDefault(); + evt.stopPropagation(); + } + + JSIL.Replay.SaveToLocalStorage(document.getElementById("recordingName").value.trim() || "untitled"); +}; + +function hideSaveRecordingDialog(evt) { + if (evt) { + evt.preventDefault(); + evt.stopPropagation(); + } + + var theDialog = document.getElementById("saveRecordingDialog"); + theDialog.style.display = "none"; + + try { + Microsoft.Xna.Framework.Game.ForceUnpause(); + } catch (exc) { + } +}; + +JSIL.WebWorker.OneShotEventListenerCount = 0; + +JSIL.WebWorker.$MakeWrappedListener = function (listener, notification) { + return function WrappedEventListener() { + notification(); + + return listener.apply(this, arguments); + }; +}; + +JSIL.WebWorker.RegisterOneShotEventListener = function (element, eventName, capture, listener) { + var registered = true; + var unregister, wrappedListener; + + unregister = function () { + if (registered) { + registered = false; + element.removeEventListener(eventName, wrappedListener, capture); + JSIL.WebWorker.OneShotEventListenerCount -= 1; + + wrappedListener = null; + element = null; + } + }; + + wrappedListener = JSIL.WebWorker.$MakeWrappedListener(listener, unregister); + listener = null; + + JSIL.WebWorker.OneShotEventListenerCount += 1; + element.addEventListener(eventName, wrappedListener, capture); + + return { + eventName: eventName, + unregister: unregister + } +}; + diff --git a/Libraries/JSIL.js b/Libraries/JSIL.js index d5de64180..6903af7f8 100644 --- a/Libraries/JSIL.js +++ b/Libraries/JSIL.js @@ -114,17 +114,47 @@ var $jsilloaderstate = { this.loadScript(libraryRoot + "JSIL.Shell.Loaders.js"); }; + // Web Worker + + function Environment_WebWorker(config) { + var self = this; + this.config = config; + + contentManifest["JSIL"].push(["Library", "JSIL.Storage.js"]); + contentManifest["JSIL"].push(["Library", "JSIL.IO.js"]); + contentManifest["JSIL"].push(["Library", "JSIL.XML.js"]); + }; + + Environment_WebWorker.prototype.getUserSetting = function (key) { + return false; + }; + + Environment_WebWorker.prototype.loadEnvironmentScripts = function () { + this.loadScript(libraryRoot + "JSIL.WebWorker.js"); + this.loadScript(libraryRoot + "JSIL.WebWorker.Loaders.js"); + }; + + Environment_WebWorker.prototype.loadScript = function (uri) { + if (console && console.log) + console.log("Loading '" + uri + "'..."); + + importScripts(uri); + }; + var environments = { "browser": Environment_Browser, - "spidermonkey_shell": Environment_SpidermonkeyShell + "spidermonkey_shell": Environment_SpidermonkeyShell, + "webworker" : Environment_WebWorker } if (!config.environment) { - if (typeof (window) !== "undefined") - config.environment = "browser"; - else - throw new Error("jsilConfig.environment not set and no default available"); + if (typeof (window) !== "undefined") + config.environment = "browser"; + else { + console.log(config); + throw new Error("jsilConfig.environment not set and no default available"); + } } var environment; From 1b4f1b492c04660ccf9339c08d0eae598dc4f3d5 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Wed, 30 Apr 2014 13:41:09 +0200 Subject: [PATCH 14/16] Add some missing methods and fields --- Libraries/JSIL.Bootstrap.js | 157 +++++++++++++++++++++++++--- Libraries/JSIL.Core.Reflection.js | 24 +++++ Libraries/JSIL.Core.js | 2 +- Libraries/JSIL.WebWorker.Loaders.js | 2 +- Libraries/JSIL.WebWorker.js | 67 ++---------- 5 files changed, 179 insertions(+), 73 deletions(-) diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index 907bf3767..8642e8234 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1561,13 +1561,16 @@ $jsilcore.$ReadOnlyCollectionExternals = function ($) { JSIL.ImplementExternals("System.Collections.ObjectModel.ReadOnlyCollection`1", $jsilcore.$ReadOnlyCollectionExternals); JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { - var system = JSIL.GetAssembly("System", true); + var system = JSIL.GetAssembly("System", true); + + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"); $.Method({Static:false, Public:true }, ".ctor", (JSIL.MethodSignature.Void), function _ctor () { $jsilcore.InitResizableArray(this, this.T, 16); this._size = 0; + this.tEnumerator = null; } ); @@ -1576,6 +1579,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { function _ctor (capacity) { $jsilcore.InitResizableArray(this, this.T, capacity); this._size = 0; + this.tEnumerator = null; } ); @@ -1593,15 +1597,8 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { } ); - $.Method({Static:false, Public:true }, "GetEnumerator", - (new JSIL.MethodSignature(system.TypeRef("System.Collections.Generic.Stack`1+Enumerator", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), [], [])), - function GetEnumerator () { - return this.$GetEnumerator(); - } - ); - $.Method({Static:false, Public:true }, "Peek", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + (new JSIL.MethodSignature(T, [], [])), function Peek () { if (this._size <= 0) throw new System.InvalidOperationException("Stack is empty"); @@ -1611,7 +1608,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { ); $.Method({Static:false, Public:true }, "Pop", - (new JSIL.MethodSignature(new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1"), [], [])), + (new JSIL.MethodSignature(T, [], [])), function Pop () { var result = this._items.pop(); this._size -= 1; @@ -1621,13 +1618,44 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { ); $.Method({Static:false, Public:true }, "Push", - (new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")], [])), + (new JSIL.MethodSignature(null, [T], [])), function Push (item) { this._items.push(item) this._size += 1; } ); + var getEnumeratorImpl = function GetEnumerator() { + if (this.tEnumerator === null) { + this.tEnumerator = $jsilcore.System.Collections.Generic.Stack$b1_Enumerator.Of(this.T).__Type__; + } + + return JSIL.CreateInstanceOfType(this.tEnumerator, [this]); + }; + + $.Method({ Static: false, Public: true }, "GetEnumerator", + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.Generic.Stack`1+Enumerator", [T]), [], [] + ), + getEnumeratorImpl + ) + + $.Method({ Static: false, Public: false }, null, + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), [], [] + ), + getEnumeratorImpl + ) + .Overrides("System.Collections.Generic.IEnumerable`1", "GetEnumerator"); + + $.Method({ Static: false, Public: false }, null, + new JSIL.MethodSignature( + $jsilcore.TypeRef("System.Collections.IEnumerator", []), [], [] + ), + getEnumeratorImpl + ) + .Overrides("System.Collections.IEnumerable", "GetEnumerator"); + }); JSIL.ImplementExternals("System.Collections.Generic.Queue`1", function ($) { @@ -1717,9 +1745,20 @@ JSIL.MakeClass("System.Object", "System.Collections.Generic.Stack`1", true, ["T" $.Property({Public: true , Static: false}, "Count"); $.ImplementInterfaces( - $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), - "System.Collections.IEnumerable" - ); + $jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]), + $jsilcore.TypeRef("System.Collections.IEnumerable"), + $jsilcore.TypeRef("System.Collections.Generic.ICollection`1", [new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1")]) + ); +}); + +JSIL.MakeStruct($jsilcore.TypeRef("System.ValueType"), "System.Collections.Generic.Stack`1+Enumerator", false, ["T"], function ($) { + var T = new JSIL.GenericParameter("T", "System.Collections.Generic.Stack`1+Enumerator"); + + $.ImplementInterfaces( + /* 0 */ $jsilcore.TypeRef("System.Collections.Generic.IEnumerator`1", [T]), + /* 1 */ $jsilcore.TypeRef("System.IDisposable"), + /* 2 */ $jsilcore.TypeRef("System.Collections.IEnumerator") + ); }); JSIL.MakeStruct( @@ -3031,6 +3070,82 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1+Enumerator", funct .Overrides("System.Collections.IEnumerator", "Reset"); }); +JSIL.ImplementExternals("System.Collections.Generic.Stack`1+Enumerator", function ($interfaceBuilder) { + var $ = $interfaceBuilder; + + $.RawMethod(false, "__CopyMembers__", + function __CopyMembers__(source, target) { + target.stack = source.stack; + target.state = source.state; + } + ); + + $.Method({ Static: false, Public: false }, ".ctor", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.Stack`1", [$.GenericParameter("T")])], []), + function _ctor(stack) { + this.stack = stack; + + var t = stack.T; + + this.state = { + t: t, + currentIndex: stack._size - 1, + current: null + }; + } + ); + + $.Method({ Static: false, Public: true, Virtual: true }, "Dispose", + JSIL.MethodSignature.Void, + function Dispose() { + this.state = null; + this.stack = null; + } + ); + + $.Method({ Static: false, Public: true, Virtual: true }, "get_Current", + new JSIL.MethodSignature($.GenericParameter("T"), [], []), + function get_Current() { + return this.state.current; + } + ); + + $.Method({ Static: false, Public: true, Virtual: true }, "MoveNext", + new JSIL.MethodSignature($.Boolean, [], []), + function MoveNext() { + var state = this.state; + var items = this.stack._items; + + + + if (state.currentIndex >= 0) { + state.current = items[state.currentIndex]; + state.currentIndex--; + return true; + } + + return false; + } + ); + + $.Method({ Static: false, Public: false }, null, + new JSIL.MethodSignature($.Object, [], []), + function System_Collections_IEnumerator_get_Current() { + return this.state.current; + } + ) + .Overrides("System.Collections.IEnumerator", "get_Current"); + + $.Method({ Static: false, Public: false, Virtual: true }, "Reset", + JSIL.MethodSignature.Void, + function System_Collections_IEnumerator_Reset() { + this.state.currentIndex = this.stack._size - 1; + } + ) + .Overrides("System.Collections.IEnumerator", "Reset"); +}); + + $jsilcore.$tArrayEnumerator = null; JSIL.MakeArrayEnumerator = function (array, elementType) { @@ -3769,6 +3884,20 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1", function ($) { } ); + $.Method({ Static: false, Public: true }, "CopyTo", + (new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [T])], [])), + function CopyTo(array) { + // Iterate through each bucket + for (var hashCode in this._dict) { + var bucket = this._dict[hashCode]; + for (var i = 0; i < bucket.length; i++) { + // push the value into the array + array.push(bucket[i].value); + } + } + } + ); + var getEnumeratorImpl = function GetEnumerator () { if (this.tEnumerator === null) { this.tEnumerator = $jsilcore.System.Collections.Generic.HashSet$b1_Enumerator.Of(this.T).__Type__; diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index 683aa048f..2a7c3baf4 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -961,6 +961,9 @@ JSIL.MakeClass("System.Object", "System.Reflection.MemberInfo", true, [], functi }); JSIL.MakeClass("System.Reflection.MemberInfo", "System.Type", true, [], function ($) { + $.Field({ Static: true, Public: true, ReadOnly: true }, "EmptyTypes", $jsilcore.TypeRef("System.Array", [$jsilcore.TypeRef("System.Type")]), function ($pi) { + return JSIL.Array.New($jsilcore.System.Type, 0); + }); $.Property({Public: true , Static: false, Virtual: true }, "Module"); $.Property({Public: true , Static: false, Virtual: true }, "Assembly"); $.Property({Public: true , Static: false, Virtual: true }, "FullName"); @@ -1259,6 +1262,27 @@ JSIL.ImplementExternals("System.Reflection.ConstructorInfo", function ($) { return JSIL.CreateInstanceOfType(this.get_DeclaringType(), impl, parameters); } ); + + var equalsImpl = function (lhs, rhs) { + if (lhs === rhs) + return true; + + return JSIL.ObjectEquals(lhs, rhs); + }; + + $.Method({ Static: true, Public: true }, "op_Equality", + (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Reflection.ConstructorInfo"), $jsilcore.TypeRef("System.Reflection.ConstructorInfo")], [])), + function op_Equality(left, right) { + return equalsImpl(left, right); + } + ); + + $.Method({ Static: true, Public: true }, "op_Inequality", + (new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("System.Reflection.ConstructorInfo"), $jsilcore.TypeRef("System.Reflection.ConstructorInfo")], [])), + function op_Inequality(left, right) { + return !equalsImpl(left, right); + } + ); }); JSIL.ImplementExternals("System.Reflection.EventInfo", function ($) { diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 51623bf6b..434cd4871 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -5209,7 +5209,7 @@ JSIL.MakeType = function (typeArgs, initializer) { } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + return typeOfValue.__AssignableTypes__ != null ? typeOfValue.__AssignableTypes__[this.__TypeId__] === true : false; }; for (var i = 0, l = typeObject.__GenericArguments__.length; i < l; i++) { diff --git a/Libraries/JSIL.WebWorker.Loaders.js b/Libraries/JSIL.WebWorker.Loaders.js index 16388a9b1..8a0142f18 100644 --- a/Libraries/JSIL.WebWorker.Loaders.js +++ b/Libraries/JSIL.WebWorker.Loaders.js @@ -369,7 +369,7 @@ var assetLoaders = { } }); }, - "Resources": function loadResources (filename, data, onError, onDoneLoading) { + "Resources": function loadResources(filename, data, onError, onDoneLoading) { loadTextAsync(jsilConfig.scriptRoot + filename, function (result, error) { if ((result !== null) && (!error)) { var finisher = function () { diff --git a/Libraries/JSIL.WebWorker.js b/Libraries/JSIL.WebWorker.js index 5469602d5..7c3a9997f 100644 --- a/Libraries/JSIL.WebWorker.js +++ b/Libraries/JSIL.WebWorker.js @@ -20,6 +20,10 @@ var $jsilbrowserstate = window.$jsilbrowserstate = { blockGamepadInput: false }; +function updateProgressBar(prefix, suffix, bytesLoaded, bytesTotal) { + postMessage({operation: 'updateProgress', prefix: prefix, suffix: suffix, bytesLoaded: bytesLoaded, bytesTotal: bytesTotal}); +} + JSIL.WebWorker.PageVisibilityService = function () { }; @@ -433,6 +437,8 @@ function finishLoading(st) { initIfNeeded(); } + updateProgressBar("Loading " + item[3], null, state.assetsFinished, state.assetCount); + if (typeof (cb) === "function") { cb(state); } @@ -454,8 +460,11 @@ function finishLoading(st) { } initIfNeeded(); + updateProgressBar("Initializing Application", null, 1, 1); + var allFailures = $jsilloaderstate.loadFailures.concat(state.assetLoadFailures); + postMessage({ operation: 'finishedLoading' }); return; }; @@ -514,6 +523,7 @@ function pollAssetQueue(st) { while ((state.assetsLoading < maxAssetsLoading) && (state.loadIndex < state.assetCount)) { try { + updateProgressBar("Downloading: ", "kb", state.bytesLoaded / 1024, state.assetBytes / 1024); var assetSpec = state.assets[state.loadIndex]; var assetType = assetSpec[0]; @@ -644,7 +654,6 @@ function beginLoading() { } } - postMessage("Loading data ... "); loadAssets(allAssetsToLoad); }; @@ -675,62 +684,6 @@ function stringifyLoadError(error) { return String(error); }; -function showSaveRecordingDialog() { - try { - Microsoft.Xna.Framework.Game.ForcePause(); - } catch (exc) { - } - - var theDialog = document.getElementById("saveRecordingDialog"); - if (!theDialog) { - var dialog = document.createElement("div"); - dialog.id = "saveRecordingDialog"; - - dialog.innerHTML = - ' ' + - '
' + - 'Save to Local Storage | ' + - 'Download | ' + - 'Close'; - - dialog.style.position = "absolute"; - dialog.style.background = "rgba(240, 240, 240, 0.9)"; - dialog.style.color = "black"; - dialog.style.padding = "24px"; - dialog.style.borderRadius = "8px 8px 8px 8px"; - dialog.style.boxShadow = "2px 2px 4px rgba(0, 0, 0, 0.75)"; - - var body = document.getElementsByTagName("body")[0]; - - body.appendChild(dialog); - theDialog = dialog; - - document.getElementById("saveRecordingToLocalStorage").addEventListener("click", saveRecordingToLocalStorage, true); - document.getElementById("cancelSaveRecording").addEventListener("click", hideSaveRecordingDialog, true); - - var inputField = document.getElementById("recordingName") - inputField.addEventListener("input", updateSaveLinkDownloadAttribute, true); - inputField.addEventListener("change", updateSaveLinkDownloadAttribute, true); - inputField.addEventListener("blur", updateSaveLinkDownloadAttribute, true); - } - - var saveLink = document.getElementById("saveRecordingAsFile"); - - try { - // FIXME: Memory leak - var json = JSIL.Replay.SaveAsJSON(); - var bytes = JSIL.StringToByteArray(json); - - saveLink.href = JSIL.GetObjectURLForBytes(bytes, "application/json"); - } catch (exc) { - } - - var x = (document.documentElement.clientWidth - theDialog.clientWidth) / 2; - var y = (document.documentElement.clientHeight - theDialog.clientHeight) / 2; - theDialog.style.left = x + "px"; - theDialog.style.top = y + "px"; - theDialog.style.display = "block"; -}; function updateSaveLinkDownloadAttribute(evt) { var saveLink = document.getElementById("saveRecordingAsFile"); From cb45528fc340847b360764a1b4ade149d114f180 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Wed, 7 May 2014 09:06:05 +0200 Subject: [PATCH 15/16] Add some missing methods --- Libraries/JSIL.Bootstrap.Int64.js | 6 ++++-- Libraries/JSIL.Bootstrap.js | 7 +++++++ Libraries/JSIL.Core.Reflection.js | 23 +++++++++++++++++++++++ Libraries/JSIL.IO.js | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Libraries/JSIL.Bootstrap.Int64.js b/Libraries/JSIL.Bootstrap.Int64.js index 9e00ac4aa..00249e2e5 100644 --- a/Libraries/JSIL.Bootstrap.Int64.js +++ b/Libraries/JSIL.Bootstrap.Int64.js @@ -283,8 +283,10 @@ JSIL.Make64BitInt = function ($, _me) { }); $.RawMethod(true, "FromNumberImpl", function (n, makeResult) { - if (n < 0) - JSIL.RuntimeError("cannot construct UInt64 from negative number"); + if (n < 0) { + //JSIL.RuntimeError("cannot construct UInt64 from negative number"); + n = 0 - n; + } var bits24 = 0xffffff; diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index 8642e8234..489c00b82 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -3559,6 +3559,13 @@ JSIL.ImplementExternals("System.Activator", function ($) { } ); + $.Method({ Static: true, Public: true }, "CreateInstance", + (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Boolean")], [])), + function CreateInstance(type, nonPublic) { + return JSIL.CreateInstanceOfType(type, []); + } + ); + $.Method({Static:true , Public:true }, "CreateInstance", (new JSIL.MethodSignature($.Object, [mscorlib.TypeRef("System.Type"), mscorlib.TypeRef("System.Array", [$.Object])], [])), function CreateInstance (type, args) { diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index 2a7c3baf4..b88feb140 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -84,6 +84,21 @@ JSIL.ImplementExternals( } ); + $.Method({ Public: true, Static: false, Virtual: true }, "GetInterface", + new JSIL.MethodSignature($.Type, [$.String]), + function (fullName) { + var interfaces = JSIL.GetInterfacesImplementedByType(this, true, false); + if (interfaces && interfaces.length) { + for (var i = 0; i < interfaces.length; i++) { + var mangled = interfaces[i].__FullName__; + if (mangled == fullName) + return interfaces[i]; + } + } + return null; + } + ); + $.Method({Static:false, Public:true }, "get_IsGenericType", new JSIL.MethodSignature($.Boolean, []), JSIL.TypeObjectPrototype.get_IsGenericType @@ -136,6 +151,13 @@ JSIL.ImplementExternals( } ); + $.Method({ Static: false, Public: true }, "get_ContainsGenericParameters", + new JSIL.MethodSignature($.Boolean, []), + function () { + return this.__GenericArguments__ && this.__GenericArguments__.length > 0; + } + ); + $.Method({ Static: false, Public: true }, "get_HasElementType", new JSIL.MethodSignature($.Boolean, []), function () { @@ -978,6 +1000,7 @@ JSIL.MakeClass("System.Reflection.MemberInfo", "System.Type", true, [], function $.Property({ Public: true, Static: false }, "IsAbstract"); $.Property({ Public: true, Static: false }, "IsPrimitive"); $.Property({ Public: true, Static: false }, "HasElementType"); + $.Property({ Public: true, Static: false }, "ContainsGenericParameters"); }); JSIL.MakeClass("System.Type", "System.RuntimeType", false, [], function ($) { diff --git a/Libraries/JSIL.IO.js b/Libraries/JSIL.IO.js index 1d561fe24..5a3233ce7 100644 --- a/Libraries/JSIL.IO.js +++ b/Libraries/JSIL.IO.js @@ -718,6 +718,21 @@ JSIL.ImplementExternals("System.IO.FileStream", function ($) { return this._fileName; } ); + + $.Method({ Static: false, Public: true }, "get_CanRead", + (new JSIL.MethodSignature($.Boolean, [], [])), + function get_CanRead() { + return this._canRead; + } + ); + + $.Method({ Static: false, Public: true }, "get_CanWrite", + (new JSIL.MethodSignature($.Boolean, [], [])), + function get_CanWrite() { + return this._canWrite; + } + ); + }); JSIL.ImplementExternals( From 777284298e3341133614ee48d8ef793f2eca39d7 Mon Sep 17 00:00:00 2001 From: Esteban Ardaya Date: Mon, 23 Jun 2014 11:47:15 +0200 Subject: [PATCH 16/16] Final Commit --- Compiler/Compiler.csproj | 37 ++ Libraries/JSIL.Bootstrap.DateTime.js | 13 +- Libraries/JSIL.Bootstrap.js | 79 ++- Libraries/JSIL.Core.Reflection.js | 9 + Libraries/JSIL.Core.js | 2 +- Libraries/JSIL.WebWorker.js | 948 ++++++++++++++------------- Proxies/DateTime.cs | 62 +- 7 files changed, 662 insertions(+), 488 deletions(-) diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj index bf35c6ef9..68cba2990 100644 --- a/Compiler/Compiler.csproj +++ b/Compiler/Compiler.csproj @@ -12,6 +12,21 @@ JSILc v4.0 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -120,6 +135,28 @@ Always
+ + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 4.5 + true + + copy "$(ProjectDir)\..\Upstream\Spidermonkey\*.*" "$(OutDir)" diff --git a/Libraries/JSIL.Bootstrap.DateTime.js b/Libraries/JSIL.Bootstrap.DateTime.js index 8025c9a61..2af7e6dfa 100644 --- a/Libraries/JSIL.Bootstrap.DateTime.js +++ b/Libraries/JSIL.Bootstrap.DateTime.js @@ -84,7 +84,7 @@ JSIL.ImplementExternals( fromTicks ); - /*$.Method({Static:true , Public:true }, "op_Addition", + $.Method({Static:true , Public:true }, "op_Addition", (new JSIL.MethodSignature($.Type, [$.Type, $.Type], [])), function op_Addition (t1, t2) { return fromTicks($jsilcore.System.Int64.op_Addition(t1._ticks, t2._ticks, TempI64A)); @@ -145,7 +145,7 @@ JSIL.ImplementExternals( function op_UnaryNegation (self) { return fromTicks($jsilcore.System.Int64.op_UnaryNegation(self._ticks)); } - );*/ + ); $.RawMethod(false, "$accumulate", function (multiplier, amount) { // FIXME: unnecessary garbage @@ -412,7 +412,14 @@ JSIL.ImplementExternals( ); JSIL.MakeStruct("System.ValueType", "System.TimeSpan", true, [], function ($) { - $.Field({Static:false, Public:false}, "_ticks", $.Int64); + $.Field({ Static: false, Public: false }, "_ticks", $.Int64); + $.Field({ Static: true, Public: true, ReadOnly: true }, "Zero", + $jsilcore.TypeRef("System.TimeSpan"), + function () { + var signature = new JSIL.ConstructorSignature($jsilcore.TypeRef("System.TimeSpan"), [0]); + return signature.Construct(); + } + ); $.Property({Public: true , Static: false}, "Ticks"); diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index 489c00b82..19f341390 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -1583,6 +1583,17 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { } ); + $.Method({ Static: false, Public: true }, "ToArray", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", T), [], []), + function to_Array() { + var array = []; + for (var i = this._size - 1; i >= 0; i--) { + array.push(this._items[i]); + } + return array; + } + ); + $.Method({Static:false, Public:true }, "Clear", (JSIL.MethodSignature.Void), function Clear () { @@ -2231,21 +2242,41 @@ $jsilcore.hashContainerBase = function ($) { }; $.RawMethod(false, "$areEqual", function HashContainer_AreEqual (lhs, rhs) { - if (lhs === rhs) - return true; + var T = this._comparer != null ? this._comparer.T : null; + var eqComparer = this._comparer != null ? + function () { + return (eqComparer = JSIL.Memoize(mscorlib.System.Collections.Generic.IEqualityComparer$b1.Of(T).Equals)) (); + } : null; + + if (eqComparer != null) { + return eqComparer().Call(this._comparer, null, lhs, rhs); + } else { + if (lhs === rhs) + return true; - return JSIL.ObjectEquals(lhs, rhs); + return JSIL.ObjectEquals(lhs, rhs); + } }); - $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket (key) { - var hashCode = JSIL.ObjectHashCode(key); + $.RawMethod(false, "$searchBucket", function HashContainer_SearchBucket(key) { + var T = this._comparer != null ? this._comparer.T : null; + var hasher = this._comparer != null ? + function () { + return (hasher = JSIL.Memoize(mscorlib.System.Collections.Generic.IEqualityComparer$b1.Of(T).GetHashCode)) (); + } : null; + + var hashCode = hasher != null ? hasher().Call(this._comparer, null, key) : JSIL.ObjectHashCode(key); var bucket = this._dict[hashCode]; - if (!bucket) - return null; - for (var i = 0, l = bucket.length; i < l; i++) { - var bucketEntry = bucket[i]; + if (!bucket) { + return null; + } + for (var i = 0, l = bucket.length; i < l; i++) { + var bucketEntry = bucket[i]; + // Try to use comparer first + if (this._comparer != null) + return bucketEntry; if (this.$areEqual(bucketEntry.key, key)) return bucketEntry; } @@ -2254,7 +2285,13 @@ $jsilcore.hashContainerBase = function ($) { }); $.RawMethod(false, "$removeByKey", function HashContainer_Remove (key) { - var hashCode = JSIL.ObjectHashCode(key); + var T = this._comparer != null ? this._comparer.T : null; + var hasher = this._comparer != null ? + function () { + return (hasher = JSIL.Memoize(mscorlib.System.Collections.Generic.IEqualityComparer$b1.Of(T).GetHashCode)) (); + } : null; + + var hashCode = hasher != null ? hasher().Call(this._comparer, null, key) : JSIL.ObjectHashCode(key); var bucket = this._dict[hashCode]; if (!bucket) return false; @@ -2273,8 +2310,15 @@ $jsilcore.hashContainerBase = function ($) { }); $.RawMethod(false, "$addToBucket", function HashContainer_Add (key, value) { - var hashCode = JSIL.ObjectHashCode(key); + var T = this._comparer != null ? this._comparer.T : null; + var hasher = this._comparer != null ? + function () { + return (hasher = JSIL.Memoize(mscorlib.System.Collections.Generic.IEqualityComparer$b1.Of(T).GetHashCode)) (); + } : null; + + var hashCode = hasher != null ? hasher().Call(this._comparer, null, key) : JSIL.ObjectHashCode(key); var bucket = this._dict[hashCode]; + if (!bucket) this._dict[hashCode] = bucket = []; @@ -2558,6 +2602,19 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+KeyCollection", } ); + $.Method({ Static: false, Public: true }, "CopyTo", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Array", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2+KeyCollection")]), $jsilcore.TypeRef("System.Int32")], []), + function Dictionary_CopyTo(array, index) { + // TODO: Implement checks + var enumerator = JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); + + while (enumerator.MoveNext()) { + array[index] = enumerator.get_Current(); + index++; + } + } + ); + var getEnumeratorImpl = function GetEnumerator () { return JSIL.CreateInstanceOfType(this.dictionary.tKeyEnumerator, [this.dictionary]); }; diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index b88feb140..f1ff8ca5d 100644 --- a/Libraries/JSIL.Core.Reflection.js +++ b/Libraries/JSIL.Core.Reflection.js @@ -47,6 +47,15 @@ JSIL.ImplementExternals( } ); + $.Method({ Public: true, Static: false, Virtual: true }, "Equals", + new JSIL.MethodSignature($.Boolean, [$.Type]), + function (type) { + if (this === type) + return true; + + return String(this) == String(type); + } + ); $.Method({Public: true , Static: true }, "op_Inequality", new JSIL.MethodSignature($.Boolean, [$.Type, $.Type]), function (lhs, rhs) { diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 434cd4871..29ee1da58 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -5318,7 +5318,7 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer typeObject.__Members__ = []; typeObject.__RenamedMethods__ = {}; typeObject.__ShortName__ = localName; - typeObject.__Context__ = $private; + typeObject.__Context__ = assembly; typeObject.__FullName__ = fullName; typeObject.__TypeInitialized__ = false; diff --git a/Libraries/JSIL.WebWorker.js b/Libraries/JSIL.WebWorker.js index 7c3a9997f..7bfbf8a27 100644 --- a/Libraries/JSIL.WebWorker.js +++ b/Libraries/JSIL.WebWorker.js @@ -5,23 +5,23 @@ var currentLogLine = null; var webglEnabled = false; var $jsilbrowserstate = window.$jsilbrowserstate = { - allFileNames: [], - allAssetNames: [], - readOnlyStorage: null, - heldKeys: [], - heldButtons: [], - mousePosition: [0, 0], - isLoading: false, - isLoaded: false, - isMainRunning: false, - hasMainRun: false, - mainRunAtTime: 0, - blockKeyboardInput: false, - blockGamepadInput: false + allFileNames: [], + allAssetNames: [], + readOnlyStorage: null, + heldKeys: [], + heldButtons: [], + mousePosition: [0, 0], + isLoading: false, + isLoaded: false, + isMainRunning: false, + hasMainRun: false, + mainRunAtTime: 0, + blockKeyboardInput: false, + blockGamepadInput: false }; function updateProgressBar(prefix, suffix, bytesLoaded, bytesTotal) { - postMessage({operation: 'updateProgress', prefix: prefix, suffix: suffix, bytesLoaded: bytesLoaded, bytesTotal: bytesTotal}); + postMessage({operation: 'progress', prefix: prefix, suffix: suffix, bytesLoaded: bytesLoaded, bytesTotal: bytesTotal}); } JSIL.WebWorker.PageVisibilityService = function () { @@ -30,292 +30,291 @@ JSIL.WebWorker.PageVisibilityService = function () { JSIL.WebWorker.PageVisibilityService.prototype.keys = ["hidden", "mozHidden", "msHidden", "webkitHidden"]; JSIL.WebWorker.PageVisibilityService.prototype.get = function () { - for (var i = 0, l = this.keys.length; i < l; i++) { - var key = this.keys[i]; - var value = document[key]; + for (var i = 0, l = this.keys.length; i < l; i++) { + var key = this.keys[i]; + var value = document[key]; - if (typeof (value) !== "undefined") - return !value; - } + if (typeof (value) !== "undefined") + return !value; + } - return true; + return true; }; - JSIL.WebWorker.RunLaterService = function () { - this.queue = []; - this.pending = false; - this.boundStep = this.step.bind(this); + this.queue = []; + this.pending = false; + this.boundStep = this.step.bind(this); }; JSIL.WebWorker.RunLaterService.prototype.enqueue = function (callback) { - this.queue.push(callback); + this.queue.push(callback); - if (!this.pending) { - this.pending = true; - window.setTimeout(this.boundStep, 0); - } + if (!this.pending) { + this.pending = true; + window.setTimeout(this.boundStep, 0); + } }; JSIL.WebWorker.RunLaterService.prototype.step = function () { - var count = this.queue.length; - this.pending = false; + var count = this.queue.length; + this.pending = false; - for (var i = 0; i < count; i++) { - var item = this.queue[i]; - item(); - } + for (var i = 0; i < count; i++) { + var item = this.queue[i]; + item(); + } - this.queue.splice(0, count); + this.queue.splice(0, count); }; JSIL.WebWorker.LogService = function () { - this.currentLine = null; + this.currentLine = null; }; JSIL.WebWorker.LogService.prototype.write = function (text) { - postMessage({ operation: 'log', text: text }); + postMessage({ operation: 'log', message: text }); }; JSIL.WebWorker.WarningService = function (stream) { - this.stream = stream; + this.stream = stream; }; JSIL.WebWorker.WarningService.prototype.write = function (text) { - // Quirky behavior, but we suppress warnings from the log if the console is available. - if (console && console.warn) { - if (typeof (text) === "string") { - console.warn(text.trim()); - } - else - console.warn(text); - } else if (this.stream) { - this.stream.write(text); + // Quirky behavior, but we suppress warnings from the log if the console is available. + if (console && console.warn) { + if (typeof (text) === "string") { + console.warn(text.trim()); } + else + console.warn(text); + } else if (this.stream) { + this.stream.write(text); + } }; JSIL.WebWorker.LocalStorageService = function (storage) { - this.storage = storage; + this.storage = storage; }; JSIL.WebWorker.LocalStorageService.prototype.getItem = function (key) { - return this.storage.getItem(key); + return this.storage.getItem(key); }; JSIL.WebWorker.LocalStorageService.prototype.setItem = function (key, text) { - return this.storage.setItem(key, text); + return this.storage.setItem(key, text); }; JSIL.WebWorker.LocalStorageService.prototype.removeItem = function (key) { - return this.storage.removeItem(key); + return this.storage.removeItem(key); }; JSIL.WebWorker.LocalStorageService.prototype.getKeys = function () { - var result = new Array(this.storage.length); + var result = new Array(this.storage.length); - for (var i = 0, l = result.length; i < l; i++) - result[i] = this.storage.key(i); + for (var i = 0, l = result.length; i < l; i++) + result[i] = this.storage.key(i); - return result; + return result; }; JSIL.WebWorker.WindowService = function (window) { - this.window = window; + this.window = window; }; JSIL.WebWorker.WindowService.prototype.alert = function () { - return this.window.alert.apply(this.window, arguments); + return this.window.alert.apply(this.window, arguments); }; JSIL.WebWorker.WindowService.prototype.prompt = function () { - return this.window.prompt.apply(this.window, arguments); + return this.window.prompt.apply(this.window, arguments); }; JSIL.WebWorker.WindowService.prototype.getTitle = function () { - return this.window.title; + return this.window.title; }; JSIL.WebWorker.WindowService.prototype.setTitle = function (value) { - return this.window.document.title = this.window.title = value; + return this.window.document.title = this.window.title = value; }; JSIL.WebWorker.WindowService.prototype.getLocationHref = function () { - return this.window.location.href; + return this.window.location.href; }; JSIL.WebWorker.WindowService.prototype.getLocationHash = function () { - return this.window.location.hash; + return this.window.location.hash; }; JSIL.WebWorker.WindowService.prototype.getLocationSearch = function () { - return this.window.location.search; + return this.window.location.search; }; JSIL.WebWorker.WindowService.prototype.getNavigatorUserAgent = function () { - return this.window.navigator.userAgent; + return this.window.navigator.userAgent; }; JSIL.WebWorker.WindowService.prototype.getNavigatorLanguage = function () { - return this.window.navigator.language || - this.window.navigator.userLanguage || - this.window.navigator.systemLanguage || - null; + return this.window.navigator.language || + this.window.navigator.userLanguage || + this.window.navigator.systemLanguage || + null; }; JSIL.WebWorker.WindowService.prototype.getPerformanceUsedJSHeapSize = function () { - if ( - (typeof (this.window.performance) !== "undefined") && - (typeof (this.window.performance.memory) !== "undefined") + if ( + (typeof (this.window.performance) !== "undefined") && + (typeof (this.window.performance.memory) !== "undefined") ) { - return this.window.performance.memory.usedJSHeapSize; - } else { - return 0; - } + return this.window.performance.memory.usedJSHeapSize; + } else { + return 0; + } }; JSIL.WebWorker.HistoryService = function (history) { - this.history = history; - this.canPushState = typeof (this.history.pushState) === "function"; + this.history = history; + this.canPushState = typeof (this.history.pushState) === "function"; }; JSIL.WebWorker.HistoryService.prototype.pushState = function (a, b, c) { - return this.history.pushState(a, b, c); + return this.history.pushState(a, b, c); }; JSIL.WebWorker.HistoryService.prototype.replaceState = function (a, b, c) { - return this.history.replaceState(a, b, c); + return this.history.replaceState(a, b, c); }; JSIL.WebWorker.TraceService = function (console) { - this.console = console; + this.console = console; }; JSIL.WebWorker.TraceService.prototype.write = function (text, category) { - if (this.console) { - if (arguments.length === 2) - this.console.log(category + ": " + text); - else if (arguments.length === 1) - this.console.log(text); - } + if (this.console) { + if (arguments.length === 2) + this.console.log(category + ": " + text); + else if (arguments.length === 1) + this.console.log(text); + } }; JSIL.WebWorker.TraceService.prototype.information = function (text) { - if (this.console) - this.console.log(text); + if (this.console) + this.console.log(text); }; JSIL.WebWorker.TraceService.prototype.warning = function (text) { - if (this.console) - this.console.warn(text); + if (this.console) + this.console.warn(text); }; JSIL.WebWorker.TraceService.prototype.error = function (text) { - if (this.console) - this.console.error(text); + if (this.console) + this.console.error(text); }; (function () { - var logSvc = new JSIL.WebWorker.LogService(); + var logSvc = new JSIL.WebWorker.LogService(); - JSIL.Host.registerServices({ - pageVisibility: new JSIL.WebWorker.PageVisibilityService(), - runLater: new JSIL.WebWorker.RunLaterService(), - stdout: logSvc, - stderr: new JSIL.WebWorker.WarningService(logSvc) - }); + JSIL.Host.registerServices({ + pageVisibility: new JSIL.WebWorker.PageVisibilityService(), + runLater: new JSIL.WebWorker.RunLaterService(), + stdout: logSvc, + stderr: new JSIL.WebWorker.WarningService(logSvc) + }); - if (typeof (localStorage) !== "undefined") - JSIL.Host.registerService("localStorage", new JSIL.WebWorker.LocalStorageService(localStorage)); + if (typeof (localStorage) !== "undefined") + JSIL.Host.registerService("localStorage", new JSIL.WebWorker.LocalStorageService(localStorage)); })(); JSIL.Host.translateFilename = function (filename) { - if (filename === null) - return null; + if (filename === null) + return null; - var slashRe = /\\/g; + var slashRe = /\\/g; - var root = JSIL.Host.getRootDirectory().toLowerCase().replace(slashRe, "/"); - var _fileRoot = jsilConfig.fileRoot.toLowerCase().replace(slashRe, "/"); - var _filename = filename.replace(slashRe, "/").toLowerCase(); + var root = JSIL.Host.getRootDirectory().toLowerCase().replace(slashRe, "/"); + var _fileRoot = jsilConfig.fileRoot.toLowerCase().replace(slashRe, "/"); + var _filename = filename.replace(slashRe, "/").toLowerCase(); - while (_filename[0] === "/") - _filename = _filename.substr(1); + while (_filename[0] === "/") + _filename = _filename.substr(1); - if (_filename.indexOf(root) === 0) - _filename = _filename.substr(root.length); + if (_filename.indexOf(root) === 0) + _filename = _filename.substr(root.length); - while (_filename[0] === "/") - _filename = _filename.substr(1); + while (_filename[0] === "/") + _filename = _filename.substr(1); - if (_filename.indexOf(_fileRoot) === 0) - _filename = _filename.substr(_fileRoot.length); + if (_filename.indexOf(_fileRoot) === 0) + _filename = _filename.substr(_fileRoot.length); - while (_filename[0] === "/") - _filename = _filename.substr(1); + while (_filename[0] === "/") + _filename = _filename.substr(1); - return _filename; + return _filename; } JSIL.Host.getImage = function (filename) { - var key = getAssetName(filename, false); - if (!allAssets.hasOwnProperty(key)) - throw new System.IO.FileNotFoundException("The image '" + key + "' is not in the asset manifest.", filename); + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + throw new System.IO.FileNotFoundException("The image '" + key + "' is not in the asset manifest.", filename); - return allAssets[key].image; + return allAssets[key].image; }; JSIL.Host.doesAssetExist = function (filename, stripRoot) { - if (filename === null) - return false; + if (filename === null) + return false; - if (stripRoot === true) { - var backslashRe = /\\/g; + if (stripRoot === true) { + var backslashRe = /\\/g; - filename = filename.replace(backslashRe, "/").toLowerCase(); - var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); + filename = filename.replace(backslashRe, "/").toLowerCase(); + var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); - filename = filename.replace(croot, "").toLowerCase(); - } + filename = filename.replace(croot, "").toLowerCase(); + } - var key = getAssetName(filename, false); - if (!allAssets.hasOwnProperty(key)) - return false; + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + return false; - return true; + return true; }; JSIL.Host.getAsset = function (filename, stripRoot) { - if (filename === null) - throw new System.Exception("Filename was null"); + if (filename === null) + throw new System.Exception("Filename was null"); - if (stripRoot === true) { - var backslashRe = /\\/g; + if (stripRoot === true) { + var backslashRe = /\\/g; - filename = filename.replace(backslashRe, "/").toLowerCase(); - var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); + filename = filename.replace(backslashRe, "/").toLowerCase(); + var croot = jsilConfig.contentRoot.replace(backslashRe, "/").toLowerCase(); - filename = filename.replace(croot, "").toLowerCase(); - } + filename = filename.replace(croot, "").toLowerCase(); + } - var key = getAssetName(filename, false); - if (!allAssets.hasOwnProperty(key)) - throw new System.IO.FileNotFoundException("The asset '" + key + "' is not in the asset manifest.", filename); + var key = getAssetName(filename, false); + if (!allAssets.hasOwnProperty(key)) + throw new System.IO.FileNotFoundException("The asset '" + key + "' is not in the asset manifest.", filename); - return allAssets[key]; + return allAssets[key]; }; JSIL.Host.getRootDirectory = function () { - var url = window.location.href; - var lastSlash = url.lastIndexOf("/"); - if (lastSlash === -1) - return url; - else - return url.substr(0, lastSlash); + var url = window.location.href; + var lastSlash = url.lastIndexOf("/"); + if (lastSlash === -1) + return url; + else + return url.substr(0, lastSlash); }; JSIL.Host.getStorageRoot = function () { - return $jsilbrowserstate.storageRoot; + return $jsilbrowserstate.storageRoot; }; @@ -326,24 +325,24 @@ var allAssets = {}; var allManifestResources = {}; function getAssetName(filename, preserveCase) { - var backslashRe = /\\/g; - filename = filename.replace(backslashRe, "/"); + var backslashRe = /\\/g; + filename = filename.replace(backslashRe, "/"); - var doubleSlashRe = /\/\//g; - while (filename.indexOf("//") >= 0) - filename = filename.replace(doubleSlashRe, "/"); + var doubleSlashRe = /\/\//g; + while (filename.indexOf("//") >= 0) + filename = filename.replace(doubleSlashRe, "/"); - var lastIndex = filename.lastIndexOf("."); - var result; - if (lastIndex === -1) - result = filename; - else - result = filename.substr(0, lastIndex); + var lastIndex = filename.lastIndexOf("."); + var result; + if (lastIndex === -1) + result = filename; + else + result = filename.substr(0, lastIndex); - if (preserveCase === true) - return result; - else - return result.toLowerCase(); + if (preserveCase === true) + return result; + else + return result.toLowerCase(); }; var loadedFontCount = 0; @@ -353,403 +352,410 @@ var soundLoadTimeout = 30000; var fontLoadTimeout = 10000; var finishStepDuration = 25; -function finishLoading(st) { - var state = st; +function finishLoading() { + var state = this; - var started = Date.now(); - var endBy = started + finishStepDuration; + var started = Date.now(); + var endBy = started + finishStepDuration; - var initFileStorage = function (volume) { - for (var i = 0, l = $jsilbrowserstate.allFileNames.length; i < l; i++) { - var filename = $jsilbrowserstate.allFileNames[i]; - var file = volume.createFile(filename, false, true); - file.writeAllBytes(allFiles[filename.toLowerCase()]); - } - }; + var initFileStorage = function (volume) { + for (var i = 0, l = $jsilbrowserstate.allFileNames.length; i < l; i++) { + var filename = $jsilbrowserstate.allFileNames[i]; + var file = volume.createFile(filename, false, true); + file.writeAllBytes(allFiles[filename.toLowerCase()]); + } + }; - var initIfNeeded = function () { - if (!state.jsilInitialized) { - state.jsilInitialized = true; - JSIL.Initialize(); - } + var initIfNeeded = function () { + if (!state.jsilInitialized) { + state.jsilInitialized = true; + JSIL.Initialize(); + } - if (state.initFailed) { - return; - } + if (state.initFailed) { + return; + } - try { - if (typeof ($jsilreadonlystorage) !== "undefined") { - var prefixedFileRoot; + try { + if (typeof ($jsilreadonlystorage) !== "undefined") { + var prefixedFileRoot; - if (jsilConfig.fileVirtualRoot[0] !== "/") - prefixedFileRoot = "/" + jsilConfig.fileVirtualRoot; - else - prefixedFileRoot = jsilConfig.fileVirtualRoot; + if (jsilConfig.fileVirtualRoot[0] !== "/") + prefixedFileRoot = "/" + jsilConfig.fileVirtualRoot; + else + prefixedFileRoot = jsilConfig.fileVirtualRoot; - $jsilbrowserstate.readOnlyStorage = new ReadOnlyStorageVolume("files", prefixedFileRoot, initFileStorage); - } + $jsilbrowserstate.readOnlyStorage = new ReadOnlyStorageVolume("files", prefixedFileRoot, initFileStorage); + } - JSIL.SetLazyValueProperty($jsilbrowserstate, "storageRoot", function InitStorageRoot() { - var root; - if (JSIL.GetStorageVolumes) { - var volumes = JSIL.GetStorageVolumes(); + JSIL.SetLazyValueProperty($jsilbrowserstate, "storageRoot", function InitStorageRoot() { + var root; + if (JSIL.GetStorageVolumes) { + var volumes = JSIL.GetStorageVolumes(); - if (volumes.length) { - root = volumes[0]; - } - } + if (volumes.length) { + root = volumes[0]; + } + } - if (!root && typeof (VirtualVolume) === "function") { - root = new VirtualVolume("root", "/"); - } + if (!root && typeof (VirtualVolume) === "function") { + root = new VirtualVolume("root", "/"); + } - if (root) { - if ($jsilbrowserstate.readOnlyStorage) { - var trimmedRoot = jsilConfig.fileVirtualRoot.trim(); + if (root) { + if ($jsilbrowserstate.readOnlyStorage) { + var trimmedRoot = jsilConfig.fileVirtualRoot.trim(); - if (trimmedRoot !== "/" && trimmedRoot) - root.createJunction(jsilConfig.fileVirtualRoot, $jsilbrowserstate.readOnlyStorage.rootDirectory, false); - else - root = $jsilbrowserstate.readOnlyStorage; - } + if (trimmedRoot !== "/" && trimmedRoot) + root.createJunction(jsilConfig.fileVirtualRoot, $jsilbrowserstate.readOnlyStorage.rootDirectory, false); + else + root = $jsilbrowserstate.readOnlyStorage; + } + + return root; + } - return root; - } + return null; + }); - return null; - }); + state.initFailed = false; + } catch (exc) { + state.initFailed = true; - state.initFailed = false; - } catch (exc) { - state.initFailed = true; + throw exc; + } + }; - throw exc; - } - }; + while (state.finishIndex < state.finishQueue.length) { + try { + var item = state.finishQueue[state.finishIndex]; + var cb = item[2]; + + // Ensure that we initialize the JSIL runtime before constructing asset objects. + if ((item[0] != "Script") && (item[0] != "Library")) { + initIfNeeded(); + } + + updateProgressBar("Loading " + item[3], null, state.assetsFinished, state.assetCount); + + if (typeof (cb) === "function") { + cb(state); + } + } catch (exc) { + state.assetLoadFailures.push( + [item[3], exc] + ); - while (state.finishIndex < state.finishQueue.length) { + if (jsilConfig.onLoadFailure) { try { - var item = state.finishQueue[state.finishIndex]; - var cb = item[2]; - - // Ensure that we initialize the JSIL runtime before constructing asset objects. - if ((item[0] != "Script") && (item[0] != "Library")) { - initIfNeeded(); - } - - updateProgressBar("Loading " + item[3], null, state.assetsFinished, state.assetCount); - - if (typeof (cb) === "function") { - cb(state); - } - } catch (exc) { - state.assetLoadFailures.push( - [item[3], exc] - ); - - if (jsilConfig.onLoadFailure) { - try { - jsilConfig.onLoadFailure(item[3], exc); - } catch (exc2) { - } - } - } finally { - state.finishIndex += 1; - state.assetsFinished += 1; + jsilConfig.onLoadFailure(item[3], exc); + } catch (exc2) { } + } + } finally { + state.finishIndex += 1; + state.assetsFinished += 1; } - initIfNeeded(); + } + initIfNeeded(); - updateProgressBar("Initializing Application", null, 1, 1); + updateProgressBar("Initializing Application ...", null, 1, -1); - var allFailures = $jsilloaderstate.loadFailures.concat(state.assetLoadFailures); + var allFailures = $jsilloaderstate.loadFailures.concat(state.assetLoadFailures); - postMessage({ operation: 'finishedLoading' }); - return; + clearInterval(state.interval); + state.interval = null; + + finishedLoading(); + + return; }; -function pollAssetQueue(st) { - var state = st; +function pollAssetQueue() { + var state = this; - var w = 0; + var w = 0; + updateProgressBar("Initializing ...", null, -1, -1); - var makeStepCallback = function (state, type, sizeBytes, i, name) { - return function (finish) { - var realName = name; + var makeStepCallback = function (state, type, sizeBytes, i, name) { + return function (finish) { + var realName = name; - var lastDot = name.lastIndexOf("."); - if (lastDot >= 0) - name = name.substr(0, lastDot); + var lastDot = name.lastIndexOf("."); + if (lastDot >= 0) + name = name.substr(0, lastDot); - var firstComma = name.indexOf(","); - if (firstComma >= 0) - name = name.substr(0, firstComma); + var firstComma = name.indexOf(","); + if (firstComma >= 0) + name = name.substr(0, firstComma); - if (typeof (finish) === "function") - state.finishQueue.push([type, i, finish, name]); + if (typeof (finish) === "function") + state.finishQueue.push([type, i, finish, name]); - delete state.assetsLoadingNames[realName]; - state.assetsLoading -= 1; - state.assetsLoaded += 1; + delete state.assetsLoadingNames[realName]; + state.assetsLoading -= 1; + state.assetsLoaded += 1; - state.bytesLoaded += sizeBytes; - }; + state.bytesLoaded += sizeBytes; }; + }; - var makeErrorCallback = function (assetPath, assetSpec) { - return function (e) { - delete state.assetsLoadingNames[getAssetName(assetPath)]; - state.assetsLoading -= 1; - state.assetsLoaded += 1; + var makeErrorCallback = function (assetPath, assetSpec) { + return function (e) { + delete state.assetsLoadingNames[getAssetName(assetPath)]; + state.assetsLoading -= 1; + state.assetsLoaded += 1; - allAssets[getAssetName(assetPath)] = null; + allAssets[getAssetName(assetPath)] = null; - var errorText = stringifyLoadError(e); + var errorText = stringifyLoadError(e); - state.assetLoadFailures.push( - [assetPath, errorText] - ); + state.assetLoadFailures.push( + [assetPath, errorText] + ); - if (jsilConfig.onLoadFailure) { - try { - jsilConfig.onLoadFailure(item[3], errorText); - } catch (exc2) { - } - } + if (jsilConfig.onLoadFailure) { + try { + jsilConfig.onLoadFailure(item[3], errorText); + } catch (exc2) { + } + } - JSIL.Host.logWriteLine("The asset '" + assetPath + "' could not be loaded: " + errorText); - }; + JSIL.Host.logWriteLine("The asset '" + assetPath + "' could not be loaded: " + errorText); }; + }; - while ((state.assetsLoading < maxAssetsLoading) && (state.loadIndex < state.assetCount)) { - try { - updateProgressBar("Downloading: ", "kb", state.bytesLoaded / 1024, state.assetBytes / 1024); - var assetSpec = state.assets[state.loadIndex]; - - var assetType = assetSpec[0]; - var assetPath = assetSpec[1]; - var assetData = assetSpec[2] || null; - var assetLoader = assetLoaders[assetType]; - - var sizeBytes = 1; - if (assetData !== null) - sizeBytes = assetData.sizeBytes || 1; - - var stepCallback = makeStepCallback(state, assetType, sizeBytes, state.loadIndex, assetPath); - var errorCallback = makeErrorCallback(assetPath, assetSpec); - - if (typeof (assetLoader) !== "function") { - errorCallback("No asset loader registered for type '" + assetType + "'."); - } else { - state.assetsLoading += 1; - state.assetsLoadingNames[assetPath] = assetLoader; - assetLoader(assetPath, assetData, errorCallback, stepCallback, state); - } - } finally { - state.loadIndex += 1; - } + while ((state.assetsLoading < maxAssetsLoading) && (state.loadIndex < state.assetCount)) { + try { + var assetSpec = state.assets[state.loadIndex]; + + var assetType = assetSpec[0]; + var assetPath = assetSpec[1]; + var assetData = assetSpec[2] || null; + var assetLoader = assetLoaders[assetType]; + + var sizeBytes = 1; + if (assetData !== null) + sizeBytes = assetData.sizeBytes || 1; + + var stepCallback = makeStepCallback(state, assetType, sizeBytes, state.loadIndex, assetPath); + var errorCallback = makeErrorCallback(assetPath, assetSpec); + + if (typeof (assetLoader) !== "function") { + errorCallback("No asset loader registered for type '" + assetType + "'."); + } else { + state.assetsLoading += 1; + state.assetsLoadingNames[assetPath] = assetLoader; + assetLoader(assetPath, assetData, errorCallback, stepCallback, state); + } + } finally { + state.loadIndex += 1; } + } + + if (state.assetsLoaded >= state.assetCount) { + clearInterval(state.interval); + state.interval = null; + + state.assetsLoadingNames = {}; + + state.finishQueue.sort(function (lhs, rhs) { + var lhsTypeIndex = 2, rhsTypeIndex = 2; + var lhsIndex = lhs[1]; + var rhsIndex = rhs[1]; + + switch (lhs[0]) { + case "Library": + lhsTypeIndex = 0; + break; + case "Script": + lhsTypeIndex = 1; + break; + } + + switch (rhs[0]) { + case "Library": + rhsTypeIndex = 0; + break; + case "Script": + rhsTypeIndex = 1; + break; + } + + var result = JSIL.CompareValues(lhsTypeIndex, rhsTypeIndex); + if (result === 0) + result = JSIL.CompareValues(lhsIndex, rhsIndex); + + return result; + }); - if (state.assetsLoaded >= state.assetCount) { - state.assetsLoadingNames = {}; - - state.finishQueue.sort(function (lhs, rhs) { - var lhsTypeIndex = 2, rhsTypeIndex = 2; - var lhsIndex = lhs[1]; - var rhsIndex = rhs[1]; - - switch (lhs[0]) { - case "Library": - lhsTypeIndex = 0; - break; - case "Script": - lhsTypeIndex = 1; - break; - } - - switch (rhs[0]) { - case "Library": - rhsTypeIndex = 0; - break; - case "Script": - rhsTypeIndex = 1; - break; - } - - var result = JSIL.CompareValues(lhsTypeIndex, rhsTypeIndex); - if (result === 0) - result = JSIL.CompareValues(lhsIndex, rhsIndex); - - return result; - }); - - finishLoading(state); - - return; - } + state.interval = setInterval(finishLoading.bind(state), 1); + + return; + } }; function loadAssets(assets) { - var state = { - assetBytes: 0, - assetCount: assets.length, - bytesLoaded: 0, - assetsLoaded: 0, - assetsFinished: 0, - assetsLoading: 0, - assets: assets, - interval: null, - finishQueue: [], - loadIndex: 0, - finishIndex: 0, - pendingScriptLoads: 0, - jsilInitialized: false, - assetsLoadingNames: {}, - assetLoadFailures: [], - failedFinishes: 0 - }; - - for (var i = 0, l = assets.length; i < l; i++) { - var properties = assets[i][2]; - - if (typeof (properties) !== "object") { - state.assetBytes += 1; - continue; - } - - var sizeBytes = properties.sizeBytes || 1; - state.assetBytes += sizeBytes; + var state = { + assetBytes: 0, + assetCount: assets.length, + bytesLoaded: 0, + assetsLoaded: 0, + assetsFinished: 0, + assetsLoading: 0, + assets: assets, + interval: null, + finishQueue: [], + loadIndex: 0, + finishIndex: 0, + pendingScriptLoads: 0, + jsilInitialized: false, + assetsLoadingNames: {}, + assetLoadFailures: [], + failedFinishes: 0 + }; + + for (var i = 0, l = assets.length; i < l; i++) { + var properties = assets[i][2]; + + if (typeof (properties) !== "object") { + state.assetBytes += 1; + continue; } - pollAssetQueue(state); + var sizeBytes = properties.sizeBytes || 1; + state.assetBytes += sizeBytes; + } + + state.interval = setInterval(pollAssetQueue.bind(state), 1); }; function beginLoading() { - initAssetLoaders(); + initAssetLoaders(); - var seenFilenames = {}; + var seenFilenames = {}; - var pushAsset = function (assetSpec) { - var filename = assetSpec[1]; - if (seenFilenames[filename]) - return; + var pushAsset = function (assetSpec) { + var filename = assetSpec[1]; + if (seenFilenames[filename]) + return; - seenFilenames[filename] = true; - allAssetsToLoad.push(assetSpec); - } + seenFilenames[filename] = true; + allAssetsToLoad.push(assetSpec); + }; - var allAssetsToLoad = []; - if (typeof (window.assetsToLoad) !== "undefined") { - for (var i = 0, l = assetsToLoad.length; i < l; i++) - pushAsset(assetsToLoad[i]); - } + var allAssetsToLoad = []; + if (typeof (window.assetsToLoad) !== "undefined") { + for (var i = 0, l = assetsToLoad.length; i < l; i++) + pushAsset(assetsToLoad[i]); + } - if (typeof (contentManifest) === "object") { - for (var k in contentManifest) { - var subManifest = contentManifest[k]; + if (typeof (contentManifest) === "object") { + for (var k in contentManifest) { + var subManifest = contentManifest[k]; - for (var i = 0, l = subManifest.length; i < l; i++) - pushAsset(subManifest[i]); + for (var i = 0, l = subManifest.length; i < l; i++) + pushAsset(subManifest[i]); - } } + } - loadAssets(allAssetsToLoad); + loadAssets(allAssetsToLoad); }; function registerErrorHandler() { - var oldErrorHandler = window.onerror; + var oldErrorHandler = window.onerror; - window.onerror = function JSIL_OnUnhandledException(errorMsg, url, lineNumber) { - JSIL.Host.logWriteLine("Unhandled exception at " + url + " line " + lineNumber + ":"); - JSIL.Host.logWriteLine(errorMsg); + window.onerror = function JSIL_OnUnhandledException(errorMsg, url, lineNumber) { + JSIL.Host.logWriteLine("Unhandled exception at " + url + " line " + lineNumber + ":"); + JSIL.Host.logWriteLine(errorMsg); - if (typeof (oldErrorHandler) === "function") - return oldErrorHandler(errorMsg, url, lineNumber); - else - return false; - }; + if (typeof (oldErrorHandler) === "function") + return oldErrorHandler(errorMsg, url, lineNumber); + else + return false; + }; }; function stringifyLoadError(error) { - if (error && error.statusText) - return error.statusText; - else if ( - error && - (typeof (error) === "object") && - (error.toString().indexOf("[object") === 0) + if (error && error.statusText) + return error.statusText; + else if ( + error && + (typeof (error) === "object") && + (error.toString().indexOf("[object") === 0) ) - return "Unknown error"; - else - return String(error); + return "Unknown error"; + else + return String(error); }; function updateSaveLinkDownloadAttribute(evt) { - var saveLink = document.getElementById("saveRecordingAsFile"); - var recordingName = document.getElementById("recordingName").value.trim() || "untitled"; + var saveLink = document.getElementById("saveRecordingAsFile"); + var recordingName = document.getElementById("recordingName").value.trim() || "untitled"; - saveLink.download = recordingName + ".replay"; + saveLink.download = recordingName + ".replay"; }; function saveRecordingToLocalStorage(evt) { - if (evt) { - evt.preventDefault(); - evt.stopPropagation(); - } + if (evt) { + evt.preventDefault(); + evt.stopPropagation(); + } - JSIL.Replay.SaveToLocalStorage(document.getElementById("recordingName").value.trim() || "untitled"); + JSIL.Replay.SaveToLocalStorage(document.getElementById("recordingName").value.trim() || "untitled"); }; function hideSaveRecordingDialog(evt) { - if (evt) { - evt.preventDefault(); - evt.stopPropagation(); - } + if (evt) { + evt.preventDefault(); + evt.stopPropagation(); + } - var theDialog = document.getElementById("saveRecordingDialog"); - theDialog.style.display = "none"; + var theDialog = document.getElementById("saveRecordingDialog"); + theDialog.style.display = "none"; - try { - Microsoft.Xna.Framework.Game.ForceUnpause(); - } catch (exc) { - } + try { + Microsoft.Xna.Framework.Game.ForceUnpause(); + } catch (exc) { + } }; JSIL.WebWorker.OneShotEventListenerCount = 0; JSIL.WebWorker.$MakeWrappedListener = function (listener, notification) { - return function WrappedEventListener() { - notification(); + return function WrappedEventListener() { + notification(); - return listener.apply(this, arguments); - }; + return listener.apply(this, arguments); + }; }; JSIL.WebWorker.RegisterOneShotEventListener = function (element, eventName, capture, listener) { - var registered = true; - var unregister, wrappedListener; + var registered = true; + var unregister, wrappedListener; - unregister = function () { - if (registered) { - registered = false; - element.removeEventListener(eventName, wrappedListener, capture); - JSIL.WebWorker.OneShotEventListenerCount -= 1; + unregister = function () { + if (registered) { + registered = false; + element.removeEventListener(eventName, wrappedListener, capture); + JSIL.WebWorker.OneShotEventListenerCount -= 1; - wrappedListener = null; - element = null; - } - }; + wrappedListener = null; + element = null; + } + }; - wrappedListener = JSIL.WebWorker.$MakeWrappedListener(listener, unregister); - listener = null; + wrappedListener = JSIL.WebWorker.$MakeWrappedListener(listener, unregister); + listener = null; - JSIL.WebWorker.OneShotEventListenerCount += 1; - element.addEventListener(eventName, wrappedListener, capture); + JSIL.WebWorker.OneShotEventListenerCount += 1; + element.addEventListener(eventName, wrappedListener, capture); - return { - eventName: eventName, - unregister: unregister - } + return { + eventName: eventName, + unregister: unregister + } }; diff --git a/Proxies/DateTime.cs b/Proxies/DateTime.cs index c370fee0d..34edef6f3 100644 --- a/Proxies/DateTime.cs +++ b/Proxies/DateTime.cs @@ -4,21 +4,73 @@ using System.Globalization; namespace JSIL.Proxies { - [JSProxy( + /*[JSProxy( typeof(TimeSpan), - JSProxyMemberPolicy.ReplaceNone + JSProxyMemberPolicy.ReplaceDeclared )] public abstract class TimeSpanProxy { + [JSReplacement("System.TimeSpan.op_Addition($lhs, $rhs)")] [JSIsPure] public static TimeSpanProxy operator + (TimeSpanProxy lhs, TimeSpanProxy rhs) { throw new InvalidOperationException(); } + [JSReplacement("System.TimeSpan.op_Subtraction($lhs, $rhs)")] [JSIsPure] public static TimeSpanProxy operator - (TimeSpanProxy lhs, TimeSpanProxy rhs) { throw new InvalidOperationException(); } + [JSReplacement("System.TimeSpan.op_Equality($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator ==(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_Inequality($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator !=(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_GreaterThan($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator >(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_GreaterThanOrEqual($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator >=(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_LessThan($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator <(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_LessThanOrEqual($lhs, $rhs)")] + [JSIsPure] + public static TimeSpanProxy operator <=(TimeSpanProxy lhs, TimeSpanProxy rhs) + { + throw new InvalidOperationException(); + } + + [JSReplacement("System.TimeSpan.op_UnaryNegation($ts)")] + [JSIsPure] + public static TimeSpanProxy operator -(TimeSpanProxy ts) + { + throw new InvalidOperationException(); + } + + } @@ -154,6 +206,12 @@ public static string ToString() { throw new InvalidOperationException(); } + }*/ + [JSProxy(typeof(TimeSpan), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class TimeSpanProxy + { + } [JSProxy(