Closed
Bug 793975
Opened 14 years ago
Closed 10 years ago
with-statement function declaration issue
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: john.david.dalton, Unassigned)
References
Details
(Whiteboard: DUPEME)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Steps to reproduce:
(function() {
with({}) {
foo();
function foo() { alert('hi') }
}
}());
Actual results:
it errored
Expected results:
alerted "hi"
| Reporter | ||
Comment 1•14 years ago
|
||
I didn't check spec, just looked at existing browser behavior in Chrome 21, Opera 12.02 , and IE 10.
| Reporter | ||
Comment 2•14 years ago
|
||
Related to this Underscore bug: https://github.com/documentcloud/underscore/issues/795
| Reporter | ||
Updated•14 years ago
|
Summary: with statement function declartion → with-statement function declaration issue
Can you please provide more details? Where are you running that code? What is the error message? What spec does this apply to?
Assignee: nobody → general
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Version: unspecified → Trunk
Comment 4•14 years ago
|
||
Per spec, the code above is a SyntaxError and should not parse or run at all. Function declarations are not allowed inside a block; they're only allowed at toplevel in a function or in a toplevel script.
In practice, UAs do various weird stuff to sorta extend the spec here. Firefox makes it look more or less like this:
with({}) {
foo();
var foo = function foo() { alert('hi') }
}
which of course throws in your case. Other UAs hoist the function decl to various places (top of block, top of function, etc); actual interop is poor as with all spec extensions. So use of constructs like this is ... not suggested.
There are existing bugs about implementing a different behavior here once ECMA actually decides on what that behavior should be and spec it.
Whiteboard: DUPEME
| Reporter | ||
Comment 5•14 years ago
|
||
Yap. I thought it might have to do with non-standard function statement jazz (http://es5.github.com/#x12 under "note"). Thanks for confirming.
| Reporter | ||
Comment 7•14 years ago
|
||
INVALID :D
Comment 8•14 years ago
|
||
It's DUPEME of the existing bug on implementing whatever ES6 comes up with here, imo.
| Reporter | ||
Comment 9•14 years ago
|
||
no worries.
| Assignee | ||
Updated•12 years ago
|
Assignee: general → nobody
Comment 10•10 years ago
|
||
No longer reproducible, probably fixed when the new block-Level Function declaration semantics were implemented. Resolving as WFM.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•