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

Add node v5.x compatibility #69

Merged
merged 1 commit into from
Nov 29, 2015
Merged

Add node v5.x compatibility #69

merged 1 commit into from
Nov 29, 2015

Conversation

tmcw
Copy link
Contributor

@tmcw tmcw commented Nov 29, 2015

This adds node v5 compatibility to mock-fs. Fixes #67

The node/fs-5.0.0.js is the same as https://github.com/nodejs/node/blob/v5.x/lib/fs.js except:

--- v5.js   2015-11-28 20:45:32.000000000 -0500
+++ node/fs-5.0.0.js    2015-11-28 20:43:23.000000000 -0500
@@ -7,8 +7,8 @@
 const util = require('util');
 const pathModule = require('path');

-const binding = process.binding('fs');
-const constants = require('constants');
+var binding = process.binding('fs');
+const constants = process.binding('constants');
 const fs = exports;
 const Buffer = require('buffer').Buffer;
 const Stream = require('stream').Stream;
@@ -250,7 +250,7 @@
   context.isUserFd = isFd(path); // file descriptor ownership
   var req = new FSReqWrap();
   req.context = context;
-  req.oncomplete = readFileAfterOpen;
+  req.oncomplete = readFileAfterOpen.bind(req);

   if (context.isUserFd) {
     process.nextTick(function() {
@@ -295,7 +295,7 @@
   }

   var req = new FSReqWrap();
-  req.oncomplete = readFileAfterRead;
+  req.oncomplete = readFileAfterRead.bind(req);
   req.context = this;

   binding.read(this.fd, buffer, offset, length, -1, req);
@@ -303,7 +303,7 @@

 ReadFileContext.prototype.close = function(err) {
   var req = new FSReqWrap();
-  req.oncomplete = readFileAfterClose;
+  req.oncomplete = readFileAfterClose.bind(req);
   req.context = this;
   this.err = err;

@@ -328,7 +328,7 @@
   context.fd = fd;

   var req = new FSReqWrap();
-  req.oncomplete = readFileAfterStat;
+  req.oncomplete = readFileAfterStat.bind(req);
   req.context = context;
   binding.fstat(fd, req);
 }
@@ -2072,4 +2072,4 @@
   return true;
 };

@tschaub
Copy link
Owner

tschaub commented Nov 29, 2015

Awesome. Thanks @tmcw. Seeing the patch here is very useful, and I regret not including these in the repo from the start. I keep thinking I'll rework this to avoid the patching, but haven't taken the time yet.

tschaub added a commit that referenced this pull request Nov 29, 2015
Add node v5.x compatibility.
@tschaub tschaub merged commit db4b1be into tschaub:master Nov 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node v5.0.x support
2 participants