From 4f46c477734cfe9833562648c12a5c8f68404351 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 31 Jul 2009 19:48:19 +0200 Subject: [PATCH] node.fs.File was not passing args to promise callbacks. Reported by Jacob Rus. --- src/file.js | 20 ++++++++++++++++---- test/mjsunit/test-fs-file-read.js | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 test/mjsunit/test-fs-file-read.js diff --git a/src/file.js b/src/file.js index a378384670..05a8496ead 100644 --- a/src/file.js +++ b/src/file.js @@ -89,7 +89,12 @@ node.fs.File = function (options) { if (!promise) throw "actionQueue empty when it shouldn't be."; - promise.emitSuccess(arguments); + var args = []; + for (var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + + promise.emitSuccess(args); actionQueue.shift(); act(); @@ -100,8 +105,13 @@ node.fs.File = function (options) { if (!promise) throw "actionQueue empty when it shouldn't be."; - promise.emitError(arguments); - self.emitError(arguments); + var args = []; + for (var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + + promise.emitError(args); + self.emitError(args); } var internal_methods = { @@ -154,7 +164,9 @@ node.fs.File = function (options) { read: function (length, position) { //node.debug("encoding: " + self.encoding); var promise = node.fs.read(self.fd, length, position, self.encoding); - promise.addCallback(success); + promise.addCallback(function (chunk) { + success(chunk); + }); promise.addErrback(error); }, diff --git a/test/mjsunit/test-fs-file-read.js b/test/mjsunit/test-fs-file-read.js new file mode 100644 index 0000000000..55a8e2b168 --- /dev/null +++ b/test/mjsunit/test-fs-file-read.js @@ -0,0 +1,20 @@ +include("mjsunit.js"); + +var dirname = node.path.dirname(__filename); +var fixtures = node.path.join(dirname, "fixtures"); +var x = node.path.join(fixtures, "x.txt"); + +var contents = ""; + +var f = new node.fs.File({ encoding: "utf8" }); +f.open(x, "r+"); +f.read(10000).addCallback(function (chunk) { + contents = chunk; + puts("got chunk: " + JSON.stringify(chunk)); +}); +f.close(); + + +function onExit () { + assertEquals("xyz\n", contents); +}