Closed
Bug 443726
Opened 17 years ago
Closed 11 years ago
TypeError: redeclaration of const FOO should occur at runtime if redeclaration really happens
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: arno, Unassigned)
References
Details
Hi,
when trying to execute that script:
var bool = true;
if (bool) {
const FOO = "bar";
} else {
const FOO = "baz";
}
javascript engine throws before running the script.
file.js:5: TypeError: redeclaration of const FOO:
file.js:5: const FOO = "baz";
file.js:5: ..........^
but redeclaration would never occur at runtime.
That makes it impossible to have libraries defining constant as following:
if (typeof (lib_alreadyloaded) == "undefined") {
const lib_alreadyloaded = true;
const FOO = "bar";
}
if library is loaded a second time, script execution will break. When working whith multiple overlays, it's sometimes hard to keep track of which script have already been included, and making it possible to include such scripts would help in that case.
Comment 1•17 years ago
|
||
For ES4 (JS2) the proposal is that const is block-scoped, cannot be used before set, but need not be set in its declaration (is a write-once variable). This means your example is useless, since FOO (neither declaration) escapes its block scope in the then or else clause of "if (bool)".
We will be changing SpiderMonkey to track ES4 in bug 229756. Making this bug depend on that one for now.
/be
Depends on: 229756
Updated•15 years ago
|
Assignee | ||
Updated•11 years ago
|
Assignee: general → nobody
Comment 2•11 years ago
|
||
const is now block scoped, so this doesn't throw.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•