Sha256: c5eebd3f168b5e40814b2c3851584aebeba980da1a97a01f77d122186e469ff6

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

// ==========================================================================
// Project:   Spade - CommonJS Runtime
// Copyright: ©2010 Strobe Inc. All rights reserved.
// License:   Licened under MIT license (see __preamble__.js)
// ==========================================================================
/*globals process */

var spade = require('../spade'),
    VM    = require('vm');

var OriginalSandbox = spade.Sandbox;
var Sandbox = function() {
  OriginalSandbox.apply(this, arguments);
  this.ctx = VM.createContext({
    setTimeout: setTimeout,
    setInterval: setInterval,
    clearInterval: clearInterval,
    console: console,
    navigator: {
      appName: 'node',
      appVersion: process.version,
      platform: process.platform,
      userAgent: 'node '+process.version
    }
  });
  this.ctx.window = this.ctx;
};

Sandbox.prototype = Object.create(OriginalSandbox.prototype);
Sandbox.prototype.compile = function(code, filename) {
  return VM.runInContext(code, this.ctx, filename || '(unknown)');
};

Sandbox.prototype.globals = function() {
  var output = {};
  for (var name in this.ctx){
    if (this.ctx.hasOwnProperty(name)) {
      output[name] = this.ctx[name];
    }
  }
  return output;
};

exports.Sandbox = Sandbox;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spade-0.0.8.1 lib/node/sandbox.js
spade-0.0.7 lib/node/sandbox.js