-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontract.html
351 lines (317 loc) · 11.1 KB
/
contract.html
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE HTML>
<!--
- Copyright (C) 2011 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<html>
<head>
<title>Testing SES</title>
<style type="text/css">
.log { color: black; }
.info { color: navy; }
.warn { color: olive; }
.error { color: maroon; }
.reports-text p { margin-top: 0.05em; margin-bottom: 0.05em; }
.console-text p { margin-top: 0.05em; margin-bottom: 0.05em; }
</style>
</head>
<body>
<div id="reports" class="reports-text"><b>Repair Reports</b></div>
<div id="console" class="console-text"><hr></div>
<div id="exprTest">exprTest...</div>
<div id="moduleTest">moduleTest...</div>
<div id="scriptTest">scriptTest...</div>
<div id="amdLoaderTest">AMD loader test...</div>
<div id="contractTest">contract test...</div>
<!-- for communication with automated test driver -->
<div id="testSignals" class="testcontainer"></div>
<script src="useHTMLLogger.js"></script>
<script>
function gebi(id) {
return document.getElementById(id);
};
useHTMLLogger(gebi("reports"), gebi("console"));
// This severity is too high for any use other than development.
ses.maxAcceptableSeverityName = 'NEW_SYMPTOM';
</script>
<!--
The <script src=... tags below, from "logger.js" to "hookupSESPlus.js", is
equivalent to <script src="initSESPlus.js"></script>, but is more
pleasant to debug.
The <script src="useHTMLLogger.js"> and the inline script above advises
the scripts below, overriding the default logger, and overriding the
default maxAcceptableSeverityName.
-->
<script src="logger.js"></script>
<script src="repair-framework.js"></script>
<script src="repairES5.js"></script>
<script src="debug.js"></script>
<script src="whitelist.js"></script>
<script src="atLeastFreeVarNames.js"></script>
<script src="startSES.js"></script>
<script src="ejectorsGuardsTrademarks.js"></script>
<script src="hookupSESPlus.js"></script>
<script>
var testSignals = gebi('testSignals');
var testExpected = 4;
var testPasses = 0;
testSignals.className += ' readytotest';
function testDone() {
"use strict";
if (testPasses === testExpected) {
document.title += ' - all tests passed';
}
testSignals.className += ' done';
}
</script>
<script>
var amdLoaderTest = gebi('amdLoaderTest');
var contractTest = gebi('contractTest');
function appendResult(node, text) {
"use strict";
if (/^succeeded/.test(text)) { testPasses += 1; }
node.appendChild(document.createTextNode(text));
}
(function() {
"use strict";
var exprTest = gebi('exprTest');
var moduleTest = gebi('moduleTest');
var scriptTest = gebi('scriptTest');
if (!ses.ok()) {
appendResult(exprTest, 'cancelled');
appendResult(moduleTest, 'cancelled');
appendResult(scriptTest, 'cancelled');
appendResult(amdLoaderTest, 'cancelled');
appendResult(contractTest, 'cancelled');
testDone();
return;
}
var imports = cajaVM.makeImports();
cajaVM.copyToImports(imports, {window: 6});
// NOTE: do not cajaVM.def(imports) for this test, since the test
// itself may modify some of the state reachable from imports that
// def would freeze.
var output = cajaVM.eval('3+4') * cajaVM.compileExpr('window')(imports);
var text1 = output === 42 ? 'succeeded' : 'failed: ' + output;
appendResult(exprTest, text1);
// Test ability to bootstrap support for a limited form of
// CommonJS modules.
var modSrc = '"use noise"; exports.x = \n' +
'require("foo.bar/baz"); return 77;';
var modMaker = cajaVM.compileModule(modSrc);
var required = modMaker.requirements;
var exported = {};
cajaVM.copyToImports(imports, {
require: function(id) { return { foo: 88, id: id}; },
exports: exported
});
// NOTE: do not cajaVM.def(imports) for this test. See above
var returned = modMaker(imports);
var did = JSON.stringify(cajaVM.def({
required: required,
exported: exported,
returned: returned
}), void 0, ' ');
var should = JSON.stringify({
"required": [ "foo.bar/baz" ],
"exported": { "x": { "foo": 88, "id": "foo.bar/baz" } },
"returned": 77
}, void 0, ' ');
var text2 = did === should ? 'succeeded' : 'failed: ' + did;
appendResult(moduleTest, text2);
// Tests the ability to do inter-module linkage as scripts
// traditionally did, by modification of (virtual) shared
// globals. Unfortunately, rather than say "var x = 88;" below, we
// must say "this.x = 88;" in order to export a global.
cajaVM.compileModule('this.x = 88;')(imports);
var text3 = cajaVM.compileExpr('x')(imports) === 88 ?
'succeeded' : 'failed';
appendResult(scriptTest, text3);
})();
</script>
<script src="makeQ.js"></script>
<script>
var Q;
(function() {
"use strict";
if (!ses.ok()) { return; }
/* TODO(erights): Extract the reusable boilerplate below into a
reusable abstraction. */
function mySetTimeout(func, millis) {
return setTimeout(function() {
try {
func();
} catch (reason) {
ses.logger.log('uncaught: ', reason);
throw reason;
}
}, millis);
}
Q = ses.makeQ(mySetTimeout);
})();
</script>
<script src="compileExprLater.js"></script>
<script>
(function() {
"use strict";
if (!ses.ok()) { return; }
var evalOnlySrc =
'function evalOnly(str) {\n' +
' debugger;\n' +
' throw Error(str);\n' +
'}\n';
var fakeUrlSrc =
'function fakeUrl(g) {\n' +
' g("Expand me to see stack");\n' +
'}\n';
var nestedSrc =
'cajaVM.confine(\n' +
' "function nested(f) {\\n" + \n' +
' " f(evalOnly);\\n" + \n' +
' "}\\n", {evalOnly: evalOnly})';
var exprSrc =
'(function dataUrl(){\n' +
' nested(fakeUrl);\n' +
'}())';
syncEval: {
var cevalOnly = cajaVM.confine(evalOnlySrc);
var cfakeUrl = cajaVM.confine(fakeUrlSrc, void 0, {
sourceUrl: 'http://example.com/fake1.js'
});
var cnested = cajaVM.confine(nestedSrc, {evalOnly: cevalOnly});
try {
cajaVM.confine(exprSrc, {fakeUrl: cfakeUrl, nested: cnested}, {
sourceUrl: 'data:,' + encodeURIComponent(exprSrc)
});
} catch (err) {
// The ses.logger installed by useHTMLLogger.js uses ses.getStack
// to display the stack, if any, associated with the err argument.
ses.logger.info('Expected error to test ses.getStack API: ', err);
break syncEval;
}
ses.logger.error('Missing expected error');
}
var eevalOnlyP = ses.confineLater(evalOnlySrc);
var efakeUrlP = ses.confineLater(fakeUrlSrc, void 0, {
sourceUrl: 'http://example.com/fake2.js'
});
var enestedP = Q(eevalOnlyP).then(function(eevalOnly) {
return ses.confineLater(nestedSrc, {evalOnly: eevalOnly});
});
var doneP = Q.all([efakeUrlP, enestedP]).then(function(efooPair) {
var efakeUrl = efooPair[0];
var enested = efooPair[1];
return ses.confineLater(exprSrc, {
fakeUrl: efakeUrl,
nested: enested
}, {
sourceUrl: 'data:,' + encodeURIComponent(exprSrc)
});
});
// TODO(erights): Should be 'done' once makeQ supports it.
Q(doneP).then(function(val) {
ses.logger.error('Missing expected error: ', val);
}, function(reason) {
// The ses.logger installed by useHTMLLogger.js uses ses.getStack
// to display the stack, if any, associated with the err argument.
ses.logger.info('Testing ses.getStack with compileExprLater: ', reason);
});
}());
</script>
<script src="makeFarResourceMaker.js"></script>
<script>
(function() {
"use strict";
if (!ses.ok()) { return; }
var makeTextResource = ses.makeFarResourceMaker();
var url = './makeSimpleAMDLoader.js';
var makeSimpleAMDLoaderFileP = makeTextResource(url);
var makeSimpleAMDLoaderSrcP = makeSimpleAMDLoaderFileP.get();
/* We really are evaluating makeSimpleAMDModuleLoader with least
authority. Even though there's a global compileExprLater, if
you don't provide it here, makeSimpleAMDModuleLoader will
fail. */
var imports = cajaVM.makeImports();
cajaVM.copyToImports(imports, {
Q: Q,
compileExprLater: ses.compileExprLater,
confineLater: ses.confineLater
});
// NOTE: Unlike confineLater, do not cajaVM.def(imports) for
// evaluating the simple AMD loader.
var makeSimpleAMDLoaderP = Q(makeSimpleAMDLoaderSrcP).then(function(src) {
var exprSrc = '(function() {' + src + '}).call(this)';
var compiledExprP = ses.compileExprLater(exprSrc, {
sourceUrl: url
});
return Q(compiledExprP).then(function(compiledExpr) {
compiledExpr(imports);
return imports.makeSimpleAMDLoader;
});
});
/**
* What we should do is accept any legal module identifier according
* to the AMD definition and encode it into a legal URL. Instead,
* for now, we just conservatively accept an ascii subset of both
* that does not need any encoding.
*
* See https://github.com/amdjs/amdjs-api/wiki/AMD#wiki-define-id-notes
*/
var isModuleId = Object.freeze(/^[a-zA-Z0-9_/]*$/);
function fetch(id) {
if (!isModuleId.test(id)) {
throw new Error('illegal module id: ' + id);
}
return makeTextResource('./' + id + '.js').get();
}
var moduleMap = new Map();
moduleMap.set('Q', Q);
var loaderP = Q(makeSimpleAMDLoaderP).send(void 0, fetch, moduleMap);
var amdTestP = Q(loaderP).send(void 0, 'amdTest');
Q(amdTestP).then(function(amdTest) {
var amdTestStatus = amdTest === 'this is a test' ?
'succeeded' : 'failed, unexpected: ' + amdTest;
appendResult(amdLoaderTest, amdTestStatus);
testDone();
}, function(reason) {
appendResult(amdLoaderTest, 'failed: ' + reason);
testDone();
}).end();
var cTestP = Q(loaderP).send(void 0, 'contractTest');
Q(cTestP).then(function(cTest) {
if (cTest === 10) {
appendResult(contractTest, 'succeeded');
} else {
appendResult(contractTest, 'unexpected: ', cTest);
}
}, function(reason) {
appendResult(contractTest, 'failed: ' + reason);
}).end();
}());
</script>
<p>
Using <span id="browserName">unknown</span>
<span id="browserVersion">unknown</span>
on <span id="browserOS">unknown</span>
<script src="detect.js"></script>
<script>
(function(){
"use strict";
gebi('browserName').textContent = BrowserDetect.browser;
gebi('browserVersion').textContent = BrowserDetect.version;
gebi('browserOS').textContent = BrowserDetect.OS;
})();
</script>
</body>
</html>