mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 723391 - Add a simple remote JS console to b2g. r=vingtetun
This commit is contained in:
parent
d574234713
commit
316c195112
@ -426,6 +426,10 @@ pref("media.realtime_decoder.enabled", true);
|
||||
// by bug 710563.
|
||||
pref("layout.frame_rate.precise", true);
|
||||
|
||||
// Temporary remote js console hack
|
||||
pref("b2g.remote-js.enabled", true);
|
||||
pref("b2g.remote-js.port", 9999);
|
||||
|
||||
// Screen timeout in minutes
|
||||
pref("power.screen.timeout", 60);
|
||||
|
||||
|
@ -8,6 +8,7 @@ const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
const CC = Components.Constructor;
|
||||
const Cr = Components.results;
|
||||
|
||||
const LocalFile = CC('@mozilla.org/file/local;1',
|
||||
'nsILocalFile',
|
||||
@ -363,3 +364,49 @@ Services.obs.addObserver(function onConsoleAPILogEvent(subject, topic, data) {
|
||||
" in " + (message.functionName || "anonymous") + ": ";
|
||||
Services.console.logStringMessage(prefix + Array.join(message.arguments, " "));
|
||||
}, "console-api-log-event", false);
|
||||
|
||||
(function Repl() {
|
||||
if (!Services.prefs.getBoolPref('b2g.remote-js.enabled')) {
|
||||
return;
|
||||
}
|
||||
const prompt = 'JS> ';
|
||||
let output;
|
||||
let reader = {
|
||||
onInputStreamReady : function repl_readInput(input) {
|
||||
let sin = Cc['@mozilla.org/scriptableinputstream;1']
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
sin.init(input);
|
||||
try {
|
||||
let val = eval(sin.read(sin.available()));
|
||||
let ret = (typeof val === 'undefined') ? 'undefined\n' : val + '\n';
|
||||
output.write(ret, ret.length);
|
||||
// TODO: check if socket has been closed
|
||||
} catch (e) {
|
||||
if (e.result === Cr.NS_BASE_STREAM_CLOSED ||
|
||||
(typeof e === 'object' && e.result === Cr.NS_BASE_STREAM_CLOSED)) {
|
||||
return;
|
||||
}
|
||||
let message = (typeof e === 'object') ? e.message + '\n' : e + '\n';
|
||||
output.write(message, message.length);
|
||||
}
|
||||
output.write(prompt, prompt.length);
|
||||
input.asyncWait(reader, 0, 0, Services.tm.mainThread);
|
||||
}
|
||||
}
|
||||
let listener = {
|
||||
onSocketAccepted: function repl_acceptConnection(serverSocket, clientSocket) {
|
||||
dump('Accepted connection on ' + clientSocket.host + '\n');
|
||||
let input = clientSocket.openInputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0)
|
||||
.QueryInterface(Ci.nsIAsyncInputStream);
|
||||
output = clientSocket.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
|
||||
output.write(prompt, prompt.length);
|
||||
input.asyncWait(reader, 0, 0, Services.tm.mainThread);
|
||||
}
|
||||
}
|
||||
let serverPort = Services.prefs.getIntPref('b2g.remote-js.port');
|
||||
let serverSocket = Cc['@mozilla.org/network/server-socket;1']
|
||||
.createInstance(Ci.nsIServerSocket);
|
||||
serverSocket.init(serverPort, true, -1);
|
||||
dump('Opened socket on ' + serverSocket.port + '\n');
|
||||
serverSocket.asyncListen(listener);
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user