| Index: test/_common.js |
| =================================================================== |
| --- a/test/_common.js |
| +++ b/test/_common.js |
| @@ -22,19 +22,22 @@ let path = require("path"); |
| let SandboxedModule = require("sandboxed-module"); |
| let globals = { |
| atob: data => new Buffer(data, "base64").toString("binary"), |
| btoa: data => new Buffer(data, "binary").toString("base64"), |
| Ci: { |
| }, |
| Cu: { |
| - import: () => |
| - { |
| - } |
| + import: () => {}, |
| + reportError: e => undefined |
| + }, |
| + console: { |
| + log: () => undefined, |
| + error: () => undefined, |
| }, |
| navigator: { |
| }, |
| onShutdown: { |
| add: () => |
| { |
| } |
| }, |
| @@ -82,23 +85,26 @@ function rewriteRequires(source) |
| return source.replace(/(\brequire\(["'])([^"']+)/g, (match, prefix, request) => |
| { |
| if (request in knownModules) |
| return prefix + escapeString(knownModules[request]); |
| return match; |
| }); |
| } |
| -exports.createSandbox = function(extraExports) |
| +exports.createSandbox = function(options) |
| { |
| + if (!options) |
| + options = {}; |
| + |
| let sourceTransformers = [rewriteRequires]; |
| - if (extraExports) |
| - sourceTransformers.push(addExports(extraExports)); |
| + if (options.extraExports) |
| + sourceTransformers.push(addExports(options.extraExports)); |
| // This module loads itself into a sandbox, keeping track of the require |
| // function which can be used to load further modules into the sandbox. |
| return SandboxedModule.require("./_common", { |
| - globals: globals, |
| + globals: Object.assign({}, globals, options.globals), |
| sourceTransformers: sourceTransformers |
| }).require; |
| }; |
| exports.require = require; |