Browse Source

Avoid re-evaluating internal modules

Cheng Zhao 9 years ago
parent
commit
e5886dda9b
1 changed files with 7 additions and 1 deletions
  1. 7 1
      lib/common/asar_init.js

+ 7 - 1
lib/common/asar_init.js

@@ -9,6 +9,12 @@
     // Make graceful-fs work with asar.
     var source = process.binding('natives');
     source['original-fs'] = source.fs;
-    return source['fs'] = "var src = '(function (exports, require, module, __filename, __dirname) { ' +\n          process.binding('natives')['original-fs'] +\n          ' });';\nvar vm = require('vm');\nvar fn = vm.runInThisContext(src, { filename: 'fs.js' });\nfn(exports, require, module);\nvar asar = require('ATOM_SHELL_ASAR');\nasar.wrapFsWithAsar(exports);";
+    return source['fs'] = `
+var nativeModule = new process.NativeModule('original-fs');
+nativeModule.cache();
+nativeModule.compile();
+var asar = require('ATOM_SHELL_ASAR');
+asar.wrapFsWithAsar(nativeModule.exports);
+module.exports = nativeModule.exports`;
   };
 })();