Reviewers: Lasse Reichstein, Mads Ager,
Message:
the first early draft.
Description:
First draft of strict mode.
Adding a boolean 'strict mode' flag to the FunctionLiteral AST node.
Adding "use strict" string to the symbol list
Adding a boolean strict_mode field to the parser, and a class to track the
stack
of strict mode flags during parsing.
Strict mode detection
Currently parser only sniffs next token to detect strict mode. This is not
100%
correct but seems like the best compromise. Issues:
* "use strict" may not contain escape sequences or line continuations. To
detect
this lexer would have to delay application of escape sequences (with likely
perf
implications)
* lexer currently looks ahead more eagerly than strictly necessary which
means
if "use strict" was detected at syntactic level (as ExpressionStatement
whose
expression is "use strict" only) the token following semicolon has already
been
scanned.
* If implemented by checking result of ParseStatement, this would also
trigger
strict mode:
((("use strict")));
because V8 throws away parentheses.
* the 100% correct implementation would have to probably sniff the upcoming
token for "use strict", parse the expression statement, check that, AND then
reparse the whole function again (to double check anything that preceded
the use
strict directive). Alternatively function beginning could be
scanned 'manually'
which would require implementation of skipping comments, newlines and
(simplified) string parsing.
Given all these influences, for now I opted for simple lexical check.
Strict mode checks implemented:
- var eval | arguments
- catch (eval | arguments)
- 'with' is disabled
- function can't be named eval or arguments
- function parameter name cannot be eval or arguments
- no duplicate parameter names allowed
Error reporting is rather rudimentary because most location information is
tossed by V8 and some of it needed later when already unavailable. Doing my
best
without arbitrarily annotating nodes/tokens with loc info.
BUG=
TEST=
Please review this at http://codereview.chromium.org/6144005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/ast.h
M src/heap.h
M src/messages.js
M src/parser.h
M src/parser.cc
M src/scopes.h
M src/scopes.cc
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev