-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSIL.Shell.js
More file actions
180 lines (129 loc) · 3.94 KB
/
Copy pathJSIL.Shell.js
File metadata and controls
180 lines (129 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"use strict";
JSIL.DeclareNamespace("JSIL.Shell", false);
JSIL.Shell.StdOutService = function () {
};
JSIL.Shell.StdOutService.prototype.write = function (text) {
putstr(text);
};
JSIL.Shell.StdErrService = function () {
};
JSIL.Shell.StdErrService.prototype.write = function (text) {
var trimmed = String(text).trim();
if (trimmed[trimmed.length - 1] === "\n") {
text = trimmed.substr(0, trimmed.length - 1);
}
printErr(text);
};
JSIL.Shell.RunLaterService = function () {
this.queue = [];
};
JSIL.Shell.RunLaterService.prototype.enqueue = function (callback) {
this.queue.push(callback);
};
JSIL.Shell.RunLaterService.prototype.flush = function () {
while (this.queue.length > 0) {
var count = this.queue.length;
for (var i = 0; i < count; i++) {
var item = this.queue[i];
item();
}
this.queue.splice(0, count);
}
};
(function () {
JSIL.Host.registerServices({
stdout: new JSIL.Shell.StdOutService(),
stderr: new JSIL.Shell.StdErrService(),
runLater: new JSIL.Shell.RunLaterService()
});
})();
function reportException (e) {
var stack = "";
try {
stack = e.stack || "";
} catch (ex) {
stack = "";
}
JSIL.Host.logWriteLine("// EXCEPTION:");
JSIL.Host.logWriteLine(String(e));
if (stack.length > 0) {
JSIL.Host.logWriteLine("// STACK:");
JSIL.Host.logWriteLine(stack);
}
JSIL.Host.logWriteLine("// ENDEXCEPTION");
throw e;
};
function loadAssets (assets) {
for (var i = 0, l = assets.length; i < l; i++) {
var assetSpec = assets[i];
var assetType = assetSpec[0];
var assetPath = assetSpec[1];
var assetData = assetSpec[2] || null;
var assetLoader = assetLoaders[assetType];
assetLoader(assetPath, assetData);
}
};
function shellStartup () {
initAssetLoaders();
var seenFilenames = {};
var pushAsset = function (assetSpec) {
var filename = assetSpec[1];
if (seenFilenames[filename])
return;
seenFilenames[filename] = true;
allAssetsToLoad.push(assetSpec);
}
var allAssetsToLoad = [];
if (typeof (assetsToLoad) !== "undefined") {
for (var i = 0, l = assetsToLoad.length; i < l; i++)
pushAsset(assetsToLoad[i]);
}
if (typeof (contentManifest) === "object") {
for (var k in contentManifest) {
var subManifest = contentManifest[k];
for (var i = 0, l = subManifest.length; i < l; i++)
pushAsset(subManifest[i]);
}
}
loadAssets(allAssetsToLoad);
if (typeof (runMain) === "function") {
JSIL.Initialize();
JSIL.Host.runInitCallbacks();
JSIL.Host.runLaterFlush();
runMain();
}
};
var $$ObjectToTag = null;
JSIL.Shell.TaggedObjectCount = 0;
JSIL.Shell.TagObject = function (obj, tag) {
if (typeof (evaluate) === "function") {
var index = JSIL.Shell.TaggedObjectCount++;
var objectId = "TAGGED_OBJECT_" + index;
$$ObjectToTag = obj;
var evalText = "$$ObjectToTag";
var evalResult = evaluate(evalText, {
fileName: objectId
});
$$ObjectToTag = null;
printErr("// " + objectId + "='" + tag + "'");
}
};
JSIL.Shell.TestPrologue = function (timeoutDuration, assemblyName, typeName, methodName, args, throwOnUnimplementedExternals) {
return function runTestCase (dateNow) {
JSIL.ThrowOnUnimplementedExternals = throwOnUnimplementedExternals;
timeout(timeoutDuration);
var started = dateNow();
var testAssembly = JSIL.GetAssembly(assemblyName, true);
if (!testAssembly)
throw new Error("No assembly named '" + assemblyName + "'");
var parsedTypeName = JSIL.ParseTypeName(typeName);
var testType = JSIL.GetTypeInternal(parsedTypeName, testAssembly, true);
var testTypePublicInterface = testType.__PublicInterface__;
var testMethod = testTypePublicInterface[methodName];
if (!testMethod)
throw new Error("No method named '" + methodName + "'");
testMethod.call(testTypePublicInterface, args);
var ended = dateNow();
return (ended - started);
};
};