Closed Bug 474236 Opened 15 years ago Closed 15 years ago

xpcshell/js shell don't wait for complete input

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: roc, Assigned: mrbkap)

References

Details

(Keywords: fixed1.9.1, Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

meekness:bin roc$ ./js
js> /* hello
typein:1: SyntaxError: unterminated comment:
typein:1: /* hello
typein:1: ^

If I understand the code correctly, 'Process' is supposed to call JS_BufferIsCompilableUnit and keep reading lines until that returns true. But in this case, JS_BufferIsCompilableUnit is returning true for my input, which is obviously wrong.
Blocks: 461841
Attached patch Proposed fixSplinter Review
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Attachment #357859 - Flags: review?(brendan)
Comment on attachment 357859 [details] [diff] [review]
Proposed fix

>diff --git a/js/src/jsparse.cpp b/js/src/jsparse.cpp
>--- a/js/src/jsparse.cpp
>+++ b/js/src/jsparse.cpp
>@@ -1442,18 +1442,21 @@ Statements(JSContext *cx, JSTokenStream 
>     tc->blockNode = pn;
>     PN_INIT_LIST(pn);
> 
>     for (;;) {
>         ts->flags |= TSF_OPERAND;
>         tt = js_PeekToken(cx, ts);
>         ts->flags &= ~TSF_OPERAND;
>         if (tt <= TOK_EOF || tt == TOK_RC) {
>-            if (tt == TOK_ERROR)
>-                return NULL;
>+            if (tt == TOK_ERROR) {
>+                if (ts->flags & TSF_EOF)
>+                    ts->flags |= TSF_UNEXPECTED_EOF;
>+                return NULL;
>+            }
>             break;
>         }
>         pn2 = Statement(cx, ts, tc);
>         if (!pn2) {
>             if (ts->flags & TSF_EOF)
>                 ts->flags |= TSF_UNEXPECTED_EOF;
>             return NULL;
>         }

Could you instead write this instead to share code?

>         if (tt <= TOK_EOF || tt == TOK_RC) {
>+            if (tt != TOK_ERROR)
>                 break;
>         }
>         pn2 = Statement(cx, ts, tc);
>         if (!pn2) {
>             if (ts->flags & TSF_EOF)
>                 ts->flags |= TSF_UNEXPECTED_EOF;
>             return NULL;
>         }

Blake pointed out that TSF_ERROR ensures stickyness. r=me with that (and maybe an assertion that the error stuck?).

/be
Attachment #357859 - Flags: review?(brendan) → review+
Wouldn't it be trivial to write a test for this?
Hmm, as far as I know, we don't have any automated tests for JS_IsCompilableUnit.
http://hg.mozilla.org/tracemonkey/rev/f48a79146301 fixes the fallout from the first checkin :-/
http://hg.mozilla.org/mozilla-central/rev/888dc199871c
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Flags: wanted1.9.1?
http://hg.mozilla.org/releases/mozilla-1.9.1/rev/bdf0378ad4f8
Flags: wanted1.9.1? → wanted1.9.1+
Keywords: fixed1.9.1
Flags: in-testsuite-
Flags: in-litmus-
You need to log in before you can comment on or make changes to this bug.