Skip to content

Commit 1bf13d3

Browse files
fix fs module process.binding hackery
Fix the horrible atrocity introduced in 08471b2. Previously it would evaluate the code directly through process.binding(), and it now creates a new Object with the prototype being the real fs module, exported by core. Ref: nodejs/node#2026
1 parent 460834a commit 1bf13d3

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

fs.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
// eeeeeevvvvviiiiiiillllll
2-
// more evil than monkey-patching the native builtin?
3-
// Not sure.
4-
5-
var mod = require("module")
6-
var pre = '(function (exports, require, module, __filename, __dirname) { '
7-
var post = '});'
8-
var src = pre + process.binding('natives').fs + post
9-
var vm = require('vm')
10-
var fn = vm.runInThisContext(src)
11-
fn(exports, require, module, __filename, __dirname)
1+
module.exports = Object.create(require('fs'))

graceful-fs.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Monkey-patching the fs module.
2-
// It's ugly, but there is simply no other way to do this.
31
var fs = module.exports = require('./fs.js')
42

53
var assert = require('assert')

test/module-evil-hackery.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var test = require('tap').test
2+
var realfs = require('fs')
3+
var fs = require('../')
4+
5+
test('module assignment should not leak', function (t) {
6+
t.plan(1)
7+
8+
fs.abc = 3
9+
t.equal(realfs.abc, undefined)
10+
})

0 commit comments

Comments
 (0)