return when desugaring to closures
brendan at mozilla.com
Thu Oct 16 16:29:28 PDT 2008
On Oct 16, 2008, at 3:33 PM, Brendan Eich wrote:
> SpiderMonkey historically used SyntaxError, not ReferenceError, and
> throw at compile-time. This pre-dates ES1. Another example not
> involving let expressions:
> js> a + b = c
> typein:1: SyntaxError: invalid assignment left-hand side:
> typein:1: a + b = c
> typein:1: ......^
> From ES3 chapter 16:
> An implementation may treat any instance of the following kinds of
> runtime errors as a syntax error and therefore
> report it early:
> • Improper uses of return, break, and continue.
> • Using the eval property other than via a direct call.
> • Errors in regular expression literals.
> • Attempts to call PutValue on a value that is not a reference (for
> example, executing the assignment statement
> You may object that we should throw ReferenceError not SyntaxError
> -- that is not entirely clear from the chapter 16 wording,
"An implementation may treat any instance of the following kinds of
runtime errors as a syntax error and therefore report it early" seems
clear enough: an implementation that does choose ("may") to report the
ReferenceError from 8.7.2 PutValue step 1 *must* treat that runtime
error as a syntax error -- throw a SyntaxError, in other words.
There's no SpiderMonkey bug here, and it would be incorrect to do
other than change ReferenceError to SyntaxError when reporting the
PutValue error at compile time.
Again, this is not a grammatical error. The ES3 grammar is not enough
to decide what syntax errors might result from feeding a given program
source to an implementation.
More information about the Es-discuss