Why Doesn't Strict Mode Restrict The Identifiers "eval", And "arguments" From Appearing As Label Names?
Solution 1:
I don't know why, but I can hazard a pretty good guess.
The reason eval
and arguments
are restricted for variable names (and, for that matter, why with
is forbidden) is that they affect where variable names bind (i.e. to a local variable, a variable in an enclosing scope, or to a property on the global object if one exists). Without those restrictions, some names are unbound until runtime, with all the hazards that implies.
Label names occupy a different naming space from variable names, property names, and so on. There's never ambiguity about the target of a break
/continue
, because labels are statically assigned and label references are statically resolved. (Yes, eval
code can include labels. But existing jumps can't target those labels, nor can jumps in eval
code target pre-existing labels, because label resolution occurs at compile time, and it is scoped to a Program, to use the ECMAScript terminal's name. A script that contains an eval
call is a Program, and the code executed by the eval
call is a Program, but the two are entirely separate for label-targeting purposes.)
The reason to forbid eval
and arguments
for variable names simply doesn't apply to labels. Therefore, labels can still be named eval
or arguments
. It would be stupid to name a label that way, true. And if someone were designing ECMAScript/JavaScript again, they'd be keywords, and not usable as label names. But there's no gain to be had from forbidding them as label names, and at least a small compatibility argument for not forbidding them, so they were not forbidden.
Post a Comment for "Why Doesn't Strict Mode Restrict The Identifiers "eval", And "arguments" From Appearing As Label Names?"