[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/externals/javelin/core/ -> init_node.js (source)

   1  /**
   2   * Alternative Javelin init file for Node.js.
   3   *
   4   * @javelin-installs JX.enableDispatch
   5   * @javelin-installs JX.onload
   6   * @javelin-installs JX.flushHoldingQueue
   7   * @javelin-installs JX.require
   8   *
   9   * @javelin
  10   */
  11  
  12  var JX = {};
  13  var fs = require('fs');
  14  var vm = require('vm');
  15  var pathModule = require('path');
  16  
  17  var noop = function() {};
  18  
  19  JX.enableDispatch = noop;
  20  JX.flushHoldingQueue = noop;
  21  
  22  JX.onload = function(func) {
  23    func();
  24  };
  25  
  26  JX.require = function(thing, relative) {
  27    relative = relative || __dirname + '/..';
  28    var path = relative + '/' + thing + '.js';
  29    var content = fs.readFileSync(path);
  30    var dir = pathModule.dirname(path);
  31  
  32    var k;
  33    var sandbox = {};
  34  
  35    for (k in global) {
  36      sandbox[k] = global[k];
  37    }
  38  
  39    var extra = {
  40      JX : this,
  41      __DEV__ : 0,
  42      window : {},
  43      __dirname : dir,
  44      require : function(thing) {
  45        if (thing == 'javelin') {
  46          return require(dir + '/' + thing);
  47        } else {
  48          return require(thing);
  49        }
  50      }
  51    };
  52  
  53    for (k in extra) {
  54      sandbox[k] = extra[k];
  55    }
  56  
  57    vm.createScript(content, path)
  58      .runInNewContext(sandbox, path);
  59  };
  60  
  61  exports.JX = JX;


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1