node/index.js
function createSandbox(filename, socket) {
  var self = new EventEmitter;
  var listeners = new WeakMap;
  self.addEventListener = function (type, listener) {
    if (!listeners.has(listener)) {
      var facade = function (event) {
        if (!event.canceled) listener.apply(this, arguments);
      };
      listeners.set(listener, facade);
      self.on(type, facade);
    }
  };
  self.removeEventListener = function (type, listener) {
    self.removeListener(type, listeners.get(listener));
  };
  self.__filename = filename;
  self.__dirname = path.dirname(filename);
  self.postMessage = function postMessage(data) { message(socket, data); };
  self.console = console;
  self.process = process;
  self.Buffer = Buffer;
  self.clearImmediate = clearImmediate;
  self.clearInterval = clearInterval;
  self.clearTimeout = clearTimeout;
  self.setImmediate = setImmediate;
  self.setInterval = setInterval;
  self.setTimeout = setTimeout;
  self.module = module;
  self.global = self;
  self.self = self;
  self.require = function (file) {
    switch (true) {
      case file === 'workway':
        return self.workway;
      case /^[./]/.test(file):
        file = path.resolve(self.__dirname, file);
      default:
        return require(file);
    }
  };
  return self;
}
function createSandbox(filename, socket) {
  var self = new EventEmitter;
  var listeners = new WeakMap;
  self.addEventListener = function (type, listener) {
    if (!listeners.has(listener)) {
      var facade = function (event) {
        if (!event.canceled) listener.apply(this, arguments);
      };
      listeners.set(listener, facade);
      self.on(type, facade);
    }
  };
  self.removeEventListener = function (type, listener) {
    self.removeListener(type, listeners.get(listener));
  };
  self.__filename = filename;
  self.__dirname = path.dirname(filename);
  self.postMessage = function postMessage(data) { message(socket, data); };
  self.console = console;
  self.process = process;
  self.Buffer = Buffer;
  self.clearImmediate = clearImmediate;
  self.clearInterval = clearInterval;
  self.clearTimeout = clearTimeout;
  self.setImmediate = setImmediate;
  self.setInterval = setInterval;
  self.setTimeout = setTimeout;
  self.module = module;
  self.global = self;
  self.self = self;
  self.require = function (file) {
    switch (true) {
      case file === 'workway':
        return self.workway;
      case /^[./]/.test(file):
        file = path.resolve(self.__dirname, file);
      default:
        return require(file);
    }
  };
  return self;
}
function createSandbox ( filename , socket ) { var self = new EventEmitter ; var listeners = new WeakMap ; self . addEventListener = function ( type , listener ) { if ( ! listeners . has ( listener ) ) { var facade = function ( event ) { if ( ! event . canceled ) listener . apply ( this , arguments ) ; } ; listeners . set ( listener , facade ) ; self . on ( type , facade ) ; } } ; self . removeEventListener = function ( type , listener ) { self . removeListener ( type , listeners . get ( listener ) ) ; } ; self . __filename = filename ; self . __dirname = path . dirname ( filename ) ; self . postMessage = function postMessage ( data ) { message ( socket , data ) ; } ; self . console = console ; self . process = process ; self . Buffer = Buffer ; self . clearImmediate = clearImmediate ; self . clearInterval = clearInterval ; self . clearTimeout = clearTimeout ; self . setImmediate = setImmediate ; self . setInterval = setInterval ; self . setTimeout = setTimeout ; self . module = module ; self . global = self ; self . self = self ; self . require = function ( file ) { switch ( true ) { case file === 'workway' : return self . workway ; case / ^[./] / . test ( file ) : file = path . resolve ( self . __dirname , file ) ; default : return require ( file ) ; } } ; return self ; }
return a new Worker sandbox
return a new Worker sandbox