JSHint the lib directory

This commit is contained in:
Ernest Wong 2018-07-13 14:21:23 +12:00 committed by Fabian
parent 46d48c4070
commit bda133ba49
6 changed files with 67 additions and 62 deletions

View file

@ -319,7 +319,7 @@ node_modules/.bin/jshint:
npm install
jshint: node_modules/.bin/jshint
./node_modules/.bin/jshint --config=./.jshint.json src tests gen
./node_modules/.bin/jshint --config=./.jshint.json src tests gen lib --exclude lib/closure-base.js
rustfmt: $(RUST_FILES)
cargo +nightly fmt --all -- --check

View file

@ -21,7 +21,7 @@ var ENOENT = 2; /* No such file or directory */
var EINVAL = 22; /* Invalid argument */
var ENOTSUPP = 524; /* Operation is not supported */
var ENOTEMPTY = 39; /* Directory not empty */
var EPROTO = 71 /* Protocol error */
var EPROTO = 71; /* Protocol error */
var P9_SETATTR_MODE = 0x00000001;
var P9_SETATTR_UID = 0x00000002;
@ -185,17 +185,20 @@ Virtio9p.prototype.set_state = function(state)
this.msize = state[5];
this.replybuffer = state[6];
this.replybuffersize = state[7];
this.fids = state[8].map(function(f) { return { inodeid: f[0], type: f[1], uid: f[2] } });
this.fids = state[8].map(function(f)
{
return { inodeid: f[0], type: f[1], uid: f[2] };
});
this.fs = state[9];
};
Virtio9p.prototype.Createfid = function(inode, type, uid) {
return {inodeid: inode, type: type, uid: uid};
}
};
Virtio9p.prototype.Reset = function() {
this.fids = [];
}
};
Virtio9p.prototype.BuildReply = function(id, tag, payloadsize) {
@ -208,20 +211,20 @@ Virtio9p.prototype.BuildReply = function(id, tag, payloadsize) {
// this.replybuffer[7+i] = payload[i];
this.replybuffersize = payloadsize+7;
return;
}
};
Virtio9p.prototype.SendError = function (tag, errormsg, errorcode) {
//var size = marshall.Marshall(["s", "w"], [errormsg, errorcode], this.replybuffer, 7);
var size = marshall.Marshall(["w"], [errorcode], this.replybuffer, 7);
this.BuildReply(6, tag, size);
}
};
Virtio9p.prototype.SendReply = function (bufchain) {
dbg_assert(this.replybuffersize >= 0, "9P: Negative replybuffersize");
bufchain.set_next_blob(this.replybuffer.subarray(0, this.replybuffersize));
this.virtqueue.push_reply(bufchain);
this.virtqueue.flush_replies();
}
};
Virtio9p.prototype.ReceiveRequest = function (bufchain) {
// TODO: split into header + data blobs to avoid unnecessary copying.
@ -431,7 +434,7 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
req[6] = (inode.major<<8) | (inode.minor); // device id low
req[7] = inode.size; // size low
req[8] = this.BLOCKSIZE;
req[9] = Math.floor(inode.size/512+1);; // blk size low
req[9] = Math.floor(inode.size/512+1); // blk size low
req[10] = inode.atime; // atime
req[11] = 0x0;
req[12] = inode.mtime; // mtime
@ -464,8 +467,8 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
"w", "w", // uid, gid
"d", // size
"d", "d", // atime
"d", "d"] // mtime
, buffer, state);
"d", "d", // mtime
], buffer, state);
var fid = req[0];
var inode = this.fs.GetInode(this.fids[fid].inodeid);
message.Debug("[setattr]: fid=" + fid + " request mask=" + req[1] + " name=" +inode.name);

View file

@ -34,13 +34,13 @@ var STATUS_UNLINKED = 0x4;
/** @const */ var JSONFS_VERSION = 2;
/** @const */ var JSONFS_IDX_NAME = 0
/** @const */ var JSONFS_IDX_SIZE = 1
/** @const */ var JSONFS_IDX_MTIME = 2
/** @const */ var JSONFS_IDX_MODE = 3
/** @const */ var JSONFS_IDX_UID = 4
/** @const */ var JSONFS_IDX_GID = 5
/** @const */ var JSONFS_IDX_TARGET = 6
/** @const */ var JSONFS_IDX_NAME = 0;
/** @const */ var JSONFS_IDX_SIZE = 1;
/** @const */ var JSONFS_IDX_MTIME = 2;
/** @const */ var JSONFS_IDX_MODE = 3;
/** @const */ var JSONFS_IDX_UID = 4;
/** @const */ var JSONFS_IDX_GID = 5;
/** @const */ var JSONFS_IDX_TARGET = 6;
/** @constructor */
@ -119,13 +119,13 @@ FS.prototype.AddEvent = function(id, OnEvent) {
return;
}
this.events.push({id: id, OnEvent: OnEvent});
}
};
FS.prototype.HandleEvent = function(id) {
if (this.filesinloadingqueue == 0) {
this.OnLoaded();
this.OnLoaded = function() {}
this.OnLoaded = function() {};
}
//message.Debug("number of events: " + this.events.length);
var newevents = [];
@ -137,7 +137,7 @@ FS.prototype.HandleEvent = function(id) {
}
}
this.events = newevents;
}
};
FS.prototype.OnJSONLoaded = function(fs)
{
@ -225,7 +225,7 @@ FS.prototype.LoadRecursive = function(data, parentid)
{
dbg_log("Unexpected ifmt: " + h(ifmt) + " (" + inode.name + ")");
}
}
};
FS.prototype.LoadDir = function(inode, children)
{
@ -237,7 +237,7 @@ FS.prototype.LoadDir = function(inode, children)
for(var i = 0; i < children.length; i++) {
this.LoadRecursive(children[i], p);
}
}
};
// Loads the data from a url for a specific inode
FS.prototype.LoadFile = function(idx) {
@ -281,7 +281,7 @@ FS.prototype.LoadFile = function(idx) {
// If baseurl is not set, we started with an empty filesystem. No files
// can be loaded
}
}
};
// -----------------------------------------------------
@ -304,7 +304,7 @@ FS.prototype.PushInode = function(inode) {
message.Debug("Error in Filesystem: Pushed inode with name = "+ inode.name + " has no parent");
message.Abort();
}
};
/** @constructor */
function Inode(qidnumber)
@ -416,7 +416,7 @@ FS.prototype.CreateDirectory = function(name, parentid) {
this.PushInode(x);
this.NotifyListeners(this.inodes.length-1, 'newdir');
return this.inodes.length-1;
}
};
FS.prototype.CreateFile = function(filename, parentid) {
var x = this.CreateInode();
@ -430,7 +430,7 @@ FS.prototype.CreateFile = function(filename, parentid) {
this.PushInode(x);
this.NotifyListeners(this.inodes.length-1, 'newfile');
return this.inodes.length-1;
}
};
FS.prototype.CreateNode = function(filename, parentid, major, minor) {
@ -446,7 +446,7 @@ FS.prototype.CreateNode = function(filename, parentid, major, minor) {
x.mode = (this.inodes[parentid].mode & 0x1B6);
this.PushInode(x);
return this.inodes.length-1;
}
};
FS.prototype.CreateSymlink = function(filename, parentid, symlink) {
var x = this.CreateInode();
@ -460,7 +460,7 @@ FS.prototype.CreateSymlink = function(filename, parentid, symlink) {
x.mode = S_IFLNK;
this.PushInode(x);
return this.inodes.length-1;
}
};
FS.prototype.CreateTextFile = function(filename, parentid, str) {
var id = this.CreateFile(filename, parentid);
@ -471,7 +471,7 @@ FS.prototype.CreateTextFile = function(filename, parentid, str) {
data[j] = str.charCodeAt(j);
}
return id;
}
};
/**
* @param {Uint8Array} buffer
@ -483,7 +483,7 @@ FS.prototype.CreateBinaryFile = function(filename, parentid, buffer) {
data.set(buffer);
x.size = buffer.length;
return id;
}
};
FS.prototype.OpenInode = function(id, mode) {
@ -506,7 +506,7 @@ FS.prototype.OpenInode = function(id, mode) {
return false;
}
return true;
}
};
FS.prototype.CloseInode = function(id) {
//message.Debug("close: " + this.GetFullPath(id));
@ -517,7 +517,7 @@ FS.prototype.CloseInode = function(id) {
delete this.inodedata[id];
inode.size = 0;
}
}
};
FS.prototype.Rename = function(olddirid, oldname, newdirid, newname) {
// message.Debug("Rename " + oldname + " to " + newname);
@ -564,7 +564,7 @@ FS.prototype.Rename = function(olddirid, oldname, newdirid, newname) {
this.NotifyListeners(idx, "rename", {oldpath: oldpath});
return true;
}
};
FS.prototype.Write = function(id, offset, count, buffer) {
this.NotifyListeners(id, 'write');
@ -580,7 +580,7 @@ FS.prototype.Write = function(id, offset, count, buffer) {
inode.size = offset + count;
}
data.set(buffer.subarray(0, count), offset);
}
};
FS.prototype.Search = function(parentid, name) {
var id = this.inodes[parentid].firstid;
@ -592,7 +592,7 @@ FS.prototype.Search = function(parentid, name) {
id = this.inodes[id].nextid;
}
return -1;
}
};
FS.prototype.GetTotalSize = function() {
return this.used_size;
@ -602,7 +602,7 @@ FS.prototype.GetTotalSize = function() {
// size += d ? d.length : 0;
//}
//return size;
}
};
FS.prototype.GetSpace = function() {
return this.total_size;
@ -616,7 +616,7 @@ FS.prototype.GetFullPath = function(idx) {
idx = this.inodes[idx].parentid;
}
return path.substring(1);
}
};
// no double linked list. So, we need this
FS.prototype.FindPreviousID = function(idx) {
@ -627,7 +627,7 @@ FS.prototype.FindPreviousID = function(idx) {
id = this.inodes[id].nextid;
}
return id;
}
};
FS.prototype.Unlink = function(idx) {
this.NotifyListeners(idx, 'delete');
@ -660,7 +660,7 @@ FS.prototype.Unlink = function(idx) {
inode.parentid = -1;
inode.nlinks--;
return true;
}
};
FS.prototype.GetInode = function(idx)
{
@ -674,7 +674,7 @@ FS.prototype.GetInode = function(idx)
return 0;
}
return this.inodes[idx];
}
};
FS.prototype.ChangeSize = function(idx, newsize)
{
@ -687,7 +687,7 @@ FS.prototype.ChangeSize = function(idx, newsize)
if(!temp) return;
var size = Math.min(temp.length, inode.size);
data.set(temp.subarray(0, size), 0);
}
};
FS.prototype.SearchPath = function(path) {
//path = path.replace(/\/\//g, "/");
@ -709,7 +709,7 @@ FS.prototype.SearchPath = function(path) {
parentid = id;
}
return {id: id, parentid: parentid, name: walk[i]};
}
};
// -----------------------------------------------------
FS.prototype.GetRecursiveList = function(dirid, list) {
@ -721,10 +721,10 @@ FS.prototype.GetRecursiveList = function(dirid, list) {
}
id = this.inodes[id].nextid;
}
}
};
FS.prototype.RecursiveDelete = function(path) {
var toDelete = []
var toDelete = [];
var ids = this.SearchPath(path);
if (ids.parentid == -1 || ids.id == -1) return;
@ -733,7 +733,7 @@ FS.prototype.RecursiveDelete = function(path) {
for(var i=toDelete.length-1; i>=0; i--)
this.Unlink(toDelete[i]);
}
};
FS.prototype.DeleteNode = function(path) {
var ids = this.SearchPath(path);
@ -744,14 +744,14 @@ FS.prototype.DeleteNode = function(path) {
return;
}
if ((this.inodes[ids.id].mode&S_IFMT) == S_IFDIR){
var toDelete = []
var toDelete = [];
this.GetRecursiveList(ids.id, toDelete);
for(var i=toDelete.length-1; i>=0; i--)
this.Unlink(toDelete[i]);
this.Unlink(ids.id);
return;
}
}
};
/** @param {*=} info */
FS.prototype.NotifyListeners = function(id, action, info) {
@ -769,7 +769,7 @@ FS.prototype.NotifyListeners = function(id, action, info) {
// message.Send("WatchDirectoryEvent", {path: path, event: action, info: info});
// }
//}
}
};
FS.prototype.Check = function() {
@ -798,7 +798,7 @@ FS.prototype.Check = function() {
}
}
}
};
FS.prototype.FillDirectory = function(dirid) {
@ -850,7 +850,7 @@ FS.prototype.FillDirectory = function(dirid) {
id = this.inodes[id].nextid;
}
inode.updatedir = false;
}
};
FS.prototype.RoundToDirentry = function(dirid, offset_target)
{
@ -908,5 +908,5 @@ FS.prototype.PrepareCAPs = function(id) {
inode.caps[11] = 0xFF;
return inode.caps.length;
}
};

View file

@ -40,7 +40,7 @@ var message = {};
message.Debug = function(log)
{
dbg_log([].slice.apply(arguments).join(" "), LOG_9P);
}
};
message.Abort = function()
{
@ -48,7 +48,7 @@ message.Abort = function()
{
throw "abort";
}
}
};
// XXX: Should go through emulator interface
@ -85,7 +85,7 @@ if(typeof XMLHttpRequest !== "undefined")
};
*/
req.send(null);
}
};
}
else
{
@ -103,5 +103,5 @@ else
OnSuccess(data.buffer);
}
});
}
};
}

View file

@ -3,6 +3,8 @@
// -------------------------------------------------
// helper functions for virtio and 9p.
"use strict";
var marshall = {};
@ -58,7 +60,7 @@ marshall.Marshall = function(typelist, input, struct, offset) {
struct[lengthoffset+1] = (length >> 8) & 0xFF;
break;
case "Q":
marshall.Marshall(["b", "w", "d"], [item.type, item.version, item.path], struct, offset)
marshall.Marshall(["b", "w", "d"], [item.type, item.version, item.path], struct, offset);
offset += 13;
size += 13;
break;
@ -105,7 +107,7 @@ marshall.Unmarshall = function(typelist, struct, state) {
var str = '';
var utf8converter = new UTF8StreamToUnicode();
for (var j=0; j < len; j++) {
var c = utf8converter.Put(struct[offset++])
var c = utf8converter.Put(struct[offset++]);
if (c == -1) continue;
str += String.fromCharCode(c);
}
@ -164,7 +166,7 @@ marshall.Unmarshall2 = function(typelist, GetByte) {
var str = '';
var utf8converter = new UTF8StreamToUnicode();
for (var j=0; j < len; j++) {
var c = utf8converter.Put(GetByte())
var c = utf8converter.Put(GetByte());
if (c == -1) continue;
str += String.fromCharCode(c);
}

View file

@ -4,7 +4,7 @@
"use strict";
var UTF8 = {}
var UTF8 = {};
/** @constructor */
function UTF8StreamToUnicode() {
@ -43,7 +43,7 @@ function UTF8StreamToUnicode() {
//break;
}
return -1;
}
};
}
function UnicodeToUTF8Stream(key)
@ -60,4 +60,4 @@ UTF8.UTF8Length = function(s)
length += c<128?1:2;
}
return length;
}
};