Skip to content

Commit

Permalink
fix fs module process.binding hackery
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brendanashworth committed Jun 21, 2015
1 parent 460834a commit 1bf13d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 1 addition & 11 deletions fs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
// eeeeeevvvvviiiiiiillllll
// more evil than monkey-patching the native builtin?
// Not sure.

var mod = require("module")
var pre = '(function (exports, require, module, __filename, __dirname) { '
var post = '});'
var src = pre + process.binding('natives').fs + post
var vm = require('vm')
var fn = vm.runInThisContext(src)
fn(exports, require, module, __filename, __dirname)
module.exports = Object.create(require('fs'))
2 changes: 0 additions & 2 deletions graceful-fs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Monkey-patching the fs module.
// It's ugly, but there is simply no other way to do this.
var fs = module.exports = require('./fs.js')

var assert = require('assert')
Expand Down
10 changes: 10 additions & 0 deletions test/module-evil-hackery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var test = require('tap').test
var realfs = require('fs')
var fs = require('../')

test('module assignment should not leak', function (t) {
t.plan(1)

fs.abc = 3
t.equal(realfs.abc, undefined)
})

0 comments on commit 1bf13d3

Please sign in to comment.