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/.gitignore b/.gitignore index 2e40b142b..a69525e79 100644 --- a/.gitignore +++ b/.gitignore @@ -94,4 +94,5 @@ Corlib/*.nlp /Upstream/OpenTKBindingGenerator /Upstream/OpenTKHeaderParser *.RuntimeProfile -*.out \ No newline at end of file +*.out +*.orig 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/JSIL/AssemblyTranslator.cs b/JSIL/AssemblyTranslator.cs index 190ffd7da..766c4e0f2 100644 --- a/JSIL/AssemblyTranslator.cs +++ b/JSIL/AssemblyTranslator.cs @@ -1226,6 +1226,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(); @@ -2618,6 +2623,7 @@ protected void DefineMethod ( output.Comma(); output.Value(Util.EscapeIdentifier(methodInfo.GetName(true), EscapingMode.String)); + output.Comma(); output.NewLine(); diff --git a/JSIL/CILSupport.cs b/JSIL/CILSupport.cs index 79534a2fd..e4cffb033 100644 --- a/JSIL/CILSupport.cs +++ b/JSIL/CILSupport.cs @@ -13,138 +13,138 @@ 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 Module; @@ -158,13 +158,13 @@ public Key (TypeReference tr) { HashCode = Namespace.GetHashCode() ^ Name.GetHashCode() ^ Module.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) && (Module == rhs.Module) && @@ -172,79 +172,79 @@ public bool Equals (Key rhs) { (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; } + } } diff --git a/JSIL/JavascriptFormatter.cs b/JSIL/JavascriptFormatter.cs index 267646b7f..eca6e2261 100644 --- a/JSIL/JavascriptFormatter.cs +++ b/JSIL/JavascriptFormatter.cs @@ -181,6 +181,7 @@ public JavascriptFormatter ( Configuration configuration, bool stubbed ) { Output = output; + //Output = Console.Out; TypeInfo = typeInfo; Manifest = manifest; Assembly = assembly; @@ -483,7 +484,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)) { @@ -681,7 +681,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/JSIL/TypeInformation.cs b/JSIL/TypeInformation.cs index 06e025282..19235e874 100644 --- a/JSIL/TypeInformation.cs +++ b/JSIL/TypeInformation.cs @@ -784,6 +784,7 @@ public RecursiveInterfaceToken[] AllInterfacesRecursive { get { if (_AllInterfacesRecursive == null) { var list = new List(); + var added = new HashSet(); var types = SelfAndBaseTypesRecursive.Reverse().ToArray(); foreach (var type in types) 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.DateTime.js b/Libraries/JSIL.Bootstrap.DateTime.js index 2e32c4cef..2af7e6dfa 100644 --- a/Libraries/JSIL.Bootstrap.DateTime.js +++ b/Libraries/JSIL.Bootstrap.DateTime.js @@ -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.Int64.js b/Libraries/JSIL.Bootstrap.Int64.js index 4d68c4303..00249e2e5 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,37 @@ 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"); + n = 0 - n; + } - 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 +311,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.Text.js b/Libraries/JSIL.Bootstrap.Text.js index fddfc3df8..7d7407ce1 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 c25684bdd..19f341390 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); @@ -1554,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; } ); @@ -1569,6 +1579,18 @@ JSIL.ImplementExternals("System.Collections.Generic.Stack`1", function ($) { function _ctor (capacity) { $jsilcore.InitResizableArray(this, this.T, capacity); this._size = 0; + this.tEnumerator = null; + } + ); + + $.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; } ); @@ -1586,15 +1608,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"); @@ -1604,7 +1619,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; @@ -1614,13 +1629,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 ($) { @@ -1710,9 +1756,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( @@ -1821,8 +1878,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; @@ -2185,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; } @@ -2208,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; @@ -2227,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 = []; @@ -2279,6 +2369,15 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) } ); + $.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); + + // TODO: Use comparer in some way + } + ); + $.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) { @@ -2503,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]); }; @@ -2542,6 +2654,20 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2+ValueCollection } ); + $.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++; + } + } + ); + + var getEnumeratorImpl = function GetEnumerator () { return JSIL.CreateInstanceOfType(this.dictionary.tValueEnumerator, [this.dictionary]); }; @@ -2926,7 +3052,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1+Enumerator", funct ); $.Method({Static:false, Public:false}, ".ctor", - new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.HashSet`1", [$.GenericParameter("T")])], []), + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("System.Collections.Generic.HashSet`1", [$.GenericParameter("T")])], []), function _ctor (hashSet) { this.hashSet = hashSet; @@ -2951,7 +3077,7 @@ JSIL.ImplementExternals("System.Collections.Generic.HashSet`1+Enumerator", funct ); $.Method({Static:false, Public:true , Virtual:true }, "get_Current", - new JSIL.MethodSignature($.GenericParameter("T"), [], []), + new JSIL.MethodSignature($.GenericParameter("T"), [], []), function get_Current () { return this.state.current; } @@ -3001,6 +3127,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) { @@ -3414,6 +3616,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) { @@ -3739,6 +3948,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__; @@ -5111,6 +5334,20 @@ JSIL.ImplementExternals("System.Array", function ($) { 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); + }); + } + ); }); JSIL.MakeInterface( diff --git a/Libraries/JSIL.Browser.js b/Libraries/JSIL.Browser.js index f92afefe4..69c009926 100644 --- a/Libraries/JSIL.Browser.js +++ b/Libraries/JSIL.Browser.js @@ -192,8 +192,9 @@ 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") + if (typeof (text) === "string") { window.console.warn(text.trim()); + } else window.console.warn(text); } else if (this.stream) { diff --git a/Libraries/JSIL.Core.Reflection.js b/Libraries/JSIL.Core.Reflection.js index 27e0b3cb8..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) { @@ -57,6 +66,48 @@ 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, true, false); + 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({ 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 @@ -94,6 +145,33 @@ JSIL.ImplementExternals( new JSIL.MethodSignature($.Boolean, []), 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_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 () { + return this.__ElementType__ != null; + }); $.Method({Public: true , Static: false}, "get_IsValueType", new JSIL.MethodSignature($.Boolean, []), @@ -386,9 +464,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; } ); @@ -491,7 +583,7 @@ JSIL.ImplementExternals( $.Method({ Public: true, Static: false }, "GetInterfaces", new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Type]), []), function () { - return JSIL.GetInterfacesImplementedByType(this, true, false); + return JSIL.GetInterfacesImplementedByType(this); } ); } @@ -821,16 +913,16 @@ JSIL.ImplementExternals("System.Reflection.MethodInfo", function ($) { var parametersCount = 0; if (parameters !== null) parametersCount = parameters.length; - + if (parameterTypes.length !== parametersCount) throw new System.Exception("Parameters count mismatch."); - if (parameters !== null) { + if (parameters !== null) { parameters = parameters.slice(); - for (var i = 0; i < parametersCount; i++) { + for (var i = 0; i < parametersCount; i++) { if (parameters[i] === null && parameterTypes[i].IsValueType) - parameters[i] = JSIL.CreateInstanceOfType(parameterTypes[i]); - } + parameters[i] = JSIL.CreateInstanceOfType(parameterTypes[i]); + } } return impl.apply(obj, parameters); @@ -900,6 +992,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"); @@ -910,7 +1005,11 @@ 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"); + $.Property({ Public: true, Static: false }, "ContainsGenericParameters"); }); JSIL.MakeClass("System.Type", "System.RuntimeType", false, [], function ($) { @@ -1195,6 +1294,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.Types.js b/Libraries/JSIL.Core.Types.js index 9254a0d3f..494d2755c 100644 --- a/Libraries/JSIL.Core.Types.js +++ b/Libraries/JSIL.Core.Types.js @@ -525,6 +525,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/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index dfe624ffd..29ee1da58 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -5059,6 +5059,8 @@ 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 isPrimitive = Boolean(typeArgs.IsPrimitive); var genericArguments = typeArgs.GenericParameters || $jsilcore.ArrayNull; var maxConstructorArguments = typeArgs.MaximumConstructorArguments; @@ -5139,6 +5141,8 @@ JSIL.MakeType = function (typeArgs, initializer) { } typeObject.__IsArray__ = false; + typeObject.__IsAbstract__ = isAbstract; + typeObject.__IsPrimitive__ = isPrimitive; typeObject.__FieldList__ = $jsilcore.ArrayNotInitialized; typeObject.__FieldInitializer__ = $jsilcore.FunctionNotInitialized; typeObject.__MemberCopier__ = $jsilcore.FunctionNotInitialized; @@ -5205,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++) { @@ -5314,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; @@ -5328,6 +5332,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 || []; @@ -5345,7 +5350,7 @@ JSIL.MakeInterface = function (fullName, isPublic, genericArguments, initializer } typeObject._IsAssignableFrom = function (typeOfValue) { - return typeOfValue.__AssignableTypes__[this.__TypeId__] === true; + return typeOfValue.__AssignableTypes__ != null ? typeOfValue.__AssignableTypes__[this.__TypeId__] === true : false; }; JSIL.MakeCastMethods(publicInterface, typeObject, "interface"); @@ -8240,6 +8245,12 @@ 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; @@ -8248,6 +8259,7 @@ JSIL.ObjectEquals = function (lhs, rhs) { switch (typeof (lhs)) { case "string": + case "boolean": case "number": return lhs == rhs; break; @@ -8675,7 +8687,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__; diff --git a/Libraries/JSIL.HeuristicLab.js b/Libraries/JSIL.HeuristicLab.js new file mode 100644 index 000000000..a512ee4fe --- /dev/null +++ b/Libraries/JSIL.HeuristicLab.js @@ -0,0 +1,148 @@ +// 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) { + // 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, 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/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( diff --git a/Libraries/JSIL.WebWorker.Loaders.js b/Libraries/JSIL.WebWorker.Loaders.js new file mode 100644 index 000000000..8a0142f18 --- /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..7bfbf8a27 --- /dev/null +++ b/Libraries/JSIL.WebWorker.js @@ -0,0 +1,761 @@ +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 +}; + +function updateProgressBar(prefix, suffix, bytesLoaded, bytesTotal) { + postMessage({operation: 'progress', prefix: prefix, suffix: suffix, bytesLoaded: bytesLoaded, bytesTotal: bytesTotal}); +} + +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', message: 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() { + var state = this; + + 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(); + } + + 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; + } + } + initIfNeeded(); + + updateProgressBar("Initializing Application ...", null, 1, -1); + + var allFailures = $jsilloaderstate.loadFailures.concat(state.assetLoadFailures); + + clearInterval(state.interval); + state.interval = null; + + finishedLoading(); + + return; +}; + +function pollAssetQueue() { + var state = this; + + var w = 0; + updateProgressBar("Initializing ...", null, -1, -1); + + 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) { + 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; + }); + + 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; + } + + state.interval = setInterval(pollAssetQueue.bind(state), 1); +}; + +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]); + + } + } + + 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 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 6c08c880d..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; @@ -179,7 +209,8 @@ 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.HeuristicLab.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/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/Array.cs b/Proxies/Array.cs index 7d32bae95..0aae65d57 100644 --- a/Proxies/Array.cs +++ b/Proxies/Array.cs @@ -1,8 +1,10 @@ using System; using JSIL.Meta; using JSIL.Proxy; +using System.Collections.Generic; namespace JSIL.Proxies { + [JSProxy( typeof(Array), memberPolicy: JSProxyMemberPolicy.ReplaceDeclared @@ -98,6 +100,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/Bootstrap.cs b/Proxies/Bootstrap.cs new file mode 100644 index 000000000..254ac9944 --- /dev/null +++ b/Proxies/Bootstrap.cs @@ -0,0 +1,447 @@ +using JSIL.Meta; +using JSIL.Proxy; +using System; +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 + { + } + + [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_Stack_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(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 + { + } + + [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(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 + { + } + + [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(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_WeakReference + { + } + +} diff --git a/Proxies/Collections.cs b/Proxies/Collections.cs index 7f18c7992..e17875876 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 @@ -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..34edef6f3 100644 --- a/Proxies/DateTime.cs +++ b/Proxies/DateTime.cs @@ -1,22 +1,217 @@ using System; using JSIL.Meta; using JSIL.Proxy; +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(); + } + + + + } + + [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(typeof(TimeSpan), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class TimeSpanProxy + { + } [JSProxy( @@ -29,4 +224,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/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/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/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/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/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/IO.cs b/Proxies/IO.cs index fa511ee0b..1c7abd433 100644 --- a/Proxies/IO.cs +++ b/Proxies/IO.cs @@ -38,6 +38,92 @@ public FileStreamProxy(SafeFileHandle handle, AnyType access, int bufferSize) { public FileStreamProxy (SafeFileHandle handle, AnyType access, int bufferSize, bool isAsync) { throw new NotImplementedException(); } + } + + [JSProxy(typeof(FileStream), JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_IO_FileStream + { + } + + [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(); + } + } + + [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/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..62a12660a 100644 --- a/Proxies/Proxies.4.0.csproj +++ b/Proxies/Proxies.4.0.csproj @@ -34,9 +34,21 @@ + + + + + + + + + + + + @@ -47,6 +59,7 @@ + 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/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/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/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/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(); + } } } 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/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 + { + } +} 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 + { + } +} 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 + { + + } +}