From 0105d4c541cdf66e5973d965ee0455af0bece2f0 Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Tue, 22 Jun 1999 23:20:26 +0000 Subject: [PATCH] Modified EditorExecuteScript() to read and execute a line at a time. This will allow us to load and execute large log files. --- editor/ui/composer/content/EditorCommands.js | 56 +++++++++++++++----- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/editor/ui/composer/content/EditorCommands.js b/editor/ui/composer/content/EditorCommands.js index 0997387d651..25a3a801eaf 100644 --- a/editor/ui/composer/content/EditorCommands.js +++ b/editor/ui/composer/content/EditorCommands.js @@ -410,17 +410,52 @@ function CheckSpelling() function EditorExecuteScript(fileSpec) { fileSpec.openStreamForReading(); - var buf = { value:null }; - fileSpec.read(buf, fileSpec.FileSize); - // fileSpec.read() reads in only the characters, without - // a zero terminator. eval() needs the string to be zero - // terminated. This is a workaround to get a zero terminated - // string. + var buf = { value:null }; + var tmpBuf = { value:null }; + var didTruncate = { value:false }; - buf.value = buf.value.substr(0, fileSpec.FileSize); + // Log files can be quite huge, so read in a line + // at a time and execute it: - eval(buf.value); + while (!fileSpec.eof()) + { + buf.value = ""; + didTruncate.value = true; + + // Keep looping until we get a complete line of + // text, or we hit the end of file: + + while (didTruncate.value && !fileSpec.eof()) + { + didTruncate.value = false; + fileSpec.readLine(tmpBuf, 1024, didTruncate); + buf.value += tmpBuf.value; + + // XXX Need to null out tmpBuf.value to avoid crashing + // XXX in some JavaScript string allocation method. + // XXX This is probably leaking the buffer allocated + // XXX by the readLine() implementation. + + tmpBuf.value = null; + + // XXX There is a bug in the nsIFileSpec implementation. + // XXX the didTruncate value actually returns a bool + // XXX that indicates if the read successfully read + // XXX a line that fit into the buffer. + // XXX That is, it returns true if everything fit + // XXX and false if it didn't ... the reverse of what + // XXX the args name suggests. + // XXX + // XXX Remove the following line when this bug gets fixed. + + didTruncate.value = !didTruncate.value; + } + + eval(buf.value); + } + + buf.value = null; } function EditorGetScriptFileSpec() @@ -437,10 +472,7 @@ function EditorStartLog() if (window.editorShell) { - fs = Components.classes["component://netscape/filespec"].createInstance(); - fs = fs.QueryInterface(Components.interfaces.nsIFileSpec); - fs.UnixStyleFilePath = "journal.js"; - + fs = EditorGetScriptFileSpec(); window.editorShell.StartLogging(fs); fs = null;