Skip to content

Commit 63a6e57

Browse files
committed
Don't emit the .Of() part of type identifiers for generic types, since it doesn't do anything at present anyway
Change UntranslatableFunction to throw on invocation instead of throw on declaration Change static constructor implementation to allow logging exceptions in static constructors instead of aborting (by overriding JSIL.Host.error, or running with firebug loaded)
1 parent 592b9f5 commit 63a6e57

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

‎Examples/output/MannuxXNA/Mannux.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
<script src="mscorlib.js"></script>
99
<script src="../../../Libraries/System.Windows.js"></script>
1010
<script src="../../../Libraries/System.Drawing.js"></script>
11+
<script src="xnaframework.js"></script>
12+
<script src="xnagame.js"></script>
1113
<script src="../../../Libraries/JSIL.XNA.js"></script>
12-
<script src="xna.js"></script>
1314
<script src="Mannux.js"></script>
1415

1516
<canvas id="canvas"></canvas><br>

‎Examples/output/MannuxXNA/Mannux.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ Cataract.XNAGraph.prototype.End = function () {
630630
Cataract.XNAGraph.prototype.Blit$0 = function (img, pos, slice) {
631631
var destRect = new Microsoft.Xna.Framework.Rectangle();
632632
destRect._ctor(Math.floor(pos.X), Math.floor(pos.Y), slice.Width, slice.Height);
633-
this.spriteBatch.Draw(img, destRect.MemberwiseClone(), new (System.Nullable$b1.Of(Microsoft.Xna.Framework.Rectangle)) (slice), Microsoft.Xna.Framework.Graphics.Color.White);
633+
this.spriteBatch.Draw(img, destRect.MemberwiseClone(), new System.Nullable$b1/* <Rectangle> */ (slice), Microsoft.Xna.Framework.Graphics.Color.White);
634634
};
635635

636636
Cataract.XNAGraph.prototype.Blit$1 = function (src, x, y, trans) {
@@ -1773,9 +1773,9 @@ Sprites.BitmapSprite.prototype.tex = null;
17731773
Sprites.BitmapSprite.prototype.graph = null;
17741774

17751775
Import.VectorIndexBuffer.prototype._ctor = function () {
1776-
this.points = new (System.Collections.Generic.List$b1.Of(Import.Geo.Vertex)) ();
1776+
this.points = new System.Collections.Generic.List$b1/* <Vertex> */ ();
17771777
System.Object.prototype._ctor.call(this);
1778-
this.points = new (System.Collections.Generic.List$b1.Of(Import.Geo.Vertex)) ();
1778+
this.points = new System.Collections.Generic.List$b1/* <Vertex> */ ();
17791779
this.lines = new System.Collections.ArrayList();
17801780
};
17811781

‎JSIL/JavascriptFormatter.cs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,27 @@ protected void TypeIdentifier (ArrayType type, bool includeParens) {
234234
}
235235
}
236236

237+
// TODO: Figure out whether generic argument information can be used
237238
protected void TypeIdentifier (GenericInstanceType type, bool includeParens) {
239+
/*
238240
if (includeParens)
239241
LPar();
242+
*/
240243

241244
Identifier(type.ElementType);
242-
Dot();
243-
Identifier("Of");
244-
LPar();
245-
CommaSeparatedList(type.GenericArguments);
246-
RPar();
247245

246+
Comment(
247+
"<{0}>", String.Join(", ",
248+
(from a in type.GenericArguments select String.Concat(a.Name)).ToArray()
249+
)
250+
);
251+
252+
/*
248253
if (includeParens) {
249254
RPar();
250255
Space();
251256
}
257+
*/
252258
}
253259

254260
public void Identifier (MethodReference method, bool fullyQualified = true) {

‎Libraries/JSIL.Core.js‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,23 @@ JSIL.Host.warning = function (text) {
7070
else
7171
JSIL.Host.logWriteLine(System.String.Concat.apply(null, arguments));
7272
};
73+
JSIL.Host.error = function (exception, text) {
74+
var rest = Array.prototype.slice.call(arguments, 1);
75+
76+
if (typeof (console) !== "undefined")
77+
console.error.apply(null, rest.concat([exception]));
78+
else
79+
throw exception;
80+
}
7381

7482
JSIL.UntranslatableNode = function (nodeType) {
7583
throw new Error("An ILAst node of type " + nodeType + " could not be translated.");
7684
};
7785

7886
JSIL.UntranslatableFunction = function (functionName) {
79-
throw new Error("The function '" + functionName + "' could not be translated.");
87+
return function () {
88+
throw new Error("The function '" + functionName + "' could not be translated.");
89+
};
8090
};
8191

8292
JSIL.UntranslatableInstruction = function (instruction, operand) {
@@ -140,7 +150,11 @@ JSIL.InitializeType = function (type) {
140150
type.__TypeInitialized__ = true;
141151

142152
if (typeof (type._cctor) != "undefined") {
143-
type._cctor();
153+
try {
154+
type._cctor();
155+
} catch (e) {
156+
JSIL.Host.error(e, "Static initializer for type ", typeName, " threw an exception");
157+
}
144158
}
145159

146160
if (typeof (type.prototype) != "undefined")
@@ -162,7 +176,7 @@ JSIL.InitializeStructFields = function (instance, typeObject) {
162176
instance[fieldName] = new fieldType();
163177
} else {
164178
instance[fieldName] = new System.ValueType();
165-
JSIL.Host.warning("Warning: The type of field ", typeObject.__FullName__ + "." + fieldName, " is undefined.");
179+
JSIL.Host.error("Warning: The type of field ", typeObject.__FullName__ + "." + fieldName, " is undefined.");
166180
}
167181
}
168182
}

0 commit comments

Comments
 (0)