Skip to content

Commit 4f46c47

Browse files
committed
node.fs.File was not passing args to promise callbacks.
Reported by Jacob Rus.
1 parent 9d3ed1b commit 4f46c47

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/file.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ node.fs.File = function (options) {
8989

9090
if (!promise) throw "actionQueue empty when it shouldn't be.";
9191

92-
promise.emitSuccess(arguments);
92+
var args = [];
93+
for (var i = 0; i < arguments.length; i++) {
94+
args.push(arguments[i]);
95+
}
96+
97+
promise.emitSuccess(args);
9398

9499
actionQueue.shift();
95100
act();
@@ -100,8 +105,13 @@ node.fs.File = function (options) {
100105

101106
if (!promise) throw "actionQueue empty when it shouldn't be.";
102107

103-
promise.emitError(arguments);
104-
self.emitError(arguments);
108+
var args = [];
109+
for (var i = 0; i < arguments.length; i++) {
110+
args.push(arguments[i]);
111+
}
112+
113+
promise.emitError(args);
114+
self.emitError(args);
105115
}
106116

107117
var internal_methods = {
@@ -154,7 +164,9 @@ node.fs.File = function (options) {
154164
read: function (length, position) {
155165
//node.debug("encoding: " + self.encoding);
156166
var promise = node.fs.read(self.fd, length, position, self.encoding);
157-
promise.addCallback(success);
167+
promise.addCallback(function (chunk) {
168+
success(chunk);
169+
});
158170
promise.addErrback(error);
159171
},
160172

test/mjsunit/test-fs-file-read.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include("mjsunit.js");
2+
3+
var dirname = node.path.dirname(__filename);
4+
var fixtures = node.path.join(dirname, "fixtures");
5+
var x = node.path.join(fixtures, "x.txt");
6+
7+
var contents = "";
8+
9+
var f = new node.fs.File({ encoding: "utf8" });
10+
f.open(x, "r+");
11+
f.read(10000).addCallback(function (chunk) {
12+
contents = chunk;
13+
puts("got chunk: " + JSON.stringify(chunk));
14+
});
15+
f.close();
16+
17+
18+
function onExit () {
19+
assertEquals("xyz\n", contents);
20+
}

0 commit comments

Comments
 (0)