-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextjs-vm.js
More file actions
127 lines (100 loc) · 2.13 KB
/
extjs-vm.js
File metadata and controls
127 lines (100 loc) · 2.13 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
/**
* ExtJS Virtual Machine
* Creates a node VM running ExtJS. For now, we're just loading the full ExtJS (hence the additional setup code below)
* copyright (c) 2014 Chris Moser (cpmoser@network54.com)
*/
var
emptyFn = function () {},
cfg =
{
setInterval: setInterval,
clearInterval: clearInterval,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
/**
* note: we may want to remove this
*/
require: require,
console: console,
ActiveXObject: emptyFn,
addEventListener: emptyFn,
removeEventListener: emptyFn,
navigator:
{
userAgent: ""
},
document:
{
addEventListener: emptyFn,
removeEventListener: emptyFn,
documentElement:
{
style:
{
boxShadow: undefined
}
},
getElementsByTagName: function (tagName)
{
return [
{
src: "io"
}
];
},
createElement: function ()
{
return {};
}
},
location:
{
protocol: "http:"
}
},
//extJsPath = "/Users/cpmoser/Sites/Embarc/Application/webroot/ext-4.2.0.663/",
// extJsPath = "/Users/cpmoser/ext-4.2.1.883/",
// extJsPath = "/www-local/web/desktop/ihr/client/node/observable.io/ext-4.2.0.663/",
extJsPath = "./ext-4.2.1.883/",
fs = require("fs"),
vm = require("vm");
cfg.ActiveXObject.prototype =
{
getElementsByTagName: function ()
{
return [];
},
loadXML: function ()
{
// console.log("ActiveXObject: loadXML");
}
};
cfg.window = cfg;
var
context = vm.createContext(cfg),
extJsFile = "ext-all-debug.js", // use ext.js to use dynamic loader
code = fs.readFileSync(extJsPath + extJsFile);
extJsFile = "src/Ext.js";
vm.runInContext(code, context, extJsFile);
var
Ext = context.Ext,
util = require("util");
Ext.Loader.setPath("Ext", extJsPath + "src");
context.Ext.Loader.loadScriptFile = function (url, onLoad, onError, scope, synchronous)
{
util.log("Ext.Loader " + url);
var code = fs.readFileSync(url);
// better way may be this --
try
{
vm.runInContext(code, context, url);
}
catch (e)
{
console.log(e.stack);
throw e;
}
onLoad.call(scope);
};
context.Ext.process = process;
module.exports = context.Ext;