]> khamidou — GitHub mirrors - electron.git/commitdiff
Evaluate the "fs.js" in original-fs
authorCheng Zhao <zcbenz@gmail.com>
Mon, 19 Jan 2015 22:22:32 +0000 (14:22 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 19 Jan 2015 22:22:32 +0000 (14:22 -0800)
Some high-level APIs in fs are using low-level APIs via "fs.xxx", which
will be overriden by our asar wrappers, so just shadow-copy those
methods is not enough.

By evaluating the whole "fs.js" we can make sure original-fs is not
polluted by the asar wrappers.

Fixes #782.

atom/common/api/lib/original-fs.coffee

index 5aefb357402d768c967f4cd88f1f16aeb40ff450..3868168343fc22a1a5d92d4cd096b7e0267c1024 100644 (file)
@@ -1,6 +1,8 @@
-fs = require 'fs'
+vm = require 'vm'
 
-copied = {}
-copied[k] = v for k, v of fs
-
-module.exports = copied
+# Execute the 'fs.js' and pass the 'exports' to it.
+source = '(function (exports, require, module, __filename, __dirname) { ' +
+         process.binding('natives').fs +
+         '\n});'
+fn = vm.runInThisContext source, { filename: 'fs.js' }
+fn exports, require, module