|
| 1 | +'use strict'; |
| 2 | + |
1 | 3 | var chalk = require('chalk'); |
2 | 4 |
|
3 | | -function Sandbox() { |
4 | | -} |
| 5 | +class Sandbox { |
5 | 6 |
|
6 | | -Sandbox.prototype.init = function(options) { |
7 | | - this.globals = options.globals; |
8 | | - this.sandbox = this.buildSandbox(); |
9 | | -}; |
10 | | - |
11 | | -Sandbox.prototype.buildSandbox = function() { |
12 | | - var console = this.buildWrappedConsole(); |
13 | | - var sourceMapSupport = require('./install-source-map-support'); |
14 | | - var URL = require('url'); |
15 | | - var globals = this.globals; |
16 | | - |
17 | | - var sandbox = { |
18 | | - sourceMapSupport: sourceMapSupport, |
19 | | - console: console, |
20 | | - setTimeout: setTimeout, |
21 | | - clearTimeout: clearTimeout, |
22 | | - URL: URL, |
23 | | - |
24 | | - // Convince jQuery not to assume it's in a browser |
25 | | - module: { exports: {} } |
26 | | - }; |
27 | | - |
28 | | - for (var key in globals) { |
29 | | - sandbox[key] = globals[key]; |
| 7 | + constructor(options) { |
| 8 | + this.globals = options.globals; |
| 9 | + this.sandbox = this.buildSandbox(); |
30 | 10 | } |
31 | 11 |
|
32 | | - // Set the global as `window`. |
33 | | - sandbox.window = sandbox; |
34 | | - sandbox.window.self = sandbox; |
| 12 | + buildSandbox() { |
| 13 | + var console = this.buildWrappedConsole(); |
| 14 | + var sourceMapSupport = require('./install-source-map-support'); |
| 15 | + var URL = require('url'); |
| 16 | + var globals = this.globals; |
| 17 | + |
| 18 | + var sandbox = { |
| 19 | + sourceMapSupport: sourceMapSupport, |
| 20 | + console: console, |
| 21 | + setTimeout: setTimeout, |
| 22 | + clearTimeout: clearTimeout, |
| 23 | + URL: URL, |
35 | 24 |
|
36 | | - return sandbox; |
37 | | -}; |
| 25 | + // Convince jQuery not to assume it's in a browser |
| 26 | + module: { exports: {} } |
| 27 | + }; |
38 | 28 |
|
39 | | -Sandbox.prototype.buildWrappedConsole = function() { |
40 | | - var wrappedConsole = Object.create(console); |
41 | | - wrappedConsole.error = function() { |
42 | | - console.error.apply(console, Array.prototype.map.call(arguments, function(a) { |
43 | | - return typeof a === 'string' ? chalk.red(a) : a; |
44 | | - })); |
45 | | - }; |
| 29 | + for (var key in globals) { |
| 30 | + sandbox[key] = globals[key]; |
| 31 | + } |
46 | 32 |
|
47 | | - return wrappedConsole; |
48 | | -}; |
| 33 | + // Set the global as `window`. |
| 34 | + sandbox.window = sandbox; |
| 35 | + sandbox.window.self = sandbox; |
| 36 | + |
| 37 | + return sandbox; |
| 38 | + } |
| 39 | + |
| 40 | + buildWrappedConsole() { |
| 41 | + var wrappedConsole = Object.create(console); |
| 42 | + wrappedConsole.error = function() { |
| 43 | + console.error.apply(console, Array.prototype.map.call(arguments, function(a) { |
| 44 | + return typeof a === 'string' ? chalk.red(a) : a; |
| 45 | + })); |
| 46 | + }; |
| 47 | + |
| 48 | + return wrappedConsole; |
| 49 | + } |
| 50 | +} |
49 | 51 |
|
50 | 52 | module.exports = Sandbox; |
0 commit comments