Skip to content

Commit 9a3243f

Browse files
author
Robert Jackson
committed
Make a single Sandbox base class.
This division was useful back when we had to support two different VM sandboxes (back in the Node 0.12 days 😱).
1 parent 99c6f4d commit 9a3243f

3 files changed

Lines changed: 13 additions & 26 deletions

File tree

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FastBoot {
4747
this.resilient = 'resilient' in options ? Boolean(options.resilient) : false;
4848

4949
this.distPath = distPath;
50-
this.sandbox = sandbox || require('./vm-sandbox');
50+
this.sandbox = sandbox || require('./sandbox');
5151
this.sandboxGlobals = sandboxGlobals || {};
5252

5353
this._buildEmberApp(this.distPath, this.sandbox, this.sandboxGlobals);

src/sandbox.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22

33
const chalk = require('chalk');
4+
const vm = require('vm');
45

5-
class Sandbox {
6+
module.exports = class Sandbox {
67
constructor(options = {}) {
78
this.globals = options.globals;
89
this.sandbox = this.buildSandbox();
10+
vm.createContext(this.sandbox);
911
}
1012

1113
buildSandbox() {
@@ -48,6 +50,13 @@ class Sandbox {
4850

4951
return wrappedConsole;
5052
}
51-
}
5253

53-
module.exports = Sandbox;
54+
eval(source, filePath) {
55+
var fileScript = new vm.Script(source, { filename: filePath });
56+
fileScript.runInContext(this.sandbox);
57+
}
58+
59+
run(cb) {
60+
return cb.call(this.sandbox, this.sandbox);
61+
}
62+
};

src/vm-sandbox.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)