Closed Bug 352268 Opened 18 years ago Closed 18 years ago

Decompilation uses braces for "else ... if" even if that changes the scope of a "let" statement

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.8.1

People

(Reporter: jruderman, Assigned: brendan)

References

Details

(Keywords: testcase, verified1.8.1)

Attachments

(1 file)

js> p = function() { if(x) { } else if (y) let b=2; } function () { if (x) { } else { if (y) let b = 2; } } (Why does the scope of a "let" statement depend only on the location of braces, rather than treating all ifs / withs / fors as implicit blocks? IMO, for the code "if(1) let b;", it would make more sense for the scope of "b" to be limited to only that statement. And it would cause less pain for decompilation too.)
block means {statements}, always. This is true for function bodies and switch case-list bodies too. If we didn't have a decompiler, we wouldn't mind. It's true that a conditional let is not too useful, and could be obfuscatory. But it's more consistent (fewer rules) if let declarations always find the braced block enclosing them and use that for scope. /be
Attached patch fix (deleted) — Splinter Review
This patch modifies SRC_IF_ELSE to have two immediate offset operands, the first as before (telling the distance from the goto around the else clause to the first bytecode after the if-else), the second if non-zero telling the distance from the goto at the end of the then clause to the else-if's condition (an else-if is an if that is the entire content of an else clause). Apart from renaming len => tail and using cond for the second note offset in the decompiler to clarify what's going on, the patch is pretty clear. A simple flag suffices to tweak else-if formatting while reusing all the good maybe-brace magic. Decompilation of the testcase, and disassembly: js> p = function() { if(x) { } else if (y) let b=2; } function () { if (x) { } else if (y) let b = 2; } js> dis(p) flags: LAMBDA main: 00000: enterblock depth 0 {b: 0} 00003: name "x" 00006: ifeq 12 (6) 00009: goto 25 (16) 00012: name "y" 00015: ifeq 25 (10) 00018: uint16 2 00021: setlocal 0 00024: pop 00025: leaveblock 1 00028: stop Source notes: 0: 6 [ 6] if-else else 3 elseif 6 3: 15 [ 9] xdelta 4: 15 [ 0] if 5: 21 [ 6] decl offset 2 /be
Assignee: general → brendan
Status: NEW → ASSIGNED
Attachment #238090 - Flags: review?(mrbkap)
OS: Mac OS X 10.4 → All
Priority: -- → P1
Hardware: Macintosh → All
Target Milestone: --- → mozilla1.8.1
Attachment #238090 - Flags: review?(mrbkap) → review+
Fixed on trunk: Checking in js.c; /cvsroot/mozilla/js/src/js.c,v <-- js.c new revision: 3.124; previous revision: 3.123 done Checking in jsemit.c; /cvsroot/mozilla/js/src/jsemit.c,v <-- jsemit.c new revision: 3.211; previous revision: 3.210 done Checking in jsopcode.c; /cvsroot/mozilla/js/src/jsopcode.c,v <-- jsopcode.c new revision: 3.180; previous revision: 3.179 done Checking in jsxdrapi.h; /cvsroot/mozilla/js/src/jsxdrapi.h,v <-- jsxdrapi.h new revision: 1.22; previous revision: 1.21 done /be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Attachment #238090 - Flags: approval1.8.1?
Comment on attachment 238090 [details] [diff] [review] fix a=schrep for 181drivers
Attachment #238090 - Flags: approval1.8.1? → approval1.8.1+
Fixed on the 1.8 branch. /be
Keywords: fixed1.8.1
Checking in regress-352268.js; /cvsroot/mozilla/js/tests/js1_7/block/regress-352268.js,v <-- regress-352268.js initial revision: 1.1 done
Flags: in-testsuite+
verified fixed 1.8 20060914 windows/linux 1.9 20060914 windows/mac*/linux
Status: RESOLVED → VERIFIED
Depends on: 562028
Historical note: we stopped the madness of "conditional let" in bug 408957, with this error: typein:5: SyntaxError: let declaration not directly within block: /be
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: