Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 433ade4

Browse files
committed
Merge pull request #958 from iskiselev/NoDynamicRefresh
Refresh: Dynamic on JS side
2 parents 960c211 + 25c1a4d commit 433ade4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+578
-775
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: csharp
22
solution: JSIL.sln
33

44
before_install:
5+
- git submodule update --init --recursive
56
- wget -P /tmp/ -N https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla-central/jsshell-linux-x86_64.zip
67
- unzip -d /tmp/js /tmp/jsshell-linux-x86_64.zip
78
- export PATH=$PATH:/tmp/js

Compiler/Analyzers/DeadCodeAnalyzer/JSIL.DeadCodeAnalyzer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<Project>{984CC812-9470-4A13-AFF9-CC44068D666C}</Project>
6666
<Name>ICSharpCode.Decompiler</Name>
6767
</ProjectReference>
68-
<ProjectReference Include="..\..\..\Upstream\ILSpy\Mono.Cecil\Mono.Cecil.csproj">
68+
<ProjectReference Include="..\..\..\Upstream\ILSpy\cecil\Mono.Cecil.csproj">
6969
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
7070
<Name>Mono.Cecil</Name>
7171
</ProjectReference>

Compiler/Compiler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<Project>{DA03D241-B70C-44D7-A465-3CEB5A9416AE}</Project>
8484
<Name>JSIL</Name>
8585
</ProjectReference>
86-
<ProjectReference Include="..\Upstream\ILSpy\Mono.Cecil\Mono.Cecil.csproj">
86+
<ProjectReference Include="..\Upstream\ILSpy\cecil\Mono.Cecil.csproj">
8787
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
8888
<Name>Mono.Cecil</Name>
8989
</ProjectReference>

JSIL.Libraries/Includes/Bootstrap/Core/Main.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,33 @@ JSIL.MakeClass("System.ComponentModel.TypeConverter", "System.ComponentModel.Exp
120120

121121
JSIL.MakeDelegate("System.Action", true, [], JSIL.MethodSignature.Void);
122122
JSIL.MakeDelegate("System.Action`1", true, ["T"], new JSIL.MethodSignature(null, [new JSIL.GenericParameter("T", "System.Action`1").in()]));
123-
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()]));
124-
JSIL.MakeDelegate("System.Action`3", true, ["T1", "T2", "T3"], new JSIL.MethodSignature(null, [
125-
new JSIL.GenericParameter("T1", "System.Action`3").in(), new JSIL.GenericParameter("T2", "System.Action`3").in(),
126-
new JSIL.GenericParameter("T3", "System.Action`3").in()
127-
]));
128-
129123
JSIL.MakeDelegate("System.Func`1", true, ["TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`1").out(), null));
130124
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()]));
131-
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()]));
132-
JSIL.MakeDelegate("System.Func`4", true, ["T1", "T2", "T3", "TResult"], new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", "System.Func`4").out(), [
133-
new JSIL.GenericParameter("T1", "System.Func`4").in(), new JSIL.GenericParameter("T2", "System.Func`4").in(),
134-
new JSIL.GenericParameter("T3", "System.Func`4").in()
135-
]));
125+
126+
(function() {
127+
for (var i = 2; i <= 16; i++) {
128+
var actionName = "System.Action`" + i;
129+
var funcName = "System.Func`" + (i + 1);
130+
var genericArgsForActions = [];
131+
var genericArgsForFunctions = [];
132+
133+
var inputForActions = [];
134+
var inputForFunctions = [];
135+
for (var j = 0; j < i; j++) {
136+
var name = "T" + (j + 1);
137+
genericArgsForActions.push(name);
138+
genericArgsForFunctions.push(name);
139+
140+
inputForActions.push(new JSIL.GenericParameter(name, actionName).in());
141+
inputForFunctions.push(new JSIL.GenericParameter(name, funcName).in());
142+
}
143+
144+
genericArgsForFunctions.push("TResult");
145+
146+
JSIL.MakeDelegate(actionName, true, genericArgsForActions, new JSIL.MethodSignature(null, inputForActions));
147+
JSIL.MakeDelegate(funcName, true, genericArgsForFunctions, new JSIL.MethodSignature(new JSIL.GenericParameter("TResult", funcName).out(), inputForFunctions));
148+
}
149+
})();
136150

137151
JSIL.MakeDelegate("System.Predicate`1", true, ["in T"], new JSIL.MethodSignature($jsilcore.TypeRef("System.Boolean"), [new JSIL.GenericParameter("T", "System.Predicate`1").in()]));
138152

@@ -331,4 +345,4 @@ JSIL.MakeInterface(
331345
$.Method({}, "CleanUpManagedData", JSIL.MethodSignature.Action($.Object));
332346
$.Method({}, "GetNativeDataSize", JSIL.MethodSignature.Return($.Int32));
333347
}, []);
334-
//? }
348+
//? }
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
JSIL.MakeStaticClass("Microsoft.CSharp.RuntimeBinder.Binder", true, [], function($) {
2+
$.RawMethod(true, "BinaryOperation",
3+
function(flags, operation, context, argumentInfo) {
4+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
5+
if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Add || operation === $jsilcore.System.Linq.Expressions.ExpressionType.AddChecked) {
6+
binder.Method = function (callSite, left, right) {
7+
return left+right;
8+
};
9+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.And) {
10+
binder.Method = function (callSite, left, right) {
11+
return left & right;
12+
};
13+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.AndAlso) {
14+
binder.Method = function (callSite, left, right) {
15+
return left && right;
16+
};
17+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Divide) {
18+
binder.Method = function (callSite, left, right) {
19+
return left / right;
20+
};
21+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Equal) {
22+
binder.Method = function (callSite, left, right) {
23+
return left == right;
24+
};
25+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.ExclusiveOr) {
26+
binder.Method = function (callSite, left, right) {
27+
return left ^ right;
28+
};
29+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.GreaterThan) {
30+
binder.Method = function (callSite, left, right) {
31+
return left > right;
32+
};
33+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.GreaterThanOrEqual) {
34+
binder.Method = function (callSite, left, right) {
35+
return left >= right;
36+
};
37+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LeftShift) {
38+
binder.Method = function (callSite, left, right) {
39+
return left << right;
40+
};
41+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LessThan) {
42+
binder.Method = function (callSite, left, right) {
43+
return left < right;
44+
};
45+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.LessThanOrEqual) {
46+
binder.Method = function (callSite, left, right) {
47+
return left <= right;
48+
};
49+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Modulo) {
50+
binder.Method = function (callSite, left, right) {
51+
return left % right;
52+
};
53+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Multiply || operation === $jsilcore.System.Linq.Expressions.ExpressionType.MultiplyChecked) {
54+
binder.Method = function (callSite, left, right) {
55+
return left * right;
56+
};
57+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.NotEqual) {
58+
binder.Method = function (callSite, left, right) {
59+
return left != right;
60+
};
61+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Or) {
62+
binder.Method = function (callSite, left, right) {
63+
return left | right;
64+
};
65+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.OrElse) {
66+
binder.Method = function (callSite, left, right) {
67+
return left || right;
68+
};
69+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.RightShift) {
70+
binder.Method = function (callSite, left, right) {
71+
return left >> right;
72+
};
73+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Subtract || operation === $jsilcore.System.Linq.Expressions.ExpressionType.SubtractChecked) {
74+
binder.Method = function (callSite, left, right) {
75+
return left - right;
76+
};
77+
} else {
78+
throw new Error("Binary operator is not supported.");
79+
}
80+
return binder;
81+
});
82+
83+
$.RawMethod(true, "Convert",
84+
function(flags, type, context) {
85+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
86+
binder.Method = function (callSite, target) {
87+
return type.__PublicInterface__.$Cast(target);
88+
};
89+
return binder;
90+
});
91+
92+
$.RawMethod(true, "GetIndex",
93+
function(flags, context, argumentInfo) {
94+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
95+
var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0;
96+
binder.Method = function (callSite, target) {
97+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
98+
if ("get_Item" in realTarget) {
99+
return realTarget["get_Item"].apply(realTarget, Array.prototype.slice.call(arguments, 2));
100+
} else {
101+
// TODO: Jagged arrays support
102+
if (arguments.length === 3) {
103+
return realTarget[arguments[2]];
104+
} else {
105+
throw new Error("Cannot use multi-dimensional indexer for object without indexed property.");
106+
}
107+
}
108+
};
109+
return binder;
110+
});
111+
112+
$.RawMethod(true, "GetMember",
113+
function (flags, name, context, argumentInfo) {
114+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
115+
var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0;
116+
binder.Method = function (callSite, target) {
117+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
118+
if (("get_" + name) in realTarget) {
119+
return realTarget["get_" + name]();
120+
} else {
121+
return realTarget[name];
122+
}
123+
};
124+
return binder;
125+
});
126+
127+
$.RawMethod(true, "Invoke",
128+
function (flags, context, argumentInfo) {
129+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
130+
binder.Method = function (callSite, target) {
131+
return target.apply(null, Array.prototype.slice.call(arguments, 2));
132+
};
133+
return binder;
134+
});
135+
136+
$.RawMethod(true, "InvokeConstructor",
137+
function(flags, context, argumentInfo) {
138+
throw new Error("Not implemented");
139+
});
140+
141+
$.RawMethod(true, "InvokeMember",
142+
function (flags, name, typeArguments, context, argumentInfo) {
143+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
144+
var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0;
145+
if (typeArguments !== null) {
146+
var useMemberName = name + "$b" + typeArguments.length;
147+
binder.Method = function (callSite, target) {
148+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
149+
return realTarget[useMemberName].apply(realTarget, typeArguments).apply(realTarget, Array.prototype.slice.call(arguments, 2));
150+
};
151+
} else {
152+
binder.Method = function (callSite, target) {
153+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
154+
return realTarget[name].apply(realTarget, Array.prototype.slice.call(arguments, 2));
155+
};
156+
}
157+
return binder;
158+
});
159+
160+
$.RawMethod(true, "IsEvent",
161+
function(flags, name, context) {
162+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
163+
binder.Method = function () {
164+
return false;
165+
};
166+
return binder;
167+
});
168+
169+
$.RawMethod(true, "SetIndex",
170+
function(flags, context, argumentInfo) {
171+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
172+
var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0;
173+
binder.Method = function (callSite, target) {
174+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
175+
if ("set_Item" in realTarget) {
176+
return realTarget["set_Item"].apply(realTarget, Array.prototype.slice.call(arguments, 2));
177+
} else {
178+
// TODO: Jagged arrays support
179+
if (arguments.length === 4) {
180+
realTarget[arguments[2]] = arguments[3];
181+
} else {
182+
throw new Error("Cannot use multi-dimensional indexer for object without indexed property.");
183+
}
184+
}
185+
};
186+
return binder;
187+
});
188+
189+
$.RawMethod(true, "SetMember",
190+
function(flags, name, context, argumentInfo) {
191+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
192+
var isStaticCall = (argumentInfo[0].Flags & $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.IsStaticType) > 0;
193+
binder.Method = function(callSite, target, value) {
194+
var realTarget = (isStaticCall ? target.__PublicInterface__ : target);
195+
if (("set_" + name) in realTarget) {
196+
return realTarget["set_" + name](value);
197+
} else {
198+
realTarget[name] = value;
199+
}
200+
};
201+
return binder;
202+
});
203+
204+
$.RawMethod(true, "UnaryOperation",
205+
function(flags, operation, context, argumentInfo) {
206+
var binder = new $jsilcore.System.Runtime.CompilerServices.CallSiteBinder();
207+
if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.UnaryPlus) {
208+
binder.Method = function(callSite, target) {
209+
return target;
210+
};
211+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Negate || operation === $jsilcore.System.Linq.Expressions.ExpressionType.NegateChecked) {
212+
binder.Method = function (callSite, target) {
213+
return -target;
214+
};
215+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.Not) {
216+
binder.Method = function (callSite, target) {
217+
if (typeof(target) === "boolean") {
218+
return ~target;
219+
}
220+
return ~target;
221+
};
222+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.IsTrue) {
223+
binder.Method = function (callSite, target) {
224+
return target === true;
225+
};
226+
} else if (operation === $jsilcore.System.Linq.Expressions.ExpressionType.IsFalse) {
227+
binder.Method = function (callSite, target) {
228+
return target === false;
229+
};
230+
} else {
231+
throw new Error("Unary operator is not supported.");
232+
}
233+
return binder;
234+
});
235+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
JSIL.MakeClass("System.Object", "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo", true, [], function ($) {
2+
$.Method({ Static: false, Public: true }, ".ctor",
3+
new JSIL.MethodSignature(null, [], []),
4+
function () {
5+
}
6+
);
7+
8+
$.Method({ Static: true, Public: true }, "Create",
9+
new JSIL.MethodSignature($.Type, [$jsilcore.TypeRef("Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags"), $.String], []),
10+
function CSharpArgumentInfo_Create(flags, name) {
11+
var info = new $jsilcore.Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo();
12+
info.Flags = flags;
13+
info.Name = name;
14+
return info;
15+
}
16+
);
17+
18+
$.Field({ Public: false, Static: false }, "Flags", $jsilcore.TypeRef("Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags"));
19+
$.Field({ Public: false, Static: false }, "Name", $.String);
20+
21+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSite", true, [], function ($) {
2+
});
3+
4+
JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSite`1", true, ["T"], function ($) {
5+
$.Method({ Static: true, Public: true }, "Create",
6+
new JSIL.MethodSignature($.Type, [$jsilcore.TypeRef("System.Runtime.CompilerServices.CallSiteBinder")], []),
7+
function(binder) {
8+
var callSite = new this();
9+
callSite.Target = binder.Method;
10+
return callSite;
11+
}
12+
);
13+
14+
$.Field({ Public: false, Static: false }, "Target", new JSIL.GenericParameter("T", "System.Runtime.CompilerServices.CallSite`1"));
15+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JSIL.MakeClass("System.Object", "System.Runtime.CompilerServices.CallSiteBinder", true, [], function($) {
2+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
JSIL.MakeEnum(
2+
"Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags", true, {
3+
None: 0,
4+
UseCompileTimeType: 1,
5+
Constant: 2,
6+
NamedArgument: 4,
7+
IsRef: 8,
8+
IsOut: 16,
9+
IsStaticType: 32
10+
}, true
11+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
JSIL.MakeEnum(
2+
"Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags", true, {
3+
None: 0,
4+
CheckedContext: 1,
5+
InvokeSimpleName: 2,
6+
InvokeSpecialName: 4,
7+
BinaryOperationLogical: 8,
8+
ConvertExplicit: 16,
9+
ConvertArrayIndex: 32,
10+
ResultIndexed: 64,
11+
ValueFromCompoundAssignment: 128,
12+
ResultDiscarded: 256
13+
}, true
14+
);

0 commit comments

Comments
 (0)