Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix horrible process.binding() atrocity #44

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
12 changes: 12 additions & 0 deletions test/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = require('tap').test
var fs = require('fs')
var gfs = require('../graceful-fs.js')

test('graceful fs uses same stats constructor as fs', function (t) {
t.equal(gfs.Stats, fs.Stats, 'should reference the same constructor')
t.ok(fs.statSync(__filename) instanceof fs.Stats,
'should be instance of fs.Stats')
t.ok(gfs.statSync(__filename) instanceof fs.Stats,
'should be instance of fs.Stats')
t.end()
})