Commit 0c2677ca authored by Ola Bini's avatar Ola Bini

Fix JSHint warnings in IPC - also add a ProcessBuilder that will be used

later.

Contribution from Fan Jiang, Iván Pazmiño and Ola Bini.
parent 1b0e7034
......@@ -170,8 +170,6 @@
* subprocess.registerLogHandler( function(s) { dump(s); } );
*/
'use strict';
Components.utils.import("resource://gre/modules/ctypes.jsm");
let EXPORTED_SYMBOLS = [ "subprocess" ];
......@@ -339,7 +337,7 @@ function getPlatformValue(valueType) {
'darwin': [ 'libc.dylib', 0x04 , ctypes.uint64_t , 8 ],
'linux': [ 'libc.so.6', 2024 , ctypes.unsigned_long, 7 ],
'freebsd': [ 'libc.so.7', 0x04 , ctypes.int64_t , 8 ],
'dragonfly':[ 'libc.so.8', 0x04, , ctypes.int64_t , 8 ],
'dragonfly': [ 'libc.so.8', 0x04 , ctypes.int64_t , 8 ],
'gnu/kfreebsd': [ 'libc.so.0.1', 0x04 , ctypes.int64_t , 8 ],
'netbsd': [ 'libc.so', 0x04 , ctypes.int64_t , 8 ],
'openbsd': [ 'libc.so.61.0', 0x04 , ctypes.int64_t , 8 ],
......@@ -369,7 +367,7 @@ function debugLog(s) {
function setTimeout(callback, timeout) {
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
};
}
function convertBytes(data, charset) {
var string = charset == "null" || charset == "UTF-8" ? data
......@@ -452,6 +450,36 @@ var subprocess = {
}
},
ProcessBuilder: function () {
this.process = {};
this.setCommand = function(command){
this.process.command = command;
};
this.setArguments = function(args){
this.process.arguments = args;
};
this.setEnvironment = function(envList){
this.process.environment = envList;
};
this.setStdin = function(stdin){
this.process.stdin = stdin;
};
this.setStdout = function(stdout){
this.process.stdout = stdout;
};
this.setDone = function(done){
this.process.done = done;
};
this.build = function(){
this.process.charset= null;
this.process.mergeStderr= false;
this.process.resultData= "";
this.process.errorData= "";
this.process.exitCode= -1;
return this.process;
};
return this;
},
registerDebugHandler: function(func) {
gDebugFunc = func;
},
......@@ -905,7 +933,7 @@ function subprocess_win32(options) {
else {
stdinOpenState = PIPE_STATE_CLOSED;
debugLog("Closing Stdin\n");
CloseHandle(child.stdin) || LogError("CloseHandle hInputWrite failed");
if(!CloseHandle(child.stdin)) LogError("CloseHandle hInputWrite failed");
}
}
......@@ -932,7 +960,7 @@ function subprocess_win32(options) {
case "done":
debugLog("Pipe "+name+" closed\n");
--readers;
if (readers == 0) cleanup();
if (readers === 0) cleanup();
break;
case "error":
exitCode = -2;
......@@ -1285,7 +1313,7 @@ function subprocess_unix(options) {
var sleep = libc.declare("sleep",
ctypes.default_abi,
ctypes.int,
ctypes.int)
ctypes.int);
//int fcntl(int fd, int cmd, ... /* arg */ );
......@@ -1370,12 +1398,12 @@ function subprocess_unix(options) {
return -1;
}
if (options.pipes[i].readFd != undefined) {
if (options.pipes[i].readFd !== undefined) {
debugLog("adding input fd: " +fd[1] + "\n");
child.otherFdChild[i] = fd[1];
child.otherFdParent[i] = fd[0];
}
else if (options.pipes[i].writeFd != undefined) {
else if (options.pipes[i].writeFd !== undefined) {
debugLog("adding output fd: " +fd[0] + "\n");
child.otherFdChild[i] = fd[0];
child.otherFdParent[i] = fd[1];
......@@ -1419,7 +1447,7 @@ function subprocess_unix(options) {
let id = pid_t(0);
let rv = posix_spawn(id.address(), command, action.address(), null, _args, _envp);
posix_spawn_file_actions_destroy(action.address());
if (rv != 0) {
if (rv !== 0) {
// we should not really end up here
if(!options.mergeStderr) {
close(_err[0]);
......@@ -1473,7 +1501,7 @@ function subprocess_unix(options) {
);
var rl = new RLIMITS();
if (getrlimit(getPlatformValue(RLIMIT_NOFILE), rl.address()) == 0) {
if (getrlimit(getPlatformValue(RLIMIT_NOFILE), rl.address()) === 0) {
if (rl.rlim_cur < Math.pow(2,20)) // ignore too high numbers
maxFD = rl.rlim_cur;
}
......@@ -1608,14 +1636,14 @@ function subprocess_unix(options) {
stdinOpenState[workerNum] = PIPE_STATE_CLOSED;
debugLog("Closing Stdin for "+workerNum+"\n");
if (!workerNum)
close(child.stdin) && LogError("CloseHandle stdin failed");
if(close(child.stdin)) LogError("CloseHandle stdin failed");
else {
let wrk = 0;
for (let i = 0; i < options.pipes.length; i++) {
if (options.pipes[i].writeFd != undefined) {
if (options.pipes[i].writeFd !== undefined) {
++wrk;
if (wrk == workerNum) {
close(child.writeFdParent[i]) && LogError("CloseHandle stdin failed");
if(close(child.writeFdParent[i])) LogError("CloseHandle stdin failed");
}
}
}
......@@ -1648,9 +1676,9 @@ function subprocess_unix(options) {
break;
case "done":
debugLog("Pipe "+name+" closed\n");
if (event.data.data != 0) workerExitCode = event.data.data;
if (event.data.data !== 0) workerExitCode = event.data.data;
--readers;
if (readers == 0) cleanup();
if (readers === 0) cleanup();
break;
case "error":
LogError("Got error from "+name+": "+event.data.data);
......@@ -1705,16 +1733,20 @@ function subprocess_unix(options) {
}
});
function flusher(pipe) {
return function(data) {
setTimeout(function() {
pipe.readFd(data);
}, 0);
};
}
if (options.pipes) {
for (let i = 0; i < options.pipes.length; i++) {
if (typeof(options.pipes[i].readFd) == "function") {
let pipe = options.pipes[i];
let wrk = createReader(child.otherFdParent[i], "fd_"+ (i+3) , function (data) {
setTimeout(function() {
pipe.readFd(data);
}, 0);
});
let wrk = createReader(child.otherFdParent[i], "fd_"+ (i+3) , flusher(pipe));
readFdWorker.push(wrk);
}
......@@ -1844,7 +1876,7 @@ function subprocess_unix(options) {
if (options.pipes) {
for (let i = 0; i < options.pipes.length; i++) {
if (options.pipes[i].writeFd != undefined) {
if (options.pipes[i].writeFd !== undefined) {
stdinOpenState.push(PIPE_STATE_NOT_INIT);
writeWorker.push(createWriter(child.otherFdParent[i], workerNum));
startWriting(workerNum, options.pipes[i].writeFd);
......
......@@ -43,8 +43,6 @@
// Being a ChromeWorker object, implicitly uses the following:
// Components.utils.import("resource://gre/modules/ctypes.jsm");
'use strict';
const BufferSize = 1024;
const MaxBufferLen = 102400;
......@@ -158,8 +156,8 @@ function createNpeError() {
}
function closePipe(pipe) {
if (pipe == null) {
createNpeError()
if (pipe === null) {
createNpeError();
return;
}
......@@ -195,7 +193,7 @@ function writePipe(pipe, data) {
function readString(data, length, charset) {
var r = '';
for(var i = 0; i < length; i++) {
if(data[i] == 0 && charset != "null") // stop on NULL character for non-binary data
if(data[i] === 0 && charset != "null") // stop on NULL character for non-binary data
break;
r += String.fromCharCode(data[i]);
......@@ -214,7 +212,7 @@ function readUtf8(data, length) {
var endChar = [];
if (data[length - 1] >= 0x80) {
// Collect all bytes from the last character if it's a non-ASCII.
for (var i = length - 1; i >= 0; i--) {
for (let i = length - 1; i >= 0; i--) {
endChar.unshift(data[i]);
if (data[i] >= 0xc0) break;
}
......@@ -232,7 +230,7 @@ function readUtf8(data, length) {
data[length - endChar.length] = 0;
var r = data.readStringReplaceMalformed();
// Place the partial character at the beginning for the next read.
var i = 0;
let i = 0;
endChar.forEach(function (v) {
data[i++] = v;
});
......@@ -242,7 +240,7 @@ function readUtf8(data, length) {
}
function readPipe(pipe, charset, pid, bufferedOutput) {
var p = new libcFunc.pollFds;
var p = new libcFunc.pollFds();
p[0].fd = pipe;
p[0].events = POLLIN | POLLERR | POLLHUP;
p[0].revents = 0;
......@@ -258,7 +256,7 @@ function readPipe(pipe, charset, pid, bufferedOutput) {
const i=0;
while (true) {
if (result == 0) {
if (result === 0) {
result = libcFunc.waitpid(pid, status.address(), WNOHANG);
if (result > 0) {
pollTimeout = NOWAIT;
......@@ -291,7 +289,7 @@ function readPipe(pipe, charset, pid, bufferedOutput) {
dataStr = "";
}
}
if (readCount == 0) break;
if (readCount === 0) break;
}
if (p[i].revents & POLLHUP) {
......@@ -319,7 +317,7 @@ function readPipe(pipe, charset, pid, bufferedOutput) {
else
dataStr += dataObj.value;
let r = libcFunc.poll(p, 1, NOWAIT);
libcFunc.poll(p, 1, NOWAIT);
}
if (bufferedOutput)
......@@ -335,7 +333,7 @@ function readPolledFd(pipe, line, charset, dataObj) {
// Start reading at first null byte (line might begin with an
// incomplete UTF-8 character from the previous read).
var offset = 0;
while (line[offset] != 0) offset++;
while (line[offset] !== 0) offset++;
var r = libcFunc.read(pipe, line.addressOfElement(offset), BufferSize-offset-1);
if (r > 0) {
......@@ -352,7 +350,7 @@ function readPolledFd(pipe, line, charset, dataObj) {
onmessage = function (event) {
switch (event.data.msg) {
case "init":
if (event.data.pipe == null) {
if (event.data.pipe === null) {
createNpeError();
return;
}
......@@ -361,7 +359,7 @@ onmessage = function (event) {
postMessage({msg: "info", data: "InitOK"});
break;
case "read":
if (event.data.pipe == null) {
if (event.data.pipe === null) {
createNpeError();
return;
}
......
......@@ -43,8 +43,6 @@
// Being a ChromeWorker object, implicitly uses the following:
// Components.utils.import("resource://gre/modules/ctypes.jsm");
'use strict';
const BufferSize = 1024;
const MaxBufferLen = 102400;
......@@ -78,10 +76,11 @@ var kernel32dll = null;
var libFunc = {};
function initLib(libName) {
var WinABI;
if (ctypes.size_t.size == 8) {
var WinABI = ctypes.default_abi;
WinABI = ctypes.default_abi;
} else {
var WinABI = ctypes.winapi_abi;
WinABI = ctypes.winapi_abi;
}
kernel32dll = ctypes.open(libName);
......@@ -165,7 +164,7 @@ function writePipe(pipe, data) {
function readString(data, length, charset) {
var r = '';
for(var i = 0; i < length; i++) {
if(data[i] == 0 && charset != "null") // stop on NULL character for non-binary data
if(data[i] === 0 && charset != "null") // stop on NULL character for non-binary data
break;
r += String.fromCharCode(data[i]);
......@@ -184,7 +183,7 @@ function readUtf8(data, length) {
var endChar = [];
if (data[length - 1] >= 0x80) {
// Collect all bytes from the last character if it's a non-ASCII.
for (var i = length - 1; i >= 0; i--) {
for (let i = length - 1; i >= 0; i--) {
endChar.unshift(data[i]);
if (data[i] >= 0xc0) break;
}
......@@ -202,7 +201,7 @@ function readUtf8(data, length) {
data[length - endChar.length] = 0;
var r = data.readStringReplaceMalformed();
// Place the partial character at the beginning for the next read.
var i = 0;
let i = 0;
endChar.forEach(function (v) {
data[i++] = v;
});
......@@ -220,7 +219,7 @@ function readPipe(pipe, charset, bufferedOutput) {
// Start reading at first null byte (line might begin with an
// incomplete UTF-8 character from the previous read).
var offset = 0;
while (line[offset] != 0) offset++;
while (line[offset] !== 0) offset++;
var r = libFunc.ReadFile(
pipe, line.addressOfElement(offset), BufferSize-offset-1,
bytesRead.address(), null
......
......@@ -27,7 +27,7 @@ function run_test()
var plPath = env.get("PL_PATH");
Assert.ok(plPath.length > 0, "PL_PATH length is > 0");
if (plPath.length == 0) throw "perl path undefined";
if (plPath.length === 0) throw "perl path undefined";
var pl = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
pl.initWithPath(plPath);
......@@ -271,4 +271,3 @@ function run_test()
Assert.equal(gTestLines.join(""), gResultData, "variable comparison");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment