Closed Bug 407727 Opened 13 years ago Closed 13 years ago

Top-level |let Object| no longer works

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: igor, Unassigned)

References

Details

As a result of changes from bug 376957 the following one-liner caused an error:

~/m/trunk/mozilla/js/src $ js -e 'let Object = 1; print(Object);'
-e:1: TypeError: redeclaration of const Object

Yet the same code inside  a block is fine:

~/m/trunk/mozilla/js/src $ js -e '{ let Object = 1; print(Object); }'
1
One of the solution to this bug is to force the top-level let in scripts to create a new scope object and not pollute the global scope. This would have a consequence as a code like:

<script>
let a = 1;
</script> 

<script>
alert(typeof a);
</script> 

would show "undefined", but IMO this would allow to use the global let as a kind of static declarations in the script tags or loaded scripts without the fear of polluting the global scope.  
Summary: let Object no longer works → Top-level |let Object| no longer works
ES4 proposes exactly what comment 1 describes: an implicit block around top-level programs and function bodies. This bug is due to bug 346749 in combination with the patch for bug 376957 -- and the change to "type name binding" in the latter patch has been undone by the patch for bug 409252.

So this bug should be FIXED now, due to the patch for bug 409252 landing. Marking so, please re-open if I'm wrong.

/be
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Checking in regress-407727-01.js;
/cvsroot/mozilla/js/tests/js1_7/regress/regress-407727-01.js,v  <--  regress-407727-01.js
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/tests/js1_7/regress/regress-407727-02.js,v
done
Checking in regress-407727-02.js;
/cvsroot/mozilla/js/tests/js1_7/regress/regress-407727-02.js,v  <--  regress-407727-02.js
initial revision: 1.1
Flags: in-testsuite+
Flags: in-litmus-
verified fixed 1.9.0
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.