Closed
Bug 351070
Opened 18 years ago
Closed 18 years ago
Scope of let declaration changes during decompilation
Categories
(Core :: JavaScript Engine, defect, P2)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla1.8.1
People
(Reporter: nanto, Assigned: brendan)
References
Details
(Keywords: verified1.8.1)
Attachments
(3 files, 6 obsolete files)
(deleted),
text/plain
|
Details | |
(deleted),
patch
|
mrbkap
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
brendan
:
review+
mtschrep
:
approval1.8.1+
|
Details | Diff | Splinter Review |
js> function f() { var a = 2; if (!!true) let a = 3; return a; }
js> f()
3
js> f
function f() {
var a = 2;
if (!!true) {
let a = 3;
}
return a;
}
js> eval(uneval(f))
js> f()
2
I don't know where the scope of a let declaration in a statement without curly brackets should be.
Assignee | ||
Comment 1•18 years ago
|
||
Decompiler always braces, for simplicity -- obviously that changes the scope of let (let declarations, e.g. let a = 3, bind in the nearest enclosing block, or the function body if no such block).
Contrast with bug 349634, where unnecessary-before-let-was-introduced braces are elided by the decompiler.
/be
Assignee: general → brendan
Blocks: js1.7let
OS: Windows XP → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.8.1
Assignee | ||
Comment 2•18 years ago
|
||
This turned out decently, after some noodling.
/be
Attachment #237550 -
Flags: review?(mrbkap)
Assignee | ||
Comment 3•18 years ago
|
||
This could be beefed up to test, for all the table entries, that braces do make the let a = 3 block-local and therefore change the expected return value.
/be
Assignee | ||
Comment 4•18 years ago
|
||
I fussed a bit, and eliminated a vacuous if (DONT_BRACE => braceOffset >= 0). I'm pretty happy with this now.
/be
Attachment #237550 -
Attachment is obsolete: true
Attachment #237562 -
Flags: review?(mrbkap)
Attachment #237550 -
Flags: review?(mrbkap)
Assignee | ||
Comment 5•18 years ago
|
||
Couldn't resist fussing once more: why unroll the memmove with an explicit store of the '\n' over the space before the brace, when it can be included in the move for free?
/be
Attachment #237562 -
Attachment is obsolete: true
Attachment #237565 -
Flags: review?(mrbkap)
Attachment #237562 -
Flags: review?(mrbkap)
Assignee | ||
Comment 6•18 years ago
|
||
D'oh, the test was broken. This is better, and gives visual results (should be testable against reference decompilations).
/be
Attachment #237551 -
Attachment is obsolete: true
Assignee | ||
Comment 7•18 years ago
|
||
Fixed to cope with JS_DONT_PRETTY_PRINT option, which suppresses newlines. Thus the memmove must handle moving the newline down two chars in the pretty case.
/be
Attachment #237565 -
Attachment is obsolete: true
Attachment #237568 -
Flags: review?(mrbkap)
Attachment #237565 -
Flags: review?(mrbkap)
Assignee | ||
Comment 8•18 years ago
|
||
Final fix, I missed early output from the test:
function f1() {
var n = 2, a = 2;
if (!!true)
let a = 3;
else {
foopy();
}
return a;
}
Easily handled by js_printf'ing the "else" with the "\t} ", leaving the " {\n" to be js_printf'd separately with SET_MAYBE_BRACE(jp).
Dangling else works, as ever:
js> version(170)
0
js> function f(x){if (x) if (y) z; else let w }
js> f
function f(x) {
if (x) {
if (y) {
z;
} else
let w;
}
}
js> function f(x){if (x){ if (y) z;} else let w }
js> f
function f(x) {
if (x) {
if (y) {
z;
}
} else
let w;
}
js> function f(x){if (x){ if (y) let z;} else let w }
js> f
function f(x) {
if (x) {
if (y)
let z;
} else
let w;
}
/be
Attachment #237568 -
Attachment is obsolete: true
Attachment #237569 -
Flags: review?(mrbkap)
Attachment #237568 -
Flags: review?(mrbkap)
Assignee | ||
Comment 9•18 years ago
|
||
This is important given let declarations for block scope in JS1.7.
/be
Status: NEW → ASSIGNED
Flags: blocking1.8.1?
Assignee | ||
Comment 10•18 years ago
|
||
Oops, I knew I forgot something that I thought of (like pink, best thoughts come in the shower, but no dive whiteboard or rubber memo-duck yet), then forgot:
js> version(170)
0
js> function f(){var a = 2; if (x) {let a = 3; print(a)} return a}
js> f
function f() {
var a = 2;
if (x)
let a = 3;
print(a);
return a;
}
With this patch, it's all good:
js> function f(){var a = 2; if (x) {let a = 3; print(a)} return a}
js> f
function f() {
var a = 2;
if (x) {
let a = 3;
print(a);
}
return a;
}
js> function f(){var a = 2; if (x) {print(a);let a = 3} return a}
js> f
function f() {
var a = 2;
if (x) {
print(a);
let a = 3;
}
return a;
}
js> function f(){var a = 2; if (x) {let a = 3} return a}
js> f
function f() {
var a = 2;
if (x) {
let a = 3;
}
return a;
}
js> function f(){var a = 2; if (x) let a = 3; return a}
js> f
function f() {
var a = 2;
if (x)
let a = 3;
return a;
}
Interdiff to the see the one crucial line.
/be
Attachment #237569 -
Attachment is obsolete: true
Attachment #237570 -
Flags: review?(mrbkap)
Attachment #237569 -
Flags: review?(mrbkap)
Updated•18 years ago
|
Flags: blocking1.8.1? → blocking1.8.1+
Comment 11•18 years ago
|
||
Comment on attachment 237570 [details] [diff] [review]
fix, v6
>+#if JS_HAS_BLOCK_SCOPE
>+ if (jp->braceState == MAYBE_BRACE &&
>+ pc + 1 == endpc &&
>+ !strncmp(rval, var_prefix[SRC_DECL_LET], 4) &&
>+ rval[4] != '(') {
>+ SetDontBrace(jp);
>+ }
>+#endif
Comment on what this is doing and r=mrbkap.
Attachment #237570 -
Flags: review?(mrbkap) → review+
Assignee | ||
Comment 12•18 years ago
|
||
This merged up to tip, to get the patch for bug 352026 that was just committed.
/be
Attachment #237788 -
Flags: review+
Attachment #237788 -
Flags: approval1.8.1?
Assignee | ||
Comment 13•18 years ago
|
||
Fixed on trunk.
/be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Comment 14•18 years ago
|
||
Comment on attachment 237788 [details] [diff] [review]
fix, v6 with comment and updated to track trunk
a=schrep for drivers.
Attachment #237788 -
Flags: approval1.8.1? → approval1.8.1+
Updated•18 years ago
|
Whiteboard: [checkin needed (1.8 branch)]
Comment 16•18 years ago
|
||
Checking in regress-351070-01.js;
/cvsroot/mozilla/js/tests/js1_7/block/regress-351070-01.js,v <-- regress-351070-01.js
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/tests/js1_7/block/regress-351070-02.js,v
done
Checking in regress-351070-02.js;
/cvsroot/mozilla/js/tests/js1_7/block/regress-351070-02.js,v <-- regress-351070-02.js
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/tests/js1_7/block/regress-351070-03.js,v
done
Checking in regress-351070-03.js;
/cvsroot/mozilla/js/tests/js1_7/block/regress-351070-03.js,v <-- regress-351070-03.js
initial revision: 1.1
done
Flags: in-testsuite+
Comment 17•18 years ago
|
||
verified fixed 1.8 20060914 windows/linux 1.9 20060914 windows/mac*/linux
Status: RESOLVED → VERIFIED
Keywords: fixed1.8.1 → verified1.8.1
Updated•18 years ago
|
Whiteboard: [checkin needed (1.8 branch)]
You need to log in
before you can comment on or make changes to this bug.
Description
•