Bug 17531 - Add interactive mode to testkjs
Summary: Add interactive mode to testkjs
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2008-02-25 00:28 PST by Sam Weinig
Modified: 2008-06-09 10:12 PDT (History)
1 user (show)

See Also:

First stab at it (8.03 KB, patch)
2008-02-25 00:35 PST, Sam Weinig
no flags Details | Formatted Diff | Diff
Proposed patch (10.41 KB, patch)
2008-06-09 01:20 PDT, Cameron Zwarich (cpst)
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2008-02-25 00:28:36 PST
Adding an interactive shell to testkjs seems like the next step.  Let's do it!
Comment 1 Sam Weinig 2008-02-25 00:35:40 PST
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.
Comment 2 Sam Weinig 2008-02-25 00:40:13 PST
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.
Comment 3 Mark Rowe (bdash) 2008-02-25 04:01:20 PST

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.
Comment 4 Cameron Zwarich (cpst) 2008-06-09 01:20:57 PDT
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 5 Darin Adler 2008-06-09 06:51:08 PDT
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.

Comment 6 Mark Rowe (bdash) 2008-06-09 09:43:15 PDT
-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.
Comment 7 Cameron Zwarich (cpst) 2008-06-09 10:02:27 PDT
(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[].
Comment 8 Cameron Zwarich (cpst) 2008-06-09 10:12:01 PDT
Landed in r34470.