// Generated by CoffeeScript 1.7.1
(function() {
  var Module, asar, fs, globalPaths, path, process, source, timers, wrapWithActivateUvLoop;

  process = global.process;

  fs = require('fs');

  path = require('path');

  timers = require('timers');

  Module = require('module');

  process.atomBinding = function(name) {
    var e;
    try {
      return process.binding("atom_" + process.type + "_" + name);
    } catch (_error) {
      e = _error;
      if (/No such module/.test(e.message)) {
        return process.binding("atom_common_" + name);
      }
    }
  };

  globalPaths = Module.globalPaths;

  globalPaths.push(path.join(process.resourcesPath, 'atom', 'common', 'api', 'lib'));

  wrapWithActivateUvLoop = function(func) {
    return function() {
      process.activateUvLoop();
      return func.apply(this, arguments);
    };
  };

  process.nextTick = wrapWithActivateUvLoop(process.nextTick);

  global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate);

  global.clearImmediate = timers.clearImmediate;

  if (process.type === 'browser') {
    global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout);
    global.setInterval = wrapWithActivateUvLoop(timers.setInterval);
  }

  asar = require('./asar');

  asar.wrapFsWithAsar(fs);

  source = process.binding('natives');

  source.originalFs = source.fs;

  source.fs = "var src = '(function (exports, require, module, __filename, __dirname) { ' +\n          process.binding('natives').originalFs +\n          ' });';\nvar vm = require('vm');\nvar fn = vm.runInThisContext(src, { filename: 'fs.js' });\nfn(exports, require, module);\nvar asar = require(" + (JSON.stringify(__dirname)) + " + '/asar');\nasar.wrapFsWithAsar(exports);";

}).call(this);
