From 3d5efab841a8ff10f89bb4fd6fcdd0c3fab10ea2 Mon Sep 17 00:00:00 2001 From: ik Date: Sun, 29 Nov 2015 15:15:24 -0800 Subject: [PATCH 1/5] Field type resolution for generic instanses fixed (#913). Test added. --- JSIL/AST/JSExpressionTypes.cs | 10 ++++++++-- JSIL/AST/JSIdentifierTypes.cs | 2 +- Tests/SimpleTestCases/Issue913.cs | 26 ++++++++++++++++++++++++++ Tests/SimpleTests.csproj | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Tests/SimpleTestCases/Issue913.cs diff --git a/JSIL/AST/JSExpressionTypes.cs b/JSIL/AST/JSExpressionTypes.cs index 5cffc0e29..e7fed2dce 100644 --- a/JSIL/AST/JSExpressionTypes.cs +++ b/JSIL/AST/JSExpressionTypes.cs @@ -1040,8 +1040,14 @@ public override bool Equals (object o) { return base.Equals(o); } - public override TypeReference GetActualType (TypeSystem typeSystem) { - return Field.Field.FieldType; + public override TypeReference GetActualType(TypeSystem typeSystem) + { + if (PackedArrayUtil.IsPackedArrayType(Field.Field.FieldType)) + { + return Field.Field.FieldType; + } + + return base.GetActualType(typeSystem); } public override string ToString () { diff --git a/JSIL/AST/JSIdentifierTypes.cs b/JSIL/AST/JSIdentifierTypes.cs index 631aea37a..3965262b3 100644 --- a/JSIL/AST/JSIdentifierTypes.cs +++ b/JSIL/AST/JSIdentifierTypes.cs @@ -234,7 +234,7 @@ public override string Identifier { } public override TypeReference GetActualType (TypeSystem typeSystem) { - return Field.ReturnType; + return TypeAnalysis.GetFieldType(Reference); } // FIXME: Is this right? diff --git a/Tests/SimpleTestCases/Issue913.cs b/Tests/SimpleTestCases/Issue913.cs new file mode 100644 index 000000000..53ea7744d --- /dev/null +++ b/Tests/SimpleTestCases/Issue913.cs @@ -0,0 +1,26 @@ +using System; + +public static class Program +{ + public static class TmpClss + { + public static T CallSite; + }; + + public static void Main(string[] args) + { + if (TmpClss.CallSite == null) + { + TmpClss.CallSite = () => Console.WriteLine("!"); + } + var action = TmpClss.CallSite; + RunMe(); + + action(); + } + + public static void RunMe() + { + TmpClss.CallSite = () => Console.WriteLine("!!"); + } +} \ No newline at end of file diff --git a/Tests/SimpleTests.csproj b/Tests/SimpleTests.csproj index 1b72af50b..e6b0e5184 100644 --- a/Tests/SimpleTests.csproj +++ b/Tests/SimpleTests.csproj @@ -139,6 +139,7 @@ + From 12876578a88d07b75c0cdfe3427ac67feed9f08f Mon Sep 17 00:00:00 2001 From: ik Date: Mon, 23 Nov 2015 14:00:34 -0800 Subject: [PATCH 2/5] Dynamic custom processing on translation removed. Use JS-side callsite/binders analogs. Updated ILSpy version. --- .../Includes/Bootstrap/Core/Main.js | 38 +- .../Microsoft.CSharp.RuntimeBinder.Binder.js | 235 +++++++ ...CSharp.RuntimeBinder.CSharpArgumentInfo.js | 21 + ...ystem.Runtime.CompilerServices.CallSite.js | 15 + ...Runtime.CompilerServices.CallSiteBinder.js | 2 + ...p.RuntimeBinder.CSharpArgumentInfoFlags.js | 11 + ....CSharp.RuntimeBinder.CSharpBinderFlags.js | 14 + .../System.Linq.Expressions.ExpressionType.js | 89 +++ .../Includes/Bootstrap/Dynamic/Main.js | 23 + JSIL.Libraries/JSIL.Libraries.csproj | 10 + .../Sources/JSIL.Bootstrap.Dynamic.js | 2 + JSIL.Libraries/Sources/JSIL.Core.js | 3 +- JSIL.Libraries/Sources/JSIL.js | 1 + JSIL/DynamicCallSites.cs | 581 ------------------ JSIL/ILBlockTranslator.cs | 97 +-- JSIL/JSIL.csproj | 1 - JSIL/TypeInformation.cs | 28 +- Proxies/SuppressDeclaration.cs | 10 +- Upstream/ILSpy | 2 +- 19 files changed, 467 insertions(+), 716 deletions(-) create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.Binder.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSite.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSiteBinder.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/System.Linq.Expressions.ExpressionType.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js create mode 100644 JSIL.Libraries/Sources/JSIL.Bootstrap.Dynamic.js delete mode 100644 JSIL/DynamicCallSites.cs diff --git a/JSIL.Libraries/Includes/Bootstrap/Core/Main.js b/JSIL.Libraries/Includes/Bootstrap/Core/Main.js index 65f519cd5..93cb6a8f9 100644 --- a/JSIL.Libraries/Includes/Bootstrap/Core/Main.js +++ b/JSIL.Libraries/Includes/Bootstrap/Core/Main.js @@ -120,19 +120,33 @@ JSIL.MakeClass("System.ComponentModel.TypeConverter", "System.ComponentModel.Exp JSIL.MakeDelegate("System.Action", true, [], JSIL.MethodSignature.Void); JSIL.MakeDelegate("System.Action`1", true, ["T"], new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Action`1").in()])); -JSIL.MakeDelegate("System.Action`2", true, ["T1", "T2"], new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T1", "System.Action`2").in(), new JSIL.GenericParameter("T2", "System.Action`2").in()])); -JSIL.MakeDelegate("System.Action`3", true, ["T1", "T2", "T3"], new JSIL.MethodSignature(null, [ - new JSIL.GenericParameter("T1", "System.Action`3").in(), new JSIL.GenericParameter("T2", "System.Action`3").in(), - new JSIL.GenericParameter("T3", "System.Action`3").in() -])); - JSIL.MakeDelegate("System.Func`1", true, ["TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`1").out(), null)); JSIL.MakeDelegate("System.Func`2", true, ["T", "TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`2").out(), [new JSIL.GenericParameter("T", "System.Func`2").in()])); -JSIL.MakeDelegate("System.Func`3", true, ["T1", "T2", "TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`3").out(), [new JSIL.GenericParameter("T1", "System.Func`3").in(), new JSIL.GenericParameter("T2", "System.Func`3").in()])); -JSIL.MakeDelegate("System.Func`4", true, ["T1", "T2", "T3", "TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`4").out(), [ - new JSIL.GenericParameter("T1", "System.Func`4").in(), new JSIL.GenericParameter("T2", "System.Func`4").in(), - new JSIL.GenericParameter("T3", "System.Func`4").in() -])); + +(function() { + for (var i = 2; i <= 16; i++) { + var actionName = "System.Action`" + i; + var funcName = "System.Func`" + (i + 1); + var genericArgsForActions = []; + var genericArgsForFunctions = []; + + var inputForActions = []; + var inputForFunctions = []; + for (var j = 0; j < i; j++) { + var name = "T" + (j + 1); + genericArgsForActions.push(name); + genericArgsForFunctions.push(name); + + inputForActions.push(new JSIL.GenericParameter(name, actionName).in()); + inputForFunctions.push(new JSIL.GenericParameter(name, funcName).in()); + } + + genericArgsForFunctions.push("TResult"); + + JSIL.MakeDelegate(actionName, true, genericArgsForActions, new JSIL.MethodSignature(null, inputForActions)); + JSIL.MakeDelegate(funcName, true, genericArgsForFunctions, new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", funcName).out(), inputForFunctions)); + } +})(); JSIL.MakeDelegate("System.Predicate`1", true, ["in T"], new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [new JSIL.GenericParameter("T", "System.Predicate`1").in()])); @@ -331,4 +345,4 @@ JSIL.MakeInterface( $.Method({}, "CleanUpManagedData", JSIL.MethodSignature.Action($.Object)); $.Method({}, "GetNativeDataSize", JSIL.MethodSignature.Return($.Int32)); }, []); -//? } +//? } \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.Binder.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.Binder.js new file mode 100644 index 000000000..add8b3cb4 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.Binder.js @@ -0,0 +1,235 @@ +JSIL.MakeStaticClass("Microsoft.CSharp.RuntimeBinder.Binder", true, [], function($) { + $.RawMethod(true, "BinaryOperation", + function(flags, operation, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Add || operation === $jsilcore.System.Linq.Expressions.ExpressionType.AddChecked) { + binder.Method = function (callSite, left, right) { + return left+right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.And) { + binder.Method = function (callSite, left, right) { + return left & right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.AndAlso) { + binder.Method = function (callSite, left, right) { + return left && right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Divide) { + binder.Method = function (callSite, left, right) { + return left / right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Equal) { + binder.Method = function (callSite, left, right) { + return left == right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.ExclusiveOr) { + binder.Method = function (callSite, left, right) { + return left ^ right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.GreaterThan) { + binder.Method = function (callSite, left, right) { + return left > right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.GreaterThanOrEqual) { + binder.Method = function (callSite, left, right) { + return left >= right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LeftShift) { + binder.Method = function (callSite, left, right) { + return left << right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LessThan) { + binder.Method = function (callSite, left, right) { + return left < right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LessThanOrEqual) { + binder.Method = function (callSite, left, right) { + return left <= right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Modulo) { + binder.Method = function (callSite, left, right) { + return left % right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Multiply || operation === $jsilcore.System.Linq.Expressions.ExpressionType.MultiplyChecked) { + binder.Method = function (callSite, left, right) { + return left * right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.NotEqual) { + binder.Method = function (callSite, left, right) { + return left != right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Or) { + binder.Method = function (callSite, left, right) { + return left | right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.OrElse) { + binder.Method = function (callSite, left, right) { + return left || right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.RightShift) { + binder.Method = function (callSite, left, right) { + return left >> right; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Subtract || operation === $jsilcore.System.Linq.Expressions.ExpressionType.SubtractChecked) { + binder.Method = function (callSite, left, right) { + return left - right; + }; + } else { + throw new Error("Binary operator is not supported."); + } + return binder; + }); + + $.RawMethod(true, "Convert", + function(flags, type, context) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + binder.Method = function (callSite, target) { + return type.__PublicInterface__.$Cast(target); + }; + return binder; + }); + + $.RawMethod(true, "GetIndex", + function(flags, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0; + binder.Method = function (callSite, target) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + if ("get_Item" in realTarget) { + return realTarget["get_Item"].apply(realTarget, Array.prototype.slice.call(arguments, 2)); + } else { + // TODO: Jagged arrays support + if (arguments.length === 3) { + return realTarget[arguments[2]]; + } else { + throw new Error("Cannot use multi-dimensional indexer for object without indexed property."); + } + } + }; + return binder; + }); + + $.RawMethod(true, "GetMember", + function (flags, name, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0; + binder.Method = function (callSite, target) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + if (("get_" + name) in realTarget) { + return realTarget["get_" + name](); + } else { + return realTarget[name]; + } + }; + return binder; + }); + + $.RawMethod(true, "Invoke", + function (flags, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + binder.Method = function (callSite, target) { + return target.apply(null, Array.prototype.slice.call(arguments, 2)); + }; + return binder; + }); + + $.RawMethod(true, "InvokeConstructor", + function(flags, context, argumentInfo) { + throw new Error("Not implemented"); + }); + + $.RawMethod(true, "InvokeMember", + function (flags, name, typeArguments, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0; + if (typeArguments !== null) { + var useMemberName = name + "$b" + typeArguments.length; + binder.Method = function (callSite, target) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + return realTarget[useMemberName].apply(realTarget, typeArguments).apply(realTarget, Array.prototype.slice.call(arguments, 2)); + }; + } else { + binder.Method = function (callSite, target) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + return realTarget[name].apply(realTarget, Array.prototype.slice.call(arguments, 2)); + }; + } + return binder; + }); + + $.RawMethod(true, "IsEvent", + function(flags, name, context) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + binder.Method = function () { + return false; + }; + return binder; + }); + + $.RawMethod(true, "SetIndex", + function(flags, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0; + binder.Method = function (callSite, target) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + if ("set_Item" in realTarget) { + return realTarget["set_Item"].apply(realTarget, Array.prototype.slice.call(arguments, 2)); + } else { + // TODO: Jagged arrays support + if (arguments.length === 4) { + realTarget[arguments[2]] = arguments[3]; + } else { + throw new Error("Cannot use multi-dimensional indexer for object without indexed property."); + } + } + }; + return binder; + }); + + $.RawMethod(true, "SetMember", + function(flags, name, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0; + binder.Method = function(callSite, target, value) { + var realTarget = (isStaticCall ? target.__PublicInterface__ : target); + if (("set_" + name) in realTarget) { + return realTarget["set_" + name](value); + } else { + realTarget[name] = value; + } + }; + return binder; + }); + + $.RawMethod(true, "UnaryOperation", + function(flags, operation, context, argumentInfo) { + var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder(); + if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.UnaryPlus) { + binder.Method = function(callSite, target) { + return target; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Negate || operation === $jsilcore.System.Linq.Expressions.ExpressionType.NegateChecked) { + binder.Method = function (callSite, target) { + return -target; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Not) { + binder.Method = function (callSite, target) { + if (typeof(target) === "boolean") { + return ~target; + } + return ~target; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.IsTrue) { + binder.Method = function (callSite, target) { + return target === true; + }; + } else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.IsFalse) { + binder.Method = function (callSite, target) { + return target === false; + }; + } else { + throw new Error("Unary operator is not supported."); + } + return binder; + }); +}); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.js new file mode 100644 index 000000000..50753106f --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.js @@ -0,0 +1,21 @@ +JSIL.MakeClass("System.Object", "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo", true, [], function ($) { + $.Method({ Static: false, Public: true }, ".ctor", + new JSIL.MethodSignature(null, [], []), + function () { + } + ); + + $.Method({ Static: true, Public: true }, "Create", + new JSIL.MethodSignature($.Type, [$jsilcore.TypeRef("Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags"), $.String], []), + function CSharpArgumentInfo_Create(flags, name) { + var info = new $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo(); + info.Flags = flags; + info.Name = name; + return info; + } + ); + + $.Field({ Public: false, Static: false }, "Flags", $jsilcore.TypeRef("Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags")); + $.Field({ Public: false, Static: false }, "Name", $.String); + +}); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSite.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSite.js new file mode 100644 index 000000000..bea41c40f --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSite.js @@ -0,0 +1,15 @@ +JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSite", true, [], function ($) { +}); + +JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSite`1", true, ["T"], function ($) { + $.Method({ Static: true, Public: true }, "Create", + new JSIL.MethodSignature($.Type, [$jsilcore.TypeRef("System.Runtime.CompilerServices.CallSiteBinder")], []), + function(binder) { + var callSite = new this(); + callSite.Target = binder.Method; + return callSite; + } + ); + + $.Field({ Public: false, Static: false }, "Target", new JSIL.GenericParameter("T", "System.Runtime.CompilerServices.CallSite`1")); +}); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSiteBinder.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSiteBinder.js new file mode 100644 index 000000000..5f3763c97 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/System.Runtime.CompilerServices.CallSiteBinder.js @@ -0,0 +1,2 @@ +JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSiteBinder", true, [], function($) { +}); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js new file mode 100644 index 000000000..eff2b3ee8 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js @@ -0,0 +1,11 @@ +JSIL.MakeEnum( + "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags", true, { + None: 0, + UseCompileTimeType: 1, + Constant: 2, + NamedArgument: 4, + IsRef: 8, + IsOut: 16, + IsStaticType: 32 + }, true +); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.js new file mode 100644 index 000000000..73868bac2 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.js @@ -0,0 +1,14 @@ +JSIL.MakeEnum( + "Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags", true, { + None: 0, + CheckedContext: 1, + InvokeSimpleName: 2, + InvokeSpecialName: 4, + BinaryOperationLogical: 8, + ConvertExplicit: 16, + ConvertArrayIndex: 32, + ResultIndexed: 64, + ValueFromCompoundAssignment: 128, + ResultDiscarded: 256 + }, true +); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/System.Linq.Expressions.ExpressionType.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/System.Linq.Expressions.ExpressionType.js new file mode 100644 index 000000000..0d9ee9bbd --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Enums/System.Linq.Expressions.ExpressionType.js @@ -0,0 +1,89 @@ +JSIL.MakeEnum( + "System.Linq.Expressions.ExpressionType", true, { + Add: 0, + AddChecked: 1, + And: 2, + AndAlso: 3, + ArrayLength: 4, + ArrayIndex: 5, + Call: 6, + Coalesce: 7, + Conditional: 8, + Constant: 9, + Convert: 10, + ConvertChecked: 11, + Divide: 12, + Equal: 13, + ExclusiveOr: 14, + GreaterThan: 15, + GreaterThanOrEqual: 16, + Invoke: 17, + Lambda: 18, + LeftShift: 19, + LessThan: 20, + LessThanOrEqual: 21, + ListInit: 22, + MemberAccess: 23, + MemberInit: 24, + Modulo: 25, + Multiply: 26, + MultiplyChecked: 27, + Negate: 28, + UnaryPlus: 29, + NegateChecked: 30, + New: 31, + NewArrayInit: 32, + NewArrayBounds: 33, + Not: 34, + NotEqual: 35, + Or: 36, + OrElse: 37, + Parameter: 38, + Power: 39, + Quote: 40, + RightShift: 41, + Subtract: 42, + SubtractChecked: 43, + TypeAs: 44, + TypeIs: 45, + Assign: 46, + Block: 47, + DebugInfo: 48, + Decrement: 49, + Dynamic: 50, + Default: 51, + Extension: 52, + Goto: 53, + Increment: 54, + Index: 55, + Label: 56, + RuntimeVariables: 57, + Loop: 58, + Switch: 59, + Throw: 60, + Try: 61, + Unbox: 62, + AddAssign: 63, + AndAssign: 64, + DivideAssign: 65, + ExclusiveOrAssign: 66, + LeftShiftAssign: 67, + ModuloAssign: 68, + MultiplyAssign: 69, + OrAssign: 70, + PowerAssign: 71, + RightShiftAssign: 72, + SubtractAssign: 73, + AddAssignChecked: 74, + MultiplyAssignChecked: 75, + SubtractAssignChecked: 76, + PreIncrementAssign: 77, + PreDecrementAssign: 78, + PostIncrementAssign: 79, + PostDecrementAssign: 80, + TypeEqual: 81, + OnesComplement: 82, + IsTrue: 83, + IsFalse: 84 + }, true +); diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js new file mode 100644 index 000000000..525560f37 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js @@ -0,0 +1,23 @@ +"use strict"; + +if (typeof (JSIL) === "undefined") + throw new Error("JSIL.Core is required"); + +if (!$jsilcore) + throw new Error("JSIL.Core is required"); + +JSIL.DeclareNamespace("System.Runtime.CompilerServices"); +JSIL.DeclareNamespace("Microsoft"); +JSIL.DeclareNamespace("Microsoft.CSharp"); +JSIL.DeclareNamespace("Microsoft.CSharp.RuntimeBinder"); +JSIL.DeclareNamespace("System.Linq"); +JSIL.DeclareNamespace("System.Linq.Expressions"); + +//? include("Classes/System.Runtime.CompilerServices.CallSite.js"); writeln(); +//? include("Classes/System.Runtime.CompilerServices.CallSiteBinder.js"); writeln(); +//? include("Classes/Microsoft.CSharp.RuntimeBinder.Binder.js"); writeln(); +//? include("Classes/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.js"); writeln(); + +//? include("Enums/Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.js"); writeln(); +//? include("Enums/Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js"); writeln(); +//? include("Enums/System.Linq.Expressions.ExpressionType.js"); writeln(); \ No newline at end of file diff --git a/JSIL.Libraries/JSIL.Libraries.csproj b/JSIL.Libraries/JSIL.Libraries.csproj index 6677acd65..7af588ac0 100644 --- a/JSIL.Libraries/JSIL.Libraries.csproj +++ b/JSIL.Libraries/JSIL.Libraries.csproj @@ -38,6 +38,14 @@ + + + + + + + + @@ -277,6 +285,7 @@ + @@ -339,6 +348,7 @@ JSIL.mscorlib + diff --git a/JSIL.Libraries/Sources/JSIL.Bootstrap.Dynamic.js b/JSIL.Libraries/Sources/JSIL.Bootstrap.Dynamic.js new file mode 100644 index 000000000..b2bd02886 --- /dev/null +++ b/JSIL.Libraries/Sources/JSIL.Bootstrap.Dynamic.js @@ -0,0 +1,2 @@ +//? __out.GENERATE_STUBS=true; +//? include("../Includes/Bootstrap/Dynamic/Main.js"); \ No newline at end of file diff --git a/JSIL.Libraries/Sources/JSIL.Core.js b/JSIL.Libraries/Sources/JSIL.Core.js index ce936be8a..f9f13ebe2 100644 --- a/JSIL.Libraries/Sources/JSIL.Core.js +++ b/JSIL.Libraries/Sources/JSIL.Core.js @@ -491,12 +491,13 @@ JSIL.GetAssembly = function (assemblyName, requireExisting) { var isSystemCore = (shortName === "System.Core") || (assemblyName.indexOf("System.Core,") === 0); var isSystemXml = (shortName === "System.Xml") || (assemblyName.indexOf("System.Xml,") === 0); var isJsilMeta = (shortName === "JSIL.Meta") || (assemblyName.indexOf("JSIL.Meta,") === 0); + var isMicrosoftCSharp = (shortName === "Microsoft.CSharp") || (assemblyName.indexOf("Microsoft.CSharp,") === 0); // Create a new private global namespace for the new assembly var template = {}; // Ensure that BCL private namespaces inherit from the JSIL namespace. - if (isMscorlib || isSystem || isSystemCore || isSystemXml || isJsilMeta) + if (isMscorlib || isSystem || isSystemCore || isSystemXml || isJsilMeta || isMicrosoftCSharp) template = $jsilcore || {}; var result = JSIL.CreateSingletonObject(template); diff --git a/JSIL.Libraries/Sources/JSIL.js b/JSIL.Libraries/Sources/JSIL.js index 42cb28047..6d36d9b0d 100644 --- a/JSIL.Libraries/Sources/JSIL.js +++ b/JSIL.Libraries/Sources/JSIL.js @@ -288,6 +288,7 @@ var $jsilloaderstate = { environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js"); } environment.loadScript(libraryRoot + "JSIL.Bootstrap.Async.js"); + environment.loadScript(libraryRoot + "JSIL.Bootstrap.Dynamic.js"); if (config.xml || environment.getUserSetting("xml")) environment.loadScript(libraryRoot + "JSIL.XML.js"); diff --git a/JSIL/DynamicCallSites.cs b/JSIL/DynamicCallSites.cs deleted file mode 100644 index 2c561b990..000000000 --- a/JSIL/DynamicCallSites.cs +++ /dev/null @@ -1,581 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using ICSharpCode.Decompiler.ILAst; -using JSIL.Ast; -using Microsoft.CSharp.RuntimeBinder; -using Mono.Cecil; - -namespace JSIL { - internal class DynamicCallSiteInfoCollection { - protected readonly Dictionary CallSites = new Dictionary(); - protected readonly Dictionary Aliases = new Dictionary(); - - public bool Get (ILVariable localVariable, out DynamicCallSiteInfo info) { - FieldReference storageField; - - if (Aliases.TryGetValue(localVariable.Name, out storageField)) - return Get(storageField, out info); - - info = null; - return false; - } - - public bool Get (FieldReference storageField, out DynamicCallSiteInfo info) { - return CallSites.TryGetValue(storageField.FullName, out info); - } - - public DynamicCallSiteInfo InitializeCallSite (FieldReference storageField, string bindingType, TypeReference targetType, JSExpression[] arguments) { - DynamicCallSiteInfo callSiteInfo; - - switch (bindingType) { - case "GetIndex": - callSiteInfo = new DynamicCallSiteInfo.GetIndex(targetType, arguments); - break; - case "SetIndex": - callSiteInfo = new DynamicCallSiteInfo.SetIndex(targetType, arguments); - break; - case "GetMember": - callSiteInfo = new DynamicCallSiteInfo.GetMember(targetType, arguments); - break; - case "SetMember": - callSiteInfo = new DynamicCallSiteInfo.SetMember(targetType, arguments); - break; - case "Invoke": - callSiteInfo = new DynamicCallSiteInfo.Invoke(targetType, arguments); - break; - case "InvokeMember": - callSiteInfo = new DynamicCallSiteInfo.InvokeMember(targetType, arguments); - break; - case "UnaryOperation": - callSiteInfo = new DynamicCallSiteInfo.UnaryOperation(targetType, arguments); - break; - case "BinaryOperation": - callSiteInfo = new DynamicCallSiteInfo.BinaryOperation(targetType, arguments); - break; - case "Convert": - callSiteInfo = new DynamicCallSiteInfo.Convert(targetType, arguments); - break; - default: - throw new NotImplementedException(String.Format("Call sites of type '{0}' not implemented.", bindingType)); - } - - return CallSites[storageField.FullName] = callSiteInfo; - } - - public void SetAlias (ILVariable variable, FieldReference fieldReference) { - Aliases[variable.Name] = fieldReference; - } - } - - internal abstract class DynamicCallSiteInfo { - public readonly TypeReference ReturnType; - protected readonly JSExpression[] Arguments; - - protected DynamicCallSiteInfo (TypeReference targetType, JSExpression[] arguments) { - Arguments = arguments; - - var targetTypeName = targetType.FullName; - var git = targetType as GenericInstanceType; - - if (targetTypeName.StartsWith("System.Action`")) { - ReturnType = null; - } else if (targetTypeName.StartsWith("System.Func`")) { - ReturnType = git.GenericArguments[git.GenericArguments.Count - 1]; - } else { - throw new NotImplementedException(String.Format( - "This type of call site target is not implemented: {0}", - targetTypeName - )); - } - - if ((BinderFlags & CSharpBinderFlags.ResultDiscarded) == CSharpBinderFlags.ResultDiscarded) - ReturnType = null; - } - - protected JSExpression FixupThisArgument (JSExpression thisArgument, TypeSystem typeSystem) { - var expectedType = thisArgument.GetActualType(typeSystem); - if (expectedType.FullName == "System.Type") - return new JSPublicInterfaceOfExpression(thisArgument); - - return thisArgument; - } - - protected TypeReference UnwrapType (JSExpression expression) { - var type = expression as JSType; - - var invocation = expression as JSInvocationExpression; - if (invocation != null) { - var firstArg = invocation.Arguments.FirstOrDefault(); - type = firstArg as JSType; - } - - if (type != null) - return type.Type; - - throw new NotImplementedException(String.Format( - "Unrecognized type expression: {0}", - expression - )); - } - - public abstract JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments); - - public CSharpBinderFlags BinderFlags { - get { - return (CSharpBinderFlags)((JSEnumLiteral)Arguments[0]).Value; - } - } - - public class InvokeMember : DynamicCallSiteInfo { - public InvokeMember (TypeReference targetType, JSExpression[] arguments) - : base (targetType, arguments) { - } - - public string MemberName { - get { - return ((JSStringLiteral)Arguments[1]).Value; - } - } - - public JSExpression[] TypeArguments { - get { - var newarray = Arguments[2] as JSNewArrayExpression; - if (newarray == null) - return null; - - var array = (JSArrayExpression)newarray.SizeOrArrayInitializer; - return array.Values.ToArray(); - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[3]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[4]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = FixupThisArgument(arguments[1], translator.TypeSystem); - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - var argumentValues = arguments.Skip(2).ToArray(); - var memberName = MemberName; - - if ((TypeArguments != null) && (TypeArguments.Length > 0)) { - memberName += "`" + TypeArguments.Length; - } - - var thisArgumentKnownType = JSType.ExtractType(thisArgument); - if (thisArgumentKnownType != null) { - var replacement = translator.DoJSILMethodReplacement( - thisArgumentKnownType.FullName, memberName, - null, - // FIXME - null, - argumentValues - ); - if (replacement != null) - return replacement; - } - - return JSInvocationExpression.InvokeMethod( - new JSFakeMethod( - memberName, returnType, - (from av in argumentValues select av.GetActualType(translator.TypeSystem)).ToArray(), - translator.MethodTypes, TypeArguments, - escape: true - ), thisArgument, - arguments.Skip(2).ToArray() - ); - } - } - - public class Invoke : DynamicCallSiteInfo { - public Invoke (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[1]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[2]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = arguments[1]; - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - return new JSDelegateInvocationExpression( - JSChangeTypeExpression.New(thisArgument, returnType, translator.TypeSystem), - returnType, arguments.Skip(2).ToArray() - ); - } - } - - public class UnaryOperation : DynamicCallSiteInfo { - public UnaryOperation (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public ExpressionType Operation { - get { - return (ExpressionType)((JSEnumLiteral)Arguments[1]).Value; - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[2]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[3]; - } - } - - public static JSUnaryOperator GetOperator (ExpressionType et) { - switch (et) { - case ExpressionType.Negate: - case ExpressionType.NegateChecked: - return JSOperator.Negation; - case ExpressionType.Not: - return JSOperator.BitwiseNot; - case ExpressionType.IsTrue: - return JSOperator.IsTrue; - default: - throw new NotImplementedException(String.Format("The unary operator '{0}' is not implemented.", et)); - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - switch (Operation) { - case ExpressionType.IsTrue: - returnType = translator.TypeSystem.Boolean; - break; - } - - return new JSUnaryOperatorExpression( - GetOperator(Operation), - arguments[1], - returnType - ); - } - } - - public class BinaryOperation : DynamicCallSiteInfo { - public BinaryOperation (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public ExpressionType Operation { - get { - return (ExpressionType)((JSEnumLiteral)Arguments[1]).Value; - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[2]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[3]; - } - } - - public static JSBinaryOperator GetOperator (ExpressionType et) { - switch (et) { - case ExpressionType.Add: - case ExpressionType.AddChecked: - return JSOperator.Add; - case ExpressionType.And: - return JSOperator.BitwiseAnd; - case ExpressionType.AndAlso: - return JSOperator.LogicalAnd; - case ExpressionType.Divide: - return JSOperator.Divide; - case ExpressionType.Equal: - return JSOperator.Equal; - case ExpressionType.ExclusiveOr: - return JSOperator.BitwiseXor; - case ExpressionType.GreaterThan: - return JSOperator.GreaterThan; - case ExpressionType.GreaterThanOrEqual: - return JSOperator.GreaterThanOrEqual; - case ExpressionType.LeftShift: - return JSOperator.ShiftLeft; - case ExpressionType.LessThan: - return JSOperator.LessThan; - case ExpressionType.LessThanOrEqual: - return JSOperator.LessThanOrEqual; - case ExpressionType.Modulo: - return JSOperator.Remainder; - case ExpressionType.Multiply: - case ExpressionType.MultiplyChecked: - return JSOperator.Multiply; - case ExpressionType.NotEqual: - return JSOperator.NotEqual; - case ExpressionType.Or: - return JSOperator.BitwiseOr; - case ExpressionType.OrElse: - return JSOperator.LogicalOr; - case ExpressionType.RightShift: - return JSOperator.ShiftRight; - case ExpressionType.Subtract: - case ExpressionType.SubtractChecked: - return JSOperator.Subtract; - case ExpressionType.AddAssign: - case ExpressionType.AddAssignChecked: - return JSOperator.AddAssignment; - case ExpressionType.AndAssign: - return JSOperator.BitwiseAndAssignment; - case ExpressionType.DivideAssign: - return JSOperator.DivideAssignment; - case ExpressionType.ExclusiveOrAssign: - return JSOperator.BitwiseXorAssignment; - case ExpressionType.LeftShiftAssign: - return JSOperator.ShiftLeftAssignment; - case ExpressionType.ModuloAssign: - return JSOperator.RemainderAssignment; - case ExpressionType.MultiplyAssign: - return JSOperator.MultiplyAssignment; - case ExpressionType.MultiplyAssignChecked: - case ExpressionType.OrAssign: - return JSOperator.BitwiseOrAssignment; - case ExpressionType.RightShiftAssign: - return JSOperator.ShiftRightAssignment; - case ExpressionType.SubtractAssign: - case ExpressionType.SubtractAssignChecked: - return JSOperator.SubtractAssignment; - default: - throw new NotImplementedException(String.Format("The binary operator '{0}' is not implemented.", et)); - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - switch (Operation) { - case ExpressionType.Equal: - case ExpressionType.NotEqual: - case ExpressionType.LessThan: - case ExpressionType.GreaterThan: - case ExpressionType.LessThanOrEqual: - case ExpressionType.GreaterThanOrEqual: - returnType = translator.TypeSystem.Boolean; - break; - } - - return new JSBinaryOperatorExpression( - GetOperator(Operation), - arguments[1], arguments[2], - returnType - ); - } - } - - public class Convert : DynamicCallSiteInfo { - public Convert (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public TypeReference TargetType { - get { - return UnwrapType(Arguments[1]); - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[2]); - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - return JSCastExpression.New( - arguments[1], - TargetType, - translator.TypeSystem - ); - } - } - - public class GetMember : DynamicCallSiteInfo { - public GetMember (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public string MemberName { - get { - return ((JSStringLiteral)Arguments[1]).Value; - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[2]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[3]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = FixupThisArgument(arguments[1], translator.TypeSystem); - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - return JSDotExpression.New( - thisArgument, - new JSStringIdentifier(MemberName, returnType, true) - ); - } - } - - public class SetMember : DynamicCallSiteInfo { - public SetMember (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public string MemberName { - get { - return ((JSStringLiteral)Arguments[1]).Value; - } - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[2]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[3]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = FixupThisArgument(arguments[1], translator.TypeSystem); - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - return new JSBinaryOperatorExpression( - JSOperator.Assignment, - JSDotExpression.New( - thisArgument, - new JSStringIdentifier(MemberName, returnType, true) - ), - arguments[2], returnType - ); - } - } - - public class GetIndex : DynamicCallSiteInfo { - public GetIndex (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[1]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[2]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = arguments[1]; - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - return new JSIndexerExpression( - thisArgument, - arguments[2], - returnType - ); - } - } - - public class SetIndex : DynamicCallSiteInfo { - public SetIndex (TypeReference targetType, JSExpression[] arguments) - : base(targetType, arguments) { - } - - public TypeReference UsageContext { - get { - return UnwrapType(Arguments[1]); - } - } - - public JSExpression ArgumentInfo { - get { - return Arguments[2]; - } - } - - public override JSExpression Translate (ILBlockTranslator translator, JSExpression[] arguments) { - var thisArgument = arguments[1]; - - var returnType = ReturnType; - if (returnType == null) - returnType = translator.TypeSystem.Void; - - return new JSBinaryOperatorExpression( - JSOperator.Assignment, - new JSIndexerExpression( - thisArgument, - arguments[2], - returnType - ), - arguments[3], returnType - ); - } - } - } -} diff --git a/JSIL/ILBlockTranslator.cs b/JSIL/ILBlockTranslator.cs index 1afa71240..91c07d566 100644 --- a/JSIL/ILBlockTranslator.cs +++ b/JSIL/ILBlockTranslator.cs @@ -28,7 +28,6 @@ public class ILBlockTranslator { public readonly JavascriptFormatter Output = null; public readonly Dictionary Variables = new Dictionary(); - internal readonly DynamicCallSiteInfoCollection DynamicCallSites = new DynamicCallSiteInfoCollection(); protected readonly Dictionary RenamedVariables = new Dictionary(); private readonly Dictionary IndirectVariables = new Dictionary(); @@ -1391,52 +1390,8 @@ public JSExpression TranslateNode (ILExpression expression) { return result; } - protected bool TranslateCallSiteConstruction (ILCondition condition, out JSStatement result) { - result = null; - - var cond = condition.Condition; - if (cond.Code != ILCode.LogicNot) - return false; - - if (cond.Arguments.Count <= 0) - return false; - - if (cond.Arguments[0].Code != ILCode.GetCallSite) - return false; - - if (condition.TrueBlock == null) - return false; - - if (condition.TrueBlock.Body.Count != 1) - return false; - - if (condition.TrueBlock.Body[0] is ILExpression) { - var callSiteExpression = (ILExpression)condition.TrueBlock.Body[0]; - var callSiteType = callSiteExpression.Arguments[0].ExpectedType; - var binderExpression = callSiteExpression.Arguments[0].Arguments[0]; - var binderMethod = (MethodReference)binderExpression.Operand; - var arguments = Translate(binderExpression.Arguments); - var targetType = ((IGenericInstance)callSiteType).GenericArguments[0]; - - DynamicCallSites.InitializeCallSite( - (FieldReference)cond.Arguments[0].Operand, - binderMethod.Name, - targetType, - arguments.ToArray() - ); - - result = new JSNullStatement(); - return true; - } - - result = null; - return false; - } - public JSStatement TranslateNode (ILCondition condition) { JSStatement result = null; - if (TranslateCallSiteConstruction(condition, out result)) - return result; JSStatement falseBlock = null; if ((condition.FalseBlock != null) && (condition.FalseBlock.Body.Count > 0)) @@ -2359,10 +2314,8 @@ protected JSExpression Translate_Ldloca (ILExpression node, ILVariable variable) } protected JSExpression Translate_Stloc (ILExpression node, ILVariable variable) { - if (node.Arguments[0].Code == ILCode.GetCallSite) - DynamicCallSites.SetAlias(variable, (FieldReference)node.Arguments[0].Operand); - // GetCallSite and CreateCallSite produce null expressions, so we want to ignore assignments containing them + // TODO: We have nor more GetCallSite and CreateCallSite. Do we need this check? var value = TranslateNode(node.Arguments[0]); if ((value.IsNull) && !(value is JSUntranslatableExpression) && !(value is JSIgnoredExpression)) return new JSNullExpression(); @@ -3526,54 +3479,6 @@ protected JSExpression Translate_Callvirt (ILExpression node, MethodReference me return result; } - protected JSExpression Translate_InvokeCallSiteTarget (ILExpression node, MethodReference method) { - ILExpression ldtarget, ldcallsite; - - ldtarget = node.Arguments[0]; - if (ldtarget.Code == ILCode.Ldloc) { - ldcallsite = node.Arguments[1]; - } else if (ldtarget.Code == ILCode.Ldfld) { - ldcallsite = ldtarget.Arguments[0]; - } else { - throw new NotImplementedException(String.Format( - "Unknown call site pattern: Invalid load of target {0}", ldtarget - )); - } - - DynamicCallSiteInfo callSite; - - if (ldcallsite.Code == ILCode.Ldloc) { - if (!DynamicCallSites.Get((ILVariable)ldcallsite.Operand, out callSite)) - return new JSUntranslatableExpression(node); - } else if (ldcallsite.Code == ILCode.GetCallSite) { - if (!DynamicCallSites.Get((FieldReference)ldcallsite.Operand, out callSite)) - return new JSUntranslatableExpression(node); - } else { - throw new NotImplementedException(String.Format( - "Unknown call site pattern: Invalid load of callsite {0}", ldcallsite - )); - } - - var invocationArguments = Translate(node.Arguments.Skip(1)); - return callSite.Translate(this, invocationArguments.ToArray()); - } - - protected JSExpression Translate_GetCallSite (ILExpression node, FieldReference field) { - return new JSNullExpression(); - } - - protected JSExpression Translate_GetCallSiteBinder (ILExpression node) { - return new JSNullExpression(); - } - - protected JSExpression Translate_GetCallSiteBinder (ILExpression node, object o) { - return new JSNullExpression(); - } - - protected JSExpression Translate_CreateCallSite (ILExpression node, FieldReference field) { - return new JSNullExpression(); - } - protected JSExpression Translate_CallGetter (ILExpression node, MethodReference getter) { var result = Translate_Call(node, getter); diff --git a/JSIL/JSIL.csproj b/JSIL/JSIL.csproj index 0be506ef6..d31ae999d 100644 --- a/JSIL/JSIL.csproj +++ b/JSIL/JSIL.csproj @@ -72,7 +72,6 @@ - diff --git a/JSIL/TypeInformation.cs b/JSIL/TypeInformation.cs index f04376965..66dd44b29 100644 --- a/JSIL/TypeInformation.cs +++ b/JSIL/TypeInformation.cs @@ -1127,8 +1127,7 @@ protected IMemberInfo AddProxyMember (ProxyInfo proxy, EventDefinition evt) { static readonly Regex IgnoredKeywordRegex = new Regex( @"\|" + - @"Runtime\.CompilerServices\.CallSite|\|__SiteContainer|" + - @"__DynamicSite", + @"\", RegexOptions.Compiled ); @@ -1182,26 +1181,11 @@ public string FullName { } public static bool IsIgnoredName (string shortName) { - foreach (Match m2 in IgnoredKeywordRegex.Matches(shortName)) { - if (m2.Success) { - var length = m2.Length; - var index = m2.Index; - if ( - (length >= 2) && - (shortName[index] == '_') && - (shortName[index + 1] == '_') - ) { - switch (m2.Value) { - case "__DynamicSite": - case "__SiteContainer": - return true; - - default: - return false; - } - } else { - return true; - } + foreach (Match m2 in IgnoredKeywordRegex.Matches(shortName)) + { + if (m2.Success) + { + return true; } } diff --git a/Proxies/SuppressDeclaration.cs b/Proxies/SuppressDeclaration.cs index 847b624c3..70d84963b 100644 --- a/Proxies/SuppressDeclaration.cs +++ b/Proxies/SuppressDeclaration.cs @@ -37,7 +37,7 @@ typeof (IList<>), typeof (IEnumerable), typeof (ICollection), - typeof (IList), + typeof (IList) }, inheritable: false)] [JSSuppressTypeDeclaration] @@ -56,7 +56,13 @@ public class SuppressDeclarationByType "System.Reflection.RuntimePropertyInfo", "System.Reflection.RuntimeEventInfo", "System.Reflection.RuntimeParameterInfo", - "System.Empty" + "System.Empty", + + "Microsoft.CSharp.RuntimeBinder.Binder", + "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo", + "System.Runtime.CompilerServices.CallSite", + "System.Runtime.CompilerServices.CallSite`1", + "System.Runtime.CompilerServices.CallSiteBinder" }, inheritable: false)] [JSSuppressTypeDeclaration] diff --git a/Upstream/ILSpy b/Upstream/ILSpy index b445b9a7e..244f5dfd8 160000 --- a/Upstream/ILSpy +++ b/Upstream/ILSpy @@ -1 +1 @@ -Subproject commit b445b9a7ee5412c86a77ab594e7a6bf2ff24ea6d +Subproject commit 244f5dfd8bac869ace799cc4e970fbdc8eba43e0 From 7b08c67abcf359c46b40ee2fd859477cbd5f1bcb Mon Sep 17 00:00:00 2001 From: ik Date: Fri, 4 Dec 2015 17:43:10 -0800 Subject: [PATCH 3/5] Fixed supposed error for dynamic tests. CallSiteVariablesEliminated test deleted. VerbatimDynamic test moved to FailingTests class. --- Tests/FailingTests.cs | 18 ++++++++++++++++++ Tests/FormattingTests.cs | 24 ------------------------ Tests/MetadataTests.cs | 4 ++-- Tests/VerbatimTests.cs | 8 -------- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/Tests/FailingTests.cs b/Tests/FailingTests.cs index f52c3e149..1ccc22c0a 100644 --- a/Tests/FailingTests.cs +++ b/Tests/FailingTests.cs @@ -84,5 +84,23 @@ public void FailingTestCases (object[] parameters) { protected IEnumerable FailingTestCasesSource () { return FolderTestSource("FailingTestCases", MakeDefaultProvider(), new AssemblyCache()); } + + [Test] + public void VerbatimDynamic() + { + try + { + var js = GetJavascript( + @"SpecialTestCases\Issue548.cs", + "{\"obj1\":\"{}\"}" + ); + } + catch (Exception) + { + return; + } + + Assert.Fail("Test passed when it should have failed"); + } } } \ No newline at end of file diff --git a/Tests/FormattingTests.cs b/Tests/FormattingTests.cs index a355c4f3b..6936a4764 100644 --- a/Tests/FormattingTests.cs +++ b/Tests/FormattingTests.cs @@ -819,30 +819,6 @@ public void InterfaceVariance () { } } - [Test] - public void CallSiteVariablesEliminated () { - var output = "a\r\n6"; - var generatedJs = GetJavascript( - @"TestCases\DynamicReturnTypes.cs", - output, () => { - var cfg = MakeConfiguration(); - cfg.CodeGenerator.CacheTypeExpressions = true; - return cfg; - } - ); - - try { - Assert.IsFalse( - generatedJs.Contains(".CallSite"), - "A CallSite was not fully eliminated" - ); - } catch { - Console.WriteLine(generatedJs); - - throw; - } - } - [Test] public void SpuriousIntegerHints () { var output = "0F0F\r\n7773"; diff --git a/Tests/MetadataTests.cs b/Tests/MetadataTests.cs index 09b13bd98..a54799370 100644 --- a/Tests/MetadataTests.cs +++ b/Tests/MetadataTests.cs @@ -446,7 +446,7 @@ public void ComplexDynamics () { Assert.Fail("Translated JS ran successfully"); } catch (JavaScriptEvaluatorException jse) { - Assert.IsTrue(jse.ToString().Contains("TypeError: document is undefined"), jse.ToString()); + Assert.IsTrue(jse.ToString().Contains("TypeError: realTarget is undefined"), jse.ToString()); } } @@ -460,7 +460,7 @@ public void ComplexDynamicsMonoBinary () { Assert.Fail("Translated JS ran successfully"); } catch (JavaScriptEvaluatorException jse) { - Assert.IsTrue(jse.ToString().Contains("TypeError: obj is undefined"), jse.ToString()); + Assert.IsTrue(jse.ToString().Contains("TypeError: realTarget is undefined"), jse.ToString()); } } diff --git a/Tests/VerbatimTests.cs b/Tests/VerbatimTests.cs index ac14ded6b..7fe7f7784 100644 --- a/Tests/VerbatimTests.cs +++ b/Tests/VerbatimTests.cs @@ -78,13 +78,5 @@ public void VerbatimVariablesExistingArray () { "hello\r\n7" ); } - - [Test] - public void VerbatimDynamic () { - var js = GetJavascript( - @"SpecialTestCases\Issue548.cs", - "{\"obj1\":\"{}\"}" - ); - } } } From 7c20f6d9be8642554a9b321c970ce773a7b91801 Mon Sep 17 00:00:00 2001 From: ik Date: Tue, 8 Dec 2015 16:44:46 -0800 Subject: [PATCH 4/5] New JsAPI (#532). Tests updated, removed depricated tests. --- .../Dynamic/Classes/JSIL.JSObjectHelper.js | 503 ++++++++++++++++++ .../Classes/JSIL.JsObject.JSFunction.js | 29 + .../Dynamic/Classes/JSIL.JsObject.js | 34 ++ .../Dynamic/Classes/JSIL.Services.js | 20 + .../Includes/Bootstrap/Dynamic/Main.js | 4 + JSIL.Libraries/JSIL.Libraries.csproj | 4 + JSIL/ILBlockTranslator.cs | 65 +-- Meta | 2 +- Tests/BinaryTestCases/DynamicComplex.exe | Bin 5120 -> 0 bytes Tests/FailingTests.cs | 18 - Tests/MetadataTests.cs | 13 - Tests/SpecialTestCases/Eval.cs | 7 +- Tests/SpecialTestCases/IndexBuiltinByName.cs | 23 +- Tests/SpecialTestCases/Verbatim.cs | 8 +- Tests/SpecialTestCases/VerbatimThis.cs | 2 +- Tests/SpecialTestCases/VerbatimVariables.cs | 2 +- .../VerbatimVariablesExistingArray.cs | 12 - Tests/Tests.csproj | 2 - Tests/VerbatimTests.cs | 13 +- 19 files changed, 649 insertions(+), 112 deletions(-) create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.JSFunction.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.js create mode 100644 JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.Services.js delete mode 100644 Tests/BinaryTestCases/DynamicComplex.exe delete mode 100644 Tests/SpecialTestCases/VerbatimVariablesExistingArray.cs diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js new file mode 100644 index 000000000..b20680b65 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js @@ -0,0 +1,503 @@ +(function JsObjectHelpers$Members() { + var $, $thisType; + + function JsObjectHelpers_As$b1(T, obj) { + return T.$As(obj); + }; + + function JsObjectHelpers_AssumeType$b1(T, obj) { + return obj; + }; + + function JsObjectHelpers_Call(target, key) { + return target[key](); + }; + + function JsObjectHelpers_Call$b1(TArg1, target, key, arg1) { + return target[key](arg1); + }; + + function JsObjectHelpers_Call$b2(TArg1, TArg2, target, key, arg1, arg2) { + return target[key](arg1, arg2); + }; + + function JsObjectHelpers_Call$b3(TArg1, TArg2, TArg3, target, key, arg1, arg2, arg3) { + return target[key](arg1, arg2, arg3); + }; + + function JsObjectHelpers_Call$b4(TArg1, TArg2, TArg3, TArg4, target, key, arg1, arg2, arg3, arg4) { + return target[key](arg1, arg2, arg3, arg4); + }; + + function JsObjectHelpers_Call$b5(TArg1, TArg2, TArg3, TArg4, TArg5, target, key, arg1, arg2, arg3, arg4, arg5) { + return target[key](arg1, arg2, arg3, arg4, arg5); + }; + + function JsObjectHelpers_Call$b6(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, target, key, arg1, arg2, arg3, arg4, arg5, arg6) { + return target[key](arg1, arg2, arg3, arg4, arg5, arg6); + }; + + function JsObjectHelpers_Call$b7(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, target, key, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { + return target[key](arg1, arg2, arg3, arg4, arg5, arg6, arg7); + }; + + function JsObjectHelpers_Call$b8(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, target, key, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { + return target[key](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + }; + + function JsObjectHelpers_Cast$b1(T, obj) { + return T.$Cast(obj); + }; + + function JsObjectHelpers_Delete(target, key) { + delete target[key]; + }; + + function JsObjectHelpers_Get(target, key) { + return target[key]; + }; + + function JsObjectHelpers_In(target, key) { + return key in target; + }; + + function JsObjectHelpers_Invoke(target) { + return target(); + }; + + function JsObjectHelpers_Invoke$b1(TArg1, target, arg1) { + return target(arg1); + }; + + function JsObjectHelpers_Invoke$b2(TArg1, TArg2, target, arg1, arg2) { + return target(arg1, arg2); + }; + + function JsObjectHelpers_Invoke$b3(TArg1, TArg2, TArg3, target, arg1, arg2, arg3) { + return target(arg1, arg2, arg3); + }; + + function JsObjectHelpers_Invoke$b4(TArg1, TArg2, TArg3, TArg4, target, arg1, arg2, arg3, arg4) { + return target(arg1, arg2, arg3, arg4); + }; + + function JsObjectHelpers_Invoke$b5(TArg1, TArg2, TArg3, TArg4, TArg5, target, arg1, arg2, arg3, arg4, arg5) { + return target(arg1, arg2, arg3, arg4, arg5); + }; + + function JsObjectHelpers_Invoke$b6(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, target, arg1, arg2, arg3, arg4, arg5, arg6) { + return target(arg1, arg2, arg3, arg4, arg5, arg6); + }; + + function JsObjectHelpers_Invoke$b7(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, target, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { + return target(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + }; + + function JsObjectHelpers_Invoke$b8(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, target, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { + return target(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + }; + + function JsObjectHelpers_Is$b1(T, obj) { + return T.$Is(obj); + }; + + function JsObjectHelpers_New(target) { + return new target(); + }; + + function JsObjectHelpers_New$b1(TArg1, target, arg1) { + return new target(arg1); + }; + + function JsObjectHelpers_New$b2(TArg1, TArg2, target, arg1, arg2) { + return new target(arg1, arg2); + }; + + function JsObjectHelpers_New$b3(TArg1, TArg2, TArg3, target, arg1, arg2, arg3) { + return new target(arg1, arg2, arg3); + }; + + function JsObjectHelpers_New$b4(TArg1, TArg2, TArg3, TArg4, target, arg1, arg2, arg3, arg4) { + return new target(arg1, arg2, arg3, arg4); + }; + + function JsObjectHelpers_New$b5(TArg1, TArg2, TArg3, TArg4, TArg5, target, arg1, arg2, arg3, arg4, arg5) { + return new target(arg1, arg2, arg3, arg4, arg5); + }; + + function JsObjectHelpers_New$b6(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, target, arg1, arg2, arg3, arg4, arg5, arg6) { + return new target(arg1, arg2, arg3, arg4, arg5, arg6); + }; + + function JsObjectHelpers_New$b7(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, target, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { + return new target(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + }; + + function JsObjectHelpers_New$b8(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, target, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { + return new target(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + }; + + function JsObjectHelpers_Set$b1(TValue, target, key, value) { + target[key] = value; + }; + + JSIL.MakeStaticClass("JSIL.JsObjectHelpers", true, [], function ($ib) { + $ = $ib; + + $.Method({ Static: true, Public: true }, "Adapt", + new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), + JsObjectHelpers_Adapt$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "As", + new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), + JsObjectHelpers_As$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "AssumeType", + new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), + JsObjectHelpers_AssumeType$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String]), + JsObjectHelpers_Call + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0" + ], ["TArg1"]), + JsObjectHelpers_Call$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1" + ], ["TArg1", "TArg2"]), + JsObjectHelpers_Call$b2 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2" + ], ["TArg1", "TArg2", "TArg3"]), + JsObjectHelpers_Call$b3 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2", "!!3" + ], ["TArg1", "TArg2", "TArg3", "TArg4"]), + JsObjectHelpers_Call$b4 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2", "!!3", + "!!4" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5" + ]), + JsObjectHelpers_Call$b5 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2", "!!3", + "!!4", "!!5" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6" + ]), + JsObjectHelpers_Call$b6 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2", "!!3", + "!!4", "!!5", + "!!6" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7" + ]), + JsObjectHelpers_Call$b7 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Call", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + "!!0", "!!1", + "!!2", "!!3", + "!!4", "!!5", + "!!6", "!!7" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7", "TArg8" + ]), + JsObjectHelpers_Call$b8 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Cast", + new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), + JsObjectHelpers_Cast$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Delete", + new JSIL.MethodSignature(null, [$jsilcore.TypeRef("JSIL.JsObject"), $.String]), + JsObjectHelpers_Delete + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Get", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject"), $.String]), + JsObjectHelpers_Get + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "In", + new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("JSIL.JsObject"), $.String]), + JsObjectHelpers_In + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction")]), + JsObjectHelpers_Invoke + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0"], ["TArg1"]), + JsObjectHelpers_Invoke$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1" + ], ["TArg1", "TArg2"]), + JsObjectHelpers_Invoke$b2 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2" + ], ["TArg1", "TArg2", "TArg3"]), + JsObjectHelpers_Invoke$b3 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3" + ], ["TArg1", "TArg2", "TArg3", "TArg4"]), + JsObjectHelpers_Invoke$b4 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5" + ]), + JsObjectHelpers_Invoke$b5 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6" + ]), + JsObjectHelpers_Invoke$b6 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5", "!!6" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7" + ]), + JsObjectHelpers_Invoke$b7 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Invoke", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5", "!!6", + "!!7" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7", "TArg8" + ]), + JsObjectHelpers_Invoke$b8 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Is", + new JSIL.MethodSignature($.Boolean, [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), + JsObjectHelpers_Is$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction")]), + JsObjectHelpers_New + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0"], ["TArg1"]), + JsObjectHelpers_New$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1" + ], ["TArg1", "TArg2"]), + JsObjectHelpers_New$b2 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2" + ], ["TArg1", "TArg2", "TArg3"]), + JsObjectHelpers_New$b3 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3" + ], ["TArg1", "TArg2", "TArg3", "TArg4"]), + JsObjectHelpers_New$b4 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5" + ]), + JsObjectHelpers_New$b5 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6" + ]), + JsObjectHelpers_New$b6 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5", "!!6" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7" + ]), + JsObjectHelpers_New$b7 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "New", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ + $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), "!!0", + "!!1", "!!2", + "!!3", "!!4", + "!!5", "!!6", + "!!7" + ], [ + "TArg1", "TArg2", "TArg3", "TArg4", + "TArg5", "TArg6", "TArg7", "TArg8" + ]), + JsObjectHelpers_New$b8 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + $.Method({ Static: true, Public: true }, "Set", + new JSIL.MethodSignature(null, [ + $jsilcore.TypeRef("JSIL.JsObject"), $.String, + "!!0" + ], ["TValue"]), + JsObjectHelpers_Set$b1 + ) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + + + return function (newThisType) { $thisType = newThisType; }; + }) + .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); + +})(); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.JSFunction.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.JSFunction.js new file mode 100644 index 000000000..6104a4f0f --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.JSFunction.js @@ -0,0 +1,29 @@ +(function JsFunction$Members() { + var $, $thisType; + var $T00 = function () { + return ($T00 = JSIL.Memoize($jsilcore.JSIL.JsObject))(); + }; + + function JsFunction__ctor() { + $T00().prototype._ctor.call(this); + }; + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("JSIL.JsObject"), + Name: "JSIL.JsObject+JsFunction", + IsPublic: false, + IsReferenceType: true, + MaximumConstructorArguments: 0, + }, function ($ib) { + $ = $ib; + + $.Method({ Static: false, Public: false }, ".ctor", + JSIL.MethodSignature.Void, + JsFunction__ctor + ); + + + return function (newThisType) { $thisType = newThisType; }; + }); + +})(); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.js new file mode 100644 index 000000000..c1c09401d --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JsObject.js @@ -0,0 +1,34 @@ +(function JsObject$Members() { + var $, $thisType; + + function JsObject__ctor() { + }; + + function JsObject_Global(key) { + return JSIL.GlobalNamespace[key]; + }; + + JSIL.MakeType({ + BaseType: $jsilcore.TypeRef("System.Object"), + Name: "JSIL.JsObject", + IsPublic: true, + IsReferenceType: true, + MaximumConstructorArguments: 0, + }, function ($ib) { + $ = $ib; + + $.Method({ Static: false, Public: false }, ".ctor", + JSIL.MethodSignature.Void, + JsObject__ctor + ); + + $.Method({ Static: true, Public: true }, "Global", + new JSIL.MethodSignature($.Type, [$.String]), + JsObject_Global + ); + + + return function (newThisType) { $thisType = newThisType; }; + }); + +})(); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.Services.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.Services.js new file mode 100644 index 000000000..b7a7235e4 --- /dev/null +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.Services.js @@ -0,0 +1,20 @@ +(function Services$Members() { + var $, $thisType; + + function Services_Get(serviceName, throwIfMissing) { + return JSIL.Host.getService(serviceName, !throwIfMissing); + }; + + JSIL.MakeStaticClass("JSIL.Services", true, [], function ($ib) { + $ = $ib; + + $.Method({ Static: true, Public: true }, "Get", + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$.String, $.Boolean]), + Services_Get + ); + + + return function (newThisType) { $thisType = newThisType; }; + }); + +})(); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js index 525560f37..b63e34e3e 100644 --- a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Main.js @@ -13,6 +13,10 @@ JSIL.DeclareNamespace("Microsoft.CSharp.RuntimeBinder"); JSIL.DeclareNamespace("System.Linq"); JSIL.DeclareNamespace("System.Linq.Expressions"); +//? include("Classes/JSIL.JsObject.js"); writeln(); +//? include("Classes/JSIL.JsObject.JSFunction.js"); writeln(); +//? include("Classes/JSIL.JSObjectHelper.js"); writeln(); + //? include("Classes/System.Runtime.CompilerServices.CallSite.js"); writeln(); //? include("Classes/System.Runtime.CompilerServices.CallSiteBinder.js"); writeln(); //? include("Classes/Microsoft.CSharp.RuntimeBinder.Binder.js"); writeln(); diff --git a/JSIL.Libraries/JSIL.Libraries.csproj b/JSIL.Libraries/JSIL.Libraries.csproj index 7af588ac0..f201ba364 100644 --- a/JSIL.Libraries/JSIL.Libraries.csproj +++ b/JSIL.Libraries/JSIL.Libraries.csproj @@ -38,6 +38,10 @@ + + + + diff --git a/JSIL/ILBlockTranslator.cs b/JSIL/ILBlockTranslator.cs index 91c07d566..27a5bfafd 100644 --- a/JSIL/ILBlockTranslator.cs +++ b/JSIL/ILBlockTranslator.cs @@ -848,61 +848,42 @@ JSExpression[] arguments JSExpression commaFirstClause = null; IDictionary argumentsDict = null; - if (arguments.Length > 1) { - var argumentsExpression = arguments[1]; - var argumentsArray = argumentsExpression as JSNewArrayExpression; - - if (method == null || method.Method.Parameters[1].ParameterType is GenericParameter) { - // This call was made dynamically or through generic version of method, so the parameters are not an array. - - argumentsDict = new Dictionary(); - - for (var i = 0; i < (arguments.Length - 1); i++) - argumentsDict.Add(String.Format("{0}", i), arguments[i + 1]); - } else if (argumentsArray == null) { - // The array is static so we need to pull elements out of it after assigning it a name. - // FIXME: Only handles up to 40 elements. - var argumentsExpressionType = argumentsExpression.GetActualType(TypeSystem); - var temporaryVariable = MakeTemporaryVariable(argumentsExpressionType); - var temporaryAssignment = new JSBinaryOperatorExpression(JSOperator.Assignment, temporaryVariable, argumentsExpression, argumentsExpressionType); - - commaFirstClause = temporaryAssignment; - - argumentsDict = new Dictionary(); - - for (var i = 0; i < 40; i++) - argumentsDict.Add(String.Format("{0}", i), new JSIndexerExpression(temporaryVariable, JSLiteral.New(i))); - } else { - var argumentsArrayExpression = argumentsArray.SizeOrArrayInitializer as JSArrayExpression; - - if (argumentsArrayExpression == null) - throw new NotImplementedException("Literal array must have values"); - - argumentsDict = new Dictionary(); - - int i = 0; - foreach (var value in argumentsArrayExpression.Values) { - argumentsDict.Add(String.Format("{0}", i), value); + if (arguments.Length > 1) + { + argumentsDict = new Dictionary(); - i += 1; - } - } + for (var i = 0; i < (arguments.Length - 1); i++) + argumentsDict.Add(String.Format("{0}", i), arguments[i + 1]); } var verbatimLiteral = new JSVerbatimLiteral( methodName, expression.Value, argumentsDict ); - if (commaFirstClause != null) - return new JSCommaExpression(commaFirstClause, verbatimLiteral); - else - return verbatimLiteral; + return verbatimLiteral; } else { throw new NotImplementedException("Verbatim method not implemented: " + methodName); } break; } + case "JSIL.JSObject": + { + if (methodName == "Global") + { + var expression = arguments[0] as JSStringLiteral; + if (expression != null) + return new JSDotExpression( + JSIL.GlobalNamespace, new JSStringIdentifier(expression.Value, TypeSystem.Object, true) + ); + else + return new JSIndexerExpression( + JSIL.GlobalNamespace, arguments[0], TypeSystem.Object + ); + } + break; + } + case "JSIL.JSGlobal": { if (methodName == "get_Item") { var expression = arguments[0] as JSStringLiteral; diff --git a/Meta b/Meta index 7ab12f0b0..1bba443d0 160000 --- a/Meta +++ b/Meta @@ -1 +1 @@ -Subproject commit 7ab12f0b00b837f7e71ddec7b578225bd4b680db +Subproject commit 1bba443d09144a619b12a82bc9751a3db0530c08 diff --git a/Tests/BinaryTestCases/DynamicComplex.exe b/Tests/BinaryTestCases/DynamicComplex.exe deleted file mode 100644 index f38afb236c8e03fed359aa664d5f431891a6398c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5120 zcmeHLU2Ggz75?t-dcB^+n|RlD<8(_VI7Tj{TPJZ6YTVR`?WB(EBxIeWjVjsuGjWE@ z&a7s~!6uPwl&1)l2856*@dV@zRe3;aC?JH2`a~oos042jPpO1}2VUTT@SQs|>va-n zRq+J9-Z}T&@0|PHbI;s+XU20EZy^aF#p~fi;4W(^6I%Xfu}*V#*SlH#xa;2TyK45{ z?)l4h(`@+Ol3%Wy)w1h)fmyLkf7vx{*PJ?CGV5N=Dt31pdm`#H)4;4sVkvm*bUfO9 zWYrdx2DTEBz@(VbHNjeHWex7LWZwM!bleF!4ql0~h`ulr_8LjdCp{E8SZI}jQm4u~FWogqNH5J!zZBDNU1OZ7u~CWsW5wMiaT^l1bkx1CaUmL7TjMO_ zSYQ1Fu}XK%5ymRbw0|Rxwcq0sHM-ZBy42VaMr_Lc@Zb2Tf#U3kIq#O(g+lXOHTGI7^j~fc z{po+ZT!wbU3ukDcrR|KhaALhOz6_v8xz-ntm)T|TuXk6k*H7s49GsiEbn=*z?6Jtc zzdBkRDIOR(uumq={nnry=TaG51AfH%712w9Z@WuP@klX&zhgaku7uxH{|>1Jk2zk2 zn8O&D5DcC;H#5aLE~HQwdJ~y0D%wE+s&dqDErH#1dk1TA5gQkpuDKF)4ZNemsMFYj zUZgQVY2ZtkpgcjD#dW+%`8H(^f4~Fk8TBTuJJqntVv>3e7t{kH6*WQK*7{BA2EM1| zAGO?(5T9{MDR1jxC1+n(+wm*5j#5{+!Pc*%Rs#L_vocjb{-)(W)brGl5G0*ALb)|D zOPNbtRDUvs^}F~`^>Ic$_$;})@GNsbfLD>H_C5yjWt>!_yhHEfB&Dyaob9SwBEGJ! zqoDDE#`kD^uSWK2WR%DqdVX8IhjERMYkW%Mvl^Mz$UKq1<0cLzuBdNmS;SA_akTgF zO*Np-!N)i77Jh(t@mt)-hv-tNb&0>d+-4T|Yb#+(?p<6A?AK~Lwi8z#!@huf8cWJb zI9ZyREzVg%nc4}iv9hBf99y=Xz;>I6z$GhKm8S-M>I8wjhT{?c;Ya)TN7l7~lqiV^WK+pSst z6M7tX%G@-QzEuw5V2XV3S(q$4PRS0esAm{wOh=b`!*(pcWcgR^sznAJQs^9V&P=#w^Z2q`T^wy8m@oUx zB|>*e(+sD!f}@&s@c>Fz5RpXCAsnb4I#@n@(8BnfS6gZ#{9M~1xv4hp40nez) zG80{_1|BCFB~d4W`LAs_@JU{Shbop)hXoe_@N|_c-9nkVg=sjHEn9b$xQnZlJOcZc zXbUh&2I*;GMf!K_M-6y3v~BL+FJg-90^-J1;G~ z-t&Pm)`>)}uV-Mxp${FoXL@#L`*K6{%ysL!&w%R7J*V=>JwxO{5OkXa9wjrg%iFw-nv$0op zTgdWank*TXZDu+mVqmF!$Ckca%a-K1l8=ZasToW@ydGyKvz#r6#4@$jn)KTrMT zpN~FqgyN-$C&jvrR-;ptimYYs^W%DFS>$waiThB>9{p7@Ppj>GIr?|6;YI{W*4Bhjz9IzEQ@X?aox Q%;;Yavamlb|92Vq7xBVl8UO$Q diff --git a/Tests/FailingTests.cs b/Tests/FailingTests.cs index 1ccc22c0a..f52c3e149 100644 --- a/Tests/FailingTests.cs +++ b/Tests/FailingTests.cs @@ -84,23 +84,5 @@ public void FailingTestCases (object[] parameters) { protected IEnumerable FailingTestCasesSource () { return FolderTestSource("FailingTestCases", MakeDefaultProvider(), new AssemblyCache()); } - - [Test] - public void VerbatimDynamic() - { - try - { - var js = GetJavascript( - @"SpecialTestCases\Issue548.cs", - "{\"obj1\":\"{}\"}" - ); - } - catch (Exception) - { - return; - } - - Assert.Fail("Test passed when it should have failed"); - } } } \ No newline at end of file diff --git a/Tests/MetadataTests.cs b/Tests/MetadataTests.cs index a54799370..f0b518e28 100644 --- a/Tests/MetadataTests.cs +++ b/Tests/MetadataTests.cs @@ -450,19 +450,6 @@ public void ComplexDynamics () { } } - // Mono compiles this to different IL. - [Test] - public void ComplexDynamicsMonoBinary () { - try { - GetJavascript( - @"BinaryTestCases\DynamicComplex.exe" - ); - - Assert.Fail("Translated JS ran successfully"); - } catch (JavaScriptEvaluatorException jse) { - Assert.IsTrue(jse.ToString().Contains("TypeError: realTarget is undefined"), jse.ToString()); - } - } // Mono generates really weird control flow for this [Test] diff --git a/Tests/SpecialTestCases/Eval.cs b/Tests/SpecialTestCases/Eval.cs index 671d22627..ea31fd60f 100644 --- a/Tests/SpecialTestCases/Eval.cs +++ b/Tests/SpecialTestCases/Eval.cs @@ -3,9 +3,10 @@ public static class Program { public static int Foo () { - var result = Builtins.Eval("2") ?? 1; - - return (int)result; + if (Builtins.IsJavascript) { + return Builtins.Eval("2").AssumeType(); + } + return 1; } public static void Main (string[] args) { diff --git a/Tests/SpecialTestCases/IndexBuiltinByName.cs b/Tests/SpecialTestCases/IndexBuiltinByName.cs index 1a93e64b9..8bdec68ba 100644 --- a/Tests/SpecialTestCases/IndexBuiltinByName.cs +++ b/Tests/SpecialTestCases/IndexBuiltinByName.cs @@ -3,19 +3,22 @@ public static class Program { public static void Main (string[] args) { - const string pri = "pri"; - string nt = "nt"; + if (Builtins.IsJavascript) + { + const string pri = "pri"; + string nt = "nt"; - var p = Builtins.Global[pri + nt] as dynamic; - if (p != null) - p("printed"); + var p = Builtins.Global[pri + nt] as dynamic; + if (p != null) + p("printed"); - if (Builtins.Local["p"] != null) - (Builtins.Local["p"] as dynamic)("printed again"); + if (Builtins.Local["p"] != null) + (Builtins.Local["p"] as dynamic)("printed again"); - var q = Builtins.Global["quit"] as dynamic; - if (q != null) - q(); + var q = Builtins.Global["quit"] as dynamic; + if (q != null) + q(); + } Console.WriteLine("test"); } diff --git a/Tests/SpecialTestCases/Verbatim.cs b/Tests/SpecialTestCases/Verbatim.cs index 1031dcab4..8145ca54e 100644 --- a/Tests/SpecialTestCases/Verbatim.cs +++ b/Tests/SpecialTestCases/Verbatim.cs @@ -2,13 +2,15 @@ using JSIL; public static class Program { - public static int Add (int a, int b) { - return Verbatim.Expression("a + b"); + public static int Add (int a, int b) + { + return Builtins.IsJavascript ? Verbatim.Expression("a + b").AssumeType() : 0; } public static void Main (string[] args) { Console.WriteLine(Add(1, 3)); - Verbatim.Expression("return"); + if (Builtins.IsJavascript) + Verbatim.Expression("return"); Console.WriteLine(2); } } \ No newline at end of file diff --git a/Tests/SpecialTestCases/VerbatimThis.cs b/Tests/SpecialTestCases/VerbatimThis.cs index ba2444713..9f1ec56fe 100644 --- a/Tests/SpecialTestCases/VerbatimThis.cs +++ b/Tests/SpecialTestCases/VerbatimThis.cs @@ -4,7 +4,7 @@ public static class Program { public class CustomType { public CustomType () { - Console.WriteLine("{0}", Builtins.This ?? ""); + Console.WriteLine("{0}", Builtins.This); } } diff --git a/Tests/SpecialTestCases/VerbatimVariables.cs b/Tests/SpecialTestCases/VerbatimVariables.cs index eb1ffc1c3..f0e478249 100644 --- a/Tests/SpecialTestCases/VerbatimVariables.cs +++ b/Tests/SpecialTestCases/VerbatimVariables.cs @@ -7,7 +7,7 @@ public static void Main (string[] args) { var a = 2; var b = 5; Console.WriteLine(Verbatim.Expression("$0 + $1", a, b)); - int i = Verbatim.Expression("$0 + $1", a, b); + int i = Verbatim.Expression("$0 + $1", a, b).AssumeType(); Console.WriteLine(i); } } \ No newline at end of file diff --git a/Tests/SpecialTestCases/VerbatimVariablesExistingArray.cs b/Tests/SpecialTestCases/VerbatimVariablesExistingArray.cs deleted file mode 100644 index 8478db339..000000000 --- a/Tests/SpecialTestCases/VerbatimVariablesExistingArray.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using JSIL; - -public static class Program { - static object[] A1 = new object[] { "hello" }; - static object[] A2 = new object[] { 2, 5 }; - - public static void Main (string[] args) { - Verbatim.Expression("print($0)", A1); - Console.WriteLine(Verbatim.Expression("$0 + $1", A2)); - } -} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 233363e14..453908c8f 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -256,7 +256,6 @@ - @@ -621,7 +620,6 @@ - diff --git a/Tests/VerbatimTests.cs b/Tests/VerbatimTests.cs index 7fe7f7784..0847ccc0a 100644 --- a/Tests/VerbatimTests.cs +++ b/Tests/VerbatimTests.cs @@ -41,9 +41,9 @@ public void VerbatimIsEmittedRawInGeneratedJavascript () { [Test] public void BuiltinsThisEvaluatesToJSThis () { - GenericTest( + GetJavascript( @"SpecialTestCases\VerbatimThis.cs", - "", "Program+CustomType" + "Program+CustomType" ); } @@ -72,11 +72,12 @@ public void VerbatimVariables () { } [Test] - public void VerbatimVariablesExistingArray () { + public void VerbatimDynamic() + { var js = GetJavascript( - @"SpecialTestCases\VerbatimVariablesExistingArray.cs", - "hello\r\n7" - ); + @"SpecialTestCases\Issue548.cs", + "{\"obj1\":\"{}\"}" + ); } } } From 9d584f0d63215b1c33ac88475121fc918d4d30f3 Mon Sep 17 00:00:00 2001 From: ik Date: Tue, 8 Dec 2015 22:28:25 -0800 Subject: [PATCH 5/5] JsAPI errors fixed, first test case added. --- .../Dynamic/Classes/JSIL.JSObjectHelper.js | 24 +++++++------------ Meta | 2 +- Tests/ComparisonTests.cs | 1 + Tests/TestCases/DynamicJsAPI.cs | 17 +++++++++++++ Tests/Tests.csproj | 1 + 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 Tests/TestCases/DynamicJsAPI.cs diff --git a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js index b20680b65..82162dba7 100644 --- a/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js +++ b/JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js @@ -144,12 +144,6 @@ JSIL.MakeStaticClass("JSIL.JsObjectHelpers", true, [], function ($ib) { $ = $ib; - $.Method({ Static: true, Public: true }, "Adapt", - new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), - JsObjectHelpers_Adapt$b1 - ) - .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); - $.Method({ Static: true, Public: true }, "As", new JSIL.MethodSignature("!!0", [$jsilcore.TypeRef("JSIL.JsObject")], ["T"]), JsObjectHelpers_As$b1 @@ -163,14 +157,14 @@ .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); $.Method({ Static: true, Public: true }, "Call", - new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String]), + new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$jsilcore.TypeRef("JSIL.JsObject"), $.String]), JsObjectHelpers_Call ) .Attribute($jsilcore.TypeRef("System.Runtime.CompilerServices.ExtensionAttribute")); $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0" ], ["TArg1"]), JsObjectHelpers_Call$b1 @@ -179,7 +173,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1" ], ["TArg1", "TArg2"]), JsObjectHelpers_Call$b2 @@ -188,7 +182,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2" ], ["TArg1", "TArg2", "TArg3"]), @@ -198,7 +192,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2", "!!3" ], ["TArg1", "TArg2", "TArg3", "TArg4"]), @@ -208,7 +202,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2", "!!3", "!!4" @@ -222,7 +216,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2", "!!3", "!!4", "!!5" @@ -236,7 +230,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2", "!!3", "!!4", "!!5", @@ -251,7 +245,7 @@ $.Method({ Static: true, Public: true }, "Call", new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [ - $jsilcore.TypeRef("JSIL.JsObject+JsFunction"), $.String, + $jsilcore.TypeRef("JSIL.JsObject"), $.String, "!!0", "!!1", "!!2", "!!3", "!!4", "!!5", diff --git a/Meta b/Meta index 1bba443d0..d0d7565d8 160000 --- a/Meta +++ b/Meta @@ -1 +1 @@ -Subproject commit 1bba443d09144a619b12a82bc9751a3db0530c08 +Subproject commit d0d7565d81bad9febf30d2a5eb6e3fe719c95e72 diff --git a/Tests/ComparisonTests.cs b/Tests/ComparisonTests.cs index c8d74c807..fb0565016 100644 --- a/Tests/ComparisonTests.cs +++ b/Tests/ComparisonTests.cs @@ -129,6 +129,7 @@ protected IEnumerable DynamicsSource () { @"TestCases\DynamicSetIndex.cs", @"TestCases\DynamicStaticOverloadedMethods.cs", @"TestCases\DynamicUnaryOperators.cs", + @"TestCases\DynamicJsAPI.cs", }, null, new AssemblyCache() ); } diff --git a/Tests/TestCases/DynamicJsAPI.cs b/Tests/TestCases/DynamicJsAPI.cs new file mode 100644 index 000000000..1ffb25041 --- /dev/null +++ b/Tests/TestCases/DynamicJsAPI.cs @@ -0,0 +1,17 @@ +using System; +using JSIL; + +public static class Program { + public static void Main (string[] args) { + if (Builtins.IsJavascript) + { + dynamic a = 5; + var b = Verbatim.Expression("{GetValue: function(value) { return value + 10}}"); + Console.WriteLine(JsObjectHelpers.Call(b, "GetValue", a)); + } + else + { + Console.WriteLine(15); + } + } +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 453908c8f..850181ab7 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -292,6 +292,7 @@ +