'use strict';

var Module        = require('module')
  , wrap          = Module.wrap
  , readFile      = require('fs').readFileSync
  , dirname       = require('path').dirname
  , vm            = require('vm')
  , createContext = vm.createContext
  , runInContext  = vm.runInContext
  , errorMsg      = require('./is-module-not-found-error')

  , props = ['require', 'module', 'exports'];

module.exports = function (path, context) {
	var fmodule, r, content, dirpath;
	console.log(context === global, path);
	if (context === global) {
		return require(path);
	} else {
		dirpath = dirname(path);
		fmodule = new Module(path, module);
		fmodule.filename = path;
		fmodule.paths = Module._nodeModulePaths(dirpath);
		try {
			content = readFile(path, 'utf8');
		} catch (e) {
			throw new Error(errorMsg.pattern.replace(errorMsg.token, path));
		}
		vm.runInContext(wrap(content), context).call(fmodule.exports, fmodule.exports,
				fmodule.require.bind(fmodule), fmodule, path, dirpath);
		fmodule.loaded = true;
		return fmodule.exports;
	}
};

@@ -384,133 +384,283 @@
 ts'%5D
-;%0A%0Amodule.exports = function (path, context) %7B%0A%09var fmodule, r, content, dirpath;%0A%09console.log(context === global, path);%0A%09if
+%0A  , modRequire = Module.prototype.require %7C%7C function (path) %7B%0A%09%09return Module._load(path, this);%0A%09%7D;%0A%0Amodule.exports = function (path, context) %7B%0A%09var fmodule, r, content, dirpath;%0A%0A%09if ((context === global)%0A%09%09%7C%7C (context.process && (context.process.title === 'node')%0A%09%09%09&&
  (co
@@ -656,32 +656,36 @@
 )%0A%09%09%09&& (context
+.pid
  === global) %7B%0A%09
@@ -679,16 +679,22 @@
 = global
+.pid))
 ) %7B%0A%09%09re
@@ -867,16 +867,48 @@
 rpath);%0A
+%09%09fmodule.require = modRequire;%0A
 %09%09try %7B%0A

Use regular require, when given context is same as current context