Closed Bug 401405 Opened 15 years ago Closed 15 years ago

narcissus - invalid label error on nest ternary

Categories

(Core :: JavaScript Engine, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bc, Assigned: brendan)

References

Details

Attachments

(1 file, 1 obsolete file)

js> a=b=c=d=e=1
1
js> q='a?b?c:d:e'
a?b?c:d:e
js> eval(q)
1
js> parse(q)
:1: Invalid label
js>
Flags: in-testsuite-
Flags: in-litmus-
Attached patch fix (obsolete) — Splinter Review
Attachment #286458 - Flags: review?(mrbkap)
Assignee: general → brendan
Attached patch forgot jsexec.jsSplinter Review
Attachment #286458 - Attachment is obsolete: true
Attachment #286459 - Flags: review?(mrbkap)
Attachment #286458 - Flags: review?(mrbkap)
Attachment #286459 - Flags: review?(mrbkap) → review+
Fixed:

js/narcissus/jsexec.js 1.27
js/narcissus/jsparse.js 1.25

/be
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
This fix is incorrect; although it does fix the erronous 'invalid label error' the result of 'a?b?c:d:e' is actually evaluated as 'a?b:c?d:e'

I fixed this by reusing 'CONDITIONAL' for nested ternaries, but giving this a higher precedence:

jsparse.js
654a655,656
>     // add special precedence for nested ternaries
>     CONDITIONAL: 3,
679c681
<     HOOK: 3,
---
>     HOOK: 3, CONDITIONAL: 3,
761a764,765
> 		if (x.hookLevel > 1)
> 		    n->type = CONDITIONAL;

jsexec.js
502a503
>       case CONDITIONAL:

I'm not sure what the current status of Narcissus is; is it actively used besides in ported projects?
err, n->type should read n.type ofcourse (doing too much PHP these days)
hmmz, my patch only moves the problem ahead; it now breaks stuff like:

a ? b ? c = 1 : c = 2 : c = 3

and we're back to bug https://bugzilla.mozilla.org/show_bug.cgi?id=330975

I wonder if this is solvable in this way or if it would be better to handle this as a seperate construct.
Since this issue is closed I opened a new one with a new proposed patch: https://bugzilla.mozilla.org/show_bug.cgi?id=492445
You need to log in before you can comment on or make changes to this bug.