Closed Bug 793975 Opened 14 years ago Closed 10 years ago

with-statement function declaration issue

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

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"
I didn't check spec, just looked at existing browser behavior in Chrome 21, Opera 12.02 , and IE 10.
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
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
Yap. I thought it might have to do with non-standard function statement jazz (http://es5.github.com/#x12 under "note"). Thanks for confirming.
So is this WONTFIX, INVALID?
INVALID :D
It's DUPEME of the existing bug on implementing whatever ES6 comes up with here, imo.
no worries.
Assignee: general → nobody
See Also: → 1071646
Depends on: 1071646
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.