Adding an interactive shell to testkjs seems like the next step. Let's do it!
Created attachment 19341 [details] First stab at it Here is a first stab at an interactive shell mode. If the platform you are on has readline support (currently I only have it set for Darwin, since I know it does, but the automake platforms can be made to check for it too) I use it and make use of the history, otherwise we just use getchar. The way interactive mode works with files is that all the files are run first, and if they succeed, we go into interactive mode. There are some names I don't especially like in this patch (the Options struct for one, not really sure we even need it) and I think it has gotten to the point where we need a more fleshed out usage message. All in all though, this is pretty close.
Another feature I would like to add to the interactive mode, though not necessarily in this first version, is good autocompletion support (js keywords, variables in scope). This can be done rather easily using readline. It also just occurred to me. Does it make sense to enter interactive mode if -p has been supplied.
+#if HAVE(asREADLINE) I wonder if the default behaviour for running testkjs with no arguments should be to drop into the interactive shell? With your patch it doesn't seem possible to get into interactive mode without executing code from some file first. That may be a useful mode for inspecting the state of a completed script, but based on experiences using Python's interactive interpreter I feel it may be less commonly used than interactive mode without executing any code from a file.
Created attachment 21590 [details] Proposed patch Here is a cleaned up version of Sam's patch. I made the prompt string the same as SpiderMonkey's, and I made it enter interactive mode if no files are specified.
Comment on attachment 21590 [details] Proposed patch +static const char* interactivePrompt = "> "; This should be static const char[] or static const char* const. The declaration as-is asks for a non-const global pointing to a const string. + fprintf(stderr, " -p Prints formatted source code\n"); I think this option is a little silly now that it does no formatting and just spits the code out as-is. r=me
-p still seems to do a relatively good job. Oliver explained to me why it may give worse results than before on some input, but in my quick test with some crazy-obfuscated gmail source code it gave reasonable results.
(In reply to comment #5) > (From update of attachment 21590 [details] [edit]) > +static const char* interactivePrompt = "> "; > > This should be static const char[] or static const char* const. The declaration > as-is asks for a non-const global pointing to a const string. Thanks. I meant to make it a static const char[].
Landed in r34470.