Closed
Bug 616618
Opened 15 years ago
Closed 10 years ago
Assigning to a const is unsoundly optimized away
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: jorendorff, Unassigned)
Details
"use strict";
const k = 0;
k = 1;
This should throw an exception, but doesn't, because the assignment to k is optimized away in the bytecode compiler.
Does any later stage depend on this optimization? It seems like it can't be for performance, since we're talking about assignment to a const here. I guess I'll find out.
| Reporter | ||
Comment 1•15 years ago
|
||
I looked into this a bit. The question, of course, is what to do once you know you're assigning to a const.
We could deoptimize the entire enclosing script/function. The emitter would then emit a JOF_NAME opcode for the assignment, inc/dec, or delete. That would work correctly. To do it during the parser's first pass, we would need to touch two places (assignExpr and BindVarOrConst). Maybe it could be done during the analyzeFunctions pass with less hassle. (?)
The other approach is to do it in the emitter, but it's not safe to emit JOF_NAME ops in those cases, is it? So, what bytecode should we emit?
k = 1;
one
??? /* opcode that behaves like setname */
pop
k++;
??? /* opcode that behaves like nameinc */
pop
delete k;
??? /* opcode that behaves like delname */
pop
I'm not taking this.
| Assignee | ||
Updated•11 years ago
|
Assignee: general → nobody
Comment 2•10 years ago
|
||
No longer reproducible - resolving as WFM.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•