Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Clean up many of the reccommendations from jslint in the file.js library
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Caswell authored and ry committed Oct 13, 2009
1 parent 8bf9a42 commit 2b9a9f9
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*jslint onevar: true, undef: true, eqeqeq: true, plusplus: true, regexp: true, newcap: true, immed: true */
/*globals exports, node, __filename */

exports.debugLevel = 0; // Increase to get more verbose debug output

function debugMessage (msg) {
Expand Down Expand Up @@ -27,7 +30,7 @@ exports.write = function (filename, data, encoding) {
node.fs.close(fd);
})
.addCallback(function (written) {
if (written == _data.length) {
if (written === _data.length) {
node.fs.close(fd);
} else {
doWrite(_data.slice(written));
Expand All @@ -37,7 +40,7 @@ exports.write = function (filename, data, encoding) {
doWrite(data);
})
.addErrback(function () {
promise.emitError()
promise.emitError();
});

return promise;
Expand Down Expand Up @@ -94,46 +97,48 @@ exports.File = function (filename, mode, options) {
var proto = exports.File.prototype;

proto._maybeDispatch = function () {
var self = this;
var self, args, method, promise, userPromise;

self = this;

if (self.currentAction) return;
if (self.currentAction) { return; }
self.currentAction = self.actionQueue.shift();
if (!self.currentAction) return;
if (!self.currentAction) { return; }

debugObject(self.currentAction);

var args = self.currentAction.args || [];
args = self.currentAction.args || [];

if (self.currentAction.method != "open") {
if (self.currentAction.method !== "open") {
args.unshift(self.fd);
}

var method = self.currentAction.method;
method = self.currentAction.method;

if (!args[3] && (method == "read" || method == "write")) {
if (!args[3] && (method === "read" || method === "write")) {
args[3] = self.encoding;
}

var promise = node.fs[method].apply(self, args);
promise = node.fs[method].apply(self, args);

var userPromise = self.currentAction.promise;
userPromise = self.currentAction.promise;

promise.addCallback(function () {
node.assert(self.currentAction.promise == userPromise);
node.assert(self.currentAction.promise === userPromise);
userPromise.emitSuccess.apply(userPromise, arguments);
self.currentAction = null;
self._maybeDispatch();
}).addErrback(function () {
debugMessage("Error in method " + method);
node.assert(self.currentAction.promise == userPromise);
node.assert(self.currentAction.promise === userPromise);
userPromise.emitError.apply(userPromise, arguments);
self.currentAction = null;
self._maybeDispatch();
});
};

proto._queueAction = function (method, args) {
var userPromise = new node.Promise;
var userPromise = new node.Promise();
this.actionQueue.push({ method: method, args: args, promise: userPromise });
this._maybeDispatch();
return userPromise;
Expand Down

0 comments on commit 2b9a9f9

Please sign in to comment.