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

Commit 7c20f6d

Browse files
committed
New JsAPI (#532). Tests updated, removed depricated tests.
1 parent 7b08c67 commit 7c20f6d

19 files changed

+649
-112
lines changed

JSIL.Libraries/Includes/Bootstrap/Dynamic/Classes/JSIL.JSObjectHelper.js

Lines changed: 503 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function JsFunction$Members() {
2+
var $, $thisType;
3+
var $T00 = function () {
4+
return ($T00 = JSIL.Memoize($jsilcore.JSIL.JsObject))();
5+
};
6+
7+
function JsFunction__ctor() {
8+
$T00().prototype._ctor.call(this);
9+
};
10+
11+
JSIL.MakeType({
12+
BaseType: $jsilcore.TypeRef("JSIL.JsObject"),
13+
Name: "JSIL.JsObject+JsFunction",
14+
IsPublic: false,
15+
IsReferenceType: true,
16+
MaximumConstructorArguments: 0,
17+
}, function ($ib) {
18+
$ = $ib;
19+
20+
$.Method({ Static: false, Public: false }, ".ctor",
21+
JSIL.MethodSignature.Void,
22+
JsFunction__ctor
23+
);
24+
25+
26+
return function (newThisType) { $thisType = newThisType; };
27+
});
28+
29+
})();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function JsObject$Members() {
2+
var $, $thisType;
3+
4+
function JsObject__ctor() {
5+
};
6+
7+
function JsObject_Global(key) {
8+
return JSIL.GlobalNamespace[key];
9+
};
10+
11+
JSIL.MakeType({
12+
BaseType: $jsilcore.TypeRef("System.Object"),
13+
Name: "JSIL.JsObject",
14+
IsPublic: true,
15+
IsReferenceType: true,
16+
MaximumConstructorArguments: 0,
17+
}, function ($ib) {
18+
$ = $ib;
19+
20+
$.Method({ Static: false, Public: false }, ".ctor",
21+
JSIL.MethodSignature.Void,
22+
JsObject__ctor
23+
);
24+
25+
$.Method({ Static: true, Public: true }, "Global",
26+
new JSIL.MethodSignature($.Type, [$.String]),
27+
JsObject_Global
28+
);
29+
30+
31+
return function (newThisType) { $thisType = newThisType; };
32+
});
33+
34+
})();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(function Services$Members() {
2+
var $, $thisType;
3+
4+
function Services_Get(serviceName, throwIfMissing) {
5+
return JSIL.Host.getService(serviceName, !throwIfMissing);
6+
};
7+
8+
JSIL.MakeStaticClass("JSIL.Services", true, [], function ($ib) {
9+
$ = $ib;
10+
11+
$.Method({ Static: true, Public: true }, "Get",
12+
new JSIL.MethodSignature($jsilcore.TypeRef("JSIL.JsObject"), [$.String, $.Boolean]),
13+
Services_Get
14+
);
15+
16+
17+
return function (newThisType) { $thisType = newThisType; };
18+
});
19+
20+
})();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ JSIL.DeclareNamespace("Microsoft.CSharp.RuntimeBinder");
1313
JSIL.DeclareNamespace("System.Linq");
1414
JSIL.DeclareNamespace("System.Linq.Expressions");
1515

16+
//? include("Classes/JSIL.JsObject.js"); writeln();
17+
//? include("Classes/JSIL.JsObject.JSFunction.js"); writeln();
18+
//? include("Classes/JSIL.JSObjectHelper.js"); writeln();
19+
1620
//? include("Classes/System.Runtime.CompilerServices.CallSite.js"); writeln();
1721
//? include("Classes/System.Runtime.CompilerServices.CallSiteBinder.js"); writeln();
1822
//? include("Classes/Microsoft.CSharp.RuntimeBinder.Binder.js"); writeln();

JSIL.Libraries/JSIL.Libraries.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
<ItemGroup>
3939
<Content Include="Includes\Bootstrap\Core\Helpers\JSIL.MakeIConvertibleMethods.js" />
4040
<Content Include="Includes\Bootstrap\Core\Interfaces\System.IConvertible.js" />
41+
<Content Include="Includes\Bootstrap\Dynamic\Classes\JSIL.Services.js" />
42+
<Content Include="Includes\Bootstrap\Dynamic\Classes\JSIL.JSObjectHelper.js" />
43+
<Content Include="Includes\Bootstrap\Dynamic\Classes\JSIL.JsObject.JSFunction.js" />
44+
<Content Include="Includes\Bootstrap\Dynamic\Classes\JSIL.JsObject.js" />
4145
<Content Include="Includes\Bootstrap\Dynamic\Classes\Microsoft.CSharp.RuntimeBinder.Binder.js" />
4246
<Content Include="Includes\Bootstrap\Dynamic\Enums\Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.js" />
4347
<Content Include="Includes\Bootstrap\Dynamic\Enums\System.Linq.Expressions.ExpressionType.js" />

JSIL/ILBlockTranslator.cs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -848,61 +848,42 @@ JSExpression[] arguments
848848
JSExpression commaFirstClause = null;
849849
IDictionary<string, JSExpression> argumentsDict = null;
850850

851-
if (arguments.Length > 1) {
852-
var argumentsExpression = arguments[1];
853-
var argumentsArray = argumentsExpression as JSNewArrayExpression;
854-
855-
if (method == null || method.Method.Parameters[1].ParameterType is GenericParameter) {
856-
// This call was made dynamically or through generic version of method, so the parameters are not an array.
857-
858-
argumentsDict = new Dictionary<string, JSExpression>();
859-
860-
for (var i = 0; i < (arguments.Length - 1); i++)
861-
argumentsDict.Add(String.Format("{0}", i), arguments[i + 1]);
862-
} else if (argumentsArray == null) {
863-
// The array is static so we need to pull elements out of it after assigning it a name.
864-
// FIXME: Only handles up to 40 elements.
865-
var argumentsExpressionType = argumentsExpression.GetActualType(TypeSystem);
866-
var temporaryVariable = MakeTemporaryVariable(argumentsExpressionType);
867-
var temporaryAssignment = new JSBinaryOperatorExpression(JSOperator.Assignment, temporaryVariable, argumentsExpression, argumentsExpressionType);
868-
869-
commaFirstClause = temporaryAssignment;
870-
871-
argumentsDict = new Dictionary<string, JSExpression>();
872-
873-
for (var i = 0; i < 40; i++)
874-
argumentsDict.Add(String.Format("{0}", i), new JSIndexerExpression(temporaryVariable, JSLiteral.New(i)));
875-
} else {
876-
var argumentsArrayExpression = argumentsArray.SizeOrArrayInitializer as JSArrayExpression;
877-
878-
if (argumentsArrayExpression == null)
879-
throw new NotImplementedException("Literal array must have values");
880-
881-
argumentsDict = new Dictionary<string, JSExpression>();
882-
883-
int i = 0;
884-
foreach (var value in argumentsArrayExpression.Values) {
885-
argumentsDict.Add(String.Format("{0}", i), value);
851+
if (arguments.Length > 1)
852+
{
853+
argumentsDict = new Dictionary<string, JSExpression>();
886854

887-
i += 1;
888-
}
889-
}
855+
for (var i = 0; i < (arguments.Length - 1); i++)
856+
argumentsDict.Add(String.Format("{0}", i), arguments[i + 1]);
890857
}
891858

892859
var verbatimLiteral = new JSVerbatimLiteral(
893860
methodName, expression.Value, argumentsDict
894861
);
895862

896-
if (commaFirstClause != null)
897-
return new JSCommaExpression(commaFirstClause, verbatimLiteral);
898-
else
899-
return verbatimLiteral;
863+
return verbatimLiteral;
900864
} else {
901865
throw new NotImplementedException("Verbatim method not implemented: " + methodName);
902866
}
903867
break;
904868
}
905869

870+
case "JSIL.JSObject":
871+
{
872+
if (methodName == "Global")
873+
{
874+
var expression = arguments[0] as JSStringLiteral;
875+
if (expression != null)
876+
return new JSDotExpression(
877+
JSIL.GlobalNamespace, new JSStringIdentifier(expression.Value, TypeSystem.Object, true)
878+
);
879+
else
880+
return new JSIndexerExpression(
881+
JSIL.GlobalNamespace, arguments[0], TypeSystem.Object
882+
);
883+
}
884+
break;
885+
}
886+
906887
case "JSIL.JSGlobal": {
907888
if (methodName == "get_Item") {
908889
var expression = arguments[0] as JSStringLiteral;

Meta

-5 KB
Binary file not shown.

Tests/FailingTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,5 @@ public void FailingTestCases (object[] parameters) {
8484
protected IEnumerable<TestCaseData> FailingTestCasesSource () {
8585
return FolderTestSource("FailingTestCases", MakeDefaultProvider(), new AssemblyCache());
8686
}
87-
88-
[Test]
89-
public void VerbatimDynamic()
90-
{
91-
try
92-
{
93-
var js = GetJavascript(
94-
@"SpecialTestCases\Issue548.cs",
95-
"{\"obj1\":\"{}\"}"
96-
);
97-
}
98-
catch (Exception)
99-
{
100-
return;
101-
}
102-
103-
Assert.Fail("Test passed when it should have failed");
104-
}
10587
}
10688
}

0 commit comments

Comments
 (0)