-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathses5.js
57 lines (48 loc) · 1.24 KB
/
ses5.js
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
// Options: --free-variable-checker --require --validate
/*global module require*/
// To start SES under nodejs
// Adapted from https://gist.github.com/3669482
module.exports = (function(){
"use strict";
var FS = require("fs");
var VM = require("vm");
function fakeRequire(name) {
if (name !== 'vm') {
throw new Error(`Cannot fake module '${name}'`);
}
return {createContext: VM.createContext,
runInContext: VM.runInContext};
}
var sesFiles = [
"cheat.js", // XXX
"logger.js",
"repair-framework.js",
"repairES5.js",
"whitelist.js",
"atLeastFreeVarNames.js",
"startSES.js",
"hookupSES.js",
];
var sesPlusFiles = [
"cheat.js", // XXX
"logger.js",
"repair-framework.js",
"repairES5.js",
"debug.js",
"whitelist.js",
"atLeastFreeVarNames.js",
"startSES.js",
"ejectorsGuardsTrademarks.js",
"hookupSESPlus.js",
];
var initSESPlus = sesPlusFiles.map(function (path) {
return FS.readFileSync(path, 'utf8');
}).join('\n') + `
cajaVM;
`;
var endowments = {console: console,
require: fakeRequire};
var context = VM.createContext(endowments);
var cajaVM = VM.runInContext(initSESPlus, context);
return cajaVM;
}());