Skip to content

Commit 8789fc5

Browse files
Robert Jacksonkrisselden
andcommitted
Remove ability to provide custom sandbox class.
Co-authored-by: Kris Selden <[email protected]>
1 parent 97aad84 commit 8789fc5

4 files changed

Lines changed: 8 additions & 68 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ let app = new FastBoot({
2828
distPath: 'path/to/dist',
2929
// optional boolean flag when set to true does not reject the promise if there are rendering errors (defaults to false)
3030
resilient: <boolean>,
31-
sandbox: 'path/to/sandbox/class', // optional sandbox class (defaults to vm-sandbox)
3231
sandboxGlobals: {...} // optional map of key value pairs to expose in the sandbox
3332
});
3433

src/ember-app.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const SimpleDOM = require('simple-dom');
99
const resolve = require('resolve');
1010
const debug = require('debug')('fastboot:ember-app');
1111

12+
const Sandbox = require('./sandbox');
1213
const FastBootInfo = require('./fastboot-info');
1314
const Result = require('./result');
1415
const FastBootSchemaVersions = require('./fastboot-schema-versions');
@@ -27,12 +28,10 @@ class EmberApp {
2728
* Create a new EmberApp.
2829
* @param {Object} options
2930
* @param {string} options.distPath - path to the built Ember application
30-
* @param {Sandbox} [options.sandbox=VMSandbox] - sandbox to use
3131
* @param {Object} [options.sandboxGlobals] - sandbox variables that can be added or used for overrides in the sandbox.
3232
*/
3333
constructor(options) {
3434
// TODO: make these two into builder functions
35-
this.SandboxClass = options.sandbox;
3635
this.sandboxGlobals = options.sandboxGlobals;
3736

3837
let distPath = (this.distPath = path.resolve(options.distPath));
@@ -70,7 +69,7 @@ class EmberApp {
7069
* Builds and initializes a new sandbox to run the Ember application in.
7170
*/
7271
buildSandbox() {
73-
const { distPath, SandboxClass, sandboxGlobals, config, appName, sandboxRequire } = this;
72+
const { distPath, sandboxGlobals, config, appName, sandboxRequire } = this;
7473

7574
function fastbootConfig(key) {
7675
if (!key) {
@@ -101,7 +100,7 @@ class EmberApp {
101100
sandboxGlobals
102101
);
103102

104-
return new SandboxClass(globals);
103+
return new Sandbox(globals);
105104
}
106105

107106
/**

src/index.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ const EmberApp = require('./ember-app');
1313
* are run inside a sandbox that prohibits them from accessing the normal
1414
* Node.js environment.
1515
*
16-
* By default, this sandbox is the built-in `VMSandbox` class, which uses
17-
* Node's `vm` module. You may provide your own sandbox implementation by
18-
* passing the `sandbox` option or add and/or override sandbox variables by
16+
* This sandbox is the built-in `VMSandbox` class, which uses
17+
* Node's `vm` module. You may add and/or override sandbox variables by
1918
* passing the `addOrOverrideSandboxGlobals` option.
2019
*
2120
* @example
2221
* const FastBoot = require('fastboot');
2322
*
2423
* let app = new FastBoot({
2524
* distPath: 'path/to/dist',
26-
* sandbox: 'path/to/sandboxClass',
2725
* sandboxGlobals: {...}
2826
* });
2927
*
@@ -38,19 +36,17 @@ class FastBoot {
3836
* @param {Object} options
3937
* @param {string} options.distPath the path to the built Ember application
4038
* @param {Boolean} [options.resilient=false] if true, errors during rendering won't reject the `visit()` promise but instead resolve to a {@link Result}
41-
* @param {Sandbox} [options.sandbox=VMSandbox] the sandbox to use
4239
* @param {Object} [options.sandboxGlobals={}] any additional sandbox variables that an app server wants to override and/or add in the sandbox
4340
*/
4441
constructor(options = {}) {
45-
let { distPath, sandbox, sandboxGlobals } = options;
42+
let { distPath, sandboxGlobals } = options;
4643

4744
this.resilient = 'resilient' in options ? Boolean(options.resilient) : false;
4845

4946
this.distPath = distPath;
50-
this.sandbox = sandbox || require('./sandbox');
5147
this.sandboxGlobals = sandboxGlobals || {};
5248

53-
this._buildEmberApp(this.distPath, this.sandbox, this.sandboxGlobals);
49+
this._buildEmberApp(this.distPath, this.sandboxGlobals);
5450
}
5551

5652
/**
@@ -96,11 +92,7 @@ class FastBoot {
9692
this._buildEmberApp(distPath);
9793
}
9894

99-
_buildEmberApp(
100-
distPath = this.distPath,
101-
sandbox = this.sandbox,
102-
sandboxGlobals = this.sandboxGlobals
103-
) {
95+
_buildEmberApp(distPath = this.distPath, sandboxGlobals = this.sandboxGlobals) {
10496
if (!distPath) {
10597
throw new Error(
10698
'You must instantiate FastBoot with a distPath ' +
@@ -117,7 +109,6 @@ class FastBoot {
117109

118110
this._app = new EmberApp({
119111
distPath,
120-
sandbox,
121112
sandboxGlobals,
122113
});
123114
}

test/fastboot-test.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const fs = require('fs');
55
const path = require('path');
66
const fixture = require('./helpers/fixture-path');
77
const FastBoot = require('./../src/index');
8-
const CustomSandbox = require('./fixtures/custom-sandbox/custom-sandbox');
98

109
describe('FastBoot', function() {
1110
it('throws an exception if no distPath is provided', function() {
@@ -166,25 +165,6 @@ describe('FastBoot', function() {
166165
});
167166
});
168167

169-
it('can render HTML when sandbox class is provided', function() {
170-
var fastboot = new FastBoot({
171-
distPath: fixture('custom-sandbox'),
172-
sandboxClass: CustomSandbox,
173-
sandboxGlobals: {
174-
myVar: 2,
175-
foo: 'undefined',
176-
najax: 'undefined',
177-
},
178-
});
179-
180-
return fastboot
181-
.visit('/foo')
182-
.then(r => r.html())
183-
.then(html => {
184-
expect(html).to.match(/myVar in sandbox: 2/);
185-
});
186-
});
187-
188168
it('rejects the promise if an error occurs', function() {
189169
var fastboot = new FastBoot({
190170
distPath: fixture('rejected-promise'),
@@ -282,35 +262,6 @@ describe('FastBoot', function() {
282262
}
283263
});
284264

285-
it('can reload the app using the same sandbox class', function() {
286-
var fastboot = new FastBoot({
287-
distPath: fixture('basic-app'),
288-
sandbox: CustomSandbox,
289-
sandboxGlobals: {
290-
myVar: 2,
291-
foo: 'undefined',
292-
najax: 'undefined',
293-
},
294-
});
295-
296-
return fastboot
297-
.visit('/')
298-
.then(r => r.html())
299-
.then(html => expect(html).to.match(/Welcome to Ember/))
300-
.then(hotReloadApp)
301-
.then(() => fastboot.visit('/foo'))
302-
.then(r => r.html())
303-
.then(html => {
304-
expect(html).to.match(/myVar in sandbox: 2/);
305-
});
306-
307-
function hotReloadApp() {
308-
fastboot.reload({
309-
distPath: fixture('custom-sandbox'),
310-
});
311-
}
312-
});
313-
314265
it('reads the config from package.json', function() {
315266
var fastboot = new FastBoot({
316267
distPath: fixture('config-app'),

0 commit comments

Comments
 (0)