The default bug view has changed. See this FAQ.

Shell should be able to read from stdin

RESOLVED FIXED in mozilla9

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: cdleary, Assigned: cdleary)

Tracking

unspecified
mozilla9
x86_64
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

Created attachment 558657 [details] [diff] [review]
Solo dash argument.

$ ./js - < test2.js 
Hoo!
$ ./js -f test.js - < test2.js 
Whoo
Hoo!
Attachment #558657 - Flags: review?(brendan)
Comment on attachment 558657 [details] [diff] [review]
Solo dash argument.

># HG changeset patch
># Parent 6a4e5dbe0d64d7646306b4c9fc50a69b29631551
>
>diff --git a/js/src/shell/jsoptparse.cpp b/js/src/shell/jsoptparse.cpp
>--- a/js/src/shell/jsoptparse.cpp
>+++ b/js/src/shell/jsoptparse.cpp
>@@ -373,19 +373,21 @@ OptionParser::parseArgs(int inputArgc, c
>     /* Permit a "no more options" capability, like |--| offers in many shell interfaces. */
>     bool optionsAllowed = true;
> 
>     for (size_t i = 1; i < argc; ++i) {
>         char *arg = argv[i];
>         Result r;
>         if (arg[0] == '-' && optionsAllowed) {
>             /* Option. */
>-            size_t arglen = strlen(arg);
>-            if (arglen < 2) /* Do not permit solo dash option. */
>-                return error("Invalid dash option");
>+            if (arg[1] == '\0') {
>+                /* Solo dash option is actually a 'stdin' argument. */
>+                r = handleArg(argc, argv, &i, &optionsAllowed);

Note statement immediately above.

>+                goto have_result;
>+            }
> 
>             Option *opt;
>             if (arg[1] == '-') {
>                 /* Long option. */
>                 opt = findOption(arg + 2);
>                 if (!opt)
>                     return error("Invalid long option: %s", arg);
>             } else {
>@@ -397,16 +399,17 @@ OptionParser::parseArgs(int inputArgc, c
>                     return error("Invalid short option: %s", arg);
>             }
> 
>             r = handleOption(opt, argc, argv, &i, &optionsAllowed);
>         } else {
>             /* Argument. */
>             r = handleArg(argc, argv, &i, &optionsAllowed);

Same as this basic block.

>         }
>+  have_result:

Succeeded by what's at this label, so instead of duplicating the r = handleArg(...) call and using a goto, how about:

         if (arg[0] == '-' && arg[1] != '\0' && optionsAllowed) {

up front, and unify the handleArg call (and avoid the strlen < 2 test).

r=me with that. Thanks,

/be
Attachment #558657 - Flags: review?(brendan) → review+
Whiteboard: [inbound]
https://hg.mozilla.org/mozilla-central/rev/ff19f221eeca
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Whiteboard: [inbound]
Target Milestone: --- → mozilla9
You need to log in before you can comment on or make changes to this bug.