Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81143 views
1
var binding = require('bindings')('contextify');
2
var ContextifyContext = binding.ContextifyContext;
3
var ContextifyScript = binding.ContextifyScript;
4
5
function Contextify (sandbox) {
6
if (typeof sandbox != 'object') {
7
sandbox = {};
8
}
9
var ctx = new ContextifyContext(sandbox);
10
11
sandbox.run = function () {
12
return ctx.run.apply(ctx, arguments);
13
};
14
15
sandbox.getGlobal = function () {
16
return ctx.getGlobal();
17
}
18
19
sandbox.dispose = function () {
20
sandbox.run = function () {
21
throw new Error("Called run() after dispose().");
22
};
23
sandbox.getGlobal = function () {
24
throw new Error("Called getGlobal() after dispose().");
25
};
26
sandbox.dispose = function () {
27
throw new Error("Called dispose() after dispose().");
28
};
29
ctx = null;
30
}
31
return sandbox;
32
}
33
34
Contextify.createContext = function (sandbox) {
35
if (typeof sandbox != 'object') {
36
sandbox = {};
37
}
38
return new ContextifyContext(sandbox);
39
};
40
41
Contextify.createScript = function (code, filename) {
42
if (typeof code != 'string') {
43
throw new TypeError('Code argument is required');
44
}
45
return new ContextifyScript(code, filename);
46
};
47
48
module.exports = Contextify;
49
50